revise 2.1.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.
- package/CHANGELOG.md +47 -1088
- package/LICENSE +24 -41
- package/README.md +103 -26
- package/agent.d.ts +139 -0
- package/chunks/chunk-U5X47PZ6.js +135 -0
- package/chunks/chunk-U6YKQBKL.js +15 -0
- package/chunks/chunk-ZLQVPMBN.js +1650 -0
- package/chunks/package-5SHL5FOJ.js +14 -0
- package/chunks/render-QD5VWKSV.js +109 -0
- package/cli-output.schema.json +1984 -0
- package/cli.js +3604 -0
- package/document.d.ts +320 -0
- package/docx.d.ts +73 -0
- package/errors.d.ts +14 -0
- package/index.d.ts +13 -967
- package/index.js +31 -1
- package/legacy/editor.d.ts +19 -0
- package/legacy/editor.js +16 -0
- package/legacy/server.d.ts +37 -0
- package/legacy/server.js +25 -0
- package/legacy/style.css +2 -0
- package/package.d.ts +23 -0
- package/package.json +49 -55
- package/render.d.ts +27 -0
- package/FONT-LICENSE-HAN-EXT-B.txt +0 -91
- package/FONT-LICENSE-KATEX.txt +0 -95
- package/FONT-LICENSE-LIBERATION.txt +0 -102
- package/FONT-LICENSE-NOTO-MULTILINGUAL.txt +0 -93
- package/FONT-LICENSE-NOTO-SANS-SC.txt +0 -93
- package/FONT-LICENSE-NOTO.txt +0 -94
- package/FONT-LICENSE-SOURCE-CODE-PRO.txt +0 -94
- package/FONT-LICENSE-SOURCE-SERIF-4.txt +0 -93
- package/THIRD-PARTY-NOTICES.md +0 -3376
- package/assets/historyMaterializeWorker-C4uxcZEh.js +0 -607
- package/backend.d.ts +0 -155
- package/backend.js +0 -3
- package/chunks/AgentPageRenderer-BFB0arQL.js +0 -1
- package/chunks/AgentPageRenderer-Dn6SaRjW.js +0 -1
- package/chunks/AttachmentDocumentImporter-BHDJAdky.js +0 -1
- package/chunks/AttachmentDocumentImporter-CxOZqzt1.js +0 -1
- package/chunks/BidiText-C8PBPSQY.js +0 -160
- package/chunks/ColorParserFull-BKH72fK8.js +0 -446
- package/chunks/DocumentMutator-4vBJQ74L.js +0 -31
- package/chunks/DocumentScrubber-COPepQKE.js +0 -1
- package/chunks/DocumentScrubber-Cf_QqHhF.js +0 -1
- package/chunks/DocumentScrubber-DS4LFDKS.js +0 -18
- package/chunks/DocumentStylesheet-byN5dtC6.js +0 -7
- package/chunks/DocxConverter-BCEB7jWY.js +0 -1083
- package/chunks/DocxConverter-C3NflpDr.js +0 -11
- package/chunks/DocxConverter-D9ZNn4nX.js +0 -11
- package/chunks/DocxGraft-Ba63IRP4.js +0 -1
- package/chunks/DocxGraft-DjERgl-z.js +0 -7
- package/chunks/DocxGraft-cYlmw4Ab.js +0 -1
- package/chunks/FileImporter-CHXj9sNX.js +0 -1
- package/chunks/FileImporter-DetvRoJc.js +0 -1
- package/chunks/HorizontalRuleOrnaments-gmUZ3R7Q.js +0 -3
- package/chunks/HtmlConverter-Sd9t49vH.js +0 -267
- package/chunks/ListNumbering-Qlu6AuRZ.js +0 -23
- package/chunks/MarkdownConverter-BdJgh8xt.js +0 -57
- package/chunks/MathRenderer-B0Y1h1JU.js +0 -62
- package/chunks/OdtConverter-BKtyx012.js +0 -1
- package/chunks/OdtConverter-Ce9j8PRt.js +0 -1
- package/chunks/OdtConverter-D709qfYb.js +0 -31
- package/chunks/ParagraphDiffAnalysis-DrmStvmz.js +0 -36
- package/chunks/PdfConverter-BA8XLTAM.js +0 -21
- package/chunks/PdfConverter-CkDClffR.js +0 -438
- package/chunks/PdfConverter-CxLxd-LJ.js +0 -21
- package/chunks/PdfImportService-CQCgsRX1.js +0 -2
- package/chunks/PdfImportService-xl7fstr-.js +0 -2
- package/chunks/RtfConverter-BZOnMUGH.js +0 -14
- package/chunks/RtfConverter-Bs81AfXt.js +0 -14
- package/chunks/RtfConverter-DfuE5olb.js +0 -45
- package/chunks/TableBorders-Cdkc62cX.js +0 -30
- package/chunks/TableGrid-DbroRucl.js +0 -12
- package/chunks/TextFileDecoder--rsVs3NR.js +0 -9
- package/chunks/TxtConverter-C-oiFUAp.js +0 -14
- package/chunks/UnicodeUtils-CXtusU4g.js +0 -10
- package/chunks/XmlConverter-C0FnrVYk.js +0 -70
- package/chunks/XmlConverter-CQa8baOF.js +0 -2
- package/chunks/XmlConverter-DjEYaIyf.js +0 -2
- package/chunks/__vite-browser-external-l0sNRNKZ.js +0 -0
- package/chunks/_commonjsHelpers-DaMA6jEr.js +0 -2
- package/chunks/_revise-sdk-lazy-harfbuzz-CDWdjF9f.js +0 -1
- package/chunks/_revise-sdk-lazy-harfbuzz-X8gnYTZL.js +0 -1
- package/chunks/ar-BdmGnaKI.js +0 -14
- package/chunks/backend-BIhAX-Gi.js +0 -484
- package/chunks/base64-Qx0OzT4p.js +0 -196
- package/chunks/browser-module-CFmqfGkE.js +0 -1791
- package/chunks/browser-module-CYGCfEyx.js +0 -3
- package/chunks/browser-module-DgvTMhpA.js +0 -3
- package/chunks/bundle.min-DRpfgV69.js +0 -782
- package/chunks/capture-BAJ2in5p.js +0 -9
- package/chunks/carrier-C5VZRMxZ.js +0 -6
- package/chunks/de-DldIXRFC.js +0 -14
- package/chunks/es-CnyKlSPK.js +0 -14
- package/chunks/footnoteFlatten-Bekh8ZfM.js +0 -6
- package/chunks/graftExport-CRRm1Oe_.js +0 -82
- package/chunks/html2canvas.esm-CntiHiYW.js +0 -997
- package/chunks/index-B1idHquf.js +0 -1094
- package/chunks/index-BWdRWxoH.js +0 -1807
- package/chunks/index-C-4H81OE.js +0 -378
- package/chunks/index-iZC8xN0t.js +0 -378
- package/chunks/index.es-Bwt05m_b.js +0 -5
- package/chunks/index.es-CI0QPo8w.js +0 -780
- package/chunks/index.es-DAQD57G4.js +0 -5
- package/chunks/jspdf.es.min-CnNRolk9.js +0 -77
- package/chunks/jspdf.es.min-DU74zN8b.js +0 -1792
- package/chunks/jspdf.es.min-DlTF8uTw.js +0 -77
- package/chunks/jszip.min-CPW0h1Kx.js +0 -476
- package/chunks/katex-DWj8TvwO.js +0 -1462
- package/chunks/pdf-BLWDCiFF.js +0 -1828
- package/chunks/persistInlineDocumentImages-DQj2iaqg.js +0 -1
- package/chunks/pseudoLocale-BoJwIubw.js +0 -1
- package/chunks/pseudoLocale-DWAm7Dpa.js +0 -1
- package/chunks/purify.es-BwLardii.js +0 -107
- package/chunks/serverDocumentSession-DASrQAbW.js +0 -15
- package/chunks/signatures-CBF7NZUy.js +0 -17
- package/chunks/tree-sitter-D6zWWUMP.js +0 -4
- package/chunks/wasmInline.generated-CBYFkdSM.js +0 -1
- package/chunks/web-tree-sitter-BXGZGnNj.js +0 -2
- package/full.js +0 -1
- package/root.d.ts +0 -5
- package/root.js +0 -2
- package/serverToolContract.d.ts +0 -391
- package/serverToolInputs.generated.d.ts +0 -250
- package/style.css +0 -1
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import{Y as ee,w as te}from"./backend-BIhAX-Gi.js";import{b as ne}from"./TableGrid-DbroRucl.js";import{a as K}from"./ParagraphDiffAnalysis-DrmStvmz.js";const U=p=>p.children.map(e=>e.text).join(""),$=({
|
|
2
|
-
id:p,children:e,...n})=>JSON.stringify(n),j=(p={})=>Object.fromEntries(ee.filter(e=>p[e]!==void 0).map(e=>[e,p[e]])),se=p=>({...p,children:p.children.map(e=>({...e,marks:j(e.marks)}))});function re(p,e,n){
|
|
3
|
-
const t=(u,c)=>u.length>0&&u.every(m=>m.type==="paragraph"&&m.children.length>0&&m.children.every(N=>N.marks?.[c]&&!N.marks.layeredInsertion));if(!t(p,"deletion")||!t(e,"insertion"))return null;const s=p,
|
|
4
|
-
o=e;if(s.length*o.length>8e6)return null;const h=s.map(U),d=o.map(U),r=[],l=(u,c,m)=>({[u]:!0,suggestionId:m,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:"Revise bill",...c?.
|
|
5
|
-
suggestionAuthorName?{suggestionAuthorName:c.suggestionAuthorName}:{}}),a=(u,c)=>{const m=n(),N=se(u),A={id:m,blockId:u.id,source:"manual",authorType:"human",label:c==="insert"?"Insert":"Delete",agentName:u.
|
|
6
|
-
children[0]?.marks?.suggestionAuthorName},E=c==="insert"?{...A,type:"block-insert"}:{...A,type:"block-delete",beforeBlock:N};r.push({...N,structuralSuggestionId:m,structuralSuggestionKind:c,structuralSuggestionRecord:JSON.
|
|
7
|
-
stringify(E)})},i=(u,c,m)=>{const N=[];let A=0;for(const E of u.children){const w=Math.max(c-A,0),f=Math.min(c+m-A,E.text.length);if(f>w&&N.push({...E,text:E.text.slice(w,f)}),A+=E.text.length,A>=c+m)
|
|
8
|
-
break}return N},g=(u,c)=>{const m=U(u),N=U(c);if($(u)!==$(c)||m.split(/\s+/).length*N.split(/\s+/).length>1e6){a(u,"delete"),a(c,"insert");return}const A=[];let E=0,w=0,f="";const k=(x,b)=>{f||(f=n()),
|
|
9
|
-
A.push(...x.map(S=>({...S,marks:{...j(S.marks),...l(b,S.marks,f)}})))};for(const[x,b]of K(m,N).diffs){if(x===-1)k(i(u,E,b.length),"deletion");else if(x===1)k(i(c,w,b.length),"insertion");else{const S=i(
|
|
10
|
-
u,E,b.length),X=i(c,w,b.length);let I=0,L=0,B=0,O=0;for(;I<S.length&&L<X.length;){const D=Math.min(S[I].text.length-B,X[L].text.length-O),Y={...S[I],text:S[I].text.slice(B,B+D)},F={...X[L],text:X[L].text.
|
|
11
|
-
slice(O,O+D)},{bookmark:ce,...V}=j(Y.marks),{bookmark:he,...Z}=j(F.marks);JSON.stringify(V)===JSON.stringify(Z)?(f="",A.push({...F,marks:j(F.marks)})):(k([Y],"deletion"),k([F],"insertion")),B+=D,O+=D,
|
|
12
|
-
B===S[I].text.length&&(I++,B=0),O===X[L].text.length&&(L++,O=0)}}x!==1&&(E+=b.length),x!==-1&&(w+=b.length)}r.push({...c,children:A})},y=new Map,q=u=>{const c=$(u)+U(u);return y.has(c)||y.set(c,`p${y.
|
|
13
|
-
size}`),y.get(c)+" "},J=K(s.map(q).join(""),o.map(q).join("")).diffs;let C=0,v=0,P=C,z=v;const H=()=>{const u=s.slice(P,C),c=o.slice(z,v),m=x=>new Set(x.toLowerCase().match(/[\p{L}\p{N}]+/gu)??[]),N=h.
|
|
14
|
-
slice(P,C).map(m),A=d.slice(z,v).map(m),E=u.map((x,b)=>c.map((S,X)=>{if($(x)!==$(S))return 0;let I=0;for(const B of N[b])A[X].has(B)&&I++;const L=2*I/(N[b].size+A[X].size||1);return L>=.5?L:0})),w=Array.
|
|
15
|
-
from({length:u.length+1},()=>new Float64Array(c.length+1));for(let x=u.length-1;x>=0;x--)for(let b=c.length-1;b>=0;b--)w[x][b]=Math.max(w[x+1][b],w[x][b+1],E[x][b]+w[x+1][b+1]);let f=0,k=0;for(;f<u.length||
|
|
16
|
-
k<c.length;)f<u.length&&k<c.length&&E[f][k]>0&&w[f][k]===E[f][k]+w[f+1][k+1]?g(u[f++],c[k++]):f<u.length&&(k===c.length||w[f+1][k]>=w[f][k+1])?a(u[f++],"delete"):a(c[k++],"insert")};for(const[u,c]of J){
|
|
17
|
-
const m=c.trim().split(/\s+/).filter(Boolean).length;if(u===0){H();for(let N=0;N<m;N++)g(s[C++],o[v++]);P=C,z=v}else u===-1?C+=m:v+=m}return H(),r}const G={division:0,title:0,subtitle:0,chapter:0,subchapter:0,
|
|
18
|
-
part:0,subpart:0,section:0,subsection:1,paragraph:2,subparagraph:3,clause:4,subclause:5,item:6,subitem:7},Q={division:"Division",title:"Title",subtitle:"Subtitle",chapter:"Chapter",subchapter:"Subchap\
|
|
19
|
-
ter",part:"Part",subpart:"Subpart",section:"Sec."},W=new Set(["added-phrase","deleted-phrase","bold","italic","underline","strike","superscript","subscript","quote","term","short-title","act-name","ex\
|
|
20
|
-
ternal-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-co\
|
|
21
|
-
mment"]),ie=new Set(["graphic","formula","footnote","footnote-ref","spanspec","entrytbl"]),M=p=>Array.from(p.children),T=(p,e)=>M(p).find(n=>n.localName===e),R=p=>p.replace(/[\t\r\n ]+/g," "),oe={id:"\
|
|
22
|
-
us-congress-bill",label:"U.S. Congressional bills (bill.dtd)",matches(p){const e=p.documentElement;if(e.localName!=="bill"||e.namespaceURI||!T(e,"legis-body"))return!1;const n=p.doctype;if(n)return n.
|
|
23
|
-
name==="bill"&&(n.publicId==="-//US Congress//DTDs/bill.dtd//EN"||!n.publicId&&/(?:^|\/)bill\.dtd$/i.test(n.systemId));const t=T(e,"form");return!!t&&!!T(t,"congress")&&!!T(t,"legis-num")},parse(p){return new le().
|
|
24
|
-
parse(p)}};class le{constructor(){this.revisionCount=0,this.revisions=new WeakMap,this.committees=new Map,this.usedIds=new Set}id(){let e;do e=te();while(this.usedIds.has(e));return this.usedIds.add(e),
|
|
25
|
-
e}parse(e){const n=e.documentElement;for(const i of Array.from(n.getElementsByTagName("committee-name"))){const g=i.getAttribute("committee-id");g&&this.committees.set(g,R(i.textContent??"").trim())}for(const i of Array.
|
|
26
|
-
from(n.getElementsByTagName("*")))if(ie.has(i.localName))throw new Error(`Unsupported Congressional XML element: <${i.localName}>. This bill requires content the XML importer does not yet support.`);const t=this.
|
|
27
|
-
context(n,{marks:{},indent:0,quoted:0}),s=[],o=M(n),h=o.map(i=>this.blocks(i,t));for(let i=0;i<o.length;i++){const g=o[i],y=h[i],q=o[i+1];if(g.localName==="legis-body"&&q?.localName==="legis-body"&&q.
|
|
28
|
-
getAttribute("display-enacting-clause")==="no-display-enacting-clause"){const J=h[i+1],C=g.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"?1:0,v=re(y.slice(C),J,()=>`congressdif\
|
|
29
|
-
f-${++this.revisionCount}`);if(v){s.push(...y.slice(0,C),...v),i++;continue}}s.push(...y)}if(!s.length)throw new Error("The Congressional XML bill contains no readable content.");const d=T(n,"form"),r=d&&
|
|
30
|
-
T(d,"legis-num")?.textContent?.trim(),l=n.getElementsByTagName("short-title")[0]?.textContent?.trim(),a=r?[r,l].filter(Boolean).join(" — "):e.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/",
|
|
31
|
-
"title")[0]?.textContent?.trim();return{type:"doc",children:s,...a?{title:a}:{}}}context(e,n){const t={...n.marks},s=e.localName,o=e.getAttribute("changed")??(s==="added-phrase"?"added":s==="deleted-p\
|
|
32
|
-
hrase"?"deleted":null);if(o==="added"||o==="deleted"){const d=o==="added"?"insertion":"deletion",r=e.getAttribute("reporting-committee")||e.getAttribute("committee-id"),l=r?this.committees.get(r)??r:void 0;
|
|
33
|
-
if(!t[d]||l&&l!==t.suggestionAuthorName){if(t.deletion&&d==="insertion")throw new Error("Unsupported Congressional XML revision: insertion nested inside a deletion.");let a=this.revisions.get(e);a||(a=
|
|
34
|
-
{[d]:!0,suggestionId:`congressrev-${++this.revisionCount}`,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:d==="insertion"?"Insert":"Delete",...l?{suggestionAuthorName:l}:{}},this.
|
|
35
|
-
revisions.set(e,a)),t.insertion&&d==="deletion"&&(t.layeredInsertion=JSON.stringify({id:t.suggestionId,source:t.suggestionSource,authorType:t.suggestionAuthorType,authorName:t.suggestionAuthorName,label:t.
|
|
36
|
-
suggestionLabel})),delete t.insertion,delete t.deletion,delete t.suggestionAuthorName,Object.assign(t,a)}}s==="bold"&&(t.bold=!0),s==="italic"&&(t.italic=!0),s==="underline"&&(t.underline=!0),s==="sup\
|
|
37
|
-
erscript"&&(t.superscript=!0),s==="subscript"&&(t.subscript=!0);const h=e.getAttribute("href");return h&&/^(https?:\/\/|#)/i.test(h.trim())&&(t.link=h.trim()),s==="internal-xref"&&e.getAttribute("idre\
|
|
38
|
-
f")&&(t.link=`#${e.getAttribute("idref")}`),{...n,marks:t,style:e.getAttribute("style")??n.style}}text(e,n){return{type:"text",text:e,marks:{...n.marks}}}inline(e,n){const t=this.context(e,n);if(e.localName===
|
|
39
|
-
"linebreak")return[this.text(`
|
|
40
|
-
`,t)];const s=[],o=e.localName==="quote"||e.localName==="term";o&&s.push(this.text(t.quoted?"‘":"“",t));for(const h of Array.from(e.childNodes))h.nodeType===3||h.nodeType===4?s.push(this.text(R(h.
|
|
41
|
-
textContent??""),t)):h.nodeType===1&&s.push(...this.inline(h,o?{...t,quoted:t.quoted+1}:t));return o&&s.push(this.text(t.quoted?"’":"”",t)),s}paragraph(e,n,t,s){for(;e.length&&!e[0].text.trim();)e.
|
|
42
|
-
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(/ +$/,""),n.quoted&&e.unshift(this.
|
|
43
|
-
text(n.quoted>1?"‘":"“",n));const o=t?.getAttribute("id");return o&&(e[0].marks={...e[0].marks,bookmark:o}),{type:"paragraph",id:this.id(),children:e,...s?{heading:s,keepNext:!0}:{},...n.indent?{leftIndent:Math.
|
|
44
|
-
min(n.indent,6)}:{}}}blocks(e,n){const t=e.localName;if(t==="metadata")return[];const s=this.context(e,n);if(Object.prototype.hasOwnProperty.call(G,t))return this.structure(e,{...s,indent:G[t]+(s.quoted?
|
|
45
|
-
1:0)});if(t==="table")return M(e).filter(r=>r.localName==="tgroup").length?M(e).flatMap(r=>r.localName==="tgroup"?[this.table(r,this.context(r,s))]:this.blocks(r,s)):[this.table(e,s)];if(t==="quoted-b\
|
|
46
|
-
lock"){const r=M(e).filter(i=>i.localName!=="after-quoted-block").flatMap(i=>this.blocks(i,{...s,quoted:s.quoted+1,indent:s.indent+1})),l=r[r.length-1],a=T(e,"after-quoted-block");if(l?.type==="paragr\
|
|
47
|
-
aph")l.children.push(this.text(s.quoted?"’":"”",s)),a&&l.children.push(...this.inline(a,s));else if(a){const i=this.paragraph([this.text(s.quoted?"’":"”",s),...this.inline(a,s)],s);i&&r.push(i)}
|
|
48
|
-
return r}if(!M(e).some(r=>!W.has(r.localName))){const r=this.paragraph(this.inline(e,n),s,e);if(r&&(t==="legis-num"||t==="legis-type")){r.align="center";for(const l of r.children)l.marks={...l.marks,bold:!0}}
|
|
49
|
-
return r?[r]:[]}const o=[];if(t==="legis-body"&&e.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"){const r=this.paragraph([this.text("Be it enacted by the Senate and House of Re\
|
|
50
|
-
presentatives of the United States of America in Congress assembled,",s)],s);r&&o.push(r)}let h=[];const d=()=>{const r=this.paragraph(h,s);r&&o.push(r),h=[]};for(const r of Array.from(e.childNodes))if(r.
|
|
51
|
-
nodeType===3||r.nodeType===4)h.push(this.text(R(r.textContent??""),s));else if(r.nodeType===1){const l=r;W.has(l.localName)?h.push(...this.inline(l,s)):(d(),o.push(...this.blocks(l,s)))}return d(),o}structure(e,n){
|
|
52
|
-
const t=[],s=Object.prototype.hasOwnProperty.call(Q,e.localName),o=T(e,"enum"),h=T(e,"header");let d=[];if(o&&(s&&d.push(this.text(e.localName==="section"&&n.style==="USC"?"§ ":`${Q[e.localName]} `,n)),
|
|
53
|
-
d.push(...this.inline(o,n),this.text(" ",n))),h){const a=this.inline(h,n);for(const i of a)i.marks={...i.marks,bold:!0};d.push(...a)}const r=(a=!1)=>{const i=this.paragraph(d,n,t.length?void 0:e,a?e.localName===
|
|
54
|
-
"section"?2:1:void 0);i&&t.push(i),d=[]};s&&r(!0);let l=!0;for(const a of Array.from(e.childNodes))if(!(a===o||a===h)){if(a.nodeType===3||a.nodeType===4)a.textContent?.trim()&&d.push(this.text(R(a.textContent),
|
|
55
|
-
n));else if(a.nodeType===1){const i=a;if(i.localName==="text")l||r(),l&&!s&&h&&d.push(this.text(".—",n)),d.push(...this.inline(i,n)),l=!1;else if(W.has(i.localName))d.push(...this.inline(i,n));else{
|
|
56
|
-
r();const g=this.blocks(i,n),y=t[t.length-1];i.getAttribute("display-inline")==="yes-display-inline"&&y?.type==="paragraph"&&!y.heading&&g[0]?.type==="paragraph"&&(y.children.push(this.text(" ",n),...g[0].
|
|
57
|
-
children),g.shift()),t.push(...g)}}}return r(),t}table(e,n){const t=T(e,"tgroup")??e,s=new Map(M(t).filter(r=>r.localName==="colspec").map((r,l)=>[r.getAttribute("colname"),Number(r.getAttribute("coln\
|
|
58
|
-
um"))||l+1])),o=M(t).flatMap(r=>r.localName==="row"?[r]:["thead","tbody","tfoot"].includes(r.localName)?M(r).filter(l=>l.localName==="row"):[]);if(!o.length)throw new Error("Unsupported Congressional \
|
|
59
|
-
XML table: no rows.");const h={type:"table",id:this.id(),columnWidths:[],children:o.map(r=>({type:"table-row",id:this.id(),children:M(r).filter(l=>l.localName==="entry").map(l=>{const a=s.get(l.getAttribute(
|
|
60
|
-
"namest")),i=s.get(l.getAttribute("nameend")),g=a&&i?i-a+1:1,y=Number(l.getAttribute("morerows")??0)+1;if(l.hasAttribute("namest")&&(!a||!i)||!Number.isInteger(g)||g<1||g>100||!Number.isInteger(y)||y<
|
|
61
|
-
1||y>o.length)throw new Error("Unsupported Congressional XML table: invalid cell span.");const q=this.blocks(l,{...this.context(r,r.parentElement&&r.parentElement!==t?this.context(r.parentElement,n):n),
|
|
62
|
-
indent:0});return{type:"table-cell",id:this.id(),children:q.length?q:[{type:"paragraph",id:this.id(),children:[{type:"text",text:""}]}],...g>1?{colSpan:g}:{},...y>1?{rowSpan:y}:{}}})}))},d=ne(h).cols;
|
|
63
|
-
if(!d||d>100)throw new Error("Unsupported Congressional XML table: invalid column count.");return h.columnWidths=Array(d).fill(100/d),h}}const _=[oe];class ae{static async parseFile(e){return this.fromBytes(
|
|
64
|
-
new Uint8Array(await e.arrayBuffer()))}static fromBytes(e){let n="utf-8";if(e[0]===255&&e[1]===254||e[0]===60&&e[1]===0&&e[2]===63&&e[3]===0)n="utf-16le";else if(e[0]===254&&e[1]===255||e[0]===0&&e[1]===
|
|
65
|
-
60&&e[2]===0&&e[3]===63)n="utf-16be";else if(!(e[0]===239&&e[1]===187&&e[2]===191)){const s=new TextDecoder("windows-1252").decode(e.subarray(0,512));n=/^<\?xml\s[^?]*\bencoding\s*=\s*["']([^"']+)["']/i.
|
|
66
|
-
exec(s)?.[1]??n}let t;try{t=new TextDecoder(n,{fatal:!0}).decode(e)}catch{throw new Error(`Invalid or unsupported XML encoding: ${n}.`)}return this.fromXml(t)}static fromXml(e){if(/<!ENTITY\s/i.test(e))
|
|
67
|
-
throw new Error("XML entity declarations are not supported.");const n=new DOMParser().parseFromString(e.replace(/^\uFEFF/,""),"application/xml");if(!n.documentElement||n.getElementsByTagName("parserer\
|
|
68
|
-
ror").length)throw new Error("Invalid XML: the document is not well-formed.");const t=[[n.documentElement,0]];for(;t.length;){const[o,h]=t.pop();if(h>128)throw new Error("XML nesting exceeds the suppo\
|
|
69
|
-
rted depth (128).");for(const d of Array.from(o.children))t.push([d,h+1])}const s=_.find(o=>o.matches(n));if(!s)throw new Error(`Unsupported XML schema: <${n.documentElement.tagName}>. Supported: ${_.
|
|
70
|
-
map(o=>o.label).join(", ")}.`);return s.parse(n)}}export{_ as XML_SCHEMA_PARSERS,ae as XmlConverter};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{aX as K,aY as ee,a1 as te,a0 as ne}from"./index-iZC8xN0t.js";const U=p=>p.children.map(e=>e.text).join(""),$=({id:p,children:e,...n})=>JSON.stringify(n),j=(p={})=>Object.fromEntries(ee.filter(e=>p[e]!==void 0).map(e=>[e,p[e]])),se=p=>({...p,children:p.children.map(e=>({...e,marks:j(e.marks)}))});function re(p,e,n){const t=(u,c)=>u.length>0&&u.every(m=>m.type==="paragraph"&&m.children.length>0&&m.children.every(N=>N.marks?.[c]&&!N.marks.layeredInsertion));if(!t(p,"deletion")||!t(e,"insertion"))return null;const s=p,o=e;if(s.length*o.length>8e6)return null;const h=s.map(U),d=o.map(U),r=[],l=(u,c,m)=>({[u]:!0,suggestionId:m,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:"Revise bill",...c?.suggestionAuthorName?{suggestionAuthorName:c.suggestionAuthorName}:{}}),a=(u,c)=>{const m=n(),N=se(u),A={id:m,blockId:u.id,source:"manual",authorType:"human",label:c==="insert"?"Insert":"Delete",agentName:u.children[0]?.marks?.suggestionAuthorName},E=c==="insert"?{...A,type:"block-insert"}:{...A,type:"block-delete",beforeBlock:N};r.push({...N,structuralSuggestionId:m,structuralSuggestionKind:c,structuralSuggestionRecord:JSON.stringify(E)})},i=(u,c,m)=>{const N=[];let A=0;for(const E of u.children){const w=Math.max(c-A,0),f=Math.min(c+m-A,E.text.length);if(f>w&&N.push({...E,text:E.text.slice(w,f)}),A+=E.text.length,A>=c+m)break}return N},g=(u,c)=>{const m=U(u),N=U(c);if($(u)!==$(c)||m.split(/\s+/).length*N.split(/\s+/).length>1e6){a(u,"delete"),a(c,"insert");return}const A=[];let E=0,w=0,f="";const k=(x,b)=>{f||(f=n()),A.push(...x.map(S=>({...S,marks:{...j(S.marks),...l(b,S.marks,f)}})))};for(const[x,b]of K(m,N).diffs){if(x===-1)k(i(u,E,b.length),"deletion");else if(x===1)k(i(c,w,b.length),"insertion");else{const S=i(u,E,b.length),q=i(c,w,b.length);let I=0,L=0,B=0,O=0;for(;I<S.length&&L<q.length;){const D=Math.min(S[I].text.length-B,q[L].text.length-O),Y={...S[I],text:S[I].text.slice(B,B+D)},F={...q[L],text:q[L].text.slice(O,O+D)},{bookmark:ce,...V}=j(Y.marks),{bookmark:he,...Z}=j(F.marks);JSON.stringify(V)===JSON.stringify(Z)?(f="",A.push({...F,marks:j(F.marks)})):(k([Y],"deletion"),k([F],"insertion")),B+=D,O+=D,B===S[I].text.length&&(I++,B=0),O===q[L].text.length&&(L++,O=0)}}x!==1&&(E+=b.length),x!==-1&&(w+=b.length)}r.push({...c,children:A})},y=new Map,X=u=>{const c=$(u)+U(u);return y.has(c)||y.set(c,`p${y.size}`),y.get(c)+" "},J=K(s.map(X).join(""),o.map(X).join("")).diffs;let C=0,v=0,P=C,z=v;const H=()=>{const u=s.slice(P,C),c=o.slice(z,v),m=x=>new Set(x.toLowerCase().match(/[\p{L}\p{N}]+/gu)??[]),N=h.slice(P,C).map(m),A=d.slice(z,v).map(m),E=u.map((x,b)=>c.map((S,q)=>{if($(x)!==$(S))return 0;let I=0;for(const B of N[b])A[q].has(B)&&I++;const L=2*I/(N[b].size+A[q].size||1);return L>=.5?L:0})),w=Array.from({length:u.length+1},()=>new Float64Array(c.length+1));for(let x=u.length-1;x>=0;x--)for(let b=c.length-1;b>=0;b--)w[x][b]=Math.max(w[x+1][b],w[x][b+1],E[x][b]+w[x+1][b+1]);let f=0,k=0;for(;f<u.length||k<c.length;)f<u.length&&k<c.length&&E[f][k]>0&&w[f][k]===E[f][k]+w[f+1][k+1]?g(u[f++],c[k++]):f<u.length&&(k===c.length||w[f+1][k]>=w[f][k+1])?a(u[f++],"delete"):a(c[k++],"insert")};for(const[u,c]of J){const m=c.trim().split(/\s+/).filter(Boolean).length;if(u===0){H();for(let N=0;N<m;N++)g(s[C++],o[v++]);P=C,z=v}else u===-1?C+=m:v+=m}return H(),r}const G={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},Q={division:"Division",title:"Title",subtitle:"Subtitle",chapter:"Chapter",subchapter:"Subchapter",part:"Part",subpart:"Subpart",section:"Sec."},W=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"]),ie=new Set(["graphic","formula","footnote","footnote-ref","spanspec","entrytbl"]),M=p=>Array.from(p.children),T=(p,e)=>M(p).find(n=>n.localName===e),R=p=>p.replace(/[\t\r\n ]+/g," "),oe={id:"us-congress-bill",label:"U.S. Congressional bills (bill.dtd)",matches(p){const e=p.documentElement;if(e.localName!=="bill"||e.namespaceURI||!T(e,"legis-body"))return!1;const n=p.doctype;if(n)return n.name==="bill"&&(n.publicId==="-//US Congress//DTDs/bill.dtd//EN"||!n.publicId&&/(?:^|\/)bill\.dtd$/i.test(n.systemId));const t=T(e,"form");return!!t&&!!T(t,"congress")&&!!T(t,"legis-num")},parse(p){return new le().parse(p)}};class le{constructor(){this.revisionCount=0,this.revisions=new WeakMap,this.committees=new Map,this.usedIds=new Set}id(){let e;do e=te();while(this.usedIds.has(e));return this.usedIds.add(e),e}parse(e){const n=e.documentElement;for(const i of Array.from(n.getElementsByTagName("committee-name"))){const g=i.getAttribute("committee-id");g&&this.committees.set(g,R(i.textContent??"").trim())}for(const i of Array.from(n.getElementsByTagName("*")))if(ie.has(i.localName))throw new Error(`Unsupported Congressional XML element: <${i.localName}>. This bill requires content the XML importer does not yet support.`);const t=this.context(n,{marks:{},indent:0,quoted:0}),s=[],o=M(n),h=o.map(i=>this.blocks(i,t));for(let i=0;i<o.length;i++){const g=o[i],y=h[i],X=o[i+1];if(g.localName==="legis-body"&&X?.localName==="legis-body"&&X.getAttribute("display-enacting-clause")==="no-display-enacting-clause"){const J=h[i+1],C=g.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"?1:0,v=re(y.slice(C),J,()=>`congressdiff-${++this.revisionCount}`);if(v){s.push(...y.slice(0,C),...v),i++;continue}}s.push(...y)}if(!s.length)throw new Error("The Congressional XML bill contains no readable content.");const d=T(n,"form"),r=d&&T(d,"legis-num")?.textContent?.trim(),l=n.getElementsByTagName("short-title")[0]?.textContent?.trim(),a=r?[r,l].filter(Boolean).join(" — "):e.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/","title")[0]?.textContent?.trim();return{type:"doc",children:s,...a?{title:a}:{}}}context(e,n){const t={...n.marks},s=e.localName,o=e.getAttribute("changed")??(s==="added-phrase"?"added":s==="deleted-phrase"?"deleted":null);if(o==="added"||o==="deleted"){const d=o==="added"?"insertion":"deletion",r=e.getAttribute("reporting-committee")||e.getAttribute("committee-id"),l=r?this.committees.get(r)??r:void 0;if(!t[d]||l&&l!==t.suggestionAuthorName){if(t.deletion&&d==="insertion")throw new Error("Unsupported Congressional XML revision: insertion nested inside a deletion.");let a=this.revisions.get(e);a||(a={[d]:!0,suggestionId:`congressrev-${++this.revisionCount}`,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:d==="insertion"?"Insert":"Delete",...l?{suggestionAuthorName:l}:{}},this.revisions.set(e,a)),t.insertion&&d==="deletion"&&(t.layeredInsertion=JSON.stringify({id:t.suggestionId,source:t.suggestionSource,authorType:t.suggestionAuthorType,authorName:t.suggestionAuthorName,label:t.suggestionLabel})),delete t.insertion,delete t.deletion,delete t.suggestionAuthorName,Object.assign(t,a)}}s==="bold"&&(t.bold=!0),s==="italic"&&(t.italic=!0),s==="underline"&&(t.underline=!0),s==="superscript"&&(t.superscript=!0),s==="subscript"&&(t.subscript=!0);const h=e.getAttribute("href");return h&&/^(https?:\/\/|#)/i.test(h.trim())&&(t.link=h.trim()),s==="internal-xref"&&e.getAttribute("idref")&&(t.link=`#${e.getAttribute("idref")}`),{...n,marks:t,style:e.getAttribute("style")??n.style}}text(e,n){return{type:"text",text:e,marks:{...n.marks}}}inline(e,n){const t=this.context(e,n);if(e.localName==="linebreak")return[this.text(`
|
|
2
|
-
`,t)];const s=[],o=e.localName==="quote"||e.localName==="term";o&&s.push(this.text(t.quoted?"‘":"“",t));for(const h of Array.from(e.childNodes))h.nodeType===3||h.nodeType===4?s.push(this.text(R(h.textContent??""),t)):h.nodeType===1&&s.push(...this.inline(h,o?{...t,quoted:t.quoted+1}:t));return o&&s.push(this.text(t.quoted?"’":"”",t)),s}paragraph(e,n,t,s){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(/ +$/,""),n.quoted&&e.unshift(this.text(n.quoted>1?"‘":"“",n));const o=t?.getAttribute("id");return o&&(e[0].marks={...e[0].marks,bookmark:o}),{type:"paragraph",id:this.id(),children:e,...s?{heading:s,keepNext:!0}:{},...n.indent?{leftIndent:Math.min(n.indent,6)}:{}}}blocks(e,n){const t=e.localName;if(t==="metadata")return[];const s=this.context(e,n);if(Object.prototype.hasOwnProperty.call(G,t))return this.structure(e,{...s,indent:G[t]+(s.quoted?1:0)});if(t==="table")return M(e).filter(r=>r.localName==="tgroup").length?M(e).flatMap(r=>r.localName==="tgroup"?[this.table(r,this.context(r,s))]:this.blocks(r,s)):[this.table(e,s)];if(t==="quoted-block"){const r=M(e).filter(i=>i.localName!=="after-quoted-block").flatMap(i=>this.blocks(i,{...s,quoted:s.quoted+1,indent:s.indent+1})),l=r[r.length-1],a=T(e,"after-quoted-block");if(l?.type==="paragraph")l.children.push(this.text(s.quoted?"’":"”",s)),a&&l.children.push(...this.inline(a,s));else if(a){const i=this.paragraph([this.text(s.quoted?"’":"”",s),...this.inline(a,s)],s);i&&r.push(i)}return r}if(!M(e).some(r=>!W.has(r.localName))){const r=this.paragraph(this.inline(e,n),s,e);if(r&&(t==="legis-num"||t==="legis-type")){r.align="center";for(const l of r.children)l.marks={...l.marks,bold:!0}}return r?[r]:[]}const o=[];if(t==="legis-body"&&e.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"){const r=this.paragraph([this.text("Be it enacted by the Senate and House of Representatives of the United States of America in Congress assembled,",s)],s);r&&o.push(r)}let h=[];const d=()=>{const r=this.paragraph(h,s);r&&o.push(r),h=[]};for(const r of Array.from(e.childNodes))if(r.nodeType===3||r.nodeType===4)h.push(this.text(R(r.textContent??""),s));else if(r.nodeType===1){const l=r;W.has(l.localName)?h.push(...this.inline(l,s)):(d(),o.push(...this.blocks(l,s)))}return d(),o}structure(e,n){const t=[],s=Object.prototype.hasOwnProperty.call(Q,e.localName),o=T(e,"enum"),h=T(e,"header");let d=[];if(o&&(s&&d.push(this.text(e.localName==="section"&&n.style==="USC"?"§ ":`${Q[e.localName]} `,n)),d.push(...this.inline(o,n),this.text(" ",n))),h){const a=this.inline(h,n);for(const i of a)i.marks={...i.marks,bold:!0};d.push(...a)}const r=(a=!1)=>{const i=this.paragraph(d,n,t.length?void 0:e,a?e.localName==="section"?2:1:void 0);i&&t.push(i),d=[]};s&&r(!0);let l=!0;for(const a of Array.from(e.childNodes))if(!(a===o||a===h)){if(a.nodeType===3||a.nodeType===4)a.textContent?.trim()&&d.push(this.text(R(a.textContent),n));else if(a.nodeType===1){const i=a;if(i.localName==="text")l||r(),l&&!s&&h&&d.push(this.text(".—",n)),d.push(...this.inline(i,n)),l=!1;else if(W.has(i.localName))d.push(...this.inline(i,n));else{r();const g=this.blocks(i,n),y=t[t.length-1];i.getAttribute("display-inline")==="yes-display-inline"&&y?.type==="paragraph"&&!y.heading&&g[0]?.type==="paragraph"&&(y.children.push(this.text(" ",n),...g[0].children),g.shift()),t.push(...g)}}}return r(),t}table(e,n){const t=T(e,"tgroup")??e,s=new Map(M(t).filter(r=>r.localName==="colspec").map((r,l)=>[r.getAttribute("colname"),Number(r.getAttribute("colnum"))||l+1])),o=M(t).flatMap(r=>r.localName==="row"?[r]:["thead","tbody","tfoot"].includes(r.localName)?M(r).filter(l=>l.localName==="row"):[]);if(!o.length)throw new Error("Unsupported Congressional XML table: no rows.");const h={type:"table",id:this.id(),columnWidths:[],children:o.map(r=>({type:"table-row",id:this.id(),children:M(r).filter(l=>l.localName==="entry").map(l=>{const a=s.get(l.getAttribute("namest")),i=s.get(l.getAttribute("nameend")),g=a&&i?i-a+1:1,y=Number(l.getAttribute("morerows")??0)+1;if(l.hasAttribute("namest")&&(!a||!i)||!Number.isInteger(g)||g<1||g>100||!Number.isInteger(y)||y<1||y>o.length)throw new Error("Unsupported Congressional XML table: invalid cell span.");const X=this.blocks(l,{...this.context(r,r.parentElement&&r.parentElement!==t?this.context(r.parentElement,n):n),indent:0});return{type:"table-cell",id:this.id(),children:X.length?X:[{type:"paragraph",id:this.id(),children:[{type:"text",text:""}]}],...g>1?{colSpan:g}:{},...y>1?{rowSpan:y}:{}}})}))},d=ne(h).cols;if(!d||d>100)throw new Error("Unsupported Congressional XML table: invalid column count.");return h.columnWidths=Array(d).fill(100/d),h}}const _=[oe];class ae{static async parseFile(e){return this.fromBytes(new Uint8Array(await e.arrayBuffer()))}static fromBytes(e){let n="utf-8";if(e[0]===255&&e[1]===254||e[0]===60&&e[1]===0&&e[2]===63&&e[3]===0)n="utf-16le";else if(e[0]===254&&e[1]===255||e[0]===0&&e[1]===60&&e[2]===0&&e[3]===63)n="utf-16be";else if(!(e[0]===239&&e[1]===187&&e[2]===191)){const s=new TextDecoder("windows-1252").decode(e.subarray(0,512));n=/^<\?xml\s[^?]*\bencoding\s*=\s*["']([^"']+)["']/i.exec(s)?.[1]??n}let t;try{t=new TextDecoder(n,{fatal:!0}).decode(e)}catch{throw new Error(`Invalid or unsupported XML encoding: ${n}.`)}return this.fromXml(t)}static fromXml(e){if(/<!ENTITY\s/i.test(e))throw new Error("XML entity declarations are not supported.");const n=new DOMParser().parseFromString(e.replace(/^\uFEFF/,""),"application/xml");if(!n.documentElement||n.getElementsByTagName("parsererror").length)throw new Error("Invalid XML: the document is not well-formed.");const t=[[n.documentElement,0]];for(;t.length;){const[o,h]=t.pop();if(h>128)throw new Error("XML nesting exceeds the supported depth (128).");for(const d of Array.from(o.children))t.push([d,h+1])}const s=_.find(o=>o.matches(n));if(!s)throw new Error(`Unsupported XML schema: <${n.documentElement.tagName}>. Supported: ${_.map(o=>o.label).join(", ")}.`);return s.parse(n)}}export{_ as XML_SCHEMA_PARSERS,ae as XmlConverter};
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{aX as K,aY as ee,a1 as te,a0 as ne}from"./index-C-4H81OE.js";const U=p=>p.children.map(e=>e.text).join(""),$=({id:p,children:e,...n})=>JSON.stringify(n),j=(p={})=>Object.fromEntries(ee.filter(e=>p[e]!==void 0).map(e=>[e,p[e]])),se=p=>({...p,children:p.children.map(e=>({...e,marks:j(e.marks)}))});function re(p,e,n){const t=(u,c)=>u.length>0&&u.every(m=>m.type==="paragraph"&&m.children.length>0&&m.children.every(N=>N.marks?.[c]&&!N.marks.layeredInsertion));if(!t(p,"deletion")||!t(e,"insertion"))return null;const s=p,o=e;if(s.length*o.length>8e6)return null;const h=s.map(U),d=o.map(U),r=[],l=(u,c,m)=>({[u]:!0,suggestionId:m,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:"Revise bill",...c?.suggestionAuthorName?{suggestionAuthorName:c.suggestionAuthorName}:{}}),a=(u,c)=>{const m=n(),N=se(u),A={id:m,blockId:u.id,source:"manual",authorType:"human",label:c==="insert"?"Insert":"Delete",agentName:u.children[0]?.marks?.suggestionAuthorName},E=c==="insert"?{...A,type:"block-insert"}:{...A,type:"block-delete",beforeBlock:N};r.push({...N,structuralSuggestionId:m,structuralSuggestionKind:c,structuralSuggestionRecord:JSON.stringify(E)})},i=(u,c,m)=>{const N=[];let A=0;for(const E of u.children){const w=Math.max(c-A,0),f=Math.min(c+m-A,E.text.length);if(f>w&&N.push({...E,text:E.text.slice(w,f)}),A+=E.text.length,A>=c+m)break}return N},g=(u,c)=>{const m=U(u),N=U(c);if($(u)!==$(c)||m.split(/\s+/).length*N.split(/\s+/).length>1e6){a(u,"delete"),a(c,"insert");return}const A=[];let E=0,w=0,f="";const k=(x,b)=>{f||(f=n()),A.push(...x.map(S=>({...S,marks:{...j(S.marks),...l(b,S.marks,f)}})))};for(const[x,b]of K(m,N).diffs){if(x===-1)k(i(u,E,b.length),"deletion");else if(x===1)k(i(c,w,b.length),"insertion");else{const S=i(u,E,b.length),q=i(c,w,b.length);let I=0,L=0,B=0,O=0;for(;I<S.length&&L<q.length;){const D=Math.min(S[I].text.length-B,q[L].text.length-O),Y={...S[I],text:S[I].text.slice(B,B+D)},F={...q[L],text:q[L].text.slice(O,O+D)},{bookmark:ce,...V}=j(Y.marks),{bookmark:he,...Z}=j(F.marks);JSON.stringify(V)===JSON.stringify(Z)?(f="",A.push({...F,marks:j(F.marks)})):(k([Y],"deletion"),k([F],"insertion")),B+=D,O+=D,B===S[I].text.length&&(I++,B=0),O===q[L].text.length&&(L++,O=0)}}x!==1&&(E+=b.length),x!==-1&&(w+=b.length)}r.push({...c,children:A})},y=new Map,X=u=>{const c=$(u)+U(u);return y.has(c)||y.set(c,`p${y.size}`),y.get(c)+" "},J=K(s.map(X).join(""),o.map(X).join("")).diffs;let C=0,v=0,P=C,z=v;const H=()=>{const u=s.slice(P,C),c=o.slice(z,v),m=x=>new Set(x.toLowerCase().match(/[\p{L}\p{N}]+/gu)??[]),N=h.slice(P,C).map(m),A=d.slice(z,v).map(m),E=u.map((x,b)=>c.map((S,q)=>{if($(x)!==$(S))return 0;let I=0;for(const B of N[b])A[q].has(B)&&I++;const L=2*I/(N[b].size+A[q].size||1);return L>=.5?L:0})),w=Array.from({length:u.length+1},()=>new Float64Array(c.length+1));for(let x=u.length-1;x>=0;x--)for(let b=c.length-1;b>=0;b--)w[x][b]=Math.max(w[x+1][b],w[x][b+1],E[x][b]+w[x+1][b+1]);let f=0,k=0;for(;f<u.length||k<c.length;)f<u.length&&k<c.length&&E[f][k]>0&&w[f][k]===E[f][k]+w[f+1][k+1]?g(u[f++],c[k++]):f<u.length&&(k===c.length||w[f+1][k]>=w[f][k+1])?a(u[f++],"delete"):a(c[k++],"insert")};for(const[u,c]of J){const m=c.trim().split(/\s+/).filter(Boolean).length;if(u===0){H();for(let N=0;N<m;N++)g(s[C++],o[v++]);P=C,z=v}else u===-1?C+=m:v+=m}return H(),r}const G={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},Q={division:"Division",title:"Title",subtitle:"Subtitle",chapter:"Chapter",subchapter:"Subchapter",part:"Part",subpart:"Subpart",section:"Sec."},W=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"]),ie=new Set(["graphic","formula","footnote","footnote-ref","spanspec","entrytbl"]),M=p=>Array.from(p.children),T=(p,e)=>M(p).find(n=>n.localName===e),R=p=>p.replace(/[\t\r\n ]+/g," "),oe={id:"us-congress-bill",label:"U.S. Congressional bills (bill.dtd)",matches(p){const e=p.documentElement;if(e.localName!=="bill"||e.namespaceURI||!T(e,"legis-body"))return!1;const n=p.doctype;if(n)return n.name==="bill"&&(n.publicId==="-//US Congress//DTDs/bill.dtd//EN"||!n.publicId&&/(?:^|\/)bill\.dtd$/i.test(n.systemId));const t=T(e,"form");return!!t&&!!T(t,"congress")&&!!T(t,"legis-num")},parse(p){return new le().parse(p)}};class le{constructor(){this.revisionCount=0,this.revisions=new WeakMap,this.committees=new Map,this.usedIds=new Set}id(){let e;do e=te();while(this.usedIds.has(e));return this.usedIds.add(e),e}parse(e){const n=e.documentElement;for(const i of Array.from(n.getElementsByTagName("committee-name"))){const g=i.getAttribute("committee-id");g&&this.committees.set(g,R(i.textContent??"").trim())}for(const i of Array.from(n.getElementsByTagName("*")))if(ie.has(i.localName))throw new Error(`Unsupported Congressional XML element: <${i.localName}>. This bill requires content the XML importer does not yet support.`);const t=this.context(n,{marks:{},indent:0,quoted:0}),s=[],o=M(n),h=o.map(i=>this.blocks(i,t));for(let i=0;i<o.length;i++){const g=o[i],y=h[i],X=o[i+1];if(g.localName==="legis-body"&&X?.localName==="legis-body"&&X.getAttribute("display-enacting-clause")==="no-display-enacting-clause"){const J=h[i+1],C=g.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"?1:0,v=re(y.slice(C),J,()=>`congressdiff-${++this.revisionCount}`);if(v){s.push(...y.slice(0,C),...v),i++;continue}}s.push(...y)}if(!s.length)throw new Error("The Congressional XML bill contains no readable content.");const d=T(n,"form"),r=d&&T(d,"legis-num")?.textContent?.trim(),l=n.getElementsByTagName("short-title")[0]?.textContent?.trim(),a=r?[r,l].filter(Boolean).join(" — "):e.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/","title")[0]?.textContent?.trim();return{type:"doc",children:s,...a?{title:a}:{}}}context(e,n){const t={...n.marks},s=e.localName,o=e.getAttribute("changed")??(s==="added-phrase"?"added":s==="deleted-phrase"?"deleted":null);if(o==="added"||o==="deleted"){const d=o==="added"?"insertion":"deletion",r=e.getAttribute("reporting-committee")||e.getAttribute("committee-id"),l=r?this.committees.get(r)??r:void 0;if(!t[d]||l&&l!==t.suggestionAuthorName){if(t.deletion&&d==="insertion")throw new Error("Unsupported Congressional XML revision: insertion nested inside a deletion.");let a=this.revisions.get(e);a||(a={[d]:!0,suggestionId:`congressrev-${++this.revisionCount}`,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:d==="insertion"?"Insert":"Delete",...l?{suggestionAuthorName:l}:{}},this.revisions.set(e,a)),t.insertion&&d==="deletion"&&(t.layeredInsertion=JSON.stringify({id:t.suggestionId,source:t.suggestionSource,authorType:t.suggestionAuthorType,authorName:t.suggestionAuthorName,label:t.suggestionLabel})),delete t.insertion,delete t.deletion,delete t.suggestionAuthorName,Object.assign(t,a)}}s==="bold"&&(t.bold=!0),s==="italic"&&(t.italic=!0),s==="underline"&&(t.underline=!0),s==="superscript"&&(t.superscript=!0),s==="subscript"&&(t.subscript=!0);const h=e.getAttribute("href");return h&&/^(https?:\/\/|#)/i.test(h.trim())&&(t.link=h.trim()),s==="internal-xref"&&e.getAttribute("idref")&&(t.link=`#${e.getAttribute("idref")}`),{...n,marks:t,style:e.getAttribute("style")??n.style}}text(e,n){return{type:"text",text:e,marks:{...n.marks}}}inline(e,n){const t=this.context(e,n);if(e.localName==="linebreak")return[this.text(`
|
|
2
|
-
`,t)];const s=[],o=e.localName==="quote"||e.localName==="term";o&&s.push(this.text(t.quoted?"‘":"“",t));for(const h of Array.from(e.childNodes))h.nodeType===3||h.nodeType===4?s.push(this.text(R(h.textContent??""),t)):h.nodeType===1&&s.push(...this.inline(h,o?{...t,quoted:t.quoted+1}:t));return o&&s.push(this.text(t.quoted?"’":"”",t)),s}paragraph(e,n,t,s){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(/ +$/,""),n.quoted&&e.unshift(this.text(n.quoted>1?"‘":"“",n));const o=t?.getAttribute("id");return o&&(e[0].marks={...e[0].marks,bookmark:o}),{type:"paragraph",id:this.id(),children:e,...s?{heading:s,keepNext:!0}:{},...n.indent?{leftIndent:Math.min(n.indent,6)}:{}}}blocks(e,n){const t=e.localName;if(t==="metadata")return[];const s=this.context(e,n);if(Object.prototype.hasOwnProperty.call(G,t))return this.structure(e,{...s,indent:G[t]+(s.quoted?1:0)});if(t==="table")return M(e).filter(r=>r.localName==="tgroup").length?M(e).flatMap(r=>r.localName==="tgroup"?[this.table(r,this.context(r,s))]:this.blocks(r,s)):[this.table(e,s)];if(t==="quoted-block"){const r=M(e).filter(i=>i.localName!=="after-quoted-block").flatMap(i=>this.blocks(i,{...s,quoted:s.quoted+1,indent:s.indent+1})),l=r[r.length-1],a=T(e,"after-quoted-block");if(l?.type==="paragraph")l.children.push(this.text(s.quoted?"’":"”",s)),a&&l.children.push(...this.inline(a,s));else if(a){const i=this.paragraph([this.text(s.quoted?"’":"”",s),...this.inline(a,s)],s);i&&r.push(i)}return r}if(!M(e).some(r=>!W.has(r.localName))){const r=this.paragraph(this.inline(e,n),s,e);if(r&&(t==="legis-num"||t==="legis-type")){r.align="center";for(const l of r.children)l.marks={...l.marks,bold:!0}}return r?[r]:[]}const o=[];if(t==="legis-body"&&e.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"){const r=this.paragraph([this.text("Be it enacted by the Senate and House of Representatives of the United States of America in Congress assembled,",s)],s);r&&o.push(r)}let h=[];const d=()=>{const r=this.paragraph(h,s);r&&o.push(r),h=[]};for(const r of Array.from(e.childNodes))if(r.nodeType===3||r.nodeType===4)h.push(this.text(R(r.textContent??""),s));else if(r.nodeType===1){const l=r;W.has(l.localName)?h.push(...this.inline(l,s)):(d(),o.push(...this.blocks(l,s)))}return d(),o}structure(e,n){const t=[],s=Object.prototype.hasOwnProperty.call(Q,e.localName),o=T(e,"enum"),h=T(e,"header");let d=[];if(o&&(s&&d.push(this.text(e.localName==="section"&&n.style==="USC"?"§ ":`${Q[e.localName]} `,n)),d.push(...this.inline(o,n),this.text(" ",n))),h){const a=this.inline(h,n);for(const i of a)i.marks={...i.marks,bold:!0};d.push(...a)}const r=(a=!1)=>{const i=this.paragraph(d,n,t.length?void 0:e,a?e.localName==="section"?2:1:void 0);i&&t.push(i),d=[]};s&&r(!0);let l=!0;for(const a of Array.from(e.childNodes))if(!(a===o||a===h)){if(a.nodeType===3||a.nodeType===4)a.textContent?.trim()&&d.push(this.text(R(a.textContent),n));else if(a.nodeType===1){const i=a;if(i.localName==="text")l||r(),l&&!s&&h&&d.push(this.text(".—",n)),d.push(...this.inline(i,n)),l=!1;else if(W.has(i.localName))d.push(...this.inline(i,n));else{r();const g=this.blocks(i,n),y=t[t.length-1];i.getAttribute("display-inline")==="yes-display-inline"&&y?.type==="paragraph"&&!y.heading&&g[0]?.type==="paragraph"&&(y.children.push(this.text(" ",n),...g[0].children),g.shift()),t.push(...g)}}}return r(),t}table(e,n){const t=T(e,"tgroup")??e,s=new Map(M(t).filter(r=>r.localName==="colspec").map((r,l)=>[r.getAttribute("colname"),Number(r.getAttribute("colnum"))||l+1])),o=M(t).flatMap(r=>r.localName==="row"?[r]:["thead","tbody","tfoot"].includes(r.localName)?M(r).filter(l=>l.localName==="row"):[]);if(!o.length)throw new Error("Unsupported Congressional XML table: no rows.");const h={type:"table",id:this.id(),columnWidths:[],children:o.map(r=>({type:"table-row",id:this.id(),children:M(r).filter(l=>l.localName==="entry").map(l=>{const a=s.get(l.getAttribute("namest")),i=s.get(l.getAttribute("nameend")),g=a&&i?i-a+1:1,y=Number(l.getAttribute("morerows")??0)+1;if(l.hasAttribute("namest")&&(!a||!i)||!Number.isInteger(g)||g<1||g>100||!Number.isInteger(y)||y<1||y>o.length)throw new Error("Unsupported Congressional XML table: invalid cell span.");const X=this.blocks(l,{...this.context(r,r.parentElement&&r.parentElement!==t?this.context(r.parentElement,n):n),indent:0});return{type:"table-cell",id:this.id(),children:X.length?X:[{type:"paragraph",id:this.id(),children:[{type:"text",text:""}]}],...g>1?{colSpan:g}:{},...y>1?{rowSpan:y}:{}}})}))},d=ne(h).cols;if(!d||d>100)throw new Error("Unsupported Congressional XML table: invalid column count.");return h.columnWidths=Array(d).fill(100/d),h}}const _=[oe];class ae{static async parseFile(e){return this.fromBytes(new Uint8Array(await e.arrayBuffer()))}static fromBytes(e){let n="utf-8";if(e[0]===255&&e[1]===254||e[0]===60&&e[1]===0&&e[2]===63&&e[3]===0)n="utf-16le";else if(e[0]===254&&e[1]===255||e[0]===0&&e[1]===60&&e[2]===0&&e[3]===63)n="utf-16be";else if(!(e[0]===239&&e[1]===187&&e[2]===191)){const s=new TextDecoder("windows-1252").decode(e.subarray(0,512));n=/^<\?xml\s[^?]*\bencoding\s*=\s*["']([^"']+)["']/i.exec(s)?.[1]??n}let t;try{t=new TextDecoder(n,{fatal:!0}).decode(e)}catch{throw new Error(`Invalid or unsupported XML encoding: ${n}.`)}return this.fromXml(t)}static fromXml(e){if(/<!ENTITY\s/i.test(e))throw new Error("XML entity declarations are not supported.");const n=new DOMParser().parseFromString(e.replace(/^\uFEFF/,""),"application/xml");if(!n.documentElement||n.getElementsByTagName("parsererror").length)throw new Error("Invalid XML: the document is not well-formed.");const t=[[n.documentElement,0]];for(;t.length;){const[o,h]=t.pop();if(h>128)throw new Error("XML nesting exceeds the supported depth (128).");for(const d of Array.from(o.children))t.push([d,h+1])}const s=_.find(o=>o.matches(n));if(!s)throw new Error(`Unsupported XML schema: <${n.documentElement.tagName}>. Supported: ${_.map(o=>o.label).join(", ")}.`);return s.parse(n)}}export{_ as XML_SCHEMA_PARSERS,ae as XmlConverter};
|
|
File without changes
|