@reviseio/engine 3.0.0 → 3.1.0
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/CHANGELOG.md +33 -0
- package/assets/{historyMaterializeWorker-Kl0syEbc.js → historyMaterializeWorker-BMHTnStL.js} +131 -130
- package/chunks/{AgentHtmlConverter-BnK7NaYA.js → AgentHtmlConverter-B5qstcmM.js} +129 -128
- package/chunks/{AgentPageRenderer-DLwq6nAa.js → AgentPageRenderer-JMhCw-hi.js} +4 -4
- package/chunks/BlockDiff-C8eiZ-sf.js +45 -0
- package/chunks/{CanvasRenderer-Bqsj1S0p.js → CanvasRenderer-C2vAzLWM.js} +12 -12
- package/chunks/DocumentCompare-DX4RWeSV.js +10 -0
- package/chunks/{DocumentLayoutEngine-7iOYvyVb.js → DocumentLayoutEngine-BhcWXkeu.js} +45 -45
- package/chunks/{DocumentMutator-DIrZBuLr.js → DocumentMutator-FEFU1YM0.js} +6 -6
- package/chunks/DocumentOutline-BOZoTohH.js +4 -0
- package/chunks/{DocumentScrubber-Cz8Q05hF.js → DocumentScrubber-C4N3Qagm.js} +1 -1
- package/chunks/{DocumentSession-lXSXqua5.js → DocumentSession-gZHWP7By.js} +1 -1
- package/chunks/{DocxConverter-BfDw7777.js → DocxConverter-BOyLn5eZ.js} +709 -703
- package/chunks/{DocxGraft-D0uCnGCo.js → DocxGraft-BbE-AaM5.js} +2 -2
- package/chunks/{HtmlConverter-7Xj_g9Jr.js → HtmlConverter-BlzwsPEn.js} +3 -3
- package/chunks/MarkdownConverter-BHVskVXI.js +59 -0
- package/chunks/{OdtConverter-GwRDMnwS.js → OdtConverter-BdmBFOD1.js} +1 -1
- package/chunks/{OfficeImportShared-nlMtIUni.js → OfficeImportShared-B2XJgnDO.js} +4 -4
- package/chunks/{PdfConverter-yOlWiVIj.js → PdfConverter-DZMCHDAo.js} +6 -6
- package/chunks/{RtfConverter--wLd0qrw.js → RtfConverter-RqE-xZcW.js} +66 -66
- package/chunks/{TableBorders-C5pNsuxP.js → TableBorders-ARyTi49V.js} +1 -1
- package/chunks/TextDecoding-IPbuUqcC.js +2 -0
- package/chunks/TextFileDecoder-BZBBejlR.js +10 -0
- package/chunks/{TxtConverter-BoRVCDZw.js → TxtConverter-EPQtb6A6.js} +1 -1
- package/chunks/{Typography-DAGM5kfI.js → Typography-XR6scRNV.js} +9 -9
- package/chunks/XmlConverter-9sFRFaza.js +55 -0
- package/chunks/{capture-Dtinb4bY.js → capture-DhGn0CWA.js} +1 -1
- package/chunks/{carrier-RNy67HN4.js → carrier-D58g-gw4.js} +1 -1
- package/chunks/{chromeImageLayout-bgHYmqTp.js → chromeImageLayout-DeYYS8YP.js} +1 -1
- package/chunks/{engine-TnK8N-gT.js → engine-C5fxuZJo.js} +140 -140
- package/chunks/{footnoteFlatten-BcKaWzVs.js → footnoteFlatten-coCVFd3c.js} +1 -1
- package/chunks/{graftExport-DxAALMHp.js → graftExport-FBGE2qvt.js} +1 -1
- package/chunks/{index-CTti7wRd.js → index-Cezk1s_y.js} +4 -4
- package/chunks/{serverDocumentSession-BmYdjC6e.js → serverDocumentSession-LMu3kocH.js} +559 -560
- package/chunks/{signatures-CU2LMLBp.js → signatures-DsJnnIqV.js} +1 -1
- package/chunks/textExtraction-Bqaqt1Kg.js +2 -0
- package/engine.js +2 -2
- package/package.json +2 -2
- package/chunks/BlockDiff-BdlcKY-t.js +0 -42
- package/chunks/DocumentCompare-BqyiP87r.js +0 -6
- package/chunks/MarkdownConverter-cnW_oePY.js +0 -57
- package/chunks/TextFileDecoder--rsVs3NR.js +0 -9
- package/chunks/XmlConverter-CO8Z28dX.js +0 -55
|
@@ -1,128 +1,131 @@
|
|
|
1
|
-
import{b8 as
|
|
2
|
-
N as
|
|
3
|
-
import{b as
|
|
4
|
-
b as Qe}from"./TableGrid-DbroRucl.js";import{R as Ct}from"./suggestionAuthorship-B-IuLQlE.js";import{b as
|
|
5
|
-
F as Ae,L as
|
|
6
|
-
|
|
7
|
-
bCs","w:iCs","w:szCs","w:highlightCs","w:ins","w:del","w:rtl","w:specVanish","w:imprint","w:emboss","w:snapToGrid"]),
|
|
8
|
-
"w:ind","w:pageBreakBefore","w:spacing","w:contextualSpacing","w:outlineLvl","w:numPr","w:pBdr","w:shd","w:tabs","w:rPr","w:sectPr","w:pPrChange"]),
|
|
9
|
-
"w:tblBorders","w:tblLayout","w:tblCellMar","w:tblPrChange"]),
|
|
10
|
-
vAlign","w:cellIns","w:cellDel","w:cellMerge","w:tcPrChange"]),
|
|
11
|
-
ce","w:sectPrChange","w:rPr"]);function at(
|
|
12
|
-
r):void 0}function sr(
|
|
13
|
-
const r=Object.keys(e).sort();if(r.length===0)return;const t={};for(const i of r)t[i]=e[i];return JSON.stringify(t)}function ar(
|
|
14
|
-
length;i++){const n=
|
|
15
|
-
`?e+=" ":n==="\r"?e+=" ":n===" "?e+="	":e+=n;continue}r&&(n==='"'||n==="'")?t=n:n==="<"?r=!0:n===">"&&(r=!1),e+=n}return e}function lr(
|
|
16
|
-
getElementsByTagName("o:OLEObject")[0];if(t)r=t.getAttribute("ProgID")??void 0;else if(
|
|
17
|
-
getAttribute("uri")?.split("/").filter(Boolean).pop();i&&i!=="picture"&&(r=i)}return{xml:e,tagName:
|
|
18
|
-
iceDocument/2006/relationships")}const
|
|
19
|
-
moveFromRangeEnd","w:moveToRangeStart","w:moveToRangeEnd","w:permStart","w:permEnd","w:ins","w:del","w:moveFrom","w:moveTo","w:proofErr","w:tcPr","w:trPr","w:tblPr","w:tblGrid","w:tblPrEx","w:pPr"]),
|
|
20
|
-
function
|
|
21
|
-
has(i))continue;const a=n.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");t+=` ${i}="${a}"`}return t}const
|
|
22
|
-
KNOWN_RPR_TAGS:
|
|
23
|
-
stabilizeSerializedXml:ar,xmlReferencesRelationships:cr},Symbol.toStringTag,{value:"Module"})),
|
|
24
|
-
"∑∏∐∫∬∭∮∯∰∱∲∳⋀⋁⋂⋃⨀⨁⨂⨄⨆".split("")),
|
|
25
|
-
"det","dim","ker","deg","gcd","hom","arg","max","min","sup","inf","lim","liminf","limsup","Pr"]),
|
|
1
|
+
import{b8 as Ci,b9 as Ni,a8 as Er,ab as Ai,a7 as Ti,r as Ee,b1 as Mi,av as Ei,aE as Di,ba as Bi,aN as Ft,X as Ri,aX as Oi,e as tr,v as Dr,bb as Fi,bc as Li,bd as $i,be as _i,b0 as Wi,aR as Xi,O as zi,
|
|
2
|
+
N as ji,aW as rr,bf as Br,W as Rr,ae as Hi,bg as Gi,ar as Or,ad as Ji,bh as Ui,at as Ki,a9 as Fr}from"./engine-C5fxuZJo.js";import{c as Zi,h as Vi,m as ir}from"./capture-DhGn0CWA.js";import{g as qi,a as Yi,
|
|
3
|
+
G as Qi}from"./graftExport-FBGE2qvt.js";import{b as Lt,l as en,g as tn,d as rn,h as nn,t as on}from"./BidiText-Bkp4Y90s.js";import{k as sn,s as Lr,j as an,p as ln,W as $r,l as cn,c as nr,b as dn,e as pn}from"./TableBorders-ARyTi49V.js";
|
|
4
|
+
import{b as Qe}from"./TableGrid-DbroRucl.js";import{R as Ct}from"./suggestionAuthorship-B-IuLQlE.js";import{b as hn,c as _r}from"./MathRenderer-Bz9WEVvF.js";import{J as Wr}from"./jszip.min-CPW0h1Kx.js";
|
|
5
|
+
import{F as Ae,L as gn,h as or,g as mn}from"./Typography-XR6scRNV.js";import{c as un}from"./chromeImageLayout-DeYYS8YP.js";import{a as fn}from"./DocumentStylesheet-CEEt18sr.js";const Xr=()=>new XMLSerializer,
|
|
6
|
+
zr=new Set(["w:rStyle","w:b","w:i","w:u","w:strike","w:dstrike","w:smallCaps","w:caps","w:vanish","w:lang","w:spacing","w:vertAlign","w:color","w:highlight","w:shd","w:rFonts","w:sz","w:rPrChange","w:\
|
|
7
|
+
bCs","w:iCs","w:szCs","w:highlightCs","w:ins","w:del","w:rtl","w:specVanish","w:imprint","w:emboss","w:snapToGrid"]),jr=new Set(["w:pStyle","w:keepNext","w:keepLines","w:widowControl","w:bidi","w:jc",
|
|
8
|
+
"w:ind","w:pageBreakBefore","w:spacing","w:contextualSpacing","w:outlineLvl","w:numPr","w:pBdr","w:shd","w:tabs","w:rPr","w:sectPr","w:pPrChange"]),Hr=new Set(["w:tblStyle","w:tblW","w:jc","w:tblInd",
|
|
9
|
+
"w:tblBorders","w:tblLayout","w:tblCellMar","w:tblPrChange"]),Gr=new Set(["w:tblHeader","w:ins","w:del","w:trPrChange"]),Jr=new Set(["w:tcW","w:gridSpan","w:vMerge","w:tcBorders","w:shd","w:tcMar","w:\
|
|
10
|
+
vAlign","w:cellIns","w:cellDel","w:cellMerge","w:tcPrChange"]),Ur=new Set(["w:pgSz","w:pgMar","w:pgNumType","w:lnNumType","w:cols","w:type","w:docGrid","w:titlePg","w:headerReference","w:footerReferen\
|
|
11
|
+
ce","w:sectPrChange","w:rPr"]);function at(F,e){if(!F)return;let r="";const t=Xr();for(let i=0;i<F.children.length;i++){const n=F.children[i];e.has(n.tagName)||(r+=t.serializeToString(n))}return r?ar(
|
|
12
|
+
r):void 0}function sr(F){if(!F||F.attributes.length===0)return;const e={};for(let i=0;i<F.attributes.length;i++){const n=F.attributes[i];n.name==="xmlns"||n.name.startsWith("xmlns:")||(e[n.name]=n.value)}
|
|
13
|
+
const r=Object.keys(e).sort();if(r.length===0)return;const t={};for(const i of r)t[i]=e[i];return JSON.stringify(t)}function ar(F){if(!/[\n\r\t]/.test(F))return F;let e="",r=!1,t=null;for(let i=0;i<F.
|
|
14
|
+
length;i++){const n=F[i];if(t){n===t?(t=null,e+=n):n===`
|
|
15
|
+
`?e+=" ":n==="\r"?e+=" ":n===" "?e+="	":e+=n;continue}r&&(n==='"'||n==="'")?t=n:n==="<"?r=!0:n===">"&&(r=!1),e+=n}return e}function lr(F){const e=ar(Xr().serializeToString(F));let r;const t=F.
|
|
16
|
+
getElementsByTagName("o:OLEObject")[0];if(t)r=t.getAttribute("ProgID")??void 0;else if(F.tagName==="w:altChunk")r=F.getAttribute("r:id")??void 0;else{const i=F.getElementsByTagName("a:graphicData")[0]?.
|
|
17
|
+
getAttribute("uri")?.split("/").filter(Boolean).pop();i&&i!=="picture"&&(r=i)}return{xml:e,tagName:F.tagName,...r?{detail:r}:{}}}function cr(F){return F.includes("http://schemas.openxmlformats.org/off\
|
|
18
|
+
iceDocument/2006/relationships")}const Kr=new Set(["w:p","w:tbl","w:sdt","w:customXml","w:sectPr","w:bookmarkStart","w:bookmarkEnd","w:commentRangeStart","w:commentRangeEnd","w:moveFromRangeStart","w:\
|
|
19
|
+
moveFromRangeEnd","w:moveToRangeStart","w:moveToRangeEnd","w:permStart","w:permEnd","w:ins","w:del","w:moveFrom","w:moveTo","w:proofErr","w:tcPr","w:trPr","w:tblPr","w:tblGrid","w:tblPrEx","w:pPr"]),wn=/^[A-Za-z_][\w.-]*(?::[\w.-]+)?$/;
|
|
20
|
+
function Zr(F,e){let r;try{r=JSON.parse(F)}catch{return""}if(r===null||typeof r!="object"||Array.isArray(r))return"";let t="";for(const[i,n]of Object.entries(r)){if(typeof n!="string"||!wn.test(i)||e?.
|
|
21
|
+
has(i))continue;const a=n.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");t+=` ${i}="${a}"`}return t}const bn=Object.freeze(Object.defineProperty({__proto__:null,KNOWN_BODY_TAGS:Kr,KNOWN_PPR_TAGS:jr,
|
|
22
|
+
KNOWN_RPR_TAGS:zr,KNOWN_SECTPR_TAGS:Ur,KNOWN_TBLPR_TAGS:Hr,KNOWN_TCPR_TAGS:Jr,KNOWN_TRPR_TAGS:Gr,attrsJsonToXmlAttributes:Zr,captureRawElement:lr,extractElementAttrsJson:sr,extractOpaqueChildrenXml:at,
|
|
23
|
+
stabilizeSerializedXml:ar,xmlReferencesRelationships:cr},Symbol.toStringTag,{value:"Module"})),yn="http://schemas.openxmlformats.org/officeDocument/2006/math",Vr=`<m:oMath xmlns:m="${yn}">`,vn=new Set(
|
|
24
|
+
"∑∏∐∫∬∭∮∯∰∱∲∳⋀⋁⋂⋃⨀⨁⨂⨄⨆".split("")),xn=new Set(["sin","cos","tan","cot","sec","csc","arcsin","arccos","arctan","sinh","cosh","tanh","coth","log","ln","lg","exp",
|
|
25
|
+
"det","dim","ker","deg","gcd","hom","arg","max","min","sup","inf","lim","liminf","limsup","Pr"]),Sn=new Set(["lim","liminf","limsup","max","min","sup","inf","Pr"]),qr={"^":"̂","ˆ":"̂","̂":"̂","~":"\
|
|
26
26
|
̃","˜":"̃","̃":"̃","ˉ":"̄","¯":"̄","̄":"̄","˙":"̇","̇":"̇","¨":"̈","̈":"̈","ˊ":"́","´":"́","́":"́","ˋ":"̀","`":"̀","̀":"̀","ˇ":"̌","̌":"̌","˘":"̆","̆":"̆","→":"\
|
|
27
|
-
⃗","⃗":"⃗"},
|
|
27
|
+
⃗","⃗":"⃗"},In=new Set(["‾","¯","_","―","−"]),kn=new Set(["⏞","⏟","⏜","⏝","⎴","⎵"]),Pn=new Set(["","","",""]),dr={normal:'<m:sty m:val="p"/>',bold:'<m:sty m:val="b\
|
|
28
28
|
"/>',italic:'<m:sty m:val="i"/>',"bold-italic":'<m:sty m:val="bi"/>',"double-struck":'<m:scr m:val="double-struck"/><m:sty m:val="p"/>',script:'<m:scr m:val="script"/>',"bold-script":'<m:scr m:val="sc\
|
|
29
29
|
ript"/><m:sty m:val="b"/>',fraktur:'<m:scr m:val="fraktur"/>',"bold-fraktur":'<m:scr m:val="fraktur"/><m:sty m:val="b"/>',"sans-serif":'<m:scr m:val="sans-serif"/><m:sty m:val="p"/>',monospace:'<m:scr\
|
|
30
|
-
m:val="monospace"/><m:sty m:val="p"/>'};function
|
|
31
|
-
from(
|
|
32
|
-
xe(e))&&We(e).filter(r
|
|
33
|
-
if(xe(e)!=="mo")return null;const r=$e(e).trim();return
|
|
34
|
-
r:null}const
|
|
35
|
-
|
|
36
|
-
l:space="preserve"':"";return`<m:r>${e?`<m:rPr>${e}</m:rPr>`:""}<m:t${t}>${
|
|
37
|
-
getAttribute("mathvariant")??e.mathvariant;return i&&dr[i]?
|
|
38
|
-
return`<m:nary><m:naryPr>${`<m:chr m:val="${lt(
|
|
39
|
-
le("e",i)+"</m:nary>"}function
|
|
40
|
-
|
|
30
|
+
m:val="monospace"/><m:sty m:val="p"/>'};function Yr(F){return F.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function lt(F){return Yr(F)}function We(F){return Array.
|
|
31
|
+
from(F.children)}function $e(F){return(F.textContent??"").replace(/[-]/g,"")}function xe(F){return F.localName.toLowerCase()}function pr(F){let e=F;for(;["mrow","mstyle","mpadded","semantics"].includes(
|
|
32
|
+
xe(e))&&We(e).filter(r=>!$t(r)).length===1;)e=We(e).filter(r=>!$t(r))[0];return e}function $t(F){return xe(F)==="mo"&&Pn.has((F.textContent??"").trim())}function _t(F){if(!F)return null;const e=pr(F);
|
|
33
|
+
if(xe(e)!=="mo")return null;const r=$e(e).trim();return vn.has(r)?r:null}function Wt(F){if(!F)return null;const e=pr(F);if(!["mi","mo"].includes(xe(e)))return null;const r=$e(e).trim();return xn.has(r)?
|
|
34
|
+
r:null}const Cn=new Set("+-−=<>≤≥≠≈≡∼≃≅∝,;:∣∈∉⊂⊆⊃⊇→←↔⇒⇐⇔".split(""));function Nn(F){return xe(F)==="mo"&&Cn.has($e(F).trim())}function Qr(F,e){let r=e;for(;r<
|
|
35
|
+
F.length&&!Nn(F[r]);)r+=1;return r}function ei(F){return!!F&&xe(F)==="mo"&&F.getAttribute("fence")==="true"}function Je(F,e){if(!F)return"";const r=/^\s+$/.test(F)?`${F}`:F,t=/^\s|\s$/.test(r)?' xm\
|
|
36
|
+
l:space="preserve"':"";return`<m:r>${e?`<m:rPr>${e}</m:rPr>`:""}<m:t${t}>${Yr(r)}</m:t></m:r>`}function An(F,e){const r=xe(F),t=$e(F);if(!t)return"";if(r==="mtext"||r==="ms")return Je(t,"<m:nor/>");const i=F.
|
|
37
|
+
getAttribute("mathvariant")??e.mathvariant;return i&&dr[i]?Je(t,dr[i]):r==="mi"&&[...t].length>1?Je(t,'<m:sty m:val="p"/>'):Je(t,"")}function le(F,e){return`<m:${F}>${e}</m:${F}>`}function ti(F,e,r,t,i){
|
|
38
|
+
return`<m:nary><m:naryPr>${`<m:chr m:val="${lt(F)}"/><m:limLoc m:val="${e}"/>`+(r===null?'<m:subHide m:val="1"/>':"")+(t===null?'<m:supHide m:val="1"/>':"")}</m:naryPr>`+le("sub",r??"")+le("sup",t??"")+
|
|
39
|
+
le("e",i)+"</m:nary>"}function ri(F,e){return`<m:func>${le("fName",F)}${le("e",e)}</m:func>`}function ii(F){return parseFloat(F.getAttribute("width")??"")>0?" ":""}function Tn(F){return xe(F)==="mrow"&&
|
|
40
|
+
F.children.length===0&&!$e(F).trim()}function Ue(F,e){const r=F.filter(i=>!$t(i)&&!Tn(i));if(r.length>=2&&ei(r[0])){const i=r[r.length-1],n=ei(i),a=r.slice(1,n?-1:void 0),o=$e(r[0]).trim(),s=n?$e(i).trim():
|
|
41
41
|
"";return`<m:d><m:dPr><m:begChr m:val="${lt(o)}"/><m:endChr m:val="${lt(s)}"/></m:dPr>`+le("e",Ue(a,e))+"</m:d>"}let t="";for(let i=0;i<r.length;i+=1){const n=r[i],a=xe(n),o=r[i+1];if(["msub","msup","\
|
|
42
|
-
msubsup","munder","mover","munderover"].includes(a)&&_t(We(n)[0])){const[c,p,h]=We(n),
|
|
43
|
-
u=a==="msubsup"||a==="munderover"?pe(h,e):a==="msup"||a==="mover"?pe(p,e):null,
|
|
44
|
-
null,null,Ue(r.slice(i+1,c),e)),i=c-1;continue}const s=["msub","munder"].includes(a)?Wt(We(n)[0]):null;if(s&&
|
|
45
|
-
lim",pe(p,e))}</m:limLow>`;t+=
|
|
46
|
-
e"].includes(xe(r[p]));)c+=xe(r[p])==="mtext"?$e(r[p]):
|
|
47
|
-
let c=$e(n);for(;r[i+1]&&xe(r[i+1])==="mi"&&r[i+1].getAttribute("mathvariant")===l;)i+=1,c+=$e(r[i]);t+=
|
|
48
|
-
|
|
49
|
-
annotation-xml":case"mphantom":case"none":case"mprescripts":return"";case"mi":case"mn":case"mo":case"mtext":case"ms":return
|
|
50
|
-
mfrac":{const i=
|
|
42
|
+
msubsup","munder","mover","munderover"].includes(a)&&_t(We(n)[0])){const[c,p,h]=We(n),g=_t(c),f=a.startsWith("mu")?"undOvr":"subSup",w=["msub","msubsup","munder","munderover"].includes(a)?pe(p,e):null,
|
|
43
|
+
u=a==="msubsup"||a==="munderover"?pe(h,e):a==="msup"||a==="mover"?pe(p,e):null,m=Qr(r,i+1);t+=ti(g,f,w,u,Ue(r.slice(i+1,m),e)),i=m-1;continue}if(a==="mo"&&_t(n)){const c=Qr(r,i+1);t+=ti(_t(n),"undOvr",
|
|
44
|
+
null,null,Ue(r.slice(i+1,c),e)),i=c-1;continue}const s=["msub","munder"].includes(a)?Wt(We(n)[0]):null;if(s&&Sn.has(s)&&o){const[c,p]=We(n),h=`<m:limLow>${le("e",Je(Wt(c),'<m:sty m:val="p"/>'))}${le("\
|
|
45
|
+
lim",pe(p,e))}</m:limLow>`;t+=ri(h,pe(o,e)),i+=1;continue}if(Wt(n)&&o){t+=ri(Je(Wt(n),'<m:sty m:val="p"/>'),pe(o,e)),i+=1;continue}if(a==="mtext"||a==="mspace"){let c="",p=i;for(;r[p]&&["mtext","mspac\
|
|
46
|
+
e"].includes(xe(r[p]));)c+=xe(r[p])==="mtext"?$e(r[p]):ii(r[p]),p+=1;i=p-1;const h=c.replace(/\s{2,}/g," ");h&&(t+=Je(h,"<m:nor/>"));continue}const l=a==="mi"?n.getAttribute("mathvariant"):null;if(l){
|
|
47
|
+
let c=$e(n);for(;r[i+1]&&xe(r[i+1])==="mi"&&r[i+1].getAttribute("mathvariant")===l;)i+=1,c+=$e(r[i]);t+=Je(c,dr[l]??"");continue}t+=pe(n,e)}return t}function pe(F,e){if(!F)return"";const r=xe(F),t=We(
|
|
48
|
+
F);switch(r){case"math":case"semantics":case"mrow":case"mpadded":case"merror":return Ue(t,e);case"mstyle":{const i=F.getAttribute("mathvariant");return Ue(t,i?{...e,mathvariant:i}:e)}case"annotation":case"\
|
|
49
|
+
annotation-xml":case"mphantom":case"none":case"mprescripts":return"";case"mi":case"mn":case"mo":case"mtext":case"ms":return $t(F)?"":An(F,e);case"mspace":{const i=ii(F);return i?Je(i,"<m:nor/>"):""}case"\
|
|
50
|
+
mfrac":{const i=F.getAttribute("linethickness");return`<m:f>${i!==null&&parseFloat(i)===0?'<m:fPr><m:type m:val="noBar"/></m:fPr>':""}`+le("num",pe(t[0],e))+le("den",pe(t[1],e))+"</m:f>"}case"msqrt":return'\
|
|
51
51
|
<m:rad><m:radPr><m:degHide m:val="1"/></m:radPr><m:deg/>'+le("e",Ue(t,e))+"</m:rad>";case"mroot":return"<m:rad>"+le("deg",pe(t[1],e))+le("e",pe(t[0],e))+"</m:rad>";case"msub":return`<m:sSub>${le("e",pe(
|
|
52
52
|
t[0],e))}${le("sub",pe(t[1],e))}</m:sSub>`;case"msup":return`<m:sSup>${le("e",pe(t[0],e))}${le("sup",pe(t[1],e))}</m:sSup>`;case"msubsup":return`<m:sSubSup>${le("e",pe(t[0],e))}`+le("sub",pe(t[1],e))+
|
|
53
|
-
le("sup",pe(t[2],e))+"</m:sSubSup>";case"mover":case"munder":return
|
|
53
|
+
le("sup",pe(t[2],e))+"</m:sSubSup>";case"mover":case"munder":return Mn(F,r==="mover"?"top":"bot",e);case"munderover":{const[i,n,a]=t,o=`<m:limLow>${le("e",pe(i,e))}${le("lim",pe(n,e))}</m:limLow>`;return`\
|
|
54
54
|
<m:limUpp>${le("e",o)}${le("lim",pe(a,e))}</m:limUpp>`}case"mtable":return"<m:m>"+t.filter(i=>["mtr","mlabeledtr"].includes(xe(i))).map(i=>"<m:mr>"+We(i).filter(n=>xe(n)==="mtd").map(n=>le("e",Ue(We(n),
|
|
55
|
-
e))).join("")+"</m:mr>").join("")+"</m:m>";case"menclose":{const i=Ue(t,e),n=
|
|
56
|
-
const i=
|
|
57
|
-
return Ue(t,e)}}function
|
|
58
|
-
ar>`;if(o&&kn.has(o))return`<m:groupChr><m:groupChrPr><m:chr m:val="${lt(o)}"/><m:pos m:val="${e}"/><m:vertJc m:val="${e==="top"?"bot":"top"}"/></m:groupChrPr>`+le("e",n)+"</m:groupChr>";const s=
|
|
59
|
-
e==="top"?"accent":"accentunder")==="true";if(e==="top"&&o&&(s||
|
|
60
|
-
Low";return`<m:${l}>${le("e",n)}${le("lim",pe(i,r))}</m:${l}>`}function
|
|
61
|
-
"mathmlToOmml: no <math> element in input");return`${
|
|
55
|
+
e))).join("")+"</m:mr>").join("")+"</m:m>";case"menclose":{const i=Ue(t,e),n=F.getAttribute("notation")??"";return/\bbox\b|roundedbox/.test(n)?`<m:borderBox>${le("e",i)}</m:borderBox>`:i}case"mfenced":{
|
|
56
|
+
const i=F.getAttribute("open")??"(",n=F.getAttribute("close")??")";return`<m:d><m:dPr><m:begChr m:val="${lt(i)}"/><m:endChr m:val="${lt(n)}"/></m:dPr>`+t.map(a=>le("e",pe(a,e))).join("")+"</m:d>"}default:
|
|
57
|
+
return Ue(t,e)}}function Mn(F,e,r){const[t,i]=We(F),n=pe(t,r),a=i?pr(i):void 0,o=a&&xe(a)==="mo"?$e(a).trim():"";if(o&&In.has(o))return`<m:bar><m:barPr><m:pos m:val="${e}"/></m:barPr>${le("e",n)}</m:b\
|
|
58
|
+
ar>`;if(o&&kn.has(o))return`<m:groupChr><m:groupChrPr><m:chr m:val="${lt(o)}"/><m:pos m:val="${e}"/><m:vertJc m:val="${e==="top"?"bot":"top"}"/></m:groupChrPr>`+le("e",n)+"</m:groupChr>";const s=F.getAttribute(
|
|
59
|
+
e==="top"?"accent":"accentunder")==="true";if(e==="top"&&o&&(s||qr[o])){const c=qr[o]??o;return`<m:acc><m:accPr><m:chr m:val="${lt(c)}"/></m:accPr>${le("e",n)}</m:acc>`}const l=e==="top"?"limUpp":"lim\
|
|
60
|
+
Low";return`<m:${l}>${le("e",n)}${le("lim",pe(i,r))}</m:${l}>`}function En(F){return new DOMParser().parseFromString(F,"text/html").querySelector("math")}function Dn(F){const e=En(F);if(!e)throw new Error(
|
|
61
|
+
"mathmlToOmml: no <math> element in input");return`${Vr}${pe(e,{})}</m:oMath>`}const ni="iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==",ue=class hr{static async parseFile(e,r){
|
|
62
62
|
if(!e.name.toLowerCase().endsWith(".docx"))throw new Error(`DocxConverter only supports .docx files, got: ${e.name}`);return this.parseDocxFile(e,r)}static async parseDocxFile(e,r){const t=await e.arrayBuffer(),
|
|
63
|
-
i=await
|
|
63
|
+
i=await Wr.loadAsync(t),n=await i.file("word/document.xml")?.async("string");if(!n)return{type:"doc",children:[this.createEmptyParagraph()]};const a=this.parseDocumentXml(n);if(!a)return{type:"doc",children:[
|
|
64
64
|
this.createEmptyParagraph()]};const o=await this.loadOOXMLPackageContext(i,n),s=await this.parseDocumentPageLayoutFromPackage(n,i,a),l=await i.file("word/fontTable.xml")?.async("string"),c=this.parseFontTableXml(
|
|
65
|
-
l),p=await i.file("word/settings.xml")?.async("string"),h=!!(p&&/<w:autoHyphenation(?![^>]*w:val="(?:0|false)")[^>]*\/?>/.test(p)),
|
|
66
|
-
n,s,o,a,
|
|
67
|
-
vise.BlockSpacingPx"))?.textContent?.trim(),
|
|
68
|
-
c&&(f.fontSubstitutes=c,
|
|
69
|
-
ote","docxfn","footnote",b,o),
|
|
70
|
-
if(v){const
|
|
71
|
-
ml")?.async("string");if(y){const
|
|
65
|
+
l),p=await i.file("word/settings.xml")?.async("string"),h=!!(p&&/<w:autoHyphenation(?![^>]*w:val="(?:0|false)")[^>]*\/?>/.test(p)),g=r?.retainSource?new Map:void 0,f=await this.parseStructuredDocxDocument(
|
|
66
|
+
n,s,o,a,g),w=await i.file("docProps/custom.xml")?.async("string");if(w){const T=this.parseDocumentXml(w),L=(T&&Array.from(T.getElementsByTagNameNS("*","property")).find(X=>X.getAttribute("name")==="Re\
|
|
67
|
+
vise.BlockSpacingPx"))?.textContent?.trim(),W=L?Number(L):NaN;Number.isFinite(W)&&W>=0&&W<=192&&(f.pageLayout={...f.pageLayout??{},blockSpacingPx:W})}h&&(f.pageLayout={...f.pageLayout??{},hyphenationEnabled:!0}),
|
|
68
|
+
c&&(f.fontSubstitutes=c,Ni(c));const u=await i.file("word/footnotes.xml")?.async("string"),m=await i.file("word/endnotes.xml")?.async("string"),b=new Map;u&&await this.collectNotesFromXml(f,u,"w:footn\
|
|
69
|
+
ote","docxfn","footnote",b,o),m&&await this.collectNotesFromXml(f,m,"w:endnote","docxen","endnote",b,o),this.finalizeImportedFootnoteRefs(f,b);const v=await i.file("word/comments.xml")?.async("string");
|
|
70
|
+
if(v){const T=await i.file("word/commentsExtended.xml")?.async("string");this.attachCommentsFromXml(f,v,T,o)}await this.attachHeadersFootersFromPackage(f,n,i,o,a);const y=await i.file("docProps/core.x\
|
|
71
|
+
ml")?.async("string");if(y){const T=this.parseCoreProperties(y);T&&(f.coreProperties=T)}return g&&Zi(f,g,await Vi(new Uint8Array(t))),f}static parseCoreProperties(e){const r=this.parseDocumentXml(e);if(!r)
|
|
72
72
|
return;const t=new Set(this.CORE_PROPERTY_LOCAL_NAMES),i={},n=r.documentElement;for(let a=0;a<n.children.length;a++){const o=n.children[a],s=o.tagName.split(":").pop()??o.tagName;if(!t.has(s))continue;
|
|
73
73
|
const l=o.textContent??"";l.trim().length!==0&&(i[s]=l)}return Object.keys(i).length>0?i:void 0}static readHeaderFooterReferences(e,r){const t={};for(let i=0;i<e.children.length;i++){const n=e.children[i];
|
|
74
74
|
if(n.tagName!==r)continue;const a=n.getAttribute("w:type")??"default",o=a==="first"||a==="even"?a:"default",s=n.getAttribute("r:id")??n.getAttribute("relationships:id");s&&(t[o]=s)}return t}static resolveSectionHeaderFooterReferences(e){
|
|
75
75
|
const r=[];for(let t=0;t<e.length;t++){const i=r[t-1]??{header:{},footer:{}};r.push({header:{...i.header,...this.readHeaderFooterReferences(e[t],"w:headerReference")},footer:{...i.footer,...this.readHeaderFooterReferences(
|
|
76
76
|
e[t],"w:footerReference")}})}return r}static async attachHeadersFootersFromPackage(e,r,t,i,n){const a=(n??this.parseDocumentXml(r))?.getElementsByTagName("w:body")[0];if(!a)return;const o=this.findAllSectionProperties(
|
|
77
|
-
a);if(o.length===0)return;const s=this.resolveSectionHeaderFooterReferences(o),l=o.length-1,c=s[l],p=new Map,h=async
|
|
78
|
-
get(
|
|
79
|
-
els`)?.async("string");if(
|
|
80
|
-
parseHeaderFooterImages(O,
|
|
81
|
-
|
|
82
|
-
(e.headers=
|
|
83
|
-
await
|
|
84
|
-
g").length!==0)for(const
|
|
85
|
-
void 0,
|
|
77
|
+
a);if(o.length===0)return;const s=this.resolveSectionHeaderFooterReferences(o),l=o.length-1,c=s[l],p=new Map,h=async L=>{const W=p.get(L);if(W)return W;const X={paragraphs:[],images:[]},D=i?.relationships.
|
|
78
|
+
get(L);if(D){const M=D.target.startsWith("word/")?D.target:`word/${D.target.replace(/^\//,"")}`,O=await t.file(M)?.async("string");if(O){const I=M.split("/").pop()??M,B=await t.file(`word/_rels/${I}.r\
|
|
79
|
+
els`)?.async("string");if(X.paragraphs=await this.parseHeaderFooterPart(O,B?this.parseRelationshipsXml(B,M):void 0),!e.watermark){const E=this.parseVmlWatermark(O);E&&(e.watermark=E)}X.images=await this.
|
|
80
|
+
parseHeaderFooterImages(O,M,t,i)}}return p.set(L,X),X},g=async L=>(await h(L)).paragraphs,f=["default","first","even"],w=[],u=async(L,W)=>{const X={};for(const D of f){const M=L[D];if(!M)continue;const O=await h(
|
|
81
|
+
M);O.paragraphs.length>0&&(X[D]=O.paragraphs);for(const I of O.images)w.push({side:W,slot:D,...I})}return Object.keys(X).length>0?X:void 0},m=await u(c.header,"header"),b=await u(c.footer,"footer");m&&
|
|
82
|
+
(e.headers=m),b&&(e.footers=b),w.length>0&&(e.chromeImages=w);const v=[];for(let L=0;L<l;L++)for(const W of["header","footer"])for(const X of f){const D=s[L][W][X],M=c[W][X];if(D===M)continue;const O=D?
|
|
83
|
+
await g(D):[];v.push(Er(W,X,O.length>0?Ai(O):void 0,void 0,L))}const y=[],T=new Set(v.map(L=>`${L.side}/${L.slot}/${L.sectionIndex}`));for(let L=0;L<o.length;L++)if(o[L].getElementsByTagName("w:titleP\
|
|
84
|
+
g").length!==0)for(const W of["header","footer"]){const X=s[L][W].first;if((X?await g(X):[]).length>0||!s[L][W].default)continue;const D=L===l?void 0:L;T.has(`${W}/first/${D}`)||y.push(Er(W,"first",void 0,
|
|
85
|
+
void 0,D))}(v.length>0||y.length>0)&&(e.chrome=[...Ti(e.headers,e.footers),...v,...y])}static parseVmlWatermark(e){if(!e.includes("v:textpath"))return;const r=this.parseDocumentXml(e);if(!r)return;const t=r.
|
|
86
86
|
getElementsByTagName("v:textpath");for(let i=0;i<t.length;i++){const n=t[i],a=(n.getAttribute("string")??"").trim();if(!a)continue;let o=n.parentNode;for(;o&&o.tagName!=="v:shape";)o=o.parentNode;const s=(o?.
|
|
87
87
|
getAttribute("style")??"").match(/rotation:\s*(-?\d+(?:\.\d+)?)/),l=s?(parseFloat(s[1])%360+360)%360:0,c=this.vmlFillColorToHex(o?.getAttribute("fillcolor")??"");let p;const h=o?.getElementsByTagName(
|
|
88
|
-
"v:fill")[0]?.getAttribute("opacity");if(h){const w=h.endsWith("f")?parseFloat(h)/65536:parseFloat(h);Number.isFinite(w)&&w>0&&w<=1&&(p=Math.abs(w-$r)<.05?void 0:w)}const
|
|
89
|
-
match(/font-size:\s*(\d+(?:\.\d+)?)pt/),f=
|
|
88
|
+
"v:fill")[0]?.getAttribute("opacity");if(h){const w=h.endsWith("f")?parseFloat(h)/65536:parseFloat(h);Number.isFinite(w)&&w>0&&w<=1&&(p=Math.abs(w-$r)<.05?void 0:w)}const g=(n.getAttribute("style")??"").
|
|
89
|
+
match(/font-size:\s*(\d+(?:\.\d+)?)pt/),f=g?parseFloat(g[1]):void 0;return sn({text:a,...c?{color:c}:{},...p!==void 0?{opacity:p}:{},diagonal:l!==0,...f&&f>2?{fontSizePx:Math.round(f*(4/3))}:{}})}}static vmlFillColorToHex(e){
|
|
90
90
|
const r=e.trim().toLowerCase();if(r){if(r.startsWith("#")){const t=r.slice(1,7);return/^[0-9a-f]{6}$/.test(t)?`#${t.toUpperCase()}`:void 0}return{silver:"#C0C0C0",gray:"#808080",grey:"#808080",black:"\
|
|
91
91
|
#000000",red:"#FF0000",blue:"#0000FF",green:"#008000",white:"#FFFFFF"}[r]}}static async parseHeaderFooterImages(e,r,t,i){if(!i||!e.includes("w:drawing"))return[];const n=this.parseDocumentXml(e);if(!n)
|
|
92
92
|
return[];const a=n.getElementsByTagName("w:drawing");if(a.length===0)return[];const o=r.split("/").pop()??r,s=await t.file(`word/_rels/${o}.rels`)?.async("string"),l={...i,relationships:this.parseRelationshipsXml(
|
|
93
|
-
s,r)},c=[];for(let p=0;p<a.length;p++){const h=await this.parseImageFromDrawing(a[p],void 0,l);if(h){const
|
|
94
|
-
{alt:h.alt}:{},...
|
|
93
|
+
s,r)},c=[];for(let p=0;p<a.length;p++){const h=await this.parseImageFromDrawing(a[p],void 0,l);if(h){const g=this.headerFooterImageAlign(a[p]);c.push({src:h.src,width:h.width,height:h.height,...h.alt?
|
|
94
|
+
{alt:h.alt}:{},...g?{align:g}:{}})}}return c}static headerFooterImageAlign(e){let r=e.parentElement;for(;r&&r.tagName!=="w:p";)r=r.parentElement;if(!r)return;const t=Array.from(r.children).find(n=>n.tagName===
|
|
95
95
|
"w:pPr"),i=(t?Array.from(t.children).find(n=>n.tagName==="w:jc"):void 0)?.getAttribute("w:val");if(i==="center")return"center";if(i==="right"||i==="end")return"right"}static async parseHeaderFooterPart(e,r){
|
|
96
96
|
const t=this.parseDocumentXml(e);if(!t)return[];const i=[],n=Array.from(t.getElementsByTagName("w:p")).filter(a=>{let o=a.parentElement;for(;o;){if(o.tagName==="w:txbxContent")return!1;o=o.parentElement}
|
|
97
|
-
return!0});for(let a=0;a<n.length;a++){const o=n[a],s=[];let l=null,c=!1;const p=
|
|
97
|
+
return!0});for(let a=0;a<n.length;a++){const o=n[a],s=[];let l=null,c=!1;const p=m=>{const b={},v=this.getDirectChild(m,"w:rPr");v&&(this.applyRunPropertiesFromElement(b,v),(this.getDirectChild(v,"w:r\
|
|
98
98
|
Style")?.getAttribute("w:val")||void 0)===this.CODE_INLINE_STYLE_ID&&(b.code=!0,/courier/i.test(b.fontFamily??"")&&delete b.fontFamily,/^(light)?gray$/i.test(b.backgroundColor??"")&&delete b.backgroundColor));
|
|
99
|
-
let y=
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
"w:
|
|
99
|
+
let y=m.parentElement;for(;y&&y!==o;){if(y.tagName==="w:ins"||y.tagName==="w:del"){const L=y.tagName==="w:ins",W=this.parseTrackedRevisionMeta(y);Object.assign(b,{...L?{insertion:!0}:{deletion:!0},suggestionId:W.
|
|
100
|
+
revisionId?`docxrev-${W.revisionId}`:this.generateId(),...this.revisionAuthorIdentity(W.author),suggestionLabel:L?"Insert":"Delete",...W.createdAt!==void 0?{suggestionCreatedAt:W.createdAt}:{},...W.author?
|
|
101
|
+
{suggestionAuthorName:W.author}:{}});break}y=y.parentElement}let T=m.parentElement;for(;T&&T!==o;){if(T.tagName==="w:hyperlink"){const L=T.getAttribute("r:id"),W=T.getAttribute("w:anchor"),X=L?r?.get(
|
|
102
|
+
L)?.target:void 0;X?b.link=X:W&&(b.link=`#${W}`);break}T=T.parentElement}return b},h=Array.from(o.getElementsByTagName("w:r")).filter(m=>{let b=m.parentElement;for(;b&&b!==o;){if(b.tagName==="w:p")return!1;
|
|
103
|
+
b=b.parentElement}return b===o});for(let m=0;m<h.length;m++){const b=h[m],v=p(b);for(let y=0;y<b.children.length;y++){const T=b.children[y];if(T.tagName==="w:t"||T.tagName==="w:delText"){if(c)continue;
|
|
104
|
+
const L=T.textContent??"";L&&s.push({type:"text",text:L,...Object.keys(v).length>0?{marks:v}:{}})}else if(T.tagName==="w:tab")s.push({type:"text",text:" "});else if(T.tagName==="w:br"&&!c&&(T.getAttribute(
|
|
105
|
+
"w:type")??"textWrapping")==="textWrapping")s.push({type:"text",text:`
|
|
106
|
+
`,...Object.keys(v).length>0?{marks:v}:{}});else if(T.tagName==="w:fldChar"){const L=T.getAttribute("w:fldCharType");L==="begin"&&(c=!0),L==="end"&&(l&&s.push({type:"text",text:"1",marks:{...v,field:l}}),
|
|
107
|
+
l=null,c=!1)}else if(T.tagName==="w:instrText"&&c){const L=(T.textContent??"").trim().toUpperCase();L.startsWith("PAGE")?l="page":L.startsWith("NUMPAGES")&&(l="numPages")}}}const g=o.getElementsByTagName(
|
|
108
|
+
"w:fldSimple");for(let m=0;m<g.length;m++){const b=(g[m].getAttribute("w:instr")??"").trim().toUpperCase();b.startsWith("PAGE")?s.push({type:"text",text:"1",marks:{field:"page"}}):b.startsWith("NUMPAG\
|
|
106
109
|
ES")&&s.push({type:"text",text:"1",marks:{field:"numPages"}})}const f=this.getDirectChild(this.getDirectChild(o,"w:pPr")??o,"w:jc")?.getAttribute("w:val"),w=f==="center"?"center":f==="right"||f==="end"?
|
|
107
|
-
"right":f==="both"?"justify":void 0;s.length>0&&i.push({type:"paragraph",id:this.generateId(),children:s,...w?{align:w}:{}});const u=await this.parseTextBoxContent(o,void 0);i.push(...u.filter(
|
|
110
|
+
"right":f==="both"?"justify":void 0;s.length>0&&i.push({type:"paragraph",id:this.generateId(),children:s,...w?{align:w}:{}});const u=await this.parseTextBoxContent(o,void 0);i.push(...u.filter(m=>m.type===
|
|
108
111
|
"paragraph"))}return i}static attachCommentsFromXml(e,r,t,i){const n=this.parseDocumentXml(r);if(!n)return;const a=new Set,o=u=>{if(!u||typeof u!="object")return;if(Array.isArray(u)){u.forEach(o);return}
|
|
109
|
-
const
|
|
110
|
-
`docxcmt-${
|
|
111
|
-
getAttribute("w15:done")==="1",parentParaId:b.getAttribute("w15:paraIdParent")??void 0})}}const c=[],p=new Map,h=new Map,
|
|
112
|
-
b=
|
|
113
|
-
O+=
|
|
114
|
-
"w:author")??"Unknown",...
|
|
112
|
+
const m=u;m.marks?.comment&&m.marks.comment.split(",").forEach(b=>a.add(b)),o(m.children)};o(e.children);const s=(i??this.fallbackCommentState).collapsedCommentAnchorBlockById;s?.forEach((u,m)=>a.add(
|
|
113
|
+
`docxcmt-${m}`));const l=new Map;if(t){const u=this.parseDocumentXml(t)?.getElementsByTagName("w15:commentEx")??[];for(let m=0;m<u.length;m++){const b=u[m],v=b.getAttribute("w15:paraId");v&&l.set(v,{done:b.
|
|
114
|
+
getAttribute("w15:done")==="1",parentParaId:b.getAttribute("w15:paraIdParent")??void 0})}}const c=[],p=new Map,h=new Map,g=n.getElementsByTagName("w:comment");for(let u=0;u<g.length;u++){const m=g[u],
|
|
115
|
+
b=m.getAttribute("w:id");if(!b)continue;const v=`docxcmt-${b}`,y=m.getElementsByTagName("w:p"),T=[];for(let D=0;D<y.length;D++){const M=y[D].getElementsByTagName("w:t");let O="";for(let B=0;B<M.length;B++)
|
|
116
|
+
O+=M[B].textContent??"";T.push(O);const I=y[D].getAttribute("w14:paraId");I&&(p.set(v,I),h.set(I,v))}const L=m.getAttribute("w:date"),W=L?Date.parse(L):NaN,X=s?.get(b);c.push({id:v,author:m.getAttribute(
|
|
117
|
+
"w:author")??"Unknown",...m.getAttribute("w:initials")?{initials:m.getAttribute("w:initials")}:{},createdAt:Number.isFinite(W)?new Date(W).toISOString():new Date(0).toISOString(),bodyMd:T.filter(D=>D.
|
|
115
118
|
length>0).join(`
|
|
116
119
|
|
|
117
|
-
`),importedId:parseInt(b,10),...
|
|
118
|
-
v)}}const f=u=>{let
|
|
119
|
-
const s=this.parseDocumentXml(r);if(!s)return;if(o){const p=t==="w:footnote"?"footnotes":"endnotes",h=await o.zip.file(`word/_rels/${p}.xml.rels`)?.async("string");if(h){const
|
|
120
|
-
h,`word/${p}.xml`);
|
|
121
|
-
getAttribute("w:type");if(
|
|
122
|
-
w),
|
|
120
|
+
`),importedId:parseInt(b,10),...X?{anchorBlockId:X}:{}})}for(const u of c){const m=p.get(u.id),b=m?l.get(m):void 0;if(b?.done&&(u.resolved=!0),b?.parentParaId){const v=h.get(b.parentParaId);v&&(u.parentId=
|
|
121
|
+
v)}}const f=u=>{let m=u;const b=new Map(c.map(v=>[v.id,v]));for(;m.parentId&&b.has(m.parentId);)m=b.get(m.parentId);return m.id},w=c.filter(u=>a.has(f(u)));w.length>0&&(e.comments=w)}static async collectNotesFromXml(e,r,t,i,n,a,o){
|
|
122
|
+
const s=this.parseDocumentXml(r);if(!s)return;if(o){const p=t==="w:footnote"?"footnotes":"endnotes",h=await o.zip.file(`word/_rels/${p}.xml.rels`)?.async("string");if(h){const g=this.parseRelationshipsXml(
|
|
123
|
+
h,`word/${p}.xml`);g.size>0&&(o={...o,relationships:new Map([...o.relationships,...g])})}}const l=Ee(e.pageLayout).indentStepPx,c=s.getElementsByTagName(t);for(let p=0;p<c.length;p++){const h=c[p],g=h.
|
|
124
|
+
getAttribute("w:type");if(g==="separator"||g==="continuationSeparator")continue;const f=h.getAttribute("w:id");if(!f)continue;const w=await this.parseBodyChildren(h,l,o),u=this.applyParagraphMarkRevisions(
|
|
125
|
+
w),m=u.length>0?u:[this.createEmptyParagraph()];Mi(m),a.set(`${i}-${f}`,{type:"footnote",id:`${i}-${f}`,...n==="endnote"?{noteKind:"endnote"}:{},children:m})}}static finalizeImportedFootnoteRefs(e,r){
|
|
123
126
|
const t=[],i={footnote:0,endnote:0},n=new Map,a=(o,s)=>{if(!o||typeof o!="object")return;if(Array.isArray(o)){o.forEach(p=>a(p));return}const l=o,c=l.marks?.footnoteRef;if(c&&(c.startsWith("docxfn-")||
|
|
124
127
|
c.startsWith("docxen-")))if(!r.has(c))l.text="",delete l.marks.footnoteRef,delete l.marks.superscript;else{if(!t.includes(c)){t.push(c);const p=c.startsWith("docxen-")?"endnote":"footnote";i[p]+=1,n.set(
|
|
125
|
-
c,
|
|
128
|
+
c,Hi(i[p],p))}l.text=n.get(c)??""}a(l.children)};a(e.children);for(const o of t){const s=r.get(o);s&&e.children.push(s)}}static documentHasMath(e){return e.includes("m:oMath")||e.includes("m:oMathPara")}static documentHasNativePageBreaks(e){
|
|
126
129
|
return e.includes('w:br w:type="page"')||e.includes("<w:lastRenderedPageBreak")||e.includes("<w:pageBreakBefore")}static documentHasComplexBodyContent(e){return e.includes("<w:tbl")||e.includes("<w:dr\
|
|
127
130
|
awing")||e.includes("<w:pict")||e.includes("<w:object")}static shouldUseStructuredDocxParser(e){return!!(this.documentHasMath(e)||this.documentHasNativePageBreaks(e)&&!this.documentHasComplexBodyContent(
|
|
128
131
|
e))}static resolveIndentStepPx(e){return Ee(e?.pageLayout).indentStepPx}static stripXmlBom(e){return e.charCodeAt(0)===65279?e.slice(1):e}static parseDocumentXml(e){const r=new DOMParser().parseFromString(
|
|
@@ -142,15 +145,15 @@ id:s,type:p,basedOn:c?.getAttribute("w:val")||void 0,name:l?.getAttribute("w:val
|
|
|
142
145
|
p&&this.isOnAttribute(o.getAttribute("w:default"))&&(r.defaultStyleIdByType.has(p)||r.defaultStyleIdByType.set(p,s))}return r}static parseFontTableXml(e){if(!e)return;const r=this.parseDocumentXml(e);
|
|
143
146
|
if(!r)return;const t={},i=r.getElementsByTagName("w:font");for(let n=0;n<i.length;n++){const a=i[n],o=(a.getAttribute("w:name")||"").trim();if(!o)continue;const s=(this.getDirectChild(a,"w:altName")?.
|
|
144
147
|
getAttribute("w:val")||"").trim(),l=(this.getDirectChild(a,"w:family")?.getAttribute("w:val")||"").trim().toLowerCase(),c=(this.getDirectChild(a,"w:pitch")?.getAttribute("w:val")||"").trim().toLowerCase(),
|
|
145
|
-
p=(this.getDirectChild(a,"w:panose1")?.getAttribute("w:val")||"").trim(),h={};s&&(h.alt=s);const
|
|
148
|
+
p=(this.getDirectChild(a,"w:panose1")?.getAttribute("w:val")||"").trim(),h={};s&&(h.alt=s);const g=this.genericFamilyFromFontMetrics(l,c,p);g&&(h.generic=g),(h.alt||h.generic)&&(t[o.toLowerCase()]=h)}
|
|
146
149
|
return Object.keys(t).length>0?t:void 0}static genericFamilyFromFontMetrics(e,r,t){if(r==="fixed"||e==="modern")return"monospace";if(/^[0-9a-fA-F]{20}$/.test(t)){const i=parseInt(t.slice(0,2),16),n=parseInt(
|
|
147
150
|
t.slice(2,4),16);if(i===2){if(n>=2&&n<=10)return"serif";if(n>=11&&n<=15)return"sans-serif"}}if(e==="roman")return"serif";if(e==="swiss")return"sans-serif"}static parseNumberingXml(e){const r={abstractNums:new Map,
|
|
148
151
|
nums:new Map};if(!e)return r;const t=this.parseDocumentXml(e);if(!t)return r;const i=t.getElementsByTagName("w:abstractNum");for(let a=0;a<i.length;a++){const o=i[a],s=o.getAttribute("w:abstractNumId");
|
|
149
|
-
if(!s)continue;const l=new Map,c=o.getElementsByTagName("w:lvl");for(let p=0;p<c.length;p++){const h=c[p],
|
|
150
|
-
getDirectChild(h,"w:numFmt"),u=this.getDirectChild(h,"w:lvlText"),
|
|
151
|
-
"w:val")||void 0,start:
|
|
152
|
-
s=o.getAttribute("w:numId");if(!s)continue;const l=this.getDirectChild(o,"w:abstractNumId"),c=new Map,p=o.getElementsByTagName("w:lvlOverride");for(let h=0;h<p.length;h++){const
|
|
153
|
-
"w:ilvl"),w=f?parseInt(f,10):NaN;if(!Number.isFinite(w))continue;const u=
|
|
152
|
+
if(!s)continue;const l=new Map,c=o.getElementsByTagName("w:lvl");for(let p=0;p<c.length;p++){const h=c[p],g=h.getAttribute("w:ilvl"),f=g?parseInt(g,10):NaN;if(!Number.isFinite(f))continue;const w=this.
|
|
153
|
+
getDirectChild(h,"w:numFmt"),u=this.getDirectChild(h,"w:lvlText"),m=this.getDirectChild(h,"w:start")?.getAttribute("w:val");l.set(f,{level:f,format:w?.getAttribute("w:val")||void 0,text:u?.getAttribute(
|
|
154
|
+
"w:val")||void 0,start:m&&Number.isFinite(parseInt(m,10))?parseInt(m,10):void 0})}r.abstractNums.set(s,{abstractNumId:s,levels:l})}const n=t.getElementsByTagName("w:num");for(let a=0;a<n.length;a++){const o=n[a],
|
|
155
|
+
s=o.getAttribute("w:numId");if(!s)continue;const l=this.getDirectChild(o,"w:abstractNumId"),c=new Map,p=o.getElementsByTagName("w:lvlOverride");for(let h=0;h<p.length;h++){const g=p[h],f=g.getAttribute(
|
|
156
|
+
"w:ilvl"),w=f?parseInt(f,10):NaN;if(!Number.isFinite(w))continue;const u=g.getElementsByTagName("w:startOverride")[0]?.getAttribute("w:val");u&&Number.isFinite(parseInt(u,10))&&c.set(w,parseInt(u,10))}
|
|
154
157
|
r.nums.set(s,{numId:s,abstractNumId:l?.getAttribute("w:val")||void 0,levelStartOverrides:c})}return r}static parseContentTypesXml(e){const r=new Map;if(!e)return r;const t=this.parseDocumentXml(e);if(!t)
|
|
155
158
|
return r;const i=t.getElementsByTagName("Default");for(let a=0;a<i.length;a++){const o=i[a],s=(o.getAttribute("Extension")||"").toLowerCase(),l=o.getAttribute("ContentType");s&&l&&r.set(s,l)}const n=t.
|
|
156
159
|
getElementsByTagName("Override");for(let a=0;a<n.length;a++){const o=n[a],s=o.getAttribute("PartName"),l=o.getAttribute("ContentType");s&&l&&r.set(s.replace(/^\/+/,""),l)}return r}static getDirectChild(e,r){
|
|
@@ -161,24 +164,24 @@ return Number.isFinite(e)?e/this.TWIPS_PER_PX:0}static inferPageSizePresetFromTw
|
|
|
161
164
|
for(const l of this.PAGE_SIZE_PRESETS){const c=Math.abs(n-l.width)+Math.abs(a-l.height);c<s&&(s=c,o=l.preset)}return o}static findAllSectionProperties(e){const r=[],t=i=>{for(const n of Array.from(i.children)){
|
|
162
165
|
if(n.tagName==="w:sdt"){const a=this.getDirectChild(n,"w:sdtContent");a&&t(a);continue}if(n.tagName==="w:p"){const a=this.getDirectChild(n,"w:pPr"),o=a?this.getDirectChild(a,"w:sectPr"):void 0;o&&r.push(
|
|
163
166
|
o)}n.tagName==="w:sectPr"&&r.push(n)}};return t(e),r}static findBodySectionProperties(e){const r=this.findAllSectionProperties(e);return r[r.length-1]}static parseSectionPropertiesElement(e){const r={},
|
|
164
|
-
t=this.getDirectChild(e,"w:pgSz");if(t){const h=this.parseTwipsAttribute(t,"w:w"),
|
|
165
|
-
|
|
166
|
-
e,"w:pgMar");if(i){const h=this.parseTwipsAttribute(i,"w:top"),
|
|
167
|
-
this.twipsToPx(h)),
|
|
168
|
-
mType"),a=(n?.getAttribute("w:start")||"").trim();if(a!==""){const h=parseInt(a,10);Number.isFinite(h)&&h>0&&(r.pageNumberStart=h)}const o=(n?.getAttribute("w:fmt")||"").trim();
|
|
169
|
-
o);const s=this.getDirectChild(e,"w:lnNumType");if(s){const h=(s.getAttribute("w:countBy")||"").trim(),
|
|
170
|
-
"w:distance")||"").trim(),u=h?parseInt(h,10):NaN,g
|
|
171
|
-
newSection"||f==="continuous"?f:"newPage",...Number.isFinite(b)&&b>=0?{distancePx:b/15}:{}})}const l=this.getDirectChild(e,"w:cols");if(l){const h=(l.getAttribute("w:num")||"").trim(),
|
|
172
|
-
NaN;if(Number.isFinite(
|
|
173
|
-
w:pgBorders"));c&&(r.pageBorders=c);const p=at(e,
|
|
167
|
+
t=this.getDirectChild(e,"w:pgSz");if(t){const h=this.parseTwipsAttribute(t,"w:w"),g=this.parseTwipsAttribute(t,"w:h"),f=(t.getAttribute("w:orient")||"").trim().toLowerCase();h!==void 0&&h>0&&g!==void 0&&
|
|
168
|
+
g>0?r.orientation=h>g?"landscape":"portrait":(f==="landscape"||f==="portrait")&&(r.orientation=f),h!==void 0&&h>0&&g!==void 0&&g>0&&(r.pageSize=this.inferPageSizePresetFromTwips(h,g))}const i=this.getDirectChild(
|
|
169
|
+
e,"w:pgMar");if(i){const h=this.parseTwipsAttribute(i,"w:top"),g=this.parseTwipsAttribute(i,"w:right"),f=this.parseTwipsAttribute(i,"w:bottom"),w=this.parseTwipsAttribute(i,"w:left");h!==void 0&&(r.marginTopPx=
|
|
170
|
+
this.twipsToPx(h)),g!==void 0&&(r.marginRightPx=this.twipsToPx(g)),f!==void 0&&(r.marginBottomPx=this.twipsToPx(f)),w!==void 0&&(r.marginLeftPx=this.twipsToPx(w))}const n=this.getDirectChild(e,"w:pgNu\
|
|
171
|
+
mType"),a=(n?.getAttribute("w:start")||"").trim();if(a!==""){const h=parseInt(a,10);Number.isFinite(h)&&h>0&&(r.pageNumberStart=h)}const o=(n?.getAttribute("w:fmt")||"").trim();Ei(o)&&(r.pageNumberFormat=
|
|
172
|
+
o);const s=this.getDirectChild(e,"w:lnNumType");if(s){const h=(s.getAttribute("w:countBy")||"").trim(),g=(s.getAttribute("w:start")||"").trim(),f=(s.getAttribute("w:restart")||"").trim(),w=(s.getAttribute(
|
|
173
|
+
"w:distance")||"").trim(),u=h?parseInt(h,10):NaN,m=g?parseInt(g,10):NaN,b=w?parseInt(w,10):NaN;r.lineNumbering=Di({countBy:Number.isFinite(u)&&u>=1?u:1,start:Number.isFinite(m)&&m>=1?m:1,restart:f==="\
|
|
174
|
+
newSection"||f==="continuous"?f:"newPage",...Number.isFinite(b)&&b>=0?{distancePx:b/15}:{}})}const l=this.getDirectChild(e,"w:cols");if(l){const h=(l.getAttribute("w:num")||"").trim(),g=h?parseInt(h,10):
|
|
175
|
+
NaN;if(Number.isFinite(g)&&g>1){r.columnCount=g;const f=(l.getAttribute("w:space")||"").trim(),w=f?parseInt(f,10):NaN;Number.isFinite(w)&&w>=0&&(r.columnGapTwips=w)}}const c=Bi(this.getDirectChild(e,"\
|
|
176
|
+
w:pgBorders"));c&&(r.pageBorders=c);const p=at(e,Ur);return p&&(r.oxmlSectPr=p),Object.keys(r).length>0?r:void 0}static parseSectionStartType(e){const r=(this.getDirectChild(e,"w:type")?.getAttribute(
|
|
174
177
|
"w:val")||"").trim();if(r==="continuous")return"continuous";if(r==="evenPage")return"evenPage";if(r==="oddPage")return"oddPage";if(r==="nextPage")return"nextPage"}static parseDocumentPageLayout(e,r){const t=r??
|
|
175
178
|
this.parseDocumentXml(e);if(!t)return;const i=t.getElementsByTagName("w:body")[0];if(!i)return;const n=this.findBodySectionProperties(i);if(!n)return;const a=this.parseSectionPropertiesElement(n);return a?.
|
|
176
179
|
pageNumberStart!==void 0&&(a.pageNumberRestart=!0),a}static async parseDocumentPageLayoutFromPackage(e,r,t){const i=t??this.parseDocumentXml(e);if(!i)return;const n=this.parseDocumentPageLayout(e,i)??
|
|
177
180
|
{},a=i.getElementsByTagName("w:body")[0];if(!a)return Object.keys(n).length>0?n:void 0;const o=this.findAllSectionProperties(a);if(o.length===0)return Object.keys(n).length>0?n:void 0;const s=this.resolveSectionHeaderFooterReferences(
|
|
178
181
|
o)[o.length-1],l=await r.file("word/_rels/document.xml.rels")?.async("string");if(!l)return Object.keys(n).length>0?n:void 0;const c=this.parseDocumentXml(l);if(!c)return Object.keys(n).length>0?n:void 0;
|
|
179
|
-
const p=new Map,h=c.getElementsByTagName("Relationship");for(let f=0;f<h.length;f++){const w=h[f],u=w.getAttribute("Id"),
|
|
180
|
-
|
|
181
|
-
v);y&&(n.showPageNumbers=!0,n.pageNumberPosition=`${w}-${y.horizontal}`)};return await
|
|
182
|
+
const p=new Map,h=c.getElementsByTagName("Relationship");for(let f=0;f<h.length;f++){const w=h[f],u=w.getAttribute("Id"),m=w.getAttribute("Target");u&&m&&p.set(u,m)}const g=async(f,w)=>{const u=s[f].default,
|
|
183
|
+
m=u?p.get(u):void 0;if(!m)return;const b=m.startsWith("/")?m.slice(1):m.startsWith("word/")?m:`word/${m.replace(/^\.?\//,"")}`,v=await r.file(b)?.async("string");if(!v)return;const y=this.parsePageNumberInfoFromReferenceXml(
|
|
184
|
+
v);y&&(n.showPageNumbers=!0,n.pageNumberPosition=`${w}-${y.horizontal}`)};return await g("header","top"),n.showPageNumbers||await g("footer","bottom"),Object.keys(n).length>0?n:void 0}static parsePageNumberInfoFromReferenceXml(e){
|
|
182
185
|
const r=this.parseDocumentXml(e);if(!r)return;const t=r.getElementsByTagName("w:p");for(let i=0;i<t.length;i++){const n=t[i],a=n.getElementsByTagName("w:instrText");let o=!1;for(let l=0;l<a.length;l++)
|
|
183
186
|
if((a[l].textContent||"").toUpperCase().includes("PAGE")){o=!0;break}if(!o){const l=n.getElementsByTagName("w:fldSimple");for(let c=0;c<l.length;c++)if((l[c].getAttribute("w:instr")||"").toUpperCase().
|
|
184
187
|
includes("PAGE")){o=!0;break}}if(!o)continue;const s=this.getDirectChild(n,"w:pPr");return{horizontal:((s?this.getDirectChild(s,"w:jc"):void 0)?.getAttribute("w:val")||"").toLowerCase()==="left"?"left":
|
|
@@ -186,8 +189,8 @@ includes("PAGE")){o=!0;break}}if(!o)continue;const s=this.getDirectChild(n,"w:pP
|
|
|
186
189
|
t,"w:pageBreakBefore"));n!==void 0&&(i.pageBreakBefore=n),this.getDirectChild(t,"w:keepNext")&&(i.keepNext=this.isOn(t,"w:keepNext")),this.getDirectChild(t,"w:keepLines")&&(i.keepLines=this.isOn(t,"w:\
|
|
187
190
|
keepLines")),this.getDirectChild(t,"w:widowControl")&&(i.widowControl=this.isOn(t,"w:widowControl")),this.getDirectChild(t,"w:bidi")&&(i.direction=this.isOn(t,"w:bidi")?"rtl":"ltr"),this.parseParagraphDecoration(
|
|
188
191
|
t,i),this.applyTabStopsFromPPr(i,t),this.applyJcFromPPr(i,t);const a=this.getDirectChild(t,"w:ind");if(a){const o=this.parseTwipsAttribute(a,"w:start")??this.parseTwipsAttribute(a,"w:left");if(o===0)i.
|
|
189
|
-
leftIndent=0;else if(o!==void 0&&o>0){const c=
|
|
190
|
-
a,"w:hanging");if(l!==void 0&&l>0)i.firstLineIndent=-1;else if(s===0)i.firstLineIndent=0;else if(s!==void 0&&s>0){const c=
|
|
192
|
+
leftIndent=0;else if(o!==void 0&&o>0){const c=Ft(this.twipsToPx(o),{indentStepPx:r,storedAsUnits:!1});c!==void 0&&(i.leftIndent=c)}const s=this.parseTwipsAttribute(a,"w:firstLine"),l=this.parseTwipsAttribute(
|
|
193
|
+
a,"w:hanging");if(l!==void 0&&l>0)i.firstLineIndent=-1;else if(s===0)i.firstLineIndent=0;else if(s!==void 0&&s>0){const c=Ft(this.twipsToPx(s),{indentStepPx:r,storedAsUnits:!1,firstLine:!0});c!==void 0&&
|
|
191
194
|
(i.firstLineIndent=c)}}return this.resolveLogicalAlignment(i),i}static applyJcFromPPr(e,r){const t=(this.getDirectChild(r,"w:jc")?.getAttribute("w:val")||"").toLowerCase();t==="center"?(e.align=t,delete e.
|
|
192
195
|
jcLogical,delete e.jcPhysical):t==="left"||t==="right"?(e.jcPhysical=t,delete e.align,delete e.jcLogical):t==="both"||t==="justify"?(e.align="justify",delete e.jcLogical,delete e.jcPhysical):(t==="sta\
|
|
193
196
|
rt"||t==="end")&&(e.jcLogical=t,delete e.align,delete e.jcPhysical)}static resolveLogicalAlignment(e){const r=e.direction==="rtl",t=e.jcPhysical;if(t){if(delete e.jcPhysical,delete e.jcLogical,!r){e.align=
|
|
@@ -196,13 +199,13 @@ t;return}const a=t==="left"?"right":"left";a==="right"?delete e.align:e.align=a;
|
|
|
196
199
|
for(let a=0;a<i.children.length;a++){const o=i.children[a];o.tagName==="w:p"&&n.push(this.parseWordParagraphProperties(o,r))}return n}static applyTopLevelParagraphProperties(e,r){const t=r.filter(n=>!n.
|
|
197
200
|
isList);let i=0;for(const n of e.children){if(n.type!=="paragraph")continue;const a=t[i];if(!a)break;i+=1,a.align&&(n.align=a.align),a.leftIndent!==void 0&&(n.leftIndent=a.leftIndent),a.firstLineIndent!==
|
|
198
201
|
void 0&&(n.firstLineIndent=a.firstLineIndent);const o=this.directionAttrFor(a.direction,this.paragraphNodeText(n));o&&(n.direction=o)}}static paragraphNodeText(e){let r="";for(const t of e.children)t.
|
|
199
|
-
type==="text"&&(r+=t.text);return r}static directionAttrFor(e,r){if(e==="rtl")return"rtl";if(e==="ltr"
|
|
202
|
+
type==="text"&&(r+=t.text);return r}static directionAttrFor(e,r){if(e==="rtl")return"rtl";if(e==="ltr"&&Lt(r)==="rtl")return"ltr"}static async parseStructuredDocxDocument(e,r,t,i,n){t||(this.fallbackCommentState=
|
|
200
203
|
{});const a=i??this.parseDocumentXml(e);if(!a)return{type:"doc",children:[this.createEmptyParagraph()]};const o=a.getElementsByTagName("w:body")[0];if(!o)return{type:"doc",children:[this.createEmptyParagraph()]};
|
|
201
204
|
const s=Ee(r).indentStepPx,l=[];this.importSdtWrappers=l;const c=[];this.importOxmlRanges=c,this.sdtAncestorStack=[];const p=t??this.fallbackCommentState;p.moveRangeByWrapper=e.includes("<w:moveFrom")||
|
|
202
205
|
e.includes("<w:moveTo")?this.indexImportedMoveRanges(a):new WeakMap,p.collapsedCommentAnchorBlockById=new Map;let h;try{h=await this.parseBodyChildren(o,s,t,l,n)}finally{this.importSdtWrappers=void 0,
|
|
203
206
|
this.importOxmlRanges=void 0,this.sdtAncestorStack=[],delete p.moveRangeByWrapper}this.finalizeImportedMovePairs(h),h=this.applyParagraphMarkMoves(h),this.applyTableMoves(h),h=this.applyParagraphMarkRevisions(
|
|
204
|
-
h),h=this.collapseTocRegions(h);const
|
|
205
|
-
|
|
207
|
+
h),h=this.collapseTocRegions(h);const g=this.findAllSectionProperties(o);if(g.length>1){let w=0;for(const u of h){if(u.type!=="section-break")continue;const m=g[w+1];if(m){const b=this.parseSectionStartType(
|
|
208
|
+
m);b&&(u.breakType=b)}w++}}const f={type:"doc",children:h.length>0?h:[this.createEmptyParagraph()]};if(r){if(f.pageLayout=r,r.pageNumberFormat&&r.pageNumberFormat!=="decimal")for(const w of f.children)
|
|
206
209
|
w.type==="section-break"&&w.layout?.pageNumberFormat===void 0&&(w.layout={...w.layout??{},pageNumberFormat:"decimal"});if((r.columnCount??1)>1)for(const w of f.children)w.type==="section-break"&&w.layout?.
|
|
207
210
|
columnCount===void 0&&(w.layout={...w.layout??{},columnCount:1})}if(l.length>0&&(f.sdtWrappers=l),c.length>0&&(f.oxmlRanges=c),t?.stylesXmlRaw){f.stylesXml=t.stylesXmlRaw;const w=this.buildDocumentStylesheet(
|
|
208
211
|
t,s);w&&(f.stylesheet=w)}return f}static resolveStylesheetFromStylesXml(e,r){const t=this.parseStylesXml(e);return this.buildDocumentStylesheet({styles:t,numbering:{abstractNums:new Map,nums:new Map}},
|
|
@@ -211,13 +214,13 @@ type!=="paragraph")continue;const o={isList:!1},s=[];t.paragraphDefault&&s.push(
|
|
|
211
214
|
c=typeof l.fontSize=="number"&&l.fontSize>0?l.fontSize:Ae.paragraph;for(const f of s)this.applyParagraphPropertiesFromElement(o,f,r,e,c);this.resolveLogicalAlignment(o);const p={};o.align&&(p.align=o.
|
|
212
215
|
align),o.direction&&(p.direction=o.direction),o.leftIndent!==void 0&&(p.leftIndent=o.leftIndent),o.firstLineIndent!==void 0&&(p.firstLineIndent=o.firstLineIndent),o.lineSpacing!==void 0&&(p.lineSpacing=
|
|
213
216
|
o.lineSpacing),this.applyDocxParagraphSpacing(p,o),o.keepNext!==void 0&&(p.keepNext=o.keepNext),o.keepLines!==void 0&&(p.keepLines=o.keepLines),o.widowControl!==void 0&&(p.widowControl=o.widowControl),
|
|
214
|
-
o.bordersJson&&(p.borders=o.bordersJson),o.shading&&(p.shading=o.shading),o.tabStops&&o.tabStops.length>0&&(p.tabStops=JSON.stringify(o.tabStops));const h={styleId:a.id};a.name&&(h.name=a.name);const
|
|
215
|
-
headingLevelForStyle(a)||o.heading;
|
|
217
|
+
o.bordersJson&&(p.borders=o.bordersJson),o.shading&&(p.shading=o.shading),o.tabStops&&o.tabStops.length>0&&(p.tabStops=JSON.stringify(o.tabStops));const h={styleId:a.id};a.name&&(h.name=a.name);const g=this.
|
|
218
|
+
headingLevelForStyle(a)||o.heading;g&&(h.headingLevel=g),a.id===i&&(h.default=!0),Object.keys(p).length>0&&(h.paragraphAttrs=p),Object.keys(l).length>0&&(h.runMarks=l),n.push(h)}return n.length>0?{paragraphStyles:n}:
|
|
216
219
|
void 0}static tocInstrOfBlock(e){if(e.type!=="paragraph")return;const r=e.children.filter(i=>i.type==="text"&&((i.text??"")!==""||i.marks?.fieldInstr));if(r.length===0)return;const t=r[0].marks?.fieldInstr;
|
|
217
220
|
if(!(!t||!/^TOC\b/i.test(t.trim())))return r.every(i=>i.marks?.fieldInstr===t)?t:void 0}static tocTypographyOfRegion(e,r){const t=e.flatMap(l=>l.children.filter(c=>c.type==="text"&&(c.text??"").trim()!==
|
|
218
221
|
"")),i=l=>{if(t.length===0)return;const c=l(t[0]);if(c!==void 0)return t.every(p=>l(p)===c)?c:void 0},n={},a=i(l=>l.marks?.fontFamily);a&&a!==r&&(n.fontFamily=a);const o=i(l=>l.marks?.fontSize);Ri(o)&&
|
|
219
222
|
(n.fontSize=o);const s=i(l=>Rr(l.marks?.color));return s&&(n.color=s),n}static collapseTocRegions(e){const r=[];let t,i,n=[],a={},o,s=!1;const l=()=>{if(t){s||(o=this.inferDocumentFontFamily({type:"do\
|
|
220
|
-
c",children:e.filter(p=>!this.tocInstrOfBlock(p))}),s=!0);const c={type:"toc",...a,...this.tocTypographyOfRegion(n,o),id:i||this.generateId(),instr:t,levels:
|
|
223
|
+
c",children:e.filter(p=>!this.tocInstrOfBlock(p))}),s=!0);const c={type:"toc",...a,...this.tocTypographyOfRegion(n,o),id:i||this.generateId(),instr:t,levels:Gi(t)};r.push(c)}t=void 0,i=void 0,n=[],a={}};
|
|
221
224
|
for(const c of e){const p=this.tocInstrOfBlock(c);if(p&&p===t){c.type==="paragraph"&&n.push(c);continue}if(t&&l(),p){t=p,i=c.id,c.type==="paragraph"&&(n.push(c),c.direction&&(a.direction=c.direction,a.
|
|
222
225
|
align=c.direction==="rtl"?"right":"left"),c.align&&(a.align=c.align));continue}r.push(c)}return l(),r}static parseParagraphMarkRevision(e){const r=this.getDirectChild(e,"w:pPr"),t=r?this.getDirectChild(
|
|
223
226
|
r,"w:rPr"):void 0;if(!t)return null;const i=this.getDirectChild(t,"w:ins");if(i)return{kind:"split",meta:this.parseTrackedRevisionMeta(i)};const n=this.getDirectChild(t,"w:del");return n?{kind:"merge",
|
|
@@ -230,12 +233,12 @@ const c=`docxmove-${encodeURIComponent(s.move.name)}`;return r.has(c)&&l.every(p
|
|
|
230
233
|
n=s=>{if(!(!s||typeof s!="object")){if(Array.isArray(s)){s.forEach(n);return}delete s.__pilcrowMove,n(s.children)}},a=(s,l,c)=>{s.structuralSuggestionId=c,s.structuralSuggestionKind=l.role==="from"?"d\
|
|
231
234
|
elete":"insert",s.structuralSuggestionLabel="Move",this.markWholeBlockMove(s,c),delete s.structuralSuggestionRole,delete s.structuralSuggestionRecord},o=[];for(const s of e){if(s.type==="paragraph"){const l=s.
|
|
232
235
|
__pilcrowMove;delete s.__pilcrowMove;const c=i(l,s.children);l&&c?a(s,l,c):l&&!s.structuralSuggestionKind&&(s.__pilcrowRevision={kind:l.role==="from"?"merge":"split",meta:l.meta}),n(s.children),o.push(
|
|
233
|
-
s);continue}if(s.type==="list"&&s.children.length>0){const l=[];for(const p of s.children){const h=p.__pilcrowMove,
|
|
234
|
-
"",u=l[l.length-1];u&&u.key===w?u.items.push(p):l.push({key:w,move:f,items:[p]})}const c={...s};l.forEach((p,h)=>{const
|
|
235
|
-
|
|
236
|
+
s);continue}if(s.type==="list"&&s.children.length>0){const l=[];for(const p of s.children){const h=p.__pilcrowMove,g=i(h,p.children),f=h&&g?{marker:h,moveId:g}:void 0,w=f?`${f.moveId}\0${f.marker.role}`:
|
|
237
|
+
"",u=l[l.length-1];u&&u.key===w?u.items.push(p):l.push({key:w,move:f,items:[p]})}const c={...s};l.forEach((p,h)=>{const g=h===0?s:{...c,id:this.generateId()};h>0&&s.numberingChainId&&delete g.startNumber,
|
|
238
|
+
g.children=p.items,p.move&&a(g,p.move.marker,p.move.moveId);for(const f of p.items)delete f.__pilcrowMove;n(g.children),o.push(g)});continue}n(s),o.push(s)}return o}static applyTableMoves(e){for(const r of e){
|
|
236
239
|
if(r.type!=="table"||r.children.length===0)continue;const t=r.children[0].diffState,i=r.children[0].suggestionId;if(t!=="insert"&&t!=="delete"||!i||!r.children.every(h=>h.diffState===t&&h.suggestionId===
|
|
237
|
-
i))continue;const n=t==="delete"?"from":"to",a=new Set;let o=!0;const s=h=>{if(!o||!h||typeof h!="object")return;if(Array.isArray(h)){h.forEach(s);return}const
|
|
238
|
-
(o=!1),
|
|
240
|
+
i))continue;const n=t==="delete"?"from":"to",a=new Set;let o=!0;const s=h=>{if(!o||!h||typeof h!="object")return;if(Array.isArray(h)){h.forEach(s);return}const g=h;g.type==="table-cell"&&g.diffState&&
|
|
241
|
+
(o=!1),g.type==="text"&&g.text&&(this.parseDocxMoveMark(g.marks?.docxMove)?.role===n&&g.marks?.suggestionId&&(n==="from"?g.marks.deletion:g.marks.insertion)?a.add(g.marks.suggestionId):o=!1),s(g.children)};
|
|
239
242
|
if(s(r.children),!o||a.size!==1)continue;let l=[];try{const h=JSON.parse(r.structuralSuggestionRecords??"[]");Array.isArray(h)&&(l=h)}catch{continue}const c=l.find(h=>h?.id===i);if(c?.type!=="table-ch\
|
|
240
243
|
ange"||c.tableRevision.operations.length!==r.children.length||!c.tableRevision.operations.every(h=>h.kind==="row"&&h.action===t))continue;const p=l.filter(h=>h!==c);p.length>0?r.structuralSuggestionRecords=
|
|
241
244
|
JSON.stringify(p):delete r.structuralSuggestionRecords;for(const h of r.children)delete h.diffState,delete h.suggestionId;r.diffState=t,r.suggestionId=[...a][0],this.markWholeBlockMove(r,r.suggestionId)}}static applyParagraphMarkRevisions(e){
|
|
@@ -254,12 +257,12 @@ fromEntries(Object.entries(a).filter(([s])=>s!=="insertion"&&s!=="deletion"&&s!=
|
|
|
254
257
|
ring")try{const s=JSON.parse(a.layeredInsertion);Object.assign(o,{insertion:!0,...s.id?{suggestionId:s.id}:{},...s.source?{suggestionSource:s.source}:{},...s.authorType?{suggestionAuthorType:s.authorType}:
|
|
255
258
|
{},...s.createdAt!==void 0?{suggestionCreatedAt:s.createdAt}:{},suggestionLabel:s.label??"Insert",...s.authorName?{suggestionAuthorName:s.authorName}:{}})}catch{}return{...n,marks:o}})}static markListItemPropertyChange(e,r){
|
|
256
259
|
const t=r,i=t.__propertyChange;if(delete t.__propertyChange,!i||r.structuralSuggestionId)return;const n=i.priorProps,a=r,o=e,s={type:"list-item",id:r.id,children:[]},l={type:"list-item",id:r.id,children:[]};
|
|
257
|
-
let c=!1;for(const
|
|
258
|
-
const
|
|
260
|
+
let c=!1;for(const g of this.LIST_ITEM_PROPERTY_FIELDS){const f=a[g]??o[g],w=n[g]??o[g];f!==void 0&&(l[g]=f),w!==void 0&&(s[g]=w),JSON.stringify(f)!==JSON.stringify(w)&&(c=!0)}if(i.priorLevel!==void 0){
|
|
261
|
+
const g=r.indentLevel??0;l.indentLevel=g,s.indentLevel=i.priorLevel,g!==i.priorLevel&&(c=!0)}if(!c)return;const p=i.meta.revisionId?`docxrev-${i.meta.revisionId}`:this.generateId(),h=this.revisionAuthorIdentity(
|
|
259
262
|
i.meta.author);r.structuralSuggestionId=p,r.structuralSuggestionKind="change",r.structuralSuggestionLabel="Format",r.structuralSuggestionRecord=JSON.stringify({id:p,type:"block-change",blockId:e.id,beforeBlock:{
|
|
260
263
|
...e,children:[]},listItemSuggestion:{kind:"change",beforeItem:s,afterItem:l},label:"Format",source:h.suggestionSource,authorType:h.suggestionAuthorType,...i.meta.createdAt!==void 0?{createdAt:i.meta.
|
|
261
264
|
createdAt}:{},...i.meta.author?{agentName:i.meta.author}:{}})}static markWholeListItemRevision(e,r){const t=r,i=t.__pilcrowRevision;if(delete t.__pilcrowRevision,!i)return;const n=i.kind==="split"?"in\
|
|
262
|
-
sertion":"deletion",a=n==="insertion"?"deletion":"insertion";if(!r.children.every(h=>{const
|
|
265
|
+
sertion":"deletion",a=n==="insertion"?"deletion":"insertion";if(!r.children.every(h=>{const g=h.marks;return!!g?.[n]&&!g?.[a]}))return;r.children=this.unwrapWholeBlockRunMarks(r.children,i);const o=i.
|
|
263
266
|
kind==="split"?"insert":"delete",s=i.meta.revisionId?`docxrev-${i.meta.revisionId}`:this.generateId(),l=this.revisionAuthorIdentity(i.meta.author),c=JSON.parse(JSON.stringify(r)),p=o==="insert"?"Inser\
|
|
264
267
|
t":"Delete";r.structuralSuggestionId=s,r.structuralSuggestionKind=o,r.structuralSuggestionLabel=p,r.structuralSuggestionRecord=JSON.stringify({id:s,type:"block-change",blockId:e.id,beforeBlock:{...e,children:[]},
|
|
265
268
|
listItemSuggestion:o==="insert"?{kind:o,afterItem:c}:{kind:o,beforeItem:c},label:p,source:l.suggestionSource,authorType:l.suggestionAuthorType,...i.meta.createdAt!==void 0?{createdAt:i.meta.createdAt}:
|
|
@@ -270,126 +273,126 @@ agentName:t.meta.author}:{}},s=t.kind==="split"?{...o,type:"paragraph-split",blo
|
|
|
270
273
|
n,e.structuralSuggestionRecord=JSON.stringify(s),r.structuralSuggestionId=i,r.structuralSuggestionKind=t.kind,r.structuralSuggestionRole="after",r.structuralSuggestionLabel=n}static paragraphPropertiesOf(e){
|
|
271
274
|
const{id:r,type:t,children:i,structuralSuggestionId:n,structuralSuggestionKind:a,structuralSuggestionRole:o,structuralSuggestionLabel:s,structuralSuggestionRecord:l,...c}=e;return delete c.__pilcrowRevision,
|
|
272
275
|
c}static replaceParagraphMarkRun(e,r){const t=r[0].meta,i=c=>c==="insertion"||c==="deletion"||c==="formatChange"||c==="layeredInsertion"||c==="docxMove"||c.startsWith("suggestion"),n=c=>Object.fromEntries(
|
|
273
|
-
Object.entries(c).filter(([p])=>!i(p))),a=(c,p)=>c.children.filter(h=>{const
|
|
274
|
-
let f={};try{f=JSON.parse(
|
|
275
|
-
length-1].push(
|
|
276
|
-
h.structuralSuggestionRecord):void 0,f=p==="before"&&
|
|
277
|
-
children:c.flatMap(v=>a(v,p))},u=p==="after"?"insert":"delete",
|
|
278
|
-
...t.createdAt!==void 0?{createdAt:t.createdAt}:{},...t.author?{agentName:t.author}:{}};return{...w,structuralSuggestionId:
|
|
276
|
+
Object.entries(c).filter(([p])=>!i(p))),a=(c,p)=>c.children.filter(h=>{const g=h.marks;return p==="before"?!g?.insertion:!g?.deletion}).map(h=>{const g=h.marks;if(!g)return h;if(p==="before"&&g.formatChange){
|
|
277
|
+
let f={};try{f=JSON.parse(g.suggestionPriorAttributes??"{}")}catch{f={}}return{...h,marks:n(f)}}return{...h,marks:n(g)}}),o=c=>{const p=c==="before"?"split":"merge",h=[[]];return e.forEach((g,f)=>{h[h.
|
|
278
|
+
length-1].push(g),(f>=r.length||r[f].kind!==p)&&h.push([])}),h.filter(g=>g.length>0)},s=this.revisionAuthorIdentity(t.author),l=(c,p)=>{const h=c[c.length-1],g=h.structuralSuggestionRecord?JSON.parse(
|
|
279
|
+
h.structuralSuggestionRecord):void 0,f=p==="before"&&g?.type==="block-change"&&g.beforeBlock?g.beforeBlock:h,w={...this.paragraphPropertiesOf(f),type:"paragraph",id:p==="after"?c[0].id:this.generateId(),
|
|
280
|
+
children:c.flatMap(v=>a(v,p))},u=p==="after"?"insert":"delete",m=this.generateId(),b={id:m,blockId:w.id,source:s.suggestionSource,authorType:s.suggestionAuthorType,label:u==="insert"?"Insert":"Delete",
|
|
281
|
+
...t.createdAt!==void 0?{createdAt:t.createdAt}:{},...t.author?{agentName:t.author}:{}};return{...w,structuralSuggestionId:m,structuralSuggestionKind:u,structuralSuggestionRecord:JSON.stringify(u==="i\
|
|
279
282
|
nsert"?{...b,type:"block-insert"}:{...b,type:"block-delete",beforeBlock:w})}};return[...o("before").map(c=>l(c,"before")),...o("after").map(c=>l(c,"after"))]}static parseParagraphPropertyChange(e,r,t){
|
|
280
283
|
const i=this.getDirectChild(e,"w:pPr"),n=i?this.getDirectChild(i,"w:pPrChange"):void 0;if(!n)return null;const a=this.parseTrackedRevisionMeta(n),o=this.getDirectChild(n,"w:pPr"),s={isList:!1};if(t){const p=o&&
|
|
281
284
|
this.getDirectChild(o,"w:pStyle")?.getAttribute("w:val")||void 0;s.styleId=p;const h=[];t.styles.paragraphDefault&&h.push(t.styles.paragraphDefault),h.push(...this.resolveStyleChainPPr(p,t.styles,"par\
|
|
282
|
-
agraph")),o&&h.push(o);for(const
|
|
285
|
+
agraph")),o&&h.push(o);for(const g of h)this.applyParagraphPropertiesFromElement(s,g,r,t)}else o&&this.applyParagraphPropertiesFromElement(s,o,r);this.resolveLogicalAlignment(s);const l=o?this.getDirectChild(
|
|
283
286
|
this.getDirectChild(o,"w:numPr")??o,"w:ilvl")?.getAttribute("w:val"):void 0,c=o&&this.getDirectChild(o,"w:numPr")&&l?parseInt(l,10):void 0;return{meta:a,priorProps:s,...c!==void 0&&Number.isFinite(c)?
|
|
284
287
|
{priorLevel:c}:{}}}static applyParsedPropertiesToParagraphNode(e,r){delete e.align,delete e.leftIndent,delete e.firstLineIndent,delete e.heading,delete e.lineSpacing,delete e.keepNext,delete e.keepLines,
|
|
285
288
|
delete e.widowControl,delete e.borders,delete e.shading,delete e.styleId,delete e.direction,r.align&&(e.align=r.align);const t=this.directionAttrFor(r.direction,this.paragraphNodeText(e));t&&(e.direction=
|
|
286
289
|
t),r.leftIndent!==void 0&&(e.leftIndent=r.leftIndent),r.firstLineIndent!==void 0&&(e.firstLineIndent=r.firstLineIndent),r.heading&&(e.heading=r.heading),r.lineSpacing!==void 0&&(e.lineSpacing=r.lineSpacing),
|
|
287
290
|
this.applyDocxParagraphSpacing(e,r),r.keepNext&&(e.keepNext=!0),r.keepLines&&(e.keepLines=!0),r.widowControl===!1&&(e.widowControl=!1),r.bordersJson&&(e.borders=r.bordersJson),r.shading&&(e.shading=r.
|
|
288
291
|
shading);const i=r.styleId;i&&i.toLowerCase()!=="normal"&&(e.styleId=i)}static applyDocxParagraphSpacing(e,r){r.contextualSpacing&&(e.contextualSpacing=!0),e.spaceBefore=r.spaceBefore??0,e.spaceAfter=
|
|
289
|
-
r.spaceAfter??0}static async parseWordParagraphBlocks(e,r,t){const i=[];for(let
|
|
292
|
+
r.spaceAfter??0}static async parseWordParagraphBlocks(e,r,t){const i=[];for(let m=0;m+1<e.children.length;m++){const b=e.children[m],v=e.children[m+1],y=b.getAttribute("w:id");b.tagName==="w:commentRa\
|
|
290
293
|
ngeStart"&&v.tagName==="w:commentRangeEnd"&&y&&v.getAttribute("w:id")===y&&i.push(y)}const n=this.resolveParagraphProperties(e,r,t),a=this.parseParagraphMarkRevision(e),o=a?null:this.parseParagraphMarkMove(
|
|
291
|
-
e,t),s=[];let l=!1,c="";const p=[];n.pageBreakBefore&&p.push(this.createPageBreakBlock());for(let
|
|
294
|
+
e,t),s=[];let l=!1,c="";const p=[];n.pageBreakBefore&&p.push(this.createPageBreakBlock());for(let m=0;m<e.children.length;m++){const b=e.children[m],v=b.tagName;if(!this.trackCommentRangeMarker(b,t)&&
|
|
292
295
|
!(this.trackBookmarkMarker(b,t)||this.trackOxmlRangeMarker(b,t))){if(v==="w:fldSimple"){s.push(...await this.parseFldSimpleItems(b,n,t));continue}if(v==="mc:AlternateContent"){const y=this.selectAlternateContentBranch(
|
|
293
296
|
b);y&&s.push(...await this.parseInlineItemsFromChildren(y,n,t));continue}if(v==="w:r")s.push(...this.stampOpenComments(await this.parseWordRunItems(b,n,t),t));else if(v==="w:sdt")s.push(...await this.
|
|
294
297
|
parseInlineSdtItems(b,n,t));else if(v==="w:ins"||v==="w:del"||v==="w:moveFrom"||v==="w:moveTo")s.push(...await this.parseTrackedChangeItems(b,n,t));else if(v==="w:hyperlink")s.push(...await this.parseHyperlinkItems(
|
|
295
|
-
b,n,t));else if(v==="m:oMathPara"){const y=this.ommlToLatex(b);y&&(s.some(
|
|
296
|
-
"m:oMath"){const y=this.ommlToLatex(b);y&&s.push({kind:"text",node:{type:"text",text:y,marks:{latex:!0}}})}}}const h=s.filter(
|
|
297
|
-
{type:"math",id:this.generateId(),content:c,displayMode:"block",align:n.align==="left"||n.align==="right"||n.align==="center"?n.align:"center"}),p;const
|
|
298
|
-
n));if(t){const g
|
|
299
|
-
resolveRunMarks(v?this.getDirectChild(v,"w:rPr"):void 0,n.styleId,t),
|
|
300
|
-
Object.keys(
|
|
301
|
-
if(i.length>0){const g
|
|
302
|
-
v.set(y,
|
|
303
|
-
parseParagraphPropertyChange(e,r,t);if(
|
|
304
|
-
revisionAuthorIdentity(
|
|
305
|
-
"change",v.structuralSuggestionLabel="Paragraph format",v.structuralSuggestionRecord=JSON.stringify({id:y,type:"block-change",blockId:v.id,source:
|
|
306
|
-
Paragraph format",...
|
|
307
|
-
if(m
|
|
308
|
-
const a=[];let o;const s=new Map,l=
|
|
309
|
-
v=
|
|
310
|
-
if(n){for(const v of f)ir(n,
|
|
311
|
-
rkEnd"||[...this.OXML_RANGE_PAIRS.values()].includes(b.tagName)?"end":null;if(this.trackBookmarkMarker(b,t)||this.trackOxmlRangeMarker(b,t)){n&&v==="end"&&w?ir(n,w,
|
|
312
|
-
b.tagName==="w:sdt"?this.getDirectChild(b,"w:sdtPr"):void 0;let
|
|
313
|
-
el:b,id
|
|
314
|
-
const
|
|
315
|
-
lineSpacing:
|
|
316
|
-
void 0&&
|
|
317
|
-
eAfter"])(
|
|
318
|
-
|
|
319
|
-
prXml:
|
|
298
|
+
b,n,t));else if(v==="m:oMathPara"){const y=this.ommlToLatex(b);y&&(s.some(T=>T.kind==="text"&&T.node.text.trim()!=="")?s.push({kind:"text",node:{type:"text",text:y,marks:{latex:!0}}}):(l=!0,c=y))}else if(v===
|
|
299
|
+
"m:oMath"){const y=this.ommlToLatex(b);y&&s.push({kind:"text",node:{type:"text",text:y,marks:{latex:!0}}})}}}const h=s.filter(m=>m.kind==="text");if(l&&h.every(m=>m.node.text.trim()===""))return p.push(
|
|
300
|
+
{type:"math",id:this.generateId(),content:c,displayMode:"block",align:n.align==="left"||n.align==="right"||n.align==="center"?n.align:"center"}),p;const g=p.concat(this.buildBlocksFromParagraphItems(s,
|
|
301
|
+
n));if(t){const m=g.find(v=>v.type==="paragraph"),b=m?.children[0];if(m&&m.children.length===1&&b?.type==="text"&&b.text===""&&b.marks?.fontSize===void 0){const v=this.getDirectChild(e,"w:pPr"),y=this.
|
|
302
|
+
resolveRunMarks(v?this.getDirectChild(v,"w:rPr"):void 0,n.styleId,t),T={};typeof y.fontSize=="number"&&y.fontSize>0&&(T.fontSize=y.fontSize),y.fontFamily&&!b.marks?.fontFamily&&(T.fontFamily=y.fontFamily),
|
|
303
|
+
Object.keys(T).length>0&&(b.marks={...b.marks,...T})}}const f=this.getDirectChild(e,"w:pPr"),w=sr(e),u=at(f,jr);if(w||u){const m=g.find(b=>b.type==="paragraph");m&&(w&&(m.oxmlAttrs=w),u&&(m.oxmlPPr=u))}
|
|
304
|
+
if(i.length>0){const m=g.find(b=>b.type==="paragraph");if(m?.id){const b=t??this.fallbackCommentState,v=b.collapsedCommentAnchorBlockById??(b.collapsedCommentAnchorBlockById=new Map);for(const y of i)
|
|
305
|
+
v.set(y,m.id)}}if(n.list&&!a){const m=this.parseParagraphPropertyChange(e,r,t);if(m){for(let b=g.length-1;b>=0;b--)if(g[b].type==="paragraph"){g[b].__propertyChange=m;break}}}if(!n.list&&!a){const m=this.
|
|
306
|
+
parseParagraphPropertyChange(e,r,t);if(m)for(let b=g.length-1;b>=0;b--){const v=g[b];if(v.type!=="paragraph")continue;const y=m.meta.revisionId?`docxrev-${m.meta.revisionId}`:this.generateId(),T=this.
|
|
307
|
+
revisionAuthorIdentity(m.meta.author),L=JSON.parse(JSON.stringify(v)),W=JSON.parse(JSON.stringify(v));this.applyParsedPropertiesToParagraphNode(W,m.priorProps),v.structuralSuggestionId=y,v.structuralSuggestionKind=
|
|
308
|
+
"change",v.structuralSuggestionLabel="Paragraph format",v.structuralSuggestionRecord=JSON.stringify({id:y,type:"block-change",blockId:v.id,source:T.suggestionSource,authorType:T.suggestionAuthorType,label:"\
|
|
309
|
+
Paragraph format",...m.meta.createdAt!==void 0?{createdAt:m.meta.createdAt}:{},...m.meta.author?{agentName:m.meta.author}:{},beforeBlock:W,acceptedBlock:L});break}}if(a){for(let m=g.length-1;m>=0;m--)
|
|
310
|
+
if(g[m].type==="paragraph"){g[m].__pilcrowRevision=a;break}}if(o){for(let m=g.length-1;m>=0;m--)if(g[m].type==="paragraph"){g[m].__pilcrowMove=o;break}}return g}static async parseBodyChildren(e,r,t,i,n){
|
|
311
|
+
const a=[];let o;const s=new Map,l=m=>m.abstractNumId??m.numId,c=m=>{const b=l(m);let v=s.get(b);return v||(v={chainId:this.generateId(),seenNumIds:new Set,started:!1},s.set(b,v)),v},p=m=>{const b=c(m),
|
|
312
|
+
v=m.hasLevel0StartOverride&&!b.seenNumIds.has(m.numId);if(!b.started||v)return m.startNumber},h=()=>{o&&o.list.children.length>0&&a.push(o.list),o=void 0},g=Array.from(e.children),f=[];let w;const u=(m,b)=>{
|
|
313
|
+
if(n){for(const v of f)ir(n,m,v);f.length=0,ir(n,m,b),w=m}};for(let m=0;m<g.length;m++){const b=g[m],v=b.tagName==="w:bookmarkStart"||this.OXML_RANGE_PAIRS.has(b.tagName)?"start":b.tagName==="w:bookma\
|
|
314
|
+
rkEnd"||[...this.OXML_RANGE_PAIRS.values()].includes(b.tagName)?"end":null;if(this.trackBookmarkMarker(b,t)||this.trackOxmlRangeMarker(b,t)){n&&v==="end"&&w?ir(n,w,m):n&&v!==null&&f.push(m);continue}const y=i&&
|
|
315
|
+
b.tagName==="w:sdt"?this.getDirectChild(b,"w:sdtPr"):void 0;let T=-1,L,W;y&&(h(),T=a.length,L=this.generateId(),W=this.sdtAncestorStack[this.sdtAncestorStack.length-1]?.id,this.sdtAncestorStack.push({
|
|
316
|
+
el:b,id:L}));let X;try{X=await this.parseBodyChild(b,r,t)}finally{y&&this.sdtAncestorStack.pop()}for(const D of X){if(D.kind==="list-item"){if(!o||o.numId!==D.list.numId||o.variant!==D.list.variant){h();
|
|
317
|
+
const M=D.list.variant==="ordered",O=M?c(D.list):null;o={numId:D.list.numId,variant:D.list.variant,list:{type:"list",id:this.generateId(),variant:D.list.variant,children:[],startNumber:M?p(D.list):void 0,
|
|
318
|
+
lineSpacing:D.list.lineSpacing,...M&&D.list.formatSpec?{numberingFormat:D.list.formatSpec}:{}}},O&&(o.list.numberingChainId=O.chainId,O.started=!0,O.seenNumIds.add(D.list.numId))}o.list.lineSpacing===
|
|
319
|
+
void 0&&D.list.lineSpacing!==void 0&&(o.list.lineSpacing=D.list.lineSpacing),o.list.spaceBefore===void 0&&this.applyDocxParagraphSpacing(o.list,D.list);for(const M of["lineSpacing","spaceBefore","spac\
|
|
320
|
+
eAfter"])(D.item[M]===void 0||D.item[M]===o.list[M])&&delete D.item[M];this.markWholeListItemRevision(o.list,D.item),this.markListItemPropertyChange(o.list,D.item),o.list.children.push(D.item),u(o.list,
|
|
321
|
+
m);continue}h(),a.push(D.block),u(D.block,m)}if(y&&T>=0){h();const D=a.slice(T).map(M=>M.id).filter(M=>!!M);if(D.length>0&&i)try{const M=new XMLSerializer().serializeToString(y);i.push({id:L??this.generateId(),
|
|
322
|
+
prXml:M,...W?{parentId:W}:{},blockIds:D})}catch{}}}return h(),a}static async parseBodyChild(e,r,t){if(e.tagName==="w:sdt"){const i=this.getDirectChild(e,"w:sdtContent");if(!i)return[];const n=this.sdtAncestorStack,
|
|
320
323
|
a=n.length>0&&n[n.length-1].el===e;let o;if(!a&&n.length>0&&this.importSdtWrappers){const l=this.getDirectChild(e,"w:sdtPr");if(l)try{o={id:this.generateId(),prXml:new XMLSerializer().serializeToString(
|
|
321
324
|
l),parentId:n[n.length-1].id}}catch{}}o&&n.push({el:e,id:o.id});const s=[];try{for(let l=0;l<i.children.length;l++)s.push(...await this.parseBodyChild(i.children[l],r,t))}finally{o&&n.pop()}if(o&&this.
|
|
322
325
|
importSdtWrappers){const l=s.filter(c=>c.kind==="block").map(c=>c.block.id).filter(c=>!!c);l.length>0&&(o.blockIds=l,this.importSdtWrappers.push(o))}return s}if(e.tagName==="w:p"){const i=await this.parseWordParagraphBlocks(
|
|
323
326
|
e,r,t),n=this.getDirectChild(e,"w:pPr"),a=n?this.getDirectChild(n,"w:sectPr"):void 0;if(a){const s={...this.parseSectionPropertiesElement(a),...this.getDirectChild(a,"w:pgBorders")?{}:{pageBorders:null}},
|
|
324
|
-
l=i.find(
|
|
327
|
+
l=i.find(g=>g.type==="paragraph"&&g.__pilcrowRevision),c=l?.__pilcrowRevision?.kind==="merge"?l.__pilcrowRevision:void 0;c&&l&&delete l.__pilcrowRevision;const p={kind:"block",block:{type:"section-bre\
|
|
325
328
|
ak",id:this.generateId(),...s?{layout:s}:{},...c?{diffState:"delete",suggestionId:c.meta.revisionId?`docxrev-${c.meta.revisionId}`:this.generateId(),...c.meta.author?{suggestionAuthorName:c.meta.author}:
|
|
326
|
-
{},...c.meta.createdAt!==void 0?{suggestionCreatedAt:c.meta.createdAt}:{}}:{}}};if(i.length===1&&i[0].type==="paragraph"&&!i[0].__pilcrowRevision&&i[0].children.every(
|
|
327
|
-
0))return[p];const h=[];for(const
|
|
329
|
+
{},...c.meta.createdAt!==void 0?{suggestionCreatedAt:c.meta.createdAt}:{}}:{}}};if(i.length===1&&i[0].type==="paragraph"&&!i[0].__pilcrowRevision&&i[0].children.every(g=>g.type==="text"&&g.text.length===
|
|
330
|
+
0))return[p];const h=[];for(const g of i)h.push({kind:"block",block:g});return h.push(p),h}const o=[];for(const s of i){if(s.type!=="paragraph"){o.push({kind:"block",block:s});continue}const l=this.codeBlockFromStyledParagraph(
|
|
328
331
|
s);if(l){o.push({kind:"block",block:l});continue}const c=this.resolveParagraphProperties(e,r,t);if(!c.list){const p=this.todoItemFromParagraph(s,c);if(p){o.push(p);continue}o.push({kind:"block",block:s});
|
|
329
332
|
continue}o.push({kind:"list-item",list:c.list,item:this.carryPilcrowMove(s,{type:"list-item",id:this.generateId(),children:s.children,lineSpacing:c.lineSpacing,spaceBefore:c.spaceBefore,spaceAfter:c.spaceAfter,
|
|
330
|
-
indentLevel:c.list.level})})}return o}if(e.tagName==="w:tbl"){const i=await this.parseTableBlock(e,r,t);return i?[{kind:"block",block:i}]:[]}if(e.tagName==="w:
|
|
331
|
-
length;n++)i.push(...await this.parseBodyChild(e.children[n],r,t));return i}if(!
|
|
332
|
-
return[]}static codeBlockFromStyledParagraph(e){const r=e.styleId;if(!r||!r.startsWith(this.CODE_BLOCK_STYLE_ID))return;const t=r.slice(this.CODE_BLOCK_STYLE_ID.length);
|
|
333
|
-
return;const i=t.startsWith("_")?t.slice(1):void 0,n=e.children.filter(a=>a.type==="text").map(a=>a.text).join("");return{type:"code",id:e.id??this.generateId(),content:n
|
|
334
|
-
if(e.styleId||r.heading)return;const t=e.children[0];if(!t||t.type!=="text")return;const i=this.TODO_MARKERS.find(([s])=>t.text.startsWith(s));if(!i)
|
|
335
|
-
0?[{...t,text:n}]:[],...e.children.slice(1)].filter(s=>s.type==="text");a.length===0&&a.push({type:"text",text:""});const o=Math.max(0,Math.round(
|
|
336
|
-
kind:"list-item",list:{numId:"revise-todo",level:o,variant:"todo",lineSpacing:r.lineSpacing,spaceBefore:r.spaceBefore,spaceAfter:r.spaceAfter,
|
|
337
|
-
e,{type:"list-item",id:this.generateId(),children:a,lineSpacing:r.lineSpacing,spaceBefore:r.spaceBefore,spaceAfter:r.spaceAfter,indentLevel:o
|
|
338
|
-
__pilcrowMove;t&&(r.__pilcrowMove=t);const i=e.__pilcrowRevision;i&&(r.__pilcrowRevision=i);const n=e.__propertyChange;return n&&(r.__propertyChange=
|
|
339
|
-
let i=[];const n=(a=!1)=>{if(i.length===0&&!a)return;const o={type:"paragraph",id:this.generateId(),children:i.length>0?i:[{type:"text",text:"",
|
|
340
|
-
(o.leftIndent=r.leftIndent),r.firstLineIndent!==void 0&&(o.firstLineIndent=r.firstLineIndent),r.heading&&(o.heading=r.heading),r.lineSpacing!==
|
|
341
|
-
o,r),r.keepNext&&(o.keepNext=!0),r.keepLines&&(o.keepLines=!0),r.widowControl===!1&&(o.widowControl=!1),r.bordersJson&&(o.borders=r.
|
|
342
|
-
toLowerCase()!=="normal"&&(o.styleId=s),r.tabStops&&r.tabStops.length&&(o.tabStops=JSON.stringify(r.tabStops));const l=this.directionAttrFor(
|
|
343
|
-
push(o),i=[]};for(const a of e){if(a.kind==="text"){i.push(a.node);continue}if(a.kind==="pagebreak"){n(),t.push(this.createPageBreakBlock());
|
|
344
|
-
n(),t.push(a.node)}return t.length===0&&i.length===0?n(!0):n(),t}static resolveParagraphProperties(e,r,t){if(!t)return this.parseWordParagraphProperties(
|
|
345
|
-
getDirectChild(i||e,"w:pStyle")?.getAttribute("w:val")||void 0,a={isList:!1,styleId:n},o=this.effectiveParagraphStyleId(n,t.styles),s=[];t.styles.paragraphDefault&&
|
|
346
|
-
push(...this.resolveStyleChainPPr(o,t.styles,"paragraph")),i&&s.push(i);const l=this.resolveParagraphFontSizePx(i,o,t);for(const c of s)this.applyParagraphPropertiesFromElement(
|
|
347
|
-
resolveLogicalAlignment(a),a}static lineSpacingFromDocxSpacing(e,r,t){const i=(r||"auto").trim().toLowerCase();if(i!=="exact"&&i!=="atleast")return Math.round(e/240*100)/100;const n=t&&
|
|
348
|
-
a=e/20*(4/3),o=Math.round(a/n*100)/100;return i==="atleast"?o>
|
|
349
|
-
const i=e?this.getDirectChild(e,"w:rPr"):void 0,n=this.resolveRunMarks(i,r,t);return typeof n.fontSize=="number"&&n.fontSize>0?n.fontSize:Ae.paragraph}static resolveStyleChainPPr(e,r,t){
|
|
350
|
-
resolveStyleChain(e,r,t).map(i=>i.pPr).filter(Boolean):[]}static resolveStyleChainRPr(e,r,t){return e?this.resolveStyleChain(e,r,t).map(i=>i.rPr).filter(Boolean):[]}static resolveStyleChain(e,r,t){
|
|
351
|
-
n=new Set;let a=r.stylesById.get(e);for(;a&&!n.has(a.id);)n.add(a.id),(!t||a.type===t)&&i.unshift(a),a=a.basedOn?r.stylesById.get(a.basedOn):void 0;return i}static applyParagraphPropertiesFromElement(e,r,t,i,n){
|
|
333
|
+
indentLevel:c.list.level,...s.heading?{heading:s.heading}:{}})})}return o}if(e.tagName==="w:tbl"){const i=await this.parseTableBlock(e,r,t);return i?[{kind:"block",block:i}]:[]}if(e.tagName==="w:custo\
|
|
334
|
+
mXml"){const i=[];for(let n=0;n<e.children.length;n++)i.push(...await this.parseBodyChild(e.children[n],r,t));return i}if(!Kr.has(e.tagName))try{return[{kind:"block",block:{type:"docx-raw",id:this.generateId(),
|
|
335
|
+
origin:"body",...lr(e)}}]}catch{}return[]}static codeBlockFromStyledParagraph(e){const r=e.styleId;if(!r||!r.startsWith(this.CODE_BLOCK_STYLE_ID))return;const t=r.slice(this.CODE_BLOCK_STYLE_ID.length);
|
|
336
|
+
if(t.length>0&&!t.startsWith("_"))return;const i=t.startsWith("_")?t.slice(1):void 0,n=e.children.filter(a=>a.type==="text").map(a=>a.text).join("");return{type:"code",id:e.id??this.generateId(),content:n,
|
|
337
|
+
...i?{language:i}:{}}}static todoItemFromParagraph(e,r){if(e.styleId||r.heading)return;const t=e.children[0];if(!t||t.type!=="text")return;const i=this.TODO_MARKERS.find(([s])=>t.text.startsWith(s));if(!i)
|
|
338
|
+
return;const n=t.text.slice(i[0].length),a=[...n.length>0?[{...t,text:n}]:[],...e.children.slice(1)].filter(s=>s.type==="text");a.length===0&&a.push({type:"text",text:""});const o=Math.max(0,Math.round(
|
|
339
|
+
Number(e.leftIndent??0)>0?Number(e.leftIndent)-1:0));return{kind:"list-item",list:{numId:"revise-todo",level:o,variant:"todo",lineSpacing:r.lineSpacing,spaceBefore:r.spaceBefore,spaceAfter:r.spaceAfter,
|
|
340
|
+
contextualSpacing:r.contextualSpacing},item:this.carryPilcrowMove(e,{type:"list-item",id:this.generateId(),children:a,lineSpacing:r.lineSpacing,spaceBefore:r.spaceBefore,spaceAfter:r.spaceAfter,indentLevel:o,
|
|
341
|
+
...i[1]?{checked:!0}:{}})}}static carryPilcrowMove(e,r){const t=e.__pilcrowMove;t&&(r.__pilcrowMove=t);const i=e.__pilcrowRevision;i&&(r.__pilcrowRevision=i);const n=e.__propertyChange;return n&&(r.__propertyChange=
|
|
342
|
+
n),r}static buildBlocksFromParagraphItems(e,r){const t=[];let i=[];const n=(a=!1)=>{if(i.length===0&&!a)return;const o={type:"paragraph",id:this.generateId(),children:i.length>0?i:[{type:"text",text:"",
|
|
343
|
+
marks:{}}]};r.align&&(o.align=r.align),r.leftIndent!==void 0&&(o.leftIndent=r.leftIndent),r.firstLineIndent!==void 0&&(o.firstLineIndent=r.firstLineIndent),r.heading&&(o.heading=r.heading),r.lineSpacing!==
|
|
344
|
+
void 0&&(o.lineSpacing=r.lineSpacing),this.applyDocxParagraphSpacing(o,r),r.keepNext&&(o.keepNext=!0),r.keepLines&&(o.keepLines=!0),r.widowControl===!1&&(o.widowControl=!1),r.bordersJson&&(o.borders=r.
|
|
345
|
+
bordersJson),r.shading&&(o.shading=r.shading);const s=r.styleId;s&&s.toLowerCase()!=="normal"&&(o.styleId=s),r.tabStops&&r.tabStops.length&&(o.tabStops=JSON.stringify(r.tabStops));const l=this.directionAttrFor(
|
|
346
|
+
r.direction,this.paragraphNodeText(o));l&&(o.direction=l),t.push(o),i=[]};for(const a of e){if(a.kind==="text"){i.push(a.node);continue}if(a.kind==="pagebreak"){n(),t.push(this.createPageBreakBlock());
|
|
347
|
+
continue}if(a.kind==="blocks"){n(),t.push(...a.blocks);continue}n(),t.push(a.node)}return t.length===0&&i.length===0?n(!0):n(),t}static resolveParagraphProperties(e,r,t){if(!t)return this.parseWordParagraphProperties(
|
|
348
|
+
e,r);const i=this.getDirectChild(e,"w:pPr"),n=this.getDirectChild(i||e,"w:pStyle")?.getAttribute("w:val")||void 0,a={isList:!1,styleId:n},o=this.effectiveParagraphStyleId(n,t.styles),s=[];t.styles.paragraphDefault&&
|
|
349
|
+
s.push(t.styles.paragraphDefault),s.push(...this.resolveStyleChainPPr(o,t.styles,"paragraph")),i&&s.push(i);const l=this.resolveParagraphFontSizePx(i,o,t);for(const c of s)this.applyParagraphPropertiesFromElement(
|
|
350
|
+
a,c,r,t,l);return this.resolveLogicalAlignment(a),a}static lineSpacingFromDocxSpacing(e,r,t){const i=(r||"auto").trim().toLowerCase();if(i!=="exact"&&i!=="atleast")return Math.round(e/240*100)/100;const n=t&&
|
|
351
|
+
t>0?t:Ae.paragraph,a=e/20*(4/3),o=Math.round(a/n*100)/100;return i==="atleast"?o>gn.paragraph?o:void 0:Math.max(.1,o)}static effectiveParagraphStyleId(e,r){return e??r.defaultStyleIdByType?.get("parag\
|
|
352
|
+
raph")}static resolveParagraphFontSizePx(e,r,t){const i=e?this.getDirectChild(e,"w:rPr"):void 0,n=this.resolveRunMarks(i,r,t);return typeof n.fontSize=="number"&&n.fontSize>0?n.fontSize:Ae.paragraph}static resolveStyleChainPPr(e,r,t){
|
|
353
|
+
return e?this.resolveStyleChain(e,r,t).map(i=>i.pPr).filter(Boolean):[]}static resolveStyleChainRPr(e,r,t){return e?this.resolveStyleChain(e,r,t).map(i=>i.rPr).filter(Boolean):[]}static resolveStyleChain(e,r,t){
|
|
354
|
+
const i=[],n=new Set;let a=r.stylesById.get(e);for(;a&&!n.has(a.id);)n.add(a.id),(!t||a.type===t)&&i.unshift(a),a=a.basedOn?r.stylesById.get(a.basedOn):void 0;return i}static applyParagraphPropertiesFromElement(e,r,t,i,n){
|
|
352
355
|
if(!r)return;this.getDirectChild(r,"w:keepNext")&&(e.keepNext=this.isOn(r,"w:keepNext")),this.getDirectChild(r,"w:keepLines")&&(e.keepLines=this.isOn(r,"w:keepLines")),this.getDirectChild(r,"w:widowCo\
|
|
353
356
|
ntrol")&&(e.widowControl=this.isOn(r,"w:widowControl")),this.getDirectChild(r,"w:bidi")&&(e.direction=this.isOn(r,"w:bidi")?"rtl":"ltr"),this.parseParagraphDecoration(r,e),this.applyTabStopsFromPPr(e,
|
|
354
|
-
r),this.applyJcFromPPr(e,r);const a=this.getDirectChild(r,"w:ind");if(a){const
|
|
355
|
-
|
|
356
|
-
v>0)e.firstLineIndent=-1;else if(b===0)e.firstLineIndent=0;else if(b!==void 0&&b>0){const y=
|
|
357
|
-
parseOnOffElement(this.getDirectChild(r,"w:pageBreakBefore"));o!==void 0&&(e.pageBreakBefore=o);const s=this.getDirectChild(r,"w:spacing"),l=s?.getAttribute("w:line");if(l){const
|
|
358
|
-
isFinite(
|
|
357
|
+
r),this.applyJcFromPPr(e,r);const a=this.getDirectChild(r,"w:ind");if(a){const m=this.parseTwipsAttribute(a,"w:start")??this.parseTwipsAttribute(a,"w:left");if(m===0)e.leftIndent=0;else if(m!==void 0&&
|
|
358
|
+
m>0){const y=Ft(this.twipsToPx(m),{indentStepPx:t,storedAsUnits:!1});y!==void 0&&(e.leftIndent=y)}const b=this.parseTwipsAttribute(a,"w:firstLine"),v=this.parseTwipsAttribute(a,"w:hanging");if(v!==void 0&&
|
|
359
|
+
v>0)e.firstLineIndent=-1;else if(b===0)e.firstLineIndent=0;else if(b!==void 0&&b>0){const y=Ft(this.twipsToPx(b),{indentStepPx:t,storedAsUnits:!1,firstLine:!0});y!==void 0&&(e.firstLineIndent=y)}}const o=this.
|
|
360
|
+
parseOnOffElement(this.getDirectChild(r,"w:pageBreakBefore"));o!==void 0&&(e.pageBreakBefore=o);const s=this.getDirectChild(r,"w:spacing"),l=s?.getAttribute("w:line");if(l){const m=parseInt(l,10);if(Number.
|
|
361
|
+
isFinite(m)&&m>0){const b=this.lineSpacingFromDocxSpacing(m,s?.getAttribute("w:lineRule"),n);b!==void 0&&(e.lineSpacing=b)}}const c=m=>Math.max(0,Math.round(this.twipsToPx(m)*100)/100),p=this.parseTwipsAttribute(
|
|
359
362
|
s,"w:before");p!==void 0&&(e.spaceBefore=c(p));const h=this.parseTwipsAttribute(s,"w:after");h!==void 0&&(e.spaceAfter=c(h)),this.getDirectChild(r,"w:contextualSpacing")&&(e.contextualSpacing=this.isOn(
|
|
360
|
-
r,"w:contextualSpacing"));const
|
|
361
|
-
tyle")?.getAttribute("w:val");if(w){e.styleId=w;const
|
|
362
|
-
mPr"):void 0;if(u&&i){const
|
|
363
|
-
if(b
|
|
364
|
-
|
|
365
|
-
i[1],10)}}static resolveListInfo(e,r,t){const i=t.nums.get(e),n=i?.abstractNumId?t.abstractNums.get(i.abstractNumId):void 0,a=n?.levels.get(r);if(!a)return;const o=(a.format||"").
|
|
366
|
-
|
|
367
|
-
format?{numFmt:
|
|
368
|
-
has(0)??!1,formatSpec:l}}static async parseHyperlinkItems(e,r,t){const i=e.getAttribute("r:id"),n=e.getAttribute("w:anchor"),a=(i?t?.relationships.get(i)?.target:void 0)||(n?`#${n}`:
|
|
369
|
-
e.children.length;s++){const l=e.children[s];if(!(this.trackBookmarkMarker(l,t)||this.trackOxmlRangeMarker(l,t))){if(l.tagName==="w:ins"||l.tagName==="w:del"){const c=await this.
|
|
370
|
-
l,r,t),p=h=>{const
|
|
371
|
-
{...f,link:a}))}catch{}return
|
|
372
|
-
return e?.trim()===Ct?{suggestionSource:"agent",suggestionAuthorType:"ai"}:{suggestionSource:"manual",suggestionAuthorType:"human"}}static indexImportedMoveRanges(e){
|
|
373
|
-
i=(a,o)=>{const s=a?.getAttribute("w:name")?.trim(),l=a?.getAttribute("w:id")?.trim();if(!a||!s||!l)return;const c=a.getAttribute("w:date"),p=c?Date.parse(c):NaN;
|
|
374
|
-
|
|
375
|
-
const o=n[a],s=o.tagName==="w:moveFromRangeStart"?"from":o.tagName==="w:moveToRangeStart"?"to":void 0;if(s){const p=i(o,s);p&&t[s].push(p);continue}const l=o.tagName===
|
|
376
|
-
"w:moveTo"?"to":void 0;if(l){let p=t[l][t[l].length-1];const h=o.parentElement,
|
|
377
|
-
getElementsByTagName(l==="from"?"w:moveFromRangeStart":"w:moveToRangeStart")[0],l));const f=o.getAttribute("w:id")?.trim();p&&f&&r.set(o,{...p,wrapperId:f,fallbackSuggestionId
|
|
378
|
-
const c=o.tagName==="w:moveFromRangeEnd"?"from":o.tagName==="w:moveToRangeEnd"?"to":void 0;if(c){const p=o.getAttribute("w:id")?.trim(),h=t[c],
|
|
379
|
-
splice(
|
|
380
|
-
rangeId!="string"||!r.rangeId||typeof r.wrapperId!="string"||!r.wrapperId||typeof r.fallbackSuggestionId!="string"||!r.fallbackSuggestionId?void 0:r}catch{return}}static finalizeImportedMovePairs(e){
|
|
381
|
-
t=i=>{if(!i||typeof i!="object")return;if(Array.isArray(i)){i.forEach(t);return}const n=i;if(n.type==="text"&&n.marks?.docxMove){const a=this.parseDocxMoveMark(n.marks.docxMove);if(a){
|
|
382
|
-
name)??{roles:new Set,nodes:[]};o.roles.add(a.role),o.nodes.push(n),r.set(a.name,o)}}t(n.children)};t(e);for(const i of r.values())if(!(i.roles.has("from")&&i.roles.has("to")))for(const n of i.
|
|
383
|
-
const a=this.parseDocxMoveMark(n.marks?.docxMove);!a||!n.marks||(n.marks.suggestionId=a.fallbackSuggestionId,delete n.marks.docxMove)}}static hasDocxMoveMarks(e){if(!e||typeof e!="object")return!1;
|
|
384
|
-
isArray(e))return e.some(t=>this.hasDocxMoveMarks(t));const r=e;return!!r.marks?.docxMove||this.hasDocxMoveMarks(r.children)}static applyTabStopsFromPPr(e,r){const t=this.getDirectChild(r,"w
|
|
385
|
-
return;const i=e.tabStops?[...e.tabStops]:[];for(let n=0;n<t.children.length;n++){const a=t.children[n];if(a.tagName!=="w:tab")continue;const o=parseFloat(a.getAttribute("w:pos")||"");if(!Number.
|
|
386
|
-
o)||o<0)continue;const s=this.twipsToPx(o),l=i.findIndex(f=>Math.abs(f.pos-s)<.5);l>=0&&i.splice(l,1);const c=(a.getAttribute("w:val")||"left").toLowerCase();if(c==="clear")continue;let p;if(c===
|
|
387
|
-
|
|
388
|
-
:leader")||"").toLowerCase();
|
|
389
|
-
0?e.tabStops=i:delete e.tabStops}static parseParagraphDecoration(e,r){const t=this.getDirectChild(e,"w:pBdr");if(t){let n={};if(r.bordersJson)try{n=JSON.parse(r.bordersJson)}catch{n={}}for(const a of[
|
|
363
|
+
r,"w:contextualSpacing"));const g=this.getDirectChild(r,"w:outlineLvl")?.getAttribute("w:val"),f=g?parseInt(g,10):NaN;Number.isFinite(f)&&f>=0&&f<6&&(e.heading=f+1);const w=this.getDirectChild(r,"w:pS\
|
|
364
|
+
tyle")?.getAttribute("w:val");if(w){e.styleId=w;const m=i?this.headingLevelForStyle(i.styles.stylesById.get(w)):this.headingLevelForStyle({id:w});m&&(e.heading=m)}const u=i?this.getDirectChild(r,"w:nu\
|
|
365
|
+
mPr"):void 0;if(u&&i){const m=this.getDirectChild(u,"w:ilvl"),b=this.getDirectChild(u,"w:numId")?.getAttribute("w:val"),v=m?.getAttribute("w:val"),y=v&&Number.isFinite(parseInt(v,10))?parseInt(v,10):0;
|
|
366
|
+
if(b==="0")delete e.list,e.isList=!1;else if(b){const T=this.resolveListInfo(b,y,i.numbering);T&&(e.list={...T,lineSpacing:e.lineSpacing,spaceBefore:e.spaceBefore,spaceAfter:e.spaceAfter,contextualSpacing:e.
|
|
367
|
+
contextualSpacing},e.isList=!0)}}}static headingLevelForStyle(e){if(!e)return;const r=[e.id,e.name].filter(Boolean).map(t=>t.toLowerCase().replace(/[\s_-]+/g,""));for(const t of r){const i=t.match(/heading([1-6])$/);
|
|
368
|
+
if(i)return parseInt(i[1],10)}}static resolveListInfo(e,r,t){const i=t.nums.get(e),n=i?.abstractNumId?t.abstractNums.get(i.abstractNumId):void 0,a=n?.levels.get(r);if(!a)return;const o=(a.format||"").
|
|
369
|
+
toLowerCase()==="bullet"?"unordered":"ordered",s=i?.levelStartOverrides.get(r)??a.start;let l;if(o==="ordered"&&n){const c=[];let p=!1;for(let h=0;h<=2;h++){const g=n.levels.get(h);(g?.format||g?.text)&&
|
|
370
|
+
(p=!0),c.push({...g?.format?{numFmt:g.format}:{},...g?.text?{lvlText:g.text}:{}})}p&&(l=JSON.stringify(c))}return{numId:e,level:r,variant:o,startNumber:s,abstractNumId:i?.abstractNumId,hasLevel0StartOverride:i?.
|
|
371
|
+
levelStartOverrides.has(0)??!1,formatSpec:l}}static async parseHyperlinkItems(e,r,t){const i=e.getAttribute("r:id"),n=e.getAttribute("w:anchor"),a=(i?t?.relationships.get(i)?.target:void 0)||(n?`#${n}`:
|
|
372
|
+
void 0),o=[];for(let s=0;s<e.children.length;s++){const l=e.children[s];if(!(this.trackBookmarkMarker(l,t)||this.trackOxmlRangeMarker(l,t))){if(l.tagName==="w:ins"||l.tagName==="w:del"){const c=await this.
|
|
373
|
+
parseTrackedChangeItems(l,r,t),p=h=>{const g={...h,link:h?.link??a};if(g.suggestionPriorAttributes)try{const f=JSON.parse(g.suggestionPriorAttributes);f&&typeof f=="object"&&!f.link&&(g.suggestionPriorAttributes=
|
|
374
|
+
JSON.stringify({...f,link:a}))}catch{}return g};o.push(...c.map(h=>h.kind==="text"&&a?{...h,node:{...h.node,marks:p(h.node.marks)}}:h));continue}l.tagName==="w:r"&&o.push(...await this.parseWordRunItems(
|
|
375
|
+
l,r,t,a))}}return o}static revisionAuthorIdentity(e){return e?.trim()===Ct?{suggestionSource:"agent",suggestionAuthorType:"ai"}:{suggestionSource:"manual",suggestionAuthorType:"human"}}static indexImportedMoveRanges(e){
|
|
376
|
+
const r=new WeakMap,t={from:[],to:[]},i=(a,o)=>{const s=a?.getAttribute("w:name")?.trim(),l=a?.getAttribute("w:id")?.trim();if(!a||!s||!l)return;const c=a.getAttribute("w:date"),p=c?Date.parse(c):NaN;
|
|
377
|
+
return{version:1,name:s,role:o,rangeId:l,...a.getAttribute("w:author")?.trim()?{rangeAuthor:a.getAttribute("w:author").trim()}:{},...Number.isFinite(p)?{rangeCreatedAt:p}:{}}},n=Array.from(e.getElementsByTagName(
|
|
378
|
+
"*"));for(let a=0;a<n.length;a++){const o=n[a],s=o.tagName==="w:moveFromRangeStart"?"from":o.tagName==="w:moveToRangeStart"?"to":void 0;if(s){const p=i(o,s);p&&t[s].push(p);continue}const l=o.tagName===
|
|
379
|
+
"w:moveFrom"?"from":o.tagName==="w:moveTo"?"to":void 0;if(l){let p=t[l][t[l].length-1];const h=o.parentElement,g=h?.parentElement;!p&&h?.tagName==="w:rPr"&&g?.tagName==="w:pPr"&&g.parentElement?.tagName===
|
|
380
|
+
"w:p"&&(p=i(g.parentElement.getElementsByTagName(l==="from"?"w:moveFromRangeStart":"w:moveToRangeStart")[0],l));const f=o.getAttribute("w:id")?.trim();p&&f&&r.set(o,{...p,wrapperId:f,fallbackSuggestionId:`\
|
|
381
|
+
docxrev-${f}`});continue}const c=o.tagName==="w:moveFromRangeEnd"?"from":o.tagName==="w:moveToRangeEnd"?"to":void 0;if(c){const p=o.getAttribute("w:id")?.trim(),h=t[c],g=p?h.map(f=>f.rangeId).lastIndexOf(
|
|
382
|
+
p):h.length-1;g>=0&&h.splice(g,1)}}return r}static parseDocxMoveMark(e){if(!(typeof e!="string"||!e))try{const r=JSON.parse(e);return r.version!==1||typeof r.name!="string"||!r.name||r.role!=="from"&&
|
|
383
|
+
r.role!=="to"||typeof r.rangeId!="string"||!r.rangeId||typeof r.wrapperId!="string"||!r.wrapperId||typeof r.fallbackSuggestionId!="string"||!r.fallbackSuggestionId?void 0:r}catch{return}}static finalizeImportedMovePairs(e){
|
|
384
|
+
const r=new Map,t=i=>{if(!i||typeof i!="object")return;if(Array.isArray(i)){i.forEach(t);return}const n=i;if(n.type==="text"&&n.marks?.docxMove){const a=this.parseDocxMoveMark(n.marks.docxMove);if(a){
|
|
385
|
+
const o=r.get(a.name)??{roles:new Set,nodes:[]};o.roles.add(a.role),o.nodes.push(n),r.set(a.name,o)}}t(n.children)};t(e);for(const i of r.values())if(!(i.roles.has("from")&&i.roles.has("to")))for(const n of i.
|
|
386
|
+
nodes){const a=this.parseDocxMoveMark(n.marks?.docxMove);!a||!n.marks||(n.marks.suggestionId=a.fallbackSuggestionId,delete n.marks.docxMove)}}static hasDocxMoveMarks(e){if(!e||typeof e!="object")return!1;
|
|
387
|
+
if(Array.isArray(e))return e.some(t=>this.hasDocxMoveMarks(t));const r=e;return!!r.marks?.docxMove||this.hasDocxMoveMarks(r.children)}static applyTabStopsFromPPr(e,r){const t=this.getDirectChild(r,"w:\
|
|
388
|
+
tabs");if(!t)return;const i=e.tabStops?[...e.tabStops]:[];for(let n=0;n<t.children.length;n++){const a=t.children[n];if(a.tagName!=="w:tab")continue;const o=parseFloat(a.getAttribute("w:pos")||"");if(!Number.
|
|
389
|
+
isFinite(o)||o<0)continue;const s=this.twipsToPx(o),l=i.findIndex(f=>Math.abs(f.pos-s)<.5);l>=0&&i.splice(l,1);const c=(a.getAttribute("w:val")||"left").toLowerCase();if(c==="clear")continue;let p;if(c===
|
|
390
|
+
"right"||c==="end")p="right";else if(c==="center")p="center";else if(c==="decimal")p="decimal";else if(c==="left"||c==="start"||c==="num")p="left";else continue;const h={pos:s,align:p},g=(a.getAttribute(
|
|
391
|
+
"w:leader")||"").toLowerCase();g==="dot"||g==="middledot"?h.leader="dot":g==="hyphen"?h.leader="hyphen":(g==="underscore"||g==="heavy")&&(h.leader="underscore"),i.push(h)}i.sort((n,a)=>n.pos-a.pos),i.
|
|
392
|
+
length>0?e.tabStops=i:delete e.tabStops}static parseParagraphDecoration(e,r){const t=this.getDirectChild(e,"w:pBdr");if(t){let n={};if(r.bordersJson)try{n=JSON.parse(r.bordersJson)}catch{n={}}for(const a of[
|
|
390
393
|
"top","bottom","left","right"]){const o=this.getDirectChild(t,`w:${a}`);if(!o)continue;const s=(o.getAttribute("w:val")||"single").toLowerCase();if(s==="none"||s==="nil"){n[a]={style:"none",width:0,color:"\
|
|
391
394
|
#000000"};continue}const l=["dashed","dotted","double"].includes(s)?s:"single",c=parseInt(o.getAttribute("w:sz")||"4",10),p=Math.max(.5,Math.round((Number.isFinite(c)?c:4)/6*100)/100),h=(o.getAttribute(
|
|
392
|
-
"w:color")||"auto").trim(),
|
|
395
|
+
"w:color")||"auto").trim(),g=h.toLowerCase()==="auto"?"#000000":`#${h.replace(/^#/,"")}`;n[a]={style:l,width:p,color:g}}Object.keys(n).length>0&&(r.bordersJson=JSON.stringify(n))}const i=this.getDirectChild(
|
|
393
396
|
e,"w:shd");if(i){const n=(i.getAttribute("w:fill")||"").trim(),a=(i.getAttribute("w:val")||"clear").toLowerCase();n&&n.toLowerCase()!=="auto"?r.shading=`#${n.replace(/^#/,"")}`:(!n||n.toLowerCase()===
|
|
394
397
|
"auto"||a==="nil"||a==="none")&&(r.shading="transparent")}}static trackBookmarkMarker(e,r){const t=r??this.fallbackCommentState;if(e.tagName==="w:bookmarkStart"){const i=e.getAttribute("w:id"),n=e.getAttribute(
|
|
395
398
|
"w:name");return i&&n&&n!=="_GoBack"&&((t.openBookmarkNames??(t.openBookmarkNames=new Set)).add(n),(t.bookmarkNameById??(t.bookmarkNameById=new Map)).set(i,n)),!0}if(e.tagName==="w:bookmarkEnd"){const i=e.
|
|
@@ -412,17 +415,17 @@ parseHyperlinkItems(a,r,t)):a.tagName==="w:ins"||a.tagName==="w:del"||a.tagName=
|
|
|
412
415
|
i):NaN;return{revisionId:r&&r.length>0?r:null,author:t,createdAt:Number.isFinite(n)?n:void 0}}static async parseTrackedChangeItems(e,r,t,i){const n=e.tagName==="w:ins"||e.tagName==="w:moveTo",a=e.tagName===
|
|
413
416
|
"w:moveFrom"||e.tagName==="w:moveTo",o=this.parseTrackedRevisionMeta(e),s=a?(t??this.fallbackCommentState).moveRangeByWrapper?.get(e):void 0,l=s?`docxmove-${encodeURIComponent(s.name)}`:o.revisionId?`\
|
|
414
417
|
docxrev-${o.revisionId}`:this.generateId(),c={...n?{insertion:!0}:{deletion:!0},suggestionId:l,...this.revisionAuthorIdentity(o.author),suggestionLabel:a?"Move":n?"Insert":"Delete",...o.createdAt!==void 0?
|
|
415
|
-
{suggestionCreatedAt:o.createdAt}:{},...o.author?{suggestionAuthorName:o.author}:{},...s?{docxMove:JSON.stringify(s)}:{},...!n&&i?{layeredInsertion:JSON.stringify(i)}:{}},p=
|
|
416
|
-
{...f,node:{...f.node,marks:{...f.node.marks??{},...c}}}:f),h=[];for(let
|
|
418
|
+
{suggestionCreatedAt:o.createdAt}:{},...o.author?{suggestionAuthorName:o.author}:{},...s?{docxMove:JSON.stringify(s)}:{},...!n&&i?{layeredInsertion:JSON.stringify(i)}:{}},p=g=>g.map(f=>f.kind==="text"?
|
|
419
|
+
{...f,node:{...f.node,marks:{...f.node.marks??{},...c}}}:f),h=[];for(let g=0;g<e.children.length;g++){const f=e.children[g];this.trackCommentRangeMarker(f,t)||this.trackBookmarkMarker(f,t)||this.trackOxmlRangeMarker(
|
|
417
420
|
f,t)||(f.tagName==="w:r"?h.push(...p(this.stampOpenComments(await this.parseWordRunItems(f,r,t),t))):f.tagName==="w:hyperlink"?h.push(...p(this.stampOpenComments(await this.parseHyperlinkItems(f,r,t),
|
|
418
421
|
t))):f.tagName==="w:del"&&n?h.push(...await this.parseTrackedChangeItems(f,r,t,{id:l,...(()=>{const w=this.revisionAuthorIdentity(o.author);return{source:w.suggestionSource,authorType:w.suggestionAuthorType}})(),
|
|
419
422
|
createdAt:o.createdAt,label:"Insert",authorName:o.author})):(f.tagName==="w:ins"||f.tagName==="w:del")&&h.push(...await this.parseTrackedChangeItems(f,r,t)))}return h}static async parseWordRunItems(e,r,t,i,n){
|
|
420
423
|
const a=this.getDirectChild(e,"w:rPr"),o=n?{...n}:this.resolveRunMarks(a,r.styleId,t,i);if(!n&&!r.heading&&o.fontSize===Ae.paragraph&&this.docDefaultRunSizePx(t)===Ae.paragraph&&delete o.fontSize,!n){
|
|
421
|
-
const
|
|
422
|
-
t,i);Object.assign(o,{formatChange:!0,suggestionId:
|
|
423
|
-
createdAt}:{},...
|
|
424
|
-
f=p.openBookmarkNames;f&&f.size>0&&(
|
|
425
|
-
u?.inResult&&u.instr.trim()&&(
|
|
424
|
+
const g=at(a,zr);g&&(o.oxmlRPr=g)}const s=!n&&a?this.getDirectChild(a,"w:rPrChange"):void 0;if(s){const g=this.parseTrackedRevisionMeta(s),f=this.getDirectChild(s,"w:rPr"),w=this.resolveRunMarks(f,r.styleId,
|
|
425
|
+
t,i);Object.assign(o,{formatChange:!0,suggestionId:g.revisionId?`docxrev-${g.revisionId}`:this.generateId(),...this.revisionAuthorIdentity(g.author),suggestionLabel:"Format",...g.createdAt!==void 0?{suggestionCreatedAt:g.
|
|
426
|
+
createdAt}:{},...g.author?{suggestionAuthorName:g.author}:{},suggestionPriorAttributes:JSON.stringify(w??{})})}const l=[];let c="";const p=t??this.fallbackCommentState,h=()=>{if(!c)return;const g={...o},
|
|
427
|
+
f=p.openBookmarkNames;f&&f.size>0&&(g.bookmark=[...f].sort().join(","));const w=p.openOxmlRanges;w&&w.size>0&&(g.oxmlRange=[...w.values()].map(m=>m.id).sort().join(","));const u=p.fieldInstrStack?.[0];
|
|
428
|
+
u?.inResult&&u.instr.trim()&&(g.fieldInstr=u.instr.trim()),l.push({kind:"text",node:{type:"text",text:c,marks:Object.keys(g).length>0?g:void 0}}),c=""};for(let g=0;g<e.children.length;g++){const f=e.children[g];
|
|
426
429
|
if(f.tagName==="w:t"){c+=f.textContent||"";continue}if(f.tagName==="w:fldChar"){const w=f.getAttribute("w:fldCharType"),u=p.fieldInstrStack??(p.fieldInstrStack=[]);h(),w==="begin"?u.push({instr:"",inResult:!1}):
|
|
427
430
|
w==="separate"?u.length>0&&(u[u.length-1].inResult=!0):w==="end"&&u.pop();continue}if(f.tagName==="w:instrText"){const w=p.fieldInstrStack;w&&w.length>0&&(w[w.length-1].instr+=f.textContent||"");continue}
|
|
428
431
|
if(f.tagName==="w:footnoteReference"||f.tagName==="w:endnoteReference"){const w=f.getAttribute("w:id");if(w){h();const u=f.tagName==="w:endnoteReference"?"docxen":"docxfn";l.push({kind:"text",node:{type:"\
|
|
@@ -430,31 +433,31 @@ text",text:"0",marks:{...o,footnoteRef:`${u}-${w}`,superscript:!0}}})}continue}i
|
|
|
430
433
|
(f.getAttribute("w:type")||"").trim().toLowerCase()==="page"?(h(),l.push({kind:"pagebreak"})):c+=`
|
|
431
434
|
`;continue}if(f.tagName!=="w:lastRenderedPageBreak"){if(f.tagName==="mc:AlternateContent"){h();const w=this.selectAlternateContentBranch(f);w&&l.push(...await this.parseWordRunItems(w,r,t,i,o));continue}
|
|
432
435
|
if(f.tagName==="w:drawing"){h();const w=await this.parseImageFromDrawing(f,r.align,t);w&&l.push({kind:"image",node:w});const u=await this.parseTextBoxContent(f,t);if(u.length>0&&l.push({kind:"blocks",
|
|
433
|
-
blocks:u}),!w&&u.length===0){const
|
|
436
|
+
blocks:u}),!w&&u.length===0){const m=this.rawChipFromRunChild(f);m&&l.push({kind:"blocks",blocks:[m]})}continue}if(f.tagName==="w:pict"||f.tagName==="w:object"){h();const w=f.getElementsByTagName("*");
|
|
434
437
|
let u=!1;for(let b=0;b<w.length;b++){const v=(w[b].getAttribute("o:hr")||"").toLowerCase();if(v==="t"||v==="true"||v==="1"){u=!0;break}}if(u){const b={type:"paragraph",id:this.generateId(),children:[{
|
|
435
|
-
type:"text",text:"",marks:{}}],borders:
|
|
438
|
+
type:"text",text:"",marks:{}}],borders:Oi()};l.push({kind:"blocks",blocks:[b]});continue}const m=await this.parseTextBoxContent(f,t);if(m.length>0)l.push({kind:"blocks",blocks:m});else{const b=this.rawChipFromRunChild(
|
|
436
439
|
f);b&&l.push({kind:"blocks",blocks:[b]})}continue}}}return h(),l}static rawChipFromRunChild(e){try{return{type:"docx-raw",id:this.generateId(),origin:"run",...lr(e)}}catch{return}}static async parseTextBoxContent(e,r){
|
|
437
440
|
const t=e.getElementsByTagName("w:txbxContent");if(t.length===0)return[];const i=Ee(void 0).indentStepPx,n=[];for(let a=0;a<t.length;a++){const o=t[a];let s=o.parentElement,l=!1;for(;s&&s!==e;){if(s.tagName===
|
|
438
|
-
"mc:Fallback"){const p=s.parentElement,h=p?Array.from(p.children).find(
|
|
441
|
+
"mc:Fallback"){const p=s.parentElement,h=p?Array.from(p.children).find(g=>g.tagName==="mc:Choice"):void 0;l=!!(h&&h.getElementsByTagName("w:txbxContent").length>0);break}s=s.parentElement}if(l)continue;
|
|
439
442
|
const c=(await this.parseBodyChildren(o,i,r)).filter(p=>p.type!=="paragraph"||p.children.some(h=>h.type==="text"&&h.text.trim()!==""));n.push(...c)}return n}static selectAlternateContentBranch(e){let r;
|
|
440
443
|
for(let t=0;t<e.children.length;t++){const i=e.children[t];if(i.tagName==="mc:Fallback"){r=i;continue}if(i.tagName==="mc:Choice"&&(i.getElementsByTagName("w:t").length>0||i.getElementsByTagName("w:del\
|
|
441
444
|
Text").length>0||i.getElementsByTagName("w:txbxContent").length>0||i.getElementsByTagName("a:blip").length>0))return i}return r}static resolveRunMarks(e,r,t,i){const n={};if(t){const a=[];t.styles.runDefault&&
|
|
442
445
|
a.push(t.styles.runDefault),a.push(...this.resolveStyleChainRPr(this.effectiveParagraphStyleId(r,t.styles),t.styles,"paragraph"));const o=e&&this.getDirectChild(e,"w:rStyle")?.getAttribute("w:val")||void 0;
|
|
443
446
|
a.push(...this.resolveStyleChainRPr(o,t.styles,"character")),e&&a.push(e);for(const s of a)this.applyRunPropertiesFromElement(n,s,t.themeFonts);o===this.CODE_INLINE_STYLE_ID&&(n.code=!0,/courier/i.test(
|
|
444
447
|
n.fontFamily??"")&&delete n.fontFamily,/^(light)?gray$/i.test(n.backgroundColor??"")&&delete n.backgroundColor)}else e&&this.applyRunPropertiesFromElement(n,e);return i&&(n.link=i),n}static applyRunPropertiesFromElement(e,r,t){
|
|
445
|
-
if(!r)return;const i=(y,
|
|
446
|
-
delete(y)
|
|
448
|
+
if(!r)return;const i=(y,T)=>{this.getDirectChild(r,y)&&(e[T]=this.isOn(r,y))},n=()=>new Set(e.docxRunPropertyResets?.split(",").map(y=>y.trim()).filter(Boolean)??[]),a=(y,T)=>{const L=n();T?L.add(y):L.
|
|
449
|
+
delete(y),L.size>0?e.docxRunPropertyResets=[...L].sort().join(","):delete e.docxRunPropertyResets};i("w:b","bold"),i("w:i","italic");const o=this.getDirectChild(r,"w:u");if(o){const y=(o.getAttribute(
|
|
447
450
|
"w:val")||"").toLowerCase();e.underline=!["none","0","false","off"].includes(y)}i("w:strike","strikethrough"),i("w:dstrike","doubleStrikethrough"),i("w:smallCaps","smallCaps"),i("w:caps","allCaps"),i(
|
|
448
451
|
"w:vanish","hidden");const s=this.getDirectChild(r,"w:lang")?.getAttribute("w:val");s&&(e.lang=s);const l=(this.getDirectChild(r,"w:spacing")?.getAttribute("w:val")||"").trim();if(l!==""){const y=parseInt(
|
|
449
452
|
l,10);Number.isFinite(y)&&(e.letterSpacing=Math.round(y/15*100)/100)}const c=(this.getDirectChild(r,"w:vertAlign")?.getAttribute("w:val")||"").toLowerCase();c==="superscript"?(e.superscript=!0,e.subscript=
|
|
450
453
|
!1):c==="subscript"?(e.superscript=!1,e.subscript=!0):c==="baseline"&&(e.superscript=!1,e.subscript=!1);const p=this.getDirectChild(r,"w:color"),h=p?.getAttribute("w:val");p&&h?.toLowerCase()==="auto"?
|
|
451
|
-
(delete e.color,a("color",!0)):h&&(e.color=`#${h.replace(/^#/,"")}`,a("color",!1));const
|
|
452
|
-
a("highlight",!0)):
|
|
454
|
+
(delete e.color,a("color",!0)):h&&(e.color=`#${h.replace(/^#/,"")}`,a("color",!1));const g=this.getDirectChild(r,"w:highlight")?.getAttribute("w:val");g?.toLowerCase()==="none"?(delete e.backgroundColor,
|
|
455
|
+
a("highlight",!0)):g&&(e.backgroundColor=this.highlightValueToColor(g),a("highlight",!1));const f=this.getDirectChild(r,"w:shd")?.getAttribute("w:fill");if(f&&["auto","none"].includes(f.toLowerCase()))
|
|
453
456
|
delete e.backgroundColor,a("highlight",!0);else if(f){const y=or(f);y&&(e.backgroundColor=y,a("highlight",!1))}const w=this.getDirectChild(r,"w:rFonts"),u=w?.getAttribute("w:asciiTheme")||w?.getAttribute(
|
|
454
|
-
"w:hAnsiTheme")||w?.getAttribute("w:cstheme")||w?.getAttribute("w:eastAsiaTheme"),
|
|
455
|
-
si")||w?.getAttribute("w:cs")||w?.getAttribute("w:eastAsia")||
|
|
457
|
+
"w:hAnsiTheme")||w?.getAttribute("w:cstheme")||w?.getAttribute("w:eastAsiaTheme"),m=u&&t?u.toLowerCase().startsWith("major")?t.major:t.minor:void 0,b=w?.getAttribute("w:ascii")||w?.getAttribute("w:hAn\
|
|
458
|
+
si")||w?.getAttribute("w:cs")||w?.getAttribute("w:eastAsia")||m;b&&(e.fontFamily=b);const v=this.getDirectChild(r,"w:sz")?.getAttribute("w:val");if(v){const y=parseInt(v,10);Number.isFinite(y)&&y>0&&(e.
|
|
456
459
|
fontSize=Math.max(1,Math.round(y*(2/3)*100)/100))}}static collectTextlessMoveHalves(e){const r=this.exportLinkedMoveSides,t=s=>{const l=s;let c,p,h=!1;return this.UNTRACKABLE_MOVE_KINDS.has(s.type)?(c=
|
|
457
|
-
l.diffState,p=l.suggestionId,h=!0):s.type==="paragraph"&&s.children.every(
|
|
460
|
+
l.diffState,p=l.suggestionId,h=!0):s.type==="paragraph"&&s.children.every(g=>g.type==="text"&&g.text==="")&&(c=l.structuralSuggestionKind??l.diffState,p=l.structuralSuggestionId??l.suggestionId),c!=="\
|
|
458
461
|
insert"&&c!=="delete"||!p||!h&&r?.has(p)?null:{kind:c,id:p}},i=s=>{const l={};for(const[c,p]of Object.entries(s))c==="id"||c==="diffState"||c==="suggestionId"||c.startsWith("structuralSuggestion")||(l[c]=
|
|
459
462
|
p);return JSON.stringify(l)},n=new Map;for(const s of e){const l=t(s);if(l?.kind!=="delete")continue;const c=`${l.id}\0${i(s)}`;n.set(c,[...n.get(c)??[],s])}const a=new Set,o=new Set;for(const s of e){
|
|
460
463
|
const l=t(s);if(l?.kind!=="insert")continue;const c=n.get(`${l.id}\0${i(s)}`)?.shift();c&&(a.add(s.id),o.add(c.id))}return{destinations:a,sources:o}}static withoutMoveState(e){const r={};for(const[t,i]of Object.
|
|
@@ -464,89 +467,89 @@ isArray(i)){i.forEach(t);return}const n=i,a=n.marks;if(n.type==="text"&&a?.docxM
|
|
|
464
467
|
o.rangeCreatedAt).toISOString():l.date}}r.set(a.suggestionId,s)}}t(n.children)};t(e);for(const[i,n]of r)(!n.from||!n.to)&&r.delete(i);return r}static linkedMoveSideFor(e,r){if(typeof e!="string")return;
|
|
465
468
|
const t=r==="delete"?"from":r==="insert"?"to":void 0;return t?this.exportLinkedMoveSides?.get(e)?.[t]:void 0}static collectLinkedMoveBlockIds(e,r){const t=new Map;if(r.size===0)return t;const i=o=>o===
|
|
466
469
|
"delete"?"from":o==="insert"?"to":void 0,n=new Map,a=o=>{const s=n.get(o);if(n.delete(o),!s?.marked)return;const l=t.get(o)??new Set;s.ids.forEach(c=>l.add(c)),t.set(o,l)};for(const o of e){const s=new Set,
|
|
467
|
-
l=new Set,c=[],p=h=>{if(!h||typeof h!="object")return;if(Array.isArray(h)){h.forEach(p);return}const
|
|
468
|
-
"string"&&f&&s.add(`${
|
|
469
|
-
suggestionId=="string"){const
|
|
470
|
-
p(o);for(const h of Array.from(n.keys()))s.has(h)||a(h);for(const h of s){const
|
|
470
|
+
l=new Set,c=[],p=h=>{if(!h||typeof h!="object")return;if(Array.isArray(h)){h.forEach(p);return}const g=h;typeof g.id=="string"&&c.push(g.id);const f=i(g.structuralSuggestionKind);typeof g.structuralSuggestionId==
|
|
471
|
+
"string"&&f&&s.add(`${g.structuralSuggestionId}\0${f}`);const w=i(g.diffState);typeof g.suggestionId=="string"&&w&&s.add(`${g.suggestionId}\0${w}`);const u=g.marks;if(g.type==="text"&&u?.docxMove&&typeof u.
|
|
472
|
+
suggestionId=="string"){const m=this.parseDocxMoveMark(u.docxMove);if(m&&(m.role==="from"&&u.deletion||m.role==="to"&&u.insertion)){const b=`${u.suggestionId}\0${m.role}`;s.add(b),l.add(b)}}p(g.children)};
|
|
473
|
+
p(o);for(const h of Array.from(n.keys()))s.has(h)||a(h);for(const h of s){const g=n.get(h)??{marked:!1,ids:[]};g.marked||(g.marked=l.has(h)),g.ids.push(...c),n.set(h,g)}}for(const o of Array.from(n.keys()))
|
|
471
474
|
a(o);return t}static isInLinkedMoveRange(e,r){return!this.exportLinkedMoveBlockIds||typeof e.id!="string"?!0:this.exportLinkedMoveBlockIds.get(`${e.structuralSuggestionId}\0${r}`)?.has(e.id)??!1}static inferDefaultRunSizeHalfPoints(e){
|
|
472
475
|
const r=e.stylesheet?.paragraphStyles.find(t=>t.default)?.runMarks?.fontSize;return typeof r=="number"&&r>0&&r!==Ae.paragraph?this.DEFAULT_RUN_SIZE_HALF_POINTS:void 0}static docDefaultRunSizePx(e){const r=e?.
|
|
473
476
|
styles.runDefault;if(!r)return;const t=this.getDirectChild(r,"w:sz")?.getAttribute("w:val"),i=t?parseInt(t,10):NaN;return Number.isFinite(i)&&i>0?Math.max(1,Math.round(i*(2/3)*100)/100):void 0}static isOnAttribute(e){
|
|
474
477
|
const r=(e||"").trim().toLowerCase();return r==="1"||r==="true"||r==="on"}static isOn(e,r){const t=this.getDirectChild(e,r);if(!t)return!1;const i=(t.getAttribute("w:val")||"").toLowerCase();return i!==
|
|
475
478
|
"false"&&i!=="0"&&i!=="off"}static async parseImageFromDrawing(e,r,t){if(!t)return null;const i=e.getElementsByTagName("a:blip")[0],n=i?.getAttribute("r:embed")||i?.getAttribute("r:link")||"";if(!n)return null;
|
|
476
|
-
const a=t.relationships.get(n);if(!a)return null;const o=i?this.findSvgBlipRelationshipId(i):void 0;let s,l;if(o){const
|
|
477
|
-
nt8array"),l="image/svg+xml")}if(!s||!l){const
|
|
479
|
+
const a=t.relationships.get(n);if(!a)return null;const o=i?this.findSvgBlipRelationshipId(i):void 0;let s,l;if(o){const T=t.relationships.get(o),L=T?t.zip.file(T.target):void 0;L&&(s=await L.async("ui\
|
|
480
|
+
nt8array"),l="image/svg+xml")}if(!s||!l){const T=t.zip.file(a.target);if(!T)return null;s=await T.async("uint8array"),l=this.getContentTypeForPart(a.target,t.contentTypes)||this.inferImagePartMimeType(
|
|
478
481
|
a.target)}if(!s)return null;const c=l?this.vectorFormatForMimeType(l):void 0;if(!c&&(!l||!this.isSupportedImageMimeType(l)))return null;const p=e.getElementsByTagName("wp:extent")[0]||e.getElementsByTagName(
|
|
479
|
-
"a:ext")[0],h=p?.getAttribute("cx"),
|
|
480
|
-
|
|
481
|
-
height:w,alt:
|
|
482
|
+
"a:ext")[0],h=p?.getAttribute("cx"),g=p?.getAttribute("cy"),f=h?Math.max(1,Math.round(parseInt(h,10)/9525)):200,w=g?Math.max(1,Math.round(parseInt(g,10)/9525)):200,u=e.getElementsByTagName("wp:docPr")[0],
|
|
483
|
+
m=u?.getAttribute("descr")||u?.getAttribute("title")||u?.getAttribute("name")||void 0,b=this.buildImageDataUrl(s,c?c==="emf"?"image/x-emf":"image/x-wmf":l),v={type:"image",id:this.generateId(),src:b,width:f,
|
|
484
|
+
height:w,alt:m,align:r&&r!=="justify"?r:void 0};c&&(v.originalFormat=c,v.originalDataUrl=b);const y=this.getDirectChild(e,"wp:anchor");if(y)try{v.anchorXml=this.serializeXmlPreservingPrefixes(y)}catch{}
|
|
482
485
|
return v}static findSvgBlipRelationshipId(e){const r=e.getElementsByTagName("*");for(let t=0;t<r.length;t++){const i=r[t],n=i.tagName||"";if(n==="svgBlip"||n.endsWith(":svgBlip"))return i.getAttribute(
|
|
483
486
|
"r:embed")||i.getAttribute("r:link")||void 0}}static inferImagePartMimeType(e){const r=e.split(".").pop()?.toLowerCase();switch(r){case"svg":return"image/svg+xml";case"emf":return"image/x-emf";case"wm\
|
|
484
487
|
f":return"image/x-wmf";default:return r?this.inferMimeTypeFromPath(e):void 0}}static vectorFormatForMimeType(e){const r=e.toLowerCase();if(r==="image/x-emf"||r==="image/emf")return"emf";if(r==="image/\
|
|
485
|
-
x-wmf"||r==="image/wmf")return"wmf"}static async parseTableBlock(e,r,t){const i=[],n=[],a=[],o=(
|
|
486
|
-
|
|
487
|
-
serializeToString(be),trIndexes:[]},a.push(
|
|
488
|
-
p=this.getDirectChild(e,"w:tblGrid"),h=p?this.getDirectChild(p,"w:tblGridChange"):void 0,
|
|
489
|
-
if(
|
|
490
|
-
[]},u=[],
|
|
491
|
-
serializeToString(
|
|
492
|
-
xChange"):void 0,be=
|
|
493
|
-
getDirectChild(de,"w:trPrChange"):void 0,et=fe?this.getDirectChild(fe,"w:trPr"):void 0;if(ve){const we=this.parseTrackedRevisionMeta(ve);u.push({rowId:
|
|
494
|
-
parseTrackedRevisionMeta(Se);u.push({rowId:
|
|
495
|
-
de,new Set(["w:ins","w:del","w:trPrChange"])),priorXml:new XMLSerializer().serializeToString(et),...
|
|
496
|
-
tableHeaderAttributesFromRowProperties(et)}:{}}),q&&
|
|
497
|
-
ExChange"])),priorXml:new XMLSerializer().serializeToString(be)});const ie=[];let he=0;const
|
|
498
|
-
tagName==="w:sdt"){const ce=this.getDirectChild(Pe,"w:sdtContent");if(!ce)continue;let De;if(this.importSdtWrappers){const
|
|
499
|
-
serializeToString(
|
|
500
|
-
el,ce=this.getDirectChild(Pe,"w:tcPr"),De=this.getDirectChild(ce||Pe,"w:shd")?.getAttribute("w:fill"),
|
|
501
|
-
isFinite(Nt)?Math.min(Math.max(1,Nt),1e3):1,tt=ce?this.getDirectChild(ce,"w:cellIns"):void 0,ft=ce?this.getDirectChild(ce,"w:cellDel"):void 0,
|
|
488
|
+
x-wmf"||r==="image/wmf")return"wmf"}static async parseTableBlock(e,r,t){const i=[],n=[],a=[],o=(k,j)=>{for(const G of Array.from(k.children))if(G.tagName==="w:tr")j&&j.trIndexes.push(n.length),n.push(
|
|
489
|
+
G);else if(G.tagName==="w:sdt"){const q=this.getDirectChild(G,"w:sdtContent");if(q){let Z=j;if(this.importSdtWrappers&&!j){const be=this.getDirectChild(G,"w:sdtPr");if(be)try{Z={prXml:new XMLSerializer().
|
|
490
|
+
serializeToString(be),trIndexes:[]},a.push(Z)}catch{Z=j}}o(q,Z)}}};o(e);const s=this.getDirectChild(e,"w:tblPr"),l=s?this.getDirectChild(s,"w:tblCellMar"):void 0,c=l?this.nonUniformCellMarginJson(l):void 0,
|
|
491
|
+
p=this.getDirectChild(e,"w:tblGrid"),h=p?this.getDirectChild(p,"w:tblGridChange"):void 0,g=h?this.getDirectChild(h,"w:tblGrid"):void 0,f=k=>{if(!k)return[];const j=[];for(const G of Array.from(k.children)){
|
|
492
|
+
if(G.tagName!=="w:gridCol")continue;const q=Number(G.getAttribute("w:w"));Number.isFinite(q)&&q>0&&j.push(q)}return j},w=k=>{const j=f(k),G=j.reduce((q,Z)=>q+Z,0);return G>0?j.map(q=>Math.round(q/G*100)):
|
|
493
|
+
[]},u=[],m=[],b=[],v=[],y=[],T=[],L=[],W=s?this.getDirectChild(s,"w:tblPrChange"):void 0,X=W?this.getDirectChild(W,"w:tblPr"):void 0,D=W?this.parseTrackedRevisionMeta(W):null;let M;if(X)try{M=new XMLSerializer().
|
|
494
|
+
serializeToString(X)}catch{M=void 0}const O=new Map,I=new Map,B=[];for(let k=0;k<n.length;k++){const j=n[k],G=this.generateId(),q=this.getDirectChild(j,"w:tblPrEx"),Z=q?this.getDirectChild(q,"w:tblPrE\
|
|
495
|
+
xChange"):void 0,be=Z?this.getDirectChild(Z,"w:tblPrEx"):void 0,de=this.getDirectChild(j,"w:trPr"),ve=de?this.getDirectChild(de,"w:ins"):void 0,Se=de?this.getDirectChild(de,"w:del"):void 0,fe=de?this.
|
|
496
|
+
getDirectChild(de,"w:trPrChange"):void 0,et=fe?this.getDirectChild(fe,"w:trPr"):void 0;if(ve){const we=this.parseTrackedRevisionMeta(ve);u.push({rowId:G,kind:"insert",...we})}else if(Se){const we=this.
|
|
497
|
+
parseTrackedRevisionMeta(Se);u.push({rowId:G,kind:"delete",...we})}de&&fe&&et&&m.push({rowId:G,rowIndex:k,...this.parseTrackedRevisionMeta(fe),currentXml:this.serializePropertiesWithoutRevisionChildren(
|
|
498
|
+
de,new Set(["w:ins","w:del","w:trPrChange"])),priorXml:new XMLSerializer().serializeToString(et),...k===0?{currentTableAttributes:this.tableHeaderAttributesFromRowProperties(de),priorTableAttributes:this.
|
|
499
|
+
tableHeaderAttributesFromRowProperties(et)}:{}}),q&&Z&&be&&b.push({rowId:G,rowIndex:k,...this.parseTrackedRevisionMeta(Z),currentXml:this.serializePropertiesWithoutRevisionChildren(q,new Set(["w:tblPr\
|
|
500
|
+
ExChange"])),priorXml:new XMLSerializer().serializeToString(be)});const ie=[];let he=0;const Ie=[];for(let we=0;we<j.children.length;we++){const Pe=j.children[we];if(Pe.tagName==="w:tc")Ie.push({el:Pe});else if(Pe.
|
|
501
|
+
tagName==="w:sdt"){const ce=this.getDirectChild(Pe,"w:sdtContent");if(!ce)continue;let De;if(this.importSdtWrappers){const Be=this.getDirectChild(Pe,"w:sdtPr");if(Be)try{De={prXml:new XMLSerializer().
|
|
502
|
+
serializeToString(Be),cellIds:[]},B.push(De)}catch{De=void 0}}for(const Be of Array.from(ce.children))Be.tagName==="w:tc"&&Ie.push({el:Be,sdtGroup:De})}}for(let we=0;we<Ie.length;we++){const Pe=Ie[we].
|
|
503
|
+
el,ce=this.getDirectChild(Pe,"w:tcPr"),De=this.getDirectChild(ce||Pe,"w:shd")?.getAttribute("w:fill"),Be=ce?this.getDirectChild(ce,"w:gridSpan")?.getAttribute("w:val"):void 0,Nt=Be?parseInt(Be,10):1,Ke=Number.
|
|
504
|
+
isFinite(Nt)?Math.min(Math.max(1,Nt),1e3):1,tt=ce?this.getDirectChild(ce,"w:cellIns"):void 0,ft=ce?this.getDirectChild(ce,"w:cellDel"):void 0,ge=ce?this.getDirectChild(ce,"w:cellMerge"):void 0,dt=ce?this.
|
|
502
505
|
getDirectChild(ce,"w:tcPrChange"):void 0,Ce=dt?this.getDirectChild(dt,"w:tcPr"):void 0,ye={type:"table-cell",id:this.generateId(),backgroundColor:De&&De.toLowerCase()!=="auto"&&De.toLowerCase()!=="non\
|
|
503
506
|
e"?`#${De.replace(/^#/,"")}`:void 0,children:this.applyParagraphMarkRevisions(await this.parseBodyChildren(Pe,r,t))};Ke>1&&(ye.colSpan=Ke);const rt=at(ce,Jr);rt&&(ye.oxmlTcPr=rt);const wt=ce?this.getDirectChild(
|
|
504
507
|
ce,"w:tcBorders"):void 0,Ze=wt?this.parseDocxBordersElement(wt,!1):void 0;Ze&&(ye.borders=Ze);const Fe=ce?this.getDirectChild(ce,"w:tcMar"):void 0,Ve=(Fe?this.parseDocxCellMargins(Fe):void 0)??c;Ve&&(ye.
|
|
505
|
-
padding=Ve);const _e=ce?this.getDirectChild(ce,"w:vAlign")?.getAttribute("w:val"):void 0;(_e==="top"||_e==="center"||_e==="bottom")&&(ye.verticalAlign=_e==="center"?"middle":_e),
|
|
506
|
-
...this.parseTrackedRevisionMeta(
|
|
507
|
-
this.getDirectChild(ce,"w:vMerge"):void 0,nt=it?.getAttribute("w:val");if(it&&nt!=="restart"){const Ne=O.get(he);if(Ne){if(Ne.cell.rowSpan=(Ne.cell.rowSpan??1)+1,
|
|
508
|
-
|
|
509
|
-
getAttribute("w:vMerge")?{vMerge:
|
|
510
|
-
rowIndex:
|
|
511
|
-
cont";if(ht)
|
|
512
|
-
rowIndex,anchorPos:Ne.cellPos,rowId:
|
|
513
|
-
:vMerge")}:{},...
|
|
514
|
-
v.push({cellId:ye.id,kind:"delete",...this.parseTrackedRevisionMeta(ft)}),dt&&Ce&&y.push({rowId:
|
|
508
|
+
padding=Ve);const _e=ce?this.getDirectChild(ce,"w:vAlign")?.getAttribute("w:val"):void 0;(_e==="top"||_e==="center"||_e==="bottom")&&(ye.verticalAlign=_e==="center"?"middle":_e),ge&&T.push({rowId:G,gridColumn:he,
|
|
509
|
+
...this.parseTrackedRevisionMeta(ge),...ge.getAttribute("w:vMerge")?{vMerge:ge.getAttribute("w:vMerge")}:{},...ge.getAttribute("w:vMergeOrig")?{vMergeOrig:ge.getAttribute("w:vMergeOrig")}:{}});const it=ce?
|
|
510
|
+
this.getDirectChild(ce,"w:vMerge"):void 0,nt=it?.getAttribute("w:val");if(it&&nt!=="restart"){const Ne=O.get(he);if(Ne){if(Ne.cell.rowSpan=(Ne.cell.rowSpan??1)+1,ge){const ot=this.parseTrackedRevisionMeta(
|
|
511
|
+
ge);L.push({row:k,pos:ie.length,colSpan:Ke,anchorRow:Ne.rowIndex,anchorPos:Ne.cellPos,rowId:G,gridColumn:he,restoredCellId:ye.id,restoredCell:JSON.parse(JSON.stringify(ye)),direction:"merge",...ot,...ge.
|
|
512
|
+
getAttribute("w:vMerge")?{vMerge:ge.getAttribute("w:vMerge")}:{},...ge.getAttribute("w:vMergeOrig")?{vMergeOrig:ge.getAttribute("w:vMergeOrig")}:{}})}he+=Ke;continue}}it&&nt==="restart"?O.set(he,{cell:ye,
|
|
513
|
+
rowIndex:k,cellPos:ie.length}):O.delete(he);const pt=ge?.hasAttribute("w:vMergeOrig")?ge.getAttribute("w:vMergeOrig"):it?nt??"continue":void 0,ht=pt==="restart"||pt==="rest",bt=pt==="continue"||pt==="\
|
|
514
|
+
cont";if(ht)I.set(he,{cell:ye,rowIndex:k,cellPos:ie.length});else if(bt){const Ne=I.get(he);if(Ne&&ge&&!it){const ot=this.parseTrackedRevisionMeta(ge);L.push({row:k,pos:ie.length,colSpan:Ke,anchorRow:Ne.
|
|
515
|
+
rowIndex,anchorPos:Ne.cellPos,rowId:G,gridColumn:he,restoredCellId:ye.id,restoredCell:JSON.parse(JSON.stringify(ye)),direction:"unmerge",...ot,...ge.getAttribute("w:vMerge")?{vMerge:ge.getAttribute("w\
|
|
516
|
+
:vMerge")}:{},...ge.getAttribute("w:vMergeOrig")?{vMergeOrig:ge.getAttribute("w:vMergeOrig")}:{}})}}else I.delete(he);tt&&v.push({cellId:ye.id,kind:"insert",...this.parseTrackedRevisionMeta(tt)}),ft&&
|
|
517
|
+
v.push({cellId:ye.id,kind:"delete",...this.parseTrackedRevisionMeta(ft)}),dt&&Ce&&y.push({rowId:G,cellId:ye.id,rowIndex:k,cellIndex:ie.length,gridColumn:he,...this.parseTrackedRevisionMeta(dt),currentXml:this.
|
|
515
518
|
serializePropertiesWithoutRevisionChildren(ce,new Set(["w:cellIns","w:cellDel","w:cellMerge","w:tcPrChange"])),priorXml:new XMLSerializer().serializeToString(Ce),currentAttributes:this.tableCellAttributesFromProperties(
|
|
516
|
-
ce),priorAttributes:this.tableCellAttributesFromProperties(Ce)}),
|
|
517
|
-
de,
|
|
518
|
-
id).filter(q=>!!q);
|
|
519
|
-
push({id:this.generateId(),prXml:
|
|
520
|
-
S).hasHeader===!0:!1,
|
|
521
|
-
de={id:q,type:"table-change",tableId:
|
|
522
|
-
version:1,suggestionKind:
|
|
523
|
-
dChange"])),
|
|
524
|
-
createdAt:
|
|
525
|
-
priorColumnWidths:
|
|
526
|
-
push({kind:
|
|
527
|
-
rowId:
|
|
528
|
-
fe=>fe.id===
|
|
529
|
-
cell",
|
|
530
|
-
createdAt:
|
|
531
|
-
const
|
|
532
|
-
currentPropertiesXml:
|
|
533
|
-
currentTableAttributes:
|
|
534
|
-
kind:"row-exception-properties",rowId:
|
|
535
|
-
operations.push({kind:"properties",target:"row-exception",rowId:
|
|
536
|
-
format");
|
|
537
|
-
createdAt,currentPropertiesXml:
|
|
538
|
-
priorPropertiesXml:
|
|
539
|
-
|
|
540
|
-
Merge table cells","format");
|
|
519
|
+
ce),priorAttributes:this.tableCellAttributesFromProperties(Ce)}),Ie[we].sdtGroup?.cellIds.push(ye.id),ie.push(ye),he+=Ke}const Oe={type:"table-row",id:G,children:ie},ke=sr(j);ke&&(Oe.oxmlAttrs=ke);const ct=at(
|
|
520
|
+
de,Gr);ct&&(Oe.oxmlTrPr=ct),i.push(Oe)}if(i.length===0)return null;if(this.importSdtWrappers){const k=this.sdtAncestorStack[this.sdtAncestorStack.length-1];for(const j of a){const G=j.trIndexes.map(q=>i[q]?.
|
|
521
|
+
id).filter(q=>!!q);G.length>0&&this.importSdtWrappers.push({id:this.generateId(),prXml:j.prXml,scope:"row",...k?{parentId:k.id}:{},blockIds:G})}for(const j of B)j.cellIds.length>0&&this.importSdtWrappers.
|
|
522
|
+
push({id:this.generateId(),prXml:j.prXml,scope:"cell",...k?{parentId:k.id}:{},blockIds:[...j.cellIds]})}const E=w(p),S=n[0]?this.getDirectChild(n[0],"w:trPr"):void 0,R=S?this.tableHeaderAttributesFromRowProperties(
|
|
523
|
+
S).hasHeader===!0:!1,z=this.generateId(),$=new Map,H=(k,j,G)=>{const q=k.revisionId?`docxrev-${k.revisionId}`:this.generateId(),Z=$.get(q);if(Z)return Z;const be=this.revisionAuthorIdentity(k.author),
|
|
524
|
+
de={id:q,type:"table-change",tableId:z,source:be.suggestionSource,authorType:be.suggestionAuthorType,label:j,...k.createdAt!==void 0?{createdAt:k.createdAt}:{},...k.author?{agentName:k.author}:{},tableRevision:{
|
|
525
|
+
version:1,suggestionKind:G,markers:[],operations:[]}};return $.set(q,de),de};if(p&&h&&g){const k=this.parseTrackedRevisionMeta(h),j=this.serializePropertiesWithoutRevisionChildren(p,new Set(["w:tblGri\
|
|
526
|
+
dChange"])),G=new XMLSerializer().serializeToString(g),q=w(p),Z=w(g),be=H(k,"Change table column widths","format");be.tableRevision.markers.push({kind:"table-grid",revisionId:k.revisionId,author:k.author,
|
|
527
|
+
createdAt:k.createdAt,currentPropertiesXml:j,priorPropertiesXml:G,currentColumnWidths:q,priorColumnWidths:Z}),be.tableRevision.operations.push({kind:"grid",currentGridXml:j,priorGridXml:G,currentColumnWidths:q,
|
|
528
|
+
priorColumnWidths:Z})}for(const k of u){const j=i.findIndex(Z=>Z.id===k.rowId),G=i[j];if(!G)continue;const q=H(k,k.kind==="insert"?"Insert table row":"Delete table row",k.kind);q.tableRevision.markers.
|
|
529
|
+
push({kind:k.kind==="insert"?"row-insert":"row-delete",rowId:k.rowId,rowIndex:j,revisionId:k.revisionId,author:k.author,createdAt:k.createdAt}),q.tableRevision.operations.push({kind:"row",action:k.kind,
|
|
530
|
+
rowId:k.rowId,rowIndex:j,row:JSON.parse(JSON.stringify(G))}),G.diffState=k.kind,G.suggestionId=q.id}for(const k of v){let j=-1,G=-1,q,Z;for(let ve=0;ve<i.length&&!Z;ve++){const Se=i[ve].children.findIndex(
|
|
531
|
+
fe=>fe.id===k.cellId);Se>=0&&(j=ve,G=Se,q=i[ve],Z=q.children[Se])}if(!q||!Z)continue;const be=Qe({children:i,columnWidths:E}).byId.get(Z.id),de=H(k,k.kind==="insert"?"Insert table cell":"Delete table \
|
|
532
|
+
cell",k.kind);de.tableRevision.markers.push({kind:k.kind==="insert"?"cell-insert":"cell-delete",rowId:q.id,cellId:Z.id,rowIndex:j,cellIndex:G,gridColumn:be?.col,revisionId:k.revisionId,author:k.author,
|
|
533
|
+
createdAt:k.createdAt}),de.tableRevision.operations.push({kind:"cell",action:k.kind,rowId:q.id,cellId:Z.id,cellIndex:G,cell:JSON.parse(JSON.stringify(Z))}),Z.diffState=k.kind,Z.suggestionId=de.id}for(const k of m){
|
|
534
|
+
const j=H(k,"Change table row properties","format");j.tableRevision.markers.push({kind:"row-properties",rowId:k.rowId,rowIndex:k.rowIndex,revisionId:k.revisionId,author:k.author,createdAt:k.createdAt,
|
|
535
|
+
currentPropertiesXml:k.currentXml,priorPropertiesXml:k.priorXml}),j.tableRevision.operations.push({kind:"properties",target:"row",rowId:k.rowId,currentPropertiesXml:k.currentXml,priorPropertiesXml:k.priorXml,
|
|
536
|
+
currentTableAttributes:k.currentTableAttributes,priorTableAttributes:k.priorTableAttributes})}for(const k of b){const j=H(k,"Change row table-style exceptions","format");j.tableRevision.markers.push({
|
|
537
|
+
kind:"row-exception-properties",rowId:k.rowId,rowIndex:k.rowIndex,revisionId:k.revisionId,author:k.author,createdAt:k.createdAt,currentPropertiesXml:k.currentXml,priorPropertiesXml:k.priorXml}),j.tableRevision.
|
|
538
|
+
operations.push({kind:"properties",target:"row-exception",rowId:k.rowId,currentPropertiesXml:k.currentXml,priorPropertiesXml:k.priorXml})}for(const k of y){const j=H(k,"Change table cell properties","\
|
|
539
|
+
format");j.tableRevision.markers.push({kind:"cell-properties",rowId:k.rowId,cellId:k.cellId,rowIndex:k.rowIndex,cellIndex:k.cellIndex,gridColumn:k.gridColumn,revisionId:k.revisionId,author:k.author,createdAt:k.
|
|
540
|
+
createdAt,currentPropertiesXml:k.currentXml,priorPropertiesXml:k.priorXml}),j.tableRevision.operations.push({kind:"properties",target:"cell",rowId:k.rowId,cellId:k.cellId,currentPropertiesXml:k.currentXml,
|
|
541
|
+
priorPropertiesXml:k.priorXml,currentAttributes:k.currentAttributes,priorAttributes:k.priorAttributes})}const K=new Map;for(const k of L){const j=k.revisionId?`docxrev-${k.revisionId}`:this.generateId(),
|
|
542
|
+
G=K.get(j)??[];G.push(k),K.set(j,G)}for(const[k,j]of K){const G=j[0],q={revisionId:G.revisionId,author:G.author,createdAt:G.createdAt},Z=H(q,j.every(ie=>ie.direction==="unmerge")?"Split table cells":"\
|
|
543
|
+
Merge table cells","format");Z.id!==k&&!$.has(k)&&($.delete(Z.id),Z.id=k,$.set(k,Z));const be=G.revisionId?T.filter(ie=>ie.revisionId===G.revisionId):j;for(const ie of be)Z.tableRevision.markers.push(
|
|
541
544
|
{kind:"cell-merge",rowId:ie.rowId,gridColumn:ie.gridColumn,revisionId:ie.revisionId,author:ie.author,createdAt:ie.createdAt,vMerge:ie.vMerge,vMergeOrig:ie.vMergeOrig});const de=JSON.parse(JSON.stringify(
|
|
542
|
-
i)),ve=new Map,Se=new Set;for(const ie of
|
|
543
|
-
delete he.rowSpan}if(
|
|
544
|
-
children.findIndex(ct=>ct.id===ie.restoredCellId);
|
|
545
|
-
JSON.stringify(ie))),et=de.filter(ie=>Se.has(ie.id));
|
|
546
|
-
|
|
547
|
-
table-properties",revisionId:
|
|
548
|
-
priorPropertiesXml:
|
|
549
|
-
s,t);return{type:"table",id:
|
|
545
|
+
i)),ve=new Map,Se=new Set;for(const ie of j){const he=de[ie.anchorRow]?.children[ie.anchorPos],Ie=de[ie.row];if(ie.direction==="merge"){if(he?.rowSpan!==void 0){const ke=he.rowSpan-1;ke>1?he.rowSpan=ke:
|
|
546
|
+
delete he.rowSpan}if(Ie){const ke=ve.get(ie.row)??0;Ie.children.splice(ie.pos+ke,0,JSON.parse(JSON.stringify(ie.restoredCell))),ve.set(ie.row,ke+1)}}else if(he&&(he.rowSpan=(he.rowSpan??1)+1),Ie){const ke=Ie.
|
|
547
|
+
children.findIndex(ct=>ct.id===ie.restoredCellId);ke>=0&&Ie.children.splice(ke,1)}Ie&&Se.add(Ie.id);const Oe=de[ie.anchorRow];Oe&&Se.add(Oe.id)}const fe=i.filter(ie=>Se.has(ie.id)).map(ie=>JSON.parse(
|
|
548
|
+
JSON.stringify(ie))),et=de.filter(ie=>Se.has(ie.id));Z.tableRevision.operations.push({kind:"geometry",pendingRows:fe,acceptedRows:JSON.parse(JSON.stringify(fe)),rejectedRows:et})}if(D&&s&&X){const k=H(
|
|
549
|
+
D,"Change table properties","format"),j=this.serializePropertiesWithoutRevisionChildren(s,new Set(["w:tblPrChange"])),G=M??new XMLSerializer().serializeToString(X);k.tableRevision.markers.push({kind:"\
|
|
550
|
+
table-properties",revisionId:D.revisionId,author:D.author,createdAt:D.createdAt,currentPropertiesXml:j,priorPropertiesXml:G}),k.tableRevision.operations.push({kind:"properties",target:"table",currentPropertiesXml:j,
|
|
551
|
+
priorPropertiesXml:G,currentAttributes:{...this.tableAttributesFromProperties(s,t)},priorAttributes:{...this.tableAttributesFromProperties(X,t)}})}const J=Array.from($.values()),re=this.tableAttributesFromProperties(
|
|
552
|
+
s,t);return{type:"table",id:z,...J.length>0?{structuralSuggestionRecords:JSON.stringify(J)}:{},children:i,columnWidths:E,...re,...R?{hasHeader:!0}:{},...(()=>{const k=at(s,Hr);return k?{oxmlTblPr:k}:{}})()}}static serializePropertiesWithoutRevisionChildren(e,r){
|
|
550
553
|
const t=e.cloneNode(!0);for(const i of Array.from(t.children))r.has(i.tagName)&&i.remove();return new XMLSerializer().serializeToString(t)}static tableCellAttributesFromProperties(e){const r={},t=this.
|
|
551
554
|
getDirectChild(e,"w:shd")?.getAttribute("w:fill");t&&t.toLowerCase()!=="auto"&&t.toLowerCase()!=="none"&&(r.backgroundColor=`#${t.replace(/^#/,"")}`);const i=this.getDirectChild(e,"w:tcBorders"),n=i?this.
|
|
552
555
|
parseDocxBordersElement(i,!1):void 0;n&&(r.borders=n);const a=this.getDirectChild(e,"w:tcMar"),o=a?this.parseDocxCellMargins(a):void 0;o&&(r.padding=o);const s=this.getDirectChild(e,"w:gridSpan")?.getAttribute(
|
|
@@ -560,13 +563,13 @@ nil":return"none";case"dotted":return"dotted";case"dashed":case"dashSmallGap":ca
|
|
|
560
563
|
e";default:return"single"}}static parseDocxBordersElement(e,r){return Lr(this.parseDocxBordersSpec(e,r))}static resolveTableBordersJson(e,r){const t={},i=s=>{s&&Object.assign(t,this.parseDocxBordersSpec(
|
|
561
564
|
s,!0))},n=r?.styles;if(n){const s=(e&&this.getDirectChild(e,"w:tblStyle")?.getAttribute("w:val")||void 0)??n.defaultStyleIdByType?.get("table"),l=s?this.resolveStyleChain(s,n,"table"):[];for(const c of l)
|
|
562
565
|
i(c.tblPr?this.getDirectChild(c.tblPr,"w:tblBorders"):void 0)}i(e?this.getDirectChild(e,"w:tblBorders"):void 0);const a={style:"none",width:0,color:"#000000"},o={top:t.top??a,bottom:t.bottom??a,left:t.
|
|
563
|
-
left??a,right:t.right??a,insideH:t.insideH??a,insideV:t.insideV??a};return Lr(o)}static parseDocxBordersSpec(e,r){const t=(...l)=>{let c;for(const
|
|
564
|
-
const p=this.mapDocxBorderStyle(c.getAttribute("w:val")),h=parseInt(c.getAttribute("w:sz")||"",10),
|
|
565
|
-
100):1,w=(c.getAttribute("w:color")||"").trim(),u=w&&w.toLowerCase()!=="auto"?`#${w.replace(/^#/,"").toLowerCase()}`:"#000000";return{style:
|
|
566
|
+
left??a,right:t.right??a,insideH:t.insideH??a,insideV:t.insideV??a};return Lr(o)}static parseDocxBordersSpec(e,r){const t=(...l)=>{let c;for(const m of l)if(c=this.getDirectChild(e,m),c)break;if(!c)return;
|
|
567
|
+
const p=this.mapDocxBorderStyle(c.getAttribute("w:val")),h=parseInt(c.getAttribute("w:sz")||"",10),g=p!=="none"&&h===0?"none":p,f=g==="none"?0:Number.isFinite(h)&&h>0?Math.max(.25,Math.round(h/6*100)/
|
|
568
|
+
100):1,w=(c.getAttribute("w:color")||"").trim(),u=w&&w.toLowerCase()!=="auto"?`#${w.replace(/^#/,"").toLowerCase()}`:"#000000";return{style:g,width:f,color:u}},i={},n=t("w:top"),a=t("w:bottom"),o=t("w\
|
|
566
569
|
:left","w:start"),s=t("w:right","w:end");if(n&&(i.top=n),a&&(i.bottom=a),o&&(i.left=o),s&&(i.right=s),r){const l=t("w:insideH"),c=t("w:insideV");l&&(i.insideH=l),c&&(i.insideV=c)}return i}static nonUniformCellMarginJson(e){
|
|
567
570
|
const r=this.parseDocxCellMargins(e);if(r){try{const t=JSON.parse(r),i=[t.top,t.right,t.bottom,t.left];if(i.every(n=>Number.isFinite(n))&&i.every(n=>n===i[0]))return}catch{return}return r}}static parseDocxCellMargins(e){
|
|
568
571
|
const r=(...o)=>{let s;for(const c of o)if(s=this.getDirectChild(e,c),s)break;if(!s)return;const l=parseInt(s.getAttribute("w:w")||"",10);if(!(!Number.isFinite(l)||l<0))return Math.round(l/15*100)/100},
|
|
569
|
-
t=r("w:top"),i=r("w:bottom"),n=r("w:left","w:start"),a=r("w:right","w:end");if(!(t===void 0&&i===void 0&&n===void 0&&a===void 0))return
|
|
572
|
+
t=r("w:top"),i=r("w:bottom"),n=r("w:left","w:start"),a=r("w:right","w:end");if(!(t===void 0&&i===void 0&&n===void 0&&a===void 0))return an({top:t??0,bottom:i??0,left:n??7.2,right:a??7.2})}static getContentTypeForPart(e,r){
|
|
570
573
|
const t=r.get(e);if(t)return t;const i=e.split(".").pop()?.toLowerCase();return i?r.get(i):void 0}static isSupportedImageMimeType(e){return e==="image/png"||e==="image/jpeg"||e==="image/jpg"||e==="ima\
|
|
571
574
|
ge/gif"||e==="image/bmp"||e==="image/svg+xml"}static buildImageDataUrl(e,r){return`data:${r};base64,${this.uint8ArrayToBase64(e)}`}static uint8ArrayToBase64(e){if(typeof Buffer<"u")return Buffer.from(
|
|
572
575
|
e).toString("base64");let r="";const t=32768;for(let i=0;i<e.length;i+=t){const n=e.subarray(i,i+t);r+=String.fromCharCode(...n)}return btoa(r)}static createEmptyParagraph(){return{type:"paragraph",id:this.
|
|
@@ -598,8 +601,8 @@ m:chr")[0]?.getAttribute("m:val");o&&(a={"̂":"\\hat","~":"\\tilde","̃":"\\tild
|
|
|
598
601
|
getElementsByTagName("m:e")[0],i=t?this.parseOmmlChildren(t):"",n=e.getElementsByTagName("m:groupChrPr")[0],a=n?.getElementsByTagName("m:chr")[0]?.getAttribute("m:val");return n?.getElementsByTagName(
|
|
599
602
|
"m:pos")[0]?.getAttribute("m:val")!=="top"&&a!=="⏞"?`\\underbrace{${i}}`:`\\overbrace{${i}}`}case"m:func":{const t=Array.from(e.children).find(l=>l.tagName==="m:fName"),i=Array.from(e.children).find(
|
|
600
603
|
l=>l.tagName==="m:e"),n=t?Array.from(t.children).find(l=>l.tagName==="m:limLow"):void 0;if(n){const l=Array.from(n.children).find(w=>w.tagName==="m:e"),c=Array.from(n.children).find(w=>w.tagName==="m:\
|
|
601
|
-
lim"),p=(l?.textContent??"").trim(),h=i?this.parseOmmlChildren(i):"",
|
|
602
|
-
"limsup"].includes(p)?`\\${p}`:f}_{${
|
|
604
|
+
lim"),p=(l?.textContent??"").trim(),h=i?this.parseOmmlChildren(i):"",g=c?this.parseOmmlChildren(c):"",f=/^[A-Za-z]+$/.test(p)?`\\operatorname*{${p}}`:p;return`${["lim","max","min","sup","inf","liminf",
|
|
605
|
+
"limsup"].includes(p)?`\\${p}`:f}_{${g}} ${h}`}const a=(t?.textContent??"").trim(),o=i?this.parseOmmlChildren(i):"",s=hr.OMML_FUNCTION_NAMES;return s.includes(a)?`\\${a}{${o}}`:s.includes(a.toLowerCase())?
|
|
603
606
|
`\\${a.toLowerCase()}{${o}}`:/^[A-Za-z]+$/.test(a)?`\\operatorname{${a}}{${o}}`:`${a}(${o})`}default:return this.parseOmmlChildren(e)}}static parseOmmlChildren(e){let r="";for(let t=0;t<e.children.length;t++){
|
|
604
607
|
const i=e.children[t];i.tagName.endsWith("Pr")||i.tagName==="m:ctrlPr"||i.tagName==="m:t"||(r+=this.parseOmmlElement(i))}return r}static cleanMathText(e){const r={"𝐴":"A","𝐵":"B","𝐶":"C","𝐷":"\
|
|
605
608
|
D","𝐸":"E","𝐹":"F","𝐺":"G","𝐻":"H","𝐼":"I","𝐽":"J","𝐾":"K","𝐿":"L","𝑀":"M","𝑁":"N","𝑂":"O","𝑃":"P","𝑄":"Q","𝑅":"R","𝑆":"S","𝑇":"T","𝑈":"U","𝑉":"V",
|
|
@@ -610,152 +613,153 @@ o","𝑝":"p","𝑞":"q","𝑟":"r","𝑠":"s","𝑡":"t","𝑢":"u","𝑣":"v",
|
|
|
610
613
|
imes","÷":"\\div","≠":"\\neq","≈":"\\approx","≤":"\\leq","≥":"\\geq","∈":"\\in","∉":"\\notin","⊂":"\\subset","⊃":"\\supset","∪":"\\cup","∩":"\\cap","→":"\\rightarrow","←":"\\le\
|
|
611
614
|
ftarrow","⇒":"\\Rightarrow","⇐":"\\Leftarrow","⇔":"\\Leftrightarrow","∀":"\\forall","∃":"\\exists","∄":"\\nexists","∴":"\\therefore","∵":"\\because","…":"\\ldots","⋯":"\\cdots","⋮":"\
|
|
612
615
|
\\vdots","⋱":"\\ddots"},t={"&":"\\&","%":"\\%","#":"\\#",$:"\\$","{":"\\{","}":"\\}"};let i="";for(const n of e){const a=r[n];a?i+=a.startsWith("\\")?`${a} `:a:i+=t[n]??n}return i}static async loadZipFromBlob(e){
|
|
613
|
-
const r=typeof e.arrayBuffer=="function"?await e.arrayBuffer():e;return
|
|
616
|
+
const r=typeof e.arrayBuffer=="function"?await e.arrayBuffer():e;return Wr.loadAsync(r)}static async generateCompressedZipBlob(e){return e.generateAsync({type:"blob",compression:"DEFLATE",compressionOptions:{
|
|
614
617
|
level:6}})}static async toBlob(e,r,t){if(t?.onWarning){const d=this.pendingListNumberingChanges(e.children);d.length>0&&t.onWarning({code:"list_numbering_tracked_unsupported",message:`${d.length===1?"\
|
|
615
618
|
A list has":`${d.length} lists have`} a pending numbering restart or list-type change. Word cannot track that, so the .docx shows ${d.length===1?"it":"them"} as already applied, with no revision to ac\
|
|
616
|
-
cept or reject. Accept or reject ${d.length===1?"it":"them"} in Revise before exporting to keep the choice.`,blockIds:d})}
|
|
617
|
-
Tab:o,TabStopType:s,LeaderType:l,CommentRangeStart:c,CommentRangeEnd:p,CommentReference:h,BookmarkStart:
|
|
618
|
-
Footer:
|
|
619
|
-
ShadingType:
|
|
619
|
+
cept or reject. Accept or reject ${d.length===1?"it":"them"} in Revise before exporting to keep the choice.`,blockIds:d})}_r()||await hn();const i=await import("./index-BWdRWxoH.js"),{Document:n,Packer:a,
|
|
620
|
+
Tab:o,TabStopType:s,LeaderType:l,CommentRangeStart:c,CommentRangeEnd:p,CommentReference:h,BookmarkStart:g,BookmarkEnd:f,Paragraph:w,TextRun:u,InsertedTextRun:m,DeletedTextRun:b,FootnoteReference:v,Header:y,
|
|
621
|
+
Footer:T,ExternalHyperlink:L,InternalHyperlink:W,HeadingLevel:X,AlignmentType:D,PageOrientation:M,PageNumber:O,PageBreak:I,SectionType:B,UnderlineType:E,Table:S,TableRow:R,TableCell:z,WidthType:$,BorderStyle:H,
|
|
622
|
+
ShadingType:K,ImportedXmlComponent:J,ImageRun:re,LevelFormat:k,LevelSuffix:j}=i,G=d=>{const x=`<root>${d}</root>`,C=J.fromXmlString(x),N=C.root?.[0];if(N?.root){for(const A of N.root)if(A?.rootKey?.startsWith(
|
|
620
623
|
"m:"))return A}return C},q=(d,x)=>{const C=d?.root;if(Array.isArray(C)){for(const N of C)if(N?.rootKey===x)return N;for(const N of C){if(N?.rootKey==="w:rPr"||N?.rootKey==="w:pPr"||N?.rootKey==="w:tbl\
|
|
621
|
-
Pr"||N?.rootKey==="w:trPr"||N?.rootKey==="w:tcPr")continue;const A=q(N,x);if(A)return A}}},
|
|
622
|
-
t>`).root?.[0]?.root??[]).filter(
|
|
623
|
-
C.rootKey!=="_attr")return C}catch{}return null},de=[],ve=[],Se=(d,x,C="w:pPr")=>{const N=de.length;de.push(x),
|
|
624
|
-
const N=(()=>{const
|
|
625
|
-
!0?
|
|
626
|
-
{},page:{size:{width:this.pxToTwips(A.orientation==="landscape"?
|
|
627
|
-
cape"?
|
|
628
|
-
|
|
624
|
+
Pr"||N?.rootKey==="w:trPr"||N?.rootKey==="w:tcPr")continue;const A=q(N,x);if(A)return A}}},Z=(d,x,C)=>{try{const N=q(d,x);if(!N||!Array.isArray(N.root))return;const A=(J.fromXmlString(`<root>${C}</roo\
|
|
625
|
+
t>`).root?.[0]?.root??[]).filter(V=>V?.rootKey&&V.rootKey!=="_attr");N.root.push(...A)}catch{}},be=d=>{try{const x=J.fromXmlString(`<root>${d}</root>`);for(const C of x.root?.[0]?.root??[])if(C?.rootKey&&
|
|
626
|
+
C.rootKey!=="_attr")return C}catch{}return null},de=[],ve=[],Se=(d,x,C="w:pPr")=>{const N=de.length;de.push(x),Z(d,C,`<w:rvseOxmlAttrs w:val="${N}"/>`)},fe=Ee(e.pageLayout),et=tr(fe),ie=(d,x,C="only")=>{
|
|
627
|
+
const N=(()=>{const _=Ee(Or(e.pageLayout,d)).pageNumberStart;switch(C){case"middle":return d?.pageNumberStart;case"first":return d?.pageNumberStart??(_!==1?_:void 0);case"final":return e.pageLayout?.pageNumberRestart===
|
|
628
|
+
!0?_:void 0;case"only":return e.pageLayout?.pageNumberRestart===!0||_!==1?_:void 0}})(),A=Ee(d),V=tr(A),P={...x&&x!=="nextPage"?{type:x==="continuous"?B.CONTINUOUS:x==="evenPage"?B.EVEN_PAGE:B.ODD_PAGE}:
|
|
629
|
+
{},page:{size:{width:this.pxToTwips(A.orientation==="landscape"?V.pageHeight:V.pageWidth),height:this.pxToTwips(A.orientation==="landscape"?V.pageWidth:V.pageHeight),orientation:A.orientation==="lands\
|
|
630
|
+
cape"?M.LANDSCAPE:M.PORTRAIT},margin:{top:this.pxToTwips(A.marginTopPx),right:this.pxToTwips(A.marginRightPx),bottom:this.pxToTwips(A.marginBottomPx),left:this.pxToTwips(A.marginLeftPx)},...(()=>{const _=Ee(
|
|
631
|
+
Or(e.pageLayout,d)).pageNumberFormat,Y={...N!==void 0?{start:N}:{},..._!=="decimal"?{formatType:_}:{}};return Object.keys(Y).length>0?{pageNumbers:Y}:{}})()}};return d?.columnCount&&d.columnCount>1&&(P.
|
|
629
632
|
column={count:d.columnCount,...d.columnGapTwips!==void 0?{space:d.columnGapTwips}:{}}),!A.lineNumbering&&A.pleadingGrid?P.lineNumbers={countBy:1,start:1,restart:"newPage",distance:Math.round((A.pleadingGrid.
|
|
630
633
|
distancePx??14)*15)}:A.lineNumbering&&(P.lineNumbers={countBy:A.lineNumbering.countBy,start:A.lineNumbering.start,restart:A.lineNumbering.restart,...A.lineNumbering.distancePx!==void 0?{distance:Math.
|
|
631
|
-
round(A.lineNumbering.distancePx*15)}:{}}),P},he=ie(e.pageLayout),
|
|
632
|
-
(et.pageWidth-fe.marginLeftPx-fe.marginRightPx)*15),ct=d=>{const x=[],C=(P,
|
|
633
|
-
P)[0]??{},Y=_e(
|
|
634
|
+
round(A.lineNumbering.distancePx*15)}:{}}),P},he=ie(e.pageLayout),Ie=fe.pageNumberPosition.endsWith("right")?D.RIGHT:D.LEFT,Oe=new w({alignment:Ie,children:[new u({children:[O.CURRENT]})]}),ke=Math.round(
|
|
635
|
+
(et.pageWidth-fe.marginLeftPx-fe.marginRightPx)*15),ct=d=>{const x=[],C=(P,_)=>(_.oxmlRPr&&Z(P,"w:rPr",_.oxmlRPr),P);for(const P of d.children){if(P.type!=="text")continue;const _=this.textNodeToDocx(
|
|
636
|
+
P)[0]??{},Y=_e(_);if(P.marks?.field==="page"||P.marks?.field==="numPages"){x.push(new u({...Y,children:[P.marks.field==="page"?O.CURRENT:O.TOTAL_PAGES]}));continue}if(P.text)if(/[\t\n]/.test(P.text)&&
|
|
634
637
|
!P.marks?.link)P.text.split(`
|
|
635
|
-
`).forEach((
|
|
636
|
-
(
|
|
637
|
-
marks.link,children:oe}))}else
|
|
638
|
-
|
|
639
|
-
d.
|
|
640
|
-
|
|
641
|
-
d.
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
638
|
+
`).forEach((U,oe)=>{const te=[];U.split(" ").forEach((me,ee)=>{ee>0&&te.push(new o),me&&te.push(me)}),x.push(new u({children:te,...Y,...oe>0?{break:1}:{}}))});else if(P.marks?.link){const U={...Y};U.underline??
|
|
639
|
+
(U.underline={type:E.SINGLE}),U.color??(U.color="2563EB");const oe=[C(new u({text:P.text,...U}),_)];x.push(P.marks.link.startsWith("#")?new W({anchor:P.marks.link.slice(1),children:oe}):new L({link:P.
|
|
640
|
+
marks.link,children:oe}))}else if(_.revision){const U={text:P.text,...Y,id:Fe(_.revision.importedId),author:_.revision.author,date:_.revision.date};x.push(C(_.revision.kind==="delete"?new b(U):new m(U),
|
|
641
|
+
_))}else x.push(C(new u({text:P.text,...Y}),_))}const N=d.children.some(P=>P.type==="text"&&P.text.includes(" ")),A={left:D.LEFT,center:D.CENTER,right:D.RIGHT,justify:D.JUSTIFIED},V=new w({children:x,
|
|
642
|
+
...d.align&&A[d.align]?{alignment:A[d.align]}:{},...N?{tabStops:[{type:s.CENTER,position:Math.round(ke/2)},{type:s.RIGHT,position:ke}]}:{}});return d.oxmlPPr&&Z(V,"w:pPr",d.oxmlPPr),d.oxmlAttrs&&Se(V,
|
|
643
|
+
d.oxmlAttrs),V},we=new Map,Pe=un(e),ce=Pe.sizes,De=d=>d.fit==="band"?ce.get(d):{width:d.width,height:d.height},Be=(d,x)=>d.fit!=="band"||x===void 0||!!Pe.sectionsShowing.get(d)?.has(x),Nt=(e.chromeImages??
|
|
644
|
+
[]).some(d=>d.fit==="band"&&!!ce.get(d)&&(Pe.sectionsShowing.get(d)?.size??0)<Pe.sectionCount);for(const d of e.chromeImages??[]){if(!De(d))continue;const x=await this.resolveImageSourceForDocx(d.src);
|
|
645
|
+
x&&we.set(d,x)}const Ke=d=>{const x=we.get(d),C=De(d);if(!x||!C)return null;try{return new w({...d.align==="center"?{alignment:D.CENTER}:d.align==="right"?{alignment:D.RIGHT}:{},children:[new re({type:x.
|
|
646
|
+
type,data:x.data,...d.alt?{altText:{name:d.alt,description:d.alt,title:d.alt}}:{},transformation:{width:Math.max(1,Math.round(C.width)),height:Math.max(1,Math.round(C.height))}})]})}catch{return null}},
|
|
647
|
+
tt=(d,x,C,N)=>{const A=P=>C?(e.chromeImages??[]).filter(_=>_.side===C&&_.slot===P&&(!N?.bandOnly||_.fit==="band")&&Be(_,N?.sectionIndex)).map(Ke).filter(_=>_!==null):[],V={};for(const P of["default","\
|
|
648
|
+
first","even"]){const _=[...(d?.[P]??[]).map(ct),...A(P)];_.length>0&&(V[P]=new x({children:_}))}return Object.keys(V).length>0?V:void 0},ft=(d,x)=>(e.chrome??[]).some(C=>C.slot===d&&(x==="any"||C.sectionIndex===
|
|
649
|
+
void 0)&&(d==="first"||Ji(C)))||Array.from(we.keys()).some(C=>C.slot===d),ge=!!(e.headers?.first||e.footers?.first)||ft("first","unscoped"),dt=!!(e.headers?.even||e.footers?.even)||ft("even","any");ge&&
|
|
650
|
+
(he.titlePage=!0);const Ce={},ye=this.buildDocxNumberingConfig(e,{AlignmentType:D,LevelFormat:k,LevelSuffix:j}),rt=new Set,wt=new Set;for(const d of JSON.stringify(e).matchAll(/docxrev-(\d+)/g))wt.add(
|
|
647
651
|
Number(d[1]));let Ze=1e5;const Fe=d=>{if(d!==void 0&&!rt.has(d))return rt.add(d),d;for(;rt.has(Ze)||wt.has(Ze);)Ze++;return rt.add(Ze),Ze};let Ve=!1;const _e=d=>{const x={};return d.bold!==void 0&&(x.
|
|
648
|
-
bold=d.bold),d.italic!==void 0&&(x.italics=d.italic),d.underline&&(x.underline={type:d.underline==="NONE"?"none":
|
|
652
|
+
bold=d.bold),d.italic!==void 0&&(x.italics=d.italic),d.underline&&(x.underline={type:d.underline==="NONE"?"none":E.SINGLE}),d.strike!==void 0&&(x.strike=d.strike),d.doubleStrike!==void 0&&(x.doubleStrike=
|
|
649
653
|
d.doubleStrike),d.smallCaps!==void 0&&(x.smallCaps=d.smallCaps),d.allCaps!==void 0&&(d.smallCaps!==void 0?(x.snapToGrid=d.allCaps,Ve=!0):x.allCaps=d.allCaps),d.vanish===!0?x.vanish=!0:d.vanish===!1&&(x.
|
|
650
654
|
specVanish=!0,Ve=!0),d.lang&&(x.language={value:d.lang}),d.characterSpacing?x.characterSpacing=d.characterSpacing:d.characterSpacing===0&&(x.imprint=!0,Ve=!0),d.superScript&&(x.superScript=!0),d.subScript&&
|
|
651
655
|
(x.subScript=!0),d.baseline&&(x.emboss=!0,Ve=!0),d.rightToLeft&&(x.rightToLeft=!0),d.color&&(x.color=d.color),d.highlight&&(x.highlight=d.highlight),d.font&&(x.font=d.font.split(",")[0].replaceAll("'",
|
|
652
656
|
"").replaceAll('"',"")),d.size&&(x.size=d.size),d.characterStyle&&(x.style=d.characterStyle),x};let it=0,nt=1e5;const pt=new Set((e.sdtWrappers??[]).filter(d=>d.scope==="inline").map(d=>d.id)),ht=new Map,
|
|
653
|
-
bt=[],Ne=[],ot=[],
|
|
654
|
-
date:typeof d.rangeCreatedAt=="number"?new Date(d.rangeCreatedAt).toISOString():N,wrapperIds:[x]})},Xt=d=>{const x=P=>P?.sdtInline?.split(",").filter(
|
|
655
|
-
(P,
|
|
656
|
-
P.rPrChange&&(Y.revision={id:Fe(P.rPrChange.importedId),author:P.rPrChange.author,date:P.rPrChange.date,..._e(P.rPrChange.prior)});const
|
|
657
|
-
|
|
658
|
-
revision.layeredInsertion.author,date:P.revision.layeredInsertion.date}),P.revision.move&&
|
|
659
|
-
ne=new u(Y);return P.oxmlRPr&&
|
|
660
|
-
link.slice(1),children:ne}):new
|
|
661
|
-
children[
|
|
662
|
-
get(P)??[])te.push(new
|
|
663
|
-
push(...Sr(se)),te.push(oe),se&&!je&&d.children[
|
|
657
|
+
bt=[],Ne=[],ot=[],oi=(d,x,C,N)=>{const A=`${d.name}\0${d.role}\0${d.rangeId}`,V=ht.get(A);if(V){V.wrapperIds.push(x);return}ht.set(A,{name:d.name,role:d.role,rangeId:d.rangeId,author:d.rangeAuthor??C,
|
|
658
|
+
date:typeof d.rangeCreatedAt=="number"?new Date(d.rangeCreatedAt).toISOString():N,wrapperIds:[x]})},Xt=d=>{const x=P=>P?.sdtInline?.split(",").filter(_=>_&&pt.has(_))??[],C=new Map,N=d.children.flatMap(
|
|
659
|
+
(P,_)=>{if(P.mathOmml)return G(P.mathOmml);const Y={text:P.text,..._e(P)};P.break&&(Y.break=1),P.footnoteReference!==void 0&&(delete Y.text,Y.style??(Y.style="FootnoteReference"),Y.children=[new v(P.footnoteReference)]),
|
|
660
|
+
P.rPrChange&&(Y.revision={id:Fe(P.rPrChange.importedId),author:P.rPrChange.author,date:P.rPrChange.date,..._e(P.rPrChange.prior)});const U=()=>{let ne;if(P.revision){const ae=Fe(P.revision.importedId),
|
|
661
|
+
Re={...Y,id:ae,author:P.revision.author,date:P.revision.date};P.revision.kind==="delete"&&P.revision.layeredInsertion&&ot.push({deletionId:ae,insertionId:Fe(P.revision.layeredInsertion.importedId),author:P.
|
|
662
|
+
revision.layeredInsertion.author,date:P.revision.layeredInsertion.date}),P.revision.move&&oi(P.revision.move,ae,P.revision.author,P.revision.date),ne=P.revision.kind==="delete"?new b(Re):new m(Re)}else
|
|
663
|
+
ne=new u(Y);return P.oxmlRPr&&Z(ne,"w:rPr",P.oxmlRPr),ne},oe=P.link?(()=>{Y.underline??(Y.underline={type:E.SINGLE}),Y.color??(Y.color="2563EB");const ne=[U()];return P.link.startsWith("#")?new W({anchor:P.
|
|
664
|
+
link.slice(1),children:ne}):new L({link:P.link,children:ne})})():U(),te=[];for(const ne of wr.get(P)??[]){const ae=Le.get(ne);ae!==void 0&&te.push(new c(ae))}const me=x(d.children[_-1]),ee=x(P),Ye=x(d.
|
|
665
|
+
children[_+1]);for(const ne of[...ee].reverse()){if(me.includes(ne))continue;const ae={name:`__rvSdt:${ne}:${it++}`,numericId:nt++};C.set(ne,ae),te.push(new g(ae.name,ae.numericId))}for(const ne of Gt.
|
|
666
|
+
get(P)??[])te.push(new g(ne,Ht.get(ne)));for(const ne of Ut.get(P)??[]){const ae=be(Dt.get(ne).startXml);ae&&te.push(ae)}const je=Vt.has(d),se=P.fieldInstr;se&&!je&&d.children[_-1]?.fieldInstr!==se&&te.
|
|
667
|
+
push(...Sr(se)),te.push(oe),se&&!je&&d.children[_+1]?.fieldInstr!==se&&te.push(...Ir());for(const ne of Kt.get(P)??[]){const ae=be(Dt.get(ne).endXml);ae&&te.push(ae)}for(const ne of Jt.get(P)??[])te.push(
|
|
664
668
|
new f(Ht.get(ne)));for(const ne of ee){if(Ye.includes(ne))continue;const ae=C.get(ne);ae&&(te.push(new f(ae.numericId)),C.delete(ne))}for(const ne of br.get(P)??[]){const ae=Le.get(ne);ae!==void 0&&(te.
|
|
665
|
-
push(new p(ae)),te.push(new u({children:[new h(ae)]})))}return te});for(const P of jt.get(d.sourceBlockId??"")??[]){const
|
|
666
|
-
new h(
|
|
667
|
-
unshift(new
|
|
668
|
-
has(d)&&N.push(...
|
|
669
|
-
const{size:
|
|
670
|
-
void 0&&(A.bidirectional=d.bidirectional),d.tabStopsJson){const P=
|
|
671
|
-
UNDERSCORE};A.tabStops=P.map(
|
|
672
|
-
dashed":return H.DASHED;case"dotted":return H.DOTTED;case"double":return H.DOUBLE;case"none":return H.NONE;default:return H.SINGLE}},Y={};for(const
|
|
673
|
-
(Y[
|
|
674
|
-
toDocxHex(d.shadingFill);A.shading=P?{type:
|
|
675
|
-
HEADING_4:
|
|
669
|
+
push(new p(ae)),te.push(new u({children:[new h(ae)]})))}return te});for(const P of jt.get(d.sourceBlockId??"")??[]){const _=Le.get(P);_!==void 0&&(N.push(new c(_)),N.push(new p(_)),N.push(new u({children:[
|
|
670
|
+
new h(_)]})))}if(Zt.has(d)&&N.unshift(...Sr(Zt.get(d))),d.inTableCell&&d.paragraphPropertiesChange){const P=`__rvPp:${bt.length}`,_=nt++;bt.push({pIndex:-1,marker:P,...d.paragraphPropertiesChange}),N.
|
|
671
|
+
unshift(new g(P,_),new f(_))}if((d.inTableCell||d.inNote)&&d.paragraphMarkRevision){const P=`__rvPm:${Ne.length}`,_=nt++;Ne.push({name:P,...d.paragraphMarkRevision}),N.unshift(new g(P,_),new f(_))}xr.
|
|
672
|
+
has(d)&&N.push(...Ir());const A={children:N};if(d.children.length>0&&d.children.every(P=>!P.text&&!P.break&&!P.mathOmml&&P.footnoteReference===void 0)){const P=d.children.find(_=>_.size||_.font);if(P){
|
|
673
|
+
const{size:_,font:Y}=_e({size:P.size,font:P.font});A.run={..._?{size:_}:{},...Y?{font:Y}:{}}}}if(d.keepNext&&(A.keepNext=!0),d.keepLines&&(A.keepLines=!0),d.widowControl===!1&&(A.widowControl=!1),d.bidirectional!==
|
|
674
|
+
void 0&&(A.bidirectional=d.bidirectional),d.tabStopsJson){const P=Ui(d.tabStopsJson);if(P){const _={left:s.LEFT,right:s.RIGHT,center:s.CENTER,decimal:s.DECIMAL},Y={dot:l.DOT,hyphen:l.HYPHEN,underscore:l.
|
|
675
|
+
UNDERSCORE};A.tabStops=P.map(U=>({type:_[U.align]??s.LEFT,position:Math.round(U.pos*15),...U.leader?{leader:Y[U.leader]}:{}}))}}if(d.bordersJson)try{const P=JSON.parse(d.bordersJson),_=U=>{switch(U){case"\
|
|
676
|
+
dashed":return H.DASHED;case"dotted":return H.DOTTED;case"double":return H.DOUBLE;case"none":return H.NONE;default:return H.SINGLE}},Y={};for(const U of["top","bottom","left","right"]){const oe=P[U];oe&&
|
|
677
|
+
(Y[U]={style:_(oe.style),size:oe.style==="none"?0:Math.max(1,Math.round((oe.width??1)*6)),color:this.toDocxHex(oe.color)??"auto"})}Object.keys(Y).length>0&&(A.border=Y)}catch{}if(d.shadingFill){const P=this.
|
|
678
|
+
toDocxHex(d.shadingFill);A.shading=P?{type:K.CLEAR,fill:P}:{type:K.CLEAR,fill:"auto",color:"auto"}}if(d.heading&&!d.styleId){const P={HEADING_1:X.HEADING_1,HEADING_2:X.HEADING_2,HEADING_3:X.HEADING_3,
|
|
679
|
+
HEADING_4:X.HEADING_4,HEADING_5:X.HEADING_5,HEADING_6:X.HEADING_6};A.heading=P[d.heading]}if(d.alignment){const P={LEFT:D.LEFT,CENTER:D.CENTER,RIGHT:D.RIGHT,JUSTIFIED:D.JUSTIFIED};A.alignment=P[d.alignment]}
|
|
676
680
|
d.styleId?A.style=d.styleId:d.style&&(A.style=d.style),d.lineSpacing!==void 0&&(A.spacing={...A.spacing,line:Math.round(d.lineSpacing*240)}),d.spacingBeforeTwips!==void 0&&(A.spacing={...A.spacing,before:d.
|
|
677
681
|
spacingBeforeTwips}),d.spacingAfterTwips!==void 0&&(A.spacing={...A.spacing,after:d.spacingAfterTwips}),d.contextualSpacing&&(A.contextualSpacing=!0),d.indent&&(A.indent={...A.indent,...d.indent}),d.list&&
|
|
678
|
-
(d.list.variant==="todo"?A.indent=this.getListIndentOptions(d.list.level):d.list.reference&&(A.numbering={reference:d.list.reference,level:d.list.level,instance:d.list.instance??0}));const
|
|
679
|
-
return d.oxmlPPr&&
|
|
682
|
+
(d.list.variant==="todo"?A.indent=this.getListIndentOptions(d.list.level):d.list.reference&&(A.numbering={reference:d.list.reference,level:d.list.level,instance:d.list.instance??0}));const V=new w(A);
|
|
683
|
+
return d.oxmlPPr&&Z(V,"w:pPr",d.oxmlPPr),d.oxmlAttrs&&Se(V,d.oxmlAttrs),V},gr=d=>{const x=Number.isFinite(d.borderWidth)?Math.max(0,Math.round(d.borderWidth)):1,C=x>0?{style:H.SINGLE,size:Math.max(1,x*
|
|
680
684
|
6),color:this.toDocxHex(d.borderColor)??"D1D5DB"}:{style:H.NONE,size:0,color:"auto"},N=ee=>{const Ye={single:H.SINGLE,dashed:H.DASHED,dotted:H.DOTTED,double:H.DOUBLE,none:H.NONE};return ee.style==="no\
|
|
681
|
-
ne"||ee.width<=0?{style:H.NONE,size:0,color:"auto"}:{style:Ye[ee.style]??H.SINGLE,size:Math.max(1,Math.round(ee.width*6)),color:this.toDocxHex(ee.color)??"auto"}},A=nr(d.borders),
|
|
685
|
+
ne"||ee.width<=0?{style:H.NONE,size:0,color:"auto"}:{style:Ye[ee.style]??H.SINGLE,size:Math.max(1,Math.round(ee.width*6)),color:this.toDocxHex(ee.color)??"auto"}},A=nr(d.borders),V=A?{top:N(A.top??{style:"\
|
|
682
686
|
single",width:1,color:"#d1d5db"}),bottom:N(A.bottom??{style:"single",width:1,color:"#d1d5db"}),left:N(A.left??{style:"single",width:1,color:"#d1d5db"}),right:N(A.right??{style:"single",width:1,color:"\
|
|
683
687
|
#d1d5db"}),insideHorizontal:N(A.insideH??{style:"single",width:1,color:"#d1d5db"}),insideVertical:N(A.insideV??{style:"single",width:1,color:"#d1d5db"})}:void 0,P=d.rows.map(ee=>{const Ye=ee.cells.map(
|
|
684
|
-
(se,ne)=>{const ae=se.blocks??se.paragraphs,
|
|
685
|
-
1),
|
|
686
|
-
se.verticalAlign==="middle"?"center":se.verticalAlign);const
|
|
687
|
-
(Me.right=N(
|
|
688
|
+
(se,ne)=>{const ae=se.blocks??se.paragraphs,Re=ae.map(Me=>Me.type==="table"?gr(Me):Xt(Me));(Re.length===0||ae[ae.length-1]?.type==="table")&&Re.push(new w({}));const st=Math.max(d.columnWidths.length,
|
|
689
|
+
1),Pi=se.colSpan??1,Ar=se.gridColumn??ne;let Tr=0;for(let Me=Ar;Me<Ar+Pi;Me++)Tr+=d.columnWidths[Me]||100/st;const He={children:Re,width:{size:Tr,type:$.PERCENTAGE}};se.verticalAlign&&(He.verticalAlign=
|
|
690
|
+
se.verticalAlign==="middle"?"center":se.verticalAlign);const Ge=dn(se.borders);if(Ge){const Me={};Ge.top&&(Me.top=N(Ge.top)),Ge.bottom&&(Me.bottom=N(Ge.bottom)),Ge.left&&(Me.left=N(Ge.left)),Ge.right&&
|
|
691
|
+
(Me.right=N(Ge.right)),He.borders=Me}else V||(He.borders={top:C,bottom:C,left:C,right:C});const Pt=pn(se.padding);Pt&&(He.margins={marginUnitType:$.DXA,top:Math.round(Pt.top*15),bottom:Math.round(Pt.bottom*
|
|
688
692
|
15),left:Math.round(Pt.left*15),right:Math.round(Pt.right*15)}),se.colSpan&&se.colSpan>1&&(He.columnSpan=se.colSpan),se.rowSpan&&se.rowSpan>1&&(He.rowSpan=se.rowSpan);const er=this.toDocxHex(se.backgroundColor);
|
|
689
|
-
er?He.shading={type:
|
|
690
|
-
Mr}),je=new
|
|
691
|
-
isFinite(d.tableWidth)&&d.tableWidth>0?Math.round(d.tableWidth*15):void 0,Y=
|
|
692
|
-
|
|
693
|
-
15),bottom:Math.round(d.cellPadding*15),left:Math.round(d.cellPadding*15),right:Math.round(d.cellPadding*15)}:void 0,
|
|
694
|
-
d.columnWidths.length&&
|
|
695
|
-
|
|
696
|
-
for(let A=0;A<C.length;A++)N[A]=C.charCodeAt(A);return N},
|
|
693
|
+
er?He.shading={type:K.SOLID,color:er,fill:er}:ee.isHeader&&!se.backgroundColor&&(He.shading={type:K.SOLID,color:"F9FAFB",fill:"F9FAFB"});const Mr=new z(He);return se.oxmlTcPr&&Z(Mr,"w:tcPr",se.oxmlTcPr),
|
|
694
|
+
Mr}),je=new R({children:Ye,tableHeader:ee.isHeader===!0?!0:void 0});return ee.oxmlTrPr&&Z(je,"w:trPr",ee.oxmlTrPr),ee.oxmlAttrs&&Se(je,ee.oxmlAttrs,"w:trPr"),je}),_=typeof d.tableWidth=="number"&&Number.
|
|
695
|
+
isFinite(d.tableWidth)&&d.tableWidth>0?Math.round(d.tableWidth*15):void 0,Y=_??9e3,U=d.columnWidths.filter(ee=>Number.isFinite(ee)&&ee>0).map(ee=>Math.max(1,Math.round(ee/100*Y))),oe=d.align==="center"?
|
|
696
|
+
D.CENTER:d.align==="right"?D.RIGHT:d.align==="left"?D.LEFT:void 0,te=typeof d.cellPadding=="number"&&Number.isFinite(d.cellPadding)&&d.cellPadding>=0?{marginUnitType:$.DXA,top:Math.round(d.cellPadding*
|
|
697
|
+
15),bottom:Math.round(d.cellPadding*15),left:Math.round(d.cellPadding*15),right:Math.round(d.cellPadding*15)}:void 0,me=new S({rows:P,width:_?{size:_,type:$.DXA}:{size:100,type:$.PERCENTAGE},...U.length===
|
|
698
|
+
d.columnWidths.length&&U.length>0?{columnWidths:U}:{},...oe?{alignment:oe}:{},...te?{margins:te}:{},borders:V??{top:C,bottom:C,left:C,right:C,insideHorizontal:C,insideVertical:C}});return d.oxmlTblPr&&
|
|
699
|
+
Z(me,"w:tblPr",d.oxmlTblPr),me},si=d=>{const x=d.split(",")[1]||"";if(typeof atob!="function")throw new Error("Base64 decoding is unavailable in this environment");const C=atob(x),N=new Uint8Array(C.length);
|
|
700
|
+
for(let A=0;A<C.length;A++)N[A]=C.charCodeAt(A);return N},ai=d=>{if(d.renderDiagram)return d.diagramPngDataUrl?new w({children:[new re({type:"png",data:si(d.diagramPngDataUrl),transformation:{width:Math.
|
|
697
701
|
max(120,Math.round(d.diagramWidth||600)),height:Math.max(60,Math.round(d.diagramHeight||180))}})],spacing:{before:120,after:120}}):new w({children:[new u({text:"Diagram unavailable"})],spacing:{before:120,
|
|
698
702
|
after:120}});const x=d.runs.map(N=>{const A={text:N.text,font:N.font||"Courier New"};return N.color&&(A.color=N.color),N.break&&(A.break=N.text.split(`
|
|
699
|
-
`).length-1,A.text=""),new u(A)}),C=this.toDocxHex(d.backgroundColor)??"F5F5F5";return new w({children:x,...d.styleId?{style:d.styleId}:{},shading:{type:
|
|
700
|
-
|
|
701
|
-
alignment==="center"?
|
|
702
|
-
marker:x,anchorXml:d.anchorXml}),x},Mt=d=>({alignment:d.align==="center"?
|
|
703
|
+
`).length-1,A.text=""),new u(A)}),C=this.toDocxHex(d.backgroundColor)??"F5F5F5";return new w({children:x,...d.styleId?{style:d.styleId}:{},shading:{type:K.SOLID,color:C,fill:C},spacing:{before:120,after:120}})},
|
|
704
|
+
li=d=>{if(!d.omml)return new w({children:[new u({text:d.content})],alignment:d.alignment==="center"?D.CENTER:d.alignment==="right"?D.RIGHT:D.LEFT});const x=G(d.omml);return new w({children:[x],alignment:d.
|
|
705
|
+
alignment==="center"?D.CENTER:d.alignment==="right"?D.RIGHT:D.LEFT,spacing:{before:120,after:120}})},At=[],Tt=[],ci=d=>{if(!d.anchorXml)return;const x=`__revise-anchor:${Tt.length}__`;return Tt.push({
|
|
706
|
+
marker:x,anchorXml:d.anchorXml}),x},Mt=d=>({alignment:d.align==="center"?D.CENTER:d.align==="right"?D.RIGHT:D.LEFT,spacing:{before:120,after:120}}),di=async d=>{const x=ci(d);if(d.originalFormat&&d.originalDataUrl){
|
|
703
707
|
const N=`__revise-original-media:${At.length}__`;return At.push({marker:N,format:d.originalFormat,dataUrl:d.originalDataUrl,alt:d.alt}),new w({children:[new re({type:"png",data:this.base64ToUint8Array(
|
|
704
|
-
|
|
705
|
-
const N=this.dataUrlToUint8Array(d.src);if(N){const A=Math.max(1,Math.round(d.width)),
|
|
706
|
-
{children:[new re({type:"svg",data:N,fallback:{type:"png",data:P},altText:{name:d.alt||"Image",description:d.alt,title:x??d.alt},transformation:{width:A,height:
|
|
708
|
+
ni),altText:{name:d.alt||"Image",description:N,title:x??d.alt},transformation:{width:Math.max(1,Math.round(d.width)),height:Math.max(1,Math.round(d.height))}})],...Mt(d)})}if(d.src.match(/^data:image\/svg\+xml(;base64)?,/i)){
|
|
709
|
+
const N=this.dataUrlToUint8Array(d.src);if(N){const A=Math.max(1,Math.round(d.width)),V=Math.max(1,Math.round(d.height)),P=await this.rasterizeSvgDataUrlToPng(d.src,A,V)??this.base64ToUint8Array(ni);return new w(
|
|
710
|
+
{children:[new re({type:"svg",data:N,fallback:{type:"png",data:P},altText:{name:d.alt||"Image",description:d.alt,title:x??d.alt},transformation:{width:A,height:V}})],...Mt(d)})}}const C=await this.resolveImageSourceForDocx(
|
|
707
711
|
d.src);return C?new w({children:[new re({type:C.type,data:C.data,altText:{name:d.alt||"Image",description:d.alt,title:x??d.alt},transformation:{width:Math.max(1,Math.round(d.width)),height:Math.max(1,
|
|
708
|
-
Math.round(d.height))}})],...Mt(d)}):new w({children:[new u({text:d.alt||"Image unavailable"})],...Mt(d)})},
|
|
709
|
-
te")],vt=new Map;for(const d of yt)vt.set(d.id,d.noteKind==="endnote"?"endnote":"footnote");const
|
|
710
|
-
{const d=x=>{if(!x||typeof x!="object")return;if(Array.isArray(x)){x.forEach(d);return}const C=x;if(C.type==="footnote")return;const N=C.marks?.footnoteRef;if(N){const A=vt.get(N)==="endnote"?
|
|
711
|
-
has(N)||A.set(N,A.size+1)}d(C.children)};d(e.children.filter(x=>x.type!=="footnote"))}for(const d of xt)
|
|
712
|
-
const x=d.importedId;Number.isSafeInteger(x)&&x>=0&&x<=2147483647&&!
|
|
713
|
-
const St=new Map,
|
|
714
|
-
const x=
|
|
712
|
+
Math.round(d.height))}})],...Mt(d)}):new w({children:[new u({text:d.alt||"Image unavailable"})],...Mt(d)})},pi=()=>new w({children:[new I]}),yt=[...e.notes??[],...e.children.filter(d=>d.type==="footno\
|
|
713
|
+
te")],vt=new Map;for(const d of yt)vt.set(d.id,d.noteKind==="endnote"?"endnote":"footnote");const hi=yt.filter(d=>vt.get(d.id)==="footnote"),xt=yt.filter(d=>vt.get(d.id)==="endnote"),Et=new Map,gt=new Map;
|
|
714
|
+
{const d=x=>{if(!x||typeof x!="object")return;if(Array.isArray(x)){x.forEach(d);return}const C=x;if(C.type==="footnote")return;const N=C.marks?.footnoteRef;if(N){const A=vt.get(N)==="endnote"?gt:Et;A.
|
|
715
|
+
has(N)||A.set(N,A.size+1)}d(C.children)};d(e.children.filter(x=>x.type!=="footnote"))}for(const d of xt)gt.has(d.id)||gt.set(d.id,gt.size+1);const Xe=e.comments??[],Le=new Map,mt=new Set;for(const d of Xe){
|
|
716
|
+
const x=d.importedId;Number.isSafeInteger(x)&&x>=0&&x<=2147483647&&!mt.has(x)&&(mt.add(x),Le.set(d.id,x))}let qe=0;for(const d of Xe)if(!Le.has(d.id)){for(;mt.has(qe);)qe++;Le.set(d.id,qe),mt.add(qe++)}
|
|
717
|
+
const St=new Map,mr=d=>{const x=new Map(Xe.map(A=>[A.id,A]));let C=d;const N=new Set;for(;C.parentId&&!N.has(C.id);){N.add(C.id);const A=x.get(C.parentId);if(!A)break;C=A}return C.id};for(const d of Xe){
|
|
718
|
+
const x=mr(d),C=St.get(x)??[];C.includes(d.id)||C.push(d.id),St.set(x,C)}const gi=e.children.some(d=>d.type==="header-footer");let ze=yt.length>0||gi?{...e,children:e.children.filter(d=>d.type!=="foot\
|
|
715
719
|
note"&&d.type!=="header-footer")}:e;if(yt.length>0){ze=JSON.parse(JSON.stringify(ze));const d=x=>{if(!x||typeof x!="object")return;if(Array.isArray(x)){x.forEach(d);return}const C=x,N=C.marks?.footnoteRef;
|
|
716
|
-
if(N)if(vt.get(N)==="endnote"){const A=
|
|
717
|
-
this.hasDocxMoveMarks(ze.children)&&(ze=JSON.parse(JSON.stringify(ze)),this.finalizeImportedMovePairs(ze.children));const ur=this.collectTableRevisionPatches(ze),zt=t?.graft?[]:void 0,
|
|
718
|
-
ze,r,t?.headingPageNumbers,zt),
|
|
719
|
-
"paragraph"||d.type==="table"));const wr=new Map,br=new Map,jt=new Map,yr=[];{const d=[];for(const P of
|
|
720
|
-
void 0&&!P.fieldInstr,C=new Map;for(const[P,
|
|
721
|
-
const oe=N.get(
|
|
722
|
-
oe)}});const A=new Set,
|
|
723
|
-
\0fragment${oe}`;for(;
|
|
724
|
-
id))continue;const Y=St.get(P.id)??[P.id],
|
|
725
|
-
...yr.map(({cloneId:d,sourceId:x})=>({id:d,record:mi.get(x),isClone:!0}))],Ht=new Map,
|
|
726
|
-
split(",")??[])
|
|
727
|
-
Dt=new Map((e.oxmlRanges??[]).filter(d=>d.startXml&&d.endXml).map(d=>[d.id,d]));if(Dt.size>0){const d=new Map,x=new Map;for(const C of
|
|
728
|
-
[])!A||!Dt.has(A)||(d.has(A)||d.set(A,N),x.set(A,N));for(const[C,N]of d)Ut.set(N,[...Ut.get(N)??[],C]);for(const[C,N]of x)Kt.set(N,[...Kt.get(N)??[],C])}const
|
|
720
|
+
if(N)if(vt.get(N)==="endnote"){const A=gt.get(N)??1;C.text=`__RVSE_EN_${A}__`,C.marks&&(delete C.marks.footnoteRef,C.marks.superscript=!0)}else C.text=String(Et.get(N)??1);d(C.children)};d(ze.children)}
|
|
721
|
+
this.hasDocxMoveMarks(ze.children)&&(ze=JSON.parse(JSON.stringify(ze)),this.finalizeImportedMovePairs(ze.children));const ur=this.collectTableRevisionPatches(ze),zt=t?.graft?[]:void 0,It=this.toDocxFormatWithTables(
|
|
722
|
+
ze,r,t?.headingPageNumbers,zt),kt=[],fr=d=>{for(const x of d){if(x.type==="paragraph"){kt.push(x);continue}for(const C of x.rows)for(const N of C.cells)fr(N.blocks??N.paragraphs)}};fr(It.filter(d=>d.type===
|
|
723
|
+
"paragraph"||d.type==="table"));const wr=new Map,br=new Map,jt=new Map,yr=[];{const d=[];for(const P of kt)d.push(...P.children);const x=P=>(P.text??"")===""&&!P.break&&!P.mathOmml&&P.footnoteReference===
|
|
724
|
+
void 0&&!P.fieldInstr,C=new Map;for(const[P,_]of St)for(const Y of _)C.set(Y,P);const N=new Map;d.forEach((P,_)=>{const Y=new Set((P.comment?.split(",")??[]).filter(Boolean).map(U=>C.get(U)??U));for(const U of Y){
|
|
725
|
+
const oe=N.get(U)??[],te=oe[oe.length-1];let me=!!te;for(let ee=te?te.lastIndex+1:_;ee<_;ee++)if(!x(d[ee])){me=!1;break}te&&me?(te.last=P,te.lastIndex=_):oe.push({first:P,last:P,lastIndex:_}),N.set(U,
|
|
726
|
+
oe)}});const A=new Set,V=(P,_,Y)=>P.set(_,[...P.get(_)??[],...Y]);for(const[P,_]of N){const Y=St.get(P)??[P];Y.forEach(U=>A.add(U)),_.forEach((U,oe)=>{let te=Y;if(oe>0){if(!Le.has(P))return;const me=`${P}\
|
|
727
|
+
\0fragment${oe}`;for(;mt.has(qe);)qe++;Le.set(me,qe),mt.add(qe++),yr.push({cloneId:me,sourceId:P}),te=[me]}V(wr,U.first,te),V(br,U.last,te)})}for(const P of Xe){const _=P.anchorBlockId;if(!_||A.has(P.
|
|
728
|
+
id))continue;const Y=St.get(P.id)??[P.id],U=jt.get(_)??[];for(const oe of Y)U.includes(oe)||U.push(oe);jt.set(_,U)}}const mi=new Map(Xe.map(d=>[d.id,d])),vr=[...Xe.map(d=>({id:d.id,record:d,isClone:!1})),
|
|
729
|
+
...yr.map(({cloneId:d,sourceId:x})=>({id:d,record:mi.get(x),isClone:!0}))],Ht=new Map,Gt=new Map,Jt=new Map;{const d=new Map,x=new Map;for(const N of kt)for(const A of N.children)for(const V of A.bookmark?.
|
|
730
|
+
split(",")??[])V&&(d.has(V)||d.set(V,A),x.set(V,A));let C=1;for(const[N,A]of d)Ht.set(N,C++),Gt.set(A,[...Gt.get(A)??[],N]);for(const[N,A]of x)Jt.set(A,[...Jt.get(A)??[],N])}const Ut=new Map,Kt=new Map,
|
|
731
|
+
Dt=new Map((e.oxmlRanges??[]).filter(d=>d.startXml&&d.endXml).map(d=>[d.id,d]));if(Dt.size>0){const d=new Map,x=new Map;for(const C of kt)for(const N of C.children)for(const A of N.oxmlRange?.split(",")??
|
|
732
|
+
[])!A||!Dt.has(A)||(d.has(A)||d.set(A,N),x.set(A,N));for(const[C,N]of d)Ut.set(N,[...Ut.get(N)??[],C]);for(const[C,N]of x)Kt.set(N,[...Kt.get(N)??[],C])}const ui=d=>{const x=d.children.filter(N=>(N.text??
|
|
729
733
|
"")!==""||N.fieldInstr);if(x.length===0)return;const C=x[0].fieldInstr;if(!(!C||!/^TOC\b/i.test(C.trim())))return x.every(N=>N.fieldInstr===C)?C:void 0},Zt=new Map,xr=new Set,Vt=new Set;{let d,x=[];const C=()=>{
|
|
730
|
-
d&&x.length>0&&(Zt.set(x[0],d),xr.add(x[x.length-1]),x.forEach(N=>Vt.add(N))),d=void 0,x=[]};for(const N of
|
|
731
|
-
C(),A&&
|
|
732
|
-
root)if(N?.rootKey==="w:r")return N}},
|
|
733
|
-
d)} </w:instrText>`),
|
|
734
|
-
|
|
735
|
-
root>`,C=
|
|
736
|
-
"mathblock"?
|
|
737
|
-
if(x.type==="paragraph"&&x.list?.reference){const C=`${x.list.reference}\0${x.list.instance??0}`;
|
|
738
|
-
blocks??N.paragraphs)},Cr=async(d,x)=>{const C=this.toDocxFormatWithTables({...e,children:d.children},r);Pr(C);for(const A of C)A.type==="paragraph"&&(A.inNote=!0);const N=(await Promise.all(C.map(
|
|
739
|
-
filter(A=>A!==null).map(A=>A);qt[String(x)]={children:N.length>0?N:[new w({})]}};let
|
|
740
|
-
const x=xt[d],C=1e6+d;Nr.set(x.id,C),await Cr(x,C)}const Yt=[...
|
|
741
|
-
x=tt(e.headers??d.headers,y,"header"),C=tt(e.footers??d.footers,
|
|
742
|
-
(fe.pageNumberPosition.startsWith("top")&&!Ce.headers?Ce.headers={default:new y({children:[Oe]})}:!fe.pageNumberPosition.startsWith("top")&&!Ce.footers&&(Ce.footers={default:new
|
|
743
|
-
const Te=e.coreProperties??{},
|
|
744
|
-
keywords}:{},...Te.description!==void 0?{description:Te.description}:{},...Te.lastModifiedBy!==void 0?{lastModifiedBy:Te.lastModifiedBy}:{}},
|
|
745
|
-
{name:"Revise.BlockSpacingPx",value:String(Ee(e.pageLayout).blockSpacingPx)}]}:{},numbering:ye,...
|
|
734
|
+
d&&x.length>0&&(Zt.set(x[0],d),xr.add(x[x.length-1]),x.forEach(N=>Vt.add(N))),d=void 0,x=[]};for(const N of It){const A=N.type==="paragraph"?N:void 0,V=A?ui(A):void 0;if(A&&V&&V===d){x.push(A);continue}
|
|
735
|
+
C(),A&&V&&(d=V,x=[A])}C()}const Bt=d=>{const x=`<root><w:r xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">${d}</w:r></root>`,C=J.fromXmlString(x).root?.[0];if(C?.root){for(const N of C.
|
|
736
|
+
root)if(N?.rootKey==="w:r")return N}},fi=d=>d.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),Sr=d=>[Bt('<w:fldChar w:fldCharType="begin"/>'),Bt(`<w:instrText xml:space="preserve"> ${fi(
|
|
737
|
+
d)} </w:instrText>`),Bt('<w:fldChar w:fldCharType="separate"/>')].filter(Boolean),Ir=()=>[Bt('<w:fldChar w:fldCharType="end"/>')].filter(Boolean),wi=Vt.size>0||kt.some(d=>d.children.some(x=>x.fieldInstr)),
|
|
738
|
+
bi=d=>{if(cr(d.xml))return new w({});try{const x=d.origin==="run"?`<root><w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:r>${d.xml}</w:r></w:p></root>`:`<root>${d.xml}</\
|
|
739
|
+
root>`,C=J.fromXmlString(x).root?.[0];for(const N of C?.root??[])if(N?.rootKey&&N.rootKey!=="_attr")return N}catch{}return new w({})},kr=async d=>d.type==="table"?gr(d):d.type==="codeblock"?ai(d):d.type===
|
|
740
|
+
"mathblock"?li(d):d.type==="pagebreak"?pi():d.type==="sectionbreak"?null:d.type==="image"?di(d):d.type==="docxraw"?bi(d):Xt(d),yi=await Promise.all(It.map(kr)),qt={},Rt=new Map,Pr=d=>{for(const x of d)
|
|
741
|
+
if(x.type==="paragraph"&&x.list?.reference){const C=`${x.list.reference}\0${x.list.instance??0}`;Rt.has(C)||Rt.set(C,x.list)}else if(x.type==="table")for(const C of x.rows)for(const N of C.cells)Pr(N.
|
|
742
|
+
blocks??N.paragraphs)},Cr=async(d,x)=>{const C=this.toDocxFormatWithTables({...e,children:d.children},r);Pr(C);for(const A of C)A.type==="paragraph"&&(A.inNote=!0);const N=(await Promise.all(C.map(kr))).
|
|
743
|
+
filter(A=>A!==null).map(A=>A);qt[String(x)]={children:N.length>0?N:[new w({})]}};let vi=Et.size;for(const d of hi){const x=Et.get(d.id)??++vi;await Cr(d,x)}const Nr=new Map;for(let d=0;d<xt.length;d++){
|
|
744
|
+
const x=xt[d],C=1e6+d;Nr.set(x.id,C),await Cr(x,C)}const Yt=[...Rt.keys()],xi=Yt.map((d,x)=>Xt({type:"paragraph",children:[{text:`__RVSE_NOTE_NUM_${x}__`}],list:Rt.get(d)}));{const d=Dr(e.chrome??[]),
|
|
745
|
+
x=tt(e.headers??d.headers,y,"header"),C=tt(e.footers??d.footers,T,"footer");x&&(Ce.headers=x),C&&(Ce.footers=C),e.watermark&&!Ce.headers&&(Ce.headers={default:new y({children:[new w({})]})}),fe.showPageNumbers&&
|
|
746
|
+
(fe.pageNumberPosition.startsWith("top")&&!Ce.headers?Ce.headers={default:new y({children:[Oe]})}:!fe.pageNumberPosition.startsWith("top")&&!Ce.footers&&(Ce.footers={default:new T({children:[Oe]})}))}
|
|
747
|
+
const Te=e.coreProperties??{},Si={...Te.title!==void 0?{title:Te.title}:{},...Te.subject!==void 0?{subject:Te.subject}:{},...Te.creator!==void 0?{creator:Te.creator}:{},...Te.keywords!==void 0?{keywords:Te.
|
|
748
|
+
keywords}:{},...Te.description!==void 0?{description:Te.description}:{},...Te.lastModifiedBy!==void 0?{lastModifiedBy:Te.lastModifiedBy}:{}},Ii=new n({...Si,...e.pageLayout?.blockSpacingPx!==void 0?{customProperties:[
|
|
749
|
+
{name:"Revise.BlockSpacingPx",value:String(Ee(e.pageLayout).blockSpacingPx)}]}:{},numbering:ye,...wi?{features:{updateFields:!0}}:{},...dt?{evenAndOddHeaderAndFooters:!0}:{},...Xe.length>0?{comments:{
|
|
746
750
|
children:vr.map(({id:d,record:x})=>({id:Le.get(d),author:x.author,...x.initials?{initials:x.initials}:{},date:new Date(x.createdAt),children:(x.bodyMd||" ").split(/\n\n+/).map(C=>new w({children:[new u(
|
|
747
751
|
{text:C})]}))}))}}:{},...Object.keys(qt).length>0?{footnotes:qt}:{},styles:{default:{document:{run:{size:this.DEFAULT_RUN_SIZE_HALF_POINTS}},...this.buildExportHeadingDefaults()},paragraphStyles:this.
|
|
748
|
-
buildExportParagraphStyles(e),characterStyles:this.buildExportCharacterStyles()},sections:(()=>{const d=e.chrome??[],x=
|
|
749
|
-
if(Array.from(we.keys()).some(te=>te.slot==="first"&&te.fit==="band"))return!0;const oe=
|
|
750
|
-
chromeImages??[]).flatMap((ae,
|
|
751
|
-
headers??se.headers,footers:e.footers??se.footers}})(),
|
|
752
|
+
buildExportParagraphStyles(e),characterStyles:this.buildExportCharacterStyles()},sections:(()=>{const d=e.chrome??[],x=Fi(d),C=U=>{if(["header","footer"].some(te=>Ki(d,te,"first",U)))return!0;if(!x)return ge;
|
|
753
|
+
if(Array.from(we.keys()).some(te=>te.slot==="first"&&te.fit==="band"))return!0;const oe=Fr(d,U);return!!(oe.headers?.first||oe.footers?.first)},N=new Map,A=U=>{let oe="";if(!x){if(!Nt)return Ce;const se=(e.
|
|
754
|
+
chromeImages??[]).flatMap((ae,Re)=>we.has(ae)&&!Be(ae,U)?[Re]:[]);if(se.length===0)return Ce;oe=se.join(",");const ne=N.get(oe);if(ne)return ne}const te=x?Fr(d,U):(()=>{const se=Dr(d);return{headers:e.
|
|
755
|
+
headers??se.headers,footers:e.footers??se.footers}})(),me={sectionIndex:U,bandOnly:x},ee={},Ye=tt(te.headers,y,"header",me),je=tt(te.footers,T,"footer",me);Ye&&(ee.headers=Ye),je&&(ee.footers=je),e.watermark&&
|
|
752
756
|
!ee.headers&&(ee.headers={default:new y({children:[new w({})]})}),fe.showPageNumbers&&(fe.pageNumberPosition.startsWith("top")&&!ee.headers?ee.headers={default:new y({children:[Oe]})}:!fe.pageNumberPosition.
|
|
753
|
-
startsWith("top")&&!ee.footers&&(ee.footers={default:new
|
|
754
|
-
!(e.chromeImages??[]).some(st=>st.side===se&&st.slot===
|
|
755
|
-
|
|
756
|
-
{properties:ee,...A(
|
|
757
|
-
Y.titlePage=!0:x&&Y===he&&delete Y.titlePage,
|
|
758
|
-
toBlob(
|
|
757
|
+
startsWith("top")&&!ee.footers&&(ee.footers={default:new T({children:[Oe]})}));for(const[se,ne,ae]of[["header","headers",y],["footer","footers",T]])for(const Re of["default","first","even"])ee[ne]?.[Re]||
|
|
758
|
+
!(e.chromeImages??[]).some(st=>st.side===se&&st.slot===Re&&we.has(st)&&(!x||st.fit==="band")&&!Be(st,U))||(ee[ne]={...ee[ne]??{},[Re]:new ae({children:[new w({})]})});return x||N.set(oe,ee),ee},V=[];let P=[],
|
|
759
|
+
_;It.forEach((U,oe)=>{if("type"in U&&U.type==="sectionbreak"){const me=U;ve.push(Li(e.pageLayout,me.layout));const ee=ie(me.layout,_,V.length===0?"first":"middle");C(V.length)&&(ee.titlePage=!0),V.push(
|
|
760
|
+
{properties:ee,...A(V.length),children:P}),P=[],_=me.breakType;return}const te=yi[oe];te!=null&&P.push(te)}),ve.push($i(e.pageLayout));const Y=V.length===0?he:ie(e.pageLayout,_,"final");return C(V.length)?
|
|
761
|
+
Y.titlePage=!0:x&&Y===he&&delete Y.titlePage,V.push({properties:Y,...A(V.length),children:[...P,...xi]}),V})()}),ki=await this.stabilizeHyperlinkRelIds(await this.stabilizeAttributeWhitespace(await a.
|
|
762
|
+
toBlob(Ii))),Ot=[],Qt=[...bt];let ut=0;for(const d of It){if("type"in d&&d.type==="table")continue;if("type"in d&&d.type==="docxraw"){d.emitsParagraph&&ut++;continue}if("type"in d&&d.type==="sectionbr\
|
|
759
763
|
eak"){const N=d.pendingDeletion;N&&Ot.push({pIndex:ut,kind:"merge",...N}),ut++;continue}const x=d.paragraphMarkRevision;x&&Ot.push({pIndex:ut,...x});const C=d.paragraphPropertiesChange;C&&Qt.push({pIndex:ut,
|
|
760
764
|
...C}),ut++}let Q=ki;if(ht.size>0&&(Q=await this.patchLinkedMoveRevisions(Q,Array.from(ht.values()))),Yt.length>0&&(Q=await this.patchNoteNumberingReferences(Q,Yt)),Ve&&(Q=await this.patchRunPropertyResetMarkers(
|
|
761
765
|
Q)),Ne.length>0&&(Q=await this.patchMarkedParagraphMarkRevisions(Q,Ne.map(d=>({...d,id:Fe(d.importedId)})))),ot.length>0&&(Q=await this.patchLayeredDeletions(Q,ot)),de.length>0&&(Q=await this.applyOxmlAttrMarkers(
|
|
@@ -764,50 +768,50 @@ g images inline",d)}if(At.length>0)try{Q=await this.patchOriginalVectorImages(Q,
|
|
|
764
768
|
0)try{Q=await this.patchParagraphMarkRevisions(Q,Ot,Fe)}catch(d){console.warn("docx export: paragraph-mark revision patch failed; exporting without pilcrow markup",d)}if(Qt.length>0)try{Q=await this.patchParagraphPropertyChanges(
|
|
765
769
|
Q,Qt,Fe)}catch(d){console.warn("docx export: w:pPrChange patch failed; exporting without paragraph property-change markup",d)}if(ur.length>0)try{Q=await this.patchTableRevisions(Q,ur,Fe)}catch(d){console.
|
|
766
770
|
warn("docx export: table revision patch failed; exporting table content without revision markup",d)}if(Xe.length>0)try{Q=await this.appendCommentsExtendedPart(Q,vr.map(({id:d,record:x,isClone:C})=>{const N=!C&&
|
|
767
|
-
x.parentId?
|
|
768
|
-
ments export flat/unresolved",d)}if(xt.length>0)try{Q=await this.appendEndnotesPart(Q,xt.map(d=>({index:
|
|
771
|
+
x.parentId?mr(x):void 0;return{numericId:Le.get(d),resolved:x.resolved===!0,parentNumericId:N&&N!==x.id?Le.get(N):void 0}}))}catch(d){console.warn("docx export: commentsExtended generation failed; com\
|
|
772
|
+
ments export flat/unresolved",d)}if(xt.length>0)try{Q=await this.appendEndnotesPart(Q,xt.map(d=>({index:gt.get(d.id),note:d,syntheticFootnoteId:Nr.get(d.id)})))}catch(d){console.warn("docx export: end\
|
|
769
773
|
notes part generation failed; endnote markers left in text",d)}if(e.sdtWrappers&&e.sdtWrappers.length>0)try{Q=await this.applySdtWrappers(Q,e)}catch(d){console.warn("docx export: content-control wrapp\
|
|
770
774
|
ing failed; content exported unwrapped",d)}if(e.coreProperties)try{Q=await this.patchCoreProperties(Q,Te)}catch(d){console.warn("docx export: core-property patch failed; library defaults kept",d)}if(e.
|
|
771
775
|
stylesXml)try{Q=await this.mergeImportedStyles(Q,e.stylesXml)}catch(d){console.warn("docx export: styles.xml merge failed; imported named styles dropped",d)}if(e.watermark)try{Q=await this.injectWatermarkIntoHeaders(
|
|
772
776
|
Q,e.watermark)}catch(d){console.warn("docx export: watermark header injection failed; exporting without watermark",d)}if(Ee(e.pageLayout).hyphenationEnabled)try{Q=await this.injectAutoHyphenationSetting(
|
|
773
777
|
Q)}catch(d){console.warn("docx export: autoHyphenation setting injection failed",d)}try{Q=await this.stampApplicationProperty(Q)}catch(d){console.warn("docx export: application stamp failed; exporting\
|
|
774
778
|
without it",d)}if(t?.graft&&zt){const d=x=>{try{t.graft?.onOutcome?.(x)}catch{}};if(!e.docxSource)return console.warn("docx export: graft requested but document has no docxSource capture; exporting r\
|
|
775
|
-
egenerated package"),d({mode:"regenerated",fallbackCode:"no-capture"}),Q;try{Q=await
|
|
776
|
-
act":"grafted",regeneratedBlockCount:x.regeneratedBlockIds.length,changedDomains:Object.entries(x.domains).filter(([,C])=>!C).map(([C])=>C)})}catch(x){const C=x instanceof
|
|
779
|
+
egenerated package"),d({mode:"regenerated",fallbackCode:"no-capture"}),Q;try{Q=await qi({generatedBlob:Q,originalDocx:t.graft.originalDocx,doc:e,blockRanges:zt});const x=Yi(e);d({mode:x.fullyExact?"ex\
|
|
780
|
+
act":"grafted",regeneratedBlockCount:x.regeneratedBlockIds.length,changedDomains:Object.entries(x.domains).filter(([,C])=>!C).map(([C])=>C)})}catch(x){const C=x instanceof Qi?x.code:"internalError";console.
|
|
777
781
|
warn(`docx export: OOXML graft rejected [${C}]; exporting regenerated package`,x),d({mode:"regenerated",fallbackCode:C})}}return Q}static async patchNoteNumberingReferences(e,r){const t=await this.loadZipFromBlob(
|
|
778
782
|
e),i=t.file("word/document.xml");if(!i)return e;let n=await i.async("text");const a=new Map;n=n.replace(/<w:p\b[^>]*>[\s\S]*?<\/w:p>/g,l=>{const c=/__RVSE_NOTE_NUM_(\d+)__/.exec(l);if(!c)return l;const p=Number(
|
|
779
|
-
c[1]),h=/<w:numId\b[^>]*w:val="([^"]+)"/.exec(l)?.[1],
|
|
780
|
-
l,c]of Object.entries(t.files)){if(!l.startsWith("word/")||!l.endsWith(".xml")||c.dir)continue;let p=await c.async("text"),h=!1;for(const[
|
|
781
|
-
new RegExp(`w:val="${o(
|
|
783
|
+
c[1]),h=/<w:numId\b[^>]*w:val="([^"]+)"/.exec(l)?.[1],g=r[p];return g&&h&&!h.startsWith("{")&&a.set(g,h),""}),t.file("word/document.xml",n);const o=l=>l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");for(const[
|
|
784
|
+
l,c]of Object.entries(t.files)){if(!l.startsWith("word/")||!l.endsWith(".xml")||c.dir)continue;let p=await c.async("text"),h=!1;for(const[g,f]of a){const[w,u]=g.split("\0"),m=`{${w}-${u}}`,b=p.replace(
|
|
785
|
+
new RegExp(`w:val="${o(m)}"`,"g"),`w:val="${f}"`);h||(h=b!==p),p=b}h&&t.file(l,p)}const s=await this.generateCompressedZipBlob(t);return new Blob([s],{type:"application/vnd.openxmlformats-officedocume\
|
|
782
786
|
nt.wordprocessingml.document"})}static async injectSectPrOpaquePayloads(e,r){const t=await this.loadZipFromBlob(e),i=t.file("word/document.xml");if(!i)return e;let n=await i.async("text"),a=0;n=n.replace(
|
|
783
787
|
/<w:sectPr\b[^>]*>[\s\S]*?<\/w:sectPr>|<w:sectPr\b[^>]*\/>/g,c=>{const p=r[a++];return p?c.endsWith("/>")?`${c.slice(0,-2)}>${p}</w:sectPr>`:c.replace(/<\/w:sectPr>$/,`${p}</w:sectPr>`):c});const o=new DOMParser().
|
|
784
788
|
parseFromString(n,"application/xml"),s=new Set(["w:lnNumType","w:pgNumType","w:cols","w:formProt","w:vAlign","w:noEndnote","w:titlePg","w:textDirection","w:bidi","w:rtlGutter","w:docGrid","w:printerSe\
|
|
785
|
-
ttings","w:sectPrChange"]);for(const c of Array.from(o.getElementsByTagName("w:sectPr"))){const p=Array.from(c.children).find(
|
|
789
|
+
ttings","w:sectPrChange"]);for(const c of Array.from(o.getElementsByTagName("w:sectPr"))){const p=Array.from(c.children).find(g=>g.tagName==="w:pgBorders"),h=Array.from(c.children).find(g=>s.has(g.tagName));
|
|
786
790
|
p&&h&&c.insertBefore(p,h)}n=new XMLSerializer().serializeToString(o),t.file("word/document.xml",n);const l=await this.generateCompressedZipBlob(t);return new Blob([l],{type:"application/vnd.openxmlfor\
|
|
787
791
|
mats-officedocument.wordprocessingml.document"})}static async stabilizeAttributeWhitespace(e){let r;try{r=await this.loadZipFromBlob(e)}catch{return e}const{stabilizeSerializedXml:t}=await Promise.resolve().
|
|
788
|
-
then(()=>
|
|
792
|
+
then(()=>bn);let i=!1;for(const[a,o]of Object.entries(r.files)){if(!a.endsWith(".xml")||o.dir)continue;const s=await o.async("text"),l=t(s);l!==s&&(r.file(a,l),i=!0)}if(!i)return e;const n=await this.
|
|
789
793
|
generateCompressedZipBlob(r);return new Blob([n],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async stabilizeHyperlinkRelIds(e){let r;try{r=await this.loadZipFromBlob(
|
|
790
794
|
e)}catch{return e}let t=!1;for(const[n,a]of Object.entries(r.files)){const o=/^(.*)_rels\/([^/]+)\.rels$/.exec(n);if(!o||a.dir)continue;const s=`${o[1]}${o[2]}`,l=r.file(s);if(!l)continue;let c=await a.
|
|
791
795
|
async("text");const p=[];for(const f of c.matchAll(/<Relationship\b[^>]*\/?>/g)){if(!/Type="[^"]*\/hyperlink"/.test(f[0]))continue;const w=/Id="([^"]+)"/.exec(f[0])?.[1];w&&p.push(w)}if(p.length===0)continue;
|
|
792
|
-
let h=await l.async("text");const
|
|
793
|
-
"`,`r:id="__rvseLnkTmp${w+1}__"`),c=c.replace(`Id="${f}"`,`Id="__rvseLnkTmp${w+1}__"`),t=!0)}),
|
|
796
|
+
let h=await l.async("text");const g=[...p].sort((f,w)=>{const u=h.indexOf(`"${f}"`),m=h.indexOf(`"${w}"`);return(u<0?1/0:u)-(m<0?1/0:m)});g.forEach((f,w)=>{f!==`rvseLnk${w+1}`&&(h=h.replaceAll(`r:id="${f}\
|
|
797
|
+
"`,`r:id="__rvseLnkTmp${w+1}__"`),c=c.replace(`Id="${f}"`,`Id="__rvseLnkTmp${w+1}__"`),t=!0)}),g.forEach((f,w)=>{h=h.replaceAll(`r:id="__rvseLnkTmp${w+1}__"`,`r:id="rvseLnk${w+1}"`),c=c.replace(`Id="_\
|
|
794
798
|
_rvseLnkTmp${w+1}__"`,`Id="rvseLnk${w+1}"`)}),r.file(s,h),r.file(n,c)}if(!t)return e;const i=await this.generateCompressedZipBlob(r);return new Blob([i],{type:"application/vnd.openxmlformats-officedoc\
|
|
795
799
|
ument.wordprocessingml.document"})}static async applyOxmlAttrMarkers(e,r){const t=await this.loadZipFromBlob(e);for(const[n,a]of Object.entries(t.files)){if(!n.startsWith("word/")||!n.endsWith(".xml")||
|
|
796
800
|
a.dir)continue;let o=await a.async("text");if(o.includes("<w:rvseOxmlAttrs ")){for(const s of["w:p","w:tr"])o=o.replace(new RegExp(`<${s}\\b([^>]*)>((?:(?!<${s}\\b)(?!</${s}>)[\\s\\S])*?)<w:rvseOxmlAttr\
|
|
797
|
-
s w:val="(\\d+)"/>`,"g"),(l,c,p,h)=>{const
|
|
801
|
+
s w:val="(\\d+)"/>`,"g"),(l,c,p,h)=>{const g=r[Number(h)];if(!g)return`<${s}${c}>${p}`;const f=new Set([...c.matchAll(/([\w:.-]+)=/g)].map(u=>u[1])),w=Zr(g,f);return`<${s}${c}${w}>${p}`});o=o.replace(
|
|
798
802
|
/<w:rvseOxmlAttrs w:val="\d+"\/>/g,"").replace(/<w:pPr><\/w:pPr>|<w:pPr\/>/g,"").replace(/<w:trPr><\/w:trPr>|<w:trPr\/>/g,""),t.file(n,o)}}const i=await this.generateCompressedZipBlob(t);return new Blob(
|
|
799
803
|
[i],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async patchMarkedParagraphMarkRevisions(e,r){const t=await this.loadZipFromBlob(e),i="http://schemas.openxm\
|
|
800
804
|
lformats.org/wordprocessingml/2006/main",n=new Map(r.map(o=>[o.name,o]));for(const o of["word/document.xml","word/footnotes.xml","word/endnotes.xml"]){const s=t.file(o);if(!s)continue;const l=await s.
|
|
801
|
-
async("text");if(!l.includes("__rvPm:"))continue;const c=this.parseDocumentXml(l);if(!c)continue;const p=Array.from(c.getElementsByTagName("w:bookmarkStart"));for(const h of p){const
|
|
802
|
-
"w:name")??"");if(!
|
|
805
|
+
async("text");if(!l.includes("__rvPm:"))continue;const c=this.parseDocumentXml(l);if(!c)continue;const p=Array.from(c.getElementsByTagName("w:bookmarkStart"));for(const h of p){const g=n.get(h.getAttribute(
|
|
806
|
+
"w:name")??"");if(!g)continue;const f=h.getAttribute("w:id");let w=h.parentElement;for(;w&&w.tagName!=="w:p";)w=w.parentElement;for(const y of Array.from(c.getElementsByTagName("w:bookmarkEnd")))y.getAttribute(
|
|
803
807
|
"w:id")===f&&y.parentNode?.removeChild(y);if(h.parentNode?.removeChild(h),!w)continue;let u=Array.from(w.children).find(y=>y.tagName==="w:pPr");u||(u=c.createElementNS(i,"w:pPr"),w.insertBefore(u,w.firstChild));
|
|
804
|
-
let
|
|
805
|
-
|
|
806
|
-
"w:author",
|
|
808
|
+
let m=Array.from(u.children).find(y=>y.tagName==="w:rPr");if(!m){m=c.createElementNS(i,"w:rPr");const y=Array.from(u.children).find(T=>T.tagName==="w:sectPr"||T.tagName==="w:pPrChange");u.insertBefore(
|
|
809
|
+
m,y??null)}const b=g.kind==="split"||g.kind==="insert"?"w:ins":g.kind==="moveTo"?"w:moveTo":g.kind==="moveFrom"?"w:moveFrom":"w:del",v=c.createElementNS(i,b);v.setAttribute("w:id",String(g.id)),v.setAttribute(
|
|
810
|
+
"w:author",g.author),v.setAttribute("w:date",g.date),m.insertBefore(v,m.firstChild)}t.file(o,new XMLSerializer().serializeToString(c))}const a=await this.generateCompressedZipBlob(t);return new Blob([
|
|
807
811
|
a],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async patchLayeredDeletions(e,r){const t=o=>o.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").
|
|
808
812
|
replace(/"/g,"""),i=new Map(r.map(o=>[o.deletionId,o])),n=await this.loadZipFromBlob(e);for(const[o,s]of Object.entries(n.files)){if(!o.startsWith("word/")||!o.endsWith(".xml")||s.dir)continue;const l=await s.
|
|
809
|
-
async("text");if(!l.includes("<w:del "))continue;const c=l.replace(/<w:del\b[^>]*\bw:id="(\d+)"[^>]*(?<!\/)>[\s\S]*?<\/w:del>/g,(p,h)=>{const
|
|
810
|
-
" w:author="${t(
|
|
813
|
+
async("text");if(!l.includes("<w:del "))continue;const c=l.replace(/<w:del\b[^>]*\bw:id="(\d+)"[^>]*(?<!\/)>[\s\S]*?<\/w:del>/g,(p,h)=>{const g=i.get(Number(h));return g?`<w:ins w:id="${g.insertionId}\
|
|
814
|
+
" w:author="${t(g.author)}" w:date="${g.date}">${p}</w:ins>`:p});c!==l&&n.file(o,c)}const a=await this.generateCompressedZipBlob(n);return new Blob([a],{type:"application/vnd.openxmlformats-officedocu\
|
|
811
815
|
ment.wordprocessingml.document"})}static async patchRunPropertyResetMarkers(e){const r=await this.loadZipFromBlob(e);for(const[i,n]of Object.entries(r.files)){if(!i.startsWith("word/")||!i.endsWith(".\
|
|
812
816
|
xml")||n.dir)continue;let a=await n.async("text");/<w:(?:specVanish|imprint|emboss|snapToGrid)\b/.test(a)&&(a=a.replace(/<w:specVanish\b[^>]*\/>/g,'<w:vanish w:val="false"/>').replace(/<w:imprint\b[^>]*\/>/g,
|
|
813
817
|
'<w:spacing w:val="0"/>').replace(/<w:emboss\b[^>]*\/>/g,'<w:vertAlign w:val="baseline"/>').replace(/<w:snapToGrid\b([^>]*)\/>/g,(o,s)=>/\bw:val="(?:false|0|off)"/i.test(s)?'<w:caps w:val="false"/>':"\
|
|
@@ -822,20 +826,20 @@ s.onload=()=>{clearTimeout(o);try{const l=document.createElement("canvas");l.wid
|
|
|
822
826
|
s,0,0,l.width,l.height),l.toBlob(async p=>{if(!p){a(void 0);return}a(new Uint8Array(await p.arrayBuffer()))},"image/png")}catch{a(void 0)}},s.onerror=()=>{clearTimeout(o),a(void 0)},s.src=e})}static serializeXmlPreservingPrefixes(e){
|
|
823
827
|
const r=new Map,t=(a,o)=>{const s=o.indexOf(":");if(s<=0)return;const l=o.slice(0,s);if(l==="xmlns"||l==="xml"||r.has(l))return;const c=a.lookupNamespaceURI(l);c&&r.set(l,c)},i=a=>{t(a,a.tagName);for(let o=0;o<
|
|
824
828
|
a.attributes.length;o++)t(a,a.attributes[o].name);for(let o=0;o<a.children.length;o++)i(a.children[o])};i(e);const n=(a,o)=>{if(a.nodeType===3)return(a.nodeValue??"").replace(/&/g,"&").replace(/</g,
|
|
825
|
-
"<").replace(/>/g,">");if(a.nodeType!==1)return"";const s=a;let l=`<${s.tagName}`;const c=new Set;for(let h=0;h<s.attributes.length;h++){const
|
|
826
|
-
|
|
829
|
+
"<").replace(/>/g,">");if(a.nodeType!==1)return"";const s=a;let l=`<${s.tagName}`;const c=new Set;for(let h=0;h<s.attributes.length;h++){const g=s.attributes[h];g.name.startsWith("xmlns:")&&c.add(
|
|
830
|
+
g.name.slice(6)),l+=` ${g.name}="${this.escapeXml(g.value)}"`}if(o)for(const[h,g]of r)c.has(h)||(l+=` xmlns:${h}="${this.escapeXml(g)}"`);const p=s.childNodes;if(p.length===0)return`${l}/>`;l+=">";for(let h=0;h<
|
|
827
831
|
p.length;h++)l+=n(p[h],!1);return`${l}</${s.tagName}>`};return n(e,!0)}static async patchAnchoredImages(e,r){const t=await this.loadZipFromBlob(e),i=t.file("word/document.xml");if(!i)return e;let n=await i.
|
|
828
832
|
async("string"),a=!1;for(const o of r){const s=`title="${this.escapeXml(o.marker)}"`,l=n.indexOf(s);if(l===-1)continue;const c=()=>{n=n.replace(` ${s}`,""),a=!0},p=n.lastIndexOf("<wp:inline",l),h=n.indexOf(
|
|
829
|
-
"</wp:inline>",l);if(p===-1||h===-1){c();continue}const
|
|
830
|
-
(v,y,
|
|
831
|
-
/\s+descr="[^"]*"/,""),
|
|
833
|
+
"</wp:inline>",l);if(p===-1||h===-1){c();continue}const g=h+12,f=n.slice(p,g),w=Array.from(f.matchAll(/r:embed="([^"]+)"/g)).map(v=>v[1]);if(w.length===0){c();continue}let u=0,m=o.anchorXml.replace(/(r:(?:embed|link)=")[^"]*(")/g,
|
|
834
|
+
(v,y,T)=>{const L=w[Math.min(u,w.length-1)];return u++,`${y}${L}${T}`});const b=f.match(/<wp:docPr\b[^>]*/)?.[0].match(/ descr="([^"]*)"/);m=m.replace(/<wp:docPr\b([^>]*?)(\/?>)/,(v,y,T)=>{const L=y.replace(
|
|
835
|
+
/\s+descr="[^"]*"/,""),W=b?` descr="${b[1]}"`:"";return`<wp:docPr${L}${W}${T}`}),n=n.slice(0,p)+m+n.slice(g),a=!0}return a?(t.file("word/document.xml",n),this.generateCompressedZipBlob(t)):e}static async patchOriginalVectorImages(e,r){
|
|
832
836
|
const t=await this.loadZipFromBlob(e),i=t.file("word/document.xml"),n=t.file("word/_rels/document.xml.rels"),a=t.file("[Content_Types].xml");if(!i||!n||!a)return e;let o=await i.async("string"),s=await n.
|
|
833
|
-
async("string"),l=await a.async("string");const c=new Set;for(let p=0;p<r.length;p++){const h=r[p],
|
|
834
|
-
indexOf(f);if(w===-1)continue;const u=o.slice(w).match(/r:embed="([^"]+)"/);if(!u)continue;const
|
|
835
|
-
Target=")[^"]*(")`),y=new RegExp(`(<Relationship\\b[^>]*\\bTarget=")[^"]*("[^>]*\\bId="${
|
|
836
|
-
`word/${b}`,
|
|
837
|
+
async("string"),l=await a.async("string");const c=new Set;for(let p=0;p<r.length;p++){const h=r[p],g=await this.resolveBinarySourceForDocx(h.dataUrl);if(!g)continue;const f=this.escapeXml(h.marker),w=o.
|
|
838
|
+
indexOf(f);if(w===-1)continue;const u=o.slice(w).match(/r:embed="([^"]+)"/);if(!u)continue;const m=u[1],b=`media/reviseOriginal${p}.${h.format}`,v=new RegExp(`(<Relationship\\b[^>]*\\bId="${m}"[^>]*\\b\
|
|
839
|
+
Target=")[^"]*(")`),y=new RegExp(`(<Relationship\\b[^>]*\\bTarget=")[^"]*("[^>]*\\bId="${m}")`);if(v.test(s))s=s.replace(v,`$1${b}$2`);else if(y.test(s))s=s.replace(y,`$1${b}$2`);else continue;t.file(
|
|
840
|
+
`word/${b}`,g),c.add(h.format),o=h.alt?o.replace(`descr="${f}"`,`descr="${this.escapeXml(h.alt)}"`):o.replace(` descr="${f}"`,"")}for(const p of c)new RegExp(`Extension="${p}"`).test(l)||(l=l.replace(
|
|
837
841
|
"</Types>",`<Default Extension="${p}" ContentType="image/x-${p}"/></Types>`));return t.file("word/document.xml",o),t.file("word/_rels/document.xml.rels",s),t.file("[Content_Types].xml",l),this.generateCompressedZipBlob(
|
|
838
|
-
t)}static async injectWatermarkIntoHeaders(e,r){const t=
|
|
842
|
+
t)}static async injectWatermarkIntoHeaders(e,r){const t=ln(r);if(!t)return e;const i=await this.loadZipFromBlob(e),n=Object.keys(i.files).filter(f=>/^word\/header\d+\.xml$/.test(f));if(n.length===0)return e;
|
|
839
843
|
const a=f=>f.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""),o=468,s=Math.max(40,Math.round(o/Math.max(2,t.text.length*.55))),l=t.diagonal?"rotation:315;":"",c=t.
|
|
840
844
|
fontSizePx?`${Math.max(1,Math.round(t.fontSizePx*.75))}pt`:"1pt",p=`<w:p><w:pPr><w:rPr><w:noProof/></w:rPr></w:pPr><w:r><w:rPr><w:noProof/></w:rPr><w:pict xmlns:v="urn:schemas-microsoft-com:vml" xmlns\
|
|
841
845
|
:o="urn:schemas-microsoft-com:office:office" xmlns:w10="urn:schemas-microsoft-com:office:word"><v:shapetype id="_x0000_t136" coordsize="21600,21600" o:spt="136" adj="10800" path="m@7,l@8,m@5,21600l@6,\
|
|
@@ -844,164 +848,164 @@ fontSizePx?`${Math.max(1,Math.round(t.fontSizePx*.75))}pt`:"1pt",p=`<w:p><w:pPr>
|
|
|
844
848
|
nnecttype="custom" o:connectlocs="@9,0;@10,10800;@11,21600;@12,10800" o:connectangles="270,180,90,0"/><v:textpath on="t" fitshape="t"/><v:handles><v:h position="#0,bottomRight" xrange="6629,14971"/></\
|
|
845
849
|
v:handles><o:lock v:ext="edit" text="t" shapetype="t"/></v:shapetype><v:shape id="PowerPlusWaterMarkObject1" o:spid="_x0000_s2049" type="#_x0000_t136" style="position:absolute;margin-left:0;margin-top\
|
|
846
850
|
:0;width:${o}pt;height:${s}pt;${l}z-index:-251654144;mso-position-horizontal:center;mso-position-horizontal-relative:margin;mso-position-vertical:center;mso-position-vertical-relative:margin" o:allowi\
|
|
847
|
-
ncell="f" fillcolor="${a(t.color)}" stroked="f"><v:fill opacity="${t.opacity===
|
|
851
|
+
ncell="f" fillcolor="${a(t.color)}" stroked="f"><v:fill opacity="${t.opacity===cn?$r:t.opacity}"/><v:textpath style="font-family:"Calibri";font-size:${c}" string="${a(t.text)}"/></v:shape></\
|
|
848
852
|
w:pict></w:r></w:p>`;let h=!1;for(const f of n){const w=await i.file(f).async("text");if(w.includes("v:textpath"))continue;const u=w.replace(/(<w:hdr[^>]*>)/,`$1${p}`);u!==w&&(i.file(f,u),h=!0)}if(!h)
|
|
849
|
-
return e;const
|
|
850
|
-
loadZipFromBlob(e),i=t.file("word/styles.xml");if(!i)return e;let n=await i.async("text");const a=r.match(/<w:docDefaults\b[\s\S]*?<\/w:docDefaults>/)?.[0];a
|
|
851
|
-
test(n)?n=n.replace(/<w:docDefaults\b[\s\S]*?<\/w:docDefaults>/,a):n=n.replace(/(<w:styles\b[^>]*>)/,`$1${a}`)
|
|
852
|
-
match(/w:styleId="([^"]+)"/);
|
|
853
|
-
void 0;return b?(s.add(
|
|
854
|
-
c.add(
|
|
855
|
-
const g=u[0].match(/w:styleId="([^"]+)"/);
|
|
856
|
-
u,g))for(const b of
|
|
857
|
-
return!g
|
|
858
|
-
t"})}static async patchCoreProperties(e,r){const t=await this.loadZipFromBlob(
|
|
859
|
-
"<").replace(/>/g,">");for(const l of["created","modified"]){const c=r[l];
|
|
860
|
-
n=n.replace(/<\/cp:coreProperties>/,`<dcterms:${l} xsi:type="dcterms:W3CDTF">${a(
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
async("text");const n="<Application>Revise (revise.io)</Application>";if(/<Application[\s>]/.test(i))return e;
|
|
865
|
-
</Properties>`);else if(i.includes("</Properties>"))i=i.replace("</Properties>",`${n}</Properties>`);else return e;
|
|
866
|
-
[a],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async appendCommentsExtendedPart(e,r){
|
|
867
|
-
return e;let n=await i.async("text");n.includes("xmlns:w14=")||(n=n.replace(/<w:comments /,'<w:comments xmlns:w14="http://
|
|
868
|
-
16).toUpperCase().padStart(8,"0");n=n.replace(/<w:comment\b([^>]*)>([\s\S]*?)<\/w:comment>/g,(p,h,
|
|
869
|
-
if(u===-1)return p;const g
|
|
870
|
-
encoding="UTF-8" standalone="yes"?><w15:commentsEx xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
|
|
871
|
-
|
|
872
|
-
].xml");if(s){let p=await s.async("text");p.includes("/word/commentsExtended.xml")||(p=p.replace("</Types>",'<
|
|
873
|
-
-officedocument.wordprocessingml.commentsExtended+xml"/></Types>'),t.file("[Content_Types].xml",p))}const l=t.file("
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
__`;for(const b of["w:t","w:delText"])n=n.replaceAll(`<${b} xml:space="preserve">${
|
|
878
|
-
file("word/document.xml",n);const a=new Map;let o='<w:endnotes xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/
|
|
879
|
-
text");const
|
|
880
|
-
y=>{const
|
|
881
|
-
|
|
882
|
-
set(
|
|
883
|
-
/</g,"<").replace(/>/g,">"),c=(u,
|
|
884
|
-
|
|
885
|
-
b.
|
|
886
|
-
"/>`),b.fontFamily){const
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
"paragraph").map((
|
|
891
|
-
(
|
|
892
|
-
"
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
/_rels/document.xml.rels");if(f){let u=await f.async("text");u.includes("endnotes.
|
|
896
|
-
|
|
897
|
-
application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static emittedBodySlotCount(e){
|
|
898
|
-
section-break":return 1;case"list":return e.children.filter(r=>r.type==="list-item").length;default:return 0}}static async applySdtWrappers(e,r){
|
|
899
|
-
loadZipFromBlob(e),n=i.file("word/document.xml");if(!n)return e;const a=await n.async("text"),o=this.parseDocumentXml(a);if(!o)return e;
|
|
900
|
-
http://schemas.openxmlformats.org/wordprocessingml/2006/main",c=Array.from(s.children).filter(O=>O.tagName==="w:p"||O.tagName==="w:
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
if(
|
|
904
|
-
`<w:root xmlns:w="${l}">${O.prXml}</w:root>`)?.getElementsByTagName("w:sdtPr")[0]??void 0,v=(O,
|
|
905
|
-
|
|
906
|
-
getAttribute("w:name")??"").startsWith("__rvSdt:"));if(O.length>0){const
|
|
907
|
-
S.parentNode&&(S.parentNode.removeChild(S),u=!0)},
|
|
908
|
-
"inline"||
|
|
909
|
-
|
|
910
|
-
1&&
|
|
911
|
-
from(
|
|
912
|
-
gridCol:S.byId.get(
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
if(
|
|
916
|
-
1}),H.length===0)continue;const
|
|
917
|
-
0){console.warn(`docx export: content control ${O.id} has no surviving member blocks; dropping wrapper`);continue}const
|
|
918
|
-
filter(
|
|
919
|
-
parentId&&!
|
|
920
|
-
get(H)).filter(H=>H!==void 0).sort((H,
|
|
921
|
-
1],S=
|
|
922
|
-
1;)
|
|
923
|
-
|
|
853
|
+
return e;const g=await this.generateCompressedZipBlob(i);return new Blob([g],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async mergeImportedStyles(e,r){const t=await this.
|
|
854
|
+
loadZipFromBlob(e),i=t.file("word/styles.xml");if(!i)return e;let n=await i.async("text");const a=r.match(/<w:docDefaults\b[\s\S]*?<\/w:docDefaults>/)?.[0];a?/<w:docDefaults\b[\s\S]*?<\/w:docDefaults>/.
|
|
855
|
+
test(n)?n=n.replace(/<w:docDefaults\b[\s\S]*?<\/w:docDefaults>/,a):n=n.replace(/(<w:styles\b[^>]*>)/,`$1${a}`):n=n.replace(/<w:docDefaults\b[\s\S]*?<\/w:docDefaults>/,"");const o=new Map;for(const u of r.
|
|
856
|
+
matchAll(/<w:style\b[^>]*>[\s\S]*?<\/w:style>/g)){const m=u[0].match(/w:styleId="([^"]+)"/);m&&o.set(m[1],u[0])}if(o.size===0&&!a)return e;const s=new Set;n=n.replace(/<w:style\b[^>]*>[\s\S]*?<\/w:style>/g,
|
|
857
|
+
u=>{const m=u.match(/w:styleId="([^"]+)"/),b=m?o.get(m[1]):void 0;return b?(s.add(m[1]),b):u});const l=[];for(const[u,m]of o)s.has(u)||l.push(m);n=n.replace(/<\/w:styles>/,`${l.join("")}</w:styles>`);
|
|
858
|
+
const c=new Set,p=u=>{for(const m of u.matchAll(/<w:(?:pStyle|rStyle|tblStyle)\b[^>]*w:val="([^"]+)"/g))c.add(m[1])};for(const u of Object.keys(t.files))/^word\/[^/]+\.xml$/.test(u)&&u!=="word/styles.\
|
|
859
|
+
xml"&&p(await t.file(u).async("text"));const h=new Map;for(const u of n.matchAll(/<w:style\b[^>]*>[\s\S]*?<\/w:style>/g)){const m=u[0].match(/w:styleId="([^"]+)"/);m&&h.set(m[1],u[0])}const g=(u,m)=>o.
|
|
860
|
+
has(u)||/w:default="(?:1|true)"/.test(m.slice(0,m.indexOf(">")))||c.has(u);let f=!0;for(;f;){f=!1;for(const[u,m]of h)if(g(u,m))for(const b of m.matchAll(/<w:(?:basedOn|link|next)\b[^>]*w:val="([^"]+)"/g))
|
|
861
|
+
c.has(b[1])||(c.add(b[1]),f=!0)}n=n.replace(/<w:style\b[^>]*>[\s\S]*?<\/w:style>/g,u=>{const m=u.match(/w:styleId="([^"]+)"/);return!m||g(m[1],u)?u:""}),t.file("word/styles.xml",n);const w=await this.
|
|
862
|
+
generateCompressedZipBlob(t);return new Blob([w],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async patchCoreProperties(e,r){const t=await this.loadZipFromBlob(
|
|
863
|
+
e),i=t.file("docProps/core.xml");if(!i)return e;let n=await i.async("text");const a=l=>l.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");for(const l of["created","modified"]){const c=r[l];
|
|
864
|
+
if(!c)continue;const p=new RegExp(`(<dcterms:${l}\\b[^>]*>)[^<]*(</dcterms:${l}>)`);p.test(n)?n=n.replace(p,`$1${a(c)}$2`):n=n.replace(/<\/cp:coreProperties>/,`<dcterms:${l} xsi:type="dcterms:W3CDTF">${a(
|
|
865
|
+
c)}</dcterms:${l}></cp:coreProperties>`)}const o=/<cp:revision>[^<]*<\/cp:revision>/;if(r.revision){const l=`<cp:revision>${a(r.revision)}</cp:revision>`;n=o.test(n)?n.replace(o,l):n.replace(/<\/cp:coreProperties>/,
|
|
866
|
+
`${l}</cp:coreProperties>`)}else n=n.replace(o,"");for(const[l,c]of[["creator","dc:creator"],["lastModifiedBy","cp:lastModifiedBy"]])r[l]||(n=n.replace(new RegExp(`<${c}>[^<]*</${c}>`),""));t.file("do\
|
|
867
|
+
cProps/core.xml",n);const s=await this.generateCompressedZipBlob(t);return new Blob([s],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async stampApplicationProperty(e){
|
|
868
|
+
const r=await this.loadZipFromBlob(e),t=r.file("docProps/app.xml");if(!t)return e;let i=await t.async("text");const n="<Application>Revise (revise.io)</Application>";if(/<Application[\s>]/.test(i))return e;
|
|
869
|
+
if(/<Properties\b[^>]*\/>/.test(i))i=i.replace(/<Properties\b([^>]*)\/>/,`<Properties$1>${n}</Properties>`);else if(i.includes("</Properties>"))i=i.replace("</Properties>",`${n}</Properties>`);else return e;
|
|
870
|
+
r.file("docProps/app.xml",i);const a=await this.generateCompressedZipBlob(r);return new Blob([a],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async appendCommentsExtendedPart(e,r){
|
|
871
|
+
const t=await this.loadZipFromBlob(e),i=t.file("word/comments.xml");if(!i)return e;let n=await i.async("text");n.includes("xmlns:w14=")||(n=n.replace(/<w:comments /,'<w:comments xmlns:w14="http://sche\
|
|
872
|
+
mas.microsoft.com/office/word/2010/wordml" '));const a=p=>(268435456+p).toString(16).toUpperCase().padStart(8,"0");n=n.replace(/<w:comment\b([^>]*)>([\s\S]*?)<\/w:comment>/g,(p,h,g)=>{const f=h.match(
|
|
873
|
+
/w:id="(\d+)"/);if(!f)return p;const w=a(parseInt(f[1],10)),u=g.lastIndexOf("<w:p");if(u===-1)return p;const m=g.slice(0,u)+g.slice(u).replace(/<w:p(\s|>)/,`<w:p w14:paraId="${w}"$1`);return`<w:commen\
|
|
874
|
+
t${h}>${m}</w:comment>`}),t.file("word/comments.xml",n);const o='<?xml version="1.0" encoding="UTF-8" standalone="yes"?><w15:commentsEx xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"\
|
|
875
|
+
>'+r.map(({numericId:p,resolved:h,parentNumericId:g})=>`<w15:commentEx ${[`w15:paraId="${a(p)}"`,...g!==void 0?[`w15:paraIdParent="${a(g)}"`]:[],`w15:done="${h?"1":"0"}"`].join(" ")}/>`).join("")+"</w\
|
|
876
|
+
15:commentsEx>";t.file("word/commentsExtended.xml",o);const s=t.file("[Content_Types].xml");if(s){let p=await s.async("text");p.includes("/word/commentsExtended.xml")||(p=p.replace("</Types>",'<Overri\
|
|
877
|
+
de PartName="/word/commentsExtended.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml"/></Types>'),t.file("[Content_Types].xml",p))}const l=t.file("\
|
|
878
|
+
word/_rels/document.xml.rels");if(l){let p=await l.async("text");p.includes("commentsExtended.xml")||(p=p.replace("</Relationships>",'<Relationship Id="rIdRvseCommentsEx" Type="http://schemas.microsof\
|
|
879
|
+
t.com/office/2011/relationships/commentsExtended" Target="commentsExtended.xml"/></Relationships>'),t.file("word/_rels/document.xml.rels",p))}const c=await this.generateCompressedZipBlob(t);return new Blob(
|
|
880
|
+
[c],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async appendEndnotesPart(e,r){const t=await this.loadZipFromBlob(e),i=t.file("word/document.xml");if(!i)return e;
|
|
881
|
+
let n=await i.async("text");for(const{index:u}of r){const m=`__RVSE_EN_${u}__`;for(const b of["w:t","w:delText"])n=n.replaceAll(`<${b} xml:space="preserve">${m}</${b}>`,`<w:endnoteReference w:id="${u}\
|
|
882
|
+
"/>`).replaceAll(`<${b}>${m}</${b}>`,`<w:endnoteReference w:id="${u}"/>`)}t.file("word/document.xml",n);const a=new Map;let o='<w:endnotes xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2\
|
|
883
|
+
006/main">';const s=t.file("word/footnotes.xml");if(s){let u=await s.async("text");const m=u.match(/<w:footnotes\b[^>]*>/)?.[0];m&&(o=m.replace(/<w:footnotes\b/,"<w:endnotes"));const b=new Set(r.map(y=>y.
|
|
884
|
+
syntheticFootnoteId).filter(y=>y!==void 0));u=u.replace(/<w:footnote\b[^>]*>[\s\S]*?<\/w:footnote>/g,y=>{const T=/\bw:id="(-?\d+)"/.exec(y)?.[1],L=T?Number(T):NaN;if(!b.has(L))return y;const W=r.find(
|
|
885
|
+
D=>D.syntheticFootnoteId===L);if(!W)return y;const X=y.replace(/^<w:footnote\b[^>]*>/,`<w:endnote w:id="${W.index}">`).replace(/<\/w:footnote>$/,"</w:endnote>").replaceAll("w:footnoteRef","w:endnoteRe\
|
|
886
|
+
f").replaceAll("FootnoteReference","EndnoteReference").replaceAll("FootnoteText","EndnoteText");return a.set(L,X),""}),t.file("word/footnotes.xml",u);const v=t.file("word/_rels/footnotes.xml.rels");v&&
|
|
887
|
+
t.file("word/_rels/endnotes.xml.rels",await v.async("text"))}const l=u=>u.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"),c=(u,m)=>{const b=u.marks??{},v=[];if(b.bold&&v.push("<w:b/>"),
|
|
888
|
+
b.italic&&v.push("<w:i/>"),b.underline&&v.push('<w:u w:val="single"/>'),b.strikethrough&&v.push("<w:strike/>"),b.doubleStrikethrough&&v.push("<w:dstrike/>"),b.smallCaps&&v.push("<w:smallCaps/>"),b.allCaps&&
|
|
889
|
+
v.push("<w:caps/>"),b.hidden&&v.push("<w:vanish/>"),b.color&&v.push(`<w:color w:val="${l(this.normalizeColor(b.color))}"/>`),b.backgroundColor&&v.push(`<w:highlight w:val="${l(b.backgroundColor)}"/>`),
|
|
890
|
+
typeof b.fontSize=="number"&&b.fontSize>0&&v.push(`<w:sz w:val="${Math.max(2,Math.round(b.fontSize*this.DOCX_HALF_POINTS_PER_PX))}"/>`),b.fontFamily){const T=l(b.fontFamily.split(",")[0].replaceAll('"',
|
|
891
|
+
"").replaceAll("'","").trim());v.push(`<w:rFonts w:ascii="${T}" w:hAnsi="${T}"/>`)}typeof b.letterSpacing=="number"&&Number.isFinite(b.letterSpacing)&&b.letterSpacing!==0&&v.push(`<w:spacing w:val="${Math.
|
|
892
|
+
round(b.letterSpacing*15)}"/>`),b.superscript?v.push('<w:vertAlign w:val="superscript"/>'):b.subscript&&v.push('<w:vertAlign w:val="subscript"/>'),b.lang&&v.push(`<w:lang w:val="${l(b.lang)}"/>`);const y=m&&
|
|
893
|
+
!/^\s/.test(u.text??"")?` ${u.text??""}`:u.text??"";return`<w:r>${v.length>0?`<w:rPr>${v.join("")}</w:rPr>`:""}<w:t xml:space="preserve">${l(y)}</w:t></w:r>`},p=r.sort((u,m)=>u.index-m.index).map(({index:u,
|
|
894
|
+
note:m,syntheticFootnoteId:b})=>{const v=b!==void 0?a.get(b):void 0;if(v)return v;const y=m.children.filter(T=>T.type==="paragraph").map((T,L)=>'<w:p><w:pPr><w:pStyle w:val="EndnoteText"/></w:pPr><w:r\
|
|
895
|
+
><w:rPr><w:rStyle w:val="EndnoteReference"/></w:rPr><w:endnoteRef/></w:r>'+(T.children.filter(W=>(W.text??"")!=="").map((W,X)=>c(W,L===0&&X===0)).join("")||'<w:r><w:t xml:space="preserve"> </w:t></w:r\
|
|
896
|
+
>')+"</w:p>").join("");return`<w:endnote w:id="${u}">${y}</w:endnote>`}).join(""),h='<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'+o+'<w:endnote w:type="separator" w:id="-1"><w:p><w:r><w:se\
|
|
897
|
+
parator/></w:r></w:p></w:endnote><w:endnote w:type="continuationSeparator" w:id="0"><w:p><w:r><w:continuationSeparator/></w:r></w:p></w:endnote>'+p+"</w:endnotes>";t.file("word/endnotes.xml",h);const g=t.
|
|
898
|
+
file("[Content_Types].xml");if(g){let u=await g.async("text");u.includes("/word/endnotes.xml")||(u=u.replace("</Types>",'<Override PartName="/word/endnotes.xml" ContentType="application/vnd.openxmlfor\
|
|
899
|
+
mats-officedocument.wordprocessingml.endnotes+xml"/></Types>'),t.file("[Content_Types].xml",u))}const f=t.file("word/_rels/document.xml.rels");if(f){let u=await f.async("text");u.includes("endnotes.xm\
|
|
900
|
+
l")||(u=u.replace("</Relationships>",'<Relationship Id="rIdRvseEndnotes" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/endnotes" Target="endnotes.xml"/></Relationships>'),t.
|
|
901
|
+
file("word/_rels/document.xml.rels",u))}const w=await this.generateCompressedZipBlob(t);return new Blob([w],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static emittedBodySlotCount(e){
|
|
902
|
+
switch(e.type){case"paragraph":case"table":case"code":case"math":case"image":case"page-break":case"section-break":return 1;case"list":return e.children.filter(r=>r.type==="list-item").length;default:return 0}}static async applySdtWrappers(e,r){
|
|
903
|
+
const t=r.sdtWrappers??[];if(t.length===0)return e;const i=await this.loadZipFromBlob(e),n=i.file("word/document.xml");if(!n)return e;const a=await n.async("text"),o=this.parseDocumentXml(a);if(!o)return e;
|
|
904
|
+
const s=o.getElementsByTagName("w:body")[0];if(!s)return e;const l="http://schemas.openxmlformats.org/wordprocessingml/2006/main",c=Array.from(s.children).filter(O=>O.tagName==="w:p"||O.tagName==="w:t\
|
|
905
|
+
bl"),p=r.children.filter(O=>O.type!=="footnote"&&O.type!=="header-footer"),h=new Map,g=[];let f=!0;{let O=0;p.forEach((I,B)=>{I.id&&h.set(I.id,B),g[B]=O,O+=this.emittedBodySlotCount(I)}),O!==c.length&&
|
|
906
|
+
(console.warn(`docx export: content-control slot accounting mismatch (${O} computed vs ${c.length} body elements); exporting without sdt wrappers`),f=!1)}const w=O=>{if(O.blockIds&&O.blockIds.length>0)
|
|
907
|
+
return O.blockIds;const I=O.startBlockId?h.get(O.startBlockId):void 0;if(I===void 0)return[];const B=Math.min(I+Math.max(1,O.blockCount??1),p.length);return p.slice(I,B).map(E=>E.id).filter(E=>!!E)};let u=!1;
|
|
908
|
+
const m=new Map(t.map(O=>[O.id,O])),b=O=>this.parseDocumentXml(`<w:root xmlns:w="${l}">${O.prXml}</w:root>`)?.getElementsByTagName("w:sdtPr")[0]??void 0,v=(O,I)=>{const B=O[0].parentNode;if(!B)return;
|
|
909
|
+
const E=o.createElementNS(l,"w:sdt"),S=o.createElementNS(l,"w:sdtContent");B.insertBefore(E,O[0]),E.appendChild(o.importNode(I,!0)),E.appendChild(S);for(const R of O)S.appendChild(R);u=!0};{const O=Array.
|
|
910
|
+
from(o.getElementsByTagName("w:bookmarkStart")).filter(I=>(I.getAttribute("w:name")??"").startsWith("__rvSdt:"));if(O.length>0){const I=new Map;for(const S of Array.from(o.getElementsByTagName("w:book\
|
|
911
|
+
markEnd"))){const R=S.getAttribute("w:id");R&&I.set(R,S)}const B=S=>{S.parentNode&&(S.parentNode.removeChild(S),u=!0)},E=[];for(const S of O){const R=(S.getAttribute("w:name")??"").slice(8).split(":")[0],
|
|
912
|
+
z=I.get(S.getAttribute("w:id")??""),$=m.get(R);if(!z||!$||$.scope!=="inline"||z.parentNode!==S.parentNode||!S.parentNode){B(S),z&&B(z);continue}let H=0;for(let K=S.nextSibling;K&&K!==z;K=K.nextSibling)
|
|
913
|
+
H++;E.push({record:$,start:S,end:z,covered:H})}E.sort((S,R)=>S.covered-R.covered);for(const S of E){const R=S.start.parentNode===S.end.parentNode&&S.start.parentNode?b(S.record):void 0;if(R){const z=[];
|
|
914
|
+
for(let $=S.start.nextSibling;$&&$!==S.end;$=$.nextSibling)$.nodeType===1&&z.push($);z.length>0&&v(z,R)}B(S.start),B(S.end)}}}const y=new Map,T=new Map,L=new Map;f&&p.forEach((O,I)=>{if(O.type!=="tabl\
|
|
915
|
+
e")return;const B=c[g[I]];if(!B||B.tagName!=="w:tbl")return;L.set(I,Array.from(B.children).filter(R=>R.tagName==="w:tr"));const E=O,S=Qe(E);E.children.forEach((R,z)=>{R.id&&y.set(R.id,{tableIndex:I,rowIndex:z});
|
|
916
|
+
for(const $ of R.children)$.id&&T.set($.id,{tableIndex:I,rowIndex:z,gridCol:S.byId.get($.id)?.col??0})})});for(const O of t){if(O.scope!=="cell")continue;if(!f)break;const I=(O.blockIds??[]).map(S=>T.
|
|
917
|
+
get(S)).filter(S=>!!S);if(I.length===0){console.warn(`docx export: content control ${O.id} has no surviving member blocks; dropping wrapper`);continue}const B=b(O);if(!B)continue;const E=new Map;for(const S of I){
|
|
918
|
+
const R=`${S.tableIndex}:${S.rowIndex}`;E.set(R,[...E.get(R)??[],S])}for(const S of E.values()){const R=L.get(S[0].tableIndex)?.[S[0].rowIndex];if(!R)continue;const z=new Set(S.map(k=>k.gridCol)),$=Array.
|
|
919
|
+
from(R.children).filter(k=>k.tagName==="w:tc"),H=[];let K=0;if($.forEach((k,j)=>{z.has(K)&&H.push(j);const G=this.getDirectChild(k,"w:tcPr"),q=G?this.getDirectChild(G,"w:gridSpan")?.getAttribute("w:va\
|
|
920
|
+
l"):void 0,Z=q?parseInt(q,10):1;K+=Number.isFinite(Z)&&Z>0?Z:1}),H.length===0)continue;const J=H[0],re=H[H.length-1];v($.slice(J,re+1),B)}}for(const O of t){if(O.scope!=="row")continue;if(!f)break;const I=(O.
|
|
921
|
+
blockIds??[]).map($=>y.get($)).filter($=>!!$);if(I.length===0){console.warn(`docx export: content control ${O.id} has no surviving member blocks; dropping wrapper`);continue}const B=b(O);if(!B)continue;
|
|
922
|
+
const E=I[0].tableIndex,S=L.get(E);if(!S)continue;const R=I.filter($=>$.tableIndex===E).map($=>$.rowIndex).sort(($,H)=>$-H),z=S.slice(R[0],R[R.length-1]+1).filter($=>!!$.parentNode);z.length>0&&v(z,B)}
|
|
923
|
+
const W=O=>{let I=0;const B=new Set([O.id]);let E=O;for(;E?.parentId&&!B.has(E.parentId);)B.add(E.parentId),E=m.get(E.parentId),E&&I++;return I},X=t.filter(O=>!O.scope||O.scope==="block").sort((O,I)=>W(
|
|
924
|
+
I)-W(O));for(const O of X){if(!f)break;const I=w(O).map(H=>h.get(H)).filter(H=>H!==void 0).sort((H,K)=>H-K);if(I.length===0){console.warn(`docx export: content control ${O.id} has no surviving member \
|
|
925
|
+
blocks; dropping wrapper`);continue}const B=I[0],E=I[I.length-1],S=g[B];let R=0;for(let H=B;H<=E;H++)R+=this.emittedBodySlotCount(p[H]);if(R===0)continue;const z=[];for(const H of c.slice(S,S+R)){let K=H;
|
|
926
|
+
for(;K.parentNode&&K.parentNode!==s&&K.parentNode.nodeType===1;)K=K.parentNode;K.parentNode===s&&!z.includes(K)&&z.push(K)}if(z.length===0)continue;const $=b(O);$&&v(z,$)}if(!u)return e;const D=new XMLSerializer().
|
|
927
|
+
serializeToString(o);i.file("word/document.xml",D);const M=await this.generateCompressedZipBlob(i);return new Blob([M],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async patchParagraphMarkRevisions(e,r,t){
|
|
924
928
|
const i=await this.loadZipFromBlob(e),n=i.file("word/document.xml");if(!n)return e;const a=await n.async("text"),o="http://schemas.openxmlformats.org/wordprocessingml/2006/main",s=new DOMParser().parseFromString(
|
|
925
|
-
a,"application/xml"),l=s.getElementsByTagName("w:body")[0];if(!l)return e;const c=[];for(let
|
|
929
|
+
a,"application/xml"),l=s.getElementsByTagName("w:body")[0];if(!l)return e;const c=[];for(let g=0;g<l.children.length;g++)l.children[g].tagName==="w:p"&&c.push(l.children[g]);for(const g of r){const f=c[g.
|
|
926
930
|
pIndex];if(!f)continue;let w=this.getDirectChild(f,"w:pPr");w||(w=s.createElementNS(o,"w:pPr"),f.insertBefore(w,f.firstChild));let u=this.getDirectChild(w,"w:rPr");if(!u){u=s.createElementNS(o,"w:rPr");
|
|
927
|
-
const b=this.getDirectChild(w,"w:sectPr");b?w.insertBefore(u,b):w.appendChild(u)}const
|
|
928
|
-
nsert"?"w:ins":"w:del");
|
|
931
|
+
const b=this.getDirectChild(w,"w:sectPr");b?w.insertBefore(u,b):w.appendChild(u)}const m=s.createElementNS(o,g.kind==="moveFrom"?"w:moveFrom":g.kind==="moveTo"?"w:moveTo":g.kind==="split"||g.kind==="i\
|
|
932
|
+
nsert"?"w:ins":"w:del");m.setAttributeNS(o,"w:id",String(t(g.importedId))),m.setAttributeNS(o,"w:author",g.author),m.setAttributeNS(o,"w:date",g.date),u.insertBefore(m,u.firstChild)}const p=new XMLSerializer().
|
|
929
933
|
serializeToString(s);i.file("word/document.xml",p);const h=await this.generateCompressedZipBlob(i);return new Blob([h],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async patchParagraphPropertyChanges(e,r,t){
|
|
930
934
|
const i=await this.loadZipFromBlob(e),n=i.file("word/document.xml");if(!n)return e;const a=await n.async("text"),o="http://schemas.openxmlformats.org/wordprocessingml/2006/main",s=new DOMParser().parseFromString(
|
|
931
|
-
a,"application/xml"),l=s.getElementsByTagName("w:body")[0];if(!l)return e;const c=[];for(let w=0;w<l.children.length;w++)l.children[w].tagName==="w:p"&&c.push(l.children[w]);const p=(w,u)=>{const
|
|
932
|
-
createElementNS(o,w);for(const[b,v]of Object.entries(u??{}))
|
|
933
|
-
if(!u)return;const
|
|
934
|
-
v.parentNode?.removeChild(v);return u.parentNode?.removeChild(u),b??void 0};for(const w of r){const u=w.marker?h(w.marker):c[w.pIndex];if(!u)continue;let
|
|
935
|
-
o,"w:pPr"),u.insertBefore(
|
|
935
|
+
a,"application/xml"),l=s.getElementsByTagName("w:body")[0];if(!l)return e;const c=[];for(let w=0;w<l.children.length;w++)l.children[w].tagName==="w:p"&&c.push(l.children[w]);const p=(w,u)=>{const m=s.
|
|
936
|
+
createElementNS(o,w);for(const[b,v]of Object.entries(u??{}))m.setAttributeNS(o,b,v);return m},h=w=>{const u=Array.from(s.getElementsByTagName("w:bookmarkStart")).find(v=>v.getAttribute("w:name")===w);
|
|
937
|
+
if(!u)return;const m=u.getAttribute("w:id");let b=u.parentNode;for(;b&&b.tagName!=="w:p";)b=b.parentNode;for(const v of Array.from(s.getElementsByTagName("w:bookmarkEnd")))v.getAttribute("w:id")===m&&
|
|
938
|
+
v.parentNode?.removeChild(v);return u.parentNode?.removeChild(u),b??void 0};for(const w of r){const u=w.marker?h(w.marker):c[w.pIndex];if(!u)continue;let m=this.getDirectChild(u,"w:pPr");m||(m=s.createElementNS(
|
|
939
|
+
o,"w:pPr"),u.insertBefore(m,u.firstChild));const b=p("w:pPrChange",{"w:id":String(t(w.importedId)),"w:author":w.author,"w:date":w.date}),v=w.prior,y=s.createElementNS(o,"w:pPr");if(v.styleId&&y.appendChild(
|
|
936
940
|
p("w:pStyle",{"w:val":v.styleId})),v.keepNext&&y.appendChild(p("w:keepNext")),v.keepLines&&y.appendChild(p("w:keepLines")),v.widowControl===!1&&y.appendChild(p("w:widowControl",{"w:val":"0"})),v.ilvl!==
|
|
937
|
-
void 0){const
|
|
938
|
-
"w:numId",{"w:val":
|
|
939
|
-
p(`w:${
|
|
941
|
+
void 0){const T=this.getDirectChild(this.getDirectChild(m,"w:numPr")??m,"w:numId")?.getAttribute("w:val");if(T){const L=p("w:numPr");L.appendChild(p("w:ilvl",{"w:val":String(v.ilvl)})),L.appendChild(p(
|
|
942
|
+
"w:numId",{"w:val":T})),y.appendChild(L)}}if(v.bordersJson)try{const T=JSON.parse(v.bordersJson),L=s.createElementNS(o,"w:pBdr");for(const W of["top","left","bottom","right"]){const X=T[W];X&&L.appendChild(
|
|
943
|
+
p(`w:${W}`,{"w:val":X.style||"single","w:sz":String(Math.max(2,Math.round((X.width??.5)*6))),"w:space":"1","w:color":(X.color||"#000000").replace(/^#/,"")}))}L.children.length>0&&y.appendChild(L)}catch{}
|
|
940
944
|
v.shadingFill&&y.appendChild(p("w:shd",{"w:val":"clear","w:fill":this.toDocxHex(v.shadingFill)??"auto"})),v.direction&&y.appendChild(p("w:bidi",v.direction==="ltr"?{"w:val":"0"}:{})),(v.lineSpacing!==
|
|
941
945
|
void 0||v.spaceBeforeTwips!==void 0||v.spaceAfterTwips!==void 0)&&y.appendChild(p("w:spacing",{...v.spaceBeforeTwips!==void 0?{"w:before":String(v.spaceBeforeTwips)}:{},...v.spaceAfterTwips!==void 0?{
|
|
942
946
|
"w:after":String(v.spaceAfterTwips)}:{},...v.lineSpacing!==void 0?{"w:line":String(Math.round(v.lineSpacing*240)),"w:lineRule":"auto"}:{}})),(v.leftIndentTwips!==void 0||v.firstLineIndentTwips!==void 0)&&
|
|
943
947
|
y.appendChild(p("w:ind",{...v.leftIndentTwips!==void 0?{"w:left":String(v.leftIndentTwips)}:{},...v.firstLineIndentTwips!==void 0?{"w:firstLine":String(v.firstLineIndentTwips)}:{}})),v.align&&y.appendChild(
|
|
944
|
-
p("w:jc",{"w:val":v.align==="justify"?"both":v.align})),b.appendChild(y),
|
|
948
|
+
p("w:jc",{"w:val":v.align==="justify"?"both":v.align})),b.appendChild(y),m.appendChild(b)}const g=new XMLSerializer().serializeToString(s);i.file("word/document.xml",g);const f=await this.generateCompressedZipBlob(
|
|
945
949
|
i);return new Blob([f],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async patchLinkedMoveRevisions(e,r){const t=await this.loadZipFromBlob(e),i=t.file("word\
|
|
946
|
-
/document.xml");if(!i)return e;const n=await i.async("text"),a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",o=new DOMParser().parseFromString(n,"application/xml"),s=(p,h)=>{const
|
|
947
|
-
createElementNS(a,h);for(const f of Array.from(p.attributes))
|
|
948
|
-
createElementNS(a,p);return f.setAttributeNS(a,"w:id",h.rangeId),
|
|
949
|
-
const h=p.role==="from"?"w:del":"w:ins",
|
|
950
|
-
if(w.length!==f.size)throw new Error(`linked move ${p.name}/${p.role}: expected ${f.size} temporary revision wrappers, found ${w.length}`);const u=w.map(y=>s(y,
|
|
951
|
-
rom"?"w:moveFromRange":"w:moveToRange";
|
|
950
|
+
/document.xml");if(!i)return e;const n=await i.async("text"),a="http://schemas.openxmlformats.org/wordprocessingml/2006/main",o=new DOMParser().parseFromString(n,"application/xml"),s=(p,h)=>{const g=o.
|
|
951
|
+
createElementNS(a,h);for(const f of Array.from(p.attributes))g.setAttributeNS(f.namespaceURI,f.name,f.value);for(;p.firstChild;)g.appendChild(p.firstChild);return p.replaceWith(g),g},l=(p,h,g)=>{const f=o.
|
|
952
|
+
createElementNS(a,p);return f.setAttributeNS(a,"w:id",h.rangeId),g&&(f.setAttributeNS(a,"w:name",h.name),f.setAttributeNS(a,"w:author",h.author),f.setAttributeNS(a,"w:date",h.date)),f};for(const p of r){
|
|
953
|
+
const h=p.role==="from"?"w:del":"w:ins",g=p.role==="from"?"w:moveFrom":"w:moveTo",f=new Set(p.wrapperIds.map(String)),w=Array.from(o.getElementsByTagName(h)).filter(y=>f.has(y.getAttribute("w:id")??""));
|
|
954
|
+
if(w.length!==f.size)throw new Error(`linked move ${p.name}/${p.role}: expected ${f.size} temporary revision wrappers, found ${w.length}`);const u=w.map(y=>s(y,g)),m=u[0],b=u[u.length-1],v=p.role==="f\
|
|
955
|
+
rom"?"w:moveFromRange":"w:moveToRange";m.parentNode?.insertBefore(l(`${v}Start`,p,!0),m),b.parentNode?.insertBefore(l(`${v}End`,p,!1),b.nextSibling)}t.file("word/document.xml",new XMLSerializer().serializeToString(
|
|
952
956
|
o));const c=await this.generateCompressedZipBlob(t);return new Blob([c],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static async patchTableRevisions(e,r,t){const i=await this.
|
|
953
957
|
loadZipFromBlob(e),n=i.file("word/document.xml");if(!n)return e;const a=await n.async("text"),o="http://schemas.openxmlformats.org/wordprocessingml/2006/main",s=new DOMParser().parseFromString(a,"appl\
|
|
954
|
-
ication/xml"),l=s.getElementsByTagName("w:body")[0];if(!l)return e;const c=Array.from(l.getElementsByTagName("w:tbl")),p=(
|
|
955
|
-
|
|
956
|
-
or").length>0||
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
958
|
+
ication/xml"),l=s.getElementsByTagName("w:body")[0];if(!l)return e;const c=Array.from(l.getElementsByTagName("w:tbl")),p=(I,B)=>Array.from(I.children).filter(E=>E.tagName===B),h=(I,B)=>{const E=this.getDirectChild(
|
|
959
|
+
I,B);if(E)return E;const S=s.createElementNS(o,B);return I.insertBefore(S,I.firstChild),S},g=(I,B)=>{const E=new DOMParser().parseFromString(I,"application/xml");if(!(E.getElementsByTagName("parsererr\
|
|
960
|
+
or").length>0||E.documentElement?.tagName!==B))return s.importNode(E.documentElement,!0)},f=(I,B)=>{const E=g(B,"w:tblGrid");if(!E)return this.getDirectChild(I,"w:tblGrid");const S=this.getDirectChild(
|
|
961
|
+
I,"w:tblGrid");if(S)S.replaceWith(E);else{const R=this.getDirectChild(I,"w:tblPr");I.insertBefore(E,R?.nextSibling??I.firstChild)}return E},w=(I,B)=>{const E=g(B,"w:tblPrEx");if(!E)return this.getDirectChild(
|
|
962
|
+
I,"w:tblPrEx");const S=this.getDirectChild(I,"w:tblPrEx");return S?S.replaceWith(E):I.insertBefore(E,I.firstChild),E},u=(I,B,E)=>{const S=g(E,B);if(!S)return h(I,B);const R=this.getDirectChild(I,B);return R?
|
|
963
|
+
R.replaceWith(S):I.insertBefore(S,I.firstChild),S},m={"w:tblPr":["w:tblStyle","w:tblpPr","w:tblOverlap","w:bidiVisual","w:tblStyleRowBandSize","w:tblStyleColBandSize","w:tblW","w:jc","w:tblCellSpacing",
|
|
960
964
|
"w:tblInd","w:tblBorders","w:shd","w:tblLayout","w:tblCellMar","w:tblLook","w:tblCaption","w:tblDescription","w:tblPrChange"],"w:trPr":["w:cnfStyle","w:divId","w:gridBefore","w:gridAfter","w:wBefore",
|
|
961
965
|
"w:wAfter","w:cantSplit","w:trHeight","w:tblHeader","w:tblCellSpacing","w:jc","w:hidden","w:ins","w:del","w:trPrChange"],"w:tcPr":["w:cnfStyle","w:tcW","w:gridSpan","w:hMerge","w:vMerge","w:tcBorders",
|
|
962
|
-
"w:shd","w:noWrap","w:tcMar","w:textDirection","w:tcFitText","w:vAlign","w:hideMark","w:headers","w:cellIns","w:cellDel","w:cellMerge","w:tcPrChange"]},b=(
|
|
963
|
-
const
|
|
964
|
-
filter(
|
|
965
|
-
createElementNS(o,
|
|
966
|
-
createElementNS(o,
|
|
967
|
-
|
|
968
|
-
Pr"),
|
|
969
|
-
rs"),
|
|
970
|
-
|
|
971
|
-
appendChild(S)},
|
|
972
|
-
["right","right"],...
|
|
973
|
-
l",H.style),
|
|
974
|
-
let
|
|
975
|
-
"top","right","bottom","left"]){const
|
|
976
|
-
S.appendChild(
|
|
977
|
-
tableWidth")){const
|
|
978
|
-
xa")),
|
|
979
|
-
|
|
980
|
-
ers");for(const re of["top","left","bottom","right","insideH","insideV"]){const
|
|
981
|
-
from(
|
|
982
|
-
o,"w:sz",typeof
|
|
983
|
-
Color")){const
|
|
984
|
-
let re;(
|
|
985
|
-
"string"?
|
|
986
|
-
|
|
987
|
-
Number.MAX_SAFE_INTEGER)-(H.get(re.tagName)??Number.MAX_SAFE_INTEGER));for(const
|
|
988
|
-
table&&b(
|
|
989
|
-
[]){const
|
|
990
|
-
cells??[]){const
|
|
991
|
-
const
|
|
992
|
-
const
|
|
993
|
-
S.priorAttributes))}for(const S of
|
|
994
|
-
void 0;
|
|
995
|
-
S.vMerge
|
|
996
|
-
"w:tblGridChange",
|
|
997
|
-
S)
|
|
998
|
-
S.currentAttributes,S.priorTableAttributes,S.currentTableAttributes)}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
"w:cellMerge","w:tcPrChange"])for(const re of p(
|
|
1002
|
-
u(
|
|
1003
|
-
|
|
1004
|
-
|
|
966
|
+
"w:shd","w:noWrap","w:tcMar","w:textDirection","w:tcFitText","w:vAlign","w:hideMark","w:headers","w:cellIns","w:cellDel","w:cellMerge","w:tcPrChange"]},b=(I,B,E,S)=>{const R=h(I,B),z=g(E,B);if(!z)return R;
|
|
967
|
+
const $=[],H=Array.from(R.children),K=Array.from(z.children),J=new Set([...H.map(j=>j.tagName),...K.map(j=>j.tagName)]);for(const j of J){const G=S.has(j)?H:K.some(q=>q.tagName===j)?K:H;for(const q of G.
|
|
968
|
+
filter(Z=>Z.tagName===j))$.push(s.importNode(q,!0))}const re=new Map(m[B].map((j,G)=>[j,G]));$.sort((j,G)=>(re.get(j.tagName)??Number.MAX_SAFE_INTEGER)-(re.get(G.tagName)??Number.MAX_SAFE_INTEGER));const k=s.
|
|
969
|
+
createElementNS(o,B);for(const j of Array.from(z.attributes))k.setAttributeNS(j.namespaceURI,j.name,j.value);for(const j of $)k.appendChild(j);return R.replaceWith(k),k},v=new Map,y=(I,B)=>{const E=s.
|
|
970
|
+
createElementNS(o,I),S=v;let R;return B.importedId===void 0&&B.revisionGroup&&(R=S.get(B.revisionGroup),R===void 0&&(R=t(),S.set(B.revisionGroup,R))),E.setAttributeNS(o,"w:id",String(B.importedId!==void 0?
|
|
971
|
+
B.importedId:R??t())),E.setAttributeNS(o,"w:author",B.author),E.setAttributeNS(o,"w:date",B.date),E},T=(I,B)=>{let E=0;for(const S of p(I,"w:tc")){if(E===B)return S;const R=this.getDirectChild(S,"w:tc\
|
|
972
|
+
Pr"),z=R?this.getDirectChild(R,"w:gridSpan")?.getAttribute("w:val"):void 0,$=z?Number(z):1;E+=Number.isFinite($)&&$>0?$:1}},L=(I,B)=>{const E=nr(B);if(!E)return;const S=s.createElementNS(o,"w:tblBorde\
|
|
973
|
+
rs"),R=[["top","top"],["bottom","bottom"],["left","left"],["right","right"],["insideH","insideH"],["insideV","insideV"]];for(const[z,$]of R){const H=E[z];if(!H)continue;const K=s.createElementNS(o,`w:${$}`);
|
|
974
|
+
K.setAttributeNS(o,"w:val",H.style),K.setAttributeNS(o,"w:sz",String(Math.max(0,Math.round(H.width*6)))),K.setAttributeNS(o,"w:color",H.color.replace(/^#/,"")),S.appendChild(K)}S.children.length>0&&I.
|
|
975
|
+
appendChild(S)},W=(I,B,E)=>{for(const S of p(I,B))S.remove();E&&I.appendChild(E)},X=(I,B)=>{const E=nr(B);if(!E)return;const S=s.createElementNS(o,I),R=[["top","top"],["bottom","bottom"],["left","left"],
|
|
976
|
+
["right","right"],...I==="w:tblBorders"?[["insideH","insideH"],["insideV","insideV"]]:[]];for(const[z,$]of R){const H=E[z];if(!H)continue;const K=s.createElementNS(o,`w:${$}`);K.setAttributeNS(o,"w:va\
|
|
977
|
+
l",H.style),K.setAttributeNS(o,"w:sz",String(Math.max(0,Math.round(H.width*6)))),K.setAttributeNS(o,"w:color",H.color.replace(/^#/,"")),S.appendChild(K)}return S.children.length>0?S:void 0},D=(I,B)=>{
|
|
978
|
+
let E;if(typeof B=="number"&&Number.isFinite(B))E={top:B,right:B,bottom:B,left:B};else if(typeof B=="string")try{E=JSON.parse(B)}catch{return}if(!E)return;const S=s.createElementNS(o,I);for(const R of[
|
|
979
|
+
"top","right","bottom","left"]){const z=E[R];if(!Number.isFinite(z))continue;const $=s.createElementNS(o,`w:${R}`);$.setAttributeNS(o,"w:w",String(Math.round(z*15))),$.setAttributeNS(o,"w:type","dxa"),
|
|
980
|
+
S.appendChild($)}return S.children.length>0?S:void 0},M=(I,B,E,S,R,z)=>{const $=J=>Object.prototype.hasOwnProperty.call(E??{},J)||Object.prototype.hasOwnProperty.call(S??{},J);if(B==="w:tblPr"){if($("\
|
|
981
|
+
tableWidth")){const J=E?.tableWidth;let re;typeof J=="number"&&Number.isFinite(J)&&(re=s.createElementNS(o,"w:tblW"),re.setAttributeNS(o,"w:w",String(Math.round(J*15))),re.setAttributeNS(o,"w:type","d\
|
|
982
|
+
xa")),W(I,"w:tblW",re)}if($("align")){const J=E?.align;let re;(J==="left"||J==="center"||J==="right")&&(re=s.createElementNS(o,"w:jc"),re.setAttributeNS(o,"w:val",J)),W(I,"w:jc",re)}if($("borders")&&W(
|
|
983
|
+
I,"w:tblBorders",typeof E?.borders=="string"?X("w:tblBorders",E.borders):void 0),$("borderColor")||$("borderWidth")){let J=this.getDirectChild(I,"w:tblBorders");if(!J){J=s.createElementNS(o,"w:tblBord\
|
|
984
|
+
ers");for(const re of["top","left","bottom","right","insideH","insideV"]){const k=s.createElementNS(o,`w:${re}`);k.setAttributeNS(o,"w:val","single"),J.appendChild(k)}I.appendChild(J)}for(const re of Array.
|
|
985
|
+
from(J.children)){if($("borderColor")){const k=E?.borderColor;re.setAttributeNS(o,"w:color",typeof k=="string"&&k?k.replace(/^#/,""):"auto")}if($("borderWidth")){const k=E?.borderWidth;re.setAttributeNS(
|
|
986
|
+
o,"w:sz",typeof k=="number"&&Number.isFinite(k)?String(Math.max(0,Math.round(k*6))):"4")}}}$("cellPadding")&&W(I,"w:tblCellMar",D("w:tblCellMar",E?.cellPadding))}else if(B==="w:tcPr"){if($("background\
|
|
987
|
+
Color")){const J=E?.backgroundColor;let re;typeof J=="string"&&J&&(re=s.createElementNS(o,"w:shd"),re.setAttributeNS(o,"w:fill",J.replace(/^#/,""))),W(I,"w:shd",re)}if($("verticalAlign")){const J=E?.verticalAlign;
|
|
988
|
+
let re;(J==="top"||J==="middle"||J==="bottom")&&(re=s.createElementNS(o,"w:vAlign"),re.setAttributeNS(o,"w:val",J==="middle"?"center":J)),W(I,"w:vAlign",re)}$("borders")&&W(I,"w:tcBorders",typeof E?.borders==
|
|
989
|
+
"string"?X("w:tcBorders",E.borders):void 0),$("padding")&&W(I,"w:tcMar",D("w:tcMar",E?.padding))}if(B==="w:trPr"&&(J=>Object.prototype.hasOwnProperty.call(R??{},J)||Object.prototype.hasOwnProperty.call(
|
|
990
|
+
z??{},J))("hasHeader")){const J=R?.hasHeader?s.createElementNS(o,"w:tblHeader"):void 0;W(I,"w:tblHeader",J)}const H=new Map(m[B].map((J,re)=>[J,re])),K=Array.from(I.children).sort((J,re)=>(H.get(J.tagName)??
|
|
991
|
+
Number.MAX_SAFE_INTEGER)-(H.get(re.tagName)??Number.MAX_SAFE_INTEGER));for(const J of K)I.appendChild(J)};for(const I of r){const B=c[I.tableIndex];if(!B)continue;const E=p(B,"w:tr");I.propertyOverrides?.
|
|
992
|
+
table&&b(B,"w:tblPr",I.propertyOverrides.table,new Set(["w:tblW","w:jc","w:tblBorders","w:tblCellMar"])),I.propertyOverrides?.grid&&f(B,I.propertyOverrides.grid);for(const S of I.propertyOverrides?.rows??
|
|
993
|
+
[]){const R=E[S.rowIndex];R&&b(R,"w:trPr",S.xml,new Set(["w:tblHeader"]))}for(const S of I.propertyOverrides?.rowExceptions??[]){const R=E[S.rowIndex];R&&w(R,S.xml)}for(const S of I.propertyOverrides?.
|
|
994
|
+
cells??[]){const R=E[S.rowIndex],z=R?T(R,S.gridColumn):void 0;z&&b(z,"w:tcPr",S.xml,new Set(["w:tcW","w:gridSpan","w:vMerge","w:tcBorders","w:shd","w:tcMar","w:vAlign"]))}for(const S of I.rowProperties){
|
|
995
|
+
const R=E[S.rowIndex];R&&(S.currentXml?u(R,"w:trPr",S.currentXml):M(h(R,"w:trPr"),"w:trPr",S.currentAttributes,S.priorAttributes,S.currentTableAttributes,S.priorTableAttributes))}for(const S of I.rowExceptionProperties){
|
|
996
|
+
const R=E[S.rowIndex];R&&w(R,S.currentXml)}for(const S of I.cellProperties){const R=E[S.rowIndex],z=R?T(R,S.gridColumn):void 0;z&&(S.currentXml?u(z,"w:tcPr",S.currentXml):M(h(z,"w:tcPr"),"w:tcPr",S.currentAttributes,
|
|
997
|
+
S.priorAttributes))}for(const S of I.rows){const R=E[S.rowIndex];R&&h(R,"w:trPr").appendChild(y(S.kind==="insert"?"w:ins":"w:del",S))}for(const S of I.cells){const R=E[S.rowIndex],z=R?T(R,S.gridColumn):
|
|
998
|
+
void 0;z&&h(z,"w:tcPr").appendChild(y(S.kind==="insert"?"w:cellIns":"w:cellDel",S))}for(const S of I.merges){const R=E[S.rowIndex],z=R?T(R,S.gridColumn):void 0;if(!z)continue;const $=y("w:cellMerge",S);
|
|
999
|
+
S.vMerge&&$.setAttributeNS(o,"w:vMerge",S.vMerge),S.vMergeOrig&&$.setAttributeNS(o,"w:vMergeOrig",S.vMergeOrig),h(z,"w:tcPr").appendChild($)}if(I.tableGrid){const S=f(B,I.tableGrid.currentXml);if(S){const R=y(
|
|
1000
|
+
"w:tblGridChange",I.tableGrid),z=g(I.tableGrid.priorXml,"w:tblGrid");z&&R.appendChild(z),S.appendChild(R)}}for(const S of I.rowProperties){const R=E[S.rowIndex];if(!R)continue;const z=y("w:trPrChange",
|
|
1001
|
+
S),$=h(R,"w:trPr"),H=S.priorXml?g(S.priorXml,"w:trPr"):$.cloneNode(!0);if(H){if(!S.priorXml){for(const K of["w:ins","w:del","w:trPrChange"])for(const J of p(H,K))J.remove();M(H,"w:trPr",S.priorAttributes,
|
|
1002
|
+
S.currentAttributes,S.priorTableAttributes,S.currentTableAttributes)}z.appendChild(H)}$.appendChild(z)}for(const S of I.rowExceptionProperties){const R=E[S.rowIndex];if(!R)continue;const z=this.getDirectChild(
|
|
1003
|
+
R,"w:tblPrEx")??w(R,S.currentXml);if(!z)continue;const $=y("w:tblPrExChange",S),H=g(S.priorXml,"w:tblPrEx");H&&$.appendChild(H),z.appendChild($)}for(const S of I.cellProperties){const R=E[S.rowIndex],
|
|
1004
|
+
z=R?T(R,S.gridColumn):void 0;if(!z)continue;const $=y("w:tcPrChange",S),H=h(z,"w:tcPr"),K=S.priorXml?g(S.priorXml,"w:tcPr"):H.cloneNode(!0);if(K){if(!S.priorXml){for(const J of["w:cellIns","w:cellDel",
|
|
1005
|
+
"w:cellMerge","w:tcPrChange"])for(const re of p(K,J))re.remove();M(K,"w:tcPr",S.priorAttributes,S.currentAttributes)}$.appendChild(K)}H.appendChild($)}if(I.tableProperties){const S=I.tableProperties.currentXml?
|
|
1006
|
+
u(B,"w:tblPr",I.tableProperties.currentXml):h(B,"w:tblPr");I.tableProperties.currentXml||M(S,"w:tblPr",I.tableProperties.currentAttributes,I.tableProperties.priorAttributes);const R=y("w:tblPrChange",
|
|
1007
|
+
I.tableProperties);let z;I.tableProperties.priorXml&&(z=g(I.tableProperties.priorXml,"w:tblPr")),z||(z=S.cloneNode(!0),M(z,"w:tblPr",I.tableProperties.priorAttributes,I.tableProperties.currentAttributes),
|
|
1008
|
+
I.tableProperties.priorBorders&&L(z,I.tableProperties.priorBorders)),R.appendChild(z),S.appendChild(R)}}i.file("word/document.xml",new XMLSerializer().serializeToString(s));const O=await this.generateCompressedZipBlob(
|
|
1005
1009
|
i);return new Blob([O],{type:"application/vnd.openxmlformats-officedocument.wordprocessingml.document"})}static inferDocumentFontFamily(e){if(!e?.children)return;const r=new Map;let t=0;const i=(o,s)=>{
|
|
1006
1010
|
for(const l of o){if(l.type!=="text")continue;const c=l.text.length;if(c===0)continue;t+=c;const p=l.marks?.fontFamily??s;p&&r.set(p,(r.get(p)??0)+c)}};for(const o of e.children)if(o.type==="paragraph"){
|
|
1007
1011
|
const s=o;i(o.children,s.fontFamily)}else if(o.type==="list")for(const s of o.children)i(s.children);if(t===0)return;let n,a=0;for(const[o,s]of r)s>a&&(n=o,a=s);return n&&a*2>t?n:void 0}static codeBlockStyleId(e){
|
|
@@ -1014,73 +1018,75 @@ return[{id:this.CODE_INLINE_STYLE_ID,name:"Code Inline",run:{font:"Courier New",
|
|
|
1014
1018
|
e),n=this.buildOrderedNumberingExportPlan(e).byListId;this.exportOrderedPlan=n,this.exportLinkedMoveSides=this.collectLinkedMoveSides(e.children),this.exportLinkedMoveBlockIds=this.collectLinkedMoveBlockIds(
|
|
1015
1019
|
e.children,this.exportLinkedMoveSides);const a=this.collectTextlessMoveHalves(e.children);for(const o of e.children){if(a.destinations.has(o.id))continue;const s=a.sources.has(o.id)?this.withoutMoveState(
|
|
1016
1020
|
o):o;s.type==="paragraph"?r.push(this.paragraphToDocx(s,t,i)):s.type==="list"?r.push(...this.listToDocxParagraphs(s,t,n)):s.type==="page-break"?r.push({type:"pagebreak"}):s.type==="toc"&&r.push(...this.
|
|
1017
|
-
tocBlockToDocxParagraphs(s,e))}return r}static tocBlockToDocxParagraphs(e,r,t){const i=
|
|
1021
|
+
tocBlockToDocxParagraphs(s,e))}return r}static tocBlockToDocxParagraphs(e,r,t){const i=_i(e),n=Wi(r,Xi(e)),a=Ee(r.pageLayout),o=tr(a),s=Math.max(o.pageWidth-a.marginLeftPx-a.marginRightPx,96),l=e.direction===
|
|
1018
1022
|
"rtl",c=this.docxAlignmentForExport({type:"paragraph",id:e.id,children:[],direction:e.direction??"ltr",align:e.align??(l?"right":"left")}),p={bidirectional:l,alignment:c},h=JSON.stringify([{pos:Math.round(
|
|
1019
|
-
s),align:"right",leader:"dot"}]),
|
|
1020
|
-
{},...f?{color:f}:{}};if(n.length===0)return[{type:"paragraph",...p,children:[{text:" ",fieldInstr:i,...w}]}];const u=24;return n.map(
|
|
1021
|
-
...w,...l?{rightToLeft:!0}:{}},...t?.has(
|
|
1022
|
-
const n=[],a=this.inferDocumentFontFamily(e);this.exportDefaultRunSizeHalfPoints=this.inferDefaultRunSizeHalfPoints(e);const o=r||
|
|
1023
|
+
s),align:"right",leader:"dot"}]),g=e.fontFamily??this.inferDocumentFontFamily(r),f=this.toDocxHex(e.color),w={...g?{font:g}:{},...e.fontSize?{size:Math.round(e.fontSize*this.DOCX_HALF_POINTS_PER_PX)}:
|
|
1024
|
+
{},...f?{color:f}:{}};if(n.length===0)return[{type:"paragraph",...p,children:[{text:" ",fieldInstr:i,...w}]}];const u=24;return n.map(m=>({type:"paragraph",...p,children:[{text:`${m.text} `,fieldInstr:i,
|
|
1025
|
+
...w,...l?{rightToLeft:!0}:{}},...t?.has(m.blockId)?[{text:String(t.get(m.blockId)),fieldInstr:i,...w,rightToLeft:!1}]:[]],tabStopsJson:h,...m.level>1?{indent:{left:this.pxToTwips((m.level-1)*u)}}:{}}))}static toDocxFormatWithTables(e,r,t,i){
|
|
1026
|
+
const n=[],a=this.inferDocumentFontFamily(e);this.exportDefaultRunSizeHalfPoints=this.inferDefaultRunSizeHalfPoints(e);const o=r||en,s=this.resolveIndentStepPx(e),l=this.buildOrderedNumberingExportPlan(
|
|
1023
1027
|
e).byListId;this.exportOrderedPlan=l,this.exportLinkedMoveSides=this.collectLinkedMoveSides(e.children),this.exportLinkedMoveBlockIds=this.collectLinkedMoveBlockIds(e.children,this.exportLinkedMoveSides);
|
|
1024
1028
|
const c=this.styleExportContext(e),p=this.collectTextlessMoveHalves(e.children);for(const f of e.children){const w=n.length;if(p.destinations.has(f.id)){i?.push({blockId:f.id,start:w,count:0});continue}
|
|
1025
1029
|
const u=p.sources.has(f.id)?this.withoutMoveState(f):f;if(u.type==="paragraph")n.push(this.styledParagraphToDocxWithMath(u,a,s,c));else if(u.type==="list")n.push(...this.listToDocxParagraphsWithMath(u,
|
|
1026
|
-
a,l));else if(u.type==="table")n.push(this.tableToDocxWithMath(u,a,s,c));else if(u.type==="code"){const
|
|
1027
|
-
type==="math")n.push(this.mathBlockToDocx(u));else if(u.type==="image")n.push(this.imageBlockToDocx(u));else if(u.type==="page-break")n.push({type:"pagebreak"});else if(u.type==="section-break"){const
|
|
1030
|
+
a,l));else if(u.type==="table")n.push(this.tableToDocxWithMath(u,a,s,c));else if(u.type==="code"){const m=this.legacyLatexCodeBlockAsMath(u);n.push(m?this.mathBlockToDocx(m):this.codeBlockToDocx(u,o))}else if(u.
|
|
1031
|
+
type==="math")n.push(this.mathBlockToDocx(u));else if(u.type==="image")n.push(this.imageBlockToDocx(u));else if(u.type==="page-break")n.push({type:"pagebreak"});else if(u.type==="section-break"){const m=u.
|
|
1028
1032
|
diffState==="delete"&&u.suggestionId?/^docxrev-(\d+)$/.exec(u.suggestionId):null;n.push({type:"sectionbreak",...u.layout?{layout:u.layout}:{},...u.breakType?{breakType:u.breakType}:{},...u.diffState===
|
|
1029
|
-
"delete"?{pendingDeletion:{author:u.suggestionAuthorName??"Anonymous",date:new Date(u.suggestionCreatedAt??Date.now()).toISOString(),...
|
|
1033
|
+
"delete"?{pendingDeletion:{author:u.suggestionAuthorName??"Anonymous",date:new Date(u.suggestionCreatedAt??Date.now()).toISOString(),...m?{importedId:Number(m[1])}:{}}}:{}})}else u.type==="toc"?n.push(
|
|
1030
1034
|
...this.tocBlockToDocxParagraphs(u,e,t)):u.type==="docx-raw"&&(cr(u.xml)?n.push(this.styledParagraphToDocxWithMath({type:"paragraph",id:u.id,children:[{type:"text",text:""}]},a,s,c)):n.push({type:"doc\
|
|
1031
|
-
xraw",sourceBlockId:u.id,xml:u.xml,origin:u.origin,emitsParagraph:u.origin==="run"}));i?.push({blockId:u.id,start:w,count:n.length-w})}const h=this.pxToTwips(Ee(e.pageLayout).blockSpacingPx),
|
|
1032
|
-
rows)for(const u of w.cells){for(const
|
|
1033
|
-
spacingAfterTwips??(
|
|
1034
|
-
h),f.spacingBeforeTwips??(f.spacingBeforeTwips=0)):f.type==="table"&&
|
|
1035
|
-
typeof r.spaceAfter=="number"&&(e.spacingAfterTwips=this.pxToTwips(r.spaceAfter)),r.contextualSpacing&&(e.contextualSpacing=!0)}static latexToOmml(e,r){const t=
|
|
1036
|
-
e,{output:"mathml",displayMode:r,throwOnError:!1});let n=
|
|
1035
|
+
xraw",sourceBlockId:u.id,xml:u.xml,origin:u.origin,emitsParagraph:u.origin==="run"}));i?.push({blockId:u.id,start:w,count:n.length-w})}const h=this.pxToTwips(Ee(e.pageLayout).blockSpacingPx),g=f=>{for(const w of f.
|
|
1036
|
+
rows)for(const u of w.cells){for(const m of u.paragraphs)m.spacingAfterTwips??(m.spacingAfterTwips=h),m.spacingBeforeTwips??(m.spacingBeforeTwips=0);for(const m of u.blocks??[])m.type==="paragraph"?(m.
|
|
1037
|
+
spacingAfterTwips??(m.spacingAfterTwips=h),m.spacingBeforeTwips??(m.spacingBeforeTwips=0)):g(m)}};for(const f of n)f.type==="paragraph"?f.styleProvidesSpacing||(f.spacingAfterTwips??(f.spacingAfterTwips=
|
|
1038
|
+
h),f.spacingBeforeTwips??(f.spacingBeforeTwips=0)):f.type==="table"&&g(f);return n}static applyExportParagraphSpacing(e,r){typeof r.spaceBefore=="number"&&(e.spacingBeforeTwips=this.pxToTwips(r.spaceBefore)),
|
|
1039
|
+
typeof r.spaceAfter=="number"&&(e.spacingAfterTwips=this.pxToTwips(r.spaceAfter)),r.contextualSpacing&&(e.contextualSpacing=!0)}static latexToOmml(e,r){const t=_r();if(!t)return"";try{const i=t.renderToString(
|
|
1040
|
+
e,{output:"mathml",displayMode:r,throwOnError:!1});let n=Dn(i);return r&&(n=n.replace(Vr,'<m:oMathPara xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"><m:oMath>'),n=n.replace(/<\/m:oMath>$/,
|
|
1037
1041
|
"</m:oMath></m:oMathPara>")),n}catch{return""}}static legacyLatexCodeBlockAsMath(e){const r=e.language?.trim().toLowerCase();return r!=="latex"&&r!=="latex-inline"||e.renderDiagram===!1?null:{type:"ma\
|
|
1038
1042
|
th",id:e.id,content:e.content||"",displayMode:r==="latex-inline"?"inline":"block",align:"center"}}static mathBlockToDocx(e){const r=e.displayMode!=="inline",t=e.align||"center",i=this.latexToOmml(e.content,
|
|
1039
1043
|
r);return{type:"mathblock",content:e.content,displayMode:r,alignment:t,omml:i||void 0}}static imageBlockToDocx(e){return{type:"image",src:e.src,width:e.width,height:e.height,alt:e.alt,align:e.align,originalFormat:e.
|
|
1040
|
-
originalFormat,originalDataUrl:e.originalDataUrl,anchorXml:e.anchorXml}}static buildParagraphIndent(e,r){const t=e.leftIndent===0?0:
|
|
1044
|
+
originalFormat,originalDataUrl:e.originalDataUrl,anchorXml:e.anchorXml}}static buildParagraphIndent(e,r){const t=e.leftIndent===0?0:zi(e.leftIndent),i=e.firstLineIndent===0?0:ji(e.firstLineIndent),n={};
|
|
1041
1045
|
return t!==void 0&&(n.left=this.pxToTwips(rr(t,r))),i!==void 0&&(i<0?n.hanging=this.pxToTwips(rr(-i,r)):n.firstLine=this.pxToTwips(rr(i,r))),Object.keys(n).length>0?n:void 0}static headerRowIndexes(e){
|
|
1042
1046
|
if(!e.hasHeader)return new Set;const r=new Set;try{const n=JSON.parse(e.structuralSuggestionRecords??"[]");for(const a of Array.isArray(n)?n:[])if(a?.type==="table-change")for(const o of a.tableRevision?.
|
|
1043
1047
|
markers??[])o.kind==="row-delete"&&o.rowId&&r.add(o.rowId)}catch{}const t=new Set([0]),i=e.children.findIndex(n=>n.diffState!=="delete"&&!(n.id&&r.has(n.id)));return i>0&&t.add(i),t}static tableToDocx(e,r){
|
|
1044
1048
|
const t=Qe(e),i=this.headerRowIndexes(e);return{type:"table",rows:e.children.map((n,a)=>{const o=i.has(a);return{cells:n.children.map(s=>{const l=[],c=[];for(const h of s.children)if(h.type==="paragra\
|
|
1045
|
-
ph"){const
|
|
1046
|
-
...
|
|
1049
|
+
ph"){const g=this.paragraphToDocx(h,r);g.inTableCell=!0,l.push(g),c.push(g)}else if(h.type==="list"){const g=this.listToDocxParagraphs(h,r,this.exportOrderedPlan);for(const f of g)f.inTableCell=!0;l.push(
|
|
1050
|
+
...g),c.push(...g)}else h.type==="table"&&c.push(this.tableToDocx(h,r));const p=t.byId.get(s.id);return{paragraphs:l,...c.some(h=>h.type==="table")?{blocks:c}:{},backgroundColor:s.backgroundColor,verticalAlign:s.
|
|
1047
1051
|
verticalAlign,borders:s.borders,padding:s.padding,colSpan:p&&p.colSpan>1?p.colSpan:void 0,rowSpan:p&&p.rowSpan>1?p.rowSpan:void 0,gridColumn:p?.col,...s.oxmlTcPr?{oxmlTcPr:s.oxmlTcPr}:{}}}),isHeader:o,
|
|
1048
1052
|
...n.oxmlAttrs?{oxmlAttrs:n.oxmlAttrs}:{},...n.oxmlTrPr?{oxmlTrPr:n.oxmlTrPr}:{}}}),columnWidths:e.columnWidths||[],hasHeader:e.hasHeader,tableWidth:e.tableWidth,align:e.align,cellPadding:e.cellPadding,
|
|
1049
|
-
borders:e.borders,borderWidth:e.borderWidth,borderColor:e.borderColor,...e.oxmlTblPr?{oxmlTblPr:e.oxmlTblPr}:{}}}static codeBlockToDocx(e,r){const t=e.content||"",i=e.language||"",n=
|
|
1050
|
-
!1&&n){const s=
|
|
1051
|
-
width,diagramHeight:s?.height}}const a=i?
|
|
1053
|
+
borders:e.borders,borderWidth:e.borderWidth,borderColor:e.borderColor,...e.oxmlTblPr?{oxmlTblPr:e.oxmlTblPr}:{}}}static codeBlockToDocx(e,r){const t=e.content||"",i=e.language||"",n=tn(i);if(n&&e.renderDiagram!==
|
|
1054
|
+
!1&&n){const s=rn({protocol:n,source:t,theme:mn(),maxWidth:900});return{type:"codeblock",content:"",language:i,runs:[],backgroundColor:r.background,renderDiagram:!0,diagramPngDataUrl:s?.dataUrl,diagramWidth:s?.
|
|
1055
|
+
width,diagramHeight:s?.height}}const a=i?nn(t,i,r):null,o=[];if(a&&a.length>0)for(const s of a){const l=s.text.split(`
|
|
1052
1056
|
`);for(let c=0;c<l.length;c++)l[c]&&o.push({text:l[c],font:"Courier New",color:this.normalizeColor(s.color)}),c<l.length-1&&o.push({text:`
|
|
1053
1057
|
`,font:"Courier New",break:!0})}else{const s=t.split(`
|
|
1054
1058
|
`);for(let l=0;l<s.length;l++)s[l]&&o.push({text:s[l],font:"Courier New",color:this.normalizeColor(r.default)}),l<s.length-1&&o.push({text:`
|
|
1055
1059
|
`,font:"Courier New",break:!0})}return{type:"codeblock",content:t,language:i,styleId:this.codeBlockStyleId(i),runs:o,backgroundColor:r.background,renderDiagram:!1}}static createStyleMarksResolver(e){const r=e.
|
|
1056
|
-
stylesXml;if(!r)return;let t;const i=new Map;return
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
r.
|
|
1063
|
-
delete t.
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
n}
|
|
1067
|
-
|
|
1068
|
-
(
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
n,e),n
|
|
1073
|
-
|
|
1074
|
-
!
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
{}
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1060
|
+
stylesXml;if(!r)return;let t;const i=new Map,n="\0unstyled";return a=>{const o=a??n;if(i.has(o))return i.get(o);t??(t=this.parseStylesXml(r));const s=!this.styleChainDeclaresFont(a,t);if(!a){const c=s?
|
|
1061
|
+
{fontFamily:Br}:void 0;return i.set(o,c),c}const l=this.resolveRunMarks(void 0,a,{styles:t});return s&&!l.fontFamily&&(l.fontFamily=Br),i.set(o,l),l}}static styleChainDeclaresFont(e,r){return[...r.runDefault?
|
|
1062
|
+
[r.runDefault]:[],...this.resolveStyleChainRPr(this.effectiveParagraphStyleId(e,r),r,"paragraph")].some(t=>!!this.getDirectChild(t,"w:rFonts"))}static styleExportContext(e){return{stylesheet:e.stylesheet,
|
|
1063
|
+
styleMarksFor:this.createStyleMarksResolver(e)}}static styledParagraphToDocxWithMath(e,r,t,i){const n=e.styleId?fn(i.stylesheet,e.styleId)?.paragraphAttrs:void 0,a=this.stripStyleProvidedParagraphAttrs(
|
|
1064
|
+
e,n),o=i.styleMarksFor?.(e.styleId),s=this.paragraphToDocxWithMath(a,o?.fontFamily?void 0:r,t,o);return a.spaceAfter===void 0&&e.spaceAfter!==void 0&&(s.styleProvidesSpacing=!0),s}static stripStyleProvidedParagraphAttrs(e,r){
|
|
1065
|
+
if(!r)return e;const t={...e},i=(n,a)=>n!==void 0&&a!==void 0&&Math.abs(n-a)<.011;return t.align!==void 0&&t.align===r.align&&delete t.align,i(t.lineSpacing,r.lineSpacing)&&delete t.lineSpacing,i(t.spaceBefore,
|
|
1066
|
+
r.spaceBefore)&&i(t.spaceAfter,r.spaceAfter)&&(t.contextualSpacing??!1)===(r.contextualSpacing??!1)&&(delete t.spaceBefore,delete t.spaceAfter,delete t.contextualSpacing),t.keepNext===!0&&r.keepNext===
|
|
1067
|
+
!0&&delete t.keepNext,t.keepLines===!0&&r.keepLines===!0&&delete t.keepLines,t.widowControl===!1&&r.widowControl===!1&&delete t.widowControl,i(t.leftIndent,r.leftIndent)&&delete t.leftIndent,i(t.firstLineIndent,
|
|
1068
|
+
r.firstLineIndent)&&delete t.firstLineIndent,t.tabStops!==void 0&&t.tabStops===r.tabStops&&delete t.tabStops,t.borders!==void 0&&t.borders===r.borders&&delete t.borders,t.shading!==void 0&&t.shading===
|
|
1069
|
+
r.shading&&delete t.shading,t}static stripStyleProvidedMarks(e,r){if(!e||!r)return e;const t=n=>String(n).split(",")[0].replaceAll('"',"").replaceAll("'","").trim().toLowerCase(),i={...e};for(const n of Object.
|
|
1070
|
+
keys(r))i[n]!==void 0&&(n==="fontFamily"?t(i[n])===t(r[n]):i[n]===r[n])&&delete i[n];return i}static paragraphToDocxWithMath(e,r,t=this.resolveIndentStepPx(),i){const n=this.exportDefaultRunSizeHalfPoints;
|
|
1071
|
+
(e.heading||i?.fontSize)&&(this.exportDefaultRunSizeHalfPoints=void 0);try{return this.paragraphToDocxWithMathInner(e,r,t,i)}finally{this.exportDefaultRunSizeHalfPoints=n}}static paragraphToDocxWithMathInner(e,r,t=this.
|
|
1072
|
+
resolveIndentStepPx(),i){const n={type:"paragraph",sourceBlockId:e.id,children:[]};e.styleId&&(n.styleId=e.styleId),e.heading&&(n.heading=`HEADING_${e.heading}`);{const s=this.docxAlignmentForExport(e);
|
|
1073
|
+
s&&(n.alignment=s)}e.lineSpacing!==void 0&&(n.lineSpacing=e.lineSpacing),this.applyExportParagraphSpacing(n,e),e.keepNext&&(n.keepNext=!0),e.keepLines&&(n.keepLines=!0),e.widowControl===!1&&(n.widowControl=
|
|
1074
|
+
!1),e.borders&&(n.bordersJson=e.borders),e.shading&&(n.shadingFill=e.shading),e.tabStops&&(n.tabStopsJson=e.tabStops),e.oxmlAttrs&&(n.oxmlAttrs=e.oxmlAttrs),e.oxmlPPr&&(n.oxmlPPr=e.oxmlPPr);const a=this.
|
|
1075
|
+
buildParagraphIndent(e,t);a&&(n.indent=a);const o=e;if(o.fontFamily&&(n.style=o.fontFamily),this.applyParagraphMarkRevisionInfo(n,e),this.applyParagraphPropertyChangeInfo(n,e,t),e.children.length===0)
|
|
1076
|
+
return this.applyWholeBlockRevisionInfo(n,e),this.applyBidiExportFlags(n,e),n;for(const s of this.dropReplacementSeparators(this.runRevisionsForBlockChange(e)))if(s.type==="text"){const l=i?{...s,marks:this.
|
|
1077
|
+
stripStyleProvidedMarks(s.marks,i)}:s,c=this.textNodeToDocxWithLatex(l,r);n.children.push(...c)}return this.applyWholeBlockRevisionInfo(n,e),this.applyBidiExportFlags(n,e),n}static docxAlignmentForExport(e){
|
|
1078
|
+
if(!e.align)return;const r=e.direction==="rtl"||e.direction===void 0&&Lt(this.paragraphNodeText(e))==="rtl",t=r&&e.align==="left"?"right":r&&e.align==="right"?"left":e.align;return{left:"LEFT",center:"\
|
|
1079
|
+
CENTER",right:"RIGHT",justify:"JUSTIFIED"}[t]}static applyBidiExportFlags(e,r){const t=this.paragraphNodeText(r);if(r.direction==="ltr"){Lt(t)==="rtl"&&(e.bidirectional=!1);return}if(r.direction==="rt\
|
|
1080
|
+
l"||r.direction===void 0&&Lt(t)==="rtl"){e.bidirectional=!0;for(const i of e.children)i.text&&on(i.text)&&(i.rightToLeft=!0)}}static listToDocxParagraphsWithMath(e,r,t){e=this.listWithItemRevisions(e);
|
|
1081
|
+
const i=[],n={level0:(e.startNumber??1)-1,level1:0,level2:0};for(const a of e.children){if(a.type!=="list-item")continue;const o=this.getClampedIndentLevel(a.indentLevel),s={type:"paragraph",sourceBlockId:a.
|
|
1082
|
+
id,children:[],lineSpacing:a.lineSpacing??e.lineSpacing,...typeof(a.spaceBefore??e.spaceBefore)=="number"?{spacingBeforeTwips:this.pxToTwips(a.spaceBefore??e.spaceBefore)}:{},...typeof(a.spaceAfter??e.
|
|
1083
|
+
spaceAfter)=="number"?{spacingAfterTwips:this.pxToTwips(a.spaceAfter??e.spaceAfter)}:{},...e.contextualSpacing?{contextualSpacing:!0}:{},list:{variant:e.variant,level:o,label:"",checked:e.variant==="t\
|
|
1084
|
+
odo"?!!a.checked:void 0,reference:t?.get(e.id)?.reference??this.getDocxListReference(e),instance:t?.get(e.id)?.instance??0}},l=this.getListLabel(e,a,n);if(s.list&&(s.list.label=l),e.variant==="todo"&&
|
|
1085
|
+
s.children.push({text:`${l} `}),a.children.length>0){for(const c of a.children)if(c.type==="text"){const p=this.textNodeToDocxWithLatex(c,r);s.children.push(...p)}}this.applyWholeBlockRevisionInfo(s,a.
|
|
1086
|
+
structuralSuggestionKind?a:e),this.applyParagraphPropertyChangeInfo(s,a,0),i.push(s)}return i}static tableToDocxWithMath(e,r,t=this.resolveIndentStepPx(),i){const n=Qe(e),a=[],o=this.headerRowIndexes(
|
|
1087
|
+
e);for(let s=0;s<e.children.length;s++){const l=e.children[s],c=o.has(s),p=[];for(const h of l.children){const g=[],f=[];for(const u of h.children)if(u.type==="paragraph"){const m=i?this.styledParagraphToDocxWithMath(
|
|
1088
|
+
u,r,t,i):this.paragraphToDocxWithMath(u,r,t);m.inTableCell=!0,g.push(m),f.push(m)}else if(u.type==="list"){const m=this.listToDocxParagraphsWithMath(u,r,this.exportOrderedPlan);for(const b of m)b.inTableCell=
|
|
1089
|
+
!0;g.push(...m),f.push(...m)}else u.type==="table"&&f.push(this.tableToDocxWithMath(u,r,t,i));const w=n.byId.get(h.id);p.push({paragraphs:g,...f.some(u=>u.type==="table")?{blocks:f}:{},backgroundColor:h.
|
|
1084
1090
|
backgroundColor,verticalAlign:h.verticalAlign,borders:h.borders,padding:h.padding,colSpan:w&&w.colSpan>1?w.colSpan:void 0,rowSpan:w&&w.rowSpan>1?w.rowSpan:void 0,gridColumn:w?.col,...h.oxmlTcPr?{oxmlTcPr:h.
|
|
1085
1091
|
oxmlTcPr}:{}})}a.push({cells:p,isHeader:c,...l.oxmlAttrs?{oxmlAttrs:l.oxmlAttrs}:{},...l.oxmlTrPr?{oxmlTrPr:l.oxmlTrPr}:{}})}return{type:"table",rows:a,columnWidths:e.columnWidths||[],hasHeader:e.hasHeader,
|
|
1086
1092
|
tableWidth:e.tableWidth,align:e.align,cellPadding:e.cellPadding,borders:e.borders,borderWidth:e.borderWidth,borderColor:e.borderColor,...e.oxmlTblPr?{oxmlTblPr:e.oxmlTblPr}:{}}}static applyParagraphMarkRevisionInfo(e,r){
|
|
@@ -1104,55 +1110,55 @@ pxToTwips(n.spaceBefore)}:{},...typeof n.spaceAfter=="number"?{spaceAfterTwips:t
|
|
|
1104
1110
|
widowControl:!1}:{},...n.direction?{direction:n.direction}:{},...n.borders?{bordersJson:n.borders}:{},...n.shading?{shadingFill:n.shading}:{},...n.styleId?{styleId:n.styleId}:n.heading?{styleId:`Headi\
|
|
1105
1111
|
ng${n.heading}`}:{}}}}static collectTableRevisionPatches(e){const r=[];let t=0;const i=[],n=o=>{for(const s of o)if(s.type==="table"){i.push(s);for(const l of s.children)for(const c of l.children)n(c.
|
|
1106
1112
|
children)}else s.type==="container"&&n(s.children)};n(e.children);const a=this.collectLinkedMoveSides(e.children);for(const o of i){const s=t++,l=o.diffState==="insert"||o.diffState==="delete"?o.diffState:
|
|
1107
|
-
void 0,c=l&&typeof o.suggestionId=="string"?a.get(o.suggestionId)?.[l==="delete"?"from":"to"]:void 0;if(l&&c){r.push({tableIndex:s,rows:o.children.map((y,
|
|
1113
|
+
void 0,c=l&&typeof o.suggestionId=="string"?a.get(o.suggestionId)?.[l==="delete"?"from":"to"]:void 0;if(l&&c){r.push({tableIndex:s,rows:o.children.map((y,T)=>({rowIndex:T,kind:l,author:c.author,date:c.
|
|
1108
1114
|
date,revisionGroup:`${o.suggestionId}\0${l}`})),cells:[],merges:[],rowProperties:[],rowExceptionProperties:[],cellProperties:[]});continue}let p=[];if(o.structuralSuggestionRecords)try{const y=JSON.parse(
|
|
1109
|
-
o.structuralSuggestionRecords);Array.isArray(y)&&(p=y.filter(
|
|
1110
|
-
1&&(h=y)}catch{}if(p.length>0||h){const y={tableIndex:s,rows:[],cells:[],merges:[],rowProperties:[],rowExceptionProperties:[],cellProperties:[]},
|
|
1111
|
-
const O=
|
|
1112
|
-
exec(
|
|
1113
|
-
isFinite(
|
|
1114
|
-
"/>`).join("")}</w:tblGrid>`};if(h){const
|
|
1115
|
-
cells:[]};for(const[
|
|
1116
|
-
rowExceptions.push({rowIndex:
|
|
1117
|
-
for(const
|
|
1118
|
-
-insert"?"insert":"delete",...O});continue}if(
|
|
1119
|
-
y.cells.push({rowIndex:
|
|
1120
|
-
y.merges.push({rowIndex:S,gridColumn:
|
|
1121
|
-
y.tableGrid={...O,currentXml:
|
|
1122
|
-
table"||
|
|
1123
|
-
rties"&&S.target==="cell"&&(!
|
|
1124
|
-
void 0);if(
|
|
1125
|
-
{}};else if(
|
|
1126
|
-
{rowIndex:S,...O,currentXml:
|
|
1127
|
-
priorTableAttributes}:{}})}else if(
|
|
1128
|
-
gridColumn:
|
|
1129
|
-
operations.find(O=>O.kind==="grid");
|
|
1115
|
+
o.structuralSuggestionRecords);Array.isArray(y)&&(p=y.filter(T=>T?.type==="table-change"))}catch{}let h;if(o.docxTablePropertyOverrides)try{const y=JSON.parse(o.docxTablePropertyOverrides);y?.version===
|
|
1116
|
+
1&&(h=y)}catch{}if(p.length>0||h){const y={tableIndex:s,rows:[],cells:[],merges:[],rowProperties:[],rowExceptionProperties:[],cellProperties:[]},T=Qe(o),L=new Map(o.children.map((D,M)=>[D.id,M])),W=(D,M)=>{
|
|
1117
|
+
const O=M.author?.trim()||D.agentName?.trim()||(D.authorType==="ai"?Ct:"Anonymous"),I=typeof M.createdAt=="number"?M.createdAt:typeof D.createdAt=="number"?D.createdAt:Date.now(),B=M.revisionId??/^docxrev-(\d+)$/.
|
|
1118
|
+
exec(D.id)?.[1],E=typeof B=="string"&&/^\d+$/.test(B)?Number(B):void 0;return{author:O,date:new Date(I).toISOString(),revisionGroup:D.id,...E!==void 0?{importedId:E}:{}}},X=D=>{const M=D.map(I=>Number.
|
|
1119
|
+
isFinite(I)&&I>0?I:1),O=M.reduce((I,B)=>I+B,0)||1;return`<w:tblGrid xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">${M.map(I=>`<w:gridCol w:w="${Math.max(1,Math.round(I/O*1e4))}\
|
|
1120
|
+
"/>`).join("")}</w:tblGrid>`};if(h){const D={...h.table?{table:h.table}:{},...h.grid&&JSON.stringify(h.grid.columnWidths)===JSON.stringify(o.columnWidths)?{grid:h.grid.xml}:{},rows:[],rowExceptions:[],
|
|
1121
|
+
cells:[]};for(const[M,O]of Object.entries(h.rows??{})){const I=L.get(M);I!==void 0&&D.rows.push({rowIndex:I,xml:O})}for(const[M,O]of Object.entries(h.rowExceptions??{})){const I=L.get(M);I!==void 0&&D.
|
|
1122
|
+
rowExceptions.push({rowIndex:I,xml:O})}for(const[M,O]of Object.entries(h.cells??{})){const I=T.byId.get(M);I&&D.cells.push({rowIndex:I.row,gridColumn:I.col,xml:O})}y.propertyOverrides=D}for(const D of p){
|
|
1123
|
+
for(const M of D.tableRevision.markers){const O=W(D,M);if(M.kind==="row-insert"||M.kind==="row-delete"){const S=M.rowId?L.get(M.rowId):M.rowIndex;S!==void 0&&y.rows.push({rowIndex:S,kind:M.kind==="row\
|
|
1124
|
+
-insert"?"insert":"delete",...O});continue}if(M.kind==="cell-insert"||M.kind==="cell-delete"){const S=M.cellId?T.byId.get(M.cellId):void 0,R=S?.row??M.rowIndex,z=S?.col??M.gridColumn;R!==void 0&&z!==void 0&&
|
|
1125
|
+
y.cells.push({rowIndex:R,gridColumn:z,kind:M.kind==="cell-insert"?"insert":"delete",...O});continue}if(M.kind==="cell-merge"){const S=M.rowId?L.get(M.rowId):M.rowIndex;S!==void 0&&M.gridColumn!==void 0&&
|
|
1126
|
+
y.merges.push({rowIndex:S,gridColumn:M.gridColumn,...O,...M.vMerge?{vMerge:M.vMerge}:{},...M.vMergeOrig?{vMergeOrig:M.vMergeOrig}:{}});continue}if(M.kind==="table-grid"&&M.currentPropertiesXml&&M.priorPropertiesXml){
|
|
1127
|
+
y.tableGrid={...O,currentXml:M.currentPropertiesXml,priorXml:M.priorPropertiesXml};continue}const I=D.tableRevision.operations.find(S=>S.kind==="properties"&&(M.kind==="table-properties"&&S.target==="\
|
|
1128
|
+
table"||M.kind==="row-properties"&&S.target==="row"&&(!M.rowId||S.rowId===M.rowId)||M.kind==="row-exception-properties"&&S.target==="row-exception"&&(!M.rowId||S.rowId===M.rowId)||M.kind==="cell-prope\
|
|
1129
|
+
rties"&&S.target==="cell"&&(!M.cellId||S.cellId===M.cellId))),B=M.currentPropertiesXml??(I?.kind==="properties"?I.currentPropertiesXml:void 0),E=M.priorPropertiesXml??(I?.kind==="properties"?I.priorPropertiesXml:
|
|
1130
|
+
void 0);if(M.kind==="table-properties")y.tableProperties={...O,...B?{currentXml:B}:{},...E?{priorXml:E}:{},...I?.kind==="properties"?{currentAttributes:I.currentAttributes,priorAttributes:I.priorAttributes}:
|
|
1131
|
+
{}};else if(M.kind==="row-properties"||M.kind==="row-exception-properties"){const S=M.rowId?L.get(M.rowId):M.rowIndex;S!==void 0&&(M.kind==="row-properties"?y.rowProperties:y.rowExceptionProperties).push(
|
|
1132
|
+
{rowIndex:S,...O,currentXml:B??"",priorXml:E??"",...I?.kind==="properties"?{currentAttributes:I.currentAttributes,priorAttributes:I.priorAttributes,currentTableAttributes:I.currentTableAttributes,priorTableAttributes:I.
|
|
1133
|
+
priorTableAttributes}:{}})}else if(M.kind==="cell-properties"){const S=M.cellId?T.byId.get(M.cellId):void 0,R=S?.row??M.rowIndex,z=S?.col??M.gridColumn;R!==void 0&&z!==void 0&&y.cellProperties.push({rowIndex:R,
|
|
1134
|
+
gridColumn:z,...O,...B?{currentXml:B}:{},...E?{priorXml:E}:{},...I?.kind==="properties"?{currentAttributes:I.currentAttributes,priorAttributes:I.priorAttributes}:{}})}}if(!y.tableGrid){const M=D.tableRevision.
|
|
1135
|
+
operations.find(O=>O.kind==="grid");M?.kind==="grid"&&(y.tableGrid={...W(D,{}),currentXml:M.currentGridXml||X(M.currentColumnWidths),priorXml:M.priorGridXml||X(M.priorColumnWidths)})}}(y.rows.length||
|
|
1130
1136
|
y.cells.length||y.merges.length||y.tableGrid||y.rowProperties.length||y.rowExceptionProperties.length||y.cellProperties.length||y.tableProperties||y.propertyOverrides)&&r.push(y);continue}if(o.structuralSuggestionKind!==
|
|
1131
|
-
"change"||!o.structuralSuggestionRecord)continue;let
|
|
1132
|
-
"table")continue;const f=/^docxrev-(\d+)$/.exec(o.structuralSuggestionId??"")?.[1],w=y=>{const
|
|
1133
|
-
|
|
1134
|
-
now(),
|
|
1135
|
-
rowProperties:[],rowExceptionProperties:[],cellProperties:[]},g
|
|
1136
|
-
|
|
1137
|
-
merges??[]){const
|
|
1138
|
-
(u.tableProperties={...w(
|
|
1139
|
-
|
|
1140
|
-
insert",...w()}):y.has(
|
|
1141
|
-
has(
|
|
1142
|
-
1,
|
|
1143
|
-
borders&&(u.tableProperties={...w(),...
|
|
1137
|
+
"change"||!o.structuralSuggestionRecord)continue;let g;try{g=JSON.parse(o.structuralSuggestionRecord)}catch{continue}if(g.type!=="block-change"||g.beforeBlock?.type!=="table"||g.acceptedBlock?.type!==
|
|
1138
|
+
"table")continue;const f=/^docxrev-(\d+)$/.exec(o.structuralSuggestionId??"")?.[1],w=y=>{const T=typeof y?.author=="string"&&y.author.trim()?y.author.trim():typeof g.agentName=="string"&&g.agentName.trim()?
|
|
1139
|
+
g.agentName.trim():g.authorType==="ai"?Ct:"Anonymous",L=typeof y?.createdAt=="number"&&Number.isFinite(y.createdAt)?y.createdAt:typeof g.createdAt=="number"&&Number.isFinite(g.createdAt)?g.createdAt:Date.
|
|
1140
|
+
now(),W=y?.revisionId??f,X=typeof W=="string"&&/^\d+$/.test(W)?Number(W):void 0;return{author:T,date:new Date(L).toISOString(),...X!==void 0?{importedId:X}:{}}},u={tableIndex:s,rows:[],cells:[],merges:[],
|
|
1141
|
+
rowProperties:[],rowExceptionProperties:[],cellProperties:[]},m=g.docxTableRevisions,b=Qe(o),v=new Map(o.children.map((y,T)=>[y.id,T]));if(m?.version===1){for(const y of m.rows??[]){const T=v.get(y.rowId);
|
|
1142
|
+
T!==void 0&&u.rows.push({rowIndex:T,kind:y.kind,...w(y)})}for(const y of m.cells??[]){const T=b.byId.get(y.cellId);T&&u.cells.push({rowIndex:T.row,gridColumn:T.col,kind:y.kind,...w(y)})}for(const y of m.
|
|
1143
|
+
merges??[]){const T=v.get(y.rowId);T!==void 0&&u.merges.push({rowIndex:T,gridColumn:y.gridColumn,...w(y),...y.vMerge?{vMerge:y.vMerge}:{},...y.vMergeOrig?{vMergeOrig:y.vMergeOrig}:{}})}m.tableProperties&&
|
|
1144
|
+
(u.tableProperties={...w(m.tableProperties),...m.tableProperties.priorXml?{priorXml:m.tableProperties.priorXml}:{},...g.beforeBlock.borders?{priorBorders:g.beforeBlock.borders}:{}})}else{const y=new Set(
|
|
1145
|
+
g.beforeBlock.children.map(X=>X.id)),T=new Set(g.acceptedBlock.children.map(X=>X.id));for(let X=0;X<o.children.length;X++){const D=o.children[X];!y.has(D.id)&&T.has(D.id)?u.rows.push({rowIndex:X,kind:"\
|
|
1146
|
+
insert",...w()}):y.has(D.id)&&!T.has(D.id)&&u.rows.push({rowIndex:X,kind:"delete",...w()})}const L=Qe(g.beforeBlock),W=Qe(g.acceptedBlock);for(const X of b.cells){const D=L.byId.has(X.cell.id),M=W.byId.
|
|
1147
|
+
has(X.cell.id);!D&&M?u.cells.push({rowIndex:X.row,gridColumn:X.col,kind:"insert",...w()}):D&&!M&&u.cells.push({rowIndex:X.row,gridColumn:X.col,kind:"delete",...w()});const O=L.byId.get(X.cell.id)?.rowSpan??
|
|
1148
|
+
1,I=W.byId.get(X.cell.id)?.rowSpan??1;if(I>O&&X.rowSpan>O)for(let B=O;B<Math.min(I,X.rowSpan);B++)u.merges.push({rowIndex:X.row+B,gridColumn:X.col,vMerge:"cont",...w()})}g.beforeBlock.borders!==g.acceptedBlock.
|
|
1149
|
+
borders&&(u.tableProperties={...w(),...g.beforeBlock.borders?{priorBorders:g.beforeBlock.borders}:{}})}(u.rows.length>0||u.cells.length>0||u.merges.length>0||u.tableProperties)&&r.push(u)}return r}static listWithItemRevisions(e){
|
|
1144
1150
|
const r=s=>{try{return s?JSON.parse(s):null}catch{return null}},t=s=>{const l={...s};return delete l.structuralSuggestionId,delete l.structuralSuggestionKind,delete l.structuralSuggestionLabel,delete l.
|
|
1145
1151
|
structuralSuggestionRecord,l},i=s=>JSON.stringify(s.flatMap(l=>{const c=JSON.stringify(Object.entries(l.marks??{}).filter(([p,h])=>!p.startsWith("suggestion")&&h!==void 0&&h!==null&&h!==!1).map(([p,h])=>[
|
|
1146
1152
|
p,p==="fontFamily"&&typeof h=="string"?h.split(",")[0].replace(/['"]/g,"").trim().toLowerCase():h]).sort(([p],[h])=>String(p).localeCompare(String(h))));return Array.from(l.text,p=>`${p}${c}`)})),n=(s,l,c,p)=>{
|
|
1147
|
-
let h=t(s);const
|
|
1148
|
-
{}},f=[...s.children,...l.children].some(
|
|
1149
|
-
...y.marks,...
|
|
1150
|
-
for(const
|
|
1153
|
+
let h=t(s);const g={suggestionId:c,...p.authorType?{suggestionAuthorType:p.authorType}:{},...p.agentName?{suggestionAuthorName:p.agentName}:{},...p.createdAt!==void 0?{suggestionCreatedAt:p.createdAt}:
|
|
1154
|
+
{}},f=[...s.children,...l.children].some(m=>m.marks?.insertion||m.marks?.deletion||m.marks?.formatChange);if(l.children.length>0&&!f&&i(l.children)!==i(s.children)){const m=(b,v)=>b.map(y=>({...y,marks:{
|
|
1155
|
+
...y.marks,...g,[v]:!0}}));h={...h,children:[...m(l.children,"deletion"),...m(s.children,"insertion")]}}const w={};let u=!1;(l.indentLevel??0)!==(s.indentLevel??0)&&(w.indentLevel=l.indentLevel??0,u=!0);
|
|
1156
|
+
for(const m of this.LIST_ITEM_PROPERTY_FIELDS){const b=l[m]??e[m],v=s[m]??e[m];b!==void 0&&(w[m]=b),JSON.stringify(b)!==JSON.stringify(v)&&(u=!0)}return u&&(h={...h,structuralSuggestionId:c,structuralSuggestionKind:"\
|
|
1151
1157
|
change",structuralSuggestionRecord:JSON.stringify({type:"block-change",beforeBlock:{type:"paragraph",id:s.id,...w},agentName:p.agentName,authorType:p.authorType,createdAt:p.createdAt})}),h},a=e.structuralSuggestionKind===
|
|
1152
|
-
"change"?r(e.structuralSuggestionRecord):null,o=a?.type==="block-change"&&a.beforeBlock?.type==="list"?a.beforeBlock:null;if(o&&e.structuralSuggestionId){const s=e.structuralSuggestionId,l=a,c=(
|
|
1153
|
-
...t(
|
|
1154
|
-
|
|
1155
|
-
children){const b=h.get(
|
|
1158
|
+
"change"?r(e.structuralSuggestionRecord):null,o=a?.type==="block-change"&&a.beforeBlock?.type==="list"?a.beforeBlock:null;if(o&&e.structuralSuggestionId){const s=e.structuralSuggestionId,l=a,c=(m,b)=>({
|
|
1159
|
+
...t(m),structuralSuggestionId:s,structuralSuggestionKind:b,structuralSuggestionRecord:JSON.stringify({agentName:l.agentName,authorType:l.authorType,createdAt:l.createdAt})}),p=new Set(e.children.map(
|
|
1160
|
+
m=>m.id)),h=new Map(o.children.map(m=>[m.id,m])),g=new Map;let f=null;for(const m of o.children)p.has(m.id)?f=m.id:g.set(f,[...g.get(f)??[],c(m,"delete")]);const w=[...g.get(null)??[]];for(const m of e.
|
|
1161
|
+
children){const b=h.get(m.id);w.push(b?n(m,b,s,l):c(m,"insert"),...g.get(m.id)??[])}const u={...e,children:w};return delete u.structuralSuggestionKind,u}return e.children.some(s=>s.structuralSuggestionKind===
|
|
1156
1162
|
"change")?{...e,children:e.children.map(s=>{if(s.structuralSuggestionKind!=="change")return s;const l=r(s.structuralSuggestionRecord),c=l?.listItemSuggestion?.beforeItem;return!l||!c||!s.structuralSuggestionId?
|
|
1157
1163
|
s:n(s,c.children.length>0?c:{...c,children:s.children},s.structuralSuggestionId,l)})}:e}static pendingListNumberingChanges(e){const r=[],t=i=>{if(i.type==="list"){if(i.structuralSuggestionKind==="chan\
|
|
1158
1164
|
ge")try{const n=JSON.parse(i.structuralSuggestionRecord??"{}").beforeBlock;n?.type==="list"&&(n.variant!==i.variant||(n.startNumber??1)!==(i.startNumber??1)||(n.numberingFormat??null)!==(i.numberingFormat??
|
|
@@ -1228,9 +1234,9 @@ image/png":return"png";case"image/jpeg":case"image/jpg":return"jpg";case"image/g
|
|
|
1228
1234
|
return this.toDocxHex(e)??"000000"}static highlightValueToColor(e){return or(e)??"yellow"}static colorToHighlight(e){const r=or(e);if(r)return{yellow:"yellow",orange:"darkYellow",green:"green",blue:"b\
|
|
1229
1235
|
lue",purple:"darkMagenta",pink:"magenta",gray:"lightGray"}[r]||"yellow";const t=this.normalizeColor(e);return{FFFF00:"yellow",FF0000:"red","00FF00":"green","0000FF":"blue",FFA500:"orange",FF00FF:"mage\
|
|
1230
1236
|
nta","00FFFF":"cyan",808080:"darkGray",D3D3D3:"lightGray"}[t]||"yellow"}};ue.LIST_BASE_INDENT_TWIPS=720,ue.LIST_INDENT_INCREMENT_TWIPS=360,ue.LIST_HANGING_INDENT_TWIPS=360,ue.TWIPS_PER_INCH=1440,ue.TWIPS_PER_PX=
|
|
1231
|
-
ue.TWIPS_PER_INCH/96,ue.DOCX_HALF_POINTS_PER_PX=1.5,ue.DEFAULT_RUN_SIZE_HALF_POINTS=ue.pxToDocxHalfPoints(Ae.paragraph),ue.PAGE_SIZE_PRESETS=Object.entries(
|
|
1237
|
+
ue.TWIPS_PER_INCH/96,ue.DOCX_HALF_POINTS_PER_PX=1.5,ue.DEFAULT_RUN_SIZE_HALF_POINTS=ue.pxToDocxHalfPoints(Ae.paragraph),ue.PAGE_SIZE_PRESETS=Object.entries(Ci).map(([F,e])=>({preset:F,width:Math.min(e.
|
|
1232
1238
|
width,e.height),height:Math.max(e.width,e.height)})),ue.CORE_PROPERTY_LOCAL_NAMES=["title","creator","subject","keywords","description","lastModifiedBy","created","modified","revision"],ue.LIST_ITEM_PROPERTY_FIELDS=
|
|
1233
1239
|
["spaceBefore","spaceAfter","lineSpacing","direction"],ue.TODO_MARKERS=[["☒ ",!0],["☐ ",!1],["[x] ",!0],["[X] ",!0],["[ ] ",!1]],ue.fallbackCommentState={},ue.sdtAncestorStack=[],ue.OXML_RANGE_PAIRS=
|
|
1234
1240
|
new Map([["w:permStart","w:permEnd"]]),ue.UNTRACKABLE_MOVE_KINDS=new Set(["image","code","math","page-break","toc"]),ue.OMML_FUNCTION_NAMES=["sin","cos","tan","cot","sec","csc","arcsin","arccos","arct\
|
|
1235
1241
|
an","sinh","cosh","tanh","coth","log","ln","lg","exp","det","dim","ker","deg","gcd","hom","arg","max","min","sup","inf","lim","liminf","limsup","Pr"],ue.CODE_BLOCK_STYLE_ID="CodeBlock",ue.CODE_INLINE_STYLE_ID=
|
|
1236
|
-
"CodeInline";let
|
|
1242
|
+
"CodeInline";let Bn=ue;export{Bn as DocxConverter};
|