revise 2.0.1 → 2.2.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 (147) hide show
  1. package/CHANGELOG.md +195 -0
  2. package/README.md +4 -1
  3. package/assets/historyMaterializeWorker-B51R08XN.js +612 -0
  4. package/backend.d.ts +8 -2
  5. package/backend.js +3 -1
  6. package/chunks/AgentPageRenderer-CH8kSTJn.js +1 -0
  7. package/chunks/AgentPageRenderer-P23XVguo.js +1 -0
  8. package/chunks/AttachmentDocumentImporter-B1WOaa7d.js +1 -0
  9. package/chunks/AttachmentDocumentImporter-CT_PJp_e.js +1 -0
  10. package/chunks/BidiText-Swm5fl9J.js +160 -0
  11. package/chunks/ColorParserFull-BKH72fK8.js +446 -1
  12. package/chunks/DocumentMutator-btiDK57e.js +31 -0
  13. package/chunks/DocumentScrubber-CMPfm_HF.js +18 -0
  14. package/chunks/{DocumentScrubber-DrgzBlx4.js → DocumentScrubber-Cm2kH8op.js} +1 -1
  15. package/chunks/{DocumentScrubber-W0EfGmL-.js → DocumentScrubber-bJoKijol.js} +1 -1
  16. package/chunks/DocumentStylesheet-DreoD7sD.js +7 -0
  17. package/chunks/DocxConverter-BcVG-p5K.js +13 -0
  18. package/chunks/DocxConverter-D2bO5RE-.js +1125 -0
  19. package/chunks/DocxConverter-haCfRuWb.js +13 -0
  20. package/chunks/{DocxGraft-B6W7fbh4.js → DocxGraft-BRKh4mHQ.js} +1 -1
  21. package/chunks/DocxGraft-BxSQtl12.js +7 -0
  22. package/chunks/{DocxGraft-Cj7v78BO.js → DocxGraft-C9MBQCnf.js} +1 -1
  23. package/chunks/FileImporter-CszqRfVU.js +1 -0
  24. package/chunks/FileImporter-DObFoCCn.js +1 -0
  25. package/chunks/HorizontalRuleOrnaments-gmUZ3R7Q.js +3 -1
  26. package/chunks/HtmlConverter-DwXB4IDh.js +267 -0
  27. package/chunks/ListNumbering-Qlu6AuRZ.js +23 -1
  28. package/chunks/MarkdownConverter-CUC8GgsS.js +57 -0
  29. package/chunks/MathRenderer-DT6GyJXb.js +68 -0
  30. package/chunks/OdtConverter-7h9HHMpL.js +125 -0
  31. package/chunks/OdtConverter-Ct4qypJk.js +6 -0
  32. package/chunks/OdtConverter-DFl__sJc.js +6 -0
  33. package/chunks/OfficeImportShared-BY6FdZ8d.js +1 -0
  34. package/chunks/OfficeImportShared-BrZoDM0j.js +30 -0
  35. package/chunks/OfficeImportShared-Bvm-mOyj.js +1 -0
  36. package/chunks/ParagraphDiffAnalysis-DrmStvmz.js +36 -0
  37. package/chunks/PdfConverter-1wyvoT7X.js +21 -0
  38. package/chunks/PdfConverter-BAoEHILo.js +21 -0
  39. package/chunks/PdfConverter-CKEvFj11.js +448 -0
  40. package/chunks/{PdfImportService-Dj1-3L2B.js → PdfImportService-BhLPp5uG.js} +2 -2
  41. package/chunks/{PdfImportService-OE9G383I.js → PdfImportService-xbzrN__L.js} +2 -2
  42. package/chunks/RtfConverter-Bxn-enp8.js +15 -0
  43. package/chunks/RtfConverter-LZPzBDSr.js +15 -0
  44. package/chunks/RtfConverter-_bacXqr1.js +186 -0
  45. package/chunks/TableBorders-CwnF3jvH.js +30 -0
  46. package/chunks/TableGrid-DbroRucl.js +12 -0
  47. package/chunks/TextFileDecoder--rsVs3NR.js +9 -2
  48. package/chunks/{TxtConverter-BYazsp6P.js → TxtConverter-C7FOwHpH.js} +5 -2
  49. package/chunks/UnicodeUtils-CXtusU4g.js +10 -0
  50. package/chunks/XmlConverter-7oo8oeQB.js +2 -0
  51. package/chunks/XmlConverter-DGORHJcZ.js +96 -0
  52. package/chunks/XmlConverter-DeLHReK_.js +2 -0
  53. package/chunks/_commonjsHelpers-DaMA6jEr.js +2 -1
  54. package/chunks/_revise-sdk-lazy-harfbuzz-CDWdjF9f.js +1 -1
  55. package/chunks/_revise-sdk-lazy-harfbuzz-X8gnYTZL.js +1 -1
  56. package/chunks/ar-ComXvtmh.js +13 -0
  57. package/chunks/backend-DecaBz-I.js +490 -0
  58. package/chunks/base64-sSPOzq-u.js +198 -0
  59. package/chunks/browser-module-CFmqfGkE.js +1791 -3
  60. package/chunks/{browser-module-BbaxnHNK.js → browser-module-Dj5o3kuL.js} +1 -1
  61. package/chunks/{browser-module-D2ixluMg.js → browser-module-UuM_O36W.js} +1 -1
  62. package/chunks/bundle.min-DRpfgV69.js +779 -5
  63. package/chunks/capture-1btcWcPF.js +9 -0
  64. package/chunks/carrier-DQeng6yq.js +6 -0
  65. package/chunks/de-BkbpIKxx.js +13 -0
  66. package/chunks/es-CKkXujOF.js +13 -0
  67. package/chunks/fil-piIHMc8F.js +13 -0
  68. package/chunks/footnoteFlatten-DUQticYy.js +6 -0
  69. package/chunks/fr-DuA8qLje.js +13 -0
  70. package/chunks/graftExport-CYnStOdU.js +82 -0
  71. package/chunks/html2canvas.esm-CntiHiYW.js +994 -2
  72. package/chunks/index-2TBhRkX7.js +387 -0
  73. package/chunks/index-BWdRWxoH.js +1796 -13
  74. package/chunks/index-Bf14eTEW.js +1096 -0
  75. package/chunks/index-BwcX_r62.js +387 -0
  76. package/chunks/index.es-CI0QPo8w.js +780 -5
  77. package/chunks/{index.es-B97tjxvW.js → index.es-CI7cDExj.js} +1 -1
  78. package/chunks/{index.es-mTU7Sl3w.js → index.es-DHpGt6Y5.js} +1 -1
  79. package/chunks/ja-DgrSs555.js +13 -0
  80. package/chunks/{jspdf.es.min-Mykp4BZO.js → jspdf.es.min--GshOuIm.js} +1 -1
  81. package/chunks/jspdf.es.min-DU74zN8b.js +1747 -32
  82. package/chunks/{jspdf.es.min-DGiD4mlU.js → jspdf.es.min-DurJZ1zW.js} +1 -1
  83. package/chunks/jszip.min-CPW0h1Kx.js +476 -2
  84. package/chunks/katex-DWj8TvwO.js +1209 -8
  85. package/chunks/pdf-BLWDCiFF.js +1826 -10
  86. package/chunks/pseudoLocale-BoYTjmiK.js +1 -0
  87. package/chunks/pseudoLocale-DG2NnZmz.js +1 -0
  88. package/chunks/purify.es-BwLardii.js +107 -2
  89. package/chunks/serverDocumentSession-CJ1EH3Tp.js +15 -0
  90. package/chunks/signatures-Bwt_OGik.js +17 -0
  91. package/chunks/suggestionAuthorship-B-IuLQlE.js +1 -0
  92. package/chunks/tree-sitter-D6zWWUMP.js +1 -1
  93. package/chunks/web-tree-sitter-BXGZGnNj.js +2 -1
  94. package/chunks/zh-9OF3SWWO.js +13 -0
  95. package/full.js +1 -1
  96. package/index.d.ts +42 -15
  97. package/index.js +1 -1
  98. package/package.json +1 -1
  99. package/root.js +2 -2
  100. package/serverToolContract.d.ts +21 -3
  101. package/serverToolInputs.generated.d.ts +23 -2
  102. package/style.css +1 -1
  103. package/assets/historyMaterializeWorker-C4uxcZEh.js +0 -3
  104. package/chunks/AgentPageRenderer-BIf_Fza8.js +0 -1
  105. package/chunks/AgentPageRenderer-DT9sNxEn.js +0 -1
  106. package/chunks/AttachmentDocumentImporter-BUavYRxO.js +0 -1
  107. package/chunks/AttachmentDocumentImporter-DGwfDJSH.js +0 -1
  108. package/chunks/BidiText-D7LYTAUL.js +0 -1
  109. package/chunks/DocumentMutator-CjN7Kk-X.js +0 -31
  110. package/chunks/DocumentScrubber-C9ZZEcYW.js +0 -1
  111. package/chunks/DocumentStylesheet-byN5dtC6.js +0 -1
  112. package/chunks/DocxConverter-Be3uPNcD.js +0 -11
  113. package/chunks/DocxConverter-CGYMfz-j.js +0 -11
  114. package/chunks/DocxConverter-DabDLfsu.js +0 -11
  115. package/chunks/DocxGraft-Duvo2cpy.js +0 -1
  116. package/chunks/FileImporter-CjUX2S4s.js +0 -1
  117. package/chunks/FileImporter-DtkbI6rF.js +0 -1
  118. package/chunks/HtmlConverter-ikXImzTY.js +0 -61
  119. package/chunks/MarkdownConverter-CFrcLyO_.js +0 -17
  120. package/chunks/MathRenderer-B0Y1h1JU.js +0 -33
  121. package/chunks/OdtConverter-BFT_P8SI.js +0 -1
  122. package/chunks/OdtConverter-Cnda9T0q.js +0 -1
  123. package/chunks/OdtConverter-WdwwXKVM.js +0 -1
  124. package/chunks/PdfConverter-D7UM58vc.js +0 -21
  125. package/chunks/PdfConverter-TB-QPw29.js +0 -21
  126. package/chunks/PdfConverter-wVP63986.js +0 -21
  127. package/chunks/RtfConverter-D-oqPWNl.js +0 -14
  128. package/chunks/RtfConverter-D9zhE07-.js +0 -14
  129. package/chunks/RtfConverter-DZgwU-_R.js +0 -14
  130. package/chunks/TableBorders-BorZS8aZ.js +0 -1
  131. package/chunks/TableGrid-DVWaRZv0.js +0 -1
  132. package/chunks/ar-C8zx2RwP.js +0 -8
  133. package/chunks/backend-MFpDFVrD.js +0 -1
  134. package/chunks/base64-BNMNG-lN.js +0 -1
  135. package/chunks/capture-qC26xmfy.js +0 -1
  136. package/chunks/carrier-BWONvrA7.js +0 -1
  137. package/chunks/de-ByQFqecF.js +0 -8
  138. package/chunks/es-PHpJXv5S.js +0 -8
  139. package/chunks/footnoteFlatten-Bdnn_bz1.js +0 -1
  140. package/chunks/graftExport-CP3h2T88.js +0 -2
  141. package/chunks/index-CjeGoI2g.js +0 -351
  142. package/chunks/index-D7V8zn4w.js +0 -36
  143. package/chunks/index-DyOcu9mD.js +0 -351
  144. package/chunks/pseudoLocale-C90lXrPg.js +0 -1
  145. package/chunks/pseudoLocale-UA_TkGrH.js +0 -1
  146. package/chunks/serverDocumentSession-CRZSb5SO.js +0 -11
  147. package/chunks/signatures-CsL_TjvW.js +0 -1
