revise 3.1.7 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/CHANGELOG.md +1677 -184
  2. package/FONT-LICENSE-HAN-EXT-B.txt +91 -0
  3. package/FONT-LICENSE-KATEX.txt +95 -0
  4. package/FONT-LICENSE-LIBERATION.txt +102 -0
  5. package/FONT-LICENSE-NOTO-MULTILINGUAL.txt +93 -0
  6. package/FONT-LICENSE-NOTO-SANS-SC.txt +93 -0
  7. package/FONT-LICENSE-NOTO.txt +94 -0
  8. package/FONT-LICENSE-SOURCE-CODE-PRO.txt +94 -0
  9. package/FONT-LICENSE-SOURCE-SERIF-4.txt +93 -0
  10. package/LICENSE +41 -21
  11. package/README.md +29 -121
  12. package/THIRD-PARTY-NOTICES.md +2751 -0
  13. package/assets/historyMaterializeWorker-ZFUHJDWr.js +619 -0
  14. package/chunks/AgentPageRenderer-CHHktDQ1.js +1 -0
  15. package/chunks/AgentPageRenderer-CN-N65JC.js +1 -0
  16. package/chunks/AttachmentDocumentImporter-DnHC9t7I.js +1 -0
  17. package/chunks/AttachmentDocumentImporter-Dqg7IPtK.js +1 -0
  18. package/chunks/ColorParserFull-BKH72fK8.js +446 -0
  19. package/chunks/DocumentScrubber-Ch_bOtHW.js +1 -0
  20. package/chunks/DocumentScrubber-DRzACkWJ.js +1 -0
  21. package/chunks/DocxConverter-BGPkGmyg.js +13 -0
  22. package/chunks/DocxConverter-DeurS5EF.js +13 -0
  23. package/chunks/DocxGraft-D71OgoMh.js +1 -0
  24. package/chunks/DocxGraft-QLkGEcwQ.js +1 -0
  25. package/chunks/FileImporter-BIT0ZBDY.js +1 -0
  26. package/chunks/FileImporter-Cgwoawuk.js +1 -0
  27. package/chunks/OdtConverter-2pm0SH5c.js +6 -0
  28. package/chunks/OdtConverter-CSUQTfVp.js +6 -0
  29. package/chunks/OfficeImportShared-C_mYnG5V.js +1 -0
  30. package/chunks/OfficeImportShared-O-d47J7O.js +1 -0
  31. package/chunks/PdfConverter-BYg_pr5J.js +21 -0
  32. package/chunks/PdfConverter-Z2HlY84F.js +21 -0
  33. package/chunks/PdfImportService-C2gwK1Sq.js +2 -0
  34. package/chunks/PdfImportService-CxtUtxM6.js +2 -0
  35. package/chunks/RtfConverter-BrtojpDV.js +15 -0
  36. package/chunks/RtfConverter-DlztsAoK.js +15 -0
  37. package/chunks/XmlConverter-3XWISlqr.js +2 -0
  38. package/chunks/XmlConverter-B1Kcohr0.js +2 -0
  39. package/chunks/__vite-browser-external-l0sNRNKZ.js +0 -0
  40. package/chunks/_revise-sdk-lazy-harfbuzz-X8gnYTZL.js +1 -0
  41. package/chunks/ar-vDYSGTpE.js +13 -0
  42. package/chunks/browser-module-BVdVmrPb.js +3 -0
  43. package/chunks/browser-module-CWlRHeO2.js +3 -0
  44. package/chunks/bundle.min-DRpfgV69.js +782 -0
  45. package/chunks/de-CWX4cvtt.js +13 -0
  46. package/chunks/es-DoAhvF6_.js +13 -0
  47. package/chunks/fil-DdAeD8Br.js +13 -0
  48. package/chunks/fr-CazsUjNQ.js +13 -0
  49. package/chunks/html2canvas.esm-CntiHiYW.js +997 -0
  50. package/chunks/index-BWdRWxoH.js +1807 -0
  51. package/chunks/index-D9_PwgOX.js +402 -0
  52. package/chunks/index-DcIXw_KB.js +402 -0
  53. package/chunks/ja-alh_QHTB.js +13 -0
  54. package/chunks/jspdf.es.min-BuJNZ-oY.js +1882 -0
  55. package/chunks/katex-DWj8TvwO.js +1462 -0
  56. package/chunks/pdf-BLWDCiFF.js +1828 -0
  57. package/chunks/persistInlineDocumentImages-DQj2iaqg.js +1 -0
  58. package/chunks/pseudoLocale-Bld5ZUFr.js +1 -0
  59. package/chunks/pseudoLocale-CLm3_c4X.js +1 -0
  60. package/chunks/tree-sitter-D6zWWUMP.js +4 -0
  61. package/chunks/wasmInline.generated-CBYFkdSM.js +1 -0
  62. package/chunks/web-tree-sitter-BXGZGnNj.js +2 -0
  63. package/chunks/zh-20eXwzFZ.js +13 -0
  64. package/cli-shim.js +34 -0
  65. package/full.js +1 -0
  66. package/index.d.ts +995 -13
  67. package/index.js +1 -31
  68. package/legacy/server.d.ts +19 -19
  69. package/legacy/server.js +39 -23
  70. package/package.json +55 -45
  71. package/serverToolContract.d.ts +420 -0
  72. package/serverToolInputs.generated.d.ts +269 -0
  73. package/style.css +1 -0
  74. package/version.d.ts +4 -0
  75. package/version.js +2 -0
  76. package/agent.d.ts +0 -139
  77. package/chunks/chunk-SMTOJL2X.js +0 -2436
  78. package/chunks/chunk-U5X47PZ6.js +0 -135
  79. package/chunks/chunk-U6YKQBKL.js +0 -15
  80. package/chunks/package-5SHL5FOJ.js +0 -14
  81. package/chunks/render-QD5VWKSV.js +0 -109
  82. package/cli-output.schema.json +0 -2159
  83. package/cli.js +0 -4152
  84. package/document.d.ts +0 -439
  85. package/docx.d.ts +0 -73
  86. package/errors.d.ts +0 -14
  87. package/legacy/editor.d.ts +0 -19
  88. package/legacy/editor.js +0 -16
  89. package/legacy/style.css +0 -2
  90. package/package.d.ts +0 -23
  91. package/render.d.ts +0 -27
