revise 3.1.7 → 4.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 (91) hide show
  1. package/CHANGELOG.md +1671 -184
  2. package/FONT-LICENSE-HAN-EXT-B.txt +91 -0
  3. package/FONT-LICENSE-KATEX.txt +95 -0
  4. package/FONT-LICENSE-LIBERATION.txt +102 -0
  5. package/FONT-LICENSE-NOTO-MULTILINGUAL.txt +93 -0
  6. package/FONT-LICENSE-NOTO-SANS-SC.txt +93 -0
  7. package/FONT-LICENSE-NOTO.txt +94 -0
  8. package/FONT-LICENSE-SOURCE-CODE-PRO.txt +94 -0
  9. package/FONT-LICENSE-SOURCE-SERIF-4.txt +93 -0
  10. package/LICENSE +41 -21
  11. package/README.md +32 -119
  12. package/THIRD-PARTY-NOTICES.md +2751 -0
  13. package/assets/historyMaterializeWorker-ZFUHJDWr.js +619 -0
  14. package/chunks/AgentPageRenderer-5mZ6fxqO.js +1 -0
  15. package/chunks/AgentPageRenderer-C3jIBoeM.js +1 -0
  16. package/chunks/AttachmentDocumentImporter-CXkM4VoT.js +1 -0
  17. package/chunks/AttachmentDocumentImporter-Kox5By7a.js +1 -0
  18. package/chunks/ColorParserFull-BKH72fK8.js +446 -0
  19. package/chunks/DocumentScrubber-BxmlzNNz.js +1 -0
  20. package/chunks/DocumentScrubber-wmjRnX7C.js +1 -0
  21. package/chunks/DocxConverter-BH3E7nfQ.js +13 -0
  22. package/chunks/DocxConverter-DEHGCdib.js +13 -0
  23. package/chunks/DocxGraft-BMvTAnGi.js +1 -0
  24. package/chunks/DocxGraft-V2YXiUmK.js +1 -0
  25. package/chunks/FileImporter-CtX8ZPjV.js +1 -0
  26. package/chunks/FileImporter-Da-7eRh3.js +1 -0
  27. package/chunks/OdtConverter-CMkSeU8e.js +6 -0
  28. package/chunks/OdtConverter-DV94rkDL.js +6 -0
  29. package/chunks/OfficeImportShared-CA3dia_A.js +1 -0
  30. package/chunks/OfficeImportShared-hxIa69By.js +1 -0
  31. package/chunks/PdfConverter-B-uRwLux.js +21 -0
  32. package/chunks/PdfConverter-B8J_5yim.js +21 -0
  33. package/chunks/PdfImportService-BjQ4rl-Z.js +2 -0
  34. package/chunks/PdfImportService-RtFCP6hh.js +2 -0
  35. package/chunks/RtfConverter-CFDnUApT.js +15 -0
  36. package/chunks/RtfConverter-CpJGtC5U.js +15 -0
  37. package/chunks/XmlConverter-CQCrgTf7.js +2 -0
  38. package/chunks/XmlConverter-CePTE21k.js +2 -0
  39. package/chunks/__vite-browser-external-l0sNRNKZ.js +0 -0
  40. package/chunks/_revise-sdk-lazy-harfbuzz-X8gnYTZL.js +1 -0
  41. package/chunks/ar-vDYSGTpE.js +13 -0
  42. package/chunks/browser-module-B-uafDG6.js +3 -0
  43. package/chunks/browser-module-jwkhffzv.js +3 -0
  44. package/chunks/bundle.min-DRpfgV69.js +782 -0
  45. package/chunks/de-CWX4cvtt.js +13 -0
  46. package/chunks/es-DoAhvF6_.js +13 -0
  47. package/chunks/fil-DdAeD8Br.js +13 -0
  48. package/chunks/fr-CazsUjNQ.js +13 -0
  49. package/chunks/html2canvas.esm-CntiHiYW.js +997 -0
  50. package/chunks/index-BWdRWxoH.js +1807 -0
  51. package/chunks/index-C7VhCKXe.js +402 -0
  52. package/chunks/index-p6UytRm8.js +402 -0
  53. package/chunks/ja-alh_QHTB.js +13 -0
  54. package/chunks/jspdf.es.min-BuJNZ-oY.js +1882 -0
  55. package/chunks/katex-DWj8TvwO.js +1462 -0
  56. package/chunks/pdf-BLWDCiFF.js +1828 -0
  57. package/chunks/persistInlineDocumentImages-DQj2iaqg.js +1 -0
  58. package/chunks/pseudoLocale-Bkzfsfiw.js +1 -0
  59. package/chunks/pseudoLocale-D-AfwRwa.js +1 -0
  60. package/chunks/tree-sitter-D6zWWUMP.js +4 -0
  61. package/chunks/wasmInline.generated-CBYFkdSM.js +1 -0
  62. package/chunks/web-tree-sitter-BXGZGnNj.js +2 -0
  63. package/chunks/zh-20eXwzFZ.js +13 -0
  64. package/cli-shim.js +34 -0
  65. package/full.js +1 -0
  66. package/index.d.ts +995 -13
  67. package/index.js +1 -31
  68. package/legacy/server.d.ts +19 -19
  69. package/legacy/server.js +39 -23
  70. package/package.json +55 -45
  71. package/serverToolContract.d.ts +420 -0
  72. package/serverToolInputs.generated.d.ts +269 -0
  73. package/style.css +1 -0
  74. package/version.d.ts +4 -0
  75. package/version.js +2 -0
  76. package/agent.d.ts +0 -139
  77. package/chunks/chunk-SMTOJL2X.js +0 -2436
  78. package/chunks/chunk-U5X47PZ6.js +0 -135
  79. package/chunks/chunk-U6YKQBKL.js +0 -15
  80. package/chunks/package-5SHL5FOJ.js +0 -14
  81. package/chunks/render-QD5VWKSV.js +0 -109
  82. package/cli-output.schema.json +0 -2159
  83. package/cli.js +0 -4152
  84. package/document.d.ts +0 -439
  85. package/docx.d.ts +0 -73
  86. package/errors.d.ts +0 -14
  87. package/legacy/editor.d.ts +0 -19
  88. package/legacy/editor.js +0 -16
  89. package/legacy/style.css +0 -2
  90. package/package.d.ts +0 -23
  91. package/render.d.ts +0 -27
