revise 3.1.6 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1680 -168
- package/FONT-LICENSE-HAN-EXT-B.txt +91 -0
- package/FONT-LICENSE-KATEX.txt +95 -0
- package/FONT-LICENSE-LIBERATION.txt +102 -0
- package/FONT-LICENSE-NOTO-MULTILINGUAL.txt +93 -0
- package/FONT-LICENSE-NOTO-SANS-SC.txt +93 -0
- package/FONT-LICENSE-NOTO.txt +94 -0
- package/FONT-LICENSE-SOURCE-CODE-PRO.txt +94 -0
- package/FONT-LICENSE-SOURCE-SERIF-4.txt +93 -0
- package/LICENSE +41 -21
- package/README.md +32 -119
- package/THIRD-PARTY-NOTICES.md +2751 -0
- package/assets/historyMaterializeWorker-ZFUHJDWr.js +619 -0
- package/chunks/AgentPageRenderer-5mZ6fxqO.js +1 -0
- package/chunks/AgentPageRenderer-C3jIBoeM.js +1 -0
- package/chunks/AttachmentDocumentImporter-CXkM4VoT.js +1 -0
- package/chunks/AttachmentDocumentImporter-Kox5By7a.js +1 -0
- package/chunks/ColorParserFull-BKH72fK8.js +446 -0
- package/chunks/DocumentScrubber-BxmlzNNz.js +1 -0
- package/chunks/DocumentScrubber-wmjRnX7C.js +1 -0
- package/chunks/DocxConverter-BH3E7nfQ.js +13 -0
- package/chunks/DocxConverter-DEHGCdib.js +13 -0
- package/chunks/DocxGraft-BMvTAnGi.js +1 -0
- package/chunks/DocxGraft-V2YXiUmK.js +1 -0
- package/chunks/FileImporter-CtX8ZPjV.js +1 -0
- package/chunks/FileImporter-Da-7eRh3.js +1 -0
- package/chunks/OdtConverter-CMkSeU8e.js +6 -0
- package/chunks/OdtConverter-DV94rkDL.js +6 -0
- package/chunks/OfficeImportShared-CA3dia_A.js +1 -0
- package/chunks/OfficeImportShared-hxIa69By.js +1 -0
- package/chunks/PdfConverter-B-uRwLux.js +21 -0
- package/chunks/PdfConverter-B8J_5yim.js +21 -0
- package/chunks/PdfImportService-BjQ4rl-Z.js +2 -0
- package/chunks/PdfImportService-RtFCP6hh.js +2 -0
- package/chunks/RtfConverter-CFDnUApT.js +15 -0
- package/chunks/RtfConverter-CpJGtC5U.js +15 -0
- package/chunks/XmlConverter-CQCrgTf7.js +2 -0
- package/chunks/XmlConverter-CePTE21k.js +2 -0
- package/chunks/__vite-browser-external-l0sNRNKZ.js +0 -0
- package/chunks/_revise-sdk-lazy-harfbuzz-X8gnYTZL.js +1 -0
- package/chunks/ar-vDYSGTpE.js +13 -0
- package/chunks/browser-module-B-uafDG6.js +3 -0
- package/chunks/browser-module-jwkhffzv.js +3 -0
- package/chunks/bundle.min-DRpfgV69.js +782 -0
- package/chunks/de-CWX4cvtt.js +13 -0
- package/chunks/es-DoAhvF6_.js +13 -0
- package/chunks/fil-DdAeD8Br.js +13 -0
- package/chunks/fr-CazsUjNQ.js +13 -0
- package/chunks/html2canvas.esm-CntiHiYW.js +997 -0
- package/chunks/index-BWdRWxoH.js +1807 -0
- package/chunks/index-C7VhCKXe.js +402 -0
- package/chunks/index-p6UytRm8.js +402 -0
- package/chunks/ja-alh_QHTB.js +13 -0
- package/chunks/jspdf.es.min-BuJNZ-oY.js +1882 -0
- package/chunks/katex-DWj8TvwO.js +1462 -0
- package/chunks/pdf-BLWDCiFF.js +1828 -0
- package/chunks/persistInlineDocumentImages-DQj2iaqg.js +1 -0
- package/chunks/pseudoLocale-Bkzfsfiw.js +1 -0
- package/chunks/pseudoLocale-D-AfwRwa.js +1 -0
- package/chunks/tree-sitter-D6zWWUMP.js +4 -0
- package/chunks/wasmInline.generated-CBYFkdSM.js +1 -0
- package/chunks/web-tree-sitter-BXGZGnNj.js +2 -0
- package/chunks/zh-20eXwzFZ.js +13 -0
- package/cli-shim.js +34 -0
- package/full.js +1 -0
- package/index.d.ts +995 -13
- package/index.js +1 -31
- package/legacy/server.d.ts +19 -19
- package/legacy/server.js +39 -23
- package/package.json +55 -45
- package/serverToolContract.d.ts +420 -0
- package/serverToolInputs.generated.d.ts +269 -0
- package/style.css +1 -0
- package/version.d.ts +4 -0
- package/version.js +2 -0
- package/agent.d.ts +0 -139
- package/chunks/chunk-SMTOJL2X.js +0 -2436
- package/chunks/chunk-U5X47PZ6.js +0 -135
- package/chunks/chunk-U6YKQBKL.js +0 -15
- package/chunks/package-5SHL5FOJ.js +0 -14
- package/chunks/render-QD5VWKSV.js +0 -109
- package/cli-output.schema.json +0 -2159
- package/cli.js +0 -4152
- package/document.d.ts +0 -439
- package/docx.d.ts +0 -73
- package/errors.d.ts +0 -14
- package/legacy/editor.d.ts +0 -19
- package/legacy/editor.js +0 -16
- package/legacy/style.css +0 -2
- package/package.d.ts +0 -23
- package/render.d.ts +0 -27
|
@@ -0,0 +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};
|
|
@@ -0,0 +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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a5 as h,a6 as y,a7 as D,a8 as k}from"./index-p6UytRm8.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-CtX8ZPjV.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-BMvTAnGi.js");await g(i,l.bytes,{hash:l.hash})}}}else{const{importPdfIntoExistingDocument:a}=await import("./PdfImportService-BjQ4rl-Z.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};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a5 as h,a6 as y,a7 as D,a8 as k}from"./index-C7VhCKXe.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-Da-7eRh3.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-V2YXiUmK.js");await g(i,l.bytes,{hash:l.hash})}}}else{const{importPdfIntoExistingDocument:a}=await import("./PdfImportService-RtFCP6hh.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};
|