@@ -0,0 +1 @@
1
+ import{z as a,C as s,D as r,G as e,v as t,a as o,b as i,d as n,l as c,c as u,g,i as S,A as l,k as R,y as p,u as E,h as C,x as f,m,n as x,p as y,t as A,q as D,r as _,e as b,s as d,o as h,w as k,f as G}from"./index-DcIXw_KB.js";export{a as CARRIER_MAP_KEY,s as CURRENT_GRAFT_SIGNATURE_VERSION,r as DEFAULT_CARRIER_BYTE_CAP,e as GraftProofError,t as assessGraftability,o as blockCanonical,i as blockSignature,n as bodySidecarsSignature,c as canonicalizeForSignature,u as captureDocxSource,g as chromeSignature,S as commentsSignature,l as computeSourceFidelity,R as corePropertiesSignature,p as getDocxCarrierMeta,E as graftExport,C as hashBytes,f as loadDocxCarrier,m as markBlockSource,x as notesSignature,y as pageLayoutSignature,A as partHeadSignature,D as partSignature,_ as refreshDocxSourceSignatures,b as settingsSignature,d as signatureDigest,h as stableStringify,k as storeDocxCarrier,G as stylesSignature};
@@ -0,0 +1 @@
1
+ import{z as a,C as s,D as r,G as e,v as t,a as o,b as i,d as n,l as c,c as u,g,i as S,A as l,k as R,y as p,u as E,h as C,x as f,m,n as x,p as y,t as A,q as D,r as _,e as b,s as d,o as h,w as k,f as G}from"./index-D9_PwgOX.js";export{a as CARRIER_MAP_KEY,s as CURRENT_GRAFT_SIGNATURE_VERSION,r as DEFAULT_CARRIER_BYTE_CAP,e as GraftProofError,t as assessGraftability,o as blockCanonical,i as blockSignature,n as bodySidecarsSignature,c as canonicalizeForSignature,u as captureDocxSource,g as chromeSignature,S as commentsSignature,l as computeSourceFidelity,R as corePropertiesSignature,p as getDocxCarrierMeta,E as graftExport,C as hashBytes,f as loadDocxCarrier,m as markBlockSource,x as notesSignature,y as pageLayoutSignature,A as partHeadSignature,D as partSignature,_ as refreshDocxSourceSignatures,b as settingsSignature,d as signatureDigest,h as stableStringify,k as storeDocxCarrier,G as stylesSignature};
@@ -0,0 +1 @@
1
+ import{aa as c,ab as m,ac as o,ad as d,ae as s,af as f,ag as u}from"./index-DcIXw_KB.js";class l{static async parseFile(r){const t=r.name.toLowerCase(),e=c(t);if(e?.import){const a=await m(new Uint8Array(await r.arrayBuffer()),r.name,e.id,r.type);if(e.id!=="docx"&&e.id!=="odt"&&e.id!=="rtf")return o(a);const{persistInlineDocumentImages:n}=await import("./persistInlineDocumentImages-DQj2iaqg.js");await n(a);const i=o(a);if(i.docxSource){const{refreshDocxSourceSignatures:p}=await import("./DocxGraft-D71OgoMh.js");p(i)}return i}else throw t.endsWith(".pdf")?new Error("PDF files are imported via the AI import flow, not FileImporter."):d(t)?new Error("Image files are imported via the AI import flow, not FileImporter."):new Error(`Unsupported file type: ${r.name}. Supported formats: ${s.join(", ")}`)}static getSupportedExtensions(){return[...s]}static getAcceptString(){return f}static isSupported(r){return u(r)}}export{l as FileImporter};
@@ -0,0 +1 @@
1
+ import{aa as c,ab as m,ac as o,ad as d,ae as s,af as f,ag as u}from"./index-D9_PwgOX.js";class l{static async parseFile(r){const t=r.name.toLowerCase(),e=c(t);if(e?.import){const a=await m(new Uint8Array(await r.arrayBuffer()),r.name,e.id,r.type);if(e.id!=="docx"&&e.id!=="odt"&&e.id!=="rtf")return o(a);const{persistInlineDocumentImages:n}=await import("./persistInlineDocumentImages-DQj2iaqg.js");await n(a);const i=o(a);if(i.docxSource){const{refreshDocxSourceSignatures:p}=await import("./DocxGraft-QLkGEcwQ.js");p(i)}return i}else throw t.endsWith(".pdf")?new Error("PDF files are imported via the AI import flow, not FileImporter."):d(t)?new Error("Image files are imported via the AI import flow, not FileImporter."):new Error(`Unsupported file type: ${r.name}. Supported formats: ${s.join(", ")}`)}static getSupportedExtensions(){return[...s]}static getAcceptString(){return f}static isSupported(r){return u(r)}}export{l as FileImporter};
@@ -0,0 +1,6 @@
1
+ import{F as P,H as S}from"./index-D9_PwgOX.js";import{N as _,k as Z,m as E,r as C,l as q,f as U,e as J,a as G,i as O,s as K,c as k,b as Q,p as Y,d as tt,n as W,M as et,g as nt}from"./OfficeImportShared-C_mYnG5V.js";class st{static async parseFile(e){const t=(await import("./index-D9_PwgOX.js").then(d=>d.j)).default,n=await e.arrayBuffer(),s=await t.loadAsync(new Uint8Array(n)),a=s.file("content.xml");if(!a)throw new Error("Invalid ODT file: missing content.xml");const o=await a.async("text"),l=await s.file("styles.xml")?.async("text"),c=new Set;for(const d of[o,l??""])for(const u of d.matchAll(/xlink:href="([^"]+)"/g))c.add(R(ct(u[1])));const h=new Map;return await Promise.all([...c].map(async d=>{const u=s.file(d);u&&!u.dir&&h.set(d,await u.async("uint8array"))})),this.fromContentXml(o,l,{parts:h})}static fromContentXml(e,t,n={}){const s=new DOMParser,a=s.parseFromString(e,"application/xml"),o=t?s.parseFromString(t,"application/xml"):null;return new at(a,o,n).read()}}class F{constructor(e){this.styles=new Map,this.defaults=new Map,this.listStyles=new Map,this.fontFaces=new Map,this.textCache=new Map,this.paraCache=new Map;for(const t of e)this.collect(t)}collect(e){for(const t of w(e,"font-face")){const n=r(t,"name"),s=r(t,"font-family");n&&this.fontFaces.set(n,L(s||n))}for(const t of w(e,"default-style")){const n=r(t,"family")||"paragraph";this.defaults.set(n,this.parseStyle(t,n))}for(const t of w(e,"style")){const n=r(t,"name");if(!n)continue;const s=r(t,"family")||"paragraph";this.styles.set(`${s}:${n}`,this.parseStyle(t,s))}for(const t of w(e,"list-style")){const n=r(t,"name");if(!n)continue;const s=new Map;for(const a of b(t)){const o=parseInt(r(a,"level")||"1",10);if(a.localName==="list-level-style-number"){const l=r(a,"num-format");s.set(o,{ordered:l!=="",unnumbered:l==="",startValue:parseInt(r(a,"start-value")||"1",10)||1})}else(a.localName==="list-level-style-bullet"||a.localName==="list-level-style-image")&&s.set(o,{ordered:!1,unnumbered:!1,startValue:1})}this.listStyles.set(n,s)}}parseStyle(e,t){const n={family:t,parentName:r(e,"parent-style-name")||void 0,text:{},para:{},listStyleName:r(e,"list-style-name")??void 0,masterPageName:r(e,"master-page-name")||void 0},s=r(e,"default-outline-level");s&&(n.outlineLevel=parseInt(s,10)||void 0);const a=g(e,"text-properties");a&&(n.text=this.parseTextProps(a));const o=g(e,"paragraph-properties");o&&(n.para=ot(o));const l=g(e,"table-cell-properties");if(l){n.cellBackground=B(r(l,"background-color"));const d=r(l,"vertical-align");(d==="middle"||d==="bottom"||d==="top")&&(n.cellVerticalAlign=d)}const c=g(e,"table-column-properties");if(c){n.columnWidth=k(r(c,"column-width"));const d=r(c,"rel-column-width");d&&(n.relColumnWidth=parseFloat(d)||void 0)}const h=g(e,"graphic-properties");return h&&(n.horizontalPos=r(h,"horizontal-pos")??void 0),n}parseTextProps(e){const t={},n=r(e,"font-weight");n&&(t.bold=n==="bold"||parseInt(n,10)>=600);const s=r(e,"font-style");s&&(t.italic=s==="italic"||s==="oblique");const a=r(e,"text-underline-style");a&&(t.underline=a!=="none");const o=r(e,"text-line-through-style");if(o){const x=o!=="none";x&&r(e,"text-line-through-type")==="double"?(t.doubleStrikethrough=!0,t.strikethrough=!1):t.strikethrough=x}const l=r(e,"text-position");if(l){const x=l.trim().split(/\s+/)[0],N=x==="super"?1:x==="sub"?-1:parseFloat(x);t.superscript=N>0,t.subscript=N<0}const c=r(e,"font-variant");c&&(t.smallCaps=c==="small-caps");const h=r(e,"text-transform");h&&(t.allCaps=h==="uppercase");const d=r(e,"display");d&&(t.hidden=d==="none");const u=r(e,"font-name"),i=r(e,"font-family");u?t.fontFamily=this.fontFaces.get(u)??L(u):i&&(t.fontFamily=L(i));const p=r(e,"font-size");if(p)if(p.trim().endsWith("%"))t.fontSizePercent=parseFloat(p);else{const x=k(p);x&&(t.fontSizePx=x)}const m=r(e,"color");m&&(t.color=W(m));const y=r(e,"background-color");y&&(t.backgroundColor=B(y));const v=r(e,"letter-spacing");if(v){const x=v==="normal"?null:k(v);t.letterSpacing=x?C(x):null}return t}get(e,t){return t?this.styles.get(`${e}:${t}`):void 0}chain(e,t){const n=[];let s=t;for(let o=0;s&&o<16;o++){const l=this.get(e,s);if(!l)break;n.push(l),s=l.parentName}const a=this.defaults.get(e);return a&&n.push(a),n.reverse()}resolveText(e,t,n){const s=`${e}:${t??""}|${n?JSON.stringify(n):""}`,a=this.textCache.get(s);if(a)return a;const o={};let l=n?.fontSizePx;const c=e==="paragraph"?this.chain(e,t):this.chain(e,t).filter(i=>i!==this.defaults.get(e));for(const i of c){const p=i.text;p.fontSizePx!==void 0?l=p.fontSizePx:p.fontSizePercent!==void 0&&l!==void 0&&(l=l*p.fontSizePercent/100);for(const[m,y]of Object.entries(p))m==="fontSizePx"||m==="fontSizePercent"||y!==void 0&&(o[m]=y)}const h={...n?.marks??{}},d=["bold","italic","underline","strikethrough","doubleStrikethrough","superscript","subscript","smallCaps","allCaps","hidden"];for(const i of d)o[i]===!0?h[i]=!0:o[i]===!1&&delete h[i];typeof o.fontFamily=="string"&&(h.fontFamily=o.fontFamily),typeof o.color=="string"&&(o.color==="#000000"?delete h.color:h.color=o.color),o.backgroundColor===null?delete h.backgroundColor:typeof o.backgroundColor=="string"&&(h.backgroundColor=o.backgroundColor),o.letterSpacing===null?delete h.letterSpacing:typeof o.letterSpacing=="number"&&(h.letterSpacing=o.letterSpacing),l!==void 0&&(h.fontSize=C(l));const u={marks:h,fontSizePx:l};return this.textCache.set(s,u),u}resolvePara(e){const t=e??"",n=this.paraCache.get(t);if(n)return n;const s={};for(const a of this.chain("paragraph",e))for(const[o,l]of Object.entries(a.para))l!==void 0&&(s[o]=l);return this.paraCache.set(t,s),s}findInChain(e,t,n){const s=this.chain(e,t).reverse();for(const a of s){const o=n(a);if(o!==void 0)return o}}listLevel(e,t){if(!e)return;const n=this.listStyles.get(e);if(n)return n.get(t)??n.get(1)}hasListStyle(e){return!!e&&this.listStyles.has(e)}}function ot(f){const e={},t=r(f,"text-align");t&&(e.align=t==="center"?"center":t==="justify"?"justify":t==="end"||t==="right"?"right":null);const n=k(r(f,"margin-top"));n!==void 0&&(e.marginTop=n);const s=k(r(f,"margin-bottom"));s!==void 0&&(e.marginBottom=s);const a=k(r(f,"margin-left")??r(f,"margin-start"));a!==void 0&&(e.marginLeft=a);const o=k(r(f,"text-indent"));o!==void 0&&(e.textIndent=o);const l=r(f,"line-height");l&&(e.lineHeight=l.trim().endsWith("%")?parseFloat(l)/100:null);const c=r(f,"background-color");c&&(e.background=B(c));const h=r(f,"keep-with-next");h&&(e.keepNext=h==="always");const d=r(f,"writing-mode");d&&(e.rtl=d.startsWith("rl")),r(f,"break-before")==="page"&&(e.breakBefore=!0),r(f,"break-after")==="page"&&(e.breakAfter=!0);const u={},i=j(r(f,"border"));for(const p of["top","bottom","left","right"]){const m=j(r(f,`border-${p}`))??i;m&&(u[p]=m)}return Object.keys(u).length>0&&(e.borders=JSON.stringify(u)),e}function j(f){if(!f)return null;const e=f.trim().toLowerCase();if(!e||e==="none"||e==="hidden")return null;const t=e.match(/\b(solid|dashed|dotted|double)\b/),n=t?t[1]==="solid"?"single":t[1]:"single",s=e.match(/([\d.]+)\s*(pt|px|cm|mm|in)/);let a=1;if(s){const l=k(`${s[1]}${s[2]}`)??1;a=Math.min(8,Math.max(1,Math.round(l)))}const o=e.match(/#[0-9a-f]{3,8}/);return{style:n,width:a,color:o?o[0]:"#000000"}}function B(f){if(f)return f.trim().toLowerCase()==="transparent"?null:W(f)}function L(f){return f.split(",")[0].trim().replace(/^['"]|['"]$/g,"")}const rt="urn:oasis:names:tc:opendocument:xmlns:text:1.0";class at{constructor(e,t,n){this.content=e,this.stylesDoc=t,this.options=n,this.notes=new _("odtfn"),this.comments=[],this.openComments=new Map,this.changes=new Map,this.activeInsertions=[],this.expandedDeletions=new Set,this.listChains={byXmlId:new Map,lastByStyle:new Map,counter:0},this.commentCounter=0,this.firstParagraphStyle=null;const s=t?g(t.documentElement,"styles"):null,a=t?g(t.documentElement,"automatic-styles"):null,o=[t?g(t.documentElement,"font-face-decls"):null,g(e.documentElement,"font-face-decls")].filter(c=>!!c),l=g(e.documentElement,"automatic-styles");if(this.bodyStyles=new F([...o,s,l].filter(c=>!!c)),this.chromeStyles=new F([...o,s,a].filter(c=>!!c)),!t){const c=g(e.documentElement,"styles");c&&(this.bodyStyles=new F([...o,c,l].filter(h=>!!h)))}this.styles=this.bodyStyles}read(){const e=M(this.content.documentElement,"text");e&&this.collectTrackedChanges(e);const t=e?this.convertChildren(e):[];for(;t[0]?.type==="page-break";)t.shift();it(t),t.length===0&&t.push(P());const n={type:"doc",children:t};this.notes.notes.length>0&&(n.notes=this.notes.notes);const s=Z(this.comments,[n.children,n.notes??[]]);s.length>0&&(n.comments=s);const a=this.masterPage();if(a){this.styles=this.chromeStyles;const o=this.readChrome(a);this.styles=this.bodyStyles,o.headers&&(n.headers=o.headers),o.footers&&(n.footers=o.footers);const l=this.pageLayout(a);l&&(n.pageLayout=l)}return n}convertChildren(e){const t=[];for(const n of b(e))t.push(...this.convertBlock(n));return t}convertBlock(e){switch(e.localName){case"h":case"p":return this.convertParagraph(e);case"list":return this.convertList(e);case"numbered-paragraph":return this.convertChildren(e);case"table":{const t=this.convertTable(e);return t?[t]:[]}case"section":case"index-body":case"index-title":return this.convertChildren(e);case"change-start":case"change-end":case"change":{const t=e.ownerDocument.createElementNS(rt,"text:p");t.appendChild(e.cloneNode(!0));const n=this.collectInline(t,{chrome:!1,paragraphId:""}).filter(s=>s.kind==="run").map(s=>s.node);return n.length>0?[P(E(n))]:[]}case"table-of-content":case"alphabetical-index":case"illustration-index":case"table-index":case"object-index":case"user-index":case"bibliography":{const t=g(e,"index-body");return t?this.convertChildren(t):[]}case"frame":case"a":return this.frameBlocks(e,{});default:return[]}}convertParagraph(e){const t=r(e,"style-name");this.firstParagraphStyle===null&&(this.firstParagraphStyle=t??"");const n=this.styles.resolvePara(t),s=S(),a=this.collectInline(e,{chrome:!1,paragraphId:s,paragraphAlign:n.align??void 0}),o=[];let l=[],c=!1;const h=u=>{const i=l.filter(m=>m.text.length>0||m.marks?.footnoteRef);if(i.length===0&&!u)return;const p=this.buildParagraph(e,t,n,i);c||(p.id=s,c=!0),o.push(p),l=[]};let d=!1;for(const u of a)u.kind==="run"?l.push(u.node):(h(!1),o.push(u.block),d=!0);return h(!d),n.breakBefore&&o.unshift({type:"page-break",id:S()}),n.breakAfter&&o.push({type:"page-break",id:S()}),o}buildParagraph(e,t,n,s){const a=P(s.length>0?E(s):[{type:"text",text:"",marks:{}}]);if(e.localName==="h"){const o=parseInt(r(e,"outline-level")||"1",10)||1;a.heading=Math.min(Math.max(o,1),6)}else{const o=this.styles.findInChain("paragraph",t,l=>l.outlineLevel);o&&o>0&&(a.heading=Math.min(o,6))}return this.applyParaProps(a,n),a}applyParaProps(e,t){if(t.align&&(e.align=t.align),t.rtl&&(e.direction="rtl"),e.spaceBefore=C(Math.max(0,t.marginTop??0)),e.spaceAfter=C(Math.max(0,t.marginBottom??0)),t.marginLeft!==void 0){const n=q(t.marginLeft);n&&(e.leftIndent=n)}if(t.textIndent!==void 0){const n=U(t.textIndent);n&&(e.firstLineIndent=n)}typeof t.lineHeight=="number"&&t.lineHeight>0&&(e.lineSpacing=C(t.lineHeight)),t.keepNext&&(e.keepNext=!0),t.background&&t.background!=="#ffffff"&&(e.shading=t.background),t.borders&&(e.borders=t.borders)}convertList(e){const t=[];let n=null;const s=this.listStyleFor(e),a=this.chainFor(e,s),o=()=>{if(!n||n.items.length===0){n=null;return}const c={type:"list",id:S(),variant:n.ordered?"ordered":"unordered",children:n.items};n.ordered&&(a?(c.numberingChainId=a.id,a.restart&&n.start!==void 0&&n.start!==1?c.startNumber=n.start:a.restart&&n.start,a.restart=!1):n.start!==void 0&&n.start!==1&&(c.startNumber=n.start)),n.props&&(c.spaceBefore=C(Math.max(0,n.props.marginTop??0)),c.spaceAfter=C(Math.max(0,n.props.marginBottom??0)),typeof n.props.lineHeight=="number"&&n.props.lineHeight>0&&(c.lineSpacing=C(n.props.lineHeight))),t.push(c),n=null},l=(c,h,d)=>{const u=r(c,"style-name")||d;for(const i of b(c)){if(i.localName!=="list-item"&&i.localName!=="list-header")continue;const p=i.localName==="list-header",m=r(i,"start-value");for(const y of b(i)){if(y.localName==="list"){l(y,h+1,u);continue}if(y.localName!=="p"&&y.localName!=="h"){o(),t.push(...this.convertBlock(y));continue}const v=r(y,"style-name"),x=u??this.styles.findInChain("paragraph",v,I=>I.listStyleName||void 0),N=this.styles.listLevel(x,h+1);if(p||y.localName==="h"||N?.unnumbered){o(),t.push(...this.convertParagraph(y));continue}const D=N?N.ordered:!1;n&&n.items.length>0&&h===0&&n.ordered!==D&&o(),n||(n={items:[],ordered:D,props:this.styles.resolvePara(v)}),n.items.length===0&&(m?n.start=parseInt(m,10)||void 0:N&&N.startValue!==1&&(!a||a.restart)&&(n.start=N.startValue));const $=S(),z=this.styles.resolvePara(v),X=this.collectInline(y,{chrome:!1,paragraphId:$,paragraphAlign:z.align??void 0}),A=[],T=[];for(const I of X)I.kind==="run"?A.push(I.node):T.push(I.block);n.items.push({type:"list-item",id:$,children:A.length>0?E(A):[{type:"text",text:"",marks:{}}],...h>0?{indentLevel:Math.min(h,8)}:{},...z.rtl?{direction:"rtl"}:{}}),T.length>0&&(o(),t.push(...T))}}};return l(e,0,s),o(),t}listStyleFor(e){const t=r(e,"style-name");if(t&&this.styles.hasListStyle(t))return t;const n=M(e,"p")??M(e,"h"),s=n?r(n,"style-name"):null;return this.styles.findInChain("paragraph",s,a=>a.listStyleName||void 0)??t??void 0}chainFor(e,t){const n=r(e,"id"),s=r(e,"continue-list"),a=r(e,"continue-numbering")==="true";let o;s?o=this.listChains.byXmlId.get(s):a&&t&&(o=this.listChains.lastByStyle.get(t));const l=!o;return o||(o=`odt-list-${++this.listChains.counter}`),n&&this.listChains.byXmlId.set(n,o),t&&this.listChains.lastByStyle.set(t,o),{id:o,restart:l}}convertTable(e){const t=[],n=[],s=[],a=l=>{for(const c of b(l))if(c.localName==="table-column"){const h=this.styles.get("table-column",r(c,"style-name")),d=h?.relColumnWidth??h?.columnWidth??0,u=Math.min(64,Math.max(1,parseInt(r(c,"number-columns-repeated")||"1",10)||1));for(let i=0;i<u;i++)s.push(d)}else(c.localName==="table-columns"||c.localName==="table-column-group")&&a(c)};a(e);const o=l=>{for(const c of b(l))c.localName==="table-row"?n.push(c):(c.localName==="table-header-rows"||c.localName==="table-rows"||c.localName==="table-row-group")&&o(c)};o(e);for(const l of n){const c=[];for(const h of b(l)){if(h.localName!=="table-cell")continue;const d=this.convertChildren(h).filter(v=>v.type!=="page-break"),u={type:"table-cell",id:S(),children:d.length>0?d:[P()]},i=H(r(h,"number-columns-spanned")),p=H(r(h,"number-rows-spanned"));i>1&&(u.colSpan=i),p>1&&(u.rowSpan=p);const m=this.styles.get("table-cell",r(h,"style-name"));m?.cellBackground&&(u.backgroundColor=m.cellBackground),m?.cellVerticalAlign&&m.cellVerticalAlign!=="top"&&(u.verticalAlign=m.cellVerticalAlign),c.push(u);const y=parseInt(r(h,"number-columns-repeated")||"1",10)-1;for(let v=0;v<y&&v<20;v++)c.push(J())}c.length>0&&t.push({type:"table-row",id:S(),children:c})}return G(t,{columnWidths:s.every(l=>l>0)?s:void 0,hasHeader:b(e).some(l=>l.localName==="table-header-rows")})}collectInline(e,t){const n=[],s=(l,c)=>{if(!l)return;const h=this.decorate(c),d=n[n.length-1];d?.kind==="run"&&!d.node.marks?.footnoteRef&&nt(d.node.marks,h)?d.node.text+=l:n.push({kind:"run",node:{type:"text",text:l,marks:{...h}}})},a=(l,c,h)=>{if(l.nodeType===Node.TEXT_NODE){const i=h?{...c.marks,link:h}:c.marks;let p=(l.textContent??"").replace(/[ \t\r\n]+/g," ");const m=n[n.length-1],y=m?.kind==="run"?m.node.text:"";p.startsWith(" ")&&(n.length===0||y.endsWith(" "))&&(p=p.slice(1)),s(p,i);return}if(l.nodeType!==Node.ELEMENT_NODE)return;const d=l,u=h?{...c.marks,link:h}:c.marks;switch(d.localName){case"span":{const i=this.styles.resolveText("text",r(d,"style-name"),c);d.childNodes.forEach(p=>a(p,i,h));return}case"a":{const i=d.getAttributeNS("http://www.w3.org/1999/xlink","href")||d.getAttribute("xlink:href")||void 0,p=r(d,"style-name")?this.styles.resolveText("text",r(d,"style-name"),c):c,m=i&&!i.startsWith("#")?tt(i)??h:h;d.childNodes.forEach(y=>a(y,p,m));return}case"s":{const i=parseInt(r(d,"c")||"1",10);s(" ".repeat(Math.min(Math.max(i,1),100)),u);return}case"tab":s(" ",u);return;case"line-break":s(`
2
+ `,u);return;case"page-number":s(d.textContent||"1",{...u,field:"page"});return;case"page-count":s(d.textContent||"1",{...u,field:"numPages"});return;case"note":{if(t.chrome)return;const i=r(d,"note-class")==="endnote"?"endnote":"footnote",p=g(d,"note-body"),m=p?this.convertChildren(p):[];n.push({kind:"run",node:this.notes.add(i,m,this.decorate(u))});return}case"annotation":t.chrome||this.addAnnotation(d,t);return;case"annotation-end":{const i=r(d,"name");i&&this.openComments.delete(i);return}case"change-start":{const i=r(d,"change-id"),p=i?this.changes.get(i):void 0;i&&p?.kind==="insertion"&&this.activeInsertions.push(i);return}case"change-end":{const i=r(d,"change-id"),p=i?this.activeInsertions.indexOf(i):-1;p>=0&&this.activeInsertions.splice(p,1);return}case"change":{const i=r(d,"change-id"),p=i?this.changes.get(i):void 0;if(!i||p?.kind!=="deletion"||this.expandedDeletions.has(i))return;this.expandedDeletions.add(i);const m=O("deletion",`odtrev-${i}`,p.author,p.date);p.deleted.forEach((y,v)=>{v>0&&n.push({kind:"run",node:{type:"text",text:`
3
+ `,marks:V(u,m)}});for(const x of this.collectInline(y,t))x.kind==="run"&&n.push({kind:"run",node:{...x.node,marks:V(x.node.marks??{},m)}})});return}case"frame":case"custom-shape":case"rect":case"ellipse":case"polygon":case"path":case"g":if(t.chrome)return;for(const i of this.frameBlocks(d,t))n.push({kind:"block",block:i});return;case"ruby-text":case"title":case"desc":case"bookmark":case"bookmark-start":case"bookmark-end":case"soft-page-break":case"reference-mark":case"reference-mark-start":case"reference-mark-end":case"hidden-text":case"hidden-paragraph":case"note-citation":case"sequence-decls":case"variable-decls":case"user-field-decls":return;default:d.childNodes.forEach(i=>a(i,c,h))}},o=this.styles.resolveText("paragraph",r(e,"style-name"));return e.childNodes.forEach(l=>a(l,o)),n}decorate(e){let t=e;this.openComments.size>0&&(t={...t,comment:[...this.openComments.values()].join(",")});const n=this.activeInsertions[this.activeInsertions.length-1];if(n){const s=this.changes.get(n);t={...t,...O("insertion",`odtrev-${n}`,s.author,s.date)}}return t}addAnnotation(e,t){this.commentCounter++;const n=`odtcmt-${this.commentCounter}`;let s="",a="",o;const l=[];for(const i of b(e))i.localName==="creator"?s=i.textContent?.trim()??"":i.localName==="creator-initials"||i.localName==="sender-initials"?a=i.textContent?.trim()??"":i.localName==="date"&&(o=i.textContent?.trim());for(const i of[...w(e,"p"),...w(e,"h")])l.push(lt(i));const c=o?Date.parse(o.endsWith("Z")||/[+-]\d\d:\d\d$/.test(o)?o:`${o}Z`):NaN,h=r(e,"name"),d=r(e,"parent-name"),u={id:n,author:s||a||"Unknown",...a?{initials:a}:{},createdAt:new Date(Number.isFinite(c)?c:0).toISOString(),bodyMd:l.map(i=>i.trim()).filter(i=>i.length>0).join(`
4
+
5
+ `),...r(e,"resolved")==="true"?{resolved:!0}:{}};if(d){const i=this.comments.find(p=>p.odtName===d);i&&(u.parentId=i.id)}this.annotationEnds??(this.annotationEnds=new Set([...this.content.getElementsByTagNameNS("*","annotation-end")].map(i=>r(i,"name")).filter(i=>!!i))),h&&this.annotationEnds.has(h)&&h?this.openComments.set(h,n):u.parentId||(u.anchorBlockId=t.paragraphId),h&&Object.defineProperty(u,"odtName",{value:h,enumerable:!1}),this.comments.push(u)}collectTrackedChanges(e){const t=g(e,"tracked-changes");if(t)for(const n of b(t)){if(n.localName!=="changed-region")continue;const s=r(n,"id"),a=b(n)[0];if(!s||!a)continue;const o=g(a,"change-info");let l,c;if(o){for(const u of b(o))if(u.localName==="creator"&&(l=u.textContent?.trim()||void 0),u.localName==="date"){const i=u.textContent?.trim()??"",p=Date.parse(/Z$|[+-]\d\d:\d\d$/.test(i)?i:`${i}Z`);Number.isFinite(p)&&(c=p)}}const h=a.localName==="insertion"?"insertion":a.localName==="deletion"?"deletion":"format",d=b(a).filter(u=>u.localName==="p"||u.localName==="h");this.changes.set(s,{kind:h,author:l,date:c,deleted:d})}}frameBlocks(e,t){if(e.localName==="a")return b(e).flatMap(o=>this.frameBlocks(o,t));if(e.localName!=="frame")return b(e).filter(o=>o.localName==="p"||o.localName==="list").flatMap(o=>this.convertBlock(o));const n=o=>o.originalFormat?2:o.src.startsWith("data:image/svg")?1:0,s=b(e).filter(o=>o.localName==="image").map(o=>this.imageFromElement(o,e,t)).filter(o=>!!o).sort((o,l)=>n(o)-n(l));if(s.length>0)return[s[0]];const a=g(e,"text-box");return a?this.convertChildren(a):[]}imageFromElement(e,t,n){let s;const a=e.getAttributeNS("http://www.w3.org/1999/xlink","href")||e.getAttribute("xlink:href");if(a)s=this.options.parts?.get(R(a));else{const p=g(e,"binary-data")?.textContent?.replace(/\s+/g,"");if(p)try{s=Uint8Array.from(atob(p),m=>m.charCodeAt(0))}catch{s=void 0}}if(!s||s.length===0)return null;const o=K(s);if(!o)return null;const l=k(r(t,"width")),c=k(r(t,"height")),h=g(t,"title")?.textContent?.trim(),d=g(t,"desc")?.textContent?.trim(),u=this.styles.get("graphic",r(t,"style-name"))?.horizontalPos,i=u==="center"?"center":u==="right"||u==="outside"?"right":n.paragraphAlign==="center"||n.paragraphAlign==="right"?n.paragraphAlign:void 0;return Q(s,o,{width:l,height:c},{alt:d||h||r(t,"name")||void 0,align:i})}masterPage(){if(!this.stylesDoc)return null;const e=g(this.stylesDoc.documentElement,"master-styles");if(!e)return null;const t=b(e).filter(s=>s.localName==="master-page");if(t.length===0)return null;const n=this.firstParagraphStyle!==null?this.bodyStyles.findInChain("paragraph",this.firstParagraphStyle,s=>s.masterPageName):void 0;return n&&t.find(s=>r(s,"name")===n)||t.find(s=>r(s,"name")==="Standard"||r(s,"name")==="Default")||t[0]}readChrome(e){const t={},n=[["header","header","default"],["footer","footer","default"],["header-first","header","first"],["footer-first","footer","first"],["header-left","header","even"],["footer-left","footer","even"]];for(const[s,a,o]of n){const l=g(e,s);if(!l||r(l,"display")==="false")continue;const c=this.chromeParagraphs(l);if(!c.some(d=>d.children.some(u=>u.text.trim()!==""||u.marks?.field)))continue;const h=a==="header"?t.headers??(t.headers={}):t.footers??(t.footers={});h[o]=c}return t}chromeParagraphs(e){if(["region-left","region-center","region-right"].map(n=>g(e,n)).filter(n=>!!n).length>0){const n=[];return["region-left","region-center","region-right"].forEach((s,a)=>{a>0&&n.push({type:"text",text:" ",marks:{}});const o=g(e,s);if(o)for(const l of b(o).filter(c=>c.localName==="p"))n.push(...this.chromeRuns(l))}),[P(E(n))]}const t=[];for(const n of b(e)){if(n.localName!=="p"&&n.localName!=="h")continue;const s=P(E(this.chromeRuns(n))),a=this.styles.resolvePara(r(n,"style-name"));a.align&&(s.align=a.align),t.push(s)}return t}chromeRuns(e){const t=this.collectInline(e,{chrome:!0,paragraphId:""}).filter(n=>n.kind==="run").map(n=>n.node);return t.length>0?t:[{type:"text",text:"",marks:{}}]}pageLayout(e){const t=r(e,"page-layout-name");if(!t||!this.stylesDoc)return;const n=w(this.stylesDoc.documentElement,"page-layout").find(a=>r(a,"name")===t),s=n?g(n,"page-layout-properties"):null;if(s)return Y({widthPx:k(r(s,"page-width")),heightPx:k(r(s,"page-height")),landscape:r(s,"print-orientation")==="landscape",marginTopPx:k(r(s,"margin-top")),marginRightPx:k(r(s,"margin-right")),marginBottomPx:k(r(s,"margin-bottom")),marginLeftPx:k(r(s,"margin-left"))})}}function H(f){const e=parseInt(f||"1",10);return Number.isFinite(e)?Math.min(Math.max(1,e),et):1}function it(f){for(;f.length>1;){const e=f[f.length-1];if(e.type==="paragraph"&&!e.borders&&e.children.every(t=>t.text.trim()===""&&!t.marks?.footnoteRef))f.pop();else break}}function lt(f){let e="";const t=n=>{if(n.nodeType===Node.TEXT_NODE){e+=(n.textContent??"").replace(/[\r\n]+/g,"");return}if(n.nodeType!==Node.ELEMENT_NODE)return;const s=n;s.localName==="s"?e+=" ".repeat(parseInt(r(s,"c")||"1",10)||1):s.localName==="tab"?e+=" ":s.localName==="line-break"?e+=`
6
+ `:s.childNodes.forEach(t)};return f.childNodes.forEach(t),e}function V(f,e){const{insertion:t,deletion:n,suggestionId:s,suggestionSource:a,suggestionAuthorType:o,suggestionLabel:l,suggestionCreatedAt:c,suggestionAuthorName:h,...d}=f;return{...d,...e}}function R(f){return f.replace(/^\.\//,"").replace(/^\//,"")}function ct(f){return f.replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">")}function b(f){const e=[];return f.childNodes.forEach(t=>{t.nodeType===Node.ELEMENT_NODE&&e.push(t)}),e}function g(f,e){for(const t of b(f))if(t.localName===e)return t;return null}function M(f,e){if(f.localName===e)return f;for(const t of b(f)){const n=M(t,e);if(n)return n}return null}function w(f,e){const t=[],n=s=>{s.localName===e&&t.push(s);for(const a of b(s))n(a)};return n(f),t}function r(f,e){const t=f.attributes;for(let n=0;n<t.length;n++)if(t[n].localName===e)return t[n].value;return null}export{st as OdtConverter};
@@ -0,0 +1,6 @@
1
+ import{F as P,H as S}from"./index-DcIXw_KB.js";import{N as _,k as Z,m as E,r as C,l as q,f as U,e as J,a as G,i as O,s as K,c as k,b as Q,p as Y,d as tt,n as W,M as et,g as nt}from"./OfficeImportShared-O-d47J7O.js";class st{static async parseFile(e){const t=(await import("./index-DcIXw_KB.js").then(d=>d.j)).default,n=await e.arrayBuffer(),s=await t.loadAsync(new Uint8Array(n)),a=s.file("content.xml");if(!a)throw new Error("Invalid ODT file: missing content.xml");const o=await a.async("text"),l=await s.file("styles.xml")?.async("text"),c=new Set;for(const d of[o,l??""])for(const u of d.matchAll(/xlink:href="([^"]+)"/g))c.add(R(ct(u[1])));const h=new Map;return await Promise.all([...c].map(async d=>{const u=s.file(d);u&&!u.dir&&h.set(d,await u.async("uint8array"))})),this.fromContentXml(o,l,{parts:h})}static fromContentXml(e,t,n={}){const s=new DOMParser,a=s.parseFromString(e,"application/xml"),o=t?s.parseFromString(t,"application/xml"):null;return new at(a,o,n).read()}}class F{constructor(e){this.styles=new Map,this.defaults=new Map,this.listStyles=new Map,this.fontFaces=new Map,this.textCache=new Map,this.paraCache=new Map;for(const t of e)this.collect(t)}collect(e){for(const t of w(e,"font-face")){const n=r(t,"name"),s=r(t,"font-family");n&&this.fontFaces.set(n,L(s||n))}for(const t of w(e,"default-style")){const n=r(t,"family")||"paragraph";this.defaults.set(n,this.parseStyle(t,n))}for(const t of w(e,"style")){const n=r(t,"name");if(!n)continue;const s=r(t,"family")||"paragraph";this.styles.set(`${s}:${n}`,this.parseStyle(t,s))}for(const t of w(e,"list-style")){const n=r(t,"name");if(!n)continue;const s=new Map;for(const a of b(t)){const o=parseInt(r(a,"level")||"1",10);if(a.localName==="list-level-style-number"){const l=r(a,"num-format");s.set(o,{ordered:l!=="",unnumbered:l==="",startValue:parseInt(r(a,"start-value")||"1",10)||1})}else(a.localName==="list-level-style-bullet"||a.localName==="list-level-style-image")&&s.set(o,{ordered:!1,unnumbered:!1,startValue:1})}this.listStyles.set(n,s)}}parseStyle(e,t){const n={family:t,parentName:r(e,"parent-style-name")||void 0,text:{},para:{},listStyleName:r(e,"list-style-name")??void 0,masterPageName:r(e,"master-page-name")||void 0},s=r(e,"default-outline-level");s&&(n.outlineLevel=parseInt(s,10)||void 0);const a=g(e,"text-properties");a&&(n.text=this.parseTextProps(a));const o=g(e,"paragraph-properties");o&&(n.para=ot(o));const l=g(e,"table-cell-properties");if(l){n.cellBackground=B(r(l,"background-color"));const d=r(l,"vertical-align");(d==="middle"||d==="bottom"||d==="top")&&(n.cellVerticalAlign=d)}const c=g(e,"table-column-properties");if(c){n.columnWidth=k(r(c,"column-width"));const d=r(c,"rel-column-width");d&&(n.relColumnWidth=parseFloat(d)||void 0)}const h=g(e,"graphic-properties");return h&&(n.horizontalPos=r(h,"horizontal-pos")??void 0),n}parseTextProps(e){const t={},n=r(e,"font-weight");n&&(t.bold=n==="bold"||parseInt(n,10)>=600);const s=r(e,"font-style");s&&(t.italic=s==="italic"||s==="oblique");const a=r(e,"text-underline-style");a&&(t.underline=a!=="none");const o=r(e,"text-line-through-style");if(o){const x=o!=="none";x&&r(e,"text-line-through-type")==="double"?(t.doubleStrikethrough=!0,t.strikethrough=!1):t.strikethrough=x}const l=r(e,"text-position");if(l){const x=l.trim().split(/\s+/)[0],N=x==="super"?1:x==="sub"?-1:parseFloat(x);t.superscript=N>0,t.subscript=N<0}const c=r(e,"font-variant");c&&(t.smallCaps=c==="small-caps");const h=r(e,"text-transform");h&&(t.allCaps=h==="uppercase");const d=r(e,"display");d&&(t.hidden=d==="none");const u=r(e,"font-name"),i=r(e,"font-family");u?t.fontFamily=this.fontFaces.get(u)??L(u):i&&(t.fontFamily=L(i));const p=r(e,"font-size");if(p)if(p.trim().endsWith("%"))t.fontSizePercent=parseFloat(p);else{const x=k(p);x&&(t.fontSizePx=x)}const m=r(e,"color");m&&(t.color=W(m));const y=r(e,"background-color");y&&(t.backgroundColor=B(y));const v=r(e,"letter-spacing");if(v){const x=v==="normal"?null:k(v);t.letterSpacing=x?C(x):null}return t}get(e,t){return t?this.styles.get(`${e}:${t}`):void 0}chain(e,t){const n=[];let s=t;for(let o=0;s&&o<16;o++){const l=this.get(e,s);if(!l)break;n.push(l),s=l.parentName}const a=this.defaults.get(e);return a&&n.push(a),n.reverse()}resolveText(e,t,n){const s=`${e}:${t??""}|${n?JSON.stringify(n):""}`,a=this.textCache.get(s);if(a)return a;const o={};let l=n?.fontSizePx;const c=e==="paragraph"?this.chain(e,t):this.chain(e,t).filter(i=>i!==this.defaults.get(e));for(const i of c){const p=i.text;p.fontSizePx!==void 0?l=p.fontSizePx:p.fontSizePercent!==void 0&&l!==void 0&&(l=l*p.fontSizePercent/100);for(const[m,y]of Object.entries(p))m==="fontSizePx"||m==="fontSizePercent"||y!==void 0&&(o[m]=y)}const h={...n?.marks??{}},d=["bold","italic","underline","strikethrough","doubleStrikethrough","superscript","subscript","smallCaps","allCaps","hidden"];for(const i of d)o[i]===!0?h[i]=!0:o[i]===!1&&delete h[i];typeof o.fontFamily=="string"&&(h.fontFamily=o.fontFamily),typeof o.color=="string"&&(o.color==="#000000"?delete h.color:h.color=o.color),o.backgroundColor===null?delete h.backgroundColor:typeof o.backgroundColor=="string"&&(h.backgroundColor=o.backgroundColor),o.letterSpacing===null?delete h.letterSpacing:typeof o.letterSpacing=="number"&&(h.letterSpacing=o.letterSpacing),l!==void 0&&(h.fontSize=C(l));const u={marks:h,fontSizePx:l};return this.textCache.set(s,u),u}resolvePara(e){const t=e??"",n=this.paraCache.get(t);if(n)return n;const s={};for(const a of this.chain("paragraph",e))for(const[o,l]of Object.entries(a.para))l!==void 0&&(s[o]=l);return this.paraCache.set(t,s),s}findInChain(e,t,n){const s=this.chain(e,t).reverse();for(const a of s){const o=n(a);if(o!==void 0)return o}}listLevel(e,t){if(!e)return;const n=this.listStyles.get(e);if(n)return n.get(t)??n.get(1)}hasListStyle(e){return!!e&&this.listStyles.has(e)}}function ot(f){const e={},t=r(f,"text-align");t&&(e.align=t==="center"?"center":t==="justify"?"justify":t==="end"||t==="right"?"right":null);const n=k(r(f,"margin-top"));n!==void 0&&(e.marginTop=n);const s=k(r(f,"margin-bottom"));s!==void 0&&(e.marginBottom=s);const a=k(r(f,"margin-left")??r(f,"margin-start"));a!==void 0&&(e.marginLeft=a);const o=k(r(f,"text-indent"));o!==void 0&&(e.textIndent=o);const l=r(f,"line-height");l&&(e.lineHeight=l.trim().endsWith("%")?parseFloat(l)/100:null);const c=r(f,"background-color");c&&(e.background=B(c));const h=r(f,"keep-with-next");h&&(e.keepNext=h==="always");const d=r(f,"writing-mode");d&&(e.rtl=d.startsWith("rl")),r(f,"break-before")==="page"&&(e.breakBefore=!0),r(f,"break-after")==="page"&&(e.breakAfter=!0);const u={},i=j(r(f,"border"));for(const p of["top","bottom","left","right"]){const m=j(r(f,`border-${p}`))??i;m&&(u[p]=m)}return Object.keys(u).length>0&&(e.borders=JSON.stringify(u)),e}function j(f){if(!f)return null;const e=f.trim().toLowerCase();if(!e||e==="none"||e==="hidden")return null;const t=e.match(/\b(solid|dashed|dotted|double)\b/),n=t?t[1]==="solid"?"single":t[1]:"single",s=e.match(/([\d.]+)\s*(pt|px|cm|mm|in)/);let a=1;if(s){const l=k(`${s[1]}${s[2]}`)??1;a=Math.min(8,Math.max(1,Math.round(l)))}const o=e.match(/#[0-9a-f]{3,8}/);return{style:n,width:a,color:o?o[0]:"#000000"}}function B(f){if(f)return f.trim().toLowerCase()==="transparent"?null:W(f)}function L(f){return f.split(",")[0].trim().replace(/^['"]|['"]$/g,"")}const rt="urn:oasis:names:tc:opendocument:xmlns:text:1.0";class at{constructor(e,t,n){this.content=e,this.stylesDoc=t,this.options=n,this.notes=new _("odtfn"),this.comments=[],this.openComments=new Map,this.changes=new Map,this.activeInsertions=[],this.expandedDeletions=new Set,this.listChains={byXmlId:new Map,lastByStyle:new Map,counter:0},this.commentCounter=0,this.firstParagraphStyle=null;const s=t?g(t.documentElement,"styles"):null,a=t?g(t.documentElement,"automatic-styles"):null,o=[t?g(t.documentElement,"font-face-decls"):null,g(e.documentElement,"font-face-decls")].filter(c=>!!c),l=g(e.documentElement,"automatic-styles");if(this.bodyStyles=new F([...o,s,l].filter(c=>!!c)),this.chromeStyles=new F([...o,s,a].filter(c=>!!c)),!t){const c=g(e.documentElement,"styles");c&&(this.bodyStyles=new F([...o,c,l].filter(h=>!!h)))}this.styles=this.bodyStyles}read(){const e=M(this.content.documentElement,"text");e&&this.collectTrackedChanges(e);const t=e?this.convertChildren(e):[];for(;t[0]?.type==="page-break";)t.shift();it(t),t.length===0&&t.push(P());const n={type:"doc",children:t};this.notes.notes.length>0&&(n.notes=this.notes.notes);const s=Z(this.comments,[n.children,n.notes??[]]);s.length>0&&(n.comments=s);const a=this.masterPage();if(a){this.styles=this.chromeStyles;const o=this.readChrome(a);this.styles=this.bodyStyles,o.headers&&(n.headers=o.headers),o.footers&&(n.footers=o.footers);const l=this.pageLayout(a);l&&(n.pageLayout=l)}return n}convertChildren(e){const t=[];for(const n of b(e))t.push(...this.convertBlock(n));return t}convertBlock(e){switch(e.localName){case"h":case"p":return this.convertParagraph(e);case"list":return this.convertList(e);case"numbered-paragraph":return this.convertChildren(e);case"table":{const t=this.convertTable(e);return t?[t]:[]}case"section":case"index-body":case"index-title":return this.convertChildren(e);case"change-start":case"change-end":case"change":{const t=e.ownerDocument.createElementNS(rt,"text:p");t.appendChild(e.cloneNode(!0));const n=this.collectInline(t,{chrome:!1,paragraphId:""}).filter(s=>s.kind==="run").map(s=>s.node);return n.length>0?[P(E(n))]:[]}case"table-of-content":case"alphabetical-index":case"illustration-index":case"table-index":case"object-index":case"user-index":case"bibliography":{const t=g(e,"index-body");return t?this.convertChildren(t):[]}case"frame":case"a":return this.frameBlocks(e,{});default:return[]}}convertParagraph(e){const t=r(e,"style-name");this.firstParagraphStyle===null&&(this.firstParagraphStyle=t??"");const n=this.styles.resolvePara(t),s=S(),a=this.collectInline(e,{chrome:!1,paragraphId:s,paragraphAlign:n.align??void 0}),o=[];let l=[],c=!1;const h=u=>{const i=l.filter(m=>m.text.length>0||m.marks?.footnoteRef);if(i.length===0&&!u)return;const p=this.buildParagraph(e,t,n,i);c||(p.id=s,c=!0),o.push(p),l=[]};let d=!1;for(const u of a)u.kind==="run"?l.push(u.node):(h(!1),o.push(u.block),d=!0);return h(!d),n.breakBefore&&o.unshift({type:"page-break",id:S()}),n.breakAfter&&o.push({type:"page-break",id:S()}),o}buildParagraph(e,t,n,s){const a=P(s.length>0?E(s):[{type:"text",text:"",marks:{}}]);if(e.localName==="h"){const o=parseInt(r(e,"outline-level")||"1",10)||1;a.heading=Math.min(Math.max(o,1),6)}else{const o=this.styles.findInChain("paragraph",t,l=>l.outlineLevel);o&&o>0&&(a.heading=Math.min(o,6))}return this.applyParaProps(a,n),a}applyParaProps(e,t){if(t.align&&(e.align=t.align),t.rtl&&(e.direction="rtl"),e.spaceBefore=C(Math.max(0,t.marginTop??0)),e.spaceAfter=C(Math.max(0,t.marginBottom??0)),t.marginLeft!==void 0){const n=q(t.marginLeft);n&&(e.leftIndent=n)}if(t.textIndent!==void 0){const n=U(t.textIndent);n&&(e.firstLineIndent=n)}typeof t.lineHeight=="number"&&t.lineHeight>0&&(e.lineSpacing=C(t.lineHeight)),t.keepNext&&(e.keepNext=!0),t.background&&t.background!=="#ffffff"&&(e.shading=t.background),t.borders&&(e.borders=t.borders)}convertList(e){const t=[];let n=null;const s=this.listStyleFor(e),a=this.chainFor(e,s),o=()=>{if(!n||n.items.length===0){n=null;return}const c={type:"list",id:S(),variant:n.ordered?"ordered":"unordered",children:n.items};n.ordered&&(a?(c.numberingChainId=a.id,a.restart&&n.start!==void 0&&n.start!==1?c.startNumber=n.start:a.restart&&n.start,a.restart=!1):n.start!==void 0&&n.start!==1&&(c.startNumber=n.start)),n.props&&(c.spaceBefore=C(Math.max(0,n.props.marginTop??0)),c.spaceAfter=C(Math.max(0,n.props.marginBottom??0)),typeof n.props.lineHeight=="number"&&n.props.lineHeight>0&&(c.lineSpacing=C(n.props.lineHeight))),t.push(c),n=null},l=(c,h,d)=>{const u=r(c,"style-name")||d;for(const i of b(c)){if(i.localName!=="list-item"&&i.localName!=="list-header")continue;const p=i.localName==="list-header",m=r(i,"start-value");for(const y of b(i)){if(y.localName==="list"){l(y,h+1,u);continue}if(y.localName!=="p"&&y.localName!=="h"){o(),t.push(...this.convertBlock(y));continue}const v=r(y,"style-name"),x=u??this.styles.findInChain("paragraph",v,I=>I.listStyleName||void 0),N=this.styles.listLevel(x,h+1);if(p||y.localName==="h"||N?.unnumbered){o(),t.push(...this.convertParagraph(y));continue}const D=N?N.ordered:!1;n&&n.items.length>0&&h===0&&n.ordered!==D&&o(),n||(n={items:[],ordered:D,props:this.styles.resolvePara(v)}),n.items.length===0&&(m?n.start=parseInt(m,10)||void 0:N&&N.startValue!==1&&(!a||a.restart)&&(n.start=N.startValue));const $=S(),z=this.styles.resolvePara(v),X=this.collectInline(y,{chrome:!1,paragraphId:$,paragraphAlign:z.align??void 0}),A=[],T=[];for(const I of X)I.kind==="run"?A.push(I.node):T.push(I.block);n.items.push({type:"list-item",id:$,children:A.length>0?E(A):[{type:"text",text:"",marks:{}}],...h>0?{indentLevel:Math.min(h,8)}:{},...z.rtl?{direction:"rtl"}:{}}),T.length>0&&(o(),t.push(...T))}}};return l(e,0,s),o(),t}listStyleFor(e){const t=r(e,"style-name");if(t&&this.styles.hasListStyle(t))return t;const n=M(e,"p")??M(e,"h"),s=n?r(n,"style-name"):null;return this.styles.findInChain("paragraph",s,a=>a.listStyleName||void 0)??t??void 0}chainFor(e,t){const n=r(e,"id"),s=r(e,"continue-list"),a=r(e,"continue-numbering")==="true";let o;s?o=this.listChains.byXmlId.get(s):a&&t&&(o=this.listChains.lastByStyle.get(t));const l=!o;return o||(o=`odt-list-${++this.listChains.counter}`),n&&this.listChains.byXmlId.set(n,o),t&&this.listChains.lastByStyle.set(t,o),{id:o,restart:l}}convertTable(e){const t=[],n=[],s=[],a=l=>{for(const c of b(l))if(c.localName==="table-column"){const h=this.styles.get("table-column",r(c,"style-name")),d=h?.relColumnWidth??h?.columnWidth??0,u=Math.min(64,Math.max(1,parseInt(r(c,"number-columns-repeated")||"1",10)||1));for(let i=0;i<u;i++)s.push(d)}else(c.localName==="table-columns"||c.localName==="table-column-group")&&a(c)};a(e);const o=l=>{for(const c of b(l))c.localName==="table-row"?n.push(c):(c.localName==="table-header-rows"||c.localName==="table-rows"||c.localName==="table-row-group")&&o(c)};o(e);for(const l of n){const c=[];for(const h of b(l)){if(h.localName!=="table-cell")continue;const d=this.convertChildren(h).filter(v=>v.type!=="page-break"),u={type:"table-cell",id:S(),children:d.length>0?d:[P()]},i=H(r(h,"number-columns-spanned")),p=H(r(h,"number-rows-spanned"));i>1&&(u.colSpan=i),p>1&&(u.rowSpan=p);const m=this.styles.get("table-cell",r(h,"style-name"));m?.cellBackground&&(u.backgroundColor=m.cellBackground),m?.cellVerticalAlign&&m.cellVerticalAlign!=="top"&&(u.verticalAlign=m.cellVerticalAlign),c.push(u);const y=parseInt(r(h,"number-columns-repeated")||"1",10)-1;for(let v=0;v<y&&v<20;v++)c.push(J())}c.length>0&&t.push({type:"table-row",id:S(),children:c})}return G(t,{columnWidths:s.every(l=>l>0)?s:void 0,hasHeader:b(e).some(l=>l.localName==="table-header-rows")})}collectInline(e,t){const n=[],s=(l,c)=>{if(!l)return;const h=this.decorate(c),d=n[n.length-1];d?.kind==="run"&&!d.node.marks?.footnoteRef&&nt(d.node.marks,h)?d.node.text+=l:n.push({kind:"run",node:{type:"text",text:l,marks:{...h}}})},a=(l,c,h)=>{if(l.nodeType===Node.TEXT_NODE){const i=h?{...c.marks,link:h}:c.marks;let p=(l.textContent??"").replace(/[ \t\r\n]+/g," ");const m=n[n.length-1],y=m?.kind==="run"?m.node.text:"";p.startsWith(" ")&&(n.length===0||y.endsWith(" "))&&(p=p.slice(1)),s(p,i);return}if(l.nodeType!==Node.ELEMENT_NODE)return;const d=l,u=h?{...c.marks,link:h}:c.marks;switch(d.localName){case"span":{const i=this.styles.resolveText("text",r(d,"style-name"),c);d.childNodes.forEach(p=>a(p,i,h));return}case"a":{const i=d.getAttributeNS("http://www.w3.org/1999/xlink","href")||d.getAttribute("xlink:href")||void 0,p=r(d,"style-name")?this.styles.resolveText("text",r(d,"style-name"),c):c,m=i&&!i.startsWith("#")?tt(i)??h:h;d.childNodes.forEach(y=>a(y,p,m));return}case"s":{const i=parseInt(r(d,"c")||"1",10);s(" ".repeat(Math.min(Math.max(i,1),100)),u);return}case"tab":s(" ",u);return;case"line-break":s(`
2
+ `,u);return;case"page-number":s(d.textContent||"1",{...u,field:"page"});return;case"page-count":s(d.textContent||"1",{...u,field:"numPages"});return;case"note":{if(t.chrome)return;const i=r(d,"note-class")==="endnote"?"endnote":"footnote",p=g(d,"note-body"),m=p?this.convertChildren(p):[];n.push({kind:"run",node:this.notes.add(i,m,this.decorate(u))});return}case"annotation":t.chrome||this.addAnnotation(d,t);return;case"annotation-end":{const i=r(d,"name");i&&this.openComments.delete(i);return}case"change-start":{const i=r(d,"change-id"),p=i?this.changes.get(i):void 0;i&&p?.kind==="insertion"&&this.activeInsertions.push(i);return}case"change-end":{const i=r(d,"change-id"),p=i?this.activeInsertions.indexOf(i):-1;p>=0&&this.activeInsertions.splice(p,1);return}case"change":{const i=r(d,"change-id"),p=i?this.changes.get(i):void 0;if(!i||p?.kind!=="deletion"||this.expandedDeletions.has(i))return;this.expandedDeletions.add(i);const m=O("deletion",`odtrev-${i}`,p.author,p.date);p.deleted.forEach((y,v)=>{v>0&&n.push({kind:"run",node:{type:"text",text:`
3
+ `,marks:V(u,m)}});for(const x of this.collectInline(y,t))x.kind==="run"&&n.push({kind:"run",node:{...x.node,marks:V(x.node.marks??{},m)}})});return}case"frame":case"custom-shape":case"rect":case"ellipse":case"polygon":case"path":case"g":if(t.chrome)return;for(const i of this.frameBlocks(d,t))n.push({kind:"block",block:i});return;case"ruby-text":case"title":case"desc":case"bookmark":case"bookmark-start":case"bookmark-end":case"soft-page-break":case"reference-mark":case"reference-mark-start":case"reference-mark-end":case"hidden-text":case"hidden-paragraph":case"note-citation":case"sequence-decls":case"variable-decls":case"user-field-decls":return;default:d.childNodes.forEach(i=>a(i,c,h))}},o=this.styles.resolveText("paragraph",r(e,"style-name"));return e.childNodes.forEach(l=>a(l,o)),n}decorate(e){let t=e;this.openComments.size>0&&(t={...t,comment:[...this.openComments.values()].join(",")});const n=this.activeInsertions[this.activeInsertions.length-1];if(n){const s=this.changes.get(n);t={...t,...O("insertion",`odtrev-${n}`,s.author,s.date)}}return t}addAnnotation(e,t){this.commentCounter++;const n=`odtcmt-${this.commentCounter}`;let s="",a="",o;const l=[];for(const i of b(e))i.localName==="creator"?s=i.textContent?.trim()??"":i.localName==="creator-initials"||i.localName==="sender-initials"?a=i.textContent?.trim()??"":i.localName==="date"&&(o=i.textContent?.trim());for(const i of[...w(e,"p"),...w(e,"h")])l.push(lt(i));const c=o?Date.parse(o.endsWith("Z")||/[+-]\d\d:\d\d$/.test(o)?o:`${o}Z`):NaN,h=r(e,"name"),d=r(e,"parent-name"),u={id:n,author:s||a||"Unknown",...a?{initials:a}:{},createdAt:new Date(Number.isFinite(c)?c:0).toISOString(),bodyMd:l.map(i=>i.trim()).filter(i=>i.length>0).join(`
4
+
5
+ `),...r(e,"resolved")==="true"?{resolved:!0}:{}};if(d){const i=this.comments.find(p=>p.odtName===d);i&&(u.parentId=i.id)}this.annotationEnds??(this.annotationEnds=new Set([...this.content.getElementsByTagNameNS("*","annotation-end")].map(i=>r(i,"name")).filter(i=>!!i))),h&&this.annotationEnds.has(h)&&h?this.openComments.set(h,n):u.parentId||(u.anchorBlockId=t.paragraphId),h&&Object.defineProperty(u,"odtName",{value:h,enumerable:!1}),this.comments.push(u)}collectTrackedChanges(e){const t=g(e,"tracked-changes");if(t)for(const n of b(t)){if(n.localName!=="changed-region")continue;const s=r(n,"id"),a=b(n)[0];if(!s||!a)continue;const o=g(a,"change-info");let l,c;if(o){for(const u of b(o))if(u.localName==="creator"&&(l=u.textContent?.trim()||void 0),u.localName==="date"){const i=u.textContent?.trim()??"",p=Date.parse(/Z$|[+-]\d\d:\d\d$/.test(i)?i:`${i}Z`);Number.isFinite(p)&&(c=p)}}const h=a.localName==="insertion"?"insertion":a.localName==="deletion"?"deletion":"format",d=b(a).filter(u=>u.localName==="p"||u.localName==="h");this.changes.set(s,{kind:h,author:l,date:c,deleted:d})}}frameBlocks(e,t){if(e.localName==="a")return b(e).flatMap(o=>this.frameBlocks(o,t));if(e.localName!=="frame")return b(e).filter(o=>o.localName==="p"||o.localName==="list").flatMap(o=>this.convertBlock(o));const n=o=>o.originalFormat?2:o.src.startsWith("data:image/svg")?1:0,s=b(e).filter(o=>o.localName==="image").map(o=>this.imageFromElement(o,e,t)).filter(o=>!!o).sort((o,l)=>n(o)-n(l));if(s.length>0)return[s[0]];const a=g(e,"text-box");return a?this.convertChildren(a):[]}imageFromElement(e,t,n){let s;const a=e.getAttributeNS("http://www.w3.org/1999/xlink","href")||e.getAttribute("xlink:href");if(a)s=this.options.parts?.get(R(a));else{const p=g(e,"binary-data")?.textContent?.replace(/\s+/g,"");if(p)try{s=Uint8Array.from(atob(p),m=>m.charCodeAt(0))}catch{s=void 0}}if(!s||s.length===0)return null;const o=K(s);if(!o)return null;const l=k(r(t,"width")),c=k(r(t,"height")),h=g(t,"title")?.textContent?.trim(),d=g(t,"desc")?.textContent?.trim(),u=this.styles.get("graphic",r(t,"style-name"))?.horizontalPos,i=u==="center"?"center":u==="right"||u==="outside"?"right":n.paragraphAlign==="center"||n.paragraphAlign==="right"?n.paragraphAlign:void 0;return Q(s,o,{width:l,height:c},{alt:d||h||r(t,"name")||void 0,align:i})}masterPage(){if(!this.stylesDoc)return null;const e=g(this.stylesDoc.documentElement,"master-styles");if(!e)return null;const t=b(e).filter(s=>s.localName==="master-page");if(t.length===0)return null;const n=this.firstParagraphStyle!==null?this.bodyStyles.findInChain("paragraph",this.firstParagraphStyle,s=>s.masterPageName):void 0;return n&&t.find(s=>r(s,"name")===n)||t.find(s=>r(s,"name")==="Standard"||r(s,"name")==="Default")||t[0]}readChrome(e){const t={},n=[["header","header","default"],["footer","footer","default"],["header-first","header","first"],["footer-first","footer","first"],["header-left","header","even"],["footer-left","footer","even"]];for(const[s,a,o]of n){const l=g(e,s);if(!l||r(l,"display")==="false")continue;const c=this.chromeParagraphs(l);if(!c.some(d=>d.children.some(u=>u.text.trim()!==""||u.marks?.field)))continue;const h=a==="header"?t.headers??(t.headers={}):t.footers??(t.footers={});h[o]=c}return t}chromeParagraphs(e){if(["region-left","region-center","region-right"].map(n=>g(e,n)).filter(n=>!!n).length>0){const n=[];return["region-left","region-center","region-right"].forEach((s,a)=>{a>0&&n.push({type:"text",text:" ",marks:{}});const o=g(e,s);if(o)for(const l of b(o).filter(c=>c.localName==="p"))n.push(...this.chromeRuns(l))}),[P(E(n))]}const t=[];for(const n of b(e)){if(n.localName!=="p"&&n.localName!=="h")continue;const s=P(E(this.chromeRuns(n))),a=this.styles.resolvePara(r(n,"style-name"));a.align&&(s.align=a.align),t.push(s)}return t}chromeRuns(e){const t=this.collectInline(e,{chrome:!0,paragraphId:""}).filter(n=>n.kind==="run").map(n=>n.node);return t.length>0?t:[{type:"text",text:"",marks:{}}]}pageLayout(e){const t=r(e,"page-layout-name");if(!t||!this.stylesDoc)return;const n=w(this.stylesDoc.documentElement,"page-layout").find(a=>r(a,"name")===t),s=n?g(n,"page-layout-properties"):null;if(s)return Y({widthPx:k(r(s,"page-width")),heightPx:k(r(s,"page-height")),landscape:r(s,"print-orientation")==="landscape",marginTopPx:k(r(s,"margin-top")),marginRightPx:k(r(s,"margin-right")),marginBottomPx:k(r(s,"margin-bottom")),marginLeftPx:k(r(s,"margin-left"))})}}function H(f){const e=parseInt(f||"1",10);return Number.isFinite(e)?Math.min(Math.max(1,e),et):1}function it(f){for(;f.length>1;){const e=f[f.length-1];if(e.type==="paragraph"&&!e.borders&&e.children.every(t=>t.text.trim()===""&&!t.marks?.footnoteRef))f.pop();else break}}function lt(f){let e="";const t=n=>{if(n.nodeType===Node.TEXT_NODE){e+=(n.textContent??"").replace(/[\r\n]+/g,"");return}if(n.nodeType!==Node.ELEMENT_NODE)return;const s=n;s.localName==="s"?e+=" ".repeat(parseInt(r(s,"c")||"1",10)||1):s.localName==="tab"?e+=" ":s.localName==="line-break"?e+=`
6
+ `:s.childNodes.forEach(t)};return f.childNodes.forEach(t),e}function V(f,e){const{insertion:t,deletion:n,suggestionId:s,suggestionSource:a,suggestionAuthorType:o,suggestionLabel:l,suggestionCreatedAt:c,suggestionAuthorName:h,...d}=f;return{...d,...e}}function R(f){return f.replace(/^\.\//,"").replace(/^\//,"")}function ct(f){return f.replace(/&amp;/g,"&").replace(/&quot;/g,'"').replace(/&apos;/g,"'").replace(/&lt;/g,"<").replace(/&gt;/g,">")}function b(f){const e=[];return f.childNodes.forEach(t=>{t.nodeType===Node.ELEMENT_NODE&&e.push(t)}),e}function g(f,e){for(const t of b(f))if(t.localName===e)return t;return null}function M(f,e){if(f.localName===e)return f;for(const t of b(f)){const n=M(t,e);if(n)return n}return null}function w(f,e){const t=[],n=s=>{s.localName===e&&t.push(s);for(const a of b(s))n(a)};return n(f),t}function r(f,e){const t=f.attributes;for(let n=0;n<t.length;n++)if(t[n].localName===e)return t[n].value;return null}export{st as OdtConverter};
@@ -0,0 +1 @@
1
+ import{F as l,I as P,J as M,K as m,P as g,H as f,L as y,R as v,M as S}from"./index-D9_PwgOX.js";const k=new Set(["http","https","mailto","tel","ftp"]);function $(n){const t=n?.trim();if(!t)return;const e=t.replace(/[\u0000- \u007f]/g,"");if(e.startsWith("//")||e.startsWith("\\\\"))return;const r=/^([a-z][a-z0-9+.-]*):/i.exec(e)?.[1];if(!(r&&!k.has(r.toLowerCase())))return t}function j(n){return n/15}function d(n){return Math.round(n*100)/100}function A(n){if(!n)return;const t=/^\s*(-?\d*\.?\d+)\s*(pt|px|cm|mm|in|pc|em)\s*$/i.exec(n);if(!t)return;const e=parseFloat(t[1]);if(Number.isFinite(e))switch(t[2].toLowerCase()){case"px":return e;case"pt":return e*96/72;case"pc":return e*16;case"in":return e*96;case"cm":return e*96/2.54;case"mm":return e*96/25.4;case"em":return e*16;default:return}}function L(n){if(n>0)return m(n,{indentStepPx:g,storedAsUnits:!1})}function F(n){if(n<0)return-1;if(n>0)return m(n,{indentStepPx:g,storedAsUnits:!1,firstLine:!0})}function C(n){const t={};if(n.widthPx&&n.heightPx){const s=S(n.widthPx,n.heightPx);s&&N(s.pageSize,n)&&(t.pageSize=s.pageSize,t.orientation=n.landscape?"landscape":s.orientation)}const e=s=>s!==void 0&&Number.isFinite(s)&&s>=0&&s<=288?Math.round(s):void 0,r=e(n.marginTopPx),i=e(n.marginRightPx),a=e(n.marginBottomPx),c=e(n.marginLeftPx);return r!==void 0&&(t.marginTopPx=r),i!==void 0&&(t.marginRightPx=i),a!==void 0&&(t.marginBottomPx=a),c!==void 0&&(t.marginLeftPx=c),Object.keys(t).length>0?t:void 0}const I={letter:[8.5,11],tabloid:[11,17],legal:[8.5,14],statement:[5.5,8.5],executive:[7.25,10.5],folio:[8.5,13],a3:[11.69,16.54],a4:[8.27,11.69],a5:[5.83,8.27],b4:[9.84,13.9],b5:[6.93,9.84]};function N(n,t){const e=I[n];if(!e||!t.widthPx||!t.heightPx)return!1;const r=Math.min(t.widthPx,t.heightPx)/96,i=Math.max(t.widthPx,t.heightPx)/96;return Math.abs(r-e[0])<.25&&Math.abs(i-e[1])<.25}function z(n){if(!n)return;const t=n.trim().toLowerCase();if(/^#[0-9a-f]{6}$/.test(t))return t;if(/^#[0-9a-f]{3}$/.test(t))return"#"+t.slice(1).split("").map(e=>e+e).join("")}function W(n,t,e){const r=i=>Math.max(0,Math.min(255,Math.round(i))).toString(16).padStart(2,"0");return`#${r(n)}${r(t)}${r(e)}`}function E(n){let t="";for(let e=0;e<n.length;e+=32768)t+=String.fromCharCode.apply(null,Array.from(n.subarray(e,e+32768)));return btoa(t)}const R={png:"image/png",jpeg:"image/jpeg",gif:"image/gif",bmp:"image/bmp",webp:"image/webp",svg:"image/svg+xml",emf:"image/x-emf",wmf:"image/x-wmf"};function T(n){if(n.length<4)return;const t=n;if(t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71)return"png";if(t[0]===255&&t[1]===216)return"jpeg";if(t[0]===71&&t[1]===73&&t[2]===70)return"gif";if(t[0]===66&&t[1]===77)return"bmp";if(t.length>=12&&t[0]===82&&t[1]===73&&t[2]===70&&t[3]===70&&t[8]===87&&t[9]===69&&t[10]===66&&t[11]===80)return"webp";if(t.length>=44&&t[0]===1&&t[1]===0&&t[40]===32&&t[41]===69&&t[42]===77&&t[43]===70)return"emf";if(t[0]===215&&t[1]===205&&t[2]===198&&t[3]===154||(t[0]===1||t[0]===2)&&t[1]===0&&t[2]===9&&t[3]===0)return"wmf";const e=new TextDecoder("utf-8").decode(n.subarray(0,256));if(/<svg[\s>]/i.test(e)||/^\s*<\?xml[^>]*>\s*(<!--[\s\S]*?-->\s*)*<svg/i.test(e))return"svg"}function B(n,t,e,r={}){const i=`data:${R[t]};base64,${E(n)}`,a=Math.max(1,Math.round(e.width&&e.width>0?e.width:200)),c=Math.max(1,Math.round(e.height&&e.height>0?e.height:200)),s={type:"image",id:f(),src:i,width:a,height:c};return r.alt&&(s.alt=r.alt),r.align&&(s.align=r.align),(t==="emf"||t==="wmf")&&(s.originalFormat=t,s.originalDataUrl=i),s}function p(){return{type:"table-cell",id:f(),children:[l()]}}const x=1e3,D=1e5;function b(n){return Math.max(1,Math.min(x,Math.floor(D/Math.max(1,n))))}function H(n,t={}){const e=n.filter(o=>o.children.length>0);if(e.length===0)return null;const r=b(e.length);for(const o of e)O(o,r);const i=y({children:e,columnWidths:[]}),a=i.cols;if(a===0)return null;for(let o=0;o<e.length;o++){let u=0;for(let h=0;h<a;h++)i.occupancy[o]?.[h]||u++;for(let h=0;h<u;h++)e[o].children.push(p())}let c=Array(a).fill(100/a);const s=t.columnWidths;if(s&&s.length===a&&s.every(o=>Number.isFinite(o)&&o>0)){const o=s.reduce((u,h)=>u+h,0);c=s.map(u=>d(u/o*100))}return{type:"table",id:f(),children:e,columnWidths:c,...t.hasHeader?{hasHeader:!0}:{}}}function O(n,t){const e=n.children;if(e.length>t){const i=e[t-1];for(const a of e.slice(t))i.children.push(...a.children);e.length=t}let r=0;e.forEach((i,a)=>{const c=t-r-(e.length-1-a),s=Math.min(i.colSpan??1,Math.max(1,c));s>1?i.colSpan=s:delete i.colSpan,r+=s})}class U{constructor(t){this.prefix=t,this.notes=[],this.counters={footnote:0,endnote:0}}add(t,e,r={}){this.counters[t]+=1;const i=`${this.prefix}-${this.notes.length+1}`,a=e.length>0?e:[l()];P(a),this.notes.push({type:"footnote",id:i,...t==="endnote"?{noteKind:"endnote"}:{},children:a});const{footnoteRef:c,superscript:s,subscript:o,...u}=r;return{type:"text",text:M(this.counters[t],t),marks:{...u,footnoteRef:i,superscript:!0}}}}function K(n,t,e,r){const i=e?.trim()===v;return{...n==="insertion"?{insertion:!0}:{deletion:!0},suggestionId:t,suggestionSource:i?"agent":"manual",suggestionAuthorType:i?"ai":"human",suggestionLabel:n==="insertion"?"Insert":"Delete",...r!==void 0&&Number.isFinite(r)?{suggestionCreatedAt:r}:{},...e?{suggestionAuthorName:e}:{}}}function J(n,t){const e=new Set,r=i=>{if(!i||typeof i!="object")return;if(Array.isArray(i)){i.forEach(r);return}const a=i;a.marks?.comment&&a.marks.comment.split(",").forEach(c=>e.add(c)),r(a.children)};return t.forEach(r),n.filter(i=>e.has(i.id)||i.anchorBlockId!==void 0||i.parentId!==void 0&&e.has(i.parentId))}function G(n){const t=[];for(const e of n){const r=t[t.length-1];r&&w(r.marks,e.marks)?r.text+=e.text:t.push({...e,...e.marks?{marks:{...e.marks}}:{}})}return t}function w(n,t){const e=n??{},r=t??{},i=new Set([...Object.keys(e),...Object.keys(r)]);for(const a of i)if(e[a]!==r[a])return!1;return!0}export{x as M,U as N,H as a,B as b,A as c,$ as d,p as e,F as f,w as g,W as h,K as i,b as j,J as k,L as l,G as m,z as n,C as p,d as r,T as s,j as t};
@@ -0,0 +1 @@
1
+ import{F as l,I as P,J as M,K as m,P as g,H as f,L as y,R as v,M as S}from"./index-DcIXw_KB.js";const k=new Set(["http","https","mailto","tel","ftp"]);function $(n){const t=n?.trim();if(!t)return;const e=t.replace(/[\u0000- \u007f]/g,"");if(e.startsWith("//")||e.startsWith("\\\\"))return;const r=/^([a-z][a-z0-9+.-]*):/i.exec(e)?.[1];if(!(r&&!k.has(r.toLowerCase())))return t}function j(n){return n/15}function d(n){return Math.round(n*100)/100}function A(n){if(!n)return;const t=/^\s*(-?\d*\.?\d+)\s*(pt|px|cm|mm|in|pc|em)\s*$/i.exec(n);if(!t)return;const e=parseFloat(t[1]);if(Number.isFinite(e))switch(t[2].toLowerCase()){case"px":return e;case"pt":return e*96/72;case"pc":return e*16;case"in":return e*96;case"cm":return e*96/2.54;case"mm":return e*96/25.4;case"em":return e*16;default:return}}function L(n){if(n>0)return m(n,{indentStepPx:g,storedAsUnits:!1})}function F(n){if(n<0)return-1;if(n>0)return m(n,{indentStepPx:g,storedAsUnits:!1,firstLine:!0})}function C(n){const t={};if(n.widthPx&&n.heightPx){const s=S(n.widthPx,n.heightPx);s&&N(s.pageSize,n)&&(t.pageSize=s.pageSize,t.orientation=n.landscape?"landscape":s.orientation)}const e=s=>s!==void 0&&Number.isFinite(s)&&s>=0&&s<=288?Math.round(s):void 0,r=e(n.marginTopPx),i=e(n.marginRightPx),a=e(n.marginBottomPx),c=e(n.marginLeftPx);return r!==void 0&&(t.marginTopPx=r),i!==void 0&&(t.marginRightPx=i),a!==void 0&&(t.marginBottomPx=a),c!==void 0&&(t.marginLeftPx=c),Object.keys(t).length>0?t:void 0}const I={letter:[8.5,11],tabloid:[11,17],legal:[8.5,14],statement:[5.5,8.5],executive:[7.25,10.5],folio:[8.5,13],a3:[11.69,16.54],a4:[8.27,11.69],a5:[5.83,8.27],b4:[9.84,13.9],b5:[6.93,9.84]};function N(n,t){const e=I[n];if(!e||!t.widthPx||!t.heightPx)return!1;const r=Math.min(t.widthPx,t.heightPx)/96,i=Math.max(t.widthPx,t.heightPx)/96;return Math.abs(r-e[0])<.25&&Math.abs(i-e[1])<.25}function z(n){if(!n)return;const t=n.trim().toLowerCase();if(/^#[0-9a-f]{6}$/.test(t))return t;if(/^#[0-9a-f]{3}$/.test(t))return"#"+t.slice(1).split("").map(e=>e+e).join("")}function W(n,t,e){const r=i=>Math.max(0,Math.min(255,Math.round(i))).toString(16).padStart(2,"0");return`#${r(n)}${r(t)}${r(e)}`}function E(n){let t="";for(let e=0;e<n.length;e+=32768)t+=String.fromCharCode.apply(null,Array.from(n.subarray(e,e+32768)));return btoa(t)}const R={png:"image/png",jpeg:"image/jpeg",gif:"image/gif",bmp:"image/bmp",webp:"image/webp",svg:"image/svg+xml",emf:"image/x-emf",wmf:"image/x-wmf"};function T(n){if(n.length<4)return;const t=n;if(t[0]===137&&t[1]===80&&t[2]===78&&t[3]===71)return"png";if(t[0]===255&&t[1]===216)return"jpeg";if(t[0]===71&&t[1]===73&&t[2]===70)return"gif";if(t[0]===66&&t[1]===77)return"bmp";if(t.length>=12&&t[0]===82&&t[1]===73&&t[2]===70&&t[3]===70&&t[8]===87&&t[9]===69&&t[10]===66&&t[11]===80)return"webp";if(t.length>=44&&t[0]===1&&t[1]===0&&t[40]===32&&t[41]===69&&t[42]===77&&t[43]===70)return"emf";if(t[0]===215&&t[1]===205&&t[2]===198&&t[3]===154||(t[0]===1||t[0]===2)&&t[1]===0&&t[2]===9&&t[3]===0)return"wmf";const e=new TextDecoder("utf-8").decode(n.subarray(0,256));if(/<svg[\s>]/i.test(e)||/^\s*<\?xml[^>]*>\s*(<!--[\s\S]*?-->\s*)*<svg/i.test(e))return"svg"}function B(n,t,e,r={}){const i=`data:${R[t]};base64,${E(n)}`,a=Math.max(1,Math.round(e.width&&e.width>0?e.width:200)),c=Math.max(1,Math.round(e.height&&e.height>0?e.height:200)),s={type:"image",id:f(),src:i,width:a,height:c};return r.alt&&(s.alt=r.alt),r.align&&(s.align=r.align),(t==="emf"||t==="wmf")&&(s.originalFormat=t,s.originalDataUrl=i),s}function p(){return{type:"table-cell",id:f(),children:[l()]}}const x=1e3,D=1e5;function b(n){return Math.max(1,Math.min(x,Math.floor(D/Math.max(1,n))))}function H(n,t={}){const e=n.filter(o=>o.children.length>0);if(e.length===0)return null;const r=b(e.length);for(const o of e)O(o,r);const i=y({children:e,columnWidths:[]}),a=i.cols;if(a===0)return null;for(let o=0;o<e.length;o++){let u=0;for(let h=0;h<a;h++)i.occupancy[o]?.[h]||u++;for(let h=0;h<u;h++)e[o].children.push(p())}let c=Array(a).fill(100/a);const s=t.columnWidths;if(s&&s.length===a&&s.every(o=>Number.isFinite(o)&&o>0)){const o=s.reduce((u,h)=>u+h,0);c=s.map(u=>d(u/o*100))}return{type:"table",id:f(),children:e,columnWidths:c,...t.hasHeader?{hasHeader:!0}:{}}}function O(n,t){const e=n.children;if(e.length>t){const i=e[t-1];for(const a of e.slice(t))i.children.push(...a.children);e.length=t}let r=0;e.forEach((i,a)=>{const c=t-r-(e.length-1-a),s=Math.min(i.colSpan??1,Math.max(1,c));s>1?i.colSpan=s:delete i.colSpan,r+=s})}class U{constructor(t){this.prefix=t,this.notes=[],this.counters={footnote:0,endnote:0}}add(t,e,r={}){this.counters[t]+=1;const i=`${this.prefix}-${this.notes.length+1}`,a=e.length>0?e:[l()];P(a),this.notes.push({type:"footnote",id:i,...t==="endnote"?{noteKind:"endnote"}:{},children:a});const{footnoteRef:c,superscript:s,subscript:o,...u}=r;return{type:"text",text:M(this.counters[t],t),marks:{...u,footnoteRef:i,superscript:!0}}}}function K(n,t,e,r){const i=e?.trim()===v;return{...n==="insertion"?{insertion:!0}:{deletion:!0},suggestionId:t,suggestionSource:i?"agent":"manual",suggestionAuthorType:i?"ai":"human",suggestionLabel:n==="insertion"?"Insert":"Delete",...r!==void 0&&Number.isFinite(r)?{suggestionCreatedAt:r}:{},...e?{suggestionAuthorName:e}:{}}}function J(n,t){const e=new Set,r=i=>{if(!i||typeof i!="object")return;if(Array.isArray(i)){i.forEach(r);return}const a=i;a.marks?.comment&&a.marks.comment.split(",").forEach(c=>e.add(c)),r(a.children)};return t.forEach(r),n.filter(i=>e.has(i.id)||i.anchorBlockId!==void 0||i.parentId!==void 0&&e.has(i.parentId))}function G(n){const t=[];for(const e of n){const r=t[t.length-1];r&&w(r.marks,e.marks)?r.text+=e.text:t.push({...e,...e.marks?{marks:{...e.marks}}:{}})}return t}function w(n,t){const e=n??{},r=t??{},i=new Set([...Object.keys(e),...Object.keys(r)]);for(const a of i)if(e[a]!==r[a])return!1;return!0}export{x as M,U as N,H as a,B as b,A as c,$ as d,p as e,F as f,w as g,W as h,K as i,b as j,J as k,L as l,G as m,z as n,C as p,d as r,T as s,j as t};
@@ -0,0 +1,21 @@
1
+ import{ba as Ft,bb as oe,bc as re,aB as se,an as bt,bd as Pt,Y as le,be as ce,bf as Ht,bg as Nt,bh as Gt,bi as zt,av as Ut,bj as Kt,bk as Rt,bl as jt,aI as Yt,bm as he,bn as ge,bo as de,bp as fe,T as me,bq as Pe,br as ue,bs as pe,bt as Te,bu as xe,bv as be,bw as _e,bx as ye,by as Fe,J as $t,bz as tt,bA as Vt,bB as Se,bC as Le,bD as St,bE as we,bF as Oe,bG as Ce,ak as Me,bH as Zt,bI as ke,bJ as vt,bK as Lt,aR as It,_ as Ne,$ as Re,bL as Jt,bM as ve,bN as Bt,bO as Qt,bP as qt,bQ as Ie,bR as Be,bS as Ee,az as De,bT as Et,b7 as Xe,L as Ae,bU as We,bV as He,aV as Ge,bW as ze,bX as dt,bY as te,Q as ee,bZ as Ue,b_ as Ke,b$ as je,c0 as ae,c1 as ie,c2 as Ye,c3 as $e,c4 as Ve,c5 as Ze,c6 as Je,c7 as Qe,c8 as qe,aH as ta,F as wt,c9 as ea,ar as aa,as as ia,ca as Dt,cb as na,cc as oa,cd as ra,ce as sa,cf as la,cg as Xt,ch as ca,ci as ne,b8 as ha,cj as ga}from"./index-DcIXw_KB.js";const kt=new Map;oe(()=>kt.clear());function da(it){const t=String.fromCharCode(...it.subarray(0,4));return it[0]===0&&it[1]===1&&it[2]===0&&it[3]===0||t==="true"||t==="OTTO"}function fa(it){let t="";for(let e=0;e<it.length;e+=32768)t+=String.fromCharCode(...it.subarray(e,e+32768));return btoa(t)}async function ma(it){try{const t=await fetch(Ft(`fonts/${encodeURIComponent(it)}`),{credentials:"omit"});if(!t.ok)return null;const e=new Uint8Array(await t.arrayBuffer());return da(e)?fa(e):null}catch{return null}}async function Pa(it){let t=kt.get(it);return t||(t=ma(it),kt.set(it,t),t.then(e=>{e===null&&kt.delete(it)})),t}const J=it=>({normal:it,bold:it}),ua={japanese:{family:"NotoSansJP",probeCodePoint:12354,charRegex:/[\p{Script=Hiragana}\p{Script=Katakana}]/u,files:J("NotoSansJP-Regular.ttf")},korean:{family:"NotoSansKR",probeCodePoint:54620,charRegex:/\p{Script=Hangul}/u,files:J("NotoSansKR-Regular.ttf")},devanagari:{family:"NotoSansDevanagari",probeCodePoint:2309,charRegex:/\p{Script=Devanagari}/u,files:J("NotoSansDevanagari-Regular.ttf"),shape:!0},bengali:{family:"NotoSansBengali",probeCodePoint:2437,charRegex:/\p{Script=Bengali}/u,files:J("NotoSansBengali-Regular.ttf"),shape:!0},gurmukhi:{family:"NotoSansGurmukhi",probeCodePoint:2565,charRegex:/\p{Script=Gurmukhi}/u,files:J("NotoSansGurmukhi-Regular.ttf"),shape:!0},gujarati:{family:"NotoSansGujarati",probeCodePoint:2693,charRegex:/\p{Script=Gujarati}/u,files:J("NotoSansGujarati-Regular.ttf"),shape:!0},oriya:{family:"NotoSansOriya",probeCodePoint:2821,charRegex:/\p{Script=Oriya}/u,files:J("NotoSansOriya-Regular.ttf"),shape:!0},tamil:{family:"NotoSansTamil",probeCodePoint:2949,charRegex:/\p{Script=Tamil}/u,files:J("NotoSansTamil-Regular.ttf"),shape:!0},telugu:{family:"NotoSansTelugu",probeCodePoint:3077,charRegex:/\p{Script=Telugu}/u,files:J("NotoSansTelugu-Regular.ttf"),shape:!0},kannada:{family:"NotoSansKannada",probeCodePoint:3205,charRegex:/\p{Script=Kannada}/u,files:J("NotoSansKannada-Regular.ttf"),shape:!0},malayalam:{family:"NotoSansMalayalam",probeCodePoint:3333,charRegex:/\p{Script=Malayalam}/u,files:J("NotoSansMalayalam-Regular.ttf"),shape:!0},sinhala:{family:"NotoSansSinhala",probeCodePoint:3461,charRegex:/\p{Script=Sinhala}/u,files:J("NotoSansSinhala-Regular.ttf"),shape:!0},thai:{family:"NotoSansThai",probeCodePoint:3585,charRegex:/\p{Script=Thai}/u,files:J("NotoSansThai-Regular.ttf"),shape:!0},lao:{family:"NotoSansLao",probeCodePoint:3713,charRegex:/\p{Script=Lao}/u,files:J("NotoSansLao-Regular.ttf"),shape:!0},khmer:{family:"NotoSansKhmer",probeCodePoint:6016,charRegex:/\p{Script=Khmer}/u,files:J("NotoSansKhmer-Regular.ttf"),shape:!0},myanmar:{family:"NotoSansMyanmar",probeCodePoint:4096,charRegex:/\p{Script=Myanmar}/u,files:J("NotoSansMyanmar-Regular.ttf"),shape:!0},tibetan:{family:"NotoSerifTibetan",probeCodePoint:3904,charRegex:/\p{Script=Tibetan}/u,files:J("NotoSerifTibetan-Regular.ttf"),shape:!0},ethiopic:{family:"NotoSansEthiopic",probeCodePoint:4608,charRegex:/\p{Script=Ethiopic}/u,files:J("NotoSansEthiopic-Regular.ttf")},armenian:{family:"NotoSansArmenian",probeCodePoint:1329,charRegex:/\p{Script=Armenian}/u,files:J("NotoSansArmenian-Regular.ttf")},georgian:{family:"NotoSansGeorgian",probeCodePoint:4304,charRegex:/\p{Script=Georgian}/u,files:J("NotoSansGeorgian-Regular.ttf")},syriac:{family:"NotoSansSyriac",probeCodePoint:1808,charRegex:/\p{Script=Syriac}/u,files:J("NotoSansSyriac-Regular.ttf"),shape:!0},thaana:{family:"NotoSansThaana",probeCodePoint:1920,charRegex:/\p{Script=Thaana}/u,files:J("NotoSansThaana-Regular.ttf"),shape:!0},arabic:{family:"NotoNaskhArabic",probeCodePoint:1575,charRegex:/[\u0600-\u06FF\u0750-\u077F\u08A0-\u08FF\uFB50-\uFDFF\uFE70-\uFEFF]/,files:{normal:"NotoNaskhArabic-Regular.ttf",bold:"NotoNaskhArabic-Bold.ttf"}},hebrew:{family:"NotoSansHebrew",probeCodePoint:1488,charRegex:/[\u0590-\u05FF\uFB1D-\uFB4F]/,files:{normal:"NotoSansHebrew-Regular.ttf",bold:"NotoSansHebrew-Bold.ttf"}},cjkExtensionB:{family:"HanExtBSubset",probeCodePoint:131079,charRegex:/[\u{20000}-\u{207FF}]/u,files:J("HanExtBSubset-Regular.ttf"),shape:!0},han:{family:"NotoSansSC",probeCodePoint:20013,charRegex:/[\p{Script=Han}\p{Script=Bopomofo}\u3000-\u303F\uFE30-\uFE4F\uFF00-\uFFEF]/u,files:J("NotoSansSC-Regular.ttf")},emoji:{family:"NotoEmoji",probeCodePoint:128512,charRegex:/[\p{Extended_Pictographic}\p{Regional_Indicator}]/u,files:J("NotoEmoji-Regular.ttf"),shape:!0},arrows:{family:"NotoSansSymbols",probeCodePoint:8592,charRegex:/[\u2190-\u21FF]/u,files:J("NotoSansSymbols-Regular.ttf")},symbols:{family:"NotoSansSymbols2",probeCodePoint:9728,charRegex:/[\u2300-\u23FF\u2460-\u24FF\u25A0-\u27BF\u2B00-\u2BFF\u{1F000}-\u{1F2FF}]/u,files:J("NotoSansSymbols2-Regular.ttf"),shape:!0}},v=class st{static async ensureAllLatexRendered(t){const e=[],a=new Set,i=(n,l)=>{const o=`${l}:${n}`;!a.has(o)&&n.trim()&&(a.add(o),e.push({content:n,displayMode:l}))},r=n=>{if(!n||typeof n!="object")return;if(Array.isArray(n)){n.forEach(r);return}const l=n;l.type==="math"&&l.content?i(l.content,l.displayMode!=="inline"):l.type==="text"&&l.marks?.latex&&l.text&&i(l.text,!1),r(l.children)};r(t.children),r(t.chrome),r(t.notes),await Promise.all(e.map(n=>le(n.content,n.displayMode)))}static getLatexSvgFromCache(t,e){return ce(t,e)}static async svgToPng(t,e,a,i=3){return new Promise(r=>{const n=new Image,l="data:image/svg+xml;charset=utf-8,"+encodeURIComponent(t);n.onload=()=>{try{const o=document.createElement("canvas");o.width=e*i,o.height=a*i;const h=o.getContext("2d");if(!h){r(null);return}h.scale(i,i),h.drawImage(n,0,0,e,a),r(o.toDataURL("image/png"))}catch(o){console.error("Failed to convert SVG to PNG:",o),r(null)}},n.onerror=()=>{r(null)},n.src=l})}static async loadFontFile(t,e=!0){const a=Ft(`fonts/${t}`),i=this.fontFileData.get(a);if(i!==void 0)return i;const r=await Pa(t);let n=r??null;try{if(r===void 0){const l=await fetch(Ft(`fonts/${t}`));if(l.ok){const o=await l.arrayBuffer();Ht(new Uint8Array(o))==="ttf"&&(n=this.arrayBufferToBase64(o))}}}catch{}return n||(n=await this.readFontFromDisk(t)),!n&&e&&console.warn(`Failed to load font ${t}; PDF export used a fallback font. Embedded editors: if revise.io is unreachable, mirror the fonts and call setAssetBaseUrl().`),this.fontFileData.set(a,n),n}static async readFontFromDisk(t){try{const{readFile:e}=await import("./__vite-browser-external-l0sNRNKZ.js"),{join:a}=await import("./__vite-browser-external-l0sNRNKZ.js"),i=[a(process.cwd(),"public","fonts",t),a(process.cwd(),"frontend","public","fonts",t),a(process.cwd(),"..","frontend","public","fonts",t),a(process.cwd(),"..","..","frontend","public","fonts",t)];for(const r of i)try{return(await e(r)).toString("base64")}catch{}}catch{}return null}static async loadSourceCodePro(t){const e=await this.loadFontFile("SourceCodePro-Regular.ttf",!1);return e?(t.addFileToVFS("SourceCodePro-Regular.ttf",e),t.addFont("SourceCodePro-Regular.ttf","SourceCodePro","normal"),!0):!1}static async loadKaTeXMain(t){const e=[{file:"KaTeX_Main-Regular.ttf",style:"normal"},{file:"KaTeX_Main-Bold.ttf",style:"bold"},{file:"KaTeX_Main-Italic.ttf",style:"italic"},{file:"KaTeX_Main-BoldItalic.ttf",style:"bolditalic"}],a=await Promise.all(e.map(async i=>{const r=await this.loadFontFile(i.file);return r?{...i,base64:r}:null}));for(const i of a)i&&(t.addFileToVFS(i.file,i.base64),t.addFont(i.file,"KaTeX_Main",i.style));return a[0]!==null}static async embedBundledGenreFonts(t,e,a){this.bundledGenreFamilies.clear();const i=new Set,r=n=>{const l=this.mapFontFamilyToStandard(n);this.BUNDLED_GENRE_FONTS[l]&&i.add(l)};r(a);for(const n of Nt(e))r(n.value);for(const n of i){const l=this.BUNDLED_GENRE_FONTS[n],o=await Promise.all(Object.entries(l.files).map(async([h,s])=>({style:h,file:s,base64:await this.loadFontFile(s)})));if(!o.some(h=>!h.base64)){for(const{style:h,file:s,base64:g}of o)t.addFileToVFS(s,g),t.addFont(s,l.family,h);this.bundledGenreFamilies.set(n,l.family)}}}static documentFallbackScripts(t){const e=new Set,a=Object.keys(this.SCRIPT_FALLBACK_FONTS),i=r=>{if(e.size===a.length||!r||typeof r!="object")return;if(Array.isArray(r)){r.forEach(i);return}const n=r;if(typeof n.text=="string"&&n.text)for(const l of a)!e.has(l)&&this.SCRIPT_FALLBACK_FONTS[l].charRegex.test(n.text)&&e.add(l);i(n.children)};return i(t.children),i(t.chrome),i(t.notes),e}static splitDocumentFallbackRuns(t,e){const a=Object.entries(this.SCRIPT_FALLBACK_FONTS),i=s=>{const g=a.filter(([,P])=>P.charRegex.test(s)).map(([P])=>P);if(g.length>1&&e){const P=s.codePointAt(0)??0,c=g.find(f=>e(f,P));if(c)return c}return g[0]},r=/[\p{Letter}\p{Number}]/u,n=this.SCRIPT_FALLBACK_FONTS.japanese.charRegex,l=this.SCRIPT_FALLBACK_FONTS.korean.charRegex,o=s=>{const g=s.text??"";if(!g)return[{...s}];const P=[];let c="",f=null;for(const d of g.split(/(\s+)/)){const T=n.test(d)?"japanese":l.test(d)?"korean":null;for(const m of d){let x=i(m);if(x==="han"&&T&&(x=T),!x&&r.test(m)&&(x="base"),!x){f?f.text+=m:c+=m;continue}!f||f.key!==x?(f&&P.push(f),f={key:x,text:c+m},c=""):f.text+=m}}return f?(f.text+=c,P.push(f)):P.push({key:"base",text:c}),P.map(d=>{if(d.key==="base")return{...s,text:d.text};const T=this.SCRIPT_FALLBACK_FONTS[d.key];return{...s,text:d.text,marks:{...s.marks,fontFamily:T.family}}})},h=s=>Array.isArray(s)?s.flatMap(g=>g&&typeof g=="object"&&g.type==="text"?o(g):[h(g)]):!s||typeof s!="object"?s:Object.fromEntries(Object.entries(s).map(([g,P])=>[g,h(P)]));return h(t)}static async loadFallbackCoverage(t){const e=Object.entries(this.SCRIPT_FALLBACK_FONTS),a=new Set,i=new Set,r=l=>{if(!l||typeof l!="object")return;if(Array.isArray(l)){l.forEach(r);return}const o=l;if(typeof o.text=="string")for(const h of o.text){if(i.has(h)||h.charCodeAt(0)<128)continue;i.add(h);const s=e.filter(([,g])=>g.charRegex.test(h));s.length>1&&s.forEach(([g])=>a.add(g))}r(o.children)};r(t.children),r(t.chrome),r(t.notes);const n=new Map;for(const l of a){const o=this.SCRIPT_FALLBACK_FONTS[l].files.normal;let h=this.fallbackCharsetCache.get(o);if(h===void 0){h=null;const s=await this.loadFontFile(o,!1);if(s)try{const g=(await import("./browser-module-BVdVmrPb.js")).create(Gt(s));h=new Set(g.characterSet??[])}catch{h=null}this.fallbackCharsetCache.set(o,h)}h&&n.set(l,h)}return(l,o)=>{const h=n.get(l);return h?h.has(o):!0}}static async embedScriptFallbackFonts(t,e){this.scriptFallbackFamilies.clear(),this.shapingFonts.clear();for(const a of this.documentFallbackScripts(e)){const i=await this.registerScriptFallbackFace(t,a);i&&this.scriptFallbackFamilies.set(a,i)}}static async registerScriptFallbackFace(t,e){const a=this.SCRIPT_FALLBACK_FONTS[e];if(!a)return null;const i=await this.loadFontFile(a.files.normal);if(!i)return null;const r=await this.loadFontFile(a.files.bold,!1);t.addFileToVFS(a.files.normal,i),r&&a.files.bold!==a.files.normal&&t.addFileToVFS(a.files.bold,r);const n=r?a.files.bold:a.files.normal;if(t.addFont(a.files.normal,a.family,"normal"),t.addFont(n,a.family,"bold"),t.addFont(a.files.normal,a.family,"italic"),t.addFont(n,a.family,"bolditalic"),a.shape&&!this.shapingFonts.has(a.family))try{const[l,o]=await Promise.all([import("./browser-module-BVdVmrPb.js"),import("./_revise-sdk-lazy-harfbuzz-X8gnYTZL.js")]),h=o,s=h.loadHarfBuzz?await h.loadHarfBuzz():o,g=Gt(i),P=l.create(g),c=new s.Blob(g),f=new s.Face(c),d=new s.Font(f);this.shapingFonts.set(a.family,{unitsPerEm:f.upem,notdefPathCommands:P.getGlyph(0).path.commands,layout:T=>{const m=new s.Buffer;m.addText(T),m.guessSegmentProperties(),s.shape(d,m);const x=m.getGlyphInfosAndPositions(),F=x.map(b=>({xAdvance:b.xAdvance??0,yAdvance:b.yAdvance??0,xOffset:b.xOffset??0,yOffset:b.yOffset??0}));return{glyphs:x.map(b=>P.getGlyph(b.codepoint)),positions:F,advanceWidth:F.reduce((b,E)=>b+E.xAdvance,0)}}})}catch(l){console.warn(`Failed to initialize PDF shaping for ${a.family}:`,l)}return a.family}static fontCoversCodePoint(t,e,a){const i=`${e}:${a}`;let r=this.scriptFontCoverageCache.get(i);if(r===void 0){let n;try{n=t.getFont(e,"normal")}catch{n=void 0}r=!!n?.metadata?.cmap?.unicode?.codeMap?.[a],this.scriptFontCoverageCache.set(i,r)}return r}static fontCoversMatchedChars(t,e,a,i){let r=!1;for(const n of a)if(i.test(n)&&(r=!0,!this.fontCoversCodePoint(t,e,n.codePointAt(0)??0)))return!1;return r}static scriptFallbackFor(t,e,a){if(!e||this.scriptFallbackFamilies.size===0)return null;let i=null;for(const[r,n]of Object.entries(this.SCRIPT_FALLBACK_FONTS)){const l=this.scriptFallbackFamilies.get(r);if(l&&n.charRegex.test(e)&&!this.fontCoversCodePoint(t,a,n.probeCodePoint)&&!this.fontCoversMatchedChars(t,a,e,n.charRegex)){if(this.fontCoversMatchedChars(t,l,e,n.charRegex))return l;i??(i=l)}}return i}static async registerDocumentFonts(t,e,a){await this.embedLocalFonts(t,e),await this.embedBundledGenreFonts(t,e,a),await this.embedScriptFallbackFonts(t,e);const i=this.documentUsesSourceCodePro(e)?await this.loadSourceCodePro(t):!1;return this.inlineCodeFontFamily=i?"SourceCodePro":"courier",this.documentUsesKaTeXMain(e)&&await this.loadKaTeXMain(t),{hasSourceCodePro:i}}static async registerCurrentPdfFonts(t,e){for(const[a,i]of this.bundledGenreFamilies){const r=this.BUNDLED_GENRE_FONTS[a];if(!r||r.family!==i)continue;const n=await Promise.all(Object.entries(r.files).map(async([l,o])=>({style:l,file:o,base64:await this.loadFontFile(o)})));for(const{style:l,file:o,base64:h}of n)h&&(t.addFileToVFS(o,h),t.addFont(o,i,l))}for(const a of this.scriptFallbackFamilies.keys())await this.registerScriptFallbackFace(t,a);e&&await this.loadSourceCodePro(t)}static documentUsesKaTeXMain(t){return Nt(t).some(e=>{const a=e.family.toLowerCase();return a.includes("katex")||a.includes("computer modern")||a.includes("computermodern")})}static documentUsesSourceCodePro(t){const e=[...t.children];for(;e.length>0;){const a=e.pop();if(!a||typeof a!="object")continue;const i=a;if(i.type==="code"||i.type==="text"&&typeof i.marks=="object"&&i.marks!==null&&i.marks.code===!0)return!0;Array.isArray(i.children)&&e.push(...i.children)}return!1}static createCanvasTextContext(){if(typeof document>"u")return null;const t=document.createElement("canvas").getContext("2d");if(!t)return null;let e=null;return{measureText:a=>({width:zt(a,e,i=>t.measureText(i).width)}),setFont:a=>{t.font=a,e=null},setMarkAdjustments:a=>{e=a}}}static resolveIndentStepPx(t){return this.resolvePdfLayoutMetrics(t).indentStepPx}static getDefaultPdfLayoutMetrics(){const t=Ut(void 0),e=Math.max(1,this.PAGE_WIDTH-this.MARGIN_LEFT-this.MARGIN_RIGHT);return{orientation:"portrait",pageWidthPt:this.PAGE_WIDTH,pageHeightPt:this.PAGE_HEIGHT,marginTopPt:this.MARGIN_TOP,marginRightPt:this.MARGIN_RIGHT,marginBottomPt:this.MARGIN_BOTTOM,marginLeftPt:this.MARGIN_LEFT,contentWidthPt:e,fullContentWidthPt:e,pageMarginLeftPt:this.MARGIN_LEFT,columnCount:1,columnGapPt:Rt(t.columnGapTwips),columnStridePt:Kt(e,Rt(t.columnGapTwips)),blockSpacingPt:t.blockSpacingPx*this.PX_TO_PT,indentStepPx:t.indentStepPx,showPageNumbers:t.showPageNumbers,pageBorders:t.pageBorders,pageNumberPosition:t.pageNumberPosition,pageNumberStart:t.pageNumberStart,pageNumberFormat:t.pageNumberFormat,hyphenationEnabled:t.hyphenationEnabled,lineNumbering:t.lineNumbering,pleadingGrid:t.pleadingGrid}}static resolvePdfLayoutMetrics(t){return this.resolvePdfMetricsFromSettings(t?.pageLayout,t?.pageLayout,!1)}static resolvePdfMetricsFromSettings(t,e,a=!1){const i=jt(e,t),r=t,{pageWidth:n,pageHeight:l}=Yt(i),o=n*this.PX_TO_PT,h=l*this.PX_TO_PT,s=i.marginTopPx*this.PX_TO_PT,g=i.marginRightPx*this.PX_TO_PT,P=i.marginBottomPx*this.PX_TO_PT,c=i.marginLeftPx*this.PX_TO_PT,f=Math.max(1,o-c-g),d=Math.max(1,i.columnCount),T=Rt(i.columnGapTwips),m=he(f,d,T);return{orientation:i.orientation,pageWidthPt:o,pageHeightPt:h,marginTopPt:s,marginRightPt:g,marginBottomPt:P,marginLeftPt:c,contentWidthPt:m,fullContentWidthPt:f,pageMarginLeftPt:c,columnCount:d,columnGapPt:T,columnStridePt:Kt(m,T),...d>1?{columnFlow:{index:0,topPt:s,pageOffset:0}}:{},blockSpacingPt:i.blockSpacingPx*this.PX_TO_PT,indentStepPx:i.indentStepPx,showPageNumbers:i.showPageNumbers,pageBorders:i.pageBorders,pageNumberPosition:i.pageNumberPosition,pageNumberStart:i.pageNumberStart,pageNumberStartExplicit:a&&r?.pageNumberStart!==void 0,pageNumberFormat:i.pageNumberFormat,hyphenationEnabled:i.hyphenationEnabled,lineNumbering:i.lineNumbering,pleadingGrid:i.pleadingGrid}}static physicalPageMetrics(t){return{...t,marginLeftPt:t.pageMarginLeftPt,contentWidthPt:t.fullContentWidthPt,columnFlow:void 0,reservedInsetForPage:void 0}}static computeEngineLayout(t){if(typeof document>"u")return null;const e=document.createElement("canvas").getContext("2d");if(!e)return null;const a=Ut(t.pageLayout),i=Yt(a),r=ge({pageWidth:i.pageWidth,pageHeight:i.pageHeight,pageMargin:a.marginLeftPx,pageMarginTop:a.marginTopPx,pageMarginRight:a.marginRightPx,pageMarginBottom:a.marginBottomPx,pageMarginLeft:a.marginLeftPx,availableWidth:Math.max(1,i.pageWidth-a.marginLeftPx-a.marginRightPx),textStartY:a.marginTopPx,indentStepPx:a.indentStepPx,blockSpacingPx:a.blockSpacingPx,hyphenationEnabled:a.hyphenationEnabled,lineNumbering:a.lineNumbering,columnCount:a.columnCount,columnGapPx:de(a.columnGapTwips),pageless:!1});try{return fe(t,me(e),r)}catch{return null}}static computeColumnBalanceTargets(t,e){const a=new Map,i=e.filter(g=>g.type==="section-break"),r=new Set;if(i.forEach((g,P)=>{const c=jt(t.pageLayout,g.layout);Pe(Math.max(1,c.columnCount),g.breakType==="continuous")&&r.add(P)}),r.size===0)return a;const n=this.computeEngineLayout(t);if(!n?.pageGeometries||n.pageGeometries.length===0)return a;const l=new Map(n.pageGeometries.map(g=>[g.pageIndex+1,g.pageTop])),o=(g,P)=>{if(!g||typeof g!="object")return;if(Array.isArray(g)){g.forEach(f=>o(f,P));return}const c=g;typeof c.id=="string"&&c.id&&P.add(c.id),o(c.children,P)},h=new Map;let s=0;for(const g of e){if(g.type==="section-break"){s+=1;continue}let P=h.get(s);P||(P=new Set,h.set(s,P)),o(g,P)}for(const g of r){const P=h.get(g);if(!P||P.size===0)continue;const c=n.fragments.filter(x=>!x.isChrome&&typeof x.pageNumber=="number"&&P.has(x.blockId));if(c.length===0)continue;let f=Number.POSITIVE_INFINITY,d=0;for(const x of c)f=Math.min(f,x.pageNumber),d=Math.max(d,x.pageNumber);const T=l.get(d);if(T===void 0)continue;let m=0;for(const x of c)x.pageNumber===d&&(m=Math.max(m,x.bounds.y+x.bounds.height-T));m<=0||a.set(g,{pageOffset:d-f,bottomPt:m*this.PX_TO_PT+this.COLUMN_BALANCE_SLACK_PT})}return a}static advancePdfColumnOrPage(t,e){const a=e.columnFlow;return!a||e.columnCount<=1?(t.addPage(),!0):a.index<e.columnCount-1?(a.index+=1,e.marginLeftPt=e.pageMarginLeftPt+a.index*e.columnStridePt,!1):(a.index=0,e.marginLeftPt=e.pageMarginLeftPt,t.addPage([e.pageWidthPt,e.pageHeightPt],e.orientation),a.topPt=e.marginTopPt,a.pageOffset+=1,!0)}static advancePdfFlowRegion(t,e){const a=this.advancePdfColumnOrPage(t,e);return{x:e.marginLeftPt,y:a?e.marginTopPt:e.columnFlow?.topPt??e.marginTopPt}}static declaredSpacingPx(t,e){const a=t?.[e];return typeof a=="number"&&Number.isFinite(a)?Math.max(0,a):void 0}static pdfSpaceBeforePt(t,e,a){const i=ue(a,t)??st.declaredSpacingPx(t,"spaceBefore");return i!==void 0?i*st.PX_TO_PT:e.blockSpacingPt}static pdfSpaceAfterPt(t,e){const a=pe(t,e)??st.declaredSpacingPx(t,"spaceAfter");return a!==void 0?a*st.PX_TO_PT:0}static syncPdfColumnOffset(t){const e=t.columnFlow;!e||t.columnCount<=1||(t.marginLeftPt=t.pageMarginLeftPt+e.index*t.columnStridePt)}static getPdfReservedInsetPt(t,e){return e.reservedInsetForPage?.get(this.getPdfCurrentPage(t))??0}static getPdfWritableBottomPt(t,e){return e.pageHeightPt-e.marginBottomPt-this.getPdfReservedInsetPt(t,e)}static getPdfFlowBottom(t,e){const a=this.getPdfWritableBottomPt(t,e),i=e.columnFlow;return!i?.balance||e.columnCount<=1||i.pageOffset!==i.balance.pageOffset?a:Math.min(a,i.balance.bottomPt)}static getPdfPageCount(t){return typeof t.getNumberOfPages=="function"?t.getNumberOfPages():typeof t.internal?.getNumberOfPages=="function"?t.internal.getNumberOfPages():1}static getPdfCurrentPage(t){return t.getCurrentPageInfo?.().pageNumber??this.getPdfPageCount(t)}static createPdfPageNumbering(t,e,a){const i=[...e?.keys()??[]].sort((o,h)=>o-h),r=o=>{let h=t;for(const s of i){if(s>o)break;h=e.get(s)}return h},n=[],l=o=>{const h=Math.max(1,Math.floor(o));for(let s=n.length+1;s<=h;s++){const g=r(s);n.push(s===1||a?.has(s)&&g.pageNumberStartExplicit?g.pageNumberStart:n[s-2]+1)}return n[h-1]};return{metricsForPage:r,numberForPage:l,labelForPage:o=>Te(l(o),r(o).pageNumberFormat)}}static async renderHeaderFooterChrome(t,e,a,i,r,n){const l=this.getPdfPageCount(t),o=f=>{if(!r)return a;let d=a,T=0;for(const[m,x]of r)m<=f&&m>T&&(d=x,T=m);return d},h=f=>{if(!n)return 0;let d=0,T=0;for(const[m,x]of n)m<=f&&m>T&&(d=x,T=m);return d},s=f=>{if(!n)return 1;let d=1;for(const[T]of n)T<=f&&T>d&&(d=T);return d},g=this.createPdfPageNumbering(a,r,n).labelForPage,P=(f,d)=>{if(e.chrome&&e.chrome.length>0)return ea(e.chrome,f,d,h(d));const T=f==="header"?e.headers:e.footers;if(!T)return;const m=d===s(d)&&T.first?"first":d%2===0&&T.even?"even":"default",x=T[m];if(x)return aa(f,m,ia(x),i)},c=async(f,d,T)=>{const m=o(T),x=f.children.slice(0,3).map((k,I)=>{const u=Dt[I];return{...k,...u&&!k.align?{align:u}:{},children:k.children.map(p=>p.type!=="text"||!p.marks?.field?p:p.marks.field==="page"?{...p,text:g(T)}:{...p,text:String(l)})}});for(;x.length<3;){const k=x.length;x.push({type:"paragraph",id:`${f.id}-pdf-column-${k}`,children:[{type:"text",text:""}],...Dt[k]?{align:Dt[k]}:{}})}const F=this.createLayoutForWrapping(m.contentWidthPt,m.indentStepPx,m),b=this.createCanvasTextContext(),E=b?na(f,b,F,e,x).map(k=>k*this.PX_TO_PT):[m.contentWidthPt/3,m.contentWidthPt/3,m.contentWidthPt/3],R=d?Math.max(10*this.PX_TO_PT,m.marginTopPt/2):m.pageHeightPt-Math.max(10*this.PX_TO_PT,m.marginBottomPt/2);let B=m.marginLeftPt;for(let k=0;k<3;k++){const I=x[k],u=E[k],p=this.measureParagraphLineAdvances(I,u,m.indentStepPx,m).reduce((C,D)=>C+D,0),S=R-p/2,w={...m,marginTopPt:S,marginLeftPt:B,marginRightPt:Math.max(0,m.pageWidthPt-B-u),contentWidthPt:Math.max(1,u)};await this.renderParagraph(t,I,S,u,i,1e9,m.indentStepPx,w),B+=u}};for(let f=0;f<l;f++){const d=f+1;t.setPage(d);const T=P("header",d),m=P("footer",d);T&&await c(T,!0,d),m&&await c(m,!1,d),await this.drawChromeImages(t,e,o(d),d,h(d))}this.renderPageNumbers(t,a,i,o,g,(f,d)=>!!P(d,f));for(let f=1;f<=l;f++){const d=o(f),T=xe(d.pageBorders,d.pageWidthPt,d.pageHeightPt,{top:d.marginTopPt,right:d.marginRightPt,bottom:d.marginBottomPt,left:d.pageMarginLeftPt},f===s(f));if(!T.length)continue;t.setPage(f);const m=t.internal?.pages?.[f],x=m?.length??0;t.saveGraphicsState(),t.setLineCap?.("square");for(const F of T){t.setDrawColor(F.color),t.setLineWidth(F.style==="double"?F.widthPt/3:F.widthPt),t.setLineDashPattern(F.style==="dotted"?[F.widthPt,F.widthPt*2]:F.style==="dashed"?[F.widthPt*4,F.widthPt*2]:[],0);for(const b of F.style==="double"?[-F.widthPt/3,F.widthPt/3]:[0]){const E=F.x1===F.x2?b:0,R=F.y1===F.y2?b:0;t.line(F.x1+E,F.y1+R,F.x2+E,F.y2+R)}}t.restoreGraphicsState(),d.pageBorders?.zOrder==="back"&&m&&m.unshift(...m.splice(x))}}static async drawChromeImages(t,e,a,i,r){if(!e.chromeImages?.length)return;const n=be({chrome:e.chrome??[],records:e.chromeImages,pageNumber:i,isFirstPage:i===1,sectionIndex:r,pageWidth:a.pageWidthPt,pageHeight:a.pageHeightPt,marginTop:a.marginTopPt,marginBottom:a.marginBottomPt,marginLeft:a.pageMarginLeftPt,marginRight:Math.max(0,a.pageWidthPt-a.pageMarginLeftPt-a.fullContentWidthPt),unit:this.PX_TO_PT});for(const l of n){const o=await this.resolveImageDataCached(t,l.src);if(o)try{t.addImage(o.data,o.format,l.x,l.y,l.width,l.height)}catch(h){console.error("Failed to add header/footer image to PDF",h)}}}static drawWatermarkOnPage(t,e,a,i){t.setFont("helvetica","normal");const r=_e(e,a/this.PX_TO_PT,i/this.PX_TO_PT,(x,F)=>{t.setFontSize(F*this.PX_TO_PT);const b=t.getTextWidth(x);return typeof b=="number"?b/this.PX_TO_PT:0})*this.PX_TO_PT;t.setFontSize(r);const n=t.getTextWidth(e.text),l=this.hexToRgb(e.color);t.setTextColor(l.r,l.g,l.b);const o=typeof t.saveGraphicsState=="function"&&typeof t.setGState=="function"&&typeof t.GState=="function";o&&(t.saveGraphicsState(),t.setGState(new t.GState({opacity:e.opacity})));const h=e.diagonal?Math.atan2(i,a):0,s=Math.cos(h),g=Math.sin(h),P=a/2,c=i/2,f=n/2,d=-.35*r,T=P-(f*s+d*g),m=c-(-f*g+d*s);t.text(e.text,T,m,{...h!==0?{angle:h*180/Math.PI}:{}}),o&&t.restoreGraphicsState()}static installWatermarkUnderpaint(t,e){const a=()=>{const r=t.internal?.pageSize,n=typeof r?.getWidth=="function"?r.getWidth():r?.width,l=typeof r?.getHeight=="function"?r.getHeight():r?.height;!n||!l||this.drawWatermarkOnPage(t,e,n,l)},i=t.addPage.bind(t);t.addPage=(...r)=>{const n=i(...r);return a(),n},a()}static renderBodyLineNumbers(t,e,a,i,r){const n=s=>{let g,P=0;for(const[c,f]of a)c<=s&&c>P&&(g=f,P=c);return g??this.resolvePdfLayoutMetrics(i)},l=this.getPdfPageCount(t),o=l;let h=!1;for(let s=1;s<=l;s++){const g=n(s),P=g.pleadingGrid;P&&(t.setPage(s),h=!0,this.renderPleadingGrid(t,P,g,r?.get(s)??P.fontFamily));const c=g.lineNumbering;if(!c||e.length===0)continue;let f=c.start;if(c.restart==="continuous")for(const T of e)T.pageNumber<s&&f++;t.setPage(s),h=!0,t.setFont(this.mapFontFamily(r?.get(s)),"normal"),t.setFontSize(10*this.PX_TO_PT),t.setTextColor(115,115,115);const d=g.marginLeftPt-(c.distancePx??12)*this.PX_TO_PT;for(const T of e){if(T.pageNumber!==s)continue;const m=f++;if(m%c.countBy!==0)continue;const x=T.baselineOffset??Math.min(T.height,12);t.text(String(m),d,T.y+x,{align:"right",baseline:"alphabetic"})}}h&&t.setPage(o)}static renderPleadingGrid(t,e,a,i){t.setFont(this.mapFontFamily(i??"Times New Roman"),"normal");const r=(e.fontSizePx??16)*this.PX_TO_PT;t.setFontSize(r),t.setTextColor(0,0,0);const n=e.firstBaselinePx!==void 0?e.firstBaselinePx*this.PX_TO_PT:a.marginTopPt+r,l=(a.pageMarginLeftPt??a.marginLeftPt)-(e.distancePx??14)*this.PX_TO_PT;for(let o=0;o<e.rows;o++)t.text(String(o+1),l,n+o*e.pitchPx*this.PX_TO_PT,{align:"right",baseline:"alphabetic"})}static lineBaselineOffsetPt(t,e){let a=0;for(const i of t){if(i.latexImage||i.marks?.latex)continue;const r=i.marks?.fontSize?i.marks.fontSize*this.PX_TO_PT:e;r>a&&(a=r)}return a||e}static renderPageNumbers(t,e,a,i,r,n){const l=this.getPdfPageCount(t),o=12,h=o/2+6;t.setFont(this.mapFontFamily(a),"normal"),t.setFontSize(o),t.setTextColor(0,0,0);for(let s=0;s<l;s++){const g=i?.(s+1)??e;if(!g.showPageNumbers)continue;const P=s+1,c=g.pageNumberPosition.startsWith("top");if(n?.(P,c?"header":"footer"))continue;const f=g.pageNumberPosition.endsWith("right"),d=f?g.pageWidthPt-g.marginRightPt:g.marginLeftPt,T=c?Math.max(h,g.marginTopPt/2):g.pageHeightPt-Math.max(h,g.marginBottomPt/2);t.setPage(P),t.text(r?.(P)??ye({pageNumberStart:e.pageNumberStart,pageNumberFormat:e.pageNumberFormat??"decimal"},s),d,T,{align:f?"right":"left"})}}static getParagraphLineIndentPt(t,e,a){return Fe(t,e,a)*this.PX_TO_PT}static createLayoutForWrapping(t,e,a=this.getDefaultPdfLayoutMetrics()){const i=t/this.PX_TO_PT;return{pageWidth:a.pageWidthPt/this.PX_TO_PT,pageHeight:a.pageHeightPt/this.PX_TO_PT,pageMargin:a.marginLeftPt/this.PX_TO_PT,pageMarginTop:a.marginTopPt/this.PX_TO_PT,pageMarginRight:a.marginRightPt/this.PX_TO_PT,pageMarginBottom:a.marginBottomPt/this.PX_TO_PT,pageMarginLeft:a.marginLeftPt/this.PX_TO_PT,pageSpacing:0,paragraphSpacing:0,availableWidth:i,textStartY:a.marginTopPt/this.PX_TO_PT,fontSize:16,fontFamily:this.DEFAULT_BODY_FONT,lineHeight:16*1.4,indentStepPx:e,pageless:!1,hyphenationEnabled:a.hyphenationEnabled}}static buildNumberedNoteEntries(t){const e=new Map,a=s=>{if(!s||typeof s!="object")return;if(Array.isArray(s)){s.forEach(a);return}const g=s;g.type!=="footnote"&&(g.marks?.footnoteRef&&!e.has(g.marks.footnoteRef)&&e.set(g.marks.footnoteRef,g.text??""),a(g.children))};a(t.children.filter(s=>s.type!=="footnote"));const i=[...t.notes??[],...t.children.filter(s=>s.type==="footnote")],r={footnote:0,endnote:0},n=new Map,l=new Map;for(const s of i)l.set(s.id,s.noteKind==="endnote"?"endnote":"footnote");for(const[s]of e){const g=l.get(s)??"footnote";r[g]+=1,n.set(s,$t(r[g],g))}const o=i.map(s=>{const g=l.get(s.id)??"footnote",P=n.get(s.id)||$t(r[g]+=1,g);return{footnoteId:s.id,number:P,kind:g,blocks:s.children}}),h=s=>{const g=[...n.keys()],P=g.indexOf(s.footnoteId);return P===-1?g.length:P};return o.sort((s,g)=>h(s)-h(g))}static async renderNoteEntry(t,e,a,i,r,n,l,o,h){o&&this.drawNoteNumeral(t,e.number,i.marginLeftPt,a,r);const s=tt.verticalPaddingPx*st.PX_TO_PT,g=tt.gutterPx*st.PX_TO_PT,P=a+s,c={...i,marginTopPt:i.marginTopPt+s,marginLeftPt:i.marginLeftPt+g,contentWidthPt:Math.max(1,i.contentWidthPt-g),blockSpacingPt:tt.blockSpacingPx*st.PX_TO_PT};if(h){const f=c.marginTopPt;Object.defineProperty(c,"marginTopPt",{get:()=>h.get(this.getPdfCurrentPage(t))??f})}return(await this.renderBodyBlocks(t,e.blocks,c,n,l,r,void 0,void 0,void 0,P)).finalY+s}static drawNoteNumeral(t,e,a,i,r){t.setFont(this.mapFontFamily(r),"normal"),t.setFontSize(Vt*this.PX_TO_PT),t.setTextColor(0,0,0),t.text(e,a+1.5,i+(6+Vt)*st.PX_TO_PT)}static mapFootnoteRefBlocks(t){const e=new Map,a=(i,r)=>{if(!i||typeof i!="object")return;if(Array.isArray(i)){i.forEach(l=>a(l,r));return}const n=i;n.marks?.footnoteRef&&!e.has(n.marks.footnoteRef)&&e.set(n.marks.footnoteRef,r),a(n.children,r)};for(const i of t)a(i,i.id??"");return e}static async renderBodyBlocks(t,e,a,i,r,n,l,o,h,s,g){const P=new Map,c=new Map([[1,0]]),f=[],d=[],T=Se(e);let m=s??a.marginTopPt,x=a.contentWidthPt,F=a.indentStepPx,b=!0;const E=new Map([[1,this.physicalPageMetrics(a)]]),R=()=>t.getCurrentPageInfo?.()?.pageNumber??t.getNumberOfPages();let B=0;const k=I=>{if(B=I,!g)return;const u=a.columnFlow;!u||a.columnCount<=1||(u.index=0,u.topPt=m,u.pageOffset=0,u.balance=g.balanceBySection.get(I),a.marginLeftPt=a.pageMarginLeftPt)};k(0);for(let I=0;I<e.length;I++){this.syncPdfColumnOffset(a);const u=e[I],p=this.getPdfFlowBottom(t,a);if(u.type==="page-break"){!b&&a.blockSpacingPt>0&&(m+=a.blockSpacingPt),u.id&&P.set(u.id,R()),t.addPage([a.pageWidthPt,a.pageHeightPt],a.orientation),a.columnFlow&&(a.columnFlow.index=0,a.columnFlow.topPt=a.marginTopPt,a.columnFlow.pageOffset+=1,a.marginLeftPt=a.pageMarginLeftPt),m=a.marginTopPt,b=!0;continue}if(u.type==="docx-raw"){const M=St.heightPx*.75,N=a.pageWidthPt-a.marginLeftPt-a.marginRightPt,G=Le(u,N/.75)*.75;!b&&a.blockSpacingPt>0&&(m+=a.blockSpacingPt),m+M>p&&(m=this.advancePdfFlowRegion(t,a).y),u.id&&P.set(u.id,R());const H=a.marginLeftPt;t.setDrawColor(107,114,128),t.setFillColor(243,244,246),t.setLineWidth(.75),t.roundedRect(H,m,G,M,St.cornerRadiusPx*.75,St.cornerRadiusPx*.75,"FD"),t.setFont("courier","normal"),t.setFontSize(St.fontPx*.75),t.setTextColor(107,114,128),t.text(we(u),H+St.paddingXPx*.75,m+M/2,{baseline:"middle"}),t.setTextColor(0,0,0),m+=M,b=!1;continue}if(u.type==="section-break"){u.id&&P.set(u.id,R());const M=l?.get(u.id),N=M?o?.(M)??M:void 0;if(N){const H=Oe(u.breakType==="continuous",{width:a.pageWidthPt,height:a.pageHeightPt},{width:N.pageWidthPt,height:N.pageHeightPt});a=N,x=N.contentWidthPt,F=N.indentStepPx,H?(m=Ce(m,a.blockSpacingPt,0,a.marginTopPt),m>this.getPdfWritableBottomPt(t,a)&&(t.addPage([a.pageWidthPt,a.pageHeightPt],a.orientation),m=a.marginTopPt)):(t.addPage([N.pageWidthPt,N.pageHeightPt],N.orientation),m=a.marginTopPt),E.set(R(),this.physicalPageMetrics(N))}else t.addPage(),m=a.marginTopPt;const G=h?.get(u.id);G!==void 0&&c.set(R(),G),k(B+1),b=!0;continue}if(u.type==="toc"){const M=a.blockSpacingPt;!b&&M>0&&(m+=M),b=!1,u.id&&P.set(u.id,R());const N=Me({children:e.map(y=>y.type==="paragraph"?this.paragraphForPdfOutput(y):y)},u),G=(u.fontSize??16)*this.PX_TO_PT,H=G*1.4,j=Zt.paddingYPx*this.PX_TO_PT;t.setFont(this.mapFontFamily(u.fontFamily??n),"normal"),t.setFontSize(G);const _=this.hexToRgb(u.color??"#000000");t.setTextColor(_.r,_.g,_.b),m+=j,N.length===0&&(m+H>p&&(m=this.advancePdfFlowRegion(t,a).y),m+=H);for(const y of N)m+H>p&&(m=this.advancePdfFlowRegion(t,a).y),d.push({pdfPage:R(),headingBlockId:y.blockId,block:u,entry:y,baseline:m+G,left:a.marginLeftPt,width:a.contentWidthPt,fontName:this.mapFontFamily(u.fontFamily??n),fontSizePt:G}),m+=H;m+=j;continue}const S=I>0?e[I-1]:void 0,w=st.pdfSpaceBeforePt(u,a,S)+st.pdfSpaceAfterPt(S,u);if(!b&&w>0?m+=w:b&&I===0&&a.keepFirstBlockDeclaredSpaceBefore&&(m+=(st.declaredSpacingPx(u,"spaceBefore")??0)*st.PX_TO_PT),b=!1,u.id&&u.type!=="paragraph"&&P.set(u.id,R()),u.type==="container"){const M=await this.renderContainerBlock(t,u,m,x,n,i,r,a);m=M.nextY;for(const[N,G]of M.blockStartPages)P.set(N,G);f.push(...M.lineMarks);continue}if(u.type==="placeholder"){m=this.advancePlaceholderBlock(t,u,m,a);continue}if(u.type==="image"){const M=await this.renderImageBlock(t,u,m,x,a);M&&(m=M.nextY);continue}if(u.type==="math"){const M=u;m=(await this.renderMathBlock(t,M,m,x,p,a)).nextY;continue}if(u.type==="list"){m=await this.renderListBlock(t,u,m,x,n,a,T.get(u.id),f);continue}if(u.type==="table"){m=await this.renderTableBlock(t,u,m,x,n,i,r,a);continue}if(u.type==="code"){m=await this.renderCodeBlock(t,u,m,x,p,a.marginLeftPt,i,r,a,f);continue}if(u.type!=="paragraph")continue;const C=u,{required:D,firstLineAdvance:V}=this.getRequiredParagraphStartHeight(e,I,x,F,a);D>0&&m+D>p&&a.marginTopPt+D<=p&&m!==a.marginTopPt&&(m=this.advancePdfFlowRegion(t,a).y),m+V>p&&m!==a.marginTopPt&&(m=this.advancePdfFlowRegion(t,a).y),C.id&&P.set(C.id,R()),m=await this.renderParagraph(t,C,m,x,n,p,F,a,f)}if(d.length>0){const I=R(),u=this.createPdfPageNumbering(E.get(1)??a,E,c).labelForPage;for(const p of d){t.setPage(p.pdfPage),t.setFont(p.fontName,"normal"),t.setFontSize(p.fontSizePt);const S=this.hexToRgb(p.block.color??"#000000");t.setTextColor(S.r,S.g,S.b);const w=P.get(p.headingBlockId),C=w!==void 0?u(w):"",D=ke(p.block,p.entry,p.left,p.width,C,V=>t.getTextWidth(V),this.PX_TO_PT);D.text&&t.text(D.text,D.textX,p.baseline,{align:D.align,...D.rtl?{isInputVisual:!1,isOutputVisual:!0,isInputRtl:!0,isOutputRtl:!1}:{}}),C&&D.leaderEnd-D.leaderStart>Zt.minimumLeaderWidthPx*this.PX_TO_PT&&(t.setDrawColor(150),typeof t.setLineDashPattern=="function"&&t.setLineDashPattern([.8,2.2],0),t.line(D.leaderStart,p.baseline,D.leaderEnd,p.baseline),typeof t.setLineDashPattern=="function"&&t.setLineDashPattern([],0),t.setDrawColor(0,0,0)),C&&t.text(C,D.numberX,p.baseline)}t.setPage(I)}return{blockStartPages:P,pageMetrics:E,pageSections:c,lineMarks:f,finalY:m}}static async renderContainerBlock(t,e,a,i,r,n,l,o){const h=Math.max(0,e.padding??vt.paddingPx)*this.PX_TO_PT,s=this.getPdfFlowBottom(t,o);a+h>s&&a!==o.marginTopPt&&(a=this.advancePdfFlowRegion(t,o).y);const g=()=>t.getCurrentPageInfo?.()?.pageNumber??t.getNumberOfPages(),P=g(),c=o.columnFlow?.index??0,f=o.columnFlow?.topPt??o.marginTopPt,d={...o,keepFirstBlockDeclaredSpaceBefore:void 0,marginTopPt:o.marginTopPt+h,marginRightPt:o.marginRightPt+h,marginBottomPt:o.marginBottomPt+h,marginLeftPt:o.marginLeftPt+h,contentWidthPt:Math.max(1,i-h*2),pageMarginLeftPt:o.pageMarginLeftPt+h},T=await this.renderBodyBlocks(t,e.children,d,n,l,r,void 0,void 0,void 0,a+h);let m=T.finalY+h;this.syncPdfColumnOffset(o),m>s&&T.finalY!==d.marginTopPt&&(m=this.advancePdfFlowRegion(t,o).y+h);const x=g(),F=o.columnFlow?.index??0,b=x,E=this.hexToRgb(e.borderColor??vt.borderColor);t.setDrawColor(E.r,E.g,E.b),t.setLineWidth(vt.borderWidthPx*this.PX_TO_PT);let R=P,B=c;for(;R<x||R===x&&B<=F;){t.setPage(R);const k=R===P&&B===c,I=R===x&&B===F,u=k?a:R===P?f:o.marginTopPt,p=I?m:s;p>u&&t.rect(o.pageMarginLeftPt+B*o.columnStridePt,u,i,p-u,"S"),B+=1,B>=o.columnCount&&(B=0,R+=1)}return t.setPage(b),{nextY:m,blockStartPages:T.blockStartPages,lineMarks:T.lineMarks}}static advancePlaceholderBlock(t,e,a,i){const r=Math.max(0,e.height||100)*this.PX_TO_PT,n=this.getPdfFlowBottom(t,i);return a+r>n&&a!==i.marginTopPt&&(a=this.advancePdfFlowRegion(t,i).y),a+r}static async toBlob(t,e,a){class i extends this{}return i.bundledGenreFamilies=new Map,i.scriptFallbackFamilies=new Map,i.shapingFonts=new Map,i.embeddedFamilyNames=new Map,i.inlineCodeFontFamily="courier",i.renderDocument(t,e,a)}static async renderDocument(t,e,a){t=this.splitDocumentFallbackRuns(t,await this.loadFallbackCoverage(t));const i=a||{...It,background:Lt.codeBackground,text:Lt.codeText};await this.ensureAllLatexRendered(t);const r=this.resolvePdfLayoutMetrics(t),n=t.children.filter(S=>S.type==="section-break"),l=new Map,o=new Map,h=t.pageLayout?.pageNumberRestart===!0?{...r,pageNumberStartExplicit:!0}:r;n.forEach((S,w)=>{const C=n[w+1];l.set(S.id,C?.layout?this.resolvePdfMetricsFromSettings(C.layout,t.pageLayout,!0):C?r:h),o.set(S.id,w+1)});const s=n[0]?.layout?this.resolvePdfMetricsFromSettings(n[0].layout,t.pageLayout,!1):r,g=await import("./jspdf.es.min-BuJNZ-oY.js"),P=g.jsPDF??g.default,c=new P({orientation:s.orientation,unit:"pt",format:[s.pageWidthPt,s.pageHeightPt]}),f=this.DEFAULT_BODY_FONT,{hasSourceCodePro:d}=await this.registerDocumentFonts(c,t,f);e&&c.setProperties({title:e});const T=Ne(t.watermark);T&&this.installWatermarkUnderpaint(c,T);const m=[...t.children.filter(S=>S.type==="footnote"),...t.notes??[]],x=t.children.filter(S=>S.type!=="footnote"&&S.type!=="header-footer"),F={balanceBySection:this.computeColumnBalanceTargets(t,x)},b=m.length>0?this.buildNumberedNoteEntries(t):[],E=b.filter(S=>S.kind==="footnote"),R=b.filter(S=>S.kind==="endnote");let B=new Map([[1,s]]),k=new Map([[1,0]]),I=s.marginTopPt,u=[],p=new Map;if(E.length===0){const S=await this.renderBodyBlocks(c,x,s,i,d,f,l,void 0,o,void 0,F);B=S.pageMetrics,k=S.pageSections,u=S.lineMarks,I=S.finalY}else{const S=E,w=tt.separatorSpacePx*this.PX_TO_PT,C=this.mapFootnoteRefBlocks(x),D=new P({orientation:s.orientation,unit:"pt",format:[s.pageWidthPt,s.pageHeightPt]});await this.registerDocumentFonts(D,t,f);const V=await this.renderBodyBlocks(D,x,s,i,d,f,l,void 0,void 0,void 0,F),M=L=>{let A=s,U=0;for(const[z,Y]of V.pageMetrics)z<=L&&z>U&&(A=Y,U=z);return A},N=new Map,G=D.getNumberOfPages();for(const L of S){const A=C.get(L.footnoteId),U=(A?V.blockStartPages.get(A):void 0)??G,z=N.get(U)??[];z.push(L),N.set(U,z)}const H=new P({orientation:r.orientation,unit:"pt",format:[r.pageWidthPt,1e4]});await this.registerDocumentFonts(H,t,f);const j=new Map;for(const[L,A]of N){const U=M(L);for(const z of A){const Y={...U,pageHeightPt:1e4,marginTopPt:0,marginBottomPt:0},Z=await this.renderNoteEntry(H,z,0,Y,f,i,d,!1);j.set(z.footnoteId,Math.max(0,Z))}}const _=new Map;for(const[L,A]of N){const U=M(L),z=w+A.reduce((q,rt)=>q+(j.get(rt.footnoteId)??0),0),Y=U.pageHeightPt-U.marginTopPt-U.marginBottomPt,Z=V.lineMarks.filter(q=>q.pageNumber===L).sort((q,rt)=>q.y-rt.y).slice(0,tt.minimumBodyLinesBeforeFootnotes),Q=this.getParagraphLineHeight({type:"paragraph",id:"__pdf_measure__",children:[]}),nt=(Z.length>0?Math.max(0,Math.max(...Z.map(q=>q.y+q.height))-U.marginTopPt):Q*tt.minimumBodyLinesBeforeFootnotes)+tt.bodyKeepSlackPx*this.PX_TO_PT;_.set(L,Math.min(z,Math.max(0,Y-nt)))}p=_;const y=L=>({...L,reservedInsetForPage:_}),X=y(s),O=await this.renderBodyBlocks(c,x,X,i,d,f,l,y,o,void 0,F);B=O.pageMetrics,k=O.pageSections,u=O.lineMarks,I=O.finalY;const K=new Map;for(const L of O.lineMarks)K.set(L.pageNumber,Math.max(K.get(L.pageNumber)??0,L.y+L.height+tt.separatorSpacePx*this.PX_TO_PT+tt.verticalPaddingPx*this.PX_TO_PT));const W=c.getNumberOfPages();for(const[L,A]of[...N.entries()].sort((U,z)=>U[0]-z[0])){const U=Math.min(L,W);c.setPage(U);const z=M(L),Y=_.get(L)??0,Z=z.pageHeightPt-z.marginBottomPt-Y+w;c.setDrawColor(120),c.setLineWidth(.75),c.line(z.marginLeftPt,Z-7,z.marginLeftPt+Math.max(tt.separatorWidthMinPx*this.PX_TO_PT,z.contentWidthPt*tt.separatorWidthFraction),Z-7);let Q=Z;for(let nt=0;nt<A.length;nt++){nt>0&&(Q+=tt.blockSpacingPx*this.PX_TO_PT);const q=this.getPdfCurrentPage(c),rt=c.addPage.bind(c),lt=[];c.addPage=(...ct)=>{const et=this.getPdfCurrentPage(c)+1;return et<=W?c.setPage(et):rt(...ct),lt.push(this.getPdfCurrentPage(c)),c};try{Q=await this.renderNoteEntry(c,A[nt],Q,z,f,i,d,!0,K)}finally{c.addPage=rt}for(const ct of lt){c.setPage(ct),c.setDrawColor(120),c.setLineWidth(.75);const et=(K.get(ct)??z.marginTopPt)-tt.verticalPaddingPx*this.PX_TO_PT*2;c.line(z.marginLeftPt,et,z.marginLeftPt+z.contentWidthPt,et)}c.setPage(lt[lt.length-1]??q)}}c.setPage(this.getPdfPageCount(c))}if(R.length>0){const S=new P({orientation:r.orientation,unit:"pt",format:[r.pageWidthPt,1e4]});await this.registerDocumentFonts(S,t,f);let w=tt.separatorToContentPx*this.PX_TO_PT;for(let H=0;H<R.length;H++){H>0&&(w+=tt.blockSpacingPx*this.PX_TO_PT);const j={...r,pageHeightPt:1e4,marginTopPt:0,marginBottomPt:0};w+=await this.renderNoteEntry(S,R[H],0,j,f,i,d,!1)}const C=this.getPdfPageCount(c);let D=s,V=0;for(const[H,j]of B)H<=C&&H>=V&&(D=j,V=H);const M=I+tt.inlineEndnoteGapPx*this.PX_TO_PT,N=M+w<=D.pageHeightPt-D.marginBottomPt-(p.get(C)??0);let G;N?(c.setPage(C),G=M):(c.addPage(),G=D.marginTopPt+tt.newPageSeparatorOffsetPx*this.PX_TO_PT),c.setDrawColor(120),c.setLineWidth(.75),c.line(D.marginLeftPt,G,D.marginLeftPt+Math.max(tt.separatorWidthMinPx*this.PX_TO_PT,D.contentWidthPt*tt.separatorWidthFraction),G),G+=tt.separatorToContentPx*this.PX_TO_PT;for(let H=0;H<R.length;H++)H>0&&(G+=tt.blockSpacingPx*this.PX_TO_PT),G=await this.renderNoteEntry(c,R[H],G,D,f,i,d,!0)}return await this.renderHeaderFooterChrome(c,t,r,f,B,k),this.renderBodyLineNumbers(c,u,B,t,[...B.values()].some(S=>S.lineNumbering||S.pleadingGrid)?Re(this.computeEngineLayout(t),this.DEFAULT_BODY_FONT):void 0),c.output("blob")}static measureLineAdvancePt(t,e,a,i){let r=0,n=0;for(const h of t)h.latexImage?n=Math.max(n,h.latexImage.contentHeight*this.PX_TO_PT):r=Math.max(r,h.marks?.fontSize?h.marks.fontSize*this.PX_TO_PT:e);r===0&&(r=e);const l=i??(a?this.LINE_HEIGHT_MULTIPLIERS.heading:this.LINE_HEIGHT_MULTIPLIERS.paragraph),o=r*l;return n>o*1.25?n:o}static parseParagraphDecoration(t){const e=t.shading&&t.shading!=="transparent"?t.shading:void 0;if(!e&&!t.borders)return null;let a;if(t.borders)try{a=JSON.parse(t.borders)}catch{a=void 0}return!e&&!a?null:{...e?{shading:e}:{},...a?{edges:a}:{}}}static drawParagraphDecorationSlice(t,e,a,i,r,n,l,o){if(e.shading){const d=this.hexToRgb(e.shading);t.setFillColor(d.r,d.g,d.b),t.rect(a,i,r,n+(o?0:.5),"F")}const h=e.edges;if(!h)return;const s=(d,T,m,x,F)=>{const b=h[d];if(!b||b.style==="none")return;const E=Math.max(.4,(b.width??1)*this.PX_TO_PT),R=m===F,B=this.hexToRgb(b.color??"#000000");if(t.setDrawColor(B.r,B.g,B.b),t.setLineWidth(E),R&&oa(b.style)){const u=ra(T,x,this.PX_TO_PT);for(const p of u.lines)t.line(p.from,m,p.to,m);t.setFillColor(B.r,B.g,B.b);for(const p of u.ornaments)if(b.style==="stars")for(const S of sa(p.cx,m,p.radius))t.line(S.x1,S.y1,S.x2,S.y2);else{const S=la(p.cx,m,p.radius);t.lines([[S[1].x-S[0].x,S[1].y-S[0].y],[S[2].x-S[1].x,S[2].y-S[1].y],[S[3].x-S[2].x,S[3].y-S[2].y]],S[0].x,S[0].y,[1,1],"F",!0)}return}const k=typeof t.setLineDashPattern=="function";k&&(b.style==="dashed"?t.setLineDashPattern([4.5,2.25],0):b.style==="dotted"?t.setLineDashPattern([1.5,1.5],0):t.setLineDashPattern([],0));const I=u=>{t.line(T+(R?0:u),m+(R?u:0),x+(R?0:u),F+(R?u:0))};b.style==="double"?(I(-E),I(E)):I(0),k&&t.setLineDashPattern([],0)},g=o?0:.5,P=d=>Math.max(0,h[d]?.space??0)*this.PX_TO_PT,c=a-P("left"),f=a+r+P("right");if(s("left",c,i,c,i+n+g),s("right",f,i,f,i+n+g),l){const d=i-P("top");s("top",a,d,a+r,d)}if(o){const d=i+n+P("bottom");s("bottom",a,d,a+r,d)}}static measureParagraphLineAdvances(t,e,a,i){const r=this.createCanvasTextContext();if(!r)return[this.getParagraphLineHeight(t)];const n=this.createLayoutForWrapping(e,a,i),l=Jt(this.paragraphForPdfOutput(t),r,n);if(l.length===0)return[this.getEmptyParagraphLineHeight(t)];const o=this.getParagraphFontSize(t),h=this.getLineSpacingMultiplier(t);return l.map(s=>this.measureLineAdvancePt(s.segments.map(g=>({marks:g.marks})),o,!!t.heading,h))}static paragraphForPdfOutput(t){const e=t.children.filter(a=>a.type!=="text"||!a.marks?.hidden||!!a.marks.footnoteRef);return e.length===t.children.length?t:{...t,children:e}}static getParagraphDirection(t){let e="";for(const a of t.children)e+=a.text??"";return ve(t.direction,e)}static getEffectiveParagraphAlignment(t,e){return t.align||(e==="rtl"?"right":"left")}static getRequiredParagraphStartHeight(t,e,a,i,r){const n=t[e];if(!n||n.type!=="paragraph")return{required:0,firstLineAdvance:0};const l=Bt(n),o=this.measureParagraphLineAdvances(n,a,i,r),h=this.paragraphForPdfOutput(n).children.every(c=>c.type==="text"&&c.text==="")||o.length===0?this.getEmptyParagraphLineHeight(n):o[0],s=c=>c.reduce((f,d)=>f+Math.max(0,d),0);let g=0;if(l.keepLines?g=s(o):l.widowControl&&o.length>=2&&(g=o[0]+o[1]),!l.keepNext)return{required:g,firstLineAdvance:h};let P=0;for(let c=0;c<Qt;c++){const f=t[e+c+1];if(!f||f.type!=="paragraph")break;const d=this.measureParagraphLineAdvances(f,a,i,r);if(d.length===0)break;const T=t[e+c];P+=st.pdfSpaceBeforePt(f,r,T)+st.pdfSpaceAfterPt(T,f);const m=Bt(f);if(m.keepNext&&c<Qt-1){P+=s(d);continue}P+=d[0],m.widowControl&&d.length>=2&&(P+=d[1]);break}return{required:Math.max(g,s(o)+P),firstLineAdvance:h}}static async renderParagraph(t,e,a,i,r,n,l=this.resolveIndentStepPx(),o=this.getDefaultPdfLayoutMetrics(),h){let s=a;const g=this.paragraphForPdfOutput(e),P=this.getParagraphFontSize(e),c=this.getParagraphLineHeight(e),f=this.getLineSpacingMultiplier(e);let d=Number.isFinite(n)&&n>0?n:this.getPdfFlowBottom(t,o),T=o.marginLeftPt;const m=()=>{const k=this.advancePdfFlowRegion(t,o);s=k.y,T=k.x,d=this.getPdfFlowBottom(t,o)},x=(k=c)=>{if(s+k>d){if(s===o.marginTopPt)return;m()}},F=()=>t.getCurrentPageInfo?.()?.pageNumber??t.getNumberOfPages(),b=this.getParagraphDirection(g),E=this.getEffectiveParagraphAlignment(e,b),R=this.parseParagraphDecoration(e);if(g.children.length===0||g.children.length===1&&g.children[0].type==="text"&&g.children[0].text===""){const k=this.getEmptyParagraphLineHeight(e);return R&&(x(k),this.drawParagraphDecorationSlice(t,R,T,s,i,k,!0,!0)),s+k}const B=this.createCanvasTextContext();if(B){const k=this.createLayoutForWrapping(i,l,o),I=Jt(g,B,k),u=await this.prepareLatexImages(g,P),p=I.map(w=>w.segments.map(C=>C.marks?.latex?{text:C.text,marks:C.marks,latexImage:u.get(C.text)}:{text:C.text,marks:C.marks,font:C.marks?.fontFamily})),S=Bt(e);for(let w=0;w<I.length;w++){const C=I[w],D=p[w];if(D.length>0){const V=this.getParagraphLineIndentPt(e,w,l),M=Math.max(1,i-V),N=this.measureLineAdvancePt(D,P,!!e.heading,f),G=p[w+1];if(S.widowControl&&I.length>=3&&w===I.length-2&&G&&s+N<=d){const j=this.measureLineAdvancePt(G,P,!!e.heading,f);s+N+j>d&&s!==o.marginTopPt&&m()}x(N);const H=b==="rtl"?T:T+V;R&&this.drawParagraphDecorationSlice(t,R,T,s,i,N,w===0,w===I.length-1),h?.push({pageNumber:F(),y:s,height:N,baselineOffset:this.lineBaselineOffsetPt(D,P)}),s=this.renderLine(t,D,s,H,M,E,P,r,!!e.heading,f,w===I.length-1,{direction:b,...C.tabLayout?{tabLayoutPx:C.tabLayout.segments,...C.tabLayout.rtl?{tabRtl:!0,tabWidthPx:C.tabLayout.width}:{}}:{},...C.hyphenTrailing?{hyphenTrailing:!0}:{}})}}return s}return this.renderParagraphWithJsPDFWrapping(t,g,a,i,r,n,l,o)}static async prepareLatexImages(t,e){const a=new Map;for(const i of t.children)if(i.type==="text"&&i.marks?.latex){const r=await this.renderLatexToImage(i.text,!1,e);r&&a.set(i.text,r)}return a}static async renderParagraphWithJsPDFWrapping(t,e,a,i,r,n,l=this.resolveIndentStepPx(),o=this.getDefaultPdfLayoutMetrics()){let h=a;const s=this.getParagraphFontSize(e),g=this.getParagraphLineHeight(e),P=this.getLineSpacingMultiplier(e);let c=Number.isFinite(n)&&n>0?n:this.getPdfFlowBottom(t,o),f=o.marginLeftPt;const d=()=>{if(h+g>c){if(h===o.marginTopPt)return;const k=this.advancePdfFlowRegion(t,o);h=k.y,f=k.x,c=this.getPdfFlowBottom(t,o)}},T=this.getParagraphDirection(e),m=this.getEffectiveParagraphAlignment(e,T),x=await this.processTextNodesWithLatex(e.children,s);if(x.length===0)return h+this.getEmptyParagraphLineHeight(e);let F=[],b=0,E=0;const R=()=>Math.max(1,i-this.getParagraphLineIndentPt(e,E,l)),B=(k=!1)=>{if(F.length===0)return;d();const I=this.getParagraphLineIndentPt(e,E,l);h=this.renderLine(t,F,h,T==="rtl"?f:f+I,Math.max(1,i-I),m,s,r,!!e.heading,P,k,{direction:T}),F=[],b=0,E+=1};if(x.length===1&&x[0].text==="")return a+this.getEmptyParagraphLineHeight(e);for(const k of x){if(k.latexImage){const u=k.latexImage.contentWidth*this.PX_TO_PT;b+u>R()&&F.length>0&&B(),F.push({text:k.text,marks:k.marks,font:k.font||k.marks?.fontFamily,latexImage:k.latexImage}),b+=u;continue}this.setRunFont(t,k,r),t.setFontSize(this.getRunEffectiveFontSizePt(k.marks,s));const I=k.text.split(`
2
+ `);for(let u=0;u<I.length;u++){const p=I[u];u>0&&F.length>0&&B();const S=p.split(/(\s+)/);for(const w of S){const C=this.measureRunDisplayWidthPt(t,w,k.marks);b+C>R()&&F.length>0&&B(),(w.trim()||F.length>0)&&(F.push({text:w,marks:k.marks,font:k.font||k.marks?.fontFamily}),b+=C)}}}return F.length>0&&B(!0),h}static getLineSpacingMultiplier(t){return qt(t)}static async renderListBlock(t,e,a,i,r,n=this.getDefaultPdfLayoutMetrics(),l,o){if(!e.children.length)return a;let h=a;const s=this.getPdfFlowBottom(t,n),g=l??Ie(e),P={...g.counters};let c;if(e.variant==="ordered"&&e.numberingFormat)try{t.setFont(this.mapFontFamily(r),"normal"),t.setFontSize(this.FONT_SIZES.normal);let f=0;for(const T of Be(e,g))f=Math.max(f,t.getTextWidth(T)/this.PX_TO_PT);const d=this.ORDERED_LIST_INDENT_PT/this.PX_TO_PT;c=Math.min(Math.max(d,Math.ceil(f)+10),240)*this.PX_TO_PT}catch{c=void 0}for(let f=0;f<e.children.length;f++){const d=e.children[f],T=this.getListIndentLevel(d);let m;e.variant==="ordered"?m={type:"ordered",label:this.computeOrderedMarkerLabel(P,T,g.start,Ee(e.numberingFormat))}:e.variant==="todo"?m={type:"todo",checked:!!d.checked}:m={type:"bullet",indentLevel:T},h=await this.renderListItem(t,d,e,m,h,i,s,r,n,o,c)}return h}static async renderListItem(t,e,a,i,r,n,l,o,h=this.getDefaultPdfLayoutMetrics(),s,g){let P=r+Math.max(0,e.spaceBefore??0)*this.PX_TO_PT;const c=this.getListIndentLevel(e)*this.SUBLIST_INDENT_PT,f=o,d=this.FONT_SIZES.normal,T=this.mapFontFamily(f);t.setFont(T,"normal"),t.setFontSize(d);const m=g??this.getListIndentPt(a.variant);let x=h.marginLeftPt,F=x+c+m,b=l;const E=()=>{const y=this.advancePdfFlowRegion(t,h);P=y.y,x=y.x,F=x+c+m,b=this.getPdfFlowBottom(t,h)};let R=n-c-m;(!Number.isFinite(R)||R<=0)&&(R=Math.max(n*.3,n*.1));let B="";for(const y of e.children)B+=y.text??"";const k=De(B)??"ltr",I=k==="rtl",u=()=>I?x:F,p=()=>I?x+R:F,S=e.lineSpacing??a.lineSpacing??this.LINE_HEIGHT_MULTIPLIERS.paragraph,w=d*S,C=await this.processTextNodesWithLatex(e.children,d);let D=C.length>0?C:[{text:""}];a.variant==="todo"&&e.checked&&(D=D.map(y=>y.latexImage?y:{...y,marks:{...y.marks,strikethrough:!0,color:Lt.todoCheckedText}}));const V=new Set(Object.values(this.SCRIPT_FALLBACK_FONTS).map(y=>y.family)),M=[...C].reverse().find(y=>!y.latexImage&&!y.marks?.latex&&y.text.length>0&&!V.has(y.marks?.fontFamily??""))?.marks;let N=[],G=0,H=!1;const j=()=>{H||(P+w>b&&P!==h.marginTopPt&&E(),this.drawListMarker(t,i,p(),P,w,d,f,o,I,M),H=!0)},_=()=>{N.length!==0&&(P+w>b&&P!==h.marginTopPt&&E(),j(),s?.push({pageNumber:t.getCurrentPageInfo?.().pageNumber??t.getNumberOfPages(),y:P,height:this.measureLineAdvancePt(N,d,!1,S),baselineOffset:this.lineBaselineOffsetPt(N,d)}),P=this.renderLine(t,N,P,u(),R,I?"right":"left",d,f,!1,S,!0,{direction:k}),N=[],G=0)};for(const y of D){if(y.latexImage){const O=y.latexImage.contentWidth*this.PX_TO_PT;G+O>R&&N.length>0&&_(),N.push({text:y.text,marks:y.marks,font:y.font,latexImage:y.latexImage}),G+=O;continue}this.setRunFont(t,y,f||o),t.setFontSize(this.getRunEffectiveFontSizePt(y.marks,d));const X=y.text.split(`
3
+ `);for(let O=0;O<X.length;O++){const K=X[O];O>0&&(N.length>0?_():(j(),P+=w));const W=K.split(/(\s+)/);for(const L of W){const A=this.measureRunDisplayWidthPt(t,L,y.marks);G+A>R&&N.length>0&&_(),(L.trim()||N.length>0)&&(N.push({text:L,marks:y.marks,font:y.font}),G+=A)}}}return N.length>0&&_(),H||(j(),P+=w),P+Math.max(0,e.spaceAfter??0)*this.PX_TO_PT}static drawListMarker(t,e,a,i,r,n,l,o,h,s){t.setDrawColor(0,0,0);const g=(f,d=0)=>h?2*a-f-d:f,P=a-this.BULLET_MARKER_WIDTH_PT,c=i+r/2;switch(e.type){case"bullet":{const f=g(P+this.BULLET_CENTER_OFFSET_PT),d=this.BULLET_RADIUS_PT;if(e.indentLevel<=0)t.circle(f,c,d,"F");else if(e.indentLevel===1)t.circle(f,c,d,"S");else{const T=this.BULLET_SQUARE_HALF_PT*2,m=g(P+this.BULLET_SQUARE_INSET_PT,T),x=c-this.BULLET_SQUARE_HALF_PT+this.BULLET_SQUARE_VERTICAL_ADJUST_PT;t.rect(m,x,T,T,"S")}break}case"todo":{const f=this.TODO_CHECKBOX_SIZE_PT,d=g(P-this.TODO_CHECKBOX_OFFSET_PT,f),T=c-f/2;t.setLineWidth(.8),typeof t.roundedRect=="function"?t.roundedRect(d,T,f,f,this.TODO_CHECKBOX_RADIUS_PT,this.TODO_CHECKBOX_RADIUS_PT,"S"):t.rect(d,T,f,f,"S"),e.checked&&(t.setLineWidth(1.2),t.line(d+f*.15,T+f*.55,d+f*.4,T+f*.75),t.line(d+f*.4,T+f*.75,d+f*.85,T+f*.25));break}case"ordered":{const f=e.label,d=s?{fontFamily:s.fontFamily,fontSize:s.fontSize,bold:s.bold,italic:s.italic,code:s.code,superscript:s.superscript,subscript:s.subscript}:void 0;this.setRunFont(t,{text:f,marks:d},l||o);const T=this.getRunEffectiveFontSizePt(d,n);t.setFontSize(T);const m=t.getTextWidth(f),x=h?a+this.ORDERED_LABEL_GAP_PT:a-this.ORDERED_LABEL_GAP_PT-m;t.text(f,x,i+T);break}}t.setLineWidth(.5),t.setTextColor(0,0,0)}static async renderTableBlock(t,e,a,i,r,n=It,l=!1,o=this.getDefaultPdfLayoutMetrics()){if(!e.children||e.children.length===0)return a;const h=this.getPdfFlowBottom(t,o);let s=a;const g=e.borderWidth??Et.borderWidthPx,P=e.borderColor??Et.borderColor,c=this.hexToRgb(P),f=Number.isFinite(e.cellPadding)?Math.max(0,Math.round(e.cellPadding)):Et.cellPaddingPx,d=f*this.PX_TO_PT,T=Xe(e.borders),m=Ae(e),x=m.cols,F=Math.min(e.tableWidth?e.tableWidth*this.PX_TO_PT:i,i),b=e.align==="center"?(i-F)/2:e.align==="right"?i-F:0;let E=o.marginLeftPt+b;const R=We(e.columnWidths??[],x).map(_=>_/100*F),B=[0];for(let _=0;_<x;_++)B.push(B[_]+R[_]);const k=_=>B[Math.min(_.col+_.colSpan,x)]-B[_.col],I=new Map;for(const _ of m.cells){const y=He(f,_.cell.padding),X={top:y.top*this.PX_TO_PT,right:y.right*this.PX_TO_PT,bottom:y.bottom*this.PX_TO_PT,left:y.left*this.PX_TO_PT},O=k(_)-X.left-X.right,K=this.extractCellBlocks(_.cell);let W=this.FONT_SIZES.normal*this.LINE_HEIGHT_MULTIPLIERS.paragraph;if(K.length>0){const A=await import("./jspdf.es.min-BuJNZ-oY.js"),U=A.jsPDF??A.default,z=new U({orientation:"portrait",unit:"pt",format:[Math.max(72,O),this.UNBOUNDED_CELL_FLOW_BOTTOM_PT]});await this.registerCurrentPdfFonts(z,l);const Y={...o,keepFirstBlockDeclaredSpaceBefore:!0,pageWidthPt:Math.max(72,O),pageHeightPt:this.UNBOUNDED_CELL_FLOW_BOTTOM_PT,marginTopPt:0,marginRightPt:0,marginBottomPt:0,marginLeftPt:0,contentWidthPt:Math.max(1,O)};W=(await this.renderBodyBlocks(z,K,Y,n,l,r,void 0,void 0,void 0,0)).finalY}const L=X.top+W+X.bottom;I.set(_.cell.id,{blocks:K,width:O,flowHeight:W,contentHeight:L,pad:X})}const u=e.children.map((_,y)=>{let X=0;for(const O of _.children){const K=m.byId.get(O.id);K&&K.rowSpan>1||(X=Math.max(X,I.get(O.id)?.contentHeight??0))}return X}),p=m.cells.filter(_=>_.rowSpan>1).sort((_,y)=>_.rowSpan-y.rowSpan);for(const _ of p){const y=I.get(_.cell.id);if(!y)continue;let X=0;for(let O=_.row;O<_.row+_.rowSpan;O++)X+=u[O];y.contentHeight>X&&(u[_.row+_.rowSpan-1]+=y.contentHeight-X)}const S=_=>{let y=0;for(let X=_.row;X<_.row+_.rowSpan;X++)y+=u[X];return y},w=[],C=()=>{if(w.length===0)return;const _=this.getPdfCurrentPage(t);for(const{page:y,draw:X}of w)t.setPage(y),X();w.length=0,t.setPage(_)},D=(_,y,X,O,K,W,L)=>{const A=_.backgroundColor?this.hexToRgb(_.backgroundColor):L?{r:249,g:250,b:251}:{r:255,g:255,b:255};(_.backgroundColor||L)&&(t.setFillColor(A.r,A.g,A.b),t.rect(X,K,O,W,"F"));const U=this.getPdfCurrentPage(t),z=ha(_.borders);if(T||z){const Y=ga({tableBorders:T,cellBorders:z,flags:{isTopRow:(y?.row??0)===0,isBottomRow:y?y.row+y.rowSpan===m.rows:!1,isLeftCol:(y?.col??0)===0,isRightCol:y?y.col+y.colSpan===m.cols:!1},fallback:{style:"single",width:g,color:P}}),Z=X+O,Q=K+W;w.push({page:U,draw:()=>{this.drawPdfBorderEdge(t,Y.top,X,K,Z,K),this.drawPdfBorderEdge(t,Y.bottom,X,Q,Z,Q),this.drawPdfBorderEdge(t,Y.left,X,K,X,Q),this.drawPdfBorderEdge(t,Y.right,Z,K,Z,Q)}})}else g>0&&w.push({page:U,draw:()=>{t.setDrawColor(c.r,c.g,c.b),t.setLineWidth(g*this.PX_TO_PT),t.rect(X,K,O,W,"S")}})},V=async(_,y,X,O)=>{const K=!!e.hasHeader&&y===0,W=u[y],L=this.getPdfCurrentPage(t);for(const A of _.children){t.setPage(L);const U=m.byId.get(A.id),z=E+(U?B[U.col]:0),Y=U?k(U):F/x,Z=O||!U?W:S(U);D(A,U,z,Y,X,Z,K);const Q=I.get(A.id),nt=Q?.blocks??this.extractCellBlocks(A),q=Q?.pad.left??d,rt=Q?.pad.right??d,lt=Q?.pad.top??d,ct=Q?.pad.bottom??d,et=Q?.width??Y-q-rt,ot=Q?.flowHeight??this.FONT_SIZES.normal*this.LINE_HEIGHT_MULTIPLIERS.paragraph,ft=Math.max(0,Z-lt-ct-ot),ut=A.verticalAlign==="bottom"?ft:A.verticalAlign==="middle"?ft/2:0,Ot=X+lt+ut;if(nt.length>0){const Ct={...o,keepFirstBlockDeclaredSpaceBefore:!0,columnCount:1,columnFlow:void 0,marginTopPt:Ot,marginRightPt:Math.max(0,o.pageWidthPt-(z+q+et)),marginBottomPt:o.pageHeightPt-this.UNBOUNDED_CELL_FLOW_BOTTOM_PT,marginLeftPt:z+q,pageMarginLeftPt:z+q,contentWidthPt:Math.max(1,et),fullContentWidthPt:Math.max(1,et),columnStridePt:Math.max(1,et)};await this.renderBodyBlocks(t,nt,Ct,n,l,r,void 0,void 0,void 0,Ot)}}t.setPage(L)},M=(_,y)=>_.idx!==y.idx?_.idx>y.idx?_:y:_.y>=y.y?_:y,N=async(_,y,X,O,K,W)=>{const L=I.get(y.id),A=L?.blocks??this.extractCellBlocks(y),U=L?.pad.left??d,z=L?.pad.bottom??d,Y=X?k(X):F/x,Z=L?.width??Y-U-(L?.pad.right??d),Q=X?B[X.col]:0;let nt=O.idx;if(A.length===0){const ot=L?.flowHeight??this.FONT_SIZES.normal*this.LINE_HEIGHT_MULTIPLIERS.paragraph;return{idx:nt,y:Math.min(W,O.y+ot+z)}}const q=(ot,ft)=>{const ut=ot.left+Q+U;ft.marginTopPt=ot.top,ft.marginLeftPt=ut,ft.pageMarginLeftPt=ut,ft.marginRightPt=Math.max(0,o.pageWidthPt-(ut+Z))},rt={...o,keepFirstBlockDeclaredSpaceBefore:!0,columnCount:1,columnFlow:void 0,marginBottomPt:o.pageHeightPt-W,reservedInsetForPage:void 0,contentWidthPt:Math.max(1,Z),fullContentWidthPt:Math.max(1,Z),columnStridePt:Math.max(1,Z)},lt=K(nt);q(lt,rt),_.setPage(lt.page);const ct=_.addPage;_.addPage=()=>{nt+=1;const ot=K(nt);return q(ot,rt),_.setPage(ot.page),_};let et=O.y;try{et=(await this.renderBodyBlocks(_,A,rt,n,l,r,void 0,void 0,void 0,O.y)).finalY}finally{_.addPage=ct}return{idx:nt,y:Math.min(W,et+z)}},G=async(_,y,X)=>{const O=h,K=H&&_>0?u[0]:0,W=o.marginTopPt+K,L=await import("./jspdf.es.min-BuJNZ-oY.js"),A=L.jsPDF??L.default,U=new A({orientation:o.orientation,unit:"pt",format:[o.pageWidthPt,o.pageHeightPt]});await this.registerCurrentPdfFonts(U,l);const z=U.addPage.bind(U),Y=[{page:1,top:o.marginTopPt,left:E}],Z=$=>{for(;Y.length<=$;)z(),Y.push({page:Y.length+1,top:W,left:E});return Y[$]},Q=($,at)=>{let{idx:pt,y:ht}=$,gt=at;for(;;){const mt=Math.max(0,O-ht);if(gt<=mt+.01)return{idx:pt,y:ht+gt};gt-=mt,pt+=1,ht=W}},nt=[],q=[],rt=new Map,lt=[];let ct={idx:0,y:X};for(let $=_;$<y;$++){const at=ct;nt[$-_]=at;for(const gt of e.children[$].children){const mt=m.byId.get(gt.id),xt=I.get(gt.id)?.pad.top??d,Mt=at.y+xt>O+.01?{idx:at.idx+1,y:W+xt}:{idx:at.idx,y:at.y+xt};rt.set(gt.id,Mt);const Tt=await N(U,gt,mt,Mt,Z,O),_t=Math.min(y-1,$+(mt?.rowSpan??1)-1),yt=lt[_t-_];lt[_t-_]=yt?M(yt,Tt):Tt}const pt=Q(at,u[$]),ht=lt[$-_];ct=ht?M(pt,ht):pt,q[$-_]=ct}let et=ct.idx;for(const $ of rt.values())et=Math.max(et,$.idx);et=Math.max(et,Y.length-1);const ot=[{page:this.getPdfCurrentPage(t),top:o.marginTopPt,left:E}],ft=t.addPage,ut=()=>{const $=this.advancePdfFlowRegion(t,o);return E=$.x+b,{page:this.getPdfCurrentPage(t),top:$.y+K,left:E}};for(let $=1;$<=et;$++){const at=ut();ot.push(at),K>0&&await V(e.children[0],0,at.top-K,!0)}const Ot=$=>{for(;ot.length<=$;){const at=t.addPage;t.addPage=ft;try{ot.push(ut())}finally{t.addPage=at}}return ot[$]};for(let $=_;$<y;$++){const at=!!e.hasHeader&&$===0;for(const pt of e.children[$].children){const ht=m.byId.get(pt.id),gt=Math.min(y-1,$+(ht?.rowSpan??1)-1),mt=nt[$-_],xt=q[gt-_],Mt=ht?k(ht):F/x;for(let Tt=mt.idx;Tt<=xt.idx;Tt++){const _t=ot[Tt],yt=Tt===mt.idx?mt.y:_t.top,Wt=Tt===xt.idx?xt.y:O;Wt-yt<=.01||(t.setPage(_t.page),D(pt,ht,_t.left+(ht?B[ht.col]:0),Mt,yt,Wt-yt,at))}}}for(let $=_;$<y;$++)for(const at of e.children[$].children)await N(t,at,m.byId.get(at.id),rt.get(at.id),Ot,O);const Ct=q[q.length-1],At=ot[Math.min(Ct.idx,ot.length-1)];return t.setPage(At.page),E=At.left,Ct.y},H=e.hasHeader===!0&&e.children.length>1&&!m.cells.some(_=>_.row===0&&_.rowSpan>1),j=e.children.map(()=>[]);for(const _ of m.cells)j[_.row]?.push(_);for(let _=0;_<e.children.length;){let y=_+1,X=0;for(let L=_;L<y;L++){X+=u[L];for(const A of j[L])y=Math.min(e.children.length,Math.max(y,A.row+A.rowSpan))}const O=H&&_>0?u[0]:0,K=h-o.marginTopPt-O,W=X>K;if((W?s>=h-.01:s+X>h)&&s!==o.marginTopPt){const L=this.advancePdfFlowRegion(t,o);s=L.y,E=L.x+b,H&&_>0&&(await V(e.children[0],0,s,!0),s+=u[0])}if(W)s=await G(_,y,s);else for(let L=_;L<y;L++)await V(e.children[L],L,s,!1),s+=u[L];_=y}return C(),s}static async renderCodeBlock(t,e,a,i,r,n=this.MARGIN_LEFT,l=It,o=!1,h=this.getDefaultPdfLayoutMetrics(),s){const g=n-h.marginLeftPt;let P=n;const c=e.language||"",f=Ge(c);if(f&&e.renderDiagram!==!1&&f)return this.renderDiagramCodeBlock(t,e,a,i,r,P,f,l,o,h);const d=o?"SourceCodePro":"courier",T=e.content||"",m=c?await ze(T,c,l):null,x=dt.fontSizePx*this.PX_TO_PT,F=x*dt.lineHeightMultiplier,b=dt.paddingPx*this.PX_TO_PT,E=dt.borderRadiusPx*this.PX_TO_PT,R=this.hexToRgb(l.background),B=this.hexToRgb(l.default);t.setFont(d,"normal"),t.setFontSize(x);const k=Math.max(1,i-b*2),I=te(T,M=>t.getTextWidth(M),k),u=[];let p=0;for(const M of m??[])u.push({start:p,end:p+M.text.length,color:M.color}),p+=M.text.length;const S=M=>{if(u.length===0)return[{text:M.text,color:l.default}];const N=[];for(const G of u){const H=Math.max(M.startCharOffset,G.start),j=Math.min(M.endCharOffset,G.end);j<=H||N.push({text:T.slice(H,j),color:G.color})}return N.length>0?N:[{text:M.text,color:l.default}]};let w=a,C=0,D=r;const V=()=>{const M=this.advancePdfFlowRegion(t,h);w=M.y,P=M.x+g,D=this.getPdfFlowBottom(t,h)};for(;C<I.length;){const M=C===0,N=M?b:0,G=N+F+(I.length===C+1?b:0);w+G>D&&w!==h.marginTopPt&&V();let H=C,j=N;for(;H<I.length;){const y=H===I.length-1,X=j+F+(y?b:0);if(w+X>D&&H>C)break;j+=F,H+=1}const _=H===I.length;_&&(j+=b),t.setFillColor(R.r,R.g,R.b),M&&_?this.drawRoundedRect(t,P,w,i,j,E):t.rect(P,w,i,j,"F"),t.setFont(d,"normal"),t.setFontSize(x);for(let y=C;y<H;y++){const X=y===0,O=y===I.length-1,K=w+N+(y-C)*F;s?.push({pageNumber:t.getCurrentPageInfo?.().pageNumber??t.getNumberOfPages(),y:K-(X?b:0),height:F+(X?b:0)+(O?b:0)});let W=P+b;const L=w+N+(y-C)*F+x;for(const A of S(I[y])){const U=A.color?this.hexToRgb(A.color):B;t.setTextColor(U.r,U.g,U.b),A.text&&t.text(A.text,W,L),W+=t.getTextWidth(A.text)}}w+=j,C=H,_||V()}return w}static async renderDiagramCodeBlock(t,e,a,i,r,n,l,o,h,s){const g=n-s.marginLeftPt;let P=n;const c=dt.paddingPx*this.PX_TO_PT,f=dt.diagramSourceGapPx*this.PX_TO_PT,d=ee(),T=Math.max(120,Math.round((i-c*2)/this.PX_TO_PT)),m=await Ue({protocol:l,source:e.content||"",theme:d,maxWidth:T}),x=Math.max(1,m.width*this.PX_TO_PT),F=Math.max(dt.diagramMinHeightPx,m.height)*this.PX_TO_PT,b=F+c*2,E=e.showDiagramSource!==!1,R=h?"SourceCodePro":"courier",B=dt.fontSizePx*this.PX_TO_PT;t.setFont(R,"normal"),t.setFontSize(B);const k=te(e.content||"",N=>t.getTextWidth(N),Math.max(1,i-c*2)),I=c*2+k.length*B*dt.lineHeightMultiplier,u=(E?I+f:0)+b;let p=a;if(p+u>r&&p!==s.marginTopPt){const N=this.advancePdfFlowRegion(t,s);p=N.y,P=N.x+g}E&&(p=await this.renderCodeBlock(t,{...e,renderDiagram:!1},p,i,r,P,o,h,s),p+=f);const S=this.hexToRgb(d.codeBorder||"#e0e0e0"),w=dt.borderRadiusPx*this.PX_TO_PT;t.setDrawColor(S.r,S.g,S.b),t.setLineWidth(this.BLOCK_BORDER_WIDTH_PT),this.drawRoundedRect(t,P,p,i,b,w,"S");const C=Math.min(i-c*2,x),D=Math.min(b-c*2,F),V=P+(i-C)/2,M=p+(b-D)/2;if(m.svg){const N=await this.svgToPng(m.svg,Math.max(1,Math.round(m.width)),Math.max(1,Math.round(m.height)),2);if(N)return t.addImage(N,"PNG",V,M,C,D),p+b}return t.setTextColor(220,38,38),t.setFont("helvetica","normal"),t.setFontSize(10),t.text("Diagram unavailable",P+c,p+c+10),p+b}static renderCellParagraph(t,e,a,i,r,n,l=!1){const o=this.getParagraphFontSize(e),h=this.getParagraphDirection(e),s=this.getEffectiveParagraphAlignment(e,h),g=this.getLineSpacingMultiplier(e),P=this.processTextNodes(e.children);let c=i,f=[],d=0;const T=m=>{f.length!==0&&(l?c+=this.measureLineAdvancePt(f,o,!!e.heading,g):c=this.renderLine(t,f,c,a,r,s,o,n,!!e.heading,g,m,{direction:h}),f=[],d=0)};for(const m of P){this.setRunFont(t,m,n),t.setFontSize(this.getRunEffectiveFontSizePt(m.marks,o));const x=m.text.split(`
4
+ `);for(let F=0;F<x.length;F++){F>0&&T(!1);const b=x[F].split(/(\s+)/);for(const E of b){const R=this.measureRunDisplayWidthPt(t,E,m.marks);d+R>r&&f.length>0&&T(!1),(E.trim()||f.length>0)&&(f.push({text:E,marks:m.marks,font:m.marks?.fontFamily}),d+=R)}}}return T(!0),c===i&&(c+=this.getEmptyParagraphLineHeight(e)),c}static extractCellBlocks(t){return t.children}static drawRoundedRect(t,e,a,i,r,n,l="F"){const o=Math.min(n,i/2,r/2);t.roundedRect(e,a,i,r,o,o,l)}static getListIndentPt(t){switch(t){case"todo":return this.TODO_LIST_INDENT_PT;case"ordered":return this.ORDERED_LIST_INDENT_PT;case"unordered":default:return this.UNORDERED_LIST_INDENT_PT}}static getListIndentLevel(t){const e=t.indentLevel??0;if(!Number.isFinite(e))return 0;const a=Math.floor(e);return Math.max(0,Math.min(a,this.MAX_LIST_INDENT_LEVEL))}static computeOrderedMarkerLabel(t,e,a,i){return Ke(t,a,e,i)}static getRunLetterSpacingPt(t){return(typeof t?.letterSpacing=="number"&&Number.isFinite(t.letterSpacing)?t.letterSpacing:0)*this.PX_TO_PT}static getRunEffectiveFontSizePt(t,e){const a=t?.fontSize?t.fontSize*this.PX_TO_PT:e;return t?.superscript||t?.subscript?Math.round(a/this.PX_TO_PT*.7)*this.PX_TO_PT:a}static setRunFont(t,e,a){if(e.marks?.code){t.setFont(this.inlineCodeFontFamily,"normal");return}const i=this.mapFontFamily(e.font||e.marks?.fontFamily||a),r=this.resolveFontStyle(e.marks),n=this.scriptFallbackFor(t,e.text,i);if(n){t.setFont(n,r==="bold"||r==="bolditalic"?"bold":"normal");return}t.setFont(i,r)}static measureRunDisplayWidthPt(t,e,a){const i=n=>{const l=t.getFont?.()?.fontName,o=l?this.shapingFonts.get(l):void 0;return o?o.layout(n).advanceWidth*t.getFontSize()/o.unitsPerEm:t.getTextWidth(n)},r=je(a);return r?zt(e,{...r,letterSpacingPx:this.getRunLetterSpacingPt(a)},i):i(e)}static drawShapedText(t,e,a,i,r,n,l){const o=t.getFont?.()?.fontName,h=o?this.shapingFonts.get(o):void 0;if(!h)return null;const s=h.layout(e);Array.from(e).every(d=>(d.codePointAt(0)??0)<=65535)&&t.text(e,a,i,{renderingMode:"invisible"}),t.setFillColor(l.r,l.g,l.b);const g=r/h.unitsPerEm;let P=0,c=0,f=0;for(let d=0;d<s.glyphs.length;d++){const T=s.glyphs[d],m=s.positions[d],x=[];let F=0,b=0;const E=B=>a+f+(P+m.xOffset+B)*g,R=B=>i-(c+m.yOffset+B)*g;for(const B of T.path.commands)if(B.command==="moveTo")[F,b]=B.args,x.push({op:"m",c:[E(F),R(b)]});else if(B.command==="lineTo")[F,b]=B.args,x.push({op:"l",c:[E(F),R(b)]});else if(B.command==="bezierCurveTo"){const[k,I,u,p,S,w]=B.args;x.push({op:"c",c:[E(k),R(I),E(u),R(p),E(S),R(w)]}),F=S,b=w}else if(B.command==="quadraticCurveTo"){const[k,I,u,p]=B.args,S=F+(k-F)*2/3,w=b+(I-b)*2/3,C=u+(k-u)*2/3,D=p+(I-p)*2/3;x.push({op:"c",c:[E(S),R(w),E(C),R(D),E(u),R(p)]}),F=u,b=p}else B.command==="closePath"&&x.push({op:"h",c:[]});x.length>0&&(t.path(x),t.fill()),P+=m.xAdvance,c+=m.yAdvance,f+=n*Math.max(1,T.codePoints?.length??1)}return s.advanceWidth*r/h.unitsPerEm+n*[...e].length}static renderLine(t,e,a,i,r,n,l,o,h,s,g=!0,P){e=e.filter(u=>!u.marks?.hidden||!!u.marks.footnoteRef);let c=P?.tabLayoutPx;const f=u=>u.marks?.fontSize?u.marks.fontSize*this.PX_TO_PT:l,d=P?.direction??"ltr";if(!c&&e.length>0&&!e.some(u=>u.latexImage||u.marks?.latex)){const u=e,p={segments:u.map(w=>({text:w.text}))},S=ae(p,d);if(S){const w=(D,V)=>{let M=0,N=0;for(const G of u){const H=Math.max(D,N),j=Math.min(V,N+G.text.length);if(H<j){const _=G.text.slice(H-N,j-N);this.setRunFont(t,{...G,text:_},o),t.setFontSize(this.getRunEffectiveFontSizePt(G.marks,l)),M+=this.measureRunDisplayWidthPt(t,_,G.marks)}N+=G.text.length}return M},C=u.map(D=>D.text).join("");e=ie(p,S,w,n==="justify"&&!g).map(D=>({...u[D.segmentIndex],text:C.slice(D.start,D.end),rtl:D.rtl}))}}if(P?.tabRtl&&c&&c.length>0){const u=e,p=c,S=[],w=[];let C=0;for(;C<u.length;){const D=u[C];if(D.text===" "){S.push(D),w.push(p[C]??{startX:0,endX:0}),C++;continue}const V=C;let M=Number.NEGATIVE_INFINITY;for(;C<u.length&&u[C].text!==" ";){const O=p[C];O&&(M=Math.max(M,O.endX)),C++}const N=u.slice(V,C),G=N.map(O=>O.text).join("");if(!G)continue;Number.isFinite(M)||(M=0);const H={segments:N.map(O=>({text:O.text}))},j=ae(H,"rtl");if(!j){for(let O=V;O<C;O++)S.push(u[O]),w.push(p[O]??{startX:0,endX:0});continue}const _=ie(H,j,(O,K)=>{let W=0,L=0;for(const A of N){const U=Math.max(O,L),z=Math.min(K,L+A.text.length);if(U<z){const Y=A.text.slice(U-L,z-L);this.setRunFont(t,{...A,text:Y},o),t.setFontSize(this.getRunEffectiveFontSizePt(A.marks,l)),W+=this.measureRunDisplayWidthPt(t,Y,A.marks)}L+=A.text.length}return W}),y=_.reduce((O,K)=>O+K.width,0),X=M*this.PX_TO_PT-y;for(const O of _)S.push({...N[O.segmentIndex],text:G.slice(O.start,O.end),rtl:O.rtl}),w.push({startX:(X+O.x)/this.PX_TO_PT,endX:(X+O.x+O.width)/this.PX_TO_PT})}e=S,c=w}let T=0,m=0;for(const u of e)if(u.latexImage){const p=u.latexImage.contentHeight*this.PX_TO_PT;p>m&&(m=p)}else{const p=f(u);p>T&&(T=p)}T===0&&(T=l);const x=a+T;let F=0;if(c&&c.length>0)F=P?.tabRtl?(P.tabWidthPx??Math.max(...c.map(u=>u.endX)))*this.PX_TO_PT:c[c.length-1].endX*this.PX_TO_PT;else for(const u of e)u.latexImage?F+=u.latexImage.contentWidth*this.PX_TO_PT:(this.setRunFont(t,u,o),t.setFontSize(this.getRunEffectiveFontSizePt(u.marks,l)),F+=this.measureRunDisplayWidthPt(t,u.text,u.marks));let b=i;n==="center"?b=i+(r-F)/2:(n==="right"||n==="justify"&&d==="rtl"&&(g||c))&&(b=i+r-F),P?.tabRtl&&c&&(b=i);let E=0;if(n==="justify"&&!g&&!c){let u=0;for(const p of e)p.latexImage||p.marks?.latex||(u+=(p.text.match(/ /g)||[]).length);u>0&&(E=Math.max(0,(r-F)/u))}const R=b;for(let u=0;u<e.length;u++){const p=e[u],S=c?.[u];if(S&&(b=R+S.startX*this.PX_TO_PT,p.text===" ")){if(S.leader){const W=this.getRunEffectiveFontSizePt(p.marks,l),L=p.marks?.color?this.hexToRgb(p.marks.color):{r:0,g:0,b:0};this.renderTabLeaderPdf(t,R+S.startX*this.PX_TO_PT,R+S.endX*this.PX_TO_PT,x,S.leader,W,L)}b=R+S.endX*this.PX_TO_PT;continue}if(p.latexImage){const W=p.latexImage.width*this.PX_TO_PT,L=p.latexImage.height*this.PX_TO_PT,A=p.latexImage.contentWidth*this.PX_TO_PT,U=p.latexImage.contentHeight*this.PX_TO_PT,z=(W-A)/2,Y=b-z,Z=x-U*.7-z;try{t.addImage(p.latexImage.dataUrl,"PNG",Y,Z,W,L)}catch(Q){console.error("Failed to add inline latex image to PDF:",Q)}b+=A;continue}this.setRunFont(t,p,o);const w=f(p),C=this.getRunEffectiveFontSizePt(p.marks,l),D=C/this.PX_TO_PT;t.setFontSize(C);const V=!!p.marks?.link;let M={r:0,g:0,b:0};V?M={r:37,g:99,b:235}:p.marks?.color?M=this.hexToRgb(p.marks.color):p.marks?.code&&(M=this.hexToRgb(Lt.codeText)),t.setTextColor(M.r,M.g,M.b);const N=!!(p.marks?.smallCaps&&!p.marks?.allCaps),G=this.getRunLetterSpacingPt(p.marks),H=p.rtl?{isInputVisual:!1,isOutputVisual:!0,isInputRtl:!0,isOutputRtl:!1}:void 0,j=G!==0||H?{...G!==0?{charSpace:G}:{},...H}:void 0,_=this.measureRunDisplayWidthPt(t,p.text,p.marks),y=E>0?(p.text.match(/ /g)||[]).length:0,X=_+y*E;if(p.marks?.backgroundColor){const W=Ye(p.marks.backgroundColor)??p.marks.backgroundColor,L=this.hexToRgb(W);t.setFillColor(L.r,L.g,L.b),t.rect(b,x-w*.8,X,w*1.1,"F"),t.setTextColor(M.r,M.g,M.b)}else if(p.marks?.code){const W=this.hexToRgb(Lt.codeBackground);t.setFillColor(W.r,W.g,W.b),this.drawRoundedRect(t,b-2*this.PX_TO_PT,x-w*.93,X+4*this.PX_TO_PT,w+4*this.PX_TO_PT,3*this.PX_TO_PT),t.setTextColor(M.r,M.g,M.b)}let O=x;p.marks?.superscript?O=x-w*.4:p.marks?.subscript&&(O=x+w*.15),(p.marks?.underline||V)&&!p.marks?.code&&(V?t.setDrawColor(37,99,235):t.setDrawColor(0,0,0),t.setLineWidth(.5),t.line(b,O+2,b+X,O+2));const K=(W,L)=>{const A=p.marks?.allCaps?Xt(W,p.marks.lang):W,U=this.drawShapedText(t,A,L,O,C,G,M);if(U!==null)return U;if(N){let z=L;for(const Y of ca(W,p.marks?.lang)){const Z=Y.lower?t.getTextWidth(Xt(Y.text,p.marks?.lang))*ne:t.getTextWidth(Y.text);Y.lower?(t.setFontSize(C*ne),t.text(Xt(Y.text,p.marks?.lang),z,O,j),t.setFontSize(C)):t.text(Y.text,z,O,j),z+=Z+G*Y.text.length}return z-L}return t.text(A,L,O,j),this.measureRunDisplayWidthPt(t,W,p.marks)};if(E>0){let W=b;for(const L of p.text.split(/( +)/))L&&(W+=K(L,W),L[0]===" "&&(W+=E*L.length))}else K(p.text,b);if(p.marks?.strikethrough||p.marks?.doubleStrikethrough){t.setDrawColor(M.r,M.g,M.b),t.setLineWidth(Math.max(1,Math.round(D*.04))*this.PX_TO_PT);const W=L=>{const A=L-C*.3;t.line(b,A,b+X,A)};p.marks?.doubleStrikethrough?(W(O+C*.09),W(O-C*.09)):W(O)}if(V&&p.marks?.link){const W=x-w*.8,L=w*1.1;t.link(b,W,X,L,{url:p.marks.link})}b+=X}if(P?.hyphenTrailing){const u=e[e.length-1];if(u&&!u.marks?.latex){this.setRunFont(t,u,o),t.setFontSize(this.getRunEffectiveFontSizePt(u.marks,l));const p=u.marks?.color?this.hexToRgb(u.marks.color):{r:0,g:0,b:0};t.setTextColor(p.r,p.g,p.b),t.text("-",b,x)}}const B=s??(h?this.LINE_HEIGHT_MULTIPLIERS.heading:this.LINE_HEIGHT_MULTIPLIERS.paragraph),k=T*B,I=m>k*1.25?m:k;return a+I}static renderTabLeaderPdf(t,e,a,i,r,n,l){const o=Math.max(1.5,n*.12),h=e+o,s=a-o;if(s-h<1)return;if(t.setFillColor(l.r,l.g,l.b),r==="underscore"){const P=i+Math.max(1,n*.08),c=Math.max(.75,n*.055);t.rect(h,P,s-h,c,"F");return}const g=Math.max(2.25,n*.33);if(r==="dot"){const P=Math.max(.45,n*.045),c=i-P;for(let f=Math.ceil(h/g)*g;f<=s;f+=g)t.circle(f,c,P,"F")}else{const P=Math.max(1.5,n*.18),c=i-n*.28,f=Math.max(.75,n*.055);for(let d=Math.ceil(h/g)*g;d+P<=s;d+=g)t.rect(d,c,P,f,"F")}}static processTextNodes(t){const e=[];for(const a of t)if(a.type==="text"){const i=a;if(i.marks?.hidden&&!i.marks.footnoteRef)continue;e.push({text:i.text,marks:i.marks,font:i.marks?.fontFamily})}return e}static async processTextNodesWithLatex(t,e){const a=[];for(let n=0;n<t.length;n++){const l=t[n];if(l.type==="text"){const o=l;if(o.marks?.hidden&&!o.marks.footnoteRef)continue;o.marks?.latex?a.push({index:n,node:o,latexPromise:this.renderLatexToImage(o.text,!1,e)}):a.push({index:n,node:o})}}const i=await Promise.all(a.map(n=>n.latexPromise||Promise.resolve(null))),r=[];for(let n=0;n<a.length;n++){const{node:l}=a[n],o=i[n];r.push({text:l.text,marks:l.marks,font:l.marks?.fontFamily,latexImage:o||void 0})}return r}static getParagraphFontSize(t){return $e(t)*this.PX_TO_PT}static getParagraphLineHeight(t){return this.getParagraphFontSize(t)*qt(t)}static getEmptyParagraphLineHeight(t){return this.measureLineAdvancePt(this.paragraphForPdfOutput(t).children.map(e=>({marks:e.type==="text"?e.marks:void 0})),this.getParagraphFontSize(t),!!t.heading,this.getLineSpacingMultiplier(t))}static async embedLocalFonts(t,e){if(this.embeddedFamilyNames.clear(),typeof window>"u")return;const a=new Set(["sans-serif","sans","serif","monospace","system-ui","system ui","ui-sans-serif","ui-serif","ui-monospace"]),i=Nt(e).map(n=>n.family).filter(n=>{const l=n.toLowerCase();return!a.has(l)&&this.FONT_MAP[l]!=="KaTeX_Main"});if(i.length===0)return;let r;for(const n of i){const l=n.toLowerCase();let o=this.localFontFiles.get(l);if(o===void 0){if(r===void 0&&(r=await Ve().catch(()=>null)),!r)return;try{o=await this.buildLocalFontFiles(n,r)}catch{o=null}this.localFontFiles.set(l,o)}if(o)try{for(const h of o)t.addFileToVFS(h.vfsName,h.base64),t.addFont(h.vfsName,n,h.style);this.embeddedFamilyNames.set(l,n)}catch(h){console.warn(`Failed to embed font "${n}" in PDF:`,h),this.localFontFiles.set(l,null)}}}static async buildLocalFontFiles(t,e){const a=t.toLowerCase(),i=e.filter(c=>c.family?.trim().toLowerCase()===a&&c.blob);if(i.length===0)return null;const r=i.map(c=>({entry:c,...Ze(c.style),specificity:(c.style??"").length})),n=(c,f)=>r.filter(d=>d.bold===c&&d.italic===f).sort((d,T)=>d.specificity-T.specificity)[0]?.entry,l=n(!1,!1)??r[0].entry,o=[{style:"normal",entry:l},{style:"bold",entry:n(!0,!1)??l},{style:"italic",entry:n(!1,!0)??l},{style:"bolditalic",entry:n(!0,!0)??n(!0,!1)??l}],h=new Map;for(const{entry:c}of o){if(h.has(c))continue;const f=await(await c.blob()).arrayBuffer(),d=Ht(new Uint8Array(f));h.set(c,d==="ttf"?this.arrayBufferToBase64(f):null)}if(!h.get(l))return null;const s=a.replace(/[^a-z0-9]+/g,"-"),g=new Map;let P=0;return o.map(({style:c,entry:f})=>{const d=h.get(f)?f:l;let T=g.get(d);return T||(T=`${s}-${P++}.ttf`,g.set(d,T)),{vfsName:T,base64:h.get(d),style:c}})}static mapFontFamily(t){const e=this.mapFontFamilyToStandard(t);return this.bundledGenreFamilies.get(e)??(e==="SourceSerif4"?"times":e)}static mapFontFamilyToStandard(t){if(!t)return"helvetica";const e=new Set(["helvetica","times","courier"]),a=t.split(",").map(r=>r.trim().replace(/^['"]|['"]$/g,"")).filter(r=>r.length>0);a.length===0&&a.push(t);for(const r of a){const n=r.toLowerCase(),l=this.embeddedFamilyNames.get(n);if(l)return l;if(e.has(n))return n;const o=this.FONT_MAP[n];if(o)return o}const i=Je(a[0]);return i==="serif"?"times":i==="monospace"?"courier":"helvetica"}static resolveFontStyle(t){const e=!!t?.bold,a=!!t?.italic;return e&&a?"bolditalic":e?"bold":a?"italic":"normal"}static drawPdfBorderEdge(t,e,a,i,r,n){if(e.style==="none"||e.width<=0)return;const l=this.hexToRgb(e.color);t.setDrawColor(l.r,l.g,l.b);const o=Qe(e).map(h=>h*this.PX_TO_PT);if(o.length>0&&typeof t.setLineDashPattern=="function"&&t.setLineDashPattern(o,0),e.style==="double"){const h=Math.max(e.width/3,.5)*this.PX_TO_PT,s=e.width*2/3/2*this.PX_TO_PT;t.setLineWidth(h);const g=i===n,P=g?0:s,c=g?s:0;t.line(a-P,i-c,r-P,n-c),t.line(a+P,i+c,r+P,n+c)}else t.setLineWidth(e.width*this.PX_TO_PT),t.line(a,i,r,n);o.length>0&&typeof t.setLineDashPattern=="function"&&t.setLineDashPattern([],0)}static hexToRgb(t){return qe(t)??{r:0,g:0,b:0}}static async renderImageBlock(t,e,a,i,r=this.getDefaultPdfLayoutMetrics()){if(!e.src)return{nextY:a};const n=this.getPdfFlowBottom(t,r);let l=Math.max(e.width||1,1)*this.PX_TO_PT,o=Math.max(e.height||1,1)*this.PX_TO_PT;if(l>i){const c=i/l;l=i,o*=c}(o<=0||!Number.isFinite(o))&&(o=72);let h=r.marginLeftPt;if(a+o>n&&a!==r.marginTopPt){const c=this.advancePdfFlowRegion(t,r);a=c.y,h=c.x}const s=e.align||"left";let g=h;if(s==="center"?g=h+(i-l)/2:s==="right"&&(g=h+i-l),e.originalFormat)return t.setFillColor(243,244,246),t.setDrawColor(209,213,219),t.setLineWidth(.75),t.rect(g,a,l,o,"FD"),t.setFont(this.mapFontFamily(void 0),"normal"),t.setFontSize(14*this.PX_TO_PT),t.setTextColor(107,114,128),t.text(`${e.originalFormat.toUpperCase()} image`,g+l/2,a+o/2,{align:"center",baseline:"middle"}),{nextY:a+o};const P=await this.resolveImageDataCached(t,e.src);if(!P)return{nextY:a+o};try{t.addImage(P.data,P.format,g,a,l,o)}catch(c){return console.error("Failed to add image to PDF",c),{nextY:a+o}}return{nextY:a+o}}static resolveImageDataCached(t,e){let a=this.imageDataCache.get(t);a||(a=new Map,this.imageDataCache.set(t,a));let i=a.get(e);return i||(i=this.resolveImageData(e),a.set(e,i)),i}static async resolveImageData(t){if(/^data:image\/svg\+xml[;,]/i.test(t))return this.rasterizeSvgImage(t);const e=t.match(/^data:image\/([a-zA-Z0-9+.-]+);base64,/);if(e){const l=this.normalizeImageFormat(e[1]);return{data:t,format:l}}const a=await this.fetchImageAsBlob(t);if(!a)return null;const{blob:i,format:r}=a,n=await this.blobToDataUrl(i,r);return r==="SVG+XML"?this.rasterizeSvgImage(n):{data:n,format:r}}static async rasterizeSvgImage(t){const e=this.decodeSvgDataUrl(t);if(!e)return null;const a=this.svgIntrinsicSize(e),i=2;if(typeof process<"u"&&process.versions?.node&&(typeof navigator>"u"||/jsdom|node/i.test(navigator.userAgent??"")))try{const n=await import(["can","vas"].join("")),l=await n.loadImage(Buffer.from(e,"utf8")),o=n.createCanvas(Math.max(1,Math.round(a.width*i)),Math.max(1,Math.round(a.height*i)));return o.getContext("2d").drawImage(l,0,0,o.width,o.height),{data:o.toDataURL("image/png"),format:"PNG"}}catch(n){return console.error("Failed to rasterize SVG image for PDF export",n),null}const r=await Promise.race([this.svgToPng(e,a.width,a.height,i),new Promise(n=>setTimeout(()=>n(null),5e3))]);return r?{data:r,format:"PNG"}:null}static decodeSvgDataUrl(t){const e=t.indexOf(",");if(e<0)return null;const a=t.slice(0,e),i=t.slice(e+1);try{if(/;base64$/i.test(a)){const r=globalThis?.Buffer;if(r)return r.from(i,"base64").toString();const n=atob(i),l=Uint8Array.from(n,o=>o.charCodeAt(0));return new TextDecoder().decode(l)}return decodeURIComponent(i)}catch{return null}}static svgIntrinsicSize(t){const e=/<svg\b[^>]*>/i.exec(t)?.[0]??"",a=o=>{const h=new RegExp(`\\s${o}="([\\d.]+)(px)?"`,"i").exec(e),s=h?Number(h[1]):NaN;return Number.isFinite(s)&&s>0?s:void 0},i=/\sviewBox="([^"]+)"/i.exec(e)?.[1]?.trim().split(/[\s,]+/).map(Number),r=i&&i.length===4&&i[2]>0?i[2]:void 0,n=i&&i.length===4&&i[3]>0?i[3]:void 0,l=o=>Math.min(4e3,Math.max(1,o));return{width:l(a("width")??r??300),height:l(a("height")??n??150)}}static async fetchImageAsBlob(t){try{const e=await fetch(t);if(!e.ok)throw new Error(`Failed to fetch image: ${e.status}`);const a=await e.blob(),i=this.extractImageFormat(a.type);return{blob:a,format:i}}catch(e){return console.error("Failed to load image for PDF export",e),null}}static async blobToDataUrl(t,e){const a=await t.arrayBuffer(),i=this.arrayBufferToBase64(a);return`data:${this.formatToMime(e)};base64,${i}`}static arrayBufferToBase64(t){const e=globalThis?.Buffer;if(e)return e.from(t).toString("base64");let a="";const i=new Uint8Array(t),r=32768;for(let n=0;n<i.length;n+=r){const l=i.subarray(n,n+r);a+=String.fromCharCode.apply(null,Array.from(l))}return btoa(a)}static formatToMime(t){const e=t.toLowerCase();return e==="jpeg"||e==="jpg"?"image/jpeg":e==="png"?"image/png":e==="webp"?"image/webp":`image/${e}`}static extractImageFormat(t){if(!t)return"PNG";const e=t.match(/^image\/([a-zA-Z0-9+.-]+)/);return e?this.normalizeImageFormat(e[1]):"PNG"}static normalizeImageFormat(t){const e=t.toLowerCase();return e==="jpg"||e==="jpeg"?"JPEG":e==="png"?"PNG":e==="webp"?"WEBP":e.toUpperCase()}static async renderMathBlock(t,e,a,i,r,n=this.getDefaultPdfLayoutMetrics()){if(!e.content||e.content.trim()==="")return{nextY:a};const l=e.displayMode!=="inline",o=await this.renderLatexToImage(e.content,l);if(!o)return{nextY:a+20};let h=o.width*this.PX_TO_PT,s=o.height*this.PX_TO_PT;const g=i-this.MATH_BLOCK_PADDING*2;if(h>g){const x=g/h;h=g,s*=x}const P=Math.max(this.MATH_BLOCK_MIN_HEIGHT,s)+this.MATH_BLOCK_PADDING*2;let c=n.marginLeftPt;if(a+P>r&&a!==n.marginTopPt){const x=this.advancePdfFlowRegion(t,n);a=x.y,c=x.x}const f=this.hexToRgb(ee().codeBorder||"#e0e0e0");t.setDrawColor(f.r,f.g,f.b),t.setLineWidth(this.BLOCK_BORDER_WIDTH_PT),typeof t.roundedRect=="function"?t.roundedRect(c,a,i,P,this.MATH_BLOCK_BORDER_RADIUS,this.MATH_BLOCK_BORDER_RADIUS,"S"):t.rect(c,a,i,P,"S");const d=e.align||"center";let T=c+this.MATH_BLOCK_PADDING;d==="center"?T=c+(i-h)/2:d==="right"&&(T=c+i-h-this.MATH_BLOCK_PADDING);const m=a+(P-s)/2;try{t.addImage(o.dataUrl,"PNG",T,m,h,s)}catch(x){console.error("Failed to add math image to PDF:",x)}return{nextY:a+P}}static async getHtml2Canvas(){return this.html2canvasModule?this.html2canvasModule:this.html2canvasLoading?this.html2canvasLoading:(this.html2canvasLoading=import("./html2canvas.esm-CntiHiYW.js").then(t=>(this.html2canvasModule=t.default,t.default)),this.html2canvasLoading)}static async renderLatexToImage(t,e,a=12){const i=this.getLatexSvgFromCache(t,e);if(i){const r=await this.svgToPng(i.svg,i.width,i.height,3);if(r){const n=e?1:this.INLINE_MATH_SCALE;return{dataUrl:r,width:i.width*n,height:i.height*n,contentWidth:i.contentWidth*n,contentHeight:i.contentHeight*n}}}try{const r=await this.getHtml2Canvas(),n=this.preprocessLaTeX(t),l=(await ta()).renderToString(n,{displayMode:e,throwOnError:!1,errorColor:"#ef4444",trust:!1,strict:!1});this.ensureKaTeXStyles();const o=a/this.PX_TO_PT,h=e?20:o*this.INLINE_MATH_SCALE,s=4,g=document.createElement("div");g.style.cssText=`
5
+ position: fixed;
6
+ top: -9999px;
7
+ left: -9999px;
8
+ font-size: ${h}px;
9
+ line-height: 1.2;
10
+ background: transparent;
11
+ padding: ${s}px;
12
+ z-index: -9999;
13
+ `,g.innerHTML=l,document.body.appendChild(g),document.fonts?.ready&&await document.fonts.ready;const P=4,c=await r(g,{backgroundColor:null,scale:P,logging:!1,useCORS:!0,allowTaint:!1});document.body.removeChild(g);const f=c.toDataURL("image/png"),d=c.width/P,T=c.height/P,m=d-s*2,x=T-s*2;return{dataUrl:f,width:d,height:T,contentWidth:m,contentHeight:x}}catch(r){return console.error("Failed to render LaTeX for PDF:",r),null}}static preprocessLaTeX(t){if(!t.includes(`
14
+ `)||["align","aligned","gather","gathered","split","cases","matrix","pmatrix","bmatrix","array"].some(a=>t.includes(`\\begin{${a}}`)||t.includes(`\\begin{${a}*}`)))return t;const e=t.split(`
15
+ `).map(a=>a.trim()).filter(a=>a.length>0);return e.length<=1?t:`\\begin{gathered}
16
+ ${e.join(` \\\\
17
+ `)}
18
+ \\end{gathered}`}static ensureKaTeXStyles(){if(this.katexStylesLoaded)return;if(document.querySelector('link[href*="katex"]')){this.katexStylesLoaded=!0;return}const t=document.createElement("link");t.rel="stylesheet",t.href=Ft("katex.min.css"),document.head.appendChild(t),this.katexStylesLoaded=!0}static async parseFile(t){const e=await import("./pdf-BLWDCiFF.js");e.GlobalWorkerOptions.workerSrc=Ft("pdfjs/worker.js");const a=await t.arrayBuffer();try{const i=await e.getDocument(a).promise;let r="";for(let h=1;h<=i.numPages;h++){const s=(await(await i.getPage(h)).getTextContent()).items.map(g=>g.str).join(" ");r+=s+`
19
+
20
+ `}const n=r.trim().split(`
21
+ `),l=[];let o=[];for(let h=0;h<n.length;h++){const s=n[h].trim();if(s===""){if(o.length>0){const g=o.join(" ").trim();g&&l.push(wt([{type:"text",text:g}])),o=[]}}else{const g=s.length<60,P=s===s.toUpperCase()&&/[A-Z]/.test(s),c=/[.!?]$/.test(s),f=h+1<n.length&&n[h+1].trim()==="";if(g&&(P||f&&!c)){if(o.length>0){const d=o.join(" ").trim();d&&l.push(wt([{type:"text",text:d}])),o=[]}l.push(wt([{type:"text",text:s}]))}else o.push(s)}}if(o.length>0){const h=o.join(" ").trim();h&&l.push(wt([{type:"text",text:h}]))}return l.length===0&&l.push(wt()),{type:"doc",children:l}}catch(i){throw console.error("Failed to parse PDF:",i),new Error(`Failed to parse PDF: ${i instanceof Error?i.message:"Unknown error"}`)}}};v.PAGE_WIDTH=612,v.PAGE_HEIGHT=792,v.MARGIN_LEFT=72,v.MARGIN_RIGHT=72,v.MARGIN_TOP=72,v.MARGIN_BOTTOM=72,v.PX_TO_PT=re,v.UNBOUNDED_CELL_FLOW_BOTTOM_PT=1e4,v.DEFAULT_BODY_FONT="Arial, sans-serif",v.LINE_HEIGHT_MULTIPLIERS=se,v.FONT_SIZES={h1:bt.h1*v.PX_TO_PT,h2:bt.h2*v.PX_TO_PT,h3:bt.h3*v.PX_TO_PT,h4:bt.h4*v.PX_TO_PT,h5:bt.h5*v.PX_TO_PT,h6:bt.h6*v.PX_TO_PT,normal:bt.paragraph*v.PX_TO_PT},v.FONT_MAP={arial:"helvetica",helvetica:"helvetica","helvetica neue":"helvetica","times new roman":"times",georgia:"times","source serif 4":"SourceSerif4",times:"times",courier:"courier","courier new":"courier",monospace:"courier",verdana:"helvetica",tahoma:"helvetica",inter:"helvetica","system-ui":"helvetica","system ui":"helvetica","ui-sans-serif":"helvetica","ui-serif":"times","ui-monospace":"courier","sans-serif":"helvetica",sans:"helvetica",serif:"times",katex_main:"KaTeX_Main",computermodern:"KaTeX_Main","computer modern":"KaTeX_Main"},v.TODO_LIST_INDENT_PT=Pt.variantIndentPx.todo*v.PX_TO_PT,v.ORDERED_LIST_INDENT_PT=Pt.variantIndentPx.ordered*v.PX_TO_PT,v.UNORDERED_LIST_INDENT_PT=Pt.variantIndentPx.unordered*v.PX_TO_PT,v.SUBLIST_INDENT_PT=Pt.sublistIndentPx*v.PX_TO_PT,v.BULLET_MARKER_WIDTH_PT=Pt.markerWidthPx*v.PX_TO_PT,v.BULLET_CENTER_OFFSET_PT=8*v.PX_TO_PT,v.BULLET_RADIUS_PT=2.5*v.PX_TO_PT,v.BULLET_SQUARE_INSET_PT=5*v.PX_TO_PT,v.BULLET_SQUARE_HALF_PT=5*v.PX_TO_PT,v.BULLET_SQUARE_VERTICAL_ADJUST_PT=1*v.PX_TO_PT,v.ORDERED_LABEL_GAP_PT=6*v.PX_TO_PT,v.TODO_CHECKBOX_SIZE_PT=Pt.todoCheckboxSizePx*v.PX_TO_PT,v.TODO_CHECKBOX_RADIUS_PT=Pt.todoCheckboxRadiusPx*v.PX_TO_PT,v.TODO_CHECKBOX_OFFSET_PT=Pt.todoCheckboxOffsetPx*v.PX_TO_PT,v.MAX_LIST_INDENT_LEVEL=Pt.maxIndentLevel,v.MATH_BLOCK_PADDING=16*v.PX_TO_PT,v.MATH_BLOCK_MIN_HEIGHT=40*v.PX_TO_PT,v.MATH_BLOCK_BORDER_RADIUS=4*v.PX_TO_PT,v.BLOCK_BORDER_WIDTH_PT=1*v.PX_TO_PT,v.INLINE_MATH_SCALE=.85,v.BUNDLED_GENRE_FONTS={SourceSerif4:{family:"SourceSerif4",files:{normal:"SourceSerif4-Regular.ttf",bold:"SourceSerif4-Bold.ttf",italic:"SourceSerif4-It.ttf",bolditalic:"SourceSerif4-BoldIt.ttf"}},helvetica:{family:"LiberationSans",files:{normal:"LiberationSans-Regular.ttf",bold:"LiberationSans-Bold.ttf",italic:"LiberationSans-Italic.ttf",bolditalic:"LiberationSans-BoldItalic.ttf"}},times:{family:"LiberationSerif",files:{normal:"LiberationSerif-Regular.ttf",bold:"LiberationSerif-Bold.ttf",italic:"LiberationSerif-Italic.ttf",bolditalic:"LiberationSerif-BoldItalic.ttf"}},courier:{family:"LiberationMono",files:{normal:"LiberationMono-Regular.ttf",bold:"LiberationMono-Bold.ttf",italic:"LiberationMono-Italic.ttf",bolditalic:"LiberationMono-BoldItalic.ttf"}}},v.bundledGenreFamilies=new Map,v.SCRIPT_FALLBACK_FONTS=ua,v.scriptFallbackFamilies=new Map,v.scriptFontCoverageCache=new Map,v.fallbackCharsetCache=new Map,v.shapingFonts=new Map,v.inlineCodeFontFamily="courier",v.fontFileData=new Map,v.localFontFiles=new Map,v.embeddedFamilyNames=new Map,v.COLUMN_BALANCE_SLACK_PT=1.5,v.imageDataCache=new WeakMap,v.html2canvasModule=null,v.html2canvasLoading=null,v.katexStylesLoaded=!1;let pa=v;export{pa as PdfConverter};