@@ -0,0 +1,2 @@
1
+ import{ck as ue,cl as Oe,H as pe,L as Te,ah as ge}from"./index-C7VhCKXe.js";const me=new WeakMap,P=n=>{let e=me.get(n);return e===void 0&&(e=n.children.map(t=>t.text).join(""),me.set(n,e)),e},F=n=>n.trim()?n.trim().split(/\s+/).length:0,Ce=/^(?:w14:paraId|w14:textId|w:rsid\w*)$/;function Be(n){if(typeof n!="string")return n;try{const e=Object.entries(JSON.parse(n)).filter(([t])=>!Ce.test(t)).sort(([t],[r])=>t.localeCompare(r));return e.length?JSON.stringify(Object.fromEntries(e)):void 0}catch{return n}}const fe=new WeakMap,w=n=>{let e=fe.get(n);if(e===void 0){const{id:t,children:r,oxmlAttrs:i,...d}=n,u=Be(i);e=JSON.stringify(u===void 0?d:{...d,oxmlAttrs:u}),fe.set(n,e)}return e},Le=n=>typeof n=="string"?n.split(",")[0].replace(/['"]/g,"").trim().toLowerCase():n,be=(n,e)=>JSON.stringify(Object.entries(n).filter(([t,r])=>!(t==="fontSize"&&r===e)).map(([t,r])=>[t,t==="fontFamily"?Le(r):r]).sort(([t],[r])=>String(t).localeCompare(String(r)))),G=(n={})=>Object.fromEntries(Oe.filter(e=>n[e]!==void 0).map(e=>[e,n[e]])),je=["comment","footnoteRef","footnotePendingBody","footnotePendingKind","oxmlRange","bookmark"],ye=n=>{const e={...n};for(const t of je)delete e[t];return e};function qe(n){return{...n,children:n.children.map(e=>({...e,marks:G(e.marks)}))}}function xe(n){return n.type==="paragraph"?`p${w(n)}${P(n)}`:n.type==="list"?`l${w(n)}${n.children.map(e=>w(e)+P(e)).join("\0")}`:JSON.stringify(n,(e,t)=>e==="id"?void 0:t)}function Xe(n){return n.type==="paragraph"||n.type==="list"||n.type==="table"}function ne(n,e){const t=JSON.parse(JSON.stringify(n)),r=new Map,i=[],d=u=>{if(!u||typeof u!="object")return;const h=u;if(typeof h.type=="string"&&typeof h.id=="string"){const s=e();r.set(h.id,s),h.id=s}typeof h.docxTablePropertyOverrides=="string"&&i.push(h),Array.isArray(h.children)&&h.children.forEach(d)};d(t);for(const u of i)try{const h=JSON.parse(u.docxTablePropertyOverrides);for(const s of["rows","rowExceptions","cells"]){const p=h[s];!p||typeof p!="object"||Array.isArray(p)||(h[s]=Object.fromEntries(Object.entries(p).map(([m,a])=>[r.get(m)??m,a])))}u.docxTablePropertyOverrides=JSON.stringify(h)}catch{}return t}function se(n){const e=t=>{if(!t||typeof t!="object")return;const r=t;r.type==="text"&&r.marks&&(r.marks=ye(r.marks)),r.children?.forEach(e)};return e(n),n}const Z=new Map,Y=n=>{let e=Z.get(n);return e||(e=new Set(n.toLowerCase().match(/[\p{L}\p{N}]+/gu)??[]),Z.size>5e4&&Z.clear(),Z.set(n,e)),e};function ie(n,e){let t=0;for(const r of n)e.has(r)&&t++;return 2*t/(n.size+e.size||1)}function oe(n,e,t,r,i,d,u,h,s=()=>!1){const p=new Map,m=k=>{const A=t(k);return p.has(A)||p.set(A,`t${p.size}`),p.get(A)+" "},a=ue(n.map(m).join(""),e.map(m).join("")).diffs;let N=0,S=0,j=0,$=0;const R=()=>{const k=n.slice(j,N),A=e.slice($,S);if(k.length===1&&A.length===1&&s(k[0],A[0])){d(k[0],A[0]);return}const J=k.map(C=>A.map(B=>r(C,B))),E=Array.from({length:k.length+1},()=>new Float64Array(A.length+1));for(let C=k.length-1;C>=0;C--)for(let B=A.length-1;B>=0;B--)E[C][B]=Math.max(E[C+1][B],E[C][B+1],J[C][B]+E[C+1][B+1]);let O=0,I=0;for(;O<k.length||I<A.length;)O<k.length&&I<A.length&&J[O][I]>0&&E[O][I]===J[O][I]+E[O+1][I+1]?d(k[O++],A[I++]):O<k.length&&(I===A.length||E[O+1][I]>=E[O][I+1])?u(k[O++]):h(A[I++])};for(const[k,A]of a){const J=A.trim().split(/\s+/).filter(Boolean).length;if(k===0){R();for(let E=0;E<J;E++)i(n[N++],e[S++]);j=N,$=S}else k===-1?N+=J:S+=J}R()}const ee=8e6,ke=1e6;function $e(n,e,t){if(n.length*e.length>ee)return null;const{nextId:r,nextBlockId:i,label:d,authorName:u,authorOf:h,pairLoneChanges:s,defaultFontSize:p}=t,m=l=>s?l:()=>!1,a={inlineChanges:0,insertedBlocks:0,deletedBlocks:0,unmarkedBlocks:0,insertedWords:0,deletedWords:0},N=l=>h?.(l)??u,S=(l,o,c)=>{const y=N(c);return{[l]:!0,suggestionId:o,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:d,...y?{suggestionAuthorName:y}:{}}},j=(l,o)=>{if(!Xe(l))return null;const c=l.type==="paragraph"?l.children[0]?.marks:void 0,y=l.type==="paragraph"?qe(l):l,g=o==="delete"?se(ne(y,i)):y,f=r(),v=N(c),b={id:f,blockId:g.id,source:"manual",authorType:"human",label:o==="insert"?"Insert":"Delete",...v?{agentName:v}:{}},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"?(a.insertedBlocks++,a.insertedWords+=F(M)):(a.deletedBlocks++,a.deletedWords+=F(M)),{...g,structuralSuggestionId:f,structuralSuggestionKind:o,structuralSuggestionRecord:JSON.stringify(x)}},$=(l,o,c)=>{const y=[];let g=0;for(const f of l.children){const v=Math.max(o-g,0),b=Math.min(o+c-g,f.text.length);if(b>v&&y.push({...f,text:f.text.slice(v,b)}),g+=f.text.length,g>=o+c)break}return y},R=(l,o,c)=>{const y=P(l),g=P(o);if(w(l)!==w(o)||F(y)*F(g)>ke){k(l,"delete",c),k(o,"insert",c);return}const f=[];let v=0,b=0,x="";const M=(W,T)=>{x||(x=r(),a.inlineChanges++);const D=F(W.map(L=>L.text).join(""));T==="insertion"?a.insertedWords+=D:a.deletedWords+=D,f.push(...W.map(L=>{const U=G(L.marks);return{...L,marks:{...T==="deletion"?ye(U):U,...S(T,x,L.marks)}}}))};for(const[W,T]of ue(y,g).diffs){if(W===-1)M($(l,v,T.length),"deletion");else if(W===1)M($(o,b,T.length),"insertion");else{const D=$(l,v,T.length),L=$(o,b,T.length);let U=0,H=0,K=0,_=0;for(;U<D.length&&H<L.length;){const Q=Math.min(D[U].text.length-K,L[H].text.length-_),he={...D[U],text:D[U].text.slice(K,K+Q)},V={...L[H],text:L[H].text.slice(_,_+Q)},{bookmark:Fe,...Ie}=G(he.marks),{bookmark:ze,...Me}=G(V.marks);be(Ie,p)===be(Me,p)?(x="",f.push({...V,marks:G(V.marks)})):(M([he],"deletion"),M([V],"insertion")),K+=Q,_+=Q,K===D[U].text.length&&(U++,K=0),_===L[H].text.length&&(H++,_=0)}}W!==1&&(v+=T.length),W!==-1&&(b+=T.length)}c.push({...o,children:f})},k=(l,o,c)=>{if(l.type==="table"){c.push(C(l,o));return}const y=j(l,o);y?c.push(y):(a.unmarkedBlocks++,o==="insert"&&c.push(l))},A=(l,o)=>{if(w(l)!==w(o))return 0;const c=ie(Y(P(l)),Y(P(o)));return c>=.5?c:0},J=(l,o,c)=>{const y=()=>{k(l,"delete",c),k(o,"insert",c)};if(l.children.length*o.children.length>ee)return y();const g=[];let f=!1;if(oe(l.children,o.children,b=>w(b)+P(b),A,(b,x)=>g.push([b,x]),(b,x)=>g.push([b,x]),()=>f=!0,()=>f=!0,m((b,x)=>w(b)===w(x))),f||g.some(([b,x])=>w(b)!==w(x)||F(P(b))*F(P(x))>ke))return y();const v=[];for(const[b,x]of g)R(b,x,v);c.push({...o,children:v})},E=(l,o)=>{const c=F(z(l));o==="insert"?(a.insertedBlocks++,a.insertedWords+=c):(a.deletedBlocks++,a.deletedWords+=c)},O=(l,o)=>o==="delete"?se(ne(l,i)):l,I=(l,o,c,y)=>{const g=r();return{id:g,record:{id:g,type:"table-change",tableId:l,source:"manual",authorType:"human",label:y[c],...u?{agentName:u}:{},tableRevision:{version:1,suggestionKind:c,markers:o.map(([f,v])=>({kind:c==="insert"?"row-insert":"row-delete",rowId:f.id,rowIndex:v})),operations:o.map(([f,v])=>({kind:"row",action:c,rowId:f.id,rowIndex:v,row:JSON.parse(JSON.stringify(f))}))}}}},C=(l,o)=>{const c=o==="delete"?se(ne(l,i)):l,{id:y,record:g}=I(c.id,c.children.map((f,v)=>[f,v]),o,{insert:"Insert table",delete:"Delete table"});return E(c,o),{...c,structuralSuggestionRecords:JSON.stringify([g]),children:c.children.map(f=>({...f,diffState:o,suggestionId:y}))}},B=(l,o)=>w(l)===w(o)&&l.children.length===o.children.length&&l.children.every((c,y)=>w(c)===w(o.children[y])),Ae=(l,o)=>l.children.every((c,y)=>c.children.length*o.children[y].children.length<=ee),re=(l,o)=>B(l,o)&&Ae(l,o),ce=(l,o)=>({...o,children:o.children.map((c,y)=>({...c,children:de(l.children[y].children,c.children)}))}),ve=(l,o,c)=>{if(w(l)!==w(o)||l.children.length*o.children.length>ee){k(l,"delete",c),k(o,"insert",c);return}const y=[],g=[],f=(b,x)=>{const M=O(b,x),{id:W,record:T}=I(o.id,[[M,y.length]],x,{insert:"Insert table row",delete:"Delete table row"});g.push(T),E(M,x),y.push({...M,diffState:x,suggestionId:W})},v=b=>xe(b);oe(l.children,o.children,v,(b,x)=>{if(!re(b,x))return 0;const M=ie(Y(z(b)),Y(z(x)));return M>=.5?M:0},(b,x)=>{re(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"),m(re)),c.push({...o,children:y,...g.length>0?{structuralSuggestionRecords:JSON.stringify(g)}:{}})},Ee=(l,o)=>{if(l.type==="paragraph"&&o.type==="paragraph")return A(l,o);if(l.type==="list"&&o.type==="list"&&w(l)===w(o)||l.type==="table"&&o.type==="table"&&w(l)===w(o)){const c=ie(Y(z(l)),Y(z(o)));return c>=.3?c:0}return 0};function de(l,o){const c=[],y=(g,f)=>{g.type==="list"&&f.type==="list"?J(g,f,c):g.type==="table"&&f.type==="table"?ve(g,f,c):g.type==="paragraph"&&f.type==="paragraph"?R(g,f,c):c.push(f)};return oe(l,o,xe,Ee,y,y,g=>k(g,"delete",c),g=>k(g,"insert",c),m((g,f)=>g.type===f.type&&(g.type==="paragraph"||g.type==="list"||g.type==="table")&&w(g)===w(f))),c}return{blocks:de(n,e),stats:a}}const Ne=new WeakMap;function z(n){const e=Ne.get(n);if(e!==void 0)return e;const t=Je(n);return Ne.set(n,t),t}function Je(n){return"children"in n&&Array.isArray(n.children)?n.children.map(e=>{const t=e;return t.type==="text"?t.text??"":z(e)}).join(" "):""}function We(n,e,t){const r=(d,u)=>d.length>0&&d.every(h=>h.type==="paragraph"&&h.children.length>0&&h.children.every(s=>s.marks?.[u]&&!s.marks.layeredInsertion));if(!r(n,"deletion")||!r(e,"insertion"))return null;const i=$e(n,e,{nextId:t,nextBlockId:pe,label:"Revise bill",authorOf:d=>d?.suggestionAuthorName});return i?i.blocks:null}const we={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},Se={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"]),Ue=new Set(["graphic","formula","footnote","footnote-ref","spanspec","entrytbl"]),q=n=>Array.from(n.children),X=(n,e)=>q(n).find(t=>t.localName===e),te=n=>n.replace(/[\t\r\n ]+/g," "),Pe={id:"us-congress-bill",label:"U.S. Congressional bills (bill.dtd)",matches(n){const e=n.documentElement;if(e.localName!=="bill"||e.namespaceURI||!X(e,"legis-body"))return!1;const t=n.doctype;if(t)return t.name==="bill"&&(t.publicId==="-//US Congress//DTDs/bill.dtd//EN"||!t.publicId&&/(?:^|\/)bill\.dtd$/i.test(t.systemId));const r=X(e,"form");return!!r&&!!X(r,"congress")&&!!X(r,"legis-num")},parse(n){return new Re().parse(n)}};class Re{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 a of Array.from(t.getElementsByTagName("committee-name"))){const N=a.getAttribute("committee-id");N&&this.committees.set(N,te(a.textContent??"").trim())}for(const a of Array.from(t.getElementsByTagName("*")))if(Ue.has(a.localName))throw new Error(`Unsupported Congressional XML element: <${a.localName}>. This bill requires content the XML importer does not yet support.`);const r=this.context(t,{marks:{},indent:0,quoted:0}),i=[],d=q(t),u=d.map(a=>this.blocks(a,r));for(let a=0;a<d.length;a++){const N=d[a],S=u[a],j=d[a+1];if(N.localName==="legis-body"&&j?.localName==="legis-body"&&j.getAttribute("display-enacting-clause")==="no-display-enacting-clause"){const $=u[a+1],R=N.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"?1:0,k=We(S.slice(R),$,()=>`congressdiff-${++this.revisionCount}`);if(k){i.push(...S.slice(0,R),...k),a++;continue}}i.push(...S)}if(!i.length)throw new Error("The Congressional XML bill contains no readable content.");const h=X(t,"form"),s=h&&X(h,"legis-num")?.textContent?.trim(),p=t.getElementsByTagName("short-title")[0]?.textContent?.trim(),m=s?[s,p].filter(Boolean).join(" — "):e.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/","title")[0]?.textContent?.trim();return{type:"doc",children:i,...m?{title:m}:{}}}context(e,t){const r={...t.marks},i=e.localName,d=e.getAttribute("changed")??(i==="added-phrase"?"added":i==="deleted-phrase"?"deleted":null);if(d==="added"||d==="deleted"){const h=d==="added"?"insertion":"deletion",s=e.getAttribute("reporting-committee")||e.getAttribute("committee-id"),p=s?this.committees.get(s)??s:void 0;if(!r[h]||p&&p!==r.suggestionAuthorName){if(r.deletion&&h==="insertion")throw new Error("Unsupported Congressional XML revision: insertion nested inside a deletion.");let m=this.revisions.get(e);m||(m={[h]:!0,suggestionId:`congressrev-${++this.revisionCount}`,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:h==="insertion"?"Insert":"Delete",...p?{suggestionAuthorName:p}:{}},this.revisions.set(e,m)),r.insertion&&h==="deletion"&&(r.layeredInsertion=JSON.stringify({id:r.suggestionId,source:r.suggestionSource,authorType:r.suggestionAuthorType,authorName:r.suggestionAuthorName,label:r.suggestionLabel})),delete r.insertion,delete r.deletion,delete r.suggestionAuthorName,Object.assign(r,m)}}i==="bold"&&(r.bold=!0),i==="italic"&&(r.italic=!0),i==="underline"&&(r.underline=!0),i==="superscript"&&(r.superscript=!0),i==="subscript"&&(r.subscript=!0);const u=e.getAttribute("href");return u&&/^(https?:\/\/|#)/i.test(u.trim())&&(r.link=u.trim()),i==="internal-xref"&&e.getAttribute("idref")&&(r.link=`#${e.getAttribute("idref")}`),{...t,marks:r,style:e.getAttribute("style")??t.style}}text(e,t){return{type:"text",text:e,marks:{...t.marks}}}inline(e,t){const r=this.context(e,t);if(e.localName==="linebreak")return[this.text(`
2
+ `,r)];const i=[],d=e.localName==="quote"||e.localName==="term";d&&i.push(this.text(r.quoted?"‘":"“",r));for(const u of Array.from(e.childNodes))u.nodeType===3||u.nodeType===4?i.push(this.text(te(u.textContent??""),r)):u.nodeType===1&&i.push(...this.inline(u,d?{...r,quoted:r.quoted+1}:r));return d&&i.push(this.text(r.quoted?"’":"”",r)),i}paragraph(e,t,r,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 d=r?.getAttribute("id");return d&&(e[0].marks={...e[0].marks,bookmark:d}),{type:"paragraph",id:this.id(),children:e,...i?{heading:i,keepNext:!0}:{},...t.indent?{leftIndent:Math.min(t.indent,6)}:{}}}blocks(e,t){const r=e.localName;if(r==="metadata")return[];const i=this.context(e,t);if(Object.prototype.hasOwnProperty.call(we,r))return this.structure(e,{...i,indent:we[r]+(i.quoted?1:0)});if(r==="table")return q(e).filter(s=>s.localName==="tgroup").length?q(e).flatMap(s=>s.localName==="tgroup"?[this.table(s,this.context(s,i))]:this.blocks(s,i)):[this.table(e,i)];if(r==="quoted-block"){const s=q(e).filter(a=>a.localName!=="after-quoted-block").flatMap(a=>this.blocks(a,{...i,quoted:i.quoted+1,indent:i.indent+1})),p=s[s.length-1],m=X(e,"after-quoted-block");if(p?.type==="paragraph")p.children.push(this.text(i.quoted?"’":"”",i)),m&&p.children.push(...this.inline(m,i));else if(m){const a=this.paragraph([this.text(i.quoted?"’":"”",i),...this.inline(m,i)],i);a&&s.push(a)}return s}if(!q(e).some(s=>!le.has(s.localName))){const s=this.paragraph(this.inline(e,t),i,e);if(s&&(r==="legis-num"||r==="legis-type")){s.align="center";for(const p of s.children)p.marks={...p.marks,bold:!0}}return s?[s]:[]}const d=[];if(r==="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&&d.push(s)}let u=[];const h=()=>{const s=this.paragraph(u,i);s&&d.push(s),u=[]};for(const s of Array.from(e.childNodes))if(s.nodeType===3||s.nodeType===4)u.push(this.text(te(s.textContent??""),i));else if(s.nodeType===1){const p=s;le.has(p.localName)?u.push(...this.inline(p,i)):(h(),d.push(...this.blocks(p,i)))}return h(),d}structure(e,t){const r=[],i=Object.prototype.hasOwnProperty.call(Se,e.localName),d=X(e,"enum"),u=X(e,"header");let h=[];if(d&&(i&&h.push(this.text(e.localName==="section"&&t.style==="USC"?"§ ":`${Se[e.localName]} `,t)),h.push(...this.inline(d,t),this.text(" ",t))),u){const m=this.inline(u,t);for(const a of m)a.marks={...a.marks,bold:!0};h.push(...m)}const s=(m=!1)=>{const a=this.paragraph(h,t,r.length?void 0:e,m?e.localName==="section"?2:1:void 0);a&&r.push(a),h=[]};i&&s(!0);let p=!0;for(const m of Array.from(e.childNodes))if(!(m===d||m===u)){if(m.nodeType===3||m.nodeType===4)m.textContent?.trim()&&h.push(this.text(te(m.textContent),t));else if(m.nodeType===1){const a=m;if(a.localName==="text")p||s(),p&&!i&&u&&h.push(this.text(".—",t)),h.push(...this.inline(a,t)),p=!1;else if(le.has(a.localName))h.push(...this.inline(a,t));else{s();const N=this.blocks(a,t),S=r[r.length-1];a.getAttribute("display-inline")==="yes-display-inline"&&S?.type==="paragraph"&&!S.heading&&N[0]?.type==="paragraph"&&(S.children.push(this.text(" ",t),...N[0].children),N.shift()),r.push(...N)}}}return s(),r}table(e,t){const r=X(e,"tgroup")??e,i=new Map(q(r).filter(s=>s.localName==="colspec").map((s,p)=>[s.getAttribute("colname"),Number(s.getAttribute("colnum"))||p+1])),d=q(r).flatMap(s=>s.localName==="row"?[s]:["thead","tbody","tfoot"].includes(s.localName)?q(s).filter(p=>p.localName==="row"):[]);if(!d.length)throw new Error("Unsupported Congressional XML table: no rows.");const u={type:"table",id:this.id(),columnWidths:[],children:d.map(s=>({type:"table-row",id:this.id(),children:q(s).filter(p=>p.localName==="entry").map(p=>{const m=i.get(p.getAttribute("namest")),a=i.get(p.getAttribute("nameend")),N=m&&a?a-m+1:1,S=Number(p.getAttribute("morerows")??0)+1;if(p.hasAttribute("namest")&&(!m||!a)||!Number.isInteger(N)||N<1||N>100||!Number.isInteger(S)||S<1||S>d.length)throw new Error("Unsupported Congressional XML table: invalid cell span.");const j=this.blocks(p,{...this.context(s,s.parentElement&&s.parentElement!==r?this.context(s.parentElement,t):t),indent:0});return{type:"table-cell",id:this.id(),children:j.length?j:[{type:"paragraph",id:this.id(),children:[{type:"text",text:""}]}],...N>1?{colSpan:N}:{},...S>1?{rowSpan:S}:{}}})}))},h=Te(u).cols;if(!h||h>100)throw new Error("Unsupported Congressional XML table: invalid column count.");return u.columnWidths=Array(h).fill(100/h),u}}const ae=[Pe];class De{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=ge(e.subarray(0,512),"windows-1252");t=/^<\?xml\s[^?]*\bencoding\s*=\s*["']([^"']+)["']/i.exec(i)?.[1]??t}let r;try{r=ge(e,t,{fatal:!0})}catch{throw new Error(`Invalid or unsupported XML encoding: ${t}.`)}return this.fromXml(r)}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 r=[[t.documentElement,0]];for(;r.length;){const[d,u]=r.pop();if(u>128)throw new Error("XML nesting exceeds the supported depth (128).");for(const h of Array.from(d.children))r.push([h,u+1])}const i=ae.find(d=>d.matches(t));if(!i)throw new Error(`Unsupported XML schema: <${t.documentElement.tagName}>. Supported: ${ae.map(d=>d.label).join(", ")}.`);return i.parse(t)}}export{ae as XML_SCHEMA_PARSERS,De as XmlConverter};
@@ -0,0 +1,2 @@
1
+ import{ck as ue,cl as Oe,H as pe,L as Te,ah as ge}from"./index-p6UytRm8.js";const me=new WeakMap,P=n=>{let e=me.get(n);return e===void 0&&(e=n.children.map(t=>t.text).join(""),me.set(n,e)),e},F=n=>n.trim()?n.trim().split(/\s+/).length:0,Ce=/^(?:w14:paraId|w14:textId|w:rsid\w*)$/;function Be(n){if(typeof n!="string")return n;try{const e=Object.entries(JSON.parse(n)).filter(([t])=>!Ce.test(t)).sort(([t],[r])=>t.localeCompare(r));return e.length?JSON.stringify(Object.fromEntries(e)):void 0}catch{return n}}const fe=new WeakMap,w=n=>{let e=fe.get(n);if(e===void 0){const{id:t,children:r,oxmlAttrs:i,...d}=n,u=Be(i);e=JSON.stringify(u===void 0?d:{...d,oxmlAttrs:u}),fe.set(n,e)}return e},Le=n=>typeof n=="string"?n.split(",")[0].replace(/['"]/g,"").trim().toLowerCase():n,be=(n,e)=>JSON.stringify(Object.entries(n).filter(([t,r])=>!(t==="fontSize"&&r===e)).map(([t,r])=>[t,t==="fontFamily"?Le(r):r]).sort(([t],[r])=>String(t).localeCompare(String(r)))),G=(n={})=>Object.fromEntries(Oe.filter(e=>n[e]!==void 0).map(e=>[e,n[e]])),je=["comment","footnoteRef","footnotePendingBody","footnotePendingKind","oxmlRange","bookmark"],ye=n=>{const e={...n};for(const t of je)delete e[t];return e};function qe(n){return{...n,children:n.children.map(e=>({...e,marks:G(e.marks)}))}}function xe(n){return n.type==="paragraph"?`p${w(n)}${P(n)}`:n.type==="list"?`l${w(n)}${n.children.map(e=>w(e)+P(e)).join("\0")}`:JSON.stringify(n,(e,t)=>e==="id"?void 0:t)}function Xe(n){return n.type==="paragraph"||n.type==="list"||n.type==="table"}function ne(n,e){const t=JSON.parse(JSON.stringify(n)),r=new Map,i=[],d=u=>{if(!u||typeof u!="object")return;const h=u;if(typeof h.type=="string"&&typeof h.id=="string"){const s=e();r.set(h.id,s),h.id=s}typeof h.docxTablePropertyOverrides=="string"&&i.push(h),Array.isArray(h.children)&&h.children.forEach(d)};d(t);for(const u of i)try{const h=JSON.parse(u.docxTablePropertyOverrides);for(const s of["rows","rowExceptions","cells"]){const p=h[s];!p||typeof p!="object"||Array.isArray(p)||(h[s]=Object.fromEntries(Object.entries(p).map(([m,a])=>[r.get(m)??m,a])))}u.docxTablePropertyOverrides=JSON.stringify(h)}catch{}return t}function se(n){const e=t=>{if(!t||typeof t!="object")return;const r=t;r.type==="text"&&r.marks&&(r.marks=ye(r.marks)),r.children?.forEach(e)};return e(n),n}const Z=new Map,Y=n=>{let e=Z.get(n);return e||(e=new Set(n.toLowerCase().match(/[\p{L}\p{N}]+/gu)??[]),Z.size>5e4&&Z.clear(),Z.set(n,e)),e};function ie(n,e){let t=0;for(const r of n)e.has(r)&&t++;return 2*t/(n.size+e.size||1)}function oe(n,e,t,r,i,d,u,h,s=()=>!1){const p=new Map,m=k=>{const A=t(k);return p.has(A)||p.set(A,`t${p.size}`),p.get(A)+" "},a=ue(n.map(m).join(""),e.map(m).join("")).diffs;let N=0,S=0,j=0,$=0;const R=()=>{const k=n.slice(j,N),A=e.slice($,S);if(k.length===1&&A.length===1&&s(k[0],A[0])){d(k[0],A[0]);return}const J=k.map(C=>A.map(B=>r(C,B))),E=Array.from({length:k.length+1},()=>new Float64Array(A.length+1));for(let C=k.length-1;C>=0;C--)for(let B=A.length-1;B>=0;B--)E[C][B]=Math.max(E[C+1][B],E[C][B+1],J[C][B]+E[C+1][B+1]);let O=0,I=0;for(;O<k.length||I<A.length;)O<k.length&&I<A.length&&J[O][I]>0&&E[O][I]===J[O][I]+E[O+1][I+1]?d(k[O++],A[I++]):O<k.length&&(I===A.length||E[O+1][I]>=E[O][I+1])?u(k[O++]):h(A[I++])};for(const[k,A]of a){const J=A.trim().split(/\s+/).filter(Boolean).length;if(k===0){R();for(let E=0;E<J;E++)i(n[N++],e[S++]);j=N,$=S}else k===-1?N+=J:S+=J}R()}const ee=8e6,ke=1e6;function $e(n,e,t){if(n.length*e.length>ee)return null;const{nextId:r,nextBlockId:i,label:d,authorName:u,authorOf:h,pairLoneChanges:s,defaultFontSize:p}=t,m=l=>s?l:()=>!1,a={inlineChanges:0,insertedBlocks:0,deletedBlocks:0,unmarkedBlocks:0,insertedWords:0,deletedWords:0},N=l=>h?.(l)??u,S=(l,o,c)=>{const y=N(c);return{[l]:!0,suggestionId:o,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:d,...y?{suggestionAuthorName:y}:{}}},j=(l,o)=>{if(!Xe(l))return null;const c=l.type==="paragraph"?l.children[0]?.marks:void 0,y=l.type==="paragraph"?qe(l):l,g=o==="delete"?se(ne(y,i)):y,f=r(),v=N(c),b={id:f,blockId:g.id,source:"manual",authorType:"human",label:o==="insert"?"Insert":"Delete",...v?{agentName:v}:{}},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"?(a.insertedBlocks++,a.insertedWords+=F(M)):(a.deletedBlocks++,a.deletedWords+=F(M)),{...g,structuralSuggestionId:f,structuralSuggestionKind:o,structuralSuggestionRecord:JSON.stringify(x)}},$=(l,o,c)=>{const y=[];let g=0;for(const f of l.children){const v=Math.max(o-g,0),b=Math.min(o+c-g,f.text.length);if(b>v&&y.push({...f,text:f.text.slice(v,b)}),g+=f.text.length,g>=o+c)break}return y},R=(l,o,c)=>{const y=P(l),g=P(o);if(w(l)!==w(o)||F(y)*F(g)>ke){k(l,"delete",c),k(o,"insert",c);return}const f=[];let v=0,b=0,x="";const M=(W,T)=>{x||(x=r(),a.inlineChanges++);const D=F(W.map(L=>L.text).join(""));T==="insertion"?a.insertedWords+=D:a.deletedWords+=D,f.push(...W.map(L=>{const U=G(L.marks);return{...L,marks:{...T==="deletion"?ye(U):U,...S(T,x,L.marks)}}}))};for(const[W,T]of ue(y,g).diffs){if(W===-1)M($(l,v,T.length),"deletion");else if(W===1)M($(o,b,T.length),"insertion");else{const D=$(l,v,T.length),L=$(o,b,T.length);let U=0,H=0,K=0,_=0;for(;U<D.length&&H<L.length;){const Q=Math.min(D[U].text.length-K,L[H].text.length-_),he={...D[U],text:D[U].text.slice(K,K+Q)},V={...L[H],text:L[H].text.slice(_,_+Q)},{bookmark:Fe,...Ie}=G(he.marks),{bookmark:ze,...Me}=G(V.marks);be(Ie,p)===be(Me,p)?(x="",f.push({...V,marks:G(V.marks)})):(M([he],"deletion"),M([V],"insertion")),K+=Q,_+=Q,K===D[U].text.length&&(U++,K=0),_===L[H].text.length&&(H++,_=0)}}W!==1&&(v+=T.length),W!==-1&&(b+=T.length)}c.push({...o,children:f})},k=(l,o,c)=>{if(l.type==="table"){c.push(C(l,o));return}const y=j(l,o);y?c.push(y):(a.unmarkedBlocks++,o==="insert"&&c.push(l))},A=(l,o)=>{if(w(l)!==w(o))return 0;const c=ie(Y(P(l)),Y(P(o)));return c>=.5?c:0},J=(l,o,c)=>{const y=()=>{k(l,"delete",c),k(o,"insert",c)};if(l.children.length*o.children.length>ee)return y();const g=[];let f=!1;if(oe(l.children,o.children,b=>w(b)+P(b),A,(b,x)=>g.push([b,x]),(b,x)=>g.push([b,x]),()=>f=!0,()=>f=!0,m((b,x)=>w(b)===w(x))),f||g.some(([b,x])=>w(b)!==w(x)||F(P(b))*F(P(x))>ke))return y();const v=[];for(const[b,x]of g)R(b,x,v);c.push({...o,children:v})},E=(l,o)=>{const c=F(z(l));o==="insert"?(a.insertedBlocks++,a.insertedWords+=c):(a.deletedBlocks++,a.deletedWords+=c)},O=(l,o)=>o==="delete"?se(ne(l,i)):l,I=(l,o,c,y)=>{const g=r();return{id:g,record:{id:g,type:"table-change",tableId:l,source:"manual",authorType:"human",label:y[c],...u?{agentName:u}:{},tableRevision:{version:1,suggestionKind:c,markers:o.map(([f,v])=>({kind:c==="insert"?"row-insert":"row-delete",rowId:f.id,rowIndex:v})),operations:o.map(([f,v])=>({kind:"row",action:c,rowId:f.id,rowIndex:v,row:JSON.parse(JSON.stringify(f))}))}}}},C=(l,o)=>{const c=o==="delete"?se(ne(l,i)):l,{id:y,record:g}=I(c.id,c.children.map((f,v)=>[f,v]),o,{insert:"Insert table",delete:"Delete table"});return E(c,o),{...c,structuralSuggestionRecords:JSON.stringify([g]),children:c.children.map(f=>({...f,diffState:o,suggestionId:y}))}},B=(l,o)=>w(l)===w(o)&&l.children.length===o.children.length&&l.children.every((c,y)=>w(c)===w(o.children[y])),Ae=(l,o)=>l.children.every((c,y)=>c.children.length*o.children[y].children.length<=ee),re=(l,o)=>B(l,o)&&Ae(l,o),ce=(l,o)=>({...o,children:o.children.map((c,y)=>({...c,children:de(l.children[y].children,c.children)}))}),ve=(l,o,c)=>{if(w(l)!==w(o)||l.children.length*o.children.length>ee){k(l,"delete",c),k(o,"insert",c);return}const y=[],g=[],f=(b,x)=>{const M=O(b,x),{id:W,record:T}=I(o.id,[[M,y.length]],x,{insert:"Insert table row",delete:"Delete table row"});g.push(T),E(M,x),y.push({...M,diffState:x,suggestionId:W})},v=b=>xe(b);oe(l.children,o.children,v,(b,x)=>{if(!re(b,x))return 0;const M=ie(Y(z(b)),Y(z(x)));return M>=.5?M:0},(b,x)=>{re(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"),m(re)),c.push({...o,children:y,...g.length>0?{structuralSuggestionRecords:JSON.stringify(g)}:{}})},Ee=(l,o)=>{if(l.type==="paragraph"&&o.type==="paragraph")return A(l,o);if(l.type==="list"&&o.type==="list"&&w(l)===w(o)||l.type==="table"&&o.type==="table"&&w(l)===w(o)){const c=ie(Y(z(l)),Y(z(o)));return c>=.3?c:0}return 0};function de(l,o){const c=[],y=(g,f)=>{g.type==="list"&&f.type==="list"?J(g,f,c):g.type==="table"&&f.type==="table"?ve(g,f,c):g.type==="paragraph"&&f.type==="paragraph"?R(g,f,c):c.push(f)};return oe(l,o,xe,Ee,y,y,g=>k(g,"delete",c),g=>k(g,"insert",c),m((g,f)=>g.type===f.type&&(g.type==="paragraph"||g.type==="list"||g.type==="table")&&w(g)===w(f))),c}return{blocks:de(n,e),stats:a}}const Ne=new WeakMap;function z(n){const e=Ne.get(n);if(e!==void 0)return e;const t=Je(n);return Ne.set(n,t),t}function Je(n){return"children"in n&&Array.isArray(n.children)?n.children.map(e=>{const t=e;return t.type==="text"?t.text??"":z(e)}).join(" "):""}function We(n,e,t){const r=(d,u)=>d.length>0&&d.every(h=>h.type==="paragraph"&&h.children.length>0&&h.children.every(s=>s.marks?.[u]&&!s.marks.layeredInsertion));if(!r(n,"deletion")||!r(e,"insertion"))return null;const i=$e(n,e,{nextId:t,nextBlockId:pe,label:"Revise bill",authorOf:d=>d?.suggestionAuthorName});return i?i.blocks:null}const we={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},Se={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"]),Ue=new Set(["graphic","formula","footnote","footnote-ref","spanspec","entrytbl"]),q=n=>Array.from(n.children),X=(n,e)=>q(n).find(t=>t.localName===e),te=n=>n.replace(/[\t\r\n ]+/g," "),Pe={id:"us-congress-bill",label:"U.S. Congressional bills (bill.dtd)",matches(n){const e=n.documentElement;if(e.localName!=="bill"||e.namespaceURI||!X(e,"legis-body"))return!1;const t=n.doctype;if(t)return t.name==="bill"&&(t.publicId==="-//US Congress//DTDs/bill.dtd//EN"||!t.publicId&&/(?:^|\/)bill\.dtd$/i.test(t.systemId));const r=X(e,"form");return!!r&&!!X(r,"congress")&&!!X(r,"legis-num")},parse(n){return new Re().parse(n)}};class Re{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 a of Array.from(t.getElementsByTagName("committee-name"))){const N=a.getAttribute("committee-id");N&&this.committees.set(N,te(a.textContent??"").trim())}for(const a of Array.from(t.getElementsByTagName("*")))if(Ue.has(a.localName))throw new Error(`Unsupported Congressional XML element: <${a.localName}>. This bill requires content the XML importer does not yet support.`);const r=this.context(t,{marks:{},indent:0,quoted:0}),i=[],d=q(t),u=d.map(a=>this.blocks(a,r));for(let a=0;a<d.length;a++){const N=d[a],S=u[a],j=d[a+1];if(N.localName==="legis-body"&&j?.localName==="legis-body"&&j.getAttribute("display-enacting-clause")==="no-display-enacting-clause"){const $=u[a+1],R=N.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"?1:0,k=We(S.slice(R),$,()=>`congressdiff-${++this.revisionCount}`);if(k){i.push(...S.slice(0,R),...k),a++;continue}}i.push(...S)}if(!i.length)throw new Error("The Congressional XML bill contains no readable content.");const h=X(t,"form"),s=h&&X(h,"legis-num")?.textContent?.trim(),p=t.getElementsByTagName("short-title")[0]?.textContent?.trim(),m=s?[s,p].filter(Boolean).join(" — "):e.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/","title")[0]?.textContent?.trim();return{type:"doc",children:i,...m?{title:m}:{}}}context(e,t){const r={...t.marks},i=e.localName,d=e.getAttribute("changed")??(i==="added-phrase"?"added":i==="deleted-phrase"?"deleted":null);if(d==="added"||d==="deleted"){const h=d==="added"?"insertion":"deletion",s=e.getAttribute("reporting-committee")||e.getAttribute("committee-id"),p=s?this.committees.get(s)??s:void 0;if(!r[h]||p&&p!==r.suggestionAuthorName){if(r.deletion&&h==="insertion")throw new Error("Unsupported Congressional XML revision: insertion nested inside a deletion.");let m=this.revisions.get(e);m||(m={[h]:!0,suggestionId:`congressrev-${++this.revisionCount}`,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:h==="insertion"?"Insert":"Delete",...p?{suggestionAuthorName:p}:{}},this.revisions.set(e,m)),r.insertion&&h==="deletion"&&(r.layeredInsertion=JSON.stringify({id:r.suggestionId,source:r.suggestionSource,authorType:r.suggestionAuthorType,authorName:r.suggestionAuthorName,label:r.suggestionLabel})),delete r.insertion,delete r.deletion,delete r.suggestionAuthorName,Object.assign(r,m)}}i==="bold"&&(r.bold=!0),i==="italic"&&(r.italic=!0),i==="underline"&&(r.underline=!0),i==="superscript"&&(r.superscript=!0),i==="subscript"&&(r.subscript=!0);const u=e.getAttribute("href");return u&&/^(https?:\/\/|#)/i.test(u.trim())&&(r.link=u.trim()),i==="internal-xref"&&e.getAttribute("idref")&&(r.link=`#${e.getAttribute("idref")}`),{...t,marks:r,style:e.getAttribute("style")??t.style}}text(e,t){return{type:"text",text:e,marks:{...t.marks}}}inline(e,t){const r=this.context(e,t);if(e.localName==="linebreak")return[this.text(`
2
+ `,r)];const i=[],d=e.localName==="quote"||e.localName==="term";d&&i.push(this.text(r.quoted?"‘":"“",r));for(const u of Array.from(e.childNodes))u.nodeType===3||u.nodeType===4?i.push(this.text(te(u.textContent??""),r)):u.nodeType===1&&i.push(...this.inline(u,d?{...r,quoted:r.quoted+1}:r));return d&&i.push(this.text(r.quoted?"’":"”",r)),i}paragraph(e,t,r,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 d=r?.getAttribute("id");return d&&(e[0].marks={...e[0].marks,bookmark:d}),{type:"paragraph",id:this.id(),children:e,...i?{heading:i,keepNext:!0}:{},...t.indent?{leftIndent:Math.min(t.indent,6)}:{}}}blocks(e,t){const r=e.localName;if(r==="metadata")return[];const i=this.context(e,t);if(Object.prototype.hasOwnProperty.call(we,r))return this.structure(e,{...i,indent:we[r]+(i.quoted?1:0)});if(r==="table")return q(e).filter(s=>s.localName==="tgroup").length?q(e).flatMap(s=>s.localName==="tgroup"?[this.table(s,this.context(s,i))]:this.blocks(s,i)):[this.table(e,i)];if(r==="quoted-block"){const s=q(e).filter(a=>a.localName!=="after-quoted-block").flatMap(a=>this.blocks(a,{...i,quoted:i.quoted+1,indent:i.indent+1})),p=s[s.length-1],m=X(e,"after-quoted-block");if(p?.type==="paragraph")p.children.push(this.text(i.quoted?"’":"”",i)),m&&p.children.push(...this.inline(m,i));else if(m){const a=this.paragraph([this.text(i.quoted?"’":"”",i),...this.inline(m,i)],i);a&&s.push(a)}return s}if(!q(e).some(s=>!le.has(s.localName))){const s=this.paragraph(this.inline(e,t),i,e);if(s&&(r==="legis-num"||r==="legis-type")){s.align="center";for(const p of s.children)p.marks={...p.marks,bold:!0}}return s?[s]:[]}const d=[];if(r==="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&&d.push(s)}let u=[];const h=()=>{const s=this.paragraph(u,i);s&&d.push(s),u=[]};for(const s of Array.from(e.childNodes))if(s.nodeType===3||s.nodeType===4)u.push(this.text(te(s.textContent??""),i));else if(s.nodeType===1){const p=s;le.has(p.localName)?u.push(...this.inline(p,i)):(h(),d.push(...this.blocks(p,i)))}return h(),d}structure(e,t){const r=[],i=Object.prototype.hasOwnProperty.call(Se,e.localName),d=X(e,"enum"),u=X(e,"header");let h=[];if(d&&(i&&h.push(this.text(e.localName==="section"&&t.style==="USC"?"§ ":`${Se[e.localName]} `,t)),h.push(...this.inline(d,t),this.text(" ",t))),u){const m=this.inline(u,t);for(const a of m)a.marks={...a.marks,bold:!0};h.push(...m)}const s=(m=!1)=>{const a=this.paragraph(h,t,r.length?void 0:e,m?e.localName==="section"?2:1:void 0);a&&r.push(a),h=[]};i&&s(!0);let p=!0;for(const m of Array.from(e.childNodes))if(!(m===d||m===u)){if(m.nodeType===3||m.nodeType===4)m.textContent?.trim()&&h.push(this.text(te(m.textContent),t));else if(m.nodeType===1){const a=m;if(a.localName==="text")p||s(),p&&!i&&u&&h.push(this.text(".—",t)),h.push(...this.inline(a,t)),p=!1;else if(le.has(a.localName))h.push(...this.inline(a,t));else{s();const N=this.blocks(a,t),S=r[r.length-1];a.getAttribute("display-inline")==="yes-display-inline"&&S?.type==="paragraph"&&!S.heading&&N[0]?.type==="paragraph"&&(S.children.push(this.text(" ",t),...N[0].children),N.shift()),r.push(...N)}}}return s(),r}table(e,t){const r=X(e,"tgroup")??e,i=new Map(q(r).filter(s=>s.localName==="colspec").map((s,p)=>[s.getAttribute("colname"),Number(s.getAttribute("colnum"))||p+1])),d=q(r).flatMap(s=>s.localName==="row"?[s]:["thead","tbody","tfoot"].includes(s.localName)?q(s).filter(p=>p.localName==="row"):[]);if(!d.length)throw new Error("Unsupported Congressional XML table: no rows.");const u={type:"table",id:this.id(),columnWidths:[],children:d.map(s=>({type:"table-row",id:this.id(),children:q(s).filter(p=>p.localName==="entry").map(p=>{const m=i.get(p.getAttribute("namest")),a=i.get(p.getAttribute("nameend")),N=m&&a?a-m+1:1,S=Number(p.getAttribute("morerows")??0)+1;if(p.hasAttribute("namest")&&(!m||!a)||!Number.isInteger(N)||N<1||N>100||!Number.isInteger(S)||S<1||S>d.length)throw new Error("Unsupported Congressional XML table: invalid cell span.");const j=this.blocks(p,{...this.context(s,s.parentElement&&s.parentElement!==r?this.context(s.parentElement,t):t),indent:0});return{type:"table-cell",id:this.id(),children:j.length?j:[{type:"paragraph",id:this.id(),children:[{type:"text",text:""}]}],...N>1?{colSpan:N}:{},...S>1?{rowSpan:S}:{}}})}))},h=Te(u).cols;if(!h||h>100)throw new Error("Unsupported Congressional XML table: invalid column count.");return u.columnWidths=Array(h).fill(100/h),u}}const ae=[Pe];class De{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=ge(e.subarray(0,512),"windows-1252");t=/^<\?xml\s[^?]*\bencoding\s*=\s*["']([^"']+)["']/i.exec(i)?.[1]??t}let r;try{r=ge(e,t,{fatal:!0})}catch{throw new Error(`Invalid or unsupported XML encoding: ${t}.`)}return this.fromXml(r)}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 r=[[t.documentElement,0]];for(;r.length;){const[d,u]=r.pop();if(u>128)throw new Error("XML nesting exceeds the supported depth (128).");for(const h of Array.from(d.children))r.push([h,u+1])}const i=ae.find(d=>d.matches(t));if(!i)throw new Error(`Unsupported XML schema: <${t.documentElement.tagName}>. Supported: ${ae.map(d=>d.label).join(", ")}.`);return i.parse(t)}}export{ae as XML_SCHEMA_PARSERS,De as XmlConverter};
File without changes