revise 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +94 -0
- package/assets/historyMaterializeWorker-B51R08XN.js +612 -0
- package/backend.d.ts +8 -2
- package/backend.js +1 -1
- package/chunks/AgentPageRenderer-CH8kSTJn.js +1 -0
- package/chunks/AgentPageRenderer-P23XVguo.js +1 -0
- package/chunks/AttachmentDocumentImporter-B1WOaa7d.js +1 -0
- package/chunks/AttachmentDocumentImporter-CT_PJp_e.js +1 -0
- package/chunks/{BidiText-C8PBPSQY.js → BidiText-Swm5fl9J.js} +74 -74
- package/chunks/DocumentMutator-btiDK57e.js +31 -0
- package/chunks/{DocumentScrubber-DS4LFDKS.js → DocumentScrubber-CMPfm_HF.js} +1 -1
- package/chunks/{DocumentScrubber-COPepQKE.js → DocumentScrubber-Cm2kH8op.js} +1 -1
- package/chunks/{DocumentScrubber-Cf_QqHhF.js → DocumentScrubber-bJoKijol.js} +1 -1
- package/chunks/DocumentStylesheet-DreoD7sD.js +7 -0
- package/chunks/DocxConverter-BcVG-p5K.js +13 -0
- package/chunks/DocxConverter-D2bO5RE-.js +1125 -0
- package/chunks/DocxConverter-haCfRuWb.js +13 -0
- package/chunks/{DocxGraft-Ba63IRP4.js → DocxGraft-BRKh4mHQ.js} +1 -1
- package/chunks/{DocxGraft-DjERgl-z.js → DocxGraft-BxSQtl12.js} +2 -2
- package/chunks/{DocxGraft-cYlmw4Ab.js → DocxGraft-C9MBQCnf.js} +1 -1
- package/chunks/FileImporter-CszqRfVU.js +1 -0
- package/chunks/FileImporter-DObFoCCn.js +1 -0
- package/chunks/{HtmlConverter-Sd9t49vH.js → HtmlConverter-DwXB4IDh.js} +12 -12
- package/chunks/{MarkdownConverter-BdJgh8xt.js → MarkdownConverter-CUC8GgsS.js} +1 -1
- package/chunks/MathRenderer-DT6GyJXb.js +68 -0
- package/chunks/OdtConverter-7h9HHMpL.js +125 -0
- package/chunks/OdtConverter-Ct4qypJk.js +6 -0
- package/chunks/OdtConverter-DFl__sJc.js +6 -0
- package/chunks/OfficeImportShared-BY6FdZ8d.js +1 -0
- package/chunks/OfficeImportShared-BrZoDM0j.js +30 -0
- package/chunks/OfficeImportShared-Bvm-mOyj.js +1 -0
- package/chunks/PdfConverter-1wyvoT7X.js +21 -0
- package/chunks/PdfConverter-BAoEHILo.js +21 -0
- package/chunks/PdfConverter-CKEvFj11.js +448 -0
- package/chunks/{PdfImportService-CQCgsRX1.js → PdfImportService-BhLPp5uG.js} +2 -2
- package/chunks/{PdfImportService-xl7fstr-.js → PdfImportService-xbzrN__L.js} +2 -2
- package/chunks/RtfConverter-Bxn-enp8.js +15 -0
- package/chunks/RtfConverter-LZPzBDSr.js +15 -0
- package/chunks/RtfConverter-_bacXqr1.js +186 -0
- package/chunks/{TableBorders-Cdkc62cX.js → TableBorders-CwnF3jvH.js} +1 -1
- package/chunks/{TxtConverter-C-oiFUAp.js → TxtConverter-C7FOwHpH.js} +1 -1
- package/chunks/XmlConverter-7oo8oeQB.js +2 -0
- package/chunks/XmlConverter-DGORHJcZ.js +96 -0
- package/chunks/XmlConverter-DeLHReK_.js +2 -0
- package/chunks/ar-ComXvtmh.js +13 -0
- package/chunks/backend-DecaBz-I.js +490 -0
- package/chunks/base64-sSPOzq-u.js +198 -0
- package/chunks/{browser-module-CYGCfEyx.js → browser-module-Dj5o3kuL.js} +1 -1
- package/chunks/{browser-module-DgvTMhpA.js → browser-module-UuM_O36W.js} +1 -1
- package/chunks/{capture-BAJ2in5p.js → capture-1btcWcPF.js} +1 -1
- package/chunks/{carrier-C5VZRMxZ.js → carrier-DQeng6yq.js} +1 -1
- package/chunks/de-BkbpIKxx.js +13 -0
- package/chunks/es-CKkXujOF.js +13 -0
- package/chunks/fil-piIHMc8F.js +13 -0
- package/chunks/{footnoteFlatten-Bekh8ZfM.js → footnoteFlatten-DUQticYy.js} +1 -1
- package/chunks/fr-DuA8qLje.js +13 -0
- package/chunks/{graftExport-CRRm1Oe_.js → graftExport-CYnStOdU.js} +1 -1
- package/chunks/index-2TBhRkX7.js +387 -0
- package/chunks/{index-B1idHquf.js → index-Bf14eTEW.js} +231 -229
- package/chunks/index-BwcX_r62.js +387 -0
- package/chunks/{index.es-Bwt05m_b.js → index.es-CI7cDExj.js} +1 -1
- package/chunks/{index.es-DAQD57G4.js → index.es-DHpGt6Y5.js} +1 -1
- package/chunks/ja-DgrSs555.js +13 -0
- package/chunks/{jspdf.es.min-DlTF8uTw.js → jspdf.es.min--GshOuIm.js} +1 -1
- package/chunks/{jspdf.es.min-CnNRolk9.js → jspdf.es.min-DurJZ1zW.js} +1 -1
- package/chunks/pseudoLocale-BoYTjmiK.js +1 -0
- package/chunks/pseudoLocale-DG2NnZmz.js +1 -0
- package/chunks/serverDocumentSession-CJ1EH3Tp.js +15 -0
- package/chunks/{signatures-CBF7NZUy.js → signatures-Bwt_OGik.js} +1 -1
- package/chunks/suggestionAuthorship-B-IuLQlE.js +1 -0
- package/chunks/zh-9OF3SWWO.js +13 -0
- package/full.js +1 -1
- package/index.d.ts +13 -5
- package/index.js +1 -1
- package/package.json +1 -1
- package/root.js +2 -2
- package/style.css +1 -1
- package/assets/historyMaterializeWorker-C4uxcZEh.js +0 -607
- package/chunks/AgentPageRenderer-BFB0arQL.js +0 -1
- package/chunks/AgentPageRenderer-Dn6SaRjW.js +0 -1
- package/chunks/AttachmentDocumentImporter-BHDJAdky.js +0 -1
- package/chunks/AttachmentDocumentImporter-CxOZqzt1.js +0 -1
- package/chunks/DocumentMutator-4vBJQ74L.js +0 -31
- package/chunks/DocumentStylesheet-byN5dtC6.js +0 -7
- package/chunks/DocxConverter-BCEB7jWY.js +0 -1083
- package/chunks/DocxConverter-C3NflpDr.js +0 -11
- package/chunks/DocxConverter-D9ZNn4nX.js +0 -11
- package/chunks/FileImporter-CHXj9sNX.js +0 -1
- package/chunks/FileImporter-DetvRoJc.js +0 -1
- package/chunks/MathRenderer-B0Y1h1JU.js +0 -62
- package/chunks/OdtConverter-BKtyx012.js +0 -1
- package/chunks/OdtConverter-Ce9j8PRt.js +0 -1
- package/chunks/OdtConverter-D709qfYb.js +0 -31
- package/chunks/PdfConverter-BA8XLTAM.js +0 -21
- package/chunks/PdfConverter-CkDClffR.js +0 -438
- package/chunks/PdfConverter-CxLxd-LJ.js +0 -21
- package/chunks/RtfConverter-BZOnMUGH.js +0 -14
- package/chunks/RtfConverter-Bs81AfXt.js +0 -14
- package/chunks/RtfConverter-DfuE5olb.js +0 -45
- package/chunks/XmlConverter-C0FnrVYk.js +0 -70
- package/chunks/XmlConverter-CQa8baOF.js +0 -2
- package/chunks/XmlConverter-DjEYaIyf.js +0 -2
- package/chunks/ar-BdmGnaKI.js +0 -14
- package/chunks/backend-BIhAX-Gi.js +0 -484
- package/chunks/base64-Qx0OzT4p.js +0 -196
- package/chunks/de-DldIXRFC.js +0 -14
- package/chunks/es-CnyKlSPK.js +0 -14
- package/chunks/index-C-4H81OE.js +0 -378
- package/chunks/index-iZC8xN0t.js +0 -378
- package/chunks/pseudoLocale-BoJwIubw.js +0 -1
- package/chunks/pseudoLocale-DWAm7Dpa.js +0 -1
- package/chunks/serverDocumentSession-DASrQAbW.js +0 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as a,D as s,G as r,t as e,a as t,b as o,d as i,l as c,c as n,g as u,i as g,x as S,k as l,w as f,q as m,h as p,v as x,m as C,n as D,p as y,r as E,e as b,s as R,o as d,u as h,f as k}from"./index-
|
|
1
|
+
import{C as a,D as s,G as r,t as e,a as t,b as o,d as i,l as c,c as n,g as u,i as g,x as S,k as l,w as f,q as m,h as p,v as x,m as C,n as D,p as y,r as E,e as b,s as R,o as d,u as h,f as k}from"./index-2TBhRkX7.js";export{a as CARRIER_MAP_KEY,s as DEFAULT_CARRIER_BYTE_CAP,r as GraftProofError,e as assessGraftability,t as blockCanonical,o as blockSignature,i as bodySidecarsSignature,c as canonicalizeForSignature,n as captureDocxSource,u as chromeSignature,g as commentsSignature,S as computeSourceFidelity,l as corePropertiesSignature,f as getDocxCarrierMeta,m as graftExport,p as hashBytes,x as loadDocxCarrier,C as markBlockSource,D as notesSignature,y as pageLayoutSignature,E as refreshDocxSourceSignatures,b as settingsSignature,R as signatureDigest,d as stableStringify,h as storeDocxCarrier,k as stylesSignature};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import{c,h as u,m as g}from"./capture-
|
|
2
|
-
import{G as k,g as R}from"./graftExport-
|
|
1
|
+
import{c,h as u,m as g}from"./capture-1btcWcPF.js";import{a as d,b as f,c as m,i as l,f as S,g as p,h,n as y,p as x,d as D,s as C,j as E,e as b}from"./signatures-Bwt_OGik.js";import{a as i}from"./graftExport-CYnStOdU.js";
|
|
2
|
+
import{G as k,g as R}from"./graftExport-CYnStOdU.js";import{C as B,D as A,g as I,l as P,s as _}from"./carrier-DQeng6yq.js";function G(a,o){const s=a.docxSource;if(!s)return r("no-capture");if(!o)return r(
|
|
3
3
|
"no-carrier");if(!s.sourceHash)return r("unpaired-capture");if(o.hash!==s.sourceHash)return r("carrier-hash-mismatch");const e=i(a),n=Object.entries(e.domains).filter(([,t])=>!t).map(([t])=>t);return{
|
|
4
4
|
fidelity:e.fullyExact?"exact":"grafted",regeneratedBlockIds:e.regeneratedBlockIds,changedDomains:n}}function r(a){return{fidelity:"converted",regeneratedBlockIds:[],changedDomains:[],convertedReason:a}}
|
|
5
5
|
export{B as CARRIER_MAP_KEY,A as DEFAULT_CARRIER_BYTE_CAP,k as GraftProofError,i as assessGraftability,d as blockCanonical,f as blockSignature,m as bodySidecarsSignature,l as canonicalizeForSignature,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{C as a,D as s,G as r,t as e,a as t,b as o,d as i,l as c,c as n,g as u,i as g,x as S,k as l,w as f,q as m,h as p,v as x,m as C,n as D,p as y,r as E,e as b,s as R,o as d,u as h,f as k}from"./index-
|
|
1
|
+
import{C as a,D as s,G as r,t as e,a as t,b as o,d as i,l as c,c as n,g as u,i as g,x as S,k as l,w as f,q as m,h as p,v as x,m as C,n as D,p as y,r as E,e as b,s as R,o as d,u as h,f as k}from"./index-BwcX_r62.js";export{a as CARRIER_MAP_KEY,s as DEFAULT_CARRIER_BYTE_CAP,r as GraftProofError,e as assessGraftability,t as blockCanonical,o as blockSignature,i as bodySidecarsSignature,c as canonicalizeForSignature,n as captureDocxSource,u as chromeSignature,g as commentsSignature,S as computeSourceFidelity,l as corePropertiesSignature,f as getDocxCarrierMeta,m as graftExport,p as hashBytes,x as loadDocxCarrier,C as markBlockSource,D as notesSignature,y as pageLayoutSignature,E as refreshDocxSourceSignatures,b as settingsSignature,R as signatureDigest,d as stableStringify,h as storeDocxCarrier,k as stylesSignature};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ac as s,ad as f,ae as d,af as p,ag as u}from"./index-BwcX_r62.js";const o=[...s.filter(e=>e.import).flatMap(e=>[...e.extensions]),".pdf",".png",".jpg",".jpeg",".webp",".gif"],w=o.join(",");function l(e){const t=e.toLowerCase();return o.some(r=>t.endsWith(r))}[...s.filter(e=>e.import).map(e=>e.mimeType)];class g{static async parseFile(t){const r=t.name.toLowerCase(),i=f(r);if(i?.import){const a=await d(new Uint8Array(await t.arrayBuffer()),t.name,i.id,t.type);if(i.id!=="docx"&&i.id!=="odt"&&i.id!=="rtf")return p(a);const{persistInlineDocumentImages:m}=await import("./persistInlineDocumentImages-DQj2iaqg.js");await m(a);const n=p(a);if(n.docxSource){const{refreshDocxSourceSignatures:c}=await import("./DocxGraft-C9MBQCnf.js");c(n)}return n}else throw r.endsWith(".pdf")?new Error("PDF files are imported via the AI import flow, not FileImporter."):u(r)?new Error("Image files are imported via the AI import flow, not FileImporter."):new Error(`Unsupported file type: ${t.name}. Supported formats: ${o.join(", ")}`)}static getSupportedExtensions(){return[...o]}static getAcceptString(){return w}static isSupported(t){return l(t)}}export{g as FileImporter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{ac as s,ad as f,ae as d,af as p,ag as u}from"./index-2TBhRkX7.js";const o=[...s.filter(e=>e.import).flatMap(e=>[...e.extensions]),".pdf",".png",".jpg",".jpeg",".webp",".gif"],w=o.join(",");function l(e){const t=e.toLowerCase();return o.some(r=>t.endsWith(r))}[...s.filter(e=>e.import).map(e=>e.mimeType)];class g{static async parseFile(t){const r=t.name.toLowerCase(),i=f(r);if(i?.import){const a=await d(new Uint8Array(await t.arrayBuffer()),t.name,i.id,t.type);if(i.id!=="docx"&&i.id!=="odt"&&i.id!=="rtf")return p(a);const{persistInlineDocumentImages:m}=await import("./persistInlineDocumentImages-DQj2iaqg.js");await m(a);const n=p(a);if(n.docxSource){const{refreshDocxSourceSignatures:c}=await import("./DocxGraft-BRKh4mHQ.js");c(n)}return n}else throw r.endsWith(".pdf")?new Error("PDF files are imported via the AI import flow, not FileImporter."):u(r)?new Error("Image files are imported via the AI import flow, not FileImporter."):new Error(`Unsupported file type: ${t.name}. Supported formats: ${o.join(", ")}`)}static getSupportedExtensions(){return[...o]}static getAcceptString(){return w}static isSupported(t){return l(t)}}export{g as FileImporter};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{w as T,C as k,
|
|
2
|
-
r as st,s as lt}from"./ListNumbering-Qlu6AuRZ.js";import{f as O}from"./footnoteFlatten-
|
|
3
|
-
import{g as ht,l as dt,a as pt,b as z}from"./MathRenderer-
|
|
1
|
+
import{w as T,C as k,aP as V,aY as Z,aW as J,k as E,x as K,l as U,r as W,q as B,s as Y,u as I,v as Q,Z as tt,t as et,j as rt,aZ as nt,S as it}from"./backend-DecaBz-I.js";import{i as at,p as D,e as ot,
|
|
2
|
+
r as st,s as lt}from"./ListNumbering-Qlu6AuRZ.js";import{f as O}from"./footnoteFlatten-DUQticYy.js";import{i as ct}from"./HorizontalRuleOrnaments-gmUZ3R7Q.js";import{b as F}from"./TableGrid-DbroRucl.js";
|
|
3
|
+
import{g as ht,l as dt,a as pt,b as z}from"./MathRenderer-DT6GyJXb.js";import{c as H,d as ut,F as N,r as q,e as R,f as mt,i as gt,g as ft,j as bt,l as yt,k as xt,L as P}from"./BidiText-Swm5fl9J.js";const $t=[
|
|
4
4
|
[/[\p{Script=Hiragana}\p{Script=Katakana}]/u,"ja"],[/\p{Script=Hangul}/u,"ko"],[/\p{Script=Han}/u,"und-Hani"],[/\p{Script=Arabic}/u,"und-Arab"],[/\p{Script=Hebrew}/u,"und-Hebr"],[/\p{Script=Devanagari}/u,
|
|
5
5
|
"und-Deva"],[/\p{Script=Bengali}/u,"und-Beng"],[/\p{Script=Gurmukhi}/u,"pa"],[/\p{Script=Gujarati}/u,"gu"],[/\p{Script=Oriya}/u,"or"],[/\p{Script=Tamil}/u,"ta"],[/\p{Script=Telugu}/u,"te"],[/\p{Script=Kannada}/u,
|
|
6
6
|
"kn"],[/\p{Script=Malayalam}/u,"ml"],[/\p{Script=Sinhala}/u,"si"],[/\p{Script=Thai}/u,"th"],[/\p{Script=Lao}/u,"lo"],[/\p{Script=Khmer}/u,"km"],[/\p{Script=Myanmar}/u,"my"],[/\p{Script=Tibetan}/u,"bo"],
|
|
@@ -45,7 +45,7 @@ r"));if(r.length===0)return null;const n=[];for(const i of r){const a=Array.from
|
|
|
45
45
|
a))if(o.getAttribute("charset")){i=!0;break}let s;for(;s=r.nextNode();)if(s.nodeType===Node.ELEMENT_NODE){const o=s,c=o.tagName.toLowerCase();if(c!=="br"&&c!=="span"&&c!=="div"&&c!=="html"&&c!=="head"&&
|
|
46
46
|
c!=="body"&&c!=="meta"){n=!1;break}if((c==="div"||c==="span")&&(o.getAttribute("style")||o.className)){n=!1;break}}const p=t.getElementsByTagName("br").length>0;return i&&n||p&&n}static extractAllContent(t){
|
|
47
47
|
const e=[];return this.processElement(t,e),e}static convertMathMLToBlock(t){try{const e=t.outerHTML,r=ht();if(!r)return dt(),console.warn("MathML converter not loaded yet; skipping <math>"),null;const n=r.
|
|
48
|
-
convert(e);if(!n||n.trim()==="")return null;const i=t.getAttribute("display")==="block";return
|
|
48
|
+
convert(e);if(!n||n.trim()==="")return null;const i=t.getAttribute("display")==="block";return Z(n.trim(),{displayMode:"block",align:"center"})}catch(e){return console.warn("Failed to convert MathML t\
|
|
49
49
|
o LaTeX:",e),null}}static processElement(t,e,r=new Set(["script","style"])){const n=t.tagName.toLowerCase();if(r.has(n))return;if(n==="img"){const c=t.getAttribute("src");if(!c||!/^(?:https?:|data:image\/|blob:)/i.
|
|
50
50
|
test(c))return;const h=t.style,l=this.parseCssLengthToPx(h.width||t.getAttribute("width")),d=this.parseCssLengthToPx(h.height||t.getAttribute("height"));e.push({type:"image",id:T(),src:c,width:l&&l>0?
|
|
51
51
|
l:300,height:d&&d>0?d:200,...t.getAttribute("alt")?{alt:t.getAttribute("alt")}:{}});return}if(/^(p|h[1-6])$/.test(n)&&t.querySelector("img")){const c=t.ownerDocument.createRange();c.setStart(t,0);const h=()=>{
|
|
@@ -61,7 +61,7 @@ n.charAt(1))),f.align=d.align??this.extractElementAlignment(t);const x=this.reso
|
|
|
61
61
|
firstLineIndent!==void 0&&(f.firstLineIndent=d.firstLineIndent),d.borders!==void 0&&m===u.length-1&&(f.borders=d.borders),Object.assign(f,this.extractParagraphSpacing(t)),e.push(f)}return}if(n==="ol"||
|
|
62
62
|
n==="ul"){const c=this.convertListElement(t);c&&c.children.length>0&&e.push(c);return}if(n==="li"){const c=this.extractInlineContent(t),h=this.extractElementDirection(t),l=this.splitOnNewlines(c);for(const d of l){
|
|
63
63
|
const u=k(d.length>0?d:[{type:"text",text:"",marks:{}}]),m=this.resolveImportedDirection(h,this.inlineNodesText(d));m&&(u.direction=m),Object.assign(u,this.extractParagraphSpacing(t)),e.push(u)}return}
|
|
64
|
-
if(n==="hr"){e.push(
|
|
64
|
+
if(n==="hr"){e.push(J());return}if(n==="br"){if(t.className&&t.className.includes("Apple-interchange-newline"))return;e.push(k());return}let a=[];const s=this.extractElementDirection(t),p=(c,h)=>{const l=this.
|
|
65
65
|
resolveImportedDirection(s,this.inlineNodesText(h));l&&(c.direction=l)},o=Array.from(t.childNodes);for(const c of o){if(c.nodeType===Node.TEXT_NODE){const d=c.textContent||"";d.trim()&&a.push({type:"t\
|
|
66
66
|
ext",text:d});continue}const h=c,l=h.tagName.toLowerCase();if(h.querySelector(":scope > p"))this.processElement(h,e,r);else if(i.includes(l)){const d=this.extractInlineContent(h);a.push(...d)}else{if(a.
|
|
67
67
|
length>0){const d=this.splitOnNewlines(a);for(const u of d){const m=k(u);p(m,u),Object.assign(m,this.extractParagraphSpacing(t)),e.push(m)}a=[]}this.processElement(h,e,r)}}if(a.length>0){const c=this.
|
|
@@ -87,8 +87,8 @@ return{};const r=[e.style.borderTopWidth,e.style.borderRightWidth,e.style.border
|
|
|
87
87
|
const e=t.querySelector("td, th");if(!(e instanceof HTMLElement))return;const r=[e.style.paddingTop,e.style.paddingRight,e.style.paddingBottom,e.style.paddingLeft].map(n=>this.parseCssLengthToPx(n)).filter(
|
|
88
88
|
n=>n!==void 0&&n>=0);if(r.length!==0)return Math.round(Math.max(...r))}static tableHasHeaderRow(t){const e=this.getDirectTableRows(t)[0];return e?Array.from(e.children).some(r=>r.tagName.toLowerCase()===
|
|
89
89
|
"th"||r.getAttribute("role")==="columnheader"):!1}static extractTableCellVerticalAlign(t){const e=t instanceof HTMLElement?t.style.verticalAlign:"",r=t.getAttribute("valign"),n=(e||r||"").trim().toLowerCase();
|
|
90
|
-
if(n==="top"||n==="middle"||n==="bottom")return n}static extractElementBackgroundColor(t){const e=t instanceof HTMLElement?t.style.backgroundColor:"";if(!(!e||e==="transparent"))return
|
|
91
|
-
const e=this.extractParagraphStyleAttributes(t.getAttribute("style")||"").align;if(e)return e;const r=
|
|
90
|
+
if(n==="top"||n==="middle"||n==="bottom")return n}static extractElementBackgroundColor(t){const e=t instanceof HTMLElement?t.style.backgroundColor:"";if(!(!e||e==="transparent"))return E(e)?e:void 0}static extractElementAlignment(t){
|
|
91
|
+
const e=this.extractParagraphStyleAttributes(t.getAttribute("style")||"").align;if(e)return e;const r=K(t,"align")?.trim().toLowerCase();if(r==="left"||r==="center"||r==="right"||r==="justify")return r}static parseCssLengthToPx(t){
|
|
92
92
|
if(!t)return;const e=t.trim().toLowerCase();if(!e)return;if(e==="0")return 0;const r=e.match(/^(-?\d+(?:\.\d+)?)(px|pt|pc|in|cm|mm|q)?$/);if(!r)return;const n=parseFloat(r[1]);switch(r[2]??"px"){case"\
|
|
93
93
|
px":return n;case"pt":return n*(96/72);case"pc":return n*16;case"in":return n*96;case"cm":return n*(96/2.54);case"mm":return n*(96/25.4);case"q":return n*(96/101.6);default:return}}static extractDirectInlineContent(t){
|
|
94
94
|
const e=[],r=this.getTextMarks(t),n=["p","h1","h2","h3","h4","h5","h6","div","section","article","aside","main","nav","header","footer","blockquote","pre","ul","ol","li"],i=["span","strong","b","em","\
|
|
@@ -104,12 +104,12 @@ i.fontWeight?parseInt(i.fontWeight):null;(n==="strong"||n==="b")&&(!a||a>=700)&&
|
|
|
104
104
|
e.subscript)&&s>0&&(e.fontSize=s*96/72),n==="a"){const p=t.getAttribute("href");p&&(e.link=p)}if(i){if((i.fontWeight==="bold"||parseInt(i.fontWeight)>=700)&&(e.bold=!0),i.fontStyle==="italic"&&(e.italic=
|
|
105
105
|
!0),i.textDecoration?.includes("underline")&&(e.underline=!0),i.textDecoration?.includes("line-through")&&(i.textDecoration.includes("double")?e.doubleStrikethrough=!0:e.strikethrough=!0),i.fontVariant?.
|
|
106
106
|
includes("small-caps")&&(e.smallCaps=!0),i.textTransform==="uppercase"&&(e.allCaps=!0),i.letterSpacing&&i.letterSpacing!=="normal"){const o=this.parseCssLengthToPx(i.letterSpacing);o!==void 0&&o!==0&&
|
|
107
|
-
(e.letterSpacing=Math.round(o*100)/100)}if(i.backgroundColor&&i.backgroundColor!=="transparent"){const o=ut(i.backgroundColor);o&&(e.backgroundColor=o)}if(i.color){const o=
|
|
107
|
+
(e.letterSpacing=Math.round(o*100)/100)}if(i.backgroundColor&&i.backgroundColor!=="transparent"){const o=ut(i.backgroundColor);o&&(e.backgroundColor=o)}if(i.color){const o=E(i.color);o&&!U(o)&&(e.color=
|
|
108
108
|
o)}const p=this.parseFontFamily(i.fontFamily);if(p&&(e.fontFamily=p),i.fontSize){const o=this.parseCssLengthToPx(i.fontSize);o!==void 0&&o>0&&(e.fontSize=o)}}return Object.keys(e).length>0?e:void 0}static resolveIndentStepPx(t){
|
|
109
109
|
return W(t?.pageLayout).indentStepPx}static resolveBlockMarginsPx(t,e){const r=n=>typeof n=="number"&&Number.isFinite(n)?Math.max(0,n):void 0;return{top:e.index===0?0:r(t.spaceBefore)??this.resolveBlockSpacingPx(
|
|
110
110
|
e.doc),bottom:r(t.spaceAfter)??0}}static resolveBlockSpacingPx(t){return W(t?.pageLayout).blockSpacingPx}static parseCssParagraphBorder(t){if(!t)return null;const e=t.trim().toLowerCase();if(!e||/\b(none|hidden)\b/.
|
|
111
111
|
test(e))return null;const r=e.match(/\b(solid|dashed|dotted|double)\b/);if(!r)return null;const n=r[1]==="solid"?"single":r[1],i=e.match(/([\d.]+)\s*(pt|px)/);let a=1;if(i){const o=parseFloat(i[1]),c=i[2]===
|
|
112
|
-
"pt"?o*4/3:o;a=Math.min(8,Math.max(1,Math.round(c)))}const s=e.replace(r[0]," ").replace(i?.[0]??""," ").trim(),p=
|
|
112
|
+
"pt"?o*4/3:o;a=Math.min(8,Math.max(1,Math.round(c)))}const s=e.replace(r[0]," ").replace(i?.[0]??""," ").trim(),p=E(s)??"#000000";return{style:n,width:a,color:p}}static extractElementDirection(t){for(let e=t;e;e=
|
|
113
113
|
e.parentElement){const r=(e.getAttribute("style")||"").match(/(?:^|;)\s*direction:\s*(rtl|ltr)\b/i);if(r)return r[1].toLowerCase();const n=e.getAttribute("dir")?.trim().toLowerCase();if(n==="rtl"||n===
|
|
114
114
|
"ltr")return n}}static resolveImportedDirection(t,e){if(t==="rtl")return"rtl";if(t==="ltr"&&H(e)==="rtl")return"ltr"}static inlineNodesText(t){return t.map(e=>e.type==="text"?e.text:"").join("")}static extractParagraphSpacing(t){
|
|
115
115
|
const e=t.style,r={},n=this.parseCssLengthToPx(e.marginTop),i=this.parseCssLengthToPx(e.marginBottom);if(n!==void 0&&n>=0&&(r.spaceBefore=n),i!==void 0&&i>=0&&(r.spaceAfter=i),e.lineHeight&&e.lineHeight!==
|
|
@@ -250,12 +250,12 @@ gin: ${this.formatPx(s.top)} 0 ${this.formatPx(s.bottom)} 0`)}else i.push("margi
|
|
|
250
250
|
i.push(`line-height: ${this.formatNumber(this.getListLineHeightMultiplier(t))}`),i.push(`font-family: ${this.escapeAttribute(a)}`),t.variant==="todo")i.push("list-style-type: none");else{const s=D(t.numberingFormat)?.[r],
|
|
251
251
|
p={decimal:"decimal",lowerLetter:"lower-alpha",upperLetter:"upper-alpha",lowerRoman:"lower-roman",upperRoman:"upper-roman",decimalZero:"decimal-leading-zero"},o=s?.numFmt==="bullet"?s.lvlText==="◦"?
|
|
252
252
|
"circle":s.lvlText==="▪"?"square":"disc":s?.numFmt&&p[s.numFmt];o&&i.push(`list-style-type: ${o}`)}return i.join("; ")}static getParagraphFontSizePx(t){if(t.heading){const e=`h${t.heading}`;return N[e]??
|
|
253
|
-
N.paragraph}return N.paragraph}static getParagraphLineHeightMultiplier(t){return typeof t.lineSpacing=="number"&&Number.isFinite(t.lineSpacing)&&t.lineSpacing>0?t.lineSpacing:t.heading?
|
|
254
|
-
return typeof t.lineSpacing=="number"&&Number.isFinite(t.lineSpacing)&&t.lineSpacing>0?t.lineSpacing:
|
|
253
|
+
N.paragraph}return N.paragraph}static getParagraphLineHeightMultiplier(t){return typeof t.lineSpacing=="number"&&Number.isFinite(t.lineSpacing)&&t.lineSpacing>0?t.lineSpacing:t.heading?P.heading:P.paragraph}static getListLineHeightMultiplier(t){
|
|
254
|
+
return typeof t.lineSpacing=="number"&&Number.isFinite(t.lineSpacing)&&t.lineSpacing>0?t.lineSpacing:P.paragraph}static normalizeFontFamily(t){if(!t)return;const e=t.trim();if(!e)return;const r=nt(e),
|
|
255
255
|
n=r&&r!=="inherit"?r:e;return/[<>;]/.test(n)?M:n}static formatNumber(t){return Number.isFinite(t)?`${Math.round(t*1e3)/1e3}`.replace(/\.0+$/,"").replace(/(\.\d*[1-9])0+$/,"$1"):"0"}static formatPx(t){
|
|
256
256
|
return`${this.formatNumber(t)}px`}static getStyledDocumentCss(t){const e=t.pageless?"min(100%, 816px)":`${_}px`,r=t.pageless?"48px":`${j}px`,n=t.pageless?"auto":`${Math.max(St-j*2,0)}px`,i=t.pageless?
|
|
257
257
|
"32px":"48px";return[":root {"," color-scheme: light;","}","body {"," margin: 0;"," background: #f3f4f6;"," color: #111827;",` font-family: ${t.baseFontFamily};`,` font-size: ${this.formatPx(N.paragraph)}\
|
|
258
|
-
;`,` line-height: ${this.formatNumber(
|
|
258
|
+
;`,` line-height: ${this.formatNumber(P.paragraph)};`," display: flex;"," justify-content: center;"," padding: 48px 0;","}",".revise-document {"," background: #ffffff;",` width: ${e};`,` min-he\
|
|
259
259
|
ight: ${n};`,` padding: ${r};`," box-sizing: border-box;"," word-wrap: break-word;","}",".revise-document * {"," color: inherit;","}",`@media (max-width: ${_+j*2}px) {`," body {"," padding: 32\
|
|
260
260
|
px 0;"," }"," .revise-document {"," width: calc(100% - 32px);",` padding: ${i};`," }","}"].join(`
|
|
261
261
|
`)}static getImageStyle(t){const e=["display: block","max-width: 100%","height: auto"];switch(t.align){case"center":e.push("margin-left: auto","margin-right: auto");break;case"right":e.push("margin-le\
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{C as k,
|
|
1
|
+
import{C as k,aR as y,f as b,aS as $,aT as w,aU as M,aV as T,aW as I,w as u,aX as _}from"./backend-DecaBz-I.js";import{b as C}from"./TableGrid-DbroRucl.js";import{a as j,e as v,i as N}from"./ListNumbering-Qlu6AuRZ.js";
|
|
2
2
|
class L{static toMarkdown(e){if(!e||e.type!=="doc"||!e.children)return"";this.exportListNumbering=j(e);const n=[];for(const t of e.children){if(t.type==="header-footer"||t.type==="footnote")continue;if(t.
|
|
3
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
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.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
const D="https://revise.io";let U=D;const G=new Set;function l(e){return`${U}/${e.replace(/^\/+/,"")}`}function V(e){G.add(e)}let x=null,K=null;async function X(){return x||(K||(K=import("./katex-DWj8TvwO.js").
|
|
2
|
+
then(e=>(x=e.default,e.default))),K)}function H(){return x}let v=null,S=null;async function P(){return v||(S||(S=import("./bundle.min-DRpfgV69.js").then(e=>e.b).then(e=>(v=e.MathMLToLaTeX,e.MathMLToLaTeX))),
|
|
3
|
+
S)}function L(){return v}function J(e){return/<math[\s>]/i.test(e)}const d=new Map,c=new Map,m=new Map,Q=new Set,b=new Map,k=[0,1e3,5e3,15e3],A=new Map;let $=!1;function C(){$||($=!0,requestAnimationFrame(
|
|
4
|
+
()=>{$=!1;for(const[e,t]of m)d.set(e,t),c.delete(e),t.provisional?Y(e,t):b.delete(e);m.clear();for(const e of Q)try{e()}catch(t){console.error("Math render callback error:",t)}}))}function R(e,t,n){return`${t?
|
|
5
|
+
"block":"inline"}:${n}:${e}`}const g="#000000";function z(e,t=!0,n=g){if(!e||e.trim()==="")return{image:null,width:100,height:40,contentWidth:80,contentHeight:20,loading:!1,error:void 0};const a=R(e,t,
|
|
6
|
+
n);return d.get(a)||(c.has(a)||F(a,e,t,n),{image:null,width:200,height:t?80:60,contentWidth:180,contentHeight:t?60:40,loading:!0})}function F(e,t,n,a){const i=ee(t,n,a);c.set(e,i),A.set(e,{content:t,displayMode:n,
|
|
7
|
+
color:a}),i.then(r=>{m.set(e,r),C()}).catch(r=>{const o={image:null,width:100,height:40,contentWidth:80,contentHeight:20,loading:!1,error:r instanceof Error?r.message:"Render failed"};m.set(e,o),C()})}
|
|
8
|
+
function Y(e,t){const n=A.get(e),a=b.get(e)??0;if(!n||a>=k.length)return;b.set(e,a+1);const i=k[a];(async()=>(i>0&&await new Promise(r=>setTimeout(r,i)),await O(),!(d.get(e)!==t||c.has(e))&&F(e,n.content,
|
|
9
|
+
n.displayMode,n.color)))()}function W(e,t,n=g){const a=R(e,t,n),i=d.get(a)||m.get(a);return!i||!i.svg?null:{svg:i.svg,width:i.width,height:i.height,contentWidth:i.contentWidth,contentHeight:i.contentHeight}}
|
|
10
|
+
async function I(e,t,n=g){const a=R(e,t,n);if(c.has(a)){await c.get(a);return}if(!(d.has(a)||m.has(a))&&z(e,t,n).loading){const i=c.get(a);i&&await i}}function Z(e){if(!e.includes(`
|
|
11
|
+
`)||["align","aligned","gather","gathered","split","cases","matrix","pmatrix","bmatrix","array"].some(n=>e.includes(`\\begin{${n}}`)||e.includes(`\\begin{${n}*}`)))return e;const t=e.split(`
|
|
12
|
+
`).map(n=>n.trim()).filter(n=>n.length>0);return t.length<=1?e:`\\begin{gathered}
|
|
13
|
+
${t.join(` \\\\
|
|
14
|
+
`)}
|
|
15
|
+
\\end{gathered}`}async function ee(e,t,n=g){try{const a=Z(e),i=(await X()).renderToString(a,{displayMode:t,throwOnError:!1,errorColor:"#ef4444",trust:!1,strict:!1}),r=await O(),{width:o,height:s,contentWidth:h,
|
|
16
|
+
contentHeight:u}=await ne(i),{css:_,complete:B}=await le(),E=se(i,o,s,_,n);return{image:await ce(E,o,s),width:o,height:s,contentWidth:h,contentHeight:u,loading:!1,svg:E,provisional:T()&&(!r||!B)}}catch(a){
|
|
17
|
+
return console.error("Math render error:",a),{image:null,width:100,height:40,contentWidth:80,contentHeight:20,loading:!1,error:a instanceof Error?a.message:"Unknown error"}}}const p=10,j=.85,q=["16px \
|
|
18
|
+
KaTeX_Main","bold 16px KaTeX_Main","italic 16px KaTeX_Main","italic 16px KaTeX_Math","16px KaTeX_Size1","16px KaTeX_Size2","16px KaTeX_Size3","16px KaTeX_Size4","16px KaTeX_AMS"],te=[...new Set(q.map(
|
|
19
|
+
e=>e.split(" ").pop()))];function T(){const e=typeof document<"u"?document.fonts:void 0;return!!e&&typeof e.forEach=="function"}function N(){if(!T())return!0;const e=document.fonts,t=new Set;return e.
|
|
20
|
+
forEach(n=>{n.status==="loaded"&&t.add(n.family.replace(/^["']|["']$/g,""))}),te.every(n=>t.has(n))}let w=null;function O(){if(w)return w;if(!T())return Promise.resolve(!0);const e=(async()=>{if(!await re())
|
|
21
|
+
return!1;if(N())return!0;try{await Promise.all(q.map(n=>document.fonts.load(n).catch(()=>[]))),await document.fonts.ready,await new Promise(n=>requestAnimationFrame(n))}catch{}return N()})();w=e;const t=()=>{
|
|
22
|
+
w===e&&(w=null)};return e.then(n=>!n&&t(),t),e}async function ne(e){const t=document.createElement("div");return t.style.cssText=`
|
|
23
|
+
position: absolute;
|
|
24
|
+
visibility: hidden;
|
|
25
|
+
pointer-events: none;
|
|
26
|
+
top: -9999px;
|
|
27
|
+
left: -9999px;
|
|
28
|
+
font-size: 16px;
|
|
29
|
+
line-height: 1.2;
|
|
30
|
+
font-family: KaTeX_Main, 'Times New Roman', serif;
|
|
31
|
+
`,t.innerHTML=e,document.body.appendChild(t),T()&&await document.fonts.ready,new Promise(n=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{const a=t.querySelector(".katex")||t,i=a.getBoundingClientRect(),
|
|
32
|
+
r=a.scrollWidth,o=a.scrollHeight,s=Math.ceil(Math.max(i.width,r)),h=Math.ceil(Math.max(i.height,o)),u=s+p*2,_=h+p*2;document.body.removeChild(t),n({width:Math.max(u,20),height:Math.max(_,20),contentWidth:Math.
|
|
33
|
+
max(s,10),contentHeight:Math.max(h,10)})})})})}let f=null;const ae=1e4;let y=null;const M=new Map;async function ie(e){if(M.has(e))return M.get(e);const t=(async()=>{try{const n=await fetch(e);if(!n.ok)
|
|
34
|
+
throw new Error(`HTTP ${n.status}`);const a=await n.blob();return new Promise((i,r)=>{const o=new FileReader;o.onload=()=>{i(o.result)},o.onerror=r,o.readAsDataURL(a)})}catch(n){return console.warn(`F\
|
|
35
|
+
ailed to load font: ${e}`,n),M.delete(e),""}})();return M.set(e,t),t}async function oe(){const e=[{family:"KaTeX_Main",weight:"normal",style:"normal",file:l("fonts/KaTeX_Main-Regular.woff2")},{family:"\
|
|
36
|
+
KaTeX_Main",weight:"bold",style:"normal",file:l("fonts/KaTeX_Main-Bold.woff2")},{family:"KaTeX_Main",weight:"normal",style:"italic",file:l("fonts/KaTeX_Main-Italic.woff2")},{family:"KaTeX_Math",weight:"\
|
|
37
|
+
normal",style:"italic",file:l("fonts/KaTeX_Math-Italic.woff2")},{family:"KaTeX_Size1",weight:"normal",style:"normal",file:l("fonts/KaTeX_Size1-Regular.woff2")},{family:"KaTeX_Size2",weight:"normal",style:"\
|
|
38
|
+
normal",file:l("fonts/KaTeX_Size2-Regular.woff2")},{family:"KaTeX_Size3",weight:"normal",style:"normal",file:l("fonts/KaTeX_Size3-Regular.woff2")},{family:"KaTeX_Size4",weight:"normal",style:"normal",
|
|
39
|
+
file:l("fonts/KaTeX_Size4-Regular.woff2")},{family:"KaTeX_AMS",weight:"normal",style:"normal",file:l("fonts/KaTeX_AMS-Regular.woff2")},{family:"KaTeX_Caligraphic",weight:"normal",style:"normal",file:l(
|
|
40
|
+
"fonts/KaTeX_Caligraphic-Regular.woff2")},{family:"KaTeX_Fraktur",weight:"normal",style:"normal",file:l("fonts/KaTeX_Fraktur-Regular.woff2")},{family:"KaTeX_SansSerif",weight:"normal",style:"normal",file:l(
|
|
41
|
+
"fonts/KaTeX_SansSerif-Regular.woff2")},{family:"KaTeX_Script",weight:"normal",style:"normal",file:l("fonts/KaTeX_Script-Regular.woff2")},{family:"KaTeX_Typewriter",weight:"normal",style:"normal",file:l(
|
|
42
|
+
"fonts/KaTeX_Typewriter-Regular.woff2")}];let t=!0;return{css:(await Promise.all(e.map(async n=>{const a=await ie(n.file);return a?`@font-face {
|
|
43
|
+
font-family: '${n.family}';
|
|
44
|
+
font-weight: ${n.weight};
|
|
45
|
+
font-style: ${n.style};
|
|
46
|
+
src: url('${a}') format('woff2');
|
|
47
|
+
}`:(t=!1,"")}))).filter(Boolean).join(`
|
|
48
|
+
`),complete:t}}function re(){if(f)return f;const e=document.querySelector('link[href*="katex"]');if(e?.sheet)return f=Promise.resolve(!0),f;let t=e;t||(t=document.createElement("link"),t.rel="styleshe\
|
|
49
|
+
et",t.href=l("katex.min.css"));const n=t,a=new Promise(i=>{const r=u=>{window.clearTimeout(h),n.removeEventListener("load",o),n.removeEventListener("error",s),!u&&f===a&&(f=null,n!==e&&n.remove()),i(u)},
|
|
50
|
+
o=()=>r(!0),s=()=>r(!1),h=window.setTimeout(()=>r(!!n.sheet),ae);n.addEventListener("load",o),n.addEventListener("error",s)});return f=a,e||document.head.appendChild(t),a}async function le(){if(y)return y;
|
|
51
|
+
const e=(async()=>{try{const[t,n]=await Promise.all([fetch(l("katex.min.css")),oe()]);if(!t.ok)throw new Error(`HTTP ${t.status}`);let a=await t.text();return a=a.replace(/@font-face\s*\{[^}]*\}/g,""),
|
|
52
|
+
{css:n.css+`
|
|
53
|
+
`+a,complete:n.complete}}catch(t){return console.warn("Failed to fetch KaTeX CSS:",t),{css:"",complete:!1}}})();return y=e,e.then(({complete:t})=>{!t&&y===e&&(y=null)}),e}function se(e,t,n,a,i=g){return`\
|
|
54
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${n}" style="overflow: visible;">
|
|
55
|
+
<defs>
|
|
56
|
+
<style type="text/css">
|
|
57
|
+
${a}
|
|
58
|
+
</style>
|
|
59
|
+
</defs>
|
|
60
|
+
<foreignObject width="100%" height="100%" style="overflow: visible;">
|
|
61
|
+
<div xmlns="http://www.w3.org/1999/xhtml" style="width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 16px; line-height: 1.2; font-family: KaTeX_Main,\
|
|
62
|
+
'Times New Roman', serif; overflow: visible; box-sizing: border-box; color: ${i};">
|
|
63
|
+
${e}
|
|
64
|
+
</div>
|
|
65
|
+
</foreignObject>
|
|
66
|
+
</svg>`}function ce(e,t,n){return new Promise((a,i)=>{const r="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(e),o=new Image;o.width=t,o.height=n,o.onload=()=>{a(o)},o.onerror=()=>{i(new Error(
|
|
67
|
+
"Failed to load math SVG as image"))},o.src=r})}const fe=Object.freeze(Object.defineProperty({__proto__:null,INLINE_MATH_SCALE:j,MATH_PADDING:p,ensureMathRendered:I,getCachedMathSvg:W,getKatexSync:H,getMathMlToLatexSync:L,
|
|
68
|
+
getMathRender:z,htmlHasMathMl:J,loadKatex:X,loadMathMlToLatex:P},Symbol.toStringTag,{value:"Module"}));export{j as I,p as M,X as a,H as b,W as c,z as d,I as e,fe as f,L as g,P as l,V as o,l as r};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import{C as P,w as S}from"./backend-DecaBz-I.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-BrZoDM0j.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,6 @@
|
|
|
1
|
+
import{A as P,B as S}from"./index-2TBhRkX7.js";import{N as _,k as Z,m as E,r as C,l as q,f as U,e as J,a as G,i as O,s as K,c as k,b as Q,p as Y,d as tt,n as W,M as et,g as nt}from"./OfficeImportShared-Bvm-mOyj.js";class st{static async parseFile(e){const t=(await import("./index-2TBhRkX7.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("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))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={}){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,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,"font-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,"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(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)||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,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=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=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"));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(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(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.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=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");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));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&&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.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!==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?.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.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=="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={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(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.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"?"justify":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,"margin-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(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=!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>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]==="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,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:names: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,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,"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-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)))}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),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.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&&(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"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.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:""}).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"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===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.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):(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:"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);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=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=="number"&&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=[];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&&(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=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},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(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",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&&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(),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:"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){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??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||(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))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",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==="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(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.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(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).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,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," ");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.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.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(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(`
|
|
2
|
+
`,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-class")==="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(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.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.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({kind:"run",node:{type:"text",text:`
|
|
3
|
+
`,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"ellipse":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-start":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"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){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("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==="creator"?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"),...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(Number.isFinite(c)?c:0).toISOString(),bodyMd:l.map(i=>i.trim()).filter(i=>i.length>0).join(`
|
|
4
|
+
|
|
5
|
+
`),...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("*","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",{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];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.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.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(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(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.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(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.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(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(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&&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","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.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){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:" ",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;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(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,"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")==="landscape",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.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 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+=" ".repeat(parseInt(r(s,"c")||"1",10)||1):s.localName==="tab"?e+=" ":s.localName==="line-break"?e+=`
|
|
6
|
+
`: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,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,"'").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)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(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,6 @@
|
|
|
1
|
+
import{A as P,B as S}from"./index-BwcX_r62.js";import{N as _,k as Z,m as E,r as C,l as q,f as U,e as J,a as G,i as O,s as K,c as k,b as Q,p as Y,d as tt,n as W,M as et,g as nt}from"./OfficeImportShared-BY6FdZ8d.js";class st{static async parseFile(e){const t=(await import("./index-BwcX_r62.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("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))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={}){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,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,"font-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,"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(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)||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,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=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=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"));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(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(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.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=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");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));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&&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.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!==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?.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.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=="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={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(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.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"?"justify":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,"margin-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(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=!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>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]==="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,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:names: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,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,"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-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)))}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),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.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&&(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"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.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:""}).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"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===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.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):(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:"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);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=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=="number"&&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=[];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&&(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=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},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(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",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&&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(),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:"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){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??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||(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))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",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==="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(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.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(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).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,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," ");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.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.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(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(`
|
|
2
|
+
`,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-class")==="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(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.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.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({kind:"run",node:{type:"text",text:`
|
|
3
|
+
`,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"ellipse":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-start":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"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){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("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==="creator"?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"),...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(Number.isFinite(c)?c:0).toISOString(),bodyMd:l.map(i=>i.trim()).filter(i=>i.length>0).join(`
|
|
4
|
+
|
|
5
|
+
`),...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("*","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",{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];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.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.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(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(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.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(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.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(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(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&&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","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.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){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:" ",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;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(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,"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")==="landscape",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.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 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+=" ".repeat(parseInt(r(s,"c")||"1",10)||1):s.localName==="tab"?e+=" ":s.localName==="line-break"?e+=`
|
|
6
|
+
`: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,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,"'").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)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(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 @@
|
|
|
1
|
+
import{A as l,E as P,F as M,H as m,P as g,B as f,I as y,R as v,J as S}from"./index-BwcX_r62.js";const k=new Set(["http","https","mailto","tel","ftp"]);function A(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.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 j(n){if(!n)return;const t=/^\s*(-?\d*\.?\d+)\s*(pt|px|cm|mm|in|pc|em)\s*$/i.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/2.54;case"mm":return e*96/25.4;case"em":return e*16;default:return}}function F(n){if(n>0)return m(n,{indentStepPx:g,storedAsUnits:!1})}function L(n){if(n<0)return-1;if(n>0)return m(n,{indentStepPx:g,storedAsUnits:!1,firstLine:!0})}function C(n){const t={};if(n.widthPx&&n.heightPx){const s=S(n.widthPx,n.heightPx);s&&N(s.pageSize,n)&&(t.pageSize=s.pageSize,t.orientation=n.landscape?"landscape":s.orientation)}const e=s=>s!==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=i),a!==void 0&&(t.marginBottomPx=a),c!==void 0&&(t.marginLeftPx=c),Object.keys(t).length>0?t:void 0}const I={letter:[8.5,11],tabloid:[11,17],legal:[8.5,14],statement:[5.5,8.5],executive:[7.25,10.5],folio:[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 N(n,t){const e=I[n];if(!e||!t.widthPx||!t.heightPx)return!1;const r=Math.min(t.widthPx,t.heightPx)/96,i=Math.max(t.widthPx,t.heightPx)/96;return Math.abs(r-e[0])<.25&&Math.abs(i-e[1])<.25}function z(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))return"#"+t.slice(1).split("").map(e=>e+e).join("")}function E(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 W(n){let t="";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 B={png:"image/png",jpeg:"image/jpeg",gif:"image/gif",bmp:"image/bmp",webp:"image/webp",svg:"image/svg+xml",emf:"image/x-emf",wmf:"image/x-wmf"};function R(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"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"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]===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 T(n,t,e,r={}){const i=`data:${B[t]};base64,${W(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.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){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=y({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).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.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-(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.counters[t]+=1;const i=`${this.prefix}-${this.notes.length+1}`,a=e.length>0?e:[l()];P(a),this.notes.push({type:"footnote",id:i,...t==="endnote"?{noteKind:"endnote"}:{},children:a});const{footnoteRef:c,superscript:s,subscript:o,...u}=r;return{type:"text",text:M(this.counters[t],t),marks:{...u,footnoteRef:i,superscript:!0}}}}function J(n,t,e,r){const i=e?.trim()===v;return{...n==="insertion"?{insertion:!0}:{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}:{},...e?{suggestionAuthorName:e}:{}}}function K(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(",").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 G(n){const t=[];for(const e of n){const r=t[t.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)if(e[a]!==r[a])return!1;return!0}export{x as M,U as N,H as a,T as b,j as c,A as d,p as e,L as f,w as g,E as h,J as i,b as j,K as k,F as l,G as m,z as n,C as p,d as r,R as s,$ as t};
|