revise 2.2.0 → 3.0.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.
Files changed (134) hide show
  1. package/CHANGELOG.md +47 -1182
  2. package/LICENSE +24 -41
  3. package/README.md +103 -26
  4. package/agent.d.ts +139 -0
  5. package/chunks/chunk-U5X47PZ6.js +135 -0
  6. package/chunks/chunk-U6YKQBKL.js +15 -0
  7. package/chunks/chunk-ZLQVPMBN.js +1650 -0
  8. package/chunks/package-5SHL5FOJ.js +14 -0
  9. package/chunks/render-QD5VWKSV.js +109 -0
  10. package/cli-output.schema.json +1984 -0
  11. package/cli.js +3604 -0
  12. package/document.d.ts +320 -0
  13. package/docx.d.ts +73 -0
  14. package/errors.d.ts +14 -0
  15. package/index.d.ts +13 -975
  16. package/index.js +31 -1
  17. package/legacy/editor.d.ts +19 -0
  18. package/legacy/editor.js +16 -0
  19. package/legacy/server.d.ts +37 -0
  20. package/legacy/server.js +25 -0
  21. package/legacy/style.css +2 -0
  22. package/package.d.ts +23 -0
  23. package/package.json +49 -55
  24. package/render.d.ts +27 -0
  25. package/FONT-LICENSE-HAN-EXT-B.txt +0 -91
  26. package/FONT-LICENSE-KATEX.txt +0 -95
  27. package/FONT-LICENSE-LIBERATION.txt +0 -102
  28. package/FONT-LICENSE-NOTO-MULTILINGUAL.txt +0 -93
  29. package/FONT-LICENSE-NOTO-SANS-SC.txt +0 -93
  30. package/FONT-LICENSE-NOTO.txt +0 -94
  31. package/FONT-LICENSE-SOURCE-CODE-PRO.txt +0 -94
  32. package/FONT-LICENSE-SOURCE-SERIF-4.txt +0 -93
  33. package/THIRD-PARTY-NOTICES.md +0 -3376
  34. package/assets/historyMaterializeWorker-B51R08XN.js +0 -612
  35. package/backend.d.ts +0 -161
  36. package/backend.js +0 -3
  37. package/chunks/AgentPageRenderer-CH8kSTJn.js +0 -1
  38. package/chunks/AgentPageRenderer-P23XVguo.js +0 -1
  39. package/chunks/AttachmentDocumentImporter-B1WOaa7d.js +0 -1
  40. package/chunks/AttachmentDocumentImporter-CT_PJp_e.js +0 -1
  41. package/chunks/BidiText-Swm5fl9J.js +0 -160
  42. package/chunks/ColorParserFull-BKH72fK8.js +0 -446
  43. package/chunks/DocumentMutator-btiDK57e.js +0 -31
  44. package/chunks/DocumentScrubber-CMPfm_HF.js +0 -18
  45. package/chunks/DocumentScrubber-Cm2kH8op.js +0 -1
  46. package/chunks/DocumentScrubber-bJoKijol.js +0 -1
  47. package/chunks/DocumentStylesheet-DreoD7sD.js +0 -7
  48. package/chunks/DocxConverter-BcVG-p5K.js +0 -13
  49. package/chunks/DocxConverter-D2bO5RE-.js +0 -1125
  50. package/chunks/DocxConverter-haCfRuWb.js +0 -13
  51. package/chunks/DocxGraft-BRKh4mHQ.js +0 -1
  52. package/chunks/DocxGraft-BxSQtl12.js +0 -7
  53. package/chunks/DocxGraft-C9MBQCnf.js +0 -1
  54. package/chunks/FileImporter-CszqRfVU.js +0 -1
  55. package/chunks/FileImporter-DObFoCCn.js +0 -1
  56. package/chunks/HorizontalRuleOrnaments-gmUZ3R7Q.js +0 -3
  57. package/chunks/HtmlConverter-DwXB4IDh.js +0 -267
  58. package/chunks/ListNumbering-Qlu6AuRZ.js +0 -23
  59. package/chunks/MarkdownConverter-CUC8GgsS.js +0 -57
  60. package/chunks/MathRenderer-DT6GyJXb.js +0 -68
  61. package/chunks/OdtConverter-7h9HHMpL.js +0 -125
  62. package/chunks/OdtConverter-Ct4qypJk.js +0 -6
  63. package/chunks/OdtConverter-DFl__sJc.js +0 -6
  64. package/chunks/OfficeImportShared-BY6FdZ8d.js +0 -1
  65. package/chunks/OfficeImportShared-BrZoDM0j.js +0 -30
  66. package/chunks/OfficeImportShared-Bvm-mOyj.js +0 -1
  67. package/chunks/ParagraphDiffAnalysis-DrmStvmz.js +0 -36
  68. package/chunks/PdfConverter-1wyvoT7X.js +0 -21
  69. package/chunks/PdfConverter-BAoEHILo.js +0 -21
  70. package/chunks/PdfConverter-CKEvFj11.js +0 -448
  71. package/chunks/PdfImportService-BhLPp5uG.js +0 -2
  72. package/chunks/PdfImportService-xbzrN__L.js +0 -2
  73. package/chunks/RtfConverter-Bxn-enp8.js +0 -15
  74. package/chunks/RtfConverter-LZPzBDSr.js +0 -15
  75. package/chunks/RtfConverter-_bacXqr1.js +0 -186
  76. package/chunks/TableBorders-CwnF3jvH.js +0 -30
  77. package/chunks/TableGrid-DbroRucl.js +0 -12
  78. package/chunks/TextFileDecoder--rsVs3NR.js +0 -9
  79. package/chunks/TxtConverter-C7FOwHpH.js +0 -14
  80. package/chunks/UnicodeUtils-CXtusU4g.js +0 -10
  81. package/chunks/XmlConverter-7oo8oeQB.js +0 -2
  82. package/chunks/XmlConverter-DGORHJcZ.js +0 -96
  83. package/chunks/XmlConverter-DeLHReK_.js +0 -2
  84. package/chunks/__vite-browser-external-l0sNRNKZ.js +0 -0
  85. package/chunks/_commonjsHelpers-DaMA6jEr.js +0 -2
  86. package/chunks/_revise-sdk-lazy-harfbuzz-CDWdjF9f.js +0 -1
  87. package/chunks/_revise-sdk-lazy-harfbuzz-X8gnYTZL.js +0 -1
  88. package/chunks/ar-ComXvtmh.js +0 -13
  89. package/chunks/backend-DecaBz-I.js +0 -490
  90. package/chunks/base64-sSPOzq-u.js +0 -198
  91. package/chunks/browser-module-CFmqfGkE.js +0 -1791
  92. package/chunks/browser-module-Dj5o3kuL.js +0 -3
  93. package/chunks/browser-module-UuM_O36W.js +0 -3
  94. package/chunks/bundle.min-DRpfgV69.js +0 -782
  95. package/chunks/capture-1btcWcPF.js +0 -9
  96. package/chunks/carrier-DQeng6yq.js +0 -6
  97. package/chunks/de-BkbpIKxx.js +0 -13
  98. package/chunks/es-CKkXujOF.js +0 -13
  99. package/chunks/fil-piIHMc8F.js +0 -13
  100. package/chunks/footnoteFlatten-DUQticYy.js +0 -6
  101. package/chunks/fr-DuA8qLje.js +0 -13
  102. package/chunks/graftExport-CYnStOdU.js +0 -82
  103. package/chunks/html2canvas.esm-CntiHiYW.js +0 -997
  104. package/chunks/index-2TBhRkX7.js +0 -387
  105. package/chunks/index-BWdRWxoH.js +0 -1807
  106. package/chunks/index-Bf14eTEW.js +0 -1096
  107. package/chunks/index-BwcX_r62.js +0 -387
  108. package/chunks/index.es-CI0QPo8w.js +0 -780
  109. package/chunks/index.es-CI7cDExj.js +0 -5
  110. package/chunks/index.es-DHpGt6Y5.js +0 -5
  111. package/chunks/ja-DgrSs555.js +0 -13
  112. package/chunks/jspdf.es.min--GshOuIm.js +0 -77
  113. package/chunks/jspdf.es.min-DU74zN8b.js +0 -1792
  114. package/chunks/jspdf.es.min-DurJZ1zW.js +0 -77
  115. package/chunks/jszip.min-CPW0h1Kx.js +0 -476
  116. package/chunks/katex-DWj8TvwO.js +0 -1462
  117. package/chunks/pdf-BLWDCiFF.js +0 -1828
  118. package/chunks/persistInlineDocumentImages-DQj2iaqg.js +0 -1
  119. package/chunks/pseudoLocale-BoYTjmiK.js +0 -1
  120. package/chunks/pseudoLocale-DG2NnZmz.js +0 -1
  121. package/chunks/purify.es-BwLardii.js +0 -107
  122. package/chunks/serverDocumentSession-CJ1EH3Tp.js +0 -15
  123. package/chunks/signatures-Bwt_OGik.js +0 -17
  124. package/chunks/suggestionAuthorship-B-IuLQlE.js +0 -1
  125. package/chunks/tree-sitter-D6zWWUMP.js +0 -4
  126. package/chunks/wasmInline.generated-CBYFkdSM.js +0 -1
  127. package/chunks/web-tree-sitter-BXGZGnNj.js +0 -2
  128. package/chunks/zh-9OF3SWWO.js +0 -13
  129. package/full.js +0 -1
  130. package/root.d.ts +0 -5
  131. package/root.js +0 -2
  132. package/serverToolContract.d.ts +0 -391
  133. package/serverToolInputs.generated.d.ts +0 -250
  134. package/style.css +0 -1
