revise 1.0.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +962 -0
- package/FONT-LICENSE-HAN-EXT-B.txt +91 -0
- package/FONT-LICENSE-KATEX.txt +95 -0
- package/FONT-LICENSE-LIBERATION.txt +102 -0
- package/FONT-LICENSE-NOTO-MULTILINGUAL.txt +93 -0
- package/FONT-LICENSE-NOTO-SANS-SC.txt +93 -0
- package/FONT-LICENSE-NOTO.txt +94 -0
- package/FONT-LICENSE-SOURCE-CODE-PRO.txt +94 -0
- package/FONT-LICENSE-SOURCE-SERIF-4.txt +93 -0
- package/LICENSE +41 -21
- package/README.md +39 -1
- package/THIRD-PARTY-NOTICES.md +3376 -0
- package/assets/historyMaterializeWorker-CoAX9ZAi.js +3 -0
- package/backend.d.ts +133 -0
- package/backend.js +1 -0
- package/chunks/AgentPageRenderer-C0n4EnuW.js +1 -0
- package/chunks/AgentPageRenderer-DURfmiu0.js +1 -0
- package/chunks/AttachmentDocumentImporter-DSic_6At.js +1 -0
- package/chunks/AttachmentDocumentImporter-dNMtkxrv.js +1 -0
- package/chunks/BidiText-B4Hzrjg9.js +1 -0
- package/chunks/ColorParserFull-BKH72fK8.js +1 -0
- package/chunks/DocumentStylesheet-byN5dtC6.js +1 -0
- package/chunks/DocxConverter-B7P52lw7.js +11 -0
- package/chunks/DocxConverter-COV6CjUM.js +11 -0
- package/chunks/DocxConverter-Cq_zCEJC.js +11 -0
- package/chunks/DocxGraft-CJ12C9WP.js +1 -0
- package/chunks/DocxGraft-CQpvFcYb.js +1 -0
- package/chunks/DocxGraft-DcmFuUkd.js +1 -0
- package/chunks/FileImporter-DVnYOJHp.js +1 -0
- package/chunks/FileImporter-q9mCch0J.js +1 -0
- package/chunks/HorizontalRuleOrnaments-gmUZ3R7Q.js +1 -0
- package/chunks/HtmlConverter-JvRlkQM3.js +61 -0
- package/chunks/ListNumbering-Qlu6AuRZ.js +1 -0
- package/chunks/MarkdownConverter-B-tPY7X3.js +17 -0
- package/chunks/MathRenderer-B0Y1h1JU.js +33 -0
- package/chunks/OdtConverter-Br81BSoJ.js +1 -0
- package/chunks/OdtConverter-CQjh0vlo.js +1 -0
- package/chunks/OdtConverter-DYHnR4E8.js +1 -0
- package/chunks/PdfConverter-D26rXumc.js +21 -0
- package/chunks/PdfConverter-DGZpUSVf.js +21 -0
- package/chunks/PdfConverter-DZzVP0-B.js +21 -0
- package/chunks/PdfImportService-CBD8TL1k.js +2 -0
- package/chunks/PdfImportService-D6uUKGMf.js +2 -0
- package/chunks/RtfConverter-BQGge3K-.js +14 -0
- package/chunks/RtfConverter-CMfZ4olw.js +14 -0
- package/chunks/RtfConverter-oIwzoqCD.js +14 -0
- package/chunks/TableBorders-BLkZYt1k.js +1 -0
- package/chunks/TableGrid-DVWaRZv0.js +1 -0
- package/chunks/TextFileDecoder--rsVs3NR.js +2 -0
- package/chunks/TxtConverter-C1lp6dBS.js +11 -0
- package/chunks/__vite-browser-external-l0sNRNKZ.js +0 -0
- package/chunks/_commonjsHelpers-DaMA6jEr.js +1 -0
- package/chunks/_revise-sdk-lazy-harfbuzz-CDWdjF9f.js +1 -0
- package/chunks/_revise-sdk-lazy-harfbuzz-X8gnYTZL.js +1 -0
- package/chunks/ar-kgSWdrXF.js +8 -0
- package/chunks/backend-Cq-khfdG.js +1 -0
- package/chunks/base64-CfDUyGi8.js +36 -0
- package/chunks/browser-module-6b2Fq-5C.js +3 -0
- package/chunks/browser-module-CFmqfGkE.js +3 -0
- package/chunks/browser-module-CkO57IPL.js +3 -0
- package/chunks/bundle.min-DRpfgV69.js +8 -0
- package/chunks/capture-DU3MC7tb.js +1 -0
- package/chunks/carrier-WgcRSu7a.js +1 -0
- package/chunks/de-C2QTHrqo.js +8 -0
- package/chunks/es-BKboUn4q.js +8 -0
- package/chunks/footnoteFlatten-CW-DUcgK.js +1 -0
- package/chunks/graftExport-CVg7PO2A.js +2 -0
- package/chunks/html2canvas.esm-CntiHiYW.js +5 -0
- package/chunks/index-BWdRWxoH.js +24 -0
- package/chunks/index-CLw_BlSL.js +353 -0
- package/chunks/index-F-kHIwWT.js +353 -0
- package/chunks/index.es-CI0QPo8w.js +5 -0
- package/chunks/index.es-DOqegDGr.js +5 -0
- package/chunks/index.es-tXDO0RMv.js +5 -0
- package/chunks/jspdf.es.min-CzYti8jo.js +77 -0
- package/chunks/jspdf.es.min-DU74zN8b.js +77 -0
- package/chunks/jspdf.es.min-ejWOGhkJ.js +77 -0
- package/chunks/jszip.min-CPW0h1Kx.js +2 -0
- package/chunks/katex-DWj8TvwO.js +261 -0
- package/chunks/pdf-BLWDCiFF.js +12 -0
- package/chunks/persistInlineDocumentImages-DQj2iaqg.js +1 -0
- package/chunks/pseudoLocale-CdBtPHRi.js +1 -0
- package/chunks/pseudoLocale-DEVWLkGC.js +1 -0
- package/chunks/purify.es-BwLardii.js +2 -0
- package/chunks/serverDocumentSession-DZrYbdpk.js +42 -0
- package/chunks/tree-sitter-D6zWWUMP.js +4 -0
- package/chunks/wasmInline.generated-CBYFkdSM.js +1 -0
- package/chunks/web-tree-sitter-BXGZGnNj.js +1 -0
- package/full.js +1 -0
- package/index.d.ts +929 -0
- package/index.js +1 -0
- package/package.json +93 -26
- package/root.d.ts +5 -0
- package/root.js +2 -0
- package/serverToolContract.d.ts +373 -0
- package/serverToolInputs.generated.d.ts +229 -0
- package/style.css +1 -0
- package/.npmignore +0 -4
- package/.travis.yml +0 -16
- package/revise.js +0 -16
- package/t/cover +0 -18
- package/t/revise/comparator.t.js +0 -31
- package/t/revise/extractor.t.js +0 -29
- package/t/test +0 -20
|
@@ -0,0 +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-CLw_BlSL.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{a as c,b as u,d as g,k as f,c as d,g as l,i as m,j as S,h as p,m as h,n as y,p as x,e as D,s as k,l as C,f as E}from"./capture-DU3MC7tb.js";import{a as i}from"./graftExport-CVg7PO2A.js";import{G as b,g as R}from"./graftExport-CVg7PO2A.js";import{C as B,D as A,g as _,l as I,s as P}from"./carrier-WgcRSu7a.js";function F(a,o){const r=a.docxSource;if(!r)return s("no-capture");if(!o)return s("no-carrier");if(!r.sourceHash)return s("unpaired-capture");if(o.hash!==r.sourceHash)return s("carrier-hash-mismatch");const e=i(a),n=Object.entries(e.domains).filter(([,t])=>!t).map(([t])=>t);return{fidelity:e.fullyExact?"exact":"grafted",regeneratedBlockIds:e.regeneratedBlockIds,changedDomains:n}}function s(a){return{fidelity:"converted",regeneratedBlockIds:[],changedDomains:[],convertedReason:a}}export{B as CARRIER_MAP_KEY,A as DEFAULT_CARRIER_BYTE_CAP,b as GraftProofError,i as assessGraftability,c as blockCanonical,u as blockSignature,g as bodySidecarsSignature,f as canonicalizeForSignature,d as captureDocxSource,l as chromeSignature,m as commentsSignature,F as computeSourceFidelity,S as corePropertiesSignature,_ as getDocxCarrierMeta,R as graftExport,p as hashBytes,I as loadDocxCarrier,h as markBlockSource,y as notesSignature,x as pageLayoutSignature,D as settingsSignature,k as signatureDigest,C as stableStringify,P as storeDocxCarrier,E as stylesSignature};
|
|
@@ -0,0 +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-F-kHIwWT.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{a0 as m,a1 as f,a2 as d,a3 as s,a4 as u}from"./index-CLw_BlSL.js";const n=[...m.filter(t=>t.import).flatMap(t=>[...t.extensions]),".pdf",".png",".jpg",".jpeg",".webp",".gif"],w=n.join(",");function g(t){const e=t.toLowerCase();return n.some(r=>e.endsWith(r))}class l{static async parseFile(e){const r=e.name.toLowerCase(),o=f(r);if(o?.import){const i=await d(new Uint8Array(await e.arrayBuffer()),e.name,o.id,e.type);if(o.id!=="docx")return s(i);const{persistInlineDocumentImages:p}=await import("./persistInlineDocumentImages-DQj2iaqg.js");await p(i);const a=s(i);if(a.docxSource){const{refreshDocxSourceSignatures:c}=await import("./DocxGraft-CJ12C9WP.js");c(a)}return a}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: ${e.name}. Supported formats: .docx, .md, .txt, .pdf, .png, .jpg, .jpeg, .webp, .gif`)}static getSupportedExtensions(){return[...n]}static getAcceptString(){return w}static isSupported(e){return g(e)}}export{l as FileImporter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a0 as m,a1 as f,a2 as d,a3 as s,a4 as u}from"./index-F-kHIwWT.js";const n=[...m.filter(t=>t.import).flatMap(t=>[...t.extensions]),".pdf",".png",".jpg",".jpeg",".webp",".gif"],w=n.join(",");function g(t){const e=t.toLowerCase();return n.some(r=>e.endsWith(r))}class l{static async parseFile(e){const r=e.name.toLowerCase(),o=f(r);if(o?.import){const i=await d(new Uint8Array(await e.arrayBuffer()),e.name,o.id,e.type);if(o.id!=="docx")return s(i);const{persistInlineDocumentImages:p}=await import("./persistInlineDocumentImages-DQj2iaqg.js");await p(i);const a=s(i);if(a.docxSource){const{refreshDocxSourceSignatures:c}=await import("./DocxGraft-DcmFuUkd.js");c(a)}return a}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: ${e.name}. Supported formats: .docx, .md, .txt, .pdf, .png, .jpg, .jpeg, .webp, .gif`)}static getSupportedExtensions(){return[...n]}static getAcceptString(){return w}static isSupported(e){return g(e)}}export{l as FileImporter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const u=new Set(["stars","diamonds"]);function x(s){return s!==void 0&&u.has(s)}function f(s,a,r=1){const t=3.5*r,e=5*r,i=13*r,o=12*r,n=(s+a)/2,c=i+t+o;return a-s<c*2+24*r?{lines:[{from:s,to:a}],ornaments:[]}:{lines:[{from:s,to:n-c},{from:n+c,to:a}],ornaments:[{cx:n-i,radius:t},{cx:n,radius:e},{cx:n+i,radius:t}]}}function d(s,a,r){const t=[];for(let e=0;e<4;e++){const i=Math.PI/4*e,o=Math.cos(i)*r,n=Math.sin(i)*r;t.push({x1:s-o,y1:a-n,x2:s+o,y2:a+n})}return t}function m(s,a,r){return[{x:s,y:a-r},{x:s+r,y:a},{x:s,y:a+r},{x:s-r,y:a}]}export{m as d,x as i,f as l,d as s};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import{k as T,s as k,aF as V,aW as J,aU as K,b as P,l as U,i as Z,r as W,c as B,d as Y,f as I,j as Q,O as tt,aM as et,h as rt,aX as nt,S as it}from"./backend-Cq-khfdG.js";import{i as at,p as D,e as ot,r as st,s as lt}from"./ListNumbering-Qlu6AuRZ.js";import{f as O}from"./footnoteFlatten-CW-DUcgK.js";import{i as ct}from"./HorizontalRuleOrnaments-gmUZ3R7Q.js";import{b as F}from"./TableGrid-DVWaRZv0.js";import{g as ht,l as dt,a as pt,b as z}from"./MathRenderer-B0Y1h1JU.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 E}from"./BidiText-B4Hzrjg9.js";const $t=[[/[\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,"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,"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"],[/\p{Script=Armenian}/u,"hy"],[/\p{Script=Georgian}/u,"ka"],[/\p{Script=Ethiopic}/u,"und-Ethi"],[/\p{Script=Cyrillic}/u,"und-Cyrl"]];function kt(w,t="en"){let e={language:t,count:0};for(const[i,a]of $t){const s=new RegExp(i.source,`${i.flags}g`),p=Array.from(w.matchAll(s)).length;p>e.count&&(e={language:a,count:p})}const r=Array.from(w.matchAll(/[\p{Script=Hiragana}\p{Script=Katakana}]/gu)).length,n=Array.from(w.matchAll(/\p{Script=Han}/gu)).length;return r>0&&r+n>=e.count?"ja":Array.from(w.matchAll(/\p{Script=Latin}/gu)).length>e.count?t:e.language}function vt(w,t="en"){const e=new Map,r=[],n=i=>{if(!i||typeof i!="object")return;const a=i;typeof a.text=="string"&&(r.push(a.text),typeof a.marks?.lang=="string"&&e.set(a.marks.lang,(e.get(a.marks.lang)??0)+a.text.length)),typeof a.content=="string"&&r.push(a.content),Array.isArray(a.children)&&a.children.forEach(n)};return n(w),[...e.entries()].sort((i,a)=>a[1]-i[1])[0]?.[0]??kt(r.join(`
|
|
2
|
+
`),t)}const M="Arial, sans-serif",_=8.5*96,j=96,St=11*96,At=4,Tt=20,X={unordered:25,ordered:30,todo:35};class wt{static fromHtml(t){const e=new DOMParser().parseFromString(t,"text/html");this.normalizeWordClipboard(e.body);const r=this.extractViewSourceText(e);if(r!==null)return this.convertPlainText(r);if(this.isMinimalHtml(e)){const a=this.extractTextWithLineBreaks(e.body);return this.convertPlainText(a)}const n=Array.from(e.body.children).filter(a=>a.tagName.toLowerCase()==="section"&&a.hasAttribute("data-revise-section"));if(n.length>0){const a=[];let s=0;Array.from(e.body.children).forEach(c=>{const h=c.tagName.toLowerCase()==="section"&&c.hasAttribute("data-revise-section");if(a.push(...this.extractAllContent(c)),h&&(s+=1,s<n.length)){const l=c.getAttribute("data-revise-break-after"),d={type:"section-break",id:T(),breakType:l==="continuous"||l==="evenPage"||l==="oddPage"?l:"nextPage"},u=this.readHtmlSectionLayout(c);u&&(d.layout=u),a.push(d)}});const p=n[n.length-1],o=this.readHtmlSectionLayout(p);return{type:"doc",children:a.length>0?a:[k()],...o?{pageLayout:o}:{}}}const i=this.extractAllContent(e.body);return at(T,i),{type:"doc",children:i.length>0?i:[k()]}}static readHtmlSectionLayout(t){const e=t.getAttribute("data-revise-section-layout");if(e!==null)try{const o=JSON.parse(e);if(o&&typeof o=="object"&&!Array.isArray(o))return Object.keys(o).length>0?o:void 0}catch{}const r=t.getAttribute("data-revise-column-count")||t.style.columnCount,n=Number.parseInt(r??"",10),i=t.getAttribute("data-revise-column-gap-twips"),a=i?Number.parseFloat(i):Number.NaN,s=Number.parseFloat(t.style.columnGap||""),p={...Number.isFinite(n)&&n>=1?{columnCount:n}:{},...Number.isFinite(a)&&a>=0?{columnGapTwips:a}:Number.isFinite(s)&&s>=0?{columnGapTwips:V(s)}:{}};return Object.keys(p).length>0?p:void 0}static convertListElement(t,e=0){const r=t.tagName.toLowerCase()==="ol"?"ordered":"unordered",n=[],i=[];let a=r==="ordered";const s=(o,c)=>{for(const h of Array.from(o.children)){const l=h.tagName.toLowerCase();if(l==="ol"||l==="ul"){s(h,c+1);continue}if(l!=="li")continue;const d=Number(h.getAttribute("data-aria-level")),u=d>0?d-1:c,m=h.getAttribute("data-clipboard-list-tag")??o.tagName.toLowerCase(),g=h.style.listStyleType||o.style.listStyleType,f=m==="ul"||["disc","circle","square"].includes(g);a||(a=!f);const x={"lower-alpha":"lowerLetter","upper-alpha":"upperLetter","lower-latin":"lowerLetter","upper-latin":"upperLetter","lower-roman":"lowerRoman","upper-roman":"upperRoman",a:"lowerLetter",A:"upperLetter",i:"lowerRoman",I:"upperRoman"},A=g||o.getAttribute("type")||"decimal";i[u]=f?{numFmt:"bullet",lvlText:g==="circle"?"◦":g==="square"?"▪":"•"}:{numFmt:x[A]??"decimal",lvlText:h.getAttribute("data-leveltext")||`%${u+1}.`};const $=h.cloneNode(!0);$.querySelectorAll("ol, ul").forEach(y=>y.remove());const b=this.extractInlineContent($).filter(y=>y.type==="text"),v={...this.extractParagraphSpacing(h),type:"list-item",id:T(),children:b.length>0?b:[{type:"text",text:"",marks:{}}]};u>0&&(v.indentLevel=u),n.push(v);for(const y of Array.from(h.children)){const S=y.tagName.toLowerCase();(S==="ol"||S==="ul")&&s(y,c+1)}}};if(s(t,e),n.length===0)return null;const p={type:"list",id:T(),variant:a?"ordered":r,children:n};if(a&&(i.length>1||i[0]?.numFmt!=="decimal")&&(p.numberingFormat=JSON.stringify(i)),r==="ordered"){const o=t.getAttribute("start"),c=o?parseInt(o,10):NaN;Number.isFinite(c)&&c!==1&&(p.startNumber=c)}return p}static normalizeWordClipboard(t){for(const r of Array.from(t.querySelectorAll(".WACImageContainer"))){const n=r.querySelector("svg image"),i=n?.getAttribute("href")??n?.getAttribute("xlink:href");if(!i)continue;const a=t.ownerDocument.createElement("img");a.setAttribute("src",i),a.setAttribute("width",r.style.width||n.getAttribute("width")||"200"),a.setAttribute("height",r.style.height||n.getAttribute("height")||"200"),a.setAttribute("alt",r.querySelector("desc")?.textContent||""),r.replaceWith(a)}t.querySelectorAll("span.EOP[data-ccp-props]").forEach(r=>r.remove());for(const r of t.querySelectorAll('p[role="heading"][aria-level]')){const n=Number(r.getAttribute("aria-level"));if(n<1||n>6||!Number.isInteger(n))continue;const i=t.ownerDocument.createElement(`h${n}`);for(const a of r.attributes)i.setAttribute(a.name,a.value);i.append(...Array.from(r.childNodes)),r.replaceWith(i)}const e=Array.from(t.querySelectorAll("ol, ul")).filter(r=>r.querySelector(":scope > li[data-listid]"));for(const r of e){for(const i of r.children)i.setAttribute("data-clipboard-list-tag",r.tagName.toLowerCase()),r.classList.contains("NumberListStyle2")&&(i.style.listStyleType="lower-alpha");const n=r.parentElement;n?.classList.contains("ListContainerWrapper")&&n.children.length===1&&n.replaceWith(r)}for(const r of e){if(!t.contains(r))continue;const n=r.firstElementChild?.getAttribute("data-listid");let i=r.nextElementSibling;for(;i?.matches("ol, ul")&&i.firstElementChild?.getAttribute("data-listid")===n;){const a=i.nextElementSibling;r.append(...Array.from(i.children)),i.remove(),i=a}}}static convertPlainText(t){let e=t.split(/\n\n+/).filter(r=>r.trim());if(e.length===1&&t.includes(`
|
|
3
|
+
`)){const r=t.split(`
|
|
4
|
+
`).filter(n=>n.trim());r.length>1&&(e=r)}return{type:"doc",children:e.length>0?e.map(r=>k([{type:"text",text:r.trim(),marks:{}}])):[k()]}}static extractTextWithLineBreaks(t){let e="";for(const r of Array.from(t.childNodes))if(r.nodeType===Node.TEXT_NODE)e+=r.textContent||"";else if(r.nodeType===Node.ELEMENT_NODE){const n=r;n.tagName.toLowerCase()==="br"?e+=`
|
|
5
|
+
`:e+=this.extractTextWithLineBreaks(n)}return e}static extractViewSourceText(t){const e=t.body.getElementsByTagName("table");if(e.length!==1)return null;const r=Array.from(e[0].getElementsByTagName("tr"));if(r.length===0)return null;const n=[];for(const i of r){const a=Array.from(i.getElementsByTagName("td")),s=a.find(o=>o.classList.contains("line-content")),p=a.every(o=>o.classList.contains("line-content")||o.classList.contains("line-number"));if(!s||!p)return null;n.push(s.textContent??"")}return n.join(`
|
|
6
|
+
`)}static isMinimalHtml(t){const e=t.body,r=document.createTreeWalker(e,NodeFilter.SHOW_ELEMENT|NodeFilter.SHOW_TEXT,null);let n=!0,i=!1;const a=t.getElementsByTagName("meta");for(const o of Array.from(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"&&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){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.convert(e);if(!n||n.trim()==="")return null;const i=t.getAttribute("display")==="block";return J(n.trim(),{displayMode:"block",align:"center"})}catch(e){return console.warn("Failed to convert MathML to 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.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?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=()=>{const l=c.cloneContents();if(!l.textContent&&!l.querySelector("br"))return;const d=t.cloneNode(!1);d.appendChild(l),this.processElement(d,e,r)};for(const l of Array.from(t.querySelectorAll("img")))c.setEndBefore(l),h(),this.processElement(l,e,r),c.setStartAfter(l);c.setEnd(t,t.childNodes.length),h();return}if(n==="math"){const c=this.convertMathMLToBlock(t);c&&e.push(c);return}if(n==="table"){const c=this.convertTableElement(t);c&&e.push(c);return}const i=["span","strong","b","em","i","u","s","strike","del","code","sup","sub","a","abbr","mark"];if(n==="p"){const c=this.extractInlineContent(t),h=this.extractElementDirection(t),l=h??H(this.inlineNodesText(c))??"ltr",d=this.extractParagraphStyleAttributes(t.getAttribute("style")||"",void 0,l),u=this.splitOnNewlines(c);for(let m=0;m<u.length;m++){const g=u[m],f=k(g.length>0?g:[{type:"text",text:"",marks:{}}]);f.align=d.align??this.extractElementAlignment(t);const x=this.resolveImportedDirection(h,this.inlineNodesText(g));x&&(f.direction=x),d.leftIndent!==void 0&&(f.leftIndent=d.leftIndent),d.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.match(/^h[1-6]$/)){const c=this.extractInlineContent(t),h=this.extractElementDirection(t),l=h??H(this.inlineNodesText(c))??"ltr",d=this.extractParagraphStyleAttributes(t.getAttribute("style")||"",void 0,l),u=this.splitOnNewlines(c);for(let m=0;m<u.length;m++){const g=u[m],f=k(g.length>0?g:[{type:"text",text:"",marks:{}}]);Object.assign(f,this.extractParagraphSpacing(t)),m===0&&(f.heading=parseInt(n.charAt(1))),f.align=d.align??this.extractElementAlignment(t);const x=this.resolveImportedDirection(h,this.inlineNodesText(g));x&&(f.direction=x),d.leftIndent!==void 0&&(f.leftIndent=d.leftIndent),d.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"||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){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}if(n==="hr"){e.push(K());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.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:"text",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.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.splitOnNewlines(a);for(const h of c){const l=k(h);p(l,h),Object.assign(l,this.extractParagraphSpacing(t)),e.push(l)}}}static convertTableElement(t){const e=this.getDirectTableRows(t);if(e.length===0)return null;const r=e.map(h=>this.convertTableRowElement(h)).filter(h=>h!==null&&h.children.length>0);if(r.length===0)return null;const n={children:r,columnWidths:[]};let i=F(n);const a=i.cols;if(a===0)return null;for(let h=0;h<r.length;h++){let l=0;for(let d=0;d<i.cols;d++)i.occupancy[h][d]||l++;if(l>0){for(let d=0;d<l;d++)r[h].children.push(this.createEmptyTableCell());i=F(n)}}const s={type:"table",id:T(),children:r,...this.extractTableSizing(t,a)},p=this.extractElementAlignment(t);p&&p!=="justify"&&(s.align=p);const o=this.extractTableBorderStyle(t);o.color&&(s.borderColor=o.color),o.width!==void 0&&(s.borderWidth=o.width);const c=this.extractTableCellPadding(t);return c!==void 0&&(s.cellPadding=c),this.tableHasHeaderRow(t)&&(s.hasHeader=!0),s}static getDirectTableRows(t){const e=[];for(const r of Array.from(t.children)){const n=r.tagName.toLowerCase();if(n==="tr"){e.push(r);continue}if(n==="thead"||n==="tbody"||n==="tfoot")for(const i of Array.from(r.children))i.tagName.toLowerCase()==="tr"&&e.push(i)}return e}static convertTableRowElement(t){const e=[];for(const r of Array.from(t.children)){const n=r.tagName.toLowerCase();if(n!=="td"&&n!=="th")continue;const i=this.convertTableCellElement(r),a=this.parseSpanAttribute(r.getAttribute("colspan")),s=this.parseSpanAttribute(r.getAttribute("rowspan"));a>1&&(i.colSpan=a),s>1&&(i.rowSpan=s),e.push(i)}return e.length===0?null:{type:"table-row",id:T(),children:e}}static convertTableCellElement(t){const e=this.extractAllContent(t),r={type:"table-cell",id:T(),children:e.length>0?e:[k()]},n=this.extractTableCellVerticalAlign(t);n&&(r.verticalAlign=n);const i=this.extractElementBackgroundColor(t);return i&&(r.backgroundColor=i),r}static parseSpanAttribute(t){const e=parseInt(t||"1",10);return Number.isFinite(e)?Math.min(Math.max(1,e),1e3):1}static createEmptyTableCell(){return{type:"table-cell",id:T(),children:[k()]}}static extractTableSizing(t,e){const r=o=>{for(const c of[o.style?.width,o.getAttribute("width")]){const h=this.parseCssLengthToPx(c);if(h!==void 0&&h>0)return h}},n=r(t);let i=[];const a=Array.from(t.querySelectorAll(":scope > colgroup > col"));for(const o of a){const c=r(o),h=Math.min(this.parseSpanAttribute(o.getAttribute("span")),e-i.length);for(let l=0;l<h;l++)i.push(c)}if(i.length!==e||i.some(o=>o===void 0)){i=Array(e).fill(void 0);const o=Array(e).fill(0),c=[];this.getDirectTableRows(t).forEach((h,l)=>{let d=0;for(const u of Array.from(h.children).filter(m=>m.matches("td, th"))){for(;d<e&&o[d]>l;)d++;const m=Math.min(this.parseSpanAttribute(u.getAttribute("colspan")),e-d),g=r(u);g&&m>0&&c.push({col:d,span:m,width:g});for(let f=d;f<d+m;f++)o[f]=l+this.parseSpanAttribute(u.getAttribute("rowspan"));d+=m}}),c.sort((h,l)=>h.span-l.span);for(const{col:h,span:l,width:d}of c){const u=Array.from({length:l},(g,f)=>h+f).filter(g=>i[g]===void 0),m=i.slice(h,h+l).reduce((g,f)=>g+(f??0),0);if(u.length&&d>m)for(const g of u)i[g]=(d-m)/u.length}}const s=i.every(o=>o!==void 0&&o>0)?i.reduce((o,c)=>o+(c??0),0):0,p=n??(s>0?s:void 0);return{columnWidths:s>0?i.map(o=>Number(((o??0)/s*100).toFixed(2))):Array(e).fill(Number((100/e).toFixed(2))),...p!==void 0?{tableWidth:Math.round(p)}:{}}}static extractTableBorderStyle(t){const e=t.querySelector("td, th");if(!(e instanceof HTMLElement))return{};const r=[e.style.borderTopWidth,e.style.borderRightWidth,e.style.borderBottomWidth,e.style.borderLeftWidth].map(i=>this.parseCssLengthToPx(i)).filter(i=>i!==void 0&&i>=0),n=r.length>0?Math.max(...r.map(i=>Math.round(i))):void 0;return{color:e.style.borderTopColor||e.style.borderRightColor||e.style.borderBottomColor||e.style.borderLeftColor||void 0,width:n}}static extractTableCellPadding(t){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(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()==="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();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 P(e)?e:void 0}static extractElementAlignment(t){const e=this.extractParagraphStyleAttributes(t.getAttribute("style")||"").align;if(e)return e;const r=U(t,"align")?.trim().toLowerCase();if(r==="left"||r==="center"||r==="right"||r==="justify")return r}static parseCssLengthToPx(t){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"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){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","i","u","s","strike","del","code","sup","sub","a","abbr","mark"];if(Array.from(t.childNodes).every(a=>{if(a.nodeType===Node.TEXT_NODE)return!0;if(a.nodeType===Node.ELEMENT_NODE){const s=a.tagName.toLowerCase();return i.includes(s)||s==="br"}return!1}))return this.extractInlineContent(t);for(const a of Array.from(t.childNodes))if(a.nodeType===Node.TEXT_NODE){const s=a.textContent||"";s.trim()&&e.push({type:"text",text:s,marks:r})}else if(a.nodeType===Node.ELEMENT_NODE){const s=a,p=s.tagName.toLowerCase();if(n.includes(p))continue;if(p==="br"){e.push({type:"text",text:`
|
|
7
|
+
`,marks:r});continue}const o=this.extractInlineContent(s);e.push(...o)}return e}static extractInlineContent(t){const e=[],r=this.getTextMarks(t);for(const n of Array.from(t.childNodes))if(n.nodeType===Node.TEXT_NODE){const i=n.textContent||"";i&&e.push({type:"text",text:i,marks:r})}else if(n.nodeType===Node.ELEMENT_NODE){const i=n;if(i.tagName.toLowerCase()==="br"){e.push({type:"text",text:`
|
|
8
|
+
`,marks:r});continue}const a=this.extractInlineContent(i),s=this.getTextMarks(i);for(const p of a)p.type==="text"&&(p.marks={...r,...s,...p.marks}),e.push(p)}return e}static getTextMarks(t){if(!t)return;const e={},r=t.closest("[lang]")?.getAttribute("lang")?.trim();r&&/^[A-Za-z]{2,8}(?:-[A-Za-z0-9]{1,8})*$/u.test(r)&&(e.lang=r);const n=t.tagName.toLowerCase(),i=t instanceof HTMLElement?t.style:null,a=i&&i.fontWeight?parseInt(i.fontWeight):null;(n==="strong"||n==="b")&&(!a||a>=700)&&(e.bold=!0),(n==="em"||n==="i")&&(e.italic=!0),n==="u"&&(e.underline=!0),(n==="s"||n==="strike"||n==="del")&&(e.strikethrough=!0),n==="code"&&(e.code=!0),(n==="sup"||i?.verticalAlign==="super")&&(e.superscript=!0),(n==="sub"||i?.verticalAlign==="sub")&&(e.subscript=!0);const s=Number(t.getAttribute("data-fontsize"));if((e.superscript||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=!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?.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&&(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=P(i.color);o&&!Z(o)&&(e.color=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){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(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/.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]==="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=P(s)??"#000000";return{style:n,width:a,color:p}}static extractElementDirection(t){for(let e=t;e;e=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==="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){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!=="normal"){const a=Number(e.lineHeight),s=this.parseCssLengthToPx(e.fontSize)??this.parseCssLengthToPx(t.querySelector("span[style]")?.style.fontSize)??N.paragraph,p=a>0?a:e.lineHeight.endsWith("%")?parseFloat(e.lineHeight)/100:(this.parseCssLengthToPx(e.lineHeight)??0)/s;p>0&&(r.lineSpacing=p)}return r}static extractParagraphStyleAttributes(t,e=this.resolveIndentStepPx(),r="ltr"){const n={};{const l={},d=this.parseCssParagraphBorder(t.match(/(?:^|;)\s*border:\s*([^;]+)/i)?.[1]);for(const u of["top","bottom","left","right"]){const m=t.match(new RegExp(`border-${u}:\\s*([^;]+)`,"i"))?.[1],g=m?this.parseCssParagraphBorder(m):d;g&&(l[u]=g)}Object.keys(l).length>0&&(n.borders=JSON.stringify(l))}const i=t.match(/text-align:\s*([^;]+)/i);if(i){const l=i[1].trim().toLowerCase();if(l==="left"||l==="center"||l==="right"||l==="justify")n.align=l;else if(l==="start"||l==="end"){const d=l==="start"==(r!=="rtl")?"left":"right";d!==(r==="rtl"?"right":"left")&&(n.align=d)}}const a=t.match(/margin-left:\s*([^;]+)/i),s=t.match(/margin-right:\s*([^;]+)/i),p=r==="rtl"?s?.[1]??a?.[1]:a?.[1],o=B(p,{indentStepPx:e});o!==void 0&&(n.leftIndent=o);const c=t.match(/text-indent:\s*([^;]+)/i),h=B(c?.[1],{indentStepPx:e,firstLine:!0});return h!==void 0&&(n.firstLineIndent=h),n}static appendParagraphIndentStyles(t,e,r){const n=Y(e.leftIndent);if(n!==void 0){const a=e.children.map(p=>"text"in p?p.text??"":"").join(""),s=q(e.direction,a)==="rtl"?"margin-right":"margin-left";t.push(`${s}: ${I(n,r)}px`)}const i=Q(e.firstLineIndent);i!==void 0&&t.push(`text-indent: ${I(i,r)}px`)}static splitOnNewlines(t){const e=[];let r=[];for(const n of t)if(n.type==="text"&&n.text.includes(`
|
|
9
|
+
`)){const i=n.text.split(`
|
|
10
|
+
`);for(let a=0;a<i.length;a++){const s=i[a];s&&r.push({type:"text",text:s,marks:n.marks}),a<i.length-1&&(r.length>0?(e.push(r),r=[]):e.push([{type:"text",text:"",marks:{}}]))}}else r.push(n);return r.length>0&&e.push(r),e.length>0?e:[[{type:"text",text:"",marks:{}}]]}static toHtml(t,e,r={}){return this.renderDocument(O(t),{mode:"plain",title:e,includeWrapper:!!e,blockSeparator:r.blockSeparator})}static toStyledHtml(t,e={}){return this.renderDocument(O(t),{mode:"styled",title:e.title,includeWrapper:e.includeWrapper??!!e.title,syntaxTheme:e.syntaxTheme,defaultFontFamily:e.defaultFontFamily})}static async toStyledHtmlAsync(t,e={}){const r=[];if(r.push(pt().then(()=>{})),typeof document<"u"){const n=R();r.push(mt(t,n,e.diagramMaxWidth??680))}return await Promise.all(r),this.toStyledHtml(t,e)}static resolveBaseFontFamily(t){return this.normalizeFontFamily(this.inferDocumentFontFamily(t))??M}static inferDocumentFontFamily(t){if(t?.children){for(const e of t.children)if(e.type==="paragraph"){for(const r of e.children)if(r.type==="text"&&r.marks?.fontFamily)return r.marks.fontFamily}else if(e.type==="list"){for(const r of e.children)for(const n of r.children)if(n.type==="text"&&n.marks?.fontFamily)return n.marks.fontFamily}}}static renderDocument(t,e){if(!t||t.type!=="doc")return"";const r=e.defaultFontFamily??this.inferDocumentFontFamily(t),n=this.normalizeFontFamily(r)??M,i=t.children&&t.children.length>0?t.children:[k()],a=i.length,s=(h,l)=>this.blockToHtml(h,{mode:e.mode,doc:t,baseFontFamily:n,index:l,totalBlocks:a,syntaxTheme:e.syntaxTheme}),p=i.some(h=>h.type==="section-break")||(t.pageLayout?.columnCount??1)>1?this.renderSectionedDocument(t,i,s,e.blockSeparator??""):i.map(s).join(e.blockSeparator??"");if(!e.includeWrapper)return p;const o=e.title??t.title??"Revise Document",c=this.escapeAttribute(vt(t));if(e.mode==="styled"){const h=this.getStyledDocumentCss({baseFontFamily:n,pageless:t.pageless??!1});return`<!DOCTYPE html>
|
|
11
|
+
<html lang="${c}">
|
|
12
|
+
<head>
|
|
13
|
+
<meta charset="UTF-8">
|
|
14
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
15
|
+
<title>${this.escapeHtml(o)}</title>
|
|
16
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">
|
|
17
|
+
<style>
|
|
18
|
+
${h}
|
|
19
|
+
</style>
|
|
20
|
+
</head>
|
|
21
|
+
<body>
|
|
22
|
+
<main class="revise-document">
|
|
23
|
+
${p}
|
|
24
|
+
</main>
|
|
25
|
+
</body>
|
|
26
|
+
</html>`}return`<!DOCTYPE html>
|
|
27
|
+
<html lang="${c}">
|
|
28
|
+
<head>
|
|
29
|
+
<meta charset="UTF-8">
|
|
30
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
31
|
+
<title>${this.escapeHtml(o)}</title>
|
|
32
|
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css">
|
|
33
|
+
<style>
|
|
34
|
+
body {
|
|
35
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
36
|
+
line-height: 1.6;
|
|
37
|
+
color: #333;
|
|
38
|
+
max-width: 800px;
|
|
39
|
+
margin: 0 auto;
|
|
40
|
+
padding: 2rem;
|
|
41
|
+
}
|
|
42
|
+
h1 { font-size: 2rem; margin: 1.5rem 0 1rem; }
|
|
43
|
+
h2 { font-size: 1.5rem; margin: 1.3rem 0 0.8rem; }
|
|
44
|
+
h3 { font-size: 1.25rem; margin: 1.2rem 0 0.6rem; }
|
|
45
|
+
h4 { font-size: 1.1rem; margin: 1rem 0 0.5rem; }
|
|
46
|
+
h5 { font-size: 1rem; margin: 1rem 0 0.5rem; }
|
|
47
|
+
h6 { font-size: 0.9rem; margin: 1rem 0 0.5rem; }
|
|
48
|
+
p { margin: 0.5rem 0; }
|
|
49
|
+
code {
|
|
50
|
+
background-color: #f4f4f4;
|
|
51
|
+
padding: 0.2rem 0.4rem;
|
|
52
|
+
border-radius: 3px;
|
|
53
|
+
font-family: 'Courier New', monospace;
|
|
54
|
+
}
|
|
55
|
+
</style>
|
|
56
|
+
</head>
|
|
57
|
+
<body>
|
|
58
|
+
${p}
|
|
59
|
+
</body>
|
|
60
|
+
</html>`}static renderSectionedDocument(t,e,r,n){const i=[];let a=[];return e.forEach((s,p)=>{s.type==="section-break"?(i.push({blocks:a,layout:s.layout,breakAfter:s.breakType??"nextPage"}),a=[]):a.push({block:s,index:p})}),i.push({blocks:a,layout:t.pageLayout}),i.map((s,p)=>{const o=tt(t.pageLayout,s.layout),c=[`column-count: ${o.columnCount}`,`column-gap: ${this.formatPx(et(o.columnGapTwips))}`,...p>0&&i[p-1].breakAfter!=="continuous"?["break-before: page"]:[]].join("; "),h=s.breakAfter?` data-revise-break-after="${s.breakAfter}"`:"",l=` data-revise-section-layout="${this.escapeAttribute(JSON.stringify(s.layout??{}))}"`;return`<section data-revise-section="${p+1}" data-revise-column-count="${o.columnCount}" data-revise-column-gap-twips="${o.columnGapTwips}"${l}${h} style="${c}">${s.blocks.map(({block:d,index:u})=>r(d,u)).join(n)}</section>`}).join(n)}static blockToHtml(t,e){return t.type==="placeholder"?this.placeholderToHtml(t,e):t.type==="image"?this.imageBlockToHtml(t,e):t.type==="list"?this.listBlockToHtml(t,e):t.type==="paragraph"?this.paragraphToHtml(t,e):t.type==="table"?this.tableBlockToHtml(t,e):t.type==="code"?this.codeBlockToHtml(t,e):t.type==="math"?this.mathBlockToHtml(t,e):""}static placeholderToHtml(t,e){const r=Math.max(16,t.height||0);if(e.mode==="styled"){const n=e.index===0?0:this.resolveBlockSpacingPx(e.doc);return`<div style="${["background-color: #e5e7eb","border-radius: 8px",`height: ${this.formatPx(r)}`,"width: 100%",`margin: ${this.formatPx(n)} 0 0 0`].join("; ")}" data-block-type="placeholder"></div>`}return`<div style="background-color: #e5e7eb; height: ${r}px; width: 100%;"></div>`}static paragraphToHtml(t,e){const r=rt(t);if(r){if(ct(r.style)){const m=r.style==="stars"?"✴":"◆",g=`flex: 1; border-bottom: ${r.width}px solid currentColor`;return`<div role="separator" style="display: flex; align-items: center; gap: 12px; margin: 1em 0; color: ${r.color}"><span style="${g}"></span><span style="font-size: 11px; letter-spacing: 6px; text-indent: 6px; line-height: 1">${m}${m}${m}</span><span style="${g}"></span></div>`}const u=r.style==="single"?"solid":r.style;return`<hr style="${["border: none",`border-bottom: ${r.width}px ${u} ${r.color}`,"margin: 1em 0"].join("; ")}" />`}const n={mode:e.mode,paragraph:t,block:t,doc:e.doc,baseFontFamily:e.baseFontFamily};let i=this.inlineNodesToHtml(t.children,n);const a=t.direction?` dir="${t.direction}"`:q(void 0,t.children.map(u=>u.text??"").join(""))==="rtl"?' dir="auto"':"";if(e.mode==="plain"){const u=[];t.align&&u.push(`text-align: ${t.align}`),this.appendParagraphIndentStyles(u,t,this.resolveIndentStepPx(e.doc));const m=u.length>0?` style="${u.join("; ")}"`:"";return t.heading?`<h${t.heading}${a}${m}>${i}</h${t.heading}>`:`<p${a}${m}>${i}</p>`}this.isEmptyInlineContent(t.children)&&(i="<br>");const s=this.getParagraphFontSizePx(t),p=this.getParagraphLineHeightMultiplier(t),o=this.resolveBlockMarginsPx(t,e),c=e.baseFontFamily,h=[`margin: ${this.formatPx(o.top)} 0 ${o.bottom>0?this.formatPx(o.bottom):"0"} 0`,`font-size: ${this.formatPx(s)}`,`line-height: ${this.formatNumber(p)}`,`font-family: ${this.escapeAttribute(c)}`,"font-weight: 400"];t.align&&h.push(`text-align: ${t.align}`),this.appendParagraphIndentStyles(h,t,this.resolveIndentStepPx(e.doc));const l=t.heading?`h${t.heading}`:"p",d=t.heading?` data-block-type="heading" data-heading="${t.heading}"`:' data-block-type="paragraph"';return`<${l}${a} style="${h.join("; ")}"${d}>${i}</${l}>`}static inlineNodesToHtml(t,e){return t.map(r=>r.type==="text"?this.textNodeToHtml(r,e):"").join("")}static isEmptyInlineContent(t){return!t.some(e=>e.type==="text"&&e.text.length>0)}static textNodeToHtml(t,e){if(t.marks?.latex){const n=z();if(n)try{return`<span data-latex="true">${n.renderToString(t.text,{displayMode:!1,throwOnError:!1,errorColor:"#ef4444",trust:!1,strict:!1})}</span>`}catch(i){const a=i instanceof Error?i.message:"LaTeX render error";return`<span style="color: #ef4444;" data-latex="true">${this.escapeHtml(a)}</span>`}return`<span data-latex="true" data-latex-content="${this.escapeAttribute(t.text)}">${this.escapeHtml(t.text)}</span>`}let r=this.escapeHtml(t.text);if(r=r.replace(/\r\n|\r|\n/g,"<br>"),t.marks){const n=[];if(t.marks.bold&&(r=`<strong>${r}</strong>`),t.marks.italic&&(r=`<em>${r}</em>`),t.marks.underline&&(r=`<u>${r}</u>`),t.marks.strikethrough&&(r=`<s>${r}</s>`),t.marks.code&&(r=`<code>${r}</code>`),t.marks.superscript&&(r=`<sup>${r}</sup>`),t.marks.subscript&&(r=`<sub>${r}</sub>`),t.marks.link){const i=this.sanitizeLinkHref(t.marks.link);i&&(r=`<a href="${this.escapeAttribute(i)}">${r}</a>`)}if(t.marks.doubleStrikethrough&&n.push("text-decoration: line-through double"),t.marks.smallCaps&&n.push("font-variant: small-caps"),t.marks.allCaps&&n.push("text-transform: uppercase"),typeof t.marks.letterSpacing=="number"&&Number.isFinite(t.marks.letterSpacing)&&t.marks.letterSpacing!==0&&n.push(`letter-spacing: ${t.marks.letterSpacing}px`),t.marks.color&&n.push(`color: ${t.marks.color}`),t.marks.backgroundColor&&n.push(`background-color: ${gt(t.marks.backgroundColor)??t.marks.backgroundColor}`),t.marks.fontFamily&&e.mode==="styled"&&n.push(`font-family: ${this.escapeAttribute(t.marks.fontFamily)}`),t.marks.fontSize&&n.push(`font-size: ${t.marks.fontSize}px`),n.length>0||t.marks.lang){const i=n.length>0?` style="${n.join("; ")}"`:"";r=`<span${t.marks.lang?` lang="${this.escapeAttribute(t.marks.lang)}"`:""}${i}>${r}</span>`}t.marks.__htmlClassName&&(r=`<span class="${this.escapeAttribute(t.marks.__htmlClassName)}">${r}</span>`)}return r}static imageBlockToHtml(t,e){const r=t.alt?` alt="${this.escapeAttribute(t.alt)}"`:"",n=t.align?` align="${t.align}" data-align="${t.align}"`:"",i=this.getImageStyle(t),a=Math.max(1,Math.round(t.width)),s=Math.max(1,Math.round(t.height));if(e.mode==="plain"){const l=i?` style="${i}"`:"";return`<img src="${this.escapeAttribute(t.src)}" width="${a}" height="${s}"${r}${n}${l}>`}const p=i?i.split(";").map(l=>l.trim()).filter(Boolean):[],o=e.index===0?0:this.resolveBlockSpacingPx(e.doc);p.push(`margin-top: ${this.formatPx(o)}`),p.push(`margin-bottom: ${this.formatPx(0)}`);const h=p.length>0?` style="${p.join("; ")}"`:"";return`<img src="${this.escapeAttribute(t.src)}" width="${a}" height="${s}"${r}${n}${h} data-block-type="image">`}static listBlockToHtml(t,e){const r=D(t.numberingFormat),n=l=>r?.[l]?.numFmt==="bullet"?"ul":t.variant==="ordered"?"ol":"ul",i=n(0),a=(l,d)=>{const u=[];let m=0;for(;m<l.length;){const g=l[m],f=Math.max(0,g.indentLevel??0);if(f<d)break;if(f!==d){m+=1;continue}const x={mode:e.mode,block:t,doc:e.doc,baseFontFamily:e.baseFontFamily},A=this.inlineNodesToHtml(g.children,x),$=[];let b=m+1;for(;b<l.length&&!(Math.max(0,l[b].indentLevel??0)<=d);)$.push(l[b]),b+=1;let v=A;if($.length>0){const S=n(d+1),C=e.mode==="styled"?this.getListStyle(t,e,d+1):"",L=C?` style="${C}"`:"",G=a($,d+1);v+=`<${S}${L}>${G}</${S}>`}if(t.variant==="todo"){const S=g.checked?" checked":"",C=e.mode==="styled"?' style="margin-right: 12px; width: 16px; height: 16px; accent-color: #111827; vertical-align: middle;"':"";v=`<input type="checkbox"${S}${C}> ${v}`}let y="";if(e.mode==="styled"){const S=g.lineSpacing??this.getListLineHeightMultiplier(t),C=b>=l.length||Math.max(0,l[b].indentLevel??0)<d,L=[`margin: 0 0 ${this.formatPx(g.spaceAfter??(C?0:At))} 0`,`margin-top: ${this.formatPx(g.spaceBefore??0)}`,`line-height: ${this.formatNumber(S)}`];t.variant==="todo"&&L.push("list-style-type: none"),y=` style="${L.join("; ")}"`}if(e.mode!=="styled"){const S=[...g.lineSpacing!==void 0?[`line-height: ${g.lineSpacing}`]:[],...g.spaceBefore!==void 0?[`margin-top: ${g.spaceBefore}px`]:[],...g.spaceAfter!==void 0?[`margin-bottom: ${g.spaceAfter}px`]:[]];S.length&&(y=` style="${S.join("; ")}"`)}u.push(`<li${y}>${v}</li>`),m=b}return u.join("")},s=a(t.children,0),p=t.variant==="ordered"?ot(st(e.doc).get(t.id)??lt(t)):1,o=t.variant==="ordered"&&p!==1?` start="${p}"`:"";if(e.mode==="plain")return`<${i}${o}>${s}</${i}>`;const c=this.getListStyle(t,e,0),h=c?` style="${c}"`:"";return`<${i}${o}${h} data-block-type="list" data-variant="${t.variant}">${s}</${i}>`}static tableBlockToHtml(t,e){const r=t.children;if(!r||r.length===0)return"";const n=t.borderColor??"#d1d5db",i=t.borderWidth??1,a=Number.isFinite(t.cellPadding)?Math.max(0,Math.round(t.cellPadding)):8,s=F(t),p=u=>{const m=s.byId.get(u.id);let g="";return m&&m.colSpan>1&&(g+=` colspan="${m.colSpan}"`),m&&m.rowSpan>1&&(g+=` rowspan="${m.rowSpan}"`),g};if(e.mode==="plain"){const u=r.map((m,g)=>`<tr>${m.children.map(f=>{const x=this.tableCellContentToHtml(f,e),A=t.hasHeader&&g===0?"th":"td";return`<${A}${p(f)}>${x}</${A}>`}).join("")}</tr>`).join("");return`<table border="${i}" cellspacing="0" cellpadding="${a}">${u}</table>`}const o=e.index===0?0:this.resolveBlockSpacingPx(e.doc),c=["border-collapse: collapse",t.tableWidth?`width: ${this.formatPx(t.tableWidth)}`:"width: 100%",`margin: ${this.formatPx(o)} 0 ${this.formatPx(0)} 0`],h=r.map((u,m)=>{const g=t.hasHeader&&m===0;return`<tr>${u.children.map(f=>{const x=this.tableCellContentToHtml(f,e),A=g?"th":"td",$=[`border: ${i}px solid ${n}`,`padding: ${a}px`],b=s.byId.get(f.id);if(t.columnWidths&&b){let v=0;for(let y=b.col;y<b.col+b.colSpan;y++)v+=t.columnWidths[y]||0;v>0&&$.push(t.tableWidth?`width: ${this.formatPx(t.tableWidth*v/100)}`:`width: ${v}%`)}return f.verticalAlign&&$.push(`vertical-align: ${f.verticalAlign}`),f.backgroundColor?$.push(`background-color: ${f.backgroundColor}`):g&&$.push("background-color: #f9fafb"),g&&$.push("font-weight: 600"),`<${A}${p(f)} style="${$.join("; ")}">${x}</${A}>`}).join("")}</tr>`}).join(""),l=t.tableWidth?` width="${Math.round(t.tableWidth)}"`:"",d=t.tableWidth&&t.columnWidths?`<colgroup>${t.columnWidths.map(u=>`<col width="${Math.round(t.tableWidth*u/100)}">`).join("")}</colgroup>`:"";return`<table${l} style="${c.join("; ")}" data-block-type="table">${d}${h}</table>`}static tableCellContentToHtml(t,e){if(!t.children||t.children.length===0)return"";const r={...e,index:0,totalBlocks:t.children.length};return t.children.map((n,i)=>{const a={...r,index:i};return this.blockToHtml(n,a)}).join("")}static codeBlockToHtml(t,e){const r=t.content||"",n=t.language||"",i=ft(n);if(i&&t.renderDiagram!==!1&&i){const l=bt({protocol:i,source:r,theme:R(),maxWidth:900}),d=n?` data-language="${n}"`:"",u=e.index===0?0:this.resolveBlockSpacingPx(e.doc),m=["background: #ffffff","border: 1px solid #e0e0e0","border-radius: 4px","padding: 12px",`margin: ${this.formatPx(u)} 0 ${this.formatPx(0)} 0`,"text-align: center","overflow: hidden"].join("; ");return l?.svg?`<figure data-block-type="diagram"${d} style="${m}">${l.svg}</figure>`:`<figure data-block-type="diagram"${d} data-diagram-source="${this.escapeAttribute(r)}" data-diagram-protocol="${i}" style="${m}"><div style="color: var(--text-muted, #999); font-style: italic;">Loading diagram...</div></figure>`}const a=e.syntaxTheme||yt,s=n?xt(r,n,a):null;if(e.mode==="plain"){const l=this.escapeHtml(r);return`<pre${n?` data-language="${n}"`:""}><code>${l}</code></pre>`}const p=e.index===0?0:this.resolveBlockSpacingPx(e.doc),o=[`background-color: var(--revise-code-background, ${a.background})`,`color: var(--revise-code-text, ${a.default})`,"padding: 12px","border-radius: 4px","overflow-x: hidden","white-space: pre-wrap","overflow-wrap: anywhere","word-break: break-word",`margin: ${this.formatPx(p)} 0 ${this.formatPx(0)} 0`,"font-family: 'Source Code Pro', Monaco, Consolas, 'Courier New', monospace","font-size: 14px","line-height: 1.5"],c=n?` data-language="${n}"`:"",h="font-family: inherit; white-space: inherit; overflow-wrap: inherit; word-break: inherit";if(s&&s.length>0){const l=s.map(d=>{const u=this.escapeHtml(d.text);return`<span style="color: ${d.color}; font-family: inherit">${u}</span>`}).join("");return`<pre style="${o.join("; ")}"${c}><code style="${h}">${l}</code></pre>`}else{const l=this.escapeHtml(r);return`<pre style="${o.join("; ")}"${c}><code style="${h}">${l}</code></pre>`}}static mathBlockToHtml(t,e){const r=t.content||"",n=t.displayMode!=="inline",i=t.align||"center";let a;const s=z();if(s)try{a=s.renderToString(r,{displayMode:n,throwOnError:!1,errorColor:"#ef4444",trust:!1,strict:!1})}catch(o){const c=o instanceof Error?o.message:"LaTeX render error";a=`<span style="color: #ef4444;">${this.escapeHtml(c)}</span>`}else a=`<span data-latex-content="${this.escapeAttribute(r)}">${this.escapeHtml(r)}</span>`;if(e.mode==="plain")return`<div style="${i==="center"?"text-align: center;":i==="right"?"text-align: right;":""}" data-math-block="true">${a}</div>`;const p=e.index===0?0:this.resolveBlockSpacingPx(e.doc);return`<div style="${["background: #ffffff","border: 1px solid #e0e0e0","border-radius: 4px","padding: 12px",`margin: ${this.formatPx(p)} 0 ${this.formatPx(0)} 0`,`text-align: ${i}`].join("; ")}" data-block-type="math">${a}</div>`}static getListStyle(t,e,r){if(e.mode!=="styled")return"";const n=(X[t.variant]??X.unordered)+Math.max(0,r)*Tt,i=[];if(r===0){const s=this.resolveBlockMarginsPx(t,e);i.push(`margin: ${this.formatPx(s.top)} 0 ${this.formatPx(s.bottom)} 0`)}else i.push("margin: 0");i.push(`padding-left: ${this.formatPx(n)}`);const a=e.baseFontFamily;if(i.push(`font-size: ${this.formatPx(N.paragraph)}`),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],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==="◦"?"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]??N.paragraph}return N.paragraph}static getParagraphLineHeightMultiplier(t){return typeof t.lineSpacing=="number"&&Number.isFinite(t.lineSpacing)&&t.lineSpacing>0?t.lineSpacing:t.heading?E.heading:E.paragraph}static getListLineHeightMultiplier(t){return typeof t.lineSpacing=="number"&&Number.isFinite(t.lineSpacing)&&t.lineSpacing>0?t.lineSpacing:E.paragraph}static normalizeFontFamily(t){if(!t)return;const e=t.trim();if(!e)return;const r=nt(e),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){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?"32px":"48px";return[":root {"," color-scheme: light;","}","body {"," margin: 0;"," background: #f3f4f6;"," color: #111827;",` font-family: ${t.baseFontFamily};`,` font-size: ${this.formatPx(N.paragraph)};`,` line-height: ${this.formatNumber(E.paragraph)};`," display: flex;"," justify-content: center;"," padding: 48px 0;","}",".revise-document {"," background: #ffffff;",` width: ${e};`,` min-height: ${n};`,` padding: ${r};`," box-sizing: border-box;"," word-wrap: break-word;","}",".revise-document * {"," color: inherit;","}",`@media (max-width: ${_+j*2}px) {`," body {"," padding: 32px 0;"," }"," .revise-document {"," width: calc(100% - 32px);",` padding: ${i};`," }","}"].join(`
|
|
61
|
+
`)}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-left: auto");break;case"left":e.push("margin-right: auto");break}return e.join("; ")}static escapeHtml(t){const e={"&":"&","<":"<",">":">",'"':""","'":"'"};return t.replace(/[&<>"']/g,r=>e[r])}static escapeAttribute(t){return this.escapeHtml(t)}static sanitizeLinkHref(t){const e=t.trim();if(!e)return null;const r=e.toLowerCase();return r.startsWith("#")||r.startsWith("?")?e:e.startsWith("/")?e.startsWith("//")?null:e:e.startsWith("./")||e.startsWith("../")||r.startsWith("http://")||r.startsWith("https://")||r.startsWith("mailto:")||r.startsWith("tel:")?e:/^[a-z][a-z0-9+.-]*:/i.test(e)?null:e}static parseFontFamily(t){if(t)for(const e of t.split(",")){const r=e.replace(/['"]/g,"").trim().toLowerCase(),n=it.find(i=>i.cssValue.split(",")[0].replace(/['"]/g,"").trim().toLowerCase()===r);if(n)return n.cssValue.split(",")[0].trim()}}static getConsistentFontFamily(t){if(t.length===0)return;let e,r=!0;for(const n of t)if(n.type==="text"){const i=n.marks?.fontFamily;if(r)e=i,r=!1;else if(e!==i)return}return e}}export{wt as HtmlConverter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function c(e){let t=Math.max(1,e),r="";for(;t>0;)t-=1,r=String.fromCharCode(97+t%26)+r,t=Math.floor(t/26);return r}function u(e,t){let r=Math.max(1,e),n="";for(;r>0;)r-=1,n=t[r%t.length]+n,r=Math.floor(r/t.length);return n}function f(e,t){return String(e).replace(/\d/g,r=>t[Number(r)])}const g="〇一二三四五六七八九";function h(e){const t=Math.max(1,Math.floor(e));if(t>=1e4){const a=Math.floor(t/1e4),l=t%1e4;return`${h(a)}万${l?h(l):""}`}const r=["","十","百","千"];let n="",o=!1;for(let a=3;a>=0;a-=1){const l=10**a,s=Math.floor(t/l)%10;if(s===0){n&&t%l!==0&&(o=!0);continue}o&&(n+="〇"),s===1&&a===1&&n===""||(n+=g[s]),n+=r[a],o=!1}return n}const $=["أ","ب","ج","د","ه","و","ز","ح","ط","ي","ك","ل","م","ن","س","ع","ف","ص","ق","ر","ش","ت","ث","خ","ذ","ض","ظ","غ"],w=["א","ב","ג","ד","ה","ו","ז","ח","ט","י","כ","ל","מ","נ","ס","ע","פ","צ","ק","ר","ש","ת"],I=Array.from("あいうえおかきくけこさしすせそたちつてとなにぬねのはひふへほまみむめもやゆよらりるれろわをん"),A=Array.from("いろはにほへとちりぬるをわかよたれそつねならむうゐのおくやまけふこえてあさきゆめみしゑひもせす"),S=[[1e3,"m"],[900,"cm"],[500,"d"],[400,"cd"],[100,"c"],[90,"xc"],[50,"l"],[40,"xl"],[10,"x"],[9,"ix"],[5,"v"],[4,"iv"],[1,"i"]];function d(e){let t=Math.max(1,e),r="";for(const[n,o]of S)for(;t>=n;)r+=o,t-=n;return r||"i"}function M(e,t){const r=Math.max(1,t);switch((e||"decimal").trim()){case"lowerLetter":return c(r);case"upperLetter":return c(r).toUpperCase();case"lowerRoman":return d(r);case"upperRoman":return d(r).toUpperCase();case"decimalZero":return r<10?`0${r}`:String(r);case"arabicIndic":return f(r,"٠١٢٣٤٥٦٧٨٩");case"hindiNumbers":return f(r,"०१२३४५६७८९");case"thaiNumbers":return f(r,"๐๑๒๓๔๕๖๗๘๙");case"decimalFullWidth":return f(r,"0123456789");case"arabicAbjad":case"arabicAlpha":return u(r,$);case"hebrew1":case"hebrew2":return u(r,w);case"aiueo":return u(r,I);case"iroha":return u(r,A);case"chineseCounting":case"chineseCountingThousand":case"japaneseCounting":return h(r);case"ideographDigital":return String(r).replace(/\d/g,n=>g[Number(n)]);case"none":return"";default:return String(r)}}const v=new Map;function x(e){if(!e)return;if(v.has(e))return v.get(e);let t;try{const r=JSON.parse(e);t=Array.isArray(r)?r:void 0}catch{t=void 0}return v.set(e,t),t}function F(e,t,r){return t.replace(/%([1-9])/g,(n,o)=>{const a=parseInt(o,10)-1;return M(e[a]?.numFmt,r(a))})}function m(e,t,r,n){const o=r<=0?0:r===1?1:2;o===0?(e.level0=Math.max(e.level0+1,t),e.level1=0,e.level2=0):o===1?(e.level0<t&&(e.level0=t),e.level1+=1,e.level2=0):(e.level0<t&&(e.level0=t),e.level1===0&&(e.level1=1),e.level2+=1);const a=n?.[o];if(a?.lvlText){const l=s=>s===0?e.level0:s===1?e.level1:e.level2;return F(n,a.lvlText,l)}if(a?.numFmt){const l=o===0?e.level0:o===1?e.level1:e.level2;return`${M(a.numFmt,l)}.`}return o===0?`${e.level0}.`:o===1?`${e.level0} ${c(e.level1)}.`:`${e.level0} ${c(e.level1)} ${d(e.level2)}.`}function L(e,t){const r={...t.counters},n=x(e.numberingFormat);return e.children.map(o=>m(r,t.start,o.indentLevel??0,n))}function p(e){const t=e??1;return{counters:{level0:t-1,level1:0,level2:0},start:t}}function N(e){return b(e.children)}function b(e){const t=new Map,r=new Map,n=a=>{for(const l of a)if(l.type==="list")o(l);else if(l.type==="container"||l.type==="footnote")n(l.children);else if(l.type==="table")for(const s of l.children)for(const i of s.children)n(i.children)},o=a=>{if(a.variant!=="ordered")return;let l;const s=a.numberingChainId;if(s){const i=r.get(s);l=i&&a.startNumber===void 0?i:p(a.startNumber),r.set(s,l)}else l=p(a.startNumber);t.set(a.id,{counters:{...l.counters},start:l.start});for(const i of a.children)m(l.counters,l.start,i.indentLevel??0)};return n(e),t}function k(e){return Math.max(e.counters.level0+1,e.start)}const C=new WeakMap;function R(e){let t=C.get(e);return t||(t=N(e),C.set(e,t)),t}function y(e){return p(e.startNumber)}function T(e,t){for(let r=0;r<t.length;r++){const n=t[r];if(!(n.type!=="list"||n.variant!=="ordered"||n.numberingChainId||!n.startNumber||n.startNumber<=1))for(let o=r-1;o>=0;o--){const a=t[o];if(a.type!=="list")continue;if(a.variant!=="ordered")break;const l=b(t.slice(0,r)).get(a.id)??y(a),s={...l.counters};for(const i of a.children)m(s,l.start,i.indentLevel??0);if(Math.max(s.level0+1,l.start)===n.startNumber){const i=a.numberingChainId??(a.numberingChainId=e());n.numberingChainId=i,delete n.startNumber}break}}}export{N as a,b,k as e,T as i,m as n,L as o,x as p,R as r,y as s};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import{s as k,aP as y,a as b,aQ as $,aR as w,aS as M,aT as T,aU as I,k as u,aV as _}from"./backend-Cq-khfdG.js";import{b as j}from"./TableGrid-DVWaRZv0.js";import{a as C,e as v,i as N}from"./ListNumbering-Qlu6AuRZ.js";class L{static toMarkdown(e){if(!e||e.type!=="doc"||!e.children)return"";this.exportListNumbering=C(e);const n=[];for(const t of e.children){if(t.type==="header-footer"||t.type==="footnote")continue;if(t.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.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.footnoteRef,o.text??""),s(o.children))};s(e.children.filter(c=>c.type!=="footnote"));let a=t.size;for(const c of i){const o=t.get(c.id)||String(a+=1),r=[];c.children.forEach((h,l)=>{const d=this.blockToMarkdown(h)??"";l===0?r.push(`[^${o}]: ${d}`):r.push(d.split(`
|
|
2
|
+
`).map(p=>` ${p}`).join(`
|
|
3
|
+
`))}),n.push(r.join(`
|
|
4
|
+
|
|
5
|
+
`))}}return n.join(`
|
|
6
|
+
|
|
7
|
+
`)}static fromInlineMarkdown(e){return k(this.parseInlineContent(e))}static tocToMarkdown(e,n){const i=y(n,b(e));return i.length===0?null:i.map(t=>`${" ".repeat(t.level-1)}${t.text}`).join(`
|
|
8
|
+
`)}static blockToMarkdown(e){switch(e.type){case"paragraph":return $(e)?"---":this.paragraphToMarkdown(e);case"list":return this.listToMarkdown(e);case"table":return this.tableToMarkdown(e);case"image":return this.imageToMarkdown(e);case"code":return this.codeBlockToMarkdown(e);case"math":return this.mathBlockToMarkdown(e);case"placeholder":return null;default:return null}}static paragraphToMarkdown(e){const n=this.inlineNodesToMarkdown(e.children);return e.heading?`${"#".repeat(e.heading)} ${n}`:n}static inlineNodesToMarkdown(e){return this.coalesceMarkdownRuns(e).map(n=>this.textNodeToMarkdown(n)).join("")}static markdownMarksKey(e){const n=e.marks||{};return JSON.stringify([!!n.code,!!n.latex,!!n.bold,!!n.italic,!!n.strikethrough,n.link||null])}static coalesceMarkdownRuns(e){const n=[];let i=null;for(const t of e){const s=t.type==="text"&&!t.marks?.footnoteRef?this.markdownMarksKey(t):null,a=n[n.length-1];s!==null&&s===i&&a?n[n.length-1]={...a,text:a.text+t.text}:n.push(t),i=s}return n}static textNodeToMarkdown(e){if(e.marks?.footnoteRef)return`[^${e.text}]`;let n=e.text;return n=n.replace(/\\/g,"\\\\"),e.marks&&(e.marks.code?n=`\`${n.replace(/`/g,"\\`")}\``:e.marks.latex?n=`$${n}$`:(e.marks.bold&&(n=`**${n}**`),e.marks.italic&&(n=`*${n}*`),e.marks.strikethrough&&(n=`~~${n}~~`)),e.marks.link&&(n=`[${n}](${e.marks.link})`)),n}static listToMarkdown(e){const n=[],i=this.exportListNumbering?.get(e.id);let t=i?v(i):e.startNumber??1;for(const s of e.children){if(s.type!=="list-item")continue;const a=" ".repeat(s.indentLevel??0),c=this.inlineNodesToMarkdown(s.children);let o;e.variant==="ordered"?(o=`${t}.`,t++):e.variant==="todo"?o=s.checked?"- [x]":"- [ ]":o="-",n.push(`${a}${o} ${c}`)}return n.join(`
|
|
9
|
+
`)}static tableToMarkdown(e){if(!e.children||e.children.length===0)return"";const n=j(e),i=[];for(let t=0;t<n.rows;t++){const s=[];for(let a=0;a<n.cols;a++){const c=n.occupancy[t][a];if(!c||c.row!==t||c.col!==a){s.push("");continue}const o=c.cell.children.map(r=>r.type==="paragraph"?this.inlineNodesToMarkdown(r.children):r.type==="code"?`\`${r.content||""}\``:"").join(" ");s.push(o)}if(i.push(`| ${s.join(" | ")} |`),t===0){const a=s.map(()=>"---").join(" | ");i.push(`| ${a} |`)}}return i.join(`
|
|
10
|
+
`)}static imageToMarkdown(e){return``}static codeBlockToMarkdown(e){const n=e.language||"",i=e.content||"";return`\`\`\`${n}
|
|
11
|
+
${i}
|
|
12
|
+
\`\`\``}static mathBlockToMarkdown(e){return`$$
|
|
13
|
+
${e.content||""}
|
|
14
|
+
$$`}static fromMarkdown(e){const n=e.split(`
|
|
15
|
+
`),i=[];let t=0;for(;t<n.length;){const s=n[t];if(s.trim()===""){t++;continue}if(s.trim().startsWith("```")){const l=this.parseCodeBlock(n,t);i.push(l.block),t=l.nextIndex;continue}if(s.trim().startsWith("$$")){const l=this.parseMathBlock(n,t);i.push(l.block),t=l.nextIndex;continue}if(s.trim().startsWith("|")&&s.trim().endsWith("|")){const l=this.parseTable(n,t);l.block&&i.push(l.block),t=l.nextIndex;continue}const a=s.match(/^\[\^([^\]]+)\]:\s?(.*)$/);if(a){const l=a[1],d=[k(this.parseInlineContent(a[2]??""))];for(t++;t<n.length;){const p=n[t];if(p.trim()===""){const f=n[t+1];if(f!==void 0&&/^ {4}/.test(f)){t++;continue}break}if(!/^ {4}/.test(p))break;d.push(k(this.parseInlineContent(p.slice(4)))),t++}w(d),i.push({type:"footnote",id:`mdfn-${l}`,children:d,...M(l)==="endnote"?{noteKind:"endnote"}:{}});continue}const c=T(s,"markdown");if(c){i.push(I(_[c])),t++;continue}if(this.isListItem(s)){const l=this.parseList(n,t);i.push(l.block),t=l.nextIndex;continue}const o=s.trim().match(/^!\[([^\]]*)\]\(([^)]+)\)$/);if(o){i.push({type:"image",id:u(),src:o[2],alt:o[1],width:400,height:300}),t++;continue}const r=s.match(/^(#{1,6})\s+(.*)$/);if(r){const l=r[1].length,d=r[2],p=k(this.parseInlineContent(d));p.heading=l,i.push(p),t++;continue}const h=k(this.parseInlineContent(s));i.push(h),t++}return N(u,i),{type:"doc",children:i.length>0?i:[k()]}}static isListItem(e){const n=e.trimStart();return!!(/^[-*+]\s/.test(n)||/^\d+\.\s/.test(n)||/^[-*+]\s\[[x ]\]\s/i.test(n))}static parseList(e,n){const i=[];let t=n,s="unordered",a=1,c=!0;for(;t<e.length;){const o=e[t];if(o.trim()===""||!this.isListItem(o))break;const r=o.match(/^(\s*)/),h=r?r[1].length:0,l=h===0?0:Math.max(1,Math.floor(h/2)),d=o.trimStart();let p,f;const m=d.match(/^[-*+]\s\[([x ])\]\s(.*)$/i);if(m)c&&(s="todo"),f=m[1].toLowerCase()==="x",p=m[2];else if(/^\d+\.\s/.test(d)){const g=d.match(/^(\d+)\.\s(.*)$/);g?(c&&(s="ordered",a=parseInt(g[1],10)),p=g[2]):p=d}else{const g=d.match(/^[-*+]\s(.*)$/);p=g?g[1]:d}const x={type:"list-item",id:u(),children:this.parseInlineContent(p),indentLevel:l};f!==void 0&&(x.checked=f),i.push(x),c=!1,t++}return{block:{type:"list",id:u(),variant:s,children:i,startNumber:s==="ordered"?a:void 0},nextIndex:t}}static parseCodeBlock(e,n){const i=e[n].trim().slice(3).trim(),t=[];let s=n+1;for(;s<e.length;){const a=e[s];if(a.trim()==="```"){s++;break}t.push(a),s++}return{block:{type:"code",id:u(),content:t.join(`
|
|
16
|
+
`),language:i||void 0},nextIndex:s}}static parseMathBlock(e,n){const i=[];let t=n+1;for(;t<e.length;){const a=e[t];if(a.trim()==="$$"){t++;break}i.push(a),t++}const s=i.join(`
|
|
17
|
+
`).replace(/\\\\/g,"\\");return{block:{type:"math",id:u(),content:s},nextIndex:t}}static parseTable(e,n){const i=[];let t=n;for(;t<e.length;){const h=e[t].trim();if(!h.startsWith("|")||!h.endsWith("|"))break;i.push(h),t++}if(i.length<2)return{block:null,nextIndex:t};const s=i[1];if(!/^\|[\s\-:|]+\|$/.test(s))return{block:null,nextIndex:t};const a=[],c=!0;for(let h=0;h<i.length;h++){if(h===1)continue;const l=i[h].slice(1,-1).split("|").map(d=>d.trim()).map(d=>({type:"table-cell",id:u(),children:[k(this.parseInlineContent(d))]}));a.push({type:"table-row",id:u(),children:l})}const o=a[0]?.children.length||1,r=Array(o).fill(100/o);return{block:{type:"table",id:u(),children:a,columnWidths:r,hasHeader:c},nextIndex:t}}static parseInlineContent(e){const n=[],i=[{regex:/\[\^([^\]]+)\]/g,type:"footnoteref"},{regex:/!\[([^\]]*)\]\(([^)]+)\)/g,type:"image"},{regex:/\[([^\]]+)\]\(([^)]+)\)/g,type:"link"},{regex:/\*\*\*([^*]+)\*\*\*/g,type:"bolditalic"},{regex:/\*\*([^*]+)\*\*/g,type:"bold"},{regex:/\*([^*]+)\*/g,type:"italic"},{regex:/(^|[^A-Za-z0-9_])___([^_]+)___(?![A-Za-z0-9_])/g,type:"bolditalic",underscore:!0},{regex:/(^|[^A-Za-z0-9_])__([^_]+)__(?![A-Za-z0-9_])/g,type:"bold",underscore:!0},{regex:/(^|[^A-Za-z0-9_])_([^_]+)_(?![A-Za-z0-9_])/g,type:"italic",underscore:!0},{regex:/~~([^~]+)~~/g,type:"strikethrough"},{regex:/`([^`]+)`/g,type:"code"},{regex:/\$([^$]+)\$/g,type:"latex"}],t=[];for(const o of i){o.regex.lastIndex=0;let r;for(;(r=o.regex.exec(e))!==null;)if(o.type==="link")t.push({index:r.index,length:r[0].length,type:o.type,content:r[1],url:r[2]});else if(o.type==="image")t.push({index:r.index,length:r[0].length,type:o.type,content:r[1]||"[image]",url:r[2]});else if(o.type==="bolditalic"||o.type==="bold"||o.type==="italic")if("underscore"in o&&o.underscore){const h=r[1];t.push({index:r.index+h.length,length:r[0].length-h.length,type:o.type,content:r[2]})}else t.push({index:r.index,length:r[0].length,type:o.type,content:r[1]});else t.push({index:r.index,length:r[0].length,type:o.type,content:r[1]})}t.sort((o,r)=>o.index-r.index);const s=[];let a=0;for(const o of t)o.index>=a&&(s.push(o),a=o.index+o.length);let c=0;for(const o of s){if(o.index>c){const h=e.slice(c,o.index);h&&n.push({type:"text",text:h,marks:{}})}const r={type:"text",text:o.content,marks:{}};switch(o.type){case"bold":r.marks={bold:!0};break;case"italic":r.marks={italic:!0};break;case"bolditalic":r.marks={bold:!0,italic:!0};break;case"strikethrough":r.marks={strikethrough:!0};break;case"code":r.marks={code:!0};break;case"latex":r.text=o.content.replace(/\\\\/g,"\\"),r.marks={latex:!0};break;case"link":r.marks={link:o.url};break;case"image":r.text=o.content||"[image]",r.marks={link:o.url};break;case"footnoteref":r.text=o.content,r.marks={footnoteRef:`mdfn-${o.content}`,superscript:!0};break}n.push(r),c=o.index+o.length}if(c<e.length){const o=e.slice(c);o&&n.push({type:"text",text:o,marks:{}})}return n.length===0&&n.push({type:"text",text:e,marks:{}}),n}}export{L as MarkdownConverter};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const L="https://revise.io";let W=L;const P=new Set;function r(e){return`${W}/${e.replace(/^\/+/,"")}`}function E(e){P.add(e)}let y=null,T=null;async function M(){return y||(T||(T=import("./katex-DWj8TvwO.js").then(e=>(y=e.default,e.default))),T)}function $(){return y}let p=null,_=null;async function z(){return p||(_||(_=import("./bundle.min-DRpfgV69.js").then(e=>e.b).then(e=>(p=e.MathMLToLaTeX,e.MathMLToLaTeX))),_)}function H(){return p}function I(e){return/<math[\s>]/i.test(e)}const u=new Map,c=new Map,f=new Map,j=new Set;let K=!1;function A(){K||(K=!0,requestAnimationFrame(()=>{K=!1;for(const[e,t]of f)u.set(e,t),c.delete(e);f.clear();for(const e of j)try{e()}catch(t){console.error("Math render callback error:",t)}}))}function X(e,t,n){return`${t?"block":"inline"}:${n}:${e}`}const h="#000000";function x(e,t=!0,n=h){if(!e||e.trim()==="")return{image:null,width:100,height:40,contentWidth:80,contentHeight:20,loading:!1,error:void 0};const a=X(e,t,n),i=u.get(a);if(i)return i;if(!c.has(a)){const l=N(e,t,n);c.set(a,l),l.then(o=>{f.set(a,o),A()}).catch(o=>{const s={image:null,width:100,height:40,contentWidth:80,contentHeight:20,loading:!1,error:o instanceof Error?o.message:"Render failed"};f.set(a,s),A()})}return{image:null,width:200,height:t?80:60,contentWidth:180,contentHeight:t?60:40,loading:!0}}function k(e,t,n=h){const a=X(e,t,n),i=u.get(a)||f.get(a);return!i||!i.svg?null:{svg:i.svg,width:i.width,height:i.height,contentWidth:i.contentWidth,contentHeight:i.contentHeight}}async function C(e,t,n=h){const a=X(e,t,n);if(!(u.has(a)||f.has(a))){if(c.has(a)){await c.get(a);return}if(x(e,t,n).loading){const i=c.get(a);i&&await i}}}function q(e){if(!e.includes(`
|
|
2
|
+
`)||["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(`
|
|
3
|
+
`).map(n=>n.trim()).filter(n=>n.length>0);return t.length<=1?e:`\\begin{gathered}
|
|
4
|
+
${t.join(` \\\\
|
|
5
|
+
`)}
|
|
6
|
+
\\end{gathered}`}async function N(e,t,n=h){try{const a=q(e),i=(await M()).renderToString(a,{displayMode:t,throwOnError:!1,errorColor:"#ef4444",trust:!1,strict:!1}),{width:l,height:o,contentWidth:s,contentHeight:g}=await B(i),w=await V(),m=J(i,l,o,w,n);return{image:await Q(m,l,o),width:l,height:o,contentWidth:s,contentHeight:g,loading:!1,svg:m}}catch(a){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 d=10,F=.85;let S=null;async function O(){return S||(S=(async()=>{const e=["16px 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"];try{await Promise.all(e.map(t=>document.fonts.load(t).catch(()=>{}))),await document.fonts.ready,await new Promise(t=>requestAnimationFrame(t))}catch{}})(),S)}async function B(e){G(),await O();const t=document.createElement("div");return t.style.cssText=`
|
|
7
|
+
position: absolute;
|
|
8
|
+
visibility: hidden;
|
|
9
|
+
pointer-events: none;
|
|
10
|
+
top: -9999px;
|
|
11
|
+
left: -9999px;
|
|
12
|
+
font-size: 16px;
|
|
13
|
+
line-height: 1.2;
|
|
14
|
+
font-family: KaTeX_Main, 'Times New Roman', serif;
|
|
15
|
+
`,t.innerHTML=e,document.body.appendChild(t),await document.fonts.ready,new Promise(n=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{const a=t.querySelector(".katex")||t,i=a.getBoundingClientRect(),l=a.scrollWidth,o=a.scrollHeight,s=Math.ceil(Math.max(i.width,l)),g=Math.ceil(Math.max(i.height,o)),w=s+d*2,m=g+d*2;document.body.removeChild(t),n({width:Math.max(w,20),height:Math.max(m,20),contentWidth:Math.max(s,10),contentHeight:Math.max(g,10)})})})})}let b=!1,v=null;const R=new Map;async function D(e){if(R.has(e))return R.get(e);const t=(async()=>{try{const n=await(await fetch(e)).blob();return new Promise((a,i)=>{const l=new FileReader;l.onload=()=>{a(l.result)},l.onerror=i,l.readAsDataURL(n)})}catch(n){return console.warn(`Failed to load font: ${e}`,n),""}})();return R.set(e,t),t}async function U(){const e=[{family:"KaTeX_Main",weight:"normal",style:"normal",file:r("fonts/KaTeX_Main-Regular.woff2")},{family:"KaTeX_Main",weight:"bold",style:"normal",file:r("fonts/KaTeX_Main-Bold.woff2")},{family:"KaTeX_Main",weight:"normal",style:"italic",file:r("fonts/KaTeX_Main-Italic.woff2")},{family:"KaTeX_Math",weight:"normal",style:"italic",file:r("fonts/KaTeX_Math-Italic.woff2")},{family:"KaTeX_Size1",weight:"normal",style:"normal",file:r("fonts/KaTeX_Size1-Regular.woff2")},{family:"KaTeX_Size2",weight:"normal",style:"normal",file:r("fonts/KaTeX_Size2-Regular.woff2")},{family:"KaTeX_Size3",weight:"normal",style:"normal",file:r("fonts/KaTeX_Size3-Regular.woff2")},{family:"KaTeX_Size4",weight:"normal",style:"normal",file:r("fonts/KaTeX_Size4-Regular.woff2")},{family:"KaTeX_AMS",weight:"normal",style:"normal",file:r("fonts/KaTeX_AMS-Regular.woff2")},{family:"KaTeX_Caligraphic",weight:"normal",style:"normal",file:r("fonts/KaTeX_Caligraphic-Regular.woff2")},{family:"KaTeX_Fraktur",weight:"normal",style:"normal",file:r("fonts/KaTeX_Fraktur-Regular.woff2")},{family:"KaTeX_SansSerif",weight:"normal",style:"normal",file:r("fonts/KaTeX_SansSerif-Regular.woff2")},{family:"KaTeX_Script",weight:"normal",style:"normal",file:r("fonts/KaTeX_Script-Regular.woff2")},{family:"KaTeX_Typewriter",weight:"normal",style:"normal",file:r("fonts/KaTeX_Typewriter-Regular.woff2")}];return(await Promise.all(e.map(async t=>{const n=await D(t.file);return n?`@font-face {
|
|
16
|
+
font-family: '${t.family}';
|
|
17
|
+
font-weight: ${t.weight};
|
|
18
|
+
font-style: ${t.style};
|
|
19
|
+
src: url('${n}') format('woff2');
|
|
20
|
+
}`:""}))).filter(Boolean).join(`
|
|
21
|
+
`)}function G(){if(b)return;if(document.querySelector('link[href*="katex"]')){b=!0;return}const e=document.createElement("link");e.rel="stylesheet",e.href=r("katex.min.css"),document.head.appendChild(e),b=!0}async function V(){return v||(v=(async()=>{try{const[e,t]=await Promise.all([fetch(r("katex.min.css")),U()]);let n=await e.text();return n=n.replace(/@font-face\s*\{[^}]*\}/g,""),t+`
|
|
22
|
+
`+n}catch(e){return console.warn("Failed to fetch KaTeX CSS:",e),""}})(),v)}function J(e,t,n,a,i=h){return`<svg xmlns="http://www.w3.org/2000/svg" width="${t}" height="${n}" style="overflow: visible;">
|
|
23
|
+
<defs>
|
|
24
|
+
<style type="text/css">
|
|
25
|
+
${a}
|
|
26
|
+
</style>
|
|
27
|
+
</defs>
|
|
28
|
+
<foreignObject width="100%" height="100%" style="overflow: visible;">
|
|
29
|
+
<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, 'Times New Roman', serif; overflow: visible; box-sizing: border-box; color: ${i};">
|
|
30
|
+
${e}
|
|
31
|
+
</div>
|
|
32
|
+
</foreignObject>
|
|
33
|
+
</svg>`}function Q(e,t,n){return new Promise((a,i)=>{const l="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("Failed to load math SVG as image"))},o.src=l})}const Z=Object.freeze(Object.defineProperty({__proto__:null,INLINE_MATH_SCALE:F,MATH_PADDING:d,ensureMathRendered:C,getCachedMathSvg:k,getKatexSync:$,getMathMlToLatexSync:H,getMathRender:x,htmlHasMathMl:I,loadKatex:M,loadMathMlToLatex:z},Symbol.toStringTag,{value:"Module"}));export{F as I,d as M,M as a,$ as b,k as c,x as d,C as e,Z as f,H as g,z as l,E as o,r};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{T as b,$ as p,_ as E}from"./index-F-kHIwWT.js";class I{static async parseFile(n){const o=(await import("./index-F-kHIwWT.js").then(a=>a.j)).default,t=await n.arrayBuffer(),e=await o.loadAsync(t),c=e.file("content.xml");if(!c)throw new Error("Invalid ODT file: missing content.xml");const f=await c.async("text"),i=await e.file("styles.xml")?.async("text");return this.fromContentXml(f,i)}static fromContentXml(n,o){const t=new DOMParser,e=t.parseFromString(n,"application/xml"),c=o?t.parseFromString(o,"application/xml"):null,f=new Map,i=new Set;for(const l of[c,e])l&&C(l,f,i);const a=N(e.documentElement,"text"),s=[];if(a)for(const l of m(a))s.push(...g(l,f,i));return s.length===0&&s.push(b()),{type:"doc",children:s}}}function C(r,n,o){for(const t of O(r.documentElement,"style")){const e=u(t,"name");if(!e)continue;const c={},f=N(t,"text-properties");if(f){const s=u(f,"font-weight")||u(f,"font-weight-asian");(s==="bold"||s&&parseInt(s,10)>=600)&&(c.bold=!0);const l=u(f,"font-style")||u(f,"font-style-asian");(l==="italic"||l==="oblique")&&(c.italic=!0);const h=u(f,"text-underline-style");h&&h!=="none"&&(c.underline=!0);const d=u(f,"text-line-through-style");d&&d!=="none"&&(c.strikethrough=!0)}let i;const a=N(t,"paragraph-properties");if(a){const s={},l=M(u(a,"border"));for(const h of["top","bottom","left","right"]){const d=M(u(a,`border-${h}`))??l;d&&(s[h]=d)}Object.keys(s).length>0&&(i=JSON.stringify(s))}n.set(e,{marks:c,parentName:u(t,"parent-style-name")||void 0,...i?{bordersJson:i}:{}})}for(const t of O(r.documentElement,"list-style")){const e=u(t,"name");if(e){for(const c of m(t))if(c.localName==="list-level-style-number"){o.add(e);break}}}}function v(r,n){const o={};let t=r,e=0;const c=[];for(;t&&e<8;){const f=n.get(t);if(!f)break;c.push(f),t=f.parentName??null,e++}for(const f of c.reverse())Object.assign(o,f.marks);return o}function D(r,n){let o=r,t=0;for(;o&&t<8;){const e=n.get(o);if(!e)return;if(e.bordersJson)return e.bordersJson;o=e.parentName??null,t++}}function M(r){if(!r)return null;const n=r.trim().toLowerCase();if(!n||n==="none"||n==="hidden")return null;const o=n.match(/\b(solid|dashed|dotted|double)\b/),t=o?o[1]==="solid"?"single":o[1]:"single",e=n.match(/([\d.]+)\s*(pt|px|cm|mm|in)/);let c=1;if(e){const i=parseFloat(e[1]),a=e[2]==="px"?i:e[2]==="pt"?i*4/3:e[2]==="cm"?i*37.8:e[2]==="mm"?i*3.78:i*96;c=Math.min(8,Math.max(1,Math.round(a)))}const f=n.match(/#[0-9a-f]{3,8}/);return{style:t,width:c,color:f?f[0]:"#000000"}}function g(r,n,o){switch(r.localName){case"h":{const t=parseInt(u(r,"outline-level")||"1",10),e=b(w(r,{},n));return e.heading=Math.min(Math.max(t,1),6),[e]}case"p":{const t=b(w(r,{},n)),e=D(u(r,"style-name"),n);return e&&(t.borders=e),[t]}case"list":{const t=F(r,n,o);return t?[t]:[]}case"table":{const t=J(r,n,o);return t?[t]:[]}case"section":{const t=[];for(const e of m(r))t.push(...g(e,n,o));return t}default:return[]}}function F(r,n,o,t=0){const e=u(r,"style-name"),c=[],f=(i,a)=>{for(const s of m(i))if(!(s.localName!=="list-item"&&s.localName!=="list-header"))for(const l of m(s))l.localName==="p"||l.localName==="h"?c.push({type:"list-item",id:p(),children:w(l,{},n),...a>0?{indentLevel:a}:{}}):l.localName==="list"&&f(l,a+1)};return f(r,t),c.length===0?null:{type:"list",id:p(),variant:e&&o.has(e)?"ordered":"unordered",children:c}}function J(r,n,o){const t=[];let e=0;const c=[];for(const a of m(r))if(a.localName==="table-row")c.push(a);else if(a.localName==="table-header-rows"||a.localName==="table-rows")for(const s of m(a))s.localName==="table-row"&&c.push(s);for(const a of c){const s=[];for(const l of m(a)){if(l.localName==="covered-table-cell"||l.localName!=="table-cell")continue;const h=[];for(const y of m(l))h.push(...g(y,n,o));const d={type:"table-cell",id:p(),children:h.length>0?h:[b()]},x=T(u(l,"number-columns-spanned")),k=T(u(l,"number-rows-spanned"));x>1&&(d.colSpan=x),k>1&&(d.rowSpan=k),s.push(d);const S=parseInt(u(l,"number-columns-repeated")||"1",10)-1;for(let y=0;y<S&&y<20;y++)s.push({type:"table-cell",id:p(),children:[b()]})}s.length>0&&t.push({type:"table-row",id:p(),children:s})}if(t.length===0)return null;const f={children:t,columnWidths:[]};let i=E(f);if(e=i.cols,e===0)return null;for(let a=0;a<t.length;a++){let s=0;for(let l=0;l<i.cols;l++)i.occupancy[a][l]||s++;if(s>0){for(let l=0;l<s;l++)t[a].children.push({type:"table-cell",id:p(),children:[b()]});i=E(f)}}return{type:"table",id:p(),children:t,columnWidths:Array(e).fill(100/e),hasHeader:r.getElementsByTagName("table:table-header-rows").length>0}}function T(r){const n=parseInt(r||"1",10);return Number.isFinite(n)?Math.min(Math.max(1,n),1e3):1}function w(r,n,o){const t=[],e=(i,a)=>{if(!i)return;const s=t[t.length-1];s&&A(s.marks??{},a)?s.text+=i:t.push({type:"text",text:i,marks:{...a}})},c=(i,a)=>{if(i.nodeType===Node.TEXT_NODE){e(i.textContent??"",a);return}if(i.nodeType!==Node.ELEMENT_NODE)return;const s=i;switch(s.localName){case"span":{const l=v(u(s,"style-name"),o),h={...a,...l};s.childNodes.forEach(d=>c(d,h));break}case"a":{const l=s.getAttributeNS("http://www.w3.org/1999/xlink","href")||s.getAttribute("xlink:href")||void 0,h=l?{...a,link:l}:a;s.childNodes.forEach(d=>c(d,h));break}case"s":{const l=parseInt(u(s,"c")||"1",10);e(" ".repeat(Math.min(l,100)),a);break}case"tab":e(" ",a);break;case"line-break":e(" ",a);break;case"note":case"annotation":break;default:s.childNodes.forEach(l=>c(l,a));break}},f={...n,...v(u(r,"style-name"),o)};return r.childNodes.forEach(i=>c(i,f)),t.length===0&&t.push({type:"text",text:"",marks:{}}),t}function A(r,n){return["bold","italic","underline","strikethrough","link"].every(o=>(r[o]??void 0)===(n[o]??void 0))}function m(r){const n=[];return r.childNodes.forEach(o=>{o.nodeType===Node.ELEMENT_NODE&&n.push(o)}),n}function N(r,n){if(r.localName===n)return r;for(const o of m(r)){const t=N(o,n);if(t)return t}return null}function O(r,n){const o=[],t=e=>{e.localName===n&&o.push(e);for(const c of m(e))t(c)};return t(r),o}function u(r,n){const o=r.attributes;for(let t=0;t<o.length;t++)if(o[t].localName===n)return o[t].value;return null}export{I as OdtConverter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{T as b,$ as p,_ as E}from"./index-CLw_BlSL.js";class I{static async parseFile(n){const o=(await import("./index-CLw_BlSL.js").then(a=>a.j)).default,t=await n.arrayBuffer(),e=await o.loadAsync(t),c=e.file("content.xml");if(!c)throw new Error("Invalid ODT file: missing content.xml");const f=await c.async("text"),i=await e.file("styles.xml")?.async("text");return this.fromContentXml(f,i)}static fromContentXml(n,o){const t=new DOMParser,e=t.parseFromString(n,"application/xml"),c=o?t.parseFromString(o,"application/xml"):null,f=new Map,i=new Set;for(const l of[c,e])l&&C(l,f,i);const a=N(e.documentElement,"text"),s=[];if(a)for(const l of m(a))s.push(...g(l,f,i));return s.length===0&&s.push(b()),{type:"doc",children:s}}}function C(r,n,o){for(const t of O(r.documentElement,"style")){const e=u(t,"name");if(!e)continue;const c={},f=N(t,"text-properties");if(f){const s=u(f,"font-weight")||u(f,"font-weight-asian");(s==="bold"||s&&parseInt(s,10)>=600)&&(c.bold=!0);const l=u(f,"font-style")||u(f,"font-style-asian");(l==="italic"||l==="oblique")&&(c.italic=!0);const h=u(f,"text-underline-style");h&&h!=="none"&&(c.underline=!0);const d=u(f,"text-line-through-style");d&&d!=="none"&&(c.strikethrough=!0)}let i;const a=N(t,"paragraph-properties");if(a){const s={},l=M(u(a,"border"));for(const h of["top","bottom","left","right"]){const d=M(u(a,`border-${h}`))??l;d&&(s[h]=d)}Object.keys(s).length>0&&(i=JSON.stringify(s))}n.set(e,{marks:c,parentName:u(t,"parent-style-name")||void 0,...i?{bordersJson:i}:{}})}for(const t of O(r.documentElement,"list-style")){const e=u(t,"name");if(e){for(const c of m(t))if(c.localName==="list-level-style-number"){o.add(e);break}}}}function v(r,n){const o={};let t=r,e=0;const c=[];for(;t&&e<8;){const f=n.get(t);if(!f)break;c.push(f),t=f.parentName??null,e++}for(const f of c.reverse())Object.assign(o,f.marks);return o}function D(r,n){let o=r,t=0;for(;o&&t<8;){const e=n.get(o);if(!e)return;if(e.bordersJson)return e.bordersJson;o=e.parentName??null,t++}}function M(r){if(!r)return null;const n=r.trim().toLowerCase();if(!n||n==="none"||n==="hidden")return null;const o=n.match(/\b(solid|dashed|dotted|double)\b/),t=o?o[1]==="solid"?"single":o[1]:"single",e=n.match(/([\d.]+)\s*(pt|px|cm|mm|in)/);let c=1;if(e){const i=parseFloat(e[1]),a=e[2]==="px"?i:e[2]==="pt"?i*4/3:e[2]==="cm"?i*37.8:e[2]==="mm"?i*3.78:i*96;c=Math.min(8,Math.max(1,Math.round(a)))}const f=n.match(/#[0-9a-f]{3,8}/);return{style:t,width:c,color:f?f[0]:"#000000"}}function g(r,n,o){switch(r.localName){case"h":{const t=parseInt(u(r,"outline-level")||"1",10),e=b(w(r,{},n));return e.heading=Math.min(Math.max(t,1),6),[e]}case"p":{const t=b(w(r,{},n)),e=D(u(r,"style-name"),n);return e&&(t.borders=e),[t]}case"list":{const t=F(r,n,o);return t?[t]:[]}case"table":{const t=J(r,n,o);return t?[t]:[]}case"section":{const t=[];for(const e of m(r))t.push(...g(e,n,o));return t}default:return[]}}function F(r,n,o,t=0){const e=u(r,"style-name"),c=[],f=(i,a)=>{for(const s of m(i))if(!(s.localName!=="list-item"&&s.localName!=="list-header"))for(const l of m(s))l.localName==="p"||l.localName==="h"?c.push({type:"list-item",id:p(),children:w(l,{},n),...a>0?{indentLevel:a}:{}}):l.localName==="list"&&f(l,a+1)};return f(r,t),c.length===0?null:{type:"list",id:p(),variant:e&&o.has(e)?"ordered":"unordered",children:c}}function J(r,n,o){const t=[];let e=0;const c=[];for(const a of m(r))if(a.localName==="table-row")c.push(a);else if(a.localName==="table-header-rows"||a.localName==="table-rows")for(const s of m(a))s.localName==="table-row"&&c.push(s);for(const a of c){const s=[];for(const l of m(a)){if(l.localName==="covered-table-cell"||l.localName!=="table-cell")continue;const h=[];for(const y of m(l))h.push(...g(y,n,o));const d={type:"table-cell",id:p(),children:h.length>0?h:[b()]},x=T(u(l,"number-columns-spanned")),k=T(u(l,"number-rows-spanned"));x>1&&(d.colSpan=x),k>1&&(d.rowSpan=k),s.push(d);const S=parseInt(u(l,"number-columns-repeated")||"1",10)-1;for(let y=0;y<S&&y<20;y++)s.push({type:"table-cell",id:p(),children:[b()]})}s.length>0&&t.push({type:"table-row",id:p(),children:s})}if(t.length===0)return null;const f={children:t,columnWidths:[]};let i=E(f);if(e=i.cols,e===0)return null;for(let a=0;a<t.length;a++){let s=0;for(let l=0;l<i.cols;l++)i.occupancy[a][l]||s++;if(s>0){for(let l=0;l<s;l++)t[a].children.push({type:"table-cell",id:p(),children:[b()]});i=E(f)}}return{type:"table",id:p(),children:t,columnWidths:Array(e).fill(100/e),hasHeader:r.getElementsByTagName("table:table-header-rows").length>0}}function T(r){const n=parseInt(r||"1",10);return Number.isFinite(n)?Math.min(Math.max(1,n),1e3):1}function w(r,n,o){const t=[],e=(i,a)=>{if(!i)return;const s=t[t.length-1];s&&A(s.marks??{},a)?s.text+=i:t.push({type:"text",text:i,marks:{...a}})},c=(i,a)=>{if(i.nodeType===Node.TEXT_NODE){e(i.textContent??"",a);return}if(i.nodeType!==Node.ELEMENT_NODE)return;const s=i;switch(s.localName){case"span":{const l=v(u(s,"style-name"),o),h={...a,...l};s.childNodes.forEach(d=>c(d,h));break}case"a":{const l=s.getAttributeNS("http://www.w3.org/1999/xlink","href")||s.getAttribute("xlink:href")||void 0,h=l?{...a,link:l}:a;s.childNodes.forEach(d=>c(d,h));break}case"s":{const l=parseInt(u(s,"c")||"1",10);e(" ".repeat(Math.min(l,100)),a);break}case"tab":e(" ",a);break;case"line-break":e(" ",a);break;case"note":case"annotation":break;default:s.childNodes.forEach(l=>c(l,a));break}},f={...n,...v(u(r,"style-name"),o)};return r.childNodes.forEach(i=>c(i,f)),t.length===0&&t.push({type:"text",text:"",marks:{}}),t}function A(r,n){return["bold","italic","underline","strikethrough","link"].every(o=>(r[o]??void 0)===(n[o]??void 0))}function m(r){const n=[];return r.childNodes.forEach(o=>{o.nodeType===Node.ELEMENT_NODE&&n.push(o)}),n}function N(r,n){if(r.localName===n)return r;for(const o of m(r)){const t=N(o,n);if(t)return t}return null}function O(r,n){const o=[],t=e=>{e.localName===n&&o.push(e);for(const c of m(e))t(c)};return t(r),o}function u(r,n){const o=r.attributes;for(let t=0;t<o.length;t++)if(o[t].localName===n)return o[t].value;return null}export{I as OdtConverter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{s as b,k as p}from"./backend-Cq-khfdG.js";import{b as E}from"./TableGrid-DVWaRZv0.js";class I{static async parseFile(n){const o=(await import("./jszip.min-CPW0h1Kx.js").then(a=>a.j)).default,t=await n.arrayBuffer(),e=await o.loadAsync(t),c=e.file("content.xml");if(!c)throw new Error("Invalid ODT file: missing content.xml");const f=await c.async("text"),i=await e.file("styles.xml")?.async("text");return this.fromContentXml(f,i)}static fromContentXml(n,o){const t=new DOMParser,e=t.parseFromString(n,"application/xml"),c=o?t.parseFromString(o,"application/xml"):null,f=new Map,i=new Set;for(const l of[c,e])l&&C(l,f,i);const a=N(e.documentElement,"text"),s=[];if(a)for(const l of m(a))s.push(...g(l,f,i));return s.length===0&&s.push(b()),{type:"doc",children:s}}}function C(r,n,o){for(const t of T(r.documentElement,"style")){const e=u(t,"name");if(!e)continue;const c={},f=N(t,"text-properties");if(f){const s=u(f,"font-weight")||u(f,"font-weight-asian");(s==="bold"||s&&parseInt(s,10)>=600)&&(c.bold=!0);const l=u(f,"font-style")||u(f,"font-style-asian");(l==="italic"||l==="oblique")&&(c.italic=!0);const h=u(f,"text-underline-style");h&&h!=="none"&&(c.underline=!0);const d=u(f,"text-line-through-style");d&&d!=="none"&&(c.strikethrough=!0)}let i;const a=N(t,"paragraph-properties");if(a){const s={},l=M(u(a,"border"));for(const h of["top","bottom","left","right"]){const d=M(u(a,`border-${h}`))??l;d&&(s[h]=d)}Object.keys(s).length>0&&(i=JSON.stringify(s))}n.set(e,{marks:c,parentName:u(t,"parent-style-name")||void 0,...i?{bordersJson:i}:{}})}for(const t of T(r.documentElement,"list-style")){const e=u(t,"name");if(e){for(const c of m(t))if(c.localName==="list-level-style-number"){o.add(e);break}}}}function v(r,n){const o={};let t=r,e=0;const c=[];for(;t&&e<8;){const f=n.get(t);if(!f)break;c.push(f),t=f.parentName??null,e++}for(const f of c.reverse())Object.assign(o,f.marks);return o}function D(r,n){let o=r,t=0;for(;o&&t<8;){const e=n.get(o);if(!e)return;if(e.bordersJson)return e.bordersJson;o=e.parentName??null,t++}}function M(r){if(!r)return null;const n=r.trim().toLowerCase();if(!n||n==="none"||n==="hidden")return null;const o=n.match(/\b(solid|dashed|dotted|double)\b/),t=o?o[1]==="solid"?"single":o[1]:"single",e=n.match(/([\d.]+)\s*(pt|px|cm|mm|in)/);let c=1;if(e){const i=parseFloat(e[1]),a=e[2]==="px"?i:e[2]==="pt"?i*4/3:e[2]==="cm"?i*37.8:e[2]==="mm"?i*3.78:i*96;c=Math.min(8,Math.max(1,Math.round(a)))}const f=n.match(/#[0-9a-f]{3,8}/);return{style:t,width:c,color:f?f[0]:"#000000"}}function g(r,n,o){switch(r.localName){case"h":{const t=parseInt(u(r,"outline-level")||"1",10),e=b(w(r,{},n));return e.heading=Math.min(Math.max(t,1),6),[e]}case"p":{const t=b(w(r,{},n)),e=D(u(r,"style-name"),n);return e&&(t.borders=e),[t]}case"list":{const t=F(r,n,o);return t?[t]:[]}case"table":{const t=L(r,n,o);return t?[t]:[]}case"section":{const t=[];for(const e of m(r))t.push(...g(e,n,o));return t}default:return[]}}function F(r,n,o,t=0){const e=u(r,"style-name"),c=[],f=(i,a)=>{for(const s of m(i))if(!(s.localName!=="list-item"&&s.localName!=="list-header"))for(const l of m(s))l.localName==="p"||l.localName==="h"?c.push({type:"list-item",id:p(),children:w(l,{},n),...a>0?{indentLevel:a}:{}}):l.localName==="list"&&f(l,a+1)};return f(r,t),c.length===0?null:{type:"list",id:p(),variant:e&&o.has(e)?"ordered":"unordered",children:c}}function L(r,n,o){const t=[];let e=0;const c=[];for(const a of m(r))if(a.localName==="table-row")c.push(a);else if(a.localName==="table-header-rows"||a.localName==="table-rows")for(const s of m(a))s.localName==="table-row"&&c.push(s);for(const a of c){const s=[];for(const l of m(a)){if(l.localName==="covered-table-cell"||l.localName!=="table-cell")continue;const h=[];for(const y of m(l))h.push(...g(y,n,o));const d={type:"table-cell",id:p(),children:h.length>0?h:[b()]},x=O(u(l,"number-columns-spanned")),k=O(u(l,"number-rows-spanned"));x>1&&(d.colSpan=x),k>1&&(d.rowSpan=k),s.push(d);const S=parseInt(u(l,"number-columns-repeated")||"1",10)-1;for(let y=0;y<S&&y<20;y++)s.push({type:"table-cell",id:p(),children:[b()]})}s.length>0&&t.push({type:"table-row",id:p(),children:s})}if(t.length===0)return null;const f={children:t,columnWidths:[]};let i=E(f);if(e=i.cols,e===0)return null;for(let a=0;a<t.length;a++){let s=0;for(let l=0;l<i.cols;l++)i.occupancy[a][l]||s++;if(s>0){for(let l=0;l<s;l++)t[a].children.push({type:"table-cell",id:p(),children:[b()]});i=E(f)}}return{type:"table",id:p(),children:t,columnWidths:Array(e).fill(100/e),hasHeader:r.getElementsByTagName("table:table-header-rows").length>0}}function O(r){const n=parseInt(r||"1",10);return Number.isFinite(n)?Math.min(Math.max(1,n),1e3):1}function w(r,n,o){const t=[],e=(i,a)=>{if(!i)return;const s=t[t.length-1];s&&A(s.marks??{},a)?s.text+=i:t.push({type:"text",text:i,marks:{...a}})},c=(i,a)=>{if(i.nodeType===Node.TEXT_NODE){e(i.textContent??"",a);return}if(i.nodeType!==Node.ELEMENT_NODE)return;const s=i;switch(s.localName){case"span":{const l=v(u(s,"style-name"),o),h={...a,...l};s.childNodes.forEach(d=>c(d,h));break}case"a":{const l=s.getAttributeNS("http://www.w3.org/1999/xlink","href")||s.getAttribute("xlink:href")||void 0,h=l?{...a,link:l}:a;s.childNodes.forEach(d=>c(d,h));break}case"s":{const l=parseInt(u(s,"c")||"1",10);e(" ".repeat(Math.min(l,100)),a);break}case"tab":e(" ",a);break;case"line-break":e(" ",a);break;case"note":case"annotation":break;default:s.childNodes.forEach(l=>c(l,a));break}},f={...n,...v(u(r,"style-name"),o)};return r.childNodes.forEach(i=>c(i,f)),t.length===0&&t.push({type:"text",text:"",marks:{}}),t}function A(r,n){return["bold","italic","underline","strikethrough","link"].every(o=>(r[o]??void 0)===(n[o]??void 0))}function m(r){const n=[];return r.childNodes.forEach(o=>{o.nodeType===Node.ELEMENT_NODE&&n.push(o)}),n}function N(r,n){if(r.localName===n)return r;for(const o of m(r)){const t=N(o,n);if(t)return t}return null}function T(r,n){const o=[],t=e=>{e.localName===n&&o.push(e);for(const c of m(e))t(c)};return t(r),o}function u(r,n){const o=r.attributes;for(let t=0;t<o.length;t++)if(o[t].localName===n)return o[t].value;return null}export{I as OdtConverter};
|