revise 2.2.0 → 3.0.1

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