@@ -1,82 +0,0 @@
1
- import{J as Oe}from"./jszip.min-CPW0h1Kx.js";import{C as ce,d as qe,e as Ke,c as Qe,p as Ye,h as et,g as tt,f as nt,n as rt,b as ot}from"./signatures-Bwt_OGik.js";import{h as st}from"./capture-1btcWcPF.js";
2
- function z(t,n,r=0){const a=le(t,n,r);if(a<0)throw new Error(`graft: <${n}> not found`);const o=Z(t,a);if(t[o-2]==="/")return{open:{tag:n,start:a,end:o},contentStart:o,contentEnd:o,children:[]};const s=[];
3
- let l=o;for(;;){const c=t.indexOf("<",l);if(c<0)throw new Error(`graft: unterminated <${n}>`);if(t.startsWith("<!--",c)){const g=t.indexOf("-->",c);if(g<0)throw new Error("graft: unterminated comment");
4
- l=g+3;continue}if(t[c+1]==="/"){const g=t.indexOf(">",c),u=t.slice(c+2,g).trim();if(u!==n)throw new Error(`graft: unexpected </${u}> inside <${n}>`);return{open:{tag:n,start:a,end:o},contentStart:o,contentEnd:c,
5
- children:s}}const w=it(t,c);s.push(w),l=w.end}}function it(t,n){const r=Z(t,n),a=t.slice(n+1,r).search(/[\s/>]/),o=t.slice(n+1,n+1+a);if(t[r-2]==="/")return{tag:o,start:n,end:r};let s=1,l=r;for(;s>0;){
6
- const c=t.indexOf("<",l);if(c<0)throw new Error(`graft: unterminated <${o}>`);if(t.startsWith("<!--",c)){const g=t.indexOf("-->",c);if(g<0)throw new Error("graft: unterminated comment");l=g+3;continue}
7
- const w=Z(t,c);t[c+1]==="/"?(s--,l=w):(t[w-2]==="/"||s++,l=w)}return{tag:o,start:n,end:l}}function Z(t,n){let r=n+1,a=null;for(;r<t.length;){const o=t[r];if(a)o===a&&(a=null);else if(o==='"'||o==="'")
8
- a=o;else if(o===">")return r+1;r++}throw new Error("graft: unterminated tag")}function le(t,n,r){const a=`<${n}`;let o=t.indexOf(a,r);for(;o>=0;){const s=t[o+a.length];if(s===" "||s===">"||s==="/"||s===
9
- " "||s===`
10
- `||s==="\r")return o;o=t.indexOf(a,o+1)}return-1}function Pe(t){return!!(t==="word/document.xml"||t==="word/styles.xml"||t==="word/settings.xml"||t==="word/footnotes.xml"||t==="word/endnotes.xml"||t===
11
- "word/comments.xml"||t==="word/commentsExtended.xml"||t==="docProps/core.xml"||/^word\/(header|footer)\d*\.xml$/.test(t)||/^word\/_rels\/(header|footer)\d*\.xml\.rels$/.test(t)||t==="word/_rels/footno\
12
- tes.xml.rels"||t==="word/_rels/endnotes.xml.rels")}function fe(t){return t==="word/footnotes.xml"||t==="word/endnotes.xml"||t==="word/_rels/footnotes.xml.rels"||t==="word/_rels/endnotes.xml.rels"?"not\
13
- es":/^word\/comments[A-Za-z]*\.xml$/.test(t)||/^word\/_rels\/comments[A-Za-z]*\.xml\.rels$/.test(t)?"comments":/^word\/(header|footer)\d*\.xml$/.test(t)||/^word\/_rels\/(header|footer)\d*\.xml\.rels$/.
14
- test(t)?"chrome":t==="docProps/core.xml"?"coreProps":t==="word/styles.xml"?"styles":t==="word/settings.xml"?"settings":t==="word/numbering.xml"?"numbering":null}const _e=/\b(?:r:id|r:embed|r:link|r:pict|r:dm|r:lo|r:qs|r:cs)\s*=\s*(?:"([^"]+)"|'([^']+)')/g;
15
- function B(t,n){const r=new RegExp("\\b"+n+`\\s*=\\s*(?:"([^"]*)"|'([^']*)')`).exec(t);return r?.[1]??r?.[2]}function V(t,n,r){return t.replace(new RegExp("(\\b"+n+`\\s*=\\s*)(["'])([\\s\\S]*?)\\2`),(a,o,s)=>o+
16
- s+r+s)}function Me(t){const n=new Set;for(const r of t)for(const a of r.matchAll(_e)){const o=a[1]??a[2];o&&n.add(o)}return n}function at(t,n){return t.replace(_e,(r,a,o)=>{const s=a??o,l=s?n.get(s):void 0;
17
- if(!l||!s)return r;const c=r.indexOf("="),w=r.slice(c+1).search(/["']/)+c+1;return r.slice(0,w+1)+l+r.slice(w+1+s.length)})}function de(t,n){let r=0;for(const a of t.matchAll(n)){const o=Number(a[1]);
18
- Number.isFinite(o)&&o>r&&(r=o)}return r}function D(t){const n=[];for(const r of t.matchAll(/<(?:[A-Za-z_][\w.-]*:)?Relationship\b[^>]*\/?>/g)){const a=r[0],o=B(a,"Id"),s=B(a,"Target");!o||s===void 0||
19
- n.push({id:o,raw:a,target:s,external:B(a,"TargetMode")==="External"})}return n}function ct(t,n,r){const a=le(t,"w:document",0),o=le(n,"w:document",0);if(a<0||o<0)throw new Error("graft: missing w:docu\
20
- ment root");const s=Z(t,a),l=Z(n,o),c=t.slice(a,s),w=n.slice(o,l),g=b=>{const P=new Map;for(const I of b.matchAll(/([\w:.-]+)\s*=\s*(?:"([^"]*)"|'([^']*)')/g))P.set(I[1],I[2]??I[3]);return P},u=g(c),p=g(
21
- w),O=[],k=[];for(const[b,P]of p){if(!b.startsWith("xmlns:")||u.has(b))continue;const I=b.slice(6);r.has(I)&&(O.push(`${b}="${P}"`),k.push(I))}let v=c;if(O.length>0){const b=v.endsWith("/>")?v.length-2:
22
- v.length-1;v=`${v.slice(0,b)} ${O.join(" ")}${v.slice(b)}`}const x=u.get("mc:Ignorable"),S=p.get("mc:Ignorable");if(x!==void 0&&S&&k.length>0){const b=new Set(x.split(/\s+/).filter(Boolean)),P=new Set(
23
- S.split(/\s+/).filter(Boolean));let I=!1;for(const T of k)P.has(T)&&!b.has(T)&&(b.add(T),I=!0);I&&(v=V(v,"mc:Ignorable",Array.from(b).join(" ")))}return t.slice(0,a)+v+t.slice(s)}function lt(t,n,r){const a=(l,c,w)=>Array.
24
- from(l.matchAll(/<(?:Default|Override)\b[^>]*\/?>/g)).some(g=>B(g[0],c)===w),o=new Set;for(const l of r){const c=l.lastIndexOf(".");c>=0&&o.add(l.slice(c+1).toLowerCase())}const s=[];for(const l of n.
25
- matchAll(/<(Default|Override)\b[^>]*\/?>/g)){const c=l[0],w=B(c,"Extension"),g=B(c,"PartName");(w&&o.has(w.toLowerCase())&&!a(t,"Extension",w)||g&&r.has(g.replace(/^\//,""))&&!a(t,"PartName",g))&&s.push(
26
- c)}return s.length===0?t:t.replace("</Types>",`${s.join("")}</Types>`)}function ft(t,n){if(!n)return t;if(!t)return n;let r=t;for(const a of["autoHyphenation","evenAndOddHeaders","updateFields"]){const o=new RegExp(
27
- "<w:"+a+"\\b[^>]*(?:\\/\\s*>|>[\\s\\S]*?<\\/w:"+a+"\\s*>)","g"),s=n.match(o)?.[0];r=r.replace(o,""),s&&(r=r.replace(/<\/w:settings\s*>/,s+"</w:settings>"))}return r}class y extends Error{constructor(n,r){
28
- super(r?`graft[${n}]: ${r}`:`graft[${n}]`),this.code=n,this.name="GraftProofError"}}const J={attempts:0,grafted:0,rejections:{}};function dt(t,n){const r=[];let a;const o=(s,l)=>{if(s.tag==="w:sdt"){const c=l??
29
- {start:s.start,xml:t.slice(s.start,s.end)},w=z(t,"w:sdtContent",s.start);if(w.open.start>s.end)throw new y("sdtWithoutContent");for(const g of w.children)o(g,c);return}if(s.tag==="w:sectPr"){a=t.slice(
30
- s.start,s.end);return}s.tag==="w:bookmarkStart"||s.tag==="w:bookmarkEnd"||r.push({xml:t.slice(s.start,s.end),outerSdt:l})};for(const s of n)o(s);return{slots:r,finalSectPr:a}}async function Re(t){const n=t instanceof
31
- ArrayBuffer||ArrayBuffer.isView(t)?t:typeof t.arrayBuffer=="function"?await t.arrayBuffer():t;return Oe.loadAsync(n)}async function ut(t){if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.
32
- isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);if(typeof t.arrayBuffer=="function")return new Uint8Array(await t.arrayBuffer());throw new y("carrierUnreadable")}function ue(t){const n=[];
33
- for(const r of t.split("/"))!r||r==="."||(r===".."?n.pop():n.push(r));return n.join("/")}function mt(t){if(t==="_rels/.rels")return"";const n=/^(.*)\/_rels\/([^/]+)\.rels$/.exec(t);return n?`${n[1]}/${n[2]}`:
34
- void 0}function Te(t,n){if(n.startsWith("/"))return ue(n);const r=mt(t);if(r===void 0)return ue(n);const a=r.lastIndexOf("/"),o=a>=0?r.slice(0,a+1):"";return ue(o+n)}async function wt(t){J.attempts++;
35
- try{const n=await gt(t);return J.grafted++,n}catch(n){const r=n instanceof y?n.code:"internalError";throw J.rejections[r]=(J.rejections[r]??0)+1,n}}function je(t){const n=t.docxSource,r=ht(t);if(!n||n.
36
- signatureVersion!==void 0&&n.signatureVersion!==1&&n.signatureVersion!==ce)return{hasCapture:!!n,domains:{notes:!1,chrome:!1,comments:!1,coreProps:!1,layout:!1,bodySidecars:!1,styles:!1,settings:!1},graftableGroups:new Set,
37
- groupByBlockId:new Map,bodyBlocks:r,regeneratedBlockIds:r.map(u=>u.id).filter(u=>!!u),fullyExact:!1};const a=n.signatureVersion===ce?ce:1,o={notes:n.notesSignature===rt(t,a),chrome:n.chromeSignature===
38
- nt(t,a),comments:n.commentsSignature===tt(t,a),coreProps:n.corePropertiesSignature===et(t),layout:n.pageLayoutSignature===Ye(t),bodySidecars:n.bodySidecarsSignature===Qe(t,a),styles:n.stylesSignature===
39
- Ke(t,a),settings:n.settingsSignature===qe(t)},s=new Map;for(const u of n.spans)if(!(!o.bodySidecars||!o.styles))for(const p of u.blockIds)s.set(p,u);const l=new Map;r.forEach((u,p)=>{u.id&&l.set(u.id,
40
- p)});const c=new Set;for(const u of n.spans){if(u.notesCoupled&&!o.notes)continue;const p=u.blockIds.map(x=>l.get(x));if(p.some(x=>x===void 0))continue;const O=[...p].sort((x,S)=>x-S),k=O.every((x,S)=>S===
41
- 0||x===O[S-1]+1),v=p.every((x,S)=>S===0||x>p[S-1]);!k||!v||u.blockIds.every(x=>{const S=r[l.get(x)];return n.signatures[x]===ot(S,a)})&&c.add(u)}const w=r.filter(u=>{const p=u.id?s.get(u.id):void 0;return!(p&&
42
- c.has(p))}).map(u=>u.id).filter(u=>!!u),g=w.length===0&&o.notes&&o.chrome&&o.comments&&o.coreProps&&o.layout&&o.bodySidecars&&o.styles&&o.settings;return{hasCapture:!0,domains:o,graftableGroups:c,groupByBlockId:s,
43
- bodyBlocks:r,regeneratedBlockIds:w,fullyExact:g}}async function gt(t){const{doc:n,blockRanges:r}=t,a=n.docxSource;if(!a)throw new y("noCapture");let o;if(a.sourceHash){const e=await ut(t.originalDocx),
44
- i=await st(e);if(i!==a.sourceHash)throw new y("carrierHashMismatch",`capture ${a.sourceHash.slice(0,12)}… vs carrier ${i.slice(0,12)}…`);o=e}const s=je(n);if(s.fullyExact&&o)return new Blob([o],{type:"\
45
- application/vnd.openxmlformats-officedocument.wordprocessingml.document"});const[l,c]=await Promise.all([Re(t.generatedBlob),Re(t.originalDocx)]),w=new Set;c.forEach((e,i)=>{i.dir||w.add(e)});const g=await l.
46
- file("word/document.xml")?.async("string"),u=await c.file("word/document.xml")?.async("string");if(!g||!u)throw new y("missingDocumentXml");const p=z(u,"w:body"),O=z(g,"w:body"),{slots:k,finalSectPr:v}=dt(
47
- g,O.children),x=n.children.filter(e=>e.type!=="footnote"&&e.type!=="header-footer"),S=new Map;for(const e of r)e.blockId&&S.set(e.blockId,e);const b=r.reduce((e,i)=>e+i.count,0);if(k.length!==b)throw new y(
48
- "slotCountMismatch",`generated body has ${k.length} slots, expected ${b}`);const{graftableGroups:P,groupByBlockId:I}=s,T=s.domains.notes,X=s.domains.chrome,Ne=s.domains.comments,We=s.domains.coreProps,
49
- me=s.domains.layout,ze=s.domains.styles,we=s.domains.settings,$=[],C=[],ge=new Set;let R=0,he=-1;for(const e of x){const i=e.id?I.get(e.id):void 0;if(i&&P.has(i)){if(ge.has(i))continue;ge.add(i);const m=p.
50
- children[i.start],f=p.children[i.end];if(!m||!f)throw new y("missingOriginalChild",`original body children ${i.start}-${i.end}`);$.push(u.slice(m.start,f.end)),R+=i.end-i.start+1;continue}const d=e.id?
51
- S.get(e.id):void 0;if(!d)throw new y("missingGeneratedRange",`block ${e.id}`);for(let m=d.start;m<d.start+d.count;m++){const f=k[m];if(!f)throw new y("missingGeneratedSlot",`slot ${m}`);if(f.outerSdt){
52
- if(f.outerSdt.start===he)continue;he=f.outerSdt.start,C.push($.length),$.push(f.outerSdt.xml),R+=1;continue}C.push($.length),$.push(f.xml),R+=1}}const G=p.children.find(e=>e.tag==="w:sectPr");me&&X&&G&&
53
- G?($.push(u.slice(G.start,G.end)),R+=1):v&&(C.push($.length),$.push(v),R+=1);const pe=C.some(e=>$[e].includes("w:numId")),Ze=C.length>0,ye={notes:T,comments:Ne,chrome:X&&me,coreProps:We,styles:ze&&!Ze&&
54
- T&&X,settings:we,numbering:!pe},N=e=>{const i=fe(e);return i!==null&&ye[i]===!0},W="word/_rels/document.xml.rels",q=await c.file(W)?.async("string")??'<?xml version="1.0" encoding="UTF-8" standalone="\
55
- yes"?><Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"></Relationships>',xe=await l.file(W)?.async("string"),De=xe?D(xe):[],K=D(q),Q=new Set(K.map(e=>e.id)),Ge=C.map(
56
- e=>$[e]),Le=Me(Ge);let Y=Math.max(0,...K.map(e=>{const i=/^rId(\d+)$/.exec(e.id);return i?Number(i[1]):0}))+1;const be=new Map,L=[],_=new Map,ee=new Set(w),$e=e=>{const i=_.get(e);if(i)return i;let d=e;
57
- if(ee.has(d)){const m=e.lastIndexOf("/"),f=e.slice(0,m+1),h=e.slice(m+1);let E=1;do{const j=E===1?"rvseg_":`rvseg_${E}_`;d=`${f}${j}${h}`,E+=1}while(ee.has(d))}return ee.add(d),_.set(e,d),d};for(const e of De){
58
- const i=Le.has(e.id),d=K.some(h=>h.target===e.target&&!h.external);if(!i&&(d||e.external)||!i&&e.target.startsWith("media/"))continue;if(!i){const h=`word/${e.target}`.replace("word/../",""),E=fe(h);if(!E||
59
- ye[E])continue}if(!e.external&&N(`word/${e.target}`.replace("word/../","")))continue;let m=e.target;if(!e.external&&m.startsWith("media/")){const h=`word/${m}`;m=$e(h).replace(/^word\//,"")}let f=e.id;
60
- if(Q.has(e.id)){for(;Q.has(`rId${Y}`);)Y+=1;f=`rId${Y++}`}Q.add(f),f!==e.id&&be.set(e.id,f),L.push(V(V(e.raw,"Id",f),"Target",m))}for(const e of C)$[e]=at($[e],be);const Se=L.length?q.replace("</Relat\
61
- ionships>",`${L.join("")}</Relationships>`):q;let U;const ve=await l.file("word/numbering.xml")?.async("string"),M=await c.file("word/numbering.xml")?.async("string");if(pe&&ve&&M){const e=Math.max(de(
62
- M,/w:numId w:val="(\d+)"/g),de(M,/<w:num\b[^>]*w:numId="(\d+)"/g),de(M,/w:abstractNumId(?: w:val)?="(\d+)"/g))+100,i=ve.replace(/(<w:num\b[^>]*w:numId=")(\d+)(")/g,(f,h,E,j)=>`${h}${Number(E)+e}${j}`).
63
- replace(/(w:abstractNumId(?: w:val)?=")(\d+)(")/g,(f,h,E,j)=>`${h}${Number(E)+e}${j}`),d=Array.from(i.matchAll(/<w:abstractNum\b[\s\S]*?<\/w:abstractNum>/g),f=>f[0]),m=Array.from(i.matchAll(/<w:num\b[\s\S]*?<\/w:num>/g),
64
- f=>f[0]);if(d.length>0||m.length>0){const f=M.search(/<w:num\b/);let h=f>=0?M.slice(0,f)+d.join("")+M.slice(f):M.replace("</w:numbering>",`${d.join("")}</w:numbering>`);h=h.replace("</w:numbering>",`${m.
65
- join("")}</w:numbering>`),U=h;for(const E of C)$[E]=$[E].replace(/(<w:numId w:val=")(\d+)(")/g,(j,Ve,Je,Xe)=>`${Ve}${Number(Je)+e}${Xe}`)}}const F=we?void 0:ft(await c.file("word/settings.xml")?.async(
66
- "string"),await l.file("word/settings.xml")?.async("string")),te=new Set;for(const e of C){const i=$[e];for(const d of i.matchAll(/<([A-Za-z][A-Za-z0-9]*):/g))te.add(d[1]);for(const d of i.matchAll(/[\s"']([A-Za-z][A-Za-z0-9]*):[A-Za-z][A-Za-z0-9]*="/g))
67
- te.add(d[1])}const ne=ct(u,g,te),Ae=z(ne,"w:body"),re=ne.slice(0,Ae.contentStart)+$.join("")+ne.slice(Ae.contentEnd);let oe;try{oe=z(re,"w:body")}catch(e){throw new y("verifyReparseFailed",e instanceof
68
- Error?e.message:String(e))}if(oe.children.length!==R)throw new y("verifyChildCountMismatch",`composed body has ${oe.children.length} children, accounted ${R}`);const Ue=new Set(D(Se).map(e=>e.id));for(const e of Me(
69
- [re]))if(!Ue.has(e))throw new y("verifyRelsUnresolved",e);const A=new Oe,H=[],se=new Map;for(const e of Object.keys(l.files)){if(e===W||!e.endsWith(".rels")||!Pe(e)||N(e))continue;const i=l.file(e);if(!i)
70
- continue;let d=await i.async("string");for(const m of D(d)){if(m.external)continue;const f=Te(e,m.target);if(!f.startsWith("word/media/")||!l.file(f))continue;const h=$e(f).replace(/^word\//,"");d=d.replace(
71
- m.raw,V(m.raw,"Target",h))}se.set(e,d)}const Ee=new Set;for(const e of L){const i=B(e,"Target");i&&B(e,"TargetMode")!=="External"&&Ee.add(`word/${i}`.replace("word/../",""))}const Ie=e=>fe(e)!==null&&
72
- !N(e)||Ee.has(e)||_.has(e);l.forEach((e,i)=>{if(i.dir||w.has(e)||N(e))return;const d=/^(.*)\/_rels\/([^/]+)\.rels$/.exec(e),m=d?`${d[1]}/${d[2]}`:null;(Ie(e)||m!==null&&Ie(m))&&(_.has(e)||_.set(e,e))});
73
- const ie=new Set(_.values());F&&ie.add("word/settings.xml");for(const e of w)if(e!=="word/document.xml"&&e!==W&&e!=="[Content_Types].xml"&&!(e==="word/numbering.xml"&&U)&&!(e==="word/settings.xml"&&F)){
74
- if(!N(e)&&Pe(e)&&l.file(e)){ie.add(e);const i=se.get(e);i!==void 0?A.file(e,i):H.push(l.file(e).async("uint8array").then(d=>{A.file(e,d)}));continue}H.push(c.file(e).async("uint8array").then(i=>{A.file(
75
- e,i)}))}for(const[e,i]of _){const d=l.file(e);if(!d)continue;const m=se.get(e);if(m!==void 0){A.file(i,m);continue}H.push(d.async("uint8array").then(f=>{A.file(i,f)}))}await Promise.all(H),A.file("wor\
76
- d/document.xml",re),A.file(W,Se),U&&A.file("word/numbering.xml",U),F&&A.file("word/settings.xml",F);const ae=await c.file("[Content_Types].xml")?.async("string"),Be=await l.file("[Content_Types].xml")?.
77
- async("string");if(!ae)throw new y("missingContentTypes");const ke=Be?lt(ae,Be,ie):ae,Ce=Array.from(ke.matchAll(/<(?:Default|Override)\b[^>]*\/?>/g),e=>e[0]),Fe=new Set(Ce.map(e=>B(e,"Extension")?.toLowerCase()).
78
- filter(e=>!!e)),He=new Set(Ce.map(e=>B(e,"PartName")?.replace(/^\//,"")).filter(e=>!!e));for(const e of new Set(_.values())){const i=e.slice(e.lastIndexOf(".")+1).toLowerCase();if(!He.has(e)&&!Fe.has(
79
- i))throw new y("verifyContentTypeMissing",e)}A.file("[Content_Types].xml",ke);for(const e of Object.keys(A.files).filter(i=>i.endsWith(".rels"))){const i=A.file(e);if(!i)continue;const d=D(await i.async(
80
- "string")),m=new Set;for(const f of d){if(m.has(f.id))throw new y("verifyDuplicateRelationshipId",`${e}: ${f.id}`);if(m.add(f.id),f.external||f.target.startsWith("#"))continue;const h=Te(e,f.target);if(!A.
81
- file(h))throw new y("verifyRelationshipTargetMissing",`${e}: ${f.target}`)}}return A.generateAsync({type:"blob",compression:"DEFLATE",compressionOptions:{level:6}})}function ht(t){return t.children.filter(
82
- n=>n.type!=="footnote"&&n.type!=="header-footer")}export{y as G,je as a,wt as g};