@reviseio/engine 0.0.0-stage → 3.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 +12 -0
- package/FONT-LICENSE-HAN-EXT-B.txt +91 -0
- package/FONT-LICENSE-KATEX.txt +95 -0
- package/FONT-LICENSE-LIBERATION.txt +102 -0
- package/FONT-LICENSE-NOTO-MULTILINGUAL.txt +93 -0
- package/FONT-LICENSE-NOTO-SANS-SC.txt +93 -0
- package/FONT-LICENSE-NOTO.txt +94 -0
- package/FONT-LICENSE-SOURCE-CODE-PRO.txt +94 -0
- package/FONT-LICENSE-SOURCE-SERIF-4.txt +93 -0
- package/LICENSE +141 -0
- package/README.md +11 -2
- package/THIRD-PARTY-NOTICES.md +3376 -0
- package/assets/historyMaterializeWorker-Kl0syEbc.js +618 -0
- package/chunks/AgentHtmlConverter-BnK7NaYA.js +379 -0
- package/chunks/AgentPageRenderViews-BTLjPZJQ.js +2 -0
- package/chunks/AgentPageRenderer-DLwq6nAa.js +180 -0
- package/chunks/BidiText-Bkp4Y90s.js +160 -0
- package/chunks/BlockDiff-BdlcKY-t.js +42 -0
- package/chunks/CanvasRenderer-Bqsj1S0p.js +110 -0
- package/chunks/ColorParserFull-BKH72fK8.js +446 -0
- package/chunks/DocumentCompare-BqyiP87r.js +6 -0
- package/chunks/DocumentLayout-CsU5MR-3.js +12 -0
- package/chunks/DocumentLayoutEngine-7iOYvyVb.js +218 -0
- package/chunks/DocumentMutator-DIrZBuLr.js +13 -0
- package/chunks/DocumentScrubber-Cz8Q05hF.js +21 -0
- package/chunks/DocumentSession-lXSXqua5.js +1 -0
- package/chunks/DocumentStylesheet-CEEt18sr.js +7 -0
- package/chunks/DocxConverter-BfDw7777.js +1236 -0
- package/chunks/DocxGraft-D0uCnGCo.js +8 -0
- package/chunks/HorizontalRuleOrnaments-gmUZ3R7Q.js +3 -0
- package/chunks/HtmlConverter-7Xj_g9Jr.js +267 -0
- package/chunks/ListNumbering-Qlu6AuRZ.js +23 -0
- package/chunks/MarkdownConverter-cnW_oePY.js +57 -0
- package/chunks/MathRenderer-Bz9WEVvF.js +68 -0
- package/chunks/OdtConverter-GwRDMnwS.js +125 -0
- package/chunks/OfficeImportShared-nlMtIUni.js +30 -0
- package/chunks/PageNumeralFonts-BWzI061X.js +5 -0
- package/chunks/ParagraphDiffAnalysis-DrmStvmz.js +36 -0
- package/chunks/PdfConverter-yOlWiVIj.js +457 -0
- package/chunks/RtfConverter--wLd0qrw.js +186 -0
- package/chunks/TableBorders-C5pNsuxP.js +32 -0
- package/chunks/TableGrid-DbroRucl.js +12 -0
- package/chunks/TextFileDecoder--rsVs3NR.js +9 -0
- package/chunks/TxtConverter-BoRVCDZw.js +14 -0
- package/chunks/Typography-DAGM5kfI.js +28 -0
- package/chunks/UnicodeUtils-CXtusU4g.js +10 -0
- package/chunks/XmlConverter-CO8Z28dX.js +55 -0
- package/chunks/_commonjsHelpers-DaMA6jEr.js +2 -0
- package/chunks/_revise-sdk-lazy-harfbuzz-CDWdjF9f.js +1 -0
- package/chunks/base64-Di1bxoXD.js +1 -0
- package/chunks/browser-module-CFmqfGkE.js +1791 -0
- package/chunks/bundle.min-DRpfgV69.js +782 -0
- package/chunks/capture-Dtinb4bY.js +11 -0
- package/chunks/carrier-RNy67HN4.js +6 -0
- package/chunks/chromeImageLayout-bgHYmqTp.js +18 -0
- package/chunks/engine-TnK8N-gT.js +520 -0
- package/chunks/footnoteFlatten-BcKaWzVs.js +6 -0
- package/chunks/graftExport-DxAALMHp.js +104 -0
- package/chunks/html2canvas.esm-CntiHiYW.js +997 -0
- package/chunks/index-BWdRWxoH.js +1807 -0
- package/chunks/index-CTti7wRd.js +1002 -0
- package/chunks/index.es-CI0QPo8w.js +780 -0
- package/chunks/jspdf.es.min-DU74zN8b.js +1792 -0
- package/chunks/jszip.min-CPW0h1Kx.js +476 -0
- package/chunks/katex-DWj8TvwO.js +1462 -0
- package/chunks/pdf-BLWDCiFF.js +1828 -0
- package/chunks/purify.es-BwLardii.js +107 -0
- package/chunks/serverDocumentSession-BmYdjC6e.js +1011 -0
- package/chunks/signatures-CU2LMLBp.js +21 -0
- package/chunks/suggestionAuthorship-B-IuLQlE.js +1 -0
- package/chunks/web-tree-sitter-BXGZGnNj.js +2 -0
- package/chunks/xmlScan-DXjt2cTS.js +8 -0
- package/engine.d.ts +179 -0
- package/engine.js +3 -0
- package/package.json +64 -4
- package/serverToolContract.d.ts +420 -0
- package/serverToolInputs.generated.d.ts +264 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import*as E from"yjs";import{S as G}from"./AgentHtmlConverter-BnK7NaYA.js";import{r as ct,f as Jt,D as Xt}from"./DocumentMutator-DIrZBuLr.js";import{p as lt,f as Q,h as Vt,y as dt}from"./engine-TnK8N-gT.js";
|
|
2
|
+
import{D as Z,i as Qt}from"./AgentPageRenderViews-BTLjPZJQ.js";import{g as gt,c as Zt,d as ft,a as tt,w as ht,b as te,e as ee}from"./CanvasRenderer-Bqsj1S0p.js";import{g as et}from"./Typography-DAGM5kfI.js";
|
|
3
|
+
import{g as oe,a as B,c as ut,b as ne}from"./index-CTti7wRd.js";import{c as ae,f as j,b as _,g as q,a as ie,d as ot,e as se}from"./DocumentLayoutEngine-7iOYvyVb.js";import{getLayoutMarginTop as mt,getLayoutMarginRight as re,
|
|
4
|
+
getLayoutMarginBottom as pt,getLayoutMarginLeft as z,layoutForBlockBounds as yt}from"./DocumentLayout-CsU5MR-3.js";import{r as ce,g as le,e as de}from"./MathRenderer-Bz9WEVvF.js";import{p as ge}from"./TableBorders-C5pNsuxP.js";
|
|
5
|
+
import{r as fe}from"./BidiText-Bkp4Y90s.js";import{g as he}from"./PageNumeralFonts-BWzI061X.js";function bt(t,e){const n=e?.saturation,o=e?.lightness,i=e?.hueRange??[0,360];let a=5381;for(let d=0;d<t.
|
|
6
|
+
length;d++)a=(a<<5)+a+t.charCodeAt(d),a|=0;const s=Math.abs(a)%1e3,[l,r]=i,c=Math.max(0,r-l);return`hsl(${l+s%(c||360)} ${n}% ${o}%)`}const xt=class U{constructor(){this.cache=new Map,this.loadingImages=
|
|
7
|
+
new Set,this.failedImages=new Set}static getInstance(){return U.instance||(U.instance=new U),U.instance}getImage(e){return this.cache.get(e)||(this.failedImages.has(e)||this.loadingImages.has(e)||this.
|
|
8
|
+
loadImage(e),null)}loadImage(e){this.loadingImages.add(e);const n=new Image;n.crossOrigin="anonymous",n.onload=()=>{this.cache.set(e,n),this.loadingImages.delete(e),this.failedImages.delete(e)},n.onerror=
|
|
9
|
+
()=>{this.loadingImages.delete(e),this.failedImages.add(e),console.warn(`Failed to load avatar image: ${e}`)},n.src=e}clear(){this.cache.clear(),this.loadingImages.clear(),this.failedImages.clear()}};
|
|
10
|
+
xt.instance=null;let ue=xt;const kt=new WeakMap;function me(t){return[t.pageWidth,t.pageHeight,t.pageMargin,mt(t),re(t),pt(t),z(t),t.pageSpacing,t.fontSize,t.fontFamily,t.lineHeight,t.paragraphSpacing,
|
|
11
|
+
t.blockSpacingPx??"",t.pageless,t.availableWidth,t.textStartY,t.columnCount??"",t.columnGapPx??"",t.hyphenationEnabled===!0,t.lineNumbering?JSON.stringify(t.lineNumbering):"","show-removals",oe()].join(
|
|
12
|
+
"|")}function A(t,e,n){const o=me(n);let i=kt.get(t);if(!i)i=new Map,kt.set(t,i);else{const s=i.get(o);if(s)return s}const a=ae(t,e,n);return i.set(o,a),a}function pe(t,e,n){return ye(t,e,n)<=0?[e,n]:
|
|
13
|
+
[n,e]}function K(t,e){if(!e?.block)return null;const n=t.blocks.find(o=>o.block?.id===e.block);return n?n.blockIndex:null}function J(t,e,n){const[o,i]=pe(t,e,n),a=K(t,o),s=K(t,i);let l=a,r=s;return a!==
|
|
14
|
+
null&&s!==null&&a>s&&(l=s,r=a),{start:o,end:i,startBlockIndex:a,endBlockIndex:s,minBlockIndex:l,maxBlockIndex:r}}function nt(t,e){return!e||e.minBlockIndex===null||e.maxBlockIndex===null?!1:t>=e.minBlockIndex&&
|
|
15
|
+
t<=e.maxBlockIndex}function It(t,e,n){if(!n||!t)return!1;const o=e.blocks.find(i=>i.block?.id===t);return o?nt(o.blockIndex,n):!1}function ye(t,e,n){const o=K(t,e),i=K(t,n);return o!==null&&i!==null&&
|
|
16
|
+
o!==i?o-i:o!==null&&i!==null?e.offset-n.offset:o!==null?-1:i!==null?1:e.block&&n.block&&e.block!==n.block?e.block.localeCompare(n.block):0}function F(t,e,n,o,i,a,s,l,r){W(t,e,n,o,i,a,s||0,l,r)}function W(t,e,n,o,i,a,s=0,l,r){
|
|
17
|
+
const c=B(),d=A(e,i,a),f=J(d,n,o),h=l!==void 0&&r!==void 0?j(d,l,r):d.fragments;for(const u of h){const{block:m,blockIndex:x,bounds:p}=u,k=c.getHandlerForBlock(m);if(!k){console.warn(`No handler for b\
|
|
18
|
+
lock type: ${m.type}`);continue}const v=m.id,w=!!v&&f.start.block===v,M=!!v&&f.end.block===v;if(w||M||nt(x,f)){let T=null,I=null;w&&(T=f.start),M&&(I=f.end);const y=_(u),g=k.getSelectionRects(m,T,I,p,
|
|
19
|
+
i,a,e,y);t.save(),t.fillStyle=t.fillStyle||"#0066CC",t.globalAlpha=t.globalAlpha||.3;for(const b of g)t.fillRect(b.x,b.y-s,b.width,b.height);t.restore()}}}function be(t){const e=(t??"").toLowerCase();
|
|
20
|
+
return e.includes("claude")||e.includes("anthropic")?"claude":e.includes("chatgpt")||e.includes("gpt")||e.includes("openai")?"chatgpt":e.includes("codex")?"codex":e.includes("grok")?"grok":e.includes(
|
|
21
|
+
"hermes")?"hermes":e.includes("gemini")||e.includes("google")?"gemini":"generic"}const xe={claude:"#D97757",codex:"#000000",hermes:"#000000",grok:"#000000",chatgpt:"#0FA47F",gemini:"#4285F4",generic:"\
|
|
22
|
+
#7C6CF0"};function ke(t){return xe[t]}function Ie(t){return ce(`agent-logos/${t}.svg`)}function ve(t){const e=be(t);return{kind:e,color:ke(e),logoSrc:Ie(e)}}const H=new Map,N=new Map,at=new Map,X=new Map,
|
|
23
|
+
vt=180,it=80,wt={saturation:78,lightness:55,hueRange:[170,290]};typeof window<"u"&&setInterval(()=>{const t=Date.now(),e=6e4;Array.from(H.entries()).forEach(([n,o])=>{t-o>e&&(H.delete(n),N.delete(n),at.
|
|
24
|
+
delete(n),X.delete(n))})},3e4);function St(t,e,n){if(!t)return[];const o=[],i=t.getStates(),a=t.clientID,s=t.getLocalState()?.user?.id;return i.forEach((l,r)=>{if(r===a)return;const c=l.user,d=l.cursor;
|
|
25
|
+
if(!c||!d||s&&c.id===s)return;const f=c.color||c.id&&bt(c.id,wt)||bt(String(r),wt),h=c.name||c.email||"Anonymous",u=d.blockSelection;if(u){const x=typeof u.blockIndex=="number"||u.blockId?{blockIndex:u.
|
|
26
|
+
blockIndex,blockType:u.blockType,blockId:u.blockId}:void 0;if(x){const p=x.blockId??(typeof x.blockIndex=="number"?n?.children[x.blockIndex]?.id:void 0);p&&(d.blockSelection={blockIndex:x.blockIndex,blockType:x.
|
|
27
|
+
blockType,blockId:p})}}const m=d;if(m?.anchor){const x=Tt(m.anchor,e),p=m.focus?Tt(m.focus,e):null;if(x){const k=JSON.stringify(x);N.get(r)!==k&&(H.set(r,Date.now()),N.set(r,k));const v={clientId:r,userId:c.
|
|
28
|
+
id,name:h,color:f,image:c.image,position:x,isSelection:!1};p&&(p.block!==x.block||p.offset!==x.offset)&&(v.isSelection=!0,v.endPosition=p),o.push(v)}}}),o}const we=5*60*1e3;function Se(t){const e=atob(
|
|
29
|
+
t),n=new Uint8Array(e.length);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);return n}function Me(t){let e=5381;for(let n=0;n<t.length;n++)e=(e<<5)+e+t.charCodeAt(n)|0;return-Math.abs(e)-1}function Mt(t,e){
|
|
30
|
+
if(!t)return[];let n;try{n=t.getMap("agent-presence")}catch{return[]}const o=[];return n.forEach(i=>{const a=i;if(!a||typeof a!="object")return;const s=typeof a.lastActiveAt=="number"?a.lastActiveAt:0;
|
|
31
|
+
if(e-s>we)return;const l=a.cursor;if(!l||typeof l.rel!="string")return;let r=null;try{const u=E.decodeRelativePosition(Se(l.rel));r=ct({blockId:l.blockId??"",textOffset:u},t)}catch{return}if(!r)return;
|
|
32
|
+
const c=ve(a.name),d=String(a.id??a.name??"agent"),f=Me(d),h=JSON.stringify(r);N.get(f)!==h&&(H.set(f,Date.now()),N.set(f,h)),o.push({clientId:f,userId:typeof a.id=="string"?a.id:void 0,name:a.name&&a.
|
|
33
|
+
name.trim()?a.name:"AI agent",color:c.color,image:c.logoSrc,position:r,isSelection:!1})}),o}function Te(t){return!!t&&typeof t=="object"&&typeof t.blockId=="string"&&t.textOffset!==void 0}function Tt(t,e,n){
|
|
34
|
+
if(Te(t))return ct(t,e);const o=E.createAbsolutePositionFromRelativePosition(t,e);return o?Pe(o):null}function Pe(t,e,n){if(!(t.type instanceof E.XmlText))return null;const o=t.index||0,i=Jt(t.type);return i?
|
|
35
|
+
{block:i.blockId,offset:i.offset+o}:null}function st(t,e,n,o,i,a,s){const l=B(),r=s??A(e,n,o),c=q(r,t.block);if(!c)return null;const{block:d}=c,f=l.getHandlerForBlock(d);if(!f)return null;const h=ie(r,
|
|
36
|
+
t,d,f);if(!h)throw new Error("unexpected: no fragment");const u=_(h),m=a?{syntaxTheme:a}:void 0;return f.getCursorScreenPosition(d,t,h.bounds,n,o,i,e,u,m)}function Ce(t,e,n,o,i,a,s){return st(t,e,n,o,
|
|
37
|
+
i,a,s)}function Pt(t,e,n,o,i,a=!1,s,l,r){const c=st(e,n,o,i,t,r);if(!c)return;const d=et(t.canvas),f=c.y-(s||0);t.save(),t.beginPath(),t.strokeStyle=c.cursorColor||l||d.cursor,t.lineWidth=2,t.moveTo(c.
|
|
38
|
+
x,f-c.fontSize),t.lineTo(c.x,f+3),t.stroke(),t.restore()}function Oe(t,e,n){if(e.block===n.block)return Math.sign(e.offset-n.offset);const o=gt(t,e.block),i=gt(t,n.block);return!o||!i?0:Zt(o,i)}function De(t,e,n,o,i,a,s,l){
|
|
39
|
+
if(!n)return;let r=e,c=n;if(Oe(i,r,c)>0&&(r=n,c=e),r.block===c.block&&r.offset===c.offset)return;const d=B(),f=A(i,a,s),h=J(f,r,c);t.save(),t.fillStyle=o,t.globalAlpha=.3;const u=k=>{const v=ot(f,k);if(!v)
|
|
40
|
+
return!1;const w=d.getHandlerForBlock(v.block);if(!w||w.isTextBased)return!1;const M=v.bounds.y-(l||0);return t.save(),t.globalAlpha=1,t.fillStyle="transparent",t.strokeStyle=o,t.lineWidth=2,t.strokeRect(
|
|
41
|
+
v.bounds.x,M,v.bounds.width,v.bounds.height),t.restore(),!0},m=(k,v)=>{const w=ot(f,k);return w?.blockId?{block:w.blockId,offset:v}:null},x=h.startBlockIndex,p=h.endBlockIndex;if(x===null||p===null){t.
|
|
42
|
+
restore();return}if(x===p)u(x)||W(t,i,r,c,a,s,l||0);else{if(!u(x)){const k=m(x,Number.MAX_SAFE_INTEGER);k&&W(t,i,r,k,a,s,l||0)}for(let k=x+1;k<p;k++)if(!u(k)){const v=m(k,0),w=m(k,Number.MAX_SAFE_INTEGER);
|
|
43
|
+
v&&w&&W(t,i,v,w,a,s,l||0)}if(!u(p)){const k=m(p,0);k&&W(t,i,k,c,a,s,l||0)}}t.restore()}function Re(t,e,n,o,i,a,s){if(!e)return;const l=A(o,i,a),r=(typeof e.blockIndex=="number"?ot(l,e.blockIndex):null)||
|
|
44
|
+
(e.blockId?q(l,e.blockId):null);if(!r)return;const{bounds:c}=r,d=c.y-(s||0),f=B().getHandlerForBlock(r.block);t.save(),f&&!f.isTextBased?(t.globalAlpha=1,t.strokeStyle=n,t.lineWidth=2,t.strokeRect(c.x,
|
|
45
|
+
d,c.width,c.height)):(t.fillStyle=n,t.globalAlpha=.3,t.fillRect(c.x,d,c.width,c.height)),t.restore()}function $e(t,e,n,o,i,a,s){const l=e.endPosition||e.position,r=st(l,n,o,i,t);if(!r)return;const c=r.
|
|
46
|
+
y-(a||0),d=Date.now(),f=H.get(e.clientId)||d,h=d-f,u=3e3,m=2500,x=500,p=24,k=r.x-10,v=c-r.fontSize-p-4;if(s){const g=c-r.fontSize,b=c+3,S=Math.max(g,Math.min(s.y,b)),P=Math.hypot(s.x-r.x,s.y-S),O=Math.
|
|
47
|
+
hypot(s.x-(k+p/2),s.y-(v+p/2));if(P<14||O<p){const R=X.get(e.clientId)??0;d-R>it&&at.set(e.clientId,d),X.set(e.clientId,d)}}let w=1;if(h>=u)w=0;else if(h>=m){const g=Math.min(1,(h-m)/x),b=g<.5?2*g*g:1-
|
|
48
|
+
Math.pow(-2*g+2,2)/2;w=Math.max(0,1-b)}const M=X.get(e.clientId)??0;let T=0;if(d-M<=it){const g=at.get(e.clientId)??d;T=Math.min(1,(d-g)/vt)}else{const g=M+it;T=Math.max(0,1-(d-g)/vt)}const I=Math.max(
|
|
49
|
+
w,T),y=I>.01;if(t.save(),e.blockSelection?Re(t,e.blockSelection,e.color,n,o,i,a):e.isSelection&&e.endPosition&&De(t,e.position,e.endPosition,e.color,n,o,i,a),t.beginPath(),t.strokeStyle=e.color,t.lineWidth=
|
|
50
|
+
2,t.moveTo(r.x,c-r.fontSize),t.lineTo(r.x,c+3),t.stroke(),y){t.globalAlpha=I;const g=(S=!0)=>{t.beginPath(),t.arc(k+p/2,v+p/2,p/2,0,Math.PI*2),S&&(t.fillStyle=e.color,t.fill())},b=()=>{if(t.fillStyle=
|
|
51
|
+
"#ffffff",t.font="12px sans-serif",t.textAlign="center",t.textBaseline="middle",e.name)t.fillText(e.name.charAt(0).toUpperCase(),k+p/2,v+p/2);else{const S=k+p/2,P=v+p/2;t.save(),t.translate(S,P),t.scale(
|
|
52
|
+
.8,.8),t.strokeStyle="#ffffff",t.lineWidth=1.5,t.beginPath(),t.arc(0,-3,3.5,0,Math.PI*2),t.stroke(),t.beginPath(),t.arc(0,7,6,Math.PI,0,!1),t.stroke(),t.restore()}};if(e.image){const S=ue.getInstance().
|
|
53
|
+
getImage(e.image);S&&S.complete?(t.save(),g(!1),t.clip(),t.drawImage(S,k,v,p,p),t.restore()):(g(),b())}else g(),t.strokeStyle="#ffffff",t.lineWidth=2,t.stroke(),b();t.globalAlpha=1}t.restore()}function Ct(t,e,n,o,i,a,s){
|
|
54
|
+
e.forEach(l=>{$e(t,l,n,o,i,a,s)})}const Ot=new WeakMap;function Ae(t,e,n){const o=Ot.get(e);if(o?.doc===t)return o.routes;const i=new Map,a=new Set(e.fragments.filter(r=>!r.isChrome&&!r.repeatedHeader).
|
|
55
|
+
map(r=>r.blockId));for(const{block:r,blockId:c}of e.blocks){const d=[];let f=0;const h=u=>{for(const m of u)d.push({node:m,offset:f}),f+=m.text.length};if(r.type==="paragraph")h(r.children);else if(r.
|
|
56
|
+
type==="list")for(const u of r.children)h(u.children),f+=1;else continue;for(const{node:u,offset:m}of d){if(!u.text||!u.marks?.suggestionId||!u.marks.docxMove)continue;let x;try{x=JSON.parse(u.marks.docxMove)}catch{
|
|
57
|
+
continue}if(!x||x.role!=="from"&&x.role!=="to")continue;const p=u.marks.suggestionId,k=i.get(p)??{};if(a.has(c)){for(const v of[m,m+u.text.length-1]){const w=Ce({block:c,offset:v},t,n.textContext,n.layout,
|
|
58
|
+
n.ctx,n.syntaxTheme,e);if(!w||!Number.isFinite(w.y))continue;const M=k[x.role],T=Math.min(M?.startY??1/0,w.y-w.fontSize),I=Math.max(M?.endY??-1/0,w.y+3);k[x.role]={startY:T,endY:I,y:(T+I)/2}}i.set(p,k)}}}
|
|
59
|
+
const s=[];for(const[r,c]of i)c.from&&c.to&&s.push({id:r,from:c.from,to:c.to,lane:0});s.sort((r,c)=>Math.min(r.from.y,r.to.y)-Math.min(c.from.y,c.to.y)||r.id.localeCompare(c.id));const l=[];for(const r of s){
|
|
60
|
+
const c=Math.min(r.from.y,r.to.y);let d=l.findIndex(f=>f+12<c);d<0&&(d=l.length),l[d]=Math.max(r.from.y,r.to.y),r.lane=d}return Ot.set(e,{doc:t,routes:s}),s}function Dt(t,e,n,o,i){if(!i?.size)return;const a=Ae(
|
|
61
|
+
e,n,t).filter(b=>i.has(b.id));if(!a.length)return;const{ctx:s}=t,l=t.pageGeometry?.marginLeft??z(t.layout),r=t.pageGeometry?.lineNumbering??t.pageLayoutSettings?.lineNumbering??t.pageGeometry?.pleadingGrid??
|
|
62
|
+
t.pageLayoutSettings?.pleadingGrid,c=Math.max(8,l-(r?(r.distancePx??12)+42:12)),d=Math.max(2,c-8),f=Math.max(...a.map(b=>b.lane))+1,h=c-Math.min(20,d/2),u=Math.min(9,Math.max(0,h-4)/Math.max(1,f-1));s.
|
|
63
|
+
save(),s.beginPath(),s.rect(0,o.startY-o.yOffset,Math.max(0,l-2),o.endY-o.startY),s.clip();const m=s.getTransform(),x=Math.abs(m.a)||1,p=Math.max(1,Math.round(x)),k=p/x,v=(b,S)=>(Math.round(b*x+S-p/2)+
|
|
64
|
+
p/2-S)/x,w=b=>v(b,m.e),M=b=>v(b,m.f),T=w(c),I=lt(t.theme.text),y=lt(t.theme.pageBackground),g=`rgb(${Math.round(I.r*.4+y.r*.6)}, ${Math.round(I.g*.4+y.g*.6)}, ${Math.round(I.b*.4+y.b*.6)})`;s.lineWidth=
|
|
65
|
+
k,s.globalAlpha=1,s.lineJoin="miter",s.lineCap="butt",s.setLineDash([]);for(const b of a){const S=Math.min(b.from.startY,b.to.startY);if(Math.max(b.from.endY,b.to.endY)<o.startY||S>o.endY)continue;const P=w(
|
|
66
|
+
h-b.lane*u),O=M(b.from.y-o.yOffset),R=M(b.to.y-o.yOffset);for(const[C,D]of[[b.from,t.theme.diffDelete],[b.to,t.theme.diffInsert]])s.strokeStyle=D,s.beginPath(),s.moveTo(T,M(C.startY-o.yOffset)),s.lineTo(
|
|
67
|
+
T,M(C.endY-o.yOffset)),s.stroke();s.strokeStyle=g;const $=w(c-7);s.beginPath(),s.moveTo(T-k/2,O),s.lineTo(P,O),s.lineTo(P,R),s.lineTo($,R),s.stroke(),s.beginPath(),s.moveTo($-4,R-4),s.lineTo($,R),s.lineTo(
|
|
68
|
+
$-4,R+4),s.stroke()}s.restore()}const Be="rgba(255, 200, 0, 0.3)",Ee="rgba(255, 180, 0, 0.5)";function Rt(t,e,n,o,i,a,s=0,l,r){if(n.length===0)return;const c=B(),d=A(e,i,a),f=l!==void 0&&r!==void 0?j(
|
|
69
|
+
d,l,r):d.fragments,h=new Map;for(const u of f){const m=u.block.id;m&&(h.has(m)||h.set(m,[]),h.get(m).push(u))}for(let u=0;u<n.length;u++){const m=n[u],x=u===o,p=h.get(m.blockId);if(!p||p.length===0)continue;
|
|
70
|
+
const k={block:m.blockId,offset:m.blockOffset},v={block:m.blockId,offset:m.blockOffset+m.length};for(const w of p){const{block:M,bounds:T}=w,I=w.charRange;if(I&&(m.blockOffset+m.length<I.start||m.blockOffset>
|
|
71
|
+
I.end))continue;const y=c.getHandlerForBlock(M);if(!y)continue;const g=w.lineRange||w.charRange?{lineRange:w.lineRange,charRange:w.charRange,fragmentIndex:w.fragmentIndex,pageNumber:w.pageNumber,unitRange:w.
|
|
72
|
+
unitRange}:w.fragmentIndex!==void 0?{fragmentIndex:w.fragmentIndex}:void 0,b=y.getSelectionRects(M,k,v,T,i,a,e,g);t.save(),t.fillStyle=x?Ee:Be;for(const S of b)t.fillRect(S.x,S.y-s,S.width,S.height);t.
|
|
73
|
+
restore()}}}function Fe(t,e){return e?{...t,pageWidth:e.pageWidth,pageHeight:e.pageHeight,pageMargin:e.marginLeft,pageMarginTop:e.marginTop,pageMarginRight:e.marginRight,pageMarginBottom:e.marginBottom,
|
|
74
|
+
pageMarginLeft:e.marginLeft,availableWidth:Math.max(1,e.pageWidth-e.marginLeft-e.marginRight),textStartY:e.marginTop}:t}function $t(t){const e=t.ctx,n=typeof e.getTransform=="function"?e.getTransform():
|
|
75
|
+
null,o=n&&n.a?n.a:1,i=n&&n.d?n.d:1;e.beginPath(),e.rect(0,0,t.canvas.width/o,t.canvas.height/i),e.clip()}function At(t,e,n){return tt(t,e,n)<=0?[e,n]:[n,e]}function Bt(t,e,n,o,i){const[a,s]=At(t,e,n),
|
|
76
|
+
[l,r]=At(t,o,i);return tt(t,a,r)<0&&tt(t,l,s)<0}typeof window<"u"&&(window.canvasDebugOn=()=>{localStorage.setItem("DEBUG_MODE","true")},window.canvasDebugOff=()=>{localStorage.removeItem("DEBUG_MODE")});
|
|
77
|
+
function Et(t,e,n,o){const i=e.footnoteSeparators;if(!(!i||i.length===0))for(const a of i){if(o.pageIndex!==void 0){if(a.pageIndex!==o.pageIndex)continue}else if(a.pageIndex!==void 0)continue;const s=a.
|
|
78
|
+
y-o.yOffset;t.save(),t.strokeStyle=n.text,t.globalAlpha=.35,t.lineWidth=1,t.beginPath(),t.moveTo(a.x,s),t.lineTo(a.x+a.width,s),t.stroke(),t.restore()}}function Ye(t,e,n,o,i,a,s,l){if(n.pageless||!a?.
|
|
79
|
+
block)return;const r=Q(e,a.block);if(!r||Vt(e.chrome??[],r.block.side,s+1,l?.sectionIndex)!==r.block)return;const c=Fe(n,l),d=mt(c),f=pt(c),h=12,u=r.block.side==="header"?Math.max(h/2+4,d/2):c.pageHeight-
|
|
80
|
+
Math.max(h/2+4,f/2),m=26,x=u-m/2,p=z(c),k=se(r.block,i,c,e);t.save(),t.strokeStyle=o.text,t.globalAlpha=.18,t.lineWidth=1;let v=p;for(let w=0;w<3;w++)t.strokeRect(v+1,x,k[w]-2,m),v+=k[w];t.restore()}function Le(t,e,n,o){
|
|
81
|
+
const i=o.diffDocument??e.getDocument(),a=!!o.diffDocument,s=n.startY,l=n.endY,r=t.layout,c=A(i,t.textContext,r),d=o.selectionRange?[o.selectionRange.start,o.selectionRange.end]:null,f=d??(!a&&e.isSelection()?
|
|
82
|
+
e.getSelectionRange():null),h=!!f&&!!Q(i,f[0]?.block??"")||!!f&&!!o.keepSelectionOnBlur,u=h&&!o.isFocused,m=!!f&&(d!==null||o.isFocused||o.isSelectionInactive||h),x=!!f&&(o.isFocused||o.isSelectionInactive),
|
|
83
|
+
p=!a&&f&&f.length===2?J(c,f[0],f[1]):null;t.ctx.save(),$t(t),Et(t.ctx,c,t.theme,{yOffset:t.yOffset??0}),o.selectionUnderText&&f&&m&&(t.ctx.save(),t.ctx.fillStyle=t.theme.selection,t.ctx.globalAlpha=t.
|
|
84
|
+
theme.selectionOpacity,F(t.ctx,i,f[0],f[1],t.textContext,r,t.yOffset,s,l),t.ctx.restore()),a&&(t.diffSegments=o.diffSegments);const k=B(),v=j(c,s,l),w=v.length>0;let M=!1;const T=[];for(const I of v){
|
|
85
|
+
const{block:y,bounds:g}=I,b=k.getHandlerForBlock(y);if(!b){console.warn(`No handler for block type: ${y.type}`);continue}t.currentParagraphIndex=y.type==="paragraph"?I.blockIndex:void 0;const S={...g,
|
|
86
|
+
y:g.y-(t.yOffset??0),relativeToPage:!0},P=_(I),O=I.blockIndex,R=Yt(O,p);let $;const C=I.data;C?.type==="table-cell"&&C?.parentTableId&&It(C.parentTableId,c,p)&&($={top:C.isTopRow,bottom:C.isBottomRow,
|
|
87
|
+
left:C.isLeftCol,right:C.isRightCol});const D={isSelected:R,isFocused:o.isFocused,showCursor:o.showCursor,isReadOnly:o.readOnly,printPreview:o.printPreview,forceImagePlaceholders:o.forceImagePlaceholders,
|
|
88
|
+
theme:t.theme,syntaxTheme:t.syntaxTheme,doc:i,renderCtx:t,fragment:P,hoveredUIComponentKey:o.hoveredUIComponentKey,activeUIComponentKey:o.activeUIComponentKey,tableSelectionEdges:$,cursorPosition:o.cursorPosition,
|
|
89
|
+
activeSuggestionIds:o.activeSuggestionIds,selection:f?{start:f[0],end:f[1]}:void 0,annotations:o.annotations,hoveredTableId:o.hoveredTableId,focusedTableId:o.focusedTableId,selectedCellIds:o.selectedCellIds},
|
|
90
|
+
L=yt(r,g);b.render(t.ctx,y,S,L,D),typeof b.renderOverlay=="function"&&T.push({handler:b,block:y,bounds:S,layout:L,options:D}),typeof localStorage<"u"&&localStorage.getItem("DEBUG_MODE")&&(t.ctx.save(),
|
|
91
|
+
t.ctx.strokeStyle="red",t.ctx.lineWidth=1,t.ctx.setLineDash([2,2]),t.ctx.strokeRect(S.x,S.y,S.width,S.height),t.ctx.restore())}for(const I of T)I.handler.renderOverlay(t.ctx,I.block,I.bounds,I.layout,
|
|
92
|
+
I.options);if(!a){if(o.pendingSelectionData&&o.pendingSelectionData.length>0){t.ctx.save(),t.ctx.fillStyle=t.theme.inactiveSelection,t.ctx.globalAlpha=t.theme.inactiveSelectionOpacity;for(const I of o.
|
|
93
|
+
pendingSelectionData){const y={block:I.startBlock,offset:I.startOffset},g={block:I.endBlock,offset:I.endOffset};x&&f&&Bt(i,y,g,f[0],f[1])||F(t.ctx,i,y,g,t.textContext,r,t.yOffset,s,l)}t.ctx.restore()}
|
|
94
|
+
if(f&&m&&!o.selectionUnderText){const[I,y]=f;t.ctx.save(),o.isSelectionInactive||u?(t.ctx.fillStyle=t.theme.inactiveSelection,t.ctx.globalAlpha=t.theme.inactiveSelectionOpacity):(t.ctx.fillStyle=t.theme.
|
|
95
|
+
selection,t.ctx.globalAlpha=t.theme.selectionOpacity),F(t.ctx,i,I,y,t.textContext,r,t.yOffset,s,l),t.ctx.restore()}}if(o.searchMatches&&o.searchMatches.length>0&&Rt(t.ctx,i,o.searchMatches,o.currentSearchMatchIndex??
|
|
96
|
+
0,t.textContext,r,t.yOffset,s,l),ft(t,"front"),o.showCursor&&!e.isSelection()&&!a&&o.isFocused&&!o.readOnly){const I=e.getCursorPosition(),y=I?q(c,I.block):null,g=y?c.fragments.some(b=>{if(b.blockIndex!==
|
|
97
|
+
y.blockIndex)return!1;const{bounds:S}=b;return S.y+S.height>=s&&S.y<=l}):!1;I&&g&&(Pt(t.ctx,I,i,t.textContext,r,!1,t.yOffset,void 0,t.syntaxTheme),M=!0)}if(o.dropPreview&&Ft(t.ctx,r,c,o.dropPreview,t.
|
|
98
|
+
yOffset??0,s,l),o.printPreview||Dt(t,i,c,{startY:s,endY:l,yOffset:t.yOffset??0},o.activeSuggestionIds),!a){const I=e.getDocumentSession().getYDoc(),y=I?I.__awareness:null;if(y&&I){const g=[...St(y,I,i),
|
|
99
|
+
...Mt(I,Date.now())];Ct(t.ctx,g,i,t.textContext,r,t.yOffset,o.mousePosition)}}return t.ctx.restore(),{renderedDocumentContent:w,renderedCursor:M}}function We(t,e,n,o){const i=o.diffDocument??e.getDocument(),
|
|
100
|
+
a=!!o.diffDocument,s=t.layout,l=t.startY??t.pageGeometry?.pageTop??0,r=l,c=t.endY??l+(t.pageGeometry?.pageHeight??s.pageHeight),d=A(i,t.textContext,s),f=o.selectionRange?[o.selectionRange.start,o.selectionRange.
|
|
101
|
+
end]:null,h=f??(!a&&e.isSelection()?e.getSelectionRange():null),u=!!h&&!!Q(i,h[0]?.block??"")||!!h&&!!o.keepSelectionOnBlur,m=u&&!o.isFocused,x=!!h&&(f!==null||o.isFocused||o.isSelectionInactive||u),p=!!h&&
|
|
102
|
+
(o.isFocused||o.isSelectionInactive),k=!a&&h&&h.length===2?J(d,h[0],h[1]):null;t.ctx.save(),$t(t),Et(t.ctx,d,t.theme,{pageIndex:n,yOffset:l}),Ye(t.ctx,i,s,t.theme,t.textContext,o.cursorPosition,n,t.pageGeometry),
|
|
103
|
+
o.selectionUnderText&&h&&x&&(t.ctx.save(),t.ctx.fillStyle=t.theme.selection,t.ctx.globalAlpha=t.theme.selectionOpacity,F(t.ctx,i,h[0],h[1],t.textContext,s,t.yOffset,t.startY,t.endY),t.ctx.restore()),a&&
|
|
104
|
+
(t.diffSegments=o.diffSegments);const v=B(),w=j(d,r,c),M=w.length>0;let T=!1;const I=[];w.forEach(y=>{const{block:g,bounds:b}=y,S=v.getHandlerForBlock(g);if(!S){console.warn(`No handler for block type\
|
|
105
|
+
: ${g.type}`);return}const P={...b,y:b.y-l,relativeToPage:!0};t.currentParagraphIndex=g.type==="paragraph"?y.blockIndex:void 0;const O=_(y),R=y.blockIndex,$=Yt(R,k);let C;const D=y.data;D?.type==="tab\
|
|
106
|
+
le-cell"&&D?.parentTableId&&It(D.parentTableId,d,k)&&(C={top:D.isTopRow,bottom:D.isBottomRow,left:D.isLeftCol,right:D.isRightCol});const L={isSelected:$,isFocused:o.isFocused,showCursor:o.showCursor,isReadOnly:o.
|
|
107
|
+
readOnly,printPreview:o.printPreview,forceImagePlaceholders:o.forceImagePlaceholders,theme:t.theme,syntaxTheme:t.syntaxTheme,doc:i,renderCtx:t,fragment:O,hoveredUIComponentKey:o.hoveredUIComponentKey,
|
|
108
|
+
activeUIComponentKey:o.activeUIComponentKey,tableSelectionEdges:C,cursorPosition:o.cursorPosition,activeSuggestionIds:o.activeSuggestionIds,selection:h?{start:h[0],end:h[1]}:void 0,annotations:o.annotations,
|
|
109
|
+
hoveredTableId:o.hoveredTableId,focusedTableId:o.focusedTableId,selectedCellIds:o.selectedCellIds},rt=yt(s,b);S.render(t.ctx,g,P,rt,L),typeof S.renderOverlay=="function"&&I.push({handler:S,block:g,bounds:P,
|
|
110
|
+
layout:rt,options:L}),typeof localStorage<"u"&&localStorage.getItem("DEBUG_MODE")&&(t.ctx.font="10px monospace",t.ctx.fillText(`${g.type} ${g.id}`,P.x-40,P.y)),typeof localStorage<"u"&&localStorage.getItem(
|
|
111
|
+
"DEBUG_MODE")&&(t.ctx.save(),t.ctx.strokeStyle="red",t.ctx.lineWidth=1,t.ctx.setLineDash([2,2]),t.ctx.strokeRect(P.x,P.y,P.width,P.height),t.ctx.restore())});for(const y of I)y.handler.renderOverlay(t.
|
|
112
|
+
ctx,y.block,y.bounds,y.layout,y.options);if(!a){if(o.pendingSelectionData&&o.pendingSelectionData.length>0){t.ctx.save(),t.ctx.fillStyle=t.theme.inactiveSelection,t.ctx.globalAlpha=t.theme.inactiveSelectionOpacity;
|
|
113
|
+
for(const y of o.pendingSelectionData){const g={block:y.startBlock,offset:y.startOffset},b={block:y.endBlock,offset:y.endOffset};p&&h&&Bt(i,g,b,h[0],h[1])||F(t.ctx,i,g,b,t.textContext,s,t.yOffset,t.startY,
|
|
114
|
+
t.endY)}t.ctx.restore()}if(h&&x&&!o.selectionUnderText){const[y,g]=h;t.ctx.save(),o.isSelectionInactive||m?(t.ctx.fillStyle=t.theme.inactiveSelection,t.ctx.globalAlpha=t.theme.inactiveSelectionOpacity):
|
|
115
|
+
(t.ctx.fillStyle=t.theme.selection,t.ctx.globalAlpha=t.theme.selectionOpacity),F(t.ctx,i,y,g,t.textContext,s,t.yOffset,t.startY,t.endY),t.ctx.restore()}}if(o.searchMatches&&o.searchMatches.length>0&&Rt(
|
|
116
|
+
t.ctx,i,o.searchMatches,o.currentSearchMatchIndex??0,t.textContext,s,t.yOffset,t.startY,t.endY),o.printPreview||Dt(t,i,d,{startY:r,endY:c,yOffset:l},o.activeSuggestionIds),ft(t,"front"),!e.isSelection()&&
|
|
117
|
+
!a&&o.isFocused&&!o.readOnly){const y=e.getCursorPosition();if(y){const g=q(d,y.block),b=g?.block,S=b?v.getHandlerForBlock(b):null;g&&b&&S&&d.fragments.filter(P=>P.blockIndex===g.blockIndex).find(P=>{
|
|
118
|
+
const{bounds:O}=P;return O.y+O.height>=r&&O.y<=c})&&(o.showCursor&&(Pt(t.ctx,y,i,t.textContext,s,!1,t.yOffset,void 0,t.syntaxTheme),T=!0),typeof localStorage<"u"&&localStorage.getItem("DEBUG_MODE")&&(t.
|
|
119
|
+
ctx.font="10px monospace",t.ctx.fillText(`Cursor: ${y.block} ${y.offset}`,20,20)))}}if(o.dropPreview&&Ft(t.ctx,s,d,o.dropPreview,t.yOffset??0,r,c),!a){const y=e.getDocumentSession().getYDoc(),g=y?y.__awareness:
|
|
120
|
+
null;if(g&&y){let b=[];try{b=[...St(g,y,i),...Mt(y,Date.now())]}catch{}b.length>0&&Ct(t.ctx,b,i,t.textContext,s,t.yOffset,o.mousePosition)}}return t.ctx.restore(),{renderedDocumentContent:M,renderedCursor:T}}
|
|
121
|
+
function Ft(t,e,n,o,i,a,s){const l=n.blocks;let r;if(l.length===0)r=e.textStartY;else if(o.insertIndex<=0)r=l[0].bounds.y;else if(o.insertIndex>=l.length){const h=l[l.length-1];r=h.bounds.y+h.bounds.height}else
|
|
122
|
+
r=l[o.insertIndex].bounds.y;if(r<a||r>s)return;const c=r-i,d=z(e),f=d+e.availableWidth;t.save(),t.strokeStyle="#2563eb",t.lineWidth=3,t.beginPath(),t.moveTo(d,c),t.lineTo(f,c),t.stroke(),t.restore()}function Yt(t,e){
|
|
123
|
+
return e?nt(t,e):!1}function V(t,e,n,o){if(Array.isArray(t)){for(const s of t)V(s,e,n,o);return}if(!t||typeof t!="object")return;const i=t,a=typeof i.id=="string"?i.id:e;i.type==="math"&&typeof i.content==
|
|
124
|
+
"string"&&n.push({content:i.content,displayMode:i.displayMode!=="inline",blockId:a}),i.type==="text"&&typeof i.text=="string"&&i.marks?.latex&&n.push({content:i.text,displayMode:!1,blockId:a}),i.type===
|
|
125
|
+
"image"&&typeof i.src=="string"&&o.push({src:i.src,blockId:a,permanentlyPlaceholder:i.originalFormat==="emf"||i.originalFormat==="wmf"});for(const s of Object.values(i))if(Array.isArray(s))for(const l of s)
|
|
126
|
+
V(l,a,n,o);else s&&typeof s=="object"&&V(s,a,n,o)}function Lt(){return new Promise(t=>{let e=!1;const n=()=>{e||(e=!0,clearTimeout(o),t())},o=setTimeout(n,50);typeof requestAnimationFrame=="function"&&
|
|
127
|
+
requestAnimationFrame(n)})}async function He(t,e){if(t.length===0)return;const n=Promise.allSettled(t.map(o=>de(o.content,o.displayMode,e)));await Promise.race([n,new Promise(o=>setTimeout(o,2500))]),
|
|
128
|
+
await Lt(),await Lt()}function Wt(t,e){if(typeof t.pageNumber=="number")return t.pageNumber-1;const n=t.bounds.y;return e.pageGeometries?.find(o=>n>=o.pageTop&&n<o.pageTop+o.pageHeight)?.pageIndex??0}
|
|
129
|
+
function Ne(t,e){return new Set(t.fragments.filter(n=>e.has(Wt(n,t))).map(n=>n.blockId))}function Ue(t){return t==="table"?"#7c3aed":t==="table-cell"||t==="table-row"?"#db2777":t==="image"?"#ea580c":t===
|
|
130
|
+
"container"?"#2563eb":t==="math"?"#ca8a04":"#0891b2"}function Ht(t,e,n){t.save(),t.lineWidth=.75,t.setLineDash([4,3]),t.strokeStyle="rgba(22, 163, 74, 0.9)",t.strokeRect(n.marginLeft,n.marginTop,n.pageWidth-
|
|
131
|
+
n.marginLeft-n.marginRight,n.pageHeight-n.marginTop-n.marginBottom),t.setLineDash([]);const o=new Set;for(const i of e.fragments){if(Wt(i,e)!==n.pageIndex)continue;const{bounds:a}=i,s=a.relativeToPage?
|
|
132
|
+
a.y:a.y-n.pageTop,l=`${i.blockId}:${Math.round(a.x)}:${Math.round(s)}:${Math.round(a.width)}:${Math.round(a.height)}`;if(o.has(l)||a.width<=0||a.height<=0)continue;o.add(l);const r=Ue(i.block.type);if(t.
|
|
133
|
+
strokeStyle=r,t.globalAlpha=.82,t.strokeRect(a.x,s,a.width,a.height),(i.block.type==="table"||i.block.type==="table-cell"||i.block.type==="image"||i.block.type==="container"||i.block.type==="math")&&a.
|
|
134
|
+
width>=42&&a.height>=12){const c=`${i.block.type} #${i.blockId}`;t.font="10px ui-monospace, SFMono-Regular, Menlo, monospace",t.textAlign="left",t.textBaseline="top";const d=Math.min(a.width,t.measureText(
|
|
135
|
+
c).width+5);t.globalAlpha=.88,t.fillStyle=r,t.fillRect(a.x,Math.max(0,s),d,13),t.globalAlpha=1,t.fillStyle="#ffffff",t.fillText(c,a.x+2,Math.max(0,s)+1,Math.max(1,d-4))}}t.restore()}function Ge(t,e){return{
|
|
136
|
+
pageIndex:0,sectionIndex:0,pageTop:0,pageWidth:t.pageWidth,pageHeight:Math.min(4096,Math.max(t.pageHeight,e.totalHeight)),marginTop:t.pageMarginTop??t.pageMargin,marginRight:t.pageMarginRight??t.pageMargin,
|
|
137
|
+
marginBottom:t.pageMarginBottom??t.pageMargin,marginLeft:t.pageMarginLeft??t.pageMargin,showPageNumbers:!1,pageNumberPosition:"bottom-right",renderedPageNumber:1}}const Nt=new WeakMap;let Ut=0;function je(t){
|
|
138
|
+
let e=Nt.get(t);return e||(Ut+=1,e=`session-${Ut}`,Nt.set(t,e)),e}const Gt=new WeakMap;let jt=0;function _e(t){let e=Gt.get(t);return e===void 0&&(jt+=1,e=jt,Gt.set(t,e)),e}function _t(t){let e=2166136261;
|
|
139
|
+
for(const n of t.join("\0"))e^=n.codePointAt(0),e=Math.imul(e,16777619)>>>0;return e.toString(36)}function qe(t){const e=t.getDocumentSession?.();if(!e)throw new G("document_unavailable","Rendered pag\
|
|
140
|
+
e inspection needs a loaded document. Wait for the document to open, then retry.","verification",!1);return e}function qt(t){const e=t.getDetachedSuggestionStore?.();return{liveIds:[...t.getDocumentMutator().
|
|
141
|
+
getLiveSuggestionIds()].sort(),legacyIds:e?[...e.getPendingSuggestions().keys()].sort():[]}}function ze(t,e){return e!==Z?"live-pending-suggestion-projection":t.isHistoryOpen()?"displayed-history-revi\
|
|
142
|
+
sion":"displayed-document"}function Y(t,e){return`${t} ${e}${t===1?"":"s"}`}function Ke(t,e,n,o){const i=o.liveIds.length,a=o.legacyIds.length,s=Y(a,"legacy detached suggestion");if(t==="displayed-his\
|
|
143
|
+
tory-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(t==="displaye\
|
|
144
|
+
d-document"){const d=`The document as the editor displays it, with ${Y(i,"pending suggestion")} drawn as tracked changes.`;return a>0?`${d} ${s} ${a===1?"is":"are"} pending outside the document and no\
|
|
145
|
+
t drawn; show-with-tracked-changes-accepted previews them.`:d}const l=n?"The live document, not the past revision the history view displays,":"The live document",r=n?"":"; this view equals show-tracke\
|
|
146
|
+
d-changes",c="in a private preview; nothing was resolved in the document.";if(e==="show-with-tracked-changes-accepted")return i>0?`${l} with all ${Y(i,"pending suggestion")} accepted ${c}`:a>0?`${l} w\
|
|
147
|
+
ith all ${s} applied ${c}`:`${l} has no pending suggestions to accept${r}.`;if(i>0){const d=a>0?` ${s} stored outside the document ${a===1?"is":"are"} absent here as well.`:"";return`${l} with all ${Y(
|
|
148
|
+
i,"pending suggestion")} rejected ${c}${d}`}return a>0?`${l} as it stands: its ${s} ${a===1?"is":"are"} stored outside the document, so there is nothing to reject${r}.`:`${l} has no pending suggestion\
|
|
149
|
+
s to reject${r}.`}function zt(t,e,n){const o=t.getDocumentId(),i=je(t),a=t.getDocumentMutator().derivedDocumentRevision,s=t.isHistoryOpen(),l=ze(t,e),r=n.liveIds.length,c=n.legacyIds.length,d=e==="sho\
|
|
150
|
+
w-with-tracked-changes-accepted"?r>0?r:c:e==="show-before-tracked-changes"?r:0,f=l==="displayed-history-revision"?[`h${_e(t.getCurrentDocument())}`]:[`r${a}`,`s${r}.${_t(n.liveIds)}`,...c>0?[`l${c}.${_t(
|
|
151
|
+
n.legacyIds)}`]:[]],h=l==="displayed-history-revision"?{...t.getSelection(),diffEnabled:t.isDiffEnabled()}:void 0;return{documentId:o,sessionId:i,basis:l,historyOpen:s,revision:a,pendingSuggestionCount:r+
|
|
152
|
+
c,legacyDetachedSuggestionCount:c,projectedSuggestionCount:d,...h?{historySelection:h}:{},description:Ke(l,e,s,n),key:[o,i,l,...f,e].join(":")}}function Je(t,e=Z){return zt(t,e,qt(t)).key}function Kt(t,e){
|
|
153
|
+
const n=qe(t),o=qt(n),i=o.liveIds.length,a=o.legacyIds.length;if(e==="show-with-tracked-changes-accepted"&&i>0&&a>0)throw new G("render_view_unsupported",`This document has ${Y(i,"pending suggestion")}\
|
|
154
|
+
plus ${Y(a,"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 rea\
|
|
155
|
+
d tool.`,"verification",!1);const s=zt(n,e,o);if(s.basis==="displayed-history-revision")return{doc:{...t.getDocument()},snapshot:s};if(e==="show-with-tracked-changes-accepted"&&i===0&&a>0){const r=n.getDetachedSuggestionStore().
|
|
156
|
+
materializeWithSuggestions(o.legacyIds);try{return{doc:dt(r),snapshot:s}}finally{r.destroy()}}const l=new E.Doc;try{if(E.applyUpdate(l,E.encodeStateAsUpdate(n.getYDoc())),s.projectedSuggestionCount===
|
|
157
|
+
0)return{doc:dt(l),snapshot:s};const r=Xt.createSuggestionProjectionFromYDoc(l,e==="show-with-tracked-changes-accepted"?"accept":"reject",o.liveIds);try{return{doc:r.doc,snapshot:s}}finally{r.ydoc.destroy()}}finally{
|
|
158
|
+
l.destroy()}}function Xe(t){const e=t.createCanvas?.()??document.createElement("canvas");e.width=Math.ceil(t.geometry.pageWidth),e.height=Math.ceil(t.geometry.pageHeight);const n=e.getContext("2d");if(!n)
|
|
159
|
+
throw new Error("The browser could not create a page canvas.");const o=et(t.themeElement);n.fillStyle=o.pageBackground,n.fillRect(0,0,e.width,e.height);const i=ut(n),a=te(n,e,t.layout,i);a.theme=o,a.currentPage=
|
|
160
|
+
t.geometry.pageIndex,a.pageGeometry=t.geometry,a.yOffset=t.geometry.pageTop,a.startY=t.geometry.pageTop,a.endY=t.geometry.pageTop+t.geometry.pageHeight,a.pageLayoutSettings=t.pageLayoutSettings,a.headersContent=
|
|
161
|
+
t.doc.headers,a.footersContent=t.doc.footers,a.watermark=ge(t.doc.watermark),a.totalPages=t.computed.pageCount,a.lineNumberMarks=t.computed.lineNumberMarks,a.pageFontFamilies=he(t.computed,a.layout.fontFamily),
|
|
162
|
+
a.headingPageNumbers=ne(t.computed),a.syntaxTheme=fe(t.codeTheme||"solarized",o.isDark),ee(a,1);const s={diffDocument:t.doc,showCursor:!1,isFocused:!1,readOnly:!0,printPreview:!0,forceImagePlaceholders:t.
|
|
163
|
+
forceImagePlaceholders};if(t.pageless){const l={startY:0,endY:t.geometry.pageHeight};Le(a,t.editor,l,s)}else We(a,t.editor,t.geometry.pageIndex,s);return t.mode==="layout"&&Ht(n,t.computed,t.geometry),
|
|
164
|
+
e}function Ve(t,e,n,o){const i=n==="compact"?360:720,a=n==="compact"?Math.min(2,t.length):t.length,s=Math.ceil(t.length/a),l=16,r=16,c=26,d=t.map(x=>({width:i,height:Math.round(x.height/x.width*i)})),
|
|
165
|
+
f=Array.from({length:s},(x,p)=>Math.max(...d.slice(p*a,(p+1)*a).map(k=>k.height+c))),h=o?.()??document.createElement("canvas");h.width=r*2+a*i+Math.max(0,a-1)*l,h.height=r*2+f.reduce((x,p)=>x+p,0)+Math.
|
|
166
|
+
max(0,s-1)*l;const u=h.getContext("2d");if(!u)throw new Error("The browser could not create a page contact sheet.");u.fillStyle="#e5e7eb",u.fillRect(0,0,h.width,h.height),u.fillStyle="#111827",u.font=
|
|
167
|
+
"600 14px ui-sans-serif, system-ui, sans-serif",u.textBaseline="top";let m=r;for(let x=0;x<s;x+=1){for(let p=0;p<a;p+=1){const k=x*a+p;if(k>=t.length)break;const v=r+p*(i+l);u.fillText(`Page ${e[k]}`,
|
|
168
|
+
v,m+4),u.drawImage(t[k],v,m+c,d[k].width,d[k].height),u.strokeStyle="#9ca3af",u.strokeRect(v,m+c,d[k].width,d[k].height)}m+=f[x]+l}return h}function Qe(t){const e={block:"",offset:0};return{getDocument:()=>t.
|
|
169
|
+
getCurrentDocument(),getDocumentSession:()=>t,isSelection:()=>!1,getSelectionRange:()=>[e,e],getCursorPosition:()=>e}}async function Ze(t){const e=t.request.view??Z;if(!Qt(e))throw new G("invalid_view",
|
|
170
|
+
`Unknown render view "${String(e)}". Use show-tracked-changes, show-with-tracked-changes-accepted, or show-before-tracked-changes.`);const{doc:n,snapshot:o}=Kt(t.editor,e),i=et(t.themeElement),a=[],s=[];
|
|
171
|
+
V(n,null,a,s),await He(a,i.text);const l=t.createCanvas?.()??document.createElement("canvas");l.width=8,l.height=8;const r=l.getContext("2d");if(!r)throw new Error("The browser could not measure docum\
|
|
172
|
+
ent pages.");const c=ut(r),d=A(n,c,t.layout),f=d.pageGeometries?.length?d.pageGeometries:[Ge(t.layout,d)],h=f.length,u=t.request.startPage-1;if(u<0||u>=h)throw new Error(`start_page ${t.request.startPage}\
|
|
173
|
+
is outside this ${h}-page document in the ${e} view.`);const m=f.slice(u,Math.min(h,u+t.request.pageCount)),x=new Set(m.map(g=>g.pageIndex)),p=Ne(d,x),k=s.filter(g=>g.blockId===null||p.has(g.blockId)),
|
|
174
|
+
v=await Promise.all(k.map(g=>g.permanentlyPlaceholder?Promise.resolve("placeholder"):ht(g.src)));await Promise.all(m.flatMap(g=>g.chromeImages??[]).map(g=>ht(g.src)));const w=m.map(g=>Xe({editor:t.editor,
|
|
175
|
+
doc:n,layout:t.layout,computed:d,geometry:g,pageLayoutSettings:t.pageLayoutSettings,mode:t.request.mode,codeTheme:t.codeTheme,themeElement:t.themeElement,pageless:!!n.pageless,createCanvas:t.createCanvas})),
|
|
176
|
+
M=m.map(g=>g.pageIndex+1),T=Ve(w,M,t.request.quality,t.createCanvas);let I;try{I=T.toDataURL("image/jpeg",t.request.quality==="compact"?.78:.9)}catch(g){throw typeof g=="object"&&g!==null&&"name"in g&&
|
|
177
|
+
g.name==="SecurityError"?new G("visual_resource_unavailable","A document resource prevented safe page export. Re-upload external images and retry visual inspection.","verification",!1):g}const y=a.filter(
|
|
178
|
+
g=>g.blockId===null||p.has(g.blockId)).filter(g=>{const b=le(g.content,g.displayMode,i.text);return b.loading||!b.image}).length;return{dataUrl:I,width:T.width,height:T.height,pages:M,totalPages:h,placeholderImageCount:v.
|
|
179
|
+
filter(g=>g==="placeholder").length,failedImageCount:v.filter(g=>g==="failed").length,mathPlaceholderCount:y,view:e,snapshot:o}}export{Kt as captureAgentPageRenderSource,Qe as createHeadlessPageRenderHost,
|
|
180
|
+
Je as getAgentPageRenderSnapshotKey,Ht as paintPageLayoutDiagnostics,Ze as renderDocumentPagesForAgent};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import{r as _a,e as hn,d as gn}from"./MathRenderer-Bz9WEVvF.js";const Ia={js:"javascript",jsx:"javascript",mjs:"javascript",cjs:"javascript",ts:"typescript",tsx:"tsx",mts:"typescript",cts:"typescript",
|
|
2
|
+
py:"python",python3:"python",py3:"python","c++":"cpp",cxx:"cpp",cc:"cpp",hpp:"cpp",h:"c",cs:"c_sharp",csharp:"c_sharp","c#":"c_sharp",golang:"go",rs:"rust",rb:"ruby",sh:"bash",shell:"bash",zsh:"bash",
|
|
3
|
+
htm:"html",yml:"yaml",kt:"kotlin",kts:"kotlin",ex:"elixir",exs:"elixir",sol:"solidity",ml:"ocaml",mli:"ocaml",plaintext:"text",plain:"text",txt:"text"},pn=new Set(["javascript","typescript","tsx","pyt\
|
|
4
|
+
hon","java","c","cpp","c_sharp","go","rust","ruby","php","swift","kotlin","scala","bash","css","html","json","yaml","toml","lua","elixir","dart","vue","zig","elm","solidity","ocaml"]);function Ge(e){const t=e.
|
|
5
|
+
toLowerCase().trim();if(Ia[t]){const n=Ia[t];return n==="text"?null:n}return pn.has(t)?t:null}const zt={keyword:"#0000FF",string:"#A31515",number:"#098658",comment:"#008000",function:"#795E26",variable:"\
|
|
6
|
+
#001080",operator:"#000000",punctuation:"#000000",type:"#267F99",property:"#001080",constant:"#0070C1",default:"#000000",background:"#ffffff",text:"#000000"},mn={keyword:"#859900",string:"#2aa198",number:"\
|
|
7
|
+
#d33682",comment:"#93a1a1",function:"#268bd2",variable:"#657b83",operator:"#657b83",punctuation:"#586e75",type:"#b58900",property:"#268bd2",constant:"#cb4b16",default:"#657b83",background:"#fdf6e3",text:"\
|
|
8
|
+
#657b83"},Ea={keyword:"#859900",string:"#2aa198",number:"#d33682",comment:"#586e75",function:"#268bd2",variable:"#839496",operator:"#839496",punctuation:"#93a1a1",type:"#b58900",property:"#268bd2",constant:"\
|
|
9
|
+
#cb4b16",default:"#839496",background:"#002b36",text:"#839496"},bn={keyword:"#ff79c6",string:"#f1fa8c",number:"#bd93f9",comment:"#6272a4",function:"#50fa7b",variable:"#f8f8f2",operator:"#ff79c6",punctuation:"\
|
|
10
|
+
#f8f8f2",type:"#8be9fd",property:"#66d9ef",constant:"#bd93f9",default:"#f8f8f2",background:"#282a36",text:"#f8f8f2"},vn={keyword:"#c678dd",string:"#98c379",number:"#d19a66",comment:"#5c6370",function:"\
|
|
11
|
+
#61afef",variable:"#e06c75",operator:"#56b6c2",punctuation:"#abb2bf",type:"#e5c07b",property:"#e06c75",constant:"#d19a66",default:"#abb2bf",background:"#282c34",text:"#abb2bf"},yn={keyword:"#81a1c1",string:"\
|
|
12
|
+
#a3be8c",number:"#b48ead",comment:"#4c566a",function:"#88c0d0",variable:"#d8dee9",operator:"#81a1c1",punctuation:"#eceff4",type:"#8fbcbb",property:"#88c0d0",constant:"#ebcb8b",default:"#d8dee9",background:"\
|
|
13
|
+
#2e3440",text:"#d8dee9"},kn={keyword:"#d73a49",string:"#032f62",number:"#005cc5",comment:"#6a737d",function:"#6f42c1",variable:"#24292e",operator:"#d73a49",punctuation:"#24292e",type:"#6f42c1",property:"\
|
|
14
|
+
#005cc5",constant:"#005cc5",default:"#24292e",background:"#fbfbfb",text:"#24292e"},La={keyword:"#ff7b72",string:"#a5d6ff",number:"#79c0ff",comment:"#8b949e",function:"#d2a8ff",variable:"#c9d1d9",operator:"\
|
|
15
|
+
#ff7b72",punctuation:"#c9d1d9",type:"#d2a8ff",property:"#79c0ff",constant:"#79c0ff",default:"#c9d1d9",background:"#0d1117",text:"#c9d1d9"},wn={keyword:"#f92672",string:"#e6db74",number:"#ae81ff",comment:"\
|
|
16
|
+
#75715e",function:"#a6e22e",variable:"#f8f8f2",operator:"#f92672",punctuation:"#f8f8f2",type:"#66d9ef",property:"#a6e22e",constant:"#ae81ff",default:"#f8f8f2",background:"#272822",text:"#f8f8f2"},Oa={
|
|
17
|
+
keyword:"#c792ea",string:"#ecc48d",number:"#f78c6c",comment:"#637777",function:"#82aaff",variable:"#d6deeb",operator:"#c792ea",punctuation:"#d6deeb",type:"#ffcb8b",property:"#7fdbca",constant:"#f78c6c",
|
|
18
|
+
default:"#d6deeb",background:"#011627",text:"#d6deeb"},xn={keyword:"#994cc3",string:"#c96765",number:"#aa0982",comment:"#989fb1",function:"#4876d6",variable:"#403f53",operator:"#994cc3",punctuation:"#\
|
|
19
|
+
403f53",type:"#994cc3",property:"#0c969b",constant:"#aa0982",default:"#403f53",background:"#fbfbfb",text:"#403f53"},jn={keyword:"#fa8d3e",string:"#86b300",number:"#a37acc",comment:"#abb0b6",function:"\
|
|
20
|
+
#f2ae49",variable:"#5c6166",operator:"#ed9366",punctuation:"#5c6166",type:"#399ee6",property:"#55b4d4",constant:"#a37acc",default:"#5c6166",background:"#fbfbfb",text:"#5c6166"},Sa={keyword:"#ff8f40",string:"\
|
|
21
|
+
#aad94c",number:"#d2a6ff",comment:"#acb6bf",function:"#ffb454",variable:"#bfbdb6",operator:"#f29668",punctuation:"#bfbdb6",type:"#59c2ff",property:"#73d0ff",constant:"#d2a6ff",default:"#bfbdb6",background:"\
|
|
22
|
+
#0b0e14",text:"#bfbdb6"},Mn={keyword:"#fede5d",string:"#ff8b39",number:"#f97e72",comment:"#848bbd",function:"#36f9f6",variable:"#ff7edb",operator:"#fede5d",punctuation:"#ffffff",type:"#fe4450",property:"\
|
|
23
|
+
#72f1b8",constant:"#f97e72",default:"#ffffff",background:"#262335",text:"#ffffff"},Ra={keyword:"#fb4934",string:"#b8bb26",number:"#d3869b",comment:"#928374",function:"#fabd2f",variable:"#ebdbb2",operator:"\
|
|
24
|
+
#fe8019",punctuation:"#ebdbb2",type:"#83a598",property:"#8ec07c",constant:"#d3869b",default:"#ebdbb2",background:"#282828",text:"#ebdbb2"},_n={keyword:"#9d0006",string:"#79740e",number:"#8f3f71",comment:"\
|
|
25
|
+
#928374",function:"#b57614",variable:"#3c3836",operator:"#af3a03",punctuation:"#3c3836",type:"#076678",property:"#427b58",constant:"#8f3f71",default:"#3c3836",background:"#fbf1c7",text:"#3c3836"},In={
|
|
26
|
+
keyword:"#bb9af7",string:"#9ece6a",number:"#ff9e64",comment:"#565f89",function:"#7aa2f7",variable:"#c0caf5",operator:"#89ddff",punctuation:"#c0caf5",type:"#2ac3de",property:"#73daca",constant:"#ff9e64",
|
|
27
|
+
default:"#c0caf5",background:"#1a1b26",text:"#c0caf5"},En={keyword:"#cba6f7",string:"#a6e3a1",number:"#fab387",comment:"#6c7086",function:"#89b4fa",variable:"#cdd6f4",operator:"#89dceb",punctuation:"#\
|
|
28
|
+
cdd6f4",type:"#f9e2af",property:"#94e2d5",constant:"#fab387",default:"#cdd6f4",background:"#1e1e2e",text:"#cdd6f4"},Ln=[{id:"solarized",name:"Solarized (adaptive)",darkOnly:!1,light:mn,dark:Ea},{id:"s\
|
|
29
|
+
olarized-dark",name:"Solarized (dark)",darkOnly:!0,dark:Ea},{id:"github",name:"GitHub (adaptive)",darkOnly:!1,light:kn,dark:La},{id:"github-dark",name:"GitHub (dark)",darkOnly:!0,dark:La},{id:"night-o\
|
|
30
|
+
wl",name:"Night Owl (adaptive)",darkOnly:!1,light:xn,dark:Oa},{id:"night-owl-dark",name:"Night Owl (dark)",darkOnly:!0,dark:Oa},{id:"ayu",name:"Ayu (adaptive)",darkOnly:!1,light:jn,dark:Sa},{id:"ayu-d\
|
|
31
|
+
ark",name:"Ayu (dark)",darkOnly:!0,dark:Sa},{id:"gruvbox",name:"Gruvbox (adaptive)",darkOnly:!1,light:_n,dark:Ra},{id:"gruvbox-dark",name:"Gruvbox (dark)",darkOnly:!0,dark:Ra},{id:"one-dark",name:"One\
|
|
32
|
+
Dark Pro",darkOnly:!0,dark:vn},{id:"dracula",name:"Dracula",darkOnly:!0,dark:bn},{id:"nord",name:"Nord",darkOnly:!0,dark:yn},{id:"monokai",name:"Monokai",darkOnly:!0,dark:wn},{id:"synthwave",name:"Sy\
|
|
33
|
+
nthWave '84",darkOnly:!0,dark:Mn},{id:"tokyo-night",name:"Tokyo Night",darkOnly:!0,dark:In},{id:"catppuccin",name:"Catppuccin Mocha",darkOnly:!0,dark:En}],On="solarized";function qa(e){return Ln.find(
|
|
34
|
+
t=>t.id===e)}function Sn(e,t){const n=qa(e);if(!n){const a=qa(On);return t?a.dark:a.light}return n.darkOnly||t?n.dark:n.light}let ye=null,Je=new Map,Qe=new Map,ke=new Set,Ba=!1;function Rn(e){return typeof e==
|
|
35
|
+
"object"&&e!==null&&"status"in e&&e.status===404?!0:(e instanceof Error?e.message:typeof e=="string"?e:"").includes("status 404")}function qn(e){let t=5381;for(let n=0;n<e.length;n++)t=(t<<5)+t^e.charCodeAt(
|
|
36
|
+
n);return(t>>>0).toString(36)}function Bn(e,t){return["const","let","var","function","return","if","else","for","while","do","switch","case","break","continue","try","catch","finally","throw","new","d\
|
|
37
|
+
elete","typeof","instanceof","void","in","of","class","extends","static","get","set","async","await","yield","import","export","from","as","default","this","super"].includes(e)?"keyword":["string","te\
|
|
38
|
+
mplate_string","string_fragment","template_literal"].includes(e)?"string":["number","integer","float"].includes(e)?"number":["comment","line_comment","block_comment"].includes(e)?"comment":e==="identi\
|
|
39
|
+
fier"&&(t==="function_declaration"||t==="call_expression"||t==="method_definition")?"function":["type_identifier","predefined_type","type_annotation"].includes(e)?"type":e==="property_identifier"||t===
|
|
40
|
+
"member_expression"?"property":["true","false","null","undefined"].includes(e)?"constant":["+","-","*","/","%","=","==","===","!=","!==","<",">","<=",">=","&&","||","!","&","|","^","~","<<",">>",">>>",
|
|
41
|
+
"++","--","+=","-=","*=","/=","?",":","=>"].includes(e)?"operator":["(",")","{","}","[","]",";",",",".","..."].includes(e)?"punctuation":e==="identifier"?"variable":"default"}function Dt(){return typeof window>
|
|
42
|
+
"u"||globalThis.__reviseServerRuntime===!0}async function za(){if(ye)return ye;const e=(async()=>{const t=(await import("./web-tree-sitter-BXGZGnNj.js")).Parser;await t.init({locateFile:a=>_a(`tree-si\
|
|
43
|
+
tter/${a}`)});const n=new t;return Ba=!0,n})();return e.catch(()=>{ye===e&&(ye=null)}),ye=e,e}async function Da(e){if(Je.has(e))return Je.get(e);if(ke.has(e))return null;if(Qe.has(e))return Qe.get(e);
|
|
44
|
+
const t=(async()=>{try{const n=await(await import("./web-tree-sitter-BXGZGnNj.js")).Language.load(_a(`tree-sitter/tree-sitter-${e}.wasm`));return Je.set(e,n),n}catch(n){return Rn(n)?(ke.add(e),console.
|
|
45
|
+
warn(`Tree-sitter grammar not found for ${e} (404). Disabling syntax highlighting for this language.`),null):(console.warn(`Failed to load tree-sitter grammar for ${e}:`,n),null)}finally{Qe.delete(e)}})();
|
|
46
|
+
return Qe.set(e,t),t}function $a(e,t){if(e.childCount===0)t.push({start:e.startIndex,end:e.endIndex,type:e.type,parentType:e.parent?.type});else for(let n=0;n<e.childCount;n++)$a(e.child(n),t)}function zn(e="\
|
|
47
|
+
javascript"){const t=Ge(e);return t?Ba&&Je.has(t):!0}async function Dn(e="javascript"){if(Dt())return!1;const t=Ge(e);if(!t)return!0;if(ke.has(t))return!1;try{const n=await za(),a=await Da(t);return a?
|
|
48
|
+
(n.setLanguage(a),!0):!1}catch(n){return console.warn("Failed to preload syntax highlighter:",n),!1}}async function $t(e,t="javascript",n=zt){if(Dt())return null;const a=Ge(t);if(!a||ke.has(a))return null;
|
|
49
|
+
try{const o=await za(),i=await Da(a);if(!i)return null;o.setLanguage(i);const d=o.parse(e),f=[];$a(d.rootNode,f),f.sort((h,z)=>h.start-z.start);const p=[];let M=0;for(const h of f){if(h.start>M){const k=e.
|
|
50
|
+
slice(M,h.start);k&&p.push({text:k,color:n.default})}const z=e.slice(h.start,h.end);if(z){const k=Bn(h.type,h.parentType);p.push({text:z,color:n[k]})}M=h.end}return M<e.length&&p.push({text:e.slice(M),
|
|
51
|
+
color:n.default}),p}catch(o){return console.warn("Syntax highlighting failed:",o),null}}let ie=new Map;const $n=100;function Cn(e,t="javascript",n){if(Dt())return null;const a=Ge(t);if(!a||ke.has(a))return null;
|
|
52
|
+
const o=n||zt,i=o.keyword+o.string,d=`${a}:${i}:${qn(e)}`;if(ie.has(d))return ie.get(d);const f=(p,M)=>{if(ie.size>=$n){const h=ie.keys().next().value;h&&ie.delete(h)}ie.set(p,M)};return zn(a)?($t(e,a,
|
|
53
|
+
o).then(p=>{p&&f(d,p)}),null):($t(e,a,o).then(p=>{p&&(f(d,p),typeof window<"u"&&window.dispatchEvent(new CustomEvent("syntax-highlight-ready")))}),null)}const we=180,Ct=new Map,Ve=new Map,Ca=new Map,Fa=new Map,
|
|
54
|
+
Fn=new Set,G=new Map;let Ft=null,Aa=0;function V(e){return e.trim().toLowerCase()}function Ta(e){return[e.background,e.text,e.selection,e.pageBorder,e.pageBackground,e.codeBackground,e.codeBorder,e.codeText,
|
|
55
|
+
e.diffInsert,e.diffDelete].join("|")}function At(e){const t=V(e.protocol),n=Math.max(120,Math.round(e.maxWidth));return`${t}:${n}:${Ta(e.theme)}:${e.source}`}function He(e){const t=V(e.protocol),n=Math.
|
|
56
|
+
max(120,Math.round(e.maxWidth));return`${t}:${n}:${Ta(e.theme)}`}function Na(e){const t=He(e);return Ca.get(t)||{width:Math.max(120,Math.round(e.maxWidth)),height:we}}function Tt(e){return e.replace(/\s+/g,
|
|
57
|
+
" ").trim()}function An(e){if(e instanceof Error&&e.message)return Tt(e.message);if(typeof e=="string"&&e.trim())return Tt(e);if(e&&typeof e=="object"){const t=e,n=typeof t.message=="string"&&t.message||
|
|
58
|
+
typeof t.str=="string"&&t.str||"",a=typeof t.hash=="object"&&t.hash?t.hash:null,o=a&&typeof a.line=="number"&&Number.isFinite(a.line)?a.line+1:null,i=a&&typeof a.loc=="object"&&a.loc?a.loc:null,d=i&&typeof i.
|
|
59
|
+
first_column=="number"&&Number.isFinite(i.first_column)?i.first_column+1:null,f=o!==null?`Line ${o}${d!==null?`, col ${d}`:""}: `:"";if(n.trim())return`${f}${Tt(n)}`}return"Diagram render failed"}function Tn(e,t,n){
|
|
60
|
+
if(t<=0||n<=0||!Number.isFinite(t)||!Number.isFinite(n))return;const a=He(e);Ca.set(a,{width:Math.max(1,Math.round(t)),height:Math.max(1,Math.round(n))})}function Nn(e,t){if(!t.image||t.width<=0||t.height<=
|
|
61
|
+
0)return;const n=He(e);Fa.set(n,{image:t.image,svg:t.svg,width:Math.max(1,Math.round(t.width)),height:Math.max(1,Math.round(t.height))})}function Wn(){typeof window<"u"&&window.dispatchEvent(new CustomEvent(
|
|
62
|
+
"diagram-render-ready"));for(const e of Fn)try{e()}catch(t){console.error("diagram render callback failed:",t)}}function Pn(e){if(typeof DOMParser<"u")try{const n=new DOMParser().parseFromString(e,"im\
|
|
63
|
+
age/svg+xml").documentElement,a=n.getAttribute("viewBox");if(a){const d=a.split(/\s+/).map(f=>Number.parseFloat(f)).filter(f=>Number.isFinite(f));if(d.length===4&&d[2]>0&&d[3]>0)return{width:d[2],height:d[3]}}
|
|
64
|
+
const o=n.getAttribute("width"),i=n.getAttribute("height");if(o&&i){const d=Number.parseFloat(o),f=Number.parseFloat(i);if(Number.isFinite(d)&&Number.isFinite(f))return{width:d,height:f}}}catch{}const t=e.
|
|
65
|
+
match(/viewBox="([^"]+)"/i);if(t){const n=t[1].split(/\s+/).map(a=>Number.parseFloat(a)).filter(a=>Number.isFinite(a));if(n.length===4&&n[2]>0&&n[3]>0)return{width:n[2],height:n[3]}}return{width:800,height:we}}
|
|
66
|
+
function Un(e,t,n){if(e<=0||t<=0)return{width:n,height:we};if(e<=n)return{width:e,height:t};const a=n/e;return{width:n,height:Math.max(40,Math.round(t*a))}}async function Zn(e,t,n){const a="data:image\
|
|
67
|
+
/svg+xml;charset=utf-8,"+encodeURIComponent(e),o=new Image;return new Promise((i,d)=>{o.onload=()=>{i(o)},o.onerror=()=>{d(new Error("Failed to load rendered diagram SVG"))},o.src=a,o.width=Math.max(1,
|
|
68
|
+
Math.round(t)),o.height=Math.max(1,Math.round(n))})}function Xn(e){const t=Math.max(1,e.naturalWidth||e.width||1),n=Math.max(1,e.naturalHeight||e.height||1),a=document.createElement("canvas");a.width=
|
|
69
|
+
t,a.height=n;const o=a.getContext("2d");if(!o)throw new Error("Unable to create PNG export canvas");return o.drawImage(e,0,0,t,n),a.toDataURL("image/png")}async function Gn(){if(typeof window>"u")throw new Error(
|
|
70
|
+
"Mermaid runtime requires a browser environment");return window.mermaid?window.mermaid:(Ft||(Ft=new Promise((e,t)=>{const n=document.querySelector('script[data-revise-mermaid="true"]');if(n){n.addEventListener(
|
|
71
|
+
"load",()=>e(window.mermaid)),n.addEventListener("error",()=>t(new Error("Failed to load Mermaid script")));return}const a=document.createElement("script");a.src="https://cdn.jsdelivr.net/npm/mermaid@\
|
|
72
|
+
11/dist/mermaid.min.js",a.async=!0,a.defer=!0,a.setAttribute("data-revise-mermaid","true"),a.onload=()=>e(window.mermaid),a.onerror=()=>t(new Error("Failed to load Mermaid script")),document.head.appendChild(
|
|
73
|
+
a)})),Ft)}function Jn(e){return{background:e.pageBackground,primaryColor:e.codeBackground,primaryBorderColor:e.codeBorder,primaryTextColor:e.codeText,secondaryColor:e.background,secondaryBorderColor:e.
|
|
74
|
+
pageBorder,tertiaryColor:e.background,tertiaryBorderColor:e.pageBorder,lineColor:e.text,arrowheadColor:e.text,defaultLinkColor:e.text,textColor:e.text,edgeLabelBackground:e.pageBackground,clusterBkg:e.
|
|
75
|
+
codeBackground,clusterBorder:e.pageBorder,nodeBorder:e.codeBorder,fontFamily:"Arial, sans-serif",cScale0:e.codeBackground,cScale1:e.background,cScale2:e.pageBackground,cScaleLabel0:e.text,cScaleLabel1:e.
|
|
76
|
+
text,cScaleLabel2:e.text}}function Wa(e){if(typeof document>"u")return;const t=document.getElementById(e);t?.parentElement&&t.parentElement.removeChild(t)}const Qn={protocol:"mermaid",renderToSvg:async(e,t)=>{
|
|
77
|
+
const n=await Gn();if(!n)throw new Error("Mermaid runtime unavailable");n.initialize({startOnLoad:!1,securityLevel:"strict",suppressErrorRendering:!0,theme:"base",themeVariables:Jn(t)}),Aa+=1;const a=`\
|
|
78
|
+
revise-mermaid-${Aa}`;Wa(a);let o;try{o=await n.render(a,e)}finally{Wa(a)}const i=typeof o=="string"?o:o?.svg;if(!i||typeof i!="string")throw new Error("Mermaid returned invalid SVG output");const d=Pn(
|
|
79
|
+
i);return{svg:i,width:d.width,height:d.height}}};function Pa(e,t){return{protocol:e,renderToSvg:async(n,a)=>{const o=n.trim();if(!o)throw new Error("LaTeX source is empty");await hn(o,t,a.text);const i=gn(
|
|
80
|
+
o,t,a.text);if(!i?.svg)throw new Error("LaTeX render unavailable");return{svg:i.svg,width:i.width,height:i.height}}}}function Ua(){G.has("mermaid")||G.set("mermaid",Qn),G.has("latex")||G.set("latex",Pa(
|
|
81
|
+
"latex",!0)),G.has("latex-inline")||G.set("latex-inline",Pa("latex-inline",!1))}async function Vn(e){Ua();const t=V(e.protocol),n=G.get(t);if(!n)return{image:null,width:e.maxWidth,height:we,loading:!1,
|
|
82
|
+
error:`Unsupported diagram protocol: ${e.protocol}`};try{const{svg:a,width:o,height:i}=await n.renderToSvg(e.source,e.theme),d=Un(o,i,e.maxWidth);Tn(e,d.width,d.height);const f={image:await Zn(a,d.width,
|
|
83
|
+
d.height),svg:a,width:d.width,height:d.height,loading:!1};return Nn(e,f),f}catch(a){const o=Na(e);return{image:null,width:o.width,height:o.height,loading:!1,error:An(a)}}}function Za(e){if(!e)return null;
|
|
84
|
+
Ua();const t=V(e);return G.has(t)?t:null}function Nt(e){const t=V(e.protocol);if(!t||!e.source.trim())return{image:null,width:e.maxWidth,height:we,loading:!1,error:"Diagram source is empty"};const n={
|
|
85
|
+
...e,protocol:t,source:e.source},a=At(n),o=Ct.get(a);if(o)return o;if(!Ve.has(a)){const p=Vn(n).then(M=>(Ct.set(a,M),Ve.delete(a),Wn(),M));Ve.set(a,p)}const i=He(n),d=Fa.get(i);if(d)return{image:d.image,
|
|
86
|
+
svg:d.svg,width:d.width,height:d.height,loading:!0};const f=Na(n);return{image:null,width:f.width,height:f.height,loading:!0}}async function Xa(e){const t=Nt(e);if(!t.loading)return t;const n=At({...e,
|
|
87
|
+
protocol:V(e.protocol)});return Ve.get(n)||Nt(e)}function Ga(e){const t=At({...e,protocol:V(e.protocol)}),n=Ct.get(t);return!n||n.loading?null:n}function Hn(e){const t=Ga(e);return!t||!t.svg?null:{svg:t.
|
|
88
|
+
svg,width:t.width,height:t.height}}function Yn(e){if(typeof document>"u")return null;const t=Ga(e);if(!t||!t.image)return null;try{return{dataUrl:Xn(t.image),width:t.width,height:t.height}}catch{return null}}
|
|
89
|
+
async function Kn(e,t,n){const a=[],o=i=>{if(!(!i||typeof i!="object")){if(i.type==="code"){const d=Za(i.language);d&&i.renderDiagram!==!1&&i.content?.trim()&&a.push({protocol:d,source:i.content,theme:t,
|
|
90
|
+
maxWidth:n});return}if(i.type==="container"||i.type==="table-cell"){for(const d of i.children||[])o(d);return}if(i.type==="table")for(const d of i.children||[])for(const f of d.children||[])for(const p of f.
|
|
91
|
+
children||[])o(p)}};for(const i of e.children)o(i);a.length!==0&&await Promise.all(a.map(i=>Xa(i)))}function er(){var e=function(t){var n={R:"13k,1a,2,3,3,2+1j,ch+16,a+1,5+2,2+n,5,a,4,6+16,4+3,h+1b,4m\
|
|
92
|
+
o,179q,2+9,2+11,2i9+7y,2+68,4,3+4,5+13,4+3,2+4k,3+29,8+cf,1t+7z,w+17,3+3m,1t+3z,16o1+5r,8+30,8+mc,29+1r,29+4v,75+73",EN:"1c+9,3d+1,6,187+9,513,4+5,7+9,sf+j,175h+9,qw+q,161f+1d,4xt+a,25i+9",ES:"17,2,6d\
|
|
93
|
+
p+1,f+1,av,16vr,mx+1,4o,2",ET:"z+2,3h+3,b+1,ym,3e+1,2o,p4+1,8,6u,7c,g6,1wc,1n9+4,30+1b,2n,6d,qhx+1,h0m,a+1,49+2,63+1,4+1,6bb+3,12jj",AN:"16o+5,2j+9,2+1,35,ed,1ff2+9,87+u",CS:"18,2+1,b,2u,12k,55v,l,17v\
|
|
94
|
+
0,2,3,53,2+1,b",B:"a,3,f+2,2v,690",S:"9,2,k",WS:"c,k,4f4,1vk+a,u,1j,335",ON:"x+1,4+4,h+5,r+5,r+3,z,5+3,2+1,2+1,5,2+2,3+4,o,w,ci+1,8+d,3+d,6+8,2+g,39+1,9,6+1,2,33,b8,3+1,3c+1,7+1,5r,b,7h+3,sa+5,2,3i+6,\
|
|
95
|
+
jg+3,ur+9,2v,ij+1,9g+9,7+a,8m,4+1,49+x,14u,2+2,c+2,e+2,e+2,e+1,i+n,e+e,2+p,u+2,e+2,36+1,2+3,2+1,b,2+2,6+5,2,2,2,h+1,5+4,6+3,3+f,16+2,5+3l,3+81,1y+p,2+40,q+a,m+13,2r+ch,2+9e,75+hf,3+v,2+2w,6e+5,f+6,75+\
|
|
96
|
+
2a,1a+p,2+2g,d+5x,r+b,6+3,4+o,g,6+1,6+2,2k+1,4,2j,5h+z,1m+1,1e+f,t+2,1f+e,d+3,4o+3,2s+1,w,535+1r,h3l+1i,93+2,2s,b+1,3l+x,2v,4g+3,21+3,kz+1,g5v+1,5a,j+9,n+v,2,3,2+8,2+1,3+2,2,3,46+1,4+4,h+5,r+5,r+a,3h+\
|
|
97
|
+
2,4+6,b+4,78,1r+24,4+c,4,1hb,ey+6,103+j,16j+c,1ux+7,5+g,fsh,jdq+1t,4,57+2e,p1,1m,1m,1m,1m,4kt+1,7j+17,5+2r,d+e,3+e,2+e,2+10,m+4,w,1n+5,1q,4z+5,4b+rb,9+c,4+c,4+37,d+2g,8+b,l+b,5+1j,9+9,7+13,9+t,3+1,27+\
|
|
98
|
+
3c,2+29,2+3q,d+d,3+4,4+2,6+6,a+o,8+6,a+2,e+6,16+42,2+1i",BN:"0+8,6+d,2s+5,2+p,e,4m9,1kt+2,2b+5,5+5,17q9+v,7k,6p+8,6+1,119d+3,440+7,96s+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,1ekf+1,\
|
|
99
|
+
1ekf+1,1ekf+1,1ekf+75,6p+2rz,1ben+1,1ekf+1,1ekf+1",NSM:"lc+33,7o+6,7c+18,2,2+1,2+1,2,21+a,1d+k,h,2u+6,3+5,3+1,2+3,10,v+q,2k+a,1n+8,a,p+3,2+8,2+2,2+4,18+2,3c+e,2+v,1k,2,5+7,5,4+6,b+1,u,1n,5+3,9,l+1,r,3\
|
|
100
|
+
+1,1m,5+1,5+1,3+2,4,v+1,4,c+1,1m,5+4,2+1,5,l+1,n+5,2,1n,3,2+3,9,8+1,c+1,v,1q,d,1f,4,1m+2,6+2,2+3,8+1,c+1,u,1n,g+1,l+1,t+1,1m+1,5+3,9,l+1,u,21,8+2,2,2j,3+6,d+7,2r,3+8,c+5,23+1,s,2,2,1k+d,2+4,2+1,6+a,2+\
|
|
101
|
+
z,a,2v+3,2+5,2+1,3+1,q+1,5+2,h+3,e,3+1,7,g,jk+2,qb+2,u+2,u+1,v+1,1t+1,2+6,9,3+a,a,1a+2,3c+1,z,3b+2,5+1,a,7+2,64+1,3,1n,2+6,2,2,3+7,7+9,3,1d+g,1s+3,1d,2+4,2,6,15+8,d+1,x+3,3+1,2+2,1l,2+1,4,2+2,1n+7,3+1\
|
|
102
|
+
,49+2,2+c,2+6,5,7,4+1,5j+1l,2+4,k1+w,2db+2,3y,2p+v,ff+3,30+1,n9x+3,2+9,x+1,29+1,7l,4,5,q+1,6,48+1,r+h,e,13+7,q+a,1b+2,1d,3+3,3+1,14,1w+5,3+1,3+1,d,9,1c,1g,2+2,3+1,6+1,2,17+1,9,6n,3,5,fn5,ki+f,h+f,r2,6\
|
|
103
|
+
b,46+4,1af+2,2+1,6+3,15+2,5,4m+1,fy+3,as+1,4a+a,4x,1j+e,1l+2,1e+3,3+1,1y+2,11+4,2+7,1r,d+1,1h+8,b+3,3,2o+2,3,2+1,7,4h,4+7,m+1,1m+1,4,12+6,4+4,5g+7,3+2,2,o,2d+5,2,5+1,2+1,6n+3,7+1,2+1,s+1,2e+7,3,2+1,2z\
|
|
104
|
+
,2,3+5,2,2u+2,3+3,2+4,78+8,2+1,75+1,2,5,41+3,3+1,5,x+5,3+1,15+5,3+3,9,a+5,3+2,1b+c,2+1,bb+6,2+5,2d+l,3+6,2+1,2+1,3f+5,4,2+1,2+6,2,21+1,4,2,9o+1,f0c+4,1o+6,t5,1s+3,2a,f5l+1,43t+2,i+7,3+6,v+3,45+2,1j0+1\
|
|
105
|
+
i,5+1d,9,f,n+4,2+e,11t+6,2+g,3+6,2+1,2+4,7a+6,c6+3,15t+6,32+6,gzhy+6n",AL:"16w,3,2,e+1b,z+2,2+2s,g+1,8+1,b+m,2+t,s+2i,c+e,4h+f,1d+1e,1bwe+dp,3+3z,x+c,2+1,35+3y,2rm+z,5+7,b+5,dt+l,c+u,17nl+27,1t+27,4x+\
|
|
106
|
+
6n,3+d",LRO:"6ct",RLO:"6cu",LRE:"6cq",RLE:"6cr",PDF:"6cs",LRI:"6ee",RLI:"6ef",FSI:"6eg",PDI:"6eh"},a={},o={};a.L=1,o[1]="L",Object.keys(n).forEach(function(l,y){a[l]=1<<y+1,o[a[l]]=l}),Object.freeze(a);
|
|
107
|
+
var i=a.LRI|a.RLI|a.FSI,d=a.L|a.R|a.AL,f=a.B|a.S|a.WS|a.ON|a.FSI|a.LRI|a.RLI|a.PDI,p=a.BN|a.RLE|a.LRE|a.RLO|a.LRO|a.PDF,M=a.S|a.WS|a.B|i|a.PDI|p,h=null;function z(){if(!h){h=new Map;var l=function(b){
|
|
108
|
+
if(n.hasOwnProperty(b)){var r=0;n[b].split(",").forEach(function(x){var s=x.split("+"),g=s[0],u=s[1];g=parseInt(g,36),u=u?parseInt(u,36):0,h.set(r+=g,a[b]);for(var _=0;_<u;_++)h.set(++r,a[b])})}};for(var y in n)
|
|
109
|
+
l(y)}}function k(l){return z(),h.get(l.codePointAt(0))||a.L}function H(l){return o[k(l)]}var Me={pairs:"14>1,1e>2,u>2,2wt>1,1>1,1ge>1,1wp>1,1j>1,f>1,hm>1,1>1,u>1,u6>1,1>1,+5,28>1,w>1,1>1,+3,b8>1,1>1,+\
|
|
110
|
+
3,1>3,-1>-1,3>1,1>1,+2,1s>1,1>1,x>1,th>1,1>1,+2,db>1,1>1,+3,3>1,1>1,+2,14qm>1,1>1,+1,4q>1,1e>2,u>2,2>1,+1",canonical:"6f1>-6dx,6dy>-6dx,6ec>-6ed,6ee>-6ed,6ww>2jj,-2ji>2jj,14r4>-1e7l,1e7m>-1e7l,1e7m>-1\
|
|
111
|
+
e5c,1e5d>-1e5b,1e5c>-14qx,14qy>-14qx,14vn>-1ecg,1ech>-1ecg,1edu>-1ecg,1eci>-1ecg,1eda>-1ecg,1eci>-1ecg,1eci>-168q,168r>-168q,168s>-14ye,14yf>-14ye"};function Ke(l,y){var b=36,r=0,x=new Map,s=y&&new Map,
|
|
112
|
+
g;return l.split(",").forEach(function u(_){if(_.indexOf("+")!==-1)for(var I=+_;I--;)u(g);else{g=_;var m=_.split(">"),j=m[0],F=m[1];j=String.fromCodePoint(r+=parseInt(j,b)),F=String.fromCodePoint(r+=parseInt(
|
|
113
|
+
F,b)),x.set(j,F),y&&s.set(F,j)}}),{map:x,reverseMap:s}}var et,Pt,Ut;function tt(){if(!et){var l=Ke(Me.pairs,!0),y=l.map,b=l.reverseMap;et=y,Pt=b,Ut=Ke(Me.canonical,!1).map}}function at(l){return tt(),
|
|
114
|
+
et.get(l)||null}function nt(l){return tt(),Pt.get(l)||null}function rt(l){return tt(),Ut.get(l)||null}var q=a.L,D=a.R,O=a.EN,ce=a.ES,_e=a.ET,le=a.AN,Ie=a.CS,Y=a.B,Va=a.S,Ee=a.ON,Ha=a.BN,Le=a.NSM,Oe=a.
|
|
115
|
+
AL,Zt=a.LRO,Se=a.RLO,Xt=a.LRE,ot=a.RLE,Gt=a.PDF,Ya=a.LRI,Jt=a.RLI,Ka=a.FSI,K=a.PDI;function en(l,y){for(var b=125,r=new Uint32Array(l.length),x=0;x<l.length;x++)r[x]=k(l[x]);var s=new Map;function g(S,C){
|
|
116
|
+
var R=r[S];r[S]=C,s.set(R,s.get(R)-1),R&f&&s.set(f,s.get(f)-1),s.set(C,(s.get(C)||0)+1),C&f&&s.set(f,(s.get(f)||0)+1)}for(var u=new Uint8Array(l.length),_=new Map,I=[],m=null,j=0;j<l.length;j++)m||I.push(
|
|
117
|
+
m={start:j,end:l.length-1,level:y==="rtl"?1:y==="ltr"?0:ja(j,!1)}),r[j]&Y&&(m.end=j,m=null);for(var F=ot|Xt|Se|Zt|i|K|Gt|Y,J=function(S){return S+(S&1?1:2)},W=function(S){return S+(S&1?2:1)},P=0;P<I.length;P++){
|
|
118
|
+
m=I[P];var v=[{_level:m.level,_override:0,_isolate:0}],w=void 0,N=0,U=0,lt=0;s.clear();for(var E=m.start;E<=m.end;E++){var L=r[E];if(w=v[v.length-1],s.set(L,(s.get(L)||0)+1),L&f&&s.set(f,(s.get(f)||0)+
|
|
119
|
+
1),L&F)if(L&(ot|Xt)){u[E]=w._level;var Ht=(L===ot?W:J)(w._level);Ht<=b&&!N&&!U?v.push({_level:Ht,_override:0,_isolate:0}):N||U++}else if(L&(Se|Zt)){u[E]=w._level;var Yt=(L===Se?W:J)(w._level);Yt<=b&&!N&&
|
|
120
|
+
!U?v.push({_level:Yt,_override:L&Se?D:q,_isolate:0}):N||U++}else if(L&i){L&Ka&&(L=ja(E+1,!0)===1?Jt:Ya),u[E]=w._level,w._override&&g(E,w._override);var Kt=(L===Jt?W:J)(w._level);Kt<=b&&N===0&&U===0?(lt++,
|
|
121
|
+
v.push({_level:Kt,_override:0,_isolate:1,_isolInitIndex:E})):N++}else if(L&K){if(N>0)N--;else if(lt>0){for(U=0;!v[v.length-1]._isolate;)v.pop();var dt=v[v.length-1]._isolInitIndex;dt!=null&&(_.set(dt,
|
|
122
|
+
E),_.set(E,dt)),v.pop(),lt--}w=v[v.length-1],u[E]=w._level,w._override&&g(E,w._override)}else L&Gt?(N===0&&(U>0?U--:!w._isolate&&v.length>1&&(v.pop(),w=v[v.length-1])),u[E]=w._level):L&Y&&(u[E]=m.level);else
|
|
123
|
+
u[E]=w._level,w._override&&L!==Ha&&g(E,w._override)}for(var ee=[],A=null,Q=m.start;Q<=m.end;Q++){var ft=r[Q];if(!(ft&p)){var ea=u[Q],ta=ft&i,on=ft===K;A&&ea===A._level?(A._end=Q,A._endsWithIsolInit=ta):
|
|
124
|
+
ee.push(A={_start:Q,_end:Q,_level:ea,_startsWithPDI:on,_endsWithIsolInit:ta})}}for(var st=[],Re=0;Re<ee.length;Re++){var qe=ee[Re];if(!qe._startsWithPDI||qe._startsWithPDI&&!_.has(qe._start)){for(var ut=[
|
|
125
|
+
A=qe],aa=void 0;A&&A._endsWithIsolInit&&(aa=_.get(A._end))!=null;)for(var Be=Re+1;Be<ee.length;Be++)if(ee[Be]._start===aa){ut.push(A=ee[Be]);break}for(var te=[],ht=0;ht<ut.length;ht++)for(var na=ut[ht],
|
|
126
|
+
gt=na._start;gt<=na._end;gt++)te.push(gt);for(var cn=u[te[0]],ra=m.level,ze=te[0]-1;ze>=0;ze--)if(!(r[ze]&p)){ra=u[ze];break}var pt=te[te.length-1],ln=u[pt],oa=m.level;if(!(r[pt]&i)){for(var De=pt+1;De<=
|
|
127
|
+
m.end;De++)if(!(r[De]&p)){oa=u[De];break}}st.push({_seqIndices:te,_sosType:Math.max(ra,cn)%2?D:q,_eosType:Math.max(oa,ln)%2?D:q})}}for(var mt=0;mt<st.length;mt++){var bt=st[mt],c=bt._seqIndices,de=bt.
|
|
128
|
+
_sosType,dn=bt._eosType,ae=u[c[0]]&1?D:q;if(s.get(Le))for(var $e=0;$e<c.length;$e++){var ia=c[$e];if(r[ia]&Le){for(var vt=de,Ce=$e-1;Ce>=0;Ce--)if(!(r[c[Ce]]&p)){vt=r[c[Ce]];break}g(ia,vt&(i|K)?Ee:vt)}}
|
|
129
|
+
if(s.get(O))for(var Fe=0;Fe<c.length;Fe++){var ca=c[Fe];if(r[ca]&O)for(var Ae=Fe-1;Ae>=-1;Ae--){var la=Ae===-1?de:r[c[Ae]];if(la&d){la===Oe&&g(ca,le);break}}}if(s.get(Oe))for(var yt=0;yt<c.length;yt++){
|
|
130
|
+
var da=c[yt];r[da]&Oe&&g(da,D)}if(s.get(ce)||s.get(Ie))for(var fe=1;fe<c.length-1;fe++){var kt=c[fe];if(r[kt]&(ce|Ie)){for(var ne=0,wt=0,xt=fe-1;xt>=0&&(ne=r[c[xt]],!!(ne&p));xt--);for(var jt=fe+1;jt<
|
|
131
|
+
c.length&&(wt=r[c[jt]],!!(wt&p));jt++);ne===wt&&(r[kt]===ce?ne===O:ne&(O|le))&&g(kt,ne)}}if(s.get(O))for(var T=0;T<c.length;T++){var fn=c[T];if(r[fn]&O){for(var Te=T-1;Te>=0&&r[c[Te]]&(_e|p);Te--)g(c[Te],
|
|
132
|
+
O);for(T++;T<c.length&&r[c[T]]&(_e|p|O);T++)r[c[T]]!==O&&g(c[T],O)}}if(s.get(_e)||s.get(ce)||s.get(Ie))for(var se=0;se<c.length;se++){var fa=c[se];if(r[fa]&(_e|ce|Ie)){g(fa,Ee);for(var Ne=se-1;Ne>=0&&
|
|
133
|
+
r[c[Ne]]&p;Ne--)g(c[Ne],Ee);for(var We=se+1;We<c.length&&r[c[We]]&p;We++)g(c[We],Ee)}}if(s.get(O))for(var Mt=0,sa=de;Mt<c.length;Mt++){var ua=c[Mt],_t=r[ua];_t&O?sa===q&&g(ua,q):_t&d&&(sa=_t)}if(s.get(
|
|
134
|
+
f)){var ue=D|O|le,ha=ue|q,Pe=[];{for(var re=[],oe=0;oe<c.length;oe++)if(r[c[oe]]&f){var he=l[c[oe]],ga=void 0;if(at(he)!==null)if(re.length<63)re.push({char:he,seqIndex:oe});else break;else if((ga=nt(
|
|
135
|
+
he))!==null)for(var ge=re.length-1;ge>=0;ge--){var It=re[ge].char;if(It===ga||It===nt(rt(he))||at(rt(It))===he){Pe.push([re[ge].seqIndex,oe]),re.length=ge;break}}}Pe.sort(function(S,C){return S[0]-C[0]})}
|
|
136
|
+
for(var Et=0;Et<Pe.length;Et++){for(var pa=Pe[Et],Ue=pa[0],Lt=pa[1],ma=!1,$=0,Ot=Ue+1;Ot<Lt;Ot++){var ba=c[Ot];if(r[ba]&ha){ma=!0;var va=r[ba]&ue?D:q;if(va===ae){$=va;break}}}if(ma&&!$){$=de;for(var St=Ue-
|
|
137
|
+
1;St>=0;St--){var ya=c[St];if(r[ya]&ha){var ka=r[ya]&ue?D:q;ka!==ae?$=ka:$=ae;break}}}if($){if(r[c[Ue]]=r[c[Lt]]=$,$!==ae){for(var pe=Ue+1;pe<c.length;pe++)if(!(r[c[pe]]&p)){k(l[c[pe]])&Le&&(r[c[pe]]=
|
|
138
|
+
$);break}}if($!==ae){for(var me=Lt+1;me<c.length;me++)if(!(r[c[me]]&p)){k(l[c[me]])&Le&&(r[c[me]]=$);break}}}}for(var Z=0;Z<c.length;Z++)if(r[c[Z]]&f){for(var wa=Z,Rt=Z,qt=de,be=Z-1;be>=0;be--)if(r[c[be]]&
|
|
139
|
+
p)wa=be;else{qt=r[c[be]]&ue?D:q;break}for(var xa=dn,ve=Z+1;ve<c.length;ve++)if(r[c[ve]]&(f|p))Rt=ve;else{xa=r[c[ve]]&ue?D:q;break}for(var Bt=wa;Bt<=Rt;Bt++)r[c[Bt]]=qt===xa?qt:ae;Z=Rt}}}for(var B=m.start;B<=
|
|
140
|
+
m.end;B++){var sn=u[B],Ze=r[B];if(sn&1?Ze&(q|O|le)&&u[B]++:Ze&D?u[B]++:Ze&(le|O)&&(u[B]+=2),Ze&p&&(u[B]=B===0?m.level:u[B-1]),B===m.end||k(l[B])&(Va|Y))for(var Xe=B;Xe>=0&&k(l[Xe])&M;Xe--)u[Xe]=m.level}}
|
|
141
|
+
return{levels:u,paragraphs:I};function ja(S,C){for(var R=S;R<l.length;R++){var X=r[R];if(X&(D|Oe))return 1;if(X&(Y|q)||C&&X===K)return 0;if(X&i){var Ma=un(R);R=Ma===-1?l.length:Ma}}return 0}function un(S){
|
|
142
|
+
for(var C=1,R=S+1;R<l.length;R++){var X=r[R];if(X&Y)break;if(X&K){if(--C===0)return R}else X&i&&C++}return-1}}var tn="14>1,j>2,t>2,u>2,1a>g,2v3>1,1>1,1ge>1,1wd>1,b>1,1j>1,f>1,ai>3,-2>3,+1,8>1k0,-1jq>1\
|
|
143
|
+
y7,-1y6>1hf,-1he>1h6,-1h5>1ha,-1h8>1qi,-1pu>1,6>3u,-3s>7,6>1,1>1,f>1,1>1,+2,3>1,1>1,+13,4>1,1>1,6>1eo,-1ee>1,3>1mg,-1me>1mk,-1mj>1mi,-1mg>1mi,-1md>1,1>1,+2,1>10k,-103>1,1>1,4>1,5>1,1>1,+10,3>1,1>8,-7>\
|
|
144
|
+
8,+1,-6>7,+1,a>1,1>1,u>1,u6>1,1>1,+5,26>1,1>1,2>1,2>2,8>1,7>1,4>1,1>1,+5,b8>1,1>1,+3,1>3,-2>1,2>1,1>1,+2,c>1,3>1,1>1,+2,h>1,3>1,a>1,1>1,2>1,3>1,1>1,d>1,f>1,3>1,1a>1,1>1,6>1,7>1,13>1,k>1,1>1,+19,4>1,1>\
|
|
145
|
+
1,+2,2>1,1>1,+18,m>1,a>1,1>1,lk>1,1>1,4>1,2>1,f>1,3>1,1>1,+3,db>1,1>1,+3,3>1,1>1,+2,14qm>1,1>1,+1,6>1,4j>1,j>2,t>2,u>2,2>1,+1",it;function an(){if(!it){var l=Ke(tn,!0),y=l.map,b=l.reverseMap;b.forEach(
|
|
146
|
+
function(r,x){y.set(x,r)}),it=y}}function ct(l){return an(),it.get(l)||null}function nn(l,y,b,r){var x=l.length;b=Math.max(0,b==null?0:+b),r=Math.min(x-1,r==null?x-1:+r);for(var s=new Map,g=b;g<=r;g++)
|
|
147
|
+
if(y[g]&1){var u=ct(l[g]);u!==null&&s.set(g,u)}return s}function Qt(l,y,b,r){var x=l.length;b=Math.max(0,b==null?0:+b),r=Math.min(x-1,r==null?x-1:+r);var s=[];return y.paragraphs.forEach(function(g){var u=Math.
|
|
148
|
+
max(b,g.start),_=Math.min(r,g.end);if(u<_){for(var I=y.levels.slice(u,_+1),m=_;m>=u&&k(l[m])&M;m--)I[m]=g.level;for(var j=g.level,F=1/0,J=0;J<I.length;J++){var W=I[J];W>j&&(j=W),W<F&&(F=W|1)}for(var P=j;P>=
|
|
149
|
+
F;P--)for(var v=0;v<I.length;v++)if(I[v]>=P){for(var w=v;v+1<I.length&&I[v+1]>=P;)v++;v>w&&s.push([w+u,v+u])}}}),s}function rn(l,y,b,r){var x=Vt(l,y,b,r),s=[].concat(l);return x.forEach(function(g,u){
|
|
150
|
+
s[u]=(y.levels[g]&1?ct(l[g]):null)||l[g]}),s.join("")}function Vt(l,y,b,r){for(var x=Qt(l,y,b,r),s=[],g=0;g<l.length;g++)s[g]=g;return x.forEach(function(u){for(var _=u[0],I=u[1],m=s.slice(_,I+1),j=m.
|
|
151
|
+
length;j--;)s[I-j]=m[j]}),s}return t.closingToOpeningBracket=nt,t.getBidiCharType=k,t.getBidiCharTypeName=H,t.getCanonicalBracket=rt,t.getEmbeddingLevels=en,t.getMirroredCharacter=ct,t.getMirroredCharactersMap=
|
|
152
|
+
nn,t.getReorderSegments=Qt,t.getReorderedIndices=Vt,t.getReorderedString=rn,t.openingToClosingBracket=at,Object.defineProperty(t,"__esModule",{value:!0}),t}({});return e}const tr=new Set(["R","AL","AN",
|
|
153
|
+
"RLE","RLO","RLI","LRE","LRO","LRI","FSI","PDI","PDF"]),xe=new Map,ar=500;function Ja(e){const t=xe.get(e);if(t!==void 0)return t;let n=!1;for(const a of e)if(tr.has(Ye().getBidiCharTypeName(a))){n=!0;
|
|
154
|
+
break}if(xe.size>=ar){const a=xe.keys().next().value;a!==void 0&&xe.delete(a)}return xe.set(e,n),n}function Qa(e){for(let t=0;t<e.length;){const n=e.codePointAt(t);if(n===void 0)break;const a=String.fromCodePoint(
|
|
155
|
+
n),o=Ye().getBidiCharTypeName(a);if(o==="R"||o==="AL")return"rtl";if(o==="L")return"ltr";t+=a.length}return null}function nr(e,t){return e==="rtl"||e==="ltr"?e:Qa(t)??"ltr"}let Wt=null;function Ye(){return Wt||
|
|
156
|
+
(Wt=er()),Wt}const je=new Map,rr=300;function or(e,t){const n=t+"\0"+e,a=je.get(n);if(a)return a;const o=Ye().getEmbeddingLevels(e,t);if(je.size>=rr){const i=je.keys().next().value;i!==void 0&&je.delete(
|
|
157
|
+
i)}return je.set(n,o),o}function ir(e,t,n,a){if(a<=n)return[];if(t==="ltr"&&!Ja(e.slice(n,a)))return[{start:n,end:a,rtl:!1}];const o=or(e,t),i=Ye().getReorderSegments(e,o,n,a-1),d=a-n,f=new Array(d);for(let h=0;h<
|
|
158
|
+
d;h++)f[h]=n+h;for(const[h,z]of i){let k=h-n,H=z-n;for(;k<H;){const Me=f[k];f[k]=f[H],f[H]=Me,k++,H--}}const p=[];let M=0;for(let h=1;h<=d;h++){if(!(h===d||Math.abs(f[h]-f[h-1])!==1||f[h]-f[h-1]!==f[M+
|
|
159
|
+
1]-f[M]))continue;const z=f[M],k=f[h-1];z<=k?p.push({start:z,end:k+1,rtl:!1}):p.push({start:k,end:z+1,rtl:!0}),M=h}for(const h of p)h.end-h.start===1&&(h.rtl=(o.levels[h.start]&1)===1);return p}export{
|
|
160
|
+
nr as a,Qa as b,Hn as c,Yn as d,Kn as e,$t as f,Za as g,Cn as h,Xa as i,ir as j,Nt as k,zt as l,Dn as p,Sn as r,Ja as t};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import{M as ke}from"./engine-TnK8N-gT.js";import{a as le}from"./ParagraphDiffAnalysis-DrmStvmz.js";const ce=new WeakMap,E=r=>{let s=ce.get(r);return s===void 0&&(s=r.children.map(d=>d.text).join(""),ce.
|
|
2
|
+
set(r,s)),s},z=r=>r.trim()?r.trim().split(/\s+/).length:0,ae=new WeakMap,h=r=>{let s=ae.get(r);if(s===void 0){const{id:d,children:m,...J}=r;s=JSON.stringify(J),ae.set(r,s)}return s},U=(r={})=>Object.fromEntries(
|
|
3
|
+
ke.filter(s=>r[s]!==void 0).map(s=>[s,r[s]])),be=["comment","footnoteRef","footnotePendingBody","footnotePendingKind","oxmlRange","bookmark"],de=r=>{const s={...r};for(const d of be)delete s[d];return s};
|
|
4
|
+
function xe(r){return{...r,children:r.children.map(s=>({...s,marks:U(s.marks)}))}}function he(r){return r.type==="paragraph"?`p${h(r)}${E(r)}`:r.type==="list"?`l${h(r)}${r.children.map(s=>h(s)+E(s)).join(
|
|
5
|
+
"\0")}`:JSON.stringify(r,(s,d)=>s==="id"?void 0:d)}function we(r){return r.type==="paragraph"||r.type==="list"||r.type==="table"}function ee(r,s){const d=JSON.parse(JSON.stringify(r)),m=new Map,J=[],C=O=>{
|
|
6
|
+
if(!O||typeof O!="object")return;const y=O;if(typeof y.type=="string"&&typeof y.id=="string"){const W=s();m.set(y.id,W),y.id=W}typeof y.docxTablePropertyOverrides=="string"&&J.push(y),Array.isArray(y.
|
|
7
|
+
children)&&y.children.forEach(C)};C(d);for(const O of J)try{const y=JSON.parse(O.docxTablePropertyOverrides);for(const W of["rows","rowExceptions","cells"]){const x=y[W];!x||typeof x!="object"||Array.
|
|
8
|
+
isArray(x)||(y[W]=Object.fromEntries(Object.entries(x).map(([u,$])=>[m.get(u)??u,$])))}O.docxTablePropertyOverrides=JSON.stringify(y)}catch{}return d}function te(r){const s=d=>{if(!d||typeof d!="objec\
|
|
9
|
+
t")return;const m=d;m.type==="text"&&m.marks&&(m.marks=de(m.marks)),m.children?.forEach(s)};return s(r),r}const Y=new Map,H=r=>{let s=Y.get(r);return s||(s=new Set(r.toLowerCase().match(/[\p{L}\p{N}]+/gu)??
|
|
10
|
+
[]),Y.size>5e4&&Y.clear(),Y.set(r,s)),s};function re(r,s){let d=0;for(const m of r)s.has(m)&&d++;return 2*d/(r.size+s.size||1)}function ne(r,s,d,m,J,C,O,y,W=()=>!1){const x=new Map,u=g=>{const f=d(g);
|
|
11
|
+
return x.has(f)||x.set(f,`t${x.size}`),x.get(f)+" "},$=le(r.map(u).join(""),s.map(u).join("")).diffs;let K=0,D=0,L=0,Q=0;const I=()=>{const g=r.slice(L,K),f=s.slice(Q,D);if(g.length===1&&f.length===1&&
|
|
12
|
+
W(g[0],f[0])){C(g[0],f[0]);return}const M=g.map(v=>f.map(j=>m(v,j))),w=Array.from({length:g.length+1},()=>new Float64Array(f.length+1));for(let v=g.length-1;v>=0;v--)for(let j=f.length-1;j>=0;j--)w[v][j]=
|
|
13
|
+
Math.max(w[v+1][j],w[v][j+1],M[v][j]+w[v+1][j+1]);let k=0,S=0;for(;k<g.length||S<f.length;)k<g.length&&S<f.length&&M[k][S]>0&&w[k][S]===M[k][S]+w[k+1][S+1]?C(g[k++],f[S++]):k<g.length&&(S===f.length||
|
|
14
|
+
w[k+1][S]>=w[k][S+1])?O(g[k++]):y(f[S++])};for(const[g,f]of $){const M=f.trim().split(/\s+/).filter(Boolean).length;if(g===0){I();for(let w=0;w<M;w++)J(r[K++],s[D++]);L=K,Q=D}else g===-1?K+=M:D+=M}I()}
|
|
15
|
+
const Z=8e6,pe=1e6;function Se(r,s,d){if(r.length*s.length>Z)return null;const{nextId:m,nextBlockId:J,label:C,authorName:O,authorOf:y,pairLoneChanges:W}=d,x=t=>W?t:()=>!1,u={inlineChanges:0,insertedBlocks:0,
|
|
16
|
+
deletedBlocks:0,unmarkedBlocks:0,insertedWords:0,deletedWords:0},$=t=>y?.(t)??O,K=(t,e,n)=>{const c=$(n);return{[t]:!0,suggestionId:e,suggestionSource:"manual",suggestionAuthorType:"human",suggestionLabel:C,
|
|
17
|
+
...c?{suggestionAuthorName:c}:{}}},D=(t,e)=>{if(!we(t))return null;const n=t.type==="paragraph"?t.children[0]?.marks:void 0,c=t.type==="paragraph"?xe(t):t,i=e==="delete"?te(ee(c,J)):c,o=m(),p=$(n),l={
|
|
18
|
+
id:o,blockId:i.id,source:"manual",authorType:"human",label:e==="insert"?"Insert":"Delete",...p?{agentName:p}:{}},a=e==="insert"?{...l,type:"block-insert"}:{...l,type:"block-delete",beforeBlock:i},b="c\
|
|
19
|
+
hildren"in i&&i.type!=="table"?P(i):"";return e==="insert"?(u.insertedBlocks++,u.insertedWords+=z(b)):(u.deletedBlocks++,u.deletedWords+=z(b)),{...i,structuralSuggestionId:o,structuralSuggestionKind:e,
|
|
20
|
+
structuralSuggestionRecord:JSON.stringify(a)}},L=(t,e,n)=>{const c=[];let i=0;for(const o of t.children){const p=Math.max(e-i,0),l=Math.min(e+n-i,o.text.length);if(l>p&&c.push({...o,text:o.text.slice(
|
|
21
|
+
p,l)}),i+=o.text.length,i>=e+n)break}return c},Q=(t,e,n)=>{const c=E(t),i=E(e);if(h(t)!==h(e)||z(c)*z(i)>pe){I(t,"delete",n),I(e,"insert",n);return}const o=[];let p=0,l=0,a="";const b=(A,N)=>{a||(a=m(),
|
|
22
|
+
u.inlineChanges++);const R=z(A.map(B=>B.text).join(""));N==="insertion"?u.insertedWords+=R:u.deletedWords+=R,o.push(...A.map(B=>{const T=U(B.marks);return{...B,marks:{...N==="deletion"?de(T):T,...K(N,
|
|
23
|
+
a,B.marks)}}}))};for(const[A,N]of le(c,i).diffs){if(A===-1)b(L(t,p,N.length),"deletion");else if(A===1)b(L(e,l,N.length),"insertion");else{const R=L(t,p,N.length),B=L(e,l,N.length);let T=0,F=0,q=0,G=0;
|
|
24
|
+
for(;T<R.length&&F<B.length;){const V=Math.min(R[T].text.length-q,B[F].text.length-G),oe={...R[T],text:R[T].text.slice(q,q+V)},X={...B[F],text:B[F].text.slice(G,G+V)},{bookmark:Ne,...me}=U(oe.marks),{
|
|
25
|
+
bookmark:Ie,...ye}=U(X.marks);JSON.stringify(me)===JSON.stringify(ye)?(a="",o.push({...X,marks:U(X.marks)})):(b([oe],"deletion"),b([X],"insertion")),q+=V,G+=V,q===R[T].text.length&&(T++,q=0),G===B[F].
|
|
26
|
+
text.length&&(F++,G=0)}}A!==1&&(p+=N.length),A!==-1&&(l+=N.length)}n.push({...e,children:o})},I=(t,e,n)=>{if(t.type==="table"){n.push(S(t,e));return}const c=D(t,e);c?n.push(c):(u.unmarkedBlocks++,e===
|
|
27
|
+
"insert"&&n.push(t))},g=(t,e)=>{if(h(t)!==h(e))return 0;const n=re(H(E(t)),H(E(e)));return n>=.5?n:0},f=(t,e,n)=>{const c=()=>{I(t,"delete",n),I(e,"insert",n)};if(t.children.length*e.children.length>Z)
|
|
28
|
+
return c();const i=[];let o=!1;if(ne(t.children,e.children,l=>h(l)+E(l),g,(l,a)=>i.push([l,a]),(l,a)=>i.push([l,a]),()=>o=!0,()=>o=!0,x((l,a)=>h(l)===h(a))),o||i.some(([l,a])=>h(l)!==h(a)||z(E(l))*z(E(
|
|
29
|
+
a))>pe))return c();const p=[];for(const[l,a]of i)Q(l,a,p);n.push({...e,children:p})},M=(t,e)=>{const n=z(P(t));e==="insert"?(u.insertedBlocks++,u.insertedWords+=n):(u.deletedBlocks++,u.deletedWords+=n)},
|
|
30
|
+
w=(t,e)=>e==="delete"?te(ee(t,J)):t,k=(t,e,n,c)=>{const i=m();return{id:i,record:{id:i,type:"table-change",tableId:t,source:"manual",authorType:"human",label:c[n],...O?{agentName:O}:{},tableRevision:{
|
|
31
|
+
version:1,suggestionKind:n,markers:e.map(([o,p])=>({kind:n==="insert"?"row-insert":"row-delete",rowId:o.id,rowIndex:p})),operations:e.map(([o,p])=>({kind:"row",action:n,rowId:o.id,rowIndex:p,row:JSON.
|
|
32
|
+
parse(JSON.stringify(o))}))}}}},S=(t,e)=>{const n=e==="delete"?te(ee(t,J)):t,{id:c,record:i}=k(n.id,n.children.map((o,p)=>[o,p]),e,{insert:"Insert table",delete:"Delete table"});return M(n,e),{...n,structuralSuggestionRecords:JSON.
|
|
33
|
+
stringify([i]),children:n.children.map(o=>({...o,diffState:e,suggestionId:c}))}},v=(t,e)=>h(t)===h(e)&&t.children.length===e.children.length&&t.children.every((n,c)=>h(n)===h(e.children[c])),j=(t,e)=>t.
|
|
34
|
+
children.every((n,c)=>n.children.length*e.children[c].children.length<=Z),_=(t,e)=>v(t,e)&&j(t,e),se=(t,e)=>({...e,children:e.children.map((n,c)=>({...n,children:ie(t.children[c].children,n.children)}))}),
|
|
35
|
+
ge=(t,e,n)=>{if(h(t)!==h(e)||t.children.length*e.children.length>Z){I(t,"delete",n),I(e,"insert",n);return}const c=[],i=[],o=(l,a)=>{const b=w(l,a),{id:A,record:N}=k(e.id,[[b,c.length]],a,{insert:"Ins\
|
|
36
|
+
ert table row",delete:"Delete table row"});i.push(N),M(b,a),c.push({...b,diffState:a,suggestionId:A})},p=l=>he(l);ne(t.children,e.children,p,(l,a)=>{if(!_(l,a))return 0;const b=re(H(P(l)),H(P(a)));return b>=
|
|
37
|
+
.5?b:0},(l,a)=>{_(l,a)?c.push(se(l,a)):(o(l,"delete"),o(a,"insert"))},(l,a)=>c.push(se(l,a)),l=>o(l,"delete"),l=>o(l,"insert"),x(_)),n.push({...e,children:c,...i.length>0?{structuralSuggestionRecords:JSON.
|
|
38
|
+
stringify(i)}:{}})},fe=(t,e)=>{if(t.type==="paragraph"&&e.type==="paragraph")return g(t,e);if(t.type==="list"&&e.type==="list"&&h(t)===h(e)||t.type==="table"&&e.type==="table"&&h(t)===h(e)){const n=re(
|
|
39
|
+
H(P(t)),H(P(e)));return n>=.3?n:0}return 0};function ie(t,e){const n=[],c=(i,o)=>{i.type==="list"&&o.type==="list"?f(i,o,n):i.type==="table"&&o.type==="table"?ge(i,o,n):i.type==="paragraph"&&o.type===
|
|
40
|
+
"paragraph"?Q(i,o,n):n.push(o)};return ne(t,e,he,fe,c,c,i=>I(i,"delete",n),i=>I(i,"insert",n),x((i,o)=>i.type===o.type&&(i.type==="paragraph"||i.type==="list"||i.type==="table")&&h(i)===h(o))),n}return{
|
|
41
|
+
blocks:ie(r,s),stats:u}}const ue=new WeakMap;function P(r){const s=ue.get(r);if(s!==void 0)return s;const d=Oe(r);return ue.set(r,d),d}function Oe(r){return"children"in r&&Array.isArray(r.children)?r.
|
|
42
|
+
children.map(s=>{const d=s;return d.type==="text"?d.text??"":P(s)}).join(" "):""}export{Se as d};
|