@reviseio/engine 0.0.0-stage → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/FONT-LICENSE-HAN-EXT-B.txt +91 -0
- package/FONT-LICENSE-KATEX.txt +95 -0
- package/FONT-LICENSE-LIBERATION.txt +102 -0
- package/FONT-LICENSE-NOTO-MULTILINGUAL.txt +93 -0
- package/FONT-LICENSE-NOTO-SANS-SC.txt +93 -0
- package/FONT-LICENSE-NOTO.txt +94 -0
- package/FONT-LICENSE-SOURCE-CODE-PRO.txt +94 -0
- package/FONT-LICENSE-SOURCE-SERIF-4.txt +93 -0
- package/LICENSE +141 -0
- package/README.md +11 -2
- package/THIRD-PARTY-NOTICES.md +3376 -0
- package/assets/historyMaterializeWorker-Kl0syEbc.js +618 -0
- package/chunks/AgentHtmlConverter-BnK7NaYA.js +379 -0
- package/chunks/AgentPageRenderViews-BTLjPZJQ.js +2 -0
- package/chunks/AgentPageRenderer-DLwq6nAa.js +180 -0
- package/chunks/BidiText-Bkp4Y90s.js +160 -0
- package/chunks/BlockDiff-BdlcKY-t.js +42 -0
- package/chunks/CanvasRenderer-Bqsj1S0p.js +110 -0
- package/chunks/ColorParserFull-BKH72fK8.js +446 -0
- package/chunks/DocumentCompare-BqyiP87r.js +6 -0
- package/chunks/DocumentLayout-CsU5MR-3.js +12 -0
- package/chunks/DocumentLayoutEngine-7iOYvyVb.js +218 -0
- package/chunks/DocumentMutator-DIrZBuLr.js +13 -0
- package/chunks/DocumentScrubber-Cz8Q05hF.js +21 -0
- package/chunks/DocumentSession-lXSXqua5.js +1 -0
- package/chunks/DocumentStylesheet-CEEt18sr.js +7 -0
- package/chunks/DocxConverter-BfDw7777.js +1236 -0
- package/chunks/DocxGraft-D0uCnGCo.js +8 -0
- package/chunks/HorizontalRuleOrnaments-gmUZ3R7Q.js +3 -0
- package/chunks/HtmlConverter-7Xj_g9Jr.js +267 -0
- package/chunks/ListNumbering-Qlu6AuRZ.js +23 -0
- package/chunks/MarkdownConverter-cnW_oePY.js +57 -0
- package/chunks/MathRenderer-Bz9WEVvF.js +68 -0
- package/chunks/OdtConverter-GwRDMnwS.js +125 -0
- package/chunks/OfficeImportShared-nlMtIUni.js +30 -0
- package/chunks/PageNumeralFonts-BWzI061X.js +5 -0
- package/chunks/ParagraphDiffAnalysis-DrmStvmz.js +36 -0
- package/chunks/PdfConverter-yOlWiVIj.js +457 -0
- package/chunks/RtfConverter--wLd0qrw.js +186 -0
- package/chunks/TableBorders-C5pNsuxP.js +32 -0
- package/chunks/TableGrid-DbroRucl.js +12 -0
- package/chunks/TextFileDecoder--rsVs3NR.js +9 -0
- package/chunks/TxtConverter-BoRVCDZw.js +14 -0
- package/chunks/Typography-DAGM5kfI.js +28 -0
- package/chunks/UnicodeUtils-CXtusU4g.js +10 -0
- package/chunks/XmlConverter-CO8Z28dX.js +55 -0
- package/chunks/_commonjsHelpers-DaMA6jEr.js +2 -0
- package/chunks/_revise-sdk-lazy-harfbuzz-CDWdjF9f.js +1 -0
- package/chunks/base64-Di1bxoXD.js +1 -0
- package/chunks/browser-module-CFmqfGkE.js +1791 -0
- package/chunks/bundle.min-DRpfgV69.js +782 -0
- package/chunks/capture-Dtinb4bY.js +11 -0
- package/chunks/carrier-RNy67HN4.js +6 -0
- package/chunks/chromeImageLayout-bgHYmqTp.js +18 -0
- package/chunks/engine-TnK8N-gT.js +520 -0
- package/chunks/footnoteFlatten-BcKaWzVs.js +6 -0
- package/chunks/graftExport-DxAALMHp.js +104 -0
- package/chunks/html2canvas.esm-CntiHiYW.js +997 -0
- package/chunks/index-BWdRWxoH.js +1807 -0
- package/chunks/index-CTti7wRd.js +1002 -0
- package/chunks/index.es-CI0QPo8w.js +780 -0
- package/chunks/jspdf.es.min-DU74zN8b.js +1792 -0
- package/chunks/jszip.min-CPW0h1Kx.js +476 -0
- package/chunks/katex-DWj8TvwO.js +1462 -0
- package/chunks/pdf-BLWDCiFF.js +1828 -0
- package/chunks/purify.es-BwLardii.js +107 -0
- package/chunks/serverDocumentSession-BmYdjC6e.js +1011 -0
- package/chunks/signatures-CU2LMLBp.js +21 -0
- package/chunks/suggestionAuthorship-B-IuLQlE.js +1 -0
- package/chunks/web-tree-sitter-BXGZGnNj.js +2 -0
- package/chunks/xmlScan-DXjt2cTS.js +8 -0
- package/engine.d.ts +179 -0
- package/engine.js +3 -0
- package/package.json +64 -4
- package/serverToolContract.d.ts +420 -0
- package/serverToolInputs.generated.d.ts +264 -0
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import{a_ as P,a as S}from"./engine-TnK8N-gT.js";import{N as _,k as Z,m as E,a as C,l as q,f as U,h as J,g as G,i as O,c as K,j as k,d as Q,p as Y,b as tt,n as W,M as et,s as nt}from"./OfficeImportShared-nlMtIUni.js";
|
|
2
|
+
class st{static async parseFile(e){const t=(await import("./jszip.min-CPW0h1Kx.js").then(d=>d.j)).default,n=await e.arrayBuffer(),s=await t.loadAsync(new Uint8Array(n)),a=s.file("content.xml");if(!a)throw new Error(
|
|
3
|
+
"Invalid ODT file: missing content.xml");const o=await a.async("text"),l=await s.file("styles.xml")?.async("text"),c=new Set;for(const d of[o,l??""])for(const u of d.matchAll(/xlink:href="([^"]+)"/g))
|
|
4
|
+
c.add(R(ct(u[1])));const h=new Map;return await Promise.all([...c].map(async d=>{const u=s.file(d);u&&!u.dir&&h.set(d,await u.async("uint8array"))})),this.fromContentXml(o,l,{parts:h})}static fromContentXml(e,t,n={}){
|
|
5
|
+
const s=new DOMParser,a=s.parseFromString(e,"application/xml"),o=t?s.parseFromString(t,"application/xml"):null;return new at(a,o,n).read()}}class B{constructor(e){this.styles=new Map,this.defaults=new Map,
|
|
6
|
+
this.listStyles=new Map,this.fontFaces=new Map,this.textCache=new Map,this.paraCache=new Map;for(const t of e)this.collect(t)}collect(e){for(const t of w(e,"font-face")){const n=r(t,"name"),s=r(t,"fon\
|
|
7
|
+
t-family");n&&this.fontFaces.set(n,L(s||n))}for(const t of w(e,"default-style")){const n=r(t,"family")||"paragraph";this.defaults.set(n,this.parseStyle(t,n))}for(const t of w(e,"style")){const n=r(t,"\
|
|
8
|
+
name");if(!n)continue;const s=r(t,"family")||"paragraph";this.styles.set(`${s}:${n}`,this.parseStyle(t,s))}for(const t of w(e,"list-style")){const n=r(t,"name");if(!n)continue;const s=new Map;for(const a of b(
|
|
9
|
+
t)){const o=parseInt(r(a,"level")||"1",10);if(a.localName==="list-level-style-number"){const l=r(a,"num-format");s.set(o,{ordered:l!=="",unnumbered:l==="",startValue:parseInt(r(a,"start-value")||"1",10)||
|
|
10
|
+
1})}else(a.localName==="list-level-style-bullet"||a.localName==="list-level-style-image")&&s.set(o,{ordered:!1,unnumbered:!1,startValue:1})}this.listStyles.set(n,s)}}parseStyle(e,t){const n={family:t,
|
|
11
|
+
parentName:r(e,"parent-style-name")||void 0,text:{},para:{},listStyleName:r(e,"list-style-name")??void 0,masterPageName:r(e,"master-page-name")||void 0},s=r(e,"default-outline-level");s&&(n.outlineLevel=
|
|
12
|
+
parseInt(s,10)||void 0);const a=g(e,"text-properties");a&&(n.text=this.parseTextProps(a));const o=g(e,"paragraph-properties");o&&(n.para=ot(o));const l=g(e,"table-cell-properties");if(l){n.cellBackground=
|
|
13
|
+
F(r(l,"background-color"));const d=r(l,"vertical-align");(d==="middle"||d==="bottom"||d==="top")&&(n.cellVerticalAlign=d)}const c=g(e,"table-column-properties");if(c){n.columnWidth=k(r(c,"column-width"));
|
|
14
|
+
const d=r(c,"rel-column-width");d&&(n.relColumnWidth=parseFloat(d)||void 0)}const h=g(e,"graphic-properties");return h&&(n.horizontalPos=r(h,"horizontal-pos")??void 0),n}parseTextProps(e){const t={},n=r(
|
|
15
|
+
e,"font-weight");n&&(t.bold=n==="bold"||parseInt(n,10)>=600);const s=r(e,"font-style");s&&(t.italic=s==="italic"||s==="oblique");const a=r(e,"text-underline-style");a&&(t.underline=a!=="none");const o=r(
|
|
16
|
+
e,"text-line-through-style");if(o){const x=o!=="none";x&&r(e,"text-line-through-type")==="double"?(t.doubleStrikethrough=!0,t.strikethrough=!1):t.strikethrough=x}const l=r(e,"text-position");if(l){const x=l.
|
|
17
|
+
trim().split(/\s+/)[0],N=x==="super"?1:x==="sub"?-1:parseFloat(x);t.superscript=N>0,t.subscript=N<0}const c=r(e,"font-variant");c&&(t.smallCaps=c==="small-caps");const h=r(e,"text-transform");h&&(t.allCaps=
|
|
18
|
+
h==="uppercase");const d=r(e,"display");d&&(t.hidden=d==="none");const u=r(e,"font-name"),i=r(e,"font-family");u?t.fontFamily=this.fontFaces.get(u)??L(u):i&&(t.fontFamily=L(i));const p=r(e,"font-size");
|
|
19
|
+
if(p)if(p.trim().endsWith("%"))t.fontSizePercent=parseFloat(p);else{const x=k(p);x&&(t.fontSizePx=x)}const m=r(e,"color");m&&(t.color=W(m));const y=r(e,"background-color");y&&(t.backgroundColor=F(y));
|
|
20
|
+
const v=r(e,"letter-spacing");if(v){const x=v==="normal"?null:k(v);t.letterSpacing=x?C(x):null}return t}get(e,t){return t?this.styles.get(`${e}:${t}`):void 0}chain(e,t){const n=[];let s=t;for(let o=0;s&&
|
|
21
|
+
o<16;o++){const l=this.get(e,s);if(!l)break;n.push(l),s=l.parentName}const a=this.defaults.get(e);return a&&n.push(a),n.reverse()}resolveText(e,t,n){const s=`${e}:${t??""}|${n?JSON.stringify(n):""}`,a=this.
|
|
22
|
+
textCache.get(s);if(a)return a;const o={};let l=n?.fontSizePx;const c=e==="paragraph"?this.chain(e,t):this.chain(e,t).filter(i=>i!==this.defaults.get(e));for(const i of c){const p=i.text;p.fontSizePx!==
|
|
23
|
+
void 0?l=p.fontSizePx:p.fontSizePercent!==void 0&&l!==void 0&&(l=l*p.fontSizePercent/100);for(const[m,y]of Object.entries(p))m==="fontSizePx"||m==="fontSizePercent"||y!==void 0&&(o[m]=y)}const h={...n?.
|
|
24
|
+
marks??{}},d=["bold","italic","underline","strikethrough","doubleStrikethrough","superscript","subscript","smallCaps","allCaps","hidden"];for(const i of d)o[i]===!0?h[i]=!0:o[i]===!1&&delete h[i];typeof o.
|
|
25
|
+
fontFamily=="string"&&(h.fontFamily=o.fontFamily),typeof o.color=="string"&&(o.color==="#000000"?delete h.color:h.color=o.color),o.backgroundColor===null?delete h.backgroundColor:typeof o.backgroundColor==
|
|
26
|
+
"string"&&(h.backgroundColor=o.backgroundColor),o.letterSpacing===null?delete h.letterSpacing:typeof o.letterSpacing=="number"&&(h.letterSpacing=o.letterSpacing),l!==void 0&&(h.fontSize=C(l));const u={
|
|
27
|
+
marks:h,fontSizePx:l};return this.textCache.set(s,u),u}resolvePara(e){const t=e??"",n=this.paraCache.get(t);if(n)return n;const s={};for(const a of this.chain("paragraph",e))for(const[o,l]of Object.entries(
|
|
28
|
+
a.para))l!==void 0&&(s[o]=l);return this.paraCache.set(t,s),s}findInChain(e,t,n){const s=this.chain(e,t).reverse();for(const a of s){const o=n(a);if(o!==void 0)return o}}listLevel(e,t){if(!e)return;const n=this.
|
|
29
|
+
listStyles.get(e);if(n)return n.get(t)??n.get(1)}hasListStyle(e){return!!e&&this.listStyles.has(e)}}function ot(f){const e={},t=r(f,"text-align");t&&(e.align=t==="center"?"center":t==="justify"?"justi\
|
|
30
|
+
fy":t==="end"||t==="right"?"right":null);const n=k(r(f,"margin-top"));n!==void 0&&(e.marginTop=n);const s=k(r(f,"margin-bottom"));s!==void 0&&(e.marginBottom=s);const a=k(r(f,"margin-left")??r(f,"marg\
|
|
31
|
+
in-start"));a!==void 0&&(e.marginLeft=a);const o=k(r(f,"text-indent"));o!==void 0&&(e.textIndent=o);const l=r(f,"line-height");l&&(e.lineHeight=l.trim().endsWith("%")?parseFloat(l)/100:null);const c=r(
|
|
32
|
+
f,"background-color");c&&(e.background=F(c));const h=r(f,"keep-with-next");h&&(e.keepNext=h==="always");const d=r(f,"writing-mode");d&&(e.rtl=d.startsWith("rl")),r(f,"break-before")==="page"&&(e.breakBefore=
|
|
33
|
+
!0),r(f,"break-after")==="page"&&(e.breakAfter=!0);const u={},i=j(r(f,"border"));for(const p of["top","bottom","left","right"]){const m=j(r(f,`border-${p}`))??i;m&&(u[p]=m)}return Object.keys(u).length>
|
|
34
|
+
0&&(e.borders=JSON.stringify(u)),e}function j(f){if(!f)return null;const e=f.trim().toLowerCase();if(!e||e==="none"||e==="hidden")return null;const t=e.match(/\b(solid|dashed|dotted|double)\b/),n=t?t[1]===
|
|
35
|
+
"solid"?"single":t[1]:"single",s=e.match(/([\d.]+)\s*(pt|px|cm|mm|in)/);let a=1;if(s){const l=k(`${s[1]}${s[2]}`)??1;a=Math.min(8,Math.max(1,Math.round(l)))}const o=e.match(/#[0-9a-f]{3,8}/);return{style:n,
|
|
36
|
+
width:a,color:o?o[0]:"#000000"}}function F(f){if(f)return f.trim().toLowerCase()==="transparent"?null:W(f)}function L(f){return f.split(",")[0].trim().replace(/^['"]|['"]$/g,"")}const rt="urn:oasis:na\
|
|
37
|
+
mes:tc:opendocument:xmlns:text:1.0";class at{constructor(e,t,n){this.content=e,this.stylesDoc=t,this.options=n,this.notes=new _("odtfn"),this.comments=[],this.openComments=new Map,this.changes=new Map,
|
|
38
|
+
this.activeInsertions=[],this.expandedDeletions=new Set,this.listChains={byXmlId:new Map,lastByStyle:new Map,counter:0},this.commentCounter=0,this.firstParagraphStyle=null;const s=t?g(t.documentElement,
|
|
39
|
+
"styles"):null,a=t?g(t.documentElement,"automatic-styles"):null,o=[t?g(t.documentElement,"font-face-decls"):null,g(e.documentElement,"font-face-decls")].filter(c=>!!c),l=g(e.documentElement,"automatic\
|
|
40
|
+
-styles");if(this.bodyStyles=new B([...o,s,l].filter(c=>!!c)),this.chromeStyles=new B([...o,s,a].filter(c=>!!c)),!t){const c=g(e.documentElement,"styles");c&&(this.bodyStyles=new B([...o,c,l].filter(h=>!!h)))}
|
|
41
|
+
this.styles=this.bodyStyles}read(){const e=M(this.content.documentElement,"text");e&&this.collectTrackedChanges(e);const t=e?this.convertChildren(e):[];for(;t[0]?.type==="page-break";)t.shift();it(t),
|
|
42
|
+
t.length===0&&t.push(P());const n={type:"doc",children:t};this.notes.notes.length>0&&(n.notes=this.notes.notes);const s=Z(this.comments,[n.children,n.notes??[]]);s.length>0&&(n.comments=s);const a=this.
|
|
43
|
+
masterPage();if(a){this.styles=this.chromeStyles;const o=this.readChrome(a);this.styles=this.bodyStyles,o.headers&&(n.headers=o.headers),o.footers&&(n.footers=o.footers);const l=this.pageLayout(a);l&&
|
|
44
|
+
(n.pageLayout=l)}return n}convertChildren(e){const t=[];for(const n of b(e))t.push(...this.convertBlock(n));return t}convertBlock(e){switch(e.localName){case"h":case"p":return this.convertParagraph(e);case"\
|
|
45
|
+
list":return this.convertList(e);case"numbered-paragraph":return this.convertChildren(e);case"table":{const t=this.convertTable(e);return t?[t]:[]}case"section":case"index-body":case"index-title":return this.
|
|
46
|
+
convertChildren(e);case"change-start":case"change-end":case"change":{const t=e.ownerDocument.createElementNS(rt,"text:p");t.appendChild(e.cloneNode(!0));const n=this.collectInline(t,{chrome:!1,paragraphId:""}).
|
|
47
|
+
filter(s=>s.kind==="run").map(s=>s.node);return n.length>0?[P(E(n))]:[]}case"table-of-content":case"alphabetical-index":case"illustration-index":case"table-index":case"object-index":case"user-index":case"\
|
|
48
|
+
bibliography":{const t=g(e,"index-body");return t?this.convertChildren(t):[]}case"frame":case"a":return this.frameBlocks(e,{});default:return[]}}convertParagraph(e){const t=r(e,"style-name");this.firstParagraphStyle===
|
|
49
|
+
null&&(this.firstParagraphStyle=t??"");const n=this.styles.resolvePara(t),s=S(),a=this.collectInline(e,{chrome:!1,paragraphId:s,paragraphAlign:n.align??void 0}),o=[];let l=[],c=!1;const h=u=>{const i=l.
|
|
50
|
+
filter(m=>m.text.length>0||m.marks?.footnoteRef);if(i.length===0&&!u)return;const p=this.buildParagraph(e,t,n,i);c||(p.id=s,c=!0),o.push(p),l=[]};let d=!1;for(const u of a)u.kind==="run"?l.push(u.node):
|
|
51
|
+
(h(!1),o.push(u.block),d=!0);return h(!d),n.breakBefore&&o.unshift({type:"page-break",id:S()}),n.breakAfter&&o.push({type:"page-break",id:S()}),o}buildParagraph(e,t,n,s){const a=P(s.length>0?E(s):[{type:"\
|
|
52
|
+
text",text:"",marks:{}}]);if(e.localName==="h"){const o=parseInt(r(e,"outline-level")||"1",10)||1;a.heading=Math.min(Math.max(o,1),6)}else{const o=this.styles.findInChain("paragraph",t,l=>l.outlineLevel);
|
|
53
|
+
o&&o>0&&(a.heading=Math.min(o,6))}return this.applyParaProps(a,n),a}applyParaProps(e,t){if(t.align&&(e.align=t.align),t.rtl&&(e.direction="rtl"),e.spaceBefore=C(Math.max(0,t.marginTop??0)),e.spaceAfter=
|
|
54
|
+
C(Math.max(0,t.marginBottom??0)),t.marginLeft!==void 0){const n=q(t.marginLeft);n&&(e.leftIndent=n)}if(t.textIndent!==void 0){const n=U(t.textIndent);n&&(e.firstLineIndent=n)}typeof t.lineHeight=="num\
|
|
55
|
+
ber"&&t.lineHeight>0&&(e.lineSpacing=C(t.lineHeight)),t.keepNext&&(e.keepNext=!0),t.background&&t.background!=="#ffffff"&&(e.shading=t.background),t.borders&&(e.borders=t.borders)}convertList(e){const t=[];
|
|
56
|
+
let n=null;const s=this.listStyleFor(e),a=this.chainFor(e,s),o=()=>{if(!n||n.items.length===0){n=null;return}const c={type:"list",id:S(),variant:n.ordered?"ordered":"unordered",children:n.items};n.ordered&&
|
|
57
|
+
(a?(c.numberingChainId=a.id,a.restart&&n.start!==void 0&&n.start!==1?c.startNumber=n.start:a.restart&&n.start,a.restart=!1):n.start!==void 0&&n.start!==1&&(c.startNumber=n.start)),n.props&&(c.spaceBefore=
|
|
58
|
+
C(Math.max(0,n.props.marginTop??0)),c.spaceAfter=C(Math.max(0,n.props.marginBottom??0)),typeof n.props.lineHeight=="number"&&n.props.lineHeight>0&&(c.lineSpacing=C(n.props.lineHeight))),t.push(c),n=null},
|
|
59
|
+
l=(c,h,d)=>{const u=r(c,"style-name")||d;for(const i of b(c)){if(i.localName!=="list-item"&&i.localName!=="list-header")continue;const p=i.localName==="list-header",m=r(i,"start-value");for(const y of b(
|
|
60
|
+
i)){if(y.localName==="list"){l(y,h+1,u);continue}if(y.localName!=="p"&&y.localName!=="h"){o(),t.push(...this.convertBlock(y));continue}const v=r(y,"style-name"),x=u??this.styles.findInChain("paragraph",
|
|
61
|
+
v,I=>I.listStyleName||void 0),N=this.styles.listLevel(x,h+1);if(p||y.localName==="h"||N?.unnumbered){o(),t.push(...this.convertParagraph(y));continue}const D=N?N.ordered:!1;n&&n.items.length>0&&h===0&&
|
|
62
|
+
n.ordered!==D&&o(),n||(n={items:[],ordered:D,props:this.styles.resolvePara(v)}),n.items.length===0&&(m?n.start=parseInt(m,10)||void 0:N&&N.startValue!==1&&(!a||a.restart)&&(n.start=N.startValue));const $=S(),
|
|
63
|
+
z=this.styles.resolvePara(v),X=this.collectInline(y,{chrome:!1,paragraphId:$,paragraphAlign:z.align??void 0}),A=[],T=[];for(const I of X)I.kind==="run"?A.push(I.node):T.push(I.block);n.items.push({type:"\
|
|
64
|
+
list-item",id:$,children:A.length>0?E(A):[{type:"text",text:"",marks:{}}],...h>0?{indentLevel:Math.min(h,8)}:{},...z.rtl?{direction:"rtl"}:{}}),T.length>0&&(o(),t.push(...T))}}};return l(e,0,s),o(),t}listStyleFor(e){
|
|
65
|
+
const t=r(e,"style-name");if(t&&this.styles.hasListStyle(t))return t;const n=M(e,"p")??M(e,"h"),s=n?r(n,"style-name"):null;return this.styles.findInChain("paragraph",s,a=>a.listStyleName||void 0)??t??
|
|
66
|
+
void 0}chainFor(e,t){const n=r(e,"id"),s=r(e,"continue-list"),a=r(e,"continue-numbering")==="true";let o;s?o=this.listChains.byXmlId.get(s):a&&t&&(o=this.listChains.lastByStyle.get(t));const l=!o;return o||
|
|
67
|
+
(o=`odt-list-${++this.listChains.counter}`),n&&this.listChains.byXmlId.set(n,o),t&&this.listChains.lastByStyle.set(t,o),{id:o,restart:l}}convertTable(e){const t=[],n=[],s=[],a=l=>{for(const c of b(l))
|
|
68
|
+
if(c.localName==="table-column"){const h=this.styles.get("table-column",r(c,"style-name")),d=h?.relColumnWidth??h?.columnWidth??0,u=Math.min(64,Math.max(1,parseInt(r(c,"number-columns-repeated")||"1",
|
|
69
|
+
10)||1));for(let i=0;i<u;i++)s.push(d)}else(c.localName==="table-columns"||c.localName==="table-column-group")&&a(c)};a(e);const o=l=>{for(const c of b(l))c.localName==="table-row"?n.push(c):(c.localName===
|
|
70
|
+
"table-header-rows"||c.localName==="table-rows"||c.localName==="table-row-group")&&o(c)};o(e);for(const l of n){const c=[];for(const h of b(l)){if(h.localName!=="table-cell")continue;const d=this.convertChildren(
|
|
71
|
+
h).filter(v=>v.type!=="page-break"),u={type:"table-cell",id:S(),children:d.length>0?d:[P()]},i=H(r(h,"number-columns-spanned")),p=H(r(h,"number-rows-spanned"));i>1&&(u.colSpan=i),p>1&&(u.rowSpan=p);const m=this.
|
|
72
|
+
styles.get("table-cell",r(h,"style-name"));m?.cellBackground&&(u.backgroundColor=m.cellBackground),m?.cellVerticalAlign&&m.cellVerticalAlign!=="top"&&(u.verticalAlign=m.cellVerticalAlign),c.push(u);const y=parseInt(
|
|
73
|
+
r(h,"number-columns-repeated")||"1",10)-1;for(let v=0;v<y&&v<20;v++)c.push(J())}c.length>0&&t.push({type:"table-row",id:S(),children:c})}return G(t,{columnWidths:s.every(l=>l>0)?s:void 0,hasHeader:b(e).
|
|
74
|
+
some(l=>l.localName==="table-header-rows")})}collectInline(e,t){const n=[],s=(l,c)=>{if(!l)return;const h=this.decorate(c),d=n[n.length-1];d?.kind==="run"&&!d.node.marks?.footnoteRef&&nt(d.node.marks,
|
|
75
|
+
h)?d.node.text+=l:n.push({kind:"run",node:{type:"text",text:l,marks:{...h}}})},a=(l,c,h)=>{if(l.nodeType===Node.TEXT_NODE){const i=h?{...c.marks,link:h}:c.marks;let p=(l.textContent??"").replace(/[ \t\r\n]+/g,
|
|
76
|
+
" ");const m=n[n.length-1],y=m?.kind==="run"?m.node.text:"";p.startsWith(" ")&&(n.length===0||y.endsWith(" "))&&(p=p.slice(1)),s(p,i);return}if(l.nodeType!==Node.ELEMENT_NODE)return;const d=l,u=h?{...c.
|
|
77
|
+
marks,link:h}:c.marks;switch(d.localName){case"span":{const i=this.styles.resolveText("text",r(d,"style-name"),c);d.childNodes.forEach(p=>a(p,i,h));return}case"a":{const i=d.getAttributeNS("http://www\
|
|
78
|
+
.w3.org/1999/xlink","href")||d.getAttribute("xlink:href")||void 0,p=r(d,"style-name")?this.styles.resolveText("text",r(d,"style-name"),c):c,m=i&&!i.startsWith("#")?tt(i)??h:h;d.childNodes.forEach(y=>a(
|
|
79
|
+
y,p,m));return}case"s":{const i=parseInt(r(d,"c")||"1",10);s(" ".repeat(Math.min(Math.max(i,1),100)),u);return}case"tab":s(" ",u);return;case"line-break":s(`
|
|
80
|
+
`,u);return;case"page-number":s(d.textContent||"1",{...u,field:"page"});return;case"page-count":s(d.textContent||"1",{...u,field:"numPages"});return;case"note":{if(t.chrome)return;const i=r(d,"note-cl\
|
|
81
|
+
ass")==="endnote"?"endnote":"footnote",p=g(d,"note-body"),m=p?this.convertChildren(p):[];n.push({kind:"run",node:this.notes.add(i,m,this.decorate(u))});return}case"annotation":t.chrome||this.addAnnotation(
|
|
82
|
+
d,t);return;case"annotation-end":{const i=r(d,"name");i&&this.openComments.delete(i);return}case"change-start":{const i=r(d,"change-id"),p=i?this.changes.get(i):void 0;i&&p?.kind==="insertion"&&this.activeInsertions.
|
|
83
|
+
push(i);return}case"change-end":{const i=r(d,"change-id"),p=i?this.activeInsertions.indexOf(i):-1;p>=0&&this.activeInsertions.splice(p,1);return}case"change":{const i=r(d,"change-id"),p=i?this.changes.
|
|
84
|
+
get(i):void 0;if(!i||p?.kind!=="deletion"||this.expandedDeletions.has(i))return;this.expandedDeletions.add(i);const m=O("deletion",`odtrev-${i}`,p.author,p.date);p.deleted.forEach((y,v)=>{v>0&&n.push(
|
|
85
|
+
{kind:"run",node:{type:"text",text:`
|
|
86
|
+
`,marks:V(u,m)}});for(const x of this.collectInline(y,t))x.kind==="run"&&n.push({kind:"run",node:{...x.node,marks:V(x.node.marks??{},m)}})});return}case"frame":case"custom-shape":case"rect":case"ellip\
|
|
87
|
+
se":case"polygon":case"path":case"g":if(t.chrome)return;for(const i of this.frameBlocks(d,t))n.push({kind:"block",block:i});return;case"ruby-text":case"title":case"desc":case"bookmark":case"bookmark-s\
|
|
88
|
+
tart":case"bookmark-end":case"soft-page-break":case"reference-mark":case"reference-mark-start":case"reference-mark-end":case"hidden-text":case"hidden-paragraph":case"note-citation":case"sequence-decls":case"\
|
|
89
|
+
variable-decls":case"user-field-decls":return;default:d.childNodes.forEach(i=>a(i,c,h))}},o=this.styles.resolveText("paragraph",r(e,"style-name"));return e.childNodes.forEach(l=>a(l,o)),n}decorate(e){
|
|
90
|
+
let t=e;this.openComments.size>0&&(t={...t,comment:[...this.openComments.values()].join(",")});const n=this.activeInsertions[this.activeInsertions.length-1];if(n){const s=this.changes.get(n);t={...t,...O(
|
|
91
|
+
"insertion",`odtrev-${n}`,s.author,s.date)}}return t}addAnnotation(e,t){this.commentCounter++;const n=`odtcmt-${this.commentCounter}`;let s="",a="",o;const l=[];for(const i of b(e))i.localName==="crea\
|
|
92
|
+
tor"?s=i.textContent?.trim()??"":i.localName==="creator-initials"||i.localName==="sender-initials"?a=i.textContent?.trim()??"":i.localName==="date"&&(o=i.textContent?.trim());for(const i of[...w(e,"p"),
|
|
93
|
+
...w(e,"h")])l.push(lt(i));const c=o?Date.parse(o.endsWith("Z")||/[+-]\d\d:\d\d$/.test(o)?o:`${o}Z`):NaN,h=r(e,"name"),d=r(e,"parent-name"),u={id:n,author:s||a||"Unknown",...a?{initials:a}:{},createdAt:new Date(
|
|
94
|
+
Number.isFinite(c)?c:0).toISOString(),bodyMd:l.map(i=>i.trim()).filter(i=>i.length>0).join(`
|
|
95
|
+
|
|
96
|
+
`),...r(e,"resolved")==="true"?{resolved:!0}:{}};if(d){const i=this.comments.find(p=>p.odtName===d);i&&(u.parentId=i.id)}this.annotationEnds??(this.annotationEnds=new Set([...this.content.getElementsByTagNameNS(
|
|
97
|
+
"*","annotation-end")].map(i=>r(i,"name")).filter(i=>!!i))),h&&this.annotationEnds.has(h)&&h?this.openComments.set(h,n):u.parentId||(u.anchorBlockId=t.paragraphId),h&&Object.defineProperty(u,"odtName",
|
|
98
|
+
{value:h,enumerable:!1}),this.comments.push(u)}collectTrackedChanges(e){const t=g(e,"tracked-changes");if(t)for(const n of b(t)){if(n.localName!=="changed-region")continue;const s=r(n,"id"),a=b(n)[0];
|
|
99
|
+
if(!s||!a)continue;const o=g(a,"change-info");let l,c;if(o){for(const u of b(o))if(u.localName==="creator"&&(l=u.textContent?.trim()||void 0),u.localName==="date"){const i=u.textContent?.trim()??"",p=Date.
|
|
100
|
+
parse(/Z$|[+-]\d\d:\d\d$/.test(i)?i:`${i}Z`);Number.isFinite(p)&&(c=p)}}const h=a.localName==="insertion"?"insertion":a.localName==="deletion"?"deletion":"format",d=b(a).filter(u=>u.localName==="p"||u.
|
|
101
|
+
localName==="h");this.changes.set(s,{kind:h,author:l,date:c,deleted:d})}}frameBlocks(e,t){if(e.localName==="a")return b(e).flatMap(o=>this.frameBlocks(o,t));if(e.localName!=="frame")return b(e).filter(
|
|
102
|
+
o=>o.localName==="p"||o.localName==="list").flatMap(o=>this.convertBlock(o));const n=o=>o.originalFormat?2:o.src.startsWith("data:image/svg")?1:0,s=b(e).filter(o=>o.localName==="image").map(o=>this.imageFromElement(
|
|
103
|
+
o,e,t)).filter(o=>!!o).sort((o,l)=>n(o)-n(l));if(s.length>0)return[s[0]];const a=g(e,"text-box");return a?this.convertChildren(a):[]}imageFromElement(e,t,n){let s;const a=e.getAttributeNS("http://www.\
|
|
104
|
+
w3.org/1999/xlink","href")||e.getAttribute("xlink:href");if(a)s=this.options.parts?.get(R(a));else{const p=g(e,"binary-data")?.textContent?.replace(/\s+/g,"");if(p)try{s=Uint8Array.from(atob(p),m=>m.charCodeAt(
|
|
105
|
+
0))}catch{s=void 0}}if(!s||s.length===0)return null;const o=K(s);if(!o)return null;const l=k(r(t,"width")),c=k(r(t,"height")),h=g(t,"title")?.textContent?.trim(),d=g(t,"desc")?.textContent?.trim(),u=this.
|
|
106
|
+
styles.get("graphic",r(t,"style-name"))?.horizontalPos,i=u==="center"?"center":u==="right"||u==="outside"?"right":n.paragraphAlign==="center"||n.paragraphAlign==="right"?n.paragraphAlign:void 0;return Q(
|
|
107
|
+
s,o,{width:l,height:c},{alt:d||h||r(t,"name")||void 0,align:i})}masterPage(){if(!this.stylesDoc)return null;const e=g(this.stylesDoc.documentElement,"master-styles");if(!e)return null;const t=b(e).filter(
|
|
108
|
+
s=>s.localName==="master-page");if(t.length===0)return null;const n=this.firstParagraphStyle!==null?this.bodyStyles.findInChain("paragraph",this.firstParagraphStyle,s=>s.masterPageName):void 0;return n&&
|
|
109
|
+
t.find(s=>r(s,"name")===n)||t.find(s=>r(s,"name")==="Standard"||r(s,"name")==="Default")||t[0]}readChrome(e){const t={},n=[["header","header","default"],["footer","footer","default"],["header-first","\
|
|
110
|
+
header","first"],["footer-first","footer","first"],["header-left","header","even"],["footer-left","footer","even"]];for(const[s,a,o]of n){const l=g(e,s);if(!l||r(l,"display")==="false")continue;const c=this.
|
|
111
|
+
chromeParagraphs(l);if(!c.some(d=>d.children.some(u=>u.text.trim()!==""||u.marks?.field)))continue;const h=a==="header"?t.headers??(t.headers={}):t.footers??(t.footers={});h[o]=c}return t}chromeParagraphs(e){
|
|
112
|
+
if(["region-left","region-center","region-right"].map(n=>g(e,n)).filter(n=>!!n).length>0){const n=[];return["region-left","region-center","region-right"].forEach((s,a)=>{a>0&&n.push({type:"text",text:"\
|
|
113
|
+
",marks:{}});const o=g(e,s);if(o)for(const l of b(o).filter(c=>c.localName==="p"))n.push(...this.chromeRuns(l))}),[P(E(n))]}const t=[];for(const n of b(e)){if(n.localName!=="p"&&n.localName!=="h")continue;
|
|
114
|
+
const s=P(E(this.chromeRuns(n))),a=this.styles.resolvePara(r(n,"style-name"));a.align&&(s.align=a.align),t.push(s)}return t}chromeRuns(e){const t=this.collectInline(e,{chrome:!0,paragraphId:""}).filter(
|
|
115
|
+
n=>n.kind==="run").map(n=>n.node);return t.length>0?t:[{type:"text",text:"",marks:{}}]}pageLayout(e){const t=r(e,"page-layout-name");if(!t||!this.stylesDoc)return;const n=w(this.stylesDoc.documentElement,
|
|
116
|
+
"page-layout").find(a=>r(a,"name")===t),s=n?g(n,"page-layout-properties"):null;if(s)return Y({widthPx:k(r(s,"page-width")),heightPx:k(r(s,"page-height")),landscape:r(s,"print-orientation")==="landscap\
|
|
117
|
+
e",marginTopPx:k(r(s,"margin-top")),marginRightPx:k(r(s,"margin-right")),marginBottomPx:k(r(s,"margin-bottom")),marginLeftPx:k(r(s,"margin-left"))})}}function H(f){const e=parseInt(f||"1",10);return Number.
|
|
118
|
+
isFinite(e)?Math.min(Math.max(1,e),et):1}function it(f){for(;f.length>1;){const e=f[f.length-1];if(e.type==="paragraph"&&!e.borders&&e.children.every(t=>t.text.trim()===""&&!t.marks?.footnoteRef))f.pop();else
|
|
119
|
+
break}}function lt(f){let e="";const t=n=>{if(n.nodeType===Node.TEXT_NODE){e+=(n.textContent??"").replace(/[\r\n]+/g,"");return}if(n.nodeType!==Node.ELEMENT_NODE)return;const s=n;s.localName==="s"?e+=
|
|
120
|
+
" ".repeat(parseInt(r(s,"c")||"1",10)||1):s.localName==="tab"?e+=" ":s.localName==="line-break"?e+=`
|
|
121
|
+
`:s.childNodes.forEach(t)};return f.childNodes.forEach(t),e}function V(f,e){const{insertion:t,deletion:n,suggestionId:s,suggestionSource:a,suggestionAuthorType:o,suggestionLabel:l,suggestionCreatedAt:c,
|
|
122
|
+
suggestionAuthorName:h,...d}=f;return{...d,...e}}function R(f){return f.replace(/^\.\//,"").replace(/^\//,"")}function ct(f){return f.replace(/&/g,"&").replace(/"/g,'"').replace(/'/g,"'").
|
|
123
|
+
replace(/</g,"<").replace(/>/g,">")}function b(f){const e=[];return f.childNodes.forEach(t=>{t.nodeType===Node.ELEMENT_NODE&&e.push(t)}),e}function g(f,e){for(const t of b(f))if(t.localName===e)
|
|
124
|
+
return t;return null}function M(f,e){if(f.localName===e)return f;for(const t of b(f)){const n=M(t,e);if(n)return n}return null}function w(f,e){const t=[],n=s=>{s.localName===e&&t.push(s);for(const a of b(
|
|
125
|
+
s))n(a)};return n(f),t}function r(f,e){const t=f.attributes;for(let n=0;n<t.length;n++)if(t[n].localName===e)return t[n].value;return null}export{st as OdtConverter};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import{a_ as l,b1 as M,ae as P,aN as m,bj as g,a as f,aH as y}from"./engine-TnK8N-gT.js";import{R as v}from"./suggestionAuthorship-B-IuLQlE.js";import{b as S}from"./TableGrid-DbroRucl.js";const k=new Set(
|
|
2
|
+
["http","https","mailto","tel","ftp"]);function j(n){const t=n?.trim();if(!t)return;const e=t.replace(/[\u0000- \u007f]/g,"");if(e.startsWith("//")||e.startsWith("\\\\"))return;const r=/^([a-z][a-z0-9+.-]*):/i.
|
|
3
|
+
exec(e)?.[1];if(!(r&&!k.has(r.toLowerCase())))return t}function $(n){return n/15}function d(n){return Math.round(n*100)/100}function A(n){if(!n)return;const t=/^\s*(-?\d*\.?\d+)\s*(pt|px|cm|mm|in|pc|em)\s*$/i.
|
|
4
|
+
exec(n);if(!t)return;const e=parseFloat(t[1]);if(Number.isFinite(e))switch(t[2].toLowerCase()){case"px":return e;case"pt":return e*96/72;case"pc":return e*16;case"in":return e*96;case"cm":return e*96/
|
|
5
|
+
2.54;case"mm":return e*96/25.4;case"em":return e*16;default:return}}function L(n){if(n>0)return m(n,{indentStepPx:g,storedAsUnits:!1})}function N(n){if(n<0)return-1;if(n>0)return m(n,{indentStepPx:g,storedAsUnits:!1,
|
|
6
|
+
firstLine:!0})}function z(n){const t={};if(n.widthPx&&n.heightPx){const s=y(n.widthPx,n.heightPx);s&&F(s.pageSize,n)&&(t.pageSize=s.pageSize,t.orientation=n.landscape?"landscape":s.orientation)}const e=s=>s!==
|
|
7
|
+
void 0&&Number.isFinite(s)&&s>=0&&s<=288?Math.round(s):void 0,r=e(n.marginTopPx),i=e(n.marginRightPx),a=e(n.marginBottomPx),c=e(n.marginLeftPx);return r!==void 0&&(t.marginTopPx=r),i!==void 0&&(t.marginRightPx=
|
|
8
|
+
i),a!==void 0&&(t.marginBottomPx=a),c!==void 0&&(t.marginLeftPx=c),Object.keys(t).length>0?t:void 0}const C={letter:[8.5,11],tabloid:[11,17],legal:[8.5,14],statement:[5.5,8.5],executive:[7.25,10.5],folio:[
|
|
9
|
+
8.5,13],a3:[11.69,16.54],a4:[8.27,11.69],a5:[5.83,8.27],b4:[9.84,13.9],b5:[6.93,9.84]};function F(n,t){const e=C[n];if(!e||!t.widthPx||!t.heightPx)return!1;const r=Math.min(t.widthPx,t.heightPx)/96,i=Math.
|
|
10
|
+
max(t.widthPx,t.heightPx)/96;return Math.abs(r-e[0])<.25&&Math.abs(i-e[1])<.25}function I(n){if(!n)return;const t=n.trim().toLowerCase();if(/^#[0-9a-f]{6}$/.test(t))return t;if(/^#[0-9a-f]{3}$/.test(t))
|
|
11
|
+
return"#"+t.slice(1).split("").map(e=>e+e).join("")}function W(n,t,e){const r=i=>Math.max(0,Math.min(255,Math.round(i))).toString(16).padStart(2,"0");return`#${r(n)}${r(t)}${r(e)}`}function E(n){let t="";
|
|
12
|
+
for(let e=0;e<n.length;e+=32768)t+=String.fromCharCode.apply(null,Array.from(n.subarray(e,e+32768)));return btoa(t)}const R={png:"image/png",jpeg:"image/jpeg",gif:"image/gif",bmp:"image/bmp",webp:"ima\
|
|
13
|
+
ge/webp",svg:"image/svg+xml",emf:"image/x-emf",wmf:"image/x-wmf"};function T(n){if(n.length<4)return;const t=n;if(t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71)return"png";if(t[0]===255&&t[1]===216)return"\
|
|
14
|
+
jpeg";if(t[0]===71&&t[1]===73&&t[2]===70)return"gif";if(t[0]===66&&t[1]===77)return"bmp";if(t.length>=12&&t[0]===82&&t[1]===73&&t[2]===70&&t[3]===70&&t[8]===87&&t[9]===69&&t[10]===66&&t[11]===80)return"\
|
|
15
|
+
webp";if(t.length>=44&&t[0]===1&&t[1]===0&&t[40]===32&&t[41]===69&&t[42]===77&&t[43]===70)return"emf";if(t[0]===215&&t[1]===205&&t[2]===198&&t[3]===154||(t[0]===1||t[0]===2)&&t[1]===0&&t[2]===9&&t[3]===
|
|
16
|
+
0)return"wmf";const e=new TextDecoder("utf-8").decode(n.subarray(0,256));if(/<svg[\s>]/i.test(e)||/^\s*<\?xml[^>]*>\s*(<!--[\s\S]*?-->\s*)*<svg/i.test(e))return"svg"}function B(n,t,e,r={}){const i=`da\
|
|
17
|
+
ta:${R[t]};base64,${E(n)}`,a=Math.max(1,Math.round(e.width&&e.width>0?e.width:200)),c=Math.max(1,Math.round(e.height&&e.height>0?e.height:200)),s={type:"image",id:f(),src:i,width:a,height:c};return r.
|
|
18
|
+
alt&&(s.alt=r.alt),r.align&&(s.align=r.align),(t==="emf"||t==="wmf")&&(s.originalFormat=t,s.originalDataUrl=i),s}function p(){return{type:"table-cell",id:f(),children:[l()]}}const x=1e3,D=1e5;function b(n){
|
|
19
|
+
return Math.max(1,Math.min(x,Math.floor(D/Math.max(1,n))))}function H(n,t={}){const e=n.filter(o=>o.children.length>0);if(e.length===0)return null;const r=b(e.length);for(const o of e)O(o,r);const i=S(
|
|
20
|
+
{children:e,columnWidths:[]}),a=i.cols;if(a===0)return null;for(let o=0;o<e.length;o++){let u=0;for(let h=0;h<a;h++)i.occupancy[o]?.[h]||u++;for(let h=0;h<u;h++)e[o].children.push(p())}let c=Array(a).
|
|
21
|
+
fill(100/a);const s=t.columnWidths;if(s&&s.length===a&&s.every(o=>Number.isFinite(o)&&o>0)){const o=s.reduce((u,h)=>u+h,0);c=s.map(u=>d(u/o*100))}return{type:"table",id:f(),children:e,columnWidths:c,...t.
|
|
22
|
+
hasHeader?{hasHeader:!0}:{}}}function O(n,t){const e=n.children;if(e.length>t){const i=e[t-1];for(const a of e.slice(t))i.children.push(...a.children);e.length=t}let r=0;e.forEach((i,a)=>{const c=t-r-
|
|
23
|
+
(e.length-1-a),s=Math.min(i.colSpan??1,Math.max(1,c));s>1?i.colSpan=s:delete i.colSpan,r+=s})}class U{constructor(t){this.prefix=t,this.notes=[],this.counters={footnote:0,endnote:0}}add(t,e,r={}){this.
|
|
24
|
+
counters[t]+=1;const i=`${this.prefix}-${this.notes.length+1}`,a=e.length>0?e:[l()];M(a),this.notes.push({type:"footnote",id:i,...t==="endnote"?{noteKind:"endnote"}:{},children:a});const{footnoteRef:c,
|
|
25
|
+
superscript:s,subscript:o,...u}=r;return{type:"text",text:P(this.counters[t],t),marks:{...u,footnoteRef:i,superscript:!0}}}}function K(n,t,e,r){const i=e?.trim()===v;return{...n==="insertion"?{insertion:!0}:
|
|
26
|
+
{deletion:!0},suggestionId:t,suggestionSource:i?"agent":"manual",suggestionAuthorType:i?"ai":"human",suggestionLabel:n==="insertion"?"Insert":"Delete",...r!==void 0&&Number.isFinite(r)?{suggestionCreatedAt:r}:
|
|
27
|
+
{},...e?{suggestionAuthorName:e}:{}}}function _(n,t){const e=new Set,r=i=>{if(!i||typeof i!="object")return;if(Array.isArray(i)){i.forEach(r);return}const a=i;a.marks?.comment&&a.marks.comment.split("\
|
|
28
|
+
,").forEach(c=>e.add(c)),r(a.children)};return t.forEach(r),n.filter(i=>e.has(i.id)||i.anchorBlockId!==void 0||i.parentId!==void 0&&e.has(i.parentId))}function q(n){const t=[];for(const e of n){const r=t[t.
|
|
29
|
+
length-1];r&&w(r.marks,e.marks)?r.text+=e.text:t.push({...e,...e.marks?{marks:{...e.marks}}:{}})}return t}function w(n,t){const e=n??{},r=t??{},i=new Set([...Object.keys(e),...Object.keys(r)]);for(const a of i)
|
|
30
|
+
if(e[a]!==r[a])return!1;return!0}export{x as M,U as N,d as a,j as b,T as c,B as d,b as e,N as f,H as g,p as h,K as i,A as j,_ as k,L as l,q as m,I as n,z as p,W as r,w as s,$ as t};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const M=new WeakMap;function x(e,i){if(!e)return;const n=M.get(e);if(n&&n.defaultFont===i)return n.fonts;const c=e.lineNumberMarks!==void 0||(e.pageGeometries??[]).some(t=>t.lineNumbering||t.pleadingGrid)?
|
|
2
|
+
y(e.fragments,i):void 0;return M.set(e,{defaultFont:i,fonts:c}),c}function y(e,i){const n=new Map;for(const t of e){if(t.isChrome||t.repeatedHeader)continue;const f=t.pageNumber;if(f===void 0)continue;
|
|
3
|
+
const s=t.block.children;if(!Array.isArray(s))continue;const o=t.charRange;let r=0;for(const g of s){const a=g;if(a.type!=="text"||typeof a.text!="string")continue;const l=r;r+=a.text.length;const p=o?
|
|
4
|
+
Math.max(l,o.start):l,d=o?Math.min(r,o.end):r;if(d<=p)continue;const m=a.text.slice(p-l,d-l).replace(/\s+/g,"").length;if(m===0)continue;const h=a.marks?.fontFamily||i;let u=n.get(f);u||(u=new Map,n.set(
|
|
5
|
+
f,u)),u.set(h,(u.get(h)??0)+m)}}const c=new Map;for(const[t,f]of n){let s="",o=0;for(const[r,g]of f)g>o&&(s=r,o=g);s&&c.set(t,s)}return c}export{x as g};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import{g as O}from"./UnicodeUtils-CXtusU4g.js";let z=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});z.decode();const b=new TextEncoder;"encodeInto"in b||(b.encodeInto=function(e,n){const t=b.encode(
|
|
2
|
+
e);return n.set(t),{read:e.length,written:t.length}});function F(e,n){return null}function J(e,n){return null}let j;function P(e){if(j===void 0){const n=Intl.Segmenter;j=n?new n("en",{granularity:"sen\
|
|
3
|
+
tence"}):null}return j?Array.from(j.segment(e),({segment:n})=>n):[e]}const T=/[\p{L}\p{N}\p{M}_'’]/u;function $(e,n){return n===0||n===e.length||!T.test(e[n-1])||!T.test(e[n])}function W(e,n,t){if(!t)
|
|
4
|
+
return;const l=e[e.length-1];l?.[0]===n?l[1]+=t:e.push([n,t])}function L(e){const n=new Set(O(e));return t=>n.has(t)&&$(e,t)}function q(e){const n=e.filter(([u])=>u!==1).map(([,u])=>u).join(""),t=e.filter(
|
|
5
|
+
([u])=>u!==-1).map(([,u])=>u).join(""),l=L(n),r=L(t),s=[];let g=0,f=0,h="",o="";const a=()=>{W(s,-1,h),W(s,1,o),h=o=""};for(const[u,p]of e){if(u===0){let d=0,i=p.length;for(;d<i&&(!l(g+d)||!r(f+d));)d++;
|
|
6
|
+
for(;i>d&&(!l(g+i)||!r(f+i));)i--;h+=p.slice(0,d),o+=p.slice(0,d),i>d&&(a(),W(s,0,p.slice(d,i))),h+=p.slice(i),o+=p.slice(i)}else u===-1?h+=p:o+=p;u!==1&&(g+=p.length),u!==-1&&(f+=p.length)}return a(),
|
|
7
|
+
s}function D(e){e=q(e);const n=[];for(let t=0;t<e.length;t++){const[l,r]=e[t];if(l!==-1||e[t+1]?.[0]!==1){W(n,l,r);continue}const s=e[++t][1],g=L(r),f=L(s);let h=0;for(;h<Math.min(r.length,s.length)&&
|
|
8
|
+
r[h]===s[h];)h++;for(;h>0&&(!g(h)||!f(h));)h--;let o=0;for(;o<Math.min(r.length,s.length)-h&&r[r.length-1-o]===s[s.length-1-o];)o++;for(;o>0&&(!g(r.length-o)||!f(s.length-o));)o--;W(n,0,r.slice(0,h)),
|
|
9
|
+
W(n,-1,r.slice(h,r.length-o)),W(n,1,s.slice(h,s.length-o)),W(n,0,o?r.slice(-o):"")}for(let t=2;t+2<n.length;t++){const[l,r]=n[t];l===0&&/^[\p{L}\p{M}\t ]+$/u.test(r)&&r.trim().length<=12&&r.trim().split(
|
|
10
|
+
/\s+/).length<=2&&n[t-2][0]===-1&&n[t-1][0]===1&&n[t+1][0]===-1&&n[t+2][0]===1&&Math.max(Math.abs(n[t-1][1].length-n[t-2][1].length),Math.abs(n[t+2][1].length-n[t+1][1].length))>2*r.length&&(n.splice(
|
|
11
|
+
t-2,5,[-1,n[t-2][1]+r+n[t+1][1]],[1,n[t-1][1]+r+n[t+2][1]]),t=Math.max(1,t-3))}return n}function C(e,n){if(e===n)return 3;const t=e.match(/[\p{L}\p{N}]+/gu)??[],l=n.match(/[\p{L}\p{N}]+/gu)??[],r=new Map;
|
|
12
|
+
for(const o of t)r.set(o,(r.get(o)??0)+1);let s=0;for(const o of l){const a=r.get(o)??0;a>0&&(s++,r.set(o,a-1))}const g=Math.min(t.length,l.length);let f=0;for(;f<g&&t[f]===l[f];)f++;const h=2*s/Math.
|
|
13
|
+
max(1,t.length+l.length);return!(f===t.length&&f>=2)&&f<3&&h<.5?0:h+f/Math.max(1,g)}function G(e,n,t){if(!e||!n||e===n)return t(e,n);const l=P(e),r=P(n);if(l.length*r.length>4096||l.length<=1&&r.length<=
|
|
14
|
+
1)return D(t(e,n));const s=r.length+1,g=new Float64Array((l.length+1)*s),f=new Float64Array(l.length*r.length);for(let i=l.length-1;i>=0;i--)for(let c=r.length-1;c>=0;c--){const m=C(l[i],r[c]);f[i*r.length+
|
|
15
|
+
c]=m,g[i*s+c]=Math.max(g[(i+1)*s+c],g[i*s+c+1],m>0?m+g[(i+1)*s+c+1]:0)}const h=[];let o=0,a=0,u="",p="";const d=()=>{for(const[i,c]of D(t(u,p)))W(h,i,c);u=p=""};for(;o<l.length&&a<r.length;){const i=f[o*
|
|
16
|
+
r.length+a];if(i>0&&g[o*s+a]===i+g[(o+1)*s+a+1]){d();const c=l[o++],m=r[a++],A=c.trimEnd(),w=m.trimEnd();for(const[I,_]of D(t(A,w)))W(h,I,_);for(const[I,_]of t(c.slice(A.length),m.slice(w.length)))W(h,
|
|
17
|
+
I,_)}else g[(o+1)*s+a]>=g[o*s+a+1]?u+=l[o++]:p+=r[a++]}return u+=l.slice(o).join(""),p+=r.slice(a).join(""),d(),h}const x=-1,y=0,M=1;function S(e){return/[\p{L}\p{N}]/u.test(e)}function H(e,n){const t=Math.
|
|
18
|
+
min(e.length,n.length);let l=0;for(;l<t&&e[l]===n[l];)l++;return l}function K(e,n){const t=Math.min(e.length,n.length);let l=0;for(;l<t&&e[e.length-1-l]===n[n.length-1-l];)l++;return l}function k(e){const n=[];
|
|
19
|
+
for(const[t,l]of e)l.length!==0&&(n.length>0&&n[n.length-1][0]===t?n[n.length-1][1]+=l:n.push([t,l]));return n}function Q(e){const n=[];for(let t=0;t<e.length;t++){const l=e[t],r=e[t+1];if(!l||!r||l[0]!==
|
|
20
|
+
x||r[0]!==M){n.push(l);continue}const s=l[1],g=r[1];let f=H(s,g);if(f>0){const o=s.slice(0,f),a=s.slice(f),u=g.slice(f);if(!S(a)&&!S(u)){n.push([y,o]),a.length>0&&n.push([x,a]),u.length>0&&n.push([M,u]),
|
|
21
|
+
t+=1;continue}}const h=K(s,g);if(h>0&&h<s.length&&h<g.length){const o=s.slice(s.length-h),a=s.slice(0,-h),u=g.slice(0,-h);if(!S(a)&&!S(u)){a.length>0&&n.push([x,a]),u.length>0&&n.push([M,u]),n.push([y,
|
|
22
|
+
o]),t+=1;continue}}n.push(l)}return k(n)}function v(e){const n=[],t=e.match(/^\s*/),l=t?t[0]:"";let r=e.slice(l.length);const s=/(\S+)(\s*)/g;let g;for(;(g=s.exec(r))!==null;)n.push({word:g[1],trailingWs:g[2]});
|
|
23
|
+
return{leadingWs:l,tokens:n}}function R(e,n){const t=Math.min(e.length,n.length);let l=0;for(;l<t&&e[l]===n[l];)l++;let r=0;for(;r<t-l&&e[e.length-1-r]===n[n.length-1-r];)r++;const s=e.slice(l,e.length-
|
|
24
|
+
r),g=n.slice(l,n.length-r),f=s.length,h=g.length,o=Array(f+1).fill(null).map(()=>Array(h+1).fill(0));for(let i=1;i<=f;i++)for(let c=1;c<=h;c++)s[i-1]===g[c-1]?o[i][c]=o[i-1][c-1]+1:o[i][c]=Math.max(o[i-
|
|
25
|
+
1][c],o[i][c-1]);const a=[];let u=f,p=h;for(;u>0&&p>0;)s[u-1]===g[p-1]?(a.push({originalIndex:l+u-1,newIndex:l+p-1}),u--,p--):o[u-1][p]>o[u][p-1]?u--:p--;a.reverse();const d=Array.from({length:l},(i,c)=>({
|
|
26
|
+
originalIndex:c,newIndex:c}));d.push(...a);for(let i=0;i<r;i++)d.push({originalIndex:e.length-r+i,newIndex:n.length-r+i});return d}function N(e,n,t){if(n===t)return n.length>0?[[y,n]]:[];if(n.length===
|
|
27
|
+
0)return t.length>0?[[M,t]]:[];if(t.length===0)return[[x,n]];const l=F();return l!==null?l:B(e,n,t)}function B(e,n,t){if(n===t)return n.length>0?[[y,n]]:[];if(n.length===0)return t.length>0?[[M,t]]:[];
|
|
28
|
+
if(t.length===0)return[[x,n]];const l=v(n),r=v(t),s=l.tokens,g=r.tokens;if(s.length===0&&g.length===0)return n===t?[[y,n]]:[[x,n],[M,t]];if(s.length===0)return[[x,n],[M,t]];if(g.length===0)return[[x,n],
|
|
29
|
+
[M,t]];const f=l.leadingWs,h=r.leadingWs,o=[];f===h?f.length>0&&o.push([y,f]):(f.length>0&&o.push([x,f]),h.length>0&&o.push([M,h]));const a=s.map(c=>c.word),u=g.map(c=>c.word),p=R(a,u);let d=0,i=0;for(const c of p){
|
|
30
|
+
for(;d<c.originalIndex;){const I=s[d];o.push([x,I.word+I.trailingWs]),d++}for(;i<c.newIndex;){const I=g[i];o.push([M,I.word+I.trailingWs]),i++}const m=s[c.originalIndex],A=g[c.newIndex];let w=0;for(;w<
|
|
31
|
+
m.trailingWs.length&&w<A.trailingWs.length&&m.trailingWs[w]===A.trailingWs[w];)w++;o.push([y,m.word+m.trailingWs.slice(0,w)]),m.trailingWs.length>w&&o.push([x,m.trailingWs.slice(w)]),A.trailingWs.length>
|
|
32
|
+
w&&o.push([M,A.trailingWs.slice(w)]),d=c.originalIndex+1,i=c.newIndex+1}for(;d<s.length;){const c=s[d];o.push([x,c.word+c.trailingWs]),d++}for(;i<g.length;){const c=g[i];o.push([M,c.word+c.trailingWs]),
|
|
33
|
+
i++}return Q(k(o))}function E(e,n){const t=e.split(`
|
|
34
|
+
`),l=n.split(`
|
|
35
|
+
`),r=t.length>1||l.length>1,s=G(e,n,(h,o)=>N([],h,o)),g=Math.max(e.length,n.length);let f=0;for(const[h,o]of s)h!==y&&(f+=o.length);return{changePercentage:g>0?f/g*100:0,hasMultipleLines:r,diffs:s}}const U=Object.
|
|
36
|
+
freeze(Object.defineProperty({__proto__:null,analyzeParagraphDiff:E,roundDiffsToWordBoundaries:N,roundDiffsToWordBoundariesJs:B},Symbol.toStringTag,{value:"Module"}));export{U as P,E as a,N as r,J as w};
|