revise 2.0.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/CHANGELOG.md +195 -0
  2. package/README.md +4 -1
  3. package/assets/historyMaterializeWorker-B51R08XN.js +612 -0
  4. package/backend.d.ts +8 -2
  5. package/backend.js +3 -1
  6. package/chunks/AgentPageRenderer-CH8kSTJn.js +1 -0
  7. package/chunks/AgentPageRenderer-P23XVguo.js +1 -0
  8. package/chunks/AttachmentDocumentImporter-B1WOaa7d.js +1 -0
  9. package/chunks/AttachmentDocumentImporter-CT_PJp_e.js +1 -0
  10. package/chunks/BidiText-Swm5fl9J.js +160 -0
  11. package/chunks/ColorParserFull-BKH72fK8.js +446 -1
  12. package/chunks/DocumentMutator-btiDK57e.js +31 -0
  13. package/chunks/DocumentScrubber-CMPfm_HF.js +18 -0
  14. package/chunks/{DocumentScrubber-DrgzBlx4.js → DocumentScrubber-Cm2kH8op.js} +1 -1
  15. package/chunks/{DocumentScrubber-W0EfGmL-.js → DocumentScrubber-bJoKijol.js} +1 -1
  16. package/chunks/DocumentStylesheet-DreoD7sD.js +7 -0
  17. package/chunks/DocxConverter-BcVG-p5K.js +13 -0
  18. package/chunks/DocxConverter-D2bO5RE-.js +1125 -0
  19. package/chunks/DocxConverter-haCfRuWb.js +13 -0
  20. package/chunks/{DocxGraft-B6W7fbh4.js → DocxGraft-BRKh4mHQ.js} +1 -1
  21. package/chunks/DocxGraft-BxSQtl12.js +7 -0
  22. package/chunks/{DocxGraft-Cj7v78BO.js → DocxGraft-C9MBQCnf.js} +1 -1
  23. package/chunks/FileImporter-CszqRfVU.js +1 -0
  24. package/chunks/FileImporter-DObFoCCn.js +1 -0
  25. package/chunks/HorizontalRuleOrnaments-gmUZ3R7Q.js +3 -1
  26. package/chunks/HtmlConverter-DwXB4IDh.js +267 -0
  27. package/chunks/ListNumbering-Qlu6AuRZ.js +23 -1
  28. package/chunks/MarkdownConverter-CUC8GgsS.js +57 -0
  29. package/chunks/MathRenderer-DT6GyJXb.js +68 -0
  30. package/chunks/OdtConverter-7h9HHMpL.js +125 -0
  31. package/chunks/OdtConverter-Ct4qypJk.js +6 -0
  32. package/chunks/OdtConverter-DFl__sJc.js +6 -0
  33. package/chunks/OfficeImportShared-BY6FdZ8d.js +1 -0
  34. package/chunks/OfficeImportShared-BrZoDM0j.js +30 -0
  35. package/chunks/OfficeImportShared-Bvm-mOyj.js +1 -0
  36. package/chunks/ParagraphDiffAnalysis-DrmStvmz.js +36 -0
  37. package/chunks/PdfConverter-1wyvoT7X.js +21 -0
  38. package/chunks/PdfConverter-BAoEHILo.js +21 -0
  39. package/chunks/PdfConverter-CKEvFj11.js +448 -0
  40. package/chunks/{PdfImportService-Dj1-3L2B.js → PdfImportService-BhLPp5uG.js} +2 -2
  41. package/chunks/{PdfImportService-OE9G383I.js → PdfImportService-xbzrN__L.js} +2 -2
  42. package/chunks/RtfConverter-Bxn-enp8.js +15 -0
  43. package/chunks/RtfConverter-LZPzBDSr.js +15 -0
  44. package/chunks/RtfConverter-_bacXqr1.js +186 -0
  45. package/chunks/TableBorders-CwnF3jvH.js +30 -0
  46. package/chunks/TableGrid-DbroRucl.js +12 -0
  47. package/chunks/TextFileDecoder--rsVs3NR.js +9 -2
  48. package/chunks/{TxtConverter-BYazsp6P.js → TxtConverter-C7FOwHpH.js} +5 -2
  49. package/chunks/UnicodeUtils-CXtusU4g.js +10 -0
  50. package/chunks/XmlConverter-7oo8oeQB.js +2 -0
  51. package/chunks/XmlConverter-DGORHJcZ.js +96 -0
  52. package/chunks/XmlConverter-DeLHReK_.js +2 -0
  53. package/chunks/_commonjsHelpers-DaMA6jEr.js +2 -1
  54. package/chunks/_revise-sdk-lazy-harfbuzz-CDWdjF9f.js +1 -1
  55. package/chunks/_revise-sdk-lazy-harfbuzz-X8gnYTZL.js +1 -1
  56. package/chunks/ar-ComXvtmh.js +13 -0
  57. package/chunks/backend-DecaBz-I.js +490 -0
  58. package/chunks/base64-sSPOzq-u.js +198 -0
  59. package/chunks/browser-module-CFmqfGkE.js +1791 -3
  60. package/chunks/{browser-module-BbaxnHNK.js → browser-module-Dj5o3kuL.js} +1 -1
  61. package/chunks/{browser-module-D2ixluMg.js → browser-module-UuM_O36W.js} +1 -1
  62. package/chunks/bundle.min-DRpfgV69.js +779 -5
  63. package/chunks/capture-1btcWcPF.js +9 -0
  64. package/chunks/carrier-DQeng6yq.js +6 -0
  65. package/chunks/de-BkbpIKxx.js +13 -0
  66. package/chunks/es-CKkXujOF.js +13 -0
  67. package/chunks/fil-piIHMc8F.js +13 -0
  68. package/chunks/footnoteFlatten-DUQticYy.js +6 -0
  69. package/chunks/fr-DuA8qLje.js +13 -0
  70. package/chunks/graftExport-CYnStOdU.js +82 -0
  71. package/chunks/html2canvas.esm-CntiHiYW.js +994 -2
  72. package/chunks/index-2TBhRkX7.js +387 -0
  73. package/chunks/index-BWdRWxoH.js +1796 -13
  74. package/chunks/index-Bf14eTEW.js +1096 -0
  75. package/chunks/index-BwcX_r62.js +387 -0
  76. package/chunks/index.es-CI0QPo8w.js +780 -5
  77. package/chunks/{index.es-B97tjxvW.js → index.es-CI7cDExj.js} +1 -1
  78. package/chunks/{index.es-mTU7Sl3w.js → index.es-DHpGt6Y5.js} +1 -1
  79. package/chunks/ja-DgrSs555.js +13 -0
  80. package/chunks/{jspdf.es.min-Mykp4BZO.js → jspdf.es.min--GshOuIm.js} +1 -1
  81. package/chunks/jspdf.es.min-DU74zN8b.js +1747 -32
  82. package/chunks/{jspdf.es.min-DGiD4mlU.js → jspdf.es.min-DurJZ1zW.js} +1 -1
  83. package/chunks/jszip.min-CPW0h1Kx.js +476 -2
  84. package/chunks/katex-DWj8TvwO.js +1209 -8
  85. package/chunks/pdf-BLWDCiFF.js +1826 -10
  86. package/chunks/pseudoLocale-BoYTjmiK.js +1 -0
  87. package/chunks/pseudoLocale-DG2NnZmz.js +1 -0
  88. package/chunks/purify.es-BwLardii.js +107 -2
  89. package/chunks/serverDocumentSession-CJ1EH3Tp.js +15 -0
  90. package/chunks/signatures-Bwt_OGik.js +17 -0
  91. package/chunks/suggestionAuthorship-B-IuLQlE.js +1 -0
  92. package/chunks/tree-sitter-D6zWWUMP.js +1 -1
  93. package/chunks/web-tree-sitter-BXGZGnNj.js +2 -1
  94. package/chunks/zh-9OF3SWWO.js +13 -0
  95. package/full.js +1 -1
  96. package/index.d.ts +42 -15
  97. package/index.js +1 -1
  98. package/package.json +1 -1
  99. package/root.js +2 -2
  100. package/serverToolContract.d.ts +21 -3
  101. package/serverToolInputs.generated.d.ts +23 -2
  102. package/style.css +1 -1
  103. package/assets/historyMaterializeWorker-C4uxcZEh.js +0 -3
  104. package/chunks/AgentPageRenderer-BIf_Fza8.js +0 -1
  105. package/chunks/AgentPageRenderer-DT9sNxEn.js +0 -1
  106. package/chunks/AttachmentDocumentImporter-BUavYRxO.js +0 -1
  107. package/chunks/AttachmentDocumentImporter-DGwfDJSH.js +0 -1
  108. package/chunks/BidiText-D7LYTAUL.js +0 -1
  109. package/chunks/DocumentMutator-CjN7Kk-X.js +0 -31
  110. package/chunks/DocumentScrubber-C9ZZEcYW.js +0 -1
  111. package/chunks/DocumentStylesheet-byN5dtC6.js +0 -1
  112. package/chunks/DocxConverter-Be3uPNcD.js +0 -11
  113. package/chunks/DocxConverter-CGYMfz-j.js +0 -11
  114. package/chunks/DocxConverter-DabDLfsu.js +0 -11
  115. package/chunks/DocxGraft-Duvo2cpy.js +0 -1
  116. package/chunks/FileImporter-CjUX2S4s.js +0 -1
  117. package/chunks/FileImporter-DtkbI6rF.js +0 -1
  118. package/chunks/HtmlConverter-ikXImzTY.js +0 -61
  119. package/chunks/MarkdownConverter-CFrcLyO_.js +0 -17
  120. package/chunks/MathRenderer-B0Y1h1JU.js +0 -33
  121. package/chunks/OdtConverter-BFT_P8SI.js +0 -1
  122. package/chunks/OdtConverter-Cnda9T0q.js +0 -1
  123. package/chunks/OdtConverter-WdwwXKVM.js +0 -1
  124. package/chunks/PdfConverter-D7UM58vc.js +0 -21
  125. package/chunks/PdfConverter-TB-QPw29.js +0 -21
  126. package/chunks/PdfConverter-wVP63986.js +0 -21
  127. package/chunks/RtfConverter-D-oqPWNl.js +0 -14
  128. package/chunks/RtfConverter-D9zhE07-.js +0 -14
  129. package/chunks/RtfConverter-DZgwU-_R.js +0 -14
  130. package/chunks/TableBorders-BorZS8aZ.js +0 -1
  131. package/chunks/TableGrid-DVWaRZv0.js +0 -1
  132. package/chunks/ar-C8zx2RwP.js +0 -8
  133. package/chunks/backend-MFpDFVrD.js +0 -1
  134. package/chunks/base64-BNMNG-lN.js +0 -1
  135. package/chunks/capture-qC26xmfy.js +0 -1
  136. package/chunks/carrier-BWONvrA7.js +0 -1
  137. package/chunks/de-ByQFqecF.js +0 -8
  138. package/chunks/es-PHpJXv5S.js +0 -8
  139. package/chunks/footnoteFlatten-Bdnn_bz1.js +0 -1
  140. package/chunks/graftExport-CP3h2T88.js +0 -2
  141. package/chunks/index-CjeGoI2g.js +0 -351
  142. package/chunks/index-D7V8zn4w.js +0 -36
  143. package/chunks/index-DyOcu9mD.js +0 -351
  144. package/chunks/pseudoLocale-C90lXrPg.js +0 -1
  145. package/chunks/pseudoLocale-UA_TkGrH.js +0 -1
  146. package/chunks/serverDocumentSession-CRZSb5SO.js +0 -11
  147. package/chunks/signatures-CsL_TjvW.js +0 -1
