revise 4.0.0 → 4.0.1
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 +6 -0
- package/README.md +6 -11
- package/chunks/{AgentPageRenderer-5mZ6fxqO.js → AgentPageRenderer-CHHktDQ1.js} +1 -1
- package/chunks/{AgentPageRenderer-C3jIBoeM.js → AgentPageRenderer-CN-N65JC.js} +1 -1
- package/chunks/{AttachmentDocumentImporter-CXkM4VoT.js → AttachmentDocumentImporter-DnHC9t7I.js} +1 -1
- package/chunks/{AttachmentDocumentImporter-Kox5By7a.js → AttachmentDocumentImporter-Dqg7IPtK.js} +1 -1
- package/chunks/{DocumentScrubber-BxmlzNNz.js → DocumentScrubber-Ch_bOtHW.js} +1 -1
- package/chunks/{DocumentScrubber-wmjRnX7C.js → DocumentScrubber-DRzACkWJ.js} +1 -1
- package/chunks/{DocxConverter-BH3E7nfQ.js → DocxConverter-BGPkGmyg.js} +1 -1
- package/chunks/{DocxConverter-DEHGCdib.js → DocxConverter-DeurS5EF.js} +1 -1
- package/chunks/{DocxGraft-BMvTAnGi.js → DocxGraft-D71OgoMh.js} +1 -1
- package/chunks/{DocxGraft-V2YXiUmK.js → DocxGraft-QLkGEcwQ.js} +1 -1
- package/chunks/{FileImporter-CtX8ZPjV.js → FileImporter-BIT0ZBDY.js} +1 -1
- package/chunks/{FileImporter-Da-7eRh3.js → FileImporter-Cgwoawuk.js} +1 -1
- package/chunks/{OdtConverter-CMkSeU8e.js → OdtConverter-2pm0SH5c.js} +1 -1
- package/chunks/{OdtConverter-DV94rkDL.js → OdtConverter-CSUQTfVp.js} +1 -1
- package/chunks/{OfficeImportShared-CA3dia_A.js → OfficeImportShared-C_mYnG5V.js} +1 -1
- package/chunks/{OfficeImportShared-hxIa69By.js → OfficeImportShared-O-d47J7O.js} +1 -1
- package/chunks/{PdfConverter-B-uRwLux.js → PdfConverter-BYg_pr5J.js} +1 -1
- package/chunks/{PdfConverter-B8J_5yim.js → PdfConverter-Z2HlY84F.js} +1 -1
- package/chunks/{PdfImportService-BjQ4rl-Z.js → PdfImportService-C2gwK1Sq.js} +1 -1
- package/chunks/{PdfImportService-RtFCP6hh.js → PdfImportService-CxtUtxM6.js} +1 -1
- package/chunks/{RtfConverter-CFDnUApT.js → RtfConverter-BrtojpDV.js} +1 -1
- package/chunks/{RtfConverter-CpJGtC5U.js → RtfConverter-DlztsAoK.js} +1 -1
- package/chunks/{XmlConverter-CQCrgTf7.js → XmlConverter-3XWISlqr.js} +1 -1
- package/chunks/{XmlConverter-CePTE21k.js → XmlConverter-B1Kcohr0.js} +1 -1
- package/chunks/{browser-module-B-uafDG6.js → browser-module-BVdVmrPb.js} +1 -1
- package/chunks/{browser-module-jwkhffzv.js → browser-module-CWlRHeO2.js} +1 -1
- package/chunks/{index-C7VhCKXe.js → index-D9_PwgOX.js} +9 -9
- package/chunks/{index-p6UytRm8.js → index-DcIXw_KB.js} +9 -9
- package/chunks/{pseudoLocale-Bkzfsfiw.js → pseudoLocale-Bld5ZUFr.js} +1 -1
- package/chunks/{pseudoLocale-D-AfwRwa.js → pseudoLocale-CLm3_c4X.js} +1 -1
- package/cli-shim.js +1 -1
- package/full.js +1 -1
- package/index.js +1 -1
- package/package.json +3 -3
- package/version.js +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{F as P,H as w,ah as D,ai as K,aj as U,ak as G,al as z,am as _,L as Y}from"./index-
|
|
1
|
+
import{F as P,H as w,ah as D,ai as K,aj as U,ak as G,al as z,am as _,L as Y}from"./index-DcIXw_KB.js";import{N as X,k as Z,h as $,g as J,r as T,t as k,i as Q,m as tt,d as et,s as st,b as rt,l as nt,f as it,j as at,a as ot,p as lt}from"./OfficeImportShared-O-d47J7O.js";const ct={65001:"utf-8",932:"shift_jis",936:"gb18030",949:"euc-kr",950:"big5",874:"windows-874",1e4:"macintosh",437:"windows-1252",850:"windows-1252"};function ht(a){const t=/\\ansicpg(\d+)/i.exec(a)?.[1];return t?C(t):/\\mac\b/.test(a)?"macintosh":"windows-1252"}function C(a){const t=String(a);return ct[t]??`windows-${t}`}const dt={77:1e4,128:932,129:949,134:936,136:950,161:1253,162:1254,163:1258,177:1255,178:1256,186:1257,204:1251,222:874,238:1250},W=new Map;function ut(a,t){let e=W.get(t);if(!e){try{D(new Uint8Array,t),e=t}catch{e="windows-1252"}W.set(t,e)}return D(a instanceof Uint8Array?a:new Uint8Array(a),e)}class L{constructor(t){this.kind=t,this.items=[],this.runs=[],this.runText="",this.runMarks={},this.paraId=w(),this.suppressEmptyPar=!1}}const pt=new Map([["emdash","—"],["endash","–"],["lquote","‘"],["rquote","’"],["ldblquote","“"],["rdblquote","”"],["bullet","•"],["emspace"," "],["enspace"," "],["qmspace"," "],["zwj",""],["zwnj",""],["ltrmark",""],["rtlmark",""]]),ft=new Set(["info","xmlnstbl","themedata","colorschememapping","latentstyles","datastore","generator","filetbl","rsidtbl","nonshppict","objdata","objclass","objname","shpinst","shptxt","userprops","docvar","pgdsctbl","mmathPr","bkmkstart","bkmkend","xe","tc","txe","template","private","passwordhash","wgrffmtfilter","defchp","defpap","listpicture","pnseclvl","protusertbl","fchars","lchars","aftnsep","aftnsepc","aftncn","ftnsep","ftnsepc","ftncn","blipuid","picprop","atnicn","atntime","do","falt","panose","fname","oldcprops","oldpprops","oldtprops","oldsprops","annotation-ignore"]),gt=new Set(["expandedcolortbl","listtable","listoverridetable","shppict","fldinst","annotation","atnauthor","atnid","atnref","atndate","atrfstart","atrfend","pn","revtbl","footnote"]),mt=new Set(["pict","footnote","annotation","fldinst","fldrslt","header","headerl","headerr","headerf","footer","footerl","footerr","footerf"]),bt=new Set(["ul","uld","uldash","uldashd","uldashdd","uldb","ulhwave","ulldash","ulth","ulthd","ulthdash","ulthdashd","ulthdashdd","ulthldash","ululdbwave","ulw","ulwave"]),E=new Map([["header","default"],["headerr","default"],["headerl","even"],["headerf","first"],["footer","default"],["footerr","default"],["footerl","even"],["footerf","first"]]);function F(a,t={}){return new kt(a,t).read()}class kt{constructor(t,e){this.rtf=t,this.options=e,this.defaultFont=0,this.fonts=new Map,this.colors=[],this.colorParts={r:0,g:0,b:0},this.colorHasValue=!1,this.expandedIndex=0,this.expandedParts=[],this.styles=new Map,this.currentStyle=null,this.lists=new Map,this.currentList=null,this.listOverrides=new Map,this.currentOverride=null,this.revAuthors=[],this.currentFontEntry=null,this.rowDefs=[],this.pendingCellDef={},this.rowIsHeader=!1,this.body=new L("body"),this.notes=new X("rtffn"),this.headers={},this.footers={},this.comments=[],this.openCommentRanges=[],this.commentMeta={},this.annotationCounter=0,this.commentRangeIds=new Map,this.commentIds=new Set,this.page={margins:{}},this.sectionSeen=!1,this.stack=[],this.marksVersion=0,this.cachedMarksVersion=-1,this.cachedMarks={},this.pendingBytes=[],this.pendingBytesEncoding="",this.chainsSeen=new Set,this.ansiEncoding=ht(t.slice(0,4096)),this.cocoa=/\\cocoartf/.test(t.slice(0,512)),this.state={dest:"body",chars:{},para:{borders:{}},unicodeSkip:1,storyRef:{story:this.body}}}read(){this.tokenize(),this.flushBytes();const t=this.body;this.flushRun(t),t.runs.some(i=>i.text.trim().length>0)&&this.flushParagraph(t);const e=this.buildBlocks(t.items,"body");V(e),e.length===0&&e.push(P());const s={type:"doc",children:e};this.notes.notes.length>0&&(s.notes=this.notes.notes),Object.keys(this.headers).length>0&&(s.headers=this.headers),Object.keys(this.footers).length>0&&(s.footers=this.footers);const r=Z(this.comments,[s.children,s.notes??[]]);r.length>0&&(s.comments=r);const n=this.pageLayout();return n&&(s.pageLayout=n),s}tokenize(){const t=this.rtf,e=t.length,s=/\\([a-zA-Z]{1,32})(-?\d{1,10})? ?/y;let r=0;for(;r<e;){const n=t.charCodeAt(r);if(n===123){this.flushBytes(),this.pushGroup(),r++;continue}if(n===125){this.flushBytes(),this.popGroup(),r++;continue}if(n===10||n===13){r++;continue}if(n!==92){let l=r+1;for(;l<e;){const f=t.charCodeAt(l);if(f===92||f===123||f===125||f===10||f===13)break;l++}this.literal(t.slice(r,l)),r=l;continue}const i=t[r+1];if(i===void 0)break;if(i==="\\"||i==="{"||i==="}"){this.flushBytes(),this.text(i),r+=2;continue}if(i==="'"){const l=parseInt(t.slice(r+2,r+4),16);r+=4,Number.isNaN(l)||this.byte(l);continue}if(this.flushBytes(),i==="*"){this.state.starred=!0,r+=2;continue}if(i==="~"){this.text(" "),r+=2;continue}if(i==="_"){this.text("‑"),r+=2;continue}if(i==="-"){r+=2;continue}if(i===`
|
|
2
2
|
`||i==="\r"){this.controlWord("par",null),r+=2;continue}s.lastIndex=r;const o=s.exec(t);if(!o){r+=2;continue}r+=o[0].length;const c=o[1],d=o[2]!==void 0?parseInt(o[2],10):null;if(c==="bin"&&d!==null&&d>0){this.binary(t.slice(r,r+d)),r+=d;continue}if(c==="u"&&d!==null){this.text(String.fromCharCode(d<0?d+65536:d));let l=this.state.unicodeSkip;for(;l>0&&r<e;){const f=t[r];if(f==="\\")if(t[r+1]==="'")r+=4;else{s.lastIndex=r;const m=s.exec(t);r+=m?m[0].length:2}else{if(f==="{"||f==="}")break;if(f===`
|
|
3
3
|
`||f==="\r"){r+=1;continue}else r+=1}l--}continue}this.controlWord(c,d)}}pushGroup(){const t=this.state;this.stack.push(t),this.state={dest:t.dest,chars:{...t.chars},para:{...t.para,borders:{...t.para.borders}},unicodeSkip:t.unicodeSkip,storyRef:t.storyRef,field:t.field,link:t.link,fieldKind:t.fieldKind,capture:void 0,metaKind:t.dest==="meta"?t.metaKind:void 0},(t.dest==="listtext"||t.dest==="fldinst"||t.dest==="meta")&&(this.state.capture=t.capture),this.marksVersion++}popGroup(){const t=this.state,e=this.stack.pop();e&&(this.endGroup(t,e),this.state=e,this.marksVersion++)}endGroup(t,e){switch(t.dest){case"pict":t.pict&&t.pict!==e.pict&&this.finishPicture(t.pict,t);break;case"fonttbl":t.capture&&t.capture!==e.capture&&this.finishFontName(t.capture.text);break;case"stylesheet":t.capture&&t.capture!==e.capture&&this.finishStyle(t.capture.text);break;case"listtext":e.dest!=="listtext"&&t.capture&&(t.storyRef.story.listText=t.capture.text);break;case"fldinst":e.dest!=="fldinst"&&t.capture&&t.field&&(t.field.instr=t.capture.text);break;case"meta":e.dest!=="meta"&&t.capture&&t.metaKind&&this.finishMeta(t.metaKind,t.capture.text.trim());break;case"revtbl":if(t.capture&&t.capture!==e.capture)for(const s of t.capture.text.split(";").slice(0,-1))this.revAuthors.push(s.trim());break}t.opensStory&&this.finishStory(t,e)}literal(t){const e=this.state;if(this.flushBytes(),e.dest==="pict"){e.pict?.hex.push(t);return}if(this.options.binary){let s=0;for(let r=0;r<t.length;r++)t.charCodeAt(r)>=128&&(r>s&&(this.flushBytes(),this.text(t.slice(s,r))),this.byte(t.charCodeAt(r)&255),s=r+1);s<t.length&&(this.flushBytes(),this.text(t.slice(s)));return}this.text(t)}byte(t){const e=this.currentEncoding();this.pendingBytes.length>0&&e!==this.pendingBytesEncoding&&this.flushBytes(),this.pendingBytesEncoding=e,this.pendingBytes.push(t)}flushBytes(){if(this.pendingBytes.length===0)return;const t=this.pendingBytes;this.pendingBytes=[],this.text(ut(t,this.pendingBytesEncoding))}currentEncoding(){const t=this.state.chars;return this.fonts.get(t.font??t.lochFont??this.defaultFont)?.encoding??this.ansiEncoding}binary(t){const e=this.state.pict;if(this.state.dest!=="pict"||!e)return;const s=new Uint8Array(t.length);for(let r=0;r<t.length;r++)s[r]=t.charCodeAt(r)&255;(e.binary??(e.binary=[])).push(s)}text(t){if(!t)return;const e=this.state;switch(e.dest){case"body":{const s=e.storyRef.story,r=this.effectiveMarks();J(r,s.runMarks)||(this.flushRun(s),s.runMarks=r),s.runText+=t,s.suppressEmptyPar=!1;return}case"fonttbl":case"stylesheet":case"listtext":case"fldinst":case"meta":e.capture&&(e.capture.text+=t),e.dest==="fonttbl"&&t.includes(";")&&this.fontTableSemicolons(t);return;case"colortbl":for(const s of t)s===";"&&(this.colors.push(this.colorHasValue?$(this.colorParts.r,this.colorParts.g,this.colorParts.b):void 0),this.colorParts={r:0,g:0,b:0},this.colorHasValue=!1);return;case"expandedcolortbl":for(const s of t){if(s!==";")continue;const r=this.expandedParts,n=i=>i/1e5*255;if(r.length>=3)this.colors[this.expandedIndex]=$(n(r[0]),n(r[1]),n(r[2]));else if(r.length===1){const i=n(r[0]);this.colors[this.expandedIndex]=$(i,i,i)}this.expandedParts=[],this.expandedIndex++}return;case"revtbl":e.capture?e.capture.text+=t:e.capture={text:t};return;default:return}}fontTableSemicolons(t){const e=this.state.capture;if(!e)return;const s=e.text.split(";");for(let r=0;r<s.length-1;r++)this.finishFontName(s[r]);e.text=s[s.length-1]}effectiveMarks(){if(this.cachedMarksVersion===this.marksVersion)return this.cachedMarks;const t=this.state,e=t.chars,s={};e.bold&&(s.bold=!0),e.italic&&(s.italic=!0),e.underline&&(s.underline=!0),e.strike&&(s.strikethrough=!0),e.dstrike&&(s.doubleStrikethrough=!0),e.superscript?s.superscript=!0:e.subscript&&(s.subscript=!0),e.caps&&(s.allCaps=!0),e.scaps&&(s.smallCaps=!0),e.hidden&&(s.hidden=!0);const r=this.fonts.get(e.font??e.lochFont??this.defaultFont)?.name;r&&(s.fontFamily=r),e.halfPoints&&e.halfPoints>0&&(s.fontSize=T(e.halfPoints/2*(96/72)));const n=e.color?this.colors[e.color]:void 0;n&&n!=="#000000"&&(s.color=n);const i=(e.highlight?this.colors[e.highlight]:void 0)??(e.background?this.colors[e.background]:void 0);return i&&i!=="#ffffff"&&(s.backgroundColor=i),e.expandTwips&&(s.letterSpacing=T(k(e.expandTwips))),t.link&&(s.link=t.link),t.fieldKind&&(s.field=t.fieldKind),this.openCommentRanges.length>0&&t.storyRef.story.kind!=="annotation"&&(s.comment=this.openCommentRanges.join(",")),e.deleted?Object.assign(s,this.revisionMarks("deletion",e.revAuthorDel??e.revAuthor,e.revTimeDel??e.revTime)):e.revised&&Object.assign(s,this.revisionMarks("insertion",e.revAuthor,e.revTime)),this.cachedMarks=s,this.cachedMarksVersion=this.marksVersion,s}revisionMarks(t,e,s){const r=e!==void 0?this.revAuthors[e]:void 0,n=s!==void 0?H(s):void 0;return Q(t,`rtfrev-${t==="insertion"?"ins":"del"}-${e??0}-${s??0}`,r&&r!=="Unknown"?r:void 0,n)}flushRun(t){t.runText&&(t.runs.push({type:"text",text:t.runText,marks:{...t.runMarks}}),t.runText="")}flushParagraph(t,e=!1){this.flushRun(t);const s=t.runs.filter(r=>r.text.length>0);if(t.runs=[],s.length===0&&t.suppressEmptyPar&&!e){t.suppressEmptyPar=!1,t.listText=void 0,t.paraId=w();return}t.items.push({kind:"para",id:t.paraId,runs:tt(s),para:{...this.state.para,borders:{...this.state.para.borders}},...t.listText!==void 0?{listText:t.listText}:{},...e?{forcedInTable:!0}:{}}),t.listText=void 0,t.suppressEmptyPar=!1,t.paraId=w()}controlWord(t,e){const s=this.state,r=s.starred;if(s.starred=!1,s.dest!=="skip"&&!this.startDestination(t)){if(r&&!gt.has(t)){s.dest="skip";return}if(ft.has(t)){s.dest="skip";return}switch(s.dest){case"fonttbl":this.fontTableWord(t,e);return;case"colortbl":this.colorTableWord(t,e);return;case"expandedcolortbl":t==="c"&&e!==null?this.expandedParts.push(e):(t==="cssrgb"||t==="csgray"||t==="csgenericrgb")&&(this.expandedParts=[]);return;case"stylesheet":this.styleSheetWord(t,e);return;case"listtable":this.listTableWord(t,e);return;case"listoverridetable":this.listOverrideWord(t,e);return;case"pict":this.pictWord(t,e);return;case"pn":this.pnWord(t,e);return;case"listtext":case"fldinst":case"meta":t==="tab"&&this.text(" ");return;case"revtbl":return}if(this.characterWord(t,e)){this.marksVersion++;return}this.paragraphWord(t,e)||this.structureWord(t,e)}}startDestination(t){const e=this.state;if(e.dest!=="body"&&mt.has(t))return e.dest="skip",!0;switch(t){case"fonttbl":return e.dest="fonttbl",e.capture={text:""},!0;case"colortbl":return e.dest="colortbl",this.colors=[],!0;case"expandedcolortbl":return e.dest="expandedcolortbl",this.expandedIndex=0,this.expandedParts=[],!0;case"stylesheet":return e.dest="stylesheet",!0;case"listtable":return e.dest="listtable",!0;case"listoverridetable":return e.dest="listoverridetable",!0;case"revtbl":return e.dest="revtbl",!0;case"pict":return e.dest="pict",e.pict={hex:[]},!0;case"shppict":case"shprslt":case"result":case"shp":case"object":case"field":return t==="field"&&(e.field={instr:""}),!0;case"fldinst":return e.dest="fldinst",e.capture={text:""},!0;case"fldrslt":{const s=e.field?.instr??"",r=/^\s*HYPERLINK\s+(?:\\[a-z]\s+)*"([^"]+)"/i.exec(s);return r&&!/^\s*HYPERLINK\s+\\l\b/i.test(s)&&(e.link=et(r[1])),/^\s*PAGE\b/i.test(s)&&(e.fieldKind="page"),/^\s*NUMPAGES\b/i.test(s)&&(e.fieldKind="numPages"),this.marksVersion++,!0}case"listtext":case"pntext":return e.dest="listtext",e.capture={text:""},!0;case"pn":return e.dest="pn",e.para.pn={kind:"number",level:0},!0;case"footnote":return this.openStory("footnote");case"annotation":return this.openStory("annotation");case"atnauthor":case"atnid":case"atnref":case"atndate":case"atrfstart":case"atrfend":return e.dest="meta",e.metaKind=t,e.capture={text:""},!0;default:return E.has(t)?(e.dest="body",e.opensStory=!0,e.storyRef={story:new L("header")},e.para={borders:{}},e.headerWord=t,!0):!1}}openStory(t){const e=this.state;return e.dest="body",e.opensStory=!0,e.storyRef={story:new L(t)},e.para={borders:{}},e.link=void 0,t==="annotation"&&(this.annotationRef=void 0,this.annotationDate=void 0),this.marksVersion++,!0}finishStory(t,e){const s=t.storyRef.story;if(this.flushRun(s),s.runs.some(i=>i.text.length>0)){const i=this.state;this.state=t,this.flushParagraph(s),this.state=i}const r=this.buildBlocks(s.items,s.kind);V(r);const n=e.storyRef.story;if(s.kind==="footnote"||s.kind==="endnote"){if(e.dest!=="body")return;this.flushRun(n),this.state=e,this.marksVersion++;const i=this.effectiveMarks(),o=this.notes.add(s.kind,r,i);n.runs.push(o),n.runMarks={},this.marksVersion++;return}if(s.kind==="header"){const i=t.headerWord??"header",o=E.get(i)??"default",c=r.filter(d=>d.type==="paragraph");if(c.some(d=>d.children.some(l=>l.text.trim()!==""||l.marks?.field))){const d=i.startsWith("footer")?this.footers:this.headers;d[o]=c}return}if(s.kind==="annotation"){const i=r.map(l=>l.type==="paragraph"?l.children.map(f=>f.text).join("").trim():"").filter(l=>l.length>0).join(`
|
|
4
4
|
|
|
@@ -1,2 +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(`
|
|
1
|
+
import{ck as ue,cl as Oe,H as pe,L as Te,ah as ge}from"./index-DcIXw_KB.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
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};
|
|
@@ -1,2 +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(`
|
|
1
|
+
import{ck as ue,cl as Oe,H as pe,L as Te,ah as ge}from"./index-D9_PwgOX.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
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};
|