revise 4.0.0 → 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.
- package/CHANGELOG.md +6 -0
- package/README.md +6 -11
- package/chunks/{AgentPageRenderer-5mZ6fxqO.js → AgentPageRenderer-CHHktDQ1.js} +1 -1
- package/chunks/{AgentPageRenderer-C3jIBoeM.js → AgentPageRenderer-CN-N65JC.js} +1 -1
- package/chunks/{AttachmentDocumentImporter-CXkM4VoT.js → AttachmentDocumentImporter-DnHC9t7I.js} +1 -1
- package/chunks/{AttachmentDocumentImporter-Kox5By7a.js → AttachmentDocumentImporter-Dqg7IPtK.js} +1 -1
- package/chunks/{DocumentScrubber-BxmlzNNz.js → DocumentScrubber-Ch_bOtHW.js} +1 -1
- package/chunks/{DocumentScrubber-wmjRnX7C.js → DocumentScrubber-DRzACkWJ.js} +1 -1
- package/chunks/{DocxConverter-BH3E7nfQ.js → DocxConverter-BGPkGmyg.js} +1 -1
- package/chunks/{DocxConverter-DEHGCdib.js → DocxConverter-DeurS5EF.js} +1 -1
- package/chunks/{DocxGraft-BMvTAnGi.js → DocxGraft-D71OgoMh.js} +1 -1
- package/chunks/{DocxGraft-V2YXiUmK.js → DocxGraft-QLkGEcwQ.js} +1 -1
- package/chunks/{FileImporter-CtX8ZPjV.js → FileImporter-BIT0ZBDY.js} +1 -1
- package/chunks/{FileImporter-Da-7eRh3.js → FileImporter-Cgwoawuk.js} +1 -1
- package/chunks/{OdtConverter-CMkSeU8e.js → OdtConverter-2pm0SH5c.js} +1 -1
- package/chunks/{OdtConverter-DV94rkDL.js → OdtConverter-CSUQTfVp.js} +1 -1
- package/chunks/{OfficeImportShared-CA3dia_A.js → OfficeImportShared-C_mYnG5V.js} +1 -1
- package/chunks/{OfficeImportShared-hxIa69By.js → OfficeImportShared-O-d47J7O.js} +1 -1
- package/chunks/{PdfConverter-B-uRwLux.js → PdfConverter-BYg_pr5J.js} +1 -1
- package/chunks/{PdfConverter-B8J_5yim.js → PdfConverter-Z2HlY84F.js} +1 -1
- package/chunks/{PdfImportService-BjQ4rl-Z.js → PdfImportService-C2gwK1Sq.js} +1 -1
- package/chunks/{PdfImportService-RtFCP6hh.js → PdfImportService-CxtUtxM6.js} +1 -1
- package/chunks/{RtfConverter-CFDnUApT.js → RtfConverter-BrtojpDV.js} +1 -1
- package/chunks/{RtfConverter-CpJGtC5U.js → RtfConverter-DlztsAoK.js} +1 -1
- package/chunks/{XmlConverter-CQCrgTf7.js → XmlConverter-3XWISlqr.js} +1 -1
- package/chunks/{XmlConverter-CePTE21k.js → XmlConverter-B1Kcohr0.js} +1 -1
- package/chunks/{browser-module-B-uafDG6.js → browser-module-BVdVmrPb.js} +1 -1
- package/chunks/{browser-module-jwkhffzv.js → browser-module-CWlRHeO2.js} +1 -1
- package/chunks/{index-C7VhCKXe.js → index-D9_PwgOX.js} +9 -9
- package/chunks/{index-p6UytRm8.js → index-DcIXw_KB.js} +9 -9
- package/chunks/{pseudoLocale-Bkzfsfiw.js → pseudoLocale-Bld5ZUFr.js} +1 -1
- package/chunks/{pseudoLocale-D-AfwRwa.js → pseudoLocale-CLm3_c4X.js} +1 -1
- package/cli-shim.js +1 -1
- package/full.js +1 -1
- package/index.js +1 -1
- package/package.json +3 -3
- package/version.js +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,22 +1,12 @@
|
|
|
1
1
|
# revise
|
|
2
2
|
|
|
3
|
-
A word processor for React apps: full DOCX support, tracked changes, comments,
|
|
3
|
+
A [word processor for React apps](https://revise.io/sdk): full DOCX support, tracked changes, comments,
|
|
4
4
|
collaboration, and tools for AI agents.
|
|
5
5
|
|
|
6
6
|
```bash
|
|
7
7
|
npm i revise
|
|
8
8
|
```
|
|
9
9
|
|
|
10
|
-
```tsx
|
|
11
|
-
import ReviseEditor from "revise";
|
|
12
|
-
import "revise/style.css";
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
For server-side work (conversion, seeding collaboration rooms, headless edits)
|
|
16
|
-
and the `revise` command line tool, use [`@reviseio/cli`](https://www.npmjs.com/package/@reviseio/cli).
|
|
17
|
-
|
|
18
|
-

|
|
19
|
-
|
|
20
10
|
## Getting started
|
|
21
11
|
|
|
22
12
|
Get started with the [quickstart guide](https://revise.io/developer/docs/editor-sdk/quickstart).
|
|
@@ -42,6 +32,11 @@ no user data or document content. Pass `telemetry={false}` to turn it off.
|
|
|
42
32
|
|
|
43
33
|
Refer to the [SDK Docs](https://revise.io/developer/docs/editor-sdk) for the full editor API, including agentic tool calling.
|
|
44
34
|
|
|
35
|
+
## Use Revise Headless
|
|
36
|
+
|
|
37
|
+
For server-side work (conversion, seeding collaboration rooms, headless edits)
|
|
38
|
+
and the `revise` command line tool, use [`@reviseio/cli`](https://www.npmjs.com/package/@reviseio/cli).
|
|
39
|
+
|
|
45
40
|
## License
|
|
46
41
|
|
|
47
42
|
The Revise editor is closed-source software, free for evaluation, personal projects, and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as x from"yjs";import{N as P,O as Y,S as k,Q as C,T as D,U as B,V as A,W as G,X as j,E as z,Y as Q,Z as V,_ as X,$ as Z,a0 as J,a1 as K,a2 as ee,a3 as te,a4 as oe}from"./index-C7VhCKXe.js";function $(e,t,n,i){if(Array.isArray(e)){for(const s of e)$(s,t,n,i);return}if(!e||typeof e!="object")return;const a=e,o=typeof a.id=="string"?a.id:t;a.type==="math"&&typeof a.content=="string"&&n.push({content:a.content,displayMode:a.displayMode!=="inline",blockId:o}),a.type==="text"&&typeof a.text=="string"&&a.marks?.latex&&n.push({content:a.text,displayMode:!1,blockId:o}),a.type==="image"&&typeof a.src=="string"&&i.push({src:a.src,blockId:o,permanentlyPlaceholder:a.originalFormat==="emf"||a.originalFormat==="wmf"});for(const s of Object.values(a))if(Array.isArray(s))for(const r of s)$(r,o,n,i);else s&&typeof s=="object"&&$(s,o,n,i)}function E(){return new Promise(e=>{let t=!1;const n=()=>{t||(t=!0,clearTimeout(i),e())},i=setTimeout(n,50);typeof requestAnimationFrame=="function"&&requestAnimationFrame(n)})}async function ne(e,t){if(e.length===0)return;const n=Promise.allSettled(e.map(i=>Q(i.content,i.displayMode,t)));await Promise.race([n,new Promise(i=>setTimeout(i,2500))]),await E(),await E()}function R(e,t){if(typeof e.pageNumber=="number")return e.pageNumber-1;const n=e.bounds.y;return t.pageGeometries?.find(i=>n>=i.pageTop&&n<i.pageTop+i.pageHeight)?.pageIndex??0}function ae(e,t){return new Set(e.fragments.filter(n=>t.has(R(n,e))).map(n=>n.blockId))}function ie(e){return e==="table"?"#7c3aed":e==="table-cell"||e==="table-row"?"#db2777":e==="image"?"#ea580c":e==="container"?"#2563eb":e==="math"?"#ca8a04":"#0891b2"}function L(e,t,n){e.save(),e.lineWidth=.75,e.setLineDash([4,3]),e.strokeStyle="rgba(22, 163, 74, 0.9)",e.strokeRect(n.marginLeft,n.marginTop,n.pageWidth-n.marginLeft-n.marginRight,n.pageHeight-n.marginTop-n.marginBottom),e.setLineDash([]);const i=new Set;for(const a of t.fragments){if(R(a,t)!==n.pageIndex)continue;const{bounds:o}=a,s=o.relativeToPage?o.y:o.y-n.pageTop,r=`${a.blockId}:${Math.round(o.x)}:${Math.round(s)}:${Math.round(o.width)}:${Math.round(o.height)}`;if(i.has(r)||o.width<=0||o.height<=0)continue;i.add(r);const g=ie(a.block.type);if(e.strokeStyle=g,e.globalAlpha=.82,e.strokeRect(o.x,s,o.width,o.height),(a.block.type==="table"||a.block.type==="table-cell"||a.block.type==="image"||a.block.type==="container"||a.block.type==="math")&&o.width>=42&&o.height>=12){const l=`${a.block.type} #${a.blockId}`;e.font="10px ui-monospace, SFMono-Regular, Menlo, monospace",e.textAlign="left",e.textBaseline="top";const d=Math.min(o.width,e.measureText(l).width+5);e.globalAlpha=.88,e.fillStyle=g,e.fillRect(o.x,Math.max(0,s),d,13),e.globalAlpha=1,e.fillStyle="#ffffff",e.fillText(l,o.x+2,Math.max(0,s)+1,Math.max(1,d-4))}}e.restore()}function se(e,t){return{pageIndex:0,sectionIndex:0,pageTop:0,pageWidth:e.pageWidth,pageHeight:Math.min(4096,Math.max(e.pageHeight,t.totalHeight)),marginTop:e.pageMarginTop??e.pageMargin,marginRight:e.pageMarginRight??e.pageMargin,marginBottom:e.pageMarginBottom??e.pageMargin,marginLeft:e.pageMarginLeft??e.pageMargin,showPageNumbers:!1,pageNumberPosition:"bottom-right",renderedPageNumber:1}}const q=new WeakMap;let F=0;function re(e){let t=q.get(e);return t||(F+=1,t=`session-${F}`,q.set(e,t)),t}const H=new WeakMap;let W=0;function ce(e){let t=H.get(e);return t===void 0&&(W+=1,t=W,H.set(e,t)),t}function N(e){let t=2166136261;for(const n of e.join("\0"))t^=n.codePointAt(0),t=Math.imul(t,16777619)>>>0;return t.toString(36)}function ge(e){const t=e.getDocumentSession?.();if(!t)throw new k("document_unavailable","Rendered page inspection needs a loaded document. Wait for the document to open, then retry.","verification",!1);return t}function de(e){const t=e.getDetachedSuggestionStore?.();return{liveIds:[...e.getDocumentMutator().getLiveSuggestionIds()].sort(),legacyIds:t?[...t.getPendingSuggestions().keys()].sort():[]}}function le(e,t){return t!==P?"live-pending-suggestion-projection":e.isHistoryOpen()?"displayed-history-revision":"displayed-document"}function v(e,t){return`${e} ${t}${e===1?"":"s"}`}function he(e,t,n,i){const a=i.liveIds.length,o=i.legacyIds.length,s=v(o,"legacy detached suggestion");if(e==="displayed-history-revision")return"The past revision the editor displays while the history view is open, not the live document. The live document's pending suggestions are not part of this image.";if(e==="displayed-document"){const d=`The document as the editor displays it, with ${v(a,"pending suggestion")} drawn as tracked changes.`;return o>0?`${d} ${s} ${o===1?"is":"are"} pending outside the document and not drawn; show-with-tracked-changes-accepted previews them.`:d}const r=n?"The live document, not the past revision the history view displays,":"The live document",g=n?"":"; this view equals show-tracked-changes",l="in a private preview; nothing was resolved in the document.";if(t==="show-with-tracked-changes-accepted")return a>0?`${r} with all ${v(a,"pending suggestion")} accepted ${l}`:o>0?`${r} with all ${s} applied ${l}`:`${r} has no pending suggestions to accept${g}.`;if(a>0){const d=o>0?` ${s} stored outside the document ${o===1?"is":"are"} absent here as well.`:"";return`${r} with all ${v(a,"pending suggestion")} rejected ${l}${d}`}return o>0?`${r} as it stands: its ${s} ${o===1?"is":"are"} stored outside the document, so there is nothing to reject${g}.`:`${r} has no pending suggestions to reject${g}.`}function ue(e,t,n){const i=e.getDocumentId(),a=re(e),o=e.getDocumentMutator().derivedDocumentRevision,s=e.isHistoryOpen(),r=le(e,t),g=n.liveIds.length,l=n.legacyIds.length,d=t==="show-with-tracked-changes-accepted"?g>0?g:l:t==="show-before-tracked-changes"?g:0,w=r==="displayed-history-revision"?[`h${ce(e.getCurrentDocument())}`]:[`r${o}`,`s${g}.${N(n.liveIds)}`,...l>0?[`l${l}.${N(n.legacyIds)}`]:[]],u=r==="displayed-history-revision"?{...e.getSelection(),diffEnabled:e.isDiffEnabled()}:void 0;return{documentId:i,sessionId:a,basis:r,historyOpen:s,revision:o,pendingSuggestionCount:g+l,legacyDetachedSuggestionCount:l,projectedSuggestionCount:d,...u?{historySelection:u}:{},description:he(r,t,s,n),key:[i,a,r,...w,t].join(":")}}function _(e,t){const n=ge(e),i=de(n),a=i.liveIds.length,o=i.legacyIds.length;if(t==="show-with-tracked-changes-accepted"&&a>0&&o>0)throw new k("render_view_unsupported",`This document has ${v(a,"pending suggestion")} plus ${v(o,"legacy detached suggestion")} stored outside it, which cannot be previewed accepted together. Use show-tracked-changes or show-before-tracked-changes, or read the accepted text with a read tool.`,"verification",!1);const s=ue(n,t,i);if(s.basis==="displayed-history-revision")return{doc:{...e.getDocument()},snapshot:s};if(t==="show-with-tracked-changes-accepted"&&a===0&&o>0){const g=n.getDetachedSuggestionStore().materializeWithSuggestions(i.legacyIds);try{return{doc:j(g),snapshot:s}}finally{g.destroy()}}const r=new x.Doc;try{if(x.applyUpdate(r,x.encodeStateAsUpdate(n.getYDoc())),s.projectedSuggestionCount===0)return{doc:j(r),snapshot:s};const g=z.createSuggestionProjectionFromYDoc(r,t==="show-with-tracked-changes-accepted"?"accept":"reject",i.liveIds);try{return{doc:g.doc,snapshot:s}}finally{g.ydoc.destroy()}}finally{r.destroy()}}function pe(e){const t=e.createCanvas?.()??document.createElement("canvas");t.width=Math.ceil(e.geometry.pageWidth),t.height=Math.ceil(e.geometry.pageHeight);const n=t.getContext("2d");if(!n)throw new Error("The browser could not create a page canvas.");const i=C(e.themeElement);n.fillStyle=i.pageBackground,n.fillRect(0,0,t.width,t.height);const a=D(n),o=V(n,t,e.layout,a);o.theme=i,o.currentPage=e.geometry.pageIndex,o.pageGeometry=e.geometry,o.yOffset=e.geometry.pageTop,o.startY=e.geometry.pageTop,o.endY=e.geometry.pageTop+e.geometry.pageHeight,o.pageLayoutSettings=e.pageLayoutSettings,o.headersContent=e.doc.headers,o.footersContent=e.doc.footers,o.watermark=X(e.doc.watermark),o.totalPages=e.computed.pageCount,o.lineNumberMarks=e.computed.lineNumberMarks,o.pageFontFamilies=Z(e.computed,o.layout.fontFamily),o.headingPageNumbers=J(e.computed),o.syntaxTheme=K(e.codeTheme||"solarized",i.isDark),ee(o,1);const s={diffDocument:e.doc,showCursor:!1,isFocused:!1,readOnly:!0,printPreview:!0,forceImagePlaceholders:e.forceImagePlaceholders};if(e.pageless){const r={startY:0,endY:e.geometry.pageHeight};te(o,e.editor,r,s)}else oe(o,e.editor,e.geometry.pageIndex,s);return e.mode==="layout"&&L(n,e.computed,e.geometry),t}function me(e,t,n,i){const a=n==="compact"?360:720,o=n==="compact"?Math.min(2,e.length):e.length,s=Math.ceil(e.length/o),r=16,g=16,l=26,d=e.map(p=>({width:a,height:Math.round(p.height/p.width*a)})),w=Array.from({length:s},(p,m)=>Math.max(...d.slice(m*o,(m+1)*o).map(f=>f.height+l))),u=i?.()??document.createElement("canvas");u.width=g*2+o*a+Math.max(0,o-1)*r,u.height=g*2+w.reduce((p,m)=>p+m,0)+Math.max(0,s-1)*r;const h=u.getContext("2d");if(!h)throw new Error("The browser could not create a page contact sheet.");h.fillStyle="#e5e7eb",h.fillRect(0,0,u.width,u.height),h.fillStyle="#111827",h.font="600 14px ui-sans-serif, system-ui, sans-serif",h.textBaseline="top";let y=g;for(let p=0;p<s;p+=1){for(let m=0;m<o;m+=1){const f=p*o+m;if(f>=e.length)break;const b=g+m*(a+r);h.fillText(`Page ${t[f]}`,b,y+4),h.drawImage(e[f],b,y+l,d[f].width,d[f].height),h.strokeStyle="#9ca3af",h.strokeRect(b,y+l,d[f].width,d[f].height)}y+=w[p]+r}return u}async function fe(e){const t=e.request.view??P;if(!Y(t))throw new k("invalid_view",`Unknown render view "${String(t)}". Use show-tracked-changes, show-with-tracked-changes-accepted, or show-before-tracked-changes.`);const{doc:n,snapshot:i}=_(e.editor,t),a=C(e.themeElement),o=[],s=[];$(n,null,o,s),await ne(o,a.text);const r=e.createCanvas?.()??document.createElement("canvas");r.width=8,r.height=8;const g=r.getContext("2d");if(!g)throw new Error("The browser could not measure document pages.");const l=D(g),d=B(n,l,e.layout),w=d.pageGeometries?.length?d.pageGeometries:[se(e.layout,d)],u=w.length,h=e.request.startPage-1;if(h<0||h>=u)throw new Error(`start_page ${e.request.startPage} is outside this ${u}-page document in the ${t} view.`);const y=w.slice(h,Math.min(u,h+e.request.pageCount)),p=new Set(y.map(c=>c.pageIndex)),m=ae(d,p),f=s.filter(c=>c.blockId===null||m.has(c.blockId)),b=await Promise.all(f.map(c=>c.permanentlyPlaceholder?Promise.resolve("placeholder"):A(c.src)));await Promise.all(y.flatMap(c=>c.chromeImages??[]).map(c=>A(c.src)));const O=y.map(c=>pe({editor:e.editor,doc:n,layout:e.layout,computed:d,geometry:c,pageLayoutSettings:e.pageLayoutSettings,mode:e.request.mode,codeTheme:e.codeTheme,themeElement:e.themeElement,pageless:!!n.pageless,createCanvas:e.createCanvas})),I=y.map(c=>c.pageIndex+1),M=me(O,I,e.request.quality,e.createCanvas);let S;try{S=M.toDataURL("image/jpeg",e.request.quality==="compact"?.78:.9)}catch(c){throw typeof c=="object"&&c!==null&&"name"in c&&c.name==="SecurityError"?new k("visual_resource_unavailable","A document resource prevented safe page export. Re-upload external images and retry visual inspection.","verification",!1):c}const U=o.filter(c=>c.blockId===null||m.has(c.blockId)).filter(c=>{const T=G(c.content,c.displayMode,a.text);return T.loading||!T.image}).length;return{dataUrl:S,width:M.width,height:M.height,pages:I,totalPages:u,placeholderImageCount:b.filter(c=>c==="placeholder").length,failedImageCount:b.filter(c=>c==="failed").length,mathPlaceholderCount:U,view:t,snapshot:i}}export{_ as captureAgentPageRenderSource,L as paintPageLayoutDiagnostics,fe as renderDocumentPagesForAgent};
|
|
1
|
+
import*as x from"yjs";import{N as P,O as Y,S as k,Q as C,T as D,U as B,V as A,W as G,X as j,E as z,Y as Q,Z as V,_ as X,$ as Z,a0 as J,a1 as K,a2 as ee,a3 as te,a4 as oe}from"./index-DcIXw_KB.js";function $(e,t,n,i){if(Array.isArray(e)){for(const s of e)$(s,t,n,i);return}if(!e||typeof e!="object")return;const a=e,o=typeof a.id=="string"?a.id:t;a.type==="math"&&typeof a.content=="string"&&n.push({content:a.content,displayMode:a.displayMode!=="inline",blockId:o}),a.type==="text"&&typeof a.text=="string"&&a.marks?.latex&&n.push({content:a.text,displayMode:!1,blockId:o}),a.type==="image"&&typeof a.src=="string"&&i.push({src:a.src,blockId:o,permanentlyPlaceholder:a.originalFormat==="emf"||a.originalFormat==="wmf"});for(const s of Object.values(a))if(Array.isArray(s))for(const r of s)$(r,o,n,i);else s&&typeof s=="object"&&$(s,o,n,i)}function E(){return new Promise(e=>{let t=!1;const n=()=>{t||(t=!0,clearTimeout(i),e())},i=setTimeout(n,50);typeof requestAnimationFrame=="function"&&requestAnimationFrame(n)})}async function ne(e,t){if(e.length===0)return;const n=Promise.allSettled(e.map(i=>Q(i.content,i.displayMode,t)));await Promise.race([n,new Promise(i=>setTimeout(i,2500))]),await E(),await E()}function R(e,t){if(typeof e.pageNumber=="number")return e.pageNumber-1;const n=e.bounds.y;return t.pageGeometries?.find(i=>n>=i.pageTop&&n<i.pageTop+i.pageHeight)?.pageIndex??0}function ae(e,t){return new Set(e.fragments.filter(n=>t.has(R(n,e))).map(n=>n.blockId))}function ie(e){return e==="table"?"#7c3aed":e==="table-cell"||e==="table-row"?"#db2777":e==="image"?"#ea580c":e==="container"?"#2563eb":e==="math"?"#ca8a04":"#0891b2"}function L(e,t,n){e.save(),e.lineWidth=.75,e.setLineDash([4,3]),e.strokeStyle="rgba(22, 163, 74, 0.9)",e.strokeRect(n.marginLeft,n.marginTop,n.pageWidth-n.marginLeft-n.marginRight,n.pageHeight-n.marginTop-n.marginBottom),e.setLineDash([]);const i=new Set;for(const a of t.fragments){if(R(a,t)!==n.pageIndex)continue;const{bounds:o}=a,s=o.relativeToPage?o.y:o.y-n.pageTop,r=`${a.blockId}:${Math.round(o.x)}:${Math.round(s)}:${Math.round(o.width)}:${Math.round(o.height)}`;if(i.has(r)||o.width<=0||o.height<=0)continue;i.add(r);const g=ie(a.block.type);if(e.strokeStyle=g,e.globalAlpha=.82,e.strokeRect(o.x,s,o.width,o.height),(a.block.type==="table"||a.block.type==="table-cell"||a.block.type==="image"||a.block.type==="container"||a.block.type==="math")&&o.width>=42&&o.height>=12){const l=`${a.block.type} #${a.blockId}`;e.font="10px ui-monospace, SFMono-Regular, Menlo, monospace",e.textAlign="left",e.textBaseline="top";const d=Math.min(o.width,e.measureText(l).width+5);e.globalAlpha=.88,e.fillStyle=g,e.fillRect(o.x,Math.max(0,s),d,13),e.globalAlpha=1,e.fillStyle="#ffffff",e.fillText(l,o.x+2,Math.max(0,s)+1,Math.max(1,d-4))}}e.restore()}function se(e,t){return{pageIndex:0,sectionIndex:0,pageTop:0,pageWidth:e.pageWidth,pageHeight:Math.min(4096,Math.max(e.pageHeight,t.totalHeight)),marginTop:e.pageMarginTop??e.pageMargin,marginRight:e.pageMarginRight??e.pageMargin,marginBottom:e.pageMarginBottom??e.pageMargin,marginLeft:e.pageMarginLeft??e.pageMargin,showPageNumbers:!1,pageNumberPosition:"bottom-right",renderedPageNumber:1}}const q=new WeakMap;let F=0;function re(e){let t=q.get(e);return t||(F+=1,t=`session-${F}`,q.set(e,t)),t}const H=new WeakMap;let W=0;function ce(e){let t=H.get(e);return t===void 0&&(W+=1,t=W,H.set(e,t)),t}function N(e){let t=2166136261;for(const n of e.join("\0"))t^=n.codePointAt(0),t=Math.imul(t,16777619)>>>0;return t.toString(36)}function ge(e){const t=e.getDocumentSession?.();if(!t)throw new k("document_unavailable","Rendered page inspection needs a loaded document. Wait for the document to open, then retry.","verification",!1);return t}function de(e){const t=e.getDetachedSuggestionStore?.();return{liveIds:[...e.getDocumentMutator().getLiveSuggestionIds()].sort(),legacyIds:t?[...t.getPendingSuggestions().keys()].sort():[]}}function le(e,t){return t!==P?"live-pending-suggestion-projection":e.isHistoryOpen()?"displayed-history-revision":"displayed-document"}function v(e,t){return`${e} ${t}${e===1?"":"s"}`}function he(e,t,n,i){const a=i.liveIds.length,o=i.legacyIds.length,s=v(o,"legacy detached suggestion");if(e==="displayed-history-revision")return"The past revision the editor displays while the history view is open, not the live document. The live document's pending suggestions are not part of this image.";if(e==="displayed-document"){const d=`The document as the editor displays it, with ${v(a,"pending suggestion")} drawn as tracked changes.`;return o>0?`${d} ${s} ${o===1?"is":"are"} pending outside the document and not drawn; show-with-tracked-changes-accepted previews them.`:d}const r=n?"The live document, not the past revision the history view displays,":"The live document",g=n?"":"; this view equals show-tracked-changes",l="in a private preview; nothing was resolved in the document.";if(t==="show-with-tracked-changes-accepted")return a>0?`${r} with all ${v(a,"pending suggestion")} accepted ${l}`:o>0?`${r} with all ${s} applied ${l}`:`${r} has no pending suggestions to accept${g}.`;if(a>0){const d=o>0?` ${s} stored outside the document ${o===1?"is":"are"} absent here as well.`:"";return`${r} with all ${v(a,"pending suggestion")} rejected ${l}${d}`}return o>0?`${r} as it stands: its ${s} ${o===1?"is":"are"} stored outside the document, so there is nothing to reject${g}.`:`${r} has no pending suggestions to reject${g}.`}function ue(e,t,n){const i=e.getDocumentId(),a=re(e),o=e.getDocumentMutator().derivedDocumentRevision,s=e.isHistoryOpen(),r=le(e,t),g=n.liveIds.length,l=n.legacyIds.length,d=t==="show-with-tracked-changes-accepted"?g>0?g:l:t==="show-before-tracked-changes"?g:0,w=r==="displayed-history-revision"?[`h${ce(e.getCurrentDocument())}`]:[`r${o}`,`s${g}.${N(n.liveIds)}`,...l>0?[`l${l}.${N(n.legacyIds)}`]:[]],u=r==="displayed-history-revision"?{...e.getSelection(),diffEnabled:e.isDiffEnabled()}:void 0;return{documentId:i,sessionId:a,basis:r,historyOpen:s,revision:o,pendingSuggestionCount:g+l,legacyDetachedSuggestionCount:l,projectedSuggestionCount:d,...u?{historySelection:u}:{},description:he(r,t,s,n),key:[i,a,r,...w,t].join(":")}}function _(e,t){const n=ge(e),i=de(n),a=i.liveIds.length,o=i.legacyIds.length;if(t==="show-with-tracked-changes-accepted"&&a>0&&o>0)throw new k("render_view_unsupported",`This document has ${v(a,"pending suggestion")} plus ${v(o,"legacy detached suggestion")} stored outside it, which cannot be previewed accepted together. Use show-tracked-changes or show-before-tracked-changes, or read the accepted text with a read tool.`,"verification",!1);const s=ue(n,t,i);if(s.basis==="displayed-history-revision")return{doc:{...e.getDocument()},snapshot:s};if(t==="show-with-tracked-changes-accepted"&&a===0&&o>0){const g=n.getDetachedSuggestionStore().materializeWithSuggestions(i.legacyIds);try{return{doc:j(g),snapshot:s}}finally{g.destroy()}}const r=new x.Doc;try{if(x.applyUpdate(r,x.encodeStateAsUpdate(n.getYDoc())),s.projectedSuggestionCount===0)return{doc:j(r),snapshot:s};const g=z.createSuggestionProjectionFromYDoc(r,t==="show-with-tracked-changes-accepted"?"accept":"reject",i.liveIds);try{return{doc:g.doc,snapshot:s}}finally{g.ydoc.destroy()}}finally{r.destroy()}}function pe(e){const t=e.createCanvas?.()??document.createElement("canvas");t.width=Math.ceil(e.geometry.pageWidth),t.height=Math.ceil(e.geometry.pageHeight);const n=t.getContext("2d");if(!n)throw new Error("The browser could not create a page canvas.");const i=C(e.themeElement);n.fillStyle=i.pageBackground,n.fillRect(0,0,t.width,t.height);const a=D(n),o=V(n,t,e.layout,a);o.theme=i,o.currentPage=e.geometry.pageIndex,o.pageGeometry=e.geometry,o.yOffset=e.geometry.pageTop,o.startY=e.geometry.pageTop,o.endY=e.geometry.pageTop+e.geometry.pageHeight,o.pageLayoutSettings=e.pageLayoutSettings,o.headersContent=e.doc.headers,o.footersContent=e.doc.footers,o.watermark=X(e.doc.watermark),o.totalPages=e.computed.pageCount,o.lineNumberMarks=e.computed.lineNumberMarks,o.pageFontFamilies=Z(e.computed,o.layout.fontFamily),o.headingPageNumbers=J(e.computed),o.syntaxTheme=K(e.codeTheme||"solarized",i.isDark),ee(o,1);const s={diffDocument:e.doc,showCursor:!1,isFocused:!1,readOnly:!0,printPreview:!0,forceImagePlaceholders:e.forceImagePlaceholders};if(e.pageless){const r={startY:0,endY:e.geometry.pageHeight};te(o,e.editor,r,s)}else oe(o,e.editor,e.geometry.pageIndex,s);return e.mode==="layout"&&L(n,e.computed,e.geometry),t}function me(e,t,n,i){const a=n==="compact"?360:720,o=n==="compact"?Math.min(2,e.length):e.length,s=Math.ceil(e.length/o),r=16,g=16,l=26,d=e.map(p=>({width:a,height:Math.round(p.height/p.width*a)})),w=Array.from({length:s},(p,m)=>Math.max(...d.slice(m*o,(m+1)*o).map(f=>f.height+l))),u=i?.()??document.createElement("canvas");u.width=g*2+o*a+Math.max(0,o-1)*r,u.height=g*2+w.reduce((p,m)=>p+m,0)+Math.max(0,s-1)*r;const h=u.getContext("2d");if(!h)throw new Error("The browser could not create a page contact sheet.");h.fillStyle="#e5e7eb",h.fillRect(0,0,u.width,u.height),h.fillStyle="#111827",h.font="600 14px ui-sans-serif, system-ui, sans-serif",h.textBaseline="top";let y=g;for(let p=0;p<s;p+=1){for(let m=0;m<o;m+=1){const f=p*o+m;if(f>=e.length)break;const b=g+m*(a+r);h.fillText(`Page ${t[f]}`,b,y+4),h.drawImage(e[f],b,y+l,d[f].width,d[f].height),h.strokeStyle="#9ca3af",h.strokeRect(b,y+l,d[f].width,d[f].height)}y+=w[p]+r}return u}async function fe(e){const t=e.request.view??P;if(!Y(t))throw new k("invalid_view",`Unknown render view "${String(t)}". Use show-tracked-changes, show-with-tracked-changes-accepted, or show-before-tracked-changes.`);const{doc:n,snapshot:i}=_(e.editor,t),a=C(e.themeElement),o=[],s=[];$(n,null,o,s),await ne(o,a.text);const r=e.createCanvas?.()??document.createElement("canvas");r.width=8,r.height=8;const g=r.getContext("2d");if(!g)throw new Error("The browser could not measure document pages.");const l=D(g),d=B(n,l,e.layout),w=d.pageGeometries?.length?d.pageGeometries:[se(e.layout,d)],u=w.length,h=e.request.startPage-1;if(h<0||h>=u)throw new Error(`start_page ${e.request.startPage} is outside this ${u}-page document in the ${t} view.`);const y=w.slice(h,Math.min(u,h+e.request.pageCount)),p=new Set(y.map(c=>c.pageIndex)),m=ae(d,p),f=s.filter(c=>c.blockId===null||m.has(c.blockId)),b=await Promise.all(f.map(c=>c.permanentlyPlaceholder?Promise.resolve("placeholder"):A(c.src)));await Promise.all(y.flatMap(c=>c.chromeImages??[]).map(c=>A(c.src)));const O=y.map(c=>pe({editor:e.editor,doc:n,layout:e.layout,computed:d,geometry:c,pageLayoutSettings:e.pageLayoutSettings,mode:e.request.mode,codeTheme:e.codeTheme,themeElement:e.themeElement,pageless:!!n.pageless,createCanvas:e.createCanvas})),I=y.map(c=>c.pageIndex+1),M=me(O,I,e.request.quality,e.createCanvas);let S;try{S=M.toDataURL("image/jpeg",e.request.quality==="compact"?.78:.9)}catch(c){throw typeof c=="object"&&c!==null&&"name"in c&&c.name==="SecurityError"?new k("visual_resource_unavailable","A document resource prevented safe page export. Re-upload external images and retry visual inspection.","verification",!1):c}const U=o.filter(c=>c.blockId===null||m.has(c.blockId)).filter(c=>{const T=G(c.content,c.displayMode,a.text);return T.loading||!T.image}).length;return{dataUrl:S,width:M.width,height:M.height,pages:I,totalPages:u,placeholderImageCount:b.filter(c=>c==="placeholder").length,failedImageCount:b.filter(c=>c==="failed").length,mathPlaceholderCount:U,view:t,snapshot:i}}export{_ as captureAgentPageRenderSource,L as paintPageLayoutDiagnostics,fe as renderDocumentPagesForAgent};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as x from"yjs";import{N as P,O as Y,S as k,Q as C,T as D,U as B,V as A,W as G,X as j,E as z,Y as Q,Z as V,_ as X,$ as Z,a0 as J,a1 as K,a2 as ee,a3 as te,a4 as oe}from"./index-p6UytRm8.js";function $(e,t,n,i){if(Array.isArray(e)){for(const s of e)$(s,t,n,i);return}if(!e||typeof e!="object")return;const a=e,o=typeof a.id=="string"?a.id:t;a.type==="math"&&typeof a.content=="string"&&n.push({content:a.content,displayMode:a.displayMode!=="inline",blockId:o}),a.type==="text"&&typeof a.text=="string"&&a.marks?.latex&&n.push({content:a.text,displayMode:!1,blockId:o}),a.type==="image"&&typeof a.src=="string"&&i.push({src:a.src,blockId:o,permanentlyPlaceholder:a.originalFormat==="emf"||a.originalFormat==="wmf"});for(const s of Object.values(a))if(Array.isArray(s))for(const r of s)$(r,o,n,i);else s&&typeof s=="object"&&$(s,o,n,i)}function E(){return new Promise(e=>{let t=!1;const n=()=>{t||(t=!0,clearTimeout(i),e())},i=setTimeout(n,50);typeof requestAnimationFrame=="function"&&requestAnimationFrame(n)})}async function ne(e,t){if(e.length===0)return;const n=Promise.allSettled(e.map(i=>Q(i.content,i.displayMode,t)));await Promise.race([n,new Promise(i=>setTimeout(i,2500))]),await E(),await E()}function R(e,t){if(typeof e.pageNumber=="number")return e.pageNumber-1;const n=e.bounds.y;return t.pageGeometries?.find(i=>n>=i.pageTop&&n<i.pageTop+i.pageHeight)?.pageIndex??0}function ae(e,t){return new Set(e.fragments.filter(n=>t.has(R(n,e))).map(n=>n.blockId))}function ie(e){return e==="table"?"#7c3aed":e==="table-cell"||e==="table-row"?"#db2777":e==="image"?"#ea580c":e==="container"?"#2563eb":e==="math"?"#ca8a04":"#0891b2"}function L(e,t,n){e.save(),e.lineWidth=.75,e.setLineDash([4,3]),e.strokeStyle="rgba(22, 163, 74, 0.9)",e.strokeRect(n.marginLeft,n.marginTop,n.pageWidth-n.marginLeft-n.marginRight,n.pageHeight-n.marginTop-n.marginBottom),e.setLineDash([]);const i=new Set;for(const a of t.fragments){if(R(a,t)!==n.pageIndex)continue;const{bounds:o}=a,s=o.relativeToPage?o.y:o.y-n.pageTop,r=`${a.blockId}:${Math.round(o.x)}:${Math.round(s)}:${Math.round(o.width)}:${Math.round(o.height)}`;if(i.has(r)||o.width<=0||o.height<=0)continue;i.add(r);const g=ie(a.block.type);if(e.strokeStyle=g,e.globalAlpha=.82,e.strokeRect(o.x,s,o.width,o.height),(a.block.type==="table"||a.block.type==="table-cell"||a.block.type==="image"||a.block.type==="container"||a.block.type==="math")&&o.width>=42&&o.height>=12){const l=`${a.block.type} #${a.blockId}`;e.font="10px ui-monospace, SFMono-Regular, Menlo, monospace",e.textAlign="left",e.textBaseline="top";const d=Math.min(o.width,e.measureText(l).width+5);e.globalAlpha=.88,e.fillStyle=g,e.fillRect(o.x,Math.max(0,s),d,13),e.globalAlpha=1,e.fillStyle="#ffffff",e.fillText(l,o.x+2,Math.max(0,s)+1,Math.max(1,d-4))}}e.restore()}function se(e,t){return{pageIndex:0,sectionIndex:0,pageTop:0,pageWidth:e.pageWidth,pageHeight:Math.min(4096,Math.max(e.pageHeight,t.totalHeight)),marginTop:e.pageMarginTop??e.pageMargin,marginRight:e.pageMarginRight??e.pageMargin,marginBottom:e.pageMarginBottom??e.pageMargin,marginLeft:e.pageMarginLeft??e.pageMargin,showPageNumbers:!1,pageNumberPosition:"bottom-right",renderedPageNumber:1}}const q=new WeakMap;let F=0;function re(e){let t=q.get(e);return t||(F+=1,t=`session-${F}`,q.set(e,t)),t}const H=new WeakMap;let W=0;function ce(e){let t=H.get(e);return t===void 0&&(W+=1,t=W,H.set(e,t)),t}function N(e){let t=2166136261;for(const n of e.join("\0"))t^=n.codePointAt(0),t=Math.imul(t,16777619)>>>0;return t.toString(36)}function ge(e){const t=e.getDocumentSession?.();if(!t)throw new k("document_unavailable","Rendered page inspection needs a loaded document. Wait for the document to open, then retry.","verification",!1);return t}function de(e){const t=e.getDetachedSuggestionStore?.();return{liveIds:[...e.getDocumentMutator().getLiveSuggestionIds()].sort(),legacyIds:t?[...t.getPendingSuggestions().keys()].sort():[]}}function le(e,t){return t!==P?"live-pending-suggestion-projection":e.isHistoryOpen()?"displayed-history-revision":"displayed-document"}function v(e,t){return`${e} ${t}${e===1?"":"s"}`}function he(e,t,n,i){const a=i.liveIds.length,o=i.legacyIds.length,s=v(o,"legacy detached suggestion");if(e==="displayed-history-revision")return"The past revision the editor displays while the history view is open, not the live document. The live document's pending suggestions are not part of this image.";if(e==="displayed-document"){const d=`The document as the editor displays it, with ${v(a,"pending suggestion")} drawn as tracked changes.`;return o>0?`${d} ${s} ${o===1?"is":"are"} pending outside the document and not drawn; show-with-tracked-changes-accepted previews them.`:d}const r=n?"The live document, not the past revision the history view displays,":"The live document",g=n?"":"; this view equals show-tracked-changes",l="in a private preview; nothing was resolved in the document.";if(t==="show-with-tracked-changes-accepted")return a>0?`${r} with all ${v(a,"pending suggestion")} accepted ${l}`:o>0?`${r} with all ${s} applied ${l}`:`${r} has no pending suggestions to accept${g}.`;if(a>0){const d=o>0?` ${s} stored outside the document ${o===1?"is":"are"} absent here as well.`:"";return`${r} with all ${v(a,"pending suggestion")} rejected ${l}${d}`}return o>0?`${r} as it stands: its ${s} ${o===1?"is":"are"} stored outside the document, so there is nothing to reject${g}.`:`${r} has no pending suggestions to reject${g}.`}function ue(e,t,n){const i=e.getDocumentId(),a=re(e),o=e.getDocumentMutator().derivedDocumentRevision,s=e.isHistoryOpen(),r=le(e,t),g=n.liveIds.length,l=n.legacyIds.length,d=t==="show-with-tracked-changes-accepted"?g>0?g:l:t==="show-before-tracked-changes"?g:0,w=r==="displayed-history-revision"?[`h${ce(e.getCurrentDocument())}`]:[`r${o}`,`s${g}.${N(n.liveIds)}`,...l>0?[`l${l}.${N(n.legacyIds)}`]:[]],u=r==="displayed-history-revision"?{...e.getSelection(),diffEnabled:e.isDiffEnabled()}:void 0;return{documentId:i,sessionId:a,basis:r,historyOpen:s,revision:o,pendingSuggestionCount:g+l,legacyDetachedSuggestionCount:l,projectedSuggestionCount:d,...u?{historySelection:u}:{},description:he(r,t,s,n),key:[i,a,r,...w,t].join(":")}}function _(e,t){const n=ge(e),i=de(n),a=i.liveIds.length,o=i.legacyIds.length;if(t==="show-with-tracked-changes-accepted"&&a>0&&o>0)throw new k("render_view_unsupported",`This document has ${v(a,"pending suggestion")} plus ${v(o,"legacy detached suggestion")} stored outside it, which cannot be previewed accepted together. Use show-tracked-changes or show-before-tracked-changes, or read the accepted text with a read tool.`,"verification",!1);const s=ue(n,t,i);if(s.basis==="displayed-history-revision")return{doc:{...e.getDocument()},snapshot:s};if(t==="show-with-tracked-changes-accepted"&&a===0&&o>0){const g=n.getDetachedSuggestionStore().materializeWithSuggestions(i.legacyIds);try{return{doc:j(g),snapshot:s}}finally{g.destroy()}}const r=new x.Doc;try{if(x.applyUpdate(r,x.encodeStateAsUpdate(n.getYDoc())),s.projectedSuggestionCount===0)return{doc:j(r),snapshot:s};const g=z.createSuggestionProjectionFromYDoc(r,t==="show-with-tracked-changes-accepted"?"accept":"reject",i.liveIds);try{return{doc:g.doc,snapshot:s}}finally{g.ydoc.destroy()}}finally{r.destroy()}}function pe(e){const t=e.createCanvas?.()??document.createElement("canvas");t.width=Math.ceil(e.geometry.pageWidth),t.height=Math.ceil(e.geometry.pageHeight);const n=t.getContext("2d");if(!n)throw new Error("The browser could not create a page canvas.");const i=C(e.themeElement);n.fillStyle=i.pageBackground,n.fillRect(0,0,t.width,t.height);const a=D(n),o=V(n,t,e.layout,a);o.theme=i,o.currentPage=e.geometry.pageIndex,o.pageGeometry=e.geometry,o.yOffset=e.geometry.pageTop,o.startY=e.geometry.pageTop,o.endY=e.geometry.pageTop+e.geometry.pageHeight,o.pageLayoutSettings=e.pageLayoutSettings,o.headersContent=e.doc.headers,o.footersContent=e.doc.footers,o.watermark=X(e.doc.watermark),o.totalPages=e.computed.pageCount,o.lineNumberMarks=e.computed.lineNumberMarks,o.pageFontFamilies=Z(e.computed,o.layout.fontFamily),o.headingPageNumbers=J(e.computed),o.syntaxTheme=K(e.codeTheme||"solarized",i.isDark),ee(o,1);const s={diffDocument:e.doc,showCursor:!1,isFocused:!1,readOnly:!0,printPreview:!0,forceImagePlaceholders:e.forceImagePlaceholders};if(e.pageless){const r={startY:0,endY:e.geometry.pageHeight};te(o,e.editor,r,s)}else oe(o,e.editor,e.geometry.pageIndex,s);return e.mode==="layout"&&L(n,e.computed,e.geometry),t}function me(e,t,n,i){const a=n==="compact"?360:720,o=n==="compact"?Math.min(2,e.length):e.length,s=Math.ceil(e.length/o),r=16,g=16,l=26,d=e.map(p=>({width:a,height:Math.round(p.height/p.width*a)})),w=Array.from({length:s},(p,m)=>Math.max(...d.slice(m*o,(m+1)*o).map(f=>f.height+l))),u=i?.()??document.createElement("canvas");u.width=g*2+o*a+Math.max(0,o-1)*r,u.height=g*2+w.reduce((p,m)=>p+m,0)+Math.max(0,s-1)*r;const h=u.getContext("2d");if(!h)throw new Error("The browser could not create a page contact sheet.");h.fillStyle="#e5e7eb",h.fillRect(0,0,u.width,u.height),h.fillStyle="#111827",h.font="600 14px ui-sans-serif, system-ui, sans-serif",h.textBaseline="top";let y=g;for(let p=0;p<s;p+=1){for(let m=0;m<o;m+=1){const f=p*o+m;if(f>=e.length)break;const b=g+m*(a+r);h.fillText(`Page ${t[f]}`,b,y+4),h.drawImage(e[f],b,y+l,d[f].width,d[f].height),h.strokeStyle="#9ca3af",h.strokeRect(b,y+l,d[f].width,d[f].height)}y+=w[p]+r}return u}async function fe(e){const t=e.request.view??P;if(!Y(t))throw new k("invalid_view",`Unknown render view "${String(t)}". Use show-tracked-changes, show-with-tracked-changes-accepted, or show-before-tracked-changes.`);const{doc:n,snapshot:i}=_(e.editor,t),a=C(e.themeElement),o=[],s=[];$(n,null,o,s),await ne(o,a.text);const r=e.createCanvas?.()??document.createElement("canvas");r.width=8,r.height=8;const g=r.getContext("2d");if(!g)throw new Error("The browser could not measure document pages.");const l=D(g),d=B(n,l,e.layout),w=d.pageGeometries?.length?d.pageGeometries:[se(e.layout,d)],u=w.length,h=e.request.startPage-1;if(h<0||h>=u)throw new Error(`start_page ${e.request.startPage} is outside this ${u}-page document in the ${t} view.`);const y=w.slice(h,Math.min(u,h+e.request.pageCount)),p=new Set(y.map(c=>c.pageIndex)),m=ae(d,p),f=s.filter(c=>c.blockId===null||m.has(c.blockId)),b=await Promise.all(f.map(c=>c.permanentlyPlaceholder?Promise.resolve("placeholder"):A(c.src)));await Promise.all(y.flatMap(c=>c.chromeImages??[]).map(c=>A(c.src)));const O=y.map(c=>pe({editor:e.editor,doc:n,layout:e.layout,computed:d,geometry:c,pageLayoutSettings:e.pageLayoutSettings,mode:e.request.mode,codeTheme:e.codeTheme,themeElement:e.themeElement,pageless:!!n.pageless,createCanvas:e.createCanvas})),I=y.map(c=>c.pageIndex+1),M=me(O,I,e.request.quality,e.createCanvas);let S;try{S=M.toDataURL("image/jpeg",e.request.quality==="compact"?.78:.9)}catch(c){throw typeof c=="object"&&c!==null&&"name"in c&&c.name==="SecurityError"?new k("visual_resource_unavailable","A document resource prevented safe page export. Re-upload external images and retry visual inspection.","verification",!1):c}const U=o.filter(c=>c.blockId===null||m.has(c.blockId)).filter(c=>{const T=G(c.content,c.displayMode,a.text);return T.loading||!T.image}).length;return{dataUrl:S,width:M.width,height:M.height,pages:I,totalPages:u,placeholderImageCount:b.filter(c=>c==="placeholder").length,failedImageCount:b.filter(c=>c==="failed").length,mathPlaceholderCount:U,view:t,snapshot:i}}export{_ as captureAgentPageRenderSource,L as paintPageLayoutDiagnostics,fe as renderDocumentPagesForAgent};
|
|
1
|
+
import*as x from"yjs";import{N as P,O as Y,S as k,Q as C,T as D,U as B,V as A,W as G,X as j,E as z,Y as Q,Z as V,_ as X,$ as Z,a0 as J,a1 as K,a2 as ee,a3 as te,a4 as oe}from"./index-D9_PwgOX.js";function $(e,t,n,i){if(Array.isArray(e)){for(const s of e)$(s,t,n,i);return}if(!e||typeof e!="object")return;const a=e,o=typeof a.id=="string"?a.id:t;a.type==="math"&&typeof a.content=="string"&&n.push({content:a.content,displayMode:a.displayMode!=="inline",blockId:o}),a.type==="text"&&typeof a.text=="string"&&a.marks?.latex&&n.push({content:a.text,displayMode:!1,blockId:o}),a.type==="image"&&typeof a.src=="string"&&i.push({src:a.src,blockId:o,permanentlyPlaceholder:a.originalFormat==="emf"||a.originalFormat==="wmf"});for(const s of Object.values(a))if(Array.isArray(s))for(const r of s)$(r,o,n,i);else s&&typeof s=="object"&&$(s,o,n,i)}function E(){return new Promise(e=>{let t=!1;const n=()=>{t||(t=!0,clearTimeout(i),e())},i=setTimeout(n,50);typeof requestAnimationFrame=="function"&&requestAnimationFrame(n)})}async function ne(e,t){if(e.length===0)return;const n=Promise.allSettled(e.map(i=>Q(i.content,i.displayMode,t)));await Promise.race([n,new Promise(i=>setTimeout(i,2500))]),await E(),await E()}function R(e,t){if(typeof e.pageNumber=="number")return e.pageNumber-1;const n=e.bounds.y;return t.pageGeometries?.find(i=>n>=i.pageTop&&n<i.pageTop+i.pageHeight)?.pageIndex??0}function ae(e,t){return new Set(e.fragments.filter(n=>t.has(R(n,e))).map(n=>n.blockId))}function ie(e){return e==="table"?"#7c3aed":e==="table-cell"||e==="table-row"?"#db2777":e==="image"?"#ea580c":e==="container"?"#2563eb":e==="math"?"#ca8a04":"#0891b2"}function L(e,t,n){e.save(),e.lineWidth=.75,e.setLineDash([4,3]),e.strokeStyle="rgba(22, 163, 74, 0.9)",e.strokeRect(n.marginLeft,n.marginTop,n.pageWidth-n.marginLeft-n.marginRight,n.pageHeight-n.marginTop-n.marginBottom),e.setLineDash([]);const i=new Set;for(const a of t.fragments){if(R(a,t)!==n.pageIndex)continue;const{bounds:o}=a,s=o.relativeToPage?o.y:o.y-n.pageTop,r=`${a.blockId}:${Math.round(o.x)}:${Math.round(s)}:${Math.round(o.width)}:${Math.round(o.height)}`;if(i.has(r)||o.width<=0||o.height<=0)continue;i.add(r);const g=ie(a.block.type);if(e.strokeStyle=g,e.globalAlpha=.82,e.strokeRect(o.x,s,o.width,o.height),(a.block.type==="table"||a.block.type==="table-cell"||a.block.type==="image"||a.block.type==="container"||a.block.type==="math")&&o.width>=42&&o.height>=12){const l=`${a.block.type} #${a.blockId}`;e.font="10px ui-monospace, SFMono-Regular, Menlo, monospace",e.textAlign="left",e.textBaseline="top";const d=Math.min(o.width,e.measureText(l).width+5);e.globalAlpha=.88,e.fillStyle=g,e.fillRect(o.x,Math.max(0,s),d,13),e.globalAlpha=1,e.fillStyle="#ffffff",e.fillText(l,o.x+2,Math.max(0,s)+1,Math.max(1,d-4))}}e.restore()}function se(e,t){return{pageIndex:0,sectionIndex:0,pageTop:0,pageWidth:e.pageWidth,pageHeight:Math.min(4096,Math.max(e.pageHeight,t.totalHeight)),marginTop:e.pageMarginTop??e.pageMargin,marginRight:e.pageMarginRight??e.pageMargin,marginBottom:e.pageMarginBottom??e.pageMargin,marginLeft:e.pageMarginLeft??e.pageMargin,showPageNumbers:!1,pageNumberPosition:"bottom-right",renderedPageNumber:1}}const q=new WeakMap;let F=0;function re(e){let t=q.get(e);return t||(F+=1,t=`session-${F}`,q.set(e,t)),t}const H=new WeakMap;let W=0;function ce(e){let t=H.get(e);return t===void 0&&(W+=1,t=W,H.set(e,t)),t}function N(e){let t=2166136261;for(const n of e.join("\0"))t^=n.codePointAt(0),t=Math.imul(t,16777619)>>>0;return t.toString(36)}function ge(e){const t=e.getDocumentSession?.();if(!t)throw new k("document_unavailable","Rendered page inspection needs a loaded document. Wait for the document to open, then retry.","verification",!1);return t}function de(e){const t=e.getDetachedSuggestionStore?.();return{liveIds:[...e.getDocumentMutator().getLiveSuggestionIds()].sort(),legacyIds:t?[...t.getPendingSuggestions().keys()].sort():[]}}function le(e,t){return t!==P?"live-pending-suggestion-projection":e.isHistoryOpen()?"displayed-history-revision":"displayed-document"}function v(e,t){return`${e} ${t}${e===1?"":"s"}`}function he(e,t,n,i){const a=i.liveIds.length,o=i.legacyIds.length,s=v(o,"legacy detached suggestion");if(e==="displayed-history-revision")return"The past revision the editor displays while the history view is open, not the live document. The live document's pending suggestions are not part of this image.";if(e==="displayed-document"){const d=`The document as the editor displays it, with ${v(a,"pending suggestion")} drawn as tracked changes.`;return o>0?`${d} ${s} ${o===1?"is":"are"} pending outside the document and not drawn; show-with-tracked-changes-accepted previews them.`:d}const r=n?"The live document, not the past revision the history view displays,":"The live document",g=n?"":"; this view equals show-tracked-changes",l="in a private preview; nothing was resolved in the document.";if(t==="show-with-tracked-changes-accepted")return a>0?`${r} with all ${v(a,"pending suggestion")} accepted ${l}`:o>0?`${r} with all ${s} applied ${l}`:`${r} has no pending suggestions to accept${g}.`;if(a>0){const d=o>0?` ${s} stored outside the document ${o===1?"is":"are"} absent here as well.`:"";return`${r} with all ${v(a,"pending suggestion")} rejected ${l}${d}`}return o>0?`${r} as it stands: its ${s} ${o===1?"is":"are"} stored outside the document, so there is nothing to reject${g}.`:`${r} has no pending suggestions to reject${g}.`}function ue(e,t,n){const i=e.getDocumentId(),a=re(e),o=e.getDocumentMutator().derivedDocumentRevision,s=e.isHistoryOpen(),r=le(e,t),g=n.liveIds.length,l=n.legacyIds.length,d=t==="show-with-tracked-changes-accepted"?g>0?g:l:t==="show-before-tracked-changes"?g:0,w=r==="displayed-history-revision"?[`h${ce(e.getCurrentDocument())}`]:[`r${o}`,`s${g}.${N(n.liveIds)}`,...l>0?[`l${l}.${N(n.legacyIds)}`]:[]],u=r==="displayed-history-revision"?{...e.getSelection(),diffEnabled:e.isDiffEnabled()}:void 0;return{documentId:i,sessionId:a,basis:r,historyOpen:s,revision:o,pendingSuggestionCount:g+l,legacyDetachedSuggestionCount:l,projectedSuggestionCount:d,...u?{historySelection:u}:{},description:he(r,t,s,n),key:[i,a,r,...w,t].join(":")}}function _(e,t){const n=ge(e),i=de(n),a=i.liveIds.length,o=i.legacyIds.length;if(t==="show-with-tracked-changes-accepted"&&a>0&&o>0)throw new k("render_view_unsupported",`This document has ${v(a,"pending suggestion")} plus ${v(o,"legacy detached suggestion")} stored outside it, which cannot be previewed accepted together. Use show-tracked-changes or show-before-tracked-changes, or read the accepted text with a read tool.`,"verification",!1);const s=ue(n,t,i);if(s.basis==="displayed-history-revision")return{doc:{...e.getDocument()},snapshot:s};if(t==="show-with-tracked-changes-accepted"&&a===0&&o>0){const g=n.getDetachedSuggestionStore().materializeWithSuggestions(i.legacyIds);try{return{doc:j(g),snapshot:s}}finally{g.destroy()}}const r=new x.Doc;try{if(x.applyUpdate(r,x.encodeStateAsUpdate(n.getYDoc())),s.projectedSuggestionCount===0)return{doc:j(r),snapshot:s};const g=z.createSuggestionProjectionFromYDoc(r,t==="show-with-tracked-changes-accepted"?"accept":"reject",i.liveIds);try{return{doc:g.doc,snapshot:s}}finally{g.ydoc.destroy()}}finally{r.destroy()}}function pe(e){const t=e.createCanvas?.()??document.createElement("canvas");t.width=Math.ceil(e.geometry.pageWidth),t.height=Math.ceil(e.geometry.pageHeight);const n=t.getContext("2d");if(!n)throw new Error("The browser could not create a page canvas.");const i=C(e.themeElement);n.fillStyle=i.pageBackground,n.fillRect(0,0,t.width,t.height);const a=D(n),o=V(n,t,e.layout,a);o.theme=i,o.currentPage=e.geometry.pageIndex,o.pageGeometry=e.geometry,o.yOffset=e.geometry.pageTop,o.startY=e.geometry.pageTop,o.endY=e.geometry.pageTop+e.geometry.pageHeight,o.pageLayoutSettings=e.pageLayoutSettings,o.headersContent=e.doc.headers,o.footersContent=e.doc.footers,o.watermark=X(e.doc.watermark),o.totalPages=e.computed.pageCount,o.lineNumberMarks=e.computed.lineNumberMarks,o.pageFontFamilies=Z(e.computed,o.layout.fontFamily),o.headingPageNumbers=J(e.computed),o.syntaxTheme=K(e.codeTheme||"solarized",i.isDark),ee(o,1);const s={diffDocument:e.doc,showCursor:!1,isFocused:!1,readOnly:!0,printPreview:!0,forceImagePlaceholders:e.forceImagePlaceholders};if(e.pageless){const r={startY:0,endY:e.geometry.pageHeight};te(o,e.editor,r,s)}else oe(o,e.editor,e.geometry.pageIndex,s);return e.mode==="layout"&&L(n,e.computed,e.geometry),t}function me(e,t,n,i){const a=n==="compact"?360:720,o=n==="compact"?Math.min(2,e.length):e.length,s=Math.ceil(e.length/o),r=16,g=16,l=26,d=e.map(p=>({width:a,height:Math.round(p.height/p.width*a)})),w=Array.from({length:s},(p,m)=>Math.max(...d.slice(m*o,(m+1)*o).map(f=>f.height+l))),u=i?.()??document.createElement("canvas");u.width=g*2+o*a+Math.max(0,o-1)*r,u.height=g*2+w.reduce((p,m)=>p+m,0)+Math.max(0,s-1)*r;const h=u.getContext("2d");if(!h)throw new Error("The browser could not create a page contact sheet.");h.fillStyle="#e5e7eb",h.fillRect(0,0,u.width,u.height),h.fillStyle="#111827",h.font="600 14px ui-sans-serif, system-ui, sans-serif",h.textBaseline="top";let y=g;for(let p=0;p<s;p+=1){for(let m=0;m<o;m+=1){const f=p*o+m;if(f>=e.length)break;const b=g+m*(a+r);h.fillText(`Page ${t[f]}`,b,y+4),h.drawImage(e[f],b,y+l,d[f].width,d[f].height),h.strokeStyle="#9ca3af",h.strokeRect(b,y+l,d[f].width,d[f].height)}y+=w[p]+r}return u}async function fe(e){const t=e.request.view??P;if(!Y(t))throw new k("invalid_view",`Unknown render view "${String(t)}". Use show-tracked-changes, show-with-tracked-changes-accepted, or show-before-tracked-changes.`);const{doc:n,snapshot:i}=_(e.editor,t),a=C(e.themeElement),o=[],s=[];$(n,null,o,s),await ne(o,a.text);const r=e.createCanvas?.()??document.createElement("canvas");r.width=8,r.height=8;const g=r.getContext("2d");if(!g)throw new Error("The browser could not measure document pages.");const l=D(g),d=B(n,l,e.layout),w=d.pageGeometries?.length?d.pageGeometries:[se(e.layout,d)],u=w.length,h=e.request.startPage-1;if(h<0||h>=u)throw new Error(`start_page ${e.request.startPage} is outside this ${u}-page document in the ${t} view.`);const y=w.slice(h,Math.min(u,h+e.request.pageCount)),p=new Set(y.map(c=>c.pageIndex)),m=ae(d,p),f=s.filter(c=>c.blockId===null||m.has(c.blockId)),b=await Promise.all(f.map(c=>c.permanentlyPlaceholder?Promise.resolve("placeholder"):A(c.src)));await Promise.all(y.flatMap(c=>c.chromeImages??[]).map(c=>A(c.src)));const O=y.map(c=>pe({editor:e.editor,doc:n,layout:e.layout,computed:d,geometry:c,pageLayoutSettings:e.pageLayoutSettings,mode:e.request.mode,codeTheme:e.codeTheme,themeElement:e.themeElement,pageless:!!n.pageless,createCanvas:e.createCanvas})),I=y.map(c=>c.pageIndex+1),M=me(O,I,e.request.quality,e.createCanvas);let S;try{S=M.toDataURL("image/jpeg",e.request.quality==="compact"?.78:.9)}catch(c){throw typeof c=="object"&&c!==null&&"name"in c&&c.name==="SecurityError"?new k("visual_resource_unavailable","A document resource prevented safe page export. Re-upload external images and retry visual inspection.","verification",!1):c}const U=o.filter(c=>c.blockId===null||m.has(c.blockId)).filter(c=>{const T=G(c.content,c.displayMode,a.text);return T.loading||!T.image}).length;return{dataUrl:S,width:M.width,height:M.height,pages:I,totalPages:u,placeholderImageCount:b.filter(c=>c==="placeholder").length,failedImageCount:b.filter(c=>c==="failed").length,mathPlaceholderCount:U,view:t,snapshot:i}}export{_ as captureAgentPageRenderSource,L as paintPageLayoutDiagnostics,fe as renderDocumentPagesForAgent};
|
package/chunks/{AttachmentDocumentImporter-CXkM4VoT.js → AttachmentDocumentImporter-DnHC9t7I.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a5 as h,a6 as y,a7 as D,a8 as k}from"./index-
|
|
1
|
+
import{a5 as h,a6 as y,a7 as D,a8 as k}from"./index-D9_PwgOX.js";const w="This attachment was stored in an older per-page image format that cannot be imported. Ask the user to re-attach the original file.";async function b(n){if(n.type==="pdf"&&(n.urls?.length??0)>1)throw new Error(w);const o=n.urls?.[0];if(!o)throw new Error("The attachment no longer has an importable file URL.");const r=await fetch(o);if(!r.ok)throw new Error(`Could not download the attachment (${r.status}).`);const e=await r.blob();if(e.type.startsWith("image/"))throw new Error(w);const t=n.type==="pdf"?"attachment.pdf":"attachment.docx";return new File([e],n.fileName||t,{type:n.mimeType||e.type})}async function x(n){const{attachment:o,documentId:r,documentSession:e}=n;let t=n.afterBlockId?.trim()||void 0;if(o.type!=="docx"&&o.type!=="pdf")throw new Error("Only DOCX and PDF attachments can be imported into the document.");const c=e.getWorkingDocument(),f=c.children.length,d=h(c);if(!d&&!t&&h(e.getDocumentWithPendingSuggestionsApplied())&&(t=c.children.at(-1)?.id),!d&&!t)throw new Error("The current document has content. Provide after_block_id to insert the attachment after a current top-level block without replacing existing content.");if(t&&!c.children.some(a=>a.id===t))throw new Error(`Block "${t}" was not found as a top-level insertion anchor. Read the document and use a current top-level block ID.`);const m=await b(o);let p;if(o.type==="docx"){const{FileImporter:a}=await import("./FileImporter-Cgwoawuk.js"),s=await a.parseFile(m),i=e.getYDoc();if(t)p=y(i,s,t);else{if(!h(e.getWorkingDocument()))throw new Error("The current document is no longer empty; import was cancelled. Read the document and provide after_block_id to insert the attachment without replacing existing content.");const l=s.pendingDocxCarrier;if(delete s.pendingDocxCarrier,i.transact(()=>{D(i),k(i,s)}),l){const{storeDocxCarrier:g}=await import("./DocxGraft-QLkGEcwQ.js");await g(i,l.bytes,{hash:l.hash})}}}else{const{importPdfIntoExistingDocument:a}=await import("./PdfImportService-C2gwK1Sq.js");await a(m,r,e.getYDoc(),void 0,t)}const u=e.getWorkingDocument();return{blockCount:p??(t?Math.max(0,u.children.length-f):u.children.length),fileName:o.fileName||m.name}}export{x as importAttachmentIntoDocument,h as isEmptyDocumentForAttachmentImport};
|
package/chunks/{AttachmentDocumentImporter-Kox5By7a.js → AttachmentDocumentImporter-Dqg7IPtK.js}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a5 as h,a6 as y,a7 as D,a8 as k}from"./index-
|
|
1
|
+
import{a5 as h,a6 as y,a7 as D,a8 as k}from"./index-DcIXw_KB.js";const w="This attachment was stored in an older per-page image format that cannot be imported. Ask the user to re-attach the original file.";async function b(n){if(n.type==="pdf"&&(n.urls?.length??0)>1)throw new Error(w);const o=n.urls?.[0];if(!o)throw new Error("The attachment no longer has an importable file URL.");const r=await fetch(o);if(!r.ok)throw new Error(`Could not download the attachment (${r.status}).`);const e=await r.blob();if(e.type.startsWith("image/"))throw new Error(w);const t=n.type==="pdf"?"attachment.pdf":"attachment.docx";return new File([e],n.fileName||t,{type:n.mimeType||e.type})}async function x(n){const{attachment:o,documentId:r,documentSession:e}=n;let t=n.afterBlockId?.trim()||void 0;if(o.type!=="docx"&&o.type!=="pdf")throw new Error("Only DOCX and PDF attachments can be imported into the document.");const c=e.getWorkingDocument(),f=c.children.length,d=h(c);if(!d&&!t&&h(e.getDocumentWithPendingSuggestionsApplied())&&(t=c.children.at(-1)?.id),!d&&!t)throw new Error("The current document has content. Provide after_block_id to insert the attachment after a current top-level block without replacing existing content.");if(t&&!c.children.some(a=>a.id===t))throw new Error(`Block "${t}" was not found as a top-level insertion anchor. Read the document and use a current top-level block ID.`);const m=await b(o);let p;if(o.type==="docx"){const{FileImporter:a}=await import("./FileImporter-BIT0ZBDY.js"),s=await a.parseFile(m),i=e.getYDoc();if(t)p=y(i,s,t);else{if(!h(e.getWorkingDocument()))throw new Error("The current document is no longer empty; import was cancelled. Read the document and provide after_block_id to insert the attachment without replacing existing content.");const l=s.pendingDocxCarrier;if(delete s.pendingDocxCarrier,i.transact(()=>{D(i),k(i,s)}),l){const{storeDocxCarrier:g}=await import("./DocxGraft-D71OgoMh.js");await g(i,l.bytes,{hash:l.hash})}}}else{const{importPdfIntoExistingDocument:a}=await import("./PdfImportService-CxtUtxM6.js");await a(m,r,e.getYDoc(),void 0,t)}const u=e.getWorkingDocument();return{blockCount:p??(t?Math.max(0,u.children.length-f):u.children.length),fileName:o.fileName||m.name}}export{x as importAttachmentIntoDocument,h as isEmptyDocumentForAttachmentImport};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{B as p,E as N}from"./index-
|
|
1
|
+
import{B as p,E as N}from"./index-DcIXw_KB.js";const i="Author",h=o=>{const n=[o.children];o.notes&&n.push(o.notes),o.chrome&&n.push(o.chrome);for(const e of[o.headers,o.footers])if(e)for(const c of Object.values(e))Array.isArray(c)&&n.push(c);return n},g=(o,n)=>{n(o);for(const e of o)e&&Array.isArray(e.children)&&g(e.children,n)},l=(o,n)=>{for(const e of h(o))g(e,c=>{for(const a of c)a?.type==="text"&&n(a)})},y=o=>{o.marks&&Object.keys(o.marks).length===0&&delete o.marks},A=o=>{const n=new Set,e=c=>{typeof c=="string"&&c.length>0&&n.add(c)};for(const c of h(o))g(c,a=>{for(const t of a){if(!t||typeof t!="object")continue;e(t.suggestionId),e(t.structuralSuggestionId);for(const s of["structuralSuggestionRecord","structuralSuggestionRecords"]){const u=t[s];if(typeof u=="string")try{const f=JSON.parse(u),m=Array.isArray(f)?f:[f];for(const d of m)e(d?.id)}catch{}}const r=t.marks;if(r&&(e(r.suggestionId),typeof r.layeredInsertion=="string"))try{e(JSON.parse(r.layeredInsertion)?.id)}catch{}}});return n},S=(o,n)=>{const e=p(o);try{const c=N.createSuggestionProjectionFromYDoc(e,n);try{const a=c.doc,t={...o,children:a.children};return a.notes?t.notes=a.notes:delete t.notes,t}finally{c.ydoc.destroy()}}finally{e.destroy()}},k=(o,n)=>{o.author&&o.author!==i&&(n.add(o.author),o.author=i),delete o.initials,delete o.authorId,delete o.authorImageUrl,o.agentName&&(n.add(o.agentName),delete o.agentName)};function v(o,n){let e=structuredClone(o);const c={commentsRemoved:0,suggestionsResolved:0,hiddenRemoved:0,authorsAnonymized:0,corePropsCleared:!1};if(n.resolveSuggestions){const a=A(e);a.size>0&&(e=S(e,n.resolveSuggestions),c.suggestionsResolved=a.size)}if(n.removeComments){const a=new Set((e.comments??[]).map(t=>t.id));l(e,t=>{if(t.marks?.comment){for(const r of t.marks.comment.split(","))r&&a.add(r);delete t.marks.comment,y(t)}}),delete e.comments,c.commentsRemoved=a.size}if(n.removeHiddenText)for(const a of h(e))g(a,t=>{const r=[];for(const s of t){if(s?.type==="text"&&s.marks?.hidden){c.hiddenRemoved+=1,s.marks.footnoteRef&&(delete s.marks.hidden,y(s),r.push(s));continue}r.push(s)}r.length!==t.length&&(t.length=0,t.push(...r))});if(n.anonymizeAuthors){const a=new Set;l(e,t=>{const r=t.marks;if(r){if(r.suggestionAuthorName&&r.suggestionAuthorName!==i&&(a.add(r.suggestionAuthorName),r.suggestionAuthorName=i),typeof r.layeredInsertion=="string")try{const s=JSON.parse(r.layeredInsertion);s&&typeof s=="object"&&s.authorName&&s.authorName!==i&&(a.add(s.authorName),s.authorName=i,r.layeredInsertion=JSON.stringify(s))}catch{}if(typeof r.docxMove=="string")try{const s=JSON.parse(r.docxMove);s&&typeof s=="object"&&s.rangeAuthor&&s.rangeAuthor!==i&&(a.add(s.rangeAuthor),s.rangeAuthor=i,r.docxMove=JSON.stringify(s))}catch{}}});for(const t of h(e))g(t,r=>{for(const s of r)for(const u of["structuralSuggestionRecord","structuralSuggestionRecords"])if(typeof s?.[u]=="string")try{const f=JSON.parse(s[u]),m=Array.isArray(f)?f:[f];for(const d of m)d&&typeof d=="object"&&typeof d.agentName=="string"&&d.agentName.length>0&&d.agentName!==i&&(a.add(d.agentName),d.agentName=i);s[u]=JSON.stringify(Array.isArray(f)?m:m[0])}catch{}});for(const t of e.comments??[])k(t,a);if(e.coreProperties)for(const t of["creator","lastModifiedBy"]){const r=e.coreProperties[t];r&&r!==i&&(a.add(r),e.coreProperties[t]=i)}c.authorsAnonymized=a.size}return n.clearCoreProperties&&(e.coreProperties&&Object.keys(e.coreProperties).length>0&&(c.corePropsCleared=!0),delete e.coreProperties),{doc:e,summary:c}}export{i as SCRUBBED_AUTHOR_NAME,v as scrubDocument};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{B as p,E as N}from"./index-
|
|
1
|
+
import{B as p,E as N}from"./index-D9_PwgOX.js";const i="Author",h=o=>{const n=[o.children];o.notes&&n.push(o.notes),o.chrome&&n.push(o.chrome);for(const e of[o.headers,o.footers])if(e)for(const c of Object.values(e))Array.isArray(c)&&n.push(c);return n},g=(o,n)=>{n(o);for(const e of o)e&&Array.isArray(e.children)&&g(e.children,n)},l=(o,n)=>{for(const e of h(o))g(e,c=>{for(const a of c)a?.type==="text"&&n(a)})},y=o=>{o.marks&&Object.keys(o.marks).length===0&&delete o.marks},A=o=>{const n=new Set,e=c=>{typeof c=="string"&&c.length>0&&n.add(c)};for(const c of h(o))g(c,a=>{for(const t of a){if(!t||typeof t!="object")continue;e(t.suggestionId),e(t.structuralSuggestionId);for(const s of["structuralSuggestionRecord","structuralSuggestionRecords"]){const u=t[s];if(typeof u=="string")try{const f=JSON.parse(u),m=Array.isArray(f)?f:[f];for(const d of m)e(d?.id)}catch{}}const r=t.marks;if(r&&(e(r.suggestionId),typeof r.layeredInsertion=="string"))try{e(JSON.parse(r.layeredInsertion)?.id)}catch{}}});return n},S=(o,n)=>{const e=p(o);try{const c=N.createSuggestionProjectionFromYDoc(e,n);try{const a=c.doc,t={...o,children:a.children};return a.notes?t.notes=a.notes:delete t.notes,t}finally{c.ydoc.destroy()}}finally{e.destroy()}},k=(o,n)=>{o.author&&o.author!==i&&(n.add(o.author),o.author=i),delete o.initials,delete o.authorId,delete o.authorImageUrl,o.agentName&&(n.add(o.agentName),delete o.agentName)};function v(o,n){let e=structuredClone(o);const c={commentsRemoved:0,suggestionsResolved:0,hiddenRemoved:0,authorsAnonymized:0,corePropsCleared:!1};if(n.resolveSuggestions){const a=A(e);a.size>0&&(e=S(e,n.resolveSuggestions),c.suggestionsResolved=a.size)}if(n.removeComments){const a=new Set((e.comments??[]).map(t=>t.id));l(e,t=>{if(t.marks?.comment){for(const r of t.marks.comment.split(","))r&&a.add(r);delete t.marks.comment,y(t)}}),delete e.comments,c.commentsRemoved=a.size}if(n.removeHiddenText)for(const a of h(e))g(a,t=>{const r=[];for(const s of t){if(s?.type==="text"&&s.marks?.hidden){c.hiddenRemoved+=1,s.marks.footnoteRef&&(delete s.marks.hidden,y(s),r.push(s));continue}r.push(s)}r.length!==t.length&&(t.length=0,t.push(...r))});if(n.anonymizeAuthors){const a=new Set;l(e,t=>{const r=t.marks;if(r){if(r.suggestionAuthorName&&r.suggestionAuthorName!==i&&(a.add(r.suggestionAuthorName),r.suggestionAuthorName=i),typeof r.layeredInsertion=="string")try{const s=JSON.parse(r.layeredInsertion);s&&typeof s=="object"&&s.authorName&&s.authorName!==i&&(a.add(s.authorName),s.authorName=i,r.layeredInsertion=JSON.stringify(s))}catch{}if(typeof r.docxMove=="string")try{const s=JSON.parse(r.docxMove);s&&typeof s=="object"&&s.rangeAuthor&&s.rangeAuthor!==i&&(a.add(s.rangeAuthor),s.rangeAuthor=i,r.docxMove=JSON.stringify(s))}catch{}}});for(const t of h(e))g(t,r=>{for(const s of r)for(const u of["structuralSuggestionRecord","structuralSuggestionRecords"])if(typeof s?.[u]=="string")try{const f=JSON.parse(s[u]),m=Array.isArray(f)?f:[f];for(const d of m)d&&typeof d=="object"&&typeof d.agentName=="string"&&d.agentName.length>0&&d.agentName!==i&&(a.add(d.agentName),d.agentName=i);s[u]=JSON.stringify(Array.isArray(f)?m:m[0])}catch{}});for(const t of e.comments??[])k(t,a);if(e.coreProperties)for(const t of["creator","lastModifiedBy"]){const r=e.coreProperties[t];r&&r!==i&&(a.add(r),e.coreProperties[t]=i)}c.authorsAnonymized=a.size}return n.clearCoreProperties&&(e.coreProperties&&Object.keys(e.coreProperties).length>0&&(c.corePropsCleared=!0),delete e.coreProperties),{doc:e,summary:c}}export{i as SCRUBBED_AUTHOR_NAME,v as scrubDocument};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{an as Ae,ao as Ni,ap as Er,aq as Ai,c as Ti,h as Mi,ar as Dr,as as Ei,at as Di,au as Bi,av as Ee,I as Ri,aw as Li,ax as Fi,ay as Oi,K as Ft,az as Ot,aA as $i,aB as _i,R as Ct,aC as Wi,aD as tr,L as Qe,aE as Br,aF as Xi,aG as Rr,aH as zi,aI as rr,aJ as Hi,aK as Lr,aL as ji,aM as Gi,aN as Ji,u as Ui,v as Ki,G as Zi,_ as Vi,aO as Fr,aP as qi,aQ as Yi,ak as Qi,aR as en,aS as tn,aT as rn,aU as ir,aV as nn,aW as on,Q as sn,aX as an,aY as Or,aZ as ln,a_ as cn,a$ as $r,J as dn,b0 as _r,b1 as pn,m as nr,b2 as Wr,b3 as hn,b4 as gn,b5 as mn,b6 as Xr,b7 as or,b8 as un,b9 as fn}from"./index-
|
|
1
|
+
import{an as Ae,ao as Ni,ap as Er,aq as Ai,c as Ti,h as Mi,ar as Dr,as as Ei,at as Di,au as Bi,av as Ee,I as Ri,aw as Li,ax as Fi,ay as Oi,K as Ft,az as Ot,aA as $i,aB as _i,R as Ct,aC as Wi,aD as tr,L as Qe,aE as Br,aF as Xi,aG as Rr,aH as zi,aI as rr,aJ as Hi,aK as Lr,aL as ji,aM as Gi,aN as Ji,u as Ui,v as Ki,G as Zi,_ as Vi,aO as Fr,aP as qi,aQ as Yi,ak as Qi,aR as en,aS as tn,aT as rn,aU as ir,aV as nn,aW as on,Q as sn,aX as an,aY as Or,aZ as ln,a_ as cn,a$ as $r,J as dn,b0 as _r,b1 as pn,m as nr,b2 as Wr,b3 as hn,b4 as gn,b5 as mn,b6 as Xr,b7 as or,b8 as un,b9 as fn}from"./index-D9_PwgOX.js";const zr=()=>new XMLSerializer,Hr=new Set(["w:rStyle","w:b","w:i","w:u","w:strike","w:dstrike","w:smallCaps","w:caps","w:vanish","w:lang","w:spacing","w:vertAlign","w:color","w:highlight","w:shd","w:rFonts","w:sz","w:rPrChange","w:bCs","w:iCs","w:szCs","w:highlightCs","w:ins","w:del","w:rtl","w:specVanish","w:imprint","w:emboss","w:snapToGrid"]),jr=new Set(["w:pStyle","w:keepNext","w:keepLines","w:widowControl","w:bidi","w:jc","w:ind","w:pageBreakBefore","w:spacing","w:contextualSpacing","w:outlineLvl","w:numPr","w:pBdr","w:shd","w:tabs","w:rPr","w:sectPr","w:pPrChange"]),Gr=new Set(["w:tblStyle","w:tblW","w:jc","w:tblInd","w:tblBorders","w:tblLayout","w:tblCellMar","w:tblPrChange"]),Jr=new Set(["w:tblHeader","w:ins","w:del","w:trPrChange"]),Ur=new Set(["w:tcW","w:gridSpan","w:vMerge","w:tcBorders","w:shd","w:tcMar","w:vAlign","w:cellIns","w:cellDel","w:cellMerge","w:tcPrChange"]),Kr=new Set(["w:pgSz","w:pgMar","w:pgNumType","w:lnNumType","w:cols","w:type","w:docGrid","w:titlePg","w:headerReference","w:footerReference","w:sectPrChange","w:rPr"]);function at(F,e){if(!F)return;let r="";const t=zr();for(let i=0;i<F.children.length;i++){const n=F.children[i];e.has(n.tagName)||(r+=t.serializeToString(n))}return r?ar(r):void 0}function sr(F){if(!F||F.attributes.length===0)return;const e={};for(let i=0;i<F.attributes.length;i++){const n=F.attributes[i];n.name==="xmlns"||n.name.startsWith("xmlns:")||(e[n.name]=n.value)}const r=Object.keys(e).sort();if(r.length===0)return;const t={};for(const i of r)t[i]=e[i];return JSON.stringify(t)}function ar(F){if(!/[\n\r\t]/.test(F))return F;let e="",r=!1,t=null;for(let i=0;i<F.length;i++){const n=F[i];if(t){n===t?(t=null,e+=n):n===`
|
|
2
2
|
`?e+=" ":n==="\r"?e+=" ":n===" "?e+="	":e+=n;continue}r&&(n==='"'||n==="'")?t=n:n==="<"?r=!0:n===">"&&(r=!1),e+=n}return e}function lr(F){const e=ar(zr().serializeToString(F));let r;const t=F.getElementsByTagName("o:OLEObject")[0];if(t)r=t.getAttribute("ProgID")??void 0;else if(F.tagName==="w:altChunk")r=F.getAttribute("r:id")??void 0;else{const i=F.getElementsByTagName("a:graphicData")[0]?.getAttribute("uri")?.split("/").filter(Boolean).pop();i&&i!=="picture"&&(r=i)}return{xml:e,tagName:F.tagName,...r?{detail:r}:{}}}function cr(F){return F.includes("http://schemas.openxmlformats.org/officeDocument/2006/relationships")}const Zr=new Set(["w:p","w:tbl","w:sdt","w:customXml","w:sectPr","w:bookmarkStart","w:bookmarkEnd","w:commentRangeStart","w:commentRangeEnd","w:moveFromRangeStart","w:moveFromRangeEnd","w:moveToRangeStart","w:moveToRangeEnd","w:permStart","w:permEnd","w:ins","w:del","w:moveFrom","w:moveTo","w:proofErr","w:tcPr","w:trPr","w:tblPr","w:tblGrid","w:tblPrEx","w:pPr"]),wn=/^[A-Za-z_][\w.-]*(?::[\w.-]+)?$/;function Vr(F,e){let r;try{r=JSON.parse(F)}catch{return""}if(r===null||typeof r!="object"||Array.isArray(r))return"";let t="";for(const[i,n]of Object.entries(r)){if(typeof n!="string"||!wn.test(i)||e?.has(i))continue;const a=n.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");t+=` ${i}="${a}"`}return t}const bn=Object.freeze(Object.defineProperty({__proto__:null,KNOWN_BODY_TAGS:Zr,KNOWN_PPR_TAGS:jr,KNOWN_RPR_TAGS:Hr,KNOWN_SECTPR_TAGS:Kr,KNOWN_TBLPR_TAGS:Gr,KNOWN_TCPR_TAGS:Ur,KNOWN_TRPR_TAGS:Jr,attrsJsonToXmlAttributes:Vr,captureRawElement:lr,extractElementAttrsJson:sr,extractOpaqueChildrenXml:at,stabilizeSerializedXml:ar,xmlReferencesRelationships:cr},Symbol.toStringTag,{value:"Module"})),yn="http://schemas.openxmlformats.org/officeDocument/2006/math",qr=`<m:oMath xmlns:m="${yn}">`,vn=new Set("∑∏∐∫∬∭∮∯∰∱∲∳⋀⋁⋂⋃⨀⨁⨂⨄⨆".split("")),xn=new Set(["sin","cos","tan","cot","sec","csc","arcsin","arccos","arctan","sinh","cosh","tanh","coth","log","ln","lg","exp","det","dim","ker","deg","gcd","hom","arg","max","min","sup","inf","lim","liminf","limsup","Pr"]),Sn=new Set(["lim","liminf","limsup","max","min","sup","inf","Pr"]),Yr={"^":"̂","ˆ":"̂","̂":"̂","~":"̃","˜":"̃","̃":"̃","ˉ":"̄","¯":"̄","̄":"̄","˙":"̇","̇":"̇","¨":"̈","̈":"̈","ˊ":"́","´":"́","́":"́","ˋ":"̀","`":"̀","̀":"̀","ˇ":"̌","̌":"̌","˘":"̆","̆":"̆","→":"⃗","⃗":"⃗"},In=new Set(["‾","¯","_","―","−"]),kn=new Set(["⏞","⏟","⏜","⏝","⎴","⎵"]),Pn=new Set(["","","",""]),dr={normal:'<m:sty m:val="p"/>',bold:'<m:sty m:val="b"/>',italic:'<m:sty m:val="i"/>',"bold-italic":'<m:sty m:val="bi"/>',"double-struck":'<m:scr m:val="double-struck"/><m:sty m:val="p"/>',script:'<m:scr m:val="script"/>',"bold-script":'<m:scr m:val="script"/><m:sty m:val="b"/>',fraktur:'<m:scr m:val="fraktur"/>',"bold-fraktur":'<m:scr m:val="fraktur"/><m:sty m:val="b"/>',"sans-serif":'<m:scr m:val="sans-serif"/><m:sty m:val="p"/>',monospace:'<m:scr m:val="monospace"/><m:sty m:val="p"/>'};function Qr(F){return F.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function lt(F){return Qr(F)}function We(F){return Array.from(F.children)}function $e(F){return(F.textContent??"").replace(/[-]/g,"")}function xe(F){return F.localName.toLowerCase()}function pr(F){let e=F;for(;["mrow","mstyle","mpadded","semantics"].includes(xe(e))&&We(e).filter(r=>!$t(r)).length===1;)e=We(e).filter(r=>!$t(r))[0];return e}function $t(F){return xe(F)==="mo"&&Pn.has((F.textContent??"").trim())}function _t(F){if(!F)return null;const e=pr(F);if(xe(e)!=="mo")return null;const r=$e(e).trim();return vn.has(r)?r:null}function Wt(F){if(!F)return null;const e=pr(F);if(!["mi","mo"].includes(xe(e)))return null;const r=$e(e).trim();return xn.has(r)?r:null}const Cn=new Set("+-−=<>≤≥≠≈≡∼≃≅∝,;:∣∈∉⊂⊆⊃⊇→←↔⇒⇐⇔".split(""));function Nn(F){return xe(F)==="mo"&&Cn.has($e(F).trim())}function ei(F,e){let r=e;for(;r<F.length&&!Nn(F[r]);)r+=1;return r}function ti(F){return!!F&&xe(F)==="mo"&&F.getAttribute("fence")==="true"}function Je(F,e){if(!F)return"";const r=/^\s+$/.test(F)?`${F}`:F,t=/^\s|\s$/.test(r)?' xml:space="preserve"':"";return`<m:r>${e?`<m:rPr>${e}</m:rPr>`:""}<m:t${t}>${Qr(r)}</m:t></m:r>`}function An(F,e){const r=xe(F),t=$e(F);if(!t)return"";if(r==="mtext"||r==="ms")return Je(t,"<m:nor/>");const i=F.getAttribute("mathvariant")??e.mathvariant;return i&&dr[i]?Je(t,dr[i]):r==="mi"&&[...t].length>1?Je(t,'<m:sty m:val="p"/>'):Je(t,"")}function le(F,e){return`<m:${F}>${e}</m:${F}>`}function ri(F,e,r,t,i){return`<m:nary><m:naryPr>${`<m:chr m:val="${lt(F)}"/><m:limLoc m:val="${e}"/>`+(r===null?'<m:subHide m:val="1"/>':"")+(t===null?'<m:supHide m:val="1"/>':"")}</m:naryPr>`+le("sub",r??"")+le("sup",t??"")+le("e",i)+"</m:nary>"}function ii(F,e){return`<m:func>${le("fName",F)}${le("e",e)}</m:func>`}function ni(F){return parseFloat(F.getAttribute("width")??"")>0?" ":""}function Tn(F){return xe(F)==="mrow"&&F.children.length===0&&!$e(F).trim()}function Ue(F,e){const r=F.filter(i=>!$t(i)&&!Tn(i));if(r.length>=2&&ti(r[0])){const i=r[r.length-1],n=ti(i),a=r.slice(1,n?-1:void 0),o=$e(r[0]).trim(),s=n?$e(i).trim():"";return`<m:d><m:dPr><m:begChr m:val="${lt(o)}"/><m:endChr m:val="${lt(s)}"/></m:dPr>`+le("e",Ue(a,e))+"</m:d>"}let t="";for(let i=0;i<r.length;i+=1){const n=r[i],a=xe(n),o=r[i+1];if(["msub","msup","msubsup","munder","mover","munderover"].includes(a)&&_t(We(n)[0])){const[c,p,h]=We(n),g=_t(c),f=a.startsWith("mu")?"undOvr":"subSup",w=["msub","msubsup","munder","munderover"].includes(a)?pe(p,e):null,u=a==="msubsup"||a==="munderover"?pe(h,e):a==="msup"||a==="mover"?pe(p,e):null,m=ei(r,i+1);t+=ri(g,f,w,u,Ue(r.slice(i+1,m),e)),i=m-1;continue}if(a==="mo"&&_t(n)){const c=ei(r,i+1);t+=ri(_t(n),"undOvr",null,null,Ue(r.slice(i+1,c),e)),i=c-1;continue}const s=["msub","munder"].includes(a)?Wt(We(n)[0]):null;if(s&&Sn.has(s)&&o){const[c,p]=We(n),h=`<m:limLow>${le("e",Je(Wt(c),'<m:sty m:val="p"/>'))}${le("lim",pe(p,e))}</m:limLow>`;t+=ii(h,pe(o,e)),i+=1;continue}if(Wt(n)&&o){t+=ii(Je(Wt(n),'<m:sty m:val="p"/>'),pe(o,e)),i+=1;continue}if(a==="mtext"||a==="mspace"){let c="",p=i;for(;r[p]&&["mtext","mspace"].includes(xe(r[p]));)c+=xe(r[p])==="mtext"?$e(r[p]):ni(r[p]),p+=1;i=p-1;const h=c.replace(/\s{2,}/g," ");h&&(t+=Je(h,"<m:nor/>"));continue}const l=a==="mi"?n.getAttribute("mathvariant"):null;if(l){let c=$e(n);for(;r[i+1]&&xe(r[i+1])==="mi"&&r[i+1].getAttribute("mathvariant")===l;)i+=1,c+=$e(r[i]);t+=Je(c,dr[l]??"");continue}t+=pe(n,e)}return t}function pe(F,e){if(!F)return"";const r=xe(F),t=We(F);switch(r){case"math":case"semantics":case"mrow":case"mpadded":case"merror":return Ue(t,e);case"mstyle":{const i=F.getAttribute("mathvariant");return Ue(t,i?{...e,mathvariant:i}:e)}case"annotation":case"annotation-xml":case"mphantom":case"none":case"mprescripts":return"";case"mi":case"mn":case"mo":case"mtext":case"ms":return $t(F)?"":An(F,e);case"mspace":{const i=ni(F);return i?Je(i,"<m:nor/>"):""}case"mfrac":{const i=F.getAttribute("linethickness");return`<m:f>${i!==null&&parseFloat(i)===0?'<m:fPr><m:type m:val="noBar"/></m:fPr>':""}`+le("num",pe(t[0],e))+le("den",pe(t[1],e))+"</m:f>"}case"msqrt":return'<m:rad><m:radPr><m:degHide m:val="1"/></m:radPr><m:deg/>'+le("e",Ue(t,e))+"</m:rad>";case"mroot":return"<m:rad>"+le("deg",pe(t[1],e))+le("e",pe(t[0],e))+"</m:rad>";case"msub":return`<m:sSub>${le("e",pe(t[0],e))}${le("sub",pe(t[1],e))}</m:sSub>`;case"msup":return`<m:sSup>${le("e",pe(t[0],e))}${le("sup",pe(t[1],e))}</m:sSup>`;case"msubsup":return`<m:sSubSup>${le("e",pe(t[0],e))}`+le("sub",pe(t[1],e))+le("sup",pe(t[2],e))+"</m:sSubSup>";case"mover":case"munder":return Mn(F,r==="mover"?"top":"bot",e);case"munderover":{const[i,n,a]=t,o=`<m:limLow>${le("e",pe(i,e))}${le("lim",pe(n,e))}</m:limLow>`;return`<m:limUpp>${le("e",o)}${le("lim",pe(a,e))}</m:limUpp>`}case"mtable":return"<m:m>"+t.filter(i=>["mtr","mlabeledtr"].includes(xe(i))).map(i=>"<m:mr>"+We(i).filter(n=>xe(n)==="mtd").map(n=>le("e",Ue(We(n),e))).join("")+"</m:mr>").join("")+"</m:m>";case"menclose":{const i=Ue(t,e),n=F.getAttribute("notation")??"";return/\bbox\b|roundedbox/.test(n)?`<m:borderBox>${le("e",i)}</m:borderBox>`:i}case"mfenced":{const i=F.getAttribute("open")??"(",n=F.getAttribute("close")??")";return`<m:d><m:dPr><m:begChr m:val="${lt(i)}"/><m:endChr m:val="${lt(n)}"/></m:dPr>`+t.map(a=>le("e",pe(a,e))).join("")+"</m:d>"}default:return Ue(t,e)}}function Mn(F,e,r){const[t,i]=We(F),n=pe(t,r),a=i?pr(i):void 0,o=a&&xe(a)==="mo"?$e(a).trim():"";if(o&&In.has(o))return`<m:bar><m:barPr><m:pos m:val="${e}"/></m:barPr>${le("e",n)}</m:bar>`;if(o&&kn.has(o))return`<m:groupChr><m:groupChrPr><m:chr m:val="${lt(o)}"/><m:pos m:val="${e}"/><m:vertJc m:val="${e==="top"?"bot":"top"}"/></m:groupChrPr>`+le("e",n)+"</m:groupChr>";const s=F.getAttribute(e==="top"?"accent":"accentunder")==="true";if(e==="top"&&o&&(s||Yr[o])){const c=Yr[o]??o;return`<m:acc><m:accPr><m:chr m:val="${lt(c)}"/></m:accPr>${le("e",n)}</m:acc>`}const l=e==="top"?"limUpp":"limLow";return`<m:${l}>${le("e",n)}${le("lim",pe(i,r))}</m:${l}>`}function En(F){return new DOMParser().parseFromString(F,"text/html").querySelector("math")}function Dn(F){const e=En(F);if(!e)throw new Error("mathmlToOmml: no <math> element in input");return`${qr}${pe(e,{})}</m:oMath>`}const oi="iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==",ue=class hr{static async parseFile(e,r){if(!e.name.toLowerCase().endsWith(".docx"))throw new Error(`DocxConverter only supports .docx files, got: ${e.name}`);return this.parseDocxFile(e,r)}static async parseDocxFile(e,r){const t=await e.arrayBuffer(),i=await Er.loadAsync(t),n=await i.file("word/document.xml")?.async("string");if(!n)return{type:"doc",children:[this.createEmptyParagraph()]};const a=this.parseDocumentXml(n);if(!a)return{type:"doc",children:[this.createEmptyParagraph()]};const o=await this.loadOOXMLPackageContext(i,n),s=await this.parseDocumentPageLayoutFromPackage(n,i,a),l=await i.file("word/fontTable.xml")?.async("string"),c=this.parseFontTableXml(l),p=await i.file("word/settings.xml")?.async("string"),h=!!(p&&/<w:autoHyphenation(?![^>]*w:val="(?:0|false)")[^>]*\/?>/.test(p)),g=r?.retainSource?new Map:void 0,f=await this.parseStructuredDocxDocument(n,s,o,a,g),w=await i.file("docProps/custom.xml")?.async("string");if(w){const T=this.parseDocumentXml(w),O=(T&&Array.from(T.getElementsByTagNameNS("*","property")).find(X=>X.getAttribute("name")==="Revise.BlockSpacingPx"))?.textContent?.trim(),W=O?Number(O):NaN;Number.isFinite(W)&&W>=0&&W<=192&&(f.pageLayout={...f.pageLayout??{},blockSpacingPx:W})}h&&(f.pageLayout={...f.pageLayout??{},hyphenationEnabled:!0}),c&&(f.fontSubstitutes=c,Ai(c));const u=await i.file("word/footnotes.xml")?.async("string"),m=await i.file("word/endnotes.xml")?.async("string"),b=new Map;u&&await this.collectNotesFromXml(f,u,"w:footnote","docxfn","footnote",b,o),m&&await this.collectNotesFromXml(f,m,"w:endnote","docxen","endnote",b,o),this.finalizeImportedFootnoteRefs(f,b);const v=await i.file("word/comments.xml")?.async("string");if(v){const T=await i.file("word/commentsExtended.xml")?.async("string");this.attachCommentsFromXml(f,v,T,o)}await this.attachHeadersFootersFromPackage(f,n,i,o,a);const y=await i.file("docProps/core.xml")?.async("string");if(y){const T=this.parseCoreProperties(y);T&&(f.coreProperties=T)}return g&&Ti(f,g,await Mi(new Uint8Array(t))),f}static parseCoreProperties(e){const r=this.parseDocumentXml(e);if(!r)return;const t=new Set(this.CORE_PROPERTY_LOCAL_NAMES),i={},n=r.documentElement;for(let a=0;a<n.children.length;a++){const o=n.children[a],s=o.tagName.split(":").pop()??o.tagName;if(!t.has(s))continue;const l=o.textContent??"";l.trim().length!==0&&(i[s]=l)}return Object.keys(i).length>0?i:void 0}static readHeaderFooterReferences(e,r){const t={};for(let i=0;i<e.children.length;i++){const n=e.children[i];if(n.tagName!==r)continue;const a=n.getAttribute("w:type")??"default",o=a==="first"||a==="even"?a:"default",s=n.getAttribute("r:id")??n.getAttribute("relationships:id");s&&(t[o]=s)}return t}static resolveSectionHeaderFooterReferences(e){const r=[];for(let t=0;t<e.length;t++){const i=r[t-1]??{header:{},footer:{}};r.push({header:{...i.header,...this.readHeaderFooterReferences(e[t],"w:headerReference")},footer:{...i.footer,...this.readHeaderFooterReferences(e[t],"w:footerReference")}})}return r}static async attachHeadersFootersFromPackage(e,r,t,i,n){const a=(n??this.parseDocumentXml(r))?.getElementsByTagName("w:body")[0];if(!a)return;const o=this.findAllSectionProperties(a);if(o.length===0)return;const s=this.resolveSectionHeaderFooterReferences(o),l=o.length-1,c=s[l],p=new Map,h=async O=>{const W=p.get(O);if(W)return W;const X={paragraphs:[],images:[]},D=i?.relationships.get(O);if(D){const M=D.target.startsWith("word/")?D.target:`word/${D.target.replace(/^\//,"")}`,L=await t.file(M)?.async("string");if(L){const I=M.split("/").pop()??M,B=await t.file(`word/_rels/${I}.rels`)?.async("string");if(X.paragraphs=await this.parseHeaderFooterPart(L,B?this.parseRelationshipsXml(B,M):void 0),!e.watermark){const E=this.parseVmlWatermark(L);E&&(e.watermark=E)}X.images=await this.parseHeaderFooterImages(L,M,t,i)}}return p.set(O,X),X},g=async O=>(await h(O)).paragraphs,f=["default","first","even"],w=[],u=async(O,W)=>{const X={};for(const D of f){const M=O[D];if(!M)continue;const L=await h(M);L.paragraphs.length>0&&(X[D]=L.paragraphs);for(const I of L.images)w.push({side:W,slot:D,...I})}return Object.keys(X).length>0?X:void 0},m=await u(c.header,"header"),b=await u(c.footer,"footer");m&&(e.headers=m),b&&(e.footers=b),w.length>0&&(e.chromeImages=w);const v=[];for(let O=0;O<l;O++)for(const W of["header","footer"])for(const X of f){const D=s[O][W][X],M=c[W][X];if(D===M)continue;const L=D?await g(D):[];v.push(Dr(W,X,L.length>0?Ei(L):void 0,void 0,O))}const y=[],T=new Set(v.map(O=>`${O.side}/${O.slot}/${O.sectionIndex}`));for(let O=0;O<o.length;O++)if(o[O].getElementsByTagName("w:titlePg").length!==0)for(const W of["header","footer"]){const X=s[O][W].first;if((X?await g(X):[]).length>0||!s[O][W].default)continue;const D=O===l?void 0:O;T.has(`${W}/first/${D}`)||y.push(Dr(W,"first",void 0,void 0,D))}(v.length>0||y.length>0)&&(e.chrome=[...Di(e.headers,e.footers),...v,...y])}static parseVmlWatermark(e){if(!e.includes("v:textpath"))return;const r=this.parseDocumentXml(e);if(!r)return;const t=r.getElementsByTagName("v:textpath");for(let i=0;i<t.length;i++){const n=t[i],a=(n.getAttribute("string")??"").trim();if(!a)continue;let o=n.parentNode;for(;o&&o.tagName!=="v:shape";)o=o.parentNode;const s=(o?.getAttribute("style")??"").match(/rotation:\s*(-?\d+(?:\.\d+)?)/),l=s?(parseFloat(s[1])%360+360)%360:0,c=this.vmlFillColorToHex(o?.getAttribute("fillcolor")??"");let p;const h=o?.getElementsByTagName("v:fill")[0]?.getAttribute("opacity");if(h){const w=h.endsWith("f")?parseFloat(h)/65536:parseFloat(h);Number.isFinite(w)&&w>0&&w<=1&&(p=Math.abs(w-Fr)<.05?void 0:w)}const g=(n.getAttribute("style")??"").match(/font-size:\s*(\d+(?:\.\d+)?)pt/),f=g?parseFloat(g[1]):void 0;return Bi({text:a,...c?{color:c}:{},...p!==void 0?{opacity:p}:{},diagonal:l!==0,...f&&f>2?{fontSizePx:Math.round(f*(4/3))}:{}})}}static vmlFillColorToHex(e){const r=e.trim().toLowerCase();if(r){if(r.startsWith("#")){const t=r.slice(1,7);return/^[0-9a-f]{6}$/.test(t)?`#${t.toUpperCase()}`:void 0}return{silver:"#C0C0C0",gray:"#808080",grey:"#808080",black:"#000000",red:"#FF0000",blue:"#0000FF",green:"#008000",white:"#FFFFFF"}[r]}}static async parseHeaderFooterImages(e,r,t,i){if(!i||!e.includes("w:drawing"))return[];const n=this.parseDocumentXml(e);if(!n)return[];const a=n.getElementsByTagName("w:drawing");if(a.length===0)return[];const o=r.split("/").pop()??r,s=await t.file(`word/_rels/${o}.rels`)?.async("string"),l={...i,relationships:this.parseRelationshipsXml(s,r)},c=[];for(let p=0;p<a.length;p++){const h=await this.parseImageFromDrawing(a[p],void 0,l);if(h){const g=this.headerFooterImageAlign(a[p]);c.push({src:h.src,width:h.width,height:h.height,...h.alt?{alt:h.alt}:{},...g?{align:g}:{}})}}return c}static headerFooterImageAlign(e){let r=e.parentElement;for(;r&&r.tagName!=="w:p";)r=r.parentElement;if(!r)return;const t=Array.from(r.children).find(n=>n.tagName==="w:pPr"),i=(t?Array.from(t.children).find(n=>n.tagName==="w:jc"):void 0)?.getAttribute("w:val");if(i==="center")return"center";if(i==="right"||i==="end")return"right"}static async parseHeaderFooterPart(e,r){const t=this.parseDocumentXml(e);if(!t)return[];const i=[],n=Array.from(t.getElementsByTagName("w:p")).filter(a=>{let o=a.parentElement;for(;o;){if(o.tagName==="w:txbxContent")return!1;o=o.parentElement}return!0});for(let a=0;a<n.length;a++){const o=n[a],s=[];let l=null,c=!1;const p=m=>{const b={},v=this.getDirectChild(m,"w:rPr");v&&(this.applyRunPropertiesFromElement(b,v),(this.getDirectChild(v,"w:rStyle")?.getAttribute("w:val")||void 0)===this.CODE_INLINE_STYLE_ID&&(b.code=!0,/courier/i.test(b.fontFamily??"")&&delete b.fontFamily,/^(light)?gray$/i.test(b.backgroundColor??"")&&delete b.backgroundColor));let y=m.parentElement;for(;y&&y!==o;){if(y.tagName==="w:ins"||y.tagName==="w:del"){const O=y.tagName==="w:ins",W=this.parseTrackedRevisionMeta(y);Object.assign(b,{...O?{insertion:!0}:{deletion:!0},suggestionId:W.revisionId?`docxrev-${W.revisionId}`:this.generateId(),...this.revisionAuthorIdentity(W.author),suggestionLabel:O?"Insert":"Delete",...W.createdAt!==void 0?{suggestionCreatedAt:W.createdAt}:{},...W.author?{suggestionAuthorName:W.author}:{}});break}y=y.parentElement}let T=m.parentElement;for(;T&&T!==o;){if(T.tagName==="w:hyperlink"){const O=T.getAttribute("r:id"),W=T.getAttribute("w:anchor"),X=O?r?.get(O)?.target:void 0;X?b.link=X:W&&(b.link=`#${W}`);break}T=T.parentElement}return b},h=Array.from(o.getElementsByTagName("w:r")).filter(m=>{let b=m.parentElement;for(;b&&b!==o;){if(b.tagName==="w:p")return!1;b=b.parentElement}return b===o});for(let m=0;m<h.length;m++){const b=h[m],v=p(b);for(let y=0;y<b.children.length;y++){const T=b.children[y];if(T.tagName==="w:t"||T.tagName==="w:delText"){if(c)continue;const O=T.textContent??"";O&&s.push({type:"text",text:O,...Object.keys(v).length>0?{marks:v}:{}})}else if(T.tagName==="w:tab")s.push({type:"text",text:" "});else if(T.tagName==="w:br"&&!c&&(T.getAttribute("w:type")??"textWrapping")==="textWrapping")s.push({type:"text",text:`
|
|
3
3
|
`,...Object.keys(v).length>0?{marks:v}:{}});else if(T.tagName==="w:fldChar"){const O=T.getAttribute("w:fldCharType");O==="begin"&&(c=!0),O==="end"&&(l&&s.push({type:"text",text:"1",marks:{...v,field:l}}),l=null,c=!1)}else if(T.tagName==="w:instrText"&&c){const O=(T.textContent??"").trim().toUpperCase();O.startsWith("PAGE")?l="page":O.startsWith("NUMPAGES")&&(l="numPages")}}}const g=o.getElementsByTagName("w:fldSimple");for(let m=0;m<g.length;m++){const b=(g[m].getAttribute("w:instr")??"").trim().toUpperCase();b.startsWith("PAGE")?s.push({type:"text",text:"1",marks:{field:"page"}}):b.startsWith("NUMPAGES")&&s.push({type:"text",text:"1",marks:{field:"numPages"}})}const f=this.getDirectChild(this.getDirectChild(o,"w:pPr")??o,"w:jc")?.getAttribute("w:val"),w=f==="center"?"center":f==="right"||f==="end"?"right":f==="both"?"justify":void 0;s.length>0&&i.push({type:"paragraph",id:this.generateId(),children:s,...w?{align:w}:{}});const u=await this.parseTextBoxContent(o,void 0);i.push(...u.filter(m=>m.type==="paragraph"))}return i}static attachCommentsFromXml(e,r,t,i){const n=this.parseDocumentXml(r);if(!n)return;const a=new Set,o=u=>{if(!u||typeof u!="object")return;if(Array.isArray(u)){u.forEach(o);return}const m=u;m.marks?.comment&&m.marks.comment.split(",").forEach(b=>a.add(b)),o(m.children)};o(e.children);const s=(i??this.fallbackCommentState).collapsedCommentAnchorBlockById;s?.forEach((u,m)=>a.add(`docxcmt-${m}`));const l=new Map;if(t){const u=this.parseDocumentXml(t)?.getElementsByTagName("w15:commentEx")??[];for(let m=0;m<u.length;m++){const b=u[m],v=b.getAttribute("w15:paraId");v&&l.set(v,{done:b.getAttribute("w15:done")==="1",parentParaId:b.getAttribute("w15:paraIdParent")??void 0})}}const c=[],p=new Map,h=new Map,g=n.getElementsByTagName("w:comment");for(let u=0;u<g.length;u++){const m=g[u],b=m.getAttribute("w:id");if(!b)continue;const v=`docxcmt-${b}`,y=m.getElementsByTagName("w:p"),T=[];for(let D=0;D<y.length;D++){const M=y[D].getElementsByTagName("w:t");let L="";for(let B=0;B<M.length;B++)L+=M[B].textContent??"";T.push(L);const I=y[D].getAttribute("w14:paraId");I&&(p.set(v,I),h.set(I,v))}const O=m.getAttribute("w:date"),W=O?Date.parse(O):NaN,X=s?.get(b);c.push({id:v,author:m.getAttribute("w:author")??"Unknown",...m.getAttribute("w:initials")?{initials:m.getAttribute("w:initials")}:{},createdAt:Number.isFinite(W)?new Date(W).toISOString():new Date(0).toISOString(),bodyMd:T.filter(D=>D.length>0).join(`
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{an as Ae,ao as Ni,ap as Er,aq as Ai,c as Ti,h as Mi,ar as Dr,as as Ei,at as Di,au as Bi,av as Ee,I as Ri,aw as Li,ax as Fi,ay as Oi,K as Ft,az as Ot,aA as $i,aB as _i,R as Ct,aC as Wi,aD as tr,L as Qe,aE as Br,aF as Xi,aG as Rr,aH as zi,aI as rr,aJ as Hi,aK as Lr,aL as ji,aM as Gi,aN as Ji,u as Ui,v as Ki,G as Zi,_ as Vi,aO as Fr,aP as qi,aQ as Yi,ak as Qi,aR as en,aS as tn,aT as rn,aU as ir,aV as nn,aW as on,Q as sn,aX as an,aY as Or,aZ as ln,a_ as cn,a$ as $r,J as dn,b0 as _r,b1 as pn,m as nr,b2 as Wr,b3 as hn,b4 as gn,b5 as mn,b6 as Xr,b7 as or,b8 as un,b9 as fn}from"./index-
|
|
1
|
+
import{an as Ae,ao as Ni,ap as Er,aq as Ai,c as Ti,h as Mi,ar as Dr,as as Ei,at as Di,au as Bi,av as Ee,I as Ri,aw as Li,ax as Fi,ay as Oi,K as Ft,az as Ot,aA as $i,aB as _i,R as Ct,aC as Wi,aD as tr,L as Qe,aE as Br,aF as Xi,aG as Rr,aH as zi,aI as rr,aJ as Hi,aK as Lr,aL as ji,aM as Gi,aN as Ji,u as Ui,v as Ki,G as Zi,_ as Vi,aO as Fr,aP as qi,aQ as Yi,ak as Qi,aR as en,aS as tn,aT as rn,aU as ir,aV as nn,aW as on,Q as sn,aX as an,aY as Or,aZ as ln,a_ as cn,a$ as $r,J as dn,b0 as _r,b1 as pn,m as nr,b2 as Wr,b3 as hn,b4 as gn,b5 as mn,b6 as Xr,b7 as or,b8 as un,b9 as fn}from"./index-DcIXw_KB.js";const zr=()=>new XMLSerializer,Hr=new Set(["w:rStyle","w:b","w:i","w:u","w:strike","w:dstrike","w:smallCaps","w:caps","w:vanish","w:lang","w:spacing","w:vertAlign","w:color","w:highlight","w:shd","w:rFonts","w:sz","w:rPrChange","w:bCs","w:iCs","w:szCs","w:highlightCs","w:ins","w:del","w:rtl","w:specVanish","w:imprint","w:emboss","w:snapToGrid"]),jr=new Set(["w:pStyle","w:keepNext","w:keepLines","w:widowControl","w:bidi","w:jc","w:ind","w:pageBreakBefore","w:spacing","w:contextualSpacing","w:outlineLvl","w:numPr","w:pBdr","w:shd","w:tabs","w:rPr","w:sectPr","w:pPrChange"]),Gr=new Set(["w:tblStyle","w:tblW","w:jc","w:tblInd","w:tblBorders","w:tblLayout","w:tblCellMar","w:tblPrChange"]),Jr=new Set(["w:tblHeader","w:ins","w:del","w:trPrChange"]),Ur=new Set(["w:tcW","w:gridSpan","w:vMerge","w:tcBorders","w:shd","w:tcMar","w:vAlign","w:cellIns","w:cellDel","w:cellMerge","w:tcPrChange"]),Kr=new Set(["w:pgSz","w:pgMar","w:pgNumType","w:lnNumType","w:cols","w:type","w:docGrid","w:titlePg","w:headerReference","w:footerReference","w:sectPrChange","w:rPr"]);function at(F,e){if(!F)return;let r="";const t=zr();for(let i=0;i<F.children.length;i++){const n=F.children[i];e.has(n.tagName)||(r+=t.serializeToString(n))}return r?ar(r):void 0}function sr(F){if(!F||F.attributes.length===0)return;const e={};for(let i=0;i<F.attributes.length;i++){const n=F.attributes[i];n.name==="xmlns"||n.name.startsWith("xmlns:")||(e[n.name]=n.value)}const r=Object.keys(e).sort();if(r.length===0)return;const t={};for(const i of r)t[i]=e[i];return JSON.stringify(t)}function ar(F){if(!/[\n\r\t]/.test(F))return F;let e="",r=!1,t=null;for(let i=0;i<F.length;i++){const n=F[i];if(t){n===t?(t=null,e+=n):n===`
|
|
2
2
|
`?e+=" ":n==="\r"?e+=" ":n===" "?e+="	":e+=n;continue}r&&(n==='"'||n==="'")?t=n:n==="<"?r=!0:n===">"&&(r=!1),e+=n}return e}function lr(F){const e=ar(zr().serializeToString(F));let r;const t=F.getElementsByTagName("o:OLEObject")[0];if(t)r=t.getAttribute("ProgID")??void 0;else if(F.tagName==="w:altChunk")r=F.getAttribute("r:id")??void 0;else{const i=F.getElementsByTagName("a:graphicData")[0]?.getAttribute("uri")?.split("/").filter(Boolean).pop();i&&i!=="picture"&&(r=i)}return{xml:e,tagName:F.tagName,...r?{detail:r}:{}}}function cr(F){return F.includes("http://schemas.openxmlformats.org/officeDocument/2006/relationships")}const Zr=new Set(["w:p","w:tbl","w:sdt","w:customXml","w:sectPr","w:bookmarkStart","w:bookmarkEnd","w:commentRangeStart","w:commentRangeEnd","w:moveFromRangeStart","w:moveFromRangeEnd","w:moveToRangeStart","w:moveToRangeEnd","w:permStart","w:permEnd","w:ins","w:del","w:moveFrom","w:moveTo","w:proofErr","w:tcPr","w:trPr","w:tblPr","w:tblGrid","w:tblPrEx","w:pPr"]),wn=/^[A-Za-z_][\w.-]*(?::[\w.-]+)?$/;function Vr(F,e){let r;try{r=JSON.parse(F)}catch{return""}if(r===null||typeof r!="object"||Array.isArray(r))return"";let t="";for(const[i,n]of Object.entries(r)){if(typeof n!="string"||!wn.test(i)||e?.has(i))continue;const a=n.replace(/&/g,"&").replace(/</g,"<").replace(/"/g,""");t+=` ${i}="${a}"`}return t}const bn=Object.freeze(Object.defineProperty({__proto__:null,KNOWN_BODY_TAGS:Zr,KNOWN_PPR_TAGS:jr,KNOWN_RPR_TAGS:Hr,KNOWN_SECTPR_TAGS:Kr,KNOWN_TBLPR_TAGS:Gr,KNOWN_TCPR_TAGS:Ur,KNOWN_TRPR_TAGS:Jr,attrsJsonToXmlAttributes:Vr,captureRawElement:lr,extractElementAttrsJson:sr,extractOpaqueChildrenXml:at,stabilizeSerializedXml:ar,xmlReferencesRelationships:cr},Symbol.toStringTag,{value:"Module"})),yn="http://schemas.openxmlformats.org/officeDocument/2006/math",qr=`<m:oMath xmlns:m="${yn}">`,vn=new Set("∑∏∐∫∬∭∮∯∰∱∲∳⋀⋁⋂⋃⨀⨁⨂⨄⨆".split("")),xn=new Set(["sin","cos","tan","cot","sec","csc","arcsin","arccos","arctan","sinh","cosh","tanh","coth","log","ln","lg","exp","det","dim","ker","deg","gcd","hom","arg","max","min","sup","inf","lim","liminf","limsup","Pr"]),Sn=new Set(["lim","liminf","limsup","max","min","sup","inf","Pr"]),Yr={"^":"̂","ˆ":"̂","̂":"̂","~":"̃","˜":"̃","̃":"̃","ˉ":"̄","¯":"̄","̄":"̄","˙":"̇","̇":"̇","¨":"̈","̈":"̈","ˊ":"́","´":"́","́":"́","ˋ":"̀","`":"̀","̀":"̀","ˇ":"̌","̌":"̌","˘":"̆","̆":"̆","→":"⃗","⃗":"⃗"},In=new Set(["‾","¯","_","―","−"]),kn=new Set(["⏞","⏟","⏜","⏝","⎴","⎵"]),Pn=new Set(["","","",""]),dr={normal:'<m:sty m:val="p"/>',bold:'<m:sty m:val="b"/>',italic:'<m:sty m:val="i"/>',"bold-italic":'<m:sty m:val="bi"/>',"double-struck":'<m:scr m:val="double-struck"/><m:sty m:val="p"/>',script:'<m:scr m:val="script"/>',"bold-script":'<m:scr m:val="script"/><m:sty m:val="b"/>',fraktur:'<m:scr m:val="fraktur"/>',"bold-fraktur":'<m:scr m:val="fraktur"/><m:sty m:val="b"/>',"sans-serif":'<m:scr m:val="sans-serif"/><m:sty m:val="p"/>',monospace:'<m:scr m:val="monospace"/><m:sty m:val="p"/>'};function Qr(F){return F.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}function lt(F){return Qr(F)}function We(F){return Array.from(F.children)}function $e(F){return(F.textContent??"").replace(/[-]/g,"")}function xe(F){return F.localName.toLowerCase()}function pr(F){let e=F;for(;["mrow","mstyle","mpadded","semantics"].includes(xe(e))&&We(e).filter(r=>!$t(r)).length===1;)e=We(e).filter(r=>!$t(r))[0];return e}function $t(F){return xe(F)==="mo"&&Pn.has((F.textContent??"").trim())}function _t(F){if(!F)return null;const e=pr(F);if(xe(e)!=="mo")return null;const r=$e(e).trim();return vn.has(r)?r:null}function Wt(F){if(!F)return null;const e=pr(F);if(!["mi","mo"].includes(xe(e)))return null;const r=$e(e).trim();return xn.has(r)?r:null}const Cn=new Set("+-−=<>≤≥≠≈≡∼≃≅∝,;:∣∈∉⊂⊆⊃⊇→←↔⇒⇐⇔".split(""));function Nn(F){return xe(F)==="mo"&&Cn.has($e(F).trim())}function ei(F,e){let r=e;for(;r<F.length&&!Nn(F[r]);)r+=1;return r}function ti(F){return!!F&&xe(F)==="mo"&&F.getAttribute("fence")==="true"}function Je(F,e){if(!F)return"";const r=/^\s+$/.test(F)?`${F}`:F,t=/^\s|\s$/.test(r)?' xml:space="preserve"':"";return`<m:r>${e?`<m:rPr>${e}</m:rPr>`:""}<m:t${t}>${Qr(r)}</m:t></m:r>`}function An(F,e){const r=xe(F),t=$e(F);if(!t)return"";if(r==="mtext"||r==="ms")return Je(t,"<m:nor/>");const i=F.getAttribute("mathvariant")??e.mathvariant;return i&&dr[i]?Je(t,dr[i]):r==="mi"&&[...t].length>1?Je(t,'<m:sty m:val="p"/>'):Je(t,"")}function le(F,e){return`<m:${F}>${e}</m:${F}>`}function ri(F,e,r,t,i){return`<m:nary><m:naryPr>${`<m:chr m:val="${lt(F)}"/><m:limLoc m:val="${e}"/>`+(r===null?'<m:subHide m:val="1"/>':"")+(t===null?'<m:supHide m:val="1"/>':"")}</m:naryPr>`+le("sub",r??"")+le("sup",t??"")+le("e",i)+"</m:nary>"}function ii(F,e){return`<m:func>${le("fName",F)}${le("e",e)}</m:func>`}function ni(F){return parseFloat(F.getAttribute("width")??"")>0?" ":""}function Tn(F){return xe(F)==="mrow"&&F.children.length===0&&!$e(F).trim()}function Ue(F,e){const r=F.filter(i=>!$t(i)&&!Tn(i));if(r.length>=2&&ti(r[0])){const i=r[r.length-1],n=ti(i),a=r.slice(1,n?-1:void 0),o=$e(r[0]).trim(),s=n?$e(i).trim():"";return`<m:d><m:dPr><m:begChr m:val="${lt(o)}"/><m:endChr m:val="${lt(s)}"/></m:dPr>`+le("e",Ue(a,e))+"</m:d>"}let t="";for(let i=0;i<r.length;i+=1){const n=r[i],a=xe(n),o=r[i+1];if(["msub","msup","msubsup","munder","mover","munderover"].includes(a)&&_t(We(n)[0])){const[c,p,h]=We(n),g=_t(c),f=a.startsWith("mu")?"undOvr":"subSup",w=["msub","msubsup","munder","munderover"].includes(a)?pe(p,e):null,u=a==="msubsup"||a==="munderover"?pe(h,e):a==="msup"||a==="mover"?pe(p,e):null,m=ei(r,i+1);t+=ri(g,f,w,u,Ue(r.slice(i+1,m),e)),i=m-1;continue}if(a==="mo"&&_t(n)){const c=ei(r,i+1);t+=ri(_t(n),"undOvr",null,null,Ue(r.slice(i+1,c),e)),i=c-1;continue}const s=["msub","munder"].includes(a)?Wt(We(n)[0]):null;if(s&&Sn.has(s)&&o){const[c,p]=We(n),h=`<m:limLow>${le("e",Je(Wt(c),'<m:sty m:val="p"/>'))}${le("lim",pe(p,e))}</m:limLow>`;t+=ii(h,pe(o,e)),i+=1;continue}if(Wt(n)&&o){t+=ii(Je(Wt(n),'<m:sty m:val="p"/>'),pe(o,e)),i+=1;continue}if(a==="mtext"||a==="mspace"){let c="",p=i;for(;r[p]&&["mtext","mspace"].includes(xe(r[p]));)c+=xe(r[p])==="mtext"?$e(r[p]):ni(r[p]),p+=1;i=p-1;const h=c.replace(/\s{2,}/g," ");h&&(t+=Je(h,"<m:nor/>"));continue}const l=a==="mi"?n.getAttribute("mathvariant"):null;if(l){let c=$e(n);for(;r[i+1]&&xe(r[i+1])==="mi"&&r[i+1].getAttribute("mathvariant")===l;)i+=1,c+=$e(r[i]);t+=Je(c,dr[l]??"");continue}t+=pe(n,e)}return t}function pe(F,e){if(!F)return"";const r=xe(F),t=We(F);switch(r){case"math":case"semantics":case"mrow":case"mpadded":case"merror":return Ue(t,e);case"mstyle":{const i=F.getAttribute("mathvariant");return Ue(t,i?{...e,mathvariant:i}:e)}case"annotation":case"annotation-xml":case"mphantom":case"none":case"mprescripts":return"";case"mi":case"mn":case"mo":case"mtext":case"ms":return $t(F)?"":An(F,e);case"mspace":{const i=ni(F);return i?Je(i,"<m:nor/>"):""}case"mfrac":{const i=F.getAttribute("linethickness");return`<m:f>${i!==null&&parseFloat(i)===0?'<m:fPr><m:type m:val="noBar"/></m:fPr>':""}`+le("num",pe(t[0],e))+le("den",pe(t[1],e))+"</m:f>"}case"msqrt":return'<m:rad><m:radPr><m:degHide m:val="1"/></m:radPr><m:deg/>'+le("e",Ue(t,e))+"</m:rad>";case"mroot":return"<m:rad>"+le("deg",pe(t[1],e))+le("e",pe(t[0],e))+"</m:rad>";case"msub":return`<m:sSub>${le("e",pe(t[0],e))}${le("sub",pe(t[1],e))}</m:sSub>`;case"msup":return`<m:sSup>${le("e",pe(t[0],e))}${le("sup",pe(t[1],e))}</m:sSup>`;case"msubsup":return`<m:sSubSup>${le("e",pe(t[0],e))}`+le("sub",pe(t[1],e))+le("sup",pe(t[2],e))+"</m:sSubSup>";case"mover":case"munder":return Mn(F,r==="mover"?"top":"bot",e);case"munderover":{const[i,n,a]=t,o=`<m:limLow>${le("e",pe(i,e))}${le("lim",pe(n,e))}</m:limLow>`;return`<m:limUpp>${le("e",o)}${le("lim",pe(a,e))}</m:limUpp>`}case"mtable":return"<m:m>"+t.filter(i=>["mtr","mlabeledtr"].includes(xe(i))).map(i=>"<m:mr>"+We(i).filter(n=>xe(n)==="mtd").map(n=>le("e",Ue(We(n),e))).join("")+"</m:mr>").join("")+"</m:m>";case"menclose":{const i=Ue(t,e),n=F.getAttribute("notation")??"";return/\bbox\b|roundedbox/.test(n)?`<m:borderBox>${le("e",i)}</m:borderBox>`:i}case"mfenced":{const i=F.getAttribute("open")??"(",n=F.getAttribute("close")??")";return`<m:d><m:dPr><m:begChr m:val="${lt(i)}"/><m:endChr m:val="${lt(n)}"/></m:dPr>`+t.map(a=>le("e",pe(a,e))).join("")+"</m:d>"}default:return Ue(t,e)}}function Mn(F,e,r){const[t,i]=We(F),n=pe(t,r),a=i?pr(i):void 0,o=a&&xe(a)==="mo"?$e(a).trim():"";if(o&&In.has(o))return`<m:bar><m:barPr><m:pos m:val="${e}"/></m:barPr>${le("e",n)}</m:bar>`;if(o&&kn.has(o))return`<m:groupChr><m:groupChrPr><m:chr m:val="${lt(o)}"/><m:pos m:val="${e}"/><m:vertJc m:val="${e==="top"?"bot":"top"}"/></m:groupChrPr>`+le("e",n)+"</m:groupChr>";const s=F.getAttribute(e==="top"?"accent":"accentunder")==="true";if(e==="top"&&o&&(s||Yr[o])){const c=Yr[o]??o;return`<m:acc><m:accPr><m:chr m:val="${lt(c)}"/></m:accPr>${le("e",n)}</m:acc>`}const l=e==="top"?"limUpp":"limLow";return`<m:${l}>${le("e",n)}${le("lim",pe(i,r))}</m:${l}>`}function En(F){return new DOMParser().parseFromString(F,"text/html").querySelector("math")}function Dn(F){const e=En(F);if(!e)throw new Error("mathmlToOmml: no <math> element in input");return`${qr}${pe(e,{})}</m:oMath>`}const oi="iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==",ue=class hr{static async parseFile(e,r){if(!e.name.toLowerCase().endsWith(".docx"))throw new Error(`DocxConverter only supports .docx files, got: ${e.name}`);return this.parseDocxFile(e,r)}static async parseDocxFile(e,r){const t=await e.arrayBuffer(),i=await Er.loadAsync(t),n=await i.file("word/document.xml")?.async("string");if(!n)return{type:"doc",children:[this.createEmptyParagraph()]};const a=this.parseDocumentXml(n);if(!a)return{type:"doc",children:[this.createEmptyParagraph()]};const o=await this.loadOOXMLPackageContext(i,n),s=await this.parseDocumentPageLayoutFromPackage(n,i,a),l=await i.file("word/fontTable.xml")?.async("string"),c=this.parseFontTableXml(l),p=await i.file("word/settings.xml")?.async("string"),h=!!(p&&/<w:autoHyphenation(?![^>]*w:val="(?:0|false)")[^>]*\/?>/.test(p)),g=r?.retainSource?new Map:void 0,f=await this.parseStructuredDocxDocument(n,s,o,a,g),w=await i.file("docProps/custom.xml")?.async("string");if(w){const T=this.parseDocumentXml(w),O=(T&&Array.from(T.getElementsByTagNameNS("*","property")).find(X=>X.getAttribute("name")==="Revise.BlockSpacingPx"))?.textContent?.trim(),W=O?Number(O):NaN;Number.isFinite(W)&&W>=0&&W<=192&&(f.pageLayout={...f.pageLayout??{},blockSpacingPx:W})}h&&(f.pageLayout={...f.pageLayout??{},hyphenationEnabled:!0}),c&&(f.fontSubstitutes=c,Ai(c));const u=await i.file("word/footnotes.xml")?.async("string"),m=await i.file("word/endnotes.xml")?.async("string"),b=new Map;u&&await this.collectNotesFromXml(f,u,"w:footnote","docxfn","footnote",b,o),m&&await this.collectNotesFromXml(f,m,"w:endnote","docxen","endnote",b,o),this.finalizeImportedFootnoteRefs(f,b);const v=await i.file("word/comments.xml")?.async("string");if(v){const T=await i.file("word/commentsExtended.xml")?.async("string");this.attachCommentsFromXml(f,v,T,o)}await this.attachHeadersFootersFromPackage(f,n,i,o,a);const y=await i.file("docProps/core.xml")?.async("string");if(y){const T=this.parseCoreProperties(y);T&&(f.coreProperties=T)}return g&&Ti(f,g,await Mi(new Uint8Array(t))),f}static parseCoreProperties(e){const r=this.parseDocumentXml(e);if(!r)return;const t=new Set(this.CORE_PROPERTY_LOCAL_NAMES),i={},n=r.documentElement;for(let a=0;a<n.children.length;a++){const o=n.children[a],s=o.tagName.split(":").pop()??o.tagName;if(!t.has(s))continue;const l=o.textContent??"";l.trim().length!==0&&(i[s]=l)}return Object.keys(i).length>0?i:void 0}static readHeaderFooterReferences(e,r){const t={};for(let i=0;i<e.children.length;i++){const n=e.children[i];if(n.tagName!==r)continue;const a=n.getAttribute("w:type")??"default",o=a==="first"||a==="even"?a:"default",s=n.getAttribute("r:id")??n.getAttribute("relationships:id");s&&(t[o]=s)}return t}static resolveSectionHeaderFooterReferences(e){const r=[];for(let t=0;t<e.length;t++){const i=r[t-1]??{header:{},footer:{}};r.push({header:{...i.header,...this.readHeaderFooterReferences(e[t],"w:headerReference")},footer:{...i.footer,...this.readHeaderFooterReferences(e[t],"w:footerReference")}})}return r}static async attachHeadersFootersFromPackage(e,r,t,i,n){const a=(n??this.parseDocumentXml(r))?.getElementsByTagName("w:body")[0];if(!a)return;const o=this.findAllSectionProperties(a);if(o.length===0)return;const s=this.resolveSectionHeaderFooterReferences(o),l=o.length-1,c=s[l],p=new Map,h=async O=>{const W=p.get(O);if(W)return W;const X={paragraphs:[],images:[]},D=i?.relationships.get(O);if(D){const M=D.target.startsWith("word/")?D.target:`word/${D.target.replace(/^\//,"")}`,L=await t.file(M)?.async("string");if(L){const I=M.split("/").pop()??M,B=await t.file(`word/_rels/${I}.rels`)?.async("string");if(X.paragraphs=await this.parseHeaderFooterPart(L,B?this.parseRelationshipsXml(B,M):void 0),!e.watermark){const E=this.parseVmlWatermark(L);E&&(e.watermark=E)}X.images=await this.parseHeaderFooterImages(L,M,t,i)}}return p.set(O,X),X},g=async O=>(await h(O)).paragraphs,f=["default","first","even"],w=[],u=async(O,W)=>{const X={};for(const D of f){const M=O[D];if(!M)continue;const L=await h(M);L.paragraphs.length>0&&(X[D]=L.paragraphs);for(const I of L.images)w.push({side:W,slot:D,...I})}return Object.keys(X).length>0?X:void 0},m=await u(c.header,"header"),b=await u(c.footer,"footer");m&&(e.headers=m),b&&(e.footers=b),w.length>0&&(e.chromeImages=w);const v=[];for(let O=0;O<l;O++)for(const W of["header","footer"])for(const X of f){const D=s[O][W][X],M=c[W][X];if(D===M)continue;const L=D?await g(D):[];v.push(Dr(W,X,L.length>0?Ei(L):void 0,void 0,O))}const y=[],T=new Set(v.map(O=>`${O.side}/${O.slot}/${O.sectionIndex}`));for(let O=0;O<o.length;O++)if(o[O].getElementsByTagName("w:titlePg").length!==0)for(const W of["header","footer"]){const X=s[O][W].first;if((X?await g(X):[]).length>0||!s[O][W].default)continue;const D=O===l?void 0:O;T.has(`${W}/first/${D}`)||y.push(Dr(W,"first",void 0,void 0,D))}(v.length>0||y.length>0)&&(e.chrome=[...Di(e.headers,e.footers),...v,...y])}static parseVmlWatermark(e){if(!e.includes("v:textpath"))return;const r=this.parseDocumentXml(e);if(!r)return;const t=r.getElementsByTagName("v:textpath");for(let i=0;i<t.length;i++){const n=t[i],a=(n.getAttribute("string")??"").trim();if(!a)continue;let o=n.parentNode;for(;o&&o.tagName!=="v:shape";)o=o.parentNode;const s=(o?.getAttribute("style")??"").match(/rotation:\s*(-?\d+(?:\.\d+)?)/),l=s?(parseFloat(s[1])%360+360)%360:0,c=this.vmlFillColorToHex(o?.getAttribute("fillcolor")??"");let p;const h=o?.getElementsByTagName("v:fill")[0]?.getAttribute("opacity");if(h){const w=h.endsWith("f")?parseFloat(h)/65536:parseFloat(h);Number.isFinite(w)&&w>0&&w<=1&&(p=Math.abs(w-Fr)<.05?void 0:w)}const g=(n.getAttribute("style")??"").match(/font-size:\s*(\d+(?:\.\d+)?)pt/),f=g?parseFloat(g[1]):void 0;return Bi({text:a,...c?{color:c}:{},...p!==void 0?{opacity:p}:{},diagonal:l!==0,...f&&f>2?{fontSizePx:Math.round(f*(4/3))}:{}})}}static vmlFillColorToHex(e){const r=e.trim().toLowerCase();if(r){if(r.startsWith("#")){const t=r.slice(1,7);return/^[0-9a-f]{6}$/.test(t)?`#${t.toUpperCase()}`:void 0}return{silver:"#C0C0C0",gray:"#808080",grey:"#808080",black:"#000000",red:"#FF0000",blue:"#0000FF",green:"#008000",white:"#FFFFFF"}[r]}}static async parseHeaderFooterImages(e,r,t,i){if(!i||!e.includes("w:drawing"))return[];const n=this.parseDocumentXml(e);if(!n)return[];const a=n.getElementsByTagName("w:drawing");if(a.length===0)return[];const o=r.split("/").pop()??r,s=await t.file(`word/_rels/${o}.rels`)?.async("string"),l={...i,relationships:this.parseRelationshipsXml(s,r)},c=[];for(let p=0;p<a.length;p++){const h=await this.parseImageFromDrawing(a[p],void 0,l);if(h){const g=this.headerFooterImageAlign(a[p]);c.push({src:h.src,width:h.width,height:h.height,...h.alt?{alt:h.alt}:{},...g?{align:g}:{}})}}return c}static headerFooterImageAlign(e){let r=e.parentElement;for(;r&&r.tagName!=="w:p";)r=r.parentElement;if(!r)return;const t=Array.from(r.children).find(n=>n.tagName==="w:pPr"),i=(t?Array.from(t.children).find(n=>n.tagName==="w:jc"):void 0)?.getAttribute("w:val");if(i==="center")return"center";if(i==="right"||i==="end")return"right"}static async parseHeaderFooterPart(e,r){const t=this.parseDocumentXml(e);if(!t)return[];const i=[],n=Array.from(t.getElementsByTagName("w:p")).filter(a=>{let o=a.parentElement;for(;o;){if(o.tagName==="w:txbxContent")return!1;o=o.parentElement}return!0});for(let a=0;a<n.length;a++){const o=n[a],s=[];let l=null,c=!1;const p=m=>{const b={},v=this.getDirectChild(m,"w:rPr");v&&(this.applyRunPropertiesFromElement(b,v),(this.getDirectChild(v,"w:rStyle")?.getAttribute("w:val")||void 0)===this.CODE_INLINE_STYLE_ID&&(b.code=!0,/courier/i.test(b.fontFamily??"")&&delete b.fontFamily,/^(light)?gray$/i.test(b.backgroundColor??"")&&delete b.backgroundColor));let y=m.parentElement;for(;y&&y!==o;){if(y.tagName==="w:ins"||y.tagName==="w:del"){const O=y.tagName==="w:ins",W=this.parseTrackedRevisionMeta(y);Object.assign(b,{...O?{insertion:!0}:{deletion:!0},suggestionId:W.revisionId?`docxrev-${W.revisionId}`:this.generateId(),...this.revisionAuthorIdentity(W.author),suggestionLabel:O?"Insert":"Delete",...W.createdAt!==void 0?{suggestionCreatedAt:W.createdAt}:{},...W.author?{suggestionAuthorName:W.author}:{}});break}y=y.parentElement}let T=m.parentElement;for(;T&&T!==o;){if(T.tagName==="w:hyperlink"){const O=T.getAttribute("r:id"),W=T.getAttribute("w:anchor"),X=O?r?.get(O)?.target:void 0;X?b.link=X:W&&(b.link=`#${W}`);break}T=T.parentElement}return b},h=Array.from(o.getElementsByTagName("w:r")).filter(m=>{let b=m.parentElement;for(;b&&b!==o;){if(b.tagName==="w:p")return!1;b=b.parentElement}return b===o});for(let m=0;m<h.length;m++){const b=h[m],v=p(b);for(let y=0;y<b.children.length;y++){const T=b.children[y];if(T.tagName==="w:t"||T.tagName==="w:delText"){if(c)continue;const O=T.textContent??"";O&&s.push({type:"text",text:O,...Object.keys(v).length>0?{marks:v}:{}})}else if(T.tagName==="w:tab")s.push({type:"text",text:" "});else if(T.tagName==="w:br"&&!c&&(T.getAttribute("w:type")??"textWrapping")==="textWrapping")s.push({type:"text",text:`
|
|
3
3
|
`,...Object.keys(v).length>0?{marks:v}:{}});else if(T.tagName==="w:fldChar"){const O=T.getAttribute("w:fldCharType");O==="begin"&&(c=!0),O==="end"&&(l&&s.push({type:"text",text:"1",marks:{...v,field:l}}),l=null,c=!1)}else if(T.tagName==="w:instrText"&&c){const O=(T.textContent??"").trim().toUpperCase();O.startsWith("PAGE")?l="page":O.startsWith("NUMPAGES")&&(l="numPages")}}}const g=o.getElementsByTagName("w:fldSimple");for(let m=0;m<g.length;m++){const b=(g[m].getAttribute("w:instr")??"").trim().toUpperCase();b.startsWith("PAGE")?s.push({type:"text",text:"1",marks:{field:"page"}}):b.startsWith("NUMPAGES")&&s.push({type:"text",text:"1",marks:{field:"numPages"}})}const f=this.getDirectChild(this.getDirectChild(o,"w:pPr")??o,"w:jc")?.getAttribute("w:val"),w=f==="center"?"center":f==="right"||f==="end"?"right":f==="both"?"justify":void 0;s.length>0&&i.push({type:"paragraph",id:this.generateId(),children:s,...w?{align:w}:{}});const u=await this.parseTextBoxContent(o,void 0);i.push(...u.filter(m=>m.type==="paragraph"))}return i}static attachCommentsFromXml(e,r,t,i){const n=this.parseDocumentXml(r);if(!n)return;const a=new Set,o=u=>{if(!u||typeof u!="object")return;if(Array.isArray(u)){u.forEach(o);return}const m=u;m.marks?.comment&&m.marks.comment.split(",").forEach(b=>a.add(b)),o(m.children)};o(e.children);const s=(i??this.fallbackCommentState).collapsedCommentAnchorBlockById;s?.forEach((u,m)=>a.add(`docxcmt-${m}`));const l=new Map;if(t){const u=this.parseDocumentXml(t)?.getElementsByTagName("w15:commentEx")??[];for(let m=0;m<u.length;m++){const b=u[m],v=b.getAttribute("w15:paraId");v&&l.set(v,{done:b.getAttribute("w15:done")==="1",parentParaId:b.getAttribute("w15:paraIdParent")??void 0})}}const c=[],p=new Map,h=new Map,g=n.getElementsByTagName("w:comment");for(let u=0;u<g.length;u++){const m=g[u],b=m.getAttribute("w:id");if(!b)continue;const v=`docxcmt-${b}`,y=m.getElementsByTagName("w:p"),T=[];for(let D=0;D<y.length;D++){const M=y[D].getElementsByTagName("w:t");let L="";for(let B=0;B<M.length;B++)L+=M[B].textContent??"";T.push(L);const I=y[D].getAttribute("w14:paraId");I&&(p.set(v,I),h.set(I,v))}const O=m.getAttribute("w:date"),W=O?Date.parse(O):NaN,X=s?.get(b);c.push({id:v,author:m.getAttribute("w:author")??"Unknown",...m.getAttribute("w:initials")?{initials:m.getAttribute("w:initials")}:{},createdAt:Number.isFinite(W)?new Date(W).toISOString():new Date(0).toISOString(),bodyMd:T.filter(D=>D.length>0).join(`
|
|
4
4
|
|
|
@@ -1 +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-
|
|
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};
|
|
@@ -1 +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-
|
|
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};
|
|
@@ -1 +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-
|
|
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};
|
|
@@ -1 +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-
|
|
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};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{F as P,H as S}from"./index-p6UytRm8.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-hxIa69By.js";class st{static async parseFile(e){const t=(await import("./index-p6UytRm8.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(`
|
|
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
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
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
4
|
|