@@ -0,0 +1,186 @@
1
+ import{C as A,w,aR as q,f as K,aS as U}from"./backend-DecaBz-I.js";import{N as G,k as z,r as $,s as _,a as T,t as k,i as Y,m as X,b as Z,c as J,d as Q,l as tt,f as et,e as st,g as rt,p as nt}from"./OfficeImportShared-BrZoDM0j.js";
2
+ import{f as it}from"./footnoteFlatten-DUQticYy.js";import{a as at,e as ot}from"./ListNumbering-Qlu6AuRZ.js";import{b as lt}from"./TableGrid-DbroRucl.js";const ct={65001:"utf-8",932:"shift_jis",936:"gb\
3
+ 18030",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":
4
+ "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},
5
+ j=new Map;function ut(a,t){let e=j.get(t);if(!e){try{e=new TextDecoder(t)}catch{e=new TextDecoder("windows-1252")}j.set(t,e)}return e.decode(a instanceof Uint8Array?a:new Uint8Array(a))}class L{constructor(t){
6
+ 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","’"],
7
+ ["ldblquote","“"],["rdblquote","”"],["bullet","•"],["emspace"," "],["enspace"," "],["qmspace"," "],["zwj","‍"],["zwnj","‌"],["ltrmark","‎"],["rtlmark","‏"]]),ft=new Set(["info","xm\
8
+ lnstbl","themedata","colorschememapping","latentstyles","datastore","generator","filetbl","rsidtbl","nonshppict","objdata","objclass","objname","shpinst","shptxt","userprops","docvar","pgdsctbl","mmat\
9
+ hPr","bkmkstart","bkmkend","xe","tc","txe","template","private","passwordhash","wgrffmtfilter","defchp","defpap","listpicture","pnseclvl","protusertbl","fchars","lchars","aftnsep","aftnsepc","aftncn",
10
+ "ftnsep","ftnsepc","ftncn","blipuid","picprop","atnicn","atntime","do","falt","panose","fname","oldcprops","oldpprops","oldtprops","oldsprops","annotation-ignore"]),gt=new Set(["expandedcolortbl","lis\
11
+ ttable","listoverridetable","shppict","fldinst","annotation","atnauthor","atnid","atnref","atndate","atrfstart","atrfend","pn","revtbl","footnote"]),mt=new Set(["pict","footnote","annotation","fldinst",
12
+ "fldrslt","header","headerl","headerr","headerf","footer","footerl","footerr","footerf"]),bt=new Set(["ul","uld","uldash","uldashd","uldashdd","uldb","ulhwave","ulldash","ulth","ulthd","ulthdash","ult\
13
+ hdashd","ulthdashdd","ulthldash","ululdbwave","ulw","ulwave"]),W=new Map([["header","default"],["headerr","default"],["headerl","even"],["headerf","first"],["footer","default"],["footerr","default"],[
14
+ "footerl","even"],["footerf","first"]]);function E(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=
15
+ {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=
16
+ null,this.revAuthors=[],this.currentFontEntry=null,this.rowDefs=[],this.pendingCellDef={},this.rowIsHeader=!1,this.body=new L("body"),this.notes=new G("rtffn"),this.headers={},this.footers={},this.comments=
17
+ [],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=
18
+ 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,
19
+ 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().
20
+ length>0)&&this.flushParagraph(t);const e=this.buildBlocks(t.items,"body");O(e),e.length===0&&e.push(A());const s={type:"doc",children:e};this.notes.notes.length>0&&(s.notes=this.notes.notes),Object.keys(
21
+ 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.
22
+ 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(),
23
+ 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===
24
+ 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(
25
+ 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}
26
+ if(i==="-"){r+=2;continue}if(i===`
27
+ `||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&&
28
+ 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]==="'")
29
+ r+=4;else{s.lastIndex=r;const m=s.exec(t);r+=m?m[0].length:2}else{if(f==="{"||f==="}")break;if(f===`
30
+ `||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.
31
+ 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==="fldin\
32
+ st"||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.
33
+ 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!==
34
+ 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&&
35
+ (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.
36
+ 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}
37
+ 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(),
38
+ 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.
39
+ 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.
40
+ 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++)
41
+ 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();_(r,s.runMarks)||(this.flushRun(
42
+ 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.
43
+ 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},
44
+ 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(
45
+ 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:
46
+ 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===
47
+ 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=
48
+ !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)?.
49
+ 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.
50
+ 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&&
51
+ (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??
52
+ 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){
53
+ const r=e!==void 0?this.revAuthors[e]:void 0,n=s!==void 0?V(s):void 0;return Y(t,`rtfrev-${t==="insertion"?"ins":"del"}-${e??0}-${s??0}`,r&&r!=="Unknown"?r:void 0,n)}flushRun(t){t.runText&&(t.runs.push(
54
+ {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.
55
+ suppressEmptyPar=!1,t.listText=void 0,t.paraId=w();return}t.items.push({kind:"para",id:t.paraId,runs:X(s),para:{...this.state.para,borders:{...this.state.para.borders}},...t.listText!==void 0?{listText:t.
56
+ 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)){
57
+ 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"expandedcolort\
58
+ bl":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.
59
+ 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==="t\
60
+ ab"&&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!==
61
+ "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.
62
+ 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=
63
+ "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===
64
+ "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&&
65
+ !/^\s*HYPERLINK\s+\\l\b/i.test(s)&&(e.link=Z(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.
66
+ 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("annotat\
67
+ ion");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 W.has(t)?(e.dest="body",e.opensStory=
68
+ !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.
69
+ 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)){
70
+ const i=this.state;this.state=t,this.flushParagraph(s),this.state=i}const r=this.buildBlocks(s.items,s.kind);O(r);const n=e.storyRef.story;if(s.kind==="footnote"||s.kind==="endnote"){if(e.dest!=="body")
71
+ 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.
72
+ headerWord??"header",o=W.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;
73
+ 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(`
74
+
75
+ `);this.annotationCounter++;const o=this.annotationRef;let c=`rtfcmt-${o??`point-${this.annotationCounter}`}`,d=o!==void 0&&this.commentRangeIds.has(o);if(this.commentIds.has(c)){d=!1;let l=this.annotationCounter;
76
+ for(;this.commentIds.has(`${c}-${l}`);)l++;c=`${c}-${l}`}this.commentIds.add(c),this.comments.push({id:c,author:this.commentMeta.author||this.commentMeta.initials||"Unknown",...this.commentMeta.initials?
77
+ {initials:this.commentMeta.initials}:{},createdAt:new Date(this.annotationDate!==void 0?V(this.annotationDate)??0:0).toISOString(),bodyMd:i,...d?{}:{anchorBlockId:n.paraId}}),this.commentMeta={}}}finishMeta(t,e){
78
+ switch(t){case"atnauthor":this.commentMeta.author=e;break;case"atnid":this.commentMeta.initials=e;break;case"atnref":this.annotationRef=e;break;case"atndate":{const s=parseInt(e,10);Number.isFinite(s)&&
79
+ (this.annotationDate=s);break}case"atrfstart":e&&(this.commentRangeIds.set(e,`rtfcmt-${e}`),this.openCommentRanges=[...this.openCommentRanges,`rtfcmt-${e}`],this.marksVersion++);break;case"atrfend":e&&
80
+ (this.openCommentRanges=this.openCommentRanges.filter(s=>s!==`rtfcmt-${e}`),this.marksVersion++);break}}fontTableWord(t,e){if(t==="f"&&e!==null){const r=this.state.capture;r&&r.text.trim()&&this.currentFontEntry!==
81
+ null&&this.finishFontName(r.text),this.currentFontEntry=e,this.fonts.has(e)||this.fonts.set(e,{name:""}),this.state.capture={text:""};return}const s=this.currentFontEntry!==null?this.fonts.get(this.currentFontEntry):
82
+ void 0;if(s)if(t==="fcharset"&&e!==null){const r=dt[e];r&&(s.encoding=C(r)),e===2&&(s.encoding="windows-1252")}else t==="cpg"&&e!==null&&e>0&&(s.encoding=C(e))}finishFontName(t){if(this.currentFontEntry===
83
+ null)return;const e=this.fonts.get(this.currentFontEntry),s=t.replace(/;$/,"").trim();e&&s&&!e.name&&(e.name=this.cocoa?St(s):s)}colorTableWord(t,e){if(e!==null){if(t==="red")this.colorParts.r=e;else if(t===
84
+ "green")this.colorParts.g=e;else if(t==="blue")this.colorParts.b=e;else return;this.colorHasValue=!0}}styleSheetWord(t,e){const s=this.state;t==="s"&&e!==null?(this.currentStyle={index:e},s.capture={text:""}):
85
+ t==="outlinelevel"&&e!==null&&this.currentStyle&&(this.currentStyle.outlineLevel=e)}finishStyle(t){if(!this.currentStyle)return;const e=t.replace(/;[\s\S]*$/,"").trim();this.styles.set(this.currentStyle.
86
+ index,{name:e,outlineLevel:this.currentStyle.outlineLevel}),this.currentStyle=null}listTableWord(t,e){switch(t){case"list":this.currentList={def:{levels:[]}};break;case"listlevel":this.currentList?.def.
87
+ levels.push({nfc:0,startAt:1});break;case"levelnfc":case"levelnfcn":{const s=this.currentList?.def.levels.at(-1);s&&e!==null&&(s.nfc=e);break}case"levelstartat":{const s=this.currentList?.def.levels.at(
88
+ -1);s&&e!==null&&(s.startAt=e);break}case"listid":this.currentList&&e!==null&&(this.currentList.id=e,this.lists.set(e,this.currentList.def));break}}listOverrideWord(t,e){t==="listoverride"?this.currentOverride=
89
+ {}:t==="listid"&&this.currentOverride&&e!==null?this.currentOverride.listId=e:t==="ls"&&this.currentOverride&&e!==null&&(this.currentOverride.ls=e);const s=this.currentOverride;s?.listId!==void 0&&s.ls!==
90
+ void 0&&this.listOverrides.set(s.ls,s.listId)}pnWord(t,e){const s=this.state.para.pn;if(!s)return;t==="pnlvlblt"?s.kind="bullet":/^pn(dec|ucltr|lcltr|ucrm|lcrm|ord|ordt|cardt)$/.test(t)?s.kind="number":
91
+ t==="pnlvl"&&e!==null&&(s.level=Math.max(0,e-1));const r=this.stack[this.stack.length-1];r&&(r.para.pn={...s})}pictWord(t,e){const s=this.state.pict;if(s)switch(t){case"pngblip":s.format="png";break;case"\
92
+ jpegblip":s.format="jpeg";break;case"emfblip":s.format="emf";break;case"wmetafile":s.format="wmf";break;case"macpict":case"dibitmap":case"wbitmap":case"pmmetafile":s.format??(s.format="unsupported");break;case"\
93
+ picw":e!==null&&(s.picw=e);break;case"pich":e!==null&&(s.pich=e);break;case"picwgoal":e!==null&&(s.goalW=e);break;case"pichgoal":e!==null&&(s.goalH=e);break;case"picscalex":e!==null&&(s.scaleX=e);break;case"\
94
+ picscaley":e!==null&&(s.scaleY=e);break}}finishPicture(t,e){let s;if(t.binary&&t.binary.length>0){const b=t.binary.reduce((u,p)=>u+p.length,0);s=new Uint8Array(b);let h=0;for(const u of t.binary)s.set(
95
+ u,h),h+=u.length}else s=vt(t.hex.join(""));if(s.length===0)return;const r=t.format&&t.format!=="unsupported"?t.format:void 0,n=J(s)??r;if(!n)return;const i=n==="emf"||n==="wmf",o=(t.scaleX??100)/100,c=(t.
96
+ scaleY??100)/100,d=(b,h)=>b?k(b):h?i?h/2540*96:h:void 0,l=d(t.goalW,t.picw),f=d(t.goalH,t.pich),m=e.storyRef.story,M=e.para;if(this.flushRun(m),m.runs.some(b=>b.text.length>0)){const b=this.state;this.
97
+ state=e,this.flushParagraph(m),this.state=b}else m.runs=[];const I=M.align==="justify"?void 0:M.align;m.items.push({kind:"image",image:Q(s,n,{width:l!==void 0?l*o:void 0,height:f!==void 0?f*c:void 0},
98
+ {align:I}),inTable:!!M.inTable}),m.suppressEmptyPar=!0}characterWord(t,e){const s=this.state.chars,r=e!==0;if(bt.has(t))return s.underline=r,!0;switch(t){case"plain":{const{revised:n,deleted:i,revAuthor:o,
99
+ revTime:c,revAuthorDel:d,revTimeDel:l}=s;return this.state.chars={revised:n,deleted:i,revAuthor:o,revTime:c,revAuthorDel:d,revTimeDel:l},!0}case"b":return s.bold=r,!0;case"i":return s.italic=r,!0;case"\
100
+ ulnone":return s.underline=!1,!0;case"strike":return s.strike=r,!0;case"striked":return s.dstrike=r,!0;case"super":return s.superscript=r,s.subscript=!1,!0;case"sub":return s.subscript=r,s.superscript=
101
+ !1,!0;case"nosupersub":return s.superscript=!1,s.subscript=!1,!0;case"caps":return s.caps=r,!0;case"scaps":return s.scaps=r,!0;case"v":return s.hidden=r,!0;case"f":return e!==null&&(s.font=e),!0;case"\
102
+ loch":case"hich":case"dbch":return s.script=t,!0;case"rtlch":case"ltrch":return s.script=void 0,!0;case"af":return e!==null&&(s.script==="loch"||s.script==="hich")&&(s.lochFont=e),!0;case"fs":return e!==
103
+ null&&(s.halfPoints=e),!0;case"fsmilli":return e!==null&&(s.halfPoints=e/1e3*2),!0;case"cf":return s.color=e??0,!0;case"highlight":return s.highlight=e??0,!0;case"cb":case"chcbpat":return s.background=
104
+ e??0,!0;case"expndtw":return s.expandTwips=e??0,!0;case"expnd":return s.expandTwips===void 0&&e!==null&&(s.expandTwips=e*5),!0;case"revised":return s.revised=r,!0;case"deleted":return s.deleted=r,!0;case"\
105
+ revauth":return e!==null&&(s.revAuthor=e),!0;case"revdttm":return e!==null&&(s.revTime=e),!0;case"revauthdel":return e!==null&&(s.revAuthorDel=e),!0;case"revdttmdel":return e!==null&&(s.revTimeDel=e),
106
+ !0;default:return!1}}paragraphWord(t,e){const s=this.state.para;switch(t){case"pard":return this.state.para={borders:{}},!0;case"qc":return s.align="center",!0;case"qr":return s.align="right",!0;case"\
107
+ qj":case"qd":return s.align="justify",!0;case"ql":return s.align=void 0,!0;case"li":case"lin":return e!==null&&(s.leftTwips=e),!0;case"fi":return e!==null&&(s.firstTwips=e),!0;case"sb":return e!==null&&
108
+ (s.spaceBeforeTwips=e),!0;case"sa":return e!==null&&(s.spaceAfterTwips=e),!0;case"sl":return s.lineTwips=e??0,!0;case"slmult":return s.lineMultiple=e===1,!0;case"keepn":return s.keepNext=e!==0,!0;case"\
109
+ keep":return s.keepLines=e!==0,!0;case"rtlpar":return s.rtl=!0,!0;case"ltrpar":return s.rtl=!1,!0;case"s":return e!==null&&(s.style=e),!0;case"outlinelevel":return e!==null&&(s.outlineLevel=e),!0;case"\
110
+ intbl":return s.inTable=e!==0,!0;case"itap":return e!==null&&(s.inTable=e>0),!0;case"ls":return e!==null&&(s.ls=e),!0;case"ilvl":return e!==null&&(s.ilvl=e),!0;case"cbpat":return e!==null&&(s.shading=
111
+ e),!0;case"pagebb":return s.pageBreakBefore=e!==0,!0;case"brdrt":case"brdrb":case"brdrl":case"brdrr":case"box":{const r=t==="box"?["top","bottom","left","right"]:[{brdrt:"top",brdrb:"bottom",brdrl:"le\
112
+ ft",brdrr:"right"}[t]];for(const n of r)s.borders[n]={style:"single",width:1,color:"#000000"};return s.borderTarget=t==="box"?"box":r[0],!0}case"brdrs":case"brdrth":case"brdrsh":case"brdrdb":case"brdr\
113
+ dash":case"brdrdashsm":case"brdrdot":case"brdrnone":case"brdrw":case"brdrcf":{const r=s.borderTarget;if(!r||r==="ignore")return!0;const n=r==="box"?["top","bottom","left","right"]:[r];for(const i of n){
114
+ const o=s.borders[i];o&&(t==="brdrnone"?delete s.borders[i]:t==="brdrdb"?o.style="double":t==="brdrdash"||t==="brdrdashsm"?o.style="dashed":t==="brdrdot"?o.style="dotted":t==="brdrth"?(o.style="single",
115
+ o.width=Math.max(o.width,2)):t==="brdrw"&&e!==null?o.width=Math.min(8,Math.max(1,Math.round(e/15))):t==="brdrcf"&&e!==null?o.color=this.colors[e]??o.color:(t==="brdrs"||t==="brdrsh")&&(o.style="single"))}
116
+ return!0}default:return/^(tr|cl|pg)brdr[tblrhv]$|^brdrbtw$|^brdrbar$/.test(t)?(s.borderTarget="ignore",!(t.startsWith("cl")||t.startsWith("tr"))):!1}}structureWord(t,e){const s=this.state.storyRef.story,
117
+ r=this.state.dest==="body";switch(t){case"par":r&&this.flushParagraph(s);return;case"sect":r&&(s.runs.length>0||s.runText)&&this.flushParagraph(s),this.sectionSeen=!0;return;case"line":this.text(`
118
+ `);return;case"tab":this.text(" ");return;case"page":if(!r||s.kind!=="body")return;this.flushRun(s),s.runs.some(n=>n.text.length>0)&&this.flushParagraph(s),s.runs=[],s.items.push({kind:"pagebreak",inTable:!!this.
119
+ state.para.inTable}),s.suppressEmptyPar=!0;return;case"cell":case"nestcell":if(!r)return;this.flushParagraph(s,!0),t==="cell"&&s.items.push({kind:"cell"});return;case"row":if(!r)return;this.flushRun(s),
120
+ s.runs.some(n=>n.text.length>0)&&(this.flushParagraph(s,!0),s.items.push({kind:"cell"})),s.runs=[],s.items.push({kind:"row",defs:this.rowDefs.slice(),header:this.rowIsHeader});return;case"trowd":this.
121
+ rowDefs=[],this.pendingCellDef={},this.rowIsHeader=!1;return;case"trhdr":this.rowIsHeader=!0;return;case"clmgf":this.pendingCellDef.hmergeFirst=!0;return;case"clmrg":this.pendingCellDef.hmergeCont=!0;
122
+ return;case"clvmgf":this.pendingCellDef.vmergeFirst=!0;return;case"clvmrg":this.pendingCellDef.vmergeCont=!0;return;case"clcbpat":e!==null&&(this.pendingCellDef.background=e);return;case"clvertalt":this.
123
+ pendingCellDef.valign="top";return;case"clvertalc":this.pendingCellDef.valign="middle";return;case"clvertalb":this.pendingCellDef.valign="bottom";return;case"cellx":e!==null&&(this.rowDefs.push({right:e,
124
+ ...this.pendingCellDef}),this.pendingCellDef={});return;case"chftn":case"chatn":case"chpgn":t==="chpgn"&&r&&s.kind==="header"&&(this.state.fieldKind="page",this.marksVersion++,this.text("1"),this.state.
125
+ fieldKind=void 0,this.marksVersion++);return;case"ftnalt":s.kind==="footnote"&&(s.kind="endnote");return;case"uc":this.state.unicodeSkip=e??1;return;case"deff":e!==null&&(this.defaultFont=e);return;case"\
126
+ paperw":case"pgwsxn":e!==null&&(!this.sectionSeen||this.page.widthTwips===void 0)&&(this.page.widthTwips=e);return;case"paperh":case"pghsxn":e!==null&&(!this.sectionSeen||this.page.heightTwips===void 0)&&
127
+ (this.page.heightTwips=e);return;case"landscape":case"lndscpsxn":this.page.landscape=!0;return;case"margl":case"margr":case"margt":case"margb":case"marglsxn":case"margrsxn":case"margtsxn":case"margbsx\
128
+ n":{if(e===null)return;const n=t.slice(4,5);if(t.endsWith("sxn")&&this.sectionSeen)return;this.page.margins[n]=e;return}default:{const n=pt.get(t);n!==void 0&&this.text(n)}}}buildBlocks(t,e){const s=[],
129
+ r=i=>i.kind==="cell"||i.kind==="row"||i.kind==="para"&&(!!i.para.inTable||!!i.forcedInTable)||(i.kind==="image"||i.kind==="pagebreak")&&i.inTable;let n=0;for(;n<t.length;){const i=t[n];if(e!=="header"&&
130
+ r(i)){const o=n;for(;n<t.length&&r(t[n]);)n++;const c=this.buildTable(t.slice(o,n),e);c&&s.push(...c);continue}if(i.kind==="para"){const o=this.listInfo(i);if(o&&e!=="header"){const c=[{item:i,info:o}];
131
+ for(n++;n<t.length;){const d=t[n];if(d.kind!=="para"||r(d))break;const l=this.listInfo(d);if(!l||l.key!==o.key)break;c.push({item:d,info:l}),n++}s.push(this.buildList(c));continue}i.para.pageBreakBefore&&
132
+ e==="body"&&s.length>0&&s.push({type:"page-break",id:w()}),s.push(this.buildParagraph(i,e)),n++;continue}i.kind==="image"?s.push(i.image):i.kind==="pagebreak"&&s.push({type:"page-break",id:w()}),n++}return s}buildParagraph(t,e){
133
+ const s=t.runs.length>0?t.runs:[{type:"text",text:"",marks:{}}],r=A(s);r.id=t.id;const n=t.para;if(n.align&&(r.align=n.align),n.rtl&&(r.direction="rtl"),e!=="header"){const i=this.headingLevel(n);if(i&&
134
+ (r.heading=i),n.leftTwips!==void 0){const c=tt(k(n.leftTwips));c&&(r.leftIndent=c)}if(n.firstTwips!==void 0){const c=et(k(n.firstTwips));c&&(r.firstLineIndent=c)}n.spaceBeforeTwips!==void 0&&(r.spaceBefore=
135
+ T(k(Math.max(0,n.spaceBeforeTwips)))),n.spaceAfterTwips!==void 0&&(r.spaceAfter=T(k(Math.max(0,n.spaceAfterTwips)))),n.lineMultiple&&n.lineTwips&&n.lineTwips>0&&(r.lineSpacing=T(n.lineTwips/240)),n.keepNext&&
136
+ (r.keepNext=!0),n.keepLines&&(r.keepLines=!0);const o=n.shading?this.colors[n.shading]:void 0;o&&o!=="#ffffff"&&(r.shading=o),Object.keys(n.borders).length>0&&(r.borders=JSON.stringify(n.borders))}return r}headingLevel(t){
137
+ let e;if(t.outlineLevel!==void 0&&t.outlineLevel<9&&(e=t.outlineLevel+1),e===void 0&&t.style!==void 0){const s=this.styles.get(t.style),r=s?.name&&/^heading\s*(\d)$/i.exec(s.name);r?e=parseInt(r[1],10):
138
+ s?.outlineLevel!==void 0&&s.outlineLevel<9&&(e=s.outlineLevel+1)}if(!(!e||e<1))return Math.min(e,6)}listInfo(t){const e=t.para;if(!this.headingLevel(e)){if(e.ls!==void 0&&e.ls>0){const s=this.listOverrides.
139
+ get(e.ls),r=s!==void 0?this.lists.get(s):void 0,n=Math.max(0,Math.min(8,e.ilvl??0));if(r){const i=r.levels[n]??r.levels[0];if(i&&i.nfc===255&&t.listText===void 0)return;const o=i?i.nfc!==23&&i.nfc!==255:
140
+ !1;return{key:`ls${e.ls}`,ordered:o,level:n,startAt:r.levels[0]?.startAt??1,chain:`rtf-ls-${e.ls}`}}return{key:`ls${e.ls}`,ordered:t.listText!==void 0&&F(t.listText),level:n,startAt:1,chain:`rtf-ls-${e.
141
+ ls}`}}if(e.pn)return{key:`pn-${e.pn.kind}`,ordered:e.pn.kind==="number",level:e.pn.level,startAt:1};if(t.listText!==void 0&&t.listText.trim()!==""){const s=F(t.listText);return{key:`lt-${s}`,ordered:s,
142
+ level:0,startAt:1}}}}buildList(t){const e=t[0].info,s=t.map(({item:i,info:o})=>{const c=i.runs.length>0?i.runs:[{type:"text",text:"",marks:{}}];return{type:"list-item",id:i.id,children:c,...o.level>0?
143
+ {indentLevel:o.level}:{},...i.para.rtl?{direction:"rtl"}:{}}}),r={type:"list",id:w(),variant:e.ordered?"ordered":"unordered",children:s};e.ordered&&e.chain?(r.numberingChainId=e.chain,this.chainsSeen.
144
+ has(e.chain)||(this.chainsSeen.add(e.chain),e.startAt!==1&&(r.startNumber=e.startAt))):e.ordered&&e.startAt!==1&&(r.startNumber=e.startAt);const n=t[0].item.para;return n.spaceAfterTwips!==void 0&&(r.
145
+ spaceAfter=T(k(Math.max(0,n.spaceAfterTwips)))),n.spaceBeforeTwips!==void 0&&(r.spaceBefore=T(k(Math.max(0,n.spaceBeforeTwips)))),n.lineMultiple&&n.lineTwips&&n.lineTwips>0&&(r.lineSpacing=T(n.lineTwips/
146
+ 240)),r}buildTable(t,e){const s=[];let r=[],n=[],i=[];for(const h of t)h.kind==="cell"?(r.push({items:n}),n=[]):h.kind==="row"?(n.length>0&&(r.push({items:n}),n=[]),s.push({cells:r,defs:h.defs.length>
147
+ 0?h.defs:i,header:h.header}),h.defs.length>0&&(i=h.defs),r=[]):n.push(h);if(n.length>0&&r.push({items:n}),r.length>0&&s.push({cells:r,defs:i,header:!1}),s.length===0)return null;const o=new Set([0]),c=s.
148
+ map(h=>{const u=[];let p=0,g=0;const P=h.defs.length>0?h.defs[h.defs.length-1].right/Math.max(1,h.defs.length):1440;return h.cells.forEach((R,S)=>{const x=h.defs[S],v=x?x.right:g+Math.max(1,Math.round(
149
+ P));if(x?.hmergeCont&&u.length>0){const N=u[u.length-1];N.right=v,N.items.push(...R.items.filter(H=>!wt(H)))}else u.push({left:p,right:Math.max(v,p+1),def:x,items:R.items});p=v,g=v}),u}),d=0;for(const h of c)
150
+ for(const u of h)o.add(Math.max(d,u.left)),o.add(u.right);const l=xt(yt([...o].sort((h,u)=>h-u),30),st(c.length)),f=h=>{let u=0,p=l.length-1;for(;u<p;){const g=u+p>>1;l[g]<h?u=g+1:p=g}return u>0&&Math.
151
+ abs(l[u-1]-h)<=Math.abs(l[u]-h)?u-1:u},m=[],M=new Map;c.forEach(h=>{const u=[];for(const p of h){const g=f(p.left),P=Math.max(g+1,f(p.right));if(p.def?.vmergeCont){const v=M.get(g);if(v){v.rowSpan=(v.
152
+ rowSpan??1)+1;continue}}const R=this.buildBlocks(p.items.map(v=>Tt(v)),e);Mt(R);const S={type:"table-cell",id:w(),children:R.length>0?R:[A()]};P-g>1&&(S.colSpan=P-g);const x=p.def?.background?this.colors[p.
153
+ def.background]:void 0;x&&x!=="#ffffff"&&(S.backgroundColor=x),p.def?.valign&&p.def.valign!=="top"&&(S.verticalAlign=p.def.valign),p.def?.vmergeFirst?M.set(g,S):M.delete(g),u.push(S)}m.push({type:"tab\
154
+ le-row",id:w(),children:u})});const I=[];for(let h=1;h<l.length;h++)I.push(l[h]-l[h-1]);const b=rt(m,{columnWidths:I,hasHeader:s[0]?.header});return b?[b]:null}pageLayout(){const t=this.page,e=s=>t.margins[s]!==
155
+ void 0?k(t.margins[s]):void 0;return nt({widthPx:t.widthTwips?k(t.widthTwips):void 0,heightPx:t.heightTwips?k(t.heightTwips):void 0,landscape:t.landscape,marginTopPx:e("t"),marginRightPx:e("r"),marginBottomPx:e(
156
+ "b"),marginLeftPx:e("l")})}}function F(a){const t=a.replace(/[\t\s]+/g,"");return/^(\d+|[a-zA-Z]|[ivxlcdm]+|[IVXLCDM]+)[.)]?$/.test(t)&&t.length>0}function vt(a){const t=a.replace(/[^0-9a-fA-F]/g,""),
157
+ e=new Uint8Array(t.length>>1);for(let s=0;s<e.length;s++)e[s]=parseInt(t.slice(s*2,s*2+2),16);return e}function yt(a,t){const e=[];for(const s of a)(e.length===0||s-e[e.length-1]>t)&&e.push(s);return e}
158
+ function xt(a,t){if(a.length-1<=t)return a;const e=a.length-1,s=[];for(let r=0;r<=t;r++)s.push(a[Math.round(r*e/t)]);return s}function wt(a){return a.kind==="para"&&a.runs.every(t=>t.text.trim()==="")}
159
+ function Tt(a){return a.kind==="para"?{...a,forcedInTable:!1,para:{...a.para,inTable:!1}}:a.kind==="image"||a.kind==="pagebreak"?{...a,inTable:!1}:a}function B(a){return a.type==="paragraph"&&!a.borders&&
160
+ a.children.every(t=>t.text.trim()===""&&!t.marks?.footnoteRef)}function O(a){for(;a.length>0&&B(a[0]);)a.shift();for(;a.length>0&&B(a[a.length-1]);)a.pop()}function Mt(a){for(;a.length>1&&B(a[a.length-
161
+ 1]);)a.pop()}function V(a){const t=a>>>0;if(t===0)return;const e=t&63,s=t>>>6&31,r=t>>>11&31,n=t>>>16&15,i=(t>>>20&511)+1900;if(!(n<1||n>12||r<1))return Date.UTC(i,n-1,r,s,e)}function St(a){if(a.startsWith(
162
+ "."))return"";if(/\s/.test(a))return a;let t=a.replace(/-(Regular|Roman|Book|Bold|Italic|Oblique|BoldItalic|BoldOblique|Light|LightItalic|Medium|MediumItalic|Semibold|SemiBold|SemiboldItalic|Heavy|Black|Condensed|Thin|UltraLight)$/,
163
+ "");return t=t.replace(/(PSMT|PS|MT)$/,""),t=t.replace(/([a-z])([A-Z])/g,"$1 $2"),t}const D=class{static async parseFile(t){const e=new Uint8Array(await t.arrayBuffer());let s="";const r=32768;for(let n=0;n<
164
+ e.length;n+=r)s+=String.fromCharCode.apply(null,Array.from(e.subarray(n,n+r)));return E(s,{binary:!0})}static fromRtf(t){return E(t)}static toRtf(t){t=it(t),this.exportListNumbering=at(t);const e=[];for(const s of t.
165
+ children){const r=this.blockToRtf(s,t);r!==null&&e.push(r)}return this.exportListNumbering=null,`{\\rtf1\\ansi\\ansicpg1252\\deff0\\uc1{\\fonttbl{\\f0\\froman Times New Roman;}{\\f1\\fmodern Courier New;}}
166
+ \\f0\\fs24
167
+ `+e.join(`
168
+ `)+`
169
+ }`}static blockToRtf(t,e){switch(t.type){case"paragraph":return U(t)?"\\pard\\brdrb\\brdrs\\brdrw15 \\par":this.paragraphToRtf(t);case"list":return this.listToRtf(t);case"table":return this.tableToRtf(
170
+ t);case"code":return"\\pard{\\f1\\fs20 "+y(t.content).replace(/\n/g,"\\line ")+"}\\par";case"math":return"\\pard "+y(t.content)+"\\par";case"toc":{const s=q(e,K(t));return s.length===0?null:s.map(r=>`\
171
+ \\pard${t.direction==="rtl"?"\\rtlpar":"\\ltrpar"}${t.align==="justify"?"\\qj":t.align==="center"?"\\qc":(t.align??(t.direction==="rtl"?"right":"left"))==="right"?"\\qr":"\\ql"}\\${t.direction==="rtl"?
172
+ "ri":"li"}${(r.level-1)*360} `+y(r.text)+"\\par").join(`
173
+ `)}case"image":return"\\pard{\\i [Image"+(t.alt?`: ${y(t.alt)}`:"")+"]}\\par";case"page-break":return"\\page";case"container":return t.children.map(s=>this.blockToRtf(s,e)).filter(s=>s!==null).join(`
174
+ `);default:return null}}static paragraphToRtf(t){let e="\\pard";t.align==="center"?e+="\\qc":t.align==="right"?e+="\\qr":t.align==="justify"&&(e+="\\qj");let s=this.inlineNodesToRtf(t.children);return t.
175
+ heading&&(s=`{\\b\\fs${this.HEADING_HALF_POINTS[t.heading-1]} ${s}}`),`${e} ${s}\\par`}static listToRtf(t){const e=this.exportListNumbering?.get(t.id);let s=e?ot(e):t.startNumber??1;const r=[];for(const n of t.
176
+ children){if(n.type!=="list-item")continue;const i=((n.indentLevel??0)+1)*360;let o;t.variant==="ordered"?(o=`${s}. `,s++):t.variant==="todo"?o=n.checked?"[x] ":"[ ] ":o="\\bullet ",r.push(`\\pard\\li${i}\
177
+ ${o}`+this.inlineNodesToRtf(n.children)+"\\par")}return r.join(`
178
+ `)}static tableToRtf(t){if(!t.children||t.children.length===0)return"";const e=lt(t),s=9360,r=[];for(let n=0;n<e.rows;n++){const i=["\\trowd\\trgaph108"];for(let o=0;o<e.cols;o++)i.push(`\\cellx${Math.
179
+ round(s*(o+1)/e.cols)}`);for(let o=0;o<e.cols;o++){const c=e.occupancy[n][o];let d="";c&&c.row===n&&c.col===o&&(d=c.cell.children.map(l=>l.type==="paragraph"?this.inlineNodesToRtf(l.children):l.type===
180
+ "code"?y(l.content):"").filter(l=>l.length>0).join("\\line ")),i.push(`\\pard\\intbl ${d}\\cell`)}i.push("\\row"),r.push(i.join(""))}return r.join(`
181
+ `)+`
182
+ \\pard`}static inlineNodesToRtf(t){return t.map(e=>this.textNodeToRtf(e)).join("")}static textNodeToRtf(t){if(t.marks?.footnoteRef)return`{\\super ${y(t.text)}}`;const e=y(t.text).replace(/\n/g,"\\line\
183
+ ");if(!t.marks)return e;const s=[];t.marks.bold&&s.push("\\b"),t.marks.italic&&s.push("\\i"),t.marks.underline&&s.push("\\ul"),t.marks.strikethrough&&s.push("\\strike"),t.marks.superscript&&s.push("\\\
184
+ super"),t.marks.subscript&&s.push("\\sub"),t.marks.code&&s.push("\\f1");const r=s.length>0?`{${s.join("")} ${e}}`:e;return t.marks.link?`{\\field{\\*\\fldinst HYPERLINK "${y(t.marks.link)}"}{\\fldrslt ${r}\
185
+ }}`:r}};D.exportListNumbering=null,D.HEADING_HALF_POINTS=[32,28,26,24,22,22];let Rt=D;function y(a){let t="";for(let e=0;e<a.length;e++){const s=a[e];if(s==="\\"||s==="{"||s==="}"){t+="\\"+s;continue}
186
+ const r=a.charCodeAt(e);if(r<128){t+=s;continue}t+=`\\u${r>32767?r-65536:r}?`}return t}export{Rt as RtfConverter,y as escapeRtfText};
@@ -0,0 +1,30 @@
1
+ import{k as N}from"./backend-DecaBz-I.js";const g="#C0C0C0",p=.3,$=.5,z=.7;function y(t){if(typeof t!="string"||t.trim()==="")return null;let o;try{const i=JSON.parse(t);if(typeof i=="string")o={text:i};else if(i&&
2
+ typeof i=="object"&&typeof i.text=="string")o=i;else return null}catch{o={text:t}}const e=o.text.trim();if(!e)return null;const n=typeof o.opacity=="number"&&o.opacity>=0&&o.opacity<=1?o.opacity:p,r=typeof o.
3
+ fontSizePx=="number"&&o.fontSizePx>0?o.fontSizePx:void 0;return{text:e,color:typeof o.color=="string"&&o.color.trim()!==""?o.color:g,opacity:n,diagonal:o.diagonal!==!1,...r!==void 0?{fontSizePx:r}:{}}}
4
+ function x(t){const o={text:t.text};return typeof t.color=="string"&&t.color.trim()!==""&&t.color.toUpperCase()!==g&&(o.color=t.color),typeof t.opacity=="number"&&t.opacity>=0&&t.opacity<=1&&t.opacity!==
5
+ p&&(o.opacity=t.opacity),t.diagonal===!1&&(o.diagonal=!1),typeof t.fontSizePx=="number"&&t.fontSizePx>0&&(o.fontSizePx=t.fontSizePx),JSON.stringify(o)}function P(t){if(t==null)return null;const o=y(t);
6
+ return o?x(o):null}function C(t,o,e,n){if(t.fontSizePx)return t.fontSizePx;const r=Math.hypot(o,e)*z,i=100;let s=0;try{s=n(t.text,i)}catch{s=0}(!Number.isFinite(s)||s<=0)&&(s=t.text.length*i*.6);const c=i*
7
+ r/s;return Math.max(12,Math.min(400,c))}function k(t,o){return Math.max(1,t-o.left-o.right)}const F=new Set(["single","dashed","dotted","double","none"]),L=24,m=200;function O(t){if(typeof t!="object"||
8
+ t===null)return;const o=t,e=typeof o.style=="string"&&F.has(o.style)?o.style:"single",n=Number(o.width),r=Number.isFinite(n)?Math.min(Math.max(0,n),L):1,i=typeof o.color=="string"&&o.color.trim().length>
9
+ 0?o.color.trim():"#cccccc";return{style:e,width:r,color:i}}const a=new Map,h=new Map;function w(t,o){let e;try{e=JSON.parse(t)}catch{return null}if(typeof e!="object"||e===null)return null;const n=e,r={},
10
+ i=o?["top","bottom","left","right","insideH","insideV"]:["top","bottom","left","right"];let s=!1;for(const c of i){const l=O(n[c]);l&&(r[c]=l,s=!0)}return s?r:null}function T(t){if(!t)return;let o=a.get(
11
+ t);return o===void 0&&(o=w(t,!0),a.size>500&&a.clear(),a.set(t,o)),o??void 0}function J(t){if(!t)return;const o=`cell:${t}`;let e=a.get(o);return e===void 0&&(e=w(t,!1),a.size>500&&a.clear(),a.set(o,e)),
12
+ e??void 0}function v(t){if(!t)return;let o=h.get(t);return o===void 0&&(o=(()=>{let e;try{e=JSON.parse(t)}catch{return null}if(typeof e!="object"||e===null)return null;const n=e,r=u=>{const f=Number(n[u]);
13
+ return Number.isFinite(f)?Math.min(Math.max(0,f),m):void 0},i=r("top"),s=r("right"),c=r("bottom"),l=r("left");return i===void 0&&s===void 0&&c===void 0&&l===void 0?null:{top:i??0,right:s??0,bottom:c??
14
+ 0,left:l??0}})(),h.size>500&&h.clear(),h.set(t,o)),o??void 0}function M(t){const o={};for(const e of["top","bottom","left","right","insideH","insideV"]){const n=t[e];n&&(o[e]={style:n.style,width:n.width,
15
+ color:n.color})}return Object.keys(o).length>0?JSON.stringify(o):void 0}function j(t){const o=e=>Number.isFinite(e)?Math.min(Math.max(0,e),m):0;if(!(t.top===void 0&&t.right===void 0&&t.bottom===void 0&&
16
+ t.left===void 0))return JSON.stringify({top:o(t.top),right:o(t.right),bottom:o(t.bottom),left:o(t.left)})}function H(t,o){const e=v(o);if(e)return e;const n=Number.isFinite(t)?Math.max(0,Math.round(t)):
17
+ 8;return{top:n,right:n,bottom:n,left:n}}function V(t){const{tableBorders:o,cellBorders:e,flags:n,fallback:r}=t,i=(s,c,l)=>(s?o?.[c]:o?.[l])??r;return{top:e?.top??i(n.isTopRow,"top","insideH"),bottom:e?.
18
+ bottom??i(n.isBottomRow,"bottom","insideH"),left:e?.left??i(n.isLeftCol,"left","insideV"),right:e?.right??i(n.isRightCol,"right","insideV")}}function S(t){const o=Math.max(1,t.width);return t.style===
19
+ "dashed"?[o*3,o*2]:t.style==="dotted"?[o,o*1.5]:[]}function B(t,o,e,n,r,i){if(o.style==="none"||o.width<=0)return;t.save(),t.strokeStyle=o.color;const s=S(o);if(s.length>0&&t.setLineDash(s),o.style===
20
+ "double"){const c=Math.max(o.width/3,.5),l=o.width-c;t.lineWidth=c;const u=n===i,f=u?0:l/2,d=u?l/2:0;t.beginPath(),t.moveTo(e-f,n-d),t.lineTo(r-f,i-d),t.moveTo(e+f,n+d),t.lineTo(r+f,i+d),t.stroke()}else
21
+ t.lineWidth=o.width,t.beginPath(),t.moveTo(e,n),t.lineTo(r,i),t.stroke();t.restore()}const R={single:"solid",dashed:"dashed",dotted:"dotted",double:"double",none:"none"};function W(t){return t.style===
22
+ "none"||t.width<=0?"none":`${t.width}px ${R[t.style]} ${t.color}`}function b(t){if(!t)return;const o=t.trim();if(!o)return;if(/(?:^|\s)(none|hidden)(?=\s|$)/i.test(o)||/^0(?:\.0+)?(?:px|pt)?$/i.test(o))
23
+ return{style:"none",width:0,color:"#000000"};const e=o.match(/\b(solid|dashed|dotted|double)\b/i);if(!e)return;const n=e[1].toLowerCase()==="solid"?"single":e[1].toLowerCase(),r=o.match(/\b([\d.]+)\s*(px|pt)\b/i);
24
+ let i=1;if(r){const l=Number(r[1]);if(Number.isFinite(l)){const u=r[2].toLowerCase()==="pt"?l*4/3:l;i=Math.min(Math.max(0,u),24)}}const s=o.replace(e[0]," ").replace(r?.[0]??""," ").trim(),c=s?N(s):"#\
25
+ cccccc";if(c)return{style:n,width:i,color:c}}function D(t){return t.top===t.right&&t.top===t.bottom&&t.top===t.left?`${t.top}px`:`${t.top}px ${t.right}px ${t.bottom}px ${t.left}px`}function E(t){if(!t)
26
+ return;const o=t.trim().split(/\s+/);if(o.length===0||o.length>4)return;const e=[];for(const c of o){const l=c.match(/^([\d.]+)(px)?$/i);if(!l)return;const u=Number(l[1]);if(!Number.isFinite(u))return;
27
+ e.push(Math.min(Math.max(0,u),m))}const[n,r=n,i=n,s=r]=e;return{top:n,right:r,bottom:i,left:s}}function q(t){return t.style==="single"&&t.width===1&&(t.color.toLowerCase()==="#ccc"||t.color.toLowerCase()===
28
+ "#cccccc")}function A(t){if(!t)return;const o=i=>{const s=t.match(new RegExp(`(?:^|;)\\s*${i}\\s*:\\s*([^;]+)`,"i"));return s?s[1].trim():void 0},e=b(o("border")),n={};let r=!1;for(const i of["top","r\
29
+ ight","bottom","left"]){const s=b(o(`border-${i}`))??e;s&&(n[i]=s,q(s)||(r=!0))}if(r)return n}function G(t){return t?M(t):void 0}export{$ as W,T as a,J as b,W as c,v as d,D as e,G as f,A as g,E as h,j as i,
30
+ x as j,y as k,p as l,C as m,P as n,S as o,b as p,V as q,H as r,M as s,k as t,B as u};
@@ -0,0 +1,12 @@
1
+ const M=r=>Math.max(1,Math.floor(r.colSpan??1)),S=r=>Math.max(1,Math.floor(r.rowSpan??1));function x(r){return r.children.reduce((h,t)=>h+M(t),0)}function y(r){const h=r.children.length;let t=r.columnWidths?.
2
+ length??0;for(const c of r.children)t=Math.max(t,x(c));t=Math.max(t,1);const i=Array.from({length:h},()=>new Array(t).fill(void 0)),n=[],f=new Map;for(let c=0;c<h;c++){const p=r.children[c];let e=0;for(let l=0;l<
3
+ p.children.length;l++){const w=p.children[l];for(;e<t&&i[c][e]!==void 0;)e++;if(e>=t)break;const u=Math.min(M(w),t-e),m=Math.min(S(w),h-c),o={cell:w,row:c,col:e,rowSpan:m,colSpan:u,physicalIndex:l};n.
4
+ push(o),f.set(w.id,o);for(let a=c;a<c+m;a++)for(let s=e;s<e+u;s++)i[a][s]===void 0&&(i[a][s]=o);e+=u}}return{rows:h,cols:t,cells:n,byId:f,occupancy:i}}function b(r,h){let{top:t,left:i,bottom:n,right:f}=h;
5
+ t=Math.max(0,Math.min(t,r.rows-1)),n=Math.max(t,Math.min(n,r.rows-1)),i=Math.max(0,Math.min(i,r.cols-1)),f=Math.max(i,Math.min(f,r.cols-1));let c=!0;for(;c;){c=!1;for(let p=t;p<=n;p++)for(let e=i;e<=f;e++){
6
+ const l=r.occupancy[p][e];l&&(l.row<t&&(t=l.row,c=!0),l.col<i&&(i=l.col,c=!0),l.row+l.rowSpan-1>n&&(n=l.row+l.rowSpan-1,c=!0),l.col+l.colSpan-1>f&&(f=l.col+l.colSpan-1,c=!0))}}return{top:t,left:i,bottom:n,
7
+ right:f}}function g(r,h){let t=r.filter(n=>Number.isFinite(n)&&n>0);if(t.length>h&&(t=t.slice(0,h)),t.length<h){const n=t.reduce((p,e)=>p+e,0),f=h-t.length,c=n>0?n/Math.max(t.length,1):100/h;t=t.concat(
8
+ Array(f).fill(c))}const i=t.reduce((n,f)=>n+f,0);return i<=0?Array(h).fill(100/h):Math.abs(i-100)<.01?t:t.map(n=>n/i*100)}function A(r,h,t,i){const n=g(t,r.cols).map(o=>h*o/100),f=[];let c=0;for(const o of n)
9
+ f.push(c),c+=o;const p=o=>{let a=0;for(let s=o.col;s<o.col+o.colSpan;s++)a+=n[s]??0;return a},e=new Map;for(const o of r.cells)e.set(o.cell.id,i(o.cell,p(o)));const l=[];for(let o=0;o<r.rows;o++){let a=0;
10
+ for(const s of r.cells)s.row===o&&s.rowSpan===1&&(a=Math.max(a,e.get(s.cell.id)??0));l.push(a)}const w=r.cells.filter(o=>o.rowSpan>1).sort((o,a)=>o.rowSpan-a.rowSpan);for(const o of w){let a=0;for(let d=o.
11
+ row;d<o.row+o.rowSpan;d++)a+=l[d]??0;const s=(e.get(o.cell.id)??0)-a;s>0&&(l[o.row+o.rowSpan-1]+=s)}const u=[];let m=0;for(const o of l)u.push(m),m+=o;return{colLefts:f,colWidths:n,rowTops:u,rowHeights:l,
12
+ totalHeight:m,cellWidth:p,measuredCellHeight:o=>e.get(o.cell.id)??0,cellHeight:o=>{let a=0;for(let s=o.row;s<o.row+o.rowSpan;s++)a+=l[s]??0;return a}}}export{y as b,A as c,b as e,g as n};
@@ -1,2 +1,9 @@
1
- const f=["shift_jis","gb18030","big5","euc-kr","windows-1251","windows-1256","windows-1252"];function p(t){return/charset\s*=\s*["']?([^;"'\s]+)/i.exec(t)?.[1]??null}function w(t){const n=new TextDecoder("windows-1252").decode(t.subarray(0,2048));return/<meta[^>]+charset\s*=\s*["']?([^\s"'/>;]+)/i.exec(n)?.[1]??/<meta[^>]+content\s*=\s*["'][^"']*charset\s*=\s*([^\s"';]+)/i.exec(n)?.[1]??null}function u(t,n,c=!0){try{return new TextDecoder(n,{fatal:c}).decode(t)}catch{return null}}function l(t){let n=0;const c=new Map;for(const r of t){r==="�"?n-=100:/\p{L}|\p{N}/u.test(r)&&(n+=1);for(const[s,e]of[["cjk",/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u],["hangul",/\p{Script=Hangul}/u],["cyrillic",/\p{Script=Cyrillic}/u],["arabic",/\p{Script=Arabic}/u]])e.test(r)&&c.set(s,(c.get(s)??0)+1);const i=r.codePointAt(0)??0;(i<32&&!`
2
- \r `.includes(r)||i>=127&&i<160)&&(n-=20)}for(const r of c.values())r>=2&&(n+=r*2);return n-=(t.match(/[ÃÂ]|â[\u0080-\u00bf]/g)??[]).length*8,n}function d(t,n={}){if(t[0]===239&&t[1]===187&&t[2]===191)return new TextDecoder("utf-8").decode(t.subarray(3));if(t[0]===255&&t[1]===254)return new TextDecoder("utf-16le").decode(t.subarray(2));if(t[0]===254&&t[1]===255){const e=t.subarray(2).slice();for(let o=0;o+1<e.length;o+=2)[e[o],e[o+1]]=[e[o+1],e[o]];return new TextDecoder("utf-16le").decode(e)}const c=p(n.mimeType??"")??(n.kind==="html"?w(t):null);if(c){const e=u(t,c,!1);if(e!==null)return e}const r=u(t,"utf-8",!0);if(r!==null)return r;let i=new TextDecoder("windows-1252").decode(t),s=l(i);for(const e of f){const o=u(t,e,!0);if(o===null)continue;const a=l(o);a>s&&(i=o,s=a)}return i}async function y(t,n="plain"){const c=new Uint8Array(await t.arrayBuffer());return d(c,{kind:n,mimeType:t.type})}export{d as decodeTextBytes,y as decodeTextFile};
1
+ const f=["shift_jis","gb18030","big5","euc-kr","windows-1251","windows-1256","windows-1252"];function p(t){return/charset\s*=\s*["']?([^;"'\s]+)/i.exec(t)?.[1]??null}function w(t){const n=new TextDecoder(
2
+ "windows-1252").decode(t.subarray(0,2048));return/<meta[^>]+charset\s*=\s*["']?([^\s"'/>;]+)/i.exec(n)?.[1]??/<meta[^>]+content\s*=\s*["'][^"']*charset\s*=\s*([^\s"';]+)/i.exec(n)?.[1]??null}function u(t,n,c=!0){
3
+ try{return new TextDecoder(n,{fatal:c}).decode(t)}catch{return null}}function l(t){let n=0;const c=new Map;for(const r of t){r==="�"?n-=100:/\p{L}|\p{N}/u.test(r)&&(n+=1);for(const[s,e]of[["cjk",/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}]/u],
4
+ ["hangul",/\p{Script=Hangul}/u],["cyrillic",/\p{Script=Cyrillic}/u],["arabic",/\p{Script=Arabic}/u]])e.test(r)&&c.set(s,(c.get(s)??0)+1);const i=r.codePointAt(0)??0;(i<32&&!`
5
+ \r `.includes(r)||i>=127&&i<160)&&(n-=20)}for(const r of c.values())r>=2&&(n+=r*2);return n-=(t.match(/[ÃÂ]|â[\u0080-\u00bf]/g)??[]).length*8,n}function d(t,n={}){if(t[0]===239&&t[1]===187&&t[2]===
6
+ 191)return new TextDecoder("utf-8").decode(t.subarray(3));if(t[0]===255&&t[1]===254)return new TextDecoder("utf-16le").decode(t.subarray(2));if(t[0]===254&&t[1]===255){const e=t.subarray(2).slice();for(let o=0;o+
7
+ 1<e.length;o+=2)[e[o],e[o+1]]=[e[o+1],e[o]];return new TextDecoder("utf-16le").decode(e)}const c=p(n.mimeType??"")??(n.kind==="html"?w(t):null);if(c){const e=u(t,c,!1);if(e!==null)return e}const r=u(t,
8
+ "utf-8",!0);if(r!==null)return r;let i=new TextDecoder("windows-1252").decode(t),s=l(i);for(const e of f){const o=u(t,e,!0);if(o===null)continue;const a=l(o);a>s&&(i=o,s=a)}return i}async function y(t,n="\
9
+ plain"){const c=new Uint8Array(await t.arrayBuffer());return d(c,{kind:n,mimeType:t.type})}export{d as decodeTextBytes,y as decodeTextFile};
@@ -1,5 +1,8 @@
1
- import{f as r}from"./footnoteFlatten-Bdnn_bz1.js";import{C as p,aP as c,f as l,aQ as s}from"./backend-MFpDFVrD.js";import{decodeTextFile as m}from"./TextFileDecoder--rsVs3NR.js";class h{static async parseFile(n){const o=await m(n);return this.fromText(o)}static fromText(n){const o=n.replace(/\r\n?/g,`
2
- `).split(/\n\s*\n+/),a=[];for(const t of o){const e=t.trim();e&&a.push(p([{type:"text",text:e}]))}return a.length===0&&a.push(p()),{type:"doc",children:a}}static toText(n,o){n=r(n);const a=t=>t.type==="placeholder"?"[Placeholder]":t.type==="image"?"[Image]":t.type==="code"?o?.codeText?.(t)??t.content:t.type==="math"?t.content:t.type==="toc"?c(n,l(t)).map(e=>`${" ".repeat(e.level-1)}${e.text}`).join(`
1
+ import{f as r}from"./footnoteFlatten-DUQticYy.js";import{C as p,aR as c,f as l,aS as s}from"./backend-DecaBz-I.js";import{decodeTextFile as m}from"./TextFileDecoder--rsVs3NR.js";class h{static async parseFile(n){
2
+ const o=await m(n);return this.fromText(o)}static fromText(n){const o=n.replace(/\r\n?/g,`
3
+ `).split(/\n\s*\n+/),a=[];for(const t of o){const e=t.trim();e&&a.push(p([{type:"text",text:e}]))}return a.length===0&&a.push(p()),{type:"doc",children:a}}static toText(n,o){n=r(n);const a=t=>t.type===
4
+ "placeholder"?"[Placeholder]":t.type==="image"?"[Image]":t.type==="code"?o?.codeText?.(t)??t.content:t.type==="math"?t.content:t.type==="toc"?c(n,l(t)).map(e=>`${" ".repeat(e.level-1)}${e.text}`).join(
5
+ `
3
6
  `):t.type==="paragraph"&&s(t)?"---":t.type==="list"?t.children.map(e=>e.children.map(i=>i.text).join("")).join(`
4
7
  `):t.type==="table"?t.children.map(e=>e.children.map(i=>i.children.map(a).join(`
5
8
 
@@ -0,0 +1,10 @@
1
+ function m(n,t){if(t<0||t>=n.length)return 0;const e=n.codePointAt(t);return e===void 0?0:e>65535?2:1}function f(n,t){if(t>=n.length)return t;const e=m(n,t);return t+e}function y(n,t){if(t<=0)return 0;
2
+ const e=n.charCodeAt(t-1);if(e>=56320&&e<=57343&&t>=2){const r=n.charCodeAt(t-2);if(r>=55296&&r<=56319)return t-2}return t-1}let c,u;function l(){if(c===void 0)try{const n=typeof Intl<"u"?Intl.Segmenter:
3
+ void 0;c=typeof n=="function"?new n(void 0,{granularity:"grapheme"}):null}catch{c=null}return c}function S(){if(u===void 0)try{const n=typeof Intl<"u"?Intl.Segmenter:void 0;u=typeof n=="function"?new n(
4
+ void 0,{granularity:"word"}):null}catch{u=null}return u}const p=/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Thai}\p{Script=Lao}\p{Script=Khmer}\p{Script=Myanmar}]/u,v=/[\p{L}\p{N}\p{M}_]/u;
5
+ function L(n){const t=S();if(t)return Array.from(t.segment(n),o=>({segment:o.segment,index:o.index,isWordLike:o.isWordLike===!0}));const e=[];let r=null;for(let o=0;o<n.length;){const i=d(n,o),s=n.slice(
6
+ o,i),h=p.test(s),a=v.test(s);a&&!h&&r?.isWordLike===!0&&!p.test(r.segment)?r.segment+=s:(r={segment:s,index:o,isWordLike:a},e.push(r)),o=i}return e}function x(n){let t=0;for(const e of L(n))e.isWordLike&&
7
+ (t+=1);return t}function k(n,t){if(!t)return n.toUpperCase();try{return n.toLocaleUpperCase(t)}catch{return n.toUpperCase()}}const g=64;function C(n){const t=[0],e=l();if(e)for(const{index:r,segment:o}of e.
8
+ segment(n))t.push(r+o.length);else for(let r=0;r<n.length;)r=f(n,r),t.push(r);return t}function d(n,t){if(t>=n.length)return t;const e=l();if(!e)return f(n,t);const r=Math.min(n.length,t+g),o=n.slice(
9
+ t,r),i=e.segment(o)[Symbol.iterator]().next();return i.done||!i.value.segment.length?f(n,t):t+i.value.segment.length}function W(n,t){if(t<=0)return 0;const e=l();if(!e)return y(n,t);const r=Math.max(0,
10
+ t-g),o=n.slice(r,t);let i=0;for(const{index:s}of e.segment(o))i=s;return r+i}export{d as a,W as b,x as c,C as g,k as l};
@@ -0,0 +1,2 @@
1
+ import{ca as ue,cb as ve,B as pe,I as Ee}from"./index-2TBhRkX7.js";const ge=new WeakMap,R=r=>{let e=ge.get(r);return e===void 0&&(e=r.children.map(t=>t.text).join(""),ge.set(r,e)),e},P=r=>r.trim()?r.trim().split(/\s+/).length:0,me=new WeakMap,k=r=>{let e=me.get(r);if(e===void 0){const{id:t,children:n,...i}=r;e=JSON.stringify(i),me.set(r,e)}return e},G=(r={})=>Object.fromEntries(ve.filter(e=>r[e]!==void 0).map(e=>[e,r[e]])),Me=["comment","footnoteRef","footnotePendingBody","footnotePendingKind","oxmlRange","bookmark"],fe=r=>{const e={...r};for(const t of Me)delete e[t];return e};function Te(r){return{...r,children:r.children.map(e=>({...e,marks:G(e.marks)}))}}function be(r){return r.type==="paragraph"?`p${k(r)}${R(r)}`:r.type==="list"?`l${k(r)}${r.children.map(e=>k(e)+R(e)).join("\0")}`:JSON.stringify(r,(e,t)=>e==="id"?void 0:t)}function Ce(r){return r.type==="paragraph"||r.type==="list"||r.type==="table"}function re(r,e){const t=JSON.parse(JSON.stringify(r)),n=new Map,i=[],h=m=>{if(!m||typeof m!="object")return;const d=m;if(typeof d.type=="string"&&typeof d.id=="string"){const s=e();n.set(d.id,s),d.id=s}typeof d.docxTablePropertyOverrides=="string"&&i.push(d),Array.isArray(d.children)&&d.children.forEach(h)};h(t);for(const m of i)try{const d=JSON.parse(m.docxTablePropertyOverrides);for(const s of["rows","rowExceptions","cells"]){const u=d[s];!u||typeof u!="object"||Array.isArray(u)||(d[s]=Object.fromEntries(Object.entries(u).map(([c,p])=>[n.get(c)??c,p])))}m.docxTablePropertyOverrides=JSON.stringify(d)}catch{}return t}function se(r){const e=t=>{if(!t||typeof t!="object")return;const n=t;n.type==="text"&&n.marks&&(n.marks=fe(n.marks)),n.children?.forEach(e)};return e(r),r}const Z=new Map,Y=r=>{let e=Z.get(r);return e||(e=new Set(r.toLowerCase().match(/[\p{L}\p{N}]+/gu)??[]),Z.size>5e4&&Z.clear(),Z.set(r,e)),e};function ie(r,e){let t=0;for(const n of r)e.has(n)&&t++;return 2*t/(r.size+e.size||1)}function oe(r,e,t,n,i,h,m,d,s=()=>!1){const u=new Map,c=w=>{const I=t(w);return u.has(I)||u.set(I,`t${u.size}`),u.get(I)+" "},p=ue(r.map(c).join(""),e.map(c).join("")).diffs;let N=0,A=0,T=0,F=0;const v=()=>{const w=r.slice(T,N),I=e.slice(F,A);if(w.length===1&&I.length===1&&s(w[0],I[0])){h(w[0],I[0]);return}const j=w.map(q=>I.map(L=>n(q,L))),C=Array.from({length:w.length+1},()=>new Float64Array(I.length+1));for(let q=w.length-1;q>=0;q--)for(let L=I.length-1;L>=0;L--)C[q][L]=Math.max(C[q+1][L],C[q][L+1],j[q][L]+C[q+1][L+1]);let E=0,O=0;for(;E<w.length||O<I.length;)E<w.length&&O<I.length&&j[E][O]>0&&C[E][O]===j[E][O]+C[E+1][O+1]?h(w[E++],I[O++]):E<w.length&&(O===I.length||C[E+1][O]>=C[E][O+1])?m(w[E++]):d(I[O++])};for(const[w,I]of p){const j=I.trim().split(/\s+/).filter(Boolean).length;if(w===0){v();for(let C=0;C<j;C++)i(r[N++],e[A++]);T=N,F=A}else w===-1?N+=j:A+=j}v()}const ee=8e6,ye=1e6;function Oe(r,e,t){if(r.length*e.length>ee)return null;const{nextId:n,nextBlockId:i,label:h,authorName:m,authorOf:d,pairLoneChanges:s}=t,u=l=>s?l:()=>!1,c={inlineChanges:0,insertedBlocks:0,deletedBlocks:0,unmarkedBlocks:0,insertedWords:0,deletedWords:0},p=l=>d?.(l)??m,N=(l,o,a)=>{const y=p(a);return{[l]:!0,suggestionId:o,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:h,...y?{suggestionAuthorName:y}:{}}},A=(l,o)=>{if(!Ce(l))return null;const a=l.type==="paragraph"?l.children[0]?.marks:void 0,y=l.type==="paragraph"?Te(l):l,g=o==="delete"?se(re(y,i)):y,f=n(),S=p(a),b={id:f,blockId:g.id,source:"manual",authorType:"human",label:o==="insert"?"Insert":"Delete",...S?{agentName:S}:{}},x=o==="insert"?{...b,type:"block-insert"}:{...b,type:"block-delete",beforeBlock:g},M="children"in g&&g.type!=="table"?z(g):"";return o==="insert"?(c.insertedBlocks++,c.insertedWords+=P(M)):(c.deletedBlocks++,c.deletedWords+=P(M)),{...g,structuralSuggestionId:f,structuralSuggestionKind:o,structuralSuggestionRecord:JSON.stringify(x)}},T=(l,o,a)=>{const y=[];let g=0;for(const f of l.children){const S=Math.max(o-g,0),b=Math.min(o+a-g,f.text.length);if(b>S&&y.push({...f,text:f.text.slice(S,b)}),g+=f.text.length,g>=o+a)break}return y},F=(l,o,a)=>{const y=R(l),g=R(o);if(k(l)!==k(o)||P(y)*P(g)>ye){v(l,"delete",a),v(o,"insert",a);return}const f=[];let S=0,b=0,x="";const M=(J,B)=>{x||(x=n(),c.inlineChanges++);const D=P(J.map(X=>X.text).join(""));B==="insertion"?c.insertedWords+=D:c.deletedWords+=D,f.push(...J.map(X=>{const U=G(X.marks);return{...X,marks:{...B==="deletion"?fe(U):U,...N(B,x,X.marks)}}}))};for(const[J,B]of ue(y,g).diffs){if(J===-1)M(T(l,S,B.length),"deletion");else if(J===1)M(T(o,b,B.length),"insertion");else{const D=T(l,S,B.length),X=T(o,b,B.length);let U=0,_=0,K=0,H=0;for(;U<D.length&&_<X.length;){const Q=Math.min(D[U].text.length-K,X[_].text.length-H),he={...D[U],text:D[U].text.slice(K,K+Q)},V={...X[_],text:X[_].text.slice(H,H+Q)},{bookmark:We,...Se}=G(he.marks),{bookmark:Je,...Ie}=G(V.marks);JSON.stringify(Se)===JSON.stringify(Ie)?(x="",f.push({...V,marks:G(V.marks)})):(M([he],"deletion"),M([V],"insertion")),K+=Q,H+=Q,K===D[U].text.length&&(U++,K=0),H===X[_].text.length&&(_++,H=0)}}J!==1&&(S+=B.length),J!==-1&&(b+=B.length)}a.push({...o,children:f})},v=(l,o,a)=>{if(l.type==="table"){a.push(O(l,o));return}const y=A(l,o);y?a.push(y):(c.unmarkedBlocks++,o==="insert"&&a.push(l))},w=(l,o)=>{if(k(l)!==k(o))return 0;const a=ie(Y(R(l)),Y(R(o)));return a>=.5?a:0},I=(l,o,a)=>{const y=()=>{v(l,"delete",a),v(o,"insert",a)};if(l.children.length*o.children.length>ee)return y();const g=[];let f=!1;if(oe(l.children,o.children,b=>k(b)+R(b),w,(b,x)=>g.push([b,x]),(b,x)=>g.push([b,x]),()=>f=!0,()=>f=!0,u((b,x)=>k(b)===k(x))),f||g.some(([b,x])=>k(b)!==k(x)||P(R(b))*P(R(x))>ye))return y();const S=[];for(const[b,x]of g)F(b,x,S);a.push({...o,children:S})},j=(l,o)=>{const a=P(z(l));o==="insert"?(c.insertedBlocks++,c.insertedWords+=a):(c.deletedBlocks++,c.deletedWords+=a)},C=(l,o)=>o==="delete"?se(re(l,i)):l,E=(l,o,a,y)=>{const g=n();return{id:g,record:{id:g,type:"table-change",tableId:l,source:"manual",authorType:"human",label:y[a],...m?{agentName:m}:{},tableRevision:{version:1,suggestionKind:a,markers:o.map(([f,S])=>({kind:a==="insert"?"row-insert":"row-delete",rowId:f.id,rowIndex:S})),operations:o.map(([f,S])=>({kind:"row",action:a,rowId:f.id,rowIndex:S,row:JSON.parse(JSON.stringify(f))}))}}}},O=(l,o)=>{const a=o==="delete"?se(re(l,i)):l,{id:y,record:g}=E(a.id,a.children.map((f,S)=>[f,S]),o,{insert:"Insert table",delete:"Delete table"});return j(a,o),{...a,structuralSuggestionRecords:JSON.stringify([g]),children:a.children.map(f=>({...f,diffState:o,suggestionId:y}))}},q=(l,o)=>k(l)===k(o)&&l.children.length===o.children.length&&l.children.every((a,y)=>k(a)===k(o.children[y])),L=(l,o)=>l.children.every((a,y)=>a.children.length*o.children[y].children.length<=ee),ne=(l,o)=>q(l,o)&&L(l,o),ce=(l,o)=>({...o,children:o.children.map((a,y)=>({...a,children:de(l.children[y].children,a.children)}))}),we=(l,o,a)=>{if(k(l)!==k(o)||l.children.length*o.children.length>ee){v(l,"delete",a),v(o,"insert",a);return}const y=[],g=[],f=(b,x)=>{const M=C(b,x),{id:J,record:B}=E(o.id,[[M,y.length]],x,{insert:"Insert table row",delete:"Delete table row"});g.push(B),j(M,x),y.push({...M,diffState:x,suggestionId:J})},S=b=>be(b);oe(l.children,o.children,S,(b,x)=>{if(!ne(b,x))return 0;const M=ie(Y(z(b)),Y(z(x)));return M>=.5?M:0},(b,x)=>{ne(b,x)?y.push(ce(b,x)):(f(b,"delete"),f(x,"insert"))},(b,x)=>y.push(ce(b,x)),b=>f(b,"delete"),b=>f(b,"insert"),u(ne)),a.push({...o,children:y,...g.length>0?{structuralSuggestionRecords:JSON.stringify(g)}:{}})},Ae=(l,o)=>{if(l.type==="paragraph"&&o.type==="paragraph")return w(l,o);if(l.type==="list"&&o.type==="list"&&k(l)===k(o)||l.type==="table"&&o.type==="table"&&k(l)===k(o)){const a=ie(Y(z(l)),Y(z(o)));return a>=.3?a:0}return 0};function de(l,o){const a=[],y=(g,f)=>{g.type==="list"&&f.type==="list"?I(g,f,a):g.type==="table"&&f.type==="table"?we(g,f,a):g.type==="paragraph"&&f.type==="paragraph"?F(g,f,a):a.push(f)};return oe(l,o,be,Ae,y,y,g=>v(g,"delete",a),g=>v(g,"insert",a),u((g,f)=>g.type===f.type&&(g.type==="paragraph"||g.type==="list"||g.type==="table")&&k(g)===k(f))),a}return{blocks:de(r,e),stats:c}}const xe=new WeakMap;function z(r){const e=xe.get(r);if(e!==void 0)return e;const t=Be(r);return xe.set(r,t),t}function Be(r){return"children"in r&&Array.isArray(r.children)?r.children.map(e=>{const t=e;return t.type==="text"?t.text??"":z(e)}).join(" "):""}function qe(r,e,t){const n=(h,m)=>h.length>0&&h.every(d=>d.type==="paragraph"&&d.children.length>0&&d.children.every(s=>s.marks?.[m]&&!s.marks.layeredInsertion));if(!n(r,"deletion")||!n(e,"insertion"))return null;const i=Oe(r,e,{nextId:t,nextBlockId:pe,label:"Revise bill",authorOf:h=>h?.suggestionAuthorName});return i?i.blocks:null}const ke={division:0,title:0,subtitle:0,chapter:0,subchapter:0,part:0,subpart:0,section:0,subsection:1,paragraph:2,subparagraph:3,clause:4,subclause:5,item:6,subitem:7},Ne={division:"Division",title:"Title",subtitle:"Subtitle",chapter:"Chapter",subchapter:"Subchapter",part:"Part",subpart:"Subpart",section:"Sec."},le=new Set(["added-phrase","deleted-phrase","bold","italic","underline","strike","superscript","subscript","quote","term","short-title","act-name","external-xref","internal-xref","enum-in-header","header-in-text","definition","linebreak","nobreak","sponsor","cosponsor","committee-name","text-to-insert","text-to-strike-out","omitted-text","inline-comment"]),Le=new Set(["graphic","formula","footnote","footnote-ref","spanspec","entrytbl"]),$=r=>Array.from(r.children),W=(r,e)=>$(r).find(t=>t.localName===e),te=r=>r.replace(/[\t\r\n ]+/g," "),Xe={id:"us-congress-bill",label:"U.S. Congressional bills (bill.dtd)",matches(r){const e=r.documentElement;if(e.localName!=="bill"||e.namespaceURI||!W(e,"legis-body"))return!1;const t=r.doctype;if(t)return t.name==="bill"&&(t.publicId==="-//US Congress//DTDs/bill.dtd//EN"||!t.publicId&&/(?:^|\/)bill\.dtd$/i.test(t.systemId));const n=W(e,"form");return!!n&&!!W(n,"congress")&&!!W(n,"legis-num")},parse(r){return new je().parse(r)}};class je{constructor(){this.revisionCount=0,this.revisions=new WeakMap,this.committees=new Map,this.usedIds=new Set}id(){let e;do e=pe();while(this.usedIds.has(e));return this.usedIds.add(e),e}parse(e){const t=e.documentElement;for(const p of Array.from(t.getElementsByTagName("committee-name"))){const N=p.getAttribute("committee-id");N&&this.committees.set(N,te(p.textContent??"").trim())}for(const p of Array.from(t.getElementsByTagName("*")))if(Le.has(p.localName))throw new Error(`Unsupported Congressional XML element: <${p.localName}>. This bill requires content the XML importer does not yet support.`);const n=this.context(t,{marks:{},indent:0,quoted:0}),i=[],h=$(t),m=h.map(p=>this.blocks(p,n));for(let p=0;p<h.length;p++){const N=h[p],A=m[p],T=h[p+1];if(N.localName==="legis-body"&&T?.localName==="legis-body"&&T.getAttribute("display-enacting-clause")==="no-display-enacting-clause"){const F=m[p+1],v=N.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"?1:0,w=qe(A.slice(v),F,()=>`congressdiff-${++this.revisionCount}`);if(w){i.push(...A.slice(0,v),...w),p++;continue}}i.push(...A)}if(!i.length)throw new Error("The Congressional XML bill contains no readable content.");const d=W(t,"form"),s=d&&W(d,"legis-num")?.textContent?.trim(),u=t.getElementsByTagName("short-title")[0]?.textContent?.trim(),c=s?[s,u].filter(Boolean).join(" — "):e.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/","title")[0]?.textContent?.trim();return{type:"doc",children:i,...c?{title:c}:{}}}context(e,t){const n={...t.marks},i=e.localName,h=e.getAttribute("changed")??(i==="added-phrase"?"added":i==="deleted-phrase"?"deleted":null);if(h==="added"||h==="deleted"){const d=h==="added"?"insertion":"deletion",s=e.getAttribute("reporting-committee")||e.getAttribute("committee-id"),u=s?this.committees.get(s)??s:void 0;if(!n[d]||u&&u!==n.suggestionAuthorName){if(n.deletion&&d==="insertion")throw new Error("Unsupported Congressional XML revision: insertion nested inside a deletion.");let c=this.revisions.get(e);c||(c={[d]:!0,suggestionId:`congressrev-${++this.revisionCount}`,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:d==="insertion"?"Insert":"Delete",...u?{suggestionAuthorName:u}:{}},this.revisions.set(e,c)),n.insertion&&d==="deletion"&&(n.layeredInsertion=JSON.stringify({id:n.suggestionId,source:n.suggestionSource,authorType:n.suggestionAuthorType,authorName:n.suggestionAuthorName,label:n.suggestionLabel})),delete n.insertion,delete n.deletion,delete n.suggestionAuthorName,Object.assign(n,c)}}i==="bold"&&(n.bold=!0),i==="italic"&&(n.italic=!0),i==="underline"&&(n.underline=!0),i==="superscript"&&(n.superscript=!0),i==="subscript"&&(n.subscript=!0);const m=e.getAttribute("href");return m&&/^(https?:\/\/|#)/i.test(m.trim())&&(n.link=m.trim()),i==="internal-xref"&&e.getAttribute("idref")&&(n.link=`#${e.getAttribute("idref")}`),{...t,marks:n,style:e.getAttribute("style")??t.style}}text(e,t){return{type:"text",text:e,marks:{...t.marks}}}inline(e,t){const n=this.context(e,t);if(e.localName==="linebreak")return[this.text(`
2
+ `,n)];const i=[],h=e.localName==="quote"||e.localName==="term";h&&i.push(this.text(n.quoted?"‘":"“",n));for(const m of Array.from(e.childNodes))m.nodeType===3||m.nodeType===4?i.push(this.text(te(m.textContent??""),n)):m.nodeType===1&&i.push(...this.inline(m,h?{...n,quoted:n.quoted+1}:n));return h&&i.push(this.text(n.quoted?"’":"”",n)),i}paragraph(e,t,n,i){for(;e.length&&!e[0].text.trim();)e.shift();for(;e.length&&!e[e.length-1].text.trim();)e.pop();if(!e.length)return null;e[0].text=e[0].text.replace(/^ +/,""),e[e.length-1].text=e[e.length-1].text.replace(/ +$/,""),t.quoted&&e.unshift(this.text(t.quoted>1?"‘":"“",t));const h=n?.getAttribute("id");return h&&(e[0].marks={...e[0].marks,bookmark:h}),{type:"paragraph",id:this.id(),children:e,...i?{heading:i,keepNext:!0}:{},...t.indent?{leftIndent:Math.min(t.indent,6)}:{}}}blocks(e,t){const n=e.localName;if(n==="metadata")return[];const i=this.context(e,t);if(Object.prototype.hasOwnProperty.call(ke,n))return this.structure(e,{...i,indent:ke[n]+(i.quoted?1:0)});if(n==="table")return $(e).filter(s=>s.localName==="tgroup").length?$(e).flatMap(s=>s.localName==="tgroup"?[this.table(s,this.context(s,i))]:this.blocks(s,i)):[this.table(e,i)];if(n==="quoted-block"){const s=$(e).filter(p=>p.localName!=="after-quoted-block").flatMap(p=>this.blocks(p,{...i,quoted:i.quoted+1,indent:i.indent+1})),u=s[s.length-1],c=W(e,"after-quoted-block");if(u?.type==="paragraph")u.children.push(this.text(i.quoted?"’":"”",i)),c&&u.children.push(...this.inline(c,i));else if(c){const p=this.paragraph([this.text(i.quoted?"’":"”",i),...this.inline(c,i)],i);p&&s.push(p)}return s}if(!$(e).some(s=>!le.has(s.localName))){const s=this.paragraph(this.inline(e,t),i,e);if(s&&(n==="legis-num"||n==="legis-type")){s.align="center";for(const u of s.children)u.marks={...u.marks,bold:!0}}return s?[s]:[]}const h=[];if(n==="legis-body"&&e.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"){const s=this.paragraph([this.text("Be it enacted by the Senate and House of Representatives of the United States of America in Congress assembled,",i)],i);s&&h.push(s)}let m=[];const d=()=>{const s=this.paragraph(m,i);s&&h.push(s),m=[]};for(const s of Array.from(e.childNodes))if(s.nodeType===3||s.nodeType===4)m.push(this.text(te(s.textContent??""),i));else if(s.nodeType===1){const u=s;le.has(u.localName)?m.push(...this.inline(u,i)):(d(),h.push(...this.blocks(u,i)))}return d(),h}structure(e,t){const n=[],i=Object.prototype.hasOwnProperty.call(Ne,e.localName),h=W(e,"enum"),m=W(e,"header");let d=[];if(h&&(i&&d.push(this.text(e.localName==="section"&&t.style==="USC"?"§ ":`${Ne[e.localName]} `,t)),d.push(...this.inline(h,t),this.text(" ",t))),m){const c=this.inline(m,t);for(const p of c)p.marks={...p.marks,bold:!0};d.push(...c)}const s=(c=!1)=>{const p=this.paragraph(d,t,n.length?void 0:e,c?e.localName==="section"?2:1:void 0);p&&n.push(p),d=[]};i&&s(!0);let u=!0;for(const c of Array.from(e.childNodes))if(!(c===h||c===m)){if(c.nodeType===3||c.nodeType===4)c.textContent?.trim()&&d.push(this.text(te(c.textContent),t));else if(c.nodeType===1){const p=c;if(p.localName==="text")u||s(),u&&!i&&m&&d.push(this.text(".—",t)),d.push(...this.inline(p,t)),u=!1;else if(le.has(p.localName))d.push(...this.inline(p,t));else{s();const N=this.blocks(p,t),A=n[n.length-1];p.getAttribute("display-inline")==="yes-display-inline"&&A?.type==="paragraph"&&!A.heading&&N[0]?.type==="paragraph"&&(A.children.push(this.text(" ",t),...N[0].children),N.shift()),n.push(...N)}}}return s(),n}table(e,t){const n=W(e,"tgroup")??e,i=new Map($(n).filter(s=>s.localName==="colspec").map((s,u)=>[s.getAttribute("colname"),Number(s.getAttribute("colnum"))||u+1])),h=$(n).flatMap(s=>s.localName==="row"?[s]:["thead","tbody","tfoot"].includes(s.localName)?$(s).filter(u=>u.localName==="row"):[]);if(!h.length)throw new Error("Unsupported Congressional XML table: no rows.");const m={type:"table",id:this.id(),columnWidths:[],children:h.map(s=>({type:"table-row",id:this.id(),children:$(s).filter(u=>u.localName==="entry").map(u=>{const c=i.get(u.getAttribute("namest")),p=i.get(u.getAttribute("nameend")),N=c&&p?p-c+1:1,A=Number(u.getAttribute("morerows")??0)+1;if(u.hasAttribute("namest")&&(!c||!p)||!Number.isInteger(N)||N<1||N>100||!Number.isInteger(A)||A<1||A>h.length)throw new Error("Unsupported Congressional XML table: invalid cell span.");const T=this.blocks(u,{...this.context(s,s.parentElement&&s.parentElement!==n?this.context(s.parentElement,t):t),indent:0});return{type:"table-cell",id:this.id(),children:T.length?T:[{type:"paragraph",id:this.id(),children:[{type:"text",text:""}]}],...N>1?{colSpan:N}:{},...A>1?{rowSpan:A}:{}}})}))},d=Ee(m).cols;if(!d||d>100)throw new Error("Unsupported Congressional XML table: invalid column count.");return m.columnWidths=Array(d).fill(100/d),m}}const ae=[Xe];class $e{static async parseFile(e){return this.fromBytes(new Uint8Array(await e.arrayBuffer()))}static fromBytes(e){let t="utf-8";if(e[0]===255&&e[1]===254||e[0]===60&&e[1]===0&&e[2]===63&&e[3]===0)t="utf-16le";else if(e[0]===254&&e[1]===255||e[0]===0&&e[1]===60&&e[2]===0&&e[3]===63)t="utf-16be";else if(!(e[0]===239&&e[1]===187&&e[2]===191)){const i=new TextDecoder("windows-1252").decode(e.subarray(0,512));t=/^<\?xml\s[^?]*\bencoding\s*=\s*["']([^"']+)["']/i.exec(i)?.[1]??t}let n;try{n=new TextDecoder(t,{fatal:!0}).decode(e)}catch{throw new Error(`Invalid or unsupported XML encoding: ${t}.`)}return this.fromXml(n)}static fromXml(e){if(/<!ENTITY\s/i.test(e))throw new Error("XML entity declarations are not supported.");const t=new DOMParser().parseFromString(e.replace(/^\uFEFF/,""),"application/xml");if(!t.documentElement||t.getElementsByTagName("parsererror").length)throw new Error("Invalid XML: the document is not well-formed.");const n=[[t.documentElement,0]];for(;n.length;){const[h,m]=n.pop();if(m>128)throw new Error("XML nesting exceeds the supported depth (128).");for(const d of Array.from(h.children))n.push([d,m+1])}const i=ae.find(h=>h.matches(t));if(!i)throw new Error(`Unsupported XML schema: <${t.documentElement.tagName}>. Supported: ${ae.map(h=>h.label).join(", ")}.`);return i.parse(t)}}export{ae as XML_SCHEMA_PARSERS,$e as XmlConverter};
@@ -0,0 +1,96 @@
1
+ import{Y as ve,w as ue}from"./backend-DecaBz-I.js";import{b as Ee}from"./TableGrid-DbroRucl.js";import{a as pe}from"./ParagraphDiffAnalysis-DrmStvmz.js";const ge=new WeakMap,U=r=>{let e=ge.get(r);return e===
2
+ void 0&&(e=r.children.map(t=>t.text).join(""),ge.set(r,e)),e},P=r=>r.trim()?r.trim().split(/\s+/).length:0,me=new WeakMap,k=r=>{let e=me.get(r);if(e===void 0){const{id:t,children:n,...i}=r;e=JSON.stringify(
3
+ i),me.set(r,e)}return e},G=(r={})=>Object.fromEntries(ve.filter(e=>r[e]!==void 0).map(e=>[e,r[e]])),Me=["comment","footnoteRef","footnotePendingBody","footnotePendingKind","oxmlRange","bookmark"],fe=r=>{
4
+ const e={...r};for(const t of Me)delete e[t];return e};function Te(r){return{...r,children:r.children.map(e=>({...e,marks:G(e.marks)}))}}function be(r){return r.type==="paragraph"?`p${k(r)}${U(r)}`:r.
5
+ type==="list"?`l${k(r)}${r.children.map(e=>k(e)+U(e)).join("\0")}`:JSON.stringify(r,(e,t)=>e==="id"?void 0:t)}function Ce(r){return r.type==="paragraph"||r.type==="list"||r.type==="table"}function re(r,e){
6
+ const t=JSON.parse(JSON.stringify(r)),n=new Map,i=[],h=m=>{if(!m||typeof m!="object")return;const d=m;if(typeof d.type=="string"&&typeof d.id=="string"){const s=e();n.set(d.id,s),d.id=s}typeof d.docxTablePropertyOverrides==
7
+ "string"&&i.push(d),Array.isArray(d.children)&&d.children.forEach(h)};h(t);for(const m of i)try{const d=JSON.parse(m.docxTablePropertyOverrides);for(const s of["rows","rowExceptions","cells"]){const u=d[s];
8
+ !u||typeof u!="object"||Array.isArray(u)||(d[s]=Object.fromEntries(Object.entries(u).map(([c,p])=>[n.get(c)??c,p])))}m.docxTablePropertyOverrides=JSON.stringify(d)}catch{}return t}function se(r){const e=t=>{
9
+ if(!t||typeof t!="object")return;const n=t;n.type==="text"&&n.marks&&(n.marks=fe(n.marks)),n.children?.forEach(e)};return e(r),r}const Z=new Map,Y=r=>{let e=Z.get(r);return e||(e=new Set(r.toLowerCase().
10
+ match(/[\p{L}\p{N}]+/gu)??[]),Z.size>5e4&&Z.clear(),Z.set(r,e)),e};function ie(r,e){let t=0;for(const n of r)e.has(n)&&t++;return 2*t/(r.size+e.size||1)}function oe(r,e,t,n,i,h,m,d,s=()=>!1){const u=new Map,
11
+ c=w=>{const I=t(w);return u.has(I)||u.set(I,`t${u.size}`),u.get(I)+" "},p=pe(r.map(c).join(""),e.map(c).join("")).diffs;let N=0,A=0,T=0,F=0;const v=()=>{const w=r.slice(T,N),I=e.slice(F,A);if(w.length===
12
+ 1&&I.length===1&&s(w[0],I[0])){h(w[0],I[0]);return}const $=w.map(q=>I.map(L=>n(q,L))),C=Array.from({length:w.length+1},()=>new Float64Array(I.length+1));for(let q=w.length-1;q>=0;q--)for(let L=I.length-
13
+ 1;L>=0;L--)C[q][L]=Math.max(C[q+1][L],C[q][L+1],$[q][L]+C[q+1][L+1]);let E=0,O=0;for(;E<w.length||O<I.length;)E<w.length&&O<I.length&&$[E][O]>0&&C[E][O]===$[E][O]+C[E+1][O+1]?h(w[E++],I[O++]):E<w.length&&
14
+ (O===I.length||C[E+1][O]>=C[E][O+1])?m(w[E++]):d(I[O++])};for(const[w,I]of p){const $=I.trim().split(/\s+/).filter(Boolean).length;if(w===0){v();for(let C=0;C<$;C++)i(r[N++],e[A++]);T=N,F=A}else w===-1?
15
+ N+=$:A+=$}v()}const ee=8e6,ye=1e6;function Oe(r,e,t){if(r.length*e.length>ee)return null;const{nextId:n,nextBlockId:i,label:h,authorName:m,authorOf:d,pairLoneChanges:s}=t,u=l=>s?l:()=>!1,c={inlineChanges:0,
16
+ insertedBlocks:0,deletedBlocks:0,unmarkedBlocks:0,insertedWords:0,deletedWords:0},p=l=>d?.(l)??m,N=(l,o,a)=>{const y=p(a);return{[l]:!0,suggestionId:o,suggestionSource:"manual",suggestionAuthorType:"h\
17
+ uman",suggestionLabel:h,...y?{suggestionAuthorName:y}:{}}},A=(l,o)=>{if(!Ce(l))return null;const a=l.type==="paragraph"?l.children[0]?.marks:void 0,y=l.type==="paragraph"?Te(l):l,g=o==="delete"?se(re(
18
+ y,i)):y,f=n(),S=p(a),b={id:f,blockId:g.id,source:"manual",authorType:"human",label:o==="insert"?"Insert":"Delete",...S?{agentName:S}:{}},x=o==="insert"?{...b,type:"block-insert"}:{...b,type:"block-del\
19
+ ete",beforeBlock:g},M="children"in g&&g.type!=="table"?z(g):"";return o==="insert"?(c.insertedBlocks++,c.insertedWords+=P(M)):(c.deletedBlocks++,c.deletedWords+=P(M)),{...g,structuralSuggestionId:f,structuralSuggestionKind:o,
20
+ structuralSuggestionRecord:JSON.stringify(x)}},T=(l,o,a)=>{const y=[];let g=0;for(const f of l.children){const S=Math.max(o-g,0),b=Math.min(o+a-g,f.text.length);if(b>S&&y.push({...f,text:f.text.slice(
21
+ S,b)}),g+=f.text.length,g>=o+a)break}return y},F=(l,o,a)=>{const y=U(l),g=U(o);if(k(l)!==k(o)||P(y)*P(g)>ye){v(l,"delete",a),v(o,"insert",a);return}const f=[];let S=0,b=0,x="";const M=(J,B)=>{x||(x=n(),
22
+ c.inlineChanges++);const D=P(J.map(X=>X.text).join(""));B==="insertion"?c.insertedWords+=D:c.deletedWords+=D,f.push(...J.map(X=>{const R=G(X.marks);return{...X,marks:{...B==="deletion"?fe(R):R,...N(B,
23
+ x,X.marks)}}}))};for(const[J,B]of pe(y,g).diffs){if(J===-1)M(T(l,S,B.length),"deletion");else if(J===1)M(T(o,b,B.length),"insertion");else{const D=T(l,S,B.length),X=T(o,b,B.length);let R=0,_=0,K=0,H=0;
24
+ for(;R<D.length&&_<X.length;){const Q=Math.min(D[R].text.length-K,X[_].text.length-H),he={...D[R],text:D[R].text.slice(K,K+Q)},V={...X[_],text:X[_].text.slice(H,H+Q)},{bookmark:We,...Se}=G(he.marks),{
25
+ bookmark:Je,...Ie}=G(V.marks);JSON.stringify(Se)===JSON.stringify(Ie)?(x="",f.push({...V,marks:G(V.marks)})):(M([he],"deletion"),M([V],"insertion")),K+=Q,H+=Q,K===D[R].text.length&&(R++,K=0),H===X[_].
26
+ text.length&&(_++,H=0)}}J!==1&&(S+=B.length),J!==-1&&(b+=B.length)}a.push({...o,children:f})},v=(l,o,a)=>{if(l.type==="table"){a.push(O(l,o));return}const y=A(l,o);y?a.push(y):(c.unmarkedBlocks++,o===
27
+ "insert"&&a.push(l))},w=(l,o)=>{if(k(l)!==k(o))return 0;const a=ie(Y(U(l)),Y(U(o)));return a>=.5?a:0},I=(l,o,a)=>{const y=()=>{v(l,"delete",a),v(o,"insert",a)};if(l.children.length*o.children.length>ee)
28
+ return y();const g=[];let f=!1;if(oe(l.children,o.children,b=>k(b)+U(b),w,(b,x)=>g.push([b,x]),(b,x)=>g.push([b,x]),()=>f=!0,()=>f=!0,u((b,x)=>k(b)===k(x))),f||g.some(([b,x])=>k(b)!==k(x)||P(U(b))*P(U(
29
+ x))>ye))return y();const S=[];for(const[b,x]of g)F(b,x,S);a.push({...o,children:S})},$=(l,o)=>{const a=P(z(l));o==="insert"?(c.insertedBlocks++,c.insertedWords+=a):(c.deletedBlocks++,c.deletedWords+=a)},
30
+ C=(l,o)=>o==="delete"?se(re(l,i)):l,E=(l,o,a,y)=>{const g=n();return{id:g,record:{id:g,type:"table-change",tableId:l,source:"manual",authorType:"human",label:y[a],...m?{agentName:m}:{},tableRevision:{
31
+ version:1,suggestionKind:a,markers:o.map(([f,S])=>({kind:a==="insert"?"row-insert":"row-delete",rowId:f.id,rowIndex:S})),operations:o.map(([f,S])=>({kind:"row",action:a,rowId:f.id,rowIndex:S,row:JSON.
32
+ parse(JSON.stringify(f))}))}}}},O=(l,o)=>{const a=o==="delete"?se(re(l,i)):l,{id:y,record:g}=E(a.id,a.children.map((f,S)=>[f,S]),o,{insert:"Insert table",delete:"Delete table"});return $(a,o),{...a,structuralSuggestionRecords:JSON.
33
+ stringify([g]),children:a.children.map(f=>({...f,diffState:o,suggestionId:y}))}},q=(l,o)=>k(l)===k(o)&&l.children.length===o.children.length&&l.children.every((a,y)=>k(a)===k(o.children[y])),L=(l,o)=>l.
34
+ children.every((a,y)=>a.children.length*o.children[y].children.length<=ee),ne=(l,o)=>q(l,o)&&L(l,o),ce=(l,o)=>({...o,children:o.children.map((a,y)=>({...a,children:de(l.children[y].children,a.children)}))}),
35
+ we=(l,o,a)=>{if(k(l)!==k(o)||l.children.length*o.children.length>ee){v(l,"delete",a),v(o,"insert",a);return}const y=[],g=[],f=(b,x)=>{const M=C(b,x),{id:J,record:B}=E(o.id,[[M,y.length]],x,{insert:"In\
36
+ sert table row",delete:"Delete table row"});g.push(B),$(M,x),y.push({...M,diffState:x,suggestionId:J})},S=b=>be(b);oe(l.children,o.children,S,(b,x)=>{if(!ne(b,x))return 0;const M=ie(Y(z(b)),Y(z(x)));return M>=
37
+ .5?M:0},(b,x)=>{ne(b,x)?y.push(ce(b,x)):(f(b,"delete"),f(x,"insert"))},(b,x)=>y.push(ce(b,x)),b=>f(b,"delete"),b=>f(b,"insert"),u(ne)),a.push({...o,children:y,...g.length>0?{structuralSuggestionRecords:JSON.
38
+ stringify(g)}:{}})},Ae=(l,o)=>{if(l.type==="paragraph"&&o.type==="paragraph")return w(l,o);if(l.type==="list"&&o.type==="list"&&k(l)===k(o)||l.type==="table"&&o.type==="table"&&k(l)===k(o)){const a=ie(
39
+ Y(z(l)),Y(z(o)));return a>=.3?a:0}return 0};function de(l,o){const a=[],y=(g,f)=>{g.type==="list"&&f.type==="list"?I(g,f,a):g.type==="table"&&f.type==="table"?we(g,f,a):g.type==="paragraph"&&f.type===
40
+ "paragraph"?F(g,f,a):a.push(f)};return oe(l,o,be,Ae,y,y,g=>v(g,"delete",a),g=>v(g,"insert",a),u((g,f)=>g.type===f.type&&(g.type==="paragraph"||g.type==="list"||g.type==="table")&&k(g)===k(f))),a}return{
41
+ blocks:de(r,e),stats:c}}const xe=new WeakMap;function z(r){const e=xe.get(r);if(e!==void 0)return e;const t=Be(r);return xe.set(r,t),t}function Be(r){return"children"in r&&Array.isArray(r.children)?r.
42
+ children.map(e=>{const t=e;return t.type==="text"?t.text??"":z(e)}).join(" "):""}function qe(r,e,t){const n=(h,m)=>h.length>0&&h.every(d=>d.type==="paragraph"&&d.children.length>0&&d.children.every(s=>s.
43
+ marks?.[m]&&!s.marks.layeredInsertion));if(!n(r,"deletion")||!n(e,"insertion"))return null;const i=Oe(r,e,{nextId:t,nextBlockId:ue,label:"Revise bill",authorOf:h=>h?.suggestionAuthorName});return i?i.
44
+ blocks:null}const ke={division:0,title:0,subtitle:0,chapter:0,subchapter:0,part:0,subpart:0,section:0,subsection:1,paragraph:2,subparagraph:3,clause:4,subclause:5,item:6,subitem:7},Ne={division:"Divis\
45
+ ion",title:"Title",subtitle:"Subtitle",chapter:"Chapter",subchapter:"Subchapter",part:"Part",subpart:"Subpart",section:"Sec."},le=new Set(["added-phrase","deleted-phrase","bold","italic","underline","\
46
+ strike","superscript","subscript","quote","term","short-title","act-name","external-xref","internal-xref","enum-in-header","header-in-text","definition","linebreak","nobreak","sponsor","cosponsor","co\
47
+ mmittee-name","text-to-insert","text-to-strike-out","omitted-text","inline-comment"]),Le=new Set(["graphic","formula","footnote","footnote-ref","spanspec","entrytbl"]),j=r=>Array.from(r.children),W=(r,e)=>j(
48
+ r).find(t=>t.localName===e),te=r=>r.replace(/[\t\r\n ]+/g," "),Xe={id:"us-congress-bill",label:"U.S. Congressional bills (bill.dtd)",matches(r){const e=r.documentElement;if(e.localName!=="bill"||e.namespaceURI||
49
+ !W(e,"legis-body"))return!1;const t=r.doctype;if(t)return t.name==="bill"&&(t.publicId==="-//US Congress//DTDs/bill.dtd//EN"||!t.publicId&&/(?:^|\/)bill\.dtd$/i.test(t.systemId));const n=W(e,"form");return!!n&&
50
+ !!W(n,"congress")&&!!W(n,"legis-num")},parse(r){return new $e().parse(r)}};class $e{constructor(){this.revisionCount=0,this.revisions=new WeakMap,this.committees=new Map,this.usedIds=new Set}id(){let e;
51
+ do e=ue();while(this.usedIds.has(e));return this.usedIds.add(e),e}parse(e){const t=e.documentElement;for(const p of Array.from(t.getElementsByTagName("committee-name"))){const N=p.getAttribute("commit\
52
+ tee-id");N&&this.committees.set(N,te(p.textContent??"").trim())}for(const p of Array.from(t.getElementsByTagName("*")))if(Le.has(p.localName))throw new Error(`Unsupported Congressional XML element: <${p.
53
+ localName}>. This bill requires content the XML importer does not yet support.`);const n=this.context(t,{marks:{},indent:0,quoted:0}),i=[],h=j(t),m=h.map(p=>this.blocks(p,n));for(let p=0;p<h.length;p++){
54
+ const N=h[p],A=m[p],T=h[p+1];if(N.localName==="legis-body"&&T?.localName==="legis-body"&&T.getAttribute("display-enacting-clause")==="no-display-enacting-clause"){const F=m[p+1],v=N.getAttribute("disp\
55
+ lay-enacting-clause")!=="no-display-enacting-clause"?1:0,w=qe(A.slice(v),F,()=>`congressdiff-${++this.revisionCount}`);if(w){i.push(...A.slice(0,v),...w),p++;continue}}i.push(...A)}if(!i.length)throw new Error(
56
+ "The Congressional XML bill contains no readable content.");const d=W(t,"form"),s=d&&W(d,"legis-num")?.textContent?.trim(),u=t.getElementsByTagName("short-title")[0]?.textContent?.trim(),c=s?[s,u].filter(
57
+ Boolean).join(" — "):e.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/","title")[0]?.textContent?.trim();return{type:"doc",children:i,...c?{title:c}:{}}}context(e,t){const n={...t.marks},i=e.
58
+ localName,h=e.getAttribute("changed")??(i==="added-phrase"?"added":i==="deleted-phrase"?"deleted":null);if(h==="added"||h==="deleted"){const d=h==="added"?"insertion":"deletion",s=e.getAttribute("repo\
59
+ rting-committee")||e.getAttribute("committee-id"),u=s?this.committees.get(s)??s:void 0;if(!n[d]||u&&u!==n.suggestionAuthorName){if(n.deletion&&d==="insertion")throw new Error("Unsupported Congressiona\
60
+ l XML revision: insertion nested inside a deletion.");let c=this.revisions.get(e);c||(c={[d]:!0,suggestionId:`congressrev-${++this.revisionCount}`,suggestionSource:"manual",suggestionAuthorType:"human",
61
+ suggestionLabel:d==="insertion"?"Insert":"Delete",...u?{suggestionAuthorName:u}:{}},this.revisions.set(e,c)),n.insertion&&d==="deletion"&&(n.layeredInsertion=JSON.stringify({id:n.suggestionId,source:n.
62
+ suggestionSource,authorType:n.suggestionAuthorType,authorName:n.suggestionAuthorName,label:n.suggestionLabel})),delete n.insertion,delete n.deletion,delete n.suggestionAuthorName,Object.assign(n,c)}}i===
63
+ "bold"&&(n.bold=!0),i==="italic"&&(n.italic=!0),i==="underline"&&(n.underline=!0),i==="superscript"&&(n.superscript=!0),i==="subscript"&&(n.subscript=!0);const m=e.getAttribute("href");return m&&/^(https?:\/\/|#)/i.
64
+ test(m.trim())&&(n.link=m.trim()),i==="internal-xref"&&e.getAttribute("idref")&&(n.link=`#${e.getAttribute("idref")}`),{...t,marks:n,style:e.getAttribute("style")??t.style}}text(e,t){return{type:"text",
65
+ text:e,marks:{...t.marks}}}inline(e,t){const n=this.context(e,t);if(e.localName==="linebreak")return[this.text(`
66
+ `,n)];const i=[],h=e.localName==="quote"||e.localName==="term";h&&i.push(this.text(n.quoted?"‘":"“",n));for(const m of Array.from(e.childNodes))m.nodeType===3||m.nodeType===4?i.push(this.text(te(m.
67
+ textContent??""),n)):m.nodeType===1&&i.push(...this.inline(m,h?{...n,quoted:n.quoted+1}:n));return h&&i.push(this.text(n.quoted?"’":"”",n)),i}paragraph(e,t,n,i){for(;e.length&&!e[0].text.trim();)e.
68
+ 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.
69
+ text(t.quoted>1?"‘":"“",t));const h=n?.getAttribute("id");return h&&(e[0].marks={...e[0].marks,bookmark:h}),{type:"paragraph",id:this.id(),children:e,...i?{heading:i,keepNext:!0}:{},...t.indent?{leftIndent:Math.
70
+ min(t.indent,6)}:{}}}blocks(e,t){const n=e.localName;if(n==="metadata")return[];const i=this.context(e,t);if(Object.prototype.hasOwnProperty.call(ke,n))return this.structure(e,{...i,indent:ke[n]+(i.quoted?
71
+ 1:0)});if(n==="table")return j(e).filter(s=>s.localName==="tgroup").length?j(e).flatMap(s=>s.localName==="tgroup"?[this.table(s,this.context(s,i))]:this.blocks(s,i)):[this.table(e,i)];if(n==="quoted-b\
72
+ lock"){const s=j(e).filter(p=>p.localName!=="after-quoted-block").flatMap(p=>this.blocks(p,{...i,quoted:i.quoted+1,indent:i.indent+1})),u=s[s.length-1],c=W(e,"after-quoted-block");if(u?.type==="paragr\
73
+ aph")u.children.push(this.text(i.quoted?"’":"”",i)),c&&u.children.push(...this.inline(c,i));else if(c){const p=this.paragraph([this.text(i.quoted?"’":"”",i),...this.inline(c,i)],i);p&&s.push(p)}
74
+ return s}if(!j(e).some(s=>!le.has(s.localName))){const s=this.paragraph(this.inline(e,t),i,e);if(s&&(n==="legis-num"||n==="legis-type")){s.align="center";for(const u of s.children)u.marks={...u.marks,
75
+ bold:!0}}return s?[s]:[]}const h=[];if(n==="legis-body"&&e.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"){const s=this.paragraph([this.text("Be it enacted by the Senate and Ho\
76
+ use of Representatives of the United States of America in Congress assembled,",i)],i);s&&h.push(s)}let m=[];const d=()=>{const s=this.paragraph(m,i);s&&h.push(s),m=[]};for(const s of Array.from(e.childNodes))
77
+ if(s.nodeType===3||s.nodeType===4)m.push(this.text(te(s.textContent??""),i));else if(s.nodeType===1){const u=s;le.has(u.localName)?m.push(...this.inline(u,i)):(d(),h.push(...this.blocks(u,i)))}return d(),
78
+ h}structure(e,t){const n=[],i=Object.prototype.hasOwnProperty.call(Ne,e.localName),h=W(e,"enum"),m=W(e,"header");let d=[];if(h&&(i&&d.push(this.text(e.localName==="section"&&t.style==="USC"?"§ ":`${Ne[e.
79
+ localName]} `,t)),d.push(...this.inline(h,t),this.text(" ",t))),m){const c=this.inline(m,t);for(const p of c)p.marks={...p.marks,bold:!0};d.push(...c)}const s=(c=!1)=>{const p=this.paragraph(d,t,n.length?
80
+ void 0:e,c?e.localName==="section"?2:1:void 0);p&&n.push(p),d=[]};i&&s(!0);let u=!0;for(const c of Array.from(e.childNodes))if(!(c===h||c===m)){if(c.nodeType===3||c.nodeType===4)c.textContent?.trim()&&
81
+ d.push(this.text(te(c.textContent),t));else if(c.nodeType===1){const p=c;if(p.localName==="text")u||s(),u&&!i&&m&&d.push(this.text(".—",t)),d.push(...this.inline(p,t)),u=!1;else if(le.has(p.localName))
82
+ d.push(...this.inline(p,t));else{s();const N=this.blocks(p,t),A=n[n.length-1];p.getAttribute("display-inline")==="yes-display-inline"&&A?.type==="paragraph"&&!A.heading&&N[0]?.type==="paragraph"&&(A.children.
83
+ push(this.text(" ",t),...N[0].children),N.shift()),n.push(...N)}}}return s(),n}table(e,t){const n=W(e,"tgroup")??e,i=new Map(j(n).filter(s=>s.localName==="colspec").map((s,u)=>[s.getAttribute("colname"),
84
+ Number(s.getAttribute("colnum"))||u+1])),h=j(n).flatMap(s=>s.localName==="row"?[s]:["thead","tbody","tfoot"].includes(s.localName)?j(s).filter(u=>u.localName==="row"):[]);if(!h.length)throw new Error(
85
+ "Unsupported Congressional XML table: no rows.");const m={type:"table",id:this.id(),columnWidths:[],children:h.map(s=>({type:"table-row",id:this.id(),children:j(s).filter(u=>u.localName==="entry").map(
86
+ u=>{const c=i.get(u.getAttribute("namest")),p=i.get(u.getAttribute("nameend")),N=c&&p?p-c+1:1,A=Number(u.getAttribute("morerows")??0)+1;if(u.hasAttribute("namest")&&(!c||!p)||!Number.isInteger(N)||N<1||
87
+ N>100||!Number.isInteger(A)||A<1||A>h.length)throw new Error("Unsupported Congressional XML table: invalid cell span.");const T=this.blocks(u,{...this.context(s,s.parentElement&&s.parentElement!==n?this.
88
+ context(s.parentElement,t):t),indent:0});return{type:"table-cell",id:this.id(),children:T.length?T:[{type:"paragraph",id:this.id(),children:[{type:"text",text:""}]}],...N>1?{colSpan:N}:{},...A>1?{rowSpan:A}:
89
+ {}}})}))},d=Ee(m).cols;if(!d||d>100)throw new Error("Unsupported Congressional XML table: invalid column count.");return m.columnWidths=Array(d).fill(100/d),m}}const ae=[Xe];class je{static async parseFile(e){
90
+ 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]===
91
+ 255||e[0]===0&&e[1]===60&&e[2]===0&&e[3]===63)t="utf-16be";else if(!(e[0]===239&&e[1]===187&&e[2]===191)){const i=new TextDecoder("windows-1252").decode(e.subarray(0,512));t=/^<\?xml\s[^?]*\bencoding\s*=\s*["']([^"']+)["']/i.
92
+ exec(i)?.[1]??t}let n;try{n=new TextDecoder(t,{fatal:!0}).decode(e)}catch{throw new Error(`Invalid or unsupported XML encoding: ${t}.`)}return this.fromXml(n)}static fromXml(e){if(/<!ENTITY\s/i.test(e))
93
+ throw new Error("XML entity declarations are not supported.");const t=new DOMParser().parseFromString(e.replace(/^\uFEFF/,""),"application/xml");if(!t.documentElement||t.getElementsByTagName("parserer\
94
+ ror").length)throw new Error("Invalid XML: the document is not well-formed.");const n=[[t.documentElement,0]];for(;n.length;){const[h,m]=n.pop();if(m>128)throw new Error("XML nesting exceeds the suppo\
95
+ rted depth (128).");for(const d of Array.from(h.children))n.push([d,m+1])}const i=ae.find(h=>h.matches(t));if(!i)throw new Error(`Unsupported XML schema: <${t.documentElement.tagName}>. Supported: ${ae.
96
+ map(h=>h.label).join(", ")}.`);return i.parse(t)}}export{ae as XML_SCHEMA_PARSERS,je as XmlConverter};