@reviseio/engine 3.0.0 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +33 -0
- package/assets/{historyMaterializeWorker-Kl0syEbc.js → historyMaterializeWorker-BMHTnStL.js} +131 -130
- package/chunks/{AgentHtmlConverter-BnK7NaYA.js → AgentHtmlConverter-B5qstcmM.js} +129 -128
- package/chunks/{AgentPageRenderer-DLwq6nAa.js → AgentPageRenderer-JMhCw-hi.js} +4 -4
- package/chunks/BlockDiff-C8eiZ-sf.js +45 -0
- package/chunks/{CanvasRenderer-Bqsj1S0p.js → CanvasRenderer-C2vAzLWM.js} +12 -12
- package/chunks/DocumentCompare-DX4RWeSV.js +10 -0
- package/chunks/{DocumentLayoutEngine-7iOYvyVb.js → DocumentLayoutEngine-BhcWXkeu.js} +45 -45
- package/chunks/{DocumentMutator-DIrZBuLr.js → DocumentMutator-FEFU1YM0.js} +6 -6
- package/chunks/DocumentOutline-BOZoTohH.js +4 -0
- package/chunks/{DocumentScrubber-Cz8Q05hF.js → DocumentScrubber-C4N3Qagm.js} +1 -1
- package/chunks/{DocumentSession-lXSXqua5.js → DocumentSession-gZHWP7By.js} +1 -1
- package/chunks/{DocxConverter-BfDw7777.js → DocxConverter-BOyLn5eZ.js} +709 -703
- package/chunks/{DocxGraft-D0uCnGCo.js → DocxGraft-BbE-AaM5.js} +2 -2
- package/chunks/{HtmlConverter-7Xj_g9Jr.js → HtmlConverter-BlzwsPEn.js} +3 -3
- package/chunks/MarkdownConverter-BHVskVXI.js +59 -0
- package/chunks/{OdtConverter-GwRDMnwS.js → OdtConverter-BdmBFOD1.js} +1 -1
- package/chunks/{OfficeImportShared-nlMtIUni.js → OfficeImportShared-B2XJgnDO.js} +4 -4
- package/chunks/{PdfConverter-yOlWiVIj.js → PdfConverter-DZMCHDAo.js} +6 -6
- package/chunks/{RtfConverter--wLd0qrw.js → RtfConverter-RqE-xZcW.js} +66 -66
- package/chunks/{TableBorders-C5pNsuxP.js → TableBorders-ARyTi49V.js} +1 -1
- package/chunks/TextDecoding-IPbuUqcC.js +2 -0
- package/chunks/TextFileDecoder-BZBBejlR.js +10 -0
- package/chunks/{TxtConverter-BoRVCDZw.js → TxtConverter-EPQtb6A6.js} +1 -1
- package/chunks/{Typography-DAGM5kfI.js → Typography-XR6scRNV.js} +9 -9
- package/chunks/XmlConverter-9sFRFaza.js +55 -0
- package/chunks/{capture-Dtinb4bY.js → capture-DhGn0CWA.js} +1 -1
- package/chunks/{carrier-RNy67HN4.js → carrier-D58g-gw4.js} +1 -1
- package/chunks/{chromeImageLayout-bgHYmqTp.js → chromeImageLayout-DeYYS8YP.js} +1 -1
- package/chunks/{engine-TnK8N-gT.js → engine-C5fxuZJo.js} +140 -140
- package/chunks/{footnoteFlatten-BcKaWzVs.js → footnoteFlatten-coCVFd3c.js} +1 -1
- package/chunks/{graftExport-DxAALMHp.js → graftExport-FBGE2qvt.js} +1 -1
- package/chunks/{index-CTti7wRd.js → index-Cezk1s_y.js} +4 -4
- package/chunks/{serverDocumentSession-BmYdjC6e.js → serverDocumentSession-LMu3kocH.js} +559 -560
- package/chunks/{signatures-CU2LMLBp.js → signatures-DsJnnIqV.js} +1 -1
- package/chunks/textExtraction-Bqaqt1Kg.js +2 -0
- package/engine.js +2 -2
- package/package.json +2 -2
- package/chunks/BlockDiff-BdlcKY-t.js +0 -42
- package/chunks/DocumentCompare-BqyiP87r.js +0 -6
- package/chunks/MarkdownConverter-cnW_oePY.js +0 -57
- package/chunks/TextFileDecoder--rsVs3NR.js +0 -9
- package/chunks/XmlConverter-CO8Z28dX.js +0 -55
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as d,ad as A,a7 as k,
|
|
1
|
+
import{r as d,ad as A,a7 as k,bi as x,bj as S}from"./engine-C5fxuZJo.js";const c=2;function s(e){return e===null||typeof e!="object"?JSON.stringify(e)??"null":Array.isArray(e)?`[${e.map(s).join(",")}]`:
|
|
2
2
|
`{${Object.entries(e).filter(([,r])=>r!==void 0).sort(([r],[t])=>r<t?-1:r>t?1:0).map(([r,t])=>`${JSON.stringify(r)}:${s(t)}`).join(",")}}`}function i(e,r=c){if(e===null||typeof e!="object")return e;if(Array.
|
|
3
3
|
isArray(e))return e.map(o=>i(o,r));const t=e;if(t.type==="text")return{...t,marks:(r===1?x:S)(t.marks)};const n={};for(const[o,a]of Object.entries(t))o==="indentLevel"&&t.type==="list-item"&&!a||o==="\
|
|
4
4
|
hasHeader"&&t.type==="table"&&!a||o==="footnoteNumber"&&t.type==="footnote"||(n[o]=i(a,r));if(Array.isArray(n.children)){const o=[];for(const a of n.children){const f=o[o.length-1];if(f&&f.type==="tex\
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function r(e){if(!e||typeof e!="object")return"";const t=e;if(t.type==="text"&&typeof t.text=="string")return t.text;if((t.type==="code"||t.type==="math")&&typeof t.content=="string")return t.content;
|
|
2
|
+
if(Array.isArray(t.children)){const n=t.type==="list"?" ":"";return t.children.map(o=>r(o)).join(n)}return""}export{r as e};
|
package/engine.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import{
|
|
2
|
-
e as decodeYDoc,o as documentToDocx,c as encodeYDoc,t as engineModules,i as exportDocument,D as fileToYDoc,m as installDomShims,r as parseDocument,
|
|
1
|
+
import{bU as s,bV as a,bW as e,bX as o,bY as c,bT as t,bZ as i,b_ as D,j as m,b$ as r,c3 as d,c0 as n,c1 as b,c2 as l}from"./chunks/engine-C5fxuZJo.js";export{s as createReviseYDoc,a as createServerDocumentSession,
|
|
2
|
+
e as decodeYDoc,o as documentToDocx,c as encodeYDoc,t as engineModules,i as exportDocument,D as fileToYDoc,m as installDomShims,r as parseDocument,d as seedDocRootWithClaim,n as seedYDocFromFile,b as ydocSourceFidelity,
|
|
3
3
|
l as ydocToDocument};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reviseio/engine",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"reviseBuild": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
|
+
"reviseBuild": "7cded52c5",
|
|
5
5
|
"description": "Revise's headless document engine: Word-faithful import and export, tracked changes, comments, layout, and agent tools. Free to use; the `revise` package is the API.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"docx",
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import{M as ke}from"./engine-TnK8N-gT.js";import{a as le}from"./ParagraphDiffAnalysis-DrmStvmz.js";const ce=new WeakMap,E=r=>{let s=ce.get(r);return s===void 0&&(s=r.children.map(d=>d.text).join(""),ce.
|
|
2
|
-
set(r,s)),s},z=r=>r.trim()?r.trim().split(/\s+/).length:0,ae=new WeakMap,h=r=>{let s=ae.get(r);if(s===void 0){const{id:d,children:m,...J}=r;s=JSON.stringify(J),ae.set(r,s)}return s},U=(r={})=>Object.fromEntries(
|
|
3
|
-
ke.filter(s=>r[s]!==void 0).map(s=>[s,r[s]])),be=["comment","footnoteRef","footnotePendingBody","footnotePendingKind","oxmlRange","bookmark"],de=r=>{const s={...r};for(const d of be)delete s[d];return s};
|
|
4
|
-
function xe(r){return{...r,children:r.children.map(s=>({...s,marks:U(s.marks)}))}}function he(r){return r.type==="paragraph"?`p${h(r)}${E(r)}`:r.type==="list"?`l${h(r)}${r.children.map(s=>h(s)+E(s)).join(
|
|
5
|
-
"\0")}`:JSON.stringify(r,(s,d)=>s==="id"?void 0:d)}function we(r){return r.type==="paragraph"||r.type==="list"||r.type==="table"}function ee(r,s){const d=JSON.parse(JSON.stringify(r)),m=new Map,J=[],C=O=>{
|
|
6
|
-
if(!O||typeof O!="object")return;const y=O;if(typeof y.type=="string"&&typeof y.id=="string"){const W=s();m.set(y.id,W),y.id=W}typeof y.docxTablePropertyOverrides=="string"&&J.push(y),Array.isArray(y.
|
|
7
|
-
children)&&y.children.forEach(C)};C(d);for(const O of J)try{const y=JSON.parse(O.docxTablePropertyOverrides);for(const W of["rows","rowExceptions","cells"]){const x=y[W];!x||typeof x!="object"||Array.
|
|
8
|
-
isArray(x)||(y[W]=Object.fromEntries(Object.entries(x).map(([u,$])=>[m.get(u)??u,$])))}O.docxTablePropertyOverrides=JSON.stringify(y)}catch{}return d}function te(r){const s=d=>{if(!d||typeof d!="objec\
|
|
9
|
-
t")return;const m=d;m.type==="text"&&m.marks&&(m.marks=de(m.marks)),m.children?.forEach(s)};return s(r),r}const Y=new Map,H=r=>{let s=Y.get(r);return s||(s=new Set(r.toLowerCase().match(/[\p{L}\p{N}]+/gu)??
|
|
10
|
-
[]),Y.size>5e4&&Y.clear(),Y.set(r,s)),s};function re(r,s){let d=0;for(const m of r)s.has(m)&&d++;return 2*d/(r.size+s.size||1)}function ne(r,s,d,m,J,C,O,y,W=()=>!1){const x=new Map,u=g=>{const f=d(g);
|
|
11
|
-
return x.has(f)||x.set(f,`t${x.size}`),x.get(f)+" "},$=le(r.map(u).join(""),s.map(u).join("")).diffs;let K=0,D=0,L=0,Q=0;const I=()=>{const g=r.slice(L,K),f=s.slice(Q,D);if(g.length===1&&f.length===1&&
|
|
12
|
-
W(g[0],f[0])){C(g[0],f[0]);return}const M=g.map(v=>f.map(j=>m(v,j))),w=Array.from({length:g.length+1},()=>new Float64Array(f.length+1));for(let v=g.length-1;v>=0;v--)for(let j=f.length-1;j>=0;j--)w[v][j]=
|
|
13
|
-
Math.max(w[v+1][j],w[v][j+1],M[v][j]+w[v+1][j+1]);let k=0,S=0;for(;k<g.length||S<f.length;)k<g.length&&S<f.length&&M[k][S]>0&&w[k][S]===M[k][S]+w[k+1][S+1]?C(g[k++],f[S++]):k<g.length&&(S===f.length||
|
|
14
|
-
w[k+1][S]>=w[k][S+1])?O(g[k++]):y(f[S++])};for(const[g,f]of $){const M=f.trim().split(/\s+/).filter(Boolean).length;if(g===0){I();for(let w=0;w<M;w++)J(r[K++],s[D++]);L=K,Q=D}else g===-1?K+=M:D+=M}I()}
|
|
15
|
-
const Z=8e6,pe=1e6;function Se(r,s,d){if(r.length*s.length>Z)return null;const{nextId:m,nextBlockId:J,label:C,authorName:O,authorOf:y,pairLoneChanges:W}=d,x=t=>W?t:()=>!1,u={inlineChanges:0,insertedBlocks:0,
|
|
16
|
-
deletedBlocks:0,unmarkedBlocks:0,insertedWords:0,deletedWords:0},$=t=>y?.(t)??O,K=(t,e,n)=>{const c=$(n);return{[t]:!0,suggestionId:e,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:C,
|
|
17
|
-
...c?{suggestionAuthorName:c}:{}}},D=(t,e)=>{if(!we(t))return null;const n=t.type==="paragraph"?t.children[0]?.marks:void 0,c=t.type==="paragraph"?xe(t):t,i=e==="delete"?te(ee(c,J)):c,o=m(),p=$(n),l={
|
|
18
|
-
id:o,blockId:i.id,source:"manual",authorType:"human",label:e==="insert"?"Insert":"Delete",...p?{agentName:p}:{}},a=e==="insert"?{...l,type:"block-insert"}:{...l,type:"block-delete",beforeBlock:i},b="c\
|
|
19
|
-
hildren"in i&&i.type!=="table"?P(i):"";return e==="insert"?(u.insertedBlocks++,u.insertedWords+=z(b)):(u.deletedBlocks++,u.deletedWords+=z(b)),{...i,structuralSuggestionId:o,structuralSuggestionKind:e,
|
|
20
|
-
structuralSuggestionRecord:JSON.stringify(a)}},L=(t,e,n)=>{const c=[];let i=0;for(const o of t.children){const p=Math.max(e-i,0),l=Math.min(e+n-i,o.text.length);if(l>p&&c.push({...o,text:o.text.slice(
|
|
21
|
-
p,l)}),i+=o.text.length,i>=e+n)break}return c},Q=(t,e,n)=>{const c=E(t),i=E(e);if(h(t)!==h(e)||z(c)*z(i)>pe){I(t,"delete",n),I(e,"insert",n);return}const o=[];let p=0,l=0,a="";const b=(A,N)=>{a||(a=m(),
|
|
22
|
-
u.inlineChanges++);const R=z(A.map(B=>B.text).join(""));N==="insertion"?u.insertedWords+=R:u.deletedWords+=R,o.push(...A.map(B=>{const T=U(B.marks);return{...B,marks:{...N==="deletion"?de(T):T,...K(N,
|
|
23
|
-
a,B.marks)}}}))};for(const[A,N]of le(c,i).diffs){if(A===-1)b(L(t,p,N.length),"deletion");else if(A===1)b(L(e,l,N.length),"insertion");else{const R=L(t,p,N.length),B=L(e,l,N.length);let T=0,F=0,q=0,G=0;
|
|
24
|
-
for(;T<R.length&&F<B.length;){const V=Math.min(R[T].text.length-q,B[F].text.length-G),oe={...R[T],text:R[T].text.slice(q,q+V)},X={...B[F],text:B[F].text.slice(G,G+V)},{bookmark:Ne,...me}=U(oe.marks),{
|
|
25
|
-
bookmark:Ie,...ye}=U(X.marks);JSON.stringify(me)===JSON.stringify(ye)?(a="",o.push({...X,marks:U(X.marks)})):(b([oe],"deletion"),b([X],"insertion")),q+=V,G+=V,q===R[T].text.length&&(T++,q=0),G===B[F].
|
|
26
|
-
text.length&&(F++,G=0)}}A!==1&&(p+=N.length),A!==-1&&(l+=N.length)}n.push({...e,children:o})},I=(t,e,n)=>{if(t.type==="table"){n.push(S(t,e));return}const c=D(t,e);c?n.push(c):(u.unmarkedBlocks++,e===
|
|
27
|
-
"insert"&&n.push(t))},g=(t,e)=>{if(h(t)!==h(e))return 0;const n=re(H(E(t)),H(E(e)));return n>=.5?n:0},f=(t,e,n)=>{const c=()=>{I(t,"delete",n),I(e,"insert",n)};if(t.children.length*e.children.length>Z)
|
|
28
|
-
return c();const i=[];let o=!1;if(ne(t.children,e.children,l=>h(l)+E(l),g,(l,a)=>i.push([l,a]),(l,a)=>i.push([l,a]),()=>o=!0,()=>o=!0,x((l,a)=>h(l)===h(a))),o||i.some(([l,a])=>h(l)!==h(a)||z(E(l))*z(E(
|
|
29
|
-
a))>pe))return c();const p=[];for(const[l,a]of i)Q(l,a,p);n.push({...e,children:p})},M=(t,e)=>{const n=z(P(t));e==="insert"?(u.insertedBlocks++,u.insertedWords+=n):(u.deletedBlocks++,u.deletedWords+=n)},
|
|
30
|
-
w=(t,e)=>e==="delete"?te(ee(t,J)):t,k=(t,e,n,c)=>{const i=m();return{id:i,record:{id:i,type:"table-change",tableId:t,source:"manual",authorType:"human",label:c[n],...O?{agentName:O}:{},tableRevision:{
|
|
31
|
-
version:1,suggestionKind:n,markers:e.map(([o,p])=>({kind:n==="insert"?"row-insert":"row-delete",rowId:o.id,rowIndex:p})),operations:e.map(([o,p])=>({kind:"row",action:n,rowId:o.id,rowIndex:p,row:JSON.
|
|
32
|
-
parse(JSON.stringify(o))}))}}}},S=(t,e)=>{const n=e==="delete"?te(ee(t,J)):t,{id:c,record:i}=k(n.id,n.children.map((o,p)=>[o,p]),e,{insert:"Insert table",delete:"Delete table"});return M(n,e),{...n,structuralSuggestionRecords:JSON.
|
|
33
|
-
stringify([i]),children:n.children.map(o=>({...o,diffState:e,suggestionId:c}))}},v=(t,e)=>h(t)===h(e)&&t.children.length===e.children.length&&t.children.every((n,c)=>h(n)===h(e.children[c])),j=(t,e)=>t.
|
|
34
|
-
children.every((n,c)=>n.children.length*e.children[c].children.length<=Z),_=(t,e)=>v(t,e)&&j(t,e),se=(t,e)=>({...e,children:e.children.map((n,c)=>({...n,children:ie(t.children[c].children,n.children)}))}),
|
|
35
|
-
ge=(t,e,n)=>{if(h(t)!==h(e)||t.children.length*e.children.length>Z){I(t,"delete",n),I(e,"insert",n);return}const c=[],i=[],o=(l,a)=>{const b=w(l,a),{id:A,record:N}=k(e.id,[[b,c.length]],a,{insert:"Ins\
|
|
36
|
-
ert table row",delete:"Delete table row"});i.push(N),M(b,a),c.push({...b,diffState:a,suggestionId:A})},p=l=>he(l);ne(t.children,e.children,p,(l,a)=>{if(!_(l,a))return 0;const b=re(H(P(l)),H(P(a)));return b>=
|
|
37
|
-
.5?b:0},(l,a)=>{_(l,a)?c.push(se(l,a)):(o(l,"delete"),o(a,"insert"))},(l,a)=>c.push(se(l,a)),l=>o(l,"delete"),l=>o(l,"insert"),x(_)),n.push({...e,children:c,...i.length>0?{structuralSuggestionRecords:JSON.
|
|
38
|
-
stringify(i)}:{}})},fe=(t,e)=>{if(t.type==="paragraph"&&e.type==="paragraph")return g(t,e);if(t.type==="list"&&e.type==="list"&&h(t)===h(e)||t.type==="table"&&e.type==="table"&&h(t)===h(e)){const n=re(
|
|
39
|
-
H(P(t)),H(P(e)));return n>=.3?n:0}return 0};function ie(t,e){const n=[],c=(i,o)=>{i.type==="list"&&o.type==="list"?f(i,o,n):i.type==="table"&&o.type==="table"?ge(i,o,n):i.type==="paragraph"&&o.type===
|
|
40
|
-
"paragraph"?Q(i,o,n):n.push(o)};return ne(t,e,he,fe,c,c,i=>I(i,"delete",n),i=>I(i,"insert",n),x((i,o)=>i.type===o.type&&(i.type==="paragraph"||i.type==="list"||i.type==="table")&&h(i)===h(o))),n}return{
|
|
41
|
-
blocks:ie(r,s),stats:u}}const ue=new WeakMap;function P(r){const s=ue.get(r);if(s!==void 0)return s;const d=Oe(r);return ue.set(r,d),d}function Oe(r){return"children"in r&&Array.isArray(r.children)?r.
|
|
42
|
-
children.map(s=>{const d=s;return d.type==="text"?d.text??"":P(s)}).join(" "):""}export{Se as d};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import{DocumentSession as m}from"./DocumentSession-lXSXqua5.js";import{g as i,a as g}from"./engine-TnK8N-gT.js";import{d}from"./BlockDiff-BdlcKY-t.js";const p=[{label:"headers and footers",keys:["chro\
|
|
2
|
-
me","headers","footers"]},{label:"footnotes and endnotes",keys:["notes"]},{label:"page layout",keys:["pageLayout","pageless"]}];function l(s,t){return JSON.stringify(t.map(e=>s[e]??null),(e,o)=>e==="i\
|
|
3
|
-
d"||e.startsWith("suggestion")?void 0:o)}function c(s){const t=new m(`compare-accept-${i()}`,s);try{const e=t.getDocumentMutator(),o=e.getLiveSuggestionIds();return o.length>0&&e.acceptLiveSuggestions(
|
|
4
|
-
o),t.getWorkingDocument()}finally{t.dispose()}}function f(s,t,e={}){const o=c(s),a=c(t),r=d(o.children,a.children,{nextId:()=>`compare-${i()}`,nextBlockId:g,label:e.label??"Compare",authorName:e.authorName,
|
|
5
|
-
pairLoneChanges:!0});if(!r)return null;const u=p.filter(({keys:n})=>l(o,n)!==l(a,n)).map(({label:n})=>n);return{doc:{...a,children:r.blocks},stats:r.stats,untrackedRegions:u}}export{c as acceptAllRevisions,
|
|
6
|
-
f as compareDocuments};
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import{a_ as k,b0 as y,aR as b,aK as $,b1 as w,b2 as M,b3 as T,b4 as I,a as u,b5 as _}from"./engine-TnK8N-gT.js";import{b as j}from"./TableGrid-DbroRucl.js";import{a as C,e as v,i as N}from"./ListNumbering-Qlu6AuRZ.js";
|
|
2
|
-
class L{static toMarkdown(e){if(!e||e.type!=="doc"||!e.children)return"";this.exportListNumbering=C(e);const n=[];for(const t of e.children){if(t.type==="header-footer"||t.type==="footnote")continue;if(t.
|
|
3
|
-
type==="toc"){const a=this.tocToMarkdown(t,e);a!==null&&n.push(a);continue}const s=this.blockToMarkdown(t);s!==null&&n.push(s)}const i=[...e.notes??[],...e.children.filter(t=>t.type==="footnote")];if(i.
|
|
4
|
-
length>0){const t=new Map,s=c=>{if(!c||typeof c!="object")return;if(Array.isArray(c)){c.forEach(s);return}const o=c;o.type!=="footnote"&&(o.marks?.footnoteRef&&!t.has(o.marks.footnoteRef)&&t.set(o.marks.
|
|
5
|
-
footnoteRef,o.text??""),s(o.children))};s(e.children.filter(c=>c.type!=="footnote"));let a=t.size;for(const c of i){const o=t.get(c.id)||String(a+=1),r=[];c.children.forEach((h,l)=>{const d=this.blockToMarkdown(
|
|
6
|
-
h)??"";l===0?r.push(`[^${o}]: ${d}`):r.push(d.split(`
|
|
7
|
-
`).map(p=>` ${p}`).join(`
|
|
8
|
-
`))}),n.push(r.join(`
|
|
9
|
-
|
|
10
|
-
`))}}return n.join(`
|
|
11
|
-
|
|
12
|
-
`)}static fromInlineMarkdown(e){return k(this.parseInlineContent(e))}static tocToMarkdown(e,n){const i=y(n,b(e));return i.length===0?null:i.map(t=>`${" ".repeat(t.level-1)}${t.text}`).join(`
|
|
13
|
-
`)}static blockToMarkdown(e){switch(e.type){case"paragraph":return $(e)?"---":this.paragraphToMarkdown(e);case"list":return this.listToMarkdown(e);case"table":return this.tableToMarkdown(e);case"image":
|
|
14
|
-
return this.imageToMarkdown(e);case"code":return this.codeBlockToMarkdown(e);case"math":return this.mathBlockToMarkdown(e);case"placeholder":return null;default:return null}}static paragraphToMarkdown(e){
|
|
15
|
-
const n=this.inlineNodesToMarkdown(e.children);return e.heading?`${"#".repeat(e.heading)} ${n}`:n}static inlineNodesToMarkdown(e){return this.coalesceMarkdownRuns(e).map(n=>this.textNodeToMarkdown(n)).
|
|
16
|
-
join("")}static markdownMarksKey(e){const n=e.marks||{};return JSON.stringify([!!n.code,!!n.latex,!!n.bold,!!n.italic,!!n.strikethrough,n.link||null])}static coalesceMarkdownRuns(e){const n=[];let i=null;
|
|
17
|
-
for(const t of e){const s=t.type==="text"&&!t.marks?.footnoteRef?this.markdownMarksKey(t):null,a=n[n.length-1];s!==null&&s===i&&a?n[n.length-1]={...a,text:a.text+t.text}:n.push(t),i=s}return n}static textNodeToMarkdown(e){
|
|
18
|
-
if(e.marks?.footnoteRef)return`[^${e.text}]`;let n=e.text;return n=n.replace(/\\/g,"\\\\"),e.marks&&(e.marks.code?n=`\`${n.replace(/`/g,"\\`")}\``:e.marks.latex?n=`$${n}$`:(e.marks.bold&&(n=`**${n}**`),
|
|
19
|
-
e.marks.italic&&(n=`*${n}*`),e.marks.strikethrough&&(n=`~~${n}~~`)),e.marks.link&&(n=`[${n}](${e.marks.link})`)),n}static listToMarkdown(e){const n=[],i=this.exportListNumbering?.get(e.id);let t=i?v(i):
|
|
20
|
-
e.startNumber??1;for(const s of e.children){if(s.type!=="list-item")continue;const a=" ".repeat(s.indentLevel??0),c=this.inlineNodesToMarkdown(s.children);let o;e.variant==="ordered"?(o=`${t}.`,t++):
|
|
21
|
-
e.variant==="todo"?o=s.checked?"- [x]":"- [ ]":o="-",n.push(`${a}${o} ${c}`)}return n.join(`
|
|
22
|
-
`)}static tableToMarkdown(e){if(!e.children||e.children.length===0)return"";const n=j(e),i=[];for(let t=0;t<n.rows;t++){const s=[];for(let a=0;a<n.cols;a++){const c=n.occupancy[t][a];if(!c||c.row!==t||
|
|
23
|
-
c.col!==a){s.push("");continue}const o=c.cell.children.map(r=>r.type==="paragraph"?this.inlineNodesToMarkdown(r.children):r.type==="code"?`\`${r.content||""}\``:"").join(" ");s.push(o)}if(i.push(`| ${s.
|
|
24
|
-
join(" | ")} |`),t===0){const a=s.map(()=>"---").join(" | ");i.push(`| ${a} |`)}}return i.join(`
|
|
25
|
-
`)}static imageToMarkdown(e){return``}static codeBlockToMarkdown(e){const n=e.language||"",i=e.content||"";return`\`\`\`${n}
|
|
26
|
-
${i}
|
|
27
|
-
\`\`\``}static mathBlockToMarkdown(e){return`$$
|
|
28
|
-
${e.content||""}
|
|
29
|
-
$$`}static fromMarkdown(e){const n=e.split(`
|
|
30
|
-
`),i=[];let t=0;for(;t<n.length;){const s=n[t];if(s.trim()===""){t++;continue}if(s.trim().startsWith("```")){const l=this.parseCodeBlock(n,t);i.push(l.block),t=l.nextIndex;continue}if(s.trim().startsWith(
|
|
31
|
-
"$$")){const l=this.parseMathBlock(n,t);i.push(l.block),t=l.nextIndex;continue}if(s.trim().startsWith("|")&&s.trim().endsWith("|")){const l=this.parseTable(n,t);l.block&&i.push(l.block),t=l.nextIndex;
|
|
32
|
-
continue}const a=s.match(/^\[\^([^\]]+)\]:\s?(.*)$/);if(a){const l=a[1],d=[k(this.parseInlineContent(a[2]??""))];for(t++;t<n.length;){const p=n[t];if(p.trim()===""){const f=n[t+1];if(f!==void 0&&/^ {4}/.
|
|
33
|
-
test(f)){t++;continue}break}if(!/^ {4}/.test(p))break;d.push(k(this.parseInlineContent(p.slice(4)))),t++}w(d),i.push({type:"footnote",id:`mdfn-${l}`,children:d,...M(l)==="endnote"?{noteKind:"endnote"}:
|
|
34
|
-
{}});continue}const c=T(s,"markdown");if(c){i.push(I(_[c])),t++;continue}if(this.isListItem(s)){const l=this.parseList(n,t);i.push(l.block),t=l.nextIndex;continue}const o=s.trim().match(/^!\[([^\]]*)\]\(([^)]+)\)$/);
|
|
35
|
-
if(o){i.push({type:"image",id:u(),src:o[2],alt:o[1],width:400,height:300}),t++;continue}const r=s.match(/^(#{1,6})\s+(.*)$/);if(r){const l=r[1].length,d=r[2],p=k(this.parseInlineContent(d));p.heading=
|
|
36
|
-
l,i.push(p),t++;continue}const h=k(this.parseInlineContent(s));i.push(h),t++}return N(u,i),{type:"doc",children:i.length>0?i:[k()]}}static isListItem(e){const n=e.trimStart();return!!(/^[-*+]\s/.test(
|
|
37
|
-
n)||/^\d+\.\s/.test(n)||/^[-*+]\s\[[x ]\]\s/i.test(n))}static parseList(e,n){const i=[];let t=n,s="unordered",a=1,c=!0;for(;t<e.length;){const o=e[t];if(o.trim()===""||!this.isListItem(o))break;const r=o.
|
|
38
|
-
match(/^(\s*)/),h=r?r[1].length:0,l=h===0?0:Math.max(1,Math.floor(h/2)),d=o.trimStart();let p,f;const m=d.match(/^[-*+]\s\[([x ])\]\s(.*)$/i);if(m)c&&(s="todo"),f=m[1].toLowerCase()==="x",p=m[2];else if(/^\d+\.\s/.
|
|
39
|
-
test(d)){const g=d.match(/^(\d+)\.\s(.*)$/);g?(c&&(s="ordered",a=parseInt(g[1],10)),p=g[2]):p=d}else{const g=d.match(/^[-*+]\s(.*)$/);p=g?g[1]:d}const x={type:"list-item",id:u(),children:this.parseInlineContent(
|
|
40
|
-
p),indentLevel:l};f!==void 0&&(x.checked=f),i.push(x),c=!1,t++}return{block:{type:"list",id:u(),variant:s,children:i,startNumber:s==="ordered"?a:void 0},nextIndex:t}}static parseCodeBlock(e,n){const i=e[n].
|
|
41
|
-
trim().slice(3).trim(),t=[];let s=n+1;for(;s<e.length;){const a=e[s];if(a.trim()==="```"){s++;break}t.push(a),s++}return{block:{type:"code",id:u(),content:t.join(`
|
|
42
|
-
`),language:i||void 0},nextIndex:s}}static parseMathBlock(e,n){const i=[];let t=n+1;for(;t<e.length;){const a=e[t];if(a.trim()==="$$"){t++;break}i.push(a),t++}const s=i.join(`
|
|
43
|
-
`).replace(/\\\\/g,"\\");return{block:{type:"math",id:u(),content:s},nextIndex:t}}static parseTable(e,n){const i=[];let t=n;for(;t<e.length;){const h=e[t].trim();if(!h.startsWith("|")||!h.endsWith("|"))
|
|
44
|
-
break;i.push(h),t++}if(i.length<2)return{block:null,nextIndex:t};const s=i[1];if(!/^\|[\s\-:|]+\|$/.test(s))return{block:null,nextIndex:t};const a=[],c=!0;for(let h=0;h<i.length;h++){if(h===1)continue;
|
|
45
|
-
const l=i[h].slice(1,-1).split("|").map(d=>d.trim()).map(d=>({type:"table-cell",id:u(),children:[k(this.parseInlineContent(d))]}));a.push({type:"table-row",id:u(),children:l})}const o=a[0]?.children.length||
|
|
46
|
-
1,r=Array(o).fill(100/o);return{block:{type:"table",id:u(),children:a,columnWidths:r,hasHeader:c},nextIndex:t}}static parseInlineContent(e){const n=[],i=[{regex:/\[\^([^\]]+)\]/g,type:"footnoteref"},{
|
|
47
|
-
regex:/!\[([^\]]*)\]\(([^)]+)\)/g,type:"image"},{regex:/\[([^\]]+)\]\(([^)]+)\)/g,type:"link"},{regex:/\*\*\*([^*]+)\*\*\*/g,type:"bolditalic"},{regex:/\*\*([^*]+)\*\*/g,type:"bold"},{regex:/\*([^*]+)\*/g,
|
|
48
|
-
type:"italic"},{regex:/(^|[^A-Za-z0-9_])___([^_]+)___(?![A-Za-z0-9_])/g,type:"bolditalic",underscore:!0},{regex:/(^|[^A-Za-z0-9_])__([^_]+)__(?![A-Za-z0-9_])/g,type:"bold",underscore:!0},{regex:/(^|[^A-Za-z0-9_])_([^_]+)_(?![A-Za-z0-9_])/g,
|
|
49
|
-
type:"italic",underscore:!0},{regex:/~~([^~]+)~~/g,type:"strikethrough"},{regex:/`([^`]+)`/g,type:"code"},{regex:/\$([^$]+)\$/g,type:"latex"}],t=[];for(const o of i){o.regex.lastIndex=0;let r;for(;(r=
|
|
50
|
-
o.regex.exec(e))!==null;)if(o.type==="link")t.push({index:r.index,length:r[0].length,type:o.type,content:r[1],url:r[2]});else if(o.type==="image")t.push({index:r.index,length:r[0].length,type:o.type,content:r[1]||
|
|
51
|
-
"[image]",url:r[2]});else if(o.type==="bolditalic"||o.type==="bold"||o.type==="italic")if("underscore"in o&&o.underscore){const h=r[1];t.push({index:r.index+h.length,length:r[0].length-h.length,type:o.
|
|
52
|
-
type,content:r[2]})}else t.push({index:r.index,length:r[0].length,type:o.type,content:r[1]});else t.push({index:r.index,length:r[0].length,type:o.type,content:r[1]})}t.sort((o,r)=>o.index-r.index);const s=[];
|
|
53
|
-
let a=0;for(const o of t)o.index>=a&&(s.push(o),a=o.index+o.length);let c=0;for(const o of s){if(o.index>c){const h=e.slice(c,o.index);h&&n.push({type:"text",text:h,marks:{}})}const r={type:"text",text:o.
|
|
54
|
-
content,marks:{}};switch(o.type){case"bold":r.marks={bold:!0};break;case"italic":r.marks={italic:!0};break;case"bolditalic":r.marks={bold:!0,italic:!0};break;case"strikethrough":r.marks={strikethrough:!0};
|
|
55
|
-
break;case"code":r.marks={code:!0};break;case"latex":r.text=o.content.replace(/\\\\/g,"\\"),r.marks={latex:!0};break;case"link":r.marks={link:o.url};break;case"image":r.text=o.content||"[image]",r.marks=
|
|
56
|
-
{link:o.url};break;case"footnoteref":r.text=o.content,r.marks={footnoteRef:`mdfn-${o.content}`,superscript:!0};break}n.push(r),c=o.index+o.length}if(c<e.length){const o=e.slice(c);o&&n.push({type:"tex\
|
|
57
|
-
t",text:o,marks:{}})}return n.length===0&&n.push({type:"text",text:e,marks:{}}),n}}export{L as MarkdownConverter};
|
|
@@ -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,55 +0,0 @@
|
|
|
1
|
-
import{a as A}from"./engine-TnK8N-gT.js";import{b as C}from"./TableGrid-DbroRucl.js";import{d as v}from"./BlockDiff-BdlcKY-t.js";function S(d,e,n){const t=(o,c)=>o.length>0&&o.every(l=>l.type==="parag\
|
|
2
|
-
raph"&&l.children.length>0&&l.children.every(r=>r.marks?.[c]&&!r.marks.layeredInsertion));if(!t(d,"deletion")||!t(e,"insertion"))return null;const s=v(d,e,{nextId:n,nextBlockId:A,label:"Revise bill",authorOf:o=>o?.
|
|
3
|
-
suggestionAuthorName});return s?s.blocks:null}const k={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,
|
|
4
|
-
subitem:7},E={division:"Division",title:"Title",subtitle:"Subtitle",chapter:"Chapter",subchapter:"Subchapter",part:"Part",subpart:"Subpart",section:"Sec."},y=new Set(["added-phrase","deleted-phrase","\
|
|
5
|
-
bold","italic","underline","strike","superscript","subscript","quote","term","short-title","act-name","external-xref","internal-xref","enum-in-header","header-in-text","definition","linebreak","nobrea\
|
|
6
|
-
k","sponsor","cosponsor","committee-name","text-to-insert","text-to-strike-out","omitted-text","inline-comment"]),M=new Set(["graphic","formula","footnote","footnote-ref","spanspec","entrytbl"]),m=d=>Array.
|
|
7
|
-
from(d.children),g=(d,e)=>m(d).find(n=>n.localName===e),b=d=>d.replace(/[\t\r\n ]+/g," "),I={id:"us-congress-bill",label:"U.S. Congressional bills (bill.dtd)",matches(d){const e=d.documentElement;if(e.
|
|
8
|
-
localName!=="bill"||e.namespaceURI||!g(e,"legis-body"))return!1;const n=d.doctype;if(n)return n.name==="bill"&&(n.publicId==="-//US Congress//DTDs/bill.dtd//EN"||!n.publicId&&/(?:^|\/)bill\.dtd$/i.test(
|
|
9
|
-
n.systemId));const t=g(e,"form");return!!t&&!!g(t,"congress")&&!!g(t,"legis-num")},parse(d){return new q().parse(d)}};class q{constructor(){this.revisionCount=0,this.revisions=new WeakMap,this.committees=
|
|
10
|
-
new Map,this.usedIds=new Set}id(){let e;do e=A();while(this.usedIds.has(e));return this.usedIds.add(e),e}parse(e){const n=e.documentElement;for(const i of Array.from(n.getElementsByTagName("committee-\
|
|
11
|
-
name"))){const h=i.getAttribute("committee-id");h&&this.committees.set(h,b(i.textContent??"").trim())}for(const i of Array.from(n.getElementsByTagName("*")))if(M.has(i.localName))throw new Error(`Unsu\
|
|
12
|
-
pported Congressional XML element: <${i.localName}>. This bill requires content the XML importer does not yet support.`);const t=this.context(n,{marks:{},indent:0,quoted:0}),s=[],o=m(n),c=o.map(i=>this.
|
|
13
|
-
blocks(i,t));for(let i=0;i<o.length;i++){const h=o[i],p=c[i],f=o[i+1];if(h.localName==="legis-body"&&f?.localName==="legis-body"&&f.getAttribute("display-enacting-clause")==="no-display-enacting-claus\
|
|
14
|
-
e"){const T=c[i+1],N=h.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"?1:0,w=S(p.slice(N),T,()=>`congressdiff-${++this.revisionCount}`);if(w){s.push(...p.slice(0,N),...w),i++;continue}}
|
|
15
|
-
s.push(...p)}if(!s.length)throw new Error("The Congressional XML bill contains no readable content.");const l=g(n,"form"),r=l&&g(l,"legis-num")?.textContent?.trim(),a=n.getElementsByTagName("short-tit\
|
|
16
|
-
le")[0]?.textContent?.trim(),u=r?[r,a].filter(Boolean).join(" — "):e.getElementsByTagNameNS("http://purl.org/dc/elements/1.1/","title")[0]?.textContent?.trim();return{type:"doc",children:s,...u?{title:u}:
|
|
17
|
-
{}}}context(e,n){const t={...n.marks},s=e.localName,o=e.getAttribute("changed")??(s==="added-phrase"?"added":s==="deleted-phrase"?"deleted":null);if(o==="added"||o==="deleted"){const l=o==="added"?"in\
|
|
18
|
-
sertion":"deletion",r=e.getAttribute("reporting-committee")||e.getAttribute("committee-id"),a=r?this.committees.get(r)??r:void 0;if(!t[l]||a&&a!==t.suggestionAuthorName){if(t.deletion&&l==="insertion")
|
|
19
|
-
throw new Error("Unsupported Congressional XML revision: insertion nested inside a deletion.");let u=this.revisions.get(e);u||(u={[l]:!0,suggestionId:`congressrev-${++this.revisionCount}`,suggestionSource:"\
|
|
20
|
-
manual",suggestionAuthorType:"human",suggestionLabel:l==="insertion"?"Insert":"Delete",...a?{suggestionAuthorName:a}:{}},this.revisions.set(e,u)),t.insertion&&l==="deletion"&&(t.layeredInsertion=JSON.
|
|
21
|
-
stringify({id:t.suggestionId,source:t.suggestionSource,authorType:t.suggestionAuthorType,authorName:t.suggestionAuthorName,label:t.suggestionLabel})),delete t.insertion,delete t.deletion,delete t.suggestionAuthorName,
|
|
22
|
-
Object.assign(t,u)}}s==="bold"&&(t.bold=!0),s==="italic"&&(t.italic=!0),s==="underline"&&(t.underline=!0),s==="superscript"&&(t.superscript=!0),s==="subscript"&&(t.subscript=!0);const c=e.getAttribute(
|
|
23
|
-
"href");return c&&/^(https?:\/\/|#)/i.test(c.trim())&&(t.link=c.trim()),s==="internal-xref"&&e.getAttribute("idref")&&(t.link=`#${e.getAttribute("idref")}`),{...n,marks:t,style:e.getAttribute("style")??
|
|
24
|
-
n.style}}text(e,n){return{type:"text",text:e,marks:{...n.marks}}}inline(e,n){const t=this.context(e,n);if(e.localName==="linebreak")return[this.text(`
|
|
25
|
-
`,t)];const s=[],o=e.localName==="quote"||e.localName==="term";o&&s.push(this.text(t.quoted?"‘":"“",t));for(const c of Array.from(e.childNodes))c.nodeType===3||c.nodeType===4?s.push(this.text(b(c.
|
|
26
|
-
textContent??""),t)):c.nodeType===1&&s.push(...this.inline(c,o?{...t,quoted:t.quoted+1}:t));return o&&s.push(this.text(t.quoted?"’":"”",t)),s}paragraph(e,n,t,s){for(;e.length&&!e[0].text.trim();)e.
|
|
27
|
-
shift();for(;e.length&&!e[e.length-1].text.trim();)e.pop();if(!e.length)return null;e[0].text=e[0].text.replace(/^ +/,""),e[e.length-1].text=e[e.length-1].text.replace(/ +$/,""),n.quoted&&e.unshift(this.
|
|
28
|
-
text(n.quoted>1?"‘":"“",n));const o=t?.getAttribute("id");return o&&(e[0].marks={...e[0].marks,bookmark:o}),{type:"paragraph",id:this.id(),children:e,...s?{heading:s,keepNext:!0}:{},...n.indent?{leftIndent:Math.
|
|
29
|
-
min(n.indent,6)}:{}}}blocks(e,n){const t=e.localName;if(t==="metadata")return[];const s=this.context(e,n);if(Object.prototype.hasOwnProperty.call(k,t))return this.structure(e,{...s,indent:k[t]+(s.quoted?
|
|
30
|
-
1:0)});if(t==="table")return m(e).filter(r=>r.localName==="tgroup").length?m(e).flatMap(r=>r.localName==="tgroup"?[this.table(r,this.context(r,s))]:this.blocks(r,s)):[this.table(e,s)];if(t==="quoted-b\
|
|
31
|
-
lock"){const r=m(e).filter(i=>i.localName!=="after-quoted-block").flatMap(i=>this.blocks(i,{...s,quoted:s.quoted+1,indent:s.indent+1})),a=r[r.length-1],u=g(e,"after-quoted-block");if(a?.type==="paragr\
|
|
32
|
-
aph")a.children.push(this.text(s.quoted?"’":"”",s)),u&&a.children.push(...this.inline(u,s));else if(u){const i=this.paragraph([this.text(s.quoted?"’":"”",s),...this.inline(u,s)],s);i&&r.push(i)}
|
|
33
|
-
return r}if(!m(e).some(r=>!y.has(r.localName))){const r=this.paragraph(this.inline(e,n),s,e);if(r&&(t==="legis-num"||t==="legis-type")){r.align="center";for(const a of r.children)a.marks={...a.marks,bold:!0}}
|
|
34
|
-
return r?[r]:[]}const o=[];if(t==="legis-body"&&e.getAttribute("display-enacting-clause")!=="no-display-enacting-clause"){const r=this.paragraph([this.text("Be it enacted by the Senate and House of Re\
|
|
35
|
-
presentatives of the United States of America in Congress assembled,",s)],s);r&&o.push(r)}let c=[];const l=()=>{const r=this.paragraph(c,s);r&&o.push(r),c=[]};for(const r of Array.from(e.childNodes))if(r.
|
|
36
|
-
nodeType===3||r.nodeType===4)c.push(this.text(b(r.textContent??""),s));else if(r.nodeType===1){const a=r;y.has(a.localName)?c.push(...this.inline(a,s)):(l(),o.push(...this.blocks(a,s)))}return l(),o}structure(e,n){
|
|
37
|
-
const t=[],s=Object.prototype.hasOwnProperty.call(E,e.localName),o=g(e,"enum"),c=g(e,"header");let l=[];if(o&&(s&&l.push(this.text(e.localName==="section"&&n.style==="USC"?"§ ":`${E[e.localName]} `,n)),
|
|
38
|
-
l.push(...this.inline(o,n),this.text(" ",n))),c){const u=this.inline(c,n);for(const i of u)i.marks={...i.marks,bold:!0};l.push(...u)}const r=(u=!1)=>{const i=this.paragraph(l,n,t.length?void 0:e,u?e.localName===
|
|
39
|
-
"section"?2:1:void 0);i&&t.push(i),l=[]};s&&r(!0);let a=!0;for(const u of Array.from(e.childNodes))if(!(u===o||u===c)){if(u.nodeType===3||u.nodeType===4)u.textContent?.trim()&&l.push(this.text(b(u.textContent),
|
|
40
|
-
n));else if(u.nodeType===1){const i=u;if(i.localName==="text")a||r(),a&&!s&&c&&l.push(this.text(".—",n)),l.push(...this.inline(i,n)),a=!1;else if(y.has(i.localName))l.push(...this.inline(i,n));else{
|
|
41
|
-
r();const h=this.blocks(i,n),p=t[t.length-1];i.getAttribute("display-inline")==="yes-display-inline"&&p?.type==="paragraph"&&!p.heading&&h[0]?.type==="paragraph"&&(p.children.push(this.text(" ",n),...h[0].
|
|
42
|
-
children),h.shift()),t.push(...h)}}}return r(),t}table(e,n){const t=g(e,"tgroup")??e,s=new Map(m(t).filter(r=>r.localName==="colspec").map((r,a)=>[r.getAttribute("colname"),Number(r.getAttribute("coln\
|
|
43
|
-
um"))||a+1])),o=m(t).flatMap(r=>r.localName==="row"?[r]:["thead","tbody","tfoot"].includes(r.localName)?m(r).filter(a=>a.localName==="row"):[]);if(!o.length)throw new Error("Unsupported Congressional \
|
|
44
|
-
XML table: no rows.");const c={type:"table",id:this.id(),columnWidths:[],children:o.map(r=>({type:"table-row",id:this.id(),children:m(r).filter(a=>a.localName==="entry").map(a=>{const u=s.get(a.getAttribute(
|
|
45
|
-
"namest")),i=s.get(a.getAttribute("nameend")),h=u&&i?i-u+1:1,p=Number(a.getAttribute("morerows")??0)+1;if(a.hasAttribute("namest")&&(!u||!i)||!Number.isInteger(h)||h<1||h>100||!Number.isInteger(p)||p<
|
|
46
|
-
1||p>o.length)throw new Error("Unsupported Congressional XML table: invalid cell span.");const f=this.blocks(a,{...this.context(r,r.parentElement&&r.parentElement!==t?this.context(r.parentElement,n):n),
|
|
47
|
-
indent:0});return{type:"table-cell",id:this.id(),children:f.length?f:[{type:"paragraph",id:this.id(),children:[{type:"text",text:""}]}],...h>1?{colSpan:h}:{},...p>1?{rowSpan:p}:{}}})}))},l=C(c).cols;if(!l||
|
|
48
|
-
l>100)throw new Error("Unsupported Congressional XML table: invalid column count.");return c.columnWidths=Array(l).fill(100/l),c}}const x=[I];class L{static async parseFile(e){return this.fromBytes(new Uint8Array(
|
|
49
|
-
await e.arrayBuffer()))}static fromBytes(e){let n="utf-8";if(e[0]===255&&e[1]===254||e[0]===60&&e[1]===0&&e[2]===63&&e[3]===0)n="utf-16le";else if(e[0]===254&&e[1]===255||e[0]===0&&e[1]===60&&e[2]===0&&
|
|
50
|
-
e[3]===63)n="utf-16be";else if(!(e[0]===239&&e[1]===187&&e[2]===191)){const s=new TextDecoder("windows-1252").decode(e.subarray(0,512));n=/^<\?xml\s[^?]*\bencoding\s*=\s*["']([^"']+)["']/i.exec(s)?.[1]??
|
|
51
|
-
n}let t;try{t=new TextDecoder(n,{fatal:!0}).decode(e)}catch{throw new Error(`Invalid or unsupported XML encoding: ${n}.`)}return this.fromXml(t)}static fromXml(e){if(/<!ENTITY\s/i.test(e))throw new Error(
|
|
52
|
-
"XML entity declarations are not supported.");const n=new DOMParser().parseFromString(e.replace(/^\uFEFF/,""),"application/xml");if(!n.documentElement||n.getElementsByTagName("parsererror").length)throw new Error(
|
|
53
|
-
"Invalid XML: the document is not well-formed.");const t=[[n.documentElement,0]];for(;t.length;){const[o,c]=t.pop();if(c>128)throw new Error("XML nesting exceeds the supported depth (128).");for(const l of Array.
|
|
54
|
-
from(o.children))t.push([l,c+1])}const s=x.find(o=>o.matches(n));if(!s)throw new Error(`Unsupported XML schema: <${n.documentElement.tagName}>. Supported: ${x.map(o=>o.label).join(", ")}.`);return s.parse(
|
|
55
|
-
n)}}export{x as XML_SCHEMA_PARSERS,L as XmlConverter};
|