superdoc 1.0.0-beta.13 → 1.0.0-beta.14
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/{PdfViewer-D_E86Mtr.cjs → PdfViewer-Cdc_EOZ9.cjs} +2 -2
- package/dist/chunks/{PdfViewer-D0cPi5hG.es.js → PdfViewer-DrsLL5TV.es.js} +2 -2
- package/dist/chunks/{eventemitter3-ByBH0NYV.es.js → eventemitter3-CcXAdeql.es.js} +1 -1
- package/dist/chunks/{eventemitter3-CFCpOk3d.cjs → eventemitter3-DQmQUge-.cjs} +1 -1
- package/dist/chunks/{index-CL4VptDO.cjs → index-9ZvcPlCg.cjs} +6 -6
- package/dist/chunks/{index-BHmLKAul.es.js → index-DB1DyDmZ.es.js} +6 -6
- package/dist/chunks/{index-BMAfbNel-CvPc3jnD.es.js → index-I4Ew0HDV-Bht7-IGi.es.js} +1 -1
- package/dist/chunks/{index-BMAfbNel-DBZCkkMj.cjs → index-I4Ew0HDV-EPhjcu7T.cjs} +1 -1
- package/dist/chunks/{jszip-BwsONqK5.es.js → jszip-5vvIqAEE.es.js} +1 -1
- package/dist/chunks/{jszip-B99MTu59.cjs → jszip-BdEez1WM.cjs} +1 -1
- package/dist/chunks/{super-editor.es-riuOlaxm.cjs → super-editor.es-DuS77THX.cjs} +3958 -531
- package/dist/chunks/{super-editor.es-5gtBhP8I.es.js → super-editor.es-DxAG4BVh.es.js} +3959 -532
- package/dist/chunks/{vue-CztqUvm1.es.js → vue-Dysv_7z5.es.js} +101 -12
- package/dist/chunks/{vue-ARQSyfaw.cjs → vue-jWLMl8Ts.cjs} +89 -0
- package/dist/chunks/xml-js-ClO_jHnq.es.js +2 -0
- package/dist/chunks/xml-js-Dz51sEbr.cjs +3 -0
- package/dist/packages/superdoc/src/core/SuperDoc.d.ts.map +1 -1
- package/dist/style.css +50 -11
- package/dist/super-editor/ai-writer.es.js +2 -2
- package/dist/super-editor/chunks/{converter-D9KiDgXx.js → converter-CfmIU--8.js} +511 -95
- package/dist/super-editor/chunks/{docx-zipper-DQmUj-ef.js → docx-zipper-B-CXiNSb.js} +1 -1
- package/dist/super-editor/chunks/{editor-ByPqJ2k8.js → editor-wC_gs8Bl.js} +2898 -347
- package/dist/super-editor/chunks/{index-BMAfbNel.js → index-I4Ew0HDV.js} +1 -1
- package/dist/super-editor/chunks/{toolbar-Da2cOhJ-.js → toolbar-BR1GYvwW.js} +36 -22
- package/dist/super-editor/converter.es.js +1 -1
- package/dist/super-editor/docx-zipper.es.js +2 -2
- package/dist/super-editor/editor.es.js +3 -3
- package/dist/super-editor/file-zipper.es.js +1 -1
- package/dist/super-editor/style.css +50 -11
- package/dist/super-editor/super-editor.es.js +559 -67
- package/dist/super-editor/toolbar.es.js +2 -2
- package/dist/super-editor.cjs +4 -4
- package/dist/super-editor.es.js +2 -2
- package/dist/superdoc.cjs +2 -2
- package/dist/superdoc.es.js +2 -2
- package/dist/superdoc.umd.js +4023 -520
- package/dist/superdoc.umd.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/xml-js-BZPSMmVo.es.js +0 -2
- package/dist/chunks/xml-js-DQa4Ye5C.cjs +0 -3
|
@@ -21649,7 +21649,7 @@ function handleAnnotationNode(params) {
|
|
|
21649
21649
|
attrs.displayLabel = placeholderLabel;
|
|
21650
21650
|
}
|
|
21651
21651
|
const { attrs: marksAsAttrs, marks } = parseAnnotationMarks(sdtContent);
|
|
21652
|
-
const allAttrs = { ...attrs, ...marksAsAttrs };
|
|
21652
|
+
const allAttrs = { ...attrs, ...marksAsAttrs, ...sdtPr && { sdtPr } };
|
|
21653
21653
|
if (!allAttrs.hash) allAttrs.hash = generateDocxRandomId(4);
|
|
21654
21654
|
if (!attrs.fieldId || !attrs.type) {
|
|
21655
21655
|
return null;
|
|
@@ -21809,16 +21809,13 @@ function handleDocPartObj(params) {
|
|
|
21809
21809
|
const sdtPr = node.elements.find((el) => el.name === "w:sdtPr");
|
|
21810
21810
|
const docPartObj = sdtPr?.elements.find((el) => el.name === "w:docPartObj");
|
|
21811
21811
|
const docPartGallery = docPartObj?.elements.find((el) => el.name === "w:docPartGallery");
|
|
21812
|
-
const docPartGalleryType = docPartGallery?.attributes["w:val"];
|
|
21813
|
-
if (!docPartGalleryType || !validGalleryTypeMap[docPartGalleryType]) {
|
|
21814
|
-
return null;
|
|
21815
|
-
}
|
|
21812
|
+
const docPartGalleryType = docPartGallery?.attributes?.["w:val"] ?? null;
|
|
21816
21813
|
const content = node?.elements.find((el) => el.name === "w:sdtContent");
|
|
21817
|
-
const handler2 = validGalleryTypeMap[docPartGalleryType];
|
|
21814
|
+
const handler2 = validGalleryTypeMap[docPartGalleryType] || genericDocPartHandler;
|
|
21818
21815
|
const result = handler2({
|
|
21819
21816
|
...params,
|
|
21820
21817
|
nodes: [content],
|
|
21821
|
-
extraParams: { ...params.extraParams || {}, sdtPr }
|
|
21818
|
+
extraParams: { ...params.extraParams || {}, sdtPr, docPartGalleryType }
|
|
21822
21819
|
});
|
|
21823
21820
|
return result;
|
|
21824
21821
|
}
|
|
@@ -21831,13 +21828,43 @@ const tableOfContentsHandler = (params) => {
|
|
|
21831
21828
|
});
|
|
21832
21829
|
const sdtPr = params.extraParams.sdtPr;
|
|
21833
21830
|
const id = sdtPr.elements?.find((el) => el.name === "w:id")?.attributes["w:val"] || "";
|
|
21831
|
+
const docPartObj = sdtPr?.elements.find((el) => el.name === "w:docPartObj");
|
|
21832
|
+
const docPartUnique = docPartObj?.elements.some((el) => el.name === "w:docPartUnique") ?? false;
|
|
21834
21833
|
const result = {
|
|
21835
21834
|
type: "documentPartObject",
|
|
21836
21835
|
content: translatedContent,
|
|
21837
21836
|
attrs: {
|
|
21838
21837
|
id,
|
|
21839
21838
|
docPartGallery: "Table of Contents",
|
|
21840
|
-
docPartUnique
|
|
21839
|
+
docPartUnique,
|
|
21840
|
+
sdtPr
|
|
21841
|
+
// Passthrough for round-trip preservation
|
|
21842
|
+
}
|
|
21843
|
+
};
|
|
21844
|
+
return result;
|
|
21845
|
+
};
|
|
21846
|
+
const genericDocPartHandler = (params) => {
|
|
21847
|
+
const node = params.nodes[0];
|
|
21848
|
+
const translatedContent = params.nodeListHandler.handler({
|
|
21849
|
+
...params,
|
|
21850
|
+
nodes: node.elements,
|
|
21851
|
+
path: [...params.path || [], node]
|
|
21852
|
+
});
|
|
21853
|
+
const sdtPr = params.extraParams.sdtPr;
|
|
21854
|
+
const docPartGalleryType = params.extraParams.docPartGalleryType;
|
|
21855
|
+
const id = sdtPr?.elements?.find((el) => el.name === "w:id")?.attributes["w:val"] || "";
|
|
21856
|
+
const docPartObj = sdtPr?.elements.find((el) => el.name === "w:docPartObj");
|
|
21857
|
+
const docPartGallery = docPartGalleryType ?? docPartObj?.elements?.find((el) => el.name === "w:docPartGallery")?.attributes?.["w:val"] ?? null;
|
|
21858
|
+
const docPartUnique = docPartObj?.elements.some((el) => el.name === "w:docPartUnique") ?? false;
|
|
21859
|
+
const result = {
|
|
21860
|
+
type: "documentPartObject",
|
|
21861
|
+
content: translatedContent,
|
|
21862
|
+
attrs: {
|
|
21863
|
+
id,
|
|
21864
|
+
docPartGallery,
|
|
21865
|
+
docPartUnique,
|
|
21866
|
+
sdtPr
|
|
21867
|
+
// Passthrough for round-trip preservation of all sdtPr elements
|
|
21841
21868
|
}
|
|
21842
21869
|
};
|
|
21843
21870
|
return result;
|
|
@@ -21859,6 +21886,9 @@ function handleDocumentSectionNode(params) {
|
|
|
21859
21886
|
const titleTag = sdtPr?.elements.find((el) => el.name === "w:alias");
|
|
21860
21887
|
const title = titleTag?.attributes?.["w:val"] || tagValue.title || null;
|
|
21861
21888
|
const { description } = tagValue;
|
|
21889
|
+
const lockTag = sdtPr?.elements.find((el) => el.name === "w:lock");
|
|
21890
|
+
const lockValue = lockTag?.attributes?.["w:val"];
|
|
21891
|
+
const isLocked = lockValue === "sdtContentLocked";
|
|
21862
21892
|
const sdtContent = node.elements.find((el) => el.name === "w:sdtContent");
|
|
21863
21893
|
const translatedContent = nodeListHandler.handler({
|
|
21864
21894
|
...params,
|
|
@@ -21871,7 +21901,10 @@ function handleDocumentSectionNode(params) {
|
|
|
21871
21901
|
attrs: {
|
|
21872
21902
|
id,
|
|
21873
21903
|
title,
|
|
21874
|
-
description
|
|
21904
|
+
description,
|
|
21905
|
+
isLocked,
|
|
21906
|
+
...sdtPr && { sdtPr }
|
|
21907
|
+
// Passthrough for round-trip preservation of unknown elements only if it exists
|
|
21875
21908
|
}
|
|
21876
21909
|
};
|
|
21877
21910
|
return result;
|
|
@@ -24664,7 +24697,10 @@ function getThemeColor(name) {
|
|
|
24664
24697
|
text1: "#000000",
|
|
24665
24698
|
text2: "#1f497d",
|
|
24666
24699
|
background1: "#ffffff",
|
|
24667
|
-
background2: "#eeece1"
|
|
24700
|
+
background2: "#eeece1",
|
|
24701
|
+
// Office XML shortcuts
|
|
24702
|
+
bg1: "#ffffff",
|
|
24703
|
+
bg2: "#eeece1"
|
|
24668
24704
|
};
|
|
24669
24705
|
return colors[name] ?? "#000000";
|
|
24670
24706
|
}
|
|
@@ -24701,7 +24737,10 @@ function applyColorModifier(hexColor, modifier, value) {
|
|
|
24701
24737
|
function extractStrokeWidth(spPr) {
|
|
24702
24738
|
const ln = spPr?.elements?.find((el) => el.name === "a:ln");
|
|
24703
24739
|
const w2 = ln?.attributes?.["w"];
|
|
24704
|
-
|
|
24740
|
+
if (!w2) return 1;
|
|
24741
|
+
const emu = typeof w2 === "string" ? parseFloat(w2) : w2;
|
|
24742
|
+
const STROKE_DPI = 72;
|
|
24743
|
+
return emu * STROKE_DPI / 914400;
|
|
24705
24744
|
}
|
|
24706
24745
|
function extractStrokeColor(spPr, style) {
|
|
24707
24746
|
const ln = spPr?.elements?.find((el) => el.name === "a:ln");
|
|
@@ -24762,6 +24801,7 @@ function extractFillColor(spPr, style) {
|
|
|
24762
24801
|
if (schemeClr2) {
|
|
24763
24802
|
const themeName2 = schemeClr2.attributes?.["val"];
|
|
24764
24803
|
let color2 = getThemeColor(themeName2);
|
|
24804
|
+
let alpha = null;
|
|
24765
24805
|
const modifiers2 = schemeClr2.elements || [];
|
|
24766
24806
|
modifiers2.forEach((mod) => {
|
|
24767
24807
|
if (mod.name === "a:shade") {
|
|
@@ -24772,18 +24812,32 @@ function extractFillColor(spPr, style) {
|
|
|
24772
24812
|
color2 = applyColorModifier(color2, "lumMod", mod.attributes["val"]);
|
|
24773
24813
|
} else if (mod.name === "a:lumOff") {
|
|
24774
24814
|
color2 = applyColorModifier(color2, "lumOff", mod.attributes["val"]);
|
|
24815
|
+
} else if (mod.name === "a:alpha") {
|
|
24816
|
+
alpha = parseInt(mod.attributes["val"]) / 1e5;
|
|
24775
24817
|
}
|
|
24776
24818
|
});
|
|
24819
|
+
if (alpha !== null && alpha < 1) {
|
|
24820
|
+
return { type: "solidWithAlpha", color: color2, alpha };
|
|
24821
|
+
}
|
|
24777
24822
|
return color2;
|
|
24778
24823
|
}
|
|
24779
24824
|
const srgbClr = solidFill.elements?.find((el) => el.name === "a:srgbClr");
|
|
24780
24825
|
if (srgbClr) {
|
|
24781
|
-
|
|
24826
|
+
let alpha = null;
|
|
24827
|
+
const alphaEl = srgbClr.elements?.find((el) => el.name === "a:alpha");
|
|
24828
|
+
if (alphaEl) {
|
|
24829
|
+
alpha = parseInt(alphaEl.attributes?.["val"] || "100000", 10) / 1e5;
|
|
24830
|
+
}
|
|
24831
|
+
const color2 = "#" + srgbClr.attributes?.["val"];
|
|
24832
|
+
if (alpha !== null && alpha < 1) {
|
|
24833
|
+
return { type: "solidWithAlpha", color: color2, alpha };
|
|
24834
|
+
}
|
|
24835
|
+
return color2;
|
|
24782
24836
|
}
|
|
24783
24837
|
}
|
|
24784
24838
|
const gradFill = spPr?.elements?.find((el) => el.name === "a:gradFill");
|
|
24785
24839
|
if (gradFill) {
|
|
24786
|
-
return
|
|
24840
|
+
return extractGradientFill(gradFill);
|
|
24787
24841
|
}
|
|
24788
24842
|
const blipFill = spPr?.elements?.find((el) => el.name === "a:blipFill");
|
|
24789
24843
|
if (blipFill) {
|
|
@@ -24792,6 +24846,8 @@ function extractFillColor(spPr, style) {
|
|
|
24792
24846
|
if (!style) return "#5b9bd5";
|
|
24793
24847
|
const fillRef = style.elements?.find((el) => el.name === "a:fillRef");
|
|
24794
24848
|
if (!fillRef) return "#5b9bd5";
|
|
24849
|
+
const fillRefIdx = fillRef.attributes?.["idx"];
|
|
24850
|
+
if (fillRefIdx === "0") return null;
|
|
24795
24851
|
const schemeClr = fillRef.elements?.find((el) => el.name === "a:schemeClr");
|
|
24796
24852
|
if (!schemeClr) return "#5b9bd5";
|
|
24797
24853
|
const themeName = schemeClr.attributes?.["val"];
|
|
@@ -24808,9 +24864,49 @@ function extractFillColor(spPr, style) {
|
|
|
24808
24864
|
});
|
|
24809
24865
|
return color;
|
|
24810
24866
|
}
|
|
24867
|
+
function extractGradientFill(gradFill) {
|
|
24868
|
+
const gradient = {
|
|
24869
|
+
type: "gradient",
|
|
24870
|
+
stops: [],
|
|
24871
|
+
angle: 0
|
|
24872
|
+
};
|
|
24873
|
+
const gsLst = gradFill.elements?.find((el) => el.name === "a:gsLst");
|
|
24874
|
+
if (gsLst) {
|
|
24875
|
+
const stops = gsLst.elements?.filter((el) => el.name === "a:gs") || [];
|
|
24876
|
+
gradient.stops = stops.map((stop) => {
|
|
24877
|
+
const pos = parseInt(stop.attributes?.["pos"] || "0", 10) / 1e5;
|
|
24878
|
+
const srgbClr = stop.elements?.find((el) => el.name === "a:srgbClr");
|
|
24879
|
+
let color = "#000000";
|
|
24880
|
+
let alpha = 1;
|
|
24881
|
+
if (srgbClr) {
|
|
24882
|
+
color = "#" + srgbClr.attributes?.["val"];
|
|
24883
|
+
const alphaEl = srgbClr.elements?.find((el) => el.name === "a:alpha");
|
|
24884
|
+
if (alphaEl) {
|
|
24885
|
+
alpha = parseInt(alphaEl.attributes?.["val"] || "100000", 10) / 1e5;
|
|
24886
|
+
}
|
|
24887
|
+
}
|
|
24888
|
+
return { position: pos, color, alpha };
|
|
24889
|
+
});
|
|
24890
|
+
}
|
|
24891
|
+
const lin = gradFill.elements?.find((el) => el.name === "a:lin");
|
|
24892
|
+
if (lin) {
|
|
24893
|
+
const ang = parseInt(lin.attributes?.["ang"] || "0", 10) / 6e4;
|
|
24894
|
+
gradient.angle = ang;
|
|
24895
|
+
}
|
|
24896
|
+
const path = gradFill.elements?.find((el) => el.name === "a:path");
|
|
24897
|
+
if (path) {
|
|
24898
|
+
gradient.gradientType = "radial";
|
|
24899
|
+
gradient.path = path.attributes?.["path"] || "circle";
|
|
24900
|
+
} else {
|
|
24901
|
+
gradient.gradientType = "linear";
|
|
24902
|
+
}
|
|
24903
|
+
return gradient;
|
|
24904
|
+
}
|
|
24811
24905
|
const DRAWING_XML_TAG = "w:drawing";
|
|
24812
24906
|
const SHAPE_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
|
|
24813
24907
|
const GROUP_URI = "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup";
|
|
24908
|
+
const DEFAULT_SHAPE_WIDTH = 100;
|
|
24909
|
+
const DEFAULT_SHAPE_HEIGHT = 100;
|
|
24814
24910
|
function handleImageNode(node, params, isAnchor) {
|
|
24815
24911
|
const { docx, filename } = params;
|
|
24816
24912
|
const { attributes } = node;
|
|
@@ -24934,7 +25030,7 @@ function handleImageNode(node, params, isAnchor) {
|
|
|
24934
25030
|
horizontal: positionHValue,
|
|
24935
25031
|
top: positionVValue
|
|
24936
25032
|
};
|
|
24937
|
-
return handleShapeDrawing(params, node, graphicData, size, padding, shapeMarginOffset);
|
|
25033
|
+
return handleShapeDrawing(params, node, graphicData, size, padding, shapeMarginOffset, anchorData, wrap2, isAnchor);
|
|
24938
25034
|
}
|
|
24939
25035
|
if (uri2 === GROUP_URI) {
|
|
24940
25036
|
const shapeMarginOffset = {
|
|
@@ -24942,13 +25038,16 @@ function handleImageNode(node, params, isAnchor) {
|
|
|
24942
25038
|
horizontal: positionHValue,
|
|
24943
25039
|
top: positionVValue
|
|
24944
25040
|
};
|
|
24945
|
-
return handleShapeGroup(params, node, graphicData, size, padding, shapeMarginOffset);
|
|
25041
|
+
return handleShapeGroup(params, node, graphicData, size, padding, shapeMarginOffset, anchorData, wrap2);
|
|
24946
25042
|
}
|
|
24947
25043
|
const picture = graphicData?.elements.find((el) => el.name === "pic:pic");
|
|
24948
25044
|
if (!picture || !picture.elements) return null;
|
|
24949
25045
|
const blipFill = picture.elements.find((el) => el.name === "pic:blipFill");
|
|
24950
25046
|
const blip = blipFill?.elements.find((el) => el.name === "a:blip");
|
|
24951
25047
|
if (!blip) return null;
|
|
25048
|
+
const stretch = blipFill?.elements.find((el) => el.name === "a:stretch");
|
|
25049
|
+
const fillRect = stretch?.elements.find((el) => el.name === "a:fillRect");
|
|
25050
|
+
const shouldStretch = Boolean(stretch && fillRect);
|
|
24952
25051
|
const spPr = picture.elements.find((el) => el.name === "pic:spPr");
|
|
24953
25052
|
if (spPr) {
|
|
24954
25053
|
const xfrm = spPr.elements.find((el) => el.name === "a:xfrm");
|
|
@@ -25002,6 +25101,7 @@ function handleImageNode(node, params, isAnchor) {
|
|
|
25002
25101
|
wrapText: wrap2.attrs.wrapText
|
|
25003
25102
|
} : {},
|
|
25004
25103
|
wrapTopAndBottom: wrap2.type === "TopAndBottom",
|
|
25104
|
+
shouldStretch,
|
|
25005
25105
|
originalPadding: {
|
|
25006
25106
|
distT: attributes["distT"],
|
|
25007
25107
|
distB: attributes["distB"],
|
|
@@ -25013,26 +25113,25 @@ function handleImageNode(node, params, isAnchor) {
|
|
|
25013
25113
|
}
|
|
25014
25114
|
};
|
|
25015
25115
|
}
|
|
25016
|
-
const handleShapeDrawing = (params, node, graphicData, size, padding, marginOffset) => {
|
|
25116
|
+
const handleShapeDrawing = (params, node, graphicData, size, padding, marginOffset, anchorData, wrap2, isAnchor) => {
|
|
25017
25117
|
const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
|
|
25018
25118
|
const textBox = wsp.elements.find((el) => el.name === "wps:txbx");
|
|
25019
25119
|
const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
|
|
25020
25120
|
const spPr = wsp.elements.find((el) => el.name === "wps:spPr");
|
|
25021
25121
|
const prstGeom = spPr?.elements.find((el) => el.name === "a:prstGeom");
|
|
25022
25122
|
const shapeType = prstGeom?.attributes["prst"];
|
|
25023
|
-
|
|
25024
|
-
|
|
25123
|
+
const hasGradientFill = spPr?.elements?.find((el) => el.name === "a:gradFill");
|
|
25124
|
+
if (shapeType === "rect" && !textBoxContent && !hasGradientFill) {
|
|
25125
|
+
return getRectangleShape(params, spPr, node, marginOffset, anchorData, wrap2, isAnchor);
|
|
25025
25126
|
}
|
|
25026
|
-
if (shapeType
|
|
25027
|
-
const result = getVectorShape({ params, graphicData });
|
|
25127
|
+
if (shapeType) {
|
|
25128
|
+
const result = getVectorShape({ params, node, graphicData, size, marginOffset, anchorData, wrap: wrap2, isAnchor });
|
|
25028
25129
|
if (result) return result;
|
|
25029
25130
|
}
|
|
25030
|
-
|
|
25031
|
-
|
|
25032
|
-
}
|
|
25033
|
-
return buildShapePlaceholder(node, size, padding, marginOffset, "textbox");
|
|
25131
|
+
const fallbackType = textBoxContent ? "textbox" : "drawing";
|
|
25132
|
+
return buildShapePlaceholder(node, size, padding, marginOffset, fallbackType);
|
|
25034
25133
|
};
|
|
25035
|
-
const handleShapeGroup = (params, node, graphicData, size, padding, marginOffset) => {
|
|
25134
|
+
const handleShapeGroup = (params, node, graphicData, size, padding, marginOffset, anchorData, wrap2) => {
|
|
25036
25135
|
const wgp = graphicData.elements.find((el) => el.name === "wpg:wgp");
|
|
25037
25136
|
if (!wgp) {
|
|
25038
25137
|
return buildShapePlaceholder(node, size, padding, marginOffset, "group");
|
|
@@ -25065,6 +25164,7 @@ const handleShapeGroup = (params, node, graphicData, size, padding, marginOffset
|
|
|
25065
25164
|
}
|
|
25066
25165
|
}
|
|
25067
25166
|
const childShapes = wgp.elements.filter((el) => el.name === "wps:wsp");
|
|
25167
|
+
const childPictures = wgp.elements.filter((el) => el.name === "pic:pic");
|
|
25068
25168
|
const shapes = childShapes.map((wsp) => {
|
|
25069
25169
|
const spPr = wsp.elements?.find((el) => el.name === "wps:spPr");
|
|
25070
25170
|
if (!spPr) return null;
|
|
@@ -25103,6 +25203,14 @@ const handleShapeGroup = (params, node, graphicData, size, padding, marginOffset
|
|
|
25103
25203
|
const cNvPr = wsp.elements?.find((el) => el.name === "wps:cNvPr");
|
|
25104
25204
|
const shapeId = cNvPr?.attributes?.["id"];
|
|
25105
25205
|
const shapeName = cNvPr?.attributes?.["name"];
|
|
25206
|
+
const textBox = wsp.elements?.find((el) => el.name === "wps:txbx");
|
|
25207
|
+
const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
|
|
25208
|
+
const bodyPr = wsp.elements?.find((el) => el.name === "wps:bodyPr");
|
|
25209
|
+
let textContent = null;
|
|
25210
|
+
if (textBoxContent) {
|
|
25211
|
+
textContent = extractTextFromTextBox(textBoxContent, bodyPr);
|
|
25212
|
+
}
|
|
25213
|
+
const textAlign = textContent?.horizontalAlign || "left";
|
|
25106
25214
|
return {
|
|
25107
25215
|
shapeType: "vectorShape",
|
|
25108
25216
|
attrs: {
|
|
@@ -25118,10 +25226,75 @@ const handleShapeGroup = (params, node, graphicData, size, padding, marginOffset
|
|
|
25118
25226
|
strokeColor,
|
|
25119
25227
|
strokeWidth,
|
|
25120
25228
|
shapeId,
|
|
25121
|
-
shapeName
|
|
25229
|
+
shapeName,
|
|
25230
|
+
textContent,
|
|
25231
|
+
textAlign,
|
|
25232
|
+
textVerticalAlign: textContent?.verticalAlign,
|
|
25233
|
+
textInsets: textContent?.insets
|
|
25234
|
+
}
|
|
25235
|
+
};
|
|
25236
|
+
}).filter(Boolean);
|
|
25237
|
+
const pictures = childPictures.map((pic) => {
|
|
25238
|
+
const spPr = pic.elements?.find((el) => el.name === "pic:spPr");
|
|
25239
|
+
if (!spPr) return null;
|
|
25240
|
+
const xfrm2 = spPr.elements?.find((el) => el.name === "a:xfrm");
|
|
25241
|
+
const off = xfrm2?.elements?.find((el) => el.name === "a:off");
|
|
25242
|
+
const ext = xfrm2?.elements?.find((el) => el.name === "a:ext");
|
|
25243
|
+
const rawX = off?.attributes?.["x"] ? parseFloat(off.attributes["x"]) : 0;
|
|
25244
|
+
const rawY = off?.attributes?.["y"] ? parseFloat(off.attributes["y"]) : 0;
|
|
25245
|
+
const rawWidth = ext?.attributes?.["cx"] ? parseFloat(ext.attributes["cx"]) : 914400;
|
|
25246
|
+
const rawHeight = ext?.attributes?.["cy"] ? parseFloat(ext.attributes["cy"]) : 914400;
|
|
25247
|
+
let x2, y2, width, height;
|
|
25248
|
+
if (groupTransform.childWidth && groupTransform.childHeight) {
|
|
25249
|
+
const scaleX = groupTransform.width / groupTransform.childWidth;
|
|
25250
|
+
const scaleY = groupTransform.height / groupTransform.childHeight;
|
|
25251
|
+
const childOriginX = groupTransform.childOriginXEmu || 0;
|
|
25252
|
+
const childOriginY = groupTransform.childOriginYEmu || 0;
|
|
25253
|
+
x2 = groupTransform.x + emuToPixels((rawX - childOriginX) * scaleX);
|
|
25254
|
+
y2 = groupTransform.y + emuToPixels((rawY - childOriginY) * scaleY);
|
|
25255
|
+
width = emuToPixels(rawWidth * scaleX);
|
|
25256
|
+
height = emuToPixels(rawHeight * scaleY);
|
|
25257
|
+
} else {
|
|
25258
|
+
x2 = emuToPixels(rawX);
|
|
25259
|
+
y2 = emuToPixels(rawY);
|
|
25260
|
+
width = emuToPixels(rawWidth);
|
|
25261
|
+
height = emuToPixels(rawHeight);
|
|
25262
|
+
}
|
|
25263
|
+
const blipFill = pic.elements?.find((el) => el.name === "pic:blipFill");
|
|
25264
|
+
const blip = blipFill?.elements?.find((el) => el.name === "a:blip");
|
|
25265
|
+
if (!blip) return null;
|
|
25266
|
+
const rEmbed = blip.attributes?.["r:embed"];
|
|
25267
|
+
if (!rEmbed) return null;
|
|
25268
|
+
const currentFile = params.filename || "document.xml";
|
|
25269
|
+
let rels = params.docx[`word/_rels/${currentFile}.rels`];
|
|
25270
|
+
if (!rels) rels = params.docx[`word/_rels/document.xml.rels`];
|
|
25271
|
+
const relationships = rels?.elements.find((el) => el.name === "Relationships");
|
|
25272
|
+
const { elements } = relationships || [];
|
|
25273
|
+
const rel = elements?.find((el) => el.attributes["Id"] === rEmbed);
|
|
25274
|
+
if (!rel) return null;
|
|
25275
|
+
const targetPath = rel.attributes?.["Target"];
|
|
25276
|
+
let path = `word/${targetPath}`;
|
|
25277
|
+
if (targetPath.startsWith("/word") || targetPath.startsWith("/media")) {
|
|
25278
|
+
path = targetPath.substring(1);
|
|
25279
|
+
}
|
|
25280
|
+
const nvPicPr = pic.elements?.find((el) => el.name === "pic:nvPicPr");
|
|
25281
|
+
const cNvPr = nvPicPr?.elements?.find((el) => el.name === "pic:cNvPr");
|
|
25282
|
+
const picId = cNvPr?.attributes?.["id"];
|
|
25283
|
+
const picName = cNvPr?.attributes?.["name"];
|
|
25284
|
+
return {
|
|
25285
|
+
shapeType: "image",
|
|
25286
|
+
attrs: {
|
|
25287
|
+
x: x2,
|
|
25288
|
+
y: y2,
|
|
25289
|
+
width,
|
|
25290
|
+
height,
|
|
25291
|
+
src: path,
|
|
25292
|
+
imageId: picId,
|
|
25293
|
+
imageName: picName
|
|
25122
25294
|
}
|
|
25123
25295
|
};
|
|
25124
25296
|
}).filter(Boolean);
|
|
25297
|
+
const allShapes = [...pictures, ...shapes];
|
|
25125
25298
|
const schemaAttrs = {};
|
|
25126
25299
|
const drawingNode = params.nodes?.[0];
|
|
25127
25300
|
if (drawingNode?.name === DRAWING_XML_TAG) {
|
|
@@ -25132,38 +25305,137 @@ const handleShapeGroup = (params, node, graphicData, size, padding, marginOffset
|
|
|
25132
25305
|
attrs: {
|
|
25133
25306
|
...schemaAttrs,
|
|
25134
25307
|
groupTransform,
|
|
25135
|
-
shapes,
|
|
25308
|
+
shapes: allShapes,
|
|
25136
25309
|
size,
|
|
25137
25310
|
padding,
|
|
25138
|
-
marginOffset
|
|
25311
|
+
marginOffset,
|
|
25312
|
+
anchorData,
|
|
25313
|
+
wrap: wrap2,
|
|
25314
|
+
originalAttributes: node?.attributes
|
|
25139
25315
|
}
|
|
25140
25316
|
};
|
|
25141
25317
|
return result;
|
|
25142
25318
|
};
|
|
25143
|
-
|
|
25319
|
+
function extractTextFromTextBox(textBoxContent, bodyPr) {
|
|
25320
|
+
if (!textBoxContent || !textBoxContent.elements) return null;
|
|
25321
|
+
const paragraphs = textBoxContent.elements.filter((el) => el.name === "w:p");
|
|
25322
|
+
const textParts = [];
|
|
25323
|
+
let horizontalAlign = null;
|
|
25324
|
+
paragraphs.forEach((paragraph, paragraphIndex) => {
|
|
25325
|
+
if (!horizontalAlign) {
|
|
25326
|
+
const pPr = paragraph.elements?.find((el) => el.name === "w:pPr");
|
|
25327
|
+
const jc = pPr?.elements?.find((el) => el.name === "w:jc");
|
|
25328
|
+
if (jc) {
|
|
25329
|
+
const jcVal = jc.attributes?.["val"] || jc.attributes?.["w:val"];
|
|
25330
|
+
if (jcVal === "left" || jcVal === "start") horizontalAlign = "left";
|
|
25331
|
+
else if (jcVal === "right" || jcVal === "end") horizontalAlign = "right";
|
|
25332
|
+
else if (jcVal === "center") horizontalAlign = "center";
|
|
25333
|
+
}
|
|
25334
|
+
}
|
|
25335
|
+
const runs = paragraph.elements?.filter((el) => el.name === "w:r") || [];
|
|
25336
|
+
let paragraphHasText = false;
|
|
25337
|
+
runs.forEach((run2) => {
|
|
25338
|
+
const textEl = run2.elements?.find((el) => el.name === "w:t");
|
|
25339
|
+
if (textEl && textEl.elements) {
|
|
25340
|
+
const text = textEl.elements.find((el) => el.type === "text");
|
|
25341
|
+
if (text) {
|
|
25342
|
+
paragraphHasText = true;
|
|
25343
|
+
const cleanedText = typeof text.text === "string" ? text.text.replace(/\[\[sdspace\]\]/g, " ") : text.text;
|
|
25344
|
+
const rPr = run2.elements?.find((el) => el.name === "w:rPr");
|
|
25345
|
+
const formatting = {};
|
|
25346
|
+
if (rPr) {
|
|
25347
|
+
const bold = rPr.elements?.find((el) => el.name === "w:b");
|
|
25348
|
+
const italic = rPr.elements?.find((el) => el.name === "w:i");
|
|
25349
|
+
const color = rPr.elements?.find((el) => el.name === "w:color");
|
|
25350
|
+
const sz = rPr.elements?.find((el) => el.name === "w:sz");
|
|
25351
|
+
if (bold) formatting.bold = true;
|
|
25352
|
+
if (italic) formatting.italic = true;
|
|
25353
|
+
if (color) formatting.color = color.attributes?.["val"] || color.attributes?.["w:val"];
|
|
25354
|
+
if (sz) {
|
|
25355
|
+
const szVal = sz.attributes?.["val"] || sz.attributes?.["w:val"];
|
|
25356
|
+
formatting.fontSize = parseInt(szVal, 10) / 2;
|
|
25357
|
+
}
|
|
25358
|
+
}
|
|
25359
|
+
textParts.push({
|
|
25360
|
+
text: cleanedText,
|
|
25361
|
+
formatting
|
|
25362
|
+
});
|
|
25363
|
+
}
|
|
25364
|
+
}
|
|
25365
|
+
});
|
|
25366
|
+
if (paragraphIndex < paragraphs.length - 1) {
|
|
25367
|
+
textParts.push({
|
|
25368
|
+
text: "\n",
|
|
25369
|
+
formatting: {},
|
|
25370
|
+
isLineBreak: true,
|
|
25371
|
+
isEmptyParagraph: !paragraphHasText
|
|
25372
|
+
// Mark empty paragraphs for extra spacing
|
|
25373
|
+
});
|
|
25374
|
+
}
|
|
25375
|
+
});
|
|
25376
|
+
if (textParts.length === 0) return null;
|
|
25377
|
+
const bodyPrAttrs = bodyPr?.attributes || {};
|
|
25378
|
+
let verticalAlign = "center";
|
|
25379
|
+
const anchorAttr = bodyPrAttrs["anchor"];
|
|
25380
|
+
if (anchorAttr === "t") verticalAlign = "top";
|
|
25381
|
+
else if (anchorAttr === "ctr") verticalAlign = "center";
|
|
25382
|
+
else if (anchorAttr === "b") verticalAlign = "bottom";
|
|
25383
|
+
const EMU_TO_PX = 96 / 914400;
|
|
25384
|
+
const DEFAULT_HORIZONTAL_INSET_EMU = 91440;
|
|
25385
|
+
const DEFAULT_VERTICAL_INSET_EMU = 45720;
|
|
25386
|
+
const lIns = bodyPrAttrs["lIns"] != null ? parseFloat(bodyPrAttrs["lIns"]) : DEFAULT_HORIZONTAL_INSET_EMU;
|
|
25387
|
+
const tIns = bodyPrAttrs["tIns"] != null ? parseFloat(bodyPrAttrs["tIns"]) : DEFAULT_VERTICAL_INSET_EMU;
|
|
25388
|
+
const rIns = bodyPrAttrs["rIns"] != null ? parseFloat(bodyPrAttrs["rIns"]) : DEFAULT_HORIZONTAL_INSET_EMU;
|
|
25389
|
+
const bIns = bodyPrAttrs["bIns"] != null ? parseFloat(bodyPrAttrs["bIns"]) : DEFAULT_VERTICAL_INSET_EMU;
|
|
25390
|
+
const insets = {
|
|
25391
|
+
top: tIns * EMU_TO_PX,
|
|
25392
|
+
right: rIns * EMU_TO_PX,
|
|
25393
|
+
bottom: bIns * EMU_TO_PX,
|
|
25394
|
+
left: lIns * EMU_TO_PX
|
|
25395
|
+
};
|
|
25396
|
+
const wrap2 = bodyPrAttrs["wrap"] || "square";
|
|
25397
|
+
return {
|
|
25398
|
+
parts: textParts,
|
|
25399
|
+
horizontalAlign: horizontalAlign || "left",
|
|
25400
|
+
// Default to left if not specified
|
|
25401
|
+
verticalAlign,
|
|
25402
|
+
insets,
|
|
25403
|
+
wrap: wrap2
|
|
25404
|
+
};
|
|
25405
|
+
}
|
|
25406
|
+
const getRectangleShape = (params, spPr, node, marginOffset, anchorData, wrap2, isAnchor) => {
|
|
25144
25407
|
const schemaAttrs = {};
|
|
25145
|
-
const
|
|
25408
|
+
const drawingNode = params.nodes?.[0];
|
|
25146
25409
|
if (drawingNode?.name === DRAWING_XML_TAG) {
|
|
25147
25410
|
schemaAttrs.drawingContent = drawingNode;
|
|
25148
25411
|
}
|
|
25149
|
-
const xfrm =
|
|
25150
|
-
const start = xfrm
|
|
25151
|
-
const size = xfrm
|
|
25152
|
-
const solidFill =
|
|
25153
|
-
|
|
25154
|
-
|
|
25155
|
-
|
|
25156
|
-
|
|
25157
|
-
|
|
25158
|
-
|
|
25159
|
-
|
|
25412
|
+
const xfrm = spPr?.elements?.find((el) => el.name === "a:xfrm");
|
|
25413
|
+
const start = xfrm?.elements?.find((el) => el.name === "a:off");
|
|
25414
|
+
const size = xfrm?.elements?.find((el) => el.name === "a:ext");
|
|
25415
|
+
const solidFill = spPr?.elements?.find((el) => el.name === "a:solidFill");
|
|
25416
|
+
if (start && size) {
|
|
25417
|
+
const rectangleSize = {
|
|
25418
|
+
top: emuToPixels(start.attributes?.["y"] || 0),
|
|
25419
|
+
left: emuToPixels(start.attributes?.["x"] || 0),
|
|
25420
|
+
width: emuToPixels(size.attributes?.["cx"] || 0),
|
|
25421
|
+
height: emuToPixels(size.attributes?.["cy"] || 0)
|
|
25422
|
+
};
|
|
25423
|
+
schemaAttrs.size = rectangleSize;
|
|
25424
|
+
}
|
|
25160
25425
|
const background = solidFill?.elements[0]?.attributes["val"];
|
|
25161
25426
|
if (background) {
|
|
25162
25427
|
schemaAttrs.background = "#" + background;
|
|
25163
25428
|
}
|
|
25164
25429
|
return {
|
|
25165
25430
|
type: "contentBlock",
|
|
25166
|
-
attrs:
|
|
25431
|
+
attrs: {
|
|
25432
|
+
...schemaAttrs,
|
|
25433
|
+
marginOffset,
|
|
25434
|
+
anchorData,
|
|
25435
|
+
wrap: wrap2,
|
|
25436
|
+
isAnchor,
|
|
25437
|
+
originalAttributes: node?.attributes
|
|
25438
|
+
}
|
|
25167
25439
|
};
|
|
25168
25440
|
};
|
|
25169
25441
|
const buildShapePlaceholder = (node, size, padding, marginOffset, shapeType) => {
|
|
@@ -25212,7 +25484,7 @@ const buildShapePlaceholder = (node, size, padding, marginOffset, shapeType) =>
|
|
|
25212
25484
|
attrs
|
|
25213
25485
|
};
|
|
25214
25486
|
};
|
|
25215
|
-
function getVectorShape({ params, graphicData }) {
|
|
25487
|
+
function getVectorShape({ params, node, graphicData, size, marginOffset, anchorData, wrap: wrap2, isAnchor }) {
|
|
25216
25488
|
const schemaAttrs = {};
|
|
25217
25489
|
const drawingNode = params.nodes?.[0];
|
|
25218
25490
|
if (drawingNode?.name === "w:drawing") {
|
|
@@ -25232,10 +25504,9 @@ function getVectorShape({ params, graphicData }) {
|
|
|
25232
25504
|
console.warn("Shape kind not found");
|
|
25233
25505
|
}
|
|
25234
25506
|
schemaAttrs.kind = shapeKind;
|
|
25507
|
+
const width = size?.width ?? DEFAULT_SHAPE_WIDTH;
|
|
25508
|
+
const height = size?.height ?? DEFAULT_SHAPE_HEIGHT;
|
|
25235
25509
|
const xfrm = spPr.elements?.find((el) => el.name === "a:xfrm");
|
|
25236
|
-
const extent = xfrm?.elements?.find((el) => el.name === "a:ext");
|
|
25237
|
-
const width = extent?.attributes?.["cx"] ? emuToPixels(extent.attributes["cx"]) : 100;
|
|
25238
|
-
const height = extent?.attributes?.["cy"] ? emuToPixels(extent.attributes["cy"]) : 100;
|
|
25239
25510
|
const rotation = xfrm?.attributes?.["rot"] ? rotToDegrees(xfrm.attributes["rot"]) : 0;
|
|
25240
25511
|
const flipH = xfrm?.attributes?.["flipH"] === "1";
|
|
25241
25512
|
const flipV = xfrm?.attributes?.["flipV"] === "1";
|
|
@@ -25243,6 +25514,15 @@ function getVectorShape({ params, graphicData }) {
|
|
|
25243
25514
|
const fillColor = extractFillColor(spPr, style);
|
|
25244
25515
|
const strokeColor = extractStrokeColor(spPr, style);
|
|
25245
25516
|
const strokeWidth = extractStrokeWidth(spPr);
|
|
25517
|
+
const textBox = wsp.elements?.find((el) => el.name === "wps:txbx");
|
|
25518
|
+
const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
|
|
25519
|
+
const bodyPr = wsp.elements?.find((el) => el.name === "wps:bodyPr");
|
|
25520
|
+
let textContent = null;
|
|
25521
|
+
let textAlign = "left";
|
|
25522
|
+
if (textBoxContent) {
|
|
25523
|
+
textContent = extractTextFromTextBox(textBoxContent, bodyPr);
|
|
25524
|
+
textAlign = textContent?.horizontalAlign || "left";
|
|
25525
|
+
}
|
|
25246
25526
|
return {
|
|
25247
25527
|
type: "vectorShape",
|
|
25248
25528
|
attrs: {
|
|
@@ -25254,7 +25534,16 @@ function getVectorShape({ params, graphicData }) {
|
|
|
25254
25534
|
flipV,
|
|
25255
25535
|
fillColor,
|
|
25256
25536
|
strokeColor,
|
|
25257
|
-
strokeWidth
|
|
25537
|
+
strokeWidth,
|
|
25538
|
+
marginOffset,
|
|
25539
|
+
anchorData,
|
|
25540
|
+
wrap: wrap2,
|
|
25541
|
+
isAnchor,
|
|
25542
|
+
textContent,
|
|
25543
|
+
textAlign,
|
|
25544
|
+
textVerticalAlign: textContent?.verticalAlign,
|
|
25545
|
+
textInsets: textContent?.insets,
|
|
25546
|
+
originalAttributes: node?.attributes
|
|
25258
25547
|
}
|
|
25259
25548
|
};
|
|
25260
25549
|
}
|
|
@@ -31148,16 +31437,24 @@ function translateFieldAnnotation(params) {
|
|
|
31148
31437
|
hash: attrs.hash
|
|
31149
31438
|
};
|
|
31150
31439
|
const annotationAttrsJson = JSON.stringify(annotationAttrs);
|
|
31440
|
+
const sdtPrElements = [
|
|
31441
|
+
{ name: "w:alias", attributes: { "w:val": attrs.displayLabel } },
|
|
31442
|
+
{ name: "w:tag", attributes: { "w:val": annotationAttrsJson } },
|
|
31443
|
+
{ name: "w:id", attributes: { "w:val": id } }
|
|
31444
|
+
];
|
|
31445
|
+
if (attrs.sdtPr?.elements && Array.isArray(attrs.sdtPr.elements)) {
|
|
31446
|
+
const elementsToExclude = ["w:alias", "w:tag", "w:id"];
|
|
31447
|
+
const passthroughElements = attrs.sdtPr.elements.filter(
|
|
31448
|
+
(el) => el && el.name && !elementsToExclude.includes(el.name)
|
|
31449
|
+
);
|
|
31450
|
+
sdtPrElements.push(...passthroughElements);
|
|
31451
|
+
}
|
|
31151
31452
|
const result = {
|
|
31152
31453
|
name: "w:sdt",
|
|
31153
31454
|
elements: [
|
|
31154
31455
|
{
|
|
31155
31456
|
name: "w:sdtPr",
|
|
31156
|
-
elements:
|
|
31157
|
-
{ name: "w:alias", attributes: { "w:val": attrs.displayLabel } },
|
|
31158
|
-
{ name: "w:tag", attributes: { "w:val": annotationAttrsJson } },
|
|
31159
|
-
{ name: "w:id", attributes: { "w:val": id } }
|
|
31160
|
-
]
|
|
31457
|
+
elements: sdtPrElements
|
|
31161
31458
|
},
|
|
31162
31459
|
{
|
|
31163
31460
|
name: "w:sdtContent",
|
|
@@ -31389,7 +31686,7 @@ function translateDocumentSection(params) {
|
|
|
31389
31686
|
type: "documentSection",
|
|
31390
31687
|
description: attrs.description
|
|
31391
31688
|
});
|
|
31392
|
-
const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag);
|
|
31689
|
+
const sdtPr = generateSdtPrTagForDocumentSection(attrs.id, attrs.title, exportedTag, attrs.sdtPr);
|
|
31393
31690
|
const { isLocked } = attrs;
|
|
31394
31691
|
if (isLocked) {
|
|
31395
31692
|
sdtPr.elements.push({
|
|
@@ -31406,73 +31703,115 @@ function translateDocumentSection(params) {
|
|
|
31406
31703
|
};
|
|
31407
31704
|
return result;
|
|
31408
31705
|
}
|
|
31409
|
-
const generateSdtPrTagForDocumentSection = (id, title, tag) => {
|
|
31706
|
+
const generateSdtPrTagForDocumentSection = (id, title, tag, sdtPr) => {
|
|
31707
|
+
const coreElements = [
|
|
31708
|
+
{
|
|
31709
|
+
name: "w:id",
|
|
31710
|
+
attributes: {
|
|
31711
|
+
"w:val": id
|
|
31712
|
+
}
|
|
31713
|
+
},
|
|
31714
|
+
{
|
|
31715
|
+
name: "w:alias",
|
|
31716
|
+
attributes: {
|
|
31717
|
+
"w:val": title
|
|
31718
|
+
}
|
|
31719
|
+
},
|
|
31720
|
+
{
|
|
31721
|
+
name: "w:tag",
|
|
31722
|
+
attributes: {
|
|
31723
|
+
"w:val": tag
|
|
31724
|
+
}
|
|
31725
|
+
}
|
|
31726
|
+
];
|
|
31727
|
+
if (sdtPr?.elements && Array.isArray(sdtPr.elements)) {
|
|
31728
|
+
const elementsToExclude = ["w:id", "w:alias", "w:tag", "w:lock"];
|
|
31729
|
+
const passthroughElements = sdtPr.elements.filter((el) => el && el.name && !elementsToExclude.includes(el.name));
|
|
31730
|
+
coreElements.push(...passthroughElements);
|
|
31731
|
+
}
|
|
31410
31732
|
return {
|
|
31411
31733
|
name: "w:sdtPr",
|
|
31412
|
-
elements:
|
|
31413
|
-
{
|
|
31414
|
-
name: "w:id",
|
|
31415
|
-
attributes: {
|
|
31416
|
-
"w:val": id
|
|
31417
|
-
}
|
|
31418
|
-
},
|
|
31419
|
-
{
|
|
31420
|
-
name: "w:alias",
|
|
31421
|
-
attributes: {
|
|
31422
|
-
"w:val": title
|
|
31423
|
-
}
|
|
31424
|
-
},
|
|
31425
|
-
{
|
|
31426
|
-
name: "w:tag",
|
|
31427
|
-
attributes: {
|
|
31428
|
-
"w:val": tag
|
|
31429
|
-
}
|
|
31430
|
-
}
|
|
31431
|
-
]
|
|
31734
|
+
elements: coreElements
|
|
31432
31735
|
};
|
|
31433
31736
|
};
|
|
31434
31737
|
function translateDocumentPartObj(params) {
|
|
31435
31738
|
const { node } = params;
|
|
31436
31739
|
const { attrs = {} } = node;
|
|
31437
31740
|
const childContent = translateChildNodes({ ...params, nodes: node.content });
|
|
31741
|
+
const sdtPr = generateSdtPrForDocPartObj(attrs);
|
|
31438
31742
|
const nodeElements = [
|
|
31743
|
+
sdtPr,
|
|
31439
31744
|
{
|
|
31745
|
+
name: "w:sdtContent",
|
|
31746
|
+
elements: childContent
|
|
31747
|
+
}
|
|
31748
|
+
];
|
|
31749
|
+
const result = {
|
|
31750
|
+
name: "w:sdt",
|
|
31751
|
+
elements: nodeElements
|
|
31752
|
+
};
|
|
31753
|
+
return result;
|
|
31754
|
+
}
|
|
31755
|
+
function generateSdtPrForDocPartObj(attrs) {
|
|
31756
|
+
const existingDocPartObj = attrs.sdtPr?.elements?.find((el) => el.name === "w:docPartObj");
|
|
31757
|
+
const existingDocPartGallery = existingDocPartObj?.elements?.find((el) => el.name === "w:docPartGallery")?.attributes?.["w:val"];
|
|
31758
|
+
const docPartGallery = attrs.docPartGallery ?? existingDocPartGallery ?? null;
|
|
31759
|
+
const id = attrs.id ?? attrs.sdtPr?.elements?.find((el) => el.name === "w:id")?.attributes?.["w:val"] ?? "";
|
|
31760
|
+
const docPartUnique = attrs.docPartUnique ?? existingDocPartObj?.elements?.some((el) => el.name === "w:docPartUnique") ?? false;
|
|
31761
|
+
if (docPartGallery === null) {
|
|
31762
|
+
if (attrs.sdtPr) {
|
|
31763
|
+
return attrs.sdtPr;
|
|
31764
|
+
}
|
|
31765
|
+
return {
|
|
31440
31766
|
name: "w:sdtPr",
|
|
31441
31767
|
elements: [
|
|
31442
31768
|
{
|
|
31443
31769
|
name: "w:id",
|
|
31444
31770
|
attributes: {
|
|
31445
|
-
"w:val":
|
|
31771
|
+
"w:val": id
|
|
31446
31772
|
}
|
|
31447
31773
|
},
|
|
31448
31774
|
{
|
|
31449
31775
|
name: "w:docPartObj",
|
|
31450
|
-
elements: [
|
|
31451
|
-
{
|
|
31452
|
-
name: "w:docPartGallery",
|
|
31453
|
-
attributes: {
|
|
31454
|
-
"w:val": attrs.docPartGallery
|
|
31455
|
-
}
|
|
31456
|
-
},
|
|
31457
|
-
...attrs.docPartUnique ? [
|
|
31458
|
-
{
|
|
31459
|
-
name: "w:docPartUnique"
|
|
31460
|
-
}
|
|
31461
|
-
] : []
|
|
31462
|
-
]
|
|
31776
|
+
elements: []
|
|
31463
31777
|
}
|
|
31464
31778
|
]
|
|
31779
|
+
};
|
|
31780
|
+
}
|
|
31781
|
+
const docPartObjElements = [
|
|
31782
|
+
{
|
|
31783
|
+
name: "w:docPartGallery",
|
|
31784
|
+
attributes: {
|
|
31785
|
+
"w:val": docPartGallery
|
|
31786
|
+
}
|
|
31787
|
+
}
|
|
31788
|
+
];
|
|
31789
|
+
if (docPartUnique) {
|
|
31790
|
+
docPartObjElements.push({ name: "w:docPartUnique" });
|
|
31791
|
+
}
|
|
31792
|
+
const sdtPrElements = [
|
|
31793
|
+
{
|
|
31794
|
+
name: "w:id",
|
|
31795
|
+
attributes: {
|
|
31796
|
+
"w:val": id
|
|
31797
|
+
}
|
|
31465
31798
|
},
|
|
31466
31799
|
{
|
|
31467
|
-
name: "w:
|
|
31468
|
-
elements:
|
|
31800
|
+
name: "w:docPartObj",
|
|
31801
|
+
elements: docPartObjElements
|
|
31469
31802
|
}
|
|
31470
31803
|
];
|
|
31471
|
-
|
|
31472
|
-
|
|
31473
|
-
elements
|
|
31804
|
+
if (attrs.sdtPr?.elements && Array.isArray(attrs.sdtPr.elements)) {
|
|
31805
|
+
const elementsToExclude = ["w:id", "w:docPartObj"];
|
|
31806
|
+
const passthroughElements = attrs.sdtPr.elements.filter(
|
|
31807
|
+
(el) => el && el.name && !elementsToExclude.includes(el.name)
|
|
31808
|
+
);
|
|
31809
|
+
sdtPrElements.push(...passthroughElements);
|
|
31810
|
+
}
|
|
31811
|
+
return {
|
|
31812
|
+
name: "w:sdtPr",
|
|
31813
|
+
elements: sdtPrElements
|
|
31474
31814
|
};
|
|
31475
|
-
return result;
|
|
31476
31815
|
}
|
|
31477
31816
|
const RUN_LEVEL_WRAPPERS = /* @__PURE__ */ new Set(["w:hyperlink", "w:ins", "w:del"]);
|
|
31478
31817
|
function convertSdtContentToRuns(elements) {
|
|
@@ -34303,6 +34642,79 @@ const _processCombinedNodesForFldChar = (nodesToCombine = [], instrText, docx) =
|
|
|
34303
34642
|
return nodesToCombine;
|
|
34304
34643
|
}
|
|
34305
34644
|
};
|
|
34645
|
+
const preProcessPageFieldsOnly = (nodes = []) => {
|
|
34646
|
+
const processedNodes = [];
|
|
34647
|
+
let i = 0;
|
|
34648
|
+
while (i < nodes.length) {
|
|
34649
|
+
const node = nodes[i];
|
|
34650
|
+
const fldCharEl = node.elements?.find((el) => el.name === "w:fldChar");
|
|
34651
|
+
const fldType = fldCharEl?.attributes?.["w:fldCharType"];
|
|
34652
|
+
if (fldType === "begin") {
|
|
34653
|
+
const fieldInfo = scanFieldSequence(nodes, i);
|
|
34654
|
+
if (fieldInfo && (fieldInfo.fieldType === "PAGE" || fieldInfo.fieldType === "NUMPAGES")) {
|
|
34655
|
+
const preprocessor = fieldInfo.fieldType === "PAGE" ? preProcessPageInstruction : preProcessNumPagesInstruction;
|
|
34656
|
+
const contentNodes = fieldInfo.contentNodes;
|
|
34657
|
+
const processedField = preprocessor(contentNodes, fieldInfo.instrText);
|
|
34658
|
+
processedNodes.push(...processedField);
|
|
34659
|
+
i = fieldInfo.endIndex + 1;
|
|
34660
|
+
continue;
|
|
34661
|
+
} else {
|
|
34662
|
+
if (fieldInfo) {
|
|
34663
|
+
for (let j2 = i; j2 <= fieldInfo.endIndex; j2++) {
|
|
34664
|
+
const passNode = nodes[j2];
|
|
34665
|
+
if (Array.isArray(passNode.elements)) {
|
|
34666
|
+
const childResult = preProcessPageFieldsOnly(passNode.elements);
|
|
34667
|
+
passNode.elements = childResult.processedNodes;
|
|
34668
|
+
}
|
|
34669
|
+
processedNodes.push(passNode);
|
|
34670
|
+
}
|
|
34671
|
+
i = fieldInfo.endIndex + 1;
|
|
34672
|
+
continue;
|
|
34673
|
+
}
|
|
34674
|
+
}
|
|
34675
|
+
}
|
|
34676
|
+
if (Array.isArray(node.elements)) {
|
|
34677
|
+
const childResult = preProcessPageFieldsOnly(node.elements);
|
|
34678
|
+
node.elements = childResult.processedNodes;
|
|
34679
|
+
}
|
|
34680
|
+
processedNodes.push(node);
|
|
34681
|
+
i++;
|
|
34682
|
+
}
|
|
34683
|
+
return { processedNodes };
|
|
34684
|
+
};
|
|
34685
|
+
function scanFieldSequence(nodes, beginIndex) {
|
|
34686
|
+
let instrText = "";
|
|
34687
|
+
let separateIndex = -1;
|
|
34688
|
+
let endIndex = -1;
|
|
34689
|
+
const contentNodes = [];
|
|
34690
|
+
for (let i = beginIndex + 1; i < nodes.length; i++) {
|
|
34691
|
+
const node = nodes[i];
|
|
34692
|
+
const fldCharEl = node.elements?.find((el) => el.name === "w:fldChar");
|
|
34693
|
+
const fldType = fldCharEl?.attributes?.["w:fldCharType"];
|
|
34694
|
+
const instrTextEl = node.elements?.find((el) => el.name === "w:instrText");
|
|
34695
|
+
if (instrTextEl) {
|
|
34696
|
+
instrText += (instrTextEl.elements?.[0]?.text || "") + " ";
|
|
34697
|
+
}
|
|
34698
|
+
if (fldType === "separate") {
|
|
34699
|
+
separateIndex = i;
|
|
34700
|
+
} else if (fldType === "end") {
|
|
34701
|
+
endIndex = i;
|
|
34702
|
+
break;
|
|
34703
|
+
} else if (separateIndex !== -1 && fldType !== "begin") {
|
|
34704
|
+
contentNodes.push(node);
|
|
34705
|
+
}
|
|
34706
|
+
}
|
|
34707
|
+
if (endIndex === -1) {
|
|
34708
|
+
return null;
|
|
34709
|
+
}
|
|
34710
|
+
const fieldType = instrText.trim().split(" ")[0];
|
|
34711
|
+
return {
|
|
34712
|
+
fieldType,
|
|
34713
|
+
instrText: instrText.trim(),
|
|
34714
|
+
contentNodes,
|
|
34715
|
+
endIndex
|
|
34716
|
+
};
|
|
34717
|
+
}
|
|
34306
34718
|
const createDocumentJson = (docx, converter, editor) => {
|
|
34307
34719
|
const json = carbonCopy(getInitialJSON(docx));
|
|
34308
34720
|
if (!json) return null;
|
|
@@ -34699,6 +35111,8 @@ const importHeadersFooters = (docx, converter, mainEditor) => {
|
|
|
34699
35111
|
editor.options.annotations = true;
|
|
34700
35112
|
headers.forEach((header) => {
|
|
34701
35113
|
const { rId, referenceFile, currentFileName } = getHeaderFooterSectionData(header, docx);
|
|
35114
|
+
const { processedNodes: headerProcessedNodes } = preProcessPageFieldsOnly(referenceFile.elements[0].elements ?? []);
|
|
35115
|
+
referenceFile.elements[0].elements = headerProcessedNodes;
|
|
34702
35116
|
const sectPrHeader = allSectPrElements.find(
|
|
34703
35117
|
(el) => el.name === "w:headerReference" && el.attributes["r:id"] === rId
|
|
34704
35118
|
);
|
|
@@ -34727,6 +35141,8 @@ const importHeadersFooters = (docx, converter, mainEditor) => {
|
|
|
34727
35141
|
if (titlePg) converter.headerIds.titlePg = true;
|
|
34728
35142
|
footers.forEach((footer) => {
|
|
34729
35143
|
const { rId, referenceFile, currentFileName } = getHeaderFooterSectionData(footer, docx);
|
|
35144
|
+
const { processedNodes: footerProcessedNodes } = preProcessPageFieldsOnly(referenceFile.elements[0].elements ?? []);
|
|
35145
|
+
referenceFile.elements[0].elements = footerProcessedNodes;
|
|
34730
35146
|
const sectPrFooter = allSectPrElements.find(
|
|
34731
35147
|
(el) => el.name === "w:footerReference" && el.attributes["r:id"] === rId
|
|
34732
35148
|
);
|
|
@@ -35869,7 +36285,7 @@ const _SuperConverter = class _SuperConverter {
|
|
|
35869
36285
|
static getStoredSuperdocVersion(docx) {
|
|
35870
36286
|
return _SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
|
|
35871
36287
|
}
|
|
35872
|
-
static setStoredSuperdocVersion(docx = this.convertedXml, version = "1.0.0-beta.
|
|
36288
|
+
static setStoredSuperdocVersion(docx = this.convertedXml, version = "1.0.0-beta.14") {
|
|
35873
36289
|
return _SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version, false);
|
|
35874
36290
|
}
|
|
35875
36291
|
/**
|