@@ -0,0 +1,2 @@
1
+ import{ca as ue,cb as ve,B as pe,I as Ee}from"./index-BwcX_r62.js";const ge=new WeakMap,R=r=>{let e=ge.get(r);return e===void 0&&(e=r.children.map(t=>t.text).join(""),ge.set(r,e)),e},P=r=>r.trim()?r.trim().split(/\s+/).length:0,me=new WeakMap,k=r=>{let e=me.get(r);if(e===void 0){const{id:t,children:n,...i}=r;e=JSON.stringify(i),me.set(r,e)}return e},G=(r={})=>Object.fromEntries(ve.filter(e=>r[e]!==void 0).map(e=>[e,r[e]])),Me=["comment","footnoteRef","footnotePendingBody","footnotePendingKind","oxmlRange","bookmark"],fe=r=>{const e={...r};for(const t of Me)delete e[t];return e};function Te(r){return{...r,children:r.children.map(e=>({...e,marks:G(e.marks)}))}}function be(r){return r.type==="paragraph"?`p${k(r)}${R(r)}`:r.type==="list"?`l${k(r)}${r.children.map(e=>k(e)+R(e)).join("\0")}`:JSON.stringify(r,(e,t)=>e==="id"?void 0:t)}function Ce(r){return r.type==="paragraph"||r.type==="list"||r.type==="table"}function re(r,e){const t=JSON.parse(JSON.stringify(r)),n=new Map,i=[],h=m=>{if(!m||typeof m!="object")return;const d=m;if(typeof d.type=="string"&&typeof d.id=="string"){const s=e();n.set(d.id,s),d.id=s}typeof d.docxTablePropertyOverrides=="string"&&i.push(d),Array.isArray(d.children)&&d.children.forEach(h)};h(t);for(const m of i)try{const d=JSON.parse(m.docxTablePropertyOverrides);for(const s of["rows","rowExceptions","cells"]){const u=d[s];!u||typeof u!="object"||Array.isArray(u)||(d[s]=Object.fromEntries(Object.entries(u).map(([c,p])=>[n.get(c)??c,p])))}m.docxTablePropertyOverrides=JSON.stringify(d)}catch{}return t}function se(r){const e=t=>{if(!t||typeof t!="object")return;const n=t;n.type==="text"&&n.marks&&(n.marks=fe(n.marks)),n.children?.forEach(e)};return e(r),r}const Z=new Map,Y=r=>{let e=Z.get(r);return e||(e=new Set(r.toLowerCase().match(/[\p{L}\p{N}]+/gu)??[]),Z.size>5e4&&Z.clear(),Z.set(r,e)),e};function ie(r,e){let t=0;for(const n of r)e.has(n)&&t++;return 2*t/(r.size+e.size||1)}function oe(r,e,t,n,i,h,m,d,s=()=>!1){const u=new Map,c=w=>{const I=t(w);return u.has(I)||u.set(I,`t${u.size}`),u.get(I)+" "},p=ue(r.map(c).join(""),e.map(c).join("")).diffs;let N=0,A=0,T=0,F=0;const v=()=>{const w=r.slice(T,N),I=e.slice(F,A);if(w.length===1&&I.length===1&&s(w[0],I[0])){h(w[0],I[0]);return}const j=w.map(q=>I.map(L=>n(q,L))),C=Array.from({length:w.length+1},()=>new Float64Array(I.length+1));for(let q=w.length-1;q>=0;q--)for(let L=I.length-1;L>=0;L--)C[q][L]=Math.max(C[q+1][L],C[q][L+1],j[q][L]+C[q+1][L+1]);let E=0,O=0;for(;E<w.length||O<I.length;)E<w.length&&O<I.length&&j[E][O]>0&&C[E][O]===j[E][O]+C[E+1][O+1]?h(w[E++],I[O++]):E<w.length&&(O===I.length||C[E+1][O]>=C[E][O+1])?m(w[E++]):d(I[O++])};for(const[w,I]of p){const j=I.trim().split(/\s+/).filter(Boolean).length;if(w===0){v();for(let C=0;C<j;C++)i(r[N++],e[A++]);T=N,F=A}else w===-1?N+=j:A+=j}v()}const ee=8e6,ye=1e6;function Oe(r,e,t){if(r.length*e.length>ee)return null;const{nextId:n,nextBlockId:i,label:h,authorName:m,authorOf:d,pairLoneChanges:s}=t,u=l=>s?l:()=>!1,c={inlineChanges:0,insertedBlocks:0,deletedBlocks:0,unmarkedBlocks:0,insertedWords:0,deletedWords:0},p=l=>d?.(l)??m,N=(l,o,a)=>{const y=p(a);return{[l]:!0,suggestionId:o,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:h,...y?{suggestionAuthorName:y}:{}}},A=(l,o)=>{if(!Ce(l))return null;const a=l.type==="paragraph"?l.children[0]?.marks:void 0,y=l.type==="paragraph"?Te(l):l,g=o==="delete"?se(re(y,i)):y,f=n(),S=p(a),b={id:f,blockId:g.id,source:"manual",authorType:"human",label:o==="insert"?"Insert":"Delete",...S?{agentName:S}:{}},x=o==="insert"?{...b,type:"block-insert"}:{...b,type:"block-delete",beforeBlock:g},M="children"in g&&g.type!=="table"?z(g):"";return o==="insert"?(c.insertedBlocks++,c.insertedWords+=P(M)):(c.deletedBlocks++,c.deletedWords+=P(M)),{...g,structuralSuggestionId:f,structuralSuggestionKind:o,structuralSuggestionRecord:JSON.stringify(x)}},T=(l,o,a)=>{const y=[];let g=0;for(const f of l.children){const S=Math.max(o-g,0),b=Math.min(o+a-g,f.text.length);if(b>S&&y.push({...f,text:f.text.slice(S,b)}),g+=f.text.length,g>=o+a)break}return y},F=(l,o,a)=>{const y=R(l),g=R(o);if(k(l)!==k(o)||P(y)*P(g)>ye){v(l,"delete",a),v(o,"insert",a);return}const f=[];let S=0,b=0,x="";const M=(J,B)=>{x||(x=n(),c.inlineChanges++);const D=P(J.map(X=>X.text).join(""));B==="insertion"?c.insertedWords+=D:c.deletedWords+=D,f.push(...J.map(X=>{const U=G(X.marks);return{...X,marks:{...B==="deletion"?fe(U):U,...N(B,x,X.marks)}}}))};for(const[J,B]of ue(y,g).diffs){if(J===-1)M(T(l,S,B.length),"deletion");else if(J===1)M(T(o,b,B.length),"insertion");else{const D=T(l,S,B.length),X=T(o,b,B.length);let U=0,_=0,K=0,H=0;for(;U<D.length&&_<X.length;){const Q=Math.min(D[U].text.length-K,X[_].text.length-H),he={...D[U],text:D[U].text.slice(K,K+Q)},V={...X[_],text:X[_].text.slice(H,H+Q)},{bookmark:We,...Se}=G(he.marks),{bookmark:Je,...Ie}=G(V.marks);JSON.stringify(Se)===JSON.stringify(Ie)?(x="",f.push({...V,marks:G(V.marks)})):(M([he],"deletion"),M([V],"insertion")),K+=Q,H+=Q,K===D[U].text.length&&(U++,K=0),H===X[_].text.length&&(_++,H=0)}}J!==1&&(S+=B.length),J!==-1&&(b+=B.length)}a.push({...o,children:f})},v=(l,o,a)=>{if(l.type==="table"){a.push(O(l,o));return}const y=A(l,o);y?a.push(y):(c.unmarkedBlocks++,o==="insert"&&a.push(l))},w=(l,o)=>{if(k(l)!==k(o))return 0;const a=ie(Y(R(l)),Y(R(o)));return a>=.5?a:0},I=(l,o,a)=>{const y=()=>{v(l,"delete",a),v(o,"insert",a)};if(l.children.length*o.children.length>ee)return y();const g=[];let f=!1;if(oe(l.children,o.children,b=>k(b)+R(b),w,(b,x)=>g.push([b,x]),(b,x)=>g.push([b,x]),()=>f=!0,()=>f=!0,u((b,x)=>k(b)===k(x))),f||g.some(([b,x])=>k(b)!==k(x)||P(R(b))*P(R(x))>ye))return y();const S=[];for(const[b,x]of g)F(b,x,S);a.push({...o,children:S})},j=(l,o)=>{const a=P(z(l));o==="insert"?(c.insertedBlocks++,c.insertedWords+=a):(c.deletedBlocks++,c.deletedWords+=a)},C=(l,o)=>o==="delete"?se(re(l,i)):l,E=(l,o,a,y)=>{const g=n();return{id:g,record:{id:g,type:"table-change",tableId:l,source:"manual",authorType:"human",label:y[a],...m?{agentName:m}:{},tableRevision:{version:1,suggestionKind:a,markers:o.map(([f,S])=>({kind:a==="insert"?"row-insert":"row-delete",rowId:f.id,rowIndex:S})),operations:o.map(([f,S])=>({kind:"row",action:a,rowId:f.id,rowIndex:S,row:JSON.parse(JSON.stringify(f))}))}}}},O=(l,o)=>{const a=o==="delete"?se(re(l,i)):l,{id:y,record:g}=E(a.id,a.children.map((f,S)=>[f,S]),o,{insert:"Insert table",delete:"Delete table"});return j(a,o),{...a,structuralSuggestionRecords:JSON.stringify([g]),children:a.children.map(f=>({...f,diffState:o,suggestionId:y}))}},q=(l,o)=>k(l)===k(o)&&l.children.length===o.children.length&&l.children.every((a,y)=>k(a)===k(o.children[y])),L=(l,o)=>l.children.every((a,y)=>a.children.length*o.children[y].children.length<=ee),ne=(l,o)=>q(l,o)&&L(l,o),ce=(l,o)=>({...o,children:o.children.map((a,y)=>({...a,children:de(l.children[y].children,a.children)}))}),we=(l,o,a)=>{if(k(l)!==k(o)||l.children.length*o.children.length>ee){v(l,"delete",a),v(o,"insert",a);return}const y=[],g=[],f=(b,x)=>{const M=C(b,x),{id:J,record:B}=E(o.id,[[M,y.length]],x,{insert:"Insert table row",delete:"Delete table row"});g.push(B),j(M,x),y.push({...M,diffState:x,suggestionId:J})},S=b=>be(b);oe(l.children,o.children,S,(b,x)=>{if(!ne(b,x))return 0;const M=ie(Y(z(b)),Y(z(x)));return M>=.5?M:0},(b,x)=>{ne(b,x)?y.push(ce(b,x)):(f(b,"delete"),f(x,"insert"))},(b,x)=>y.push(ce(b,x)),b=>f(b,"delete"),b=>f(b,"insert"),u(ne)),a.push({...o,children:y,...g.length>0?{structuralSuggestionRecords:JSON.stringify(g)}:{}})},Ae=(l,o)=>{if(l.type==="paragraph"&&o.type==="paragraph")return w(l,o);if(l.type==="list"&&o.type==="list"&&k(l)===k(o)||l.type==="table"&&o.type==="table"&&k(l)===k(o)){const a=ie(Y(z(l)),Y(z(o)));return a>=.3?a:0}return 0};function de(l,o){const a=[],y=(g,f)=>{g.type==="list"&&f.type==="list"?I(g,f,a):g.type==="table"&&f.type==="table"?we(g,f,a):g.type==="paragraph"&&f.type==="paragraph"?F(g,f,a):a.push(f)};return oe(l,o,be,Ae,y,y,g=>v(g,"delete",a),g=>v(g,"insert",a),u((g,f)=>g.type===f.type&&(g.type==="paragraph"||g.type==="list"||g.type==="table")&&k(g)===k(f))),a}return{blocks:de(r,e),stats:c}}const xe=new WeakMap;function z(r){const e=xe.get(r);if(e!==void 0)return e;const t=Be(r);return xe.set(r,t),t}function Be(r){return"children"in r&&Array.isArray(r.children)?r.children.map(e=>{const t=e;return t.type==="text"?t.text??"":z(e)}).join(" "):""}function qe(r,e,t){const n=(h,m)=>h.length>0&&h.every(d=>d.type==="paragraph"&&d.children.length>0&&d.children.every(s=>s.marks?.[m]&&!s.marks.layeredInsertion));if(!n(r,"deletion")||!n(e,"insertion"))return null;const i=Oe(r,e,{nextId:t,nextBlockId:pe,label:"Revise bill",authorOf:h=>h?.suggestionAuthorName});return i?i.blocks:null}const ke={division:0,title:0,subtitle:0,chapter:0,subchapter:0,part:0,subpart:0,section:0,subsection:1,paragraph:2,subparagraph:3,clause:4,subclause:5,item:6,subitem:7},Ne={division:"Division",title:"Title",subtitle:"Subtitle",chapter:"Chapter",subchapter:"Subchapter",part:"Part",subpart:"Subpart",section:"Sec."},le=new Set(["added-phrase","deleted-phrase","bold","italic","underline","strike","superscript","subscript","quote","term","short-title","act-name","external-xref","internal-xref","enum-in-header","header-in-text","definition","linebreak","nobreak","sponsor","cosponsor","committee-name","text-to-insert","text-to-strike-out","omitted-text","inline-comment"]),Le=new Set(["graphic","formula","footnote","footnote-ref","spanspec","entrytbl"]),$=r=>Array.from(r.children),W=(r,e)=>$(r).find(t=>t.localName===e),te=r=>r.replace(/[\t\r\n ]+/g," "),Xe={id:"us-congress-bill",label:"U.S. Congressional bills (bill.dtd)",matches(r){const e=r.documentElement;if(e.localName!=="bill"||e.namespaceURI||!W(e,"legis-body"))return!1;const t=r.doctype;if(t)return t.name==="bill"&&(t.publicId==="-//US Congress//DTDs/bill.dtd//EN"||!t.publicId&&/(?:^|\/)bill\.dtd$/i.test(t.systemId));const n=W(e,"form");return!!n&&!!W(n,"congress")&&!!W(n,"legis-num")},parse(r){return new je().parse(r)}};class je{constructor(){this.revisionCount=0,this.revisions=new WeakMap,this.committees=new Map,this.usedIds=new Set}id(){let e;do e=pe();while(this.usedIds.has(e));return this.usedIds.add(e),e}parse(e){const t=e.documentElement;for(const p of Array.from(t.getElementsByTagName("committee-name"))){const N=p.getAttribute("committee-id");N&&this.committees.set(N,te(p.textContent??"").trim())}for(const p of Array.from(t.getElementsByTagName("*")))if(Le.has(p.localName))throw new Error(`Unsupported Congressional XML element: <${p.localName}>. This bill requires content the XML importer does not yet support.`);const n=this.context(t,{marks:{},indent:0,quoted:0}),i=[],h=$(t),m=h.map(p=>this.blocks(p,n));for(let p=0;p<h.length;p++){const N=h[p],A=m[p],T=h[p+1];if(N.localName==="legis-body"&&T?.localName==="legis-body"&&T.getAttribute("display-enacting-clause")==="no-display-enacting-clause"){const F=m[p+1],v=N.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"?1:0,w=qe(A.slice(v),F,()=>`congressdiff-${++this.revisionCount}`);if(w){i.push(...A.slice(0,v),...w),p++;continue}}i.push(...A)}if(!i.length)throw new Error("The Congressional XML bill contains no readable content.");const d=W(t,"form"),s=d&&W(d,"legis-num")?.textContent?.trim(),u=t.getElementsByTagName("short-title")[0]?.textContent?.trim(),c=s?[s,u].filter(Boolean).join(" — "):e.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/","title")[0]?.textContent?.trim();return{type:"doc",children:i,...c?{title:c}:{}}}context(e,t){const n={...t.marks},i=e.localName,h=e.getAttribute("changed")??(i==="added-phrase"?"added":i==="deleted-phrase"?"deleted":null);if(h==="added"||h==="deleted"){const d=h==="added"?"insertion":"deletion",s=e.getAttribute("reporting-committee")||e.getAttribute("committee-id"),u=s?this.committees.get(s)??s:void 0;if(!n[d]||u&&u!==n.suggestionAuthorName){if(n.deletion&&d==="insertion")throw new Error("Unsupported Congressional XML revision: insertion nested inside a deletion.");let c=this.revisions.get(e);c||(c={[d]:!0,suggestionId:`congressrev-${++this.revisionCount}`,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:d==="insertion"?"Insert":"Delete",...u?{suggestionAuthorName:u}:{}},this.revisions.set(e,c)),n.insertion&&d==="deletion"&&(n.layeredInsertion=JSON.stringify({id:n.suggestionId,source:n.suggestionSource,authorType:n.suggestionAuthorType,authorName:n.suggestionAuthorName,label:n.suggestionLabel})),delete n.insertion,delete n.deletion,delete n.suggestionAuthorName,Object.assign(n,c)}}i==="bold"&&(n.bold=!0),i==="italic"&&(n.italic=!0),i==="underline"&&(n.underline=!0),i==="superscript"&&(n.superscript=!0),i==="subscript"&&(n.subscript=!0);const m=e.getAttribute("href");return m&&/^(https?:\/\/|#)/i.test(m.trim())&&(n.link=m.trim()),i==="internal-xref"&&e.getAttribute("idref")&&(n.link=`#${e.getAttribute("idref")}`),{...t,marks:n,style:e.getAttribute("style")??t.style}}text(e,t){return{type:"text",text:e,marks:{...t.marks}}}inline(e,t){const n=this.context(e,t);if(e.localName==="linebreak")return[this.text(`
2
+ `,n)];const i=[],h=e.localName==="quote"||e.localName==="term";h&&i.push(this.text(n.quoted?"‘":"“",n));for(const m of Array.from(e.childNodes))m.nodeType===3||m.nodeType===4?i.push(this.text(te(m.textContent??""),n)):m.nodeType===1&&i.push(...this.inline(m,h?{...n,quoted:n.quoted+1}:n));return h&&i.push(this.text(n.quoted?"’":"”",n)),i}paragraph(e,t,n,i){for(;e.length&&!e[0].text.trim();)e.shift();for(;e.length&&!e[e.length-1].text.trim();)e.pop();if(!e.length)return null;e[0].text=e[0].text.replace(/^ +/,""),e[e.length-1].text=e[e.length-1].text.replace(/ +$/,""),t.quoted&&e.unshift(this.text(t.quoted>1?"‘":"“",t));const h=n?.getAttribute("id");return h&&(e[0].marks={...e[0].marks,bookmark:h}),{type:"paragraph",id:this.id(),children:e,...i?{heading:i,keepNext:!0}:{},...t.indent?{leftIndent:Math.min(t.indent,6)}:{}}}blocks(e,t){const n=e.localName;if(n==="metadata")return[];const i=this.context(e,t);if(Object.prototype.hasOwnProperty.call(ke,n))return this.structure(e,{...i,indent:ke[n]+(i.quoted?1:0)});if(n==="table")return $(e).filter(s=>s.localName==="tgroup").length?$(e).flatMap(s=>s.localName==="tgroup"?[this.table(s,this.context(s,i))]:this.blocks(s,i)):[this.table(e,i)];if(n==="quoted-block"){const s=$(e).filter(p=>p.localName!=="after-quoted-block").flatMap(p=>this.blocks(p,{...i,quoted:i.quoted+1,indent:i.indent+1})),u=s[s.length-1],c=W(e,"after-quoted-block");if(u?.type==="paragraph")u.children.push(this.text(i.quoted?"’":"”",i)),c&&u.children.push(...this.inline(c,i));else if(c){const p=this.paragraph([this.text(i.quoted?"’":"”",i),...this.inline(c,i)],i);p&&s.push(p)}return s}if(!$(e).some(s=>!le.has(s.localName))){const s=this.paragraph(this.inline(e,t),i,e);if(s&&(n==="legis-num"||n==="legis-type")){s.align="center";for(const u of s.children)u.marks={...u.marks,bold:!0}}return s?[s]:[]}const h=[];if(n==="legis-body"&&e.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"){const s=this.paragraph([this.text("Be it enacted by the Senate and House of Representatives of the United States of America in Congress assembled,",i)],i);s&&h.push(s)}let m=[];const d=()=>{const s=this.paragraph(m,i);s&&h.push(s),m=[]};for(const s of Array.from(e.childNodes))if(s.nodeType===3||s.nodeType===4)m.push(this.text(te(s.textContent??""),i));else if(s.nodeType===1){const u=s;le.has(u.localName)?m.push(...this.inline(u,i)):(d(),h.push(...this.blocks(u,i)))}return d(),h}structure(e,t){const n=[],i=Object.prototype.hasOwnProperty.call(Ne,e.localName),h=W(e,"enum"),m=W(e,"header");let d=[];if(h&&(i&&d.push(this.text(e.localName==="section"&&t.style==="USC"?"§ ":`${Ne[e.localName]} `,t)),d.push(...this.inline(h,t),this.text(" ",t))),m){const c=this.inline(m,t);for(const p of c)p.marks={...p.marks,bold:!0};d.push(...c)}const s=(c=!1)=>{const p=this.paragraph(d,t,n.length?void 0:e,c?e.localName==="section"?2:1:void 0);p&&n.push(p),d=[]};i&&s(!0);let u=!0;for(const c of Array.from(e.childNodes))if(!(c===h||c===m)){if(c.nodeType===3||c.nodeType===4)c.textContent?.trim()&&d.push(this.text(te(c.textContent),t));else if(c.nodeType===1){const p=c;if(p.localName==="text")u||s(),u&&!i&&m&&d.push(this.text(".—",t)),d.push(...this.inline(p,t)),u=!1;else if(le.has(p.localName))d.push(...this.inline(p,t));else{s();const N=this.blocks(p,t),A=n[n.length-1];p.getAttribute("display-inline")==="yes-display-inline"&&A?.type==="paragraph"&&!A.heading&&N[0]?.type==="paragraph"&&(A.children.push(this.text(" ",t),...N[0].children),N.shift()),n.push(...N)}}}return s(),n}table(e,t){const n=W(e,"tgroup")??e,i=new Map($(n).filter(s=>s.localName==="colspec").map((s,u)=>[s.getAttribute("colname"),Number(s.getAttribute("colnum"))||u+1])),h=$(n).flatMap(s=>s.localName==="row"?[s]:["thead","tbody","tfoot"].includes(s.localName)?$(s).filter(u=>u.localName==="row"):[]);if(!h.length)throw new Error("Unsupported Congressional XML table: no rows.");const m={type:"table",id:this.id(),columnWidths:[],children:h.map(s=>({type:"table-row",id:this.id(),children:$(s).filter(u=>u.localName==="entry").map(u=>{const c=i.get(u.getAttribute("namest")),p=i.get(u.getAttribute("nameend")),N=c&&p?p-c+1:1,A=Number(u.getAttribute("morerows")??0)+1;if(u.hasAttribute("namest")&&(!c||!p)||!Number.isInteger(N)||N<1||N>100||!Number.isInteger(A)||A<1||A>h.length)throw new Error("Unsupported Congressional XML table: invalid cell span.");const T=this.blocks(u,{...this.context(s,s.parentElement&&s.parentElement!==n?this.context(s.parentElement,t):t),indent:0});return{type:"table-cell",id:this.id(),children:T.length?T:[{type:"paragraph",id:this.id(),children:[{type:"text",text:""}]}],...N>1?{colSpan:N}:{},...A>1?{rowSpan:A}:{}}})}))},d=Ee(m).cols;if(!d||d>100)throw new Error("Unsupported Congressional XML table: invalid column count.");return m.columnWidths=Array(d).fill(100/d),m}}const ae=[Xe];class $e{static async parseFile(e){return this.fromBytes(new Uint8Array(await e.arrayBuffer()))}static fromBytes(e){let t="utf-8";if(e[0]===255&&e[1]===254||e[0]===60&&e[1]===0&&e[2]===63&&e[3]===0)t="utf-16le";else if(e[0]===254&&e[1]===255||e[0]===0&&e[1]===60&&e[2]===0&&e[3]===63)t="utf-16be";else if(!(e[0]===239&&e[1]===187&&e[2]===191)){const i=new TextDecoder("windows-1252").decode(e.subarray(0,512));t=/^<\?xml\s[^?]*\bencoding\s*=\s*["']([^"']+)["']/i.exec(i)?.[1]??t}let n;try{n=new TextDecoder(t,{fatal:!0}).decode(e)}catch{throw new Error(`Invalid or unsupported XML encoding: ${t}.`)}return this.fromXml(n)}static fromXml(e){if(/<!ENTITY\s/i.test(e))throw new Error("XML entity declarations are not supported.");const t=new DOMParser().parseFromString(e.replace(/^\uFEFF/,""),"application/xml");if(!t.documentElement||t.getElementsByTagName("parsererror").length)throw new Error("Invalid XML: the document is not well-formed.");const n=[[t.documentElement,0]];for(;n.length;){const[h,m]=n.pop();if(m>128)throw new Error("XML nesting exceeds the supported depth (128).");for(const d of Array.from(h.children))n.push([d,m+1])}const i=ae.find(h=>h.matches(t));if(!i)throw new Error(`Unsupported XML schema: <${t.documentElement.tagName}>. Supported: ${ae.map(h=>h.label).join(", ")}.`);return i.parse(t)}}export{ae as XML_SCHEMA_PARSERS,$e as XmlConverter};
@@ -1 +1,2 @@
1
- var l=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function t(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}export{l as c,t as g};
1
+ var l=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function t(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?
2
+ o.default:o}export{l as c,t as g};