documint 0.0.2 → 0.0.3

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/dist/index.js CHANGED
@@ -1,587 +1,67 @@
1
- import{useEffect as k0,useEffectEvent as B1,useLayoutEffect as vG,useMemo as f0,useRef as y1,useState as MM}from"react";function _2($){let M=F1($.children);return{children:$.children,id:G1($.path,"paragraph",M),plainText:M,type:"paragraph"}}function I($){return _2({children:NM(void 0,$.text)})}function h4($){let M=F1($.children);return{children:$.children,depth:$.depth,id:G1($.path,"heading",`${$.depth}:${M}`),plainText:M,type:"heading"}}function Z0($){return h4({children:NM(void 0,$.text),depth:$.depth})}function W1($){let M=$.marks??[];return{id:G1($.path,"text",`${$.text}:${M.join(",")}`),marks:M,text:$.text,type:"text"}}function H2($={}){return{id:G1($.path,"break","break"),type:"break"}}function S0($){return{code:$.code,id:G1($.path,"inlineCode",$.code),type:"inlineCode"}}function m0($){return{children:$.children,id:G1($.path,"link",`${$.url}:${F1($.children)}`),title:$.title??null,type:"link",url:$.url}}function I4($){let M=$.alt??null,J=$.width??null;return{alt:M,id:G1($.path,"image",`${$.url}:${J??""}:${M??""}`),title:$.title??null,type:"image",url:$.url,width:J}}function p4($){return{id:G1($.path,"unsupported",$.source),originalType:$.originalType,source:$.source,type:"unsupported"}}function n1($){let M=g0($.children);return{checked:$.checked??null,children:$.children,id:G1($.path,"listItem",M),plainText:M,spread:$.spread??!1,type:"listItem"}}function y0($){let M=$.items.map((J)=>J.plainText).join(`
2
- `);return{id:G1($.path,"list",`${String($.ordered)}:${M}`),items:$.items,ordered:$.ordered,plainText:M,spread:$.spread??!1,start:$.start??null,type:"list"}}function T1($){let M=g0($.children);return{children:$.children,id:G1($.path,"blockquote",M),plainText:M,type:"blockquote"}}function N6($){return{id:G1($.path,"code",`${$.language??""}:${$.source}`),language:$.language??null,meta:$.meta??null,plainText:$.source,source:$.source,type:"code"}}function X0($){let M=F1($.children);return{children:$.children,id:G1($.path,"tableCell",M),plainText:M}}function v0($){return{cells:$.cells,id:G1($.path,"tableRow",String($.cells.length))}}function V0($){let M=$.rows.map((J)=>J.cells.map((Z)=>Z.plainText).join(" | ")).join(`
3
- `);return{align:$.align??[],id:G1($.path,"table",M),plainText:M,rows:$.rows,type:"table"}}function l4(){return{id:"",plainText:"",type:"thematicBreak"}}function r4($){return{id:G1($.path,"unsupported",$.source),originalType:$.originalType,plainText:$.source,source:$.source,type:"unsupported"}}function qM($){return{attributes:$.attributes,body:$.body,id:G1($.path,"directive",`${$.name}{${$.attributes}}:${$.body}`),name:$.name,plainText:$.body,type:"directive"}}function k1($,M){return $.type==="heading"?h4({children:M,depth:$.depth}):_2({children:M})}function b1($,M){return n1({checked:$.checked,children:M,spread:$.spread})}function $1($,M,J={}){return y0({items:M,ordered:J.ordered??$.ordered,spread:J.spread??$.spread,start:J.start??$.start})}function r1($,M){return V0({align:$.align,rows:M})}function c4($,M){return N6({language:$.language,meta:$.meta,source:M})}function x4($,M){return r4({originalType:$.originalType,source:M})}function NM($,M){return M.length>0?[W1({path:$?`${$}.children.0`:void 0,text:M})]:[]}function G1($,M,J){return $?Q1(M,$,J):""}function h0($,M=[]){return{blocks:$.map((J,Z)=>U6(J,Z)),comments:M}}function I0($,M,J,Z){let X=Z.map((Q,K)=>U6(Q,M+K)),A=$.blocks.slice(M+J),Y=Z.length===J?A:A.map((Q,K)=>U6(Q,M+X.length+K));return{blocks:[...$.blocks.slice(0,M),...X,...Y],comments:$.comments}}function UM($,M,J,Z){return{blocks:$.blocks,comments:[...$.comments.slice(0,M),...Z,...$.comments.slice(M+J)]}}function F1($){return $.map((M)=>{switch(M.type){case"break":return`
4
- `;case"image":return M.alt??"";case"inlineCode":return M.code;case"link":return F1(M.children);case"text":return M.text;case"unsupported":return M.source}}).join("")}function g0($){return $.map((M)=>{switch(M.type){case"blockquote":case"listItem":return g0(M.children);case"code":return M.source;case"directive":return M.body;case"heading":case"paragraph":return F1(M.children);case"list":return M.items.map((J)=>J.plainText).join(`
5
- `);case"table":return M.rows.map((J)=>J.cells.map((Z)=>Z.plainText).join(" | ")).join(`
1
+ import{useEffect as B2,useEffectEvent as _2,useLayoutEffect as YB,useMemo as t0,useRef as R1,useState as G$}from"react";function b2($){let M=A0($.children);return{children:$.children,id:N0($.path,"paragraph",M),plainText:M,type:"paragraph"}}function p($){return b2({children:H$(void 0,$.text)})}function i4($){let M=A0($.children);return{children:$.children,depth:$.depth,id:N0($.path,"heading",`${$.depth}:${M}`),plainText:M,type:"heading"}}function $1($){return i4({children:H$(void 0,$.text),depth:$.depth})}function z0($){let M=$.marks??[];return{id:N0($.path,"text",`${$.text}:${M.join(",")}`),marks:M,text:$.text,type:"text"}}function D2($={}){return{id:N0($.path,"break","break"),type:"break"}}function m1($){return{code:$.code,id:N0($.path,"inlineCode",$.code),type:"inlineCode"}}function S1($){return{children:$.children,id:N0($.path,"link",`${$.url}:${A0($.children)}`),title:$.title??null,type:"link",url:$.url}}function s4($){let M=$.alt??null,Z=$.width??null;return{alt:M,id:N0($.path,"image",`${$.url}:${Z??""}:${M??""}`),title:$.title??null,type:"image",url:$.url,width:Z}}function o4($){return{id:N0($.path,"unsupported",$.source),originalType:$.originalType,source:$.source,type:"unsupported"}}function d0($){let M=v1($.children);return{checked:$.checked??null,children:$.children,id:N0($.path,"listItem",M),plainText:M,spread:$.spread??!1,type:"listItem"}}function P1($){let M=$.items.map((Z)=>Z.plainText).join(`
2
+ `);return{id:N0($.path,"list",`${String($.ordered)}:${M}`),items:$.items,ordered:$.ordered,plainText:M,spread:$.spread??!1,start:$.start??null,type:"list"}}function T0($){let M=v1($.children);return{children:$.children,id:N0($.path,"blockquote",M),plainText:M,type:"blockquote"}}function D8($){return{id:N0($.path,"code",`${$.language??""}:${$.source}`),language:$.language??null,meta:$.meta??null,plainText:$.source,source:$.source,type:"code"}}function M1($){let M=A0($.children);return{children:$.children,id:N0($.path,"tableCell",M),plainText:M}}function u1($){return{cells:$.cells,id:N0($.path,"tableRow",String($.cells.length))}}function z1($){let M=$.rows.map((Z)=>Z.cells.map((J)=>J.plainText).join(" | ")).join(`
3
+ `);return{align:$.align??[],id:N0($.path,"table",M),plainText:M,rows:$.rows,type:"table"}}function n4(){return{id:"",plainText:"",type:"thematicBreak"}}function t4($){return{id:N0($.path,"unsupported",$.source),originalType:$.originalType,plainText:$.source,source:$.source,type:"unsupported"}}function D$($){return{attributes:$.attributes,body:$.body,id:N0($.path,"directive",`${$.name}{${$.attributes}}:${$.body}`),name:$.name,plainText:$.body,type:"directive"}}function R0($,M){return $.type==="heading"?i4({children:M,depth:$.depth}):b2({children:M})}function V0($,M){return d0({checked:$.checked,children:M,spread:$.spread})}function o($,M,Z={}){return P1({items:M,ordered:Z.ordered??$.ordered,spread:Z.spread??$.spread,start:Z.start??$.start})}function h0($,M){return z1({align:$.align,rows:M})}function e4($,M){return D8({language:$.language,meta:$.meta,source:M})}function $5($,M){return t4({originalType:$.originalType,source:M})}function H$($,M){return M.length>0?[z0({path:$?`${$}.children.0`:void 0,text:M})]:[]}function N0($,M,Z){return $?X0(M,$,Z):""}function h1($,M=[]){return{blocks:$.map((Z,J)=>H8(Z,J)),comments:M}}function g1($,M,Z,J){let X=J.map((K,q)=>H8(K,M+q)),Y=$.blocks.slice(M+Z),Q=J.length===Z?Y:Y.map((K,q)=>H8(K,M+X.length+q));return{blocks:[...$.blocks.slice(0,M),...X,...Q],comments:$.comments}}function P$($,M,Z,J){return{blocks:$.blocks,comments:[...$.comments.slice(0,M),...J,...$.comments.slice(M+Z)]}}function A0($){return $.map((M)=>{switch(M.type){case"break":return`
4
+ `;case"image":return M.alt??"";case"inlineCode":return M.code;case"link":return A0(M.children);case"text":return M.text;case"unsupported":return M.source}}).join("")}function v1($){return $.map((M)=>{switch(M.type){case"blockquote":case"listItem":return v1(M.children);case"code":return M.source;case"directive":return M.body;case"heading":case"paragraph":return A0(M.children);case"list":return M.items.map((Z)=>Z.plainText).join(`
5
+ `);case"table":return M.rows.map((Z)=>Z.cells.map((J)=>J.plainText).join(" | ")).join(`
6
6
  `);case"thematicBreak":return"";case"unsupported":return M.source}}).join(`
7
- `).trim()}function U6($,M){return d4($,`root.${M}`)}function d4($,M){switch($.type){case"blockquote":{let J=$.children.map((X,A)=>d4(X,`${M}.children.${A}`)),Z=g0(J);return{children:J,id:Q1("blockquote",M,Z),plainText:Z,type:"blockquote"}}case"code":return{id:Q1("code",M,`${$.language??""}:${$.source}`),language:$.language,meta:$.meta,plainText:$.source,source:$.source,type:"code"};case"directive":return{attributes:$.attributes,body:$.body,id:Q1("directive",M,`${$.name}{${$.attributes}}:${$.body}`),name:$.name,plainText:$.body,type:"directive"};case"heading":{let J=$.children.map((X,A)=>a4(X,`${M}.children.${A}`)),Z=F1(J);return{children:J,depth:$.depth,id:Q1("heading",M,`${$.depth}:${Z}`),plainText:Z,type:"heading"}}case"list":{let J=$.items.map((X,A)=>d4(X,`${M}.children.${A}`)),Z=J.map((X)=>X.plainText).join(`
8
- `);return{id:Q1("list",M,`${String($.ordered)}:${Z}`),items:J,ordered:$.ordered,plainText:Z,spread:$.spread,start:$.start,type:"list"}}case"listItem":{let J=$.children.map((X,A)=>d4(X,`${M}.children.${A}`)),Z=g0(J);return{checked:$.checked,children:J,id:Q1("listItem",M,Z),plainText:Z,spread:$.spread,type:"listItem"}}case"paragraph":{let J=$.children.map((X,A)=>a4(X,`${M}.children.${A}`)),Z=F1(J);return{children:J,id:Q1("paragraph",M,Z),plainText:Z,type:"paragraph"}}case"table":{let J=$.rows.map((X,A)=>AZ(X,`${M}.rows.${A}`)),Z=J.map((X)=>X.cells.map((A)=>A.plainText).join(" | ")).join(`
9
- `);return{align:$.align,id:Q1("table",M,Z),plainText:Z,rows:J,type:"table"}}case"thematicBreak":return{id:Q1("thematicBreak",M,"thematic-break"),plainText:"",type:"thematicBreak"};case"unsupported":return{id:Q1("unsupported",M,$.source),originalType:$.originalType,plainText:$.source,source:$.source,type:"unsupported"}}}function AZ($,M){return{cells:$.cells.map((J,Z)=>{let X=J.children.map((Y,Q)=>a4(Y,`${M}.cells.${Z}.children.${Q}`)),A=F1(X);return{children:X,id:Q1("tableCell",`${M}.cells.${Z}`,A),plainText:A}}),id:Q1("tableRow",M,String($.cells.length))}}function a4($,M){switch($.type){case"break":return{id:Q1("break",M,"break"),type:"break"};case"image":return{alt:$.alt,id:Q1("image",M,`${$.url}:${$.width??""}:${$.alt??""}`),title:$.title,type:"image",url:$.url,width:$.width};case"inlineCode":return{code:$.code,id:Q1("inlineCode",M,$.code),type:"inlineCode"};case"link":{let J=$.children.map((X,A)=>a4(X,`${M}.children.${A}`)),Z=F1(J);return{children:J,id:Q1("link",M,`${$.url}:${Z}`),title:$.title,type:"link",url:$.url}}case"text":return{id:Q1("text",M,`${$.text}:${$.marks.join(",")}`),marks:$.marks,text:$.text,type:"text"};case"unsupported":return{id:Q1("unsupported",M,$.source),originalType:$.originalType,source:$.source,type:"unsupported"}}}function P2($){return $.map((M)=>{switch(M.type){case"blockquote":return{...M,children:P2(M.children)};case"heading":case"paragraph":return k1(M,G6(M.children));case"list":return{...M,items:M.items.map((J)=>({...J,children:P2(J.children)}))};case"listItem":return{...M,children:P2(M.children)};case"table":return r1(M,M.rows.map((J)=>({...J,cells:J.cells.map((Z)=>({...Z,children:G6(Z.children)}))})));default:return M}})}function G6($){let M=[...$];for(let J=M.length-1;J>=0;J-=1){let Z=M[J];if(Z.type==="text"){let X=Z.text.replace(/[ \t]+$/u,"");if(X.length===Z.text.length)return M;if(X.length===0){M.splice(J,1);continue}return M[J]={...Z,text:X},M}if(Z.type==="link"){let X=G6(Z.children);if(X.length===Z.children.length&&X.every((A,Y)=>A===Z.children[Y]))return M;if(X.length===0){M.splice(J,1);continue}return M[J]={...Z,children:X},M}return M}return M}function Q1($,M,J){let Z=2166136261;for(let X of`${$}:${M}:${J}`)Z^=X.charCodeAt(0),Z=Math.imul(Z,16777619);return`${$}-${(Z>>>0).toString(36)}`}function W2($,M){B6($.blocks,M,FM(),DM())}function BM($,M){B6($,M,FM(),DM())}function B6($,M,J,Z){for(let[X,A]of $.entries()){if(J.stopped)return;let Y=`${Z.pathPrefix}.${X}`,Q={blockAncestors:Z.blockAncestors,depth:Z.depth,parentBlock:Z.parentBlock,path:Y},K=M.enterBlock?.(A,Q);if(p0(K,J))return;if(K!=="skip")switch(A.type){case"list":GM(A.items,A,M,J,Z,Y);break;case"blockquote":case"listItem":GM(A.children,A,M,J,Z,Y);break;case"heading":case"paragraph":F6(A.children,M,J,{block:A,blockAncestors:[...Z.blockAncestors,A],inlineAncestors:[],parentInline:null,pathPrefix:`${Y}.children`});break;case"table":QZ(A,M,J,{blockAncestors:[...Z.blockAncestors,A],pathPrefix:Y});break;case"code":case"directive":case"thematicBreak":case"unsupported":break}if(J.stopped)return;if(p0(M.leaveBlock?.(A,Q),J))return}}function F6($,M,J,Z){for(let[X,A]of $.entries()){if(J.stopped)return;let Y=`${Z.pathPrefix}.${X}`,Q={block:Z.block,blockAncestors:Z.blockAncestors,inlineAncestors:Z.inlineAncestors,parentInline:Z.parentInline,path:Y},K=M.enterInline?.(A,Q);if(p0(K,J))return;if(K!=="skip"){if(A.type==="link")YZ(A.children,A,M,J,Z,Y)}if(J.stopped)return;if(p0(M.leaveInline?.(A,Q),J))return}}function FM(){return{stopped:!1}}function DM(){return{blockAncestors:[],depth:0,parentBlock:null,pathPrefix:"root"}}function GM($,M,J,Z,X,A){B6($,J,Z,{blockAncestors:[...X.blockAncestors,M],depth:X.depth+1,parentBlock:M,pathPrefix:`${A}.children`})}function YZ($,M,J,Z,X,A){F6($,J,Z,{block:X.block,blockAncestors:X.blockAncestors,inlineAncestors:[...X.inlineAncestors,M],parentInline:M,pathPrefix:`${A}.children`})}function QZ($,M,J,Z){for(let[X,A]of $.rows.entries())for(let[Y,Q]of A.cells.entries()){if(J.stopped)return;let K=`${Z.pathPrefix}.rows.${X}.cells.${Y}`,q={blockAncestors:Z.blockAncestors,cellIndex:Y,path:K,row:A,rowIndex:X,table:$},N=M.enterTableCell?.(Q,q);if(p0(N,J))return;if(N!=="skip")F6(Q.children,M,J,{block:$,blockAncestors:Z.blockAncestors,inlineAncestors:[],parentInline:null,pathPrefix:`${K}.children`});if(J.stopped)return;if(p0(M.leaveTableCell?.(Q,q),J))return}}function p0($,M){if($!=="stop")return!1;return M.stopped=!0,!0}var D6="text";function _6($){return $==="text"||$==="code"||$==="tableCell"}function s4($){return $===D6?void 0:$}function i4($){let M=[];return W2($,{enterBlock(J){switch(J.type){case"heading":case"paragraph":M.push({containerKind:"text",containerOrdinal:M.length,id:J.id,text:F1(J.children)});break;case"code":M.push({containerKind:"code",containerOrdinal:M.length,id:J.id,text:J.source});break}},enterTableCell(J){M.push({containerKind:"tableCell",containerOrdinal:M.length,id:J.id,text:F1(J.children)})}}),M}function _M($){let M=new Set;return W2($,{enterInline(J){if(J.type==="image")M.add(J.url)}}),[...M]}function l0($,M){let J=null;return KZ($,{enterBlock(Z){if(Z.id===M)return J=Z,"stop"}}),J}function KZ($,M){if(Array.isArray($)){BM($,M);return}W2($,M)}var HM=24;function T2($,M,J){let Z=r0(M,0,$.text.length),X=r0(J,Z,$.text.length);return{kind:s4($.containerKind),prefix:$.text.slice(Math.max(0,Z-HM),Z)||void 0,suffix:$.text.slice(X,X+HM)||void 0}}function y2($,M,J){let Z=r0(M,0,$.text.length),X=r0(J,Z,$.text.length);return $.text.slice(Z,X)}var PM=48,WM=64,qZ=32;function V2($,M){let J=$.anchor.kind??D6,Z=i4(M).filter((Y)=>Y.containerKind===J),X=NZ($,Z);if(X.length>0)return TM($,X,null);let A=UZ($,Z);if(A.length>0)return TM($,A,"repaired");return{match:null,repair:null,status:"stale"}}function NZ($,M){let J=[],Z=$.quote;if(Z.length===0)return J;for(let X of M){let A=0;while(A<=X.text.length){let Y=X.text.indexOf(Z,A);if(Y===-1)break;J.push({container:X,endOffset:Y+Z.length,score:FZ($,X,Y),startOffset:Y}),A=Y+Math.max(1,Z.length)}}return J.sort((X,A)=>A.score-X.score),J}function UZ($,M){let J=[];for(let Z of M)J.push(...GZ($,Z));return J.sort((Z,X)=>X.score-Z.score),J}function GZ($,M){let J=[],Z=$.quote.length,X=M.text,A=$.anchor.prefix??"",Y=$.anchor.suffix??"";if(A.length>0&&Y.length>0){let Q=0;while(Q<=X.length){let K=X.indexOf(A,Q);if(K===-1)break;let q=K+A.length,N=X.indexOf(Y,q);if(N!==-1&&N>=q)J.push({container:M,endOffset:N,score:H6($,M,q,N,Z),startOffset:q});Q=K+Math.max(1,A.length)}return J}if(A.length>0){let Q=0;while(Q<=X.length){let K=X.indexOf(A,Q);if(K===-1)break;let q=K+A.length,N=r0(q+Z,q,X.length);J.push({container:M,endOffset:N,score:H6($,M,q,N,Z),startOffset:q}),Q=K+Math.max(1,A.length)}return J}if(Y.length>0){let Q=0;while(Q<=X.length){let K=X.indexOf(Y,Q);if(K===-1)break;let q=K,N=r0(q-Z,0,q);J.push({container:M,endOffset:q,score:H6($,M,N,q,Z),startOffset:N}),Q=K+Math.max(1,Y.length)}}return J}function TM($,M,J){let[Z,X]=M;if(!Z)return{match:null,repair:null,status:"stale"};if(X&&Z.score===X.score)return{match:null,repair:null,status:"ambiguous"};let A=T2(Z.container,Z.startOffset,Z.endOffset),Y=y2(Z.container,Z.startOffset,Z.endOffset),Q=J??(Y===$.quote&&(A.prefix??"")===($.anchor.prefix??"")&&(A.suffix??"")===($.anchor.suffix??"")?"matched":"repaired");return{match:BZ(Z.container,Z.startOffset,Z.endOffset),repair:{anchor:A,quote:Y},status:Q}}function BZ($,M,J){return{containerId:$.id,containerKind:$.containerKind,containerOrdinal:$.containerOrdinal,endOffset:J,startOffset:M}}function FZ($,M,J){let Z=0;if(yM(M.text,$.anchor.prefix,J))Z+=PM;if(VM(M.text,$.anchor.suffix,J+$.quote.length))Z+=PM;return Z}function H6($,M,J,Z,X){let A=0;if(yM(M.text,$.anchor.prefix,J))A+=WM;if(VM(M.text,$.anchor.suffix,Z))A+=WM;if(A+=Math.max(0,qZ-Math.abs(X-(Z-J))),$.quote.length>0){let Y=M.text.slice(J,Z);if(Y.length>0)A+=DZ($.quote,Y),A+=_Z($.quote,Y)}return A}function yM($,M,J){if(!M)return!1;return $.slice(Math.max(0,J-M.length),J)===M}function VM($,M,J){if(!M)return!1;return $.slice(J,J+M.length)===M}function DZ($,M){let J=0;while(J<$.length&&J<M.length&&$[J]===M[J])J+=1;return J}function _Z($,M){let J=0;while(J<$.length&&J<M.length&&$[$.length-1-J]===M[M.length-1-J])J+=1;return J}function r0($,M,J){return Math.min(Math.max($,M),J)}function P6($){if(!$||typeof $!=="object"||Array.isArray($))return null;let M=$,J=PZ(M.anchor),Z=typeof M.quote==="string"?M.quote:null,X=Array.isArray(M.comments)?M.comments.flatMap((A)=>{let Y=HZ(A);return Y?[Y]:[]}):[];if(!J||!Z||X.length===0)return null;return{quote:Z,anchor:J,comments:X,resolvedAt:typeof M.resolvedAt==="string"?M.resolvedAt:void 0}}function HZ($){if(!$||typeof $!=="object"||Array.isArray($))return null;let M=$;if(typeof M.body!=="string"||typeof M.updatedAt!=="string")return null;return{body:M.body,updatedAt:M.updatedAt}}function PZ($){if(!$||typeof $!=="object"||Array.isArray($))return null;let{kind:M,prefix:J,suffix:Z}=$;if("kind"in $&&!_6(M)||"prefix"in $&&typeof J!=="string"||"suffix"in $&&typeof Z!=="string")return null;return{kind:_6(M)?s4(M):void 0,prefix:typeof J==="string"?J:void 0,suffix:typeof Z==="string"?Z:void 0}}function W6($){let M=$.createdAt??new Date().toISOString();return{comments:[zM({body:$.body,updatedAt:M})],quote:$.quote,anchor:$.anchor}}function T6($,M){let J=zM(M);return{...$,comments:[...$.comments,J]}}function y6($,M,J,Z=new Date().toISOString()){let X=J.trim();if(X.length===0)return $;let A=!1,Y=$.comments.map((Q,K)=>{if(K!==M||Q.body===X)return Q;return A=!0,{...Q,body:X,updatedAt:Z}});if(!A)return $;return{...$,comments:Y}}function V6($,M){let J=$.comments.filter((Z,X)=>X!==M);if(J.length===$.comments.length)return $;if(J.length===0)return null;return{...$,comments:J}}function z6($,M,J=new Date().toISOString()){if(A0($)===M)return $;return{...$,resolvedAt:M?J:void 0}}function A0($){return $.resolvedAt!=null}function O6($){return $.filter((M)=>A0(M)).length}function b6($){if($.comments.length===0)return null;return $.comments.reduce((M,J)=>J.updatedAt>M?J.updatedAt:M,$.comments[0].updatedAt)}function zM($){let M=$.updatedAt??new Date().toISOString();return{body:$.body,updatedAt:M}}function z0(){return{graphemeWidths:new Map,lineBoundaries:new Map,measuredContainerHeights:new Map,measuredLines:new Map,preparedText:new Map,viewportPlans:new WeakMap}}function OM($,M,J){return z2($.preparedText,M,J,256)}function bM($,M,J){return z2($.measuredLines,M,J,512)}function CM($,M,J){return z2($.lineBoundaries,M,J,1024)}function EM($,M,J){return z2($.measuredContainerHeights,M,J,1024)}function wM($,M){let J=$.graphemeWidths.get(M);if(J)return J;let Z=new Map;return z2($.graphemeWidths,M,Z,64),Z}function jM($,M,J){return $.viewportPlans.get(M)?.get(J)??null}function RM($,M,J,Z){let X=$.viewportPlans.get(M)??new Map;return X.set(J,Z),$.viewportPlans.set(M,X),Z}function z2($,M,J,Z){if($.has(M))$.delete(M);if($.set(M,J),$.size>Z){let X=$.keys().next().value;if(X!==void 0)$.delete(X)}return J}var WZ=["BN","BN","BN","BN","BN","BN","BN","BN","BN","S","B","S","WS","B","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","B","B","B","S","WS","ON","ON","ET","ET","ET","ON","ON","ON","ON","ON","ON","CS","ON","CS","ON","EN","EN","EN","EN","EN","EN","EN","EN","EN","EN","ON","ON","ON","ON","ON","ON","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","ON","ON","ON","ON","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","ON","ON","ON","BN","BN","BN","BN","BN","BN","B","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","CS","ON","ET","ET","ET","ET","ON","ON","ON","ON","L","ON","ON","ON","ON","ON","ET","ET","EN","EN","ON","L","ON","ON","ON","EN","L","ON","ON","ON","ON","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","L","L","L","L","L","L","L","L"],TZ=["AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","CS","AL","ON","ON","NSM","NSM","NSM","NSM","NSM","NSM","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","AL","AL","AL","AL","AL","AL","AL","AN","AN","AN","AN","AN","AN","AN","AN","AN","AN","ET","AN","AN","AL","AL","AL","NSM","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","ON","NSM","NSM","NSM","NSM","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL"];function yZ($){if($<=255)return WZ[$];if(1424<=$&&$<=1524)return"R";if(1536<=$&&$<=1791)return TZ[$&255];if(1792<=$&&$<=2220)return"AL";return"L"}function VZ($){let M=$.length;if(M===0)return null;let J=Array(M),Z=0;for(let q=0;q<M;q++){let N=yZ($.charCodeAt(q));if(N==="R"||N==="AL"||N==="AN")Z++;J[q]=N}if(Z===0)return null;let X=M/Z<0.3?0:1,A=new Int8Array(M);for(let q=0;q<M;q++)A[q]=X;let Y=X&1?"R":"L",Q=Y,K=Q;for(let q=0;q<M;q++)if(J[q]==="NSM")J[q]=K;else K=J[q];K=Q;for(let q=0;q<M;q++){let N=J[q];if(N==="EN")J[q]=K==="AL"?"AN":"EN";else if(N==="R"||N==="L"||N==="AL")K=N}for(let q=0;q<M;q++)if(J[q]==="AL")J[q]="R";for(let q=1;q<M-1;q++){if(J[q]==="ES"&&J[q-1]==="EN"&&J[q+1]==="EN")J[q]="EN";if(J[q]==="CS"&&(J[q-1]==="EN"||J[q-1]==="AN")&&J[q+1]===J[q-1])J[q]=J[q-1]}for(let q=0;q<M;q++){if(J[q]!=="EN")continue;let N;for(N=q-1;N>=0&&J[N]==="ET";N--)J[N]="EN";for(N=q+1;N<M&&J[N]==="ET";N++)J[N]="EN"}for(let q=0;q<M;q++){let N=J[q];if(N==="WS"||N==="ES"||N==="ET"||N==="CS")J[q]="ON"}K=Q;for(let q=0;q<M;q++){let N=J[q];if(N==="EN")J[q]=K==="L"?"L":"EN";else if(N==="R"||N==="L")K=N}for(let q=0;q<M;q++){if(J[q]!=="ON")continue;let N=q+1;while(N<M&&J[N]==="ON")N++;let U=q>0?J[q-1]:Q,G=N<M?J[N]:Q,B=U!=="L"?"R":"L";if(B===(G!=="L"?"R":"L"))for(let F=q;F<N;F++)J[F]=B;q=N-1}for(let q=0;q<M;q++)if(J[q]==="ON")J[q]=Y;for(let q=0;q<M;q++){let N=J[q];if((A[q]&1)===0){if(N==="R")A[q]++;else if(N==="AN"||N==="EN")A[q]+=2}else if(N==="L"||N==="AN"||N==="EN")A[q]++}return A}function LM($,M){let J=VZ($);if(J===null)return null;let Z=new Int8Array(M.length);for(let X=0;X<M.length;X++)Z[X]=J[M[X]];return Z}var zZ=/[ \t\n\r\f]+/g,OZ=/[\t\n\r\f]| {2,}|^ | $/;function bZ($){let M=$??"normal";return M==="pre-wrap"?{mode:M,preserveOrdinarySpaces:!0,preserveHardBreaks:!0}:{mode:M,preserveOrdinarySpaces:!1,preserveHardBreaks:!1}}function CZ($){if(!OZ.test($))return $;let M=$.replace(zZ," ");if(M.charCodeAt(0)===32)M=M.slice(1);if(M.length>0&&M.charCodeAt(M.length-1)===32)M=M.slice(0,-1);return M}function EZ($){if(!/[\r\f]/.test($))return $.replace(/\r\n/g,`
7
+ `).trim()}function H8($,M){return M5($,`root.${M}`)}function M5($,M){switch($.type){case"blockquote":{let Z=$.children.map((X,Y)=>M5(X,`${M}.children.${Y}`)),J=v1(Z);return{children:Z,id:X0("blockquote",M,J),plainText:J,type:"blockquote"}}case"code":return{id:X0("code",M,`${$.language??""}:${$.source}`),language:$.language,meta:$.meta,plainText:$.source,source:$.source,type:"code"};case"directive":return{attributes:$.attributes,body:$.body,id:X0("directive",M,`${$.name}{${$.attributes}}:${$.body}`),name:$.name,plainText:$.body,type:"directive"};case"heading":{let Z=$.children.map((X,Y)=>Z5(X,`${M}.children.${Y}`)),J=A0(Z);return{children:Z,depth:$.depth,id:X0("heading",M,`${$.depth}:${J}`),plainText:J,type:"heading"}}case"list":{let Z=$.items.map((X,Y)=>M5(X,`${M}.children.${Y}`)),J=Z.map((X)=>X.plainText).join(`
8
+ `);return{id:X0("list",M,`${String($.ordered)}:${J}`),items:Z,ordered:$.ordered,plainText:J,spread:$.spread,start:$.start,type:"list"}}case"listItem":{let Z=$.children.map((X,Y)=>M5(X,`${M}.children.${Y}`)),J=v1(Z);return{checked:$.checked,children:Z,id:X0("listItem",M,J),plainText:J,spread:$.spread,type:"listItem"}}case"paragraph":{let Z=$.children.map((X,Y)=>Z5(X,`${M}.children.${Y}`)),J=A0(Z);return{children:Z,id:X0("paragraph",M,J),plainText:J,type:"paragraph"}}case"table":{let Z=$.rows.map((X,Y)=>QJ(X,`${M}.rows.${Y}`)),J=Z.map((X)=>X.cells.map((Y)=>Y.plainText).join(" | ")).join(`
9
+ `);return{align:$.align,id:X0("table",M,J),plainText:J,rows:Z,type:"table"}}case"thematicBreak":return{id:X0("thematicBreak",M,"thematic-break"),plainText:"",type:"thematicBreak"};case"unsupported":return{id:X0("unsupported",M,$.source),originalType:$.originalType,plainText:$.source,source:$.source,type:"unsupported"}}}function QJ($,M){return{cells:$.cells.map((Z,J)=>{let X=Z.children.map((Q,K)=>Z5(Q,`${M}.cells.${J}.children.${K}`)),Y=A0(X);return{children:X,id:X0("tableCell",`${M}.cells.${J}`,Y),plainText:Y}}),id:X0("tableRow",M,String($.cells.length))}}function Z5($,M){switch($.type){case"break":return{id:X0("break",M,"break"),type:"break"};case"image":return{alt:$.alt,id:X0("image",M,`${$.url}:${$.width??""}:${$.alt??""}`),title:$.title,type:"image",url:$.url,width:$.width};case"inlineCode":return{code:$.code,id:X0("inlineCode",M,$.code),type:"inlineCode"};case"link":{let Z=$.children.map((X,Y)=>Z5(X,`${M}.children.${Y}`)),J=A0(Z);return{children:Z,id:X0("link",M,`${$.url}:${J}`),title:$.title,type:"link",url:$.url}}case"text":return{id:X0("text",M,`${$.text}:${$.marks.join(",")}`),marks:$.marks,text:$.text,type:"text"};case"unsupported":return{id:X0("unsupported",M,$.source),originalType:$.originalType,source:$.source,type:"unsupported"}}}function H2($){return $.map((M)=>{switch(M.type){case"blockquote":return{...M,children:H2(M.children)};case"heading":case"paragraph":return R0(M,P8(M.children));case"list":return{...M,items:M.items.map((Z)=>({...Z,children:H2(Z.children)}))};case"listItem":return{...M,children:H2(M.children)};case"table":return h0(M,M.rows.map((Z)=>({...Z,cells:Z.cells.map((J)=>({...J,children:P8(J.children)}))})));default:return M}})}function P8($){let M=[...$];for(let Z=M.length-1;Z>=0;Z-=1){let J=M[Z];if(J.type==="text"){let X=J.text.replace(/[ \t]+$/u,"");if(X.length===J.text.length)return M;if(X.length===0){M.splice(Z,1);continue}return M[Z]={...J,text:X},M}if(J.type==="link"){let X=P8(J.children);if(X.length===J.children.length&&X.every((Y,Q)=>Y===J.children[Q]))return M;if(X.length===0){M.splice(Z,1);continue}return M[Z]={...J,children:X},M}return M}return M}function X0($,M,Z){let J=2166136261;for(let X of`${$}:${M}:${Z}`)J^=X.charCodeAt(0),J=Math.imul(J,16777619);return`${$}-${(J>>>0).toString(36)}`}function P2($,M){z8($.blocks,M,y$(),W$())}function T$($,M){z8($,M,y$(),W$())}function z8($,M,Z,J){for(let[X,Y]of $.entries()){if(Z.stopped)return;let Q=`${J.pathPrefix}.${X}`,K={blockAncestors:J.blockAncestors,depth:J.depth,parentBlock:J.parentBlock,path:Q},q=M.enterBlock?.(Y,K);if(I1(q,Z))return;if(q!=="skip")switch(Y.type){case"list":z$(Y.items,Y,M,Z,J,Q);break;case"blockquote":case"listItem":z$(Y.children,Y,M,Z,J,Q);break;case"heading":case"paragraph":T8(Y.children,M,Z,{block:Y,blockAncestors:[...J.blockAncestors,Y],inlineAncestors:[],parentInline:null,pathPrefix:`${Q}.children`});break;case"table":qJ(Y,M,Z,{blockAncestors:[...J.blockAncestors,Y],pathPrefix:Q});break;case"code":case"directive":case"thematicBreak":case"unsupported":break}if(Z.stopped)return;if(I1(M.leaveBlock?.(Y,K),Z))return}}function T8($,M,Z,J){for(let[X,Y]of $.entries()){if(Z.stopped)return;let Q=`${J.pathPrefix}.${X}`,K={block:J.block,blockAncestors:J.blockAncestors,inlineAncestors:J.inlineAncestors,parentInline:J.parentInline,path:Q},q=M.enterInline?.(Y,K);if(I1(q,Z))return;if(q!=="skip"){if(Y.type==="link")KJ(Y.children,Y,M,Z,J,Q)}if(Z.stopped)return;if(I1(M.leaveInline?.(Y,K),Z))return}}function y$(){return{stopped:!1}}function W$(){return{blockAncestors:[],depth:0,parentBlock:null,pathPrefix:"root"}}function z$($,M,Z,J,X,Y){z8($,Z,J,{blockAncestors:[...X.blockAncestors,M],depth:X.depth+1,parentBlock:M,pathPrefix:`${Y}.children`})}function KJ($,M,Z,J,X,Y){T8($,Z,J,{block:X.block,blockAncestors:X.blockAncestors,inlineAncestors:[...X.inlineAncestors,M],parentInline:M,pathPrefix:`${Y}.children`})}function qJ($,M,Z,J){for(let[X,Y]of $.rows.entries())for(let[Q,K]of Y.cells.entries()){if(Z.stopped)return;let q=`${J.pathPrefix}.rows.${X}.cells.${Q}`,U={blockAncestors:J.blockAncestors,cellIndex:Q,path:q,row:Y,rowIndex:X,table:$},N=M.enterTableCell?.(K,U);if(I1(N,Z))return;if(N!=="skip")T8(K.children,M,Z,{block:$,blockAncestors:J.blockAncestors,inlineAncestors:[],parentInline:null,pathPrefix:`${q}.children`});if(Z.stopped)return;if(I1(M.leaveTableCell?.(K,U),Z))return}}function I1($,M){if($!=="stop")return!1;return M.stopped=!0,!0}var y8="text";function W8($){return $==="text"||$==="code"||$==="tableCell"}function V8($){return $===y8?void 0:$}function w$($){switch($){case"heading":case"paragraph":return"text";case"code":return"code";default:return null}}function J5($){let M=[];return P2($,{enterBlock(Z){switch(Z.type){case"heading":case"paragraph":M.push({containerKind:"text",containerOrdinal:M.length,id:Z.id,text:A0(Z.children)});break;case"code":M.push({containerKind:"code",containerOrdinal:M.length,id:Z.id,text:Z.source});break}},enterTableCell(Z){M.push({containerKind:"tableCell",containerOrdinal:M.length,id:Z.id,text:A0(Z.children)})}}),M}function w8($,M,Z){return{prefix:$.slice(Math.max(0,M-V$),M),suffix:$.slice(Z,Math.min($.length,Z+V$))}}function z2($,M,Z){let J=L0(M,0,$.text.length),X=L0(Z,J,$.text.length),{prefix:Y,suffix:Q}=w8($.text,J,X);return{kind:V8($.containerKind),prefix:Y||void 0,suffix:Q||void 0}}function T2($,M,Z){let J=L0(M,0,$.text.length),X=L0(Z,J,$.text.length);return $.text.slice(J,X)}function g0($,M){if(M.length===0)return[];let Z=[],J=0;while(J<=$.length){let X=$.indexOf(M,J);if(X===-1)break;Z.push(X),J=X+Math.max(1,M.length)}return Z}function p1($,M,Z){if(M.length===0||Z.length===0)return[];let J=[];for(let X of g0($,M)){let Y=X+M.length,Q=$.indexOf(Z,Y);if(Q!==-1)J.push({startOffset:Y,endOffset:Q})}return J}function O8($,M,Z){if(!M)return!1;return $.slice(Math.max(0,Z-M.length),Z)===M}function E8($,M,Z){if(!M)return!1;return $.slice(Z,Z+M.length)===M}var V$=24;function L0($,M,Z){return Math.min(Math.max($,M),Z)}var O$=48,E$=64,UJ=32;function y2($,M){let Z=$.anchor.kind??y8,J=J5(M).filter((Q)=>Q.containerKind===Z),X=NJ($,J);if(X.length>0)return C$($,X,null);let Y=AJ($,J);if(Y.length>0)return C$($,Y,"repaired");return{match:null,repair:null,status:"stale"}}function NJ($,M){let Z=[],J=$.quote;if(J.length===0)return Z;for(let X of M)for(let Y of g0(X.text,J))Z.push({container:X,endOffset:Y+J.length,score:_J($,X,Y),startOffset:Y});return Z.sort((X,Y)=>Y.score-X.score),Z}function AJ($,M){let Z=[];for(let J of M)Z.push(...GJ($,J));return Z.sort((J,X)=>X.score-J.score),Z}function GJ($,M){let Z=[],J=$.quote.length,X=M.text,Y=$.anchor.prefix??"",Q=$.anchor.suffix??"";if(Y.length>0&&Q.length>0){for(let K of p1(X,Y,Q))Z.push({container:M,endOffset:K.endOffset,score:C8($,M,K.startOffset,K.endOffset,J),startOffset:K.startOffset});return Z}if(Y.length>0){for(let K of g0(X,Y)){let q=K+Y.length,U=L0(q+J,q,X.length);Z.push({container:M,endOffset:U,score:C8($,M,q,U,J),startOffset:q})}return Z}if(Q.length>0)for(let K of g0(X,Q)){let q=K,U=L0(q-J,0,q);Z.push({container:M,endOffset:q,score:C8($,M,U,q,J),startOffset:U})}return Z}function C$($,M,Z){let[J,X]=M;if(!J)return{match:null,repair:null,status:"stale"};if(X&&J.score===X.score)return{match:null,repair:null,status:"ambiguous"};let Y=z2(J.container,J.startOffset,J.endOffset),Q=T2(J.container,J.startOffset,J.endOffset),K=Z??(Q===$.quote&&(Y.prefix??"")===($.anchor.prefix??"")&&(Y.suffix??"")===($.anchor.suffix??"")?"matched":"repaired");return{match:BJ(J.container,J.startOffset,J.endOffset),repair:{anchor:Y,quote:Q},status:K}}function BJ($,M,Z){return{containerId:$.id,containerKind:$.containerKind,containerOrdinal:$.containerOrdinal,endOffset:Z,startOffset:M}}function _J($,M,Z){let J=0;if(O8(M.text,$.anchor.prefix,Z))J+=O$;if(E8(M.text,$.anchor.suffix,Z+$.quote.length))J+=O$;return J}function C8($,M,Z,J,X){let Y=0;if(O8(M.text,$.anchor.prefix,Z))Y+=E$;if(E8(M.text,$.anchor.suffix,J))Y+=E$;if(Y+=Math.max(0,UJ-Math.abs(X-(J-Z))),$.quote.length>0){let Q=M.text.slice(Z,J);if(Q.length>0)Y+=FJ($.quote,Q),Y+=bJ($.quote,Q)}return Y}function FJ($,M){let Z=0;while(Z<$.length&&Z<M.length&&$[Z]===M[Z])Z+=1;return Z}function bJ($,M){let Z=0;while(Z<$.length&&Z<M.length&&$[$.length-1-Z]===M[M.length-1-Z])Z+=1;return Z}function j8($){if(!$||typeof $!=="object"||Array.isArray($))return null;let M=$,Z=HJ(M.anchor),J=typeof M.quote==="string"?M.quote:null,X=Array.isArray(M.comments)?M.comments.flatMap((Y)=>{let Q=DJ(Y);return Q?[Q]:[]}):[];if(!Z||!J||X.length===0)return null;return{quote:J,anchor:Z,comments:X,resolvedAt:typeof M.resolvedAt==="string"?M.resolvedAt:void 0}}function DJ($){if(!$||typeof $!=="object"||Array.isArray($))return null;let M=$;if(typeof M.body!=="string"||typeof M.updatedAt!=="string")return null;return{body:M.body,updatedAt:M.updatedAt}}function HJ($){if(!$||typeof $!=="object"||Array.isArray($))return null;let{kind:M,prefix:Z,suffix:J}=$;if("kind"in $&&!W8(M)||"prefix"in $&&typeof Z!=="string"||"suffix"in $&&typeof J!=="string")return null;return{kind:W8(M)?V8(M):void 0,prefix:typeof Z==="string"?Z:void 0,suffix:typeof J==="string"?J:void 0}}function R8($){let M=$.createdAt??new Date().toISOString();return{comments:[j$({body:$.body,updatedAt:M})],quote:$.quote,anchor:$.anchor}}function L8($,M){let Z=j$(M);return{...$,comments:[...$.comments,Z]}}function k8($,M,Z,J=new Date().toISOString()){let X=Z.trim();if(X.length===0)return $;let Y=!1,Q=$.comments.map((K,q)=>{if(q!==M||K.body===X)return K;return Y=!0,{...K,body:X,updatedAt:J}});if(!Y)return $;return{...$,comments:Q}}function f8($,M){let Z=$.comments.filter((J,X)=>X!==M);if(Z.length===$.comments.length)return $;if(Z.length===0)return null;return{...$,comments:Z}}function m8($,M,Z=new Date().toISOString()){if(Z1($)===M)return $;return{...$,resolvedAt:M?Z:void 0}}function Z1($){return $.resolvedAt!=null}function S8($){return $.filter((M)=>Z1(M)).length}function u8($){if($.comments.length===0)return null;return $.comments.reduce((M,Z)=>Z.updatedAt>M?Z.updatedAt:M,$.comments[0].updatedAt)}function j$($){let M=$.updatedAt??new Date().toISOString();return{body:$.body,updatedAt:M}}function R$($){let M=new Set;return P2($,{enterInline(Z){if(Z.type==="image")M.add(Z.url)}}),[...M]}function l1($,M){let Z=null;return PJ($,{enterBlock(J){if(J.id===M)return Z=J,"stop"}}),Z}function PJ($,M){if(Array.isArray($)){T$($,M);return}P2($,M)}function T1(){return{graphemeWidths:new Map,lineBoundaries:new Map,measuredContainerHeights:new Map,measuredLines:new Map,preparedText:new Map,viewportPlans:new WeakMap}}function L$($,M,Z){return W2($.preparedText,M,Z,256)}function k$($,M,Z){return W2($.measuredLines,M,Z,512)}function f$($,M,Z){return W2($.lineBoundaries,M,Z,1024)}function m$($,M,Z){return W2($.measuredContainerHeights,M,Z,1024)}function S$($,M){let Z=$.graphemeWidths.get(M);if(Z)return Z;let J=new Map;return W2($.graphemeWidths,M,J,64),J}function u$($,M,Z){return $.viewportPlans.get(M)?.get(Z)??null}function v$($,M,Z,J){let X=$.viewportPlans.get(M)??new Map;return X.set(Z,J),$.viewportPlans.set(M,X),J}function W2($,M,Z,J){if($.has(M))$.delete(M);if($.set(M,Z),$.size>J){let X=$.keys().next().value;if(X!==void 0)$.delete(X)}return Z}var zJ=["BN","BN","BN","BN","BN","BN","BN","BN","BN","S","B","S","WS","B","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","B","B","B","S","WS","ON","ON","ET","ET","ET","ON","ON","ON","ON","ON","ON","CS","ON","CS","ON","EN","EN","EN","EN","EN","EN","EN","EN","EN","EN","ON","ON","ON","ON","ON","ON","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","ON","ON","ON","ON","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","ON","ON","ON","BN","BN","BN","BN","BN","BN","B","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","BN","CS","ON","ET","ET","ET","ET","ON","ON","ON","ON","L","ON","ON","ON","ON","ON","ET","ET","EN","EN","ON","L","ON","ON","ON","EN","L","ON","ON","ON","ON","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","L","ON","L","L","L","L","L","L","L","L"],TJ=["AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","CS","AL","ON","ON","NSM","NSM","NSM","NSM","NSM","NSM","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","AL","AL","AL","AL","AL","AL","AL","AN","AN","AN","AN","AN","AN","AN","AN","AN","AN","ET","AN","AN","AL","AL","AL","NSM","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","NSM","ON","NSM","NSM","NSM","NSM","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL","AL"];function yJ($){if($<=255)return zJ[$];if(1424<=$&&$<=1524)return"R";if(1536<=$&&$<=1791)return TJ[$&255];if(1792<=$&&$<=2220)return"AL";return"L"}function WJ($){let M=$.length;if(M===0)return null;let Z=Array(M),J=0;for(let U=0;U<M;U++){let N=yJ($.charCodeAt(U));if(N==="R"||N==="AL"||N==="AN")J++;Z[U]=N}if(J===0)return null;let X=M/J<0.3?0:1,Y=new Int8Array(M);for(let U=0;U<M;U++)Y[U]=X;let Q=X&1?"R":"L",K=Q,q=K;for(let U=0;U<M;U++)if(Z[U]==="NSM")Z[U]=q;else q=Z[U];q=K;for(let U=0;U<M;U++){let N=Z[U];if(N==="EN")Z[U]=q==="AL"?"AN":"EN";else if(N==="R"||N==="L"||N==="AL")q=N}for(let U=0;U<M;U++)if(Z[U]==="AL")Z[U]="R";for(let U=1;U<M-1;U++){if(Z[U]==="ES"&&Z[U-1]==="EN"&&Z[U+1]==="EN")Z[U]="EN";if(Z[U]==="CS"&&(Z[U-1]==="EN"||Z[U-1]==="AN")&&Z[U+1]===Z[U-1])Z[U]=Z[U-1]}for(let U=0;U<M;U++){if(Z[U]!=="EN")continue;let N;for(N=U-1;N>=0&&Z[N]==="ET";N--)Z[N]="EN";for(N=U+1;N<M&&Z[N]==="ET";N++)Z[N]="EN"}for(let U=0;U<M;U++){let N=Z[U];if(N==="WS"||N==="ES"||N==="ET"||N==="CS")Z[U]="ON"}q=K;for(let U=0;U<M;U++){let N=Z[U];if(N==="EN")Z[U]=q==="L"?"L":"EN";else if(N==="R"||N==="L")q=N}for(let U=0;U<M;U++){if(Z[U]!=="ON")continue;let N=U+1;while(N<M&&Z[N]==="ON")N++;let A=U>0?Z[U-1]:K,G=N<M?Z[N]:K,B=A!=="L"?"R":"L";if(B===(G!=="L"?"R":"L"))for(let _=U;_<N;_++)Z[_]=B;U=N-1}for(let U=0;U<M;U++)if(Z[U]==="ON")Z[U]=Q;for(let U=0;U<M;U++){let N=Z[U];if((Y[U]&1)===0){if(N==="R")Y[U]++;else if(N==="AN"||N==="EN")Y[U]+=2}else if(N==="L"||N==="AN"||N==="EN")Y[U]++}return Y}function h$($,M){let Z=WJ($);if(Z===null)return null;let J=new Int8Array(M.length);for(let X=0;X<M.length;X++)J[X]=Z[M[X]];return J}var VJ=/[ \t\n\r\f]+/g,wJ=/[\t\n\r\f]| {2,}|^ | $/;function OJ($){let M=$??"normal";return M==="pre-wrap"?{mode:M,preserveOrdinarySpaces:!0,preserveHardBreaks:!0}:{mode:M,preserveOrdinarySpaces:!1,preserveHardBreaks:!1}}function EJ($){if(!wJ.test($))return $;let M=$.replace(VJ," ");if(M.charCodeAt(0)===32)M=M.slice(1);if(M.length>0&&M.charCodeAt(M.length-1)===32)M=M.slice(0,-1);return M}function CJ($){if(!/[\r\f]/.test($))return $.replace(/\r\n/g,`
10
10
  `);return $.replace(/\r\n/g,`
11
11
  `).replace(/[\r\f]/g,`
12
- `)}var C6=null,wZ;function jZ(){if(C6===null)C6=new Intl.Segmenter(wZ,{granularity:"word"});return C6}var RZ=/\p{Script=Arabic}/u,o4=/\p{M}/u,uM=/\p{Nd}/u;function E6($){return RZ.test($)}function t1($){for(let M of $){let J=M.codePointAt(0);if(J>=19968&&J<=40959||J>=13312&&J<=19903||J>=131072&&J<=173791||J>=173824&&J<=177983||J>=177984&&J<=178207||J>=178208&&J<=183983||J>=183984&&J<=191471||J>=196608&&J<=201551||J>=63744&&J<=64255||J>=194560&&J<=195103||J>=12288&&J<=12351||J>=12352&&J<=12447||J>=12448&&J<=12543||J>=44032&&J<=55215||J>=65280&&J<=65519)return!0}return!1}var R6=new Set([",",".","!",":",";","?","、","。","・",")","〕","〉","》","」","』","】","〗","〙","〛","ー","々","〻","ゝ","ゞ","ヽ","ヾ"]),O2=new Set(['"',"(","[","{","“","‘","«","‹","(","〔","〈","《","「","『","【","〖","〘","〚"]),L6=new Set(["'","’"]),c0=new Set([".",",","!","?",":",";","،","؛","؟","।","॥","၊","။","၌","၍","၏",")","]","}","%",'"',"”","’","»","›","…"]),LZ=new Set([":",".","،","؛"]),kZ=new Set(["၏"]),fZ=new Set(["”","’","»","›","」","』","】","》","〉","〕",")"]);function uZ($){if(k6($))return!0;let M=!1;for(let J of $){if(c0.has(J)){M=!0;continue}if(M&&o4.test(J))continue;return!1}return M}function SZ($){for(let M of $)if(!R6.has(M)&&!c0.has(M))return!1;return $.length>0}function mZ($){if(k6($))return!0;for(let M of $)if(!O2.has(M)&&!L6.has(M)&&!o4.test(M))return!1;return $.length>0}function k6($){let M=!1;for(let J of $){if(J==="\\"||o4.test(J))continue;if(O2.has(J)||c0.has(J)||L6.has(J)){M=!0;continue}return!1}return M}function vZ($){let M=Array.from($),J=M.length;while(J>0){let Z=M[J-1];if(o4.test(Z)){J--;continue}if(O2.has(Z)||L6.has(Z)){J--;continue}break}if(J<=0||J===M.length)return null;return{head:M.slice(0,J).join(""),tail:M.slice(J).join("")}}function gZ($,M){if($.length===0)return!1;for(let J of $)if(J!==M)return!1;return!0}function hZ($){if(!E6($)||$.length===0)return!1;return LZ.has($[$.length-1])}function IZ($){if($.length===0)return!1;return kZ.has($[$.length-1])}function pZ($){if($.length<2||$[0]!==" ")return null;let M=$.slice(1);if(/^\p{M}+$/u.test(M))return{space:" ",marks:M};return null}function f6($){for(let M=$.length-1;M>=0;M--){let J=$[M];if(fZ.has(J))return!0;if(!c0.has(J))return!1}return!1}function lZ($,M){if(M.preserveOrdinarySpaces||M.preserveHardBreaks){if($===" ")return"preserved-space";if($==="\t")return"tab";if(M.preserveHardBreaks&&$===`
13
- `)return"hard-break"}if($===" ")return"space";if($===" "||$===" "||$==="⁠"||$==="\uFEFF")return"glue";if($==="​")return"zero-width-break";if($==="­")return"soft-hyphen";return"text"}function e1($){return $.length===1?$[0]:$.join("")}function rZ($,M,J,Z){let X=[],A=null,Y=[],Q=J,K=!1,q=0;for(let N of $){let U=lZ(N,Z),G=U==="text"&&M;if(A!==null&&U===A&&G===K){Y.push(N),q+=N.length;continue}if(A!==null)X.push({text:e1(Y),isWordLike:K,kind:A,start:Q});A=U,Y=[N],Q=J+q,K=G,q+=N.length}if(A!==null)X.push({text:e1(Y),isWordLike:K,kind:A,start:Q});return X}function w6($){return $==="space"||$==="preserved-space"||$==="zero-width-break"||$==="hard-break"}var cZ=/^[A-Za-z][A-Za-z0-9+.-]*:$/;function xZ($,M){let J=$.texts[M];if(J.startsWith("www."))return!0;return cZ.test(J)&&M+1<$.len&&$.kinds[M+1]==="text"&&$.texts[M+1]==="//"}function dZ($){return $.includes("?")&&($.includes("://")||$.startsWith("www."))}function aZ($){let M=$.texts.slice(),J=$.isWordLike.slice(),Z=$.kinds.slice(),X=$.starts.slice();for(let Y=0;Y<$.len;Y++){if(Z[Y]!=="text"||!xZ($,Y))continue;let Q=[M[Y]],K=Y+1;while(K<$.len&&!w6(Z[K])){Q.push(M[K]),J[Y]=!0;let q=M[K].includes("?");if(Z[K]="text",M[K]="",K++,q)break}M[Y]=e1(Q)}let A=0;for(let Y=0;Y<M.length;Y++){let Q=M[Y];if(Q.length===0)continue;if(A!==Y)M[A]=Q,J[A]=J[Y],Z[A]=Z[Y],X[A]=X[Y];A++}return M.length=A,J.length=A,Z.length=A,X.length=A,{len:A,texts:M,isWordLike:J,kinds:Z,starts:X}}function sZ($){let M=[],J=[],Z=[],X=[];for(let A=0;A<$.len;A++){let Y=$.texts[A];if(M.push(Y),J.push($.isWordLike[A]),Z.push($.kinds[A]),X.push($.starts[A]),!dZ(Y))continue;let Q=A+1;if(Q>=$.len||w6($.kinds[Q]))continue;let K=[],q=$.starts[Q],N=Q;while(N<$.len&&!w6($.kinds[N]))K.push($.texts[N]),N++;if(K.length>0)M.push(e1(K)),J.push(!0),Z.push("text"),X.push(q),A=N-1}return{len:M.length,texts:M,isWordLike:J,kinds:Z,starts:X}}var iZ=new Set([":","-","/","×",",",".","+","–","—"]),kM=/^[A-Za-z0-9_]+[,:;]*$/,fM=/[,:;]+$/;function SM($){for(let M of $)if(uM.test(M))return!0;return!1}function j6($){if($.length===0)return!1;for(let M of $){if(uM.test(M)||iZ.has(M))continue;return!1}return!0}function oZ($){let M=[],J=[],Z=[],X=[];for(let A=0;A<$.len;A++){let Y=$.texts[A],Q=$.kinds[A];if(Q==="text"&&j6(Y)&&SM(Y)){let K=[Y],q=A+1;while(q<$.len&&$.kinds[q]==="text"&&j6($.texts[q]))K.push($.texts[q]),q++;M.push(e1(K)),J.push(!0),Z.push("text"),X.push($.starts[A]),A=q-1;continue}M.push(Y),J.push($.isWordLike[A]),Z.push(Q),X.push($.starts[A])}return{len:M.length,texts:M,isWordLike:J,kinds:Z,starts:X}}function nZ($){let M=[],J=[],Z=[],X=[];for(let A=0;A<$.len;A++){let Y=$.texts[A],Q=$.kinds[A],K=$.isWordLike[A];if(Q==="text"&&K&&kM.test(Y)){let q=[Y],N=fM.test(Y),U=A+1;while(N&&U<$.len&&$.kinds[U]==="text"&&$.isWordLike[U]&&kM.test($.texts[U])){let G=$.texts[U];q.push(G),N=fM.test(G),U++}M.push(e1(q)),J.push(!0),Z.push("text"),X.push($.starts[A]),A=U-1;continue}M.push(Y),J.push(K),Z.push(Q),X.push($.starts[A])}return{len:M.length,texts:M,isWordLike:J,kinds:Z,starts:X}}function tZ($){let M=[],J=[],Z=[],X=[];for(let A=0;A<$.len;A++){let Y=$.texts[A];if($.kinds[A]==="text"&&Y.includes("-")){let Q=Y.split("-"),K=Q.length>1;for(let q=0;q<Q.length;q++){let N=Q[q];if(!K)break;if(N.length===0||!SM(N)||!j6(N))K=!1}if(K){let q=0;for(let N=0;N<Q.length;N++){let U=Q[N],G=N<Q.length-1?`${U}-`:U;M.push(G),J.push(!0),Z.push("text"),X.push($.starts[A]+q),q+=G.length}continue}}M.push(Y),J.push($.isWordLike[A]),Z.push($.kinds[A]),X.push($.starts[A])}return{len:M.length,texts:M,isWordLike:J,kinds:Z,starts:X}}function eZ($){let M=[],J=[],Z=[],X=[],A=0;while(A<$.len){let Y=[$.texts[A]],Q=$.isWordLike[A],K=$.kinds[A],q=$.starts[A];if(K==="glue"){let N=[Y[0]],U=q;A++;while(A<$.len&&$.kinds[A]==="glue")N.push($.texts[A]),A++;let G=e1(N);if(A<$.len&&$.kinds[A]==="text")Y[0]=G,Y.push($.texts[A]),Q=$.isWordLike[A],K="text",q=U,A++;else{M.push(G),J.push(!1),Z.push("glue"),X.push(U);continue}}else A++;if(K==="text")while(A<$.len&&$.kinds[A]==="glue"){let N=[];while(A<$.len&&$.kinds[A]==="glue")N.push($.texts[A]),A++;let U=e1(N);if(A<$.len&&$.kinds[A]==="text"){Y.push(U,$.texts[A]),Q=Q||$.isWordLike[A],A++;continue}Y.push(U)}M.push(e1(Y)),J.push(Q),Z.push(K),X.push(q)}return{len:M.length,texts:M,isWordLike:J,kinds:Z,starts:X}}function $X($){let M=$.texts.slice(),J=$.isWordLike.slice(),Z=$.kinds.slice(),X=$.starts.slice();for(let A=0;A<M.length-1;A++){if(Z[A]!=="text"||Z[A+1]!=="text")continue;if(!t1(M[A])||!t1(M[A+1]))continue;let Y=vZ(M[A]);if(Y===null)continue;M[A]=Y.head,M[A+1]=Y.tail+M[A+1],X[A+1]=X[A]+Y.head.length}return{len:M.length,texts:M,isWordLike:J,kinds:Z,starts:X}}function MX($,M,J){let Z=jZ(),X=0,A=[],Y=[],Q=[],K=[];for(let G of Z.segment($))for(let B of rZ(G.segment,G.isWordLike??!1,G.index,J)){let D=B.kind==="text";if(M.carryCJKAfterClosingQuote&&D&&X>0&&Q[X-1]==="text"&&t1(B.text)&&t1(A[X-1])&&f6(A[X-1]))A[X-1]+=B.text,Y[X-1]=Y[X-1]||B.isWordLike;else if(D&&X>0&&Q[X-1]==="text"&&SZ(B.text)&&t1(A[X-1]))A[X-1]+=B.text,Y[X-1]=Y[X-1]||B.isWordLike;else if(D&&X>0&&Q[X-1]==="text"&&IZ(A[X-1]))A[X-1]+=B.text,Y[X-1]=Y[X-1]||B.isWordLike;else if(D&&X>0&&Q[X-1]==="text"&&B.isWordLike&&E6(B.text)&&hZ(A[X-1]))A[X-1]+=B.text,Y[X-1]=!0;else if(D&&!B.isWordLike&&X>0&&Q[X-1]==="text"&&B.text.length===1&&B.text!=="-"&&B.text!=="—"&&gZ(A[X-1],B.text))A[X-1]+=B.text;else if(D&&!B.isWordLike&&X>0&&Q[X-1]==="text"&&(uZ(B.text)||B.text==="-"&&Y[X-1]))A[X-1]+=B.text;else A[X]=B.text,Y[X]=B.isWordLike,Q[X]=B.kind,K[X]=B.start,X++}for(let G=1;G<X;G++)if(Q[G]==="text"&&!Y[G]&&k6(A[G])&&Q[G-1]==="text")A[G-1]+=A[G],Y[G-1]=Y[G-1]||Y[G],A[G]="";for(let G=X-2;G>=0;G--)if(Q[G]==="text"&&!Y[G]&&mZ(A[G])){let B=G+1;while(B<X&&A[B]==="")B++;if(B<X&&Q[B]==="text")A[B]=A[G]+A[B],K[B]=K[G],A[G]=""}let q=0;for(let G=0;G<X;G++){let B=A[G];if(B.length===0)continue;if(q!==G)A[q]=B,Y[q]=Y[G],Q[q]=Q[G],K[q]=K[G];q++}A.length=q,Y.length=q,Q.length=q,K.length=q;let N=eZ({len:q,texts:A,isWordLike:Y,kinds:Q,starts:K}),U=$X(nZ(tZ(oZ(sZ(aZ(N))))));for(let G=0;G<U.len-1;G++){let B=pZ(U.texts[G]);if(B===null)continue;if(U.kinds[G]!=="space"&&U.kinds[G]!=="preserved-space"||U.kinds[G+1]!=="text"||!E6(U.texts[G+1]))continue;U.texts[G]=B.space,U.isWordLike[G]=!1,U.kinds[G]=U.kinds[G]==="preserved-space"?"preserved-space":"space",U.texts[G+1]=B.marks+U.texts[G+1],U.starts[G+1]=U.starts[G]+B.space.length}return U}function JX($,M){if($.len===0)return[];if(!M.preserveHardBreaks)return[{startSegmentIndex:0,endSegmentIndex:$.len,consumedEndSegmentIndex:$.len}];let J=[],Z=0;for(let X=0;X<$.len;X++){if($.kinds[X]!=="hard-break")continue;J.push({startSegmentIndex:Z,endSegmentIndex:X,consumedEndSegmentIndex:X+1}),Z=X+1}if(Z<$.len)J.push({startSegmentIndex:Z,endSegmentIndex:$.len,consumedEndSegmentIndex:$.len});return J}function mM($,M,J="normal"){let Z=bZ(J),X=Z.mode==="pre-wrap"?EZ($):CZ($);if(X.length===0)return{normalized:X,chunks:[],len:0,texts:[],isWordLike:[],kinds:[],starts:[]};let A=MX(X,M,Z);return{normalized:X,chunks:JX(A,Z),...A}}var x0=null,vM=new Map,d0=null,ZX=/\p{Emoji_Presentation}/u,XX=/[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u,u6=null,gM=new Map;function S6(){if(x0!==null)return x0;if(typeof OffscreenCanvas<"u")return x0=new OffscreenCanvas(1,1).getContext("2d"),x0;if(typeof document<"u")return x0=document.createElement("canvas").getContext("2d"),x0;throw Error("Text measurement requires OffscreenCanvas or a DOM canvas context.")}function AX($){let M=vM.get($);if(!M)M=new Map,vM.set($,M);return M}function Y0($,M){let J=M.get($);if(J===void 0)J={width:S6().measureText($).width,containsCJK:t1($)},M.set($,J);return J}function a0(){if(d0!==null)return d0;if(typeof navigator>"u")return d0={lineFitEpsilon:0.005,carryCJKAfterClosingQuote:!1,preferPrefixWidthsForBreakableRuns:!1,preferEarlySoftHyphenBreak:!1},d0;let $=navigator.userAgent,J=navigator.vendor==="Apple Computer, Inc."&&$.includes("Safari/")&&!$.includes("Chrome/")&&!$.includes("Chromium/")&&!$.includes("CriOS/")&&!$.includes("FxiOS/")&&!$.includes("EdgiOS/"),Z=$.includes("Chrome/")||$.includes("Chromium/")||$.includes("CriOS/")||$.includes("Edg/");return d0={lineFitEpsilon:J?0.015625:0.005,carryCJKAfterClosingQuote:Z,preferPrefixWidthsForBreakableRuns:J,preferEarlySoftHyphenBreak:J},d0}function YX($){let M=$.match(/(\d+(?:\.\d+)?)\s*px/);return M?parseFloat(M[1]):16}function m6(){if(u6===null)u6=new Intl.Segmenter(void 0,{granularity:"grapheme"});return u6}function QX($){return ZX.test($)||$.includes("️")}function hM($){return XX.test($)}function KX($,M){let J=gM.get($);if(J!==void 0)return J;let Z=S6();Z.font=$;let X=Z.measureText("\uD83D\uDE00").width;if(J=0,X>M+0.5&&typeof document<"u"&&document.body!==null){let A=document.createElement("span");A.style.font=$,A.style.display="inline-block",A.style.visibility="hidden",A.style.position="absolute",A.textContent="\uD83D\uDE00",document.body.appendChild(A);let Y=A.getBoundingClientRect().width;if(document.body.removeChild(A),X-Y>0.5)J=X-Y}return gM.set($,J),J}function qX($){let M=0,J=m6();for(let Z of J.segment($))if(QX(Z.segment))M++;return M}function NX($,M){if(M.emojiCount===void 0)M.emojiCount=qX($);return M.emojiCount}function Q0($,M,J){if(J===0)return M.width;return M.width-NX($,M)*J}function IM($,M,J,Z){if(M.graphemeWidths!==void 0)return M.graphemeWidths;let X=[],A=m6();for(let Y of A.segment($)){let Q=Y0(Y.segment,J);X.push(Q0(Y.segment,Q,Z))}return M.graphemeWidths=X.length>1?X:null,M.graphemeWidths}function pM($,M,J,Z){if(M.graphemePrefixWidths!==void 0)return M.graphemePrefixWidths;let X=[],A=m6(),Y="";for(let Q of A.segment($)){Y+=Q.segment;let K=Y0(Y,J);X.push(Q0(Y,K,Z))}return M.graphemePrefixWidths=X.length>1?X:null,M.graphemePrefixWidths}function lM($,M){let J=S6();J.font=$;let Z=AX($),X=YX($),A=M?KX($,X):0;return{cache:Z,fontSize:X,emojiCorrection:A}}function n4($){return $==="space"||$==="preserved-space"||$==="tab"||$==="zero-width-break"||$==="soft-hyphen"}function UX($,M){while(M<$.widths.length){let J=$.kinds[M];if(J!=="space"&&J!=="zero-width-break"&&J!=="soft-hyphen")break;M++}return M}function GX($,M){if(M<=0)return 0;let J=$%M;if(Math.abs(J)<=0.000001)return M;return M-J}function rM($,M,J,Z){if(!Z||M===null)return $[J];return M[J]-(J>0?M[J-1]:0)}function BX($,M,J,Z,X,A){let Y=0,Q=M;while(Y<$.length){let K=A?M+$[Y]:Q+$[Y];if((Y+1<$.length?K+X:K)>J+Z)break;Q=K,Y++}return{fitCount:Y,fittedWidth:Q}}function FX($,M,J){let{widths:Z,kinds:X,breakableWidths:A,breakablePrefixWidths:Y}=$;if(Z.length===0)return 0;let Q=a0(),K=Q.lineFitEpsilon,q=0,N=0,U=!1,G=0,B=0,D=0,F=0,H=-1,b=0;function E(){H=-1,b=0}function V(W=D,_=F,C=N){q++,J?.({startSegmentIndex:G,startGraphemeIndex:B,endSegmentIndex:W,endGraphemeIndex:_,width:C}),N=0,U=!1,E()}function R(W,_){U=!0,G=W,B=0,D=W+1,F=0,N=_}function O(W,_,C){U=!0,G=W,B=_,D=W,F=_+1,N=C}function j(W,_){if(!U){R(W,_);return}N+=_,D=W+1,F=0}function f(W,_){if(!n4(X[W]))return;H=W+1,b=N-_}function z(W){y(W,0)}function y(W,_){let C=A[W],g=Y[W]??null;for(let u=_;u<C.length;u++){let d=rM(C,g,u,Q.preferPrefixWidthsForBreakableRuns);if(!U){O(W,u,d);continue}if(N+d>M+K)V(),O(W,u,d);else N+=d,D=W,F=u+1}if(U&&D===W&&F===C.length)D=W+1,F=0}let T=0;while(T<Z.length){if(!U){if(T=UX($,T),T>=Z.length)break}let W=Z[T],_=X[T];if(!U){if(W>M&&A[T]!==null)z(T);else R(T,W);f(T,W),T++;continue}if(N+W>M+K){if(n4(_)){j(T,W),V(T+1,0,N-W),T++;continue}if(H>=0){if(D>H||D===H&&F>0){V();continue}V(H,0,b);continue}if(W>M&&A[T]!==null){V(),z(T),T++;continue}V();continue}j(T,W),f(T,W),T++}if(U)V();return q}function cM($,M,J){if($.simpleLineWalkFastPath)return FX($,M,J);let{widths:Z,lineEndFitAdvances:X,lineEndPaintAdvances:A,kinds:Y,breakableWidths:Q,breakablePrefixWidths:K,discretionaryHyphenWidth:q,tabStopAdvance:N,chunks:U}=$;if(Z.length===0||U.length===0)return 0;let G=a0(),B=G.lineFitEpsilon,D=0,F=0,H=!1,b=0,E=0,V=0,R=0,O=-1,j=0,f=0,z=null;function y(){O=-1,j=0,f=0,z=null}function T(k=V,S=R,m=F){D++,J?.({startSegmentIndex:b,startGraphemeIndex:E,endSegmentIndex:k,endGraphemeIndex:S,width:m}),F=0,H=!1,y()}function W(k,S){H=!0,b=k,E=0,V=k+1,R=0,F=S}function _(k,S,m){H=!0,b=k,E=S,V=k,R=S+1,F=m}function C(k,S){if(!H){W(k,S);return}F+=S,V=k+1,R=0}function g(k,S){if(!n4(Y[k]))return;let m=Y[k]==="tab"?0:X[k],Z1=Y[k]==="tab"?S:A[k];O=k+1,j=F-S+m,f=F-S+Z1,z=Y[k]}function u(k){d(k,0)}function d(k,S){let m=Q[k],Z1=K[k]??null;for(let t=S;t<m.length;t++){let N1=rM(m,Z1,t,G.preferPrefixWidthsForBreakableRuns);if(!H){_(k,t,N1);continue}if(F+N1>M+B)T(),_(k,t,N1);else F+=N1,V=k,R=t+1}if(H&&V===k&&R===m.length)V=k+1,R=0}function p(k){if(z!=="soft-hyphen")return!1;let S=Q[k];if(S===null)return!1;let m=G.preferPrefixWidthsForBreakableRuns?K[k]??S:S,Z1=m!==S,{fitCount:t,fittedWidth:N1}=BX(m,F,M,B,q,Z1);if(t===0)return!1;if(F=N1,V=k,R=t,y(),t===S.length)return V=k+1,R=0,!0;return T(k,t,N1+q),d(k,t),!0}function J1(k){D++,J?.({startSegmentIndex:k.startSegmentIndex,startGraphemeIndex:0,endSegmentIndex:k.consumedEndSegmentIndex,endGraphemeIndex:0,width:0}),y()}for(let k=0;k<U.length;k++){let S=U[k];if(S.startSegmentIndex===S.endSegmentIndex){J1(S);continue}H=!1,F=0,b=S.startSegmentIndex,E=0,V=S.startSegmentIndex,R=0,y();let m=S.startSegmentIndex;while(m<S.endSegmentIndex){let Z1=Y[m],t=Z1==="tab"?GX(F,N):Z[m];if(Z1==="soft-hyphen"){if(H)V=m+1,R=0,O=m+1,j=F+q,f=F+q,z=Z1;m++;continue}if(!H){if(t>M&&Q[m]!==null)u(m);else W(m,t);g(m,t),m++;continue}if(F+t>M+B){let v1=F+(Z1==="tab"?0:X[m]),g1=F+(Z1==="tab"?t:A[m]);if(z==="soft-hyphen"&&G.preferEarlySoftHyphenBreak&&j<=M+B){T(O,0,f);continue}if(z==="soft-hyphen"&&p(m)){m++;continue}if(n4(Z1)&&v1<=M+B){C(m,t),T(m+1,0,g1),m++;continue}if(O>=0&&j<=M+B){if(V>O||V===O&&R>0){T();continue}let A1=O;T(A1,0,f),m=A1;continue}if(t>M&&Q[m]!==null){T(),u(m),m++;continue}T();continue}C(m,t),g(m,t),m++}if(H){let Z1=O===S.consumedEndSegmentIndex?f:F;T(S.consumedEndSegmentIndex,0,Z1)}}return D}var v6=null,xM=new WeakMap;function aM(){if(v6===null)v6=new Intl.Segmenter(void 0,{granularity:"grapheme"});return v6}function DX($){if($)return{widths:[],lineEndFitAdvances:[],lineEndPaintAdvances:[],kinds:[],simpleLineWalkFastPath:!0,segLevels:null,breakableWidths:[],breakablePrefixWidths:[],discretionaryHyphenWidth:0,tabStopAdvance:0,chunks:[],segments:[]};return{widths:[],lineEndFitAdvances:[],lineEndPaintAdvances:[],kinds:[],simpleLineWalkFastPath:!0,segLevels:null,breakableWidths:[],breakablePrefixWidths:[],discretionaryHyphenWidth:0,tabStopAdvance:0,chunks:[]}}function _X($,M,J){let Z=aM(),X=a0(),{cache:A,emojiCorrection:Y}=lM(M,hM($.normalized)),Q=Q0("-",Y0("-",A),Y),q=Q0(" ",Y0(" ",A),Y)*8;if($.len===0)return DX(J);let N=[],U=[],G=[],B=[],D=$.chunks.length<=1,F=J?[]:null,H=[],b=[],E=J?[]:null,V=Array.from({length:$.len}),R=Array.from({length:$.len});function O(z,y,T,W,_,C,g,u){if(_!=="text"&&_!=="space"&&_!=="zero-width-break")D=!1;if(N.push(y),U.push(T),G.push(W),B.push(_),F?.push(C),H.push(g),b.push(u),E!==null)E.push(z)}for(let z=0;z<$.len;z++){V[z]=N.length;let y=$.texts[z],T=$.isWordLike[z],W=$.kinds[z],_=$.starts[z];if(W==="soft-hyphen"){O(y,0,Q,Q,W,_,null,null),R[z]=N.length;continue}if(W==="hard-break"){O(y,0,0,0,W,_,null,null),R[z]=N.length;continue}if(W==="tab"){O(y,0,0,0,W,_,null,null),R[z]=N.length;continue}let C=Y0(y,A);if(W==="text"&&C.containsCJK){let p="",J1=0;for(let k of Z.segment(y)){let S=k.segment;if(p.length===0){p=S,J1=k.index;continue}if(O2.has(p)||R6.has(S)||c0.has(S)||X.carryCJKAfterClosingQuote&&t1(S)&&f6(p)){p+=S;continue}let m=Y0(p,A),Z1=Q0(p,m,Y);O(p,Z1,Z1,Z1,"text",_+J1,null,null),p=S,J1=k.index}if(p.length>0){let k=Y0(p,A),S=Q0(p,k,Y);O(p,S,S,S,"text",_+J1,null,null)}R[z]=N.length;continue}let g=Q0(y,C,Y),u=W==="space"||W==="preserved-space"||W==="zero-width-break"?0:g,d=W==="space"||W==="zero-width-break"?0:g;if(T&&y.length>1){let p=IM(y,C,A,Y),J1=X.preferPrefixWidthsForBreakableRuns?pM(y,C,A,Y):null;O(y,g,u,d,W,_,p,J1)}else O(y,g,u,d,W,_,null,null);R[z]=N.length}let j=HX($.chunks,V,R),f=F===null?null:LM($.normalized,F);if(E!==null)return{widths:N,lineEndFitAdvances:U,lineEndPaintAdvances:G,kinds:B,simpleLineWalkFastPath:D,segLevels:f,breakableWidths:H,breakablePrefixWidths:b,discretionaryHyphenWidth:Q,tabStopAdvance:q,chunks:j,segments:E};return{widths:N,lineEndFitAdvances:U,lineEndPaintAdvances:G,kinds:B,simpleLineWalkFastPath:D,segLevels:f,breakableWidths:H,breakablePrefixWidths:b,discretionaryHyphenWidth:Q,tabStopAdvance:q,chunks:j}}function HX($,M,J){let Z=[];for(let X=0;X<$.length;X++){let A=$[X],Y=A.startSegmentIndex<M.length?M[A.startSegmentIndex]:J[J.length-1]??0,Q=A.endSegmentIndex<M.length?M[A.endSegmentIndex]:J[J.length-1]??0,K=A.consumedEndSegmentIndex<M.length?M[A.consumedEndSegmentIndex]:J[J.length-1]??0;Z.push({startSegmentIndex:Y,endSegmentIndex:Q,consumedEndSegmentIndex:K})}return Z}function PX($,M,J,Z){let X=mM($,a0(),Z?.whiteSpace);return _X(X,M,J)}function sM($,M,J){return PX($,M,!0,J)}function WX($){return $}function dM($,M,J){let Z=J.get($);if(Z!==void 0)return Z;Z=[];let X=aM();for(let A of X.segment(M[$]))Z.push(A.segment);return J.set($,Z),Z}function TX($){let M=xM.get($);if(M!==void 0)return M;return M=new Map,xM.set($,M),M}function yX($,M,J,Z){return Z>0&&$[Z-1]==="soft-hyphen"&&!(M===Z&&J>0)}function VX($,M,J,Z,X,A,Y){let Q="",K=yX(M,Z,X,A);for(let q=Z;q<A;q++){if(M[q]==="soft-hyphen"||M[q]==="hard-break")continue;if(q===Z&&X>0)Q+=dM(q,$,J).slice(X).join("");else Q+=$[q]}if(Y>0){if(K)Q+="-";Q+=dM(A,$,J).slice(Z===A?X:0,Y).join("")}else if(K)Q+="-";return Q}function zX($,M,J,Z,X,A,Y){return{text:VX($.segments,$.kinds,M,Z,X,A,Y),width:J,start:{segmentIndex:Z,graphemeIndex:X},end:{segmentIndex:A,graphemeIndex:Y}}}function OX($,M,J){return zX($,M,J.width,J.startSegmentIndex,J.startGraphemeIndex,J.endSegmentIndex,J.endGraphemeIndex)}function iM($,M,J){let Z=[];if($.widths.length===0)return{lineCount:0,height:0,lines:Z};let X=TX($),A=cM(WX($),M,(Y)=>{Z.push(OX($,X,Y))});return{lineCount:A,height:A*J,lines:Z}}function g6($,M,J){let Z=$.image?M.images.get($.image.url)??null:null,X=$.image?.width??null,A=Math.min(J,X??240),Y=Math.max(120,Math.round(A*0.5625));if(!Z||Z.intrinsicWidth<=0||Z.intrinsicHeight<=0)return{height:Y,width:A};let Q=Math.min(J,X??Z.intrinsicWidth),K=Math.min(1,Q/Z.intrinsicWidth);return{height:Math.max(48,Math.round(Z.intrinsicHeight*K)),width:Math.max(48,Math.round(Z.intrinsicWidth*K))}}function oM($,M){if(!$.image)return`${$.kind}:missing-image`;let J=M.images.get($.image.url);return`${$.kind}:${$.image.url}:${$.image.width??0}:${J?.status??"loading"}:${J?.intrinsicWidth??0}:${J?.intrinsicHeight??0}`}var nM=[{fontSize:32,lineHeight:36},{fontSize:26,lineHeight:32},{fontSize:21,lineHeight:28},{fontSize:21,lineHeight:28},{fontSize:19,lineHeight:26},{fontSize:18,lineHeight:26}],t4;function s0($){if($?.type==="heading"){let{fontSize:M}=$3($.depth);return`700 ${M}px "Iowan Old Style", "Palatino Linotype", serif`}switch($?.type){case"code":return"15px ui-monospace, SFMono-Regular, Menlo, monospace";default:return'16px "Iowan Old Style", "Palatino Linotype", serif'}}function O0($,M){if($?.type==="heading")return $3($.depth).lineHeight;if($?.type==="code")return 22;return M}function $3($){return nM[$-1]??nM.at(-1)}function i0($,M,J,Z,X,A,Y){let Q=`${$5(M,Y)}:${X}:${A}:${J}`,K=$.measuredLines.get(Q);if(K)return K;let q=CX($,M,J,Z,X,A,Y);return bM($,Q,q)}function e4($,M,J,Z,X,A,Y,Q){let K=`${$5(M,Q)}:${J}:${Z}:${A}:${Y}`,q=$.lineBoundaries.get(K);if(q)return q;let N=J3();if(!N)return eM(X);let U=[{left:0,offset:0}],G=0,B=M.inlines.filter((D)=>D.end>J&&D.start<Z);if(B.length===0)return eM(X);for(let D of B){let F=Math.max(J,D.start),H=Math.min(Z,D.end),b=M.text.slice(F,H),E=F-J;if(D.kind==="image"){let V=g6(D,Q,Y).width;G+=V,E+=b.length,U.push({left:G,offset:E});continue}N.font=M3(A,D.marks);for(let V of Array.from(b))G+=Z3($,N,V),E+=V.length,U.push({left:G,offset:E})}return CM($,K,U)}function bX($,M,J,Z){let X=`${J}::${Z}::${M}`,A=$.preparedText.get(X);if(A)return A;let Y=sM(M,J,{whiteSpace:Z});return OM($,X,Y)}function CX($,M,J,Z,X,A,Y){let Q=M.text;if(Q.length===0)return[{end:0,height:A,start:0,text:"",width:0}];if(LX(M))return wX($,M,J,X,A,Y);try{let K=bX($,Q,J,mX(Z));return iM(K,X,A).lines.map((N)=>({end:tM(K.segments,N.end),height:A,start:tM(K.segments,N.start),text:N.text,width:N.width}))}catch{return EX(Q,X,A)}}function tM($,M){let J=0;for(let A=0;A<M.segmentIndex;A+=1)J+=$[A]?.length??0;let Z=$[M.segmentIndex]??"",X=Array.from(Z);for(let A=0;A<M.graphemeIndex;A+=1)J+=X[A]?.length??0;return J}function eM($){let M=[{left:0,offset:0}],J=0,Z=0;for(let X of Array.from($))J+=9,Z+=X.length,M.push({left:J,offset:Z});return M}function EX($,M,J){let Z=Math.max(1,Math.floor(M/9)),X=vX($,Z),A=0;return X.map((Y)=>{let Q=A,K=Q+Y.length;return A=K,{end:K,height:J,start:Q,text:Y,width:Y.length*9}})}function wX($,M,J,Z,X,A){let Y=RX($,J3(),M,J,Z,X,A);if(Y.length===0)return[{end:0,height:X,start:0,text:"",width:0}];return jX(Y,M.text,Z,X)}function jX($,M,J,Z){let X=[],A=0;while(A<$.length){let Y=$[A].start;if($[A].text===`
14
- `){X.push({end:Y,height:Z,start:Y,text:"",width:0}),A+=1;continue}let Q=0,K=0,q=A,N=-1,U=Z;while(q<$.length){let B=$[q];if(B.text===`
15
- `)break;let D=Q+B.width;if(D>J&&q>A)break;if(Q=D,U=Math.max(U,B.height),B.breakable)N=q,K=Q;q+=1}if(q===$.length||$[q]?.text===`
16
- `){let B=$[q-1]?.end??Y;X.push({end:B,height:U,start:Y,text:M.slice(Y,B),width:Q}),A=q<$.length&&$[q]?.text===`
17
- `?q+1:q;continue}if(N>=A){let B=$[N].end;X.push({end:B,height:U,start:Y,text:M.slice(Y,B),width:K}),A=N+1;continue}let G=$[Math.max(A,q-1)].end;X.push({end:G,height:U,start:Y,text:M.slice(Y,G),width:Q}),A=Math.max(A+1,q)}return X}function RX($,M,J,Z,X,A,Y){let Q=[];for(let K of J.inlines){if(K.kind==="image"){let N=g6(K,Y,X);Q.push({breakable:!0,end:K.end,height:N.height,start:K.start,text:K.text,width:N.width});continue}if(M)M.font=M3(Z,K.marks);let q=K.start;for(let N of Array.from(K.text)){let U=q,G=U+N.length;Q.push({breakable:/\s/.test(N),end:G,height:A,start:U,text:N,width:N===`
18
- `?0:Z3($,M,N)}),q=G}}return Q}function LX($){return $.inlines.some((M)=>M.kind==="image"||SX(M))}function $5($,M){return[$.path,uX($.text),kX($,M)].join(":")}function kX($,M){return $.inlines.map((J)=>`${J.start}-${J.end}:${fX(J,M)}`).join("|")}function fX($,M){if($.kind==="image"&&$.image)return oM($,M);return`${$.kind}:${$.inlineCode?1:0}:${$.marks.join(",")}:${$.link?.url??""}`}function uX($){let M=2166136261;for(let J of $)M^=J.charCodeAt(0),M=Math.imul(M,16777619);return(M>>>0).toString(36)}function SX($){return $.marks.includes("italic")||$.marks.includes("bold")}function M3($,M){let J=[];if(M.includes("italic"))J.push("italic");if(M.includes("bold"))J.push("700");return J.length>0?`${J.join(" ")} ${$}`:$}function J3(){if(t4!==void 0)return t4;return t4=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):typeof document<"u"?document.createElement("canvas"):null)?.getContext("2d")??null,t4}function Z3($,M,J){if(!M)return 9;let Z=M.font,X=wM($,Z),A=X.get(J);if(A!==void 0)return A;let Y=M.measureText(J).width;return X.set(J,Y),Y}function mX($){return $?.type==="code"?"pre-wrap":"normal"}function vX($,M){if($.length===0)return[""];let J=$.split(`
19
- `),Z=[];for(let X of J){if(X.length===0){Z.push("");continue}let A=X;while(A.length>M){let Y=A.slice(0,M),Q=Y.lastIndexOf(" ");if(Q<=0){Z.push(Y),A=A.slice(M);continue}Z.push(Y.slice(0,Q)),A=A.slice(Q+1)}Z.push(A)}return Z}var b2=10,o0=8,h6=120;function X3($,M,J,Z,X,A,Y,Q,K,q){let N=Math.max(1,...A.rows.map((F)=>F.cells.length)),G=Math.max(h6,K.width-Y-K.paddingX)/N,B=gX(Z),D=Q;for(let F=0;F<A.rows.length;F+=1){let H=hX(B.get(F)??[],X,A,G,b2,K.lineHeight,q),b=Math.max(K.lineHeight+o0*2,...H.map((E)=>E.measuredLines.reduce((V,R)=>V+R.height,0)+o0*2));for(let E of H){let V=Y+E.cellIndex*G,R=D+o0;for(let O of E.measuredLines){let j={blockId:E.container.blockId,boundaries:e4(X,E.container,O.start,O.end,O.text,E.font,G-b2*2,q),regionId:E.container.id,end:O.end,font:E.font,height:O.height,left:V+b2,start:O.start,text:O.text,top:R,width:O.width};$.push(j),I6(M,j),R+=O.height}J.set(E.container.id,{bottom:D+b,left:V,right:V+G,top:D})}pX(M,A.id,D,D+b),D+=b}return D+K.blockGap}function gX($){let M=new Map;for(let J of $){let Z=IX(J.path);if(!Z)continue;let X=M.get(Z.rowIndex)??[];X.push({cellIndex:Z.cellIndex,container:J}),M.set(Z.rowIndex,X)}return M}function hX($,M,J,Z,X,A,Y){return[...$].sort((Q,K)=>Q.cellIndex-K.cellIndex).map(({cellIndex:Q,container:K})=>{let q=s0(J),N=O0(J,A),U=i0(M,K,q,J,Math.max(40,Z-X*2),N,Y);return{cellIndex:Q,container:K,font:q,lineHeight:N,measuredLines:U}})}function IX($){let M=/\.rows\.(\d+)\.cells\.(\d+)$/.exec($);if(!M)return null;return{cellIndex:Number(M[2]),rowIndex:Number(M[1])}}function pX($,M,J,Z){let X=$.get(M);$.set(M,{bottom:X?Math.max(X.bottom,Z):Z,top:X?Math.min(X.top,J):J})}var lX={blockGap:16,charWidth:9,indentWidth:24,lineHeight:24,paddingX:16,paddingY:12},rX=24,cX=16,xX=6,dX=10,aX=4;function M5($){let M=Math.max(12,Math.floor($.width/9)),J=Math.max(1,Math.ceil($.text.length/M));return{estimatedHeight:J*24,lineCount:J,width:$.width}}function J5($,M,J=z0(),Z=null){let X=Z??{images:new Map},A={...lX,...M},Y=[],Q=new Map,K=new Map($.regions.map((F)=>[F.id,{textLength:F.text.length}])),q=new Map($.blocks.map((F)=>[F.id,F.depth])),N=new Map($.blocks.map((F)=>[F.id,F])),U=E2($.document.blocks),G=new Map,B=A.paddingY;for(let F=0;F<$.regions.length;F+=1){let H=$.regions[F],b=q.get(H.blockId)??0,E=A.paddingX+b*A.indentWidth,V=Math.max(40,A.width-E-A.paddingX),R=U.get(H.blockId)??null;if(R?.type==="table"){let f=N.get(H.blockId)?.regionIds??[],z=$.regions.slice(F,F+f.length);B=X3(Y,G,Q,z,J,R,E,B,A,X),F+=z.length-1;continue}B=sX(Y,G,Q,H,J,R,E,B,V,A,X);let O=X5(N,U,$.regions,F,A.blockGap);B+=O;let j=G.get(H.blockId);if(j)j.bottom=Math.max(j.bottom,B)}return{blocks:$.blocks.map((F)=>{let H=G.get(F.id),b=H?.top??A.paddingY;return{bottom:H?.bottom??b+A.lineHeight/2,depth:F.depth,id:F.id,top:b,type:F.type}}),regionBounds:oX(Y,Q),regionLineIndices:iX(Y),regionMetrics:K,height:Math.max(B,A.paddingY),lines:Y,options:A,width:A.width}}function sX($,M,J,Z,X,A,Y,Q,K,q,N){let U=s0(A),G=O0(A,q.lineHeight),B=i0(X,Z,U,A,K,G,N),D=Q;for(let F of B){let H={blockId:Z.blockId,boundaries:e4(X,Z,F.start,F.end,F.text,U,K,N),regionId:Z.id,end:F.end,font:U,height:F.height,left:Y,start:F.start,text:F.text,top:D,width:F.width};$.push(H),I6(M,H),D+=F.height}return nX($,Z.id,J),D}function iX($){let M=[...$].sort((Z,X)=>Z.top-X.top||Z.left-X.left),J=new Map;$.length=0,$.push(...M);for(let[Z,X]of $.entries()){let A=J.get(X.regionId)??[];A.push(Z),J.set(X.regionId,A)}return J}function oX($,M){let J=new Map(M);for(let Z of $){let X=J.get(Z.regionId),A={bottom:Z.top+Z.height,left:Z.left,right:Z.left+Z.width,top:Z.top};J.set(Z.regionId,X?{bottom:Math.max(X.bottom,A.bottom),left:Math.min(X.left,A.left),right:Math.max(X.right,A.right),top:Math.min(X.top,A.top)}:A)}return J}function nX($,M,J){let Z=$.filter((X)=>X.regionId===M);if(Z.length===0)return;J.set(M,{bottom:Math.max(...Z.map((X)=>X.top+X.height)),left:Math.min(...Z.map((X)=>X.left)),right:Math.max(...Z.map((X)=>X.left+X.width)),top:Math.min(...Z.map((X)=>X.top))})}function I6($,M){let J=$.get(M.blockId),Z=M.top+M.height;$.set(M.blockId,{bottom:J?Math.max(J.bottom,Z):Z,top:J?Math.min(J.top,M.top):M.top})}function q3($,M){let J=0,Z=$.lines.length-1;while(J<=Z){let X=J+Z>>1,A=$.lines[X];if(M<A.top){Z=X-1;continue}if(M>=A.top+A.height){J=X+1;continue}return{index:X,line:A}}return null}function p6($,M){let J=[...$.regionBounds.entries()].find(([,A])=>{return M.x>=A.left&&M.x<=A.right&&M.y>=A.top&&M.y<=A.bottom});if(J)return Z5($,J[0],M.y);let Z=q3($,M.y);if(!Z)return null;let X=tX($,M.y,Z.index);if(X.length===1)return X[0]??null;return X.find((A)=>{let Y=$.regionBounds.get(A.line.regionId);return Y?M.x>=Y.left&&M.x<=Y.right:!1})??[...X].sort((A,Y)=>{let Q=$.regionBounds.get(A.line.regionId),K=$.regionBounds.get(Y.line.regionId),q=A3(M.x,Q),N=A3(M.x,K);return q-N})[0]??null}function l6($,M,J){if($.lines.length===0)return{endIndex:0,startIndex:0};let Z=M+J,X=Y3($,M),A=Y3($,Z);if(X>0){let Y=$.lines[X-1];if(Y.top+Y.height>M)X-=1}if(A<$.lines.length){if($.lines[A].top<Z)A+=1}return{endIndex:A,startIndex:X}}function c1($,M,J){if(!$.regionMetrics.get(J.regionId))return null;let X=$0($,J.regionId,J.offset);if(!X)return null;return{blockId:X.blockId,regionId:X.regionId,height:X.height,left:x1(X,J.offset-X.start),offset:J.offset,top:X.top}}function $0($,M,J){return C2($,M,J)?.line??null}function Z5($,M,J){let Z=$.regionLineIndices.get(M);if(!Z||Z.length===0)return null;let X=Z[0],A=Number.POSITIVE_INFINITY;for(let Y of Z){let Q=$.lines[Y],K=J<Q.top?Q.top-J:J>Q.top+Q.height?J-(Q.top+Q.height):0;if(K<A)A=K,X=Y;if(K===0)break}return{index:X,line:$.lines[X]}}function C2($,M,J){let Z=$.regionLineIndices.get(M);if(!Z||Z.length===0)return null;let X=0,A=Z.length-1;while(X<=A){let N=X+A>>1,U=Z[N],G=$.lines[U];if(J<G.start){A=N-1;continue}if(J>G.end){X=N+1;continue}return{index:U,line:G}}let Y=Z[0],Q=Z[Z.length-1],K=$.lines[Y],q=$.lines[Q];if(J<=K.start)return{index:Y,line:K};if(J>=q.end)return{index:Q,line:q};return null}function tX($,M,J){let Z=[];for(let X=J;X>=0;X-=1){let A=$.lines[X];if(M<A.top||M>=A.top+A.height)break;Z.unshift({index:X,line:A})}for(let X=J+1;X<$.lines.length;X+=1){let A=$.lines[X];if(M<A.top||M>=A.top+A.height)break;Z.push({index:X,line:A})}return Z}function A3($,M){if(!M)return Number.POSITIVE_INFINITY;if($<M.left)return M.left-$;if($>M.right)return $-M.right;return 0}function x1($,M){return $.left+eX($.boundaries,M)}function E2($){let M=new Map,J=(Z)=>{for(let X of Z)if(M.set(X.id,X),X.type==="blockquote"||X.type==="listItem")J(X.children);else if(X.type==="list")J(X.items)};return J($),M}function eX($,M){for(let Z of $)if(Z.offset===M)return Z.left;return $.filter((Z)=>Z.offset<=M).at(-1)?.left??0}function Y3($,M){let J=0,Z=$.lines.length;while(J<Z){let X=J+Z>>1,A=$.lines[X];if(A.top+A.height<=M)J=X+1;else Z=X}return J}function N3($,M){if($.length===0)return 0;for(let J=1;J<$.length;J+=1){let Z=$[J-1],X=$[J],A=Z.left+(X.left-Z.left)/2;if(M<=A)return Z.offset;if(M<=X.left)return X.offset}return $.at(-1)?.offset??0}function X5($,M,J,Z,X){let A=J[Z],Y=J[Z+1];if(!A||!Y)return X;if(Q3($,A.blockId,Y.blockId,"list"))return xX;if(Q3($,A.blockId,Y.blockId,"blockquote"))return dX;if(A.blockId===Y.blockId)return aX;return X+$A(M.get(A.blockId))}function $A($){if($?.type!=="heading")return 0;if($.depth===1)return rX;return $.depth===2?cX:0}function Q3($,M,J,Z){let X=K3($,M,Z),A=K3($,J,Z);for(let Y of X)if(A.has(Y))return!0;return!1}function K3($,M,J){let Z=new Set,X=$.get(M)??null;while(X){if(X.type===J)Z.add(X.id);X=X.parentBlockId?$.get(X.parentBlockId)??null:null}return Z}function r6($,M,J,Z=[],X=z0(),A=null){let Y=A??{images:new Map},Q=E2($.document.blocks),K=new Map($.blocks.map((V)=>[V.id,V])),q=new Set(Z),N=Math.max(0,J.top-J.overscan),U=J.top+J.height+J.overscan,G=AA(X,$,Q,K,M,Y),B=U3(G,N),D=U3(G,U);if(B>0){let V=G.entries[B-1];if(V&&V.bottom>N)B-=1}if(D<G.entries.length){let V=G.entries[D];if(V&&V.top<U)D+=1}for(let V of q){let R=G.containerIndices.get(V);if(R===void 0)continue;B=Math.min(B,R),D=Math.max(D,R+1)}if(!Number.isFinite(B)||!Number.isFinite(D))return{estimateRegionBounds:G.estimateRegionBounds,layout:J5({...$,regions:[]},M,X,Y),totalHeight:G.totalHeight,viewport:J};let F=ZA($,K,G.containerIndices,B,D),H=G.entries[F.startIndex]?.top??M.paddingY??0,b=J5({...$,regions:$.regions.slice(F.startIndex,F.endIndex)},M,X,Y),E=JA(b,H,G.totalHeight);return MA(X,$,E,M,Y),{estimateRegionBounds:G.estimateRegionBounds,layout:E,totalHeight:G.totalHeight,viewport:J}}function MA($,M,J,Z,X){for(let[A,Y]of J.regionBounds){let Q=Y.bottom-Y.top,K=M.regionIndex.get(A);EM($,G3(K??{path:A,inlines:[],text:""},Z,X),Q)}}function JA($,M,J){return{...$,blocks:$.blocks.map((Z)=>({...Z,bottom:Z.bottom+M,top:Z.top+M})),regionBounds:new Map([...$.regionBounds.entries()].map(([Z,X])=>[Z,{bottom:X.bottom+M,left:X.left,right:X.right,top:X.top+M}])),height:J,lines:$.lines.map((Z)=>({...Z,top:Z.top+M}))}}function ZA($,M,J,Z,X){let A=Z,Y=X;for(let Q=Z;Q<X;Q+=1){let K=$.regions[Q],q=M.get(K.blockId);if(!q)continue;if(q.type==="table"){let N=J.get(q.regionIds[0]??""),U=J.get(q.regionIds[q.regionIds.length-1]??"");if(N!==void 0)A=Math.min(A,N);if(U!==void 0)Y=Math.max(Y,U+1)}}return{endIndex:Y,startIndex:A}}function XA($,M,J,Z,X,A){let Y=G3(M,X,A),Q=$.measuredContainerHeights.get(Y);if(Q!==void 0)return Q;let K=X.paddingX??0,q=X.indentWidth??24,N=O0(J,X.lineHeight??24),U=K+Z*q,G=Math.max(40,X.width-U-K);if(M.inlines.some((F)=>F.kind==="image")){let F=s0(J);return i0($,M,F,J,G,N,A).reduce((H,b)=>H+b.height,0)}let B=M5({text:M.text,width:G});return Math.max(N,B.lineCount*N)}function AA($,M,J,Z,X,A){let Y=qA(M,X,A),Q=jM($,M,Y);if(Q)return Q;let K=X.paddingY??0,q=[],N=new Map;for(let U=0;U<M.regions.length;U+=1){let G=M.regions[U],B=J.get(G.blockId)??null;if(B?.type==="table"){let b=YA({block:B,blockMap:J,containerIndices:N,entries:q,index:U,options:X,runtimeBlocks:Z,totalHeight:K,regions:M.regions});if(b){U=b.nextIndex-1,K=b.totalHeight;continue}}let D=XA($,G,B,Z.get(G.blockId)?.depth??0,X,A),F=K,H=F+D;q.push({bottom:H,top:F}),N.set(G.id,U),K=H+X5(Z,J,M.regions,U,X.blockGap??16)}return RM($,M,Y,{containerIndices:N,entries:q,estimateRegionBounds(U){let G=N.get(U);return G===void 0?null:q[G]??null},totalHeight:K})}function YA({block:$,blockMap:M,containerIndices:J,entries:Z,index:X,options:A,runtimeBlocks:Y,totalHeight:Q,regions:K}){let q=Y.get($.id),N=q?.regionIds??[];if(N.length===0)return null;let U=K.slice(X,X+N.length);if(U.length===0||U[0]?.blockId!==$.id)return null;let G=A.paddingX??0,B=A.indentWidth??24,D=q?.depth??0,F=G+D*B,H=Math.max(h6,A.width-F-G),b=Math.max(1,...$.rows.map((f)=>f.cells.length)),E=H/b,V=Math.max(40,E-b2*2),R=O0($,A.lineHeight??24),O=QA(U,X),j=Q;for(let f=0;f<$.rows.length;f+=1){let z=O.get(f)??[],y=Math.max(R+o0*2,...z.map(({region:W})=>KA(W,V,R)+o0*2)),T=j+y;for(let{index:W,region:_}of z)Z[W]={bottom:T,top:j},J.set(_.id,W);j=T}for(let f=X;f<X+U.length;f+=1){let z=K[f];if(!z||Z[f])continue;Z[f]={bottom:j,top:j},J.set(z.id,f)}return{nextIndex:X+U.length,totalHeight:j+X5(Y,M,K,X+U.length-1,A.blockGap??16)}}function QA($,M){let J=new Map;for(let[Z,X]of $.entries()){let A=X.tableCellPosition?.rowIndex;if(A===void 0)continue;let Y=J.get(A)??[];Y.push({index:M+Z,region:X}),J.set(A,Y)}return J}function KA($,M,J){let Z=M5({text:$.text,width:M});return Math.max(J,Z.lineCount*J)}function qA($,M,J){return[M.width,M.paddingX??0,M.paddingY??0,M.indentWidth??24,M.lineHeight??24,M.blockGap??16,NA($,J)].join(":")}function U3($,M){let J=0,Z=$.entries.length;while(J<Z){let X=J+Z>>1;if($.entries[X].bottom<=M)J=X+1;else Z=X}return J}function G3($,M,J){return`${$5($,J)}:${M.width}:${M.paddingX??0}:${M.indentWidth??24}:${M.lineHeight??24}`}function NA($,M){return $.regions.flatMap((J)=>J.inlines.filter((Z)=>Z.kind==="image"&&Z.image).map((Z)=>{let X=Z.image?M.images.get(Z.image.url):null;return`${Z.image?.url??""}:${Z.image?.width??0}:${X?.status??"loading"}:${X?.intrinsicWidth??0}:${X?.intrinsicHeight??0}`})).join("|")}var A5=null;function UA($){let M=/(\d+(?:\.\d+)?)\s*px/.exec($);return M?Number.parseFloat(M[1]):16}function K0($){A5??=new Map;let M=A5.get($);if(M)return M;let J=D3(),Z=Math.max(12,Math.round(UA($)));if(!J){let G={ascent:Math.round(Z*0.8),descent:Math.max(2,Z-Math.round(Z*0.8)),emHeight:Z};return A5.set($,G),G}J.font=$;let X=J.measureText("Hg"),A=Math.round(X.actualBoundingBoxAscent||0),Y=Math.round(X.actualBoundingBoxDescent||0),Q=A+Y,K=Math.max(Z,Q),q=Q>0?A:Math.round(K*0.8),N=Q>0?Y:Math.max(2,K-q),U={ascent:q,descent:N,emHeight:K};return A5.set($,U),U}function GA($,M){let{emHeight:J}=K0(M);return Math.max(0,Math.floor(($-J)/2))}function B3($,M){let{ascent:J}=K0(M);return GA($,M)+J}var Y5;function F3($,M){let J=D3();if(!J||$.length===0)return 0;return J.font=M,J.measureText($).width}function D3(){if(Y5!==void 0)return Y5;return Y5=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):typeof document<"u"?document.createElement("canvas"):null)?.getContext("2d")??null,Y5}var BA=18,FA=14,DA=22;function C1($,M,J){let Z=HA($,J);if(!Z)return null;return _3($,M,Z,J.x)}function c6($,M,J){let Z=$.lines[$.lines.length-1];if(!Z||J.y<=Z.top+Z.height)return null;return _3($,M,Z,J.x)}function _3($,M,J,Z){let X=$.regionMetrics.get(J.regionId);if(!X)return null;let A=Math.max(0,Z-N0(M,J)-J.left),Y=N3(J.boundaries,A),Q=Math.min(X.textLength,J.start+Y);return{regionId:J.regionId,offset:Q,left:x1(J,Y),top:J.top,height:J.height}}function x6($,M,J,Z){let X=o6(M,Z.regionId);if(!X)return null;let A=C1($,M,J);if(A)return{regionId:A.regionId,offset:A.offset};let Y=J.y<WA($);return{regionId:Z.regionId,offset:Y?0:X.text.length}}function d6($,M,J){let Z=C1($,M,J);if(!Z)return null;let X=o6(M,Z.regionId);if(!X||X.text.length===0)return null;let A=Z.offset<X.text.length&&/\w/.test(X.text[Z.offset]??"")?Z.offset:Z.offset>0&&/\w/.test(X.text[Z.offset-1]??"")?Z.offset-1:Z.offset,Y=TA(X.text,A);if(Y.start===Y.end)return null;return{anchor:{regionId:Z.regionId,offset:Y.start},focus:{regionId:Z.regionId,offset:Y.end}}}function H3($,M,J){let Z=PA($,J);if(!Z||Z.start!==0)return null;let X=n0(M,Z.blockId,"listItem");if(!X)return null;if(j2(M,X.id)?.kind!=="task")return null;let Y=w2(Z),Q=Y.left-4,K=Y.left+Y.size+4,q=Y.top-4,N=Y.top+Y.size+4;return J.x>=Q&&J.x<=K&&J.y>=q&&J.y<=N?{listItemId:X.id}:null}function P3($,M,J){let Z=C1($,M,J);if(!Z)return null;let X=o6(M,Z.regionId);if(!X)return null;let A=X.inlines.find((Q)=>Q.link&&Z.offset>=Q.start&&Z.offset<Q.end);if(!A?.link)return null;let Y=i6($,M,Z.regionId,A.start);if(!Y)return null;return{anchorBottom:Y.anchorBottom,anchorLeft:Y.anchorLeft,endOffset:A.end,regionId:Z.regionId,startOffset:A.start,title:A.link.title,url:A.link.url}}function a6($,M,J,Z){let X=H3($,M,J);if(X)return{kind:"task-toggle",listItemId:X.listItemId};let A=C1($,M,J);if(!A)return null;let Y=W3(A.regionId,A.offset,Z),Q=Y!==null?T3(Y,$,M,Z):null,K=P3($,M,J);if(K)return{anchorBottom:Q?.anchorBottom??K.anchorBottom,anchorLeft:Q?.anchorLeft??K.anchorLeft,endOffset:K.endOffset,kind:"link",commentThreadIndex:Y,regionId:K.regionId,startOffset:K.startOffset,title:K.title,url:K.url};return{anchorBottom:Q?.anchorBottom??A.top+A.height,anchorLeft:Q?.anchorLeft??A.left,kind:"text",commentThreadIndex:Y}}function s6($,M,J,Z){let X=M.documentIndex.regionIndex.get(J.regionId);if(!X)return null;let A=W3(J.regionId,J.offset,Z),Y=A!==null?T3(A,$,M,Z):null,Q=X.inlines.find((K)=>J.offset>=K.start&&J.offset<=K.end)??null;if(Q?.link){let K=i6($,M,J.regionId,Q.start);if(!K)return null;return{anchorBottom:Y?.anchorBottom??K.anchorBottom,anchorLeft:Y?.anchorLeft??K.anchorLeft,commentThreadIndex:A,endOffset:Q.end,kind:"link",regionId:J.regionId,startOffset:Q.start,title:Q.link.title,url:Q.link.url}}if(Y)return{anchorBottom:Y.anchorBottom,anchorLeft:Y.anchorLeft,commentThreadIndex:A,kind:"text"};return null}function d1($,M,J){let Z=$0(M,J.regionId,J.offset);if(!Z)return J.left;return J.left+N0($,Z)+_A($,Z,J.offset)}function q0($,M,J){return x1(M,J)+N0($,M)}function N0($,M){let J=n0($,M.blockId,"listItem");if(!J)return 0;return j2($,J.id)?.kind==="task"?DA:BA}function w2($){return{left:$.left,size:FA,top:$.top+3}}function n0($,M,J){let Z=$.documentIndex.blockIndex.get(M)??null;while(Z){if(Z.type===J)return Z;let X=Z.parentBlockId;Z=X?$.documentIndex.blockIndex.get(X)??null:null}return null}function j2($,M){return $.documentIndex.listItemMarkers.get(M)??null}function W3($,M,J){for(let Z of J)if(Z.regionId===$&&M>=Z.startOffset&&M<=Z.endOffset)return Z.threadIndex;return null}function T3($,M,J,Z){let X=Z.find((A)=>A.threadIndex===$);if(!X)return null;return i6(M,J,X.regionId,X.startOffset)}function i6($,M,J,Z){let X=$0($,J,Z);if(!X)return null;return{anchorBottom:X.top+X.height,anchorLeft:x1(X,Z)+N0(M,X)}}function _A($,M,J){if(J<=M.end)return 0;let Z=$.documentIndex.regionIndex.get(M.regionId);if(!Z)return 0;let X=Z.text.slice(M.end,J);if(!/^[ \t]+$/u.test(X))return 0;return F3(X,M.font)}function HA($,M){for(let[Z,X]of $.regionBounds)if(M.x>=X.left&&M.x<=X.right&&M.y>=X.top&&M.y<=X.bottom)return Z5($,Z,M.y)?.line??null;let J=p6($,M)?.line??null;if(J)return J;for(let Z of $.blocks)if(M.y>=Z.top&&M.y<=Z.bottom){for(let X=$.lines.length-1;X>=0;X--)if($.lines[X].blockId===Z.id)return $.lines[X]}return null}function PA($,M){return $.lines.find((J)=>M.y>=J.top-4&&M.y<=J.top+J.height+4)??$.lines.filter((J)=>Math.abs(M.y-(J.top+J.height/2))<=10).sort((J,Z)=>Math.abs(M.y-(J.top+J.height/2))-Math.abs(M.y-(Z.top+Z.height/2)))[0]??null}function o6($,M){return $.documentIndex.regionIndex.get(M)??null}function WA($){return $.lines[0]?.top??0}function TA($,M){let J=M,Z=M;while(J>0&&/\w/.test($[J-1]??""))J-=1;while(Z<$.length&&/\w/.test($[Z]??""))Z+=1;return{end:Z,start:J}}function n6($,M,J,Z=null){let X={height:M.height,overscan:Math.max(160,M.height),top:M.top},A=r6($.documentIndex,M,X,[$.selection.anchor.regionId,$.selection.focus.regionId],J,Z);return{blockMap:E2($.documentIndex.document.blocks),estimateRegionBounds:A.estimateRegionBounds,regionBounds:new Map(A.layout.regionBounds),layout:A.layout,paintHeight:Math.max(240,X.height+X.overscan*2),paintTop:Math.max(0,X.top-X.overscan),totalHeight:A.totalHeight,viewport:{height:X.height,top:X.top}}}function t6($,M,J){return C1(M.layout,$,J)??c6(M.layout,$,J)}function R2($,M,J,Z){return x6(M.layout,$,J,Z)}function e6($,M,J){return d6(M.layout,$,J)}function $8($,M,J,Z){return a6(M.layout,$,J,Z)}function M8($,M,J,Z){return s6(M.layout,$,J,Z)}function J8($,M,J){return c1(M.layout,$.documentIndex,J)}function M0($,M,J){let Z=c1(M.layout,$.documentIndex,J);if(!Z)return null;return{...Z,left:d1($,M.layout,Z)}}function X8($,M,J){let Z=J.trim();if(Z.length===0||M.startOffset===M.endOffset)return null;let X=$.regionIndex.get(M.regionId)??null,A=X?Z8($,X):null;if(!A)return null;return W6({anchor:T2(A,M.startOffset,M.endOffset),body:Z,quote:y2(A,M.startOffset,M.endOffset)})}function f1($){let M="documentIndex"in $?$.documentIndex:$,J=Q5(M),Z=M.document.comments,X=[...Z],A=[];for(let[Y,Q]of Z.entries()){let K=V2(Q,M.document);if(!K.match)continue;let N=J.findBySemanticMatch(K.match.containerId,K.match.containerOrdinal)?.runtimeContainer??null;if(!N)continue;if(K.repair)X[Y]={...Q,anchor:K.repair.anchor,quote:K.repair.quote};A.push({endOffset:K.match.endOffset,resolution:K,regionId:N.id,resolved:Q.resolvedAt!=null,startOffset:K.match.startOffset,threadIndex:Y})}return{liveRanges:A,threads:X}}function A8($,M,J,Z,X,A){if($.document.comments.length===0)return M.document.comments;let Y=$.commentContainerIndex.get(J.semanticRegionId)??[],Q=new Set(Y);if(Y.length===0)return M.document.comments;let K=f1($),q=new Map(K.liveRanges.map((B)=>[B.threadIndex,B])),N=Z8($,J),U=t0(M,J.path),G=U?Z8(M,U):null;if(!N||!G)return M.document.comments;return M.document.comments.map((B,D)=>{if(!Q.has(D))return B;let F=q.get(D),H=F?.resolution.match??null;if(!F||!H||H.containerId!==N.id)return B;let b=VA(H.startOffset,H.endOffset,Z,X,A.length);if(!b)return B;return{...B,anchor:T2(G,b.start,b.end),quote:y2(G,b.start,b.end)}})}function Z8($,M){let J=yA($,M);if(!J)return null;return{containerKind:J,containerOrdinal:-1,id:M.semanticRegionId,text:M.text}}function yA($,M){if($.tableCellIndex.has(M.id))return"tableCell";switch(M.blockType){case"code":return"code";case"heading":case"paragraph":return"text";default:return null}}function VA($,M,J,Z,X){let A=Z-J,Y=X-A;if(Z<=$)return{end:M+Y,start:$+Y};if(J>=M)return{end:M,start:$};let Q=Math.max(0,Math.min(J,M)-$),K=Math.max(0,M-Math.max(Z,$)),q=$<J?$:J;return{end:q+Q+X+K,start:q}}function K5($,M){if(M.length===0)return[];let J=Q5($),Z=J.list();return M.map((X)=>({...X,cursorPoint:zA(X,Z,J),viewport:null}))}function zA($,M,J){if(!$.cursor)return null;let Z=OA(M,$.cursor),X=bA(Z,$.cursor);if(X.length!==1)return null;let A=X[0],Y=J.resolveRuntimeContainer(A.container.id);if(!Y)return null;return{offset:Math.max(0,Math.min(A.offset,Y.text.length)),regionId:Y.id}}function OA($,M){return M.kind?$.filter((J)=>J.containerKind===M.kind):$}function bA($,M){if(M.prefix&&M.suffix)return CA($,M.prefix,M.suffix);if(M.prefix)return y3($,M.prefix,"after");if(M.suffix)return y3($,M.suffix,"before");return[]}function y3($,M,J){if(M.length===0)return[];let Z=[];for(let X of $)for(let A of V3(X.text,M))Z.push({container:X,offset:J==="after"?A+M.length:A});return Z}function CA($,M,J){if(M.length===0||J.length===0)return[];let Z=[];for(let X of $)for(let A of V3(X.text,M)){let Y=A+M.length;if(X.text.indexOf(J,Y)!==-1)Z.push({container:X,offset:Y})}return Z}function V3($,M){let J=[],Z=0;while(Z<=$.length){let X=$.indexOf(M,Z);if(X===-1)break;J.push(X),Z=X+Math.max(1,M.length)}return J}var EA=48;function q5($,M,J){let Z="documentIndex"in $?$.documentIndex:$;if(J.length===0)return[];return J.map((X)=>({...X,viewport:wA(Z,M,X)}))}function wA($,M,J){if(!J.cursorPoint)return z3();let Z=c1(M.layout,$,J.cursorPoint),X=Z?{bottom:Z.top+Z.height,top:Z.top}:M.estimateRegionBounds(J.cursorPoint.regionId);if(!X)return z3();return{scrollTop:RA(M,X),status:jA(M,X)}}function jA($,M){let J=$.viewport.top,Z=J+$.viewport.height;if(M.bottom<J)return"above";if(M.top>Z)return"below";return"visible"}function RA($,M){let J=Math.max(0,$.totalHeight-$.viewport.height),Z=M.top-Math.min(EA,$.viewport.height/4);return Math.max(0,Math.min(J,Z))}function z3(){return{scrollTop:null,status:"unresolved"}}function Q5($){let M=i4($.document),J=new Map(M.map((X)=>[X.id,X])),Z=new Map($.regions.map((X)=>[X.semanticRegionId,X]));return{findBySemanticMatch(X,A){let Y=J.get(X)??M[A]??null;if(!Y)return null;return{runtimeContainer:Z.get(Y.id)??null,semanticContainer:Y}},list(X){return X?M.filter((A)=>A.containerKind===X):M},resolveRuntimeContainer(X){return Z.get(X)??null}}}var L2="",O3=1e6;function k2($,M,J){return`${$}:${M}:${J}`}function U1($){let M=[];for(let J of $){let Z=M.at(-1);if(Z?.type==="text"&&J.type==="text"&&Z.marks.join(",")===J.marks.join(",")){M[M.length-1]=W1({marks:Z.marks,path:Z.id,text:Z.text+J.text});continue}M.push(J)}return M}function e0($){let M=aA($),J=Q8(M.blocks.map((Z,X)=>u2(Z,X)));return K8(M,J)}function u2($,M){let J=[],Z=[],X=[],A=0;function Y(K,q,N,U,G=null){if(Z.length>0)X.push(`
20
- `),A+=1;let B=N.map((H)=>H.text).join(""),D=A,F=D+B.length;X.push(B),A=F,Z.push({blockId:K.id,blockType:K.type,end:F,id:`${K.id}:${q}`,path:q,rootIndex:M,inlines:N,semanticRegionId:U,start:D,tableCellPosition:G,text:B})}function Q(K,q,N,U){let G={childBlockIds:[],depth:N,end:A,id:K.id,parentBlockId:U,path:q,regionIds:[],rootIndex:M,start:A,type:K.type};switch(J.push(G),K.type){case"blockquote":case"listItem":for(let[B,D]of K.children.entries())G.childBlockIds.push(D.id),Q(D,`${q}.children.${B}`,N+1,K.id);break;case"code":{Y(K,`${q}.source`,[{end:K.source.length,id:`${K.id}:code`,image:null,inlineCode:!1,kind:"text",link:null,marks:[],originalType:null,start:0,text:K.source}],K.id),G.regionIds.push(Z.at(-1).id);break}case"heading":case"paragraph":Y(K,`${q}.children`,Y8(K.children),K.id),G.regionIds.push(Z.at(-1).id);break;case"list":for(let[B,D]of K.items.entries())G.childBlockIds.push(D.id),Q(D,`${q}.children.${B}`,N+1,K.id);break;case"table":for(let[B,D]of K.rows.entries())for(let[F,H]of D.cells.entries())Y(K,`${q}.rows.${B}.cells.${F}`,Y8(H.children),H.id,{cellIndex:F,rowIndex:B}),G.regionIds.push(Z.at(-1).id);break;case"thematicBreak":break;case"directive":break;case"unsupported":Y(K,`${q}.source`,[{end:K.source.length,id:`${K.id}:unsupported`,image:null,inlineCode:!1,kind:"unsupported",link:null,marks:[],originalType:K.originalType,start:0,text:K.source}],K.id),G.regionIds.push(Z.at(-1).id);break}G.end=A}return Q($,`root.${M}`,0,null),{blockRange:{end:J.length,start:0},blocks:J,end:A,length:A,regionRange:Z.length>0?{end:Z.length,start:0}:void 0,regions:Z,rootIndex:M,start:0,text:X.join("")}}function Q8($,M=null){let J=[],Z=0,X=0,A=0,Y=!1;for(let[Q,K]of $.entries()){if(K.regions.length>0&&Y)A+=1;let q={...K,blockRange:{end:Z+K.blocks.length,start:Z},end:A+K.length,regionRange:K.regions.length>0?{end:X+K.regions.length,start:X}:void 0,start:A},N=M?.[Q];if(J.push(kA(N,K,q)?N:b3(K,q)),Z=q.blockRange.end,X=q.regionRange?.end??X,K.regions.length>0)A=q.end,Y=!0}return J}function $2($,M,J,Z){let X=M.blocks.length-($.roots.length-Z);if(X<0)throw Error("Editor model splice received an invalid replacement count.");if(J===$.roots.length&&X===1){let K=M.blocks[J];if(K)return LA($,M,K)}let A=X===Z,Y=[...$.roots.slice(0,J),...M.blocks.slice(J,J+X).map((K,q)=>u2(K,J+q)),...A?$.roots.slice(J+Z):M.blocks.slice(J+X).map((K,q)=>u2(K,J+X+q))],Q=Q8(Y,$.roots);return K8(M,Q,$)}function LA($,M,J){let Z=$.roots.length,X=u2(J,Z),A=$.roots.some((N)=>N.regions.length>0),Y=X.regions.length>0&&A?$.length+1:$.length,Q=b3(X,{...X,blockRange:{end:$.blocks.length+X.blocks.length,start:$.blocks.length},end:Y+X.length,regionRange:X.regions.length>0?{end:$.regions.length+X.regions.length,start:$.regions.length}:void 0,start:Y}),K=[...$.blocks,...Q.blocks],q=[...$.regions,...Q.regions];return{blockIndex:vA($.blockIndex,Q.blocks),blocks:K,commentContainerIndex:M.comments===$.document.comments?$.commentContainerIndex:C3(M),document:M,engine:"canvas",length:Q.end,listItemMarkers:M.blocks===$.document.blocks?$.listItemMarkers:rA($.listItemMarkers,J),regionIndex:gA($.regionIndex,Q.regions),regionOrderIndex:hA($.regionOrderIndex,Q.regions,$.regions.length),regionPathIndex:IA($.regionPathIndex,Q.regions),regions:q,roots:[...$.roots,Q],tableCellIndex:pA($.tableCellIndex,Q.regions),tableCellRegionIndex:lA($.tableCellRegionIndex,Q.regions),text:cA($.text,Q)}}function S2($,M){if(M.blocks!==$.document.blocks)throw Error("Editor model document replacement requires preserving root blocks.");return K8(M,$.roots,$)}function K8($,M,J=null){let Z=M.flatMap((N)=>N.blocks),X=M.flatMap((N)=>N.regions),{regionIndex:A,regionOrderIndex:Y,regionPathIndex:Q,tableCellIndex:K,tableCellRegionIndex:q}=mA(X);return{blockIndex:SA(Z),blocks:Z,commentContainerIndex:$.comments===J?.document.comments?J.commentContainerIndex:C3($),document:$,engine:"canvas",length:M.at(-1)?.end??0,listItemMarkers:$.blocks===J?.document.blocks?J.listItemMarkers:dA($.blocks),regionIndex:A,regionOrderIndex:Y,regionPathIndex:Q,regions:X,roots:M,tableCellIndex:K,tableCellRegionIndex:q,text:xA(M)}}function b3($,M){let J=M.start-$.start;return{...M,blocks:J===0?$.blocks:fA($.blocks,J),regions:J===0?$.regions:uA($.regions,J)}}function kA($,M,J){return Boolean($&&M===$&&$.start===J.start&&$.end===J.end&&$.blockRange.start===J.blockRange.start&&$.blockRange.end===J.blockRange.end&&$.regionRange?.start===J.regionRange?.start&&$.regionRange?.end===J.regionRange?.end)}function fA($,M){return $.map((J)=>({...J,end:J.end+M,start:J.start+M}))}function uA($,M){return $.map((J)=>({...J,end:J.end+M,start:J.start+M}))}function SA($){let M=new Map;for(let J of $)M.set(J.id,J);return M}function mA($){let M=new Map,J=new Map,Z=new Map,X=new Map,A=new Map;for(let[Y,Q]of $.entries()){if(M.set(Q.id,Q),J.set(Q.id,Y),Z.set(Q.path,Q),!Q.tableCellPosition)continue;X.set(Q.id,Q.tableCellPosition),A.set(k2(Q.blockId,Q.tableCellPosition.rowIndex,Q.tableCellPosition.cellIndex),Q.id)}return{regionIndex:M,regionOrderIndex:J,regionPathIndex:Z,tableCellIndex:X,tableCellRegionIndex:A}}function vA($,M){let J=new Map($);for(let Z of M)J.set(Z.id,Z);return J}function gA($,M){let J=new Map($);for(let Z of M)J.set(Z.id,Z);return J}function hA($,M,J){let Z=new Map($);for(let[X,A]of M.entries())Z.set(A.id,J+X);return Z}function IA($,M){let J=new Map($);for(let Z of M)J.set(Z.path,Z);return J}function pA($,M){let J=new Map($);for(let Z of M)if(Z.tableCellPosition)J.set(Z.id,Z.tableCellPosition);return J}function lA($,M){let J=new Map($);for(let Z of M){if(!Z.tableCellPosition)continue;J.set(k2(Z.blockId,Z.tableCellPosition.rowIndex,Z.tableCellPosition.cellIndex),Z.id)}return J}function rA($,M){let J=new Map($);return f2(J,[M]),J}function cA($,M){if(M.regions.length===0)return $;return $.length>0?`${$}
21
- ${M.text}`:M.text}function xA($){return $.filter((M)=>M.regions.length>0).map((M)=>M.text).join(`
22
- `)}function C3($){let M=new Map;for(let[J,Z]of $.comments.entries()){let X=V2(Z,$).match?.containerId??null;if(!X)continue;let A=M.get(X)??[];A.push(J),M.set(X,A)}return M}function dA($){let M=new Map;return f2(M,$),M}function f2($,M,J=null){for(let Z of M){if(Z.type==="list"){for(let[X,A]of Z.items.entries())f2($,[A],{index:X,ordered:Z.ordered,start:Z.start});continue}if(Z.type==="listItem"){if(typeof Z.checked==="boolean")$.set(Z.id,{checked:Z.checked,kind:"task"});else if(J?.ordered)$.set(Z.id,{kind:"ordered",label:`${(J.start??1)+J.index}.`});else $.set(Z.id,{kind:"bullet",label:"•"});f2($,Z.children,J)}if(Z.type==="blockquote")f2($,Z.children,J)}}function aA($){if($.blocks.length>0)return $;return h0([I({text:""})],$.comments)}function Y8($,M=null){let J=[],Z=0,X=(A)=>{let Y=Z,Q=Y+A.text.length;J.push({...A,end:Q,start:Y}),Z=Q};for(let A of $)switch(A.type){case"break":X({id:A.id,image:null,inlineCode:!1,kind:"break",link:M,marks:[],originalType:null,text:`
23
- `});break;case"image":X({id:A.id,image:{alt:A.alt,title:A.title,url:A.url,width:A.width},inlineCode:!1,kind:"image",link:M,marks:[],originalType:null,text:sA(A.alt)});break;case"inlineCode":X({id:A.id,image:null,inlineCode:!0,kind:"inlineCode",link:M,marks:[],originalType:null,text:A.code});break;case"link":for(let Y of Y8(A.children,{title:A.title,url:A.url}))X(Y);break;case"text":X({id:A.id,image:null,inlineCode:!1,kind:"text",link:M,marks:A.marks,originalType:null,text:A.text});break;case"unsupported":X({id:A.id,image:null,inlineCode:!1,kind:"unsupported",link:M,marks:[],originalType:A.originalType,text:A.source});break}return J}function sA($){return L2}function N5($,M){let J=$.regionIndex.get(M);if(!J)return null;let Z=l0($.document.blocks,J.blockId);if(!Z)return null;return U5(Z,J.path,J.semanticRegionId)}function w3($,M,J,Z,X){if(J>=Z)return null;let A=N5($,M);return A?X(A,J,Z):null}function m2($,M,J,Z,X){let A=w3($,M,J,Z,X);return A?{kind:"replace-block",block:A.block,blockId:A.blockId,selection:A.selection}:null}function U5($,M,J){if($.type==="heading"||$.type==="paragraph")return{block:$,children:$.children,kind:"inlineBlock",path:M.replace(/\.children$/,"")};if($.type!=="table")return null;let Z=/^(.*\.rows\.\d+\.cells\.\d+)$/.exec(M);if(!Z)return null;for(let X of $.rows)for(let A of X.cells)if(A.id===J)return{block:$,blockPath:Z[1].replace(/\.rows\.\d+\.cells\.\d+$/,""),cell:A,children:A.children,kind:"tableCell",path:Z[1]};return null}function U0($,M,J,Z){switch($.kind){case"inlineBlock":return{block:k1($.block,M),blockId:$.block.id,selection:E3(`${$.path}.children`,J,Z)};case"tableCell":{let X=X0({children:M,path:$.path}),A=$.block.rows.map((Y)=>({...Y,cells:Y.cells.map((Q)=>Q.id===$.cell.id?X:Q)}));return{block:r1($.block,A),blockId:$.block.id,selection:E3($.path,J,Z)}}}}function E3($,M,J){return{endOffset:J,kind:"region-range-path",path:$,startOffset:M}}function P1($){switch($.type){case"break":return 1;case"image":return L2.length;case"inlineCode":return $.code.length;case"link":return F1($.children).length;case"text":return $.text.length;case"unsupported":return $.source.length}}function G5($,M,J){if(M<=0)return[];return q8($,0,M,`${J}.before`)}function B5($,M,J){let Z=P1($);if(M>=Z)return[];return q8($,M,Z,`${J}.after`)}function q8($,M,J,Z){if(M>=J)return[];switch($.type){case"text":return U1([b0($.text.slice(M,J),$.marks,Z)].filter(Boolean));case"inlineCode":return[U8($.code.slice(M,J),Z)];case"link":{let X=U1(iA($.children,M,J,`${Z}.children`));return X.length>0?[{...$,children:X}]:[]}default:return[]}}function N8($,M,J){let Z=0,X="";for(let A of $){let Y=P1(A),Q=Z,K=Q+Y;if(Z=K,J<=Q||M>=K)continue;X+=oA(A,Math.max(0,M-Q),Math.min(Y,J-Q))}return X}function b0($,M,J){if($.length===0)return null;return W1({marks:M,path:J,text:$})}function U8($,M){return S0({code:$,path:M})}function iA($,M,J,Z){let X=[],A=0;for(let[Y,Q]of $.entries()){let K=P1(Q),q=A,N=q+K;if(A=N,J<=q||M>=N)continue;X.push(...q8(Q,Math.max(0,M-q),Math.min(K,J-q),`${Z}.${Y}`))}return X}function oA($,M,J){if(M>=J)return"";switch($.type){case"break":return`
24
- `.slice(M,J);case"image":return L2.slice(M,J);case"inlineCode":return $.code.slice(M,J);case"link":return N8($.children,M,J);case"text":return $.text.slice(M,J);case"unsupported":return $.source.slice(M,J)}}function G8($,M,J,Z){let X=nA($.children,M,J,Z);if(X===null)return null;let A=U1(j3($.children,M,J,Z,X,`${$.path}.children`));return A.length>0?U0($,A,M,J):null}function B8($,M,J){let Z=0,X=null,A=(Y)=>{for(let Q of Y){let K=P1(Q),q=Z,N=q+K;if(Z=N,J<=q||M>=N)continue;if(Q.type==="text"){let U=Math.max(M,q);if(Math.min(J,N)>U)X=X===null?new Set(Q.marks):new Set(Q.marks.filter((B)=>X?.has(B)));continue}if(Q.type==="link"){let U=Z;Z=q,A(Q.children),Z=U}}};return A($.children),X?[...X]:[]}function nA($,M,J,Z){let X=0,A=!1,Y=!0,Q=(K)=>{for(let q of K){let N=P1(q),U=X,G=U+N;if(X=G,J<=U||M>=G)continue;if(q.type==="text"){let B=Math.max(M,U);if(Math.min(J,G)>B)A=!0,Y&&=q.marks.includes(Z);continue}if(q.type==="link"){let B=X;X=U,Q(q.children),X=B}}};return Q($),A?Y:null}function j3($,M,J,Z,X,A){let Y=[],Q=0;for(let[K,q]of $.entries()){let N=Q,U=P1(q),G=N+U,B=`${A}.${K}`;if(Q=G,J<=N||M>=G){Y.push(q);continue}if(q.type==="text"){Y.push(...tA(q,Math.max(0,M-N),Math.min(U,J-N),Z,X,B));continue}if(q.type==="link"){let D=U1(j3(q.children,Math.max(0,M-N),Math.min(U,J-N),Z,X,`${B}.children`));if(D.length>0)Y.push({...q,children:D});continue}Y.push(q)}return Y}function tA($,M,J,Z,X,A){let Y=$.text.slice(0,M),Q=$.text.slice(M,J),K=$.text.slice(J),q=X?$.marks.filter((N)=>N!==Z):eA($.marks,Z);return[b0(Y,$.marks,`${A}.before`),b0(Q,q,`${A}.selected`),b0(K,$.marks,`${A}.after`)].filter(Boolean)}function eA($,M){return $.includes(M)?$:[...$,M].sort()}function F8($,M,J){let Z=U1($Y($.children,M,J,`${$.path}.children`));return Z.length>0?U0($,Z,M,J):null}function $Y($,M,J,Z){let X=L3($,M,J);if(X)return R3($,M,J,X.code,Z,!1);let A=N8($,M,J);if(A.length===0)return $;return R3($,M,J,A,Z,!0)}function L3($,M,J){let Z=0;for(let X of $){let A=P1(X),Y=Z,Q=Y+A;if(Z=Q,M===Y&&J===Q&&X.type==="inlineCode")return X;if(X.type==="link"){let K=L3(X.children,Math.max(0,M-Y),Math.min(A,J-Y));if(K)return K}}return null}function R3($,M,J,Z,X,A){let Y=[],Q=0,K=!1;for(let[q,N]of $.entries()){let U=`${X}.${q}`,G=P1(N),B=Q,D=B+G;if(Q=D,J<=B||M>=D){Y.push(N);continue}if(!K){Y.push(...G5(N,Math.max(0,M-B),U));let F=A?U8(Z,`${X}.selected`):b0(Z,[],`${X}.selected`);if(F)Y.push(F);K=!0}Y.push(...B5(N,Math.min(G,J-B),U))}return Y}function F5($,M,J,Z,X){return m2($,M,J,Z,(A,Y,Q)=>k3(A,Y,Q,X))}function k3($,M,J,Z){let X=U1(MY($.children,M,J,Z,`${$.path}.children`)??[]);return X.length>0?U0($,X,M,J):null}function MY($,M,J,Z,X){let A=[],Y=0,Q=!1;for(let[K,q]of $.entries()){let N=`${X}.${K}`,U=P1(q),G=Y,B=G+U;if(Y=B,!Q&&q.type==="link"&&M===G&&J===B){if(Z===null)A.push(...q.children);else A.push(m0({children:q.children,path:N,title:q.title,url:Z}));Q=!0;continue}A.push(q)}return Q?A:null}function D8($,M,J){let Z=U1(JY($.children,M,J,`${$.path}.children`));return U0($,Z,M+1,M+1)}function JY($,M,J,Z){let X=[],A=0,Y=!1;for(let[Q,K]of $.entries()){let q=`${Z}.${Q}`,N=P1(K),U=A,G=U+N;if(A=G,J<=U||M>=G){X.push(K);continue}if(!Y)X.push(...G5(K,Math.max(0,M-U),q)),X.push(H2({path:`${Z}.selected`})),Y=!0;X.push(...B5(K,Math.min(N,J-U),q))}if(!Y)X.push(H2({path:`${Z}.selected`}));return X}function X1($,M,J=0){return{childIndices:M,kind:"descendant-primary-region",offset:J,rootIndex:$}}function M1($,M=0){return{kind:"root-primary-region",offset:M,rootIndex:$}}function G0($,M,J,Z=0){return{cellIndex:J,kind:"table-cell",offset:Z,rootIndex:$,rowIndex:M}}function J0($,M){return $.regionIndex.get(M)??null}function t0($,M){return $.regionPathIndex.get(M)??null}function M2($,M,J,Z){let X=$.tableCellRegionIndex.get(k2(M,J,Z));return X?$.regionIndex.get(X)??null:null}function H8($){return $.anchor.regionId===$.focus.regionId&&$.anchor.offset===$.focus.offset}function n($,M){let J="documentIndex"in $?$.documentIndex:$,Z="documentIndex"in $?$.selection:M,X=f3(J,Z.anchor),A=f3(J,Z.focus);if(X<=A)return{end:Z.focus,start:Z.anchor};return{end:Z.anchor,start:Z.focus}}function v2($,M){if(!M)return null;if("kind"in M){if(M.kind==="root-primary-region"){let Z=$.document.blocks[M.rootIndex],X=Z?_8($,Z):null;return X?D5(X.id,_5(X.text,M.offset)):null}if(M.kind==="descendant-primary-region"){let Z=$.document.blocks[M.rootIndex],X=Z?ZY(Z,M.childIndices):null,A=X?_8($,X):null;return A?D5(A.id,_5(A.text,M.offset)):null}if(M.kind==="table-cell"){let Z=$.document.blocks[M.rootIndex];if(!Z||Z.type!=="table")return null;let X=M2($,Z.id,M.rowIndex,M.cellIndex);return X?D5(X.id,_5(X.text,M.offset)):null}let J=t0($,M.path);if(!J)return null;if(M.kind==="region-path")return D5(J.id,_5(J.text,M.offset));return{anchor:{regionId:J.id,offset:Math.max(0,Math.min(M.startOffset,J.text.length))},focus:{regionId:J.id,offset:Math.max(0,Math.min(M.endOffset,J.text.length))}}}return M}function f3($,M){let J=$.regionOrderIndex.get(M.regionId);if(J===void 0)throw Error(`Unknown canvas region: ${M.regionId}`);return J*O3+M.offset}function D5($,M){let J={offset:M,regionId:$};return{anchor:J,focus:J}}function _5($,M){return M==="end"?$.length:Math.max(0,Math.min(M,$.length))}function ZY($,M){let J=$;for(let Z of M){if(!J)return null;let X=u3(J);if(!X)return null;J=X[Z]??null}return J}function _8($,M){let J=$.blockIndex.get(M.id);if(!J)return null;let Z=J.regionIds[0];if(Z)return $.regionIndex.get(Z)??null;let X=u3(M);if(!X)return null;for(let A of X){let Y=_8($,A);if(Y)return Y}return null}function u3($){switch($.type){case"list":return $.items;case"blockquote":case"listItem":return $.children;default:return null}}function g2($){let M=$.documentIndex.regionIndex.get($.selection.anchor.regionId)??null,J=M?$.documentIndex.blockIndex.get(M.blockId)??null:null,Z=$.selection.anchor.offset,X=M?.inlines.find((A)=>Z>A.start&&Z<A.end)??M?.inlines.find((A)=>A.end===Z)??M?.inlines.find((A)=>A.start===Z)??null;return{block:J?{blockId:J.id,depth:J.depth,nodeType:J.type,text:M?.text??""}:null,span:X?.link?{kind:"link",url:X.link.url}:X&&X.marks.length>0?{kind:"marks",marks:X.marks}:{kind:"none"}}}function H5($){let M=n($.documentIndex,$.selection);if(M.start.regionId!==M.end.regionId||M.start.offset===M.end.offset)return[];let J=$.documentIndex.regionIndex.get(M.start.regionId);if(!J)return[];let Z=l0($.documentIndex.document.blocks,J.blockId);if(!Z)return[];let X=U5(Z,J.path,J.semanticRegionId);return X?B8(X,M.start.offset,M.end.offset):[]}function P5($,M,J,Z=null){return J2($,M,1,[J],Z)}function J2($,M,J,Z,X=null){return{document:I0($.document,M,J,Z),selection:X}}function W5($,M,J,Z=null){return h2($,M,()=>J,Z)}function h2($,M,J,Z=null){let X=$.blockIndex.get(M);if(!X)return null;let A=$.document.blocks[X.rootIndex];if(!A)return null;let Y=S3(A,M,J);return Y?J2($,X.rootIndex,1,[Y],Z):null}function S3($,M,J){if($.id===M)return J($);switch($.type){case"blockquote":{let Z=P8($.children,M,J);return Z?T1({children:Z}):null}case"listItem":{let Z=P8($.children,M,J);return Z?b1($,Z):null}case"list":{let Z=P8($.items,M,J);return Z?$1($,Z):null}default:return null}}function P8($,M,J){let Z=!1,X=$.map((A)=>{let Y=S3(A,M,J);if(!Y)return A;return Z=!0,Y});return Z?X:null}function y5($,M,J){let Z=n($,M);if(Z.start.regionId===Z.end.regionId)return XY($,Z,J);return KY($,Z,J)}function XY($,M,J){let Z=J0($,M.start.regionId);if(!Z)throw Error(`Unknown region: ${M.start.regionId}`);let X=h2($,Z.blockId,(q)=>AY(q,Z,M.start.offset,M.end.offset,J));if(!X)throw Error(`Failed to replace block for canvas region: ${Z.id}`);let A=$2($,X.document,Z.rootIndex,1),Y=$.document.comments.length===0?A:l3($,A,Z,M.start.offset,M.end.offset,J),Q=t0(Y,Z.path);if(!Q)throw Error(`Failed to remap region after replacement: ${Z.path}`);let K=M.start.offset+J.length;return{documentIndex:Y,selection:r3(Q.id,K)}}function AY($,M,J,Z,X){switch($.type){case"heading":case"paragraph":return YY($,M,J,Z,X);case"code":return c4($,m3(M,J,Z,X));case"table":return QY($,M,J,Z,X);case"unsupported":return x4($,m3(M,J,Z,X));default:throw Error(`Canvas text replacement is not supported for block type: ${$.type}`)}}function YY($,M,J,Z,X){let A=p2(M.inlines,J,Z,X),Y=V5(A);return k1($,Y)}function QY($,M,J,Z,X){let A=M.tableCellPosition?.rowIndex,Y=M.tableCellPosition?.cellIndex;if(A===void 0||Y===void 0)throw Error(`Unable to resolve table cell position for region: ${M.id}`);let Q=p2(M.inlines,J,Z,X),K=V5(Q),q=$.rows.map((N,U)=>{if(U!==A)return N;let G=N.cells.map((B,D)=>{if(D!==Y)return B;return X0({children:K})});return{...N,cells:G}});return r1($,q)}function m3($,M,J,Z){return p2($.inlines,M,J,Z).map((X)=>X.text).join("")}function I2($){return $!==null&&($.type==="heading"||$.type==="paragraph")}function KY($,M,J){let Z=J0($,M.start.regionId),X=J0($,M.end.regionId);if(!Z||!X)throw Error("Unknown cross-region selection endpoints.");let A=$.document.blocks[Z.rootIndex],Y=$.document.blocks[X.rootIndex];if(!A||!Y)throw Error("Unknown root blocks for cross-region selection.");let Q=h3(A,Z,M.start.offset),K=I3(Y,X,M.end.offset),q=qY(Q,K,J),N=q.blocks.length>0?q.blocks:[I({text:""})],U=Z.rootIndex,G=X.rootIndex-Z.rootIndex+1,B=I0($.document,U,G,N),D=$2($,B,U,G),F=$.document.comments.length===0?D:l3($,D,Z,M.start.offset,Z.text.length,I2(Q)?J:""),H=F.roots[U+q.caretLocalIndex]?.regions[0]??null;return{documentIndex:F,selection:r3(H?.id??Z.id,H?q.caretOffset:0)}}function qY($,M,J){if(I2($)&&I2(M))return{blocks:[NY($,M,J)],caretLocalIndex:0,caretOffset:$.plainText.length+J.length};if(I2($)){let A=[J.length>0?UY($,J):$];if(M)A.push(M);return{blocks:A,caretLocalIndex:0,caretOffset:$.plainText.length+J.length}}if(I2(M)){let X=J.length>0?GY(M,J):M,A=[];if($)A.push($);let Y=A.length;return A.push(X),{blocks:A,caretLocalIndex:Y,caretOffset:J.length}}let Z=[];if($)Z.push($);if(J.length>0){let X=Z.length;if(Z.push(I({text:J})),M)Z.push(M);return{blocks:Z,caretLocalIndex:X,caretOffset:J.length}}if(M){let X=Z.length;return Z.push(M),{blocks:Z,caretLocalIndex:X,caretOffset:0}}return{blocks:Z,caretLocalIndex:0,caretOffset:0}}function NY($,M,J){let Z=J.length>0?[W1({text:J})]:[];return k1($,U1([...$.children,...Z,...M.children]))}function UY($,M){return k1($,U1([...$.children,W1({text:M})]))}function GY($,M){return k1($,U1([W1({text:M}),...$.children]))}function h3($,M,J){if($.type==="table")return null;if($.id===M.blockId)return BY($,M,J);return p3($,(Z)=>DY(Z,M,J))}function I3($,M,J){if($.type==="table")return null;if($.id===M.blockId)return FY($,M,J);return p3($,(Z)=>_Y(Z,M,J))}function BY($,M,J){if(J===0)return null;switch($.type){case"heading":case"paragraph":{let Z=p2(M.inlines,J,M.text.length,"");return k1($,V5(Z))}case"code":return c4($,M.text.slice(0,J));case"unsupported":return x4($,M.text.slice(0,J));default:return null}}function FY($,M,J){if(J===M.text.length)return null;switch($.type){case"heading":case"paragraph":{let Z=p2(M.inlines,0,J,"");return k1($,V5(Z))}case"code":return c4($,M.text.slice(J));case"unsupported":return x4($,M.text.slice(J));default:return null}}function p3($,M){switch($.type){case"blockquote":{let J=M($.children);return J.length===0?null:T1({children:J})}case"list":{let J=M($.items);return J.length===0?null:$1($,J)}case"listItem":{let J=M($.children);return J.length===0?null:b1($,J)}default:return null}}function DY($,M,J){let Z=$.findIndex((Y)=>T5(Y,M));if(Z===-1)return[];let X=$.slice(0,Z),A=h3($[Z],M,J);return A?[...X,A]:X}function _Y($,M,J){let Z=$.findIndex((Y)=>T5(Y,M));if(Z===-1)return[];let X=$.slice(Z+1),A=I3($[Z],M,J);return A?[A,...X]:X}function T5($,M){if($.id===M.blockId)return!0;switch($.type){case"blockquote":case"listItem":return $.children.some((J)=>T5(J,M));case"list":return $.items.some((J)=>T5(J,M));default:return!1}}function l3($,M,J,Z,X,A){let Y=A8($,M,J,Z,X,A);return Y===M.document.comments?M:S2(M,{...M.document,comments:Y})}function r3($,M){return{anchor:{regionId:$,offset:M},focus:{regionId:$,offset:M}}}function p2($,M,J,Z){let A=HY($,M,J,{didInsert:!1,generatedRunCount:0,replacementText:Z});return VY(zY(A))}function V5($){let M=[];for(let J=0;J<$.length;J+=1){let Z=$[J];if(Z.link){let A=[],Y=Z.link;while(J<$.length&&T8($[J].link,Y)){let Q=g3($[J]);if(Q)A.push(Q);J+=1}if(J-=1,A.length>0)M.push(m0({children:U1(A),title:Y.title,url:Y.url}));continue}let X=g3(Z);if(X)M.push(X)}return U1(M)}function HY($,M,J,Z){let X=[];for(let[A,Y]of $.entries()){if(!Z.didInsert&&M===J&&M===Y.start)W8(X,Z,v3($[A-1]??null,Y));if(J<=Y.start||M>=Y.end){X.push(z5(Y));continue}let Q=Math.max(0,M-Y.start),K=Math.min(Y.text.length,J-Y.start),q=!Z.didInsert&&Z.replacementText.length>0?Z.replacementText:"",N=PY(Y,Q,K,q,Z);if(Q!==K||q.length>0)Z.didInsert=!0;X.push(...N)}if(!Z.didInsert)W8(X,Z,v3($.at(-1)??null,null));return X}function PY($,M,J,Z,X){switch($.kind){case"text":case"inlineCode":case"unsupported":return WY($,M,J,Z);case"break":return TY($,M,J,Z,X);case"image":return yY($,M,J,Z)}}function WY($,M,J,Z){let X=$.text.slice(0,M)+Z+$.text.slice(J);return X.length>0?[{...z5($),text:X}]:[]}function TY($,M,J,Z,X){if(M===J)return[z5($)];let A=[];if(Z.length>0)W8(A,X,$.link);return A}function yY($,M,J,Z){if(M===0&&J===$.text.length)return Z.length>0?[c3(Z,$.link,0)]:[];return[z5($)]}function W8($,M,J){if(M.replacementText.length===0){M.didInsert=!0;return}$.push(c3(M.replacementText,J,M.generatedRunCount)),M.generatedRunCount+=1,M.didInsert=!0}function c3($,M,J){return{id:`generated:${J}`,image:null,inlineCode:!1,kind:"text",link:M,marks:[],originalType:null,text:$}}function v3($,M){return $?.link&&M?.link&&T8($.link,M.link)?$.link:null}function z5($){return{id:$.id,image:$.image,inlineCode:$.inlineCode,kind:$.kind,link:$.link,marks:$.marks,originalType:$.originalType,text:$.text}}function VY($){let M=[],J=0;for(let Z of $){let X=J,A=X+Z.text.length;M.push({...Z,end:A,start:X}),J=A}return M}function zY($){let M=[];for(let J of $){let Z=M.at(-1);if(Z&&OY(Z,J)){M[M.length-1]={...Z,text:Z.text+J.text};continue}M.push(J)}return M}function OY($,M){return $.kind===M.kind&&$.inlineCode===M.inlineCode&&T8($.link,M.link)&&CY($.image,M.image)&&$.originalType===M.originalType&&$.marks.join(",")===M.marks.join(",")}function g3($){switch($.kind){case"break":return H2();case"image":return $.image?bY($.image):null;case"inlineCode":return S0({code:$.text});case"text":return $.text.length>0?W1({marks:$.marks,text:$.text}):null;case"unsupported":return p4({originalType:$.originalType??"unsupported",source:$.text})}}function bY($){return I4({alt:$.alt,title:$.title,url:$.url,width:$.width})}function T8($,M){return $?.url===M?.url&&$?.title===M?.title}function CY($,M){return $?.url===M?.url&&$?.title===M?.title&&$?.alt===M?.alt&&$?.width===M?.width}function x3($,M){switch(M.kind){case"replace-block":return W5($,M.blockId,M.block,M.selection??null);case"replace-root":return P5($,M.rootIndex,M.block,M.selection??null);case"replace-root-range":return J2($,M.rootIndex,M.count,M.replacements,M.selection??null);case"replace-selection":{let J=y5($,M.selection,M.text);return{document:J.documentIndex.document,documentIndex:J.documentIndex,selection:J.selection}}}return null}var y8=new Map([["rgba(0, 0, 0, 0)",[0,0,0,0]]]);function l2($){switch($.kind){case"active-block-flash":return 300;case"deleted-text-fade":return 180;case"inserted-text-highlight":return 1000;case"list-marker-pop":return 500;case"punctuation-pulse":return 140}}function z8($,M){let J=M??wY();return $.animations.some((Z)=>J-Z.startedAt<l2(Z))}function a3($,M){return O8($,M,"inserted-text-highlight",(J)=>J.regionPath)}function s3($,M){return X9($,M,"active-block-flash",(J)=>J.blockPath)}function i3($,M){return O8($,M,"deleted-text-fade",(J)=>J.regionPath)}function o3($,M){return O8($,M,"punctuation-pulse",(J)=>J.regionPath)}function n3($,M){return X9($,M,"list-marker-pop",(J)=>J.blockPath)}function t3($,M,J){let Z=new Set([$,M]);for(let X of J){if(X.endOffset<=$||X.startOffset>=M)continue;Z.add(Math.max($,X.startOffset)),Z.add(Math.min(M,X.endOffset))}return[...Z].sort((X,A)=>X-A)}function e3($,M,J){return $.find((Z)=>Z.startOffset<J&&Z.endOffset>M)??null}function $9($,M,J){if(!M)return $;return c2(J.insertHighlightText,$,M.progress)}function M9($,M){return c2($,"rgba(0, 0, 0, 0)",M.progress)}function b5($,M){return c2($,"rgba(0, 0, 0, 0)",M.progress)}function J9($,M){return c2(M.insertHighlightText,"rgba(0, 0, 0, 0)",$.progress)}function Z9($){let M=Math.min(1,$.progress*2);return 0.1+0.9*EY(M)}function r2($,M,J){let Z=Math.max(0,M.progress*2-1);return c2(J.insertHighlightText,$,Z)}function O8($,M,J,Z){let X=new Map;for(let A of $.animations){if(A.kind!==J)continue;let Y=l2(A),Q=M-A.startedAt;if(Q>=Y)continue;let K={...A,progress:Math.max(0,Math.min(1,Q/Y))},q=Z(A),N=X.get(q);if(N)N.push(K);else X.set(q,[K])}return X}function X9($,M,J,Z){let X=new Map;for(let A of $.animations){if(A.kind!==J)continue;let Y=l2(A),Q=M-A.startedAt;if(Q>=Y)continue;X.set(Z(A),{...A,progress:Math.max(0,Math.min(1,Q/Y))})}return X}function EY($){return 1-(1-$)*(1-$)*(1-$)}function c2($,M,J){let Z=d3($),X=d3(M);return`rgba(${V8(O5(Z[0],X[0],J))}, ${V8(O5(Z[1],X[1],J))}, ${V8(O5(Z[2],X[2],J))}, ${O5(Z[3],X[3],J)})`}function wY(){return typeof performance<"u"?performance.now():Date.now()}function d3($){let M=y8.get($);if(M)return M;let J=jY($)??RY($)??LY($)??y8.get("rgba(0, 0, 0, 0)");return y8.set($,J),J}function jY($){let M=$.trim();if(!M.startsWith("#"))return null;let J=M.slice(1);if(J.length===3)return[Number.parseInt(`${J[0]}${J[0]}`,16),Number.parseInt(`${J[1]}${J[1]}`,16),Number.parseInt(`${J[2]}${J[2]}`,16),1];if(J.length===6)return[Number.parseInt(J.slice(0,2),16),Number.parseInt(J.slice(2,4),16),Number.parseInt(J.slice(4,6),16),1];return null}function RY($){let M=/^rgb\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec($.trim());if(!M)return null;return[Number(M[1]),Number(M[2]),Number(M[3]),1]}function LY($){let M=/^rgba\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec($.trim());if(!M)return null;return[Number(M[1]),Number(M[2]),Number(M[3]),Number(M[4])]}function O5($,M,J){return $+(M-$)*J}function V8($){return Math.round($)}function C5($,M,J=B0()){if(M<=0)return $;let Z=$.documentIndex.regionIndex.get($.selection.focus.regionId);if(!Z)return $;let X=$.selection.focus.offset,A=Math.max(0,X-M);if(X<=A)return $;return x2($,{endOffset:X,kind:"inserted-text-highlight",regionPath:Z.path,startOffset:A,startedAt:J})}function b8($,M,J=B0()){if(M.text.length===0)return $;return x2($,{kind:"deleted-text-fade",regionPath:M.regionPath,startOffset:M.startOffset,startedAt:J,text:M.text})}function C8($,M,J=B0()){return x2($,{blockPath:M,kind:"active-block-flash",startedAt:J})}function E8($,M=B0()){let J=$.documentIndex.regionIndex.get($.selection.focus.regionId),Z=$.selection.focus.offset-1;if(!J||Z<0||J.text[Z]!==".")return $;return x2($,{kind:"punctuation-pulse",offset:Z,regionPath:J.path,startedAt:M})}function w8($,M,J=B0()){return x2($,{blockPath:M,kind:"list-marker-pop",startedAt:J})}function x2($,M){let J=E5($.animations,M.startedAt);return{...$,animations:[...J,M]}}function E5($,M){return $.filter((J)=>J.startedAt+l2(J)>M)}function B0(){return typeof performance<"u"?performance.now():Date.now()}function A9($){let M=$.documentIndex.regionIndex.get($.selection.focus.regionId);return(M?$.documentIndex.blockIndex.get(M.blockId)??null:null)?.path??""}function w5($,M){let J=Math.max(-1/0,...$.animations.map((Z)=>Z.startedAt));return M.animations.some((Z)=>Z.startedAt>J)}function d2($){let M=e0($),J=Q9(M);return{animations:[],documentIndex:M,future:[],history:[],selection:{anchor:J,focus:J}}}function a2($){let M=f1($.documentIndex);return h0(P2($.documentIndex.document.blocks),M.threads)}function a($,M){if(!M)return null;switch(M.kind){case"keep-state":return $;case"set-selection":return K1($,M.selection);default:{let J=x3($.documentIndex,M);if(!J)return null;let Z=kY($,J.document,J.documentIndex??null),X=v2(Z.documentIndex,J.selection)??$.selection,A=K9($,Z,X);return K1(Z,X,A)}}}function K1($,M,J){let Z="regionId"in M?{anchor:j5($.documentIndex,M),focus:j5($.documentIndex,M)}:{anchor:j5($.documentIndex,M.anchor),focus:j5($.documentIndex,M.focus)},X={...$,selection:Z};return J??K9($,X)?C8(X,A9(X)):X}function E1($,M,J,Z){let X={regionId:M,offset:J};return K1($,Z?{anchor:$.selection.anchor,focus:X}:X)}function kY($,M,J=null){let Z=J??e0(M);return{animations:E5($.animations,B0()),documentIndex:Z,future:[],history:[...$.history,{document:$.documentIndex.document,selection:$.selection}],selection:fY(Z)}}function j8($){let M=$.history.at(-1);if(!M)return $;let J=e0(M.document);return{animations:[],documentIndex:J,future:[{document:$.documentIndex.document,selection:$.selection},...$.future],history:$.history.slice(0,-1),selection:M.selection}}function R8($){let M=$.future[0];if(!M)return $;let J=e0(M.document);return{animations:[],documentIndex:J,future:$.future.slice(1),history:[...$.history,{document:$.documentIndex.document,selection:$.selection}],selection:M.selection}}function R5($,M,J,Z){let X=UM($.documentIndex.document,M,J,Z),A=S2($.documentIndex,X);return{animations:E5($.animations,B0()),documentIndex:A,future:[],history:[...$.history,{document:$.documentIndex.document,selection:$.selection}],selection:$.selection}}function fY($){let M=Q9($);return{anchor:M,focus:M}}function Q9($){return $.regions[0]?{regionId:$.regions[0].id,offset:0}:{regionId:"empty",offset:0}}function j5($,M){let J=J0($,M.regionId);if(!J)return M;return{regionId:J.id,offset:Math.max(0,Math.min(M.offset,J.text.length))}}function K9($,M,J){let Z=Y9($.documentIndex,$.selection),X=Y9(M.documentIndex,J??M.selection);return X!==null&&X!==Z}function Y9($,M){let J=$.regionIndex.get(M.focus.regionId),Z=J?$.blockIndex.get(J.blockId)??null:null;if(!J||!Z?.path)return null;return Z.type==="table"?`cell:${J.path}`:`block:${Z.path}`}function o2($,M){let J=$.regionIndex.get(M.anchor.regionId);if(!J)return{kind:"unsupported"};if(J.blockType==="code"){let Q=$.blockIndex.get(J.blockId);return Q?{kind:"code",region:J,rootIndex:Q.rootIndex}:{kind:"unsupported"}}let Z=F0($,J.id);if(Z)return{kind:"tableCell",...Z};let X=s1($,M);if(X)return{kind:"listItem",...X};let A=Z2($,M);if(A)return{kind:"blockquoteTextBlock",...A};let Y=a1($,M);if(Y)return{kind:"rootTextBlock",...Y};return{kind:"unsupported"}}function n2($,M){let J=$.blockIndex.get(M);if(!J)throw Error(`Unknown root block: ${M}`);return J.rootIndex}function L5($,M,J){let Z=M?$.blockIndex.get(M)??null:null;while(Z){if(Z.type===J)return Z;let X=Z.parentBlockId;Z=X?$.blockIndex.get(X)??null:null}return null}function s2($){let M=$.split("."),J=[];for(let Z=0;Z<M.length-1;Z+=1)if(M[Z]==="children"){let X=Number(M[Z+1]);if(Number.isInteger(X))J.push(X)}return J}function a1($,M){let J=$.regionIndex.get(M.anchor.regionId);if(!J)return null;let Z=$.blockIndex.get(J.blockId);if(!Z)return null;let X=Z.rootIndex,A=$.document.blocks[X];if(!A||A.type!=="heading"&&A.type!=="paragraph")return null;return{block:A,region:J,rootIndex:X}}function q9($,M){let J=$.regionIndex.get(M.anchor.regionId);if(!J)return null;let Z=$.blockIndex.get(J.blockId),X=L5($,Z?.id??null,"blockquote");if(!X)return null;let A=X.rootIndex,Y=$.document.blocks[A];return Y?.type==="blockquote"?{quote:Y,rootIndex:A}:null}function Z2($,M){let J=$.regionIndex.get(M.anchor.regionId);if(!J)return null;let Z=$.blockIndex.get(J.blockId),X=L5($,Z?.id??null,"blockquote");if(!Z||!X||Z.parentBlockId!==X.id)return null;let A=X.rootIndex,Y=$.document.blocks[A];if(!Y||Y.type!=="blockquote")return null;let Q=Y.children.findIndex((q)=>q.id===Z.id),K=Y.children[Q];if(!K||K.type!=="heading"&&K.type!=="paragraph")return null;return{block:K,blockChildIndices:s2(Z.path),childIndex:Q,region:J,quote:Y,rootIndex:A}}function i2($,M){return l0($.document.blocks,M)}function s1($,M){let J=$.regionIndex.get(M.anchor.regionId);if(!J)return null;let Z=$.blockIndex.get(J.blockId),X=L5($,Z?.id??null,"listItem"),A=L5($,Z?.id??null,"list");if(!Z||!X||!A)return null;let Y=i2($,A.id);if(!Y||Y.type!=="list")return null;let Q=Y.items.findIndex((D)=>D.id===X.id),K=Y.items[Q];if(!K)return null;let q=A.parentBlockId?$.blockIndex.get(A.parentBlockId)??null:null,N=q?.parentBlockId?$.blockIndex.get(q.parentBlockId)??null:null,U=q?.type==="listItem"?i2($,q.id):null,G=N?.type==="list"?i2($,N.id):null,B=G?.type==="list"&&U?G.items.findIndex((D)=>D.id===U.id):-1;return{region:J,item:K,itemChildIndices:s2(X.path),itemIndex:Q,list:Y,listChildIndices:s2(A.path),parentItem:U?.type==="listItem"?U:null,parentItemChildIndices:q?.type==="listItem"?s2(q.path):null,parentItemIndex:B>=0?B:null,parentList:G?.type==="list"?G:null,parentListChildIndices:N?.type==="list"?s2(N.path):null,rootIndex:A.rootIndex}}function F0($,M){let J=$.regionIndex.get(M);if(!J)return null;let Z=$.tableCellIndex.get(J.id),X=$.blockIndex.get(J.blockId),A=X?.type==="table"?$.document.blocks[X.rootIndex]:null;if(!Z||!X||!A||A.type!=="table")return null;return{cellIndex:Z.cellIndex,rootIndex:X.rootIndex,rowIndex:Z.rowIndex,table:A}}function t2($,M,J){return n1({checked:M,children:[I({text:$})],spread:J})}function X2($,M){let J=$.children[0];if(!J||J.type!=="paragraph")return null;return b1($,[I({text:M}),...$.children.slice(1)])}function N9($,M){return M.reduce((J,Z)=>`${J}.children.${Z}`,`root.${$}`)}function U9($,M,J){let Z=$.regionIndex.get(M.anchor.regionId);if(!Z)return null;let X=n($,M),A=X.start.regionId===X.end.regionId&&X.start.regionId===Z.id?Z.text.slice(0,X.start.offset)+J+Z.text.slice(X.end.offset):J;return uY($,M,Z.id,A)??mY($,M,Z.id,A)??SY($,M,Z.id,A)??vY($,M,Z.id,A)??IY($,Z.blockId,Z.rootIndex,A)??{kind:"replace-selection",selection:M,text:J}}function uY($,M,J,Z){let X=s1($,M),A=rY(Z);if(!X||!A||X.region.id!==J)return null;let Y=X2(X.item,A.text);if(!Y)return null;return{kind:"replace-block",block:$1(X.list,X.list.items.map((Q,K)=>K===X.itemIndex?Y:Q),{ordered:A.ordered,start:A.ordered?1:null}),blockId:X.list.id,selection:X1(X.rootIndex,[...X.listChildIndices,X.itemIndex,0])}}function SY($,M,J,Z){if(!k8($,M,J))return null;if(/^\s*([-+*])\s\[( |x|X)\]\s$/.exec(Z)){let Y=Z.toLowerCase().includes("[x]");return L8($,M,{checked:Y,ordered:!1,start:null})}if(/^\s*[-+*]\s$/.test(Z))return L8($,M,{checked:null,ordered:!1,start:null});let A=/^\s*(\d+)\.\s$/.exec(Z);if(A)return L8($,M,{checked:null,ordered:!0,start:Number(A[1])});return null}function mY($,M,J,Z){let X=a1($,M),A=cY(Z);if(!X||X.region.id!==J||X.block.type!=="heading"||!A)return null;return{kind:"replace-root",block:Z0({depth:A.depth,text:A.text}),rootIndex:X.rootIndex,selection:M1(X.rootIndex)}}function vY($,M,J,Z){return gY($,M,J,Z)??hY($,M,J,Z)}function gY($,M,J,Z){if(!k8($,M,J))return null;let X=/^(#{1,6})\s$/.exec(Z);if(!X)return null;return pY($,M,X[1].length)}function hY($,M,J,Z){if(!k8($,M,J)||!/^>\s$/.test(Z))return null;return lY($,M)}function IY($,M,J,Z){if(!/^(?:(?:-\s?){3}|(?:\*\s?){3}|(?:_\s?){3})$/.test(Z))return null;return{kind:"replace-root-range",count:1,replacements:[l4(),I({text:""})],rootIndex:n2($,M),selection:M1(J+1)}}function L8($,M,J){let Z=n2($,$.regionIndex.get(M.anchor.regionId).blockId);return{kind:"replace-root",block:y0({items:[n1({checked:J.checked,children:[I({text:""})],spread:!1})],ordered:J.ordered,spread:!1,start:J.start}),rootIndex:Z,selection:X1(Z,[0,0])}}function pY($,M,J){let Z=n2($,$.regionIndex.get(M.anchor.regionId).blockId);return{kind:"replace-root",block:Z0({depth:J,text:""}),rootIndex:Z,selection:M1(Z)}}function lY($,M){let J=n2($,$.regionIndex.get(M.anchor.regionId).blockId);return{kind:"replace-root",block:T1({children:[I({text:""})]}),rootIndex:J,selection:X1(J,[0])}}function k8($,M,J){let Z=a1($,M);return Z?.region.id===J&&Z.block.type==="paragraph"}function rY($){let M=/^[-+*]\s(.+)$/.exec($);if(M)return{ordered:!1,text:M[1]};let J=/^\d+\.\s(.+)$/.exec($);if(J)return{ordered:!0,text:J[1]};return null}function cY($){let M=/^(#{1,6})\s(.+)$/.exec($);return M?{depth:M[1].length,text:M[2]}:null}function G9($,M){let J=n($,M);if(J.start.regionId!==J.end.regionId||J.start.offset!==J.end.offset)return null;let Z=s1($,M);if(!Z)return null;let X=Z.region.text,A=Z.item,Y=typeof A.checked==="boolean"?!1:A.checked;if(J.start.offset===0){let U=t2("",Y,A.spread);return{kind:"replace-block",block:$1(Z.list,[...Z.list.items.slice(0,Z.itemIndex),U,A,...Z.list.items.slice(Z.itemIndex+1)]),blockId:Z.list.id,listItemInsertedPath:k5(U,Z.rootIndex,[...Z.listChildIndices,Z.itemIndex]),selection:X1(Z.rootIndex,[...Z.listChildIndices,Z.itemIndex,0])}}if(J.start.offset===X.length){let U=t2("",Y,A.spread);return{kind:"replace-block",block:$1(Z.list,[...Z.list.items.slice(0,Z.itemIndex+1),U,...Z.list.items.slice(Z.itemIndex+1)]),blockId:Z.list.id,listItemInsertedPath:k5(U,Z.rootIndex,[...Z.listChildIndices,Z.itemIndex+1]),selection:X1(Z.rootIndex,[...Z.listChildIndices,Z.itemIndex+1,0])}}let Q=X.slice(0,J.start.offset),K=X.slice(J.start.offset),q=t2(K,Y,A.spread),N=b1(A,[I({text:Q})]);return{kind:"replace-block",block:$1(Z.list,[...Z.list.items.slice(0,Z.itemIndex),N,q,...Z.list.items.slice(Z.itemIndex+1)]),blockId:Z.list.id,listItemInsertedPath:k5(q,Z.rootIndex,[...Z.listChildIndices,Z.itemIndex+1]),selection:X1(Z.rootIndex,[...Z.listChildIndices,Z.itemIndex+1,0])}}function B9($,M){let J=n($,M),Z=s1($,M);if(!Z||J.start.regionId!==J.end.regionId)return null;if(J.start.offset!==0||Z.region.text.length!==0)return G9($,M);if(Z.parentItem&&Z.parentItemIndex!==null&&Z.parentItemChildIndices&&Z.parentList&&Z.parentListChildIndices)return xY(Z);let X=Z.list.items.slice(0,Z.itemIndex),A=Z.list.items.slice(Z.itemIndex+1),Y=[];if(X.length>0)Y.push($1(Z.list,X));if(Y.push(I({text:""})),A.length>0)Y.push($1(Z.list,A));return{kind:"replace-root-range",count:1,replacements:Y,rootIndex:Z.rootIndex,selection:M1(Z.rootIndex+(X.length>0?1:0))}}function F9($,M){let J=s1($,M);if(!J)return null;if(typeof J.item.checked==="boolean"){let Z=n1({checked:null,children:J.item.children,spread:J.item.spread});return{kind:"replace-block",block:$1(J.list,J.list.items.map((X,A)=>A===J.itemIndex?Z:X)),blockId:J.list.id}}if(J.itemIndex>0){let Z=J.list.items[J.itemIndex-1];if(!Z)return null;if(J.item.plainText.length===0)return{kind:"replace-block",block:$1(J.list,J.list.items.filter((A,Y)=>Y!==J.itemIndex)),blockId:J.list.id,selection:X1(J.rootIndex,[...J.listChildIndices,J.itemIndex-1,0],"end")};let X=X2(Z,`${Z.plainText}${J.item.plainText}`);if(!X)return null;return{kind:"replace-block",block:$1(J.list,J.list.items.flatMap((A,Y)=>{if(Y===J.itemIndex-1)return[X];if(Y===J.itemIndex)return[];return[A]})),blockId:J.list.id,selection:X1(J.rootIndex,[...J.listChildIndices,J.itemIndex-1,0],"end")}}return{kind:"replace-root-range",count:1,replacements:[I({text:J.item.plainText})],rootIndex:J.rootIndex,selection:M1(J.rootIndex)}}function D9($,M){let J=s1($,M);if(!J||J.itemIndex===0)return null;let Z=J.list.items[J.itemIndex-1];if(!Z)return null;let X=dY(Z,J.item,J);return{kind:"replace-block",block:$1(J.list,J.list.items.flatMap((A,Y)=>{if(Y===J.itemIndex-1)return[X.item];if(Y===J.itemIndex)return[];return[A]})),blockId:J.list.id,selection:X1(J.rootIndex,X.regionChildIndices)}}function _9($,M){let J=s1($,M);if(!J||!J.parentItem||J.parentItemIndex===null||!J.parentItemChildIndices||!J.parentList||!J.parentListChildIndices)return null;let Z=J.list.items.filter((Y,Q)=>Q!==J.itemIndex),X=J.parentItem.children.flatMap((Y)=>{if(Y.type!=="list"||Y.id!==J.list.id)return[Y];if(Z.length===0)return[];return[$1(J.list,Z)]}),A=b1(J.parentItem,X);return{kind:"replace-block",block:$1(J.parentList,[...J.parentList.items.slice(0,J.parentItemIndex),A,J.item,...J.parentList.items.slice(J.parentItemIndex+1)]),blockId:J.parentList.id,selection:X1(J.rootIndex,[...J.parentListChildIndices,J.parentItemIndex+1,0])}}function f8($,M,J){let Z=s1($,M);if(!Z)return null;let X=Z.itemIndex+J;if(X<0||X>=Z.list.items.length)return null;let A=[...Z.list.items],[Y]=A.splice(Z.itemIndex,1);if(!Y)return null;return A.splice(X,0,Y),{kind:"replace-block",block:$1(Z.list,A),blockId:Z.list.id,selection:X1(Z.rootIndex,[...Z.listChildIndices,X,0])}}function xY($){if(!$.parentItem||$.parentItemIndex===null||!$.parentItemChildIndices||!$.parentList||!$.parentListChildIndices)return null;let M=$.list.items.filter((Y,Q)=>Q!==$.itemIndex),J=$.parentItem.children.flatMap((Y)=>{if(Y.type!=="list"||Y.id!==$.list.id)return[Y];if(M.length===0)return[];return[$1($.list,M)]}),Z=b1($.parentItem,J),X=typeof $.parentItem.checked==="boolean"?!1:$.parentItem.checked,A=t2("",X,$.parentItem.spread);return{kind:"replace-block",block:$1($.parentList,[...$.parentList.items.slice(0,$.parentItemIndex),Z,A,...$.parentList.items.slice($.parentItemIndex+1)]),blockId:$.parentList.id,listItemInsertedPath:k5(A,$.rootIndex,[...$.parentListChildIndices,$.parentItemIndex+1]),selection:X1($.rootIndex,[...$.parentListChildIndices,$.parentItemIndex+1,0])}}function k5($,M,J){return typeof $.checked==="boolean"?void 0:N9(M,J)}function dY($,M,J){let Z=$.children.findIndex((A)=>A.type==="list"&&A.ordered===J.list.ordered&&A.start===J.list.start);if(Z>=0){let A=$.children[Z];if(!A||A.type!=="list")return{item:$,regionChildIndices:[...J.listChildIndices,J.itemIndex-1,0]};return{item:b1($,$.children.map((Y,Q)=>Q===Z?$1(A,[...A.items,M]):Y)),regionChildIndices:[...J.listChildIndices,J.itemIndex-1,Z,A.items.length,0]}}let X=y0({items:[M],ordered:J.list.ordered,spread:J.list.spread,start:J.list.start});return{item:b1($,[...$.children,X]),regionChildIndices:[...J.listChildIndices,J.itemIndex-1,$.children.length,0,0]}}function f5($,M){let J=n($,M);if(J.start.regionId!==J.end.regionId||J.start.offset!==J.end.offset)return null;let Z=a1($,M);if(!Z)return aY($,M);let X=Z.region.text.slice(0,J.start.offset),A=Z.region.text.slice(J.start.offset),Y=J.start.offset===0&&Z.region.text.length>0?Z.rootIndex:Z.rootIndex+1;if(Z.block.type==="paragraph")return{kind:"replace-root-range",count:1,replacements:J.start.offset===0?[I({text:""}),Z.block]:J.start.offset===Z.region.text.length?[Z.block,I({text:""})]:[I({text:X}),I({text:A})],rootIndex:Z.rootIndex,selection:M1(Y)};return{kind:"replace-root-range",count:1,replacements:J.start.offset===0?[I({text:""}),Z.block]:J.start.offset===Z.region.text.length?[Z.block,I({text:""})]:[Z0({depth:Z.block.depth,text:X}),I({text:A})],rootIndex:Z.rootIndex,selection:M1(Y)}}function aY($,M){let J=n($,M);if(J.start.regionId!==J.end.regionId||J.start.offset!==J.end.offset)return null;let Z=Z2($,M);if(!Z)return null;let X=Z.region.text,A=X.slice(0,J.start.offset),Y=X.slice(J.start.offset),Q=Z.block.type==="heading"?eY(Z.block,A,Y,Z.blockChildIndices,J.start.offset,X.length):tY(Z.block,A,Y,Z.blockChildIndices,J.start.offset,X.length);return{kind:"replace-root",block:T1({children:[...Z.quote.children.slice(0,Z.childIndex),...Q.blocks,...Z.quote.children.slice(Z.childIndex+1)]}),rootIndex:Z.rootIndex,selection:X1(Z.rootIndex,Q.focusChildIndices)}}function H9($,M){let J=n($,M);if(J.start.regionId!==J.end.regionId||J.start.offset!==0||J.end.offset!==0)return null;let Z=Z2($,M);if(!Z||Z.region.text.length!==0||Z.block.type!=="paragraph")return null;let X=Z.quote.children.slice(0,Z.childIndex),A=Z.quote.children.slice(Z.childIndex+1),Y=[];if(X.length>0)Y.push(T1({children:X}));if(Y.push(I({text:""})),A.length>0)Y.push(T1({children:A}));return{kind:"replace-root-range",count:1,replacements:Y,rootIndex:Z.rootIndex,selection:M1(Z.rootIndex+(X.length>0?1:0))}}function P9($,M){let J=n($,M);if(J.start.regionId!==J.end.regionId||J.start.regionId!==M.anchor.regionId)return null;let Z=$.regionIndex.get(J.start.regionId);if(!Z||Z.blockType!=="code")return null;return{kind:"replace-selection",selection:M,text:`
25
- `}}function W9($,M){let J=n($,M);if(J.start.regionId!==J.end.regionId||J.start.offset!==0||J.end.offset!==0)return null;let Z=a1($,M),X=Z?oY(Z):null;if(X)return X;if(Z&&Z.rootIndex>0){let K=$.document.blocks[Z.rootIndex-1],q=$.document.blocks[Z.rootIndex+1];if(K){if(Z.block.plainText.length===0){let N=sY(Z,K,q);if(N)return N;return{kind:"replace-root-range",count:1,replacements:[],rootIndex:Z.rootIndex,selection:K.type==="paragraph"||K.type==="heading"?M1(Z.rootIndex-1,"end"):K.type==="list"?X1(Z.rootIndex-1,[K.items.length-1,0],"end"):K.type==="blockquote"?X1(Z.rootIndex-1,[K.children.length-1],"end"):M1(Z.rootIndex-1,"end")}}if(K.type==="paragraph")return{kind:"replace-root-range",count:2,replacements:[I({text:`${K.plainText}${Z.block.plainText}`})],rootIndex:Z.rootIndex-1,selection:M1(Z.rootIndex-1,"end")};if(K.type==="heading")return{kind:"replace-root-range",count:2,replacements:[Z0({depth:K.depth,text:`${K.plainText}${Z.block.plainText}`})],rootIndex:Z.rootIndex-1,selection:M1(Z.rootIndex-1,"end")};if(K.type==="list"){let N=K.items.length-1,U=K.items[N];if(U){let G=X2(U,`${U.plainText}${Z.block.plainText}`);if(G)return{kind:"replace-root-range",count:2,replacements:[$1(K,K.items.map((B,D)=>D===N?G:B))],rootIndex:Z.rootIndex-1,selection:X1(Z.rootIndex-1,[N,0],"end")}}}}}let A=nY($,M);if(A)return A;let Y=q9($,M);if(!Y)return null;let Q=Z2($,M);return{kind:"replace-root-range",count:1,replacements:Y.quote.children,rootIndex:Y.rootIndex,selection:M1(Q?Y.rootIndex+Q.childIndex:Y.rootIndex)}}function u8($,M,J){let Z=a1($,M);if(!Z||Z.block.type!=="heading")return null;let X=Math.max(1,Math.min(6,Z.block.depth+J));if(X===Z.block.depth)return{kind:"keep-state"};return{kind:"replace-root",block:Z0({depth:X,text:Z.block.plainText}),rootIndex:Z.rootIndex,selection:M1(Z.rootIndex,M.focus.offset)}}function sY($,M,J){if($.block.type!=="paragraph"||$.block.plainText.length!==0||M.type!=="list"||J?.type!=="list"||!iY(M,J))return null;let Z=M.items.length-1;return{kind:"replace-root-range",count:3,replacements:[$1(M,[...M.items,...J.items])],rootIndex:$.rootIndex-1,selection:X1($.rootIndex-1,[Z,0],"end")}}function iY($,M){return $.ordered===M.ordered&&$.start===M.start}function oY($){if($.block.type!=="heading")return null;return{kind:"replace-root",block:I({text:$.block.plainText}),rootIndex:$.rootIndex,selection:M1($.rootIndex)}}function nY($,M){let J=n($,M);if(J.start.regionId!==J.end.regionId||J.start.offset!==0||J.end.offset!==0)return null;let Z=Z2($,M);if(!Z||Z.block.type!=="paragraph"||Z.region.text.length!==0)return null;if(Z.quote.children.length===1)return{kind:"replace-root-range",count:1,replacements:[I({text:""})],rootIndex:Z.rootIndex,selection:M1(Z.rootIndex)};let X=Math.max(0,Z.childIndex-1),A=Z.childIndex>0?"end":0;return{kind:"replace-root",block:T1({children:Z.quote.children.filter((Y,Q)=>Q!==Z.childIndex)}),rootIndex:Z.rootIndex,selection:X1(Z.rootIndex,[X],A)}}function tY($,M,J,Z,X,A){return{blocks:X===0?[I({text:""}),$]:X===A?[$,I({text:""})]:[I({text:M}),I({text:J})],focusChildIndices:X===0?Z:[...Z.slice(0,-1),Z.at(-1)+1]}}function eY($,M,J,Z,X,A){return{blocks:X===0?[I({text:""}),$]:X===A?[$,I({text:""})]:[Z0({depth:$.depth,text:M}),I({text:J})],focusChildIndices:X===0?Z:[...Z.slice(0,-1),Z.at(-1)+1]}}function T9($,M,J){let Z=a1($,M),X=Math.max(2,J);if(!Z||Z.block.type!=="paragraph"||Z.block.plainText.length>0||M.anchor.regionId!==M.focus.regionId||M.anchor.offset!==0||M.focus.offset!==0)return null;return{kind:"replace-root",block:V0({rows:Array.from({length:2},()=>m8(X))}),rootIndex:Z.rootIndex,selection:G0(Z.rootIndex,0,0)}}function S8($,M,J){let Z=F0($,M.focus.regionId);if(!Z)return null;let X=J<0?ZQ(Z.table,Z.rowIndex,Z.cellIndex):XQ(Z.table,Z.rowIndex,Z.cellIndex);if(!X)return J>0&&AQ(Z.table,Z.rowIndex,Z.cellIndex)?$Q(Z):{kind:"keep-state"};let A=Z.table.rows[X.rowIndex]?.cells[X.cellIndex];if(!A)return{kind:"keep-state"};return{kind:"set-selection",selection:JQ($,M,Z.table,X.rowIndex,X.cellIndex,Math.min(M.focus.offset,A.plainText.length))}}function y9($,M){let J=N5($,M.focus.regionId);if(!J||J.kind!=="tableCell")return null;let Z=Math.min(M.anchor.offset,M.focus.offset),X=Math.max(M.anchor.offset,M.focus.offset),A=D8(J,Z,X);return{kind:"replace-block",block:A.block,blockId:A.blockId,selection:A.selection}}function V9($,M,J){let Z=F0($,M.focus.regionId);if(!Z)return null;let X=J==="left"?Z.cellIndex:Z.cellIndex+1;return A2(Z,V0({align:w9(Z.table.align,X,0,[null]),rows:Z.table.rows.map((A)=>v0({cells:MQ(A.cells,X,0,[E9()])}))}),G0(Z.rootIndex,Z.rowIndex,X))}function z9($,M){let J=F0($,M.focus.regionId);if(!J)return null;let Z=Math.max(0,...J.table.rows.map((X)=>X.cells.length));if(Z<=1)return null;return A2(J,V0({align:w9(J.table.align,J.cellIndex,1,[]),rows:J.table.rows.map((X)=>v0({cells:X.cells.filter((A,Y)=>Y!==J.cellIndex)}))}),G0(J.rootIndex,J.rowIndex,Math.min(J.cellIndex,Z-2)))}function O9($,M,J){let Z=F0($,M.focus.regionId);if(!Z)return null;let X=J==="above"?Z.rowIndex:Z.rowIndex+1,A=Math.max(1,...Z.table.rows.map((Y)=>Y.cells.length));return A2(Z,r1(Z.table,[...Z.table.rows.slice(0,X),m8(A),...Z.table.rows.slice(X)]),G0(Z.rootIndex,X,Math.min(Z.cellIndex,A-1)))}function b9($,M){let J=F0($,M.focus.regionId);if(!J||J.table.rows.length<=1)return null;let Z=J.table.rows.filter((Y,Q)=>Q!==J.rowIndex),X=Math.min(J.rowIndex,Z.length-1),A=Z[X]?.cells.length??1;return A2(J,r1(J.table,Z),G0(J.rootIndex,X,Math.min(J.cellIndex,A-1)))}function C9($,M){let J=F0($,M.focus.regionId);if(!J)return null;return A2(J,I({text:""}),M1(J.rootIndex))}function m8($){return v0({cells:Array.from({length:$},()=>E9())})}function E9(){return X0({children:[]})}function $Q($){let M=$.table.rows.length,J=Math.max(1,...$.table.rows.map((Z)=>Z.cells.length));return A2($,r1($.table,[...$.table.rows,m8(J)]),G0($.rootIndex,M,0))}function A2($,M,J){return{kind:"replace-block",block:M,blockId:$.table.id,selection:J}}function MQ($,M,J,Z){return[...$.slice(0,M),...Z,...$.slice(M+J)]}function w9($,M,J,Z){return[...$.slice(0,M),...Z,...$.slice(M+J)]}function JQ($,M,J,Z,X,A){let Y=M2($,J.id,Z,X);if(!Y)return M;return{anchor:{regionId:Y.id,offset:A},focus:{regionId:Y.id,offset:A}}}function ZQ($,M,J){if(J>0)return{cellIndex:J-1,rowIndex:M};if(M>0){let Z=$.rows[M-1];if(!Z||Z.cells.length===0)return null;return{cellIndex:Z.cells.length-1,rowIndex:M-1}}return null}function XQ($,M,J){let Z=$.rows[M];if(!Z)return null;if(J+1<Z.cells.length)return{cellIndex:J+1,rowIndex:M};let X=$.rows[M+1];if(!X||X.cells.length===0)return null;return{cellIndex:0,rowIndex:M+1}}function AQ($,M,J){let Z=$.rows[M];return Boolean(Z&&M===$.rows.length-1&&J===Z.cells.length-1)}function Y2($,M){let J=U9($.documentIndex,$.selection,M),Z=a($,J);if(!Z)return null;if(J?.kind==="replace-selection"&&M.length>0)Z=C5(Z,M.length);if(M===".")Z=E8(Z);return Z}function e2($){switch(o2($.documentIndex,$.selection).kind){case"code":return a($,P9($.documentIndex,$.selection));case"tableCell":return a($,y9($.documentIndex,$.selection));case"listItem":{let J=B9($.documentIndex,$.selection);return KQ({state:a($,J)??a($,f5($.documentIndex,$.selection)),action:J})}case"blockquoteTextBlock":return a($,H9($.documentIndex,$.selection))??a($,f5($.documentIndex,$.selection));case"rootTextBlock":return a($,f5($.documentIndex,$.selection));case"unsupported":return null}}function u5($){if(R9($))return $4($);let M=qQ($);if(M)return M;let J=n($.documentIndex,$.selection);if(J.start.regionId!==J.end.regionId||J.start.offset!==0||J.end.offset!==0)return null;switch(o2($.documentIndex,$.selection).kind){case"listItem":return a($,F9($.documentIndex,$.selection));case"blockquoteTextBlock":case"rootTextBlock":return a($,W9($.documentIndex,$.selection));default:return null}}function S5($){if(R9($))return $4($);return NQ($)}function v8($,M){return a($,{kind:"replace-selection",selection:$.selection,text:M})}function m5($,M){let J=v8($,M);return M.length>0?C5(J,M.length):J}function $4($){return v8($,"")}function g8($){let M=$.documentIndex.regions,J=M[0],Z=M.at(-1);if(!J||!Z)return $;return K1($,{anchor:{regionId:J.id,offset:0},focus:{regionId:Z.id,offset:Z.text.length}})}function h8($){switch(o2($.documentIndex,$.selection).kind){case"tableCell":return a($,S8($.documentIndex,$.selection,1));case"rootTextBlock":return a($,u8($.documentIndex,$.selection,1));case"listItem":return YQ($);default:return null}}function I8($){switch(o2($.documentIndex,$.selection).kind){case"tableCell":return a($,S8($.documentIndex,$.selection,-1));case"rootTextBlock":return a($,u8($.documentIndex,$.selection,-1));case"listItem":return QQ($);default:return null}}function YQ($){return a($,D9($.documentIndex,$.selection))}function QQ($){return a($,_9($.documentIndex,$.selection))}function p8($){return a($,f8($.documentIndex,$.selection,-1))}function l8($){return a($,f8($.documentIndex,$.selection,1))}function r8($,M){return a($,T9($.documentIndex,$.selection,M))}function c8($,M){return a($,V9($.documentIndex,$.selection,M))}function x8($){return a($,z9($.documentIndex,$.selection))}function d8($,M){return a($,O9($.documentIndex,$.selection,M))}function a8($){return a($,b9($.documentIndex,$.selection))}function s8($){return a($,C9($.documentIndex,$.selection))}function v5($,M){return j9($,(J,Z,X)=>G8(J,Z,X,M))}function i8($){return j9($,(M,J,Z)=>F8(M,J,Z))}function M4($){return v5($,"bold")}function J4($){return v5($,"italic")}function Z4($){return v5($,"strikethrough")}function X4($){return v5($,"underline")}function o8($,M,J,Z,X){return a($,F5($.documentIndex,M,J,Z,X))}function n8($,M,J,Z){return a($,F5($.documentIndex,M,J,Z,null))}function t8($,M){let J=i2($.documentIndex,M);if(!J||J.type!=="listItem"||typeof J.checked!=="boolean")return null;return a($,{kind:"replace-block",block:{...J,checked:!J.checked},blockId:M})}function g5($){return j8($)}function h5($){return R8($)}function e8($,M,J){let Z=X8($.documentIndex,M,J);if(!Z)return null;return R5($,$.documentIndex.document.comments.length,0,[Z])}function $$($,M,J){return A4($,M,(Z)=>T6(Z,{body:J.trim()}))}function M$($,M,J,Z){return A4($,M,(X)=>y6(X,J,Z))}function J$($,M,J){return A4($,M,(Z)=>V6(Z,J))}function Z$($,M){return A4($,M,()=>null)}function X$($,M,J){return A4($,M,(Z)=>z6(Z,J))}function A4($,M,J){let X=f1($.documentIndex).threads[M];if(!X)return null;let A=J(X);if(A===X)return null;return R5($,M,1,A?[A]:[])}function KQ($){if(!$.state||!$.action||$.action.kind!=="replace-block"||!$.action.listItemInsertedPath)return $.state;return w8($.state,$.action.listItemInsertedPath)}function j9($,M){let J=n($.documentIndex,$.selection);if(J.start.regionId!==J.end.regionId||J.start.offset===J.end.offset)return null;return a($,m2($.documentIndex,J.start.regionId,J.start.offset,J.end.offset,M))}function R9($){let M=n($.documentIndex,$.selection);return M.start.regionId!==M.end.regionId||M.start.offset!==M.end.offset}function qQ($){return L9($,"backward")}function NQ($){return L9($,"forward")}function L9($,M){if($.selection.anchor.regionId!==$.selection.focus.regionId||$.selection.anchor.offset!==$.selection.focus.offset)return null;let J=J0($.documentIndex,$.selection.focus.regionId);if(!J)return null;if(M==="forward"&&$.selection.focus.offset>=J.text.length)return null;let Z=M==="backward"?BQ(J.text,$.selection.focus.offset):$.selection.focus.offset,X=M==="backward"?$.selection.focus.offset:FQ(J.text,$.selection.focus.offset);if(Z===X)return null;let A=v8(K1($,{anchor:{regionId:J.id,offset:Z},focus:{regionId:J.id,offset:X}}),"");return UQ($,A,Z,X)}function UQ($,M,J,Z){let X=GQ($,J,Z);return X?b8(M,X):M}function GQ($,M,J){let Z=$.documentIndex.regionIndex.get($.selection.focus.regionId);if(!Z)return null;let X=Z.text.slice(M,J);if(X.length===0)return null;if(!Z.inlines.find((Y)=>Y.start<=M&&Y.end>=J&&Y.kind==="text"&&Y.link===null&&Y.marks.length===0))return null;return{regionPath:Z.path,startOffset:M,text:X}}function BQ($,M){let J=Array.from($.slice(0,M));if(J.length===0)return 0;return M-J.at(-1).length}function FQ($,M){let J=Array.from($.slice(M))[0];return J?M+J.length:$.length}var k9=1;function f9($,M,J){let Z=$.documentIndex.regionOrderIndex.get($.selection.focus.regionId);if(Z===void 0)return $;let X=$.documentIndex.regions[Z],A=$.selection.focus.offset+M;if(A>=0&&A<=X.text.length)return E1($,X.id,A,J);if(M<0){let Q=$.documentIndex.regions[Z-1];if(!Q)return $;return E1($,Q.id,Q.text.length,J)}let Y=$.documentIndex.regions[Z+1];if(!Y)return $;return E1($,Y.id,0,J)}function u9($,M,J,Z,X){let A=C2(M,J.regionId,J.offset);if(!A)return $;let Y=M.lines[A.index+Z];if(!Y)return $;let Q=C1(M,$,{x:d1($,M,J)+k9,y:Y.top+Y.height/2});if(!Q)return $;return E1($,Q.regionId,Q.offset,X)}function S9($,M,J,Z){let X=v9($,M);if(!X)return $;return E1($,X.regionId,J==="Home"?X.start:X.end,Z)}function m9($,M,J,Z,X){let A=v9($,M);if(!A)return $;let Q=Math.max(1,Math.floor(480/M.options.lineHeight)),K=C2(M,A.regionId,$.selection.focus.offset),q=K?M.lines[K.index+Z*Q]:null;if(!q)return $;let N=C1(M,$,{x:d1($,M,J)+k9,y:q.top+q.height/2});if(!N)return $;return E1($,N.regionId,N.offset,X)}function v9($,M){return $0(M,$.selection.focus.regionId,$.selection.focus.offset)}var DQ=1;function g9($,M,J,Z,X){let A=$.documentIndex.regionIndex.get($.selection.focus.regionId)??null;if(!A)return null;let Y=$.documentIndex.tableCellIndex.get(A.id)??null,Q=$.documentIndex.blockIndex.get(A.blockId)??null;if(!Y||Q?.type!=="table")return null;let K=_Q($,Q.id,Y.rowIndex+Z,Y.cellIndex)??HQ($,Q.id,Z);if(!K)return $;let q=M.regionBounds.get(A.id),N=M.regionBounds.get(K.id);if(!q||!N)return $;let U=N.top+PQ(J.top+J.height/2-q.top,0,Math.max(0,N.bottom-N.top-1)),G=C1(M,$,{x:d1($,M,J)+DQ,y:U});if(!G)return $;return E1($,G.regionId,G.offset,X)}function _Q($,M,J,Z){return M2($.documentIndex,M,J,Z)}function HQ($,M,J){let Z=$.documentIndex.blockIndex.get(M),X=$.documentIndex.regions,A=Z?$.documentIndex.roots[Z.rootIndex]?.regionRange:void 0;if(!A)return null;return J<0?X[A.start-1]??null:X[A.end]??null}function PQ($,M,J){return Math.max(M,Math.min(J,$))}function A$($,M,J=!1){return f9($,M,J)}function Y$($,M,J,Z=!1){return WQ($,M,J,Z)}function Q$($,M,J,Z=!1){return TQ($,M,J,Z)}function K$($,M,J,Z=!1){return S9($,M,J,Z)}function q$($,M,J=!1){return yQ($,M,J)}function WQ($,M,J,Z){let X=h9($,M);if(!X)return $;return g9($,M,X,J,Z)??u9($,M,X,J,Z)}function TQ($,M,J,Z){let X=h9($,M);if(!X)return $;return m9($,M,X,J,Z)}function yQ($,M,J){let Z=$.documentIndex.regions,X=M==="start"?Z[0]:Z.at(-1);if(!X)return $;return E1($,X.id,M==="start"?0:X.text.length,J)}function h9($,M){return c1(M,$.documentIndex,{regionId:$.selection.focus.regionId,offset:$.selection.focus.offset})}function p9($,M,J,Z,X,A,Y){let Q=J.image?Z.images.get(J.image.url):null,K=OQ(J,Z,Y),q=bQ(M,A,Y,K);if($.fillStyle=X.imageSurfaceBackground,$.fillRect(q.left,q.top,q.width,q.height),Q?.status==="loaded"&&Q.source)$.drawImage(Q.source,q.left,q.top,q.width,q.height);else VQ($,X,{...q,status:Q?.status==="error"?"error":"loading"});$.strokeStyle=X.imageSurfaceBorder,$.strokeRect(q.left,q.top,q.width,q.height)}function VQ($,M,J){let Z=J.status==="loading"?"Loading image":"Image unavailable",X=CQ(J),A=J.top+J.height/2+X.size*0.9;if($.save(),$.beginPath(),$.rect(J.left,J.top,J.width,J.height),$.clip(),J.status==="loading")zQ($,M,J);$.strokeStyle=M.imagePlaceholderIcon,$.lineWidth=1.5,$.strokeRect(X.left,X.top,X.size,X.size),$.beginPath(),$.arc(X.left+X.size*0.28,X.top+X.size*0.3,X.size*0.1,0,Math.PI*2),$.moveTo(X.left+X.size*0.12,X.top+X.size*0.82),$.lineTo(X.left+X.size*0.42,X.top+X.size*0.5),$.lineTo(X.left+X.size*0.58,X.top+X.size*0.66),$.lineTo(X.left+X.size*0.78,X.top+X.size*0.38),$.lineTo(X.left+X.size*0.88,X.top+X.size*0.82),$.stroke(),$.font='500 12px "Iowan Old Style", "Palatino Linotype", serif',$.fillStyle=M.imagePlaceholderText,$.textAlign="center",$.textBaseline="middle",$.fillText(Z,J.left+J.width/2,A),$.restore()}function zQ($,M,J){let Z=Math.max(48,Math.round(J.width*0.22)),X=J.width+Z*2,A=performance.now()%1800/1800,Y=J.left-Z+X*A,Q=$.createLinearGradient(Y,J.top,Y+Z,J.top);Q.addColorStop(0,"rgba(255,255,255,0)"),Q.addColorStop(0.5,M.imageLoadingOverlay),Q.addColorStop(1,"rgba(255,255,255,0)"),$.fillStyle=Q,$.fillRect(J.left,J.top,J.width,J.height)}function OQ($,M,J){if(!$.image)return I9(J);let Z=M.images.get($.image.url);if(!Z||Z.intrinsicWidth<=0||Z.intrinsicHeight<=0)return I9(J);return Math.max(48,Math.round(J*(Z.intrinsicHeight/Z.intrinsicWidth)))}function bQ($,M,J,Z){return{height:Z,left:M,top:$.top+Math.max(0,Math.floor(($.height-Z)/2)),width:J}}function CQ($){let M=Math.max(18,Math.min(34,Math.round(Math.min($.width,$.height)*0.18)));return{left:$.left+Math.max(12,Math.round(($.width-M)/2)),size:M,top:$.top+Math.max(12,Math.round($.height/2-M*0.95))}}function I9($){return Math.max(48,Math.round($*0.5625))}var l9=2,r9=8,EQ=3,wQ=1.5,jQ=2,Q2={elbow:{x:6.5,y:10.5},end:{x:11.5,y:3.5},start:{x:3.5,y:7.5}};function c9($,M,J,Z,X,A,Y=null){if(!J||M.start!==0)return;if(Y){let Q=Z9(Y),K=uQ(J,M,Z,X,$);$.save(),$.translate(K.x,K.y),$.scale(Q,Q),$.translate(-K.x,-K.y)}if(J.kind==="task")RQ($,M,J.checked,A,Y);else if($.fillStyle=Y?r2(A.listMarkerText,Y,A):A.listMarkerText,J.kind==="ordered")fQ($,J.label,Z,X);else $.fillText(J.label,M.left-l9,X);if(Y)$.restore()}function RQ($,M,J,Z,X=null){let A=w2(M);if(LQ($,A,J,Z,X),!J)return;kQ($,A,Z,X)}function LQ($,M,J,Z,X=null){let A=J?Z.checkboxCheckedFill:Z.checkboxUncheckedFill,Y=J?Z.checkboxCheckedStroke:Z.checkboxUncheckedStroke;$.fillStyle=X?r2(A,X,Z):A,$.strokeStyle=X?r2(Y,X,Z):Y,$.beginPath(),$.lineWidth=wQ,$.roundRect(M.left,M.top,M.size,M.size,EQ),$.fill(),$.stroke()}function kQ($,M,J,Z=null){$.strokeStyle=Z?r2(J.checkboxCheckmark,Z,J):J.checkboxCheckmark,$.lineWidth=jQ,$.beginPath(),$.moveTo(M.left+Q2.start.x,M.top+Q2.start.y),$.lineTo(M.left+Q2.elbow.x,M.top+Q2.elbow.y),$.lineTo(M.left+Q2.end.x,M.top+Q2.end.y),$.stroke()}function fQ($,M,J,Z){let X=$.textAlign;$.textAlign="right",$.fillText(M,J-r9,Z),$.textAlign=X}function uQ($,M,J,Z,X){if($.kind==="task"){let Q=w2(M);return{x:Q.left+Q.size/2,y:Q.top+Q.size/2}}let A=X.measureText($.label),Y=Z-(A.actualBoundingBoxAscent-A.actualBoundingBoxDescent)/2;if($.kind==="ordered")return{x:J-r9-A.width/2,y:Y};return{x:M.left-l9+A.width/2,y:Y}}var SQ=80;function d9({context:$,containerBounds:M,isHeaderRow:J,lineHeight:Z,theme:X}){let A=s9(M,Z);$.fillStyle=J?X.tableHeaderBackground:X.tableBodyBackground,$.fillRect(A.left,A.top,A.width,A.height),i9($,A,X)}function a9({activeBlockFlashes:$,activeBlockId:M,activeRegionId:J,context:Z,editorState:X,endIndex:A,layout:Y,regionBounds:Q,startIndex:K,theme:q,verticalBleed:N}){if(!M||!J)return;let U=X.documentIndex.blockIndex.get(M)??null;if(U?.type!=="table")return;if((X.documentIndex.regionIndex.get(J)??null)?.blockId!==M)return;let B=Q.get(J)??null,D=Y.regionLineIndices.get(J)??null;if(!B||!D||D.length===0)return;let F=Y.lines[D[0]]??null;if(!F)return;let H=s9(B,F.height);if(H.width===0)return;let b=x9({context:Z,endIndex:A,fillStyle:q.activeBlockBackground,layout:Y,left:H.left,lineIndices:D,startIndex:K,verticalBleed:N,width:H.width}),E=U.path?$.get(U.path)??null:null;if(E)x9({context:Z,endIndex:A,fillStyle:b5(q.activeBlockFlash,E),layout:Y,left:H.left,lineIndices:D,startIndex:K,verticalBleed:N,width:H.width});if(!b)return;i9(Z,H,q)}function x9({context:$,endIndex:M,fillStyle:J,layout:Z,left:X,lineIndices:A,startIndex:Y,verticalBleed:Q,width:K}){$.fillStyle=J;let q=!1;for(let N of A){if(N<Y)continue;if(N>=M)break;let U=Z.lines[N];$.fillRect(X,U.top-Q,K,U.height),q=!0}return q}function s9($,M){return{height:Math.max($.bottom-$.top,M),left:$.left,top:$.top,width:Math.max($.right-$.left,SQ)}}function i9($,M,J){$.strokeStyle=J.tableBorder,$.strokeRect(M.left,M.top,M.width,M.height)}var N$=2,mQ=3,vQ=12,gQ=6,hQ=3,IQ=1,pQ=2,lQ=2,rQ=8,cQ=12,xQ=28,dQ=4,aQ=5,sQ=2,iQ=3,oQ=6,o9=3,nQ=12,tQ=10,eQ=2,$K=2,MK=1,JK=2,U$=2,n9=1.25,ZK=5,XK=1,t9=4,AK=4,YK=1.5;function QK({activeBlockId:$,activeRegionId:M,activeThreadIndex:J,containerLineBounds:Z,context:X,devicePixelRatio:A,editorState:Y,height:Q,layout:K,liveCommentRanges:q,normalizedSelection:N,now:U=kK(),resources:G,runtimeBlockMap:B,theme:D,viewportTop:F,width:H}){X.save(),X.scale(A,A),X.clearRect(0,0,H,Q),X.fillStyle=D.background,X.fillRect(0,0,H,Q),X.textBaseline="alphabetic",X.translate(0,-F);let b=KK(Y,N),{endIndex:E,startIndex:V}=l6(K,F,Q),R=s3(Y,U),O=i3(Y,U),j=a3(Y,U),f=n3(Y,U),z=o3(Y,U),y=NK(K,Y,$,V,E),T=qK(K,Y,B,V,E,H);for(let W=V;W<E;W+=1){let _=K.lines[W];FK({containerLineBounds:Z,context:X,editorState:Y,line:_,runtimeBlockMap:B,theme:D,width:H})}a9({activeBlockFlashes:R,activeBlockId:$,activeRegionId:M,context:X,editorState:Y,endIndex:E,layout:K,regionBounds:Z,startIndex:V,theme:D,verticalBleed:N$});for(let W=V;W<E;W+=1){let _=K.lines[W];DK({activeBlockId:$,activeBlockFlashes:R,activeDeletedTextFades:O,activeThreadIndex:J,activeInsertedTextHighlights:j,activeListMarkerPops:f,activePunctuationPulses:z,context:X,editorState:Y,line:_,liveCommentRanges:q,normalizedSelection:N,resources:G,runtimeBlockMap:B,selectionRegionOrderRange:b,theme:D,width:H})}UK(X,T,D),GK(X,y,D),X.restore()}function KK($,M){let J=$.documentIndex.regionOrderIndex,Z=J.get(M.start.regionId),X=J.get(M.end.regionId);return Z===void 0||X===void 0?null:{end:X,start:Z}}function qK($,M,J,Z,X,A){let Y=new Map;for(let Q=Z;Q<X;Q+=1){let K=$.lines[Q],q=J.get(K.blockId);if(q?.type!=="heading"||q.depth!==1&&q.depth!==2)continue;let N=Y.get(q.id),U={bottom:K.top+K.height,left:K.left+N0(M,K),right:A-$.options.paddingX};Y.set(q.id,N?{bottom:Math.max(N.bottom,U.bottom),left:N.left,right:N.right}:U)}return Y}function NK($,M,J,Z,X){let A=new Map;for(let Y=Z;Y<X;Y+=1){let Q=$.lines[Y],K=n0(M,Q.blockId,"blockquote");if(!K)continue;let q=A.get(K.id),N={bottom:Q.top+Q.height,isActive:Q.blockId===J,left:$.options.paddingX+(K.depth+1)*$.options.indentWidth-10,top:Q.top};A.set(K.id,q?{bottom:Math.max(q.bottom,N.bottom),isActive:q.isActive||N.isActive,left:q.left,top:Math.min(q.top,N.top)}:N)}return A}function UK($,M,J){$.fillStyle=J.headingRule;for(let Z of M.values())$.fillRect(Z.left,Z.bottom+ZK,Math.max(U$,Z.right-Z.left),XK)}function GK($,M,J){for(let Z of M.values())$.fillStyle=Z.isActive?J.blockquoteRuleActive:J.blockquoteRule,$.fillRect(Z.left,Z.top+mQ,hQ,Math.max(vQ,Z.bottom-Z.top-gQ))}function BK({context:$,devicePixelRatio:M,editorState:J,height:Z,layout:X,normalizedSelection:A,presence:Y,showCaret:Q,theme:K,viewportTop:q,width:N}){$.save(),$.scale(M,M),$.clearRect(0,0,N,Z);let U=A.start.regionId===A.end.regionId&&A.start.offset!==A.end.offset,G=Q&&!U;if($.translate(0,-q),G)e9($,J,X,{color:K.caret,offset:J.selection.focus.offset,regionId:J.selection.focus.regionId});if(Y)for(let B of Y){if(!B.cursorPoint)continue;e9($,J,X,{color:B.color??K.leafAccent,offset:B.cursorPoint.offset,regionId:B.cursorPoint.regionId})}$.restore()}function e9($,M,J,Z){let X=c1(J,M.documentIndex,{regionId:Z.regionId,offset:Z.offset});if(!X)return;let A=d1(M,J,X),Y=zK(J,X);$.fillStyle=Z.color,$.fillRect(A,Y.top,pQ,Y.height)}function FK({containerLineBounds:$,context:M,editorState:J,line:Z,runtimeBlockMap:X,theme:A,width:Y}){let Q=X.get(Z.blockId)??null,K=$.get(Z.regionId)??null,q=J.documentIndex.tableCellIndex.get(Z.regionId)??null;_K(M,Z,Q,K,q,A,Y)}function DK({activeBlockId:$,activeBlockFlashes:M,activeDeletedTextFades:J,activeThreadIndex:Z,activeInsertedTextHighlights:X,activeListMarkerPops:A,activePunctuationPulses:Y,context:Q,editorState:K,line:q,liveCommentRanges:N,normalizedSelection:U,resources:G,runtimeBlockMap:B,selectionRegionOrderRange:D,theme:F,width:H}){let b=B.get(q.blockId)??null,E=K.documentIndex.blockIndex.get(q.blockId)?.path??null,V=K.documentIndex.regionIndex.get(q.regionId)??null,R=V?.path??"",O=n0(K,q.blockId,"listItem"),j=O?j2(K,O.id):null,f=O?A.get(O.path)??null:null,z=q.left+N0(K,q),y=CK(q),T=b?.type==="code"?F.codeText:jK(b,F);Q.font=q.font,HK(Q,q,b,E,$,M,F,H),PK(Q,K,q,U,D,F),WK(Q,K,q,N,Z,F),c9(Q,q,j,z,y,F,f),TK(Q,q,V,z,y,X.get(R)??[],T,G,F),yK(Q,q,V,z,y,J.get(R)??[],T),VK(Q,q,V,z,y,Y.get(R)??[],F)}function _K($,M,J,Z,X,A,Y){if(!Z||M.start!==0)return;if(J?.type==="code"){let Q=Math.max(0,M.left-cQ);$.fillStyle=A.codeBackground,$.fillRect(Q,Z.top-dQ,Math.max(Z.right-M.left+xQ,Y-Q),Z.bottom-Z.top+rQ);return}if(J?.type!=="table")return;d9({context:$,containerBounds:Z,isHeaderRow:X?.rowIndex===0,lineHeight:M.height,theme:A})}function HK($,M,J,Z,X,A,Y,Q){if(M.blockId!==X||J?.type==="table")return;let K=Z?A.get(Z)??null:null;if($.fillStyle=Y.activeBlockBackground,$.fillRect(0,M.top-N$,Q,M.height),!K)return;$.fillStyle=b5(Y.activeBlockFlash,K),$.fillRect(0,M.top-N$,Q,M.height)}function PK($,M,J,Z,X,A){if(!X)return;let Y=M.documentIndex.regionOrderIndex.get(J.regionId);if(Y===void 0||Y<X.start||Y>X.end)return;let Q=Y===X.start?Math.max(J.start,Z.start.offset):J.start,K=Y===X.end?Math.min(J.end,Z.end.offset):J.end;if(K<=Q)return;$.fillStyle=A.selectionBackground,$.fillRect(q0(M,J,Q-J.start),J.top+MK,Math.max($K,q0(M,J,K-J.start)-q0(M,J,Q-J.start)),J.height-JK)}function WK($,M,J,Z,X,A){for(let Y of Z){if(Y.regionId!==J.regionId)continue;let Q=Math.max(Y.startOffset,J.start),K=Math.min(Y.endOffset,J.end);if(K<=Q)continue;$.fillStyle=LK(Y,X,A),$.fillRect(q0(M,J,Q-J.start),J.top+J.height-aQ,Math.max(sQ,q0(M,J,K-J.start)-q0(M,J,Q-J.start)),iQ)}}function TK($,M,J,Z,X,A,Y,Q,K){if(!J){$.fillStyle=Y,$.fillText(M.text,Z,X);return}let q=J.inlines.filter((N)=>N.end>M.start&&N.start<M.end);if(q.length===0){$.fillStyle=Y,$.fillText(M.text,Z,X);return}for(let N of q){let U=Math.max(M.start,N.start),G=Math.min(M.end,N.end);if(J.text.slice(U,G).length===0)continue;let{left:D,right:F}=B$(M,Z,U,G),H=RK(M.font,N.marks);if($.font=H,N.kind==="image"){let b=Math.max(24,F-D);p9($,M,N,Q,K,D,b);continue}if(N.kind==="inlineCode"){let b=EK(M,H),E=wK(M,H);$.fillStyle=K.inlineCodeBackground,$.fillRect(D-o9,b,Math.max(tQ,F-D+o9*2),E),$7($,M,J.text,Z,X,U,G,K.inlineCodeText,A,K,{strikethrough:!1,underline:!1});continue}$7($,M,J.text,Z,X,U,G,N.link?K.linkText:Y,A,K,{strikethrough:N.marks.includes("strikethrough"),underline:N.marks.includes("underline")||Boolean(N.link)})}}function $7($,M,J,Z,X,A,Y,Q,K,q,N){let U=t3(A,Y,K);for(let G=0;G<U.length-1;G+=1){let B=U[G],D=U[G+1];if(D<=B)continue;let F=J.slice(B,D);if(F.length===0)continue;let{left:H,right:b}=B$(M,Z,B,D),E=e3(K,B,D),V=$9(Q,E,q);if($.fillStyle=V,$.fillText(F,H,X),N.strikethrough)$.fillRect(H,bK(X,M.height,$.font),Math.max(U$,b-H),n9);if(N.underline)$.fillRect(H,OK(X,M.height,$.font),Math.max(U$,b-H),n9)}}function yK($,M,J,Z,X,A,Y){if(!J||A.length===0)return;for(let Q of A){if(Q.startOffset<M.start||Q.startOffset>M.end)continue;let K=Z+(x1(M,Q.startOffset-M.start)-M.left);$.fillStyle=M9(Y,Q),$.fillText(Q.text,K,X)}}function VK($,M,J,Z,X,A,Y){if(!J||A.length===0)return;for(let Q of A){if(Q.offset<M.start||Q.offset>=M.end)continue;let{left:K,right:q}=B$(M,Z,Q.offset,Q.offset+1),N=Math.max(t9,(q-K)/2+t9+AK*Q.progress),{ascent:U,descent:G}=K0(M.font),B=X-Math.max(1,U*0.42)+Math.max(0.5,G*0.15);$.strokeStyle=J9(Q,Y),$.lineWidth=YK,$.beginPath(),$.arc((K+q)/2,B,N,0,Math.PI*2),$.stroke()}}function zK($,M){let J=$0($,M.regionId,M.offset),Z=J?.font??'16px "Iowan Old Style", "Palatino Linotype", serif',{ascent:X,descent:A}=K0(Z),Y=Math.max(1,X+A),Q=Math.min(M.height-lQ,Y),K=J?Math.max(J.top,J.top+G$(J.height,Z)-IQ):M.top+Math.max(0,Math.floor((M.height-Q)/2));return{height:Q,top:K}}function OK($,M,J){let{descent:Z}=K0(J),X=Math.max(1,Math.round(Math.max(2,Z)*0.35)),A=$+Z-X,Y=$-I5(M,J);return Math.min(Y+M-4,A)}function bK($,M,J){let{ascent:Z}=K0(J),X=$-I5(M,J);return Math.max(X+2,$-Math.round(Z*0.32))}function CK($){return $.top+I5($.height,$.font)}function I5($,M){return B3($,M)}function EK($,M){let J=G$($.height,M);return $.top+J+eQ}function wK($,M){let J=G$($.height,M);return Math.max(nQ,$.height-J-oQ)}function G$($,M){let{ascent:J}=K0(M);return I5($,M)-J}function jK($,M){switch($?.type){case"heading":return M.headingText;case"blockquote":return M.blockquoteText;case"table":return M.headingText;default:return M.paragraphText}}function B$($,M,J,Z){return{left:M+(x1($,J-$.start)-$.left),right:M+(x1($,Z-$.start)-$.left)}}function RK($,M){let J=[];if(M.includes("italic"))J.push("italic");if(M.includes("bold"))J.push("700");return J.length>0?`${J.join(" ")} ${$}`:$}function LK($,M,J){if($.resolved)return $.threadIndex===M?J.commentHighlightResolvedActive:J.commentHighlightResolved;return $.threadIndex===M?J.commentHighlightActive:J.commentHighlight}function kK(){return typeof performance<"u"?performance.now():Date.now()}function F$($,M,J,Z){QK({activeBlockId:Z.activeBlockId,activeRegionId:Z.activeRegionId,activeThreadIndex:Z.activeThreadIndex,containerLineBounds:M.regionBounds,context:J,devicePixelRatio:Z.devicePixelRatio,editorState:$,height:Z.height,layout:M.layout,liveCommentRanges:Z.liveCommentRanges,normalizedSelection:Z.normalizedSelection,now:Z.now,resources:Z.resources??{images:new Map},runtimeBlockMap:M.blockMap,theme:Z.theme,viewportTop:M.paintTop,width:Z.width})}function D$($,M,J,Z){BK({context:J,devicePixelRatio:Z.devicePixelRatio,editorState:$,height:Z.height,layout:M.layout,normalizedSelection:Z.normalizedSelection,presence:Z.presence,showCaret:Z.showCaret,theme:Z.theme,viewportTop:M.paintTop,width:Z.width})}import{forwardRef as vK,createElement as gK}from"react";var p5=(...$)=>$.filter((M,J,Z)=>{return Boolean(M)&&M.trim()!==""&&Z.indexOf(M)===J}).join(" ").trim();var M7=($)=>$.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var J7=($)=>$.replace(/^([A-Z])|[\s-_]+(\w)/g,(M,J,Z)=>Z?Z.toUpperCase():J.toLowerCase());var _$=($)=>{let M=J7($);return M.charAt(0).toUpperCase()+M.slice(1)};import{forwardRef as mK,createElement as A7}from"react";var l5={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var Z7=($)=>{for(let M in $)if(M.startsWith("aria-")||M==="role"||M==="title")return!0;return!1};import{createContext as fK,useContext as uK,useMemo as YH,createElement as QH}from"react";var SK=fK({});var X7=()=>uK(SK);var Y7=mK(({color:$,size:M,strokeWidth:J,absoluteStrokeWidth:Z,className:X="",children:A,iconNode:Y,...Q},K)=>{let{size:q=24,strokeWidth:N=2,absoluteStrokeWidth:U=!1,color:G="currentColor",className:B=""}=X7()??{},D=Z??U?Number(J??N)*24/Number(M??q):J??N;return A7("svg",{ref:K,...l5,width:M??q??l5.width,height:M??q??l5.height,stroke:$??G,strokeWidth:D,className:p5("lucide",B,X),...!A&&!Z7(Q)&&{"aria-hidden":"true"},...Q},[...Y.map(([F,H])=>A7(F,H)),...Array.isArray(A)?A:[A]])});var L=($,M)=>{let J=vK(({className:Z,...X},A)=>gK(Y7,{ref:A,iconNode:M,className:p5(`lucide-${M7(_$($))}`,`lucide-${$}`,Z),...X}));return J.displayName=_$($),J};var hK=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],D0=L("columns-2",hK);var IK=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]],_0=L("rows-3",IK);var pK=[["path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z",key:"117uat"}],["path",{d:"M6 12h16",key:"s4cdu5"}]],H0=L("send-horizontal",pK);var lK=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],Y4=L("arrow-down",lK);var rK=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Q4=L("arrow-up",rK);var cK=[["path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8",key:"mg9rjx"}]],K4=L("bold",cK);var xK=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],C0=L("check",xK);var dK=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],q4=L("chevron-down",dK);var aK=[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"m17 12 3-2v8",key:"1hhhft"}]],N4=L("heading-1",aK);var sK=[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1",key:"9jr5yi"}]],U4=L("heading-2",sK);var iK=[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2",key:"68ncm8"}],["path",{d:"M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2",key:"1ejuhz"}]],G4=L("heading-3",iK);var oK=[["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M17 10v3a1 1 0 0 0 1 1h3",key:"tj5zdr"}],["path",{d:"M21 10v8",key:"1kdml4"}],["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}]],B4=L("heading-4",oK);var nK=[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M17 13v-3h4",key:"1nvgqp"}],["path",{d:"M17 17.7c.4.2.8.3 1.3.3 1.5 0 2.7-1.1 2.7-2.5S19.8 13 18.3 13H17",key:"2nebdn"}]],F4=L("heading-5",nK);var tK=[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["circle",{cx:"19",cy:"16",r:"2",key:"15mx69"}],["path",{d:"M20 10c-2 2-3 3.5-3 6",key:"f35dl0"}]],D4=L("heading-6",tK);var eK=[["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M6 20V4",key:"1w1bmo"}],["path",{d:"M18 20V4",key:"o2hl4u"}]],_4=L("heading",eK);var $q=[["line",{x1:"19",x2:"10",y1:"4",y2:"4",key:"15jd3p"}],["line",{x1:"14",x2:"5",y1:"20",y2:"20",key:"bu0au3"}],["line",{x1:"15",x2:"9",y1:"4",y2:"20",key:"uljnxc"}]],H4=L("italic",$q);var Mq=[["path",{d:"M11 5h10",key:"1cz7ny"}],["path",{d:"M11 12h10",key:"1438ji"}],["path",{d:"M11 19h10",key:"11t30w"}],["path",{d:"M4 4h1v5",key:"10yrso"}],["path",{d:"M4 9h2",key:"r1h2o0"}],["path",{d:"M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02",key:"xtkcd5"}]],P4=L("list-ordered",Mq);var Jq=[["path",{d:"M13 5h8",key:"a7qcls"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["rect",{x:"3",y:"4",width:"6",height:"6",rx:"1",key:"cif1o7"}]],W4=L("list-todo",Jq);var Zq=[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]],T4=L("list",Zq);var Xq=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M12 8v6",key:"1ib9pf"}],["path",{d:"M9 11h6",key:"1fldmi"}]],y4=L("message-square-plus",Xq);var Aq=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],E0=L("pencil",Aq);var Yq=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],K2=L("plus",Yq);var Qq=[["path",{d:"M16 4H9a3 3 0 0 0-2.83 4",key:"43sutm"}],["path",{d:"M14 12a4 4 0 0 1 0 8H6",key:"nlfj13"}],["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}]],V4=L("strikethrough",Qq);var Kq=[["path",{d:"M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18",key:"gugj83"}]],P0=L("table-2",Kq);var qq=[["path",{d:"M17 5H3",key:"1cn7zz"}],["path",{d:"M21 12H8",key:"scolzb"}],["path",{d:"M21 19H8",key:"13qgcb"}],["path",{d:"M3 12v7",key:"1ri8j3"}]],z4=L("text-quote",qq);var Nq=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],w1=L("trash-2",Nq);var Uq=[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4",key:"9kb039"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20",key:"nun2al"}]],O4=L("underline",Uq);var Gq=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],b4=L("x",Gq);import{jsxDEV as w0}from"react/jsx-dev-runtime";function Q7({insetX:$,insetY:M,onSelect:J,presence:Z}){if(Z.length===0)return null;return w0("div",{"aria-label":"Presence",className:"documint-presence-indicators",style:{paddingRight:`${$}px`,top:`${M}px`},children:Z.map((X,A)=>w0(Bq,{onSelect:()=>J(X),presence:X},_q(X,A),!1,void 0,this))},void 0,!1,void 0,this)}function Bq({onSelect:$,presence:M}){let J=M.viewport,Z=Fq(M),X=J?.status==="above"?Q4:Y4,A=J!==null&&J.scrollTop!==null,Y=J?.status==="above"||J?.status==="below";return w0("button",{"aria-label":Dq(M),className:"documint-presence-indicator","data-status":J?.status??"unresolved",disabled:!A,onClick:A?$:void 0,style:{"--documint-presence-color":M.color??"var(--documint-leaf-accent)"},type:"button",children:[w0("span",{className:"documint-presence-indicator-avatar",children:M.imageUrl?w0("img",{alt:"","aria-hidden":"true",className:"documint-presence-indicator-image",draggable:!1,src:M.imageUrl},void 0,!1,void 0,this):Z},void 0,!1,void 0,this),Y?w0("span",{className:"documint-presence-indicator-direction","aria-hidden":"true",children:w0(X,{className:"documint-presence-indicator-arrow",size:14,strokeWidth:2.3},void 0,!1,void 0,this)},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)}function Fq($){return K7($).charAt(0).toLocaleUpperCase()}function Dq($){let M=K7($),J=$.viewport?.status??"unresolved";if(J==="above")return`${M} above viewport`;if(J==="below")return`${M} below viewport`;if(J==="unresolved")return`${M} unresolved`;return`${M} in viewport`}function K7($){return $.name.trim()||"Presence"}function _q($,M){return[M,$.name,$.imageUrl??"",$.color??"",$.cursor?.kind??"",$.cursor?.prefix??"",$.cursor?.suffix??""].join(":")}var s=`
26
- `,W0="<ins>",C4="</ins>",q2=">",E4="```",r5=":::",H$=/^:::([A-Za-z][-\w]*)(.*)$/,c5="documint-comments";var x5="`",y$="\\",W$="![",T$="[",G7="(",q7=")",B7=" ",F7=":",Hq=/[A-Za-z]/,Pq=/[-A-Za-z0-9_]/,Wq=/^\{width=([1-9]\d*)\}/,Tq=/\\([\\`*_[\]{}()#+\-.!~|])/g,D7=/\\(.)/g,yq=[{delimiter:"**",mark:"bold"},{delimiter:"~~",mark:"strikethrough"},{delimiter:"*",mark:"italic"}];function N2($,M=[]){return V$($,0,$.length,M)}function V$($,M,J,Z){let X=[],A=M,Y=M;while(A<J){let Q=Vq($,A,J,Z);if(Q){N7(X,$.slice(Y,A),Z),X.push(...Q.nodes),A=Q.end,Y=A;continue}if($[A]===y$){A+=Math.min(2,J-A);continue}A+=1}return N7(X,$.slice(Y,J),Z),zq(X)}function Vq($,M,J,Z){switch($[M]){case F7:return uq($,M,J);case"<":return kq($,M,J,Z);case x5:return wq($,M,J);case"!":return jq($,M,J);case T$:return Rq($,M,J,Z);case"*":case"~":return bq($,M,J,Z);default:return null}}function N7($,M,J){if(M.length===0)return;$.push(W1({marks:J,text:T7(M)}))}function z$($,M){return p4({originalType:$,source:M})}function zq($){let M=[];for(let J of $){let Z=M.at(-1);if(Z?.type==="text"&&J.type==="text"&&Cq(Z.marks,J.marks)){M[M.length-1]=W1({marks:Z.marks,text:Z.text+J.text});continue}M.push(J)}return M}function Oq($,M,J){for(let Z of yq){if(!$.startsWith(Z.delimiter,M))continue;let X=$.indexOf(Z.delimiter,M+Z.delimiter.length);if(X<0||X>=J)continue;return{contentEnd:X,contentStart:M+Z.delimiter.length,end:X+Z.delimiter.length,mark:Z.mark}}return null}function bq($,M,J,Z){let X=Oq($,M,J);if(!X)return null;return{end:X.end,nodes:V$($,X.contentStart,X.contentEnd,[...Z,X.mark])}}function Cq($,M){return $.length===M.length&&$.every((J,Z)=>J===M[Z])}function Eq($,M,J){if($[M]!==x5)return null;let Z=1;while(M+Z<J&&$[M+Z]===x5)Z+=1;let X=x5.repeat(Z),A=$.indexOf(X,M+Z);if(A<0||A>=J)return null;return{end:A+Z,value:$.slice(M+Z,A)}}function wq($,M,J){let Z=Eq($,M,J);if(!Z)return null;return{end:Z.end,nodes:[S0({code:Z.value})]}}function jq($,M,J){if(!$.startsWith(W$,M))return null;let Z=H7($,M+1,J);if(Z<0||$[Z+1]!==G7)return null;let X=_7($,Z+1,J);if(!X)return null;let A=Lq($,X.end,J);return{end:A?.end??X.end,nodes:[I4({alt:T7($.slice(M+W$.length,Z)),title:X.title,url:X.url,width:A?.width??null})]}}function Rq($,M,J,Z){if($[M]!==T$||$.startsWith(W$,M-1))return null;let X=H7($,M,J);if(X<0||$[X+1]!==G7)return null;let A=_7($,X+1,J);if(!A)return null;return{end:A.end,nodes:[m0({children:N2($.slice(M+T$.length,X),Z),title:A.title,url:A.url})]}}function _7($,M,J){let Z=P$($,M+1,J),X=Z;while(X<J&&$[X]!==q7&&$[X]!==B7){if($[X]===y$){X+=2;continue}X+=1}if(X===Z)return null;let A=Sq($.slice(Z,X));Z=P$($,X,J);let Y=null;if(Z<J&&$[Z]==='"'){let Q=W7($,'"',Z+1,J);if(Q<0)return null;Y=$.slice(Z+1,Q).replace(D7,"$1"),Z=P$($,Q+1,J)}if($[Z]!==q7)return null;return{end:Z+1,title:Y,url:A}}function Lq($,M,J){let Z=Wq.exec($.slice(M,J));if(!Z)return null;return{end:M+Z[0].length,width:Number(Z[1])}}function kq($,M,J,Z){if(!$.startsWith(W0,M))return fq($,M,J);let X=$.indexOf(C4,M+W0.length);if(X<0||X>=J)return{end:M+W0.length,nodes:[z$("html",W0)]};return{end:X+C4.length,nodes:V$($,M+W0.length,X,[...Z,"underline"])}}function fq($,M,J){if($[M]!=="<")return null;let Z=$.indexOf(">",M+1);if(Z<0||Z>=J)return null;return{end:Z+1,nodes:[z$("html",$.slice(M,Z+1))]}}function uq($,M,J){if($[M]!==F7||!Hq.test($[M+1]??""))return null;let Z=M+2;while(Z<J&&Pq.test($[Z]??""))Z+=1;let X=U7($,Z,J,"[","]"),Y=U7($,X?.end??Z,J,"{","}")?.end??X?.end??Z;return{end:Y,nodes:[z$("textDirective",$.slice(M,Y))]}}function U7($,M,J,Z,X){if($[M]!==Z)return null;let A=P7($,X,M+1,J);if(A<0)return null;return{end:A+1}}function H7($,M,J){return P7($,"]",M+1,J)}function P7($,M,J,Z){return W7($,M,J,Z)}function W7($,M,J,Z){for(let X=J;X<Z;X+=1){if($[X]===y$){X+=1;continue}if($[X]===M)return X}return-1}function P$($,M,J){while(M<J&&$[M]===B7)M+=1;return M}function T7($){return $.replace(Tq,"$1")}function Sq($){return $.replace(D7,"$1")}var mq=/^:?-+:?$/;function z7($,M){let J=V7($),Z=$.lines[$.index+1]??"",X=O$(J,M),A=O$(Z,M);if(!y7(X)||!b$(A))return null;let Y=[d5(X)],Q=vq(A);$.index+=2;while($.index<$.lines.length){let K=V7($),q=O$(K,M);if(gq(K)||!y7(q))break;Y.push(d5(q)),$.index+=1}return V0({align:Q,rows:Y.map((K)=>v0({cells:K.map((q)=>X0({children:N2(q)}))}))})}function y7($){let M=$.trim();return/\|/.test($)&&M.startsWith("|")&&M.endsWith("|")}function b$($){let M=d5($);return M.length>0&&M.every((J)=>mq.test(J.trim()))}function vq($){return d5($).map((M)=>{let J=M.trim();if(J.startsWith(":")&&J.endsWith(":"))return"center";if(J.startsWith(":"))return"left";if(J.endsWith(":"))return"right";return null})}function d5($){return $.trim().slice(1,-1).split("|").map((J)=>J.trim())}function V7($){return $.lines[$.index]??""}function gq($){return $.trim()===""}function O$($,M){return $.slice(M)}var hq=3,Iq=/^\d+\.$/,pq=/^\[( |x|X)\](?:\s|$)/,O7=/^```([^\s`]*)?(?:\s+(.*))?$/,b7=/^::(?!:)[A-Za-z][-\w]*/,C7=/^(#{1,6})\s+(.*)$/,lq=/\s+#+\s*$/u,rq=/^(\s*)([-+*]|\d+\.)(?:\s+(.*)|\s*)$/,cq=/^(\*\s*){3,}$/,xq=/^(-\s*){3,}$/,dq=/^(_\s*){3,}$/;function s5($,M,J){let Z=[];while($.index<$.lines.length){let X=H1($);if($.index===$.lines.length-1&&X==="")break;if(w4(X)){$.index+=1;continue}if(U2(X)>M+hq)break;let Y=aq($,M,J);if(!Y)break;Z.push(Y)}return Z}function aq($,M,J){return sq($,M,J)??iq($,M)??oq($,M)??tq($,M)??eq($,M)??$N($,M)??z7($,M)??MN($,M,J)??JN($,M)??ZN($,M)}function sq($,M,J){let Z=H1($);if(!AN(Z,M))return null;let X=[];while($.index<$.lines.length){let A=H1($),Y=U2(A);if(w4(A)){X.push(""),$.index+=1;continue}if(Y<M)break;let Q=u1(A,M);if(!Q.startsWith(q2))break;let K=Q.slice(1);if(K.startsWith(" "))K=K.slice(1);X.push(K),$.index+=1}return T1({children:s5({index:0,lines:X},0,J)})}function iq($,M){let J=H1($),Z=u1(J,M),X=O7.exec(Z);if(!X)return null;$.index+=1;let A=[];while($.index<$.lines.length){let Y=H1($),Q=u1(Y,M);if(Q.trim()===E4){$.index+=1;break}A.push(Q),$.index+=1}return N6({language:X[1]?X[1]:null,meta:X[2]?X[2]:null,source:A.join(s)})}function oq($,M){let J=H1($),Z=u1(J,M),X=H$.exec(Z);if(!X)return null;let A=X[1],Y=[];$.index+=1;while($.index<$.lines.length){let Q=H1($),K=u1(Q,M);if($.index+=1,K.trim()===r5)break;Y.push(K)}return qM({attributes:nq(X[2]??""),body:Y.join(s),name:A})}function nq($){let M=$.trim();if(M.startsWith("{")&&M.endsWith("}"))return M.slice(1,-1);return M}function tq($,M){let J=H1($),Z=u1(J,M);if(!b7.test(Z))return null;return $.index+=1,r4({originalType:"leafDirective",source:Z})}function eq($,M){let J=H1($),Z=C7.exec(u1(J,M));if(!Z)return null;return $.index+=1,h4({children:N2(Z[2].replace(lq,"")),depth:Z[1].length})}function $N($,M){let J=u1(H1($),M).trim();if(!E7(J))return null;return $.index+=1,l4()}function MN($,M,J){let Z=a5(H1($),M);if(!Z)return null;let X=[],A=!1;while($.index<$.lines.length){let Y=H1($),Q=a5(Y,M);if(!Q||Q.ordered!==Z.ordered)break;$.index+=1;let K=[Q.content],q=!1;while($.index<$.lines.length){let N=H1($),U=U2(N);if(w4(N)){let G=KN($.lines,$.index+1);if(G<0||U2($.lines[G]??"")<=M)break;q=!0,K.push(""),$.index+=1;continue}if(U<Q.contentIndent)break;if(U===M&&a5(N,M))break;K.push(YN(N,Q.contentIndent)),$.index+=1}A||=q,X.push(n1({checked:Q.checked,children:XN(K,J),spread:q}))}return y0({items:X,ordered:Z.ordered,spread:A,start:Z.ordered&&J.preserveOrderedListStart?Z.start??1:null})}function JN($,M){let J=u1(H1($),M).trim();if(!w7(J))return null;return $.index+=1,r4({originalType:"html",source:J})}function ZN($,M){let J=[];while($.index<$.lines.length){let Z=H1($),X=U2(Z);if(w4(Z))break;if(X<M)break;let A=u1(Z,M);if(J.length>0&&QN(Z,A,M))break;J.push(A),$.index+=1}return _2({children:N2(J.join(s))})}function XN($,M){let J=s5({index:0,lines:$},0,M);if(J.length>0)return J;return[_2({children:[]})]}function a5($,M){let J=rq.exec($);if(!J||J[1].length!==M)return null;let Z=J[2],X=Iq.test(Z),A=X?Number(Z.slice(0,-1)):null,Y=J[3]??"",Q=null;if(pq.test(Y)){if(Q=Y[1]==="x"||Y[1]==="X",Y=Y.slice(3),Y.startsWith(" "))Y=Y.slice(1)}let K=Y.length>0?J[0].length-J[1].length-J[2].length-Y.length:J[0].length-J[1].length-J[2].length;return{checked:Q,content:Y,contentIndent:M+J[2].length+K,ordered:X,start:A}}function AN($,M){return u1($,M).startsWith(q2)}function u1($,M){return $.slice(M)}function YN($,M){let J=U2($);if(J>=M)return $.slice(M);return $.trim()===""?"":$.slice(Math.min(J,M))}function E7($){return cq.test($)||xq.test($)||dq.test($)}function w7($){return $.startsWith("<")&&$.endsWith(">")}function U2($){let M=0;while(M<$.length&&$[M]===" ")M+=1;return M}function QN($,M,J){return M.startsWith(q2)||O7.test(M)||H$.test(M)||b7.test(M)||C7.test(M)||E7(M.trim())||b$(M)||a5($,J)!==null||w7(M.trim())}function H1($){return $.lines[$.index]??""}function w4($){return $.trim()===""}function KN($,M){for(let J=M;J<$.length;J+=1)if(!w4($[J]??""))return J;return-1}function R7($){let M=$.at(-1),J=M&&j7(M)?M:null;return{blocks:$.filter((X)=>!j7(X)),comments:J?qN(J.body):[]}}function qN($){let M;try{M=JSON.parse($)}catch{return[]}if(!Array.isArray(M))return[];return M.flatMap((J)=>{let Z=P6(J);return Z?[Z]:[]})}function j7($){return $.type==="directive"&&$.name===c5}function C$($,M={}){let Z={index:0,lines:$.replace(/\r\n/g,s).split(s)},X=s5(Z,0,M),{comments:A,blocks:Y}=R7(X);return h0(Y,A)}var j4=`
27
-
28
- `,NN="-",UN=".",GN="***",BN="&#x20;",E$=3,FN=5,DN=4,L7=2,_N=2,HN=1,PN=/([\\`*_[\]])/g,WN=/([\\)&])/g,TN=/(["\\])/g;function i5($,M={}){if($.blocks.length===0&&$.comments.length===0)return"";let J=$.blocks.map((X)=>o5(X,0,M));if($.comments.length>0)J.push(gN($.comments));let Z=J.join(j4);return Z.endsWith(s)?Z:`${Z}${s}`}function o5($,M,J){let Z=T0(M);switch($.type){case"blockquote":return yN($,M,J);case"code":return VN($,M);case"directive":return hN($,M);case"heading":return f7($,M);case"list":return zN($,M,J);case"listItem":return u7($,M,!1,1,J);case"paragraph":return`${Z}${w$(R4($.children))}`;case"table":return bN($,M,J);case"thematicBreak":return`${Z}${GN}`;case"unsupported":return M===0?$.source:v7($.source,M)}}function yN($,M,J){let Z=$.children.map((A)=>o5(A,0,J)).join(j4),X=T0(M);return Z.split(s).map((A)=>`${X}${q2}${A.length>0?` ${A}`:""}`).join(s)}function VN($,M){let J=[$.language??"",$.meta??""].filter(Boolean).join(" ").trim(),Z=T0(M),X=`${Z}${E4}${J?J:""}`,A=$.source.length>0?$.source.split(s).map((Y)=>`${Z}${Y}`).join(s):Z;return`${X}${s}${A}${s}${Z}${E4}`}function f7($,M){let J=w$(R4($.children)),Z=`${T0(M)}${"#".repeat($.depth)}`;return J.length>0?`${Z} ${J}`:Z}function zN($,M,J){let Z=$.start??1;return $.items.map((X)=>u7(X,M,$.ordered,Z,J)).join($.spread?j4:s)}function u7($,M,J,Z,X){let A=J?`${Z}${UN}`:NN,Y=$.checked===null?"":`[${$.checked?"x":" "}] `,Q=`${T0(M)}${A} ${Y}`,K=M+A.length+1,q=$.children;if(q.length===0)return Y.length>0?Q:Q.trimEnd();let[N,...U]=q,G=ON(N,Q,Y.length>0,X),B=U.map((D)=>o5(D,K,X)).join($.spread?j4:s);if(!B)return G;return`${G}${$.spread?j4:s}${B}`}function ON($,M,J,Z){switch($.type){case"paragraph":{let X=w$(R4($.children));if(X.length===0)return J?M:M.trimEnd();return`${M}${X}`}case"heading":return`${M}${f7($,0)}`;case"directive":case"unsupported":{let X=$.type==="directive"?j$($):$.source,[A,...Y]=X.split(s);return[M+A,...Y.map((Q)=>`${T0(M.length)}${Q}`)].join(s)}default:{let X=M.length;return`${M.trimEnd()}${s}${o5($,X,Z)}`}}}function bN($,M,J){let Z=$.rows.map((N)=>N.cells.map((U)=>R4(U.children))),X=Math.max(1,...Z.map((N)=>N.length)),A=Z[0]??[],Y=Array.from({length:X},(N,U)=>Math.max(E$,jN($.align[U]),...J.padTableColumns?Z.map((G)=>G[U]?.length??0):[A[U]?.length??0])),Q=CN(Y,$.align,M),K=k7(A,Y,$.align,M,J),q=Z.slice(1).map((N)=>k7(N,Y,$.align,M,J));return[K??EN(Y,M),Q,...q].join(s)}function k7($,M,J,Z,X){let A=M.map((Y,Q)=>{let K=$[Q]??"";if(!X.padTableColumns)return K;return RN(K,Y,J[Q])});return`${" ".repeat(Z)}| ${A.join(" | ")} |`}function CN($,M,J){let Z=$.map((X,A)=>wN(M[A],X));return`${" ".repeat(J)}| ${Z.join(" | ")} |`}function EN($,M){return`${T0(M)}| ${$.map((J)=>"".padEnd(J," ")).join(" | ")} |`}function wN($,M){let J=Math.max(E$,M-($==="center"?_N:$?HN:0));switch($){case"center":return`:${"-".repeat(Math.max(1,J))}:`;case"left":return`:${"-".repeat(Math.max(L7,J))}`;case"right":return`${"-".repeat(Math.max(L7,J))}:`;default:return"-".repeat(J)}}function jN($){return $==="center"?FN:$?DN:E$}function RN($,M,J){if(J==="right")return $.padStart(M," ");return $.padEnd(M," ")}function R4($){return kN($).map((M)=>LN(M)).join("")}function w$($){return $.replace(/^ +/gm,(M)=>BN.repeat(M.length))}function LN($){switch($.type){case"break":return s;case"image":return IN($);case"inlineCode":return SN($.code);case"link":return pN($);case"text":return uN(S7($.text),$.marks);case"unsupported":return $.source}}function kN($){let M=[];for(let J of $){let Z=M.at(-1);if(Z?.type==="text"&&J.type==="text"&&fN(Z.marks,J.marks)){M[M.length-1]={...Z,text:Z.text+J.text};continue}M.push(J)}return M}function fN($,M){return $.length===M.length&&$.every((J,Z)=>J===M[Z])}function uN($,M){return M.reduce((J,Z)=>{switch(Z){case"bold":return`**${J}**`;case"italic":return`*${J}*`;case"strikethrough":return`~~${J}~~`;case"underline":return`${W0}${J}${C4}`}},$)}function SN($){let M=0,J=0;for(let Y of $){if(Y==="`"){if(J+=1,J>M)M=J;continue}J=0}let Z=M>0?M+1:1,X="`".repeat(Z),A=$.startsWith("`")||$.endsWith("`")?` ${$} `:$;return`${X}${A}${X}`}function S7($){return $.replace(PN,"\\$1")}function mN($){return $.replace(WN,"\\$1")}function vN($){return $?` "${$.replace(TN,"\\$1")}"`:""}function gN($){return j$({attributes:"",body:JSON.stringify($,null,2),name:c5})}function hN($,M){let J=j$($);return M===0?J:v7(J,M)}function j$($){let M=$.attributes?`{${$.attributes}}`:"";return`:::${$.name}${M}${s}${$.body}${s}${r5}`}function IN($){let M=S7($.alt??""),J=m7($.url,$.title),Z=$.width?`{width=${$.width}}`:"";return`![${M}]${J}${Z}`}function pN($){return`[${R4($.children)}]${m7($.url,$.title)}`}function m7($,M){return`(${mN($)}${vN(M)})`}function T0($){return" ".repeat($)}function v7($,M){let J=T0(M);return $.split(s).map((Z)=>`${J}${Z}`).join(s)}import{useEffect as t5,useRef as tN,useState as j0}from"react";import{forwardRef as lN}from"react";import{jsxDEV as G2}from"react/jsx-dev-runtime";var n5=lN(function({className:M,onCancel:J,onChange:Z,onSave:X,placeholder:A,readOnly:Y=!1,rows:Q=3,saveDisabled:K=!1,value:q},N){return G2("div",{className:"documint-edit-input-field",children:[G2("textarea",{className:M??"documint-comment-input",onChange:(U)=>Z(U.currentTarget.value),onKeyDown:(U)=>{if(U.key!=="Escape")return;U.preventDefault(),J()},placeholder:A,readOnly:Y,ref:N,rows:Q,value:q},void 0,!1,void 0,this),G2("button",{className:"documint-leaf-action documint-edit-input-cancel","aria-label":"Cancel editing",onClick:J,title:"Cancel editing",type:"button",children:G2(b4,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this),G2("button",{className:"documint-leaf-action documint-edit-input-save","aria-label":"Save",disabled:K,onClick:X,title:"Save",type:"button",children:G2(C0,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)});import{Children as g7,isValidElement as h7,useEffect as rN,useRef as cN,useState as xN}from"react";import{jsxDEV as q1}from"react/jsx-dev-runtime";var R$=($)=>{$.preventDefault()},L$=($)=>$.isPrimary&&$.button===0;function dN({children:$}){return q1("div",{className:"documint-leaf-toolbar",children:g7.map($,aN)},void 0,!1,void 0,this)}function aN($){if(!h7($))return null;if($.type===p7){let M=$.props;return q1(I7,{children:q1(sN,{...M},void 0,!1,void 0,this)},void 0,!1,void 0,this)}if($.type===l7){let{className:M}=$.props;return q1("div",{className:L4("documint-leaf-toolbar-divider",M)},void 0,!1,void 0,this)}if($.type===r7){let M=$.props;return q1(iN,{...M},void 0,!1,void 0,this)}return null}function sN({active:$=!1,className:M,disabled:J=!1,icon:Z,label:X,onClick:A}){return q1("button",{"aria-label":X,className:L4("documint-leaf-toolbar-button",$?"active":null,M),disabled:J,onPointerDown:(Y)=>{if(R$(Y),!J&&L$(Y))A()},title:X,type:"button",children:q1(Z,{size:15,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function iN({children:$,className:M,icon:J,label:Z,onSelect:X}){let A=cN(null),[Y,Q]=xN(!1);return rN(()=>{if(!Y)return;let K=(q)=>{if(A.current&&q.target instanceof Node&&!A.current.contains(q.target))Q(!1)};return window.addEventListener("pointerdown",K),()=>{window.removeEventListener("pointerdown",K)}},[Y]),q1(I7,{children:q1("div",{className:"documint-leaf-toolbar-menu-shell",ref:A,children:[q1(oN,{className:M,icon:J,isOpen:Y,label:Z,onClick:()=>Q((K)=>!K)},void 0,!1,void 0,this),Y?q1("div",{className:"documint-leaf-toolbar-menu",role:"menu",children:g7.map($,(K)=>nN(K,(q)=>{Q(!1),X(q)}))},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function oN({className:$,icon:M,isOpen:J,label:Z,onClick:X}){return q1("button",{"aria-expanded":J,"aria-haspopup":"menu","aria-label":Z,className:L4("documint-leaf-toolbar-button",J?"active":null,$),onPointerDown:(A)=>{if(R$(A),L$(A))X()},title:Z,type:"button",children:[q1(M,{size:15,strokeWidth:2.2},void 0,!1,void 0,this),q1(q4,{className:L4("documint-leaf-toolbar-menu-chevron",J?"is-open":null),size:13,strokeWidth:2.2},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function nN($,M){if(!h7($))return null;if($.type===x7){let{className:Y}=$.props;return q1("div",{className:L4("documint-leaf-toolbar-menu-divider",Y),role:"separator"},void 0,!1,void 0,this)}if($.type!==c7)return null;let{disabled:J=!1,icon:Z,text:X,value:A}=$.props;return q1("button",{className:"documint-leaf-toolbar-menu-item",disabled:J,onPointerDown:(Y)=>{if(R$(Y),!J&&L$(Y))M(A)},role:"menuitem",type:"button",children:[q1(Z,{size:15,strokeWidth:2.2},void 0,!1,void 0,this),q1("span",{children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function L4(...$){return $.filter(Boolean).join(" ")}function I7({children:$}){return q1("div",{className:"documint-leaf-toolbar-group",children:$},void 0,!1,void 0,this)}function p7($){return null}function l7($){return null}function r7($){return null}function c7($){return null}function x7($){return null}var x=Object.assign(dN,{Button:p7,Divider:l7,Menu:r7,MenuDivider:x7,MenuItem:c7});import{jsxDEV as h,Fragment as JU}from"react/jsx-dev-runtime";var eN=!1,$U=220,R0=()=>{};function k$($){let M=$.mode==="create",J=$.mode==="create"?$:null,Z=$.mode==="thread"?$:null,X=$.canEdit,A=$.link,Y=Z?.thread??null,Q=Y?.comments??[],K=Q[0]??null,q=Y?A0(Y):!1,N=Z?.animateInitialComment??!1,[U,G]=j0(null),[B,D]=j0(""),[F,H]=j0(""),[b,E]=j0(""),[V,R]=j0(!N),[O,j]=j0(eN),[f,z]=j0(!1),y=tN(null),T=Y?b6(Y):null,W=T?d7(T):"",_=X&&!q,C=_&&B.trim().length>0,g=_&&F.trim().length>0,u=X&&b.trim().length>0,d=M||f,p=!M||O,J1=!M&&Boolean(Y),k=Boolean(K),S=M?O:!0,m=Z?.onDeleteComment??R0,Z1=Z?.onDeleteThread??R0,t=Z?.onToggleResolved??R0,N1=J?.activeMarks??[],v1=J?.onToggleBold??R0,g1=J?.onToggleItalic??R0,A1=J?.onToggleStrikethrough??R0,S4=J?.onToggleUnderline??R0,Q6=X?M?"Add a comment":"Reply to this comment":"Comment editing is disabled",u0=M?b:F;t5(()=>{if(U!==null&&(U<0||U>=Q.length))G(null),D("")},[Q.length,U]),t5(()=>{if(!k||!N){R(!0);return}R(!1);let z1=requestAnimationFrame(()=>{R(!0)});return()=>{cancelAnimationFrame(z1)}},[N,K,k]),t5(()=>{if(!Z||!N){z(!1);return}z(!0);let z1=window.setTimeout(()=>{z(!1)},$U);return()=>{window.clearTimeout(z1)}},[N,Z]),t5(()=>{if(!M||!O||!X)return;let z1=requestAnimationFrame(()=>{y.current?.querySelector(".documint-comment-reply-field textarea")?.focus()});return()=>{cancelAnimationFrame(z1)}},[X,M,O]);let m4=()=>{G(null),D("")},i1=(z1,i)=>{if(!J1||!_)return;G(z1),D(i)},v4=(z1)=>{if(!Z)return;Z.onEditComment(z1,B),m4()},h1=()=>{if(!Z)return;Z.onReply(F),H("")},V1=()=>{if(!J||!u)return;J.onCreateThread(b),E("")},g4=d?`documint-comment-leaf documint-comment-leaf-create${S?" is-expanded":""}`:"documint-comment-leaf",e=J1||k||p?h(MU,{canCreate:u,canEdit:X,canMutateThread:_,canReply:g,canSaveEditedComment:C,commentAgeFormatter:d7,comments:Q,editDraft:B,editingCommentIndex:U,isComposerVisible:p,isInitialCommentVisible:V,isResolved:q,link:A,mode:$.mode,onBeginEditingComment:i1,onCancelEditing:m4,onChangeCreateDraft:E,onChangeEditDraft:D,onChangeReplyDraft:H,onDeleteComment:m,onDeleteThread:Z1,onSubmitCreate:V1,onSubmitEditedComment:v4,onSubmitReply:h1,onToggleResolved:t,rootComment:K,showRootComment:k,showThreadChrome:J1,threadAge:W,composerPlaceholder:Q6,composerValue:u0},void 0,!1,void 0,this):null;return h("div",{className:g4,ref:y,children:h("div",{className:d?"documint-comment-leaf-create-shell":void 0,children:[d?h(x,{children:[h(x.Button,{className:"documint-comment-leaf-create-button",icon:y4,label:"Add comment",onClick:()=>j(!0)},void 0,!1,void 0,this),h(x.Divider,{className:"documint-comment-leaf-create-divider"},void 0,!1,void 0,this),h(x.Button,{active:N1.includes("bold"),className:"documint-comment-leaf-create-mark",icon:K4,label:"Bold",onClick:v1},void 0,!1,void 0,this),h(x.Button,{active:N1.includes("italic"),className:"documint-comment-leaf-create-mark",icon:H4,label:"Italic",onClick:g1},void 0,!1,void 0,this),h(x.Button,{active:N1.includes("underline"),className:"documint-comment-leaf-create-mark",icon:O4,label:"Underline",onClick:S4},void 0,!1,void 0,this),h(x.Button,{active:N1.includes("strikethrough"),className:"documint-comment-leaf-create-mark",icon:V4,label:"Strikethrough",onClick:A1},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,h("div",{className:d?"documint-comment-leaf-create-content":void 0,children:e},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function MU({canCreate:$,canEdit:M,canMutateThread:J,canReply:Z,canSaveEditedComment:X,commentAgeFormatter:A,comments:Y,editDraft:Q,editingCommentIndex:K,isComposerVisible:q,isInitialCommentVisible:N,isResolved:U,link:G,mode:B,onBeginEditingComment:D,onCancelEditing:F,onChangeCreateDraft:H,onChangeEditDraft:b,onChangeReplyDraft:E,onDeleteComment:V,onDeleteThread:R,onSubmitCreate:O,onSubmitEditedComment:j,onSubmitReply:f,onToggleResolved:z,rootComment:y,showRootComment:T,showThreadChrome:W,threadAge:_,composerPlaceholder:C,composerValue:g}){return h(JU,{children:[W?h("div",{className:"documint-comment-leaf-header",children:[h("span",{className:"documint-comment-leaf-age",children:_},void 0,!1,void 0,this),h("div",{className:"documint-comment-leaf-actions",children:[h("button",{className:"documint-leaf-action","aria-label":U?"Reopen comment":"Resolve comment",disabled:!M,onClick:z,title:U?"Reopen comment":"Resolve comment",type:"button",children:h(C0,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this),h("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Delete comment thread",disabled:!M,onClick:R,title:"Delete comment thread",type:"button",children:h(w1,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):null,W&&G?h("div",{className:"documint-comment-leaf-link",children:[G.title?h("div",{className:"documint-link-leaf-title",children:G.title},void 0,!1,void 0,this):null,h("div",{className:"documint-link-leaf-url",children:G.url},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,h("div",{className:`documint-comment-thread${T?"":" is-empty"}`,children:[h("article",{className:T?`documint-comment-message documint-comment-message-root${N?" is-visible":""}`:"documint-comment-message documint-comment-message-root is-hidden",children:y?h("p",{onDoubleClick:()=>{D(0,y.body)},children:y.body},void 0,!1,void 0,this):null},void 0,!1,void 0,this),Y.slice(1).map((u,d)=>{let p=d+1,J1=K===p;return h("article",{className:"documint-comment-message",children:[!J1?h("div",{className:"documint-comment-message-meta",children:[h("span",{children:A(u.updatedAt)},void 0,!1,void 0,this),J?h("div",{className:"documint-comment-leaf-actions",children:[h("button",{className:"documint-leaf-action","aria-label":"Edit comment",disabled:!J,onClick:()=>{D(p,u.body)},title:"Edit comment",type:"button",children:h(E0,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this),h("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Delete comment",disabled:!J,onClick:()=>V(p),title:"Delete comment",type:"button",children:h(w1,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null]},void 0,!0,void 0,this):null,J1?h(n5,{className:"documint-comment-input",onCancel:F,onChange:b,onSave:()=>j(p),readOnly:!M,rows:3,saveDisabled:!X,value:Q},void 0,!1,void 0,this):h("p",{onDoubleClick:()=>{D(p,u.body)},children:u.body},void 0,!1,void 0,this)]},`${u.updatedAt}:${p}`,!0,void 0,this)})]},void 0,!0,void 0,this),h("div",{className:`documint-comment-reply${W?"":" is-standalone"}${q?" is-visible":""}`,children:h("div",{className:"documint-comment-reply-field",children:[h("textarea",{className:"documint-comment-input",onChange:(u)=>B==="create"?H(u.currentTarget.value):E(u.currentTarget.value),placeholder:C,readOnly:!M,rows:3,value:g},void 0,!1,void 0,this),h("button",{className:"documint-leaf-action documint-comment-reply-submit","aria-label":B==="create"?"Create comment":"Reply",disabled:B==="create"?!$:!Z,onClick:B==="create"?O:f,title:B==="create"?"Create comment":"Reply",type:"button",children:h(H0,{size:15,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function d7($){let M=new Date($);if(Number.isNaN(M.getTime()))return $;let J=M.getTime()-Date.now(),Z=60000,X=60*Z,A=24*X,Y=7*A,Q=30*A,K=365*A,q=new Intl.RelativeTimeFormat(void 0,{numeric:"auto"});if(Math.abs(J)<Z)return"just now";if(Math.abs(J)<X)return q.format(Math.round(J/Z),"minute");if(Math.abs(J)<A)return q.format(Math.round(J/X),"hour");if(Math.abs(J)<Y)return q.format(Math.round(J/A),"day");if(Math.abs(J)<K)return q.format(Math.round(J/Q),"month");return q.format(Math.round(J/K),"year")}import{jsxDEV as S1}from"react/jsx-dev-runtime";var ZU=[{icon:N4,label:"Heading 1",text:"# "},{icon:U4,label:"Heading 2",text:"## "},{icon:G4,label:"Heading 3",text:"### "},{icon:B4,label:"Heading 4",text:"#### "},{icon:F4,label:"Heading 5",text:"##### "},{icon:D4,label:"Heading 6",text:"###### "}],XU=[{columns:2,text:"2 columns"},{columns:3,text:"3 columns"},{columns:4,text:"4 columns"},{columns:5,text:"5 columns"}];function a7({onInsert:$,onInsertTable:M}){return S1(x,{children:[S1(x.Button,{icon:T4,label:"Insert bulleted list",onClick:()=>$("- ")},void 0,!1,void 0,this),S1(x.Button,{icon:P4,label:"Insert numbered list",onClick:()=>$("1. ")},void 0,!1,void 0,this),S1(x.Button,{icon:W4,label:"Insert task list",onClick:()=>$("- [ ] ")},void 0,!1,void 0,this),S1(x.Divider,{},void 0,!1,void 0,this),S1(x.Menu,{icon:_4,label:"Insert heading",onSelect:$,children:ZU.map(({icon:J,label:Z,text:X})=>S1(x.MenuItem,{icon:J,text:Z,value:X},X,!1,void 0,this))},void 0,!1,void 0,this),S1(x.Menu,{icon:P0,label:"Insert table",onSelect:(J)=>M(Number(J)),children:XU.map(({columns:J,text:Z})=>S1(x.MenuItem,{icon:P0,text:Z,value:String(J)},J,!1,void 0,this))},void 0,!1,void 0,this),S1(x.Divider,{},void 0,!1,void 0,this),S1(x.Button,{icon:z4,label:"Insert blockquote",onClick:()=>$("> ")},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{createPortal as AU}from"react-dom";import{jsxDEV as f$}from"react/jsx-dev-runtime";function s7({anchor:$,children:M,className:J,status:Z="default"}){if(typeof document>"u")return null;let X=$.container??document.body,A=!$.isSelection,Y=J?`documint-leaf-shell ${J}`:"documint-leaf-shell";return AU(f$("div",{className:"documint-leaf-anchor","data-selection":$.isSelection?"true":"false",onPointerEnter:$.onPointerEnter,onPointerLeave:$.onPointerLeave,style:{left:`${$.left}px`,top:`${$.top}px`},children:[A?f$("div",{className:"documint-leaf-bridge"},void 0,!1,void 0,this):null,f$("div",{className:Y,"data-status":Z,children:M},void 0,!1,void 0,this)]},void 0,!0,void 0,this),X)}import{useEffect as i7,useRef as YU,useState as o7}from"react";import{jsxDEV as j1}from"react/jsx-dev-runtime";function n7({canEdit:$,onDelete:M,onSave:J,title:Z,url:X}){let[A,Y]=o7(X),[Q,K]=o7(!1),q=YU(null),N=QU(),U=A.trim(),G=$&&U.length>0,B=$&&!Q,D=`${N}click to open`,F=`documint-link-leaf-row${Q?" is-editing":""}`;return i7(()=>{if(Q)return;Y(X)},[Q,X]),i7(()=>{if(!Q)return;q.current?.focus()},[Q]),j1("div",{className:"documint-link-leaf",children:[Z?j1("div",{className:"documint-link-leaf-title",children:Z},void 0,!1,void 0,this):null,j1("div",{className:F,children:[Q?j1(n5,{className:"documint-comment-input documint-link-leaf-input",onCancel:()=>{Y(X),K(!1)},onChange:Y,onSave:()=>{J(U),K(!1)},readOnly:!$,ref:q,rows:3,saveDisabled:!G,value:A},void 0,!1,void 0,this):j1("div",{className:"documint-link-leaf-url",children:X},void 0,!1,void 0,this),B?j1("div",{className:"documint-link-leaf-actions",children:[j1("button",{className:"documint-leaf-action","aria-label":"Edit link",onClick:()=>{if(!$)return;Y(X),K(!0)},title:"Edit link",type:"button",children:j1(E0,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this),j1("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Remove link",onClick:M,title:"Remove link",type:"button",children:j1(w1,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null]},void 0,!0,void 0,this),j1("div",{className:"documint-link-leaf-divider"},void 0,!1,void 0,this),j1("div",{className:"documint-link-leaf-hint",children:D},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function QU(){if(typeof navigator>"u")return"Ctrl+";let $=navigator.platform||navigator.userAgent;return/Mac|iPhone|iPad|iPod/.test($)?"CMD+":"CTRL+"}import{jsxDEV as R1}from"react/jsx-dev-runtime";var KU=[{text:"Column left",value:"left"},{text:"Column right",value:"right"}],qU=[{text:"Row above",value:"above"},{text:"Row below",value:"below"}],u$={text:"Delete column",value:"delete"},S$={text:"Delete row",value:"delete"},t7={text:"Delete table",value:"delete"};function e7({canDeleteColumn:$,canDeleteRow:M,onDeleteColumn:J,onDeleteRow:Z,onDeleteTable:X,onInsertColumn:A,onInsertRow:Y}){return R1(x,{children:[R1(x.Menu,{icon:D0,label:"Column actions",onSelect:(Q)=>{if(Q===u$.value){J();return}A(Q)},children:[KU.map(({text:Q,value:K})=>R1(x.MenuItem,{icon:K2,text:Q,value:K},K,!1,void 0,this)),R1(x.MenuDivider,{},void 0,!1,void 0,this),R1(x.MenuItem,{disabled:!$,icon:w1,text:u$.text,value:u$.value},void 0,!1,void 0,this)]},void 0,!0,void 0,this),R1(x.Menu,{icon:_0,label:"Row actions",onSelect:(Q)=>{if(Q===S$.value){Z();return}Y(Q)},children:[qU.map(({text:Q,value:K})=>R1(x.MenuItem,{icon:K2,text:Q,value:K},K,!1,void 0,this)),R1(x.MenuDivider,{},void 0,!1,void 0,this),R1(x.MenuItem,{disabled:!M,icon:w1,text:S$.text,value:S$.value},void 0,!1,void 0,this)]},void 0,!0,void 0,this),R1(x.Divider,{},void 0,!1,void 0,this),R1(x.Menu,{icon:P0,label:"Table actions",onSelect:()=>X(),children:R1(x.MenuItem,{icon:w1,text:t7.text,value:t7.value},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as NU,useEffectEvent as $J,useLayoutEffect as UU,useMemo as GU,useRef as MJ,useState as BU}from"react";function e5($,M){if(!$||$.kind==="task-toggle")return null;if($.commentThreadIndex!==null){let J=M[$.commentThreadIndex]??null;if(!J)return null;return{kind:"comment",left:$.anchorLeft,link:$.kind==="link"?{title:$.title,url:$.url}:null,thread:J,threadIndex:$.commentThreadIndex,top:$.anchorBottom}}if($.kind!=="link")return null;return{endOffset:$.endOffset,kind:"link",left:$.anchorLeft,regionId:$.regionId,startOffset:$.startOffset,title:$.title,top:$.anchorBottom,url:$.url}}var FU=600,DU=530;function JJ({canShowInsertionLeaf:$,canShowTableLeaf:M,commentState:J,editorState:Z,editorViewportState:X,onVisibilityChange:A}){let Y=GU(()=>n(Z),[Z]),[Q,K]=BU(null),q=Y.start.regionId===Y.end.regionId&&Y.start.offset===Y.end.offset,N=MJ(!0),U=MJ(0),G=$J(()=>{A()}),B=$J(()=>{U.current=typeof performance<"u"?performance.now():Date.now(),N.current=!0,G()});return UU(()=>{let D=_U({canShowInsertionLeaf:$,canShowTableLeaf:M,commentState:J,normalizedSelection:Y,state:Z,viewport:X.get()});K((F)=>TU(F,D)?F:D)},[$,M,J,Z,X,Y.end.offset,Y.end.regionId,Y.start.offset,Y.start.regionId]),NU(()=>{if(N.current=!0,G(),!q||typeof window>"u")return;let D=window.setInterval(()=>{if((typeof performance<"u"?performance.now():Date.now())-U.current<FU){if(!N.current)N.current=!0,G();return}N.current=!N.current,G()},DU);return()=>{window.clearInterval(D)}},[q]),{leaf:Q,isVisible:()=>N.current,markActivity:B}}function _U({canShowInsertionLeaf:$,canShowTableLeaf:M,commentState:J,normalizedSelection:Z,state:X,viewport:A}){if(!A)return null;let Y=X.selection.focus;if(Z.start.regionId!==Z.end.regionId||Z.start.offset!==Z.end.offset)return null;let Q=$?WU(X,A):null;if(Q)return Q;let K=M?HU(X,A):null;if(K)return K;return e5(M8(X,A,Y,J.liveRanges),J.threads)}function HU($,M){let J=$.selection.focus,Z=$.documentIndex.regionIndex.get(J.regionId),X=Z?$.documentIndex.tableCellIndex.get(Z.id)??null:null;if(!Z||!X)return null;let A=$.documentIndex.blockIndex.get(Z.blockId),Y=A?.type==="table"?$.documentIndex.document.blocks[A.rootIndex]:null;if(!A||!Y||Y.type!=="table")return null;let Q=M0($,M,J),K=PU(M,Z.id),q=Math.max(1,...Y.rows.map((N)=>N.cells.length));return Q&&K!==null?{cellIndex:X.cellIndex,columnCount:q,kind:"table",left:K,rowCount:Y.rows.length,rowIndex:X.rowIndex,top:Q.top+Q.height}:null}function PU($,M){let J=$.layout.lines.find((Z)=>Z.regionId===M);return J?J.left:null}function WU($,M){let J=$.selection.focus,Z=$.documentIndex.regionIndex.get(J.regionId);if(!Z||Z.blockType!=="paragraph"||Z.text.length>0)return null;if(J.offset!==0)return null;let X=$.documentIndex.blockIndex.get(Z.blockId);if(!X||X.parentBlockId!==null)return null;let A=M0($,M,J);return A?{kind:"insertion",left:A.left,top:A.top+A.height}:null}function TU($,M){if($===M)return!0;if(!$||!M||$.kind!==M.kind)return!1;switch($.kind){case"comment":return M.kind==="comment"&&$.left===M.left&&$.link?.title===M.link?.title&&$.link?.url===M.link?.url&&$.thread===M.thread&&$.threadIndex===M.threadIndex&&$.top===M.top;case"insertion":return M.kind==="insertion"&&$.left===M.left&&$.top===M.top;case"link":return M.kind==="link"&&$.endOffset===M.endOffset&&$.left===M.left&&$.regionId===M.regionId&&$.startOffset===M.startOffset&&$.title===M.title&&$.top===M.top&&$.url===M.url;case"table":return M.kind==="table"&&$.cellIndex===M.cellIndex&&$.columnCount===M.columnCount&&$.left===M.left&&$.rowCount===M.rowCount&&$.rowIndex===M.rowIndex&&$.top===M.top}}import{useEffect as yU,useMemo as m$,useRef as ZJ,useState as VU}from"react";function XJ($){let M=m$(()=>zU($),[$]),J=m$(()=>M.join(`
29
- `),[M]),[Z,X]=VU(new Map),A=ZJ(Z),Y=ZJ(new Map);return A.current=Z,yU(()=>{if(typeof Image>"u")return;let Q=!0,K=new Set(M),q=Y.current;X((N)=>bU(N,K,q));for(let N of M){if(OU(A.current,q,N))continue;CU(N,q,X,()=>Q)}return()=>{Q=!1}},[J]),m$(()=>Z.size===0?null:{images:Z},[Z])}function zU($){return[..._M($)].sort()}function OU($,M,J){return $.get(J)?.status==="loaded"||M.has(J)}function bU($,M,J){let Z=!1,X=new Map($);for(let A of X.keys())if(!M.has(A))X.delete(A),J.delete(A),Z=!0;return Z?X:$}function CU($,M,J,Z){let X=new Image;X.decoding="async",X.crossOrigin="anonymous",M.set($,X),J((A)=>{let Y=new Map(A);return Y.set($,EU()),Y}),X.onload=()=>{if(M.delete($),!Z())return;J((A)=>{let Y=new Map(A);return Y.set($,wU(X)),Y})},X.onerror=()=>{if(M.delete($),!Z())return;J((A)=>{let Y=new Map(A);return Y.set($,jU()),Y})},X.src=$}function EU(){return{intrinsicHeight:0,intrinsicWidth:0,source:null,status:"loading"}}function wU($){return{intrinsicHeight:$.naturalHeight,intrinsicWidth:$.naturalWidth,source:$,status:"loaded"}}function jU(){return{intrinsicHeight:0,intrinsicWidth:0,source:null,status:"error"}}import{useEffect as AJ,useEffectEvent as m1,useRef as YJ,useState as RU}from"react";var LU=48;function QJ({commentState:$,editorStateRef:M,editorViewportState:J,resolveDocumentPoint:Z}){let[X,A]=RU(null),Y=YJ(null),Q=YJ(!1),K=e5(X,$.threads),q=X?.kind==="task-toggle"||K?.kind==="link"?"pointer":"text";AJ(()=>{if(X&&X.kind!=="task-toggle"&&!K)A(null)},[X,K]);let N=m1(()=>{if(Y.current!==null)window.clearTimeout(Y.current),Y.current=null}),U=m1(()=>{N(),Y.current=window.setTimeout(()=>{if(Y.current=null,!Q.current)A(null)},LU)}),G=m1(()=>{N(),A(null)}),B=m1(()=>{if(!Q.current)G()});AJ(()=>()=>{if(Y.current!==null)window.clearTimeout(Y.current)},[]);let D=m1((O)=>{let j=M.current;if(!j)return null;let f=Z(O);if(!f)return null;return $8(j,J.get(),f,$.liveRanges)}),F=m1((O)=>{if(!O){B();return}if(O.kind==="task-toggle"){N(),A((j)=>j?.kind==="task-toggle"&&j.listItemId===O.listItemId?j:O);return}if(O.commentThreadIndex!==null){if(!($.threads[O.commentThreadIndex]??null)){B();return}N();let f=O.commentThreadIndex;A((z)=>z?.kind!=="task-toggle"&&z?.commentThreadIndex===f?z:O);return}if(O.kind!=="link"){B();return}N(),A((j)=>j?.kind==="link"&&j.title===O.title&&j.url===O.url&&j.startOffset===O.startOffset&&j.endOffset===O.endOffset?j:O)}),H=m1((O)=>{F(D(O))}),b=m1(()=>{if(!Q.current)U()}),E=m1(()=>{Q.current=!0,N()}),V=m1(()=>{Q.current=!1,U()});return{canvasHandlers:{onClick:m1((O)=>{let j=D(O);if(!j||j.kind!=="link"||!O.metaKey&&!O.ctrlKey)return!1;return O.preventDefault(),O.stopPropagation(),O.currentTarget.ownerDocument.defaultView?.open(j.url,"_blank","noopener,noreferrer"),!0}),onPointerLeave:b,onPointerMove:H},cursor:q,leaf:K,leafHandlers:{onPointerEnter:E,onPointerLeave:V},resolveTarget:D}}import{useEffect as p$,useEffectEvent as D1,useLayoutEffect as fU,useRef as BJ,useState as uU}from"react";var v$=[{key:"Backspace",command:"deleteBackward"},{key:"Enter",command:"insertLineBreak"},{key:"Home",command:"moveToLineStart"},{key:"End",command:"moveToLineEnd"},{key:"Tab",command:"indent"},{key:"Tab",shiftKey:!0,command:"dedent"},{key:"ArrowLeft",modKey:!0,shiftKey:"any",command:"moveToLineStart"},{key:"ArrowRight",modKey:!0,shiftKey:"any",command:"moveToLineEnd"},{key:"ArrowUp",modKey:!0,shiftKey:"any",command:"moveToDocumentStart"},{key:"ArrowDown",modKey:!0,shiftKey:"any",command:"moveToDocumentEnd"},{key:"ArrowUp",altKey:!0,shiftKey:!0,command:"moveListItemUp"},{key:"ArrowDown",altKey:!0,shiftKey:!0,command:"moveListItemDown"},{key:"a",modKey:!0,command:"selectAll"},{key:"b",modKey:!0,command:"toggleBold"},{key:"e",modKey:!0,command:"toggleInlineCode"},{key:"i",modKey:!0,command:"toggleItalic"},{key:"u",modKey:!0,command:"toggleUnderline"},{key:"y",modKey:!0,command:"redo"},{key:"z",modKey:!0,command:"undo"},{key:"z",modKey:!0,shiftKey:!0,command:"redo"}];function KJ($,M=v$){return M.find((J)=>{let Z=J.shiftKey==="any"?!0:(J.shiftKey??!1)===($.shiftKey??!1);return J.key.toLowerCase()===$.key.toLowerCase()&&(J.altKey??!1)===($.altKey??!1)&&Z&&(J.modKey??!1)===Boolean($.metaKey||$.ctrlKey)})?.command??null}function GJ($){let M=$.documentIndex.regions.find((A)=>A.id===$.selection.anchor.regionId),J=$.documentIndex.regions.find((A)=>A.id===$.selection.focus.regionId),Z=(M?.start??0)+$.selection.anchor.offset,X=(J?.start??0)+$.selection.focus.offset;return{end:Math.max(Z,X),start:Math.min(Z,X)}}function g$($){let M=h$($);if(!M)return"";let J=$.documentIndex.regions.find((Z)=>Z.id===M.regionId);if(!J)return"";return J.text.slice(M.startOffset,M.endOffset)}function h$($){let M=kU($);if(M.start.regionId!==M.end.regionId||M.start.offset===M.end.offset)return null;return{endOffset:M.end.offset,regionId:M.start.regionId,startOffset:M.start.offset}}var qJ=28,NJ=18;function I$($,M){if(!$)return;let J=$.getBoundingClientRect();if(M.clientY<J.top+qJ){$.scrollTop=Math.max(0,$.scrollTop-NJ);return}if(M.clientY>J.bottom-qJ)$.scrollTop+=NJ}function kU($){let M=UJ($.documentIndex.regions,$.selection.anchor.regionId,$.selection.anchor.offset),J=UJ($.documentIndex.regions,$.selection.focus.regionId,$.selection.focus.offset);return M<=J?{end:$.selection.focus,start:$.selection.anchor}:{end:$.selection.anchor,start:$.selection.focus}}function UJ($,M,J){let Z=$.findIndex((X)=>X.id===M);if(Z===-1)return-1;return Z*1e6+J}var SU=64;function DJ({editorState:$,editorStateRef:M,editorViewportState:J,inputRef:Z,keybindings:X,onActivity:A,onEditorStateChange:Y}){let Q=mU(),K=()=>M.current??$,q=BJ(!1),N=BJ(!1),U=D1((_)=>{if(!_)return;A(),Y(_)}),G=D1(()=>{let _=Z.current;if(!_)return;if(typeof document>"u")return;let C=document.execCommand;if(typeof C!=="function")return;try{q.current=!0,C.call(document,"insertText",!1,"‌"),C.call(document,"delete")}catch{}finally{q.current=!1,k4(_,K())}}),B=D1(()=>{if(N.current)return;N.current=!0,G()}),D=D1(()=>{G()}),F=D1((_)=>{if(!Q)return;let C=Z.current;if(!C)return;let g=J.get(),u=M0(K(),g,_);if(!u)return;C.style.top=`${u.top}px`,C.style.left=`${u.left}px`,C.style.height=`${u.height}px`}),H=D1((_)=>{let C=Z.current;if(!C)return;F(_??K().selection.focus),C.focus({preventScroll:!Q}),k4(C,K()),B()}),b=D1((_,C)=>{let u=FJ(C,l$(_)).replace(/\r\n/g,`
30
- `).split(/(\n)/),d=_;for(let p of u){if(p.length===0)continue;let J1=p===`
31
- `?e2(d):Y2(d,p);if(!J1)continue;d=J1}return d===_?null:d}),E=D1((_,C,g)=>{let u=_.selection.focus,d={regionId:u.regionId,offset:Math.max(0,u.offset-C)},p=K1(_,{anchor:d,focus:u});return m5(p,g)}),V=D1((_)=>{if(q.current)return;let C=K(),g=gU(_.inputType);if(_.inputType==="insertText"){if(!_.data)return;_.preventDefault(),U(b(C,_.data));return}if(_.inputType==="insertReplacementText"){if(!_.data)return;_.preventDefault();let u=_.target,d=u?.selectionStart??0,p=u?.selectionEnd??d,J1=Math.max(0,p-d);U(E(C,J1,_.data));return}if(vU(_.inputType)){_.preventDefault(),U(e2(C));return}if(g==="backward"){_.preventDefault(),U(u5(C));return}if(g==="forward"){_.preventDefault(),U(S5(C));return}if(_.inputType==="historyUndo"){_.preventDefault(),U(g5(C)),D();return}if(_.inputType==="historyRedo"){_.preventDefault(),U(h5(C)),D();return}}),R=D1((_)=>{if(q.current)return;let C=K(),g=_.currentTarget.value;if(FJ(g,l$(C)).length===0){k4(_.currentTarget,C);return}U(b(C,g))}),O=D1((_)=>{let C=IU(K(),J.get(),_.nativeEvent,X);if(!C)return;_.preventDefault(),U(C)}),j=D1((_)=>{let C=g$(K());if(!C)return;_.preventDefault(),_.clipboardData.setData("text/plain",C)}),f=D1((_)=>{let C=K(),g=g$(C);if(!g)return;_.preventDefault(),_.clipboardData.setData("text/plain",g),U($4(C))}),z=D1((_)=>{let C=_.clipboardData.getData("text/plain");if(C.length===0)return;_.preventDefault(),U(m5(K(),C))}),y=D1(()=>{A();let _=Z.current;if(_)k4(_,K())}),T=D1(()=>{A(),H()});p$(()=>{let _=Z.current;if(!_)return;k4(_,$)},[$,Z]),fU(()=>{F($.selection.focus)},[$,F]),p$(()=>{let _=Z.current;if(!_)return;let C=(g)=>V(g);return _.addEventListener("beforeinput",C),()=>_.removeEventListener("beforeinput",C)},[Z,V]);let W={onCopy:j,onCut:f,onPaste:z,...Q?{}:{onKeyDown:O}};return{canvasHandlers:{...W,onFocus:T},focus:H,inputHandlers:{...W,onFocus:y,onInput:R}}}var _J="​";function mU(){let[$,M]=uU(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function")return!1;return window.matchMedia("(pointer: coarse)").matches});return p$(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function")return;let J=window.matchMedia("(pointer: coarse)"),Z=(X)=>M(X.matches);return J.addEventListener?.("change",Z),()=>J.removeEventListener?.("change",Z)},[]),$}function vU($){return $==="insertLineBreak"||$==="insertParagraph"}function gU($){switch($){case"deleteContentBackward":case"deleteComposedCharacterBackward":case"deleteSoftLineBackward":case"deleteHardLineBackward":case"deleteWordBackward":return"backward";case"deleteContentForward":case"deleteSoftLineForward":case"deleteHardLineForward":case"deleteWordForward":return"forward";default:return null}}function hU($){return $.replaceAll(_J,"")}function l$($,M=SU){let{anchor:J,focus:Z}=$.selection;if(J.regionId!==Z.regionId||J.offset!==Z.offset)return"";let X=$.documentIndex.regionIndex.get(Z.regionId);if(!X)return"";return X.text.slice(Math.max(0,Z.offset-M),Z.offset)}function FJ($,M){let J=hU($);return J.startsWith(M)?J.slice(M.length):J}function k4($,M){let J=l$(M),Z=`${_J}${J}`;$.value=Z,$.setSelectionRange(Z.length,Z.length)}function IU($,M,J,Z){if(J.key==="Delete")return S5($);let X=KJ(J,Z);if(X){if(X==="moveToLineStart"||X==="moveToLineEnd")return K$($,M.layout,X==="moveToLineStart"?"Home":"End",J.shiftKey);if(X==="moveToDocumentStart"||X==="moveToDocumentEnd")return q$($,X==="moveToDocumentStart"?"start":"end",J.shiftKey);switch(X){case"insertLineBreak":return e2($);case"deleteBackward":return u5($);case"indent":return h8($);case"dedent":return I8($);case"moveListItemUp":return p8($);case"moveListItemDown":return l8($);case"toggleBold":return M4($);case"toggleItalic":return J4($);case"toggleStrikethrough":return Z4($);case"toggleUnderline":return X4($);case"toggleInlineCode":return i8($);case"undo":return g5($);case"redo":return h5($);case"selectAll":return g8($)}}if(J.key==="ArrowLeft"||J.key==="ArrowRight")return A$($,J.key==="ArrowLeft"?-1:1,J.shiftKey);if(J.key==="ArrowUp"||J.key==="ArrowDown")return Y$($,M.layout,J.key==="ArrowUp"?-1:1,J.shiftKey);if(J.key==="PageUp"||J.key==="PageDown")return Q$($,M.layout,J.key==="PageUp"?-1:1,J.shiftKey);if(J.key.length===1&&!J.altKey&&!J.ctrlKey&&!J.metaKey)return Y2($,J.key);return null}import{useEffect as pU,useEffectEvent as r$,useLayoutEffect as lU,useMemo as rU,useRef as HJ,useState as cU}from"react";var xU=[];function PJ({editorState:$,editorStateRef:M,editorViewportState:J,onViewportScroll:Z,presence:X,scrollContainerRef:A,scheduleOverlayRender:Y}){let Q=rU(()=>{if(!X||X.length===0)return xU;return K5($.documentIndex,X)},[$.documentIndex,X]),[K,q]=cU([]),N=HJ(Q),U=HJ(K);N.current=Q,U.current=K;let G=r$((F)=>{if(dU(U.current,F))return;U.current=F,q(F)}),B=r$((F)=>{let H=N.current;if(H.length===0){G([]);return}G(q5(M.current??$,F,H))});pU(()=>{Y()},[Q,Y]),lU(()=>{if(Q.length===0){G([]);return}B(J.get())},[J,B,Q,G]);let D=r$((F)=>{if(!F.viewport||F.viewport.scrollTop===null)return;let H=A.current;if(!H)return;H.scrollTop=F.viewport.scrollTop,Z(H)});return{canvasPresence:Q.length===0?void 0:Q,presenceOverlayProps:{onSelect:D,presence:K},refreshViewportPresence:B}}function dU($,M){if($.length!==M.length)return!1;return $.every((J,Z)=>{let X=M[Z];return X!==void 0&&J.color===X.color&&J.imageUrl===X.imageUrl&&J.name===X.name&&J.viewport?.scrollTop===X.viewport?.scrollTop&&J.viewport?.status===X.viewport?.status})}import{useEffect as aU,useEffectEvent as $6,useRef as M6}from"react";function WJ({hasRunningAnimations:$,renderContent:M,renderOverlay:J,renderViewport:Z}){let X=M6(null),A=M6(!1),Y=M6(!1),Q=M6(!1),K=$6(()=>{if(typeof window>"u"||X.current!==null)return;X.current=window.requestAnimationFrame(()=>{N()})}),q=$6(()=>{if(!$?.())return;Y.current=!0,K()}),N=$6(()=>{X.current=null;let G=A.current,B=Y.current,D=Q.current;if(A.current=!1,Y.current=!1,Q.current=!1,G){Z(),q();return}if(B){if(M(),D)J();q();return}if(D)J()}),U=$6((G)=>{if(typeof window>"u")switch(G){case"viewport":Z();return;case"content":M();return;case"overlay":J();return}switch(G){case"viewport":A.current=!0;break;case"content":Y.current=!0;break;case"overlay":Q.current=!0;break}K()});return aU(()=>{return()=>{if(typeof window>"u"||X.current===null)return;window.cancelAnimationFrame(X.current),X.current=null}},[]),{scheduleRender:U}}import{useEffectEvent as c$,useLayoutEffect as TJ,useMemo as x$,useRef as d$,useState as yJ}from"react";function J6($,M){let J=M.getBoundingClientRect();return{x:$.clientX-J.left+M.scrollLeft,y:$.clientY-J.top+M.scrollTop}}function VJ({autoScrollContainer:$,canShowSelectionLeaf:M,canvasRef:J,threads:Z,editorState:X,editorStateRef:A,scrollContainerRef:Y,editorViewportState:Q,onActivity:K,onEditorStateChange:q}){let N=x$(()=>n(X),[X]),U=x$(()=>h$(X),[X]),G=x$(()=>H5(X),[X]),[B,D]=yJ(null),[F,H]=yJ(null),b=d$(null),E=d$(null),V=d$(null);TJ(()=>{let z=sU(X,Q.get(),N);D((y)=>eU(y,z)?y:z)},[X,Q,N.end.offset,N.end.regionId,N.start.offset,N.start.regionId]),TJ(()=>{let z=oU({canShowSelectionLeaf:M,currentLeaf:F,activeMarks:G,handles:B,selectionRange:U,threads:Z});H((y)=>tU(y,z)?y:z)},[G,M,B,F,U,Z]);let R=c$((z,y=!0)=>{H((T)=>T?.kind==="create"?{animateInitialComment:y,kind:"thread",left:T.left,threadIndex:z,top:T.top}:T)}),O=c$((z)=>{if(z&&V.current===z.pointerId&&z.currentTarget.hasPointerCapture(z.pointerId))z.currentTarget.releasePointerCapture(z.pointerId);b.current=null,E.current=null,V.current=null}),j=c$((z)=>{let y=Y.current,T=A.current,W=E.current;if(!y||!T||!W||V.current!==z.pointerId)return;let _=J6(z,y),C=R2(T,Q.get(),_,W);if(!C)return;z.preventDefault(),z.stopPropagation(),K(),$(z),q(K1(T,{anchor:W,focus:C}))}),f=(z)=>({onPointerCancel:(y)=>{O(y)},onPointerDown:(y)=>{let T=A.current??X,W=MG(N,z),_=z==="start"?N.start:N.end;if(!B)return;y.preventDefault(),y.stopPropagation(),V.current=y.pointerId,E.current=W,b.current=z,y.currentTarget.setPointerCapture(y.pointerId),K(),J.current?.focus({preventScroll:!0}),q(K1(T,{anchor:W,focus:_}))},onPointerMove:(y)=>{if(b.current!==z)return;j(y)},onPointerUp:(y)=>{if(b.current===z)j(y);O(y)}});return{endHandleProps:f("end"),handles:B,leaf:F,promoteLeafToThread:R,startHandleProps:f("start")}}function sU($,M,J){if(H8($.selection))return null;let Z=M0($,M,J.start),X=M0($,M,J.end);if(!Z||!X)return null;return{end:{left:X.left,top:X.top+X.height},start:{left:Z.left,top:Z.top}}}function iU($,M,J){return{activeMarks:J,kind:"create",left:M.start.left,selection:$,top:M.end.top}}function oU({activeMarks:$,canShowSelectionLeaf:M,currentLeaf:J,handles:Z,selectionRange:X,threads:A}){if(!M||!X||!Z)return null;if(J?.kind==="thread")return A[J.threadIndex]?J:null;return iU(X,Z,$)}function nU($,M){return $?.kind==="create"&&$.left===M.left&&$.selection.regionId===M.selection.regionId&&$.selection.startOffset===M.selection.startOffset&&$.selection.endOffset===M.selection.endOffset&&$G($.activeMarks,M.activeMarks)&&$.top===M.top}function tU($,M){if($===M)return!0;if(!$||!M||$.kind!==M.kind)return!1;if($.kind==="create"&&M.kind==="create")return nU($,M);return $.kind==="thread"&&M.kind==="thread"&&$.animateInitialComment===M.animateInitialComment&&$.left===M.left&&$.threadIndex===M.threadIndex&&$.top===M.top}function eU($,M){if($===M)return!0;if(!$||!M)return!1;return $.start.left===M.start.left&&$.start.top===M.start.top&&$.end.left===M.end.left&&$.end.top===M.end.top}function $G($,M){return $.length===M.length&&$.every((J,Z)=>J===M[Z])}function MG($,M){return M==="start"?$.end:$.start}import{useEffect as JG,useMemo as bJ,useState as ZG}from"react";var f4={activeBlockBackground:"#fff1c7",activeBlockFlash:"rgba(245, 158, 11, 0.28)",background:"#fcfbf7",blockquoteRule:"rgba(14, 116, 144, 0.2)",blockquoteRuleActive:"rgba(124, 45, 18, 0.36)",blockquoteText:"#334155",caret:"#111827",checkboxCheckmark:"#f8fafc",checkboxCheckedFill:"#0f766e",checkboxCheckedStroke:"#0f766e",checkboxUncheckedFill:"#fcfffe",checkboxUncheckedStroke:"#64748b",codeBackground:"#0f172a",codeText:"#e2e8f0",commentHighlight:"#d7e3fc",commentHighlightActive:"#f4d35e",commentHighlightResolved:"#cfe9d8",commentHighlightResolvedActive:"#8dc4a0",headingRule:"rgba(15, 23, 42, 0.18)",headingText:"#0f172a",imageLoadingOverlay:"rgba(255, 255, 255, 0.42)",imagePlaceholderIcon:"rgba(14, 116, 144, 0.42)",imagePlaceholderText:"rgba(15, 23, 42, 0.58)",imageSurfaceBackground:"rgba(240, 249, 255, 0.98)",imageSurfaceBorder:"rgba(14, 116, 144, 0.22)",inlineCodeBackground:"rgba(15, 23, 42, 0.08)",inlineCodeText:"#7c2d12",insertHighlightText:"#2563eb",leafAccent:"#1d4ed8",leafBackground:"#fcfbf7",leafBorder:"rgba(148, 163, 184, 0.55)",leafButtonBackground:"rgba(15, 23, 42, 0.08)",leafButtonBorder:"rgba(148, 163, 184, 0.55)",leafButtonText:"#1f2937",leafResolvedBackground:"#cfe9d8",leafResolvedBorder:"#8dc4a0",leafSecondaryText:"#334155",leafShadow:"0 14px 40px rgba(15, 23, 42, 0.16)",leafText:"#1f2937",linkText:"#1d4ed8",listMarkerText:"#1f2937",paddingX:16,paddingY:12,paragraphText:"#1f2937",selectionBackground:"rgba(125, 211, 252, 0.35)",selectionHandleBackground:"#fcfbf7",selectionHandleBorder:"#1d4ed8",tableBodyBackground:"rgba(248, 250, 252, 0.98)",tableBorder:"rgba(148, 163, 184, 0.55)",tableHeaderBackground:"rgba(226, 232, 240, 0.95)"},u4={activeBlockBackground:"rgba(125, 211, 252, 0.12)",activeBlockFlash:"rgba(226, 232, 240, 0.12)",background:"#0b1220",blockquoteRule:"rgba(103, 232, 249, 0.34)",blockquoteRuleActive:"rgba(125, 211, 252, 0.5)",blockquoteText:"#cbd5e1",caret:"#f8fafc",checkboxCheckmark:"#082f49",checkboxCheckedFill:"#67e8f9",checkboxCheckedStroke:"#67e8f9",checkboxUncheckedFill:"#0f172a",checkboxUncheckedStroke:"#64748b",codeBackground:"#020617",codeText:"#dbeafe",commentHighlight:"rgba(96, 165, 250, 0.34)",commentHighlightActive:"#facc15",commentHighlightResolved:"rgba(74, 222, 128, 0.24)",commentHighlightResolvedActive:"#4ade80",headingRule:"rgba(226, 232, 240, 0.22)",headingText:"#f8fafc",imageLoadingOverlay:"rgba(186, 230, 253, 0.18)",imagePlaceholderIcon:"rgba(125, 211, 252, 0.44)",imagePlaceholderText:"rgba(226, 232, 240, 0.62)",imageSurfaceBackground:"rgba(15, 23, 42, 0.92)",imageSurfaceBorder:"rgba(56, 189, 248, 0.28)",inlineCodeBackground:"rgba(148, 163, 184, 0.16)",inlineCodeText:"#fdba74",insertHighlightText:"#60a5fa",leafAccent:"#93c5fd",leafBackground:"#0b1220",leafBorder:"rgba(100, 116, 139, 0.7)",leafButtonBackground:"rgba(148, 163, 184, 0.16)",leafButtonBorder:"rgba(100, 116, 139, 0.7)",leafButtonText:"#dbe4f0",leafResolvedBackground:"rgba(74, 222, 128, 0.24)",leafResolvedBorder:"#4ade80",leafSecondaryText:"#cbd5e1",leafShadow:"0 18px 44px rgba(2, 6, 23, 0.42), 0 0 0 1px rgba(148, 163, 184, 0.06)",leafText:"#dbe4f0",linkText:"#93c5fd",listMarkerText:"#e2e8f0",paddingX:16,paddingY:12,paragraphText:"#dbe4f0",selectionBackground:"rgba(56, 189, 248, 0.28)",selectionHandleBackground:"#0b1220",selectionHandleBorder:"#93c5fd",tableBodyBackground:"rgba(15, 23, 42, 0.9)",tableBorder:"rgba(100, 116, 139, 0.7)",tableHeaderBackground:"rgba(30, 41, 59, 0.96)"},zJ={...f4,activeBlockBackground:"rgba(16, 185, 129, 0.14)",activeBlockFlash:"rgba(16, 185, 129, 0.26)",background:"#f3fbf6",blockquoteRule:"rgba(5, 150, 105, 0.22)",blockquoteRuleActive:"rgba(6, 95, 70, 0.38)",blockquoteText:"#166534",caret:"#14532d",codeBackground:"#052e16",codeText:"#dcfce7",commentHighlight:"rgba(52, 211, 153, 0.26)",commentHighlightActive:"#10b981",commentHighlightResolved:"rgba(187, 247, 208, 0.96)",commentHighlightResolvedActive:"#059669",headingRule:"rgba(20, 83, 45, 0.18)",headingText:"#14532d",inlineCodeBackground:"rgba(20, 83, 45, 0.08)",inlineCodeText:"#166534",insertHighlightText:"#10b981",leafAccent:"#059669",leafBackground:"#f3fbf6",leafBorder:"rgba(22, 163, 74, 0.24)",leafButtonBackground:"rgba(20, 83, 45, 0.08)",leafButtonBorder:"rgba(22, 163, 74, 0.28)",leafButtonText:"#14532d",leafResolvedBackground:"#d1fae5",leafResolvedBorder:"#10b981",leafSecondaryText:"#166534",leafShadow:"0 14px 40px rgba(20, 83, 45, 0.14)",leafText:"#14532d",linkText:"#047857",paragraphText:"#14532d",selectionBackground:"rgba(52, 211, 153, 0.24)",selectionHandleBackground:"#f3fbf6",selectionHandleBorder:"#059669",tableBodyBackground:"rgba(243, 251, 246, 0.96)",tableBorder:"rgba(22, 163, 74, 0.24)",tableHeaderBackground:"rgba(220, 252, 231, 0.96)"},OJ={...u4,activeBlockBackground:"rgba(168, 85, 247, 0.16)",activeBlockFlash:"rgba(243, 232, 255, 0.13)",blockquoteRule:"rgba(196, 181, 253, 0.34)",blockquoteRuleActive:"rgba(216, 180, 254, 0.44)",caret:"#f5f3ff",codeBackground:"#1e1b4b",codeText:"#ede9fe",commentHighlight:"rgba(167, 139, 250, 0.28)",commentHighlightActive:"#c084fc",commentHighlightResolved:"rgba(45, 212, 191, 0.22)",commentHighlightResolvedActive:"#2dd4bf",headingRule:"rgba(233, 213, 255, 0.24)",headingText:"#f5f3ff",inlineCodeBackground:"rgba(196, 181, 253, 0.16)",inlineCodeText:"#f9a8d4",insertHighlightText:"#c084fc",leafAccent:"#d8b4fe",leafBackground:"#12091f",leafBorder:"rgba(139, 92, 246, 0.34)",leafButtonBackground:"rgba(196, 181, 253, 0.16)",leafButtonBorder:"rgba(139, 92, 246, 0.34)",leafButtonText:"#ede9fe",leafResolvedBackground:"rgba(45, 212, 191, 0.22)",leafResolvedBorder:"#2dd4bf",leafSecondaryText:"#ddd6fe",leafShadow:"0 20px 48px rgba(2, 6, 23, 0.48), 0 0 0 1px rgba(196, 181, 253, 0.08)",leafText:"#f5f3ff",linkText:"#d8b4fe",listMarkerText:"#ede9fe",paragraphText:"#ede9fe",selectionBackground:"rgba(167, 139, 250, 0.26)",selectionHandleBackground:"#12091f",selectionHandleBorder:"#d8b4fe",tableBodyBackground:"rgba(30, 27, 75, 0.88)",tableBorder:"rgba(139, 92, 246, 0.34)",tableHeaderBackground:"rgba(49, 46, 129, 0.94)"};function CJ($){let M=bJ(()=>AG($),[$]),[J,Z]=ZG(M.light),X=bJ(()=>YG(J),[J]);return JG(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function"){Z(M.light);return}let A=window.matchMedia("(prefers-color-scheme: dark)"),Y=()=>{Z(A.matches?M.dark:M.light)};if(Y(),typeof A.addEventListener==="function")return A.addEventListener("change",Y),()=>{A.removeEventListener("change",Y)};return A.addListener(Y),()=>{A.removeListener(Y)}},[M]),{theme:J,themeStyles:X}}function XG($){return"light"in $&&"dark"in $}function AG($){if(!$)return{dark:u4,light:f4};if(XG($))return $;return{dark:$,light:$}}function YG($){return{"--documint-leaf-button-bg":$.leafButtonBackground,"--documint-leaf-button-border":$.leafButtonBorder,"--documint-leaf-button-text":$.leafButtonText,"--documint-leaf-accent":$.leafAccent,"--documint-leaf-bg":$.leafBackground,"--documint-leaf-border":$.leafBorder,"--documint-leaf-font-family":'"Avenir Next", "Segoe UI", sans-serif',"--documint-leaf-shadow":$.leafShadow??void 0,"--documint-leaf-secondary-text":$.leafSecondaryText,"--documint-leaf-resolved-bg":$.leafResolvedBackground,"--documint-leaf-resolved-border":$.leafResolvedBorder,"--documint-leaf-text":$.leafText,"--documint-selection-handle-bg":$.selectionHandleBackground,"--documint-selection-handle-border":$.selectionHandleBorder}}import{useEffect as qG,useEffectEvent as L0,useRef as a$,useState as Z6}from"react";import{useMemo as QG}from"react";function EJ($){return QG(()=>KG({current:null},$),[$])}function KG($,M){return{get current(){return $.current},get(){let J=$.current;if(J!==null)return J;let Z=M();return $.current=Z,Z},invalidate(){$.current=null}}}function wJ({editorState:$,editorStateRef:M,renderResources:J,theme:Z}){let X=a$(z0()),A=a$(null),Y=a$({height:240,top:0}),[Q,K]=Z6(0),[q,N]=Z6(240),[U,G]=Z6(0),[B,D]=Z6(240),F=NG(Q),H=L0(()=>{let y=M.current??$,T=Y.current;return n6(y,{height:T.height,paddingX:Z.paddingX,paddingY:Z.paddingY,top:T.top,width:F},X.current,J)}),b=EJ(H),E=L0((y)=>{D((T)=>{let W=GG(y,Y.current.height);return T===W?T:W})}),V=L0((y)=>{let T=UG(y);Y.current=T,G((W)=>W===T.top?W:T.top)}),R=L0((y)=>{Y.current={...Y.current,top:y},G((T)=>T===y?T:y),b.invalidate()}),O=L0((y)=>{let T=A.current;if(!T)return R(y),y;T.scrollTop=y;let W=T.scrollTop;return R(W),W}),j=L0(()=>{return A.current?.scrollTop??Y.current.top}),f=L0((y)=>{let T=A.current;return T?J6(y,T):null}),z=(y)=>({onScroll:(T)=>{V(T.currentTarget),y?.onScroll?.(T)},ref:A});return qG(()=>{let y=A.current;if(!y||typeof ResizeObserver>"u")return;let T=new ResizeObserver((W)=>{let _=W[0];if(!_)return;let C=Math.max(0,Math.floor(_.contentRect.width)),g=jJ(y);Y.current={...Y.current,height:g},K((u)=>u===C?u:C),N((u)=>u===g?u:g)});return T.observe(y),()=>{T.disconnect()}},[A]),{actions:{getScrollTop:j,observePreparedViewport:E,observeScrollContainer:V,resolvePointerPoint:f,scrollTo:O},props:{getScrollContainer:z,scrollContent:{style:{height:`${B}px`}}},refs:{scrollContainer:A},state:{layoutWidth:F,preparedViewport:b,scrollContentHeight:B,surfaceWidth:Q,viewportHeight:q,viewportTop:U}}}function NG($){return Math.max(240,Math.floor($||480))}function jJ($){return Math.max(240,$.clientHeight)}function UG($){return{height:jJ($),top:$.scrollTop}}function GG($,M){return Math.max(M,Math.ceil($.totalHeight+24))}function BG(){if(typeof window>"u")return 1;return Math.max(1,window.devicePixelRatio||1)}function s$($,{paintHeight:M,paintTop:J,width:Z}){if(!$)return null;let X=Math.max(240,Math.ceil(M)),A=BG();$.width=Math.ceil(Z*A),$.height=Math.ceil(X*A),$.style.width=`${Z}px`,$.style.height=`${X}px`,$.style.transform=`translateY(${J}px)`;let Y=$.getContext("2d");if(!Y)return null;return{context:Y,devicePixelRatio:A,height:X,width:Z}}function i$($,M){return $.activeBlockType===M.activeBlockType&&$.activeCommentThreadIndex===M.activeCommentThreadIndex&&$.activeSpanKind===M.activeSpanKind&&$.canonicalContent===M.canonicalContent&&$.characterCount===M.characterCount&&$.commentThreadCount===M.commentThreadCount&&$.layoutWidth===M.layoutWidth&&$.resolvedCommentCount===M.resolvedCommentCount&&$.selectionFrom===M.selectionFrom&&$.selectionTo===M.selectionTo}var RJ=24;function fJ($,M){if(!$)return LJ(M);let J=DG($,M)??HG($,M);return J?FG(J):LJ(M)}function FG($){return{didReconcile:!0,state:$}}function LJ($){return{didReconcile:!1,state:$}}function DG($,M){let J=_G($,M);return J?K1(M,J,!1):null}function _G($,M){if(e$($.selection.anchor,$.selection.focus)){let A=o$($,M,$.selection.focus,"neutral");return A?{anchor:A,focus:A}:null}let J=EG($),Z=o$($,M,$.selection.anchor,J.anchor),X=o$($,M,$.selection.focus,J.focus);return Z&&X?{anchor:Z,focus:X}:null}function o$($,M,J,Z){let X=$.documentIndex.regionIndex.get(J.regionId);if(!X)return null;let A=t$(X,M);if(!A)return null;return{offset:zG(X.text,A.text,J.offset,Z),regionId:A.id}}function t$($,M){let J=M.documentIndex.regionIndex.get($.id);if(J)return J;if($.text.length===0)return null;let Z=VG($,M);if(Z)return Z;let X=M.documentIndex.regionPathIndex.get($.path);if(X)return X;return null}function HG($,M){if(!e$($.selection.anchor,$.selection.focus))return null;let J=PG($);if(!J)return null;let Z=TG($,M,J);if(Z===null)return null;return WG(M,Z)}function PG($){let M=$.documentIndex.regionIndex.get($.selection.focus.regionId);if(!M||M.blockType!=="paragraph"||M.text.length>0)return null;return $.documentIndex.blockIndex.get(M.blockId)?.parentBlockId===null?M:null}function WG($,M){let J=I0($.documentIndex.document,M,0,[I({text:""})]),Z={...$,documentIndex:$2($.documentIndex,J,M,0)},X=v2(Z.documentIndex,M1(M));return X?K1(Z,X,!1):null}function TG($,M,J){let Z=kJ($,J.rootIndex,"before"),X=kJ($,J.rootIndex,"after"),A=Z?t$(Z,M):null,Y=X?t$(X,M):null;if(A&&Y)return A.rootIndex<Y.rootIndex?Y.rootIndex:null;if(A)return A.rootIndex+1;if(Y)return Y.rootIndex;return null}function kJ($,M,J){let Z=J==="before"?-1:1;for(let X=M+Z;X>=0&&X<$.documentIndex.roots.length;X+=Z){let A=yG($,X,J);if(!A)continue;return A}return null}function yG($,M,J){let Z=$.documentIndex.roots[M]?.regions??[],X=J==="before"?Z.length-1:0,A=J==="before"?-1:1;for(let Y=X;Y>=0&&Y<Z.length;Y+=A){let Q=Z[Y];if(Q&&Q.text.length>0)return Q}return null}function VG($,M){let J=null;for(let Z of M.documentIndex.regions){if(Z.blockType!==$.blockType||Z.text!==$.text)continue;if(J)return null;J=Z}return J}function zG($,M,J,Z){let X=n$(J,0,$.length),A=$.slice(Math.max(0,X-RJ),X),Y=$.slice(X,Math.min($.length,X+RJ)),Q=OG(M,A,Y);if(Q!==null)return Q;let K=bG(M,A),q=CG(M,Y);if(Z==="before-suffix")return q??K??n$(J,0,M.length);return K??q??n$(J,0,M.length)}function OG($,M,J){if(M.length===0||J.length===0)return null;let Z=null,X=0;while(X<=$.length){let A=$.indexOf(M,X);if(A===-1)break;let Y=A+M.length;if($.startsWith(J,Y)){if(Z!==null)return null;Z=Y}X=A+Math.max(1,M.length)}return Z}function bG($,M){if(M.length===0)return null;let J=uJ($,M);return J===null?null:J+M.length}function CG($,M){return M.length===0?null:uJ($,M)}function uJ($,M){let J=null,Z=0;while(Z<=$.length){let X=$.indexOf(M,Z);if(X===-1)break;if(J!==null)return null;J=X,Z=X+Math.max(1,M.length)}return J}function EG($){let{anchor:M,focus:J}=$.selection;if(e$(M,J))return{anchor:"neutral",focus:"neutral"};return wG($,M,J)<=0?{anchor:"before-suffix",focus:"after-prefix"}:{anchor:"after-prefix",focus:"before-suffix"}}function wG($,M,J){let Z=$.documentIndex.regionOrderIndex.get(M.regionId),X=$.documentIndex.regionOrderIndex.get(J.regionId);if(Z===void 0||X===void 0)return 0;return Z===X?M.offset-J.offset:Z-X}function e$($,M){return $.regionId===M.regionId&&$.offset===M.offset}function n$($,M,J){return Math.max(M,Math.min($,J))}import{jsxDEV as l,Fragment as mG}from"react/jsx-dev-runtime";function A6({blocks:$}){return l(mG,{children:$.map((M)=>jG(M))},void 0,!1,void 0,this)}function jG($){switch($.type){case"blockquote":return l("blockquote",{className:"preview-block preview-block-blockquote",children:l(A6,{blocks:$.children},void 0,!1,void 0,this)},$.id,!1,void 0,this);case"code":return l("div",{className:"preview-block preview-block-code",children:[l("div",{className:"preview-rich-header",children:kG($.language,$.meta)},void 0,!1,void 0,this),l("pre",{children:l("code",{children:$.source||" "},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},$.id,!0,void 0,this);case"heading":{let M=`h${$.depth}`;return l(M,{className:"preview-block preview-block-heading",children:X6($.children)},$.id,!1,void 0,this)}case"list":return $.ordered?l("ol",{className:"preview-block preview-block-list",start:$.start??1,children:$.items.map((M)=>$M(M))},$.id,!1,void 0,this):l("ul",{className:"preview-block preview-block-list",children:$.items.map((M)=>$M(M))},$.id,!1,void 0,this);case"listItem":return $M($);case"paragraph":return l("p",{className:"preview-block preview-block-paragraph",children:X6($.children)},$.id,!1,void 0,this);case"table":return l("div",{className:"preview-block preview-block-table",children:[l("div",{className:"preview-rich-header",children:fG($.rows.length,$.rows[0]?.cells.length??0,$.align.filter((M)=>M!==null).length)},void 0,!1,void 0,this),l("div",{className:"preview-table-scroll",children:l("table",{children:l("tbody",{children:$.rows.map((M)=>l("tr",{children:M.cells.map((J)=>l("td",{children:X6(J.children)},J.id,!1,void 0,this))},M.id,!1,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},$.id,!0,void 0,this);case"thematicBreak":return l("hr",{className:"preview-block preview-block-rule"},$.id,!1,void 0,this);case"directive":return l("pre",{className:`preview-block preview-block-directive preview-block-directive-${$.name}`,children:$.body},$.id,!1,void 0,this);case"unsupported":return l("pre",{className:"preview-block preview-block-unsupported",children:$.source},$.id,!1,void 0,this)}}function $M($){return l("li",{className:"preview-block preview-block-list-item",children:l(A6,{blocks:$.children},void 0,!1,void 0,this)},$.id,!1,void 0,this)}function X6($){return $.map((M)=>{switch(M.type){case"break":return l("br",{},M.id,!1,void 0,this);case"image":return l("span",{className:"preview-inline preview-inline-image",children:[l("img",{alt:M.alt??"",src:M.url,title:M.title??""},void 0,!1,void 0,this),l("span",{children:[l("strong",{children:uG(M.alt)},void 0,!1,void 0,this),l("small",{children:SG(M.url,M.title)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},M.id,!0,void 0,this);case"inlineCode":return l("code",{className:"preview-inline preview-inline-code",children:M.code},M.id,!1,void 0,this);case"link":return RG(M);case"text":return l("span",{className:"preview-inline",children:LG(M.text,M.marks)},M.id,!1,void 0,this);case"unsupported":return l("span",{className:"preview-inline preview-inline-unsupported",children:M.source},M.id,!1,void 0,this)}})}function RG($){return l("a",{className:"preview-inline preview-inline-link",href:$.url,children:X6($.children)},$.id,!1,void 0,this)}function LG($,M){let J=$;for(let Z of M)switch(Z){case"strikethrough":J=l("del",{children:J},void 0,!1,void 0,this);break;case"italic":J=l("em",{children:J},void 0,!1,void 0,this);break;case"bold":J=l("strong",{children:J},void 0,!1,void 0,this);break;case"underline":J=l("ins",{children:J},void 0,!1,void 0,this);break}return J}function kG($,M){return[$??"plain text",M].filter(Boolean).join(" • ")}function fG($,M,J){let Z=J>0?`${J} aligned ${J===1?"column":"columns"}`:"no alignment";return`${$} ${$===1?"row":"rows"} • ${M} ${M===1?"column":"columns"} • ${Z}`}function uG($){return $?.trim()?$:"Untitled image"}function SG($,M){return M?.trim()?`${M} • ${$}`:$}var SJ=`
32
- :where(.documint-leaf-toolbar) {
33
- --documint-leaf-toolbar-button-active-bg:
34
- color-mix(in srgb, var(--documint-leaf-accent) 16%, var(--documint-leaf-bg));
35
- --documint-leaf-toolbar-divider-color:
36
- color-mix(in srgb, var(--documint-leaf-border) 72%, transparent);
37
- --documint-leaf-toolbar-menu-border-color:
38
- color-mix(in srgb, var(--documint-leaf-border) 88%, transparent);
39
- --documint-leaf-toolbar-menu-hover-bg:
40
- color-mix(in srgb, var(--documint-leaf-accent) 12%, var(--documint-leaf-bg));
41
- --documint-leaf-toolbar-shadow-fallback:
42
- 0 14px 40px color-mix(in srgb, var(--documint-leaf-text) 16%, transparent);
43
- display: inline-flex;
44
- align-items: center;
45
- gap: 0.52rem;
46
- }
47
-
48
- :where(.documint-leaf-toolbar-group) {
49
- display: inline-flex;
50
- align-items: center;
51
- gap: 0.38rem;
52
- }
53
-
54
- :where(.documint-leaf-toolbar-divider) {
55
- width: 1px;
56
- height: 1.15rem;
57
- background: var(--documint-leaf-toolbar-divider-color);
58
- }
59
-
60
- :where(.documint-leaf-toolbar-button),
61
- :where(.documint-leaf-toolbar-menu-item) {
62
- appearance: none;
63
- display: inline-flex;
64
- align-items: center;
65
- gap: 0.36rem;
66
- border: 0;
67
- background: transparent;
68
- color: var(--documint-leaf-button-text);
69
- cursor: pointer;
70
- font: inherit;
71
- }
72
-
73
- :where(.documint-leaf-toolbar-button) {
74
- justify-content: center;
75
- min-width: 1.45rem;
76
- height: 1.45rem;
77
- padding: 0 0.12rem;
78
- border-radius: 0.38rem;
79
- line-height: 0;
80
- transition:
81
- background-color 120ms ease,
82
- color 120ms ease;
83
- }
84
-
85
- :where(.documint-leaf-toolbar-menu-shell .documint-leaf-toolbar-button) {
86
- gap: 0.18rem;
87
- }
88
-
89
- :where(.documint-leaf-toolbar-button:hover) {
90
- background: var(--documint-leaf-toolbar-button-active-bg);
91
- }
92
-
93
- :where(.documint-leaf-toolbar-button:disabled) {
94
- opacity: 0.42;
95
- cursor: default;
96
- }
97
-
98
- :where(.documint-leaf-toolbar-button:disabled:hover) {
99
- background: transparent;
100
- }
101
-
102
- :where(.documint-leaf-toolbar-button.active) {
103
- background: var(--documint-leaf-toolbar-button-active-bg);
104
- color: var(--documint-leaf-text);
105
- }
106
-
107
- :where(.documint-leaf-toolbar-menu-shell) {
108
- position: relative;
109
- }
110
-
111
- :where(.documint-leaf-toolbar-menu-chevron) {
112
- transition: transform 140ms ease;
113
- }
114
-
115
- :where(.documint-leaf-toolbar-menu-chevron.is-open) {
116
- transform: rotate(180deg);
117
- }
118
-
119
- :where(.documint-leaf-toolbar-menu) {
120
- position: absolute;
121
- top: calc(100% + 0.55rem);
122
- left: 0;
123
- display: grid;
124
- gap: 0.2rem;
125
- min-width: 10.5rem;
126
- padding: 0.35rem;
127
- border: 1px solid var(--documint-leaf-toolbar-menu-border-color);
128
- border-radius: 0.8rem;
129
- background: var(--documint-leaf-bg);
130
- box-shadow: var(--documint-leaf-shadow, var(--documint-leaf-toolbar-shadow-fallback));
131
- }
132
-
133
- :where(.documint-leaf-toolbar-menu-item) {
134
- width: 100%;
135
- padding: 0.45rem 0.55rem;
136
- border-radius: 0.55rem;
137
- line-height: 1.2;
138
- text-align: left;
139
- }
140
-
141
- :where(.documint-leaf-toolbar-menu-item:hover) {
142
- background: var(--documint-leaf-toolbar-menu-hover-bg);
143
- }
144
-
145
- :where(.documint-leaf-toolbar-menu-item:disabled) {
146
- opacity: 0.42;
147
- cursor: default;
148
- }
149
-
150
- :where(.documint-leaf-toolbar-menu-item:disabled:hover) {
151
- background: transparent;
152
- }
153
-
154
- :where(.documint-leaf-toolbar-menu-divider) {
155
- height: 1px;
156
- margin: 0.15rem 0.2rem;
157
- background: var(--documint-leaf-toolbar-divider-color);
158
- }
159
- `;var mJ=`
160
- :where(.documint-leaf-shell) {
161
- --documint-leaf-divider-color:
162
- color-mix(in srgb, var(--documint-leaf-border) 60%, transparent);
163
- --documint-leaf-shadow-fallback:
164
- 0 14px 40px color-mix(in srgb, var(--documint-leaf-text) 16%, transparent);
165
- padding: 0.8rem;
166
- border: 1px solid var(--documint-leaf-border);
167
- border-radius: 0.95rem;
168
- background: var(--documint-leaf-bg);
169
- box-shadow: var(--documint-leaf-shadow, var(--documint-leaf-shadow-fallback));
170
- color: var(--documint-leaf-text);
171
- font-family: var(--documint-leaf-font-family, "Avenir Next", "Segoe UI", sans-serif);
172
- font-size: 0.84rem;
173
- line-height: 1.45;
174
- pointer-events: auto;
175
- }
176
-
177
- :where(.documint-leaf-shell:has(> .documint-leaf-toolbar)),
178
- :where(.documint-leaf-shell:has(> .documint-comment-leaf-create)) {
179
- width: auto;
180
- padding: 0.38rem 0.58rem;
181
- }
182
-
183
- :where(.documint-leaf-shell:has(> .documint-comment-leaf-create.is-expanded)) {
184
- padding: 0.8rem;
185
- }
186
-
187
- :where(.documint-leaf-shell[data-status="resolved"]) {
188
- border-color: var(--documint-leaf-resolved-border);
189
- background: var(--documint-leaf-resolved-bg);
190
- }
191
-
192
- :where(.documint-leaf-shell p) {
193
- margin: 0;
194
- }
195
-
196
- :where(.documint-comment-leaf:not(.documint-comment-leaf-create)),
197
- :where(.documint-comment-leaf-create.is-expanded) {
198
- width: var(--documint-leaf-width, min(18rem, calc(100vw - 4rem)));
199
- }
200
-
201
- :where(.documint-link-leaf) {
202
- width: min(16rem, calc(100vw - 4rem));
203
- }
204
-
205
- ${SJ}
206
-
207
- :where(.documint-leaf-anchor) {
208
- --documint-leaf-anchor-bridge-height: 12px;
209
- position: fixed;
210
- z-index: 1000;
211
- padding-top: var(--documint-leaf-anchor-bridge-height);
212
- margin-top: calc(var(--documint-leaf-anchor-bridge-height) * -1);
213
- pointer-events: auto;
214
- }
215
-
216
- :where(.documint-leaf-anchor[data-selection="true"]) {
217
- --documint-leaf-anchor-bridge-height: 0px;
218
- padding-top: 0;
219
- margin-top: 14px;
220
- pointer-events: none;
221
- }
222
-
223
- :where(.documint-leaf-bridge) {
224
- width: 100%;
225
- height: var(--documint-leaf-anchor-bridge-height);
226
- }
227
-
228
- :where(.documint-link-leaf) {
229
- display: grid;
230
- gap: 0.3rem;
231
- min-width: 0;
232
- }
233
-
234
- :where(.documint-link-leaf-row) {
235
- display: grid;
236
- grid-template-columns: minmax(0, 1fr) auto;
237
- align-items: flex-start;
238
- gap: 0.6rem;
239
- }
240
-
241
- :where(.documint-link-leaf-row.is-editing) {
242
- grid-template-columns: minmax(0, 1fr);
243
- }
244
-
245
- :where(.documint-link-leaf-actions) {
246
- display: inline-flex;
247
- align-items: center;
248
- gap: 0.5rem;
249
- }
250
-
251
- :where(.documint-link-leaf-divider) {
252
- margin: 0.2rem 0;
253
- border-top: 1px solid var(--documint-leaf-divider-color);
254
- }
255
-
256
- :where(.documint-link-leaf-hint) {
257
- color: var(--documint-leaf-secondary-text);
258
- font-size: 0.74rem;
259
- font-style: italic;
260
- }
261
-
262
- :where(.documint-link-leaf-title) {
263
- color: var(--documint-leaf-text);
264
- font-size: 0.78rem;
265
- font-weight: 600;
266
- }
267
-
268
- :where(.documint-link-leaf-url) {
269
- min-width: 0;
270
- color: var(--documint-leaf-secondary-text);
271
- font-size: 0.76rem;
272
- line-height: 1.4;
273
- overflow-wrap: anywhere;
274
- }
275
-
276
- :where(.documint-link-leaf-input) {
277
- min-height: auto;
278
- padding-right: 0.75rem;
279
- padding-bottom: 2.1rem;
280
- overflow-wrap: anywhere;
281
- }
282
-
283
- :where(.documint-comment-leaf-header),
284
- :where(.documint-comment-leaf-actions),
285
- :where(.documint-comment-message-meta) {
286
- display: flex;
287
- align-items: center;
288
- justify-content: space-between;
289
- gap: 0.5rem;
290
- }
291
-
292
- :where(.documint-comment-leaf-header) {
293
- margin-bottom: 0.7rem;
294
- }
295
-
296
- :where(.documint-comment-leaf-link) {
297
- display: grid;
298
- gap: 0.3rem;
299
- margin-bottom: 0.8rem;
300
- padding-bottom: 0.8rem;
301
- border-bottom: 1px solid var(--documint-leaf-divider-color);
302
- }
303
-
304
- :where(.documint-comment-leaf-create) {
305
- --documint-comment-create-scale-duration: 180ms;
306
- --documint-comment-create-fade-duration: 120ms;
307
- height: auto;
308
- padding: 0;
309
- overflow: visible;
310
- }
311
-
312
- :where(.documint-comment-leaf-create-shell) {
313
- position: relative;
314
- display: grid;
315
- width: max-content;
316
- height: 100%;
317
- }
318
-
319
- :where(.documint-comment-leaf-create-shell > .documint-leaf-toolbar) {
320
- position: relative;
321
- z-index: 0;
322
- }
323
-
324
- :where(.documint-comment-leaf-create.is-expanded .documint-comment-leaf-create-shell) {
325
- width: 100%;
326
- min-height: 5.5rem;
327
- }
328
-
329
- :where(.documint-comment-leaf-create.is-expanded .documint-comment-leaf-create-shell > .documint-leaf-toolbar) {
330
- position: absolute;
331
- inset: 0;
332
- pointer-events: none;
333
- z-index: 1;
334
- }
335
-
336
- :where(.documint-comment-leaf-create-button) {
337
- width: 1.7rem;
338
- height: 1.7rem;
339
- padding: 0;
340
- line-height: 0;
341
- position: relative;
342
- z-index: 0;
343
- display: inline-flex;
344
- opacity: 1;
345
- transform: scale(1);
346
- transition:
347
- opacity var(--documint-comment-create-fade-duration) ease,
348
- transform var(--documint-comment-create-scale-duration) ease;
349
- }
350
-
351
- :where(.documint-comment-leaf-create-divider) {
352
- opacity: 1;
353
- transition: opacity var(--documint-comment-create-fade-duration) ease;
354
- }
355
-
356
- :where(.documint-comment-leaf-create-mark) {
357
- opacity: 1;
358
- transition:
359
- opacity var(--documint-comment-create-fade-duration) ease,
360
- transform var(--documint-comment-create-scale-duration) ease;
361
- }
362
-
363
- :where(.documint-comment-leaf-create.is-expanded .documint-comment-leaf-create-button),
364
- :where(.documint-comment-leaf-create.is-expanded .documint-comment-leaf-create-mark) {
365
- opacity: 0;
366
- transform: scale(0.72);
367
- pointer-events: none;
368
- }
369
-
370
- :where(.documint-comment-leaf-create.is-expanded .documint-comment-leaf-create-divider) {
371
- opacity: 0;
372
- }
373
-
374
- :where(.documint-comment-leaf-create-content) {
375
- position: absolute;
376
- top: 0;
377
- left: 0;
378
- right: 0;
379
- opacity: 0;
380
- transform: scale(0);
381
- transform-origin: top left;
382
- transition:
383
- opacity var(--documint-comment-create-fade-duration) ease,
384
- transform var(--documint-comment-create-scale-duration) ease;
385
- pointer-events: none;
386
- z-index: 1;
387
- }
388
-
389
- :where(.documint-comment-leaf-create.is-expanded .documint-comment-leaf-create-content) {
390
- position: relative;
391
- opacity: 1;
392
- transform: scale(1);
393
- pointer-events: auto;
394
- z-index: 0;
395
- }
396
-
397
- :where(.documint-comment-leaf-age) {
398
- color: var(--documint-leaf-secondary-text);
399
- font-size: 0.76rem;
400
- }
401
-
402
- :where(.documint-comment-thread) {
403
- display: grid;
404
- gap: 0.75rem;
405
- max-height: 16rem;
406
- margin-bottom: 0.8rem;
407
- overflow: auto;
408
- }
409
-
410
- :where(.documint-comment-thread.is-empty) {
411
- max-height: 0;
412
- margin-bottom: 0;
413
- overflow: hidden;
414
- }
415
-
416
- :where(.documint-comment-message) {
417
- display: grid;
418
- gap: 0.55rem;
419
- padding-bottom: 0.75rem;
420
- border-bottom: 1px solid var(--documint-leaf-divider-color);
421
- }
422
-
423
- :where(.documint-comment-message-root) {
424
- transform: translateY(-8px) scaleY(0);
425
- transform-origin: top left;
426
- opacity: 0;
427
- transition:
428
- opacity 140ms ease,
429
- transform 180ms ease;
430
- }
431
-
432
- :where(.documint-comment-message-root.is-visible) {
433
- transform: translateY(0) scaleY(1);
434
- opacity: 1;
435
- }
436
-
437
- :where(.documint-comment-message-root.is-hidden) {
438
- max-height: 0;
439
- padding-bottom: 0;
440
- border-bottom: 0;
441
- overflow: hidden;
442
- }
443
-
444
- :where(.documint-comment-message:last-child) {
445
- padding-bottom: 0;
446
- border-bottom: 0;
447
- }
448
-
449
- :where(.documint-comment-reply) {
450
- position: relative;
451
- display: block;
452
- padding-top: 0.85rem;
453
- border-top: 1px solid var(--documint-leaf-divider-color);
454
- }
455
-
456
- :where(.documint-comment-reply.is-standalone) {
457
- padding-top: 0;
458
- border-top: 0;
459
- }
460
-
461
- :where(.documint-comment-reply.is-standalone:not(.is-visible)) {
462
- max-height: 0;
463
- overflow: hidden;
464
- }
465
-
466
- :where(.documint-leaf-shell[data-status="resolved"] .documint-comment-reply) {
467
- border-top-color: color-mix(in srgb, var(--documint-leaf-resolved-border) 72%, transparent);
468
- }
469
-
470
- :where(.documint-comment-message-meta span) {
471
- color: var(--documint-leaf-secondary-text);
472
- font-size: 0.74rem;
473
- }
474
-
475
- :where(.documint-comment-actions) {
476
- display: flex;
477
- gap: 0.4rem;
478
- }
479
-
480
- :where(.documint-leaf-action) {
481
- appearance: none;
482
- display: inline-flex;
483
- align-items: center;
484
- justify-content: center;
485
- width: auto;
486
- height: auto;
487
- padding: 0;
488
- border: 0;
489
- border-radius: 0;
490
- background: transparent;
491
- color: var(--documint-leaf-button-text);
492
- cursor: pointer;
493
- font: inherit;
494
- }
495
-
496
- :where(.documint-leaf-action-text) {
497
- padding: 0.35rem 0.62rem;
498
- border: 1px solid var(--documint-leaf-button-border);
499
- border-radius: 999px;
500
- background: var(--documint-leaf-button-bg);
501
- }
502
-
503
- :where(.documint-leaf-action:not(.documint-leaf-action-text)) {
504
- line-height: 0;
505
- }
506
-
507
- :where(.documint-leaf-action:disabled) {
508
- opacity: 0.45;
509
- cursor: default;
510
- }
511
-
512
- :where(.documint-leaf-action-danger) {
513
- color: var(--documint-leaf-accent);
514
- }
515
-
516
- :where(.documint-comment-input) {
517
- box-sizing: border-box;
518
- width: 100%;
519
- min-height: 4.6rem;
520
- padding: 0.65rem 3.2rem 0.75rem 0.75rem;
521
- border: 1px solid var(--documint-leaf-border);
522
- border-radius: 0.75rem;
523
- background: var(--documint-leaf-button-bg);
524
- color: var(--documint-leaf-text);
525
- font: inherit;
526
- resize: none;
527
- }
528
-
529
- :where(.documint-leaf-shell[data-status="resolved"] .documint-comment-input) {
530
- border-color: var(--documint-leaf-resolved-border);
531
- }
532
-
533
- :where(.documint-comment-input::placeholder) {
534
- color: var(--documint-leaf-secondary-text);
535
- }
536
-
537
- :where(.documint-edit-input-field) {
538
- position: relative;
539
- width: 100%;
540
- min-width: 0;
541
- }
542
-
543
- :where(.documint-link-leaf-row > .documint-edit-input-field) {
544
- width: 100%;
545
- }
546
-
547
- :where(.documint-edit-input-cancel) {
548
- position: absolute;
549
- right: 0.7rem;
550
- top: 0.7rem;
551
- }
552
-
553
- :where(.documint-edit-input-save) {
554
- position: absolute;
555
- right: 0.7rem;
556
- bottom: calc(0.7rem + 3px);
557
- }
558
-
559
- :where(.documint-comment-reply-field) {
560
- position: relative;
561
- }
562
-
563
- :where(.documint-comment-reply-submit) {
564
- position: absolute;
565
- right: 0.7rem;
566
- bottom: calc(0.7rem + 3px);
567
- }
568
- `;var vJ=`
569
- :where(.documint) {
12
+ `)}var v8=null,jJ;function RJ(){if(v8===null)v8=new Intl.Segmenter(jJ,{granularity:"word"});return v8}var LJ=/\p{Script=Arabic}/u,X5=/\p{M}/u,p$=/\p{Nd}/u;function h8($){return LJ.test($)}function a0($){for(let M of $){let Z=M.codePointAt(0);if(Z>=19968&&Z<=40959||Z>=13312&&Z<=19903||Z>=131072&&Z<=173791||Z>=173824&&Z<=177983||Z>=177984&&Z<=178207||Z>=178208&&Z<=183983||Z>=183984&&Z<=191471||Z>=196608&&Z<=201551||Z>=63744&&Z<=64255||Z>=194560&&Z<=195103||Z>=12288&&Z<=12351||Z>=12352&&Z<=12447||Z>=12448&&Z<=12543||Z>=44032&&Z<=55215||Z>=65280&&Z<=65519)return!0}return!1}var p8=new Set([",",".","!",":",";","?","、","。","・",")","〕","〉","》","」","』","】","〗","〙","〛","ー","々","〻","ゝ","ゞ","ヽ","ヾ"]),V2=new Set(['"',"(","[","{","“","‘","«","‹","(","〔","〈","《","「","『","【","〖","〘","〚"]),l8=new Set(["'","’"]),r1=new Set([".",",","!","?",":",";","،","؛","؟","।","॥","၊","။","၌","၍","၏",")","]","}","%",'"',"”","’","»","›","…"]),kJ=new Set([":",".","،","؛"]),fJ=new Set(["၏"]),mJ=new Set(["”","’","»","›","」","』","】","》","〉","〕",")"]);function SJ($){if(r8($))return!0;let M=!1;for(let Z of $){if(r1.has(Z)){M=!0;continue}if(M&&X5.test(Z))continue;return!1}return M}function uJ($){for(let M of $)if(!p8.has(M)&&!r1.has(M))return!1;return $.length>0}function vJ($){if(r8($))return!0;for(let M of $)if(!V2.has(M)&&!l8.has(M)&&!X5.test(M))return!1;return $.length>0}function r8($){let M=!1;for(let Z of $){if(Z==="\\"||X5.test(Z))continue;if(V2.has(Z)||r1.has(Z)||l8.has(Z)){M=!0;continue}return!1}return M}function hJ($){let M=Array.from($),Z=M.length;while(Z>0){let J=M[Z-1];if(X5.test(J)){Z--;continue}if(V2.has(J)||l8.has(J)){Z--;continue}break}if(Z<=0||Z===M.length)return null;return{head:M.slice(0,Z).join(""),tail:M.slice(Z).join("")}}function gJ($,M){if($.length===0)return!1;for(let Z of $)if(Z!==M)return!1;return!0}function IJ($){if(!h8($)||$.length===0)return!1;return kJ.has($[$.length-1])}function pJ($){if($.length===0)return!1;return fJ.has($[$.length-1])}function lJ($){if($.length<2||$[0]!==" ")return null;let M=$.slice(1);if(/^\p{M}+$/u.test(M))return{space:" ",marks:M};return null}function c8($){for(let M=$.length-1;M>=0;M--){let Z=$[M];if(mJ.has(Z))return!0;if(!r1.has(Z))return!1}return!1}function rJ($,M){if(M.preserveOrdinarySpaces||M.preserveHardBreaks){if($===" ")return"preserved-space";if($==="\t")return"tab";if(M.preserveHardBreaks&&$===`
13
+ `)return"hard-break"}if($===" ")return"space";if($===" "||$===" "||$==="⁠"||$==="\uFEFF")return"glue";if($==="​")return"zero-width-break";if($==="­")return"soft-hyphen";return"text"}function i0($){return $.length===1?$[0]:$.join("")}function cJ($,M,Z,J){let X=[],Y=null,Q=[],K=Z,q=!1,U=0;for(let N of $){let A=rJ(N,J),G=A==="text"&&M;if(Y!==null&&A===Y&&G===q){Q.push(N),U+=N.length;continue}if(Y!==null)X.push({text:i0(Q),isWordLike:q,kind:Y,start:K});Y=A,Q=[N],K=Z+U,q=G,U+=N.length}if(Y!==null)X.push({text:i0(Q),isWordLike:q,kind:Y,start:K});return X}function g8($){return $==="space"||$==="preserved-space"||$==="zero-width-break"||$==="hard-break"}var xJ=/^[A-Za-z][A-Za-z0-9+.-]*:$/;function dJ($,M){let Z=$.texts[M];if(Z.startsWith("www."))return!0;return xJ.test(Z)&&M+1<$.len&&$.kinds[M+1]==="text"&&$.texts[M+1]==="//"}function aJ($){return $.includes("?")&&($.includes("://")||$.startsWith("www."))}function iJ($){let M=$.texts.slice(),Z=$.isWordLike.slice(),J=$.kinds.slice(),X=$.starts.slice();for(let Q=0;Q<$.len;Q++){if(J[Q]!=="text"||!dJ($,Q))continue;let K=[M[Q]],q=Q+1;while(q<$.len&&!g8(J[q])){K.push(M[q]),Z[Q]=!0;let U=M[q].includes("?");if(J[q]="text",M[q]="",q++,U)break}M[Q]=i0(K)}let Y=0;for(let Q=0;Q<M.length;Q++){let K=M[Q];if(K.length===0)continue;if(Y!==Q)M[Y]=K,Z[Y]=Z[Q],J[Y]=J[Q],X[Y]=X[Q];Y++}return M.length=Y,Z.length=Y,J.length=Y,X.length=Y,{len:Y,texts:M,isWordLike:Z,kinds:J,starts:X}}function sJ($){let M=[],Z=[],J=[],X=[];for(let Y=0;Y<$.len;Y++){let Q=$.texts[Y];if(M.push(Q),Z.push($.isWordLike[Y]),J.push($.kinds[Y]),X.push($.starts[Y]),!aJ(Q))continue;let K=Y+1;if(K>=$.len||g8($.kinds[K]))continue;let q=[],U=$.starts[K],N=K;while(N<$.len&&!g8($.kinds[N]))q.push($.texts[N]),N++;if(q.length>0)M.push(i0(q)),Z.push(!0),J.push("text"),X.push(U),Y=N-1}return{len:M.length,texts:M,isWordLike:Z,kinds:J,starts:X}}var oJ=new Set([":","-","/","×",",",".","+","–","—"]),g$=/^[A-Za-z0-9_]+[,:;]*$/,I$=/[,:;]+$/;function l$($){for(let M of $)if(p$.test(M))return!0;return!1}function I8($){if($.length===0)return!1;for(let M of $){if(p$.test(M)||oJ.has(M))continue;return!1}return!0}function nJ($){let M=[],Z=[],J=[],X=[];for(let Y=0;Y<$.len;Y++){let Q=$.texts[Y],K=$.kinds[Y];if(K==="text"&&I8(Q)&&l$(Q)){let q=[Q],U=Y+1;while(U<$.len&&$.kinds[U]==="text"&&I8($.texts[U]))q.push($.texts[U]),U++;M.push(i0(q)),Z.push(!0),J.push("text"),X.push($.starts[Y]),Y=U-1;continue}M.push(Q),Z.push($.isWordLike[Y]),J.push(K),X.push($.starts[Y])}return{len:M.length,texts:M,isWordLike:Z,kinds:J,starts:X}}function tJ($){let M=[],Z=[],J=[],X=[];for(let Y=0;Y<$.len;Y++){let Q=$.texts[Y],K=$.kinds[Y],q=$.isWordLike[Y];if(K==="text"&&q&&g$.test(Q)){let U=[Q],N=I$.test(Q),A=Y+1;while(N&&A<$.len&&$.kinds[A]==="text"&&$.isWordLike[A]&&g$.test($.texts[A])){let G=$.texts[A];U.push(G),N=I$.test(G),A++}M.push(i0(U)),Z.push(!0),J.push("text"),X.push($.starts[Y]),Y=A-1;continue}M.push(Q),Z.push(q),J.push(K),X.push($.starts[Y])}return{len:M.length,texts:M,isWordLike:Z,kinds:J,starts:X}}function eJ($){let M=[],Z=[],J=[],X=[];for(let Y=0;Y<$.len;Y++){let Q=$.texts[Y];if($.kinds[Y]==="text"&&Q.includes("-")){let K=Q.split("-"),q=K.length>1;for(let U=0;U<K.length;U++){let N=K[U];if(!q)break;if(N.length===0||!l$(N)||!I8(N))q=!1}if(q){let U=0;for(let N=0;N<K.length;N++){let A=K[N],G=N<K.length-1?`${A}-`:A;M.push(G),Z.push(!0),J.push("text"),X.push($.starts[Y]+U),U+=G.length}continue}}M.push(Q),Z.push($.isWordLike[Y]),J.push($.kinds[Y]),X.push($.starts[Y])}return{len:M.length,texts:M,isWordLike:Z,kinds:J,starts:X}}function $X($){let M=[],Z=[],J=[],X=[],Y=0;while(Y<$.len){let Q=[$.texts[Y]],K=$.isWordLike[Y],q=$.kinds[Y],U=$.starts[Y];if(q==="glue"){let N=[Q[0]],A=U;Y++;while(Y<$.len&&$.kinds[Y]==="glue")N.push($.texts[Y]),Y++;let G=i0(N);if(Y<$.len&&$.kinds[Y]==="text")Q[0]=G,Q.push($.texts[Y]),K=$.isWordLike[Y],q="text",U=A,Y++;else{M.push(G),Z.push(!1),J.push("glue"),X.push(A);continue}}else Y++;if(q==="text")while(Y<$.len&&$.kinds[Y]==="glue"){let N=[];while(Y<$.len&&$.kinds[Y]==="glue")N.push($.texts[Y]),Y++;let A=i0(N);if(Y<$.len&&$.kinds[Y]==="text"){Q.push(A,$.texts[Y]),K=K||$.isWordLike[Y],Y++;continue}Q.push(A)}M.push(i0(Q)),Z.push(K),J.push(q),X.push(U)}return{len:M.length,texts:M,isWordLike:Z,kinds:J,starts:X}}function MX($){let M=$.texts.slice(),Z=$.isWordLike.slice(),J=$.kinds.slice(),X=$.starts.slice();for(let Y=0;Y<M.length-1;Y++){if(J[Y]!=="text"||J[Y+1]!=="text")continue;if(!a0(M[Y])||!a0(M[Y+1]))continue;let Q=hJ(M[Y]);if(Q===null)continue;M[Y]=Q.head,M[Y+1]=Q.tail+M[Y+1],X[Y+1]=X[Y]+Q.head.length}return{len:M.length,texts:M,isWordLike:Z,kinds:J,starts:X}}function ZX($,M,Z){let J=RJ(),X=0,Y=[],Q=[],K=[],q=[];for(let G of J.segment($))for(let B of cJ(G.segment,G.isWordLike??!1,G.index,Z)){let F=B.kind==="text";if(M.carryCJKAfterClosingQuote&&F&&X>0&&K[X-1]==="text"&&a0(B.text)&&a0(Y[X-1])&&c8(Y[X-1]))Y[X-1]+=B.text,Q[X-1]=Q[X-1]||B.isWordLike;else if(F&&X>0&&K[X-1]==="text"&&uJ(B.text)&&a0(Y[X-1]))Y[X-1]+=B.text,Q[X-1]=Q[X-1]||B.isWordLike;else if(F&&X>0&&K[X-1]==="text"&&pJ(Y[X-1]))Y[X-1]+=B.text,Q[X-1]=Q[X-1]||B.isWordLike;else if(F&&X>0&&K[X-1]==="text"&&B.isWordLike&&h8(B.text)&&IJ(Y[X-1]))Y[X-1]+=B.text,Q[X-1]=!0;else if(F&&!B.isWordLike&&X>0&&K[X-1]==="text"&&B.text.length===1&&B.text!=="-"&&B.text!=="—"&&gJ(Y[X-1],B.text))Y[X-1]+=B.text;else if(F&&!B.isWordLike&&X>0&&K[X-1]==="text"&&(SJ(B.text)||B.text==="-"&&Q[X-1]))Y[X-1]+=B.text;else Y[X]=B.text,Q[X]=B.isWordLike,K[X]=B.kind,q[X]=B.start,X++}for(let G=1;G<X;G++)if(K[G]==="text"&&!Q[G]&&r8(Y[G])&&K[G-1]==="text")Y[G-1]+=Y[G],Q[G-1]=Q[G-1]||Q[G],Y[G]="";for(let G=X-2;G>=0;G--)if(K[G]==="text"&&!Q[G]&&vJ(Y[G])){let B=G+1;while(B<X&&Y[B]==="")B++;if(B<X&&K[B]==="text")Y[B]=Y[G]+Y[B],q[B]=q[G],Y[G]=""}let U=0;for(let G=0;G<X;G++){let B=Y[G];if(B.length===0)continue;if(U!==G)Y[U]=B,Q[U]=Q[G],K[U]=K[G],q[U]=q[G];U++}Y.length=U,Q.length=U,K.length=U,q.length=U;let N=$X({len:U,texts:Y,isWordLike:Q,kinds:K,starts:q}),A=MX(tJ(eJ(nJ(sJ(iJ(N))))));for(let G=0;G<A.len-1;G++){let B=lJ(A.texts[G]);if(B===null)continue;if(A.kinds[G]!=="space"&&A.kinds[G]!=="preserved-space"||A.kinds[G+1]!=="text"||!h8(A.texts[G+1]))continue;A.texts[G]=B.space,A.isWordLike[G]=!1,A.kinds[G]=A.kinds[G]==="preserved-space"?"preserved-space":"space",A.texts[G+1]=B.marks+A.texts[G+1],A.starts[G+1]=A.starts[G]+B.space.length}return A}function JX($,M){if($.len===0)return[];if(!M.preserveHardBreaks)return[{startSegmentIndex:0,endSegmentIndex:$.len,consumedEndSegmentIndex:$.len}];let Z=[],J=0;for(let X=0;X<$.len;X++){if($.kinds[X]!=="hard-break")continue;Z.push({startSegmentIndex:J,endSegmentIndex:X,consumedEndSegmentIndex:X+1}),J=X+1}if(J<$.len)Z.push({startSegmentIndex:J,endSegmentIndex:$.len,consumedEndSegmentIndex:$.len});return Z}function r$($,M,Z="normal"){let J=OJ(Z),X=J.mode==="pre-wrap"?CJ($):EJ($);if(X.length===0)return{normalized:X,chunks:[],len:0,texts:[],isWordLike:[],kinds:[],starts:[]};let Y=ZX(X,M,J);return{normalized:X,chunks:JX(Y,J),...Y}}var c1=null,c$=new Map,x1=null,XX=/\p{Emoji_Presentation}/u,YX=/[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u,x8=null,x$=new Map;function d8(){if(c1!==null)return c1;if(typeof OffscreenCanvas<"u")return c1=new OffscreenCanvas(1,1).getContext("2d"),c1;if(typeof document<"u")return c1=document.createElement("canvas").getContext("2d"),c1;throw Error("Text measurement requires OffscreenCanvas or a DOM canvas context.")}function QX($){let M=c$.get($);if(!M)M=new Map,c$.set($,M);return M}function J1($,M){let Z=M.get($);if(Z===void 0)Z={width:d8().measureText($).width,containsCJK:a0($)},M.set($,Z);return Z}function d1(){if(x1!==null)return x1;if(typeof navigator>"u")return x1={lineFitEpsilon:0.005,carryCJKAfterClosingQuote:!1,preferPrefixWidthsForBreakableRuns:!1,preferEarlySoftHyphenBreak:!1},x1;let $=navigator.userAgent,Z=navigator.vendor==="Apple Computer, Inc."&&$.includes("Safari/")&&!$.includes("Chrome/")&&!$.includes("Chromium/")&&!$.includes("CriOS/")&&!$.includes("FxiOS/")&&!$.includes("EdgiOS/"),J=$.includes("Chrome/")||$.includes("Chromium/")||$.includes("CriOS/")||$.includes("Edg/");return x1={lineFitEpsilon:Z?0.015625:0.005,carryCJKAfterClosingQuote:J,preferPrefixWidthsForBreakableRuns:Z,preferEarlySoftHyphenBreak:Z},x1}function KX($){let M=$.match(/(\d+(?:\.\d+)?)\s*px/);return M?parseFloat(M[1]):16}function a8(){if(x8===null)x8=new Intl.Segmenter(void 0,{granularity:"grapheme"});return x8}function qX($){return XX.test($)||$.includes("️")}function d$($){return YX.test($)}function UX($,M){let Z=x$.get($);if(Z!==void 0)return Z;let J=d8();J.font=$;let X=J.measureText("\uD83D\uDE00").width;if(Z=0,X>M+0.5&&typeof document<"u"&&document.body!==null){let Y=document.createElement("span");Y.style.font=$,Y.style.display="inline-block",Y.style.visibility="hidden",Y.style.position="absolute",Y.textContent="\uD83D\uDE00",document.body.appendChild(Y);let Q=Y.getBoundingClientRect().width;if(document.body.removeChild(Y),X-Q>0.5)Z=X-Q}return x$.set($,Z),Z}function NX($){let M=0,Z=a8();for(let J of Z.segment($))if(qX(J.segment))M++;return M}function AX($,M){if(M.emojiCount===void 0)M.emojiCount=NX($);return M.emojiCount}function X1($,M,Z){if(Z===0)return M.width;return M.width-AX($,M)*Z}function a$($,M,Z,J){if(M.graphemeWidths!==void 0)return M.graphemeWidths;let X=[],Y=a8();for(let Q of Y.segment($)){let K=J1(Q.segment,Z);X.push(X1(Q.segment,K,J))}return M.graphemeWidths=X.length>1?X:null,M.graphemeWidths}function i$($,M,Z,J){if(M.graphemePrefixWidths!==void 0)return M.graphemePrefixWidths;let X=[],Y=a8(),Q="";for(let K of Y.segment($)){Q+=K.segment;let q=J1(Q,Z);X.push(X1(Q,q,J))}return M.graphemePrefixWidths=X.length>1?X:null,M.graphemePrefixWidths}function s$($,M){let Z=d8();Z.font=$;let J=QX($),X=KX($),Y=M?UX($,X):0;return{cache:J,fontSize:X,emojiCorrection:Y}}function Y5($){return $==="space"||$==="preserved-space"||$==="tab"||$==="zero-width-break"||$==="soft-hyphen"}function GX($,M){while(M<$.widths.length){let Z=$.kinds[M];if(Z!=="space"&&Z!=="zero-width-break"&&Z!=="soft-hyphen")break;M++}return M}function BX($,M){if(M<=0)return 0;let Z=$%M;if(Math.abs(Z)<=0.000001)return M;return M-Z}function o$($,M,Z,J){if(!J||M===null)return $[Z];return M[Z]-(Z>0?M[Z-1]:0)}function _X($,M,Z,J,X,Y){let Q=0,K=M;while(Q<$.length){let q=Y?M+$[Q]:K+$[Q];if((Q+1<$.length?q+X:q)>Z+J)break;K=q,Q++}return{fitCount:Q,fittedWidth:K}}function FX($,M,Z){let{widths:J,kinds:X,breakableWidths:Y,breakablePrefixWidths:Q}=$;if(J.length===0)return 0;let K=d1(),q=K.lineFitEpsilon,U=0,N=0,A=!1,G=0,B=0,F=0,_=0,D=-1,T=0;function O(){D=-1,T=0}function y(W=F,b=_,z=N){U++,Z?.({startSegmentIndex:G,startGraphemeIndex:B,endSegmentIndex:W,endGraphemeIndex:b,width:z}),N=0,A=!1,O()}function R(W,b){A=!0,G=W,B=0,F=W+1,_=0,N=b}function C(W,b,z){A=!0,G=W,B=b,F=W,_=b+1,N=z}function m(W,b){if(!A){R(W,b);return}N+=b,F=W+1,_=0}function H(W,b){if(!Y5(X[W]))return;D=W+1,T=N-b}function P(W){E(W,0)}function E(W,b){let z=Y[W],u=Q[W]??null;for(let v=b;v<z.length;v++){let l=o$(z,u,v,K.preferPrefixWidthsForBreakableRuns);if(!A){C(W,v,l);continue}if(N+l>M+q)y(),C(W,v,l);else N+=l,F=W,_=v+1}if(A&&F===W&&_===z.length)F=W+1,_=0}let j=0;while(j<J.length){if(!A){if(j=GX($,j),j>=J.length)break}let W=J[j],b=X[j];if(!A){if(W>M&&Y[j]!==null)P(j);else R(j,W);H(j,W),j++;continue}if(N+W>M+q){if(Y5(b)){m(j,W),y(j+1,0,N-W),j++;continue}if(D>=0){if(F>D||F===D&&_>0){y();continue}y(D,0,T);continue}if(W>M&&Y[j]!==null){y(),P(j),j++;continue}y();continue}m(j,W),H(j,W),j++}if(A)y();return U}function n$($,M,Z){if($.simpleLineWalkFastPath)return FX($,M,Z);let{widths:J,lineEndFitAdvances:X,lineEndPaintAdvances:Y,kinds:Q,breakableWidths:K,breakablePrefixWidths:q,discretionaryHyphenWidth:U,tabStopAdvance:N,chunks:A}=$;if(J.length===0||A.length===0)return 0;let G=d1(),B=G.lineFitEpsilon,F=0,_=0,D=!1,T=0,O=0,y=0,R=0,C=-1,m=0,H=0,P=null;function E(){C=-1,m=0,H=0,P=null}function j(V=y,L=R,f=_){F++,Z?.({startSegmentIndex:T,startGraphemeIndex:O,endSegmentIndex:V,endGraphemeIndex:L,width:f}),_=0,D=!1,E()}function W(V,L){D=!0,T=V,O=0,y=V+1,R=0,_=L}function b(V,L,f){D=!0,T=V,O=L,y=V,R=L+1,_=f}function z(V,L){if(!D){W(V,L);return}_+=L,y=V+1,R=0}function u(V,L){if(!Y5(Q[V]))return;let f=Q[V]==="tab"?0:X[V],x=Q[V]==="tab"?L:Y[V];C=V+1,m=_-L+f,H=_-L+x,P=Q[V]}function v(V){l(V,0)}function l(V,L){let f=K[V],x=q[V]??null;for(let h=L;h<f.length;h++){let Q0=o$(f,x,h,G.preferPrefixWidthsForBreakableRuns);if(!D){b(V,h,Q0);continue}if(_+Q0>M+B)j(),b(V,h,Q0);else _+=Q0,y=V,R=h+1}if(D&&y===V&&R===f.length)y=V+1,R=0}function g(V){if(P!=="soft-hyphen")return!1;let L=K[V];if(L===null)return!1;let f=G.preferPrefixWidthsForBreakableRuns?q[V]??L:L,x=f!==L,{fitCount:h,fittedWidth:Q0}=_X(f,_,M,B,U,x);if(h===0)return!1;if(_=Q0,y=V,R=h,E(),h===L.length)return y=V+1,R=0,!0;return j(V,h,Q0+U),l(V,h),!0}function w(V){F++,Z?.({startSegmentIndex:V.startSegmentIndex,startGraphemeIndex:0,endSegmentIndex:V.consumedEndSegmentIndex,endGraphemeIndex:0,width:0}),E()}for(let V=0;V<A.length;V++){let L=A[V];if(L.startSegmentIndex===L.endSegmentIndex){w(L);continue}D=!1,_=0,T=L.startSegmentIndex,O=0,y=L.startSegmentIndex,R=0,E();let f=L.startSegmentIndex;while(f<L.endSegmentIndex){let x=Q[f],h=x==="tab"?BX(_,N):J[f];if(x==="soft-hyphen"){if(D)y=f+1,R=0,C=f+1,m=_+U,H=_+U,P=x;f++;continue}if(!D){if(h>M&&K[f]!==null)v(f);else W(f,h);u(f,h),f++;continue}if(_+h>M+B){let b0=_+(x==="tab"?0:X[f]),e0=_+(x==="tab"?h:Y[f]);if(P==="soft-hyphen"&&G.preferEarlySoftHyphenBreak&&m<=M+B){j(C,0,H);continue}if(P==="soft-hyphen"&&g(f)){f++;continue}if(Y5(x)&&b0<=M+B){z(f,h),j(f+1,0,e0),f++;continue}if(C>=0&&m<=M+B){if(y>C||y===C&&R>0){j();continue}let L1=C;j(L1,0,H),f=L1;continue}if(h>M&&K[f]!==null){j(),v(f),f++;continue}j();continue}z(f,h),u(f,h),f++}if(D){let x=C===L.consumedEndSegmentIndex?H:_;j(L.consumedEndSegmentIndex,0,x)}}return F}var i8=null,t$=new WeakMap;function $9(){if(i8===null)i8=new Intl.Segmenter(void 0,{granularity:"grapheme"});return i8}function bX($){if($)return{widths:[],lineEndFitAdvances:[],lineEndPaintAdvances:[],kinds:[],simpleLineWalkFastPath:!0,segLevels:null,breakableWidths:[],breakablePrefixWidths:[],discretionaryHyphenWidth:0,tabStopAdvance:0,chunks:[],segments:[]};return{widths:[],lineEndFitAdvances:[],lineEndPaintAdvances:[],kinds:[],simpleLineWalkFastPath:!0,segLevels:null,breakableWidths:[],breakablePrefixWidths:[],discretionaryHyphenWidth:0,tabStopAdvance:0,chunks:[]}}function DX($,M,Z){let J=$9(),X=d1(),{cache:Y,emojiCorrection:Q}=s$(M,d$($.normalized)),K=X1("-",J1("-",Y),Q),U=X1(" ",J1(" ",Y),Q)*8;if($.len===0)return bX(Z);let N=[],A=[],G=[],B=[],F=$.chunks.length<=1,_=Z?[]:null,D=[],T=[],O=Z?[]:null,y=Array.from({length:$.len}),R=Array.from({length:$.len});function C(P,E,j,W,b,z,u,v){if(b!=="text"&&b!=="space"&&b!=="zero-width-break")F=!1;if(N.push(E),A.push(j),G.push(W),B.push(b),_?.push(z),D.push(u),T.push(v),O!==null)O.push(P)}for(let P=0;P<$.len;P++){y[P]=N.length;let E=$.texts[P],j=$.isWordLike[P],W=$.kinds[P],b=$.starts[P];if(W==="soft-hyphen"){C(E,0,K,K,W,b,null,null),R[P]=N.length;continue}if(W==="hard-break"){C(E,0,0,0,W,b,null,null),R[P]=N.length;continue}if(W==="tab"){C(E,0,0,0,W,b,null,null),R[P]=N.length;continue}let z=J1(E,Y);if(W==="text"&&z.containsCJK){let g="",w=0;for(let V of J.segment(E)){let L=V.segment;if(g.length===0){g=L,w=V.index;continue}if(V2.has(g)||p8.has(L)||r1.has(L)||X.carryCJKAfterClosingQuote&&a0(L)&&c8(g)){g+=L;continue}let f=J1(g,Y),x=X1(g,f,Q);C(g,x,x,x,"text",b+w,null,null),g=L,w=V.index}if(g.length>0){let V=J1(g,Y),L=X1(g,V,Q);C(g,L,L,L,"text",b+w,null,null)}R[P]=N.length;continue}let u=X1(E,z,Q),v=W==="space"||W==="preserved-space"||W==="zero-width-break"?0:u,l=W==="space"||W==="zero-width-break"?0:u;if(j&&E.length>1){let g=a$(E,z,Y,Q),w=X.preferPrefixWidthsForBreakableRuns?i$(E,z,Y,Q):null;C(E,u,v,l,W,b,g,w)}else C(E,u,v,l,W,b,null,null);R[P]=N.length}let m=HX($.chunks,y,R),H=_===null?null:h$($.normalized,_);if(O!==null)return{widths:N,lineEndFitAdvances:A,lineEndPaintAdvances:G,kinds:B,simpleLineWalkFastPath:F,segLevels:H,breakableWidths:D,breakablePrefixWidths:T,discretionaryHyphenWidth:K,tabStopAdvance:U,chunks:m,segments:O};return{widths:N,lineEndFitAdvances:A,lineEndPaintAdvances:G,kinds:B,simpleLineWalkFastPath:F,segLevels:H,breakableWidths:D,breakablePrefixWidths:T,discretionaryHyphenWidth:K,tabStopAdvance:U,chunks:m}}function HX($,M,Z){let J=[];for(let X=0;X<$.length;X++){let Y=$[X],Q=Y.startSegmentIndex<M.length?M[Y.startSegmentIndex]:Z[Z.length-1]??0,K=Y.endSegmentIndex<M.length?M[Y.endSegmentIndex]:Z[Z.length-1]??0,q=Y.consumedEndSegmentIndex<M.length?M[Y.consumedEndSegmentIndex]:Z[Z.length-1]??0;J.push({startSegmentIndex:Q,endSegmentIndex:K,consumedEndSegmentIndex:q})}return J}function PX($,M,Z,J){let X=r$($,d1(),J?.whiteSpace);return DX(X,M,Z)}function M9($,M,Z){return PX($,M,!0,Z)}function zX($){return $}function e$($,M,Z){let J=Z.get($);if(J!==void 0)return J;J=[];let X=$9();for(let Y of X.segment(M[$]))J.push(Y.segment);return Z.set($,J),J}function TX($){let M=t$.get($);if(M!==void 0)return M;return M=new Map,t$.set($,M),M}function yX($,M,Z,J){return J>0&&$[J-1]==="soft-hyphen"&&!(M===J&&Z>0)}function WX($,M,Z,J,X,Y,Q){let K="",q=yX(M,J,X,Y);for(let U=J;U<Y;U++){if(M[U]==="soft-hyphen"||M[U]==="hard-break")continue;if(U===J&&X>0)K+=e$(U,$,Z).slice(X).join("");else K+=$[U]}if(Q>0){if(q)K+="-";K+=e$(Y,$,Z).slice(J===Y?X:0,Q).join("")}else if(q)K+="-";return K}function VX($,M,Z,J,X,Y,Q){return{text:WX($.segments,$.kinds,M,J,X,Y,Q),width:Z,start:{segmentIndex:J,graphemeIndex:X},end:{segmentIndex:Y,graphemeIndex:Q}}}function wX($,M,Z){return VX($,M,Z.width,Z.startSegmentIndex,Z.startGraphemeIndex,Z.endSegmentIndex,Z.endGraphemeIndex)}function Z9($,M,Z){let J=[];if($.widths.length===0)return{lineCount:0,height:0,lines:J};let X=TX($),Y=n$(zX($),M,(Q)=>{J.push(wX($,X,Q))});return{lineCount:Y,height:Y*Z,lines:J}}function s8($,M,Z){let J=$.image?M.images.get($.image.url)??null:null,X=$.image?.width??null,Y=Math.min(Z,X??240),Q=Math.max(120,Math.round(Y*0.5625));if(!J||J.intrinsicWidth<=0||J.intrinsicHeight<=0)return{height:Q,width:Y};let K=Math.min(Z,X??J.intrinsicWidth),q=Math.min(1,K/J.intrinsicWidth);return{height:Math.max(48,Math.round(J.intrinsicHeight*q)),width:Math.max(48,Math.round(J.intrinsicWidth*q))}}function J9($,M){if(!$.image)return`${$.kind}:missing-image`;let Z=M.images.get($.image.url);return`${$.kind}:${$.image.url}:${$.image.width??0}:${Z?.status??"loading"}:${Z?.intrinsicWidth??0}:${Z?.intrinsicHeight??0}`}var X9=[{fontSize:32,lineHeight:36},{fontSize:26,lineHeight:32},{fontSize:21,lineHeight:28},{fontSize:21,lineHeight:28},{fontSize:19,lineHeight:26},{fontSize:18,lineHeight:26}],Q5;function a1($){if($?.type==="heading"){let{fontSize:M}=K9($.depth);return`700 ${M}px "Iowan Old Style", "Palatino Linotype", serif`}switch($?.type){case"code":return"15px ui-monospace, SFMono-Regular, Menlo, monospace";default:return'16px "Iowan Old Style", "Palatino Linotype", serif'}}function y1($,M){if($?.type==="heading")return K9($.depth).lineHeight;if($?.type==="code")return 22;return M}function K9($){return X9[$-1]??X9.at(-1)}function i1($,M,Z,J,X,Y,Q){let K=`${q5(M,Q)}:${X}:${Y}:${Z}`,q=$.measuredLines.get(K);if(q)return q;let U=EX($,M,Z,J,X,Y,Q);return k$($,K,U)}function K5($,M,Z,J,X,Y,Q,K){let q=`${q5(M,K)}:${Z}:${J}:${Y}:${Q}`,U=$.lineBoundaries.get(q);if(U)return U;let N=U9();if(!N)return Q9(X);let A=[{left:0,offset:0}],G=0,B=M.inlines.filter((F)=>F.end>Z&&F.start<J);if(B.length===0)return Q9(X);for(let F of B){let _=Math.max(Z,F.start),D=Math.min(J,F.end),T=M.text.slice(_,D),O=_-Z;if(F.kind==="image"){let y=s8(F,K,Q).width;G+=y,O+=T.length,A.push({left:G,offset:O});continue}N.font=q9(Y,F.marks);for(let y of Array.from(T))G+=N9($,N,y),O+=y.length,A.push({left:G,offset:O})}return f$($,q,A)}function OX($,M,Z,J){let X=`${Z}::${J}::${M}`,Y=$.preparedText.get(X);if(Y)return Y;let Q=M9(M,Z,{whiteSpace:J});return L$($,X,Q)}function EX($,M,Z,J,X,Y,Q){let K=M.text;if(K.length===0)return[{end:0,height:Y,start:0,text:"",width:0}];if(kX(M))return jX($,M,Z,X,Y,Q);try{let q=OX($,K,Z,vX(J));return Z9(q,X,Y).lines.map((N)=>({end:Y9(q.segments,N.end),height:Y,start:Y9(q.segments,N.start),text:N.text,width:N.width}))}catch{return CX(K,X,Y)}}function Y9($,M){let Z=0;for(let Y=0;Y<M.segmentIndex;Y+=1)Z+=$[Y]?.length??0;let J=$[M.segmentIndex]??"",X=Array.from(J);for(let Y=0;Y<M.graphemeIndex;Y+=1)Z+=X[Y]?.length??0;return Z}function Q9($){let M=[{left:0,offset:0}],Z=0,J=0;for(let X of Array.from($))Z+=9,J+=X.length,M.push({left:Z,offset:J});return M}function CX($,M,Z){let J=Math.max(1,Math.floor(M/9)),X=hX($,J),Y=0;return X.map((Q)=>{let K=Y,q=K+Q.length;return Y=q,{end:q,height:Z,start:K,text:Q,width:Q.length*9}})}function jX($,M,Z,J,X,Y){let Q=LX($,U9(),M,Z,J,X,Y);if(Q.length===0)return[{end:0,height:X,start:0,text:"",width:0}];return RX(Q,M.text,J,X)}function RX($,M,Z,J){let X=[],Y=0;while(Y<$.length){let Q=$[Y].start;if($[Y].text===`
14
+ `){X.push({end:Q,height:J,start:Q,text:"",width:0}),Y+=1;continue}let K=0,q=0,U=Y,N=-1,A=J;while(U<$.length){let B=$[U];if(B.text===`
15
+ `)break;let F=K+B.width;if(F>Z&&U>Y)break;if(K=F,A=Math.max(A,B.height),B.breakable)N=U,q=K;U+=1}if(U===$.length||$[U]?.text===`
16
+ `){let B=$[U-1]?.end??Q;X.push({end:B,height:A,start:Q,text:M.slice(Q,B),width:K}),Y=U<$.length&&$[U]?.text===`
17
+ `?U+1:U;continue}if(N>=Y){let B=$[N].end;X.push({end:B,height:A,start:Q,text:M.slice(Q,B),width:q}),Y=N+1;continue}let G=$[Math.max(Y,U-1)].end;X.push({end:G,height:A,start:Q,text:M.slice(Q,G),width:K}),Y=Math.max(Y+1,U)}return X}function LX($,M,Z,J,X,Y,Q){let K=[];for(let q of Z.inlines){if(q.kind==="image"){let N=s8(q,Q,X);K.push({breakable:!0,end:q.end,height:N.height,start:q.start,text:q.text,width:N.width});continue}if(M)M.font=q9(J,q.marks);let U=q.start;for(let N of Array.from(q.text)){let A=U,G=A+N.length;K.push({breakable:/\s/.test(N),end:G,height:Y,start:A,text:N,width:N===`
18
+ `?0:N9($,M,N)}),U=G}}return K}function kX($){return $.inlines.some((M)=>M.kind==="image"||uX(M))}function q5($,M){return[$.path,SX($.text),fX($,M)].join(":")}function fX($,M){return $.inlines.map((Z)=>`${Z.start}-${Z.end}:${mX(Z,M)}`).join("|")}function mX($,M){if($.kind==="image"&&$.image)return J9($,M);return`${$.kind}:${$.inlineCode?1:0}:${$.marks.join(",")}:${$.link?.url??""}`}function SX($){let M=2166136261;for(let Z of $)M^=Z.charCodeAt(0),M=Math.imul(M,16777619);return(M>>>0).toString(36)}function uX($){return $.marks.includes("italic")||$.marks.includes("bold")}function q9($,M){let Z=[];if(M.includes("italic"))Z.push("italic");if(M.includes("bold"))Z.push("700");return Z.length>0?`${Z.join(" ")} ${$}`:$}function U9(){if(Q5!==void 0)return Q5;return Q5=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):typeof document<"u"?document.createElement("canvas"):null)?.getContext("2d")??null,Q5}function N9($,M,Z){if(!M)return 9;let J=M.font,X=S$($,J),Y=X.get(Z);if(Y!==void 0)return Y;let Q=M.measureText(Z).width;return X.set(Z,Q),Q}function vX($){return $?.type==="code"?"pre-wrap":"normal"}function hX($,M){if($.length===0)return[""];let Z=$.split(`
19
+ `),J=[];for(let X of Z){if(X.length===0){J.push("");continue}let Y=X;while(Y.length>M){let Q=Y.slice(0,M),K=Q.lastIndexOf(" ");if(K<=0){J.push(Q),Y=Y.slice(M);continue}J.push(Q.slice(0,K)),Y=Y.slice(K+1)}J.push(Y)}return J}var w2=10,s1=8,o8=120;function A9($,M,Z,J,X,Y,Q,K,q,U){let N=Math.max(1,...Y.rows.map((_)=>_.cells.length)),G=Math.max(o8,q.width-Q-q.paddingX)/N,B=gX(J),F=K;for(let _=0;_<Y.rows.length;_+=1){let D=IX(B.get(_)??[],X,Y,G,w2,q.lineHeight,U),T=Math.max(q.lineHeight+s1*2,...D.map((O)=>O.measuredLines.reduce((y,R)=>y+R.height,0)+s1*2));for(let O of D){let y=Q+O.cellIndex*G,R=F+s1;for(let C of O.measuredLines){let m={blockId:O.container.blockId,boundaries:K5(X,O.container,C.start,C.end,C.text,O.font,G-w2*2,U),regionId:O.container.id,end:C.end,font:O.font,height:C.height,left:y+w2,start:C.start,text:C.text,top:R,width:C.width};$.push(m),n8(M,m),R+=C.height}Z.set(O.container.id,{bottom:F+T,left:y,right:y+G,top:F})}lX(M,Y.id,F,F+T),F+=T}return F+q.blockGap}function gX($){let M=new Map;for(let Z of $){let J=pX(Z.path);if(!J)continue;let X=M.get(J.rowIndex)??[];X.push({cellIndex:J.cellIndex,container:Z}),M.set(J.rowIndex,X)}return M}function IX($,M,Z,J,X,Y,Q){return[...$].sort((K,q)=>K.cellIndex-q.cellIndex).map(({cellIndex:K,container:q})=>{let U=a1(Z),N=y1(Z,Y),A=i1(M,q,U,Z,Math.max(40,J-X*2),N,Q);return{cellIndex:K,container:q,font:U,lineHeight:N,measuredLines:A}})}function pX($){let M=/\.rows\.(\d+)\.cells\.(\d+)$/.exec($);if(!M)return null;return{cellIndex:Number(M[2]),rowIndex:Number(M[1])}}function lX($,M,Z,J){let X=$.get(M);$.set(M,{bottom:X?Math.max(X.bottom,J):J,top:X?Math.min(X.top,Z):Z})}var rX={blockGap:16,charWidth:9,indentWidth:24,lineHeight:24,paddingX:16,paddingY:12},cX=24,xX=16,dX=6,aX=10,iX=4;function U5($){let M=Math.max(12,Math.floor($.width/9)),Z=Math.max(1,Math.ceil($.text.length/M));return{estimatedHeight:Z*24,lineCount:Z,width:$.width}}function N5($,M,Z=T1(),J=null){let X=J??{images:new Map},Y={...rX,...M},Q=[],K=new Map,q=new Map($.regions.map((_)=>[_.id,{textLength:_.text.length}])),U=new Map($.blocks.map((_)=>[_.id,_.depth])),N=new Map($.blocks.map((_)=>[_.id,_])),A=E2($.document.blocks),G=new Map,B=Y.paddingY;for(let _=0;_<$.regions.length;_+=1){let D=$.regions[_],T=U.get(D.blockId)??0,O=Y.paddingX+T*Y.indentWidth,y=Math.max(40,Y.width-O-Y.paddingX),R=A.get(D.blockId)??null;if(R?.type==="table"){let H=N.get(D.blockId)?.regionIds??[],P=$.regions.slice(_,_+H.length);B=A9(Q,G,K,P,Z,R,O,B,Y,X),_+=P.length-1;continue}B=sX(Q,G,K,D,Z,R,O,B,y,Y,X);let C=G5(N,A,$.regions,_,Y.blockGap);B+=C;let m=G.get(D.blockId);if(m)m.bottom=Math.max(m.bottom,B)}return{blocks:$.blocks.map((_)=>{let D=G.get(_.id),T=D?.top??Y.paddingY;return{bottom:D?.bottom??T+Y.lineHeight/2,depth:_.depth,id:_.id,top:T,type:_.type}}),regionBounds:nX(Q,K),regionLineIndices:oX(Q),regionMetrics:q,height:Math.max(B,Y.paddingY),lines:Q,options:Y,width:Y.width}}function sX($,M,Z,J,X,Y,Q,K,q,U,N){let A=a1(Y),G=y1(Y,U.lineHeight),B=i1(X,J,A,Y,q,G,N),F=K;for(let _ of B){let D={blockId:J.blockId,boundaries:K5(X,J,_.start,_.end,_.text,A,q,N),regionId:J.id,end:_.end,font:A,height:_.height,left:Q,start:_.start,text:_.text,top:F,width:_.width};$.push(D),n8(M,D),F+=_.height}return tX($,J.id,Z),F}function oX($){let M=[...$].sort((J,X)=>J.top-X.top||J.left-X.left),Z=new Map;$.length=0,$.push(...M);for(let[J,X]of $.entries()){let Y=Z.get(X.regionId)??[];Y.push(J),Z.set(X.regionId,Y)}return Z}function nX($,M){let Z=new Map(M);for(let J of $){let X=Z.get(J.regionId),Y={bottom:J.top+J.height,left:J.left,right:J.left+J.width,top:J.top};Z.set(J.regionId,X?{bottom:Math.max(X.bottom,Y.bottom),left:Math.min(X.left,Y.left),right:Math.max(X.right,Y.right),top:Math.min(X.top,Y.top)}:Y)}return Z}function tX($,M,Z){let J=$.filter((X)=>X.regionId===M);if(J.length===0)return;Z.set(M,{bottom:Math.max(...J.map((X)=>X.top+X.height)),left:Math.min(...J.map((X)=>X.left)),right:Math.max(...J.map((X)=>X.left+X.width)),top:Math.min(...J.map((X)=>X.top))})}function n8($,M){let Z=$.get(M.blockId),J=M.top+M.height;$.set(M.blockId,{bottom:Z?Math.max(Z.bottom,J):J,top:Z?Math.min(Z.top,M.top):M.top})}function b9($,M){let Z=0,J=$.lines.length-1;while(Z<=J){let X=Z+J>>1,Y=$.lines[X];if(M<Y.top){J=X-1;continue}if(M>=Y.top+Y.height){Z=X+1;continue}return{index:X,line:Y}}return null}function t8($,M){let Z=[...$.regionBounds.entries()].find(([,Y])=>{return M.x>=Y.left&&M.x<=Y.right&&M.y>=Y.top&&M.y<=Y.bottom});if(Z)return A5($,Z[0],M.y);let J=b9($,M.y);if(!J)return null;let X=eX($,M.y,J.index);if(X.length===1)return X[0]??null;return X.find((Y)=>{let Q=$.regionBounds.get(Y.line.regionId);return Q?M.x>=Q.left&&M.x<=Q.right:!1})??[...X].sort((Y,Q)=>{let K=$.regionBounds.get(Y.line.regionId),q=$.regionBounds.get(Q.line.regionId),U=G9(M.x,K),N=G9(M.x,q);return U-N})[0]??null}function e8($,M,Z){if($.lines.length===0)return{endIndex:0,startIndex:0};let J=M+Z,X=B9($,M),Y=B9($,J);if(X>0){let Q=$.lines[X-1];if(Q.top+Q.height>M)X-=1}if(Y<$.lines.length){if($.lines[Y].top<J)Y+=1}return{endIndex:Y,startIndex:X}}function I0($,M,Z){if(!$.regionMetrics.get(Z.regionId))return null;let X=s0($,Z.regionId,Z.offset);if(!X)return null;return{blockId:X.blockId,regionId:X.regionId,height:X.height,left:p0(X,Z.offset-X.start),offset:Z.offset,top:X.top}}function s0($,M,Z){return O2($,M,Z)?.line??null}function A5($,M,Z){let J=$.regionLineIndices.get(M);if(!J||J.length===0)return null;let X=J[0],Y=Number.POSITIVE_INFINITY;for(let Q of J){let K=$.lines[Q],q=Z<K.top?K.top-Z:Z>K.top+K.height?Z-(K.top+K.height):0;if(q<Y)Y=q,X=Q;if(q===0)break}return{index:X,line:$.lines[X]}}function O2($,M,Z){let J=$.regionLineIndices.get(M);if(!J||J.length===0)return null;let X=0,Y=J.length-1;while(X<=Y){let N=X+Y>>1,A=J[N],G=$.lines[A];if(Z<G.start){Y=N-1;continue}if(Z>G.end){X=N+1;continue}return{index:A,line:G}}let Q=J[0],K=J[J.length-1],q=$.lines[Q],U=$.lines[K];if(Z<=q.start)return{index:Q,line:q};if(Z>=U.end)return{index:K,line:U};return null}function eX($,M,Z){let J=[];for(let X=Z;X>=0;X-=1){let Y=$.lines[X];if(M<Y.top||M>=Y.top+Y.height)break;J.unshift({index:X,line:Y})}for(let X=Z+1;X<$.lines.length;X+=1){let Y=$.lines[X];if(M<Y.top||M>=Y.top+Y.height)break;J.push({index:X,line:Y})}return J}function G9($,M){if(!M)return Number.POSITIVE_INFINITY;if($<M.left)return M.left-$;if($>M.right)return $-M.right;return 0}function p0($,M){return $.left+$Y($.boundaries,M)}function E2($){let M=new Map,Z=(J)=>{for(let X of J)if(M.set(X.id,X),X.type==="blockquote"||X.type==="listItem")Z(X.children);else if(X.type==="list")Z(X.items)};return Z($),M}function $Y($,M){for(let J of $)if(J.offset===M)return J.left;return $.filter((J)=>J.offset<=M).at(-1)?.left??0}function B9($,M){let Z=0,J=$.lines.length;while(Z<J){let X=Z+J>>1,Y=$.lines[X];if(Y.top+Y.height<=M)Z=X+1;else J=X}return Z}function D9($,M){if($.length===0)return 0;for(let Z=1;Z<$.length;Z+=1){let J=$[Z-1],X=$[Z],Y=J.left+(X.left-J.left)/2;if(M<=Y)return J.offset;if(M<=X.left)return X.offset}return $.at(-1)?.offset??0}function G5($,M,Z,J,X){let Y=Z[J],Q=Z[J+1];if(!Y||!Q)return X;if(_9($,Y.blockId,Q.blockId,"list"))return dX;if(_9($,Y.blockId,Q.blockId,"blockquote"))return aX;if(Y.blockId===Q.blockId)return iX;return X+MY(M.get(Y.blockId))}function MY($){if($?.type!=="heading")return 0;if($.depth===1)return cX;return $.depth===2?xX:0}function _9($,M,Z,J){let X=F9($,M,J),Y=F9($,Z,J);for(let Q of X)if(Y.has(Q))return!0;return!1}function F9($,M,Z){let J=new Set,X=$.get(M)??null;while(X){if(X.type===Z)J.add(X.id);X=X.parentBlockId?$.get(X.parentBlockId)??null:null}return J}function $6($,M,Z,J=[],X=T1(),Y=null){let Q=Y??{images:new Map},K=E2($.document.blocks),q=new Map($.blocks.map((y)=>[y.id,y])),U=new Set(J),N=Math.max(0,Z.top-Z.overscan),A=Z.top+Z.height+Z.overscan,G=QY(X,$,K,q,M,Q),B=H9(G,N),F=H9(G,A);if(B>0){let y=G.entries[B-1];if(y&&y.bottom>N)B-=1}if(F<G.entries.length){let y=G.entries[F];if(y&&y.top<A)F+=1}for(let y of U){let R=G.containerIndices.get(y);if(R===void 0)continue;B=Math.min(B,R),F=Math.max(F,R+1)}if(!Number.isFinite(B)||!Number.isFinite(F))return{estimateRegionBounds:G.estimateRegionBounds,layout:N5({...$,regions:[]},M,X,Q),totalHeight:G.totalHeight,viewport:Z};let _=XY($,q,G.containerIndices,B,F),D=G.entries[_.startIndex]?.top??M.paddingY??0,T=N5({...$,regions:$.regions.slice(_.startIndex,_.endIndex)},M,X,Q),O=JY(T,D,G.totalHeight);return ZY(X,$,O,M,Q),{estimateRegionBounds:G.estimateRegionBounds,layout:O,totalHeight:G.totalHeight,viewport:Z}}function ZY($,M,Z,J,X){for(let[Y,Q]of Z.regionBounds){let K=Q.bottom-Q.top,q=M.regionIndex.get(Y);m$($,P9(q??{path:Y,inlines:[],text:""},J,X),K)}}function JY($,M,Z){return{...$,blocks:$.blocks.map((J)=>({...J,bottom:J.bottom+M,top:J.top+M})),regionBounds:new Map([...$.regionBounds.entries()].map(([J,X])=>[J,{bottom:X.bottom+M,left:X.left,right:X.right,top:X.top+M}])),height:Z,lines:$.lines.map((J)=>({...J,top:J.top+M}))}}function XY($,M,Z,J,X){let Y=J,Q=X;for(let K=J;K<X;K+=1){let q=$.regions[K],U=M.get(q.blockId);if(!U)continue;if(U.type==="table"){let N=Z.get(U.regionIds[0]??""),A=Z.get(U.regionIds[U.regionIds.length-1]??"");if(N!==void 0)Y=Math.min(Y,N);if(A!==void 0)Q=Math.max(Q,A+1)}}return{endIndex:Q,startIndex:Y}}function YY($,M,Z,J,X,Y){let Q=P9(M,X,Y),K=$.measuredContainerHeights.get(Q);if(K!==void 0)return K;let q=X.paddingX??0,U=X.indentWidth??24,N=y1(Z,X.lineHeight??24),A=q+J*U,G=Math.max(40,X.width-A-q);if(M.inlines.some((_)=>_.kind==="image")){let _=a1(Z);return i1($,M,_,Z,G,N,Y).reduce((D,T)=>D+T.height,0)}let B=U5({text:M.text,width:G});return Math.max(N,B.lineCount*N)}function QY($,M,Z,J,X,Y){let Q=NY(M,X,Y),K=u$($,M,Q);if(K)return K;let q=X.paddingY??0,U=[],N=new Map;for(let A=0;A<M.regions.length;A+=1){let G=M.regions[A],B=Z.get(G.blockId)??null;if(B?.type==="table"){let T=KY({block:B,blockMap:Z,containerIndices:N,entries:U,index:A,options:X,runtimeBlocks:J,totalHeight:q,regions:M.regions});if(T){A=T.nextIndex-1,q=T.totalHeight;continue}}let F=YY($,G,B,J.get(G.blockId)?.depth??0,X,Y),_=q,D=_+F;U.push({bottom:D,top:_}),N.set(G.id,A),q=D+G5(J,Z,M.regions,A,X.blockGap??16)}return v$($,M,Q,{containerIndices:N,entries:U,estimateRegionBounds(A){let G=N.get(A);return G===void 0?null:U[G]??null},totalHeight:q})}function KY({block:$,blockMap:M,containerIndices:Z,entries:J,index:X,options:Y,runtimeBlocks:Q,totalHeight:K,regions:q}){let U=Q.get($.id),N=U?.regionIds??[];if(N.length===0)return null;let A=q.slice(X,X+N.length);if(A.length===0||A[0]?.blockId!==$.id)return null;let G=Y.paddingX??0,B=Y.indentWidth??24,F=U?.depth??0,_=G+F*B,D=Math.max(o8,Y.width-_-G),T=Math.max(1,...$.rows.map((H)=>H.cells.length)),O=D/T,y=Math.max(40,O-w2*2),R=y1($,Y.lineHeight??24),C=qY(A,X),m=K;for(let H=0;H<$.rows.length;H+=1){let P=C.get(H)??[],E=Math.max(R+s1*2,...P.map(({region:W})=>UY(W,y,R)+s1*2)),j=m+E;for(let{index:W,region:b}of P)J[W]={bottom:j,top:m},Z.set(b.id,W);m=j}for(let H=X;H<X+A.length;H+=1){let P=q[H];if(!P||J[H])continue;J[H]={bottom:m,top:m},Z.set(P.id,H)}return{nextIndex:X+A.length,totalHeight:m+G5(Q,M,q,X+A.length-1,Y.blockGap??16)}}function qY($,M){let Z=new Map;for(let[J,X]of $.entries()){let Y=X.tableCellPosition?.rowIndex;if(Y===void 0)continue;let Q=Z.get(Y)??[];Q.push({index:M+J,region:X}),Z.set(Y,Q)}return Z}function UY($,M,Z){let J=U5({text:$.text,width:M});return Math.max(Z,J.lineCount*Z)}function NY($,M,Z){return[M.width,M.paddingX??0,M.paddingY??0,M.indentWidth??24,M.lineHeight??24,M.blockGap??16,AY($,Z)].join(":")}function H9($,M){let Z=0,J=$.entries.length;while(Z<J){let X=Z+J>>1;if($.entries[X].bottom<=M)Z=X+1;else J=X}return Z}function P9($,M,Z){return`${q5($,Z)}:${M.width}:${M.paddingX??0}:${M.indentWidth??24}:${M.lineHeight??24}`}function AY($,M){return $.regions.flatMap((Z)=>Z.inlines.filter((J)=>J.kind==="image"&&J.image).map((J)=>{let X=J.image?M.images.get(J.image.url):null;return`${J.image?.url??""}:${J.image?.width??0}:${X?.status??"loading"}:${X?.intrinsicWidth??0}:${X?.intrinsicHeight??0}`})).join("|")}var B5=null;function GY($){let M=/(\d+(?:\.\d+)?)\s*px/.exec($);return M?Number.parseFloat(M[1]):16}function Y1($){B5??=new Map;let M=B5.get($);if(M)return M;let Z=y9(),J=Math.max(12,Math.round(GY($)));if(!Z){let G={ascent:Math.round(J*0.8),descent:Math.max(2,J-Math.round(J*0.8)),emHeight:J};return B5.set($,G),G}Z.font=$;let X=Z.measureText("Hg"),Y=Math.round(X.actualBoundingBoxAscent||0),Q=Math.round(X.actualBoundingBoxDescent||0),K=Y+Q,q=Math.max(J,K),U=K>0?Y:Math.round(q*0.8),N=K>0?Q:Math.max(2,q-U),A={ascent:U,descent:N,emHeight:q};return B5.set($,A),A}function BY($,M){let{emHeight:Z}=Y1(M);return Math.max(0,Math.floor(($-Z)/2))}function z9($,M){let{ascent:Z}=Y1(M);return BY($,M)+Z}var _5;function T9($,M){let Z=y9();if(!Z||$.length===0)return 0;return Z.font=M,Z.measureText($).width}function y9(){if(_5!==void 0)return _5;return _5=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):typeof document<"u"?document.createElement("canvas"):null)?.getContext("2d")??null,_5}var _Y=18,FY=14,bY=22;function w0($,M,Z){let J=HY($,Z);if(!J)return null;return W9($,M,J,Z.x)}function M6($,M,Z){let J=$.lines[$.lines.length-1];if(!J||Z.y<=J.top+J.height)return null;return W9($,M,J,Z.x)}function W9($,M,Z,J){let X=$.regionMetrics.get(Z.regionId);if(!X)return null;let Y=Math.max(0,J-K1(M,Z)-Z.left),Q=D9(Z.boundaries,Y),K=Math.min(X.textLength,Z.start+Q);return{regionId:Z.regionId,offset:K,left:p0(Z,Q),top:Z.top,height:Z.height}}function Z6($,M,Z,J){let X=K6(M,J.regionId);if(!X)return null;let Y=w0($,M,Z);if(Y)return{regionId:Y.regionId,offset:Y.offset};let Q=Z.y<zY($);return{regionId:J.regionId,offset:Q?0:X.text.length}}function J6($,M,Z){let J=w0($,M,Z);if(!J)return null;let X=K6(M,J.regionId);if(!X||X.text.length===0)return null;let Y=J.offset<X.text.length&&/\w/.test(X.text[J.offset]??"")?J.offset:J.offset>0&&/\w/.test(X.text[J.offset-1]??"")?J.offset-1:J.offset,Q=TY(X.text,Y);if(Q.start===Q.end)return null;return{anchor:{regionId:J.regionId,offset:Q.start},focus:{regionId:J.regionId,offset:Q.end}}}function V9($,M,Z){let J=PY($,Z);if(!J||J.start!==0)return null;let X=o1(M,J.blockId,"listItem");if(!X)return null;if(j2(M,X.id)?.kind!=="task")return null;let Q=C2(J),K=Q.left-4,q=Q.left+Q.size+4,U=Q.top-4,N=Q.top+Q.size+4;return Z.x>=K&&Z.x<=q&&Z.y>=U&&Z.y<=N?{listItemId:X.id}:null}function w9($,M,Z){let J=w0($,M,Z);if(!J)return null;let X=K6(M,J.regionId);if(!X)return null;let Y=X.inlines.find((K)=>K.link&&J.offset>=K.start&&J.offset<K.end);if(!Y?.link)return null;let Q=Q6($,M,J.regionId,Y.start);if(!Q)return null;return{anchorBottom:Q.anchorBottom,anchorLeft:Q.anchorLeft,endOffset:Y.end,regionId:J.regionId,startOffset:Y.start,title:Y.link.title,url:Y.link.url}}function X6($,M,Z,J){let X=V9($,M,Z);if(X)return{kind:"task-toggle",listItemId:X.listItemId};let Y=w0($,M,Z);if(!Y)return null;let Q=O9(Y.regionId,Y.offset,J),K=Q!==null?E9(Q,$,M,J):null,q=w9($,M,Z);if(q)return{anchorBottom:K?.anchorBottom??q.anchorBottom,anchorLeft:K?.anchorLeft??q.anchorLeft,endOffset:q.endOffset,kind:"link",commentThreadIndex:Q,regionId:q.regionId,startOffset:q.startOffset,title:q.title,url:q.url};return{anchorBottom:K?.anchorBottom??Y.top+Y.height,anchorLeft:K?.anchorLeft??Y.left,kind:"text",commentThreadIndex:Q}}function Y6($,M,Z,J){let X=M.documentIndex.regionIndex.get(Z.regionId);if(!X)return null;let Y=O9(Z.regionId,Z.offset,J),Q=Y!==null?E9(Y,$,M,J):null,K=X.inlines.find((q)=>Z.offset>=q.start&&Z.offset<=q.end)??null;if(K?.link){let q=Q6($,M,Z.regionId,K.start);if(!q)return null;return{anchorBottom:Q?.anchorBottom??q.anchorBottom,anchorLeft:Q?.anchorLeft??q.anchorLeft,commentThreadIndex:Y,endOffset:K.end,kind:"link",regionId:Z.regionId,startOffset:K.start,title:K.link.title,url:K.link.url}}if(Q)return{anchorBottom:Q.anchorBottom,anchorLeft:Q.anchorLeft,commentThreadIndex:Y,kind:"text"};return null}function l0($,M,Z){let J=s0(M,Z.regionId,Z.offset);if(!J)return Z.left;return Z.left+K1($,J)+DY($,J,Z.offset)}function Q1($,M,Z){return p0(M,Z)+K1($,M)}function K1($,M){let Z=o1($,M.blockId,"listItem");if(!Z)return 0;return j2($,Z.id)?.kind==="task"?bY:_Y}function C2($){return{left:$.left,size:FY,top:$.top+3}}function o1($,M,Z){let J=$.documentIndex.blockIndex.get(M)??null;while(J){if(J.type===Z)return J;let X=J.parentBlockId;J=X?$.documentIndex.blockIndex.get(X)??null:null}return null}function j2($,M){return $.documentIndex.listItemMarkers.get(M)??null}function O9($,M,Z){for(let J of Z)if(J.regionId===$&&M>=J.startOffset&&M<=J.endOffset)return J.threadIndex;return null}function E9($,M,Z,J){let X=J.find((Y)=>Y.threadIndex===$);if(!X)return null;return Q6(M,Z,X.regionId,X.startOffset)}function Q6($,M,Z,J){let X=s0($,Z,J);if(!X)return null;return{anchorBottom:X.top+X.height,anchorLeft:p0(X,J)+K1(M,X)}}function DY($,M,Z){if(Z<=M.end)return 0;let J=$.documentIndex.regionIndex.get(M.regionId);if(!J)return 0;let X=J.text.slice(M.end,Z);if(!/^[ \t]+$/u.test(X))return 0;return T9(X,M.font)}function HY($,M){for(let[J,X]of $.regionBounds)if(M.x>=X.left&&M.x<=X.right&&M.y>=X.top&&M.y<=X.bottom)return A5($,J,M.y)?.line??null;let Z=t8($,M)?.line??null;if(Z)return Z;for(let J of $.blocks)if(M.y>=J.top&&M.y<=J.bottom){for(let X=$.lines.length-1;X>=0;X--)if($.lines[X].blockId===J.id)return $.lines[X]}return null}function PY($,M){return $.lines.find((Z)=>M.y>=Z.top-4&&M.y<=Z.top+Z.height+4)??$.lines.filter((Z)=>Math.abs(M.y-(Z.top+Z.height/2))<=10).sort((Z,J)=>Math.abs(M.y-(Z.top+Z.height/2))-Math.abs(M.y-(J.top+J.height/2)))[0]??null}function K6($,M){return $.documentIndex.regionIndex.get(M)??null}function zY($){return $.lines[0]?.top??0}function TY($,M){let Z=M,J=M;while(Z>0&&/\w/.test($[Z-1]??""))Z-=1;while(J<$.length&&/\w/.test($[J]??""))J+=1;return{end:J,start:Z}}function q6($,M,Z,J=null){let X={height:M.height,overscan:Math.max(160,M.height),top:M.top},Y=$6($.documentIndex,M,X,[$.selection.anchor.regionId,$.selection.focus.regionId],Z,J);return{blockMap:E2($.documentIndex.document.blocks),estimateRegionBounds:Y.estimateRegionBounds,regionBounds:new Map(Y.layout.regionBounds),layout:Y.layout,paintHeight:Math.max(240,X.height+X.overscan*2),paintTop:Math.max(0,X.top-X.overscan),totalHeight:Y.totalHeight,viewport:{height:X.height,top:X.top}}}function F5($,M,Z){return w0(M.layout,$,Z)??M6(M.layout,$,Z)}function R2($,M,Z,J){return Z6(M.layout,$,Z,J)}function U6($,M,Z){return J6(M.layout,$,Z)}function N6($,M,Z,J){return X6(M.layout,$,Z,J)}function A6($,M,Z,J){return Y6(M.layout,$,Z,J)}function G6($,M,Z){return I0(M.layout,$.documentIndex,Z)}function o0($,M,Z){let J=I0(M.layout,$.documentIndex,Z);if(!J)return null;return{...J,left:l0($,M.layout,J)}}function C9($,M,Z,J,X){let Y=J-Z,Q=X-Y;if(J<=$)return{end:M+Q,start:$+Q};if(Z>=M)return{end:M,start:$};let K=Math.max(0,Math.min(Z,M)-$),q=Math.max(0,M-Math.max(J,$)),U=$<Z?$:Z;return{end:U+K+X+q,start:U}}function _6($,M,Z){let J=Z.trim();if(J.length===0||M.startOffset===M.endOffset)return null;let X=$.regionIndex.get(M.regionId)??null,Y=X?B6($,X):null;if(!Y)return null;return R8({anchor:z2(Y,M.startOffset,M.endOffset),body:J,quote:T2(Y,M.startOffset,M.endOffset)})}function k0($){let M="documentIndex"in $?$.documentIndex:$,Z=b5(M),J=M.document.comments,X=[...J],Y=[];for(let[Q,K]of J.entries()){let q=y2(K,M.document);if(!q.match)continue;let N=Z.findBySemanticMatch(q.match.containerId,q.match.containerOrdinal)?.runtimeContainer??null;if(!N)continue;if(q.repair)X[Q]={...K,anchor:q.repair.anchor,quote:q.repair.quote};Y.push({endOffset:q.match.endOffset,resolution:q,regionId:N.id,resolved:K.resolvedAt!=null,startOffset:q.match.startOffset,threadIndex:Q})}return{liveRanges:Y,threads:X}}function F6($,M,Z,J,X,Y){if($.document.comments.length===0)return M.document.comments;let Q=$.commentContainerIndex.get(Z.semanticRegionId)??[],K=new Set(Q);if(Q.length===0)return M.document.comments;let q=k0($),U=new Map(q.liveRanges.map((B)=>[B.threadIndex,B])),N=B6($,Z),A=n1(M,Z.path),G=A?B6(M,A):null;if(!N||!G)return M.document.comments;return M.document.comments.map((B,F)=>{if(!K.has(F))return B;let _=U.get(F),D=_?.resolution.match??null;if(!_||!D||D.containerId!==N.id)return B;let T=C9(D.startOffset,D.endOffset,J,X,Y.length);return{...B,anchor:z2(G,T.start,T.end),quote:T2(G,T.start,T.end)}})}function B6($,M){let Z=yY($,M);if(!Z)return null;return{containerKind:Z,containerOrdinal:-1,id:M.semanticRegionId,text:M.text}}function yY($,M){if($.tableCellIndex.has(M.id))return"tableCell";return w$(M.blockType)}function D5($,M){if(M.length===0)return[];let Z=b5($),J=Z.list();return M.map((X)=>({...X,cursorPoint:WY(X,J,Z),viewport:null}))}function WY($,M,Z){if(!$.cursor)return null;let J=VY(M,$.cursor),X=wY(J,$.cursor);if(X.length!==1)return null;let Y=X[0],Q=Z.resolveRuntimeContainer(Y.container.id);if(!Q)return null;return{offset:Math.max(0,Math.min(Y.offset,Q.text.length)),regionId:Q.id}}function VY($,M){return M.kind?$.filter((Z)=>Z.containerKind===M.kind):$}function wY($,M){if(M.prefix&&M.suffix)return OY($,M.prefix,M.suffix);if(M.prefix)return j9($,M.prefix,"after");if(M.suffix)return j9($,M.suffix,"before");return[]}function j9($,M,Z){let J=[];for(let X of $)for(let Y of g0(X.text,M))J.push({container:X,offset:Z==="after"?Y+M.length:Y});return J}function OY($,M,Z){let J=[];for(let X of $)for(let Y of p1(X.text,M,Z))J.push({container:X,offset:Y.startOffset});return J}var EY=48;function L2($,M,Z){let J="documentIndex"in $?$.documentIndex:$;if(Z.length===0)return[];return Z.map((X)=>({...X,viewport:CY(J,M,X)}))}function CY($,M,Z){if(!Z.cursorPoint)return{status:"unresolved"};let J=I0(M.layout,$,Z.cursorPoint),X=J?{bottom:J.top+J.height,top:J.top}:M.estimateRegionBounds(Z.cursorPoint.regionId);if(!X)return{status:"unresolved"};return{scrollTop:RY(M,X),status:jY(M,X)}}function jY($,M){let Z=$.viewport.top,J=Z+$.viewport.height;if(M.bottom<Z)return"above";if(M.top>J)return"below";return"visible"}function RY($,M){let Z=Math.max(0,$.totalHeight-$.viewport.height),J=M.top-Math.min(EY,$.viewport.height/4);return Math.max(0,Math.min(Z,J))}function b5($){let M=J5($.document),Z=new Map(M.map((X)=>[X.id,X])),J=new Map($.regions.map((X)=>[X.semanticRegionId,X]));return{findBySemanticMatch(X,Y){let Q=Z.get(X)??M[Y]??null;if(!Q)return null;return{runtimeContainer:J.get(Q.id)??null,semanticContainer:Q}},list(X){return X?M.filter((Y)=>Y.containerKind===X):M},resolveRuntimeContainer(X){return J.get(X)??null}}}var k2="",R9=1e6;function f2($,M,Z){return`${$}:${M}:${Z}`}function K0($){let M=[];for(let Z of $){let J=M.at(-1);if(J?.type==="text"&&Z.type==="text"&&J.marks.join(",")===Z.marks.join(",")){M[M.length-1]=z0({marks:J.marks,path:J.id,text:J.text+Z.text});continue}M.push(Z)}return M}function t1($){let M=aY($),Z=D6(M.blocks.map((J,X)=>S2(J,X)));return H6(M,Z)}function S2($,M){let Z=[],J=[],X=[],Y=0;function Q(q,U,N,A,G=null){if(J.length>0)X.push(`
20
+ `),Y+=1;let B=N.map((D)=>D.text).join(""),F=Y,_=F+B.length;X.push(B),Y=_,J.push({blockId:q.id,blockType:q.type,end:_,id:`${q.id}:${U}`,path:U,rootIndex:M,inlines:N,semanticRegionId:A,start:F,tableCellPosition:G,text:B})}function K(q,U,N,A){let G={childBlockIds:[],depth:N,end:Y,id:q.id,parentBlockId:A,path:U,regionIds:[],rootIndex:M,start:Y,type:q.type};switch(Z.push(G),q.type){case"blockquote":case"listItem":for(let[B,F]of q.children.entries())G.childBlockIds.push(F.id),K(F,`${U}.children.${B}`,N+1,q.id);break;case"code":{Q(q,`${U}.source`,[{end:q.source.length,id:`${q.id}:code`,image:null,inlineCode:!1,kind:"text",link:null,marks:[],originalType:null,start:0,text:q.source}],q.id),G.regionIds.push(J.at(-1).id);break}case"heading":case"paragraph":Q(q,`${U}.children`,b6(q.children),q.id),G.regionIds.push(J.at(-1).id);break;case"list":for(let[B,F]of q.items.entries())G.childBlockIds.push(F.id),K(F,`${U}.children.${B}`,N+1,q.id);break;case"table":for(let[B,F]of q.rows.entries())for(let[_,D]of F.cells.entries())Q(q,`${U}.rows.${B}.cells.${_}`,b6(D.children),D.id,{cellIndex:_,rowIndex:B}),G.regionIds.push(J.at(-1).id);break;case"thematicBreak":break;case"directive":break;case"unsupported":Q(q,`${U}.source`,[{end:q.source.length,id:`${q.id}:unsupported`,image:null,inlineCode:!1,kind:"unsupported",link:null,marks:[],originalType:q.originalType,start:0,text:q.source}],q.id),G.regionIds.push(J.at(-1).id);break}G.end=Y}return K($,`root.${M}`,0,null),{blockRange:{end:Z.length,start:0},blocks:Z,end:Y,length:Y,regionRange:J.length>0?{end:J.length,start:0}:void 0,regions:J,rootIndex:M,start:0,text:X.join("")}}function D6($,M=null){let Z=[],J=0,X=0,Y=0,Q=!1;for(let[K,q]of $.entries()){if(q.regions.length>0&&Q)Y+=1;let U={...q,blockRange:{end:J+q.blocks.length,start:J},end:Y+q.length,regionRange:q.regions.length>0?{end:X+q.regions.length,start:X}:void 0,start:Y},N=M?.[K];if(Z.push(kY(N,q,U)?N:L9(q,U)),J=U.blockRange.end,X=U.regionRange?.end??X,q.regions.length>0)Y=U.end,Q=!0}return Z}function e1($,M,Z,J){let X=M.blocks.length-($.roots.length-J);if(X<0)throw Error("Editor model splice received an invalid replacement count.");if(Z===$.roots.length&&X===1){let q=M.blocks[Z];if(q)return LY($,M,q)}let Y=X===J,Q=[...$.roots.slice(0,Z),...M.blocks.slice(Z,Z+X).map((q,U)=>S2(q,Z+U)),...Y?$.roots.slice(Z+J):M.blocks.slice(Z+X).map((q,U)=>S2(q,Z+X+U))],K=D6(Q,$.roots);return H6(M,K,$)}function LY($,M,Z){let J=$.roots.length,X=S2(Z,J),Y=$.roots.some((N)=>N.regions.length>0),Q=X.regions.length>0&&Y?$.length+1:$.length,K=L9(X,{...X,blockRange:{end:$.blocks.length+X.blocks.length,start:$.blocks.length},end:Q+X.length,regionRange:X.regions.length>0?{end:$.regions.length+X.regions.length,start:$.regions.length}:void 0,start:Q}),q=[...$.blocks,...K.blocks],U=[...$.regions,...K.regions];return{blockIndex:vY($.blockIndex,K.blocks),blocks:q,commentContainerIndex:M.comments===$.document.comments?$.commentContainerIndex:k9(M),document:M,engine:"canvas",length:K.end,listItemMarkers:M.blocks===$.document.blocks?$.listItemMarkers:rY($.listItemMarkers,Z),regionIndex:hY($.regionIndex,K.regions),regionOrderIndex:gY($.regionOrderIndex,K.regions,$.regions.length),regionPathIndex:IY($.regionPathIndex,K.regions),regions:U,roots:[...$.roots,K],tableCellIndex:pY($.tableCellIndex,K.regions),tableCellRegionIndex:lY($.tableCellRegionIndex,K.regions),text:cY($.text,K)}}function u2($,M){if(M.blocks!==$.document.blocks)throw Error("Editor model document replacement requires preserving root blocks.");return H6(M,$.roots,$)}function H6($,M,Z=null){let J=M.flatMap((N)=>N.blocks),X=M.flatMap((N)=>N.regions),{regionIndex:Y,regionOrderIndex:Q,regionPathIndex:K,tableCellIndex:q,tableCellRegionIndex:U}=uY(X);return{blockIndex:SY(J),blocks:J,commentContainerIndex:$.comments===Z?.document.comments?Z.commentContainerIndex:k9($),document:$,engine:"canvas",length:M.at(-1)?.end??0,listItemMarkers:$.blocks===Z?.document.blocks?Z.listItemMarkers:dY($.blocks),regionIndex:Y,regionOrderIndex:Q,regionPathIndex:K,regions:X,roots:M,tableCellIndex:q,tableCellRegionIndex:U,text:xY(M)}}function L9($,M){let Z=M.start-$.start;return{...M,blocks:Z===0?$.blocks:fY($.blocks,Z),regions:Z===0?$.regions:mY($.regions,Z)}}function kY($,M,Z){return Boolean($&&M===$&&$.start===Z.start&&$.end===Z.end&&$.blockRange.start===Z.blockRange.start&&$.blockRange.end===Z.blockRange.end&&$.regionRange?.start===Z.regionRange?.start&&$.regionRange?.end===Z.regionRange?.end)}function fY($,M){return $.map((Z)=>({...Z,end:Z.end+M,start:Z.start+M}))}function mY($,M){return $.map((Z)=>({...Z,end:Z.end+M,start:Z.start+M}))}function SY($){let M=new Map;for(let Z of $)M.set(Z.id,Z);return M}function uY($){let M=new Map,Z=new Map,J=new Map,X=new Map,Y=new Map;for(let[Q,K]of $.entries()){if(M.set(K.id,K),Z.set(K.id,Q),J.set(K.path,K),!K.tableCellPosition)continue;X.set(K.id,K.tableCellPosition),Y.set(f2(K.blockId,K.tableCellPosition.rowIndex,K.tableCellPosition.cellIndex),K.id)}return{regionIndex:M,regionOrderIndex:Z,regionPathIndex:J,tableCellIndex:X,tableCellRegionIndex:Y}}function vY($,M){let Z=new Map($);for(let J of M)Z.set(J.id,J);return Z}function hY($,M){let Z=new Map($);for(let J of M)Z.set(J.id,J);return Z}function gY($,M,Z){let J=new Map($);for(let[X,Y]of M.entries())J.set(Y.id,Z+X);return J}function IY($,M){let Z=new Map($);for(let J of M)Z.set(J.path,J);return Z}function pY($,M){let Z=new Map($);for(let J of M)if(J.tableCellPosition)Z.set(J.id,J.tableCellPosition);return Z}function lY($,M){let Z=new Map($);for(let J of M){if(!J.tableCellPosition)continue;Z.set(f2(J.blockId,J.tableCellPosition.rowIndex,J.tableCellPosition.cellIndex),J.id)}return Z}function rY($,M){let Z=new Map($);return m2(Z,[M]),Z}function cY($,M){if(M.regions.length===0)return $;return $.length>0?`${$}
21
+ ${M.text}`:M.text}function xY($){return $.filter((M)=>M.regions.length>0).map((M)=>M.text).join(`
22
+ `)}function k9($){let M=new Map;for(let[Z,J]of $.comments.entries()){let X=y2(J,$).match?.containerId??null;if(!X)continue;let Y=M.get(X)??[];Y.push(Z),M.set(X,Y)}return M}function dY($){let M=new Map;return m2(M,$),M}function m2($,M,Z=null){for(let J of M){if(J.type==="list"){for(let[X,Y]of J.items.entries())m2($,[Y],{index:X,ordered:J.ordered,start:J.start});continue}if(J.type==="listItem"){if(typeof J.checked==="boolean")$.set(J.id,{checked:J.checked,kind:"task"});else if(Z?.ordered)$.set(J.id,{kind:"ordered",label:`${(Z.start??1)+Z.index}.`});else $.set(J.id,{kind:"bullet",label:"•"});m2($,J.children,Z)}if(J.type==="blockquote")m2($,J.children,Z)}}function aY($){if($.blocks.length>0)return $;return h1([p({text:""})],$.comments)}function b6($,M=null){let Z=[],J=0,X=(Y)=>{let Q=J,K=Q+Y.text.length;Z.push({...Y,end:K,start:Q}),J=K};for(let Y of $)switch(Y.type){case"break":X({id:Y.id,image:null,inlineCode:!1,kind:"break",link:M,marks:[],originalType:null,text:`
23
+ `});break;case"image":X({id:Y.id,image:{alt:Y.alt,title:Y.title,url:Y.url,width:Y.width},inlineCode:!1,kind:"image",link:M,marks:[],originalType:null,text:iY(Y.alt)});break;case"inlineCode":X({id:Y.id,image:null,inlineCode:!0,kind:"inlineCode",link:M,marks:[],originalType:null,text:Y.code});break;case"link":for(let Q of b6(Y.children,{title:Y.title,url:Y.url}))X(Q);break;case"text":X({id:Y.id,image:null,inlineCode:!1,kind:"text",link:M,marks:Y.marks,originalType:null,text:Y.text});break;case"unsupported":X({id:Y.id,image:null,inlineCode:!1,kind:"unsupported",link:M,marks:[],originalType:Y.originalType,text:Y.source});break}return Z}function iY($){return k2}function H5($,M){let Z=$.regionIndex.get(M);if(!Z)return null;let J=l1($.document.blocks,Z.blockId);if(!J)return null;return P5(J,Z.path,Z.semanticRegionId)}function m9($,M,Z,J,X){if(Z>=J)return null;let Y=H5($,M);return Y?X(Y,Z,J):null}function v2($,M,Z,J,X){let Y=m9($,M,Z,J,X);return Y?{kind:"replace-block",block:Y.block,blockId:Y.blockId,selection:Y.selection}:null}function P5($,M,Z){if($.type==="heading"||$.type==="paragraph")return{block:$,children:$.children,kind:"inlineBlock",path:M.replace(/\.children$/,"")};if($.type!=="table")return null;let J=/^(.*\.rows\.\d+\.cells\.\d+)$/.exec(M);if(!J)return null;for(let X of $.rows)for(let Y of X.cells)if(Y.id===Z)return{block:$,blockPath:J[1].replace(/\.rows\.\d+\.cells\.\d+$/,""),cell:Y,children:Y.children,kind:"tableCell",path:J[1]};return null}function q1($,M,Z,J){switch($.kind){case"inlineBlock":return{block:R0($.block,M),blockId:$.block.id,selection:f9(`${$.path}.children`,Z,J)};case"tableCell":{let X=M1({children:M,path:$.path}),Y=$.block.rows.map((Q)=>({...Q,cells:Q.cells.map((K)=>K.id===$.cell.id?X:K)}));return{block:h0($.block,Y),blockId:$.block.id,selection:f9($.path,Z,J)}}}}function f9($,M,Z){return{endOffset:Z,kind:"region-range-path",path:$,startOffset:M}}function H0($){switch($.type){case"break":return 1;case"image":return k2.length;case"inlineCode":return $.code.length;case"link":return A0($.children).length;case"text":return $.text.length;case"unsupported":return $.source.length}}function z5($,M,Z){if(M<=0)return[];return P6($,0,M,`${Z}.before`)}function T5($,M,Z){let J=H0($);if(M>=J)return[];return P6($,M,J,`${Z}.after`)}function P6($,M,Z,J){if(M>=Z)return[];switch($.type){case"text":return K0([W1($.text.slice(M,Z),$.marks,J)].filter(Boolean));case"inlineCode":return[T6($.code.slice(M,Z),J)];case"link":{let X=K0(sY($.children,M,Z,`${J}.children`));return X.length>0?[{...$,children:X}]:[]}default:return[]}}function z6($,M,Z){let J=0,X="";for(let Y of $){let Q=H0(Y),K=J,q=K+Q;if(J=q,Z<=K||M>=q)continue;X+=oY(Y,Math.max(0,M-K),Math.min(Q,Z-K))}return X}function W1($,M,Z){if($.length===0)return null;return z0({marks:M,path:Z,text:$})}function T6($,M){return m1({code:$,path:M})}function sY($,M,Z,J){let X=[],Y=0;for(let[Q,K]of $.entries()){let q=H0(K),U=Y,N=U+q;if(Y=N,Z<=U||M>=N)continue;X.push(...P6(K,Math.max(0,M-U),Math.min(q,Z-U),`${J}.${Q}`))}return X}function oY($,M,Z){if(M>=Z)return"";switch($.type){case"break":return`
24
+ `.slice(M,Z);case"image":return k2.slice(M,Z);case"inlineCode":return $.code.slice(M,Z);case"link":return z6($.children,M,Z);case"text":return $.text.slice(M,Z);case"unsupported":return $.source.slice(M,Z)}}function y6($,M,Z,J){let X=nY($.children,M,Z,J);if(X===null)return null;let Y=K0(S9($.children,M,Z,J,X,`${$.path}.children`));return Y.length>0?q1($,Y,M,Z):null}function W6($,M,Z){let J=0,X=null,Y=(Q)=>{for(let K of Q){let q=H0(K),U=J,N=U+q;if(J=N,Z<=U||M>=N)continue;if(K.type==="text"){let A=Math.max(M,U);if(Math.min(Z,N)>A)X=X===null?new Set(K.marks):new Set(K.marks.filter((B)=>X?.has(B)));continue}if(K.type==="link"){let A=J;J=U,Y(K.children),J=A}}};return Y($.children),X?[...X]:[]}function nY($,M,Z,J){let X=0,Y=!1,Q=!0,K=(q)=>{for(let U of q){let N=H0(U),A=X,G=A+N;if(X=G,Z<=A||M>=G)continue;if(U.type==="text"){let B=Math.max(M,A);if(Math.min(Z,G)>B)Y=!0,Q&&=U.marks.includes(J);continue}if(U.type==="link"){let B=X;X=A,K(U.children),X=B}}};return K($),Y?Q:null}function S9($,M,Z,J,X,Y){let Q=[],K=0;for(let[q,U]of $.entries()){let N=K,A=H0(U),G=N+A,B=`${Y}.${q}`;if(K=G,Z<=N||M>=G){Q.push(U);continue}if(U.type==="text"){Q.push(...tY(U,Math.max(0,M-N),Math.min(A,Z-N),J,X,B));continue}if(U.type==="link"){let F=K0(S9(U.children,Math.max(0,M-N),Math.min(A,Z-N),J,X,`${B}.children`));if(F.length>0)Q.push({...U,children:F});continue}Q.push(U)}return Q}function tY($,M,Z,J,X,Y){let Q=$.text.slice(0,M),K=$.text.slice(M,Z),q=$.text.slice(Z),U=X?$.marks.filter((N)=>N!==J):eY($.marks,J);return[W1(Q,$.marks,`${Y}.before`),W1(K,U,`${Y}.selected`),W1(q,$.marks,`${Y}.after`)].filter(Boolean)}function eY($,M){return $.includes(M)?$:[...$,M].sort()}function V6($,M,Z){let J=K0($Q($.children,M,Z,`${$.path}.children`));return J.length>0?q1($,J,M,Z):null}function $Q($,M,Z,J){let X=v9($,M,Z);if(X)return u9($,M,Z,X.code,J,!1);let Y=z6($,M,Z);if(Y.length===0)return $;return u9($,M,Z,Y,J,!0)}function v9($,M,Z){let J=0;for(let X of $){let Y=H0(X),Q=J,K=Q+Y;if(J=K,M===Q&&Z===K&&X.type==="inlineCode")return X;if(X.type==="link"){let q=v9(X.children,Math.max(0,M-Q),Math.min(Y,Z-Q));if(q)return q}}return null}function u9($,M,Z,J,X,Y){let Q=[],K=0,q=!1;for(let[U,N]of $.entries()){let A=`${X}.${U}`,G=H0(N),B=K,F=B+G;if(K=F,Z<=B||M>=F){Q.push(N);continue}if(!q){Q.push(...z5(N,Math.max(0,M-B),A));let _=Y?T6(J,`${X}.selected`):W1(J,[],`${X}.selected`);if(_)Q.push(_);q=!0}Q.push(...T5(N,Math.min(G,Z-B),A))}return Q}function y5($,M,Z,J,X){return v2($,M,Z,J,(Y,Q,K)=>h9(Y,Q,K,X))}function h9($,M,Z,J){let X=K0(MQ($.children,M,Z,J,`${$.path}.children`)??[]);return X.length>0?q1($,X,M,Z):null}function MQ($,M,Z,J,X){let Y=[],Q=0,K=!1;for(let[q,U]of $.entries()){let N=`${X}.${q}`,A=H0(U),G=Q,B=G+A;if(Q=B,!K&&U.type==="link"&&M===G&&Z===B){if(J===null)Y.push(...U.children);else Y.push(S1({children:U.children,path:N,title:U.title,url:J}));K=!0;continue}Y.push(U)}return K?Y:null}function w6($,M,Z){let J=K0(ZQ($.children,M,Z,`${$.path}.children`));return q1($,J,M+1,M+1)}function ZQ($,M,Z,J){let X=[],Y=0,Q=!1;for(let[K,q]of $.entries()){let U=`${J}.${K}`,N=H0(q),A=Y,G=A+N;if(Y=G,Z<=A||M>=G){X.push(q);continue}if(!Q)X.push(...z5(q,Math.max(0,M-A),U)),X.push(D2({path:`${J}.selected`})),Q=!0;X.push(...T5(q,Math.min(N,Z-A),U))}if(!Q)X.push(D2({path:`${J}.selected`}));return X}function $0($,M,Z=0){return{childIndices:M,kind:"descendant-primary-region",offset:Z,rootIndex:$}}function t($,M=0){return{kind:"root-primary-region",offset:M,rootIndex:$}}function U1($,M,Z,J=0){return{cellIndex:Z,kind:"table-cell",offset:J,rootIndex:$,rowIndex:M}}function n0($,M){return $.regionIndex.get(M)??null}function n1($,M){return $.regionPathIndex.get(M)??null}function $2($,M,Z,J){let X=$.tableCellRegionIndex.get(f2(M,Z,J));return X?$.regionIndex.get(X)??null:null}function JQ($){return $.anchor.regionId===$.focus.regionId&&$.anchor.offset===$.focus.offset}function s($,M){let Z="documentIndex"in $?$.documentIndex:$,J="documentIndex"in $?$.selection:M,X=JQ(J),Y=g9(Z,J.anchor),Q=g9(Z,J.focus);if(Y<=Q)return{collapsed:X,end:J.focus,start:J.anchor};return{collapsed:X,end:J.anchor,start:J.focus}}function h2($,M){if(!M)return null;if("kind"in M){if(M.kind==="root-primary-region"){let J=$.document.blocks[M.rootIndex],X=J?O6($,J):null;return X?W5(X.id,V5(X.text,M.offset)):null}if(M.kind==="descendant-primary-region"){let J=$.document.blocks[M.rootIndex],X=J?XQ(J,M.childIndices):null,Y=X?O6($,X):null;return Y?W5(Y.id,V5(Y.text,M.offset)):null}if(M.kind==="table-cell"){let J=$.document.blocks[M.rootIndex];if(!J||J.type!=="table")return null;let X=$2($,J.id,M.rowIndex,M.cellIndex);return X?W5(X.id,V5(X.text,M.offset)):null}let Z=n1($,M.path);if(!Z)return null;if(M.kind==="region-path")return W5(Z.id,V5(Z.text,M.offset));return{anchor:{regionId:Z.id,offset:Math.max(0,Math.min(M.startOffset,Z.text.length))},focus:{regionId:Z.id,offset:Math.max(0,Math.min(M.endOffset,Z.text.length))}}}return M}function g9($,M){let Z=$.regionOrderIndex.get(M.regionId);if(Z===void 0)throw Error(`Unknown canvas region: ${M.regionId}`);return Z*R9+M.offset}function W5($,M){let Z={offset:M,regionId:$};return{anchor:Z,focus:Z}}function V5($,M){return M==="end"?$.length:Math.max(0,Math.min(M,$.length))}function XQ($,M){let Z=$;for(let J of M){if(!Z)return null;let X=I9(Z);if(!X)return null;Z=X[J]??null}return Z}function O6($,M){let Z=$.blockIndex.get(M.id);if(!Z)return null;let J=Z.regionIds[0];if(J)return $.regionIndex.get(J)??null;let X=I9(M);if(!X)return null;for(let Y of X){let Q=O6($,Y);if(Q)return Q}return null}function I9($){switch($.type){case"list":return $.items;case"blockquote":case"listItem":return $.children;default:return null}}function g2($){let M=$.documentIndex.regionIndex.get($.selection.anchor.regionId)??null,Z=M?$.documentIndex.blockIndex.get(M.blockId)??null:null,J=$.selection.anchor.offset,X=M?.inlines.find((Y)=>J>Y.start&&J<Y.end)??M?.inlines.find((Y)=>Y.end===J)??M?.inlines.find((Y)=>Y.start===J)??null;return{block:Z?{blockId:Z.id,depth:Z.depth,nodeType:Z.type,text:M?.text??""}:null,span:X?.link?{kind:"link",url:X.link.url}:X&&X.marks.length>0?{kind:"marks",marks:X.marks}:{kind:"none"}}}function w5($){let M=s($.documentIndex,$.selection);if(M.start.regionId!==M.end.regionId||M.start.offset===M.end.offset)return[];let Z=$.documentIndex.regionIndex.get(M.start.regionId);if(!Z)return[];let J=l1($.documentIndex.document.blocks,Z.blockId);if(!J)return[];let X=P5(J,Z.path,Z.semanticRegionId);return X?W6(X,M.start.offset,M.end.offset):[]}function O5($,M,Z,J=null){return M2($,M,1,[Z],J)}function M2($,M,Z,J,X=null){return{document:g1($.document,M,Z,J),selection:X}}function E5($,M,Z,J=null){return I2($,M,()=>Z,J)}function I2($,M,Z,J=null){let X=$.blockIndex.get(M);if(!X)return null;let Y=$.document.blocks[X.rootIndex];if(!Y)return null;let Q=p9(Y,M,Z);return Q?M2($,X.rootIndex,1,[Q],J):null}function p9($,M,Z){if($.id===M)return Z($);switch($.type){case"blockquote":{let J=E6($.children,M,Z);return J?T0({children:J}):null}case"listItem":{let J=E6($.children,M,Z);return J?V0($,J):null}case"list":{let J=E6($.items,M,Z);return J?o($,J):null}default:return null}}function E6($,M,Z){let J=!1,X=$.map((Y)=>{let Q=p9(Y,M,Z);if(!Q)return Y;return J=!0,Q});return J?X:null}function j5($,M,Z){let J=s($,M);if(J.start.regionId===J.end.regionId)return YQ($,J,Z);return UQ($,J,Z)}function YQ($,M,Z){let J=n0($,M.start.regionId);if(!J)throw Error(`Unknown region: ${M.start.regionId}`);let X=I2($,J.blockId,(U)=>QQ(U,J,M.start.offset,M.end.offset,Z));if(!X)throw Error(`Failed to replace block for canvas region: ${J.id}`);let Y=e1($,X.document,J.rootIndex,1),Q=$.document.comments.length===0?Y:i9($,Y,J,M.start.offset,M.end.offset,Z),K=n1(Q,J.path);if(!K)throw Error(`Failed to remap region after replacement: ${J.path}`);let q=M.start.offset+Z.length;return{documentIndex:Q,selection:s9(K.id,q)}}function QQ($,M,Z,J,X){switch($.type){case"heading":case"paragraph":return KQ($,M,Z,J,X);case"code":return e4($,l9(M,Z,J,X));case"table":return qQ($,M,Z,J,X);case"unsupported":return $5($,l9(M,Z,J,X));default:throw Error(`Canvas text replacement is not supported for block type: ${$.type}`)}}function KQ($,M,Z,J,X){let Y=l2(M.inlines,Z,J,X),Q=R5(Y);return R0($,Q)}function qQ($,M,Z,J,X){let Y=M.tableCellPosition?.rowIndex,Q=M.tableCellPosition?.cellIndex;if(Y===void 0||Q===void 0)throw Error(`Unable to resolve table cell position for region: ${M.id}`);let K=l2(M.inlines,Z,J,X),q=R5(K),U=$.rows.map((N,A)=>{if(A!==Y)return N;let G=N.cells.map((B,F)=>{if(F!==Q)return B;return M1({children:q})});return{...N,cells:G}});return h0($,U)}function l9($,M,Z,J){return l2($.inlines,M,Z,J).map((X)=>X.text).join("")}function p2($){return $!==null&&($.type==="heading"||$.type==="paragraph")}function UQ($,M,Z){let J=n0($,M.start.regionId),X=n0($,M.end.regionId);if(!J||!X)throw Error("Unknown cross-region selection endpoints.");let Y=$.document.blocks[J.rootIndex],Q=$.document.blocks[X.rootIndex];if(!Y||!Q)throw Error("Unknown root blocks for cross-region selection.");let K=x9(Y,J,M.start.offset),q=d9(Q,X,M.end.offset),U=NQ(K,q,Z),N=U.blocks.length>0?U.blocks:[p({text:""})],A=J.rootIndex,G=X.rootIndex-J.rootIndex+1,B=g1($.document,A,G,N),F=e1($,B,A,G),_=$.document.comments.length===0?F:i9($,F,J,M.start.offset,J.text.length,p2(K)?Z:""),D=_.roots[A+U.caretLocalIndex]?.regions[0]??null;return{documentIndex:_,selection:s9(D?.id??J.id,D?U.caretOffset:0)}}function NQ($,M,Z){if(p2($)&&p2(M))return{blocks:[AQ($,M,Z)],caretLocalIndex:0,caretOffset:$.plainText.length+Z.length};if(p2($)){let Y=[Z.length>0?GQ($,Z):$];if(M)Y.push(M);return{blocks:Y,caretLocalIndex:0,caretOffset:$.plainText.length+Z.length}}if(p2(M)){let X=Z.length>0?BQ(M,Z):M,Y=[];if($)Y.push($);let Q=Y.length;return Y.push(X),{blocks:Y,caretLocalIndex:Q,caretOffset:Z.length}}let J=[];if($)J.push($);if(Z.length>0){let X=J.length;if(J.push(p({text:Z})),M)J.push(M);return{blocks:J,caretLocalIndex:X,caretOffset:Z.length}}if(M){let X=J.length;return J.push(M),{blocks:J,caretLocalIndex:X,caretOffset:0}}return{blocks:J,caretLocalIndex:0,caretOffset:0}}function AQ($,M,Z){let J=Z.length>0?[z0({text:Z})]:[];return R0($,K0([...$.children,...J,...M.children]))}function GQ($,M){return R0($,K0([...$.children,z0({text:M})]))}function BQ($,M){return R0($,K0([z0({text:M}),...$.children]))}function x9($,M,Z){if($.type==="table")return null;if($.id===M.blockId)return _Q($,M,Z);return a9($,(J)=>bQ(J,M,Z))}function d9($,M,Z){if($.type==="table")return null;if($.id===M.blockId)return FQ($,M,Z);return a9($,(J)=>DQ(J,M,Z))}function _Q($,M,Z){if(Z===0)return null;switch($.type){case"heading":case"paragraph":{let J=l2(M.inlines,Z,M.text.length,"");return R0($,R5(J))}case"code":return e4($,M.text.slice(0,Z));case"unsupported":return $5($,M.text.slice(0,Z));default:return null}}function FQ($,M,Z){if(Z===M.text.length)return null;switch($.type){case"heading":case"paragraph":{let J=l2(M.inlines,0,Z,"");return R0($,R5(J))}case"code":return e4($,M.text.slice(Z));case"unsupported":return $5($,M.text.slice(Z));default:return null}}function a9($,M){switch($.type){case"blockquote":{let Z=M($.children);return Z.length===0?null:T0({children:Z})}case"list":{let Z=M($.items);return Z.length===0?null:o($,Z)}case"listItem":{let Z=M($.children);return Z.length===0?null:V0($,Z)}default:return null}}function bQ($,M,Z){let J=$.findIndex((Q)=>C5(Q,M));if(J===-1)return[];let X=$.slice(0,J),Y=x9($[J],M,Z);return Y?[...X,Y]:X}function DQ($,M,Z){let J=$.findIndex((Q)=>C5(Q,M));if(J===-1)return[];let X=$.slice(J+1),Y=d9($[J],M,Z);return Y?[Y,...X]:X}function C5($,M){if($.id===M.blockId)return!0;switch($.type){case"blockquote":case"listItem":return $.children.some((Z)=>C5(Z,M));case"list":return $.items.some((Z)=>C5(Z,M));default:return!1}}function i9($,M,Z,J,X,Y){let Q=F6($,M,Z,J,X,Y);return Q===M.document.comments?M:u2(M,{...M.document,comments:Q})}function s9($,M){return{anchor:{regionId:$,offset:M},focus:{regionId:$,offset:M}}}function l2($,M,Z,J){let Y=HQ($,M,Z,{didInsert:!1,generatedRunCount:0,replacementText:J});return WQ(VQ(Y))}function R5($){let M=[];for(let Z=0;Z<$.length;Z+=1){let J=$[Z];if(J.link){let Y=[],Q=J.link;while(Z<$.length&&j6($[Z].link,Q)){let K=c9($[Z]);if(K)Y.push(K);Z+=1}if(Z-=1,Y.length>0)M.push(S1({children:K0(Y),title:Q.title,url:Q.url}));continue}let X=c9(J);if(X)M.push(X)}return K0(M)}function HQ($,M,Z,J){let X=[];for(let[Y,Q]of $.entries()){if(!J.didInsert&&M===Z&&M===Q.start)C6(X,J,r9($[Y-1]??null,Q));if(Z<=Q.start||M>=Q.end){X.push(L5(Q));continue}let K=Math.max(0,M-Q.start),q=Math.min(Q.text.length,Z-Q.start),U=!J.didInsert&&J.replacementText.length>0?J.replacementText:"",N=PQ(Q,K,q,U,J);if(K!==q||U.length>0)J.didInsert=!0;X.push(...N)}if(!J.didInsert)C6(X,J,r9($.at(-1)??null,null));return X}function PQ($,M,Z,J,X){switch($.kind){case"text":case"inlineCode":case"unsupported":return zQ($,M,Z,J);case"break":return TQ($,M,Z,J,X);case"image":return yQ($,M,Z,J)}}function zQ($,M,Z,J){let X=$.text.slice(0,M)+J+$.text.slice(Z);return X.length>0?[{...L5($),text:X}]:[]}function TQ($,M,Z,J,X){if(M===Z)return[L5($)];let Y=[];if(J.length>0)C6(Y,X,$.link);return Y}function yQ($,M,Z,J){if(M===0&&Z===$.text.length)return J.length>0?[o9(J,$.link,0)]:[];return[L5($)]}function C6($,M,Z){if(M.replacementText.length===0){M.didInsert=!0;return}$.push(o9(M.replacementText,Z,M.generatedRunCount)),M.generatedRunCount+=1,M.didInsert=!0}function o9($,M,Z){return{id:`generated:${Z}`,image:null,inlineCode:!1,kind:"text",link:M,marks:[],originalType:null,text:$}}function r9($,M){return $?.link&&M?.link&&j6($.link,M.link)?$.link:null}function L5($){return{id:$.id,image:$.image,inlineCode:$.inlineCode,kind:$.kind,link:$.link,marks:$.marks,originalType:$.originalType,text:$.text}}function WQ($){let M=[],Z=0;for(let J of $){let X=Z,Y=X+J.text.length;M.push({...J,end:Y,start:X}),Z=Y}return M}function VQ($){let M=[];for(let Z of $){let J=M.at(-1);if(J&&wQ(J,Z)){M[M.length-1]={...J,text:J.text+Z.text};continue}M.push(Z)}return M}function wQ($,M){return $.kind===M.kind&&$.inlineCode===M.inlineCode&&j6($.link,M.link)&&EQ($.image,M.image)&&$.originalType===M.originalType&&$.marks.join(",")===M.marks.join(",")}function c9($){switch($.kind){case"break":return D2();case"image":return $.image?OQ($.image):null;case"inlineCode":return m1({code:$.text});case"text":return $.text.length>0?z0({marks:$.marks,text:$.text}):null;case"unsupported":return o4({originalType:$.originalType??"unsupported",source:$.text})}}function OQ($){return s4({alt:$.alt,title:$.title,url:$.url,width:$.width})}function j6($,M){return $?.url===M?.url&&$?.title===M?.title}function EQ($,M){return $?.url===M?.url&&$?.title===M?.title&&$?.alt===M?.alt&&$?.width===M?.width}function n9($,M){switch(M.kind){case"replace-block":return E5($,M.blockId,M.block,M.selection??null);case"replace-root":return O5($,M.rootIndex,M.block,M.selection??null);case"replace-root-range":return M2($,M.rootIndex,M.count,M.replacements,M.selection??null);case"replace-selection":{let Z=j5($,M.selection,M.text);return{document:Z.documentIndex.document,documentIndex:Z.documentIndex,selection:Z.selection}}}return null}var R6=new Map([["rgba(0, 0, 0, 0)",[0,0,0,0]]]);function r2($){switch($.kind){case"active-block-flash":return 300;case"deleted-text-fade":return 180;case"inserted-text-highlight":return 1000;case"list-marker-pop":return 500;case"punctuation-pulse":return 140}}function k6($,M){let Z=M??jQ();return $.animations.some((J)=>Z-J.startedAt<r2(J))}function e9($,M){return f6($,M,"inserted-text-highlight",(Z)=>Z.regionPath)}function $7($,M){return N7($,M,"active-block-flash",(Z)=>Z.blockPath)}function M7($,M){return f6($,M,"deleted-text-fade",(Z)=>Z.regionPath)}function Z7($,M){return f6($,M,"punctuation-pulse",(Z)=>Z.regionPath)}function J7($,M){return N7($,M,"list-marker-pop",(Z)=>Z.blockPath)}function X7($,M,Z){let J=new Set([$,M]);for(let X of Z){if(X.endOffset<=$||X.startOffset>=M)continue;J.add(Math.max($,X.startOffset)),J.add(Math.min(M,X.endOffset))}return[...J].sort((X,Y)=>X-Y)}function Y7($,M,Z){return $.find((J)=>J.startOffset<Z&&J.endOffset>M)??null}function Q7($,M,Z){if(!M)return $;return x2(Z.insertHighlightText,$,M.progress)}function K7($,M){return x2($,"rgba(0, 0, 0, 0)",M.progress)}function f5($,M){return x2($,"rgba(0, 0, 0, 0)",M.progress)}function q7($,M){return x2(M.insertHighlightText,"rgba(0, 0, 0, 0)",$.progress)}function U7($){let M=Math.min(1,$.progress*2);return 0.1+0.9*CQ(M)}function c2($,M,Z){let J=Math.max(0,M.progress*2-1);return x2(Z.insertHighlightText,$,J)}function f6($,M,Z,J){let X=new Map;for(let Y of $.animations){if(Y.kind!==Z)continue;let Q=r2(Y),K=M-Y.startedAt;if(K>=Q)continue;let q={...Y,progress:Math.max(0,Math.min(1,K/Q))},U=J(Y),N=X.get(U);if(N)N.push(q);else X.set(U,[q])}return X}function N7($,M,Z,J){let X=new Map;for(let Y of $.animations){if(Y.kind!==Z)continue;let Q=r2(Y),K=M-Y.startedAt;if(K>=Q)continue;X.set(J(Y),{...Y,progress:Math.max(0,Math.min(1,K/Q))})}return X}function CQ($){return 1-(1-$)*(1-$)*(1-$)}function x2($,M,Z){let J=t9($),X=t9(M);return`rgba(${L6(k5(J[0],X[0],Z))}, ${L6(k5(J[1],X[1],Z))}, ${L6(k5(J[2],X[2],Z))}, ${k5(J[3],X[3],Z)})`}function jQ(){return typeof performance<"u"?performance.now():Date.now()}function t9($){let M=R6.get($);if(M)return M;let Z=RQ($)??LQ($)??kQ($)??R6.get("rgba(0, 0, 0, 0)");return R6.set($,Z),Z}function RQ($){let M=$.trim();if(!M.startsWith("#"))return null;let Z=M.slice(1);if(Z.length===3)return[Number.parseInt(`${Z[0]}${Z[0]}`,16),Number.parseInt(`${Z[1]}${Z[1]}`,16),Number.parseInt(`${Z[2]}${Z[2]}`,16),1];if(Z.length===6)return[Number.parseInt(Z.slice(0,2),16),Number.parseInt(Z.slice(2,4),16),Number.parseInt(Z.slice(4,6),16),1];return null}function LQ($){let M=/^rgb\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec($.trim());if(!M)return null;return[Number(M[1]),Number(M[2]),Number(M[3]),1]}function kQ($){let M=/^rgba\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec($.trim());if(!M)return null;return[Number(M[1]),Number(M[2]),Number(M[3]),Number(M[4])]}function k5($,M,Z){return $+(M-$)*Z}function L6($){return Math.round($)}function m5($,M,Z=N1()){if(M<=0)return $;let J=$.documentIndex.regionIndex.get($.selection.focus.regionId);if(!J)return $;let X=$.selection.focus.offset,Y=Math.max(0,X-M);if(X<=Y)return $;return d2($,{endOffset:X,kind:"inserted-text-highlight",regionPath:J.path,startOffset:Y,startedAt:Z})}function m6($,M,Z=N1()){if(M.text.length===0)return $;return d2($,{kind:"deleted-text-fade",regionPath:M.regionPath,startOffset:M.startOffset,startedAt:Z,text:M.text})}function S6($,M,Z=N1()){return d2($,{blockPath:M,kind:"active-block-flash",startedAt:Z})}function u6($,M=N1()){let Z=$.documentIndex.regionIndex.get($.selection.focus.regionId),J=$.selection.focus.offset-1;if(!Z||J<0||Z.text[J]!==".")return $;return d2($,{kind:"punctuation-pulse",offset:J,regionPath:Z.path,startedAt:M})}function v6($,M,Z=N1()){return d2($,{blockPath:M,kind:"list-marker-pop",startedAt:Z})}function d2($,M){let Z=S5($.animations,M.startedAt);return{...$,animations:[...Z,M]}}function S5($,M){return $.filter((Z)=>Z.startedAt+r2(Z)>M)}function N1(){return typeof performance<"u"?performance.now():Date.now()}function A7($){let M=$.documentIndex.regionIndex.get($.selection.focus.regionId);return(M?$.documentIndex.blockIndex.get(M.blockId)??null:null)?.path??""}function u5($,M){let Z=Math.max(-1/0,...$.animations.map((J)=>J.startedAt));return M.animations.some((J)=>J.startedAt>Z)}function a2($){let M=t1($),Z=B7(M);return{animations:[],documentIndex:M,future:[],history:[],selection:{anchor:Z,focus:Z}}}function i2($){let M=k0($.documentIndex);return h1(H2($.documentIndex.document.blocks),M.threads)}function a($,M){if(!M)return null;switch(M.kind){case"keep-state":return $;case"set-selection":return Z0($,M.selection);default:{let Z=n9($.documentIndex,M);if(!Z)return null;let J=fQ($,Z.document,Z.documentIndex??null),X=h2(J.documentIndex,Z.selection)??$.selection,Y=_7($,J,X);return Z0(J,X,Y)}}}function Z0($,M,Z){let J="regionId"in M?{anchor:v5($.documentIndex,M),focus:v5($.documentIndex,M)}:{anchor:v5($.documentIndex,M.anchor),focus:v5($.documentIndex,M.focus)},X={...$,selection:J};return Z??_7($,X)?S6(X,A7(X)):X}function O0($,M,Z,J){let X={regionId:M,offset:Z};return Z0($,J?{anchor:$.selection.anchor,focus:X}:X)}function fQ($,M,Z=null){let J=Z??t1(M);return{animations:S5($.animations,N1()),documentIndex:J,future:[],history:[...$.history,{document:$.documentIndex.document,selection:$.selection}],selection:mQ(J)}}function h6($){let M=$.history.at(-1);if(!M)return $;let Z=t1(M.document);return{animations:[],documentIndex:Z,future:[{document:$.documentIndex.document,selection:$.selection},...$.future],history:$.history.slice(0,-1),selection:M.selection}}function g6($){let M=$.future[0];if(!M)return $;let Z=t1(M.document);return{animations:[],documentIndex:Z,future:$.future.slice(1),history:[...$.history,{document:$.documentIndex.document,selection:$.selection}],selection:M.selection}}function h5($,M,Z,J){let X=P$($.documentIndex.document,M,Z,J),Y=u2($.documentIndex,X);return{animations:S5($.animations,N1()),documentIndex:Y,future:[],history:[...$.history,{document:$.documentIndex.document,selection:$.selection}],selection:$.selection}}function mQ($){let M=B7($);return{anchor:M,focus:M}}function B7($){return $.regions[0]?{regionId:$.regions[0].id,offset:0}:{regionId:"empty",offset:0}}function v5($,M){let Z=n0($,M.regionId);if(!Z)return M;return{regionId:Z.id,offset:Math.max(0,Math.min(M.offset,Z.text.length))}}function _7($,M,Z){let J=G7($.documentIndex,$.selection),X=G7(M.documentIndex,Z??M.selection);return X!==null&&X!==J}function G7($,M){let Z=$.regionIndex.get(M.focus.regionId),J=Z?$.blockIndex.get(Z.blockId)??null:null;if(!Z||!J?.path)return null;return J.type==="table"?`cell:${Z.path}`:`block:${J.path}`}function n2($,M){let Z=$.regionIndex.get(M.anchor.regionId);if(!Z)return{kind:"unsupported"};if(Z.blockType==="code"){let K=$.blockIndex.get(Z.blockId);return K?{kind:"code",region:Z,rootIndex:K.rootIndex}:{kind:"unsupported"}}let J=A1($,Z.id);if(J)return{kind:"tableCell",...J};let X=c0($,M);if(X)return{kind:"listItem",...X};let Y=Z2($,M);if(Y)return{kind:"blockquoteTextBlock",...Y};let Q=r0($,M);if(Q)return{kind:"rootTextBlock",...Q};return{kind:"unsupported"}}function t2($,M){let Z=$.blockIndex.get(M);if(!Z)throw Error(`Unknown root block: ${M}`);return Z.rootIndex}function g5($,M,Z){let J=M?$.blockIndex.get(M)??null:null;while(J){if(J.type===Z)return J;let X=J.parentBlockId;J=X?$.blockIndex.get(X)??null:null}return null}function s2($){let M=$.split("."),Z=[];for(let J=0;J<M.length-1;J+=1)if(M[J]==="children"){let X=Number(M[J+1]);if(Number.isInteger(X))Z.push(X)}return Z}function r0($,M){let Z=$.regionIndex.get(M.anchor.regionId);if(!Z)return null;let J=$.blockIndex.get(Z.blockId);if(!J)return null;let X=J.rootIndex,Y=$.document.blocks[X];if(!Y||Y.type!=="heading"&&Y.type!=="paragraph")return null;return{block:Y,region:Z,rootIndex:X}}function F7($,M){let Z=$.regionIndex.get(M.anchor.regionId);if(!Z)return null;let J=$.blockIndex.get(Z.blockId),X=g5($,J?.id??null,"blockquote");if(!X)return null;let Y=X.rootIndex,Q=$.document.blocks[Y];return Q?.type==="blockquote"?{quote:Q,rootIndex:Y}:null}function Z2($,M){let Z=$.regionIndex.get(M.anchor.regionId);if(!Z)return null;let J=$.blockIndex.get(Z.blockId),X=g5($,J?.id??null,"blockquote");if(!J||!X||J.parentBlockId!==X.id)return null;let Y=X.rootIndex,Q=$.document.blocks[Y];if(!Q||Q.type!=="blockquote")return null;let K=Q.children.findIndex((U)=>U.id===J.id),q=Q.children[K];if(!q||q.type!=="heading"&&q.type!=="paragraph")return null;return{block:q,blockChildIndices:s2(J.path),childIndex:K,region:Z,quote:Q,rootIndex:Y}}function o2($,M){return l1($.document.blocks,M)}function c0($,M){let Z=$.regionIndex.get(M.anchor.regionId);if(!Z)return null;let J=$.blockIndex.get(Z.blockId),X=g5($,J?.id??null,"listItem"),Y=g5($,J?.id??null,"list");if(!J||!X||!Y)return null;let Q=o2($,Y.id);if(!Q||Q.type!=="list")return null;let K=Q.items.findIndex((F)=>F.id===X.id),q=Q.items[K];if(!q)return null;let U=Y.parentBlockId?$.blockIndex.get(Y.parentBlockId)??null:null,N=U?.parentBlockId?$.blockIndex.get(U.parentBlockId)??null:null,A=U?.type==="listItem"?o2($,U.id):null,G=N?.type==="list"?o2($,N.id):null,B=G?.type==="list"&&A?G.items.findIndex((F)=>F.id===A.id):-1;return{region:Z,item:q,itemChildIndices:s2(X.path),itemIndex:K,list:Q,listChildIndices:s2(Y.path),parentItem:A?.type==="listItem"?A:null,parentItemChildIndices:U?.type==="listItem"?s2(U.path):null,parentItemIndex:B>=0?B:null,parentList:G?.type==="list"?G:null,parentListChildIndices:N?.type==="list"?s2(N.path):null,rootIndex:Y.rootIndex}}function A1($,M){let Z=$.regionIndex.get(M);if(!Z)return null;let J=$.tableCellIndex.get(Z.id),X=$.blockIndex.get(Z.blockId),Y=X?.type==="table"?$.document.blocks[X.rootIndex]:null;if(!J||!X||!Y||Y.type!=="table")return null;return{cellIndex:J.cellIndex,rootIndex:X.rootIndex,rowIndex:J.rowIndex,table:Y}}function e2($,M,Z){return d0({checked:M,children:[p({text:$})],spread:Z})}function J2($,M){let Z=$.children[0];if(!Z||Z.type!=="paragraph")return null;return V0($,[p({text:M}),...$.children.slice(1)])}function b7($,M){return M.reduce((Z,J)=>`${Z}.children.${J}`,`root.${$}`)}function D7($,M,Z){let J=$.regionIndex.get(M.anchor.regionId);if(!J)return null;let X=s($,M),Y=X.start.regionId===X.end.regionId&&X.start.regionId===J.id?J.text.slice(0,X.start.offset)+Z+J.text.slice(X.end.offset):Z;return SQ($,M,J.id,Y)??vQ($,M,J.id,Y)??uQ($,M,J.id,Y)??hQ($,M,J.id,Y)??pQ($,J.blockId,J.rootIndex,Y)??{kind:"replace-selection",selection:M,text:Z}}function SQ($,M,Z,J){let X=c0($,M),Y=cQ(J);if(!X||!Y||X.region.id!==Z)return null;let Q=J2(X.item,Y.text);if(!Q)return null;return{kind:"replace-block",block:o(X.list,X.list.items.map((K,q)=>q===X.itemIndex?Q:K),{ordered:Y.ordered,start:Y.ordered?1:null}),blockId:X.list.id,selection:$0(X.rootIndex,[...X.listChildIndices,X.itemIndex,0])}}function uQ($,M,Z,J){if(!p6($,M,Z))return null;if(/^\s*([-+*])\s\[( |x|X)\]\s$/.exec(J)){let Q=J.toLowerCase().includes("[x]");return I6($,M,{checked:Q,ordered:!1,start:null})}if(/^\s*[-+*]\s$/.test(J))return I6($,M,{checked:null,ordered:!1,start:null});let Y=/^\s*(\d+)\.\s$/.exec(J);if(Y)return I6($,M,{checked:null,ordered:!0,start:Number(Y[1])});return null}function vQ($,M,Z,J){let X=r0($,M),Y=xQ(J);if(!X||X.region.id!==Z||X.block.type!=="heading"||!Y)return null;return{kind:"replace-root",block:$1({depth:Y.depth,text:Y.text}),rootIndex:X.rootIndex,selection:t(X.rootIndex)}}function hQ($,M,Z,J){return gQ($,M,Z,J)??IQ($,M,Z,J)}function gQ($,M,Z,J){if(!p6($,M,Z))return null;let X=/^(#{1,6})\s$/.exec(J);if(!X)return null;return lQ($,M,X[1].length)}function IQ($,M,Z,J){if(!p6($,M,Z)||!/^>\s$/.test(J))return null;return rQ($,M)}function pQ($,M,Z,J){if(!/^(?:(?:-\s?){3}|(?:\*\s?){3}|(?:_\s?){3})$/.test(J))return null;return{kind:"replace-root-range",count:1,replacements:[n4(),p({text:""})],rootIndex:t2($,M),selection:t(Z+1)}}function I6($,M,Z){let J=t2($,$.regionIndex.get(M.anchor.regionId).blockId);return{kind:"replace-root",block:P1({items:[d0({checked:Z.checked,children:[p({text:""})],spread:!1})],ordered:Z.ordered,spread:!1,start:Z.start}),rootIndex:J,selection:$0(J,[0,0])}}function lQ($,M,Z){let J=t2($,$.regionIndex.get(M.anchor.regionId).blockId);return{kind:"replace-root",block:$1({depth:Z,text:""}),rootIndex:J,selection:t(J)}}function rQ($,M){let Z=t2($,$.regionIndex.get(M.anchor.regionId).blockId);return{kind:"replace-root",block:T0({children:[p({text:""})]}),rootIndex:Z,selection:$0(Z,[0])}}function p6($,M,Z){let J=r0($,M);return J?.region.id===Z&&J.block.type==="paragraph"}function cQ($){let M=/^[-+*]\s(.+)$/.exec($);if(M)return{ordered:!1,text:M[1]};let Z=/^\d+\.\s(.+)$/.exec($);if(Z)return{ordered:!0,text:Z[1]};return null}function xQ($){let M=/^(#{1,6})\s(.+)$/.exec($);return M?{depth:M[1].length,text:M[2]}:null}function H7($,M){let Z=s($,M);if(Z.start.regionId!==Z.end.regionId||Z.start.offset!==Z.end.offset)return null;let J=c0($,M);if(!J)return null;let X=J.region.text,Y=J.item,Q=typeof Y.checked==="boolean"?!1:Y.checked;if(Z.start.offset===0){let A=e2("",Q,Y.spread);return{kind:"replace-block",block:o(J.list,[...J.list.items.slice(0,J.itemIndex),A,Y,...J.list.items.slice(J.itemIndex+1)]),blockId:J.list.id,listItemInsertedPath:I5(A,J.rootIndex,[...J.listChildIndices,J.itemIndex]),selection:$0(J.rootIndex,[...J.listChildIndices,J.itemIndex,0])}}if(Z.start.offset===X.length){let A=e2("",Q,Y.spread);return{kind:"replace-block",block:o(J.list,[...J.list.items.slice(0,J.itemIndex+1),A,...J.list.items.slice(J.itemIndex+1)]),blockId:J.list.id,listItemInsertedPath:I5(A,J.rootIndex,[...J.listChildIndices,J.itemIndex+1]),selection:$0(J.rootIndex,[...J.listChildIndices,J.itemIndex+1,0])}}let K=X.slice(0,Z.start.offset),q=X.slice(Z.start.offset),U=e2(q,Q,Y.spread),N=V0(Y,[p({text:K})]);return{kind:"replace-block",block:o(J.list,[...J.list.items.slice(0,J.itemIndex),N,U,...J.list.items.slice(J.itemIndex+1)]),blockId:J.list.id,listItemInsertedPath:I5(U,J.rootIndex,[...J.listChildIndices,J.itemIndex+1]),selection:$0(J.rootIndex,[...J.listChildIndices,J.itemIndex+1,0])}}function P7($,M){let Z=s($,M),J=c0($,M);if(!J||Z.start.regionId!==Z.end.regionId)return null;if(Z.start.offset!==0||J.region.text.length!==0)return H7($,M);if(J.parentItem&&J.parentItemIndex!==null&&J.parentItemChildIndices&&J.parentList&&J.parentListChildIndices)return dQ(J);let X=J.list.items.slice(0,J.itemIndex),Y=J.list.items.slice(J.itemIndex+1),Q=[];if(X.length>0)Q.push(o(J.list,X));if(Q.push(p({text:""})),Y.length>0)Q.push(o(J.list,Y));return{kind:"replace-root-range",count:1,replacements:Q,rootIndex:J.rootIndex,selection:t(J.rootIndex+(X.length>0?1:0))}}function z7($,M){let Z=c0($,M);if(!Z)return null;if(typeof Z.item.checked==="boolean"){let J=d0({checked:null,children:Z.item.children,spread:Z.item.spread});return{kind:"replace-block",block:o(Z.list,Z.list.items.map((X,Y)=>Y===Z.itemIndex?J:X)),blockId:Z.list.id}}if(Z.itemIndex>0){let J=Z.list.items[Z.itemIndex-1];if(!J)return null;if(Z.item.plainText.length===0)return{kind:"replace-block",block:o(Z.list,Z.list.items.filter((Y,Q)=>Q!==Z.itemIndex)),blockId:Z.list.id,selection:$0(Z.rootIndex,[...Z.listChildIndices,Z.itemIndex-1,0],"end")};let X=J2(J,`${J.plainText}${Z.item.plainText}`);if(!X)return null;return{kind:"replace-block",block:o(Z.list,Z.list.items.flatMap((Y,Q)=>{if(Q===Z.itemIndex-1)return[X];if(Q===Z.itemIndex)return[];return[Y]})),blockId:Z.list.id,selection:$0(Z.rootIndex,[...Z.listChildIndices,Z.itemIndex-1,0],"end")}}return{kind:"replace-root-range",count:1,replacements:[p({text:Z.item.plainText})],rootIndex:Z.rootIndex,selection:t(Z.rootIndex)}}function T7($,M){let Z=c0($,M);if(!Z||Z.itemIndex===0)return null;let J=Z.list.items[Z.itemIndex-1];if(!J)return null;let X=aQ(J,Z.item,Z);return{kind:"replace-block",block:o(Z.list,Z.list.items.flatMap((Y,Q)=>{if(Q===Z.itemIndex-1)return[X.item];if(Q===Z.itemIndex)return[];return[Y]})),blockId:Z.list.id,selection:$0(Z.rootIndex,X.regionChildIndices)}}function y7($,M){let Z=c0($,M);if(!Z||!Z.parentItem||Z.parentItemIndex===null||!Z.parentItemChildIndices||!Z.parentList||!Z.parentListChildIndices)return null;let J=Z.list.items.filter((Q,K)=>K!==Z.itemIndex),X=Z.parentItem.children.flatMap((Q)=>{if(Q.type!=="list"||Q.id!==Z.list.id)return[Q];if(J.length===0)return[];return[o(Z.list,J)]}),Y=V0(Z.parentItem,X);return{kind:"replace-block",block:o(Z.parentList,[...Z.parentList.items.slice(0,Z.parentItemIndex),Y,Z.item,...Z.parentList.items.slice(Z.parentItemIndex+1)]),blockId:Z.parentList.id,selection:$0(Z.rootIndex,[...Z.parentListChildIndices,Z.parentItemIndex+1,0])}}function l6($,M,Z){let J=c0($,M);if(!J)return null;let X=J.itemIndex+Z;if(X<0||X>=J.list.items.length)return null;let Y=[...J.list.items],[Q]=Y.splice(J.itemIndex,1);if(!Q)return null;return Y.splice(X,0,Q),{kind:"replace-block",block:o(J.list,Y),blockId:J.list.id,selection:$0(J.rootIndex,[...J.listChildIndices,X,0])}}function dQ($){if(!$.parentItem||$.parentItemIndex===null||!$.parentItemChildIndices||!$.parentList||!$.parentListChildIndices)return null;let M=$.list.items.filter((Q,K)=>K!==$.itemIndex),Z=$.parentItem.children.flatMap((Q)=>{if(Q.type!=="list"||Q.id!==$.list.id)return[Q];if(M.length===0)return[];return[o($.list,M)]}),J=V0($.parentItem,Z),X=typeof $.parentItem.checked==="boolean"?!1:$.parentItem.checked,Y=e2("",X,$.parentItem.spread);return{kind:"replace-block",block:o($.parentList,[...$.parentList.items.slice(0,$.parentItemIndex),J,Y,...$.parentList.items.slice($.parentItemIndex+1)]),blockId:$.parentList.id,listItemInsertedPath:I5(Y,$.rootIndex,[...$.parentListChildIndices,$.parentItemIndex+1]),selection:$0($.rootIndex,[...$.parentListChildIndices,$.parentItemIndex+1,0])}}function I5($,M,Z){return typeof $.checked==="boolean"?void 0:b7(M,Z)}function aQ($,M,Z){let J=$.children.findIndex((Y)=>Y.type==="list"&&Y.ordered===Z.list.ordered&&Y.start===Z.list.start);if(J>=0){let Y=$.children[J];if(!Y||Y.type!=="list")return{item:$,regionChildIndices:[...Z.listChildIndices,Z.itemIndex-1,0]};return{item:V0($,$.children.map((Q,K)=>K===J?o(Y,[...Y.items,M]):Q)),regionChildIndices:[...Z.listChildIndices,Z.itemIndex-1,J,Y.items.length,0]}}let X=P1({items:[M],ordered:Z.list.ordered,spread:Z.list.spread,start:Z.list.start});return{item:V0($,[...$.children,X]),regionChildIndices:[...Z.listChildIndices,Z.itemIndex-1,$.children.length,0,0]}}function p5($,M){let Z=s($,M);if(Z.start.regionId!==Z.end.regionId||Z.start.offset!==Z.end.offset)return null;let J=r0($,M);if(!J)return iQ($,M);let X=J.region.text.slice(0,Z.start.offset),Y=J.region.text.slice(Z.start.offset),Q=Z.start.offset===0&&J.region.text.length>0?J.rootIndex:J.rootIndex+1;if(J.block.type==="paragraph")return{kind:"replace-root-range",count:1,replacements:Z.start.offset===0?[p({text:""}),J.block]:Z.start.offset===J.region.text.length?[J.block,p({text:""})]:[p({text:X}),p({text:Y})],rootIndex:J.rootIndex,selection:t(Q)};return{kind:"replace-root-range",count:1,replacements:Z.start.offset===0?[p({text:""}),J.block]:Z.start.offset===J.region.text.length?[J.block,p({text:""})]:[$1({depth:J.block.depth,text:X}),p({text:Y})],rootIndex:J.rootIndex,selection:t(Q)}}function iQ($,M){let Z=s($,M);if(Z.start.regionId!==Z.end.regionId||Z.start.offset!==Z.end.offset)return null;let J=Z2($,M);if(!J)return null;let X=J.region.text,Y=X.slice(0,Z.start.offset),Q=X.slice(Z.start.offset),K=J.block.type==="heading"?$K(J.block,Y,Q,J.blockChildIndices,Z.start.offset,X.length):eQ(J.block,Y,Q,J.blockChildIndices,Z.start.offset,X.length);return{kind:"replace-root",block:T0({children:[...J.quote.children.slice(0,J.childIndex),...K.blocks,...J.quote.children.slice(J.childIndex+1)]}),rootIndex:J.rootIndex,selection:$0(J.rootIndex,K.focusChildIndices)}}function W7($,M){let Z=s($,M);if(Z.start.regionId!==Z.end.regionId||Z.start.offset!==0||Z.end.offset!==0)return null;let J=Z2($,M);if(!J||J.region.text.length!==0||J.block.type!=="paragraph")return null;let X=J.quote.children.slice(0,J.childIndex),Y=J.quote.children.slice(J.childIndex+1),Q=[];if(X.length>0)Q.push(T0({children:X}));if(Q.push(p({text:""})),Y.length>0)Q.push(T0({children:Y}));return{kind:"replace-root-range",count:1,replacements:Q,rootIndex:J.rootIndex,selection:t(J.rootIndex+(X.length>0?1:0))}}function V7($,M){let Z=s($,M);if(Z.start.regionId!==Z.end.regionId||Z.start.regionId!==M.anchor.regionId)return null;let J=$.regionIndex.get(Z.start.regionId);if(!J||J.blockType!=="code")return null;return{kind:"replace-selection",selection:M,text:`
25
+ `}}function w7($,M){let Z=s($,M);if(Z.start.regionId!==Z.end.regionId||Z.start.offset!==0||Z.end.offset!==0)return null;let J=r0($,M),X=J?nQ(J):null;if(X)return X;if(J&&J.rootIndex>0){let q=$.document.blocks[J.rootIndex-1],U=$.document.blocks[J.rootIndex+1];if(q){if(J.block.plainText.length===0){let N=sQ(J,q,U);if(N)return N;return{kind:"replace-root-range",count:1,replacements:[],rootIndex:J.rootIndex,selection:q.type==="paragraph"||q.type==="heading"?t(J.rootIndex-1,"end"):q.type==="list"?$0(J.rootIndex-1,[q.items.length-1,0],"end"):q.type==="blockquote"?$0(J.rootIndex-1,[q.children.length-1],"end"):t(J.rootIndex-1,"end")}}if(q.type==="paragraph")return{kind:"replace-root-range",count:2,replacements:[p({text:`${q.plainText}${J.block.plainText}`})],rootIndex:J.rootIndex-1,selection:t(J.rootIndex-1,"end")};if(q.type==="heading")return{kind:"replace-root-range",count:2,replacements:[$1({depth:q.depth,text:`${q.plainText}${J.block.plainText}`})],rootIndex:J.rootIndex-1,selection:t(J.rootIndex-1,"end")};if(q.type==="list"){let N=q.items.length-1,A=q.items[N];if(A){let G=J2(A,`${A.plainText}${J.block.plainText}`);if(G)return{kind:"replace-root-range",count:2,replacements:[o(q,q.items.map((B,F)=>F===N?G:B))],rootIndex:J.rootIndex-1,selection:$0(J.rootIndex-1,[N,0],"end")}}}}}let Y=tQ($,M);if(Y)return Y;let Q=F7($,M);if(!Q)return null;let K=Z2($,M);return{kind:"replace-root-range",count:1,replacements:Q.quote.children,rootIndex:Q.rootIndex,selection:t(K?Q.rootIndex+K.childIndex:Q.rootIndex)}}function r6($,M,Z){let J=r0($,M);if(!J||J.block.type!=="heading")return null;let X=Math.max(1,Math.min(6,J.block.depth+Z));if(X===J.block.depth)return{kind:"keep-state"};return{kind:"replace-root",block:$1({depth:X,text:J.block.plainText}),rootIndex:J.rootIndex,selection:t(J.rootIndex,M.focus.offset)}}function sQ($,M,Z){if($.block.type!=="paragraph"||$.block.plainText.length!==0||M.type!=="list"||Z?.type!=="list"||!oQ(M,Z))return null;let J=M.items.length-1;return{kind:"replace-root-range",count:3,replacements:[o(M,[...M.items,...Z.items])],rootIndex:$.rootIndex-1,selection:$0($.rootIndex-1,[J,0],"end")}}function oQ($,M){return $.ordered===M.ordered&&$.start===M.start}function nQ($){if($.block.type!=="heading")return null;return{kind:"replace-root",block:p({text:$.block.plainText}),rootIndex:$.rootIndex,selection:t($.rootIndex)}}function tQ($,M){let Z=s($,M);if(Z.start.regionId!==Z.end.regionId||Z.start.offset!==0||Z.end.offset!==0)return null;let J=Z2($,M);if(!J||J.block.type!=="paragraph"||J.region.text.length!==0)return null;if(J.quote.children.length===1)return{kind:"replace-root-range",count:1,replacements:[p({text:""})],rootIndex:J.rootIndex,selection:t(J.rootIndex)};let X=Math.max(0,J.childIndex-1),Y=J.childIndex>0?"end":0;return{kind:"replace-root",block:T0({children:J.quote.children.filter((Q,K)=>K!==J.childIndex)}),rootIndex:J.rootIndex,selection:$0(J.rootIndex,[X],Y)}}function eQ($,M,Z,J,X,Y){return{blocks:X===0?[p({text:""}),$]:X===Y?[$,p({text:""})]:[p({text:M}),p({text:Z})],focusChildIndices:X===0?J:[...J.slice(0,-1),J.at(-1)+1]}}function $K($,M,Z,J,X,Y){return{blocks:X===0?[p({text:""}),$]:X===Y?[$,p({text:""})]:[$1({depth:$.depth,text:M}),p({text:Z})],focusChildIndices:X===0?J:[...J.slice(0,-1),J.at(-1)+1]}}function O7($,M,Z){let J=r0($,M),X=Math.max(2,Z);if(!J||J.block.type!=="paragraph"||J.block.plainText.length>0||M.anchor.regionId!==M.focus.regionId||M.anchor.offset!==0||M.focus.offset!==0)return null;return{kind:"replace-root",block:z1({rows:Array.from({length:2},()=>x6(X))}),rootIndex:J.rootIndex,selection:U1(J.rootIndex,0,0)}}function c6($,M,Z){let J=A1($,M.focus.regionId);if(!J)return null;let X=Z<0?XK(J.table,J.rowIndex,J.cellIndex):YK(J.table,J.rowIndex,J.cellIndex);if(!X)return Z>0&&QK(J.table,J.rowIndex,J.cellIndex)?MK(J):{kind:"keep-state"};let Y=J.table.rows[X.rowIndex]?.cells[X.cellIndex];if(!Y)return{kind:"keep-state"};return{kind:"set-selection",selection:JK($,M,J.table,X.rowIndex,X.cellIndex,Math.min(M.focus.offset,Y.plainText.length))}}function E7($,M){let Z=H5($,M.focus.regionId);if(!Z||Z.kind!=="tableCell")return null;let J=Math.min(M.anchor.offset,M.focus.offset),X=Math.max(M.anchor.offset,M.focus.offset),Y=w6(Z,J,X);return{kind:"replace-block",block:Y.block,blockId:Y.blockId,selection:Y.selection}}function C7($,M,Z){let J=A1($,M.focus.regionId);if(!J)return null;let X=Z==="left"?J.cellIndex:J.cellIndex+1;return X2(J,z1({align:m7(J.table.align,X,0,[null]),rows:J.table.rows.map((Y)=>u1({cells:ZK(Y.cells,X,0,[f7()])}))}),U1(J.rootIndex,J.rowIndex,X))}function j7($,M){let Z=A1($,M.focus.regionId);if(!Z)return null;let J=Math.max(0,...Z.table.rows.map((X)=>X.cells.length));if(J<=1)return null;return X2(Z,z1({align:m7(Z.table.align,Z.cellIndex,1,[]),rows:Z.table.rows.map((X)=>u1({cells:X.cells.filter((Y,Q)=>Q!==Z.cellIndex)}))}),U1(Z.rootIndex,Z.rowIndex,Math.min(Z.cellIndex,J-2)))}function R7($,M,Z){let J=A1($,M.focus.regionId);if(!J)return null;let X=Z==="above"?J.rowIndex:J.rowIndex+1,Y=Math.max(1,...J.table.rows.map((Q)=>Q.cells.length));return X2(J,h0(J.table,[...J.table.rows.slice(0,X),x6(Y),...J.table.rows.slice(X)]),U1(J.rootIndex,X,Math.min(J.cellIndex,Y-1)))}function L7($,M){let Z=A1($,M.focus.regionId);if(!Z||Z.table.rows.length<=1)return null;let J=Z.table.rows.filter((Q,K)=>K!==Z.rowIndex),X=Math.min(Z.rowIndex,J.length-1),Y=J[X]?.cells.length??1;return X2(Z,h0(Z.table,J),U1(Z.rootIndex,X,Math.min(Z.cellIndex,Y-1)))}function k7($,M){let Z=A1($,M.focus.regionId);if(!Z)return null;return X2(Z,p({text:""}),t(Z.rootIndex))}function x6($){return u1({cells:Array.from({length:$},()=>f7())})}function f7(){return M1({children:[]})}function MK($){let M=$.table.rows.length,Z=Math.max(1,...$.table.rows.map((J)=>J.cells.length));return X2($,h0($.table,[...$.table.rows,x6(Z)]),U1($.rootIndex,M,0))}function X2($,M,Z){return{kind:"replace-block",block:M,blockId:$.table.id,selection:Z}}function ZK($,M,Z,J){return[...$.slice(0,M),...J,...$.slice(M+Z)]}function m7($,M,Z,J){return[...$.slice(0,M),...J,...$.slice(M+Z)]}function JK($,M,Z,J,X,Y){let Q=$2($,Z.id,J,X);if(!Q)return M;return{anchor:{regionId:Q.id,offset:Y},focus:{regionId:Q.id,offset:Y}}}function XK($,M,Z){if(Z>0)return{cellIndex:Z-1,rowIndex:M};if(M>0){let J=$.rows[M-1];if(!J||J.cells.length===0)return null;return{cellIndex:J.cells.length-1,rowIndex:M-1}}return null}function YK($,M,Z){let J=$.rows[M];if(!J)return null;if(Z+1<J.cells.length)return{cellIndex:Z+1,rowIndex:M};let X=$.rows[M+1];if(!X||X.cells.length===0)return null;return{cellIndex:0,rowIndex:M+1}}function QK($,M,Z){let J=$.rows[M];return Boolean(J&&M===$.rows.length-1&&Z===J.cells.length-1)}function Y2($,M){let Z=D7($.documentIndex,$.selection,M),J=a($,Z);if(!J)return null;if(Z?.kind==="replace-selection"&&M.length>0)J=m5(J,M.length);if(M===".")J=u6(J);return J}function $4($){switch(n2($.documentIndex,$.selection).kind){case"code":return a($,V7($.documentIndex,$.selection));case"tableCell":return a($,E7($.documentIndex,$.selection));case"listItem":{let Z=P7($.documentIndex,$.selection);return UK({state:a($,Z)??a($,p5($.documentIndex,$.selection)),action:Z})}case"blockquoteTextBlock":return a($,W7($.documentIndex,$.selection))??a($,p5($.documentIndex,$.selection));case"rootTextBlock":return a($,p5($.documentIndex,$.selection));case"unsupported":return null}}function l5($){if(u7($))return M4($);let M=NK($);if(M)return M;let Z=s($.documentIndex,$.selection);if(Z.start.regionId!==Z.end.regionId||Z.start.offset!==0||Z.end.offset!==0)return null;switch(n2($.documentIndex,$.selection).kind){case"listItem":return a($,z7($.documentIndex,$.selection));case"blockquoteTextBlock":case"rootTextBlock":return a($,w7($.documentIndex,$.selection));default:return null}}function r5($){if(u7($))return M4($);return AK($)}function d6($,M){return a($,{kind:"replace-selection",selection:$.selection,text:M})}function c5($,M){let Z=d6($,M);return M.length>0?m5(Z,M.length):Z}function M4($){return d6($,"")}function a6($){let M=$.documentIndex.regions,Z=M[0],J=M.at(-1);if(!Z||!J)return $;return Z0($,{anchor:{regionId:Z.id,offset:0},focus:{regionId:J.id,offset:J.text.length}})}function i6($){switch(n2($.documentIndex,$.selection).kind){case"tableCell":return a($,c6($.documentIndex,$.selection,1));case"rootTextBlock":return a($,r6($.documentIndex,$.selection,1));case"listItem":return KK($);default:return null}}function s6($){switch(n2($.documentIndex,$.selection).kind){case"tableCell":return a($,c6($.documentIndex,$.selection,-1));case"rootTextBlock":return a($,r6($.documentIndex,$.selection,-1));case"listItem":return qK($);default:return null}}function KK($){return a($,T7($.documentIndex,$.selection))}function qK($){return a($,y7($.documentIndex,$.selection))}function o6($){return a($,l6($.documentIndex,$.selection,-1))}function n6($){return a($,l6($.documentIndex,$.selection,1))}function t6($,M){return a($,O7($.documentIndex,$.selection,M))}function e6($,M){return a($,C7($.documentIndex,$.selection,M))}function $3($){return a($,j7($.documentIndex,$.selection))}function M3($,M){return a($,R7($.documentIndex,$.selection,M))}function Z3($){return a($,L7($.documentIndex,$.selection))}function J3($){return a($,k7($.documentIndex,$.selection))}function x5($,M){return S7($,(Z,J,X)=>y6(Z,J,X,M))}function X3($){return S7($,(M,Z,J)=>V6(M,Z,J))}function Z4($){return x5($,"bold")}function J4($){return x5($,"italic")}function X4($){return x5($,"strikethrough")}function Y4($){return x5($,"underline")}function Y3($,M,Z,J,X){return a($,y5($.documentIndex,M,Z,J,X))}function Q3($,M,Z,J){return a($,y5($.documentIndex,M,Z,J,null))}function K3($,M){let Z=o2($.documentIndex,M);if(!Z||Z.type!=="listItem"||typeof Z.checked!=="boolean")return null;return a($,{kind:"replace-block",block:{...Z,checked:!Z.checked},blockId:M})}function d5($){return h6($)}function a5($){return g6($)}function q3($,M,Z){let J=_6($.documentIndex,M,Z);if(!J)return null;return h5($,$.documentIndex.document.comments.length,0,[J])}function U3($,M,Z){return Q4($,M,(J)=>L8(J,{body:Z.trim()}))}function N3($,M,Z,J){return Q4($,M,(X)=>k8(X,Z,J))}function A3($,M,Z){return Q4($,M,(J)=>f8(J,Z))}function G3($,M){return Q4($,M,()=>null)}function B3($,M,Z){return Q4($,M,(J)=>m8(J,Z))}function Q4($,M,Z){let X=k0($.documentIndex).threads[M];if(!X)return null;let Y=Z(X);if(Y===X)return null;return h5($,M,1,Y?[Y]:[])}function UK($){if(!$.state||!$.action||$.action.kind!=="replace-block"||!$.action.listItemInsertedPath)return $.state;return v6($.state,$.action.listItemInsertedPath)}function S7($,M){let Z=s($.documentIndex,$.selection);if(Z.start.regionId!==Z.end.regionId||Z.start.offset===Z.end.offset)return null;return a($,v2($.documentIndex,Z.start.regionId,Z.start.offset,Z.end.offset,M))}function u7($){let M=s($.documentIndex,$.selection);return M.start.regionId!==M.end.regionId||M.start.offset!==M.end.offset}function NK($){return v7($,"backward")}function AK($){return v7($,"forward")}function v7($,M){if($.selection.anchor.regionId!==$.selection.focus.regionId||$.selection.anchor.offset!==$.selection.focus.offset)return null;let Z=n0($.documentIndex,$.selection.focus.regionId);if(!Z)return null;if(M==="forward"&&$.selection.focus.offset>=Z.text.length)return null;let J=M==="backward"?_K(Z.text,$.selection.focus.offset):$.selection.focus.offset,X=M==="backward"?$.selection.focus.offset:FK(Z.text,$.selection.focus.offset);if(J===X)return null;let Y=d6(Z0($,{anchor:{regionId:Z.id,offset:J},focus:{regionId:Z.id,offset:X}}),"");return GK($,Y,J,X)}function GK($,M,Z,J){let X=BK($,Z,J);return X?m6(M,X):M}function BK($,M,Z){let J=$.documentIndex.regionIndex.get($.selection.focus.regionId);if(!J)return null;let X=J.text.slice(M,Z);if(X.length===0)return null;if(!J.inlines.find((Q)=>Q.start<=M&&Q.end>=Z&&Q.kind==="text"&&Q.link===null&&Q.marks.length===0))return null;return{regionPath:J.path,startOffset:M,text:X}}function _K($,M){let Z=Array.from($.slice(0,M));if(Z.length===0)return 0;return M-Z.at(-1).length}function FK($,M){let Z=Array.from($.slice(M))[0];return Z?M+Z.length:$.length}var h7=1;function g7($,M,Z){let J=$.documentIndex.regionOrderIndex.get($.selection.focus.regionId);if(J===void 0)return $;let X=$.documentIndex.regions[J],Y=$.selection.focus.offset+M;if(Y>=0&&Y<=X.text.length)return O0($,X.id,Y,Z);if(M<0){let K=$.documentIndex.regions[J-1];if(!K)return $;return O0($,K.id,K.text.length,Z)}let Q=$.documentIndex.regions[J+1];if(!Q)return $;return O0($,Q.id,0,Z)}function I7($,M,Z,J,X){let Y=O2(M,Z.regionId,Z.offset);if(!Y)return $;let Q=M.lines[Y.index+J];if(!Q)return $;let K=w0(M,$,{x:l0($,M,Z)+h7,y:Q.top+Q.height/2});if(!K)return $;return O0($,K.regionId,K.offset,X)}function p7($,M,Z,J){let X=r7($,M);if(!X)return $;return O0($,X.regionId,Z==="Home"?X.start:X.end,J)}function l7($,M,Z,J,X){let Y=r7($,M);if(!Y)return $;let K=Math.max(1,Math.floor(480/M.options.lineHeight)),q=O2(M,Y.regionId,$.selection.focus.offset),U=q?M.lines[q.index+J*K]:null;if(!U)return $;let N=w0(M,$,{x:l0($,M,Z)+h7,y:U.top+U.height/2});if(!N)return $;return O0($,N.regionId,N.offset,X)}function r7($,M){return s0(M,$.selection.focus.regionId,$.selection.focus.offset)}var bK=1;function c7($,M,Z,J,X){let Y=$.documentIndex.regionIndex.get($.selection.focus.regionId)??null;if(!Y)return null;let Q=$.documentIndex.tableCellIndex.get(Y.id)??null,K=$.documentIndex.blockIndex.get(Y.blockId)??null;if(!Q||K?.type!=="table")return null;let q=DK($,K.id,Q.rowIndex+J,Q.cellIndex)??HK($,K.id,J);if(!q)return $;let U=M.regionBounds.get(Y.id),N=M.regionBounds.get(q.id);if(!U||!N)return $;let A=N.top+PK(Z.top+Z.height/2-U.top,0,Math.max(0,N.bottom-N.top-1)),G=w0(M,$,{x:l0($,M,Z)+bK,y:A});if(!G)return $;return O0($,G.regionId,G.offset,X)}function DK($,M,Z,J){return $2($.documentIndex,M,Z,J)}function HK($,M,Z){let J=$.documentIndex.blockIndex.get(M),X=$.documentIndex.regions,Y=J?$.documentIndex.roots[J.rootIndex]?.regionRange:void 0;if(!Y)return null;return Z<0?X[Y.start-1]??null:X[Y.end]??null}function PK($,M,Z){return Math.max(M,Math.min(Z,$))}function _3($,M,Z=!1){return g7($,M,Z)}function F3($,M,Z,J=!1){return zK($,M,Z,J)}function b3($,M,Z,J=!1){return TK($,M,Z,J)}function D3($,M,Z,J=!1){return p7($,M,Z,J)}function H3($,M,Z=!1){return yK($,M,Z)}function zK($,M,Z,J){let X=x7($,M);if(!X)return $;return c7($,M,X,Z,J)??I7($,M,X,Z,J)}function TK($,M,Z,J){let X=x7($,M);if(!X)return $;return l7($,M,X,Z,J)}function yK($,M,Z){let J=$.documentIndex.regions,X=M==="start"?J[0]:J.at(-1);if(!X)return $;return O0($,X.id,M==="start"?0:X.text.length,Z)}function x7($,M){return I0(M,$.documentIndex,{regionId:$.selection.focus.regionId,offset:$.selection.focus.offset})}function a7($,M,Z,J,X,Y,Q){let K=Z.image?J.images.get(Z.image.url):null,q=wK(Z,J,Q),U=OK(M,Y,Q,q);if($.fillStyle=X.imageSurfaceBackground,$.fillRect(U.left,U.top,U.width,U.height),K?.status==="loaded"&&K.source)$.drawImage(K.source,U.left,U.top,U.width,U.height);else WK($,X,{...U,status:K?.status==="error"?"error":"loading"});$.strokeStyle=X.imageSurfaceBorder,$.strokeRect(U.left,U.top,U.width,U.height)}function WK($,M,Z){let J=Z.status==="loading"?"Loading image":"Image unavailable",X=EK(Z),Y=Z.top+Z.height/2+X.size*0.9;if($.save(),$.beginPath(),$.rect(Z.left,Z.top,Z.width,Z.height),$.clip(),Z.status==="loading")VK($,M,Z);$.strokeStyle=M.imagePlaceholderIcon,$.lineWidth=1.5,$.strokeRect(X.left,X.top,X.size,X.size),$.beginPath(),$.arc(X.left+X.size*0.28,X.top+X.size*0.3,X.size*0.1,0,Math.PI*2),$.moveTo(X.left+X.size*0.12,X.top+X.size*0.82),$.lineTo(X.left+X.size*0.42,X.top+X.size*0.5),$.lineTo(X.left+X.size*0.58,X.top+X.size*0.66),$.lineTo(X.left+X.size*0.78,X.top+X.size*0.38),$.lineTo(X.left+X.size*0.88,X.top+X.size*0.82),$.stroke(),$.font='500 12px "Iowan Old Style", "Palatino Linotype", serif',$.fillStyle=M.imagePlaceholderText,$.textAlign="center",$.textBaseline="middle",$.fillText(J,Z.left+Z.width/2,Y),$.restore()}function VK($,M,Z){let J=Math.max(48,Math.round(Z.width*0.22)),X=Z.width+J*2,Y=performance.now()%1800/1800,Q=Z.left-J+X*Y,K=$.createLinearGradient(Q,Z.top,Q+J,Z.top);K.addColorStop(0,"rgba(255,255,255,0)"),K.addColorStop(0.5,M.imageLoadingOverlay),K.addColorStop(1,"rgba(255,255,255,0)"),$.fillStyle=K,$.fillRect(Z.left,Z.top,Z.width,Z.height)}function wK($,M,Z){if(!$.image)return d7(Z);let J=M.images.get($.image.url);if(!J||J.intrinsicWidth<=0||J.intrinsicHeight<=0)return d7(Z);return Math.max(48,Math.round(Z*(J.intrinsicHeight/J.intrinsicWidth)))}function OK($,M,Z,J){return{height:J,left:M,top:$.top+Math.max(0,Math.floor(($.height-J)/2)),width:Z}}function EK($){let M=Math.max(18,Math.min(34,Math.round(Math.min($.width,$.height)*0.18)));return{left:$.left+Math.max(12,Math.round(($.width-M)/2)),size:M,top:$.top+Math.max(12,Math.round($.height/2-M*0.95))}}function d7($){return Math.max(48,Math.round($*0.5625))}var i7=2,s7=8,CK=3,jK=1.5,RK=2,Q2={elbow:{x:6.5,y:10.5},end:{x:11.5,y:3.5},start:{x:3.5,y:7.5}};function o7($,M,Z,J,X,Y,Q=null){if(!Z||M.start!==0)return;if(Q){let K=U7(Q),q=SK(Z,M,J,X,$);$.save(),$.translate(q.x,q.y),$.scale(K,K),$.translate(-q.x,-q.y)}if(Z.kind==="task")LK($,M,Z.checked,Y,Q);else if($.fillStyle=Q?c2(Y.listMarkerText,Q,Y):Y.listMarkerText,Z.kind==="ordered")mK($,Z.label,J,X);else $.fillText(Z.label,M.left-i7,X);if(Q)$.restore()}function LK($,M,Z,J,X=null){let Y=C2(M);if(kK($,Y,Z,J,X),!Z)return;fK($,Y,J,X)}function kK($,M,Z,J,X=null){let Y=Z?J.checkboxCheckedFill:J.checkboxUncheckedFill,Q=Z?J.checkboxCheckedStroke:J.checkboxUncheckedStroke;$.fillStyle=X?c2(Y,X,J):Y,$.strokeStyle=X?c2(Q,X,J):Q,$.beginPath(),$.lineWidth=jK,$.roundRect(M.left,M.top,M.size,M.size,CK),$.fill(),$.stroke()}function fK($,M,Z,J=null){$.strokeStyle=J?c2(Z.checkboxCheckmark,J,Z):Z.checkboxCheckmark,$.lineWidth=RK,$.beginPath(),$.moveTo(M.left+Q2.start.x,M.top+Q2.start.y),$.lineTo(M.left+Q2.elbow.x,M.top+Q2.elbow.y),$.lineTo(M.left+Q2.end.x,M.top+Q2.end.y),$.stroke()}function mK($,M,Z,J){let X=$.textAlign;$.textAlign="right",$.fillText(M,Z-s7,J),$.textAlign=X}function SK($,M,Z,J,X){if($.kind==="task"){let K=C2(M);return{x:K.left+K.size/2,y:K.top+K.size/2}}let Y=X.measureText($.label),Q=J-(Y.actualBoundingBoxAscent-Y.actualBoundingBoxDescent)/2;if($.kind==="ordered")return{x:Z-s7-Y.width/2,y:Q};return{x:M.left-i7+Y.width/2,y:Q}}var uK=80;function t7({context:$,containerBounds:M,isHeaderRow:Z,lineHeight:J,theme:X}){let Y=$M(M,J);$.fillStyle=Z?X.tableHeaderBackground:X.tableBodyBackground,$.fillRect(Y.left,Y.top,Y.width,Y.height),MM($,Y,X)}function e7({activeBlockFlashes:$,activeBlockId:M,activeRegionId:Z,context:J,editorState:X,endIndex:Y,layout:Q,regionBounds:K,startIndex:q,theme:U,verticalBleed:N}){if(!M||!Z)return;let A=X.documentIndex.blockIndex.get(M)??null;if(A?.type!=="table")return;if((X.documentIndex.regionIndex.get(Z)??null)?.blockId!==M)return;let B=K.get(Z)??null,F=Q.regionLineIndices.get(Z)??null;if(!B||!F||F.length===0)return;let _=Q.lines[F[0]]??null;if(!_)return;let D=$M(B,_.height);if(D.width===0)return;let T=n7({context:J,endIndex:Y,fillStyle:U.activeBlockBackground,layout:Q,left:D.left,lineIndices:F,startIndex:q,verticalBleed:N,width:D.width}),O=A.path?$.get(A.path)??null:null;if(O)n7({context:J,endIndex:Y,fillStyle:f5(U.activeBlockFlash,O),layout:Q,left:D.left,lineIndices:F,startIndex:q,verticalBleed:N,width:D.width});if(!T)return;MM(J,D,U)}function n7({context:$,endIndex:M,fillStyle:Z,layout:J,left:X,lineIndices:Y,startIndex:Q,verticalBleed:K,width:q}){$.fillStyle=Z;let U=!1;for(let N of Y){if(N<Q)continue;if(N>=M)break;let A=J.lines[N];$.fillRect(X,A.top-K,q,A.height),U=!0}return U}function $M($,M){return{height:Math.max($.bottom-$.top,M),left:$.left,top:$.top,width:Math.max($.right-$.left,uK)}}function MM($,M,Z){$.strokeStyle=Z.tableBorder,$.strokeRect(M.left,M.top,M.width,M.height)}var P3=2,vK=3,hK=12,gK=6,IK=3,pK=1,lK=2,rK=2,cK=8,xK=12,dK=28,aK=4,iK=5,sK=2,oK=3,nK=6,ZM=3,tK=12,eK=10,$q=2,Mq=2,Zq=1,Jq=2,z3=2,JM=1.25,Xq=5,Yq=1,XM=4,Qq=4,Kq=1.5;function qq({activeBlockId:$,activeRegionId:M,activeThreadIndex:Z,containerLineBounds:J,context:X,devicePixelRatio:Y,editorState:Q,height:K,layout:q,liveCommentRanges:U,normalizedSelection:N,now:A=fq(),resources:G,runtimeBlockMap:B,theme:F,viewportTop:_,width:D}){X.save(),X.scale(Y,Y),X.clearRect(0,0,D,K),X.fillStyle=F.background,X.fillRect(0,0,D,K),X.textBaseline="alphabetic",X.translate(0,-_);let T=Uq(Q,N),{endIndex:O,startIndex:y}=e8(q,_,K),R=$7(Q,A),C=M7(Q,A),m=e9(Q,A),H=J7(Q,A),P=Z7(Q,A),E=Aq(q,Q,$,y,O),j=Nq(q,Q,B,y,O,D);for(let W=y;W<O;W+=1){let b=q.lines[W];Fq({containerLineBounds:J,context:X,editorState:Q,line:b,runtimeBlockMap:B,theme:F,width:D})}e7({activeBlockFlashes:R,activeBlockId:$,activeRegionId:M,context:X,editorState:Q,endIndex:O,layout:q,regionBounds:J,startIndex:y,theme:F,verticalBleed:P3});for(let W=y;W<O;W+=1){let b=q.lines[W];bq({activeBlockId:$,activeBlockFlashes:R,activeDeletedTextFades:C,activeThreadIndex:Z,activeInsertedTextHighlights:m,activeListMarkerPops:H,activePunctuationPulses:P,context:X,editorState:Q,line:b,liveCommentRanges:U,normalizedSelection:N,resources:G,runtimeBlockMap:B,selectionRegionOrderRange:T,theme:F,width:D})}Gq(X,j,F),Bq(X,E,F),X.restore()}function Uq($,M){let Z=$.documentIndex.regionOrderIndex,J=Z.get(M.start.regionId),X=Z.get(M.end.regionId);return J===void 0||X===void 0?null:{end:X,start:J}}function Nq($,M,Z,J,X,Y){let Q=new Map;for(let K=J;K<X;K+=1){let q=$.lines[K],U=Z.get(q.blockId);if(U?.type!=="heading"||U.depth!==1&&U.depth!==2)continue;let N=Q.get(U.id),A={bottom:q.top+q.height,left:q.left+K1(M,q),right:Y-$.options.paddingX};Q.set(U.id,N?{bottom:Math.max(N.bottom,A.bottom),left:N.left,right:N.right}:A)}return Q}function Aq($,M,Z,J,X){let Y=new Map;for(let Q=J;Q<X;Q+=1){let K=$.lines[Q],q=o1(M,K.blockId,"blockquote");if(!q)continue;let U=Y.get(q.id),N={bottom:K.top+K.height,isActive:K.blockId===Z,left:$.options.paddingX+(q.depth+1)*$.options.indentWidth-10,top:K.top};Y.set(q.id,U?{bottom:Math.max(U.bottom,N.bottom),isActive:U.isActive||N.isActive,left:U.left,top:Math.min(U.top,N.top)}:N)}return Y}function Gq($,M,Z){$.fillStyle=Z.headingRule;for(let J of M.values())$.fillRect(J.left,J.bottom+Xq,Math.max(z3,J.right-J.left),Yq)}function Bq($,M,Z){for(let J of M.values())$.fillStyle=J.isActive?Z.blockquoteRuleActive:Z.blockquoteRule,$.fillRect(J.left,J.top+vK,IK,Math.max(hK,J.bottom-J.top-gK))}function _q({context:$,devicePixelRatio:M,editorState:Z,height:J,layout:X,normalizedSelection:Y,presence:Q,showCaret:K,theme:q,viewportTop:U,width:N}){$.save(),$.scale(M,M),$.clearRect(0,0,N,J);let A=Y.start.regionId===Y.end.regionId&&Y.start.offset!==Y.end.offset,G=K&&!A;if($.translate(0,-U),G)YM($,Z,X,{color:q.caret,offset:Z.selection.focus.offset,regionId:Z.selection.focus.regionId});if(Q)for(let B of Q){if(!B.cursorPoint)continue;YM($,Z,X,{color:B.color??q.leafAccent,offset:B.cursorPoint.offset,regionId:B.cursorPoint.regionId})}$.restore()}function YM($,M,Z,J){let X=I0(Z,M.documentIndex,{regionId:J.regionId,offset:J.offset});if(!X)return;let Y=l0(M,Z,X),Q=Vq(Z,X);$.fillStyle=J.color,$.fillRect(Y,Q.top,lK,Q.height)}function Fq({containerLineBounds:$,context:M,editorState:Z,line:J,runtimeBlockMap:X,theme:Y,width:Q}){let K=X.get(J.blockId)??null,q=$.get(J.regionId)??null,U=Z.documentIndex.tableCellIndex.get(J.regionId)??null;Dq(M,J,K,q,U,Y,Q)}function bq({activeBlockId:$,activeBlockFlashes:M,activeDeletedTextFades:Z,activeThreadIndex:J,activeInsertedTextHighlights:X,activeListMarkerPops:Y,activePunctuationPulses:Q,context:K,editorState:q,line:U,liveCommentRanges:N,normalizedSelection:A,resources:G,runtimeBlockMap:B,selectionRegionOrderRange:F,theme:_,width:D}){let T=B.get(U.blockId)??null,O=q.documentIndex.blockIndex.get(U.blockId)?.path??null,y=q.documentIndex.regionIndex.get(U.regionId)??null,R=y?.path??"",C=o1(q,U.blockId,"listItem"),m=C?j2(q,C.id):null,H=C?Y.get(C.path)??null:null,P=U.left+K1(q,U),E=Eq(U),j=T?.type==="code"?_.codeText:Rq(T,_);K.font=U.font,Hq(K,U,T,O,$,M,_,D),Pq(K,q,U,A,F,_),zq(K,q,U,N,J,_),o7(K,U,m,P,E,_,H),Tq(K,U,y,P,E,X.get(R)??[],j,G,_),yq(K,U,y,P,E,Z.get(R)??[],j),Wq(K,U,y,P,E,Q.get(R)??[],_)}function Dq($,M,Z,J,X,Y,Q){if(!J||M.start!==0)return;if(Z?.type==="code"){let K=Math.max(0,M.left-xK);$.fillStyle=Y.codeBackground,$.fillRect(K,J.top-aK,Math.max(J.right-M.left+dK,Q-K),J.bottom-J.top+cK);return}if(Z?.type!=="table")return;t7({context:$,containerBounds:J,isHeaderRow:X?.rowIndex===0,lineHeight:M.height,theme:Y})}function Hq($,M,Z,J,X,Y,Q,K){if(M.blockId!==X||Z?.type==="table")return;let q=J?Y.get(J)??null:null;if($.fillStyle=Q.activeBlockBackground,$.fillRect(0,M.top-P3,K,M.height),!q)return;$.fillStyle=f5(Q.activeBlockFlash,q),$.fillRect(0,M.top-P3,K,M.height)}function Pq($,M,Z,J,X,Y){if(!X)return;let Q=M.documentIndex.regionOrderIndex.get(Z.regionId);if(Q===void 0||Q<X.start||Q>X.end)return;let K=Q===X.start?Math.max(Z.start,J.start.offset):Z.start,q=Q===X.end?Math.min(Z.end,J.end.offset):Z.end;if(q<=K)return;$.fillStyle=Y.selectionBackground,$.fillRect(Q1(M,Z,K-Z.start),Z.top+Zq,Math.max(Mq,Q1(M,Z,q-Z.start)-Q1(M,Z,K-Z.start)),Z.height-Jq)}function zq($,M,Z,J,X,Y){for(let Q of J){if(Q.regionId!==Z.regionId)continue;let K=Math.max(Q.startOffset,Z.start),q=Math.min(Q.endOffset,Z.end);if(q<=K)continue;$.fillStyle=kq(Q,X,Y),$.fillRect(Q1(M,Z,K-Z.start),Z.top+Z.height-iK,Math.max(sK,Q1(M,Z,q-Z.start)-Q1(M,Z,K-Z.start)),oK)}}function Tq($,M,Z,J,X,Y,Q,K,q){if(!Z){$.fillStyle=Q,$.fillText(M.text,J,X);return}let U=Z.inlines.filter((N)=>N.end>M.start&&N.start<M.end);if(U.length===0){$.fillStyle=Q,$.fillText(M.text,J,X);return}for(let N of U){let A=Math.max(M.start,N.start),G=Math.min(M.end,N.end);if(Z.text.slice(A,G).length===0)continue;let{left:F,right:_}=y3(M,J,A,G),D=Lq(M.font,N.marks);if($.font=D,N.kind==="image"){let T=Math.max(24,_-F);a7($,M,N,K,q,F,T);continue}if(N.kind==="inlineCode"){let T=Cq(M,D),O=jq(M,D);$.fillStyle=q.inlineCodeBackground,$.fillRect(F-ZM,T,Math.max(eK,_-F+ZM*2),O),QM($,M,Z.text,J,X,A,G,q.inlineCodeText,Y,q,{strikethrough:!1,underline:!1});continue}QM($,M,Z.text,J,X,A,G,N.link?q.linkText:Q,Y,q,{strikethrough:N.marks.includes("strikethrough"),underline:N.marks.includes("underline")||Boolean(N.link)})}}function QM($,M,Z,J,X,Y,Q,K,q,U,N){let A=X7(Y,Q,q);for(let G=0;G<A.length-1;G+=1){let B=A[G],F=A[G+1];if(F<=B)continue;let _=Z.slice(B,F);if(_.length===0)continue;let{left:D,right:T}=y3(M,J,B,F),O=Y7(q,B,F),y=Q7(K,O,U);if($.fillStyle=y,$.fillText(_,D,X),N.strikethrough)$.fillRect(D,Oq(X,M.height,$.font),Math.max(z3,T-D),JM);if(N.underline)$.fillRect(D,wq(X,M.height,$.font),Math.max(z3,T-D),JM)}}function yq($,M,Z,J,X,Y,Q){if(!Z||Y.length===0)return;for(let K of Y){if(K.startOffset<M.start||K.startOffset>M.end)continue;let q=J+(p0(M,K.startOffset-M.start)-M.left);$.fillStyle=K7(Q,K),$.fillText(K.text,q,X)}}function Wq($,M,Z,J,X,Y,Q){if(!Z||Y.length===0)return;for(let K of Y){if(K.offset<M.start||K.offset>=M.end)continue;let{left:q,right:U}=y3(M,J,K.offset,K.offset+1),N=Math.max(XM,(U-q)/2+XM+Qq*K.progress),{ascent:A,descent:G}=Y1(M.font),B=X-Math.max(1,A*0.42)+Math.max(0.5,G*0.15);$.strokeStyle=q7(K,Q),$.lineWidth=Kq,$.beginPath(),$.arc((q+U)/2,B,N,0,Math.PI*2),$.stroke()}}function Vq($,M){let Z=s0($,M.regionId,M.offset),J=Z?.font??'16px "Iowan Old Style", "Palatino Linotype", serif',{ascent:X,descent:Y}=Y1(J),Q=Math.max(1,X+Y),K=Math.min(M.height-rK,Q),q=Z?Math.max(Z.top,Z.top+T3(Z.height,J)-pK):M.top+Math.max(0,Math.floor((M.height-K)/2));return{height:K,top:q}}function wq($,M,Z){let{descent:J}=Y1(Z),X=Math.max(1,Math.round(Math.max(2,J)*0.35)),Y=$+J-X,Q=$-i5(M,Z);return Math.min(Q+M-4,Y)}function Oq($,M,Z){let{ascent:J}=Y1(Z),X=$-i5(M,Z);return Math.max(X+2,$-Math.round(J*0.32))}function Eq($){return $.top+i5($.height,$.font)}function i5($,M){return z9($,M)}function Cq($,M){let Z=T3($.height,M);return $.top+Z+$q}function jq($,M){let Z=T3($.height,M);return Math.max(tK,$.height-Z-nK)}function T3($,M){let{ascent:Z}=Y1(M);return i5($,M)-Z}function Rq($,M){switch($?.type){case"heading":return M.headingText;case"blockquote":return M.blockquoteText;case"table":return M.headingText;default:return M.paragraphText}}function y3($,M,Z,J){return{left:M+(p0($,Z-$.start)-$.left),right:M+(p0($,J-$.start)-$.left)}}function Lq($,M){let Z=[];if(M.includes("italic"))Z.push("italic");if(M.includes("bold"))Z.push("700");return Z.length>0?`${Z.join(" ")} ${$}`:$}function kq($,M,Z){if($.resolved)return $.threadIndex===M?Z.commentHighlightResolvedActive:Z.commentHighlightResolved;return $.threadIndex===M?Z.commentHighlightActive:Z.commentHighlight}function fq(){return typeof performance<"u"?performance.now():Date.now()}function W3($,M,Z,J){qq({activeBlockId:J.activeBlockId,activeRegionId:J.activeRegionId,activeThreadIndex:J.activeThreadIndex,containerLineBounds:M.regionBounds,context:Z,devicePixelRatio:J.devicePixelRatio,editorState:$,height:J.height,layout:M.layout,liveCommentRanges:J.liveCommentRanges,normalizedSelection:J.normalizedSelection,now:J.now,resources:J.resources??{images:new Map},runtimeBlockMap:M.blockMap,theme:J.theme,viewportTop:M.paintTop,width:J.width})}function V3($,M,Z,J){_q({context:Z,devicePixelRatio:J.devicePixelRatio,editorState:$,height:J.height,layout:M.layout,normalizedSelection:J.normalizedSelection,presence:J.presence,showCaret:J.showCaret,theme:J.theme,viewportTop:M.paintTop,width:J.width})}import{forwardRef as hq,createElement as gq}from"react";var s5=(...$)=>$.filter((M,Z,J)=>{return Boolean(M)&&M.trim()!==""&&J.indexOf(M)===Z}).join(" ").trim();var KM=($)=>$.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var qM=($)=>$.replace(/^([A-Z])|[\s-_]+(\w)/g,(M,Z,J)=>J?J.toUpperCase():Z.toLowerCase());var w3=($)=>{let M=qM($);return M.charAt(0).toUpperCase()+M.slice(1)};import{forwardRef as vq,createElement as AM}from"react";var o5={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var UM=($)=>{for(let M in $)if(M.startsWith("aria-")||M==="role"||M==="title")return!0;return!1};import{createContext as mq,useContext as Sq,useMemo as RD,createElement as LD}from"react";var uq=mq({});var NM=()=>Sq(uq);var GM=vq(({color:$,size:M,strokeWidth:Z,absoluteStrokeWidth:J,className:X="",children:Y,iconNode:Q,...K},q)=>{let{size:U=24,strokeWidth:N=2,absoluteStrokeWidth:A=!1,color:G="currentColor",className:B=""}=NM()??{},F=J??A?Number(Z??N)*24/Number(M??U):Z??N;return AM("svg",{ref:q,...o5,width:M??U??o5.width,height:M??U??o5.height,stroke:$??G,strokeWidth:F,className:s5("lucide",B,X),...!Y&&!UM(K)&&{"aria-hidden":"true"},...K},[...Q.map(([_,D])=>AM(_,D)),...Array.isArray(Y)?Y:[Y]])});var S=($,M)=>{let Z=hq(({className:J,...X},Y)=>gq(GM,{ref:Y,iconNode:M,className:s5(`lucide-${KM(w3($))}`,`lucide-${$}`,J),...X}));return Z.displayName=w3($),Z};var Iq=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],G1=S("columns-2",Iq);var pq=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M21 9H3",key:"1338ky"}],["path",{d:"M21 15H3",key:"9uk58r"}]],B1=S("rows-3",pq);var lq=[["path",{d:"M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z",key:"117uat"}],["path",{d:"M6 12h16",key:"s4cdu5"}]],_1=S("send-horizontal",lq);var rq=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],K4=S("arrow-down",rq);var cq=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],q4=S("arrow-up",cq);var xq=[["path",{d:"M6 12h9a4 4 0 0 1 0 8H7a1 1 0 0 1-1-1V5a1 1 0 0 1 1-1h7a4 4 0 0 1 0 8",key:"mg9rjx"}]],U4=S("bold",xq);var dq=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],V1=S("check",dq);var aq=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],N4=S("chevron-down",aq);var iq=[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"m17 12 3-2v8",key:"1hhhft"}]],A4=S("heading-1",iq);var sq=[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M21 18h-4c0-4 4-3 4-6 0-1.5-2-2.5-4-1",key:"9jr5yi"}]],G4=S("heading-2",sq);var oq=[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M17.5 10.5c1.7-1 3.5 0 3.5 1.5a2 2 0 0 1-2 2",key:"68ncm8"}],["path",{d:"M17 17.5c2 1.5 4 .3 4-1.5a2 2 0 0 0-2-2",key:"1ejuhz"}]],B4=S("heading-3",oq);var nq=[["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M17 10v3a1 1 0 0 0 1 1h3",key:"tj5zdr"}],["path",{d:"M21 10v8",key:"1kdml4"}],["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}]],_4=S("heading-4",nq);var tq=[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["path",{d:"M17 13v-3h4",key:"1nvgqp"}],["path",{d:"M17 17.7c.4.2.8.3 1.3.3 1.5 0 2.7-1.1 2.7-2.5S19.8 13 18.3 13H17",key:"2nebdn"}]],F4=S("heading-5",tq);var eq=[["path",{d:"M4 12h8",key:"17cfdx"}],["path",{d:"M4 18V6",key:"1rz3zl"}],["path",{d:"M12 18V6",key:"zqpxq5"}],["circle",{cx:"19",cy:"16",r:"2",key:"15mx69"}],["path",{d:"M20 10c-2 2-3 3.5-3 6",key:"f35dl0"}]],b4=S("heading-6",eq);var $U=[["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M6 20V4",key:"1w1bmo"}],["path",{d:"M18 20V4",key:"o2hl4u"}]],D4=S("heading",$U);var MU=[["line",{x1:"19",x2:"10",y1:"4",y2:"4",key:"15jd3p"}],["line",{x1:"14",x2:"5",y1:"20",y2:"20",key:"bu0au3"}],["line",{x1:"15",x2:"9",y1:"4",y2:"20",key:"uljnxc"}]],H4=S("italic",MU);var ZU=[["path",{d:"M11 5h10",key:"1cz7ny"}],["path",{d:"M11 12h10",key:"1438ji"}],["path",{d:"M11 19h10",key:"11t30w"}],["path",{d:"M4 4h1v5",key:"10yrso"}],["path",{d:"M4 9h2",key:"r1h2o0"}],["path",{d:"M6.5 20H3.4c0-1 2.6-1.925 2.6-3.5a1.5 1.5 0 0 0-2.6-1.02",key:"xtkcd5"}]],P4=S("list-ordered",ZU);var JU=[["path",{d:"M13 5h8",key:"a7qcls"}],["path",{d:"M13 12h8",key:"h98zly"}],["path",{d:"M13 19h8",key:"c3s6r1"}],["path",{d:"m3 17 2 2 4-4",key:"1jhpwq"}],["rect",{x:"3",y:"4",width:"6",height:"6",rx:"1",key:"cif1o7"}]],z4=S("list-todo",JU);var XU=[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]],T4=S("list",XU);var YU=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M12 8v6",key:"1ib9pf"}],["path",{d:"M9 11h6",key:"1fldmi"}]],y4=S("message-square-plus",YU);var QU=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],w1=S("pencil",QU);var KU=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],K2=S("plus",KU);var qU=[["path",{d:"M16 4H9a3 3 0 0 0-2.83 4",key:"43sutm"}],["path",{d:"M14 12a4 4 0 0 1 0 8H6",key:"nlfj13"}],["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}]],W4=S("strikethrough",qU);var UU=[["path",{d:"M9 3H5a2 2 0 0 0-2 2v4m6-6h10a2 2 0 0 1 2 2v4M9 3v18m0 0h10a2 2 0 0 0 2-2V9M9 21H5a2 2 0 0 1-2-2V9m0 0h18",key:"gugj83"}]],F1=S("table-2",UU);var NU=[["path",{d:"M17 5H3",key:"1cn7zz"}],["path",{d:"M21 12H8",key:"scolzb"}],["path",{d:"M21 19H8",key:"13qgcb"}],["path",{d:"M3 12v7",key:"1ri8j3"}]],V4=S("text-quote",NU);var AU=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],E0=S("trash-2",AU);var GU=[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4",key:"9kb039"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20",key:"nun2al"}]],w4=S("underline",GU);var BU=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],O4=S("x",BU);import{jsxDEV as O1}from"react/jsx-dev-runtime";function BM({insetX:$,insetY:M,onSelect:Z,presence:J}){if(!J)return null;return O1("div",{"aria-label":"Presence",className:"documint-presence-indicators",style:{paddingRight:`${$}px`,top:`${M}px`},children:J.map((X)=>O1(_U,{onSelect:()=>Z(X),presence:X},X.id,!1,void 0,this))},void 0,!1,void 0,this)}function _U({onSelect:$,presence:M}){let Z=M.viewport,J=FU(M),X=Z?.status==="above"?q4:K4,Y=Z!==null&&Z.status!=="unresolved",Q=Z?.status==="above"||Z?.status==="below";return O1("button",{"aria-label":bU(M),className:"documint-presence-indicator","data-status":Z?.status??"unresolved",disabled:!Y,onClick:Y?$:void 0,style:{"--documint-presence-color":M.color??"var(--documint-leaf-accent)"},type:"button",children:[O1("span",{className:"documint-presence-indicator-avatar",children:M.avatarUrl?O1("img",{alt:"","aria-hidden":"true",className:"documint-presence-indicator-image",draggable:!1,src:M.avatarUrl},void 0,!1,void 0,this):J},void 0,!1,void 0,this),Q?O1("span",{className:"documint-presence-indicator-direction","aria-hidden":"true",children:O1(X,{className:"documint-presence-indicator-arrow",size:14,strokeWidth:2.3},void 0,!1,void 0,this)},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)}function FU($){return _M($).charAt(0).toLocaleUpperCase()}function bU($){let M=_M($),Z=$.viewport?.status??"unresolved";if(Z==="above")return`${M} above viewport`;if(Z==="below")return`${M} below viewport`;if(Z==="unresolved")return`${M} unresolved`;return`${M} in viewport`}function _M($){return($.fullName??$.username).trim()||"Presence"}var i=`
26
+ `,b1="<ins>",E4="</ins>",q2=">",C4="```",n5=":::",O3=/^:::([A-Za-z][-\w]*)(.*)$/,t5="documint-comments";var e5="`",R3="\\",C3="![",j3="[",HM="(",FM=")",PM=" ",zM=":",DU=/[A-Za-z]/,HU=/[-A-Za-z0-9_]/,PU=/^\{width=([1-9]\d*)\}/,zU=/\\([\\`*_[\]{}()#+\-.!~|])/g,TM=/\\(.)/g,TU=[{delimiter:"**",mark:"bold"},{delimiter:"~~",mark:"strikethrough"},{delimiter:"*",mark:"italic"}];function U2($,M=[]){return L3($,0,$.length,M)}function L3($,M,Z,J){let X=[],Y=M,Q=M;while(Y<Z){let K=yU($,Y,Z,J);if(K){bM(X,$.slice(Q,Y),J),X.push(...K.nodes),Y=K.end,Q=Y;continue}if($[Y]===R3){Y+=Math.min(2,Z-Y);continue}Y+=1}return bM(X,$.slice(Q,Z),J),WU(X)}function yU($,M,Z,J){switch($[M]){case zM:return mU($,M,Z);case"<":return kU($,M,Z,J);case e5:return CU($,M,Z);case"!":return jU($,M,Z);case j3:return RU($,M,Z,J);case"*":case"~":return wU($,M,Z,J);default:return null}}function bM($,M,Z){if(M.length===0)return;$.push(z0({marks:Z,text:OM(M)}))}function k3($,M){return o4({originalType:$,source:M})}function WU($){let M=[];for(let Z of $){let J=M.at(-1);if(J?.type==="text"&&Z.type==="text"&&OU(J.marks,Z.marks)){M[M.length-1]=z0({marks:J.marks,text:J.text+Z.text});continue}M.push(Z)}return M}function VU($,M,Z){for(let J of TU){if(!$.startsWith(J.delimiter,M))continue;let X=$.indexOf(J.delimiter,M+J.delimiter.length);if(X<0||X>=Z)continue;return{contentEnd:X,contentStart:M+J.delimiter.length,end:X+J.delimiter.length,mark:J.mark}}return null}function wU($,M,Z,J){let X=VU($,M,Z);if(!X)return null;return{end:X.end,nodes:L3($,X.contentStart,X.contentEnd,[...J,X.mark])}}function OU($,M){return $.length===M.length&&$.every((Z,J)=>Z===M[J])}function EU($,M,Z){if($[M]!==e5)return null;let J=1;while(M+J<Z&&$[M+J]===e5)J+=1;let X=e5.repeat(J),Y=$.indexOf(X,M+J);if(Y<0||Y>=Z)return null;return{end:Y+J,value:$.slice(M+J,Y)}}function CU($,M,Z){let J=EU($,M,Z);if(!J)return null;return{end:J.end,nodes:[m1({code:J.value})]}}function jU($,M,Z){if(!$.startsWith(C3,M))return null;let J=WM($,M+1,Z);if(J<0||$[J+1]!==HM)return null;let X=yM($,J+1,Z);if(!X)return null;let Y=LU($,X.end,Z);return{end:Y?.end??X.end,nodes:[s4({alt:OM($.slice(M+C3.length,J)),title:X.title,url:X.url,width:Y?.width??null})]}}function RU($,M,Z,J){if($[M]!==j3||$.startsWith(C3,M-1))return null;let X=WM($,M,Z);if(X<0||$[X+1]!==HM)return null;let Y=yM($,X+1,Z);if(!Y)return null;return{end:Y.end,nodes:[S1({children:U2($.slice(M+j3.length,X),J),title:Y.title,url:Y.url})]}}function yM($,M,Z){let J=E3($,M+1,Z),X=J;while(X<Z&&$[X]!==FM&&$[X]!==PM){if($[X]===R3){X+=2;continue}X+=1}if(X===J)return null;let Y=SU($.slice(J,X));J=E3($,X,Z);let Q=null;if(J<Z&&$[J]==='"'){let K=wM($,'"',J+1,Z);if(K<0)return null;Q=$.slice(J+1,K).replace(TM,"$1"),J=E3($,K+1,Z)}if($[J]!==FM)return null;return{end:J+1,title:Q,url:Y}}function LU($,M,Z){let J=PU.exec($.slice(M,Z));if(!J)return null;return{end:M+J[0].length,width:Number(J[1])}}function kU($,M,Z,J){if(!$.startsWith(b1,M))return fU($,M,Z);let X=$.indexOf(E4,M+b1.length);if(X<0||X>=Z)return{end:M+b1.length,nodes:[k3("html",b1)]};return{end:X+E4.length,nodes:L3($,M+b1.length,X,[...J,"underline"])}}function fU($,M,Z){if($[M]!=="<")return null;let J=$.indexOf(">",M+1);if(J<0||J>=Z)return null;return{end:J+1,nodes:[k3("html",$.slice(M,J+1))]}}function mU($,M,Z){if($[M]!==zM||!DU.test($[M+1]??""))return null;let J=M+2;while(J<Z&&HU.test($[J]??""))J+=1;let X=DM($,J,Z,"[","]"),Q=DM($,X?.end??J,Z,"{","}")?.end??X?.end??J;return{end:Q,nodes:[k3("textDirective",$.slice(M,Q))]}}function DM($,M,Z,J,X){if($[M]!==J)return null;let Y=VM($,X,M+1,Z);if(Y<0)return null;return{end:Y+1}}function WM($,M,Z){return VM($,"]",M+1,Z)}function VM($,M,Z,J){return wM($,M,Z,J)}function wM($,M,Z,J){for(let X=Z;X<J;X+=1){if($[X]===R3){X+=1;continue}if($[X]===M)return X}return-1}function E3($,M,Z){while(M<Z&&$[M]===PM)M+=1;return M}function OM($){return $.replace(zU,"$1")}function SU($){return $.replace(TM,"$1")}var uU=/^:?-+:?$/;function jM($,M){let Z=CM($),J=$.lines[$.index+1]??"",X=f3(Z,M),Y=f3(J,M);if(!EM(X)||!m3(Y))return null;let Q=[$8(X)],K=vU(Y);$.index+=2;while($.index<$.lines.length){let q=CM($),U=f3(q,M);if(hU(q)||!EM(U))break;Q.push($8(U)),$.index+=1}return z1({align:K,rows:Q.map((q)=>u1({cells:q.map((U)=>M1({children:U2(U)}))}))})}function EM($){let M=$.trim();return/\|/.test($)&&M.startsWith("|")&&M.endsWith("|")}function m3($){let M=$8($);return M.length>0&&M.every((Z)=>uU.test(Z.trim()))}function vU($){return $8($).map((M)=>{let Z=M.trim();if(Z.startsWith(":")&&Z.endsWith(":"))return"center";if(Z.startsWith(":"))return"left";if(Z.endsWith(":"))return"right";return null})}function $8($){return $.trim().slice(1,-1).split("|").map((Z)=>Z.trim())}function CM($){return $.lines[$.index]??""}function hU($){return $.trim()===""}function f3($,M){return $.slice(M)}var gU=3,IU=/^\d+\.$/,pU=/^\[( |x|X)\](?:\s|$)/,RM=/^```([^\s`]*)?(?:\s+(.*))?$/,LM=/^::(?!:)[A-Za-z][-\w]*/,kM=/^(#{1,6})\s+(.*)$/,lU=/\s+#+\s*$/u,rU=/^(\s*)([-+*]|\d+\.)(?:\s+(.*)|\s*)$/,cU=/^(\*\s*){3,}$/,xU=/^(-\s*){3,}$/,dU=/^(_\s*){3,}$/;function Z8($,M,Z){let J=[];while($.index<$.lines.length){let X=_0($);if($.index===$.lines.length-1&&X==="")break;if(j4(X)){$.index+=1;continue}if(N2(X)>M+gU)break;let Q=aU($,M,Z);if(!Q)break;J.push(Q)}return J}function aU($,M,Z){return iU($,M,Z)??sU($,M)??oU($,M)??tU($,M)??eU($,M)??$N($,M)??jM($,M)??MN($,M,Z)??ZN($,M)??JN($,M)}function iU($,M,Z){let J=_0($);if(!YN(J,M))return null;let X=[];while($.index<$.lines.length){let Y=_0($),Q=N2(Y);if(j4(Y)){X.push(""),$.index+=1;continue}if(Q<M)break;let K=f0(Y,M);if(!K.startsWith(q2))break;let q=K.slice(1);if(q.startsWith(" "))q=q.slice(1);X.push(q),$.index+=1}return T0({children:Z8({index:0,lines:X},0,Z)})}function sU($,M){let Z=_0($),J=f0(Z,M),X=RM.exec(J);if(!X)return null;$.index+=1;let Y=[];while($.index<$.lines.length){let Q=_0($),K=f0(Q,M);if(K.trim()===C4){$.index+=1;break}Y.push(K),$.index+=1}return D8({language:X[1]?X[1]:null,meta:X[2]?X[2]:null,source:Y.join(i)})}function oU($,M){let Z=_0($),J=f0(Z,M),X=O3.exec(J);if(!X)return null;let Y=X[1],Q=[];$.index+=1;while($.index<$.lines.length){let K=_0($),q=f0(K,M);if($.index+=1,q.trim()===n5)break;Q.push(q)}return D$({attributes:nU(X[2]??""),body:Q.join(i),name:Y})}function nU($){let M=$.trim();if(M.startsWith("{")&&M.endsWith("}"))return M.slice(1,-1);return M}function tU($,M){let Z=_0($),J=f0(Z,M);if(!LM.test(J))return null;return $.index+=1,t4({originalType:"leafDirective",source:J})}function eU($,M){let Z=_0($),J=kM.exec(f0(Z,M));if(!J)return null;return $.index+=1,i4({children:U2(J[2].replace(lU,"")),depth:J[1].length})}function $N($,M){let Z=f0(_0($),M).trim();if(!fM(Z))return null;return $.index+=1,n4()}function MN($,M,Z){let J=M8(_0($),M);if(!J)return null;let X=[],Y=!1;while($.index<$.lines.length){let Q=_0($),K=M8(Q,M);if(!K||K.ordered!==J.ordered)break;$.index+=1;let q=[K.content],U=!1;while($.index<$.lines.length){let N=_0($),A=N2(N);if(j4(N)){let G=qN($.lines,$.index+1);if(G<0||N2($.lines[G]??"")<=M)break;U=!0,q.push(""),$.index+=1;continue}if(A<K.contentIndent)break;if(A===M&&M8(N,M))break;q.push(QN(N,K.contentIndent)),$.index+=1}Y||=U,X.push(d0({checked:K.checked,children:XN(q,Z),spread:U}))}return P1({items:X,ordered:J.ordered,spread:Y,start:J.ordered&&Z.preserveOrderedListStart?J.start??1:null})}function ZN($,M){let Z=f0(_0($),M).trim();if(!mM(Z))return null;return $.index+=1,t4({originalType:"html",source:Z})}function JN($,M){let Z=[];while($.index<$.lines.length){let J=_0($),X=N2(J);if(j4(J))break;if(X<M)break;let Y=f0(J,M);if(Z.length>0&&KN(J,Y,M))break;Z.push(Y),$.index+=1}return b2({children:U2(Z.join(i))})}function XN($,M){let Z=Z8({index:0,lines:$},0,M);if(Z.length>0)return Z;return[b2({children:[]})]}function M8($,M){let Z=rU.exec($);if(!Z||Z[1].length!==M)return null;let J=Z[2],X=IU.test(J),Y=X?Number(J.slice(0,-1)):null,Q=Z[3]??"",K=null;if(pU.test(Q)){if(K=Q[1]==="x"||Q[1]==="X",Q=Q.slice(3),Q.startsWith(" "))Q=Q.slice(1)}let q=Q.length>0?Z[0].length-Z[1].length-Z[2].length-Q.length:Z[0].length-Z[1].length-Z[2].length;return{checked:K,content:Q,contentIndent:M+Z[2].length+q,ordered:X,start:Y}}function YN($,M){return f0($,M).startsWith(q2)}function f0($,M){return $.slice(M)}function QN($,M){let Z=N2($);if(Z>=M)return $.slice(M);return $.trim()===""?"":$.slice(Math.min(Z,M))}function fM($){return cU.test($)||xU.test($)||dU.test($)}function mM($){return $.startsWith("<")&&$.endsWith(">")}function N2($){let M=0;while(M<$.length&&$[M]===" ")M+=1;return M}function KN($,M,Z){return M.startsWith(q2)||RM.test(M)||O3.test(M)||LM.test(M)||kM.test(M)||fM(M.trim())||m3(M)||M8($,Z)!==null||mM(M.trim())}function _0($){return $.lines[$.index]??""}function j4($){return $.trim()===""}function qN($,M){for(let Z=M;Z<$.length;Z+=1)if(!j4($[Z]??""))return Z;return-1}function uM($){let M=$.at(-1),Z=M&&SM(M)?M:null;return{blocks:$.filter((X)=>!SM(X)),comments:Z?UN(Z.body):[]}}function UN($){let M;try{M=JSON.parse($)}catch{return[]}if(!Array.isArray(M))return[];return M.flatMap((Z)=>{let J=j8(Z);return J?[J]:[]})}function SM($){return $.type==="directive"&&$.name===t5}function S3($,M={}){let J={index:0,lines:$.replace(/\r\n/g,i).split(i)},X=Z8(J,0,M),{comments:Y,blocks:Q}=uM(X);return h1(Q,Y)}var R4=`
27
+
28
+ `,NN="-",AN=".",GN="***",BN="&#x20;",u3=3,_N=5,FN=4,vM=2,bN=2,DN=1,HN=/([\\`*_[\]])/g,PN=/([\\)&])/g,zN=/(["\\])/g;function J8($,M={}){if($.blocks.length===0&&$.comments.length===0)return"";let Z=$.blocks.map((X)=>X8(X,0,M));if($.comments.length>0)Z.push(hN($.comments));let J=Z.join(R4);return J.endsWith(i)?J:`${J}${i}`}function X8($,M,Z){let J=D1(M);switch($.type){case"blockquote":return TN($,M,Z);case"code":return yN($,M);case"directive":return gN($,M);case"heading":return gM($,M);case"list":return WN($,M,Z);case"listItem":return IM($,M,!1,1,Z);case"paragraph":return`${J}${v3(L4($.children))}`;case"table":return wN($,M,Z);case"thematicBreak":return`${J}${GN}`;case"unsupported":return M===0?$.source:rM($.source,M)}}function TN($,M,Z){let J=$.children.map((Y)=>X8(Y,0,Z)).join(R4),X=D1(M);return J.split(i).map((Y)=>`${X}${q2}${Y.length>0?` ${Y}`:""}`).join(i)}function yN($,M){let Z=[$.language??"",$.meta??""].filter(Boolean).join(" ").trim(),J=D1(M),X=`${J}${C4}${Z?Z:""}`,Y=$.source.length>0?$.source.split(i).map((Q)=>`${J}${Q}`).join(i):J;return`${X}${i}${Y}${i}${J}${C4}`}function gM($,M){let Z=v3(L4($.children)),J=`${D1(M)}${"#".repeat($.depth)}`;return Z.length>0?`${J} ${Z}`:J}function WN($,M,Z){let J=$.start??1;return $.items.map((X)=>IM(X,M,$.ordered,J,Z)).join($.spread?R4:i)}function IM($,M,Z,J,X){let Y=Z?`${J}${AN}`:NN,Q=$.checked===null?"":`[${$.checked?"x":" "}] `,K=`${D1(M)}${Y} ${Q}`,q=M+Y.length+1,U=$.children;if(U.length===0)return Q.length>0?K:K.trimEnd();let[N,...A]=U,G=VN(N,K,Q.length>0,X),B=A.map((F)=>X8(F,q,X)).join($.spread?R4:i);if(!B)return G;return`${G}${$.spread?R4:i}${B}`}function VN($,M,Z,J){switch($.type){case"paragraph":{let X=v3(L4($.children));if(X.length===0)return Z?M:M.trimEnd();return`${M}${X}`}case"heading":return`${M}${gM($,0)}`;case"directive":case"unsupported":{let X=$.type==="directive"?h3($):$.source,[Y,...Q]=X.split(i);return[M+Y,...Q.map((K)=>`${D1(M.length)}${K}`)].join(i)}default:{let X=M.length;return`${M.trimEnd()}${i}${X8($,X,J)}`}}}function wN($,M,Z){let J=$.rows.map((N)=>N.cells.map((A)=>L4(A.children))),X=Math.max(1,...J.map((N)=>N.length)),Y=J[0]??[],Q=Array.from({length:X},(N,A)=>Math.max(u3,jN($.align[A]),...Z.padTableColumns?J.map((G)=>G[A]?.length??0):[Y[A]?.length??0])),K=ON(Q,$.align,M),q=hM(Y,Q,$.align,M,Z),U=J.slice(1).map((N)=>hM(N,Q,$.align,M,Z));return[q??EN(Q,M),K,...U].join(i)}function hM($,M,Z,J,X){let Y=M.map((Q,K)=>{let q=$[K]??"";if(!X.padTableColumns)return q;return RN(q,Q,Z[K])});return`${" ".repeat(J)}| ${Y.join(" | ")} |`}function ON($,M,Z){let J=$.map((X,Y)=>CN(M[Y],X));return`${" ".repeat(Z)}| ${J.join(" | ")} |`}function EN($,M){return`${D1(M)}| ${$.map((Z)=>"".padEnd(Z," ")).join(" | ")} |`}function CN($,M){let Z=Math.max(u3,M-($==="center"?bN:$?DN:0));switch($){case"center":return`:${"-".repeat(Math.max(1,Z))}:`;case"left":return`:${"-".repeat(Math.max(vM,Z))}`;case"right":return`${"-".repeat(Math.max(vM,Z))}:`;default:return"-".repeat(Z)}}function jN($){return $==="center"?_N:$?FN:u3}function RN($,M,Z){if(Z==="right")return $.padStart(M," ");return $.padEnd(M," ")}function L4($){return kN($).map((M)=>LN(M)).join("")}function v3($){return $.replace(/^ +/gm,(M)=>BN.repeat(M.length))}function LN($){switch($.type){case"break":return i;case"image":return IN($);case"inlineCode":return SN($.code);case"link":return pN($);case"text":return mN(pM($.text),$.marks);case"unsupported":return $.source}}function kN($){let M=[];for(let Z of $){let J=M.at(-1);if(J?.type==="text"&&Z.type==="text"&&fN(J.marks,Z.marks)){M[M.length-1]={...J,text:J.text+Z.text};continue}M.push(Z)}return M}function fN($,M){return $.length===M.length&&$.every((Z,J)=>Z===M[J])}function mN($,M){return M.reduce((Z,J)=>{switch(J){case"bold":return`**${Z}**`;case"italic":return`*${Z}*`;case"strikethrough":return`~~${Z}~~`;case"underline":return`${b1}${Z}${E4}`}},$)}function SN($){let M=0,Z=0;for(let Q of $){if(Q==="`"){if(Z+=1,Z>M)M=Z;continue}Z=0}let J=M>0?M+1:1,X="`".repeat(J),Y=$.startsWith("`")||$.endsWith("`")?` ${$} `:$;return`${X}${Y}${X}`}function pM($){return $.replace(HN,"\\$1")}function uN($){return $.replace(PN,"\\$1")}function vN($){return $?` "${$.replace(zN,"\\$1")}"`:""}function hN($){return h3({attributes:"",body:JSON.stringify($,null,2),name:t5})}function gN($,M){let Z=h3($);return M===0?Z:rM(Z,M)}function h3($){let M=$.attributes?`{${$.attributes}}`:"";return`:::${$.name}${M}${i}${$.body}${i}${n5}`}function IN($){let M=pM($.alt??""),Z=lM($.url,$.title),J=$.width?`{width=${$.width}}`:"";return`![${M}]${Z}${J}`}function pN($){return`[${L4($.children)}]${lM($.url,$.title)}`}function lM($,M){return`(${uN($)}${vN(M)})`}function D1($){return" ".repeat($)}function rM($,M){let Z=D1(M);return $.split(i).map((J)=>`${Z}${J}`).join(i)}import{createContext as lN,useContext as rN}from"react";import{createPortal as cN}from"react-dom";import{jsxDEV as dM}from"react/jsx-dev-runtime";var cM=lN(void 0);function xM({children:$,themeStyles:M}){return dM(cM.Provider,{value:M,children:$},void 0,!1,void 0,this)}function Y8({children:$}){let M=rN(cM);if(typeof document>"u")return null;return cN(dM("div",{className:"documint-overlay",style:{display:"contents",...M},children:$},void 0,!1,void 0,this),document.body)}import{useEffect as Q8,useRef as XZ,useState as E1}from"react";import{forwardRef as dN,useCallback as A2,useEffect as aN,useImperativeHandle as iN,useLayoutEffect as sN,useMemo as oN,useRef as sM,useState as g3}from"react";var xN=["box-sizing","width","height","overflow-x","overflow-y","border-top-width","border-right-width","border-bottom-width","border-left-width","border-style","padding-top","padding-right","padding-bottom","padding-left","font-style","font-variant","font-weight","font-stretch","font-size","font-size-adjust","line-height","font-family","text-align","text-transform","text-indent","text-decoration","letter-spacing","word-spacing","tab-size"];function aM($,M,{topGap:Z=8}={}){if(!$.isConnected)return null;let J=getComputedStyle($),X=document.createElement("div");for(let U of xN)X.style.setProperty(U,J.getPropertyValue(U));Object.assign(X.style,{position:"absolute",top:"0",left:"0",visibility:"hidden",whiteSpace:"pre-wrap",wordWrap:"break-word",width:`${$.clientWidth}px`}),X.textContent=$.value.slice(0,M);let Y=document.createElement("span");Y.textContent=$.value.slice(M)||".",X.appendChild(Y),document.body.appendChild(X);let Q=$.getBoundingClientRect(),K=parseFloat(J.lineHeight)||Y.offsetHeight,q={left:Q.left+Y.offsetLeft+parseFloat(J.borderLeftWidth)-$.scrollLeft,top:Q.top+Y.offsetTop+parseFloat(J.borderTopWidth)+K+Z-$.scrollTop};return document.body.removeChild(X),q}import{jsxDEV as y0,Fragment as YA}from"react/jsx-dev-runtime";var nN=240,tN="documint-leaf-menu-item documint-completion-item",k4=dN(function({actions:M,completionSources:Z,onChange:J,placeholder:X,readOnly:Y=!1,rows:Q=3,value:K},q){let U=sM(null);iN(q,()=>U.current,[]);let N=oN(()=>ZA(Z),[Z]),[A,G]=g3(null),[B,F]=g3(0),[_,D]=g3(null),T=A2((H,P)=>{if(!N.length){G(null);return}let E=JA(H,P,N);if(!E){G(null);return}G(E),F(0)},[N]),O=A2((H)=>{let P=H.currentTarget.value,E=H.currentTarget.selectionEnd??P.length;J(P),T(P,E)},[J,T]),y=A2((H)=>{let P=H.currentTarget;T(P.value,P.selectionEnd??P.value.length)},[T]),R=A2(()=>{G(null)},[]),C=A2((H)=>{if(!U.current||!A)return;let E=`${A.trigger}${H.label} `,j=K.slice(0,A.triggerStart),W=K.slice(A.caret),b=j+E+W,z=A.triggerStart+E.length;J(b),G(null),requestAnimationFrame(()=>{let u=U.current;if(!u)return;u.focus(),u.setSelectionRange(z,z)})},[A,J,K]),m=A2((H)=>{if(A&&A.matches.length>0){if(H.key==="ArrowDown"){H.preventDefault(),H.stopPropagation(),F((P)=>(P+1)%A.matches.length);return}if(H.key==="ArrowUp"){H.preventDefault(),H.stopPropagation(),F((P)=>(P-1+A.matches.length)%A.matches.length);return}if(H.key==="Enter"||H.key==="Tab"){H.preventDefault(),H.stopPropagation();let P=A.matches[B];if(P)C(P);return}if(H.key==="Escape"){H.preventDefault(),H.stopPropagation(),G(null);return}}if(H.key==="Escape"&&M.kind==="edit")H.preventDefault(),M.onCancel()},[M,A,B,C]);return sN(()=>{if(!A){D(null);return}let H=()=>{let P=U.current;if(!P)return;D(aM(P,A.triggerStart))};return H(),window.addEventListener("scroll",H,!0),window.addEventListener("resize",H),()=>{window.removeEventListener("scroll",H,!0),window.removeEventListener("resize",H)}},[A]),y0("div",{className:"documint-leaf-input-field",children:[y0("textarea",{className:"documint-leaf-input",onBlur:R,onChange:O,onKeyDown:m,onSelect:y,placeholder:X,readOnly:Y,ref:U,rows:Q,value:K},void 0,!1,void 0,this),eN(M),A&&_&&A.matches.length>0?y0(Y8,{children:y0($A,{activeIndex:B,left:_.left,matches:A.matches,onHover:F,onSelect:C,top:_.top},void 0,!1,void 0,this)},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)});function eN($){if($.kind==="edit")return y0(YA,{children:[y0(I3,{className:"documint-leaf-input-cancel",icon:O4,label:"Cancel editing",onClick:$.onCancel},void 0,!1,void 0,this),y0(I3,{className:"documint-leaf-input-save",disabled:$.saveDisabled??!1,icon:V1,label:"Save",onClick:$.onSave},void 0,!1,void 0,this)]},void 0,!0,void 0,this);return y0(I3,{className:"documint-leaf-input-submit",disabled:$.submitDisabled??!1,icon:_1,iconSize:15,label:$.submitLabel,onClick:$.onSubmit},void 0,!1,void 0,this)}function I3({className:$,disabled:M=!1,icon:Z,iconSize:J=14,label:X,onClick:Y}){return y0("button",{"aria-label":X,className:`documint-leaf-action ${$}`,disabled:M,onClick:Y,title:X,type:"button",children:y0(Z,{size:J,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function $A({activeIndex:$,left:M,matches:Z,onHover:J,onSelect:X,top:Y}){let Q=sM(null);return aN(()=>{let K=Q.current;if(!K)return;let q=K.children[$];if(q instanceof HTMLElement)q.scrollIntoView({block:"nearest"})},[$]),y0("div",{className:"documint-leaf-menu documint-completion-popover",ref:Q,role:"listbox",style:{position:"fixed",left:M,top:Y,maxHeight:nN,overflowY:"auto"},children:Z.map((K,q)=>{let U=q===$;return y0("button",{"aria-selected":U,className:`${tN}${U?" is-active":""}`,onPointerDown:MA,onPointerEnter:()=>J(q),onClick:()=>X(K),role:"option",type:"button",children:y0("span",{children:K.label},void 0,!1,void 0,this)},K.label,!1,void 0,this)})},void 0,!1,void 0,this)}function MA($){$.preventDefault()}function ZA($){if(!$?.length)return[];return $.map((M)=>({trigger:M.trigger,items:[...M.items].sort((Z,J)=>Z.label.localeCompare(J.label,void 0,{sensitivity:"base"}))}))}function JA($,M,Z){for(let J=M-1;J>=0;J-=1){let X=$[J];if(iM(X))return null;let Y=Z.find((K)=>K.trigger===X);if(!Y)continue;if(J>0&&!iM($[J-1]))return null;let Q=$.slice(J+1,M);return{trigger:Y.trigger,query:Q,triggerStart:J,caret:M,matches:XA(Y.items,Q)}}return null}function iM($){return $===void 0||$===" "||$===`
29
+ `||$==="\t"}function XA($,M){if(!M)return $;let Z=M.toLowerCase();return $.filter((J)=>J.label.toLowerCase().includes(Z))}import{Fragment as QA}from"react";import{jsxDEV as p3}from"react/jsx-dev-runtime";function l3({value:$,completionSources:M,onEdit:Z}){return p3("p",{onDoubleClick:Z,children:KA($,M)},void 0,!1,void 0,this)}function KA($,M){let Z=qA($,M);if(Z.length===1&&Z[0].kind==="text")return $;return Z.map((J,X)=>J.kind==="token"?p3("span",{className:"documint-mention",children:[J.trigger,J.label]},X,!0,void 0,this):p3(QA,{children:J.text},X,!1,void 0,this))}function qA($,M){if(!M?.length||!M.some((Q)=>$.includes(Q.trigger)))return[{kind:"text",text:$}];let Z=new Map;for(let Q of M){let K=Q.items.map((q)=>q.label).sort((q,U)=>U.length-q.length);Z.set(Q.trigger,K)}let J=[],X=0,Y=0;while(X<$.length){let Q=$[X],K=Z.get(Q);if(K!==void 0&&(X===0||UA($[X-1]))){let U=K.find((N)=>$.startsWith(N,X+1));if(U){if(X>Y)J.push({kind:"text",text:$.slice(Y,X)});J.push({kind:"token",trigger:Q,label:U}),X+=1+U.length,Y=X;continue}}X+=1}if(Y<$.length)J.push({kind:"text",text:$.slice(Y)});return J}function UA($){return $===" "||$===`
30
+ `||$==="\t"}import{Children as oM,isValidElement as nM,useEffect as NA,useRef as AA,useState as GA}from"react";import{jsxDEV as Y0}from"react/jsx-dev-runtime";var r3=($)=>{$.preventDefault()},c3=($)=>$.isPrimary&&$.button===0;function BA({children:$}){return Y0("div",{className:"documint-leaf-toolbar",children:oM.map($,_A)},void 0,!1,void 0,this)}function _A($){if(!nM($))return null;if($.type===eM){let M=$.props;return Y0(tM,{children:Y0(FA,{...M},void 0,!1,void 0,this)},void 0,!1,void 0,this)}if($.type===$Z){let{className:M}=$.props;return Y0("div",{className:f4("documint-leaf-toolbar-divider",M)},void 0,!1,void 0,this)}if($.type===MZ){let M=$.props;return Y0(bA,{...M},void 0,!1,void 0,this)}return null}function FA({active:$=!1,className:M,disabled:Z=!1,icon:J,label:X,onClick:Y}){return Y0("button",{"aria-label":X,className:f4("documint-leaf-toolbar-button",$?"active":null,M),disabled:Z,onPointerDown:(Q)=>{if(r3(Q),!Z&&c3(Q))Y()},title:X,type:"button",children:Y0(J,{size:15,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this)}function bA({children:$,className:M,icon:Z,label:J,onSelect:X}){let Y=AA(null),[Q,K]=GA(!1);return NA(()=>{if(!Q)return;let q=(U)=>{if(Y.current&&U.target instanceof Node&&!Y.current.contains(U.target))K(!1)};return window.addEventListener("pointerdown",q),()=>{window.removeEventListener("pointerdown",q)}},[Q]),Y0(tM,{children:Y0("div",{className:"documint-leaf-toolbar-menu-shell",ref:Y,children:[Y0(DA,{className:M,icon:Z,isOpen:Q,label:J,onClick:()=>K((q)=>!q)},void 0,!1,void 0,this),Q?Y0("div",{className:"documint-leaf-menu",role:"menu",children:oM.map($,(q)=>HA(q,(U)=>{K(!1),X(U)}))},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function DA({className:$,icon:M,isOpen:Z,label:J,onClick:X}){return Y0("button",{"aria-expanded":Z,"aria-haspopup":"menu","aria-label":J,className:f4("documint-leaf-toolbar-button",Z?"active":null,$),onPointerDown:(Y)=>{if(r3(Y),c3(Y))X()},title:J,type:"button",children:[Y0(M,{size:15,strokeWidth:2.2},void 0,!1,void 0,this),Y0(N4,{className:f4("documint-leaf-toolbar-menu-chevron",Z?"is-open":null),size:13,strokeWidth:2.2},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function HA($,M){if(!nM($))return null;if($.type===JZ){let{className:Q}=$.props;return Y0("div",{className:f4("documint-leaf-menu-divider",Q),role:"separator"},void 0,!1,void 0,this)}if($.type!==ZZ)return null;let{disabled:Z=!1,icon:J,text:X,value:Y}=$.props;return Y0("button",{className:"documint-leaf-menu-item",disabled:Z,onPointerDown:(Q)=>{if(r3(Q),!Z&&c3(Q))M(Y)},role:"menuitem",type:"button",children:[Y0(J,{size:15,strokeWidth:2.2},void 0,!1,void 0,this),Y0("span",{children:X},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function f4(...$){return $.filter(Boolean).join(" ")}function tM({children:$}){return Y0("div",{className:"documint-leaf-toolbar-group",children:$},void 0,!1,void 0,this)}function eM($){return null}function $Z($){return null}function MZ($){return null}function ZZ($){return null}function JZ($){return null}var d=Object.assign(BA,{Button:eM,Divider:$Z,Menu:MZ,MenuDivider:JZ,MenuItem:ZZ});import{jsxDEV as r,Fragment as yA}from"react/jsx-dev-runtime";var PA=!1,zA=220,C1=()=>{};function x3($){let M=$.mode==="create",Z=$.mode==="create"?$:null,J=$.mode==="thread"?$:null,X=$.canEdit,Y=$.link,Q=J?.thread??null,K=Q?.comments??[],q=K[0]??null,U=Q?Z1(Q):!1,N=J?.animateInitialComment??!1,[A,G]=E1(null),[B,F]=E1(""),[_,D]=E1(""),[T,O]=E1(""),[y,R]=E1(!N),[C,m]=E1(PA),[H,P]=E1(!1),E=XZ(null),j=XZ(null),W=$.mentionSources,b=Q?u8(Q):null,z=b?YZ(b):"",u=X&&!U,v=u&&B.trim().length>0,l=u&&_.trim().length>0,g=X&&T.trim().length>0,w=M||H,V=!M||C,L=!M&&Boolean(Q),f=Boolean(q),x=M?C:!0,h=J?.onDeleteComment??C1,Q0=J?.onDeleteThread??C1,b0=J?.onToggleResolved??C1,e0=Z?.activeMarks??[],L1=Z?.onToggleBold??C1,g4=Z?.onToggleItalic??C1,B8=Z?.onToggleStrikethrough??C1,I4=Z?.onToggleUnderline??C1,p4=X?M?"Add a comment":"Reply to this comment":"Comment editing is disabled",S0=M?T:_;Q8(()=>{if(A!==null&&(A<0||A>=K.length))G(null),F("")},[K.length,A]),Q8(()=>{if(!f||!N){R(!0);return}R(!1);let W0=requestAnimationFrame(()=>{R(!0)});return()=>{cancelAnimationFrame(W0)}},[N,q,f]),Q8(()=>{if(!J||!N){P(!1);return}P(!0);let W0=window.setTimeout(()=>{P(!1)},zA);return()=>{window.clearTimeout(W0)}},[N,J]),Q8(()=>{if(!M||!C||!X)return;let W0=requestAnimationFrame(()=>{j.current?.focus()});return()=>{cancelAnimationFrame(W0)}},[X,M,C]);let P0=()=>{G(null),F("")},l4=(W0,c4)=>{if(!L||!u)return;G(W0),F(c4)},_8=(W0)=>{if(!J)return;J.onEditComment(W0,B),P0()},r4=()=>{if(!J)return;J.onReply(_),D("")},k1=()=>{if(!Z||!g)return;Z.onCreateThread(T),O("")},e=w?`documint-comment-leaf documint-comment-leaf-create${x?" is-expanded":""}`:"documint-comment-leaf",n=L||f||V?r(TA,{canCreate:g,canEdit:X,canMutateThread:u,canReply:l,canSaveEditedComment:v,comments:K,composerRef:j,editDraft:B,editingCommentIndex:A,isComposerVisible:V,isInitialCommentVisible:y,isResolved:U,link:Y,mentionSources:W,mode:$.mode,onBeginEditingComment:l4,onCancelEditing:P0,onChangeCreateDraft:O,onChangeEditDraft:F,onChangeReplyDraft:D,onDeleteComment:h,onDeleteThread:Q0,onSubmitCreate:k1,onSubmitEditedComment:_8,onSubmitReply:r4,onToggleResolved:b0,rootComment:q,showRootComment:f,showThreadChrome:L,threadAge:z,composerPlaceholder:p4,composerValue:S0},void 0,!1,void 0,this):null;return r("div",{className:e,ref:E,children:r("div",{className:w?"documint-comment-leaf-create-shell":void 0,children:[w?r(d,{children:[r(d.Button,{className:"documint-comment-leaf-create-button",icon:y4,label:"Add comment",onClick:()=>m(!0)},void 0,!1,void 0,this),r(d.Divider,{className:"documint-comment-leaf-create-divider"},void 0,!1,void 0,this),r(d.Button,{active:e0.includes("bold"),className:"documint-comment-leaf-create-mark",icon:U4,label:"Bold",onClick:L1},void 0,!1,void 0,this),r(d.Button,{active:e0.includes("italic"),className:"documint-comment-leaf-create-mark",icon:H4,label:"Italic",onClick:g4},void 0,!1,void 0,this),r(d.Button,{active:e0.includes("underline"),className:"documint-comment-leaf-create-mark",icon:w4,label:"Underline",onClick:I4},void 0,!1,void 0,this),r(d.Button,{active:e0.includes("strikethrough"),className:"documint-comment-leaf-create-mark",icon:W4,label:"Strikethrough",onClick:B8},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,r("div",{className:w?"documint-comment-leaf-create-content":void 0,children:n},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function TA({canCreate:$,canEdit:M,canMutateThread:Z,canReply:J,canSaveEditedComment:X,comments:Y,composerRef:Q,editDraft:K,editingCommentIndex:q,isComposerVisible:U,isInitialCommentVisible:N,isResolved:A,link:G,mentionSources:B,mode:F,onBeginEditingComment:_,onCancelEditing:D,onChangeCreateDraft:T,onChangeEditDraft:O,onChangeReplyDraft:y,onDeleteComment:R,onDeleteThread:C,onSubmitCreate:m,onSubmitEditedComment:H,onSubmitReply:P,onToggleResolved:E,rootComment:j,showRootComment:W,showThreadChrome:b,threadAge:z,composerPlaceholder:u,composerValue:v}){return r(yA,{children:[b?r("div",{className:"documint-comment-leaf-header",children:[r("span",{className:"documint-comment-leaf-age",children:z},void 0,!1,void 0,this),r("div",{className:"documint-comment-leaf-actions",children:[r("button",{className:"documint-leaf-action","aria-label":A?"Reopen comment":"Resolve comment",disabled:!M,onClick:E,title:A?"Reopen comment":"Resolve comment",type:"button",children:r(V1,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Delete comment thread",disabled:!M,onClick:C,title:"Delete comment thread",type:"button",children:r(E0,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},void 0,!0,void 0,this):null,b&&G?r("div",{className:"documint-comment-leaf-link",children:[G.title?r("div",{className:"documint-link-leaf-title",children:G.title},void 0,!1,void 0,this):null,r("div",{className:"documint-link-leaf-url",children:G.url},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,r("div",{className:`documint-comment-thread${W?"":" is-empty"}`,children:[r("article",{className:W?`documint-comment-message documint-comment-message-root${N?" is-visible":""}`:"documint-comment-message documint-comment-message-root is-hidden",children:j?r(l3,{completionSources:B,onEdit:()=>_(0,j.body),value:j.body},void 0,!1,void 0,this):null},void 0,!1,void 0,this),Y.slice(1).map((l,g)=>{let w=g+1,V=q===w;return r("article",{className:"documint-comment-message",children:[!V?r("div",{className:"documint-comment-message-meta",children:[r("span",{children:YZ(l.updatedAt)},void 0,!1,void 0,this),Z?r("div",{className:"documint-comment-leaf-actions",children:[r("button",{className:"documint-leaf-action","aria-label":"Edit comment",disabled:!Z,onClick:()=>{_(w,l.body)},title:"Edit comment",type:"button",children:r(w1,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this),r("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Delete comment",disabled:!Z,onClick:()=>R(w),title:"Delete comment",type:"button",children:r(E0,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null]},void 0,!0,void 0,this):null,V?r(k4,{actions:{kind:"edit",onCancel:D,onSave:()=>H(w),saveDisabled:!X},completionSources:B,onChange:O,readOnly:!M,rows:3,value:K},void 0,!1,void 0,this):r(l3,{completionSources:B,onEdit:()=>_(w,l.body),value:l.body},void 0,!1,void 0,this)]},`${l.updatedAt}:${w}`,!0,void 0,this)})]},void 0,!0,void 0,this),r("div",{className:`documint-comment-reply${b?"":" is-standalone"}${U?" is-visible":""}`,children:r(k4,{actions:F==="create"?{kind:"compose",onSubmit:m,submitDisabled:!$,submitLabel:"Create comment"}:{kind:"compose",onSubmit:P,submitDisabled:!J,submitLabel:"Reply"},completionSources:B,onChange:F==="create"?T:y,placeholder:u,readOnly:!M,ref:Q,rows:3,value:v},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function YZ($){let M=new Date($);if(Number.isNaN(M.getTime()))return $;let Z=M.getTime()-Date.now(),J=60000,X=60*J,Y=24*X,Q=7*Y,K=30*Y,q=365*Y,U=new Intl.RelativeTimeFormat(void 0,{numeric:"auto"});if(Math.abs(Z)<J)return"just now";if(Math.abs(Z)<X)return U.format(Math.round(Z/J),"minute");if(Math.abs(Z)<Y)return U.format(Math.round(Z/X),"hour");if(Math.abs(Z)<Q)return U.format(Math.round(Z/Y),"day");if(Math.abs(Z)<q)return U.format(Math.round(Z/K),"month");return U.format(Math.round(Z/q),"year")}import{jsxDEV as m0}from"react/jsx-dev-runtime";var WA=[{icon:A4,label:"Heading 1",text:"# "},{icon:G4,label:"Heading 2",text:"## "},{icon:B4,label:"Heading 3",text:"### "},{icon:_4,label:"Heading 4",text:"#### "},{icon:F4,label:"Heading 5",text:"##### "},{icon:b4,label:"Heading 6",text:"###### "}],VA=[{columns:2,text:"2 columns"},{columns:3,text:"3 columns"},{columns:4,text:"4 columns"},{columns:5,text:"5 columns"}];function QZ({onInsert:$,onInsertTable:M}){return m0(d,{children:[m0(d.Button,{icon:T4,label:"Insert bulleted list",onClick:()=>$("- ")},void 0,!1,void 0,this),m0(d.Button,{icon:P4,label:"Insert numbered list",onClick:()=>$("1. ")},void 0,!1,void 0,this),m0(d.Button,{icon:z4,label:"Insert task list",onClick:()=>$("- [ ] ")},void 0,!1,void 0,this),m0(d.Divider,{},void 0,!1,void 0,this),m0(d.Menu,{icon:D4,label:"Insert heading",onSelect:$,children:WA.map(({icon:Z,label:J,text:X})=>m0(d.MenuItem,{icon:Z,text:J,value:X},X,!1,void 0,this))},void 0,!1,void 0,this),m0(d.Menu,{icon:F1,label:"Insert table",onSelect:(Z)=>M(Number(Z)),children:VA.map(({columns:Z,text:J})=>m0(d.MenuItem,{icon:F1,text:J,value:String(Z)},Z,!1,void 0,this))},void 0,!1,void 0,this),m0(d.Divider,{},void 0,!1,void 0,this),m0(d.Button,{icon:V4,label:"Insert blockquote",onClick:()=>$("> ")},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{jsxDEV as K8}from"react/jsx-dev-runtime";function KZ({anchor:$,children:M,status:Z="default"}){let J=!$.isSelection;return K8(Y8,{children:K8("div",{className:"documint-leaf-anchor","data-selection":$.isSelection?"true":"false",onPointerEnter:$.onPointerEnter,onPointerLeave:$.onPointerLeave,style:{left:`${$.left}px`,top:`${$.top}px`},children:[J?K8("div",{className:"documint-leaf-bridge"},void 0,!1,void 0,this):null,K8("div",{className:"documint-leaf-shell","data-status":Z,children:M},void 0,!1,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}import{useEffect as qZ,useRef as wA,useState as UZ}from"react";import{jsxDEV as C0}from"react/jsx-dev-runtime";function NZ({canEdit:$,onDelete:M,onSave:Z,title:J,url:X}){let[Y,Q]=UZ(X),[K,q]=UZ(!1),U=wA(null),N=OA(),A=Y.trim(),G=$&&A.length>0,B=$&&!K,F=`${N}click to open`,_=`documint-link-leaf-row${K?" is-editing":""}`;return qZ(()=>{if(K)return;Q(X)},[K,X]),qZ(()=>{if(!K)return;U.current?.focus()},[K]),C0("div",{className:"documint-link-leaf",children:[J?C0("div",{className:"documint-link-leaf-title",children:J},void 0,!1,void 0,this):null,C0("div",{className:_,children:[K?C0(k4,{actions:{kind:"edit",onCancel:()=>{Q(X),q(!1)},onSave:()=>{Z(A),q(!1)},saveDisabled:!G},onChange:Q,readOnly:!$,ref:U,rows:3,value:Y},void 0,!1,void 0,this):C0("div",{className:"documint-link-leaf-url",children:X},void 0,!1,void 0,this),B?C0("div",{className:"documint-link-leaf-actions",children:[C0("button",{className:"documint-leaf-action","aria-label":"Edit link",onClick:()=>{if(!$)return;Q(X),q(!0)},title:"Edit link",type:"button",children:C0(w1,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this),C0("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Remove link",onClick:M,title:"Remove link",type:"button",children:C0(E0,{size:14,strokeWidth:2.2},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null]},void 0,!0,void 0,this),C0("div",{className:"documint-link-leaf-divider"},void 0,!1,void 0,this),C0("div",{className:"documint-link-leaf-hint",children:F},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}function OA(){if(typeof navigator>"u")return"Ctrl+";let $=navigator.platform||navigator.userAgent;return/Mac|iPhone|iPad|iPod/.test($)?"CMD+":"CTRL+"}import{jsxDEV as j0}from"react/jsx-dev-runtime";var EA=[{text:"Column left",value:"left"},{text:"Column right",value:"right"}],CA=[{text:"Row above",value:"above"},{text:"Row below",value:"below"}],d3={text:"Delete column",value:"delete"},a3={text:"Delete row",value:"delete"},AZ={text:"Delete table",value:"delete"};function GZ({canDeleteColumn:$,canDeleteRow:M,onDeleteColumn:Z,onDeleteRow:J,onDeleteTable:X,onInsertColumn:Y,onInsertRow:Q}){return j0(d,{children:[j0(d.Menu,{icon:G1,label:"Column actions",onSelect:(K)=>{if(K===d3.value){Z();return}Y(K)},children:[EA.map(({text:K,value:q})=>j0(d.MenuItem,{icon:K2,text:K,value:q},q,!1,void 0,this)),j0(d.MenuDivider,{},void 0,!1,void 0,this),j0(d.MenuItem,{disabled:!$,icon:E0,text:d3.text,value:d3.value},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j0(d.Menu,{icon:B1,label:"Row actions",onSelect:(K)=>{if(K===a3.value){J();return}Q(K)},children:[CA.map(({text:K,value:q})=>j0(d.MenuItem,{icon:K2,text:K,value:q},q,!1,void 0,this)),j0(d.MenuDivider,{},void 0,!1,void 0,this),j0(d.MenuItem,{disabled:!M,icon:E0,text:a3.text,value:a3.value},void 0,!1,void 0,this)]},void 0,!0,void 0,this),j0(d.Divider,{},void 0,!1,void 0,this),j0(d.Menu,{icon:F1,label:"Table actions",onSelect:()=>X(),children:j0(d.MenuItem,{icon:E0,text:AZ.text,value:AZ.value},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)}import{useEffect as BZ,useEffectEvent as _Z,useLayoutEffect as jA,useMemo as RA,useRef as i3,useState as LA}from"react";function q8($,M){if(!$||$.kind==="task-toggle")return null;if($.commentThreadIndex!==null){let Z=M[$.commentThreadIndex]??null;if(!Z)return null;return{kind:"comment",left:$.anchorLeft,link:$.kind==="link"?{title:$.title,url:$.url}:null,thread:Z,threadIndex:$.commentThreadIndex,top:$.anchorBottom}}if($.kind!=="link")return null;return{endOffset:$.endOffset,kind:"link",left:$.anchorLeft,regionId:$.regionId,startOffset:$.startOffset,title:$.title,top:$.anchorBottom,url:$.url}}var kA=600,fA=530,G2=24;function bZ({canShowInsertionLeaf:$,canShowTableLeaf:M,commentState:Z,editorState:J,editorViewportState:X,getScrollTop:Y,layoutWidth:Q,onVisibilityChange:K,scrollContentHeight:q,scrollTo:U,viewportHeight:N}){let A=RA(()=>s(J),[J]),[G,B]=LA(null),F=A.start.regionId===A.end.regionId&&A.start.offset===A.end.offset,_=i3(!0),D=i3(0),T=i3(null),O=_Z(()=>{K()}),y=_Z(()=>{D.current=typeof performance<"u"?performance.now():Date.now(),_.current=!0,O()});return jA(()=>{let R=mA({canShowInsertionLeaf:$,canShowTableLeaf:M,commentState:Z,normalizedSelection:A,state:J,viewport:X.get()});B((C)=>hA(C,R)?C:R)},[$,M,Z,J,X]),BZ(()=>{let R=J.selection.focus,C={layoutWidth:Q,offset:R.offset,regionId:R.regionId,scrollContentHeight:q,viewportHeight:N};if(gA(T.current,C))return;let m=G6(J,X.get(),R);if(!m)return;let H=Y(),P=H+G2,E=H+N-G2;if(m.top<P){let j=U(Math.max(0,m.top-G2));if(FZ(m,j,N,G2))T.current=C;return}if(m.top+m.height>E){let j=U(Math.max(0,m.top+m.height-N+G2));if(FZ(m,j,N,G2))T.current=C;return}T.current=C},[J,J.selection.focus.offset,J.selection.focus.regionId,X,Q,q,U,N]),BZ(()=>{if(_.current=!0,O(),!F||typeof window>"u")return;let R=window.setInterval(()=>{if((typeof performance<"u"?performance.now():Date.now())-D.current<kA){if(!_.current)_.current=!0,O();return}_.current=!_.current,O()},fA);return()=>{window.clearInterval(R)}},[F]),{leaf:G,isVisible:()=>_.current,markActivity:y}}function mA({canShowInsertionLeaf:$,canShowTableLeaf:M,commentState:Z,normalizedSelection:J,state:X,viewport:Y}){if(!Y)return null;let Q=X.selection.focus;if(J.start.regionId!==J.end.regionId||J.start.offset!==J.end.offset)return null;let K=$?vA(X,Y):null;if(K)return K;let q=M?SA(X,Y):null;if(q)return q;return q8(A6(X,Y,Q,Z.liveRanges),Z.threads)}function SA($,M){let Z=$.selection.focus,J=$.documentIndex.regionIndex.get(Z.regionId),X=J?$.documentIndex.tableCellIndex.get(J.id)??null:null;if(!J||!X)return null;let Y=$.documentIndex.blockIndex.get(J.blockId),Q=Y?.type==="table"?$.documentIndex.document.blocks[Y.rootIndex]:null;if(!Y||!Q||Q.type!=="table")return null;let K=o0($,M,Z),q=uA(M,J.id),U=Math.max(1,...Q.rows.map((N)=>N.cells.length));return K&&q!==null?{cellIndex:X.cellIndex,columnCount:U,kind:"table",left:q,rowCount:Q.rows.length,rowIndex:X.rowIndex,top:K.top+K.height}:null}function uA($,M){let Z=$.layout.lines.find((J)=>J.regionId===M);return Z?Z.left:null}function vA($,M){let Z=$.selection.focus,J=$.documentIndex.regionIndex.get(Z.regionId);if(!J||J.blockType!=="paragraph"||J.text.length>0)return null;if(Z.offset!==0)return null;let X=$.documentIndex.blockIndex.get(J.blockId);if(!X||X.parentBlockId!==null)return null;let Y=o0($,M,Z);return Y?{kind:"insertion",left:Y.left,top:Y.top+Y.height}:null}function hA($,M){if($===M)return!0;if(!$||!M||$.kind!==M.kind)return!1;switch($.kind){case"comment":return M.kind==="comment"&&$.left===M.left&&$.link?.title===M.link?.title&&$.link?.url===M.link?.url&&$.thread===M.thread&&$.threadIndex===M.threadIndex&&$.top===M.top;case"insertion":return M.kind==="insertion"&&$.left===M.left&&$.top===M.top;case"link":return M.kind==="link"&&$.endOffset===M.endOffset&&$.left===M.left&&$.regionId===M.regionId&&$.startOffset===M.startOffset&&$.title===M.title&&$.top===M.top&&$.url===M.url;case"table":return M.kind==="table"&&$.cellIndex===M.cellIndex&&$.columnCount===M.columnCount&&$.left===M.left&&$.rowCount===M.rowCount&&$.rowIndex===M.rowIndex&&$.top===M.top}}function gA($,M){return $?.layoutWidth===M.layoutWidth&&$.regionId===M.regionId&&$.offset===M.offset&&$.scrollContentHeight===M.scrollContentHeight&&$.viewportHeight===M.viewportHeight}function FZ($,M,Z,J){return $.top>=M+J&&$.top+$.height<=M+Z-J}import{useEffect as IA,useEffectEvent as pA,useMemo as s3,useRef as lA,useState as rA}from"react";function DZ($){let M=s3(()=>cA($),[$]),Z=s3(()=>M.join(`
31
+ `),[M]),[J,X]=rA(new Map),Y=lA(new Map),Q=pA((K,q)=>{if(typeof Image>"u")return;let U=new Set(K),N=Y.current;X((A)=>dA(A,U,N));for(let A of K){if(xA(J,N,A))continue;aA(A,N,X,q)}});return IA(()=>{let K=!0;return Q(M,()=>K),()=>{K=!1}},[Z]),s3(()=>J.size===0?null:{images:J},[J])}function cA($){return[...R$($)].sort()}function xA($,M,Z){return $.get(Z)?.status==="loaded"||M.has(Z)}function dA($,M,Z){let J=!1,X=new Map($);for(let Y of X.keys())if(!M.has(Y))X.delete(Y),Z.delete(Y),J=!0;return J?X:$}function aA($,M,Z,J){let X=new Image;X.decoding="async",X.crossOrigin="anonymous",M.set($,X),Z((Y)=>{let Q=new Map(Y);return Q.set($,iA()),Q}),X.onload=()=>{if(M.delete($),!J())return;Z((Y)=>{let Q=new Map(Y);return Q.set($,sA(X)),Q})},X.onerror=()=>{if(M.delete($),!J())return;Z((Y)=>{let Q=new Map(Y);return Q.set($,oA()),Q})},X.src=$}function iA(){return{intrinsicHeight:0,intrinsicWidth:0,source:null,status:"loading"}}function sA($){return{intrinsicHeight:$.naturalHeight,intrinsicWidth:$.naturalWidth,source:$,status:"loaded"}}function oA(){return{intrinsicHeight:0,intrinsicWidth:0,source:null,status:"error"}}import{useEffect as HZ,useEffectEvent as F0,useRef as m4,useState as nA}from"react";var tA=48;function PZ({applyNextState:$,autoScrollDuringDrag:M,canvasRef:Z,commentState:J,editorStateRef:X,editorViewportState:Y,focusInput:Q,onActivity:K,readCurrentState:q,resolvePoint:U}){let[N,A]=nA(null),G=m4(null),B=m4(!1),F=m4(null),_=m4(null),D=m4(null),T=q8(N,J.threads),O=N?.kind==="task-toggle"||T?.kind==="link"?"pointer":"text";HZ(()=>{if(N&&N.kind!=="task-toggle"&&!T)A(null)},[N,T]),HZ(()=>()=>{if(G.current!==null)window.clearTimeout(G.current)},[]);let y=F0(()=>{if(G.current!==null)window.clearTimeout(G.current),G.current=null}),R=F0(()=>{y(),G.current=window.setTimeout(()=>{if(G.current=null,!B.current)A(null)},tA)}),C=F0(()=>{if(!B.current)y(),A(null)}),m=F0((w)=>{if(!w){C();return}if(w.kind==="task-toggle"){y(),A((V)=>V?.kind==="task-toggle"&&V.listItemId===w.listItemId?V:w);return}if(w.commentThreadIndex!==null){if(!(J.threads[w.commentThreadIndex]??null)){C();return}y();let L=w.commentThreadIndex;A((f)=>f?.kind!=="task-toggle"&&f?.commentThreadIndex===L?f:w);return}if(w.kind!=="link"){C();return}y(),A((V)=>V?.kind==="link"&&V.title===w.title&&V.url===w.url&&V.startOffset===w.startOffset&&V.endOffset===w.endOffset?V:w)}),H=F0((w)=>{let V=X.current;if(!V)return null;let L=U(w);if(!L)return null;return N6(V,Y.get(),L,J.liveRanges)}),P=F0((w)=>{let V=Z.current;if(V&&F.current===w)V.releasePointerCapture(w)}),E=F0(()=>{F.current=null,_.current=null}),j=F0((w)=>{P(w.pointerId),E()}),W=F0((w)=>{if(D.current=w.pointerType,w.pointerType==="touch")return;let V=Z.current,L=q(),f=U(w);if(!f)return;if(H(w)?.kind==="task-toggle")return;let h=F5(L,Y.get(),f);if(!V||!h)return;F.current=w.pointerId,_.current={offset:h.offset,regionId:h.regionId},K(),V.setPointerCapture(w.pointerId),$(Z0(L,{offset:h.offset,regionId:h.regionId})),Q({offset:h.offset,regionId:h.regionId})}),b=F0((w)=>{let V=_.current,L=q(),f=U(w);if(!f)return;if(F.current!==w.pointerId||!V){m(H(w));return}let x=R2(L,Y.get(),f,V);if(!x)return;K(),M(w),$(Z0(L,{anchor:V,focus:x}))}),z=F0(()=>{if(!B.current)R()}),u=F0((w)=>{let V=D.current==="touch";D.current=null;let L=H(w);if(L?.kind==="task-toggle"){let Q0=q(),b0=K3(Q0,L.listItemId);if(b0)w.preventDefault(),w.stopPropagation(),K(),$(b0);return}if(L?.kind==="link"&&(w.metaKey||w.ctrlKey)){w.preventDefault(),w.stopPropagation(),w.currentTarget.ownerDocument.defaultView?.open(L.url,"_blank","noopener,noreferrer");return}if(!V){Q();return}let f=q(),x=U(w),h=x?F5(f,Y.get(),x):null;if(h)K(),$(Z0(f,{offset:h.offset,regionId:h.regionId})),Q({offset:h.offset,regionId:h.regionId});else Q()}),v=F0((w)=>{let V=q(),L=U(w),f=H(w);if(!L||f?.kind==="task-toggle")return;let x=U6(V,Y.get(),L);if(!x)return;w.preventDefault(),w.stopPropagation(),K(),$(Z0(V,x)),Q()}),l=F0(()=>{B.current=!0,y()}),g=F0(()=>{B.current=!1,R()});return{canvasHandlers:{onClick:u,onDoubleClick:v,onPointerCancel:j,onPointerDown:W,onPointerLeave:z,onPointerMove:b,onPointerUp:j},cursor:O,leaf:T,leafHandlers:{onPointerEnter:l,onPointerLeave:g}}}import{useEffect as e3,useEffectEvent as G0,useLayoutEffect as $G,useRef as OZ,useState as MG}from"react";var o3=[{key:"Backspace",command:"deleteBackward"},{key:"Enter",command:"insertLineBreak"},{key:"Home",command:"moveToLineStart"},{key:"End",command:"moveToLineEnd"},{key:"Tab",command:"indent"},{key:"Tab",shiftKey:!0,command:"dedent"},{key:"ArrowLeft",modKey:!0,shiftKey:"any",command:"moveToLineStart"},{key:"ArrowRight",modKey:!0,shiftKey:"any",command:"moveToLineEnd"},{key:"ArrowUp",modKey:!0,shiftKey:"any",command:"moveToDocumentStart"},{key:"ArrowDown",modKey:!0,shiftKey:"any",command:"moveToDocumentEnd"},{key:"ArrowUp",altKey:!0,shiftKey:!0,command:"moveListItemUp"},{key:"ArrowDown",altKey:!0,shiftKey:!0,command:"moveListItemDown"},{key:"a",modKey:!0,command:"selectAll"},{key:"b",modKey:!0,command:"toggleBold"},{key:"e",modKey:!0,command:"toggleInlineCode"},{key:"i",modKey:!0,command:"toggleItalic"},{key:"u",modKey:!0,command:"toggleUnderline"},{key:"y",modKey:!0,command:"redo"},{key:"z",modKey:!0,command:"undo"},{key:"z",modKey:!0,shiftKey:!0,command:"redo"}];function zZ($,M=o3){return M.find((Z)=>{let J=Z.shiftKey==="any"?!0:(Z.shiftKey??!1)===($.shiftKey??!1);return Z.key.toLowerCase()===$.key.toLowerCase()&&(Z.altKey??!1)===($.altKey??!1)&&J&&(Z.modKey??!1)===Boolean($.metaKey||$.ctrlKey)})?.command??null}function VZ($){let M=$.documentIndex.regions.find((Y)=>Y.id===$.selection.anchor.regionId),Z=$.documentIndex.regions.find((Y)=>Y.id===$.selection.focus.regionId),J=(M?.start??0)+$.selection.anchor.offset,X=(Z?.start??0)+$.selection.focus.offset;return{end:Math.max(J,X),start:Math.min(J,X)}}function n3($){let M=t3($);if(!M)return"";let Z=$.documentIndex.regions.find((J)=>J.id===M.regionId);if(!Z)return"";return Z.text.slice(M.startOffset,M.endOffset)}function t3($){let M=eA($);if(M.start.regionId!==M.end.regionId||M.start.offset===M.end.offset)return null;return{endOffset:M.end.offset,regionId:M.start.regionId,startOffset:M.start.offset}}var TZ=28,yZ=18;function wZ($,M){if(!$)return;let Z=$.getBoundingClientRect();if(M.clientY<Z.top+TZ){$.scrollTop=Math.max(0,$.scrollTop-yZ);return}if(M.clientY>Z.bottom-TZ)$.scrollTop+=yZ}function eA($){let M=WZ($.documentIndex.regions,$.selection.anchor.regionId,$.selection.anchor.offset),Z=WZ($.documentIndex.regions,$.selection.focus.regionId,$.selection.focus.offset);return M<=Z?{end:$.selection.focus,start:$.selection.anchor}:{end:$.selection.anchor,start:$.selection.focus}}function WZ($,M,Z){let J=$.findIndex((X)=>X.id===M);if(J===-1)return-1;return J*1e6+Z}var ZG=64;function CZ({applyNextState:$,editorState:M,editorStateRef:Z,editorViewportState:J,inputRef:X,keybindings:Y,onActivity:Q}){let K=JG(),q=()=>Z.current??M,U=OZ(!1),N=OZ(!1),A=G0((b)=>{if(!b)return;Q(),$(b)}),G=G0(()=>{let b=X.current;if(!b)return;if(typeof document>"u")return;let z=document.execCommand;if(typeof z!=="function")return;try{U.current=!0,z.call(document,"insertText",!1,"‌"),z.call(document,"delete")}catch{}finally{U.current=!1,S4(b,q())}}),B=G0(()=>{if(N.current)return;N.current=!0,G()}),F=G0(()=>{G()}),_=G0((b)=>{if(!K)return;let z=X.current;if(!z)return;let u=J.get(),v=o0(q(),u,b);if(!v)return;z.style.top=`${v.top}px`,z.style.left=`${v.left}px`,z.style.height=`${v.height}px`}),D=G0((b)=>{let z=X.current;if(!z)return;_(b??q().selection.focus),z.focus({preventScroll:!K}),S4(z,q()),B()}),T=G0((b,z)=>{let v=EZ(z,$$(b)).replace(/\r\n/g,`
32
+ `).split(/(\n)/),l=b;for(let g of v){if(g.length===0)continue;let w=g===`
33
+ `?$4(l):Y2(l,g);if(!w)continue;l=w}return l===b?null:l}),O=G0((b,z,u)=>{let v=b.selection.focus,l={regionId:v.regionId,offset:Math.max(0,v.offset-z)},g=Z0(b,{anchor:l,focus:v});return c5(g,u)}),y=G0((b)=>{if(U.current)return;let z=q(),u=YG(b.inputType);if(b.inputType==="insertText"){if(!b.data)return;b.preventDefault(),A(T(z,b.data));return}if(b.inputType==="insertReplacementText"){if(!b.data)return;b.preventDefault();let v=b.target,l=v?.selectionStart??0,g=v?.selectionEnd??l,w=Math.max(0,g-l);A(O(z,w,b.data));return}if(XG(b.inputType)){b.preventDefault(),A($4(z));return}if(u==="backward"){b.preventDefault(),A(l5(z));return}if(u==="forward"){b.preventDefault(),A(r5(z));return}if(b.inputType==="historyUndo"){b.preventDefault(),A(d5(z)),F();return}if(b.inputType==="historyRedo"){b.preventDefault(),A(a5(z)),F();return}}),R=G0((b)=>{if(U.current)return;let z=q(),u=b.currentTarget.value;if(EZ(u,$$(z)).length===0){S4(b.currentTarget,z);return}A(T(z,u))}),C=G0((b)=>{let z=KG(q(),J.get(),b.nativeEvent,Y);if(!z)return;b.preventDefault(),A(z)}),m=G0((b)=>{let z=n3(q());if(!z)return;b.preventDefault(),b.clipboardData.setData("text/plain",z)}),H=G0((b)=>{let z=q(),u=n3(z);if(!u)return;b.preventDefault(),b.clipboardData.setData("text/plain",u),A(M4(z))}),P=G0((b)=>{let z=b.clipboardData.getData("text/plain");if(z.length===0)return;b.preventDefault(),A(c5(q(),z))}),E=G0(()=>{Q();let b=X.current;if(b)S4(b,q())}),j=G0((b)=>{if(Q(),b.target.matches(":focus-visible"))D()});e3(()=>{let b=X.current;if(!b)return;S4(b,M)},[M,X]),$G(()=>{_(M.selection.focus)},[M,_]),e3(()=>{let b=X.current;if(!b)return;let z=(u)=>y(u);return b.addEventListener("beforeinput",z),()=>b.removeEventListener("beforeinput",z)},[X,y]);let W={onCopy:m,onCut:H,onPaste:P,...K?{}:{onKeyDown:C}};return{canvasHandlers:{...W,onFocus:j},focus:D,inputHandlers:{...W,onFocus:E,onInput:R}}}var jZ="​";function JG(){let[$,M]=MG(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function")return!1;return window.matchMedia("(pointer: coarse)").matches});return e3(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function")return;let Z=window.matchMedia("(pointer: coarse)"),J=(X)=>M(X.matches);return Z.addEventListener?.("change",J),()=>Z.removeEventListener?.("change",J)},[]),$}function XG($){return $==="insertLineBreak"||$==="insertParagraph"}function YG($){switch($){case"deleteContentBackward":case"deleteComposedCharacterBackward":case"deleteSoftLineBackward":case"deleteHardLineBackward":case"deleteWordBackward":return"backward";case"deleteContentForward":case"deleteSoftLineForward":case"deleteHardLineForward":case"deleteWordForward":return"forward";default:return null}}function QG($){return $.replaceAll(jZ,"")}function $$($,M=ZG){let{anchor:Z,focus:J}=$.selection;if(Z.regionId!==J.regionId||Z.offset!==J.offset)return"";let X=$.documentIndex.regionIndex.get(J.regionId);if(!X)return"";return X.text.slice(Math.max(0,J.offset-M),J.offset)}function EZ($,M){let Z=QG($);return Z.startsWith(M)?Z.slice(M.length):Z}function S4($,M){let Z=$$(M),J=`${jZ}${Z}`;$.value=J,$.setSelectionRange(J.length,J.length)}function KG($,M,Z,J){if(Z.key==="Delete")return r5($);let X=zZ(Z,J);if(X){if(X==="moveToLineStart"||X==="moveToLineEnd")return D3($,M.layout,X==="moveToLineStart"?"Home":"End",Z.shiftKey);if(X==="moveToDocumentStart"||X==="moveToDocumentEnd")return H3($,X==="moveToDocumentStart"?"start":"end",Z.shiftKey);switch(X){case"insertLineBreak":return $4($);case"deleteBackward":return l5($);case"indent":return i6($);case"dedent":return s6($);case"moveListItemUp":return o6($);case"moveListItemDown":return n6($);case"toggleBold":return Z4($);case"toggleItalic":return J4($);case"toggleStrikethrough":return X4($);case"toggleUnderline":return Y4($);case"toggleInlineCode":return X3($);case"undo":return d5($);case"redo":return a5($);case"selectAll":return a6($)}}if(Z.key==="ArrowLeft"||Z.key==="ArrowRight")return _3($,Z.key==="ArrowLeft"?-1:1,Z.shiftKey);if(Z.key==="ArrowUp"||Z.key==="ArrowDown")return F3($,M.layout,Z.key==="ArrowUp"?-1:1,Z.shiftKey);if(Z.key==="PageUp"||Z.key==="PageDown")return b3($,M.layout,Z.key==="PageUp"?-1:1,Z.shiftKey);if(Z.key.length===1&&!Z.altKey&&!Z.ctrlKey&&!Z.metaKey)return Y2($,Z.key);return null}import{useEffectEvent as M$,useLayoutEffect as qG,useMemo as UG,useState as NG}from"react";function RZ({editorState:$,editorStateRef:M,editorViewportState:Z,onViewportScroll:J,scrollContainerRef:X,scheduleOverlayRender:Y,userPresence:Q}){let K=UG(()=>{if(!Q||Q.length===0)return;return D5($.documentIndex,Q)},[$.documentIndex,Q]),[q,U]=NG(void 0),N=M$(()=>{if(K===void 0){if(q!==void 0)U(void 0)}else U(L2(M.current??$,Z.get(),K));Y()}),A=M$((B)=>{if(K===void 0){if(q!==void 0)U(void 0);return}let F=L2(M.current??$,B,K);if(AG(q,F))return;U(F)});qG(()=>{N()},[K]);let G=M$((B)=>{if(!B.viewport||B.viewport.status==="unresolved")return;let F=X.current;if(!F)return;F.scrollTop=B.viewport.scrollTop,J(F)});return{presence:q,scrollToPresence:G,refreshPresence:A}}function AG($,M){if($===M)return!0;if($===void 0||M===void 0||$.length!==M.length)return!1;return $.every((Z,J)=>{let X=M[J];return Z.id===X.id&&GG(Z.viewport,X.viewport)})}function GG($,M){if($===M)return!0;if($===null||M===null)return!1;if($.status==="unresolved")return M.status==="unresolved";if(M.status==="unresolved")return!1;return $.status===M.status&&$.scrollTop===M.scrollTop}import{useEffect as BG,useEffectEvent as j1,useRef as u4}from"react";function LZ({editorStateRef:$,renderContent:M,renderOverlay:Z,renderViewport:J}){let X=u4(null),Y=u4(!1),Q=u4(!1),K=u4(!1),q=u4(!1),U=j1(()=>{if(typeof window>"u"){J();return}Y.current=!0,B()}),N=j1(()=>{if(typeof window>"u"){M(),Z();return}Q.current=!0,B()}),A=j1(()=>{if(typeof window>"u"){M();return}K.current=!0,B()}),G=j1(()=>{if(typeof window>"u"){Z();return}q.current=!0,B()}),B=j1(()=>{if(typeof window>"u"||X.current!==null)return;X.current=window.requestAnimationFrame(()=>{F()})}),F=j1(()=>{X.current=null;let D=Y.current,T=Q.current,O=K.current,y=q.current;if(Y.current=!1,Q.current=!1,K.current=!1,q.current=!1,D){J(),_();return}if(T){M(),Z(),_();return}if(O)M(),_();if(y)Z()}),_=j1(()=>{let D=$.current;if(!D||!k6(D,performance.now()))return;K.current=!0,B()});return BG(()=>{return()=>{if(typeof window>"u"||X.current===null)return;window.cancelAnimationFrame(X.current),X.current=null}},[]),{scheduleContentPaint:A,scheduleFullPaint:N,scheduleFullRender:U,scheduleOverlayPaint:G}}import{useEffectEvent as Z$,useLayoutEffect as kZ,useMemo as J$,useRef as X$,useState as fZ}from"react";function mZ({applyNextState:$,autoScrollDuringDrag:M,canShowSelectionLeaf:Z,editorState:J,editorStateRef:X,editorViewportState:Y,focusInput:Q,onActivity:K,resolvePoint:q,threads:U}){let N=J$(()=>s(J),[J]),A=J$(()=>t3(J),[J]),G=J$(()=>w5(J),[J]),[B,F]=fZ(null),[_,D]=fZ(null),T=X$(null),O=X$(null),y=X$(null);kZ(()=>{let P=_G(J,Y.get(),N);F((E)=>PG(E,P)?E:P)},[J,Y,N.end.offset,N.end.regionId,N.start.offset,N.start.regionId]),kZ(()=>{let P=bG({canShowSelectionLeaf:Z,currentLeaf:_,activeMarks:G,handles:B,selectionRange:A,threads:U});D((E)=>HG(E,P)?E:P)},[G,Z,B,_,A,U]);let R=Z$((P,E=!0)=>{D((j)=>j?.kind==="create"?{animateInitialComment:E,kind:"thread",left:j.left,threadIndex:P,top:j.top}:j)}),C=Z$((P)=>{if(P&&y.current===P.pointerId&&P.currentTarget.hasPointerCapture(P.pointerId))P.currentTarget.releasePointerCapture(P.pointerId);T.current=null,O.current=null,y.current=null}),m=Z$((P)=>{let E=X.current,j=O.current,W=q(P);if(!W||!E||!j||y.current!==P.pointerId)return;let b=R2(E,Y.get(),W,j);if(!b)return;P.preventDefault(),P.stopPropagation(),K(),M(P),$(Z0(E,{anchor:j,focus:b}))}),H=(P)=>({onPointerCancel:(E)=>{C(E)},onPointerDown:(E)=>{let j=X.current??J,W=TG(N,P),b=P==="start"?N.start:N.end;if(!B)return;E.preventDefault(),E.stopPropagation(),y.current=E.pointerId,O.current=W,T.current=P,E.currentTarget.setPointerCapture(E.pointerId),K(),Q(),$(Z0(j,{anchor:W,focus:b}))},onPointerMove:(E)=>{if(T.current!==P)return;m(E)},onPointerUp:(E)=>{if(T.current===P)m(E);C(E)}});return{endHandleProps:H("end"),handles:B,leaf:_,promoteLeafToThread:R,startHandleProps:H("start")}}function _G($,M,Z){if(Z.collapsed)return null;let J=o0($,M,Z.start),X=o0($,M,Z.end);if(!J||!X)return null;return{end:{left:X.left,top:X.top+X.height},start:{left:J.left,top:J.top}}}function FG($,M,Z){return{activeMarks:Z,kind:"create",left:M.start.left,selection:$,top:M.end.top}}function bG({activeMarks:$,canShowSelectionLeaf:M,currentLeaf:Z,handles:J,selectionRange:X,threads:Y}){if(!M||!X||!J)return null;if(Z?.kind==="thread")return Y[Z.threadIndex]?Z:null;return FG(X,J,$)}function DG($,M){return $?.kind==="create"&&$.left===M.left&&$.selection.regionId===M.selection.regionId&&$.selection.startOffset===M.selection.startOffset&&$.selection.endOffset===M.selection.endOffset&&zG($.activeMarks,M.activeMarks)&&$.top===M.top}function HG($,M){if($===M)return!0;if(!$||!M||$.kind!==M.kind)return!1;if($.kind==="create"&&M.kind==="create")return DG($,M);return $.kind==="thread"&&M.kind==="thread"&&$.animateInitialComment===M.animateInitialComment&&$.left===M.left&&$.threadIndex===M.threadIndex&&$.top===M.top}function PG($,M){if($===M)return!0;if(!$||!M)return!1;return $.start.left===M.start.left&&$.start.top===M.start.top&&$.end.left===M.end.left&&$.end.top===M.end.top}function zG($,M){return $.length===M.length&&$.every((Z,J)=>Z===M[J])}function TG($,M){return M==="start"?$.end:$.start}import{useEffect as yG,useMemo as vZ,useState as WG}from"react";var v4={activeBlockBackground:"#fff1c7",activeBlockFlash:"rgba(245, 158, 11, 0.28)",background:"#fcfbf7",blockquoteRule:"rgba(14, 116, 144, 0.2)",blockquoteRuleActive:"rgba(124, 45, 18, 0.36)",blockquoteText:"#334155",caret:"#111827",checkboxCheckmark:"#f8fafc",checkboxCheckedFill:"#0f766e",checkboxCheckedStroke:"#0f766e",checkboxUncheckedFill:"#fcfffe",checkboxUncheckedStroke:"#64748b",codeBackground:"#0f172a",codeText:"#e2e8f0",commentHighlight:"#d7e3fc",commentHighlightActive:"#f4d35e",commentHighlightResolved:"#cfe9d8",commentHighlightResolvedActive:"#8dc4a0",headingRule:"rgba(15, 23, 42, 0.18)",headingText:"#0f172a",imageLoadingOverlay:"rgba(255, 255, 255, 0.42)",imagePlaceholderIcon:"rgba(14, 116, 144, 0.42)",imagePlaceholderText:"rgba(15, 23, 42, 0.58)",imageSurfaceBackground:"rgba(240, 249, 255, 0.98)",imageSurfaceBorder:"rgba(14, 116, 144, 0.22)",inlineCodeBackground:"rgba(15, 23, 42, 0.08)",inlineCodeText:"#7c2d12",insertHighlightText:"#2563eb",leafAccent:"#1d4ed8",leafBackground:"#fcfbf7",leafBorder:"rgba(148, 163, 184, 0.55)",leafButtonBackground:"rgba(15, 23, 42, 0.08)",leafButtonBorder:"rgba(148, 163, 184, 0.55)",leafButtonText:"#1f2937",leafResolvedBackground:"#cfe9d8",leafResolvedBorder:"#8dc4a0",leafSecondaryText:"#334155",leafShadow:"0 14px 40px rgba(15, 23, 42, 0.16)",leafText:"#1f2937",linkText:"#1d4ed8",listMarkerText:"#1f2937",paddingX:16,paddingY:12,paragraphText:"#1f2937",selectionBackground:"rgba(125, 211, 252, 0.35)",selectionHandleBackground:"#fcfbf7",selectionHandleBorder:"#1d4ed8",tableBodyBackground:"rgba(248, 250, 252, 0.98)",tableBorder:"rgba(148, 163, 184, 0.55)",tableHeaderBackground:"rgba(226, 232, 240, 0.95)"},h4={activeBlockBackground:"rgba(125, 211, 252, 0.12)",activeBlockFlash:"rgba(226, 232, 240, 0.12)",background:"#0b1220",blockquoteRule:"rgba(103, 232, 249, 0.34)",blockquoteRuleActive:"rgba(125, 211, 252, 0.5)",blockquoteText:"#cbd5e1",caret:"#f8fafc",checkboxCheckmark:"#082f49",checkboxCheckedFill:"#67e8f9",checkboxCheckedStroke:"#67e8f9",checkboxUncheckedFill:"#0f172a",checkboxUncheckedStroke:"#64748b",codeBackground:"#020617",codeText:"#dbeafe",commentHighlight:"rgba(96, 165, 250, 0.34)",commentHighlightActive:"#facc15",commentHighlightResolved:"rgba(74, 222, 128, 0.24)",commentHighlightResolvedActive:"#4ade80",headingRule:"rgba(226, 232, 240, 0.22)",headingText:"#f8fafc",imageLoadingOverlay:"rgba(186, 230, 253, 0.18)",imagePlaceholderIcon:"rgba(125, 211, 252, 0.44)",imagePlaceholderText:"rgba(226, 232, 240, 0.62)",imageSurfaceBackground:"rgba(15, 23, 42, 0.92)",imageSurfaceBorder:"rgba(56, 189, 248, 0.28)",inlineCodeBackground:"rgba(148, 163, 184, 0.16)",inlineCodeText:"#fdba74",insertHighlightText:"#60a5fa",leafAccent:"#93c5fd",leafBackground:"#0b1220",leafBorder:"rgba(100, 116, 139, 0.7)",leafButtonBackground:"rgba(148, 163, 184, 0.16)",leafButtonBorder:"rgba(100, 116, 139, 0.7)",leafButtonText:"#dbe4f0",leafResolvedBackground:"rgba(74, 222, 128, 0.24)",leafResolvedBorder:"#4ade80",leafSecondaryText:"#cbd5e1",leafShadow:"0 18px 44px rgba(2, 6, 23, 0.42), 0 0 0 1px rgba(148, 163, 184, 0.06)",leafText:"#dbe4f0",linkText:"#93c5fd",listMarkerText:"#e2e8f0",paddingX:16,paddingY:12,paragraphText:"#dbe4f0",selectionBackground:"rgba(56, 189, 248, 0.28)",selectionHandleBackground:"#0b1220",selectionHandleBorder:"#93c5fd",tableBodyBackground:"rgba(15, 23, 42, 0.9)",tableBorder:"rgba(100, 116, 139, 0.7)",tableHeaderBackground:"rgba(30, 41, 59, 0.96)"},SZ={...v4,activeBlockBackground:"rgba(16, 185, 129, 0.14)",activeBlockFlash:"rgba(16, 185, 129, 0.26)",background:"#f3fbf6",blockquoteRule:"rgba(5, 150, 105, 0.22)",blockquoteRuleActive:"rgba(6, 95, 70, 0.38)",blockquoteText:"#166534",caret:"#14532d",codeBackground:"#052e16",codeText:"#dcfce7",commentHighlight:"rgba(52, 211, 153, 0.26)",commentHighlightActive:"#10b981",commentHighlightResolved:"rgba(187, 247, 208, 0.96)",commentHighlightResolvedActive:"#059669",headingRule:"rgba(20, 83, 45, 0.18)",headingText:"#14532d",inlineCodeBackground:"rgba(20, 83, 45, 0.08)",inlineCodeText:"#166534",insertHighlightText:"#10b981",leafAccent:"#059669",leafBackground:"#f3fbf6",leafBorder:"rgba(22, 163, 74, 0.24)",leafButtonBackground:"rgba(20, 83, 45, 0.08)",leafButtonBorder:"rgba(22, 163, 74, 0.28)",leafButtonText:"#14532d",leafResolvedBackground:"#d1fae5",leafResolvedBorder:"#10b981",leafSecondaryText:"#166534",leafShadow:"0 14px 40px rgba(20, 83, 45, 0.14)",leafText:"#14532d",linkText:"#047857",paragraphText:"#14532d",selectionBackground:"rgba(52, 211, 153, 0.24)",selectionHandleBackground:"#f3fbf6",selectionHandleBorder:"#059669",tableBodyBackground:"rgba(243, 251, 246, 0.96)",tableBorder:"rgba(22, 163, 74, 0.24)",tableHeaderBackground:"rgba(220, 252, 231, 0.96)"},uZ={...h4,activeBlockBackground:"rgba(168, 85, 247, 0.16)",activeBlockFlash:"rgba(243, 232, 255, 0.13)",blockquoteRule:"rgba(196, 181, 253, 0.34)",blockquoteRuleActive:"rgba(216, 180, 254, 0.44)",caret:"#f5f3ff",codeBackground:"#1e1b4b",codeText:"#ede9fe",commentHighlight:"rgba(167, 139, 250, 0.28)",commentHighlightActive:"#c084fc",commentHighlightResolved:"rgba(45, 212, 191, 0.22)",commentHighlightResolvedActive:"#2dd4bf",headingRule:"rgba(233, 213, 255, 0.24)",headingText:"#f5f3ff",inlineCodeBackground:"rgba(196, 181, 253, 0.16)",inlineCodeText:"#f9a8d4",insertHighlightText:"#c084fc",leafAccent:"#d8b4fe",leafBackground:"#12091f",leafBorder:"rgba(139, 92, 246, 0.34)",leafButtonBackground:"rgba(196, 181, 253, 0.16)",leafButtonBorder:"rgba(139, 92, 246, 0.34)",leafButtonText:"#ede9fe",leafResolvedBackground:"rgba(45, 212, 191, 0.22)",leafResolvedBorder:"#2dd4bf",leafSecondaryText:"#ddd6fe",leafShadow:"0 20px 48px rgba(2, 6, 23, 0.48), 0 0 0 1px rgba(196, 181, 253, 0.08)",leafText:"#f5f3ff",linkText:"#d8b4fe",listMarkerText:"#ede9fe",paragraphText:"#ede9fe",selectionBackground:"rgba(167, 139, 250, 0.26)",selectionHandleBackground:"#12091f",selectionHandleBorder:"#d8b4fe",tableBodyBackground:"rgba(30, 27, 75, 0.88)",tableBorder:"rgba(139, 92, 246, 0.34)",tableHeaderBackground:"rgba(49, 46, 129, 0.94)"};function hZ($){let M=vZ(()=>wG($),[$]),[Z,J]=WG(M.light),X=vZ(()=>OG(Z),[Z]);return yG(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function"){J(M.light);return}let Y=window.matchMedia("(prefers-color-scheme: dark)"),Q=()=>{J(Y.matches?M.dark:M.light)};if(Q(),typeof Y.addEventListener==="function")return Y.addEventListener("change",Q),()=>{Y.removeEventListener("change",Q)};return Y.addListener(Q),()=>{Y.removeListener(Q)}},[M]),{theme:Z,themeStyles:X}}function VG($){return"light"in $&&"dark"in $}function wG($){if(!$)return{dark:h4,light:v4};if(VG($))return $;return{dark:$,light:$}}function OG($){return{"--documint-background":$.background,"--documint-leaf-button-bg":$.leafButtonBackground,"--documint-leaf-button-border":$.leafButtonBorder,"--documint-leaf-button-text":$.leafButtonText,"--documint-leaf-accent":$.leafAccent,"--documint-leaf-bg":$.leafBackground,"--documint-leaf-border":$.leafBorder,"--documint-leaf-font-family":'"Avenir Next", "Segoe UI", sans-serif',"--documint-leaf-shadow":$.leafShadow??void 0,"--documint-leaf-secondary-text":$.leafSecondaryText,"--documint-leaf-resolved-bg":$.leafResolvedBackground,"--documint-leaf-resolved-border":$.leafResolvedBorder,"--documint-leaf-text":$.leafText,"--documint-mention-bg":$.mentionBackground??void 0,"--documint-mention-text":$.mentionText??void 0,"--documint-selection-handle-bg":$.selectionHandleBackground,"--documint-selection-handle-border":$.selectionHandleBorder}}import{useEffect as jG,useEffectEvent as x0,useRef as Y$,useState as U8}from"react";import{useMemo as EG}from"react";function gZ($){return EG(()=>CG({current:null},$),[$])}function CG($,M){return{peek(){return $.current},get(){let Z=$.current;if(Z!==null)return Z;let J=M();return $.current=J,J},invalidate(){$.current=null}}}function IZ($,M){let Z=M.getBoundingClientRect();return{x:$.clientX-Z.left+M.scrollLeft,y:$.clientY-Z.top+M.scrollTop}}function pZ({editorState:$,editorStateRef:M,renderResources:Z,theme:J}){let X=Y$(T1()),Y=Y$(null),Q=Y$({height:240,top:0}),[K,q]=U8(0),[U,N]=U8(240),[A,G]=U8(0),[B,F]=U8(240),_=RG(K),D=x0(()=>{let b=M.current??$,z=Q.current;return q6(b,{height:z.height,paddingX:J.paddingX,paddingY:J.paddingY,top:z.top,width:_},X.current,Z)}),T=gZ(D),O=x0((b)=>{F((z)=>{let u=kG(b,Q.current.height);return z===u?z:u})}),y=x0((b)=>{Q.current={...Q.current,top:b},G((z)=>z===b?z:b),T.invalidate()}),R=x0((b)=>{let z=LG(b),u=z.top!==Q.current.top;if(Q.current=z,G((v)=>v===z.top?v:z.top),u)T.invalidate()}),C=x0((b)=>{let z=Y.current;if(!z)return y(b),b;z.scrollTop=b;let u=z.scrollTop;return y(u),u}),m=x0(()=>{return Y.current?.scrollTop??Q.current.top}),H=x0((b,z)=>{let u=b!==null&&b.documentIndex!==z.documentIndex,v=T.peek();if(!(!u||!v||v.layout.regionLineIndices.has(z.selection.focus.regionId)))T.invalidate()}),P=x0(()=>{return T.invalidate(),T.get()}),E=x0((b)=>{let z=Y.current;return z?IZ(b,z):null}),j=x0((b)=>{wZ(Y.current,b)});return jG(()=>{let b=Y.current;if(!b||typeof ResizeObserver>"u")return;let z=new ResizeObserver((u)=>{let v=u[0];if(!v)return;let l=Math.max(0,Math.floor(v.contentRect.width)),g=lZ(b);Q.current={...Q.current,height:g},q((w)=>w===l?w:l),N((w)=>w===g?w:g)});return z.observe(b),()=>z.disconnect()},[Y]),{actions:{autoScrollDuringDrag:j,getScrollTop:m,observePreparedViewport:O,observeScrollContainer:R,prepareNextPaint:P,reconcileEditorState:H,resolvePoint:E,scrollTo:C},props:{getScrollContainer:(b)=>({onScroll:(z)=>{R(z.currentTarget),b?.onScroll?.(z)},ref:Y}),scrollContent:{style:{height:`${B}px`}}},refs:{scrollContainer:Y},state:{layoutWidth:_,preparedViewport:T,scrollContentHeight:B,surfaceWidth:K,viewportHeight:U,viewportTop:A}}}function RG($){return Math.max(240,Math.floor($||480))}function lZ($){return Math.max(240,$.clientHeight)}function LG($){return{height:lZ($),top:$.scrollTop}}function kG($,M){return Math.max(M,Math.ceil($.totalHeight+24))}function fG(){if(typeof window>"u")return 1;return Math.max(1,window.devicePixelRatio||1)}function Q$($,{paintHeight:M,paintTop:Z,width:J}){if(!$)return null;let X=Math.max(240,Math.ceil(M)),Y=fG();$.width=Math.ceil(J*Y),$.height=Math.ceil(X*Y),$.style.width=`${J}px`,$.style.height=`${X}px`,$.style.transform=`translateY(${Z}px)`;let Q=$.getContext("2d");if(!Q)return null;return{context:Q,devicePixelRatio:Y,height:X,width:J}}function K$($,M){return $.activeBlockType===M.activeBlockType&&$.activeCommentThreadIndex===M.activeCommentThreadIndex&&$.activeSpanKind===M.activeSpanKind&&$.canonicalContent===M.canonicalContent&&$.characterCount===M.characterCount&&$.commentThreadCount===M.commentThreadCount&&$.layoutWidth===M.layoutWidth&&$.resolvedCommentCount===M.resolvedCommentCount&&$.selectionFrom===M.selectionFrom&&$.selectionTo===M.selectionTo}function rZ($,M){if(!M?.length||!$?.length)return;let Z=new Map($.map((X)=>[X.id,X])),J=[];for(let X of M){let Y=Z.get(X.userId);if(!Y)continue;J.push({...Y,color:X.color,cursor:X.cursor})}return J.length===0?void 0:J}function xZ($,M){if(!$)return{didReconcile:!1,state:M};let Z=mG($,M)??rG($,M);return Z?{didReconcile:!0,state:Z}:{didReconcile:!1,state:M}}function mG($,M){let Z=SG($,M);return Z?Z0(M,Z,!1):null}function SG($,M){if(N$($.selection.anchor,$.selection.focus)){let Y=q$($,M,$.selection.focus,"neutral");return Y?{anchor:Y,focus:Y}:null}let Z=pG($),J=q$($,M,$.selection.anchor,Z.anchor),X=q$($,M,$.selection.focus,Z.focus);return J&&X?{anchor:J,focus:X}:null}function q$($,M,Z,J){let X=$.documentIndex.regionIndex.get(Z.regionId);if(!X)return null;let Y=U$(X,M);if(!Y)return null;return{offset:vG(X.text,Y.text,Z.offset,J),regionId:Y.id}}function U$($,M){let Z=M.documentIndex.regionIndex.get($.id);if(Z)return Z;if($.text.length===0)return null;let J=uG($,M);if(J)return J;return M.documentIndex.regionPathIndex.get($.path)??null}function uG($,M){let Z=null;for(let J of M.documentIndex.regions){if(J.blockType!==$.blockType||J.text!==$.text)continue;if(Z)return null;Z=J}return Z}function vG($,M,Z,J){let X=L0(Z,0,$.length),{prefix:Y,suffix:Q}=w8($,X,X),K=hG(M,Y,Q);if(K!==null)return K;let q=gG(M,Y),U=IG(M,Q);if(J==="before-suffix")return U??q??L0(Z,0,M.length);return q??U??L0(Z,0,M.length)}function hG($,M,Z){let J=p1($,M,Z).filter((X)=>X.startOffset===X.endOffset);return J.length===1?J[0].startOffset:null}function gG($,M){let Z=g0($,M);return Z.length===1?Z[0]+M.length:null}function IG($,M){let Z=g0($,M);return Z.length===1?Z[0]:null}function pG($){let{anchor:M,focus:Z}=$.selection;if(N$(M,Z))return{anchor:"neutral",focus:"neutral"};return lG($,M,Z)<=0?{anchor:"before-suffix",focus:"after-prefix"}:{anchor:"after-prefix",focus:"before-suffix"}}function lG($,M,Z){let J=$.documentIndex.regionOrderIndex.get(M.regionId),X=$.documentIndex.regionOrderIndex.get(Z.regionId);if(J===void 0||X===void 0)return 0;return J===X?M.offset-Z.offset:J-X}function rG($,M){if(!N$($.selection.anchor,$.selection.focus))return null;let Z=cG($);if(!Z)return null;let J=xG($,M,Z);if(J===null)return null;return dG(M,J)}function cG($){let M=$.documentIndex.regionIndex.get($.selection.focus.regionId);if(!M||M.blockType!=="paragraph"||M.text.length>0)return null;return $.documentIndex.blockIndex.get(M.blockId)?.parentBlockId===null?M:null}function xG($,M,Z){let J=cZ($,Z.rootIndex,"before"),X=cZ($,Z.rootIndex,"after"),Y=J?U$(J,M):null,Q=X?U$(X,M):null;if(Y&&Q)return Y.rootIndex<Q.rootIndex?Q.rootIndex:null;if(Y)return Y.rootIndex+1;if(Q)return Q.rootIndex;return null}function dG($,M){let Z=g1($.documentIndex.document,M,0,[p({text:""})]),J={...$,documentIndex:e1($.documentIndex,Z,M,0)},X=h2(J.documentIndex,t(M));return X?Z0(J,X,!1):null}function cZ($,M,Z){let J=Z==="before"?-1:1;for(let X=M+J;X>=0&&X<$.documentIndex.roots.length;X+=J){let Y=aG($,X,Z);if(Y)return Y}return null}function aG($,M,Z){let J=$.documentIndex.roots[M]?.regions??[],X=Z==="before"?J.length-1:0,Y=Z==="before"?-1:1;for(let Q=X;Q>=0&&Q<J.length;Q+=Y){let K=J[Q];if(K&&K.text.length>0)return K}return null}function N$($,M){return $.regionId===M.regionId&&$.offset===M.offset}import{jsxDEV as c,Fragment as MB}from"react/jsx-dev-runtime";function A8({blocks:$}){return c(MB,{children:$.map((M)=>iG(M))},void 0,!1,void 0,this)}function iG($){switch($.type){case"blockquote":return c("blockquote",{className:"preview-block preview-block-blockquote",children:c(A8,{blocks:$.children},void 0,!1,void 0,this)},$.id,!1,void 0,this);case"code":return c("div",{className:"preview-block preview-block-code",children:[c("div",{className:"preview-rich-header",children:nG($.language,$.meta)},void 0,!1,void 0,this),c("pre",{children:c("code",{children:$.source||" "},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},$.id,!0,void 0,this);case"heading":{let M=`h${$.depth}`;return c(M,{className:"preview-block preview-block-heading",children:N8($.children)},$.id,!1,void 0,this)}case"list":return $.ordered?c("ol",{className:"preview-block preview-block-list",start:$.start??1,children:$.items.map((M)=>A$(M))},$.id,!1,void 0,this):c("ul",{className:"preview-block preview-block-list",children:$.items.map((M)=>A$(M))},$.id,!1,void 0,this);case"listItem":return A$($);case"paragraph":return c("p",{className:"preview-block preview-block-paragraph",children:N8($.children)},$.id,!1,void 0,this);case"table":return c("div",{className:"preview-block preview-block-table",children:[c("div",{className:"preview-rich-header",children:tG($.rows.length,$.rows[0]?.cells.length??0,$.align.filter((M)=>M!==null).length)},void 0,!1,void 0,this),c("div",{className:"preview-table-scroll",children:c("table",{children:c("tbody",{children:$.rows.map((M)=>c("tr",{children:M.cells.map((Z)=>c("td",{children:N8(Z.children)},Z.id,!1,void 0,this))},M.id,!1,void 0,this))},void 0,!1,void 0,this)},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},$.id,!0,void 0,this);case"thematicBreak":return c("hr",{className:"preview-block preview-block-rule"},$.id,!1,void 0,this);case"directive":return c("pre",{className:`preview-block preview-block-directive preview-block-directive-${$.name}`,children:$.body},$.id,!1,void 0,this);case"unsupported":return c("pre",{className:"preview-block preview-block-unsupported",children:$.source},$.id,!1,void 0,this)}}function A$($){return c("li",{className:"preview-block preview-block-list-item",children:c(A8,{blocks:$.children},void 0,!1,void 0,this)},$.id,!1,void 0,this)}function N8($){return $.map((M)=>{switch(M.type){case"break":return c("br",{},M.id,!1,void 0,this);case"image":return c("span",{className:"preview-inline preview-inline-image",children:[c("img",{alt:M.alt??"",src:M.url,title:M.title??""},void 0,!1,void 0,this),c("span",{children:[c("strong",{children:eG(M.alt)},void 0,!1,void 0,this),c("small",{children:$B(M.url,M.title)},void 0,!1,void 0,this)]},void 0,!0,void 0,this)]},M.id,!0,void 0,this);case"inlineCode":return c("code",{className:"preview-inline preview-inline-code",children:M.code},M.id,!1,void 0,this);case"link":return sG(M);case"text":return c("span",{className:"preview-inline",children:oG(M.text,M.marks)},M.id,!1,void 0,this);case"unsupported":return c("span",{className:"preview-inline preview-inline-unsupported",children:M.source},M.id,!1,void 0,this)}})}function sG($){return c("a",{className:"preview-inline preview-inline-link",href:$.url,children:N8($.children)},$.id,!1,void 0,this)}function oG($,M){let Z=$;for(let J of M)switch(J){case"strikethrough":Z=c("del",{children:Z},void 0,!1,void 0,this);break;case"italic":Z=c("em",{children:Z},void 0,!1,void 0,this);break;case"bold":Z=c("strong",{children:Z},void 0,!1,void 0,this);break;case"underline":Z=c("ins",{children:Z},void 0,!1,void 0,this);break}return Z}function nG($,M){return[$??"plain text",M].filter(Boolean).join(" • ")}function tG($,M,Z){let J=Z>0?`${Z} aligned ${Z===1?"column":"columns"}`:"no alignment";return`${$} ${$===1?"row":"rows"} • ${M} ${M===1?"column":"columns"} • ${J}`}function eG($){return $?.trim()?$:"Untitled image"}function $B($,M){return M?.trim()?`${M} • ${$}`:$}var dZ=`/* Base Documint host and SSR-fallback styles. */
34
+
35
+ .documint {
570
36
  display: grid;
571
37
  min-width: 0;
572
38
  min-height: 0;
573
39
  }
574
40
 
575
- :where(.documint-scroll-container) {
41
+ /* Default elevated-surface shadow shared by leaf overlays, menus, and
42
+ presence indicators. Both the host section and the overlay portal
43
+ wrapper carry it so descendants inherit the same value whether they're
44
+ rendered in-tree or portaled to document.body. */
45
+ .documint,
46
+ .documint-overlay {
47
+ --documint-leaf-shadow-fallback:
48
+ 0 14px 40px color-mix(in srgb, var(--documint-leaf-text) 16%, transparent);
49
+ }
50
+
51
+ .documint-scroll-container {
576
52
  position: relative;
577
53
  display: block;
578
54
  width: 100%;
579
55
  min-width: 0;
580
56
  min-height: 0;
581
57
  overflow: auto;
58
+ /* Match the canvas's paint color so the iOS overscroll bounce (and any
59
+ other reveal of the scroll container beyond the canvas's painted area)
60
+ shows the themed background instead of browser white. */
61
+ background: var(--documint-background);
582
62
  }
583
63
 
584
- :where(.documint-input) {
64
+ .documint-input {
585
65
  /* The bridge must look like a real focused input to iOS so Safari
586
66
  shifts the page above the virtual keyboard. Empirically:
587
67
  - opacity must be greater than 0
@@ -606,21 +86,25 @@ ${SJ}
606
86
  resize: none;
607
87
  }
608
88
 
609
- :where(.documint-scroll-content) {
89
+ .documint-scroll-content {
610
90
  position: relative;
611
91
  min-height: 100%;
612
92
  overflow: hidden;
613
93
  }
614
94
 
615
- :where(.documint-content-canvas) {
95
+ .documint-content-canvas {
616
96
  position: absolute;
617
97
  inset: 0 auto auto 0;
618
98
  display: block;
619
99
  width: 100%;
620
100
  outline: none;
101
+ /* Let the browser handle native pan (scrolling) on touch and eliminate the
102
+ historical 300ms tap delay. Double-tap zoom is suppressed on the canvas
103
+ (we want \`dblclick\` for word-select), but pinch-zoom and pan are kept. */
104
+ touch-action: manipulation;
621
105
  }
622
106
 
623
- :where(.documint-overlay-canvas) {
107
+ .documint-overlay-canvas {
624
108
  position: absolute;
625
109
  inset: 0 auto auto 0;
626
110
  display: block;
@@ -628,7 +112,7 @@ ${SJ}
628
112
  pointer-events: none;
629
113
  }
630
114
 
631
- :where(.documint-presence-indicators) {
115
+ .documint-presence-indicators {
632
116
  position: sticky;
633
117
  z-index: 5;
634
118
  display: flex;
@@ -650,10 +134,7 @@ ${SJ}
650
134
  border: 1px solid var(--documint-leaf-border);
651
135
  border-radius: 999px;
652
136
  background: var(--documint-leaf-bg);
653
- box-shadow: var(
654
- --documint-leaf-shadow,
655
- 0 14px 40px color-mix(in srgb, var(--documint-leaf-text) 16%, transparent)
656
- );
137
+ box-shadow: var(--documint-leaf-shadow, var(--documint-leaf-shadow-fallback));
657
138
  color: var(--documint-leaf-text);
658
139
  cursor: pointer;
659
140
  font-family: var(--documint-leaf-font-family, "Avenir Next", "Segoe UI", sans-serif);
@@ -661,237 +142,829 @@ ${SJ}
661
142
  font-weight: 700;
662
143
  line-height: 1;
663
144
  pointer-events: auto;
145
+
146
+ &:disabled {
147
+ cursor: default;
148
+ opacity: 0.72;
149
+ }
150
+ }
151
+
152
+ .documint-presence-indicator-avatar {
153
+ display: inline-grid;
154
+ place-items: center;
155
+ width: var(--documint-presence-indicator-size);
156
+ height: var(--documint-presence-indicator-size);
157
+ overflow: hidden;
158
+ border-radius: 999px;
159
+ background: var(--documint-presence-color);
160
+ color: white;
161
+ }
162
+
163
+ .documint-presence-indicator-image {
164
+ display: block;
165
+ width: calc(100% - 2px);
166
+ height: calc(100% - 2px);
167
+ border-radius: inherit;
168
+ object-fit: cover;
169
+ }
170
+
171
+ .documint-presence-indicator-direction {
172
+ display: inline-flex;
173
+ align-items: center;
174
+ height: 100%;
175
+ padding: 0 0.42rem 0 0.36rem;
176
+ color: var(--documint-leaf-text);
177
+ }
178
+
179
+ .documint-presence-indicator-arrow {
180
+ display: block;
181
+ }
182
+
183
+ .documint-selection-handle {
184
+ position: absolute;
185
+ z-index: 4;
186
+ width: 1.2rem;
187
+ height: 1.2rem;
188
+ margin: 0;
189
+ padding: 0;
190
+ border: 0;
191
+ background: transparent;
192
+ pointer-events: auto;
193
+ touch-action: none;
194
+ cursor: grab;
195
+
196
+ &:active {
197
+ cursor: grabbing;
198
+ }
199
+ }
200
+
201
+ .documint-selection-handle-start {
202
+ transform: translate(-70%, -82%);
203
+ }
204
+
205
+ .documint-selection-handle-end {
206
+ transform: translate(-30%, -39%);
207
+ }
208
+
209
+ .documint-selection-handle-knob {
210
+ position: absolute;
211
+ inset: 0;
212
+ display: block;
213
+ border: 2px solid var(--documint-selection-handle-border);
214
+ border-radius: 999px;
215
+ background: var(--documint-selection-handle-bg);
216
+ box-shadow: 0 2px 8px rgba(15, 23, 42, 0.18);
217
+ }
218
+
219
+ .documint-fallback {
220
+ max-width: 100%;
221
+ color: #0f172a;
222
+ line-height: 1.65;
223
+ white-space: normal;
224
+
225
+ & p {
226
+ margin: 0 0 0.9rem;
227
+ }
228
+
229
+ & h1,
230
+ & h2,
231
+ & h3,
232
+ & h4,
233
+ & h5,
234
+ & h6 {
235
+ margin: 0 0 0.85rem;
236
+ line-height: 1.15;
237
+ }
238
+
239
+ & h1 {
240
+ font-size: 2rem;
241
+ }
242
+
243
+ & h2 {
244
+ font-size: 1.55rem;
245
+ }
246
+
247
+ & h3 {
248
+ font-size: 1.25rem;
249
+ }
250
+
251
+ & ul,
252
+ & ol {
253
+ margin: 0 0 1rem;
254
+ padding-left: 1.4rem;
255
+ }
256
+
257
+ & li > p {
258
+ margin: 0;
259
+ }
260
+
261
+ & blockquote {
262
+ margin: 0 0 1rem;
263
+ padding-left: 1rem;
264
+ border-left: 3px solid rgba(14, 116, 144, 0.3);
265
+ color: #334155;
266
+ }
267
+
268
+ & pre {
269
+ margin: 0 0 1rem;
270
+ padding: 0.9rem 1rem;
271
+ overflow: auto;
272
+ border-radius: 0.85rem;
273
+ background: #0f172a;
274
+ color: #e2e8f0;
275
+ }
276
+
277
+ & table {
278
+ width: 100%;
279
+ margin: 0 0 1rem;
280
+ border-collapse: collapse;
281
+ }
282
+
283
+ & td {
284
+ padding: 0.45rem 0.55rem;
285
+ border: 1px solid rgba(148, 163, 184, 0.35);
286
+ }
287
+
288
+ & a {
289
+ color: #0369a1;
290
+ }
291
+ }
292
+
293
+ .preview-rich-header {
294
+ margin: 0 0 0.35rem;
295
+ color: #9fb3c8;
296
+ font-family: "Avenir Next", "Segoe UI", sans-serif;
297
+ font-size: 0.74rem;
298
+ font-weight: 700;
299
+ letter-spacing: 0.08em;
300
+ text-transform: uppercase;
301
+ }
302
+
303
+ .preview-block-code {
304
+ margin: 0 0 1rem;
305
+ padding: 0.75rem;
306
+ border-radius: 0.9rem;
307
+ background: linear-gradient(180deg, #132033, #0f172a);
308
+ color: #e2e8f0;
309
+
310
+ & pre {
311
+ margin: 0;
312
+ padding: 0.9rem 1rem;
313
+ overflow: auto;
314
+ border-radius: 0.75rem;
315
+ background: rgba(15, 23, 42, 0.72);
316
+ }
317
+ }
318
+
319
+ .preview-block-table {
320
+ margin: 0 0 1rem;
321
+ padding: 0.75rem;
322
+ border: 1px solid rgba(14, 116, 144, 0.18);
323
+ border-radius: 0.9rem;
324
+ background: rgba(248, 250, 252, 0.96);
325
+ }
326
+
327
+ .preview-table-scroll {
328
+ overflow-x: auto;
329
+
330
+ & table {
331
+ min-width: max-content;
332
+ }
333
+ }
334
+
335
+ .preview-inline-image {
336
+ display: inline-flex;
337
+ align-items: center;
338
+ gap: 0.65rem;
339
+ max-width: min(100%, 34rem);
340
+ margin: 0 0.15rem;
341
+ padding: 0.35rem 0.55rem;
342
+ border: 1px solid rgba(14, 116, 144, 0.16);
343
+ border-radius: 999px;
344
+ background: rgba(240, 249, 255, 0.95);
345
+ vertical-align: middle;
346
+
347
+ & img {
348
+ flex: none;
349
+ width: 2.4rem;
350
+ height: 2.4rem;
351
+ object-fit: cover;
352
+ border-radius: 0.65rem;
353
+ background: rgba(148, 163, 184, 0.18);
354
+ }
355
+
356
+ & > span {
357
+ display: grid;
358
+ min-width: 0;
359
+ }
360
+
361
+ & strong {
362
+ color: #0f172a;
363
+ font-family: "Avenir Next", "Segoe UI", sans-serif;
364
+ font-size: 0.88rem;
365
+ }
366
+
367
+ & small {
368
+ overflow: hidden;
369
+ color: #475569;
370
+ font-family: "Avenir Next", "Segoe UI", sans-serif;
371
+ font-size: 0.75rem;
372
+ text-overflow: ellipsis;
373
+ white-space: nowrap;
374
+ }
375
+ }
376
+ `;var aZ=`/* Leaf overlay styles, ordered outer → inner:
377
+ 1. Anchor — viewport positioning + hover bridge
378
+ 2. Shell — bordered container (with state and content variants)
379
+ 3. Menu — shared dropdown surface (toolbar menus, completion popover)
380
+ 4. Action — small icon buttons used throughout leaf chrome
381
+ 5. Input — textarea wrapper (cancel/save/submit positioning)
382
+ 6. Comment — comment leaf root, header, thread, replies, create chrome
383
+ 7. Link — link leaf layout
384
+ 8. Mention — inline pill rendered inside read-only leaf text
385
+
386
+ The toolbar's own styles live in \`toolbar/styles.css\`; both files are
387
+ concatenated by the editor's stylesheet assembly. */
388
+
389
+ /* -- Anchor: positioned wrapper rendered by LeafAnchor (via OverlayPortal) -- */
390
+
391
+ .documint-leaf-anchor {
392
+ --documint-leaf-anchor-bridge-height: 12px;
393
+ position: fixed;
394
+ z-index: 1000;
395
+ padding-top: var(--documint-leaf-anchor-bridge-height);
396
+ margin-top: calc(var(--documint-leaf-anchor-bridge-height) * -1);
397
+ pointer-events: auto;
398
+
399
+ &[data-selection="true"] {
400
+ --documint-leaf-anchor-bridge-height: 0px;
401
+ padding-top: 0;
402
+ margin-top: 14px;
403
+ pointer-events: none;
404
+ }
405
+ }
406
+
407
+ .documint-leaf-bridge {
408
+ width: 100%;
409
+ height: var(--documint-leaf-anchor-bridge-height);
410
+ }
411
+
412
+ /* -- Shell: bordered, themed container that holds leaf content -- */
413
+
414
+ .documint-leaf-shell {
415
+ --documint-leaf-divider-color:
416
+ color-mix(in srgb, var(--documint-leaf-border) 60%, transparent);
417
+ padding: 0.8rem;
418
+ border: 1px solid var(--documint-leaf-border);
419
+ border-radius: 0.95rem;
420
+ background: var(--documint-leaf-bg);
421
+ box-shadow: var(--documint-leaf-shadow, var(--documint-leaf-shadow-fallback));
422
+ color: var(--documint-leaf-text);
423
+ font-family: var(--documint-leaf-font-family, "Avenir Next", "Segoe UI", sans-serif);
424
+ font-size: 0.84rem;
425
+ line-height: 1.45;
426
+ pointer-events: auto;
427
+
428
+ &:has(> .documint-leaf-toolbar),
429
+ &:has(> .documint-comment-leaf-create) {
430
+ width: auto;
431
+ padding: 0.38rem 0.58rem;
432
+ }
433
+
434
+ &:has(> .documint-comment-leaf-create.is-expanded) {
435
+ padding: 0.8rem;
436
+ }
437
+
438
+ &[data-status="resolved"] {
439
+ border-color: var(--documint-leaf-resolved-border);
440
+ background: var(--documint-leaf-resolved-bg);
441
+ }
442
+
443
+ & p {
444
+ margin: 0;
445
+ }
446
+ }
447
+
448
+ /* -- Menu: shared dropdown surface (toolbar menus, completion popover) -- */
449
+
450
+ .documint-leaf-menu {
451
+ --documint-leaf-menu-border-color:
452
+ color-mix(in srgb, var(--documint-leaf-border) 88%, transparent);
453
+ --documint-leaf-menu-hover-bg:
454
+ color-mix(in srgb, var(--documint-leaf-accent) 12%, var(--documint-leaf-bg));
455
+ position: absolute;
456
+ top: calc(100% + 0.55rem);
457
+ left: 0;
458
+ display: grid;
459
+ gap: 0.2rem;
460
+ min-width: 10.5rem;
461
+ padding: 0.35rem;
462
+ border: 1px solid var(--documint-leaf-menu-border-color);
463
+ border-radius: 0.8rem;
464
+ background: var(--documint-leaf-bg);
465
+ box-shadow: var(--documint-leaf-shadow, var(--documint-leaf-shadow-fallback));
466
+ color: var(--documint-leaf-text);
467
+ font-family: var(--documint-leaf-font-family, "Avenir Next", "Segoe UI", sans-serif);
468
+ font-size: 0.84rem;
469
+ line-height: 1.45;
470
+ }
471
+
472
+ .documint-leaf-menu-item {
473
+ appearance: none;
474
+ display: inline-flex;
475
+ align-items: center;
476
+ gap: 0.36rem;
477
+ width: 100%;
478
+ padding: 0.45rem 0.55rem;
479
+ border: 0;
480
+ border-radius: 0.55rem;
481
+ background: transparent;
482
+ color: var(--documint-leaf-button-text);
483
+ cursor: pointer;
484
+ font: inherit;
485
+ line-height: 1.2;
486
+ text-align: left;
487
+
488
+ &:hover {
489
+ background: var(--documint-leaf-menu-hover-bg);
490
+ }
491
+
492
+ &:disabled {
493
+ opacity: 0.42;
494
+ cursor: default;
495
+
496
+ &:hover {
497
+ background: transparent;
498
+ }
499
+ }
500
+ }
501
+
502
+ .documint-leaf-menu-divider {
503
+ height: 1px;
504
+ margin: 0.15rem 0.2rem;
505
+ background: color-mix(in srgb, var(--documint-leaf-border) 72%, transparent);
506
+ }
507
+
508
+ /* -- Action: icon button used throughout leaf chrome -- */
509
+
510
+ .documint-leaf-action {
511
+ appearance: none;
512
+ display: inline-flex;
513
+ justify-content: center;
514
+ align-items: center;
515
+ width: auto;
516
+ height: auto;
517
+ padding: 0;
518
+ border: 0;
519
+ border-radius: 0;
520
+ background: transparent;
521
+ color: var(--documint-leaf-button-text);
522
+ cursor: pointer;
523
+ font: inherit;
524
+
525
+ &:not(.documint-leaf-action-text) {
526
+ line-height: 0;
527
+ }
528
+
529
+ &:disabled {
530
+ opacity: 0.45;
531
+ cursor: default;
532
+ }
533
+ }
534
+
535
+ .documint-leaf-action-text {
536
+ padding: 0.35rem 0.62rem;
537
+ border: 1px solid var(--documint-leaf-button-border);
538
+ border-radius: 999px;
539
+ background: var(--documint-leaf-button-bg);
540
+ }
541
+
542
+ .documint-leaf-action-danger {
543
+ color: var(--documint-leaf-accent);
544
+ }
545
+
546
+ /* -- Input: textarea (leaf-input) inside a positioning field that hosts
547
+ the absolutely-placed action buttons (cancel, save, submit). -- */
548
+
549
+ .documint-leaf-input-field {
550
+ position: relative;
551
+ width: 100%;
552
+ min-width: 0;
553
+ }
554
+
555
+ .documint-leaf-input-cancel {
556
+ position: absolute;
557
+ top: 0.7rem;
558
+ right: 0.7rem;
559
+ }
560
+
561
+ .documint-leaf-input-save,
562
+ .documint-leaf-input-submit {
563
+ position: absolute;
564
+ right: 0.7rem;
565
+ bottom: calc(0.7rem + 3px);
664
566
  }
665
567
 
666
- :where(.documint-presence-indicator:disabled) {
667
- cursor: default;
668
- opacity: 0.72;
568
+ .documint-leaf-input {
569
+ box-sizing: border-box;
570
+ width: 100%;
571
+ min-height: 4.6rem;
572
+ padding: 0.65rem 3.2rem 0.75rem 0.75rem;
573
+ border: 1px solid var(--documint-leaf-border);
574
+ border-radius: 0.75rem;
575
+ background: var(--documint-leaf-button-bg);
576
+ color: var(--documint-leaf-text);
577
+ font: inherit;
578
+ resize: none;
579
+
580
+ &::placeholder {
581
+ color: var(--documint-leaf-secondary-text);
582
+ }
669
583
  }
670
584
 
671
- :where(.documint-presence-indicator-avatar) {
672
- display: inline-grid;
673
- place-items: center;
674
- width: var(--documint-presence-indicator-size);
675
- height: var(--documint-presence-indicator-size);
676
- overflow: hidden;
677
- border-radius: 999px;
678
- background: var(--documint-presence-color);
679
- color: white;
585
+ .documint-leaf-shell[data-status="resolved"] .documint-leaf-input {
586
+ border-color: var(--documint-leaf-resolved-border);
680
587
  }
681
588
 
682
- :where(.documint-presence-indicator-image) {
683
- display: block;
684
- width: calc(100% - 2px);
685
- height: calc(100% - 2px);
686
- border-radius: inherit;
687
- object-fit: cover;
589
+ /* -- Comment leaf -- */
590
+
591
+ .documint-comment-leaf:not(.documint-comment-leaf-create),
592
+ .documint-comment-leaf-create.is-expanded {
593
+ width: var(--documint-leaf-width, min(18rem, calc(100vw - 4rem)));
688
594
  }
689
595
 
690
- :where(.documint-presence-indicator-direction) {
691
- display: inline-flex;
596
+ .documint-comment-leaf-header,
597
+ .documint-comment-leaf-actions,
598
+ .documint-comment-message-meta {
599
+ display: flex;
600
+ justify-content: space-between;
692
601
  align-items: center;
693
- height: 100%;
694
- padding: 0 0.42rem 0 0.36rem;
695
- color: var(--documint-leaf-text);
602
+ gap: 0.5rem;
696
603
  }
697
604
 
698
- :where(.documint-presence-indicator-arrow) {
699
- display: block;
605
+ .documint-comment-leaf-header {
606
+ margin-bottom: 0.7rem;
700
607
  }
701
608
 
702
- :where(.documint-selection-handle) {
703
- position: absolute;
704
- z-index: 4;
705
- width: 1.2rem;
706
- height: 1.2rem;
707
- margin: 0;
708
- padding: 0;
709
- border: 0;
710
- background: transparent;
711
- pointer-events: auto;
712
- touch-action: none;
713
- cursor: grab;
609
+ .documint-comment-leaf-link {
610
+ display: grid;
611
+ gap: 0.3rem;
612
+ margin-bottom: 0.8rem;
613
+ padding-bottom: 0.8rem;
614
+ border-bottom: 1px solid var(--documint-leaf-divider-color);
714
615
  }
715
616
 
716
- :where(.documint-selection-handle:active) {
717
- cursor: grabbing;
617
+ .documint-comment-leaf-age {
618
+ color: var(--documint-leaf-secondary-text);
619
+ font-size: 0.76rem;
718
620
  }
719
621
 
720
- :where(.documint-selection-handle-start) {
721
- transform: translate(-70%, -82%);
622
+ .documint-comment-actions {
623
+ display: flex;
624
+ gap: 0.4rem;
722
625
  }
723
626
 
724
- :where(.documint-selection-handle-end) {
725
- transform: translate(-30%, -39%);
627
+ .documint-comment-message-meta span {
628
+ color: var(--documint-leaf-secondary-text);
629
+ font-size: 0.74rem;
726
630
  }
727
631
 
728
- :where(.documint-selection-handle-knob) {
729
- position: absolute;
730
- inset: 0;
731
- display: block;
732
- border: 2px solid var(--documint-selection-handle-border);
733
- border-radius: 999px;
734
- background: var(--documint-selection-handle-bg);
735
- box-shadow: 0 2px 8px rgba(15, 23, 42, 0.18);
632
+ /* Thread (scrollable list of comment messages) */
633
+
634
+ .documint-comment-thread {
635
+ display: grid;
636
+ gap: 0.75rem;
637
+ max-height: 16rem;
638
+ margin-bottom: 0.8rem;
639
+ overflow: auto;
640
+
641
+ &.is-empty {
642
+ max-height: 0;
643
+ margin-bottom: 0;
644
+ overflow: hidden;
645
+ }
736
646
  }
737
647
 
738
- :where(.documint-fallback) {
739
- max-width: 100%;
740
- color: #0f172a;
741
- line-height: 1.65;
742
- white-space: normal;
648
+ .documint-comment-message {
649
+ display: grid;
650
+ gap: 0.55rem;
651
+ padding-bottom: 0.75rem;
652
+ border-bottom: 1px solid var(--documint-leaf-divider-color);
653
+
654
+ &:last-child {
655
+ padding-bottom: 0;
656
+ border-bottom: 0;
657
+ }
743
658
  }
744
659
 
745
- :where(.documint-fallback p) {
746
- margin: 0 0 0.9rem;
660
+ .documint-comment-message-root {
661
+ transform: translateY(-8px) scaleY(0);
662
+ transform-origin: top left;
663
+ opacity: 0;
664
+ transition:
665
+ opacity 140ms ease,
666
+ transform 180ms ease;
667
+
668
+ &.is-visible {
669
+ transform: translateY(0) scaleY(1);
670
+ opacity: 1;
671
+ }
672
+
673
+ &.is-hidden {
674
+ max-height: 0;
675
+ padding-bottom: 0;
676
+ border-bottom: 0;
677
+ overflow: hidden;
678
+ }
747
679
  }
748
680
 
749
- :where(.documint-fallback h1),
750
- :where(.documint-fallback h2),
751
- :where(.documint-fallback h3),
752
- :where(.documint-fallback h4),
753
- :where(.documint-fallback h5),
754
- :where(.documint-fallback h6) {
755
- margin: 0 0 0.85rem;
756
- line-height: 1.15;
681
+ /* Reply (compose surface at the bottom of the thread) */
682
+
683
+ .documint-comment-reply {
684
+ position: relative;
685
+ display: block;
686
+ padding-top: 0.85rem;
687
+ border-top: 1px solid var(--documint-leaf-divider-color);
688
+
689
+ &.is-standalone {
690
+ padding-top: 0;
691
+ border-top: 0;
692
+
693
+ &:not(.is-visible) {
694
+ max-height: 0;
695
+ overflow: hidden;
696
+ }
697
+ }
757
698
  }
758
699
 
759
- :where(.documint-fallback h1) {
760
- font-size: 2rem;
700
+ .documint-leaf-shell[data-status="resolved"] .documint-comment-reply {
701
+ border-top-color: color-mix(in srgb, var(--documint-leaf-resolved-border) 72%, transparent);
761
702
  }
762
703
 
763
- :where(.documint-fallback h2) {
764
- font-size: 1.55rem;
704
+ /* Create chrome (the animated "add comment" toolbar that expands into a composer) */
705
+
706
+ .documint-comment-leaf-create {
707
+ --documint-comment-create-scale-duration: 180ms;
708
+ --documint-comment-create-fade-duration: 120ms;
709
+ height: auto;
710
+ padding: 0;
711
+ overflow: visible;
712
+
713
+ &.is-expanded {
714
+ & .documint-comment-leaf-create-shell {
715
+ width: 100%;
716
+ min-height: 5.5rem;
717
+
718
+ & > .documint-leaf-toolbar {
719
+ position: absolute;
720
+ inset: 0;
721
+ z-index: 1;
722
+ pointer-events: none;
723
+ }
724
+ }
725
+
726
+ & .documint-comment-leaf-create-button,
727
+ & .documint-comment-leaf-create-mark {
728
+ opacity: 0;
729
+ transform: scale(0.72);
730
+ pointer-events: none;
731
+ }
732
+
733
+ & .documint-comment-leaf-create-divider {
734
+ opacity: 0;
735
+ }
736
+
737
+ & .documint-comment-leaf-create-content {
738
+ position: relative;
739
+ z-index: 0;
740
+ opacity: 1;
741
+ transform: scale(1);
742
+ pointer-events: auto;
743
+ }
744
+ }
745
+ }
746
+
747
+ .documint-comment-leaf-create-shell {
748
+ position: relative;
749
+ display: grid;
750
+ width: max-content;
751
+ height: 100%;
752
+
753
+ & > .documint-leaf-toolbar {
754
+ position: relative;
755
+ z-index: 0;
756
+ }
765
757
  }
766
758
 
767
- :where(.documint-fallback h3) {
768
- font-size: 1.25rem;
759
+ .documint-comment-leaf-create-button {
760
+ position: relative;
761
+ z-index: 0;
762
+ display: inline-flex;
763
+ width: 1.7rem;
764
+ height: 1.7rem;
765
+ padding: 0;
766
+ line-height: 0;
767
+ opacity: 1;
768
+ transform: scale(1);
769
+ transition:
770
+ opacity var(--documint-comment-create-fade-duration) ease,
771
+ transform var(--documint-comment-create-scale-duration) ease;
769
772
  }
770
773
 
771
- :where(.documint-fallback ul),
772
- :where(.documint-fallback ol) {
773
- margin: 0 0 1rem;
774
- padding-left: 1.4rem;
774
+ .documint-comment-leaf-create-divider {
775
+ opacity: 1;
776
+ transition: opacity var(--documint-comment-create-fade-duration) ease;
775
777
  }
776
778
 
777
- :where(.documint-fallback li > p) {
778
- margin: 0;
779
+ .documint-comment-leaf-create-mark {
780
+ opacity: 1;
781
+ transition:
782
+ opacity var(--documint-comment-create-fade-duration) ease,
783
+ transform var(--documint-comment-create-scale-duration) ease;
779
784
  }
780
785
 
781
- :where(.documint-fallback blockquote) {
782
- margin: 0 0 1rem;
783
- padding-left: 1rem;
784
- border-left: 3px solid rgba(14, 116, 144, 0.3);
785
- color: #334155;
786
+ .documint-comment-leaf-create-content {
787
+ position: absolute;
788
+ top: 0;
789
+ left: 0;
790
+ right: 0;
791
+ z-index: 1;
792
+ opacity: 0;
793
+ transform: scale(0);
794
+ transform-origin: top left;
795
+ pointer-events: none;
796
+ transition:
797
+ opacity var(--documint-comment-create-fade-duration) ease,
798
+ transform var(--documint-comment-create-scale-duration) ease;
786
799
  }
787
800
 
788
- :where(.documint-fallback pre) {
789
- margin: 0 0 1rem;
790
- padding: 0.9rem 1rem;
791
- overflow: auto;
792
- border-radius: 0.85rem;
793
- background: #0f172a;
794
- color: #e2e8f0;
801
+ /* -- Link leaf -- */
802
+
803
+ .documint-link-leaf {
804
+ display: grid;
805
+ gap: 0.3rem;
806
+ min-width: 0;
807
+ width: min(16rem, calc(100vw - 4rem));
795
808
  }
796
809
 
797
- :where(.documint-fallback table) {
798
- width: 100%;
799
- margin: 0 0 1rem;
800
- border-collapse: collapse;
810
+ .documint-link-leaf-row {
811
+ display: grid;
812
+ grid-template-columns: minmax(0, 1fr) auto;
813
+ align-items: flex-start;
814
+ gap: 0.6rem;
815
+
816
+ &.is-editing {
817
+ grid-template-columns: minmax(0, 1fr);
818
+ }
819
+
820
+ & > .documint-leaf-input-field {
821
+ width: 100%;
822
+ }
801
823
  }
802
824
 
803
- :where(.documint-fallback td) {
804
- padding: 0.45rem 0.55rem;
805
- border: 1px solid rgba(148, 163, 184, 0.35);
825
+ .documint-link-leaf-actions {
826
+ display: inline-flex;
827
+ align-items: center;
828
+ gap: 0.5rem;
806
829
  }
807
830
 
808
- :where(.documint-fallback a) {
809
- color: #0369a1;
831
+ .documint-link-leaf-divider {
832
+ margin: 0.2rem 0;
833
+ border-top: 1px solid var(--documint-leaf-divider-color);
810
834
  }
811
835
 
812
- :where(.preview-rich-header) {
813
- margin: 0 0 0.35rem;
814
- color: #9fb3c8;
815
- font-family: "Avenir Next", "Segoe UI", sans-serif;
816
- font-size: 0.74rem;
817
- font-weight: 700;
818
- letter-spacing: 0.08em;
819
- text-transform: uppercase;
836
+ .documint-link-leaf-title {
837
+ color: var(--documint-leaf-text);
838
+ font-size: 0.78rem;
839
+ font-weight: 600;
820
840
  }
821
841
 
822
- :where(.preview-block-code) {
823
- margin: 0 0 1rem;
824
- padding: 0.75rem;
825
- border-radius: 0.9rem;
826
- background: linear-gradient(180deg, #132033, #0f172a);
827
- color: #e2e8f0;
842
+ .documint-link-leaf-url {
843
+ min-width: 0;
844
+ color: var(--documint-leaf-secondary-text);
845
+ font-size: 0.76rem;
846
+ line-height: 1.4;
847
+ overflow-wrap: anywhere;
828
848
  }
829
849
 
830
- :where(.preview-block-code pre) {
831
- margin: 0;
832
- padding: 0.9rem 1rem;
833
- overflow: auto;
834
- border-radius: 0.75rem;
835
- background: rgba(15, 23, 42, 0.72);
850
+ .documint-link-leaf-hint {
851
+ color: var(--documint-leaf-secondary-text);
852
+ font-size: 0.74rem;
853
+ font-style: italic;
836
854
  }
837
855
 
838
- :where(.preview-block-table) {
839
- margin: 0 0 1rem;
840
- padding: 0.75rem;
841
- border: 1px solid rgba(14, 116, 144, 0.18);
842
- border-radius: 0.9rem;
843
- background: rgba(248, 250, 252, 0.96);
856
+ /* -- Completion popover (uses .documint-leaf-menu for visual base) -- */
857
+
858
+ .documint-completion-popover {
859
+ z-index: 1100;
860
+ min-width: 12rem;
844
861
  }
845
862
 
846
- :where(.preview-table-scroll) {
847
- overflow-x: auto;
863
+ .documint-completion-item {
864
+ white-space: nowrap;
865
+ overflow: hidden;
866
+ text-overflow: ellipsis;
867
+
868
+ &.is-active {
869
+ background: var(--documint-leaf-menu-hover-bg);
870
+ }
848
871
  }
849
872
 
850
- :where(.preview-table-scroll table) {
851
- min-width: max-content;
873
+ /* -- Mention: inline pill rendered inside read-only leaf text -- */
874
+
875
+ .documint-mention {
876
+ padding: 0.05em 0.3em;
877
+ border-radius: 0.4em;
878
+ background: var(
879
+ --documint-mention-bg,
880
+ color-mix(in srgb, var(--documint-leaf-accent) 14%, transparent)
881
+ );
882
+ color: var(--documint-mention-text, var(--documint-leaf-accent));
883
+ font-weight: 500;
884
+ white-space: nowrap;
852
885
  }
886
+ `;var iZ=`/* Toolbar-specific styles (button, group, divider, and the menu trigger
887
+ shell + chevron). The menu container/item/divider styles themselves
888
+ live one level up in \`overlays/leaves/styles.css\` as \`.documint-leaf-menu*\`
889
+ so they can be shared by the toolbar's nested menu and other surfaces
890
+ (e.g. the completion popover in LeafInput). */
853
891
 
854
- :where(.preview-inline-image) {
892
+ .documint-leaf-toolbar {
893
+ --documint-leaf-toolbar-button-active-bg:
894
+ color-mix(in srgb, var(--documint-leaf-accent) 16%, var(--documint-leaf-bg));
895
+ --documint-leaf-toolbar-divider-color:
896
+ color-mix(in srgb, var(--documint-leaf-border) 72%, transparent);
855
897
  display: inline-flex;
856
898
  align-items: center;
857
- gap: 0.65rem;
858
- max-width: min(100%, 34rem);
859
- margin: 0 0.15rem;
860
- padding: 0.35rem 0.55rem;
861
- border: 1px solid rgba(14, 116, 144, 0.16);
862
- border-radius: 999px;
863
- background: rgba(240, 249, 255, 0.95);
864
- vertical-align: middle;
899
+ gap: 0.52rem;
865
900
  }
866
901
 
867
- :where(.preview-inline-image img) {
868
- flex: none;
869
- width: 2.4rem;
870
- height: 2.4rem;
871
- object-fit: cover;
872
- border-radius: 0.65rem;
873
- background: rgba(148, 163, 184, 0.18);
902
+ .documint-leaf-toolbar-group {
903
+ display: inline-flex;
904
+ align-items: center;
905
+ gap: 0.38rem;
874
906
  }
875
907
 
876
- :where(.preview-inline-image > span) {
877
- display: grid;
878
- min-width: 0;
908
+ .documint-leaf-toolbar-divider {
909
+ width: 1px;
910
+ height: 1.15rem;
911
+ background: var(--documint-leaf-toolbar-divider-color);
879
912
  }
880
913
 
881
- :where(.preview-inline-image strong) {
882
- color: #0f172a;
883
- font-family: "Avenir Next", "Segoe UI", sans-serif;
884
- font-size: 0.88rem;
914
+ .documint-leaf-toolbar-button {
915
+ appearance: none;
916
+ display: inline-flex;
917
+ justify-content: center;
918
+ align-items: center;
919
+ gap: 0.36rem;
920
+ min-width: 1.45rem;
921
+ height: 1.45rem;
922
+ padding: 0 0.12rem;
923
+ border: 0;
924
+ border-radius: 0.38rem;
925
+ background: transparent;
926
+ color: var(--documint-leaf-button-text);
927
+ cursor: pointer;
928
+ font: inherit;
929
+ line-height: 0;
930
+ transition:
931
+ background-color 120ms ease,
932
+ color 120ms ease;
933
+
934
+ &:hover {
935
+ background: var(--documint-leaf-toolbar-button-active-bg);
936
+ }
937
+
938
+ &.active {
939
+ background: var(--documint-leaf-toolbar-button-active-bg);
940
+ color: var(--documint-leaf-text);
941
+ }
942
+
943
+ &:disabled {
944
+ opacity: 0.42;
945
+ cursor: default;
946
+
947
+ &:hover {
948
+ background: transparent;
949
+ }
950
+ }
885
951
  }
886
952
 
887
- :where(.preview-inline-image small) {
888
- overflow: hidden;
889
- color: #475569;
890
- font-family: "Avenir Next", "Segoe UI", sans-serif;
891
- font-size: 0.75rem;
892
- text-overflow: ellipsis;
893
- white-space: nowrap;
953
+ .documint-leaf-toolbar-menu-shell {
954
+ position: relative;
955
+
956
+ & .documint-leaf-toolbar-button {
957
+ gap: 0.18rem;
958
+ }
894
959
  }
895
960
 
896
- ${mJ}
897
- `;import{jsxDEV as Y1,Fragment as IG}from"react/jsx-dev-runtime";var gG=2,gJ={activeBlockType:null,activeCommentThreadIndex:null,activeSpanKind:null,canonicalContent:"",characterCount:0,commentThreadCount:0,layoutWidth:0,resolvedCommentCount:0,selectionFrom:0,selectionTo:0};function pJ({className:$,content:M,keybindings:J,onContentChange:Z,onStateChange:X,presence:A,theme:Y}){let Q=y1(null),K=y1(null),q=y1(null),N=y1(null),U=y1(null),G=y1(null),B=y1(null),D=y1(null),F=y1(!1),H=y1(M),b=y1(""),E=y1(gJ),V=y1(null),[R,O]=MM(!1),{theme:j,themeStyles:f}=CJ(Y),[z,y]=MM(gJ),T=f0(()=>C$(M),[M]),W=f0(()=>i5(T),[T]),[_,C]=MM(()=>d2(T)),g=XJ(_.documentIndex.document),u=f0(()=>[...g?.images.values()??[]].some((P)=>P.status==="loading"),[g]);U.current=_,b.current||=W;let d=wJ({editorState:_,editorStateRef:U,renderResources:g,theme:j}),{actions:p,props:J1,refs:k,state:S}=d,{getScrollTop:m,observePreparedViewport:Z1,observeScrollContainer:t,resolvePointerPoint:N1,scrollTo:v1}=p,{layoutWidth:g1,preparedViewport:A1,scrollContentHeight:S4,surfaceWidth:Q6,viewportHeight:u0,viewportTop:m4}=S,{scrollContainer:i1}=k,v4=f0(()=>g2(_),[_]),h1=f0(()=>f1(_),[_]),V1=f0(()=>n(_),[_]),g4=f0(()=>IJ(_,h1.liveRanges),[h1.liveRanges,_]),B2=Boolean(Z),e=()=>U.current??_,z1=B1((P,w)=>{let v=g2(P),c=f1(P),r=GJ(P),o={activeBlockType:v.block?.nodeType??null,activeCommentThreadIndex:IJ(P,c.liveRanges),activeSpanKind:v.span.kind==="none"?null:v.span.kind,canonicalContent:w,characterCount:w.length,commentThreadCount:c.threads.length,layoutWidth:g1,resolvedCommentCount:O6(c.threads),selectionFrom:r.start,selectionTo:r.end};if(y((l1)=>i$(l1,o)?l1:o),!i$(E.current,o))E.current=o,X?.(o)}),i=B1((P)=>{if(!P)return;let w=U.current??_,v=w.documentIndex!==P.documentIndex,c=w5(w,P);U.current=P,C(P);let r=A1.current;if(!(!v||!r||r.layout.regionLineIndices.has(P.selection.focus.regionId)))A1.invalidate();if(c)O1("viewport");if(!v)return;let l1=a2(P),D2=i5(l1);b.current=D2,H.current=D2,Z?.(D2,l1)}),JM=B1((P=A1.current)=>{if(!P)return;let w=s$(K.current,{paintHeight:P.paintHeight,paintTop:P.paintTop,width:g1});if(!w)return;let{context:v,devicePixelRatio:c,height:r,width:o}=w;F$(_,P,v,{activeBlockId:v4.block?.blockId??null,activeRegionId:_.selection.focus.regionId,activeThreadIndex:XM??g4,devicePixelRatio:c,height:r,liveCommentRanges:h1.liveRanges,normalizedSelection:V1,now:performance.now(),resources:g,theme:j,width:o})}),ZM=B1((P=A1.current)=>{if(!P)return;let w=s$(q.current,{paintHeight:P.paintHeight,paintTop:P.paintTop,width:g1});if(!w)return;let{context:v,devicePixelRatio:c,height:r,width:o}=w;D$(_,P,v,{devicePixelRatio:c,height:r,normalizedSelection:V1,presence:K6.canvasPresence,showCaret:V1.start.regionId!==V1.end.regionId||V1.start.offset!==V1.end.offset||o1.isVisible(),theme:j,width:o})}),lJ=B1(()=>{A1.invalidate();let P=A1.get();Z1(P),K6.refreshViewportPresence(P),JM(P),ZM(P)}),{scheduleRender:O1}=WJ({hasRunningAnimations:()=>z8(U.current??_,performance.now()),renderContent:JM,renderOverlay:ZM,renderViewport:lJ}),rJ=J1.getScrollContainer({onScroll:()=>O1("viewport")}),o1=JJ({canShowInsertionLeaf:Boolean(Z),canShowTableLeaf:Boolean(Z),commentState:h1,editorState:_,editorViewportState:A1,onVisibilityChange:()=>O1("overlay")}),L1=QJ({commentState:h1,editorStateRef:U,editorViewportState:A1,resolveDocumentPoint:N1}),XM=L1.leaf?.kind==="comment"?L1.leaf.threadIndex:null,cJ=B1((P)=>{t(P),O1("viewport")}),K6=PJ({editorState:_,editorStateRef:U,editorViewportState:A1,onViewportScroll:cJ,presence:A,scrollContainerRef:i1,scheduleOverlayRender:()=>O1("overlay")}),AM=B1((P,w)=>{if(P.scrollHeight<=P.clientHeight||w.deltaY===0)return;let v=24,c=w.deltaMode===1?v:w.deltaMode===2?P.clientHeight:1,r=Math.max(0,Math.min(P.scrollHeight-P.clientHeight,P.scrollTop+w.deltaY*c));if(r===P.scrollTop)return;w.preventDefault(),v1(r),O1("viewport")}),F2=DJ({editorState:_,editorStateRef:U,editorViewportState:A1,inputRef:N,keybindings:J,onActivity:o1.markActivity,onEditorStateChange:i}),I1=VJ({autoScrollContainer:(P)=>{I$(i1.current,P)},canShowSelectionLeaf:B2,canvasRef:K,threads:h1.threads,editorState:_,editorStateRef:U,scrollContainerRef:i1,editorViewportState:A1,onActivity:o1.markActivity,onEditorStateChange:i}),xJ=B1(()=>{K.current?.focus({preventScroll:!0})}),YM=B1((P)=>{let w=K.current;if(w&&G.current===P)w.releasePointerCapture(P)}),QM=B1(()=>{G.current=null,B.current=null}),dJ=B1((P)=>{YM(P.pointerId),QM(),D.current=null,F.current=!1}),aJ=B1((P)=>{let w=K.current,v=e(),c=N1(P);if(!c)return;let r=L1.resolveTarget(P);if(r?.kind==="task-toggle"){P.preventDefault(),P.stopPropagation(),D.current=r.listItemId,o1.markActivity(),xJ();return}let o=t6(v,A1.get(),c);if(!w||!o)return;G.current=P.pointerId,B.current={offset:o.offset,regionId:o.regionId},o1.markActivity(),w.setPointerCapture(P.pointerId),i(K1(v,{offset:o.offset,regionId:o.regionId})),F2.focus({offset:o.offset,regionId:o.regionId})}),sJ=B1(()=>{L1.canvasHandlers.onPointerLeave(),F.current=!1}),iJ=B1((P)=>{let w=B.current,v=e(),c=N1(P);if(!c)return;if(L1.canvasHandlers.onPointerMove(P),G.current!==P.pointerId||!w)return;let r=R2(v,A1.get(),c,w);if(!r)return;o1.markActivity(),I$(i1.current,P),i(K1(v,{anchor:w,focus:r}))}),oJ=B1((P)=>{let w=e();if(YM(P.pointerId),D.current){let v=t8(w,D.current);if(D.current=null,v)F.current=!0,P.preventDefault(),P.stopPropagation(),o1.markActivity(),i(v)}QM()}),nJ=B1((P)=>{if(F.current){F.current=!1,D.current=null,P.preventDefault(),P.stopPropagation();return}if(L1.canvasHandlers.onClick(P))return;D.current=null,F2.focus()}),tJ=B1((P)=>{let w=e(),v=N1(P),c=L1.resolveTarget(P);if(!v||c?.kind==="task-toggle")return;let r=e6(w,A1.get(),v);if(!r)return;P.preventDefault(),P.stopPropagation(),o1.markActivity(),i(K1(w,r)),F2.focus()});k0(()=>{O(!0)},[]),vG(()=>{if(M===H.current)return;let P=U.current,w=fJ(P,d2(T)),v=w.state,c=w.didReconcile?m():0;U.current=v,C(v),H.current=M,b.current=W,v1(c)},[W,M,T,m,v1]),k0(()=>{z1(_,b.current||W)},[W,_,z1,Q6]),k0(()=>{let P=i1.current,w=_.selection.focus;if(!P)return;let v={layoutWidth:g1,offset:w.offset,regionId:w.regionId,scrollContentHeight:S4,viewportHeight:u0};if(hG(V.current,v))return;let c=24,r=J8(_,A1.get(),w);if(!r)return;let o=u0,l1=P.scrollTop,D2=l1+c,XZ=l1+o-c;if(r.top<D2){let q6=v1(Math.max(0,r.top-c));if(hJ(r,q6,o,c))V.current=v;return}if(r.top+r.height>XZ){let q6=v1(Math.max(0,r.top+r.height-o+c));if(hJ(r,q6,o,c))V.current=v;return}V.current=v},[_,_.selection.focus.offset,_.selection.focus.regionId,A1,g1,S4,v1,u0]),k0(()=>{O1("viewport")},[h1.liveRanges,_,g1,V1.end.regionId,V1.end.offset,V1.start.regionId,V1.start.offset,v4.block?.blockId,j,g,g4,O1,u0]),k0(()=>{if(!u)return;let P=null,w=window,v=()=>{O1("viewport"),P=w.requestAnimationFrame(v)};return P=w.requestAnimationFrame(v),()=>{if(P!==null)w.cancelAnimationFrame(P)}},[u,O1]),k0(()=>{O1("content")},[XM,O1]),k0(()=>{let P=i1.current;if(!P)return;let w=(v)=>{AM(P,v)};return P.addEventListener("wheel",w,{passive:!1}),()=>{P.removeEventListener("wheel",w)}},[AM]);let eJ=$?`documint ${$}`:"documint",$Z=()=>{let P=L1.leaf,w=P??I1.leaf??o1.leaf,v=!P&&Boolean(I1.leaf),c=i1.current?.getBoundingClientRect()??null,r=w?.kind==="thread"?{...w,thread:h1.threads[w.threadIndex]??null}:null,o=w?.kind==="comment"?{animateInitialComment:!1,link:w.link,thread:w.thread,threadIndex:w.threadIndex}:r?.thread?{animateInitialComment:r.animateInitialComment??!1,link:null,thread:r.thread,threadIndex:r.threadIndex}:null,l1=o?.thread&&A0(o.thread)?"resolved":"default";return{annotationThreadLeaf:o,visibleLeaf:w,visibleLeafAnchor:w?{container:Q.current,isSelection:v,left:(c?.left??0)+w.left,onPointerEnter:P?L1.leafHandlers.onPointerEnter:void 0,onPointerLeave:P?L1.leafHandlers.onPointerLeave:void 0,top:(c?.top??0)+w.top-m4+(v?gG:0)}:void 0,visibleLeafClassName:w?.kind==="link"?"documint-link-leaf":void 0,visibleLeafStatus:l1}},{annotationThreadLeaf:p1,visibleLeaf:_1,visibleLeafAnchor:KM,visibleLeafClassName:MZ,visibleLeafStatus:JZ}=$Z(),ZZ=(()=>{if(!_1)return null;switch(_1.kind){case"insertion":return Y1(a7,{onInsert:(P)=>{i(Y2(e(),P))},onInsertTable:(P)=>{i(r8(e(),P))}},void 0,!1,void 0,this);case"table":return Y1(e7,{canDeleteColumn:_1.columnCount>1,canDeleteRow:_1.rowCount>1,onDeleteColumn:()=>{i(x8(e()))},onDeleteRow:()=>{i(a8(e()))},onDeleteTable:()=>{i(s8(e()))},onInsertColumn:(P)=>{i(c8(e(),P))},onInsertRow:(P)=>{i(d8(e(),P))}},void 0,!1,void 0,this);case"link":return Y1(n7,{canEdit:B2,onDelete:()=>{let P=n8(e(),_1.regionId,_1.startOffset,_1.endOffset);if(P)i(P)},onSave:(P)=>{let w=o8(e(),_1.regionId,_1.startOffset,_1.endOffset,P);if(w)i(w)},title:_1.title,url:_1.url},void 0,!1,void 0,this);case"create":return Y1(k$,{activeMarks:_1.activeMarks,canEdit:B2,link:null,mode:"create",onCreateThread:(P)=>{let w=e(),v=a2(w).comments.length,c=e8(w,_1.selection,P.trim());if(!c)return;i(c),I1.promoteLeafToThread(v,!0)},onToggleBold:()=>{i(M4(e()))},onToggleItalic:()=>{i(J4(e()))},onToggleStrikethrough:()=>{i(Z4(e()))},onToggleUnderline:()=>{i(X4(e()))}},void 0,!1,void 0,this);default:return p1?Y1(k$,{animateInitialComment:p1.animateInitialComment,canEdit:B2,link:p1.link,mode:"thread",onDeleteComment:(P)=>{i(J$(e(),p1.threadIndex,P))},onDeleteThread:()=>{i(Z$(e(),p1.threadIndex))},onEditComment:(P,w)=>{i(M$(e(),p1.threadIndex,P,w))},onReply:(P)=>{i($$(e(),p1.threadIndex,P))},onToggleResolved:()=>{i(X$(e(),p1.threadIndex,!A0(p1.thread)))},thread:p1.thread},void 0,!1,void 0,this):null}})();return Y1("section",{className:eJ,"data-active-block":z.activeBlockType??"","data-active-comment-thread":z.activeCommentThreadIndex??"","data-active-span":z.activeSpanKind??"",ref:Q,style:{...f,height:"100%",minHeight:0},children:[Y1("style",{children:vJ},void 0,!1,void 0,this),Y1("div",{...rJ,className:"documint-scroll-container",style:{height:"100%",minHeight:0},children:[Y1("textarea",{...F2.inputHandlers,ref:N,autoCapitalize:"sentences",className:"documint-input",spellCheck:!1,tabIndex:-1},void 0,!1,void 0,this),Y1(Q7,{insetX:j.paddingX,insetY:j.paddingY,...K6.presenceOverlayProps},void 0,!1,void 0,this),Y1("div",{...J1.scrollContent,className:"documint-scroll-content",children:[Y1("canvas",{...F2.canvasHandlers,"aria-label":"Documint editor",className:"documint-content-canvas",style:{cursor:L1.cursor},onPointerCancel:dJ,onPointerDown:aJ,onPointerLeave:sJ,onPointerMove:iJ,onPointerUp:oJ,onClick:nJ,onDoubleClick:tJ,ref:K,tabIndex:0},void 0,!1,void 0,this),Y1("canvas",{"aria-hidden":"true",className:"documint-overlay-canvas",ref:q},void 0,!1,void 0,this),I1.handles?Y1(IG,{children:[Y1("div",{"aria-hidden":"true",className:"documint-selection-handle documint-selection-handle-start",style:{left:`${I1.handles.start.left}px`,top:`${I1.handles.start.top}px`},...I1.startHandleProps,children:Y1("span",{className:"documint-selection-handle-knob"},void 0,!1,void 0,this)},void 0,!1,void 0,this),Y1("div",{"aria-hidden":"true",className:"documint-selection-handle documint-selection-handle-end",style:{left:`${I1.handles.end.left}px`,top:`${I1.handles.end.top}px`},...I1.endHandleProps,children:Y1("span",{className:"documint-selection-handle-knob"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,_1&&KM?Y1(s7,{anchor:KM,className:MZ,status:JZ,children:ZZ},void 0,!1,void 0,this):null]},void 0,!0,void 0,this),!R?Y1("div",{className:"documint-fallback",children:Y1(A6,{blocks:T.blocks},void 0,!1,void 0,this)},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)}function hG($,M){return $?.layoutWidth===M.layoutWidth&&$.regionId===M.regionId&&$.offset===M.offset&&$.scrollContentHeight===M.scrollContentHeight&&$.viewportHeight===M.viewportHeight}function hJ($,M,J,Z){return $.top>=M+Z&&$.top+$.height<=M+J-Z}function IJ($,M){let J=new Map($.documentIndex.regions.map((K,q)=>[K.id,q])),Z=Y6(J,$.selection.anchor.regionId,$.selection.anchor.offset),X=Y6(J,$.selection.focus.regionId,$.selection.focus.offset),[A,Y]=Z<=X?[Z,X]:[X,Z],Q=Z===X;for(let K of M){let q=Y6(J,K.regionId,K.startOffset),N=Y6(J,K.regionId,K.endOffset);if(Q){if(A>=q&&A<=N)return K.threadIndex;continue}if(Math.max(A,q)<Math.min(Y,N))return K.threadIndex}return null}function Y6($,M,J){return($.get(M)??-1)*1e6+J}export{zJ as mintTheme,OJ as midnightTheme,f4 as lightTheme,v$ as defaultKeybindings,u4 as darkTheme,pJ as Documint};
961
+ .documint-leaf-toolbar-menu-chevron {
962
+ transition: transform 140ms ease;
963
+
964
+ &.is-open {
965
+ transform: rotate(180deg);
966
+ }
967
+ }
968
+ `;var sZ=`${dZ}
969
+ ${aZ}
970
+ ${iZ}`;import{jsxDEV as M0,Fragment as KB}from"react/jsx-dev-runtime";var QB=2,oZ={activeBlockType:null,activeCommentThreadIndex:null,activeSpanKind:null,canonicalContent:"",characterCount:0,commentThreadCount:0,layoutWidth:0,resolvedCommentCount:0,selectionFrom:0,selectionTo:0};function tZ({className:$,content:M,keybindings:Z,onContentChange:J,onStateChange:X,presence:Y,theme:Q,users:K}){let q=R1(null),U=R1(null),N=R1(null),A=R1(null),G=R1(M),B=R1(""),F=R1(oZ),[_,D]=G$(!1),{theme:T,themeStyles:O}=hZ(Q),[y,R]=G$(oZ),C=t0(()=>S3(M),[M]),m=t0(()=>J8(C),[C]),[H,P]=G$(()=>a2(C)),E=DZ(H.documentIndex.document),j=t0(()=>[...E?.images.values()??[]].some((k)=>k.status==="loading"),[E]);A.current=H,B.current||=m;let W=pZ({editorState:H,editorStateRef:A,renderResources:E,theme:T}),{actions:b,props:z,refs:u,state:v}=W,{autoScrollDuringDrag:l,getScrollTop:g,observePreparedViewport:w,observeScrollContainer:V,prepareNextPaint:L,reconcileEditorState:f,resolvePoint:x,scrollTo:h}=b,{layoutWidth:Q0,preparedViewport:b0,scrollContentHeight:e0,surfaceWidth:L1,viewportHeight:g4,viewportTop:B8}=v,{scrollContainer:I4}=u,p4=t0(()=>g2(H),[H]),S0=t0(()=>k0(H),[H]),P0=t0(()=>s(H),[H]),l4=t0(()=>{if(!K?.length)return;return[{trigger:"@",items:K.map((k)=>({label:k.fullName??k.username}))}]},[K]),_8=t0(()=>rZ(K,Y),[K,Y]),r4=t0(()=>nZ(H,S0.liveRanges),[S0.liveRanges,H]),k1=Boolean(J),e=()=>A.current??H,F8=_2((k,I)=>{let J0=g2(k),q0=k0(k),D0=VZ(k),U0={activeBlockType:J0.block?.nodeType??null,activeCommentThreadIndex:nZ(k,q0.liveRanges),activeSpanKind:J0.span.kind==="none"?null:J0.span.kind,canonicalContent:I,characterCount:I.length,commentThreadCount:q0.threads.length,layoutWidth:Q0,resolvedCommentCount:S8(q0.threads),selectionFrom:D0.start,selectionTo:D0.end};if(R((a4)=>K$(a4,U0)?a4:U0),!K$(F.current,U0))F.current=U0,X?.(U0)}),n=_2((k)=>{if(!k)return;let I=A.current??H,J0=I.documentIndex!==k.documentIndex,q0=u5(I,k);if(A.current=k,P(k),f(I,k),q0)b8();if(!J0)return;let D0=i2(k),U0=J8(D0);B.current=U0,G.current=U0,J?.(U0,D0)}),W0=_2((k=b0.peek())=>{if(!k)return;let I=Q$(q.current,{paintHeight:k.paintHeight,paintTop:k.paintTop,width:Q0});if(!I)return;let{context:J0,devicePixelRatio:q0,height:D0,width:U0}=I;W3(H,k,J0,{activeBlockId:p4.block?.blockId??null,activeRegionId:H.selection.focus.regionId,activeThreadIndex:F$??r4,devicePixelRatio:q0,height:D0,liveCommentRanges:S0.liveRanges,normalizedSelection:P0,now:performance.now(),resources:E,theme:T,width:U0})}),c4=_2((k=b0.peek())=>{if(!k)return;let I=Q$(U.current,{paintHeight:k.paintHeight,paintTop:k.paintTop,width:Q0});if(!I)return;let{context:J0,devicePixelRatio:q0,height:D0,width:U0}=I;V3(H,k,J0,{devicePixelRatio:q0,height:D0,normalizedSelection:P0,presence:d4.presence,showCaret:P0.start.regionId!==P0.end.regionId||P0.start.offset!==P0.end.offset||F2.isVisible(),theme:T,width:U0})}),eZ=_2(()=>{let k=L();w(k),d4.refreshPresence(k),W0(k),c4(k)}),{scheduleContentPaint:b8,scheduleFullPaint:B$,scheduleFullRender:f1,scheduleOverlayPaint:_$}=LZ({editorStateRef:A,renderContent:W0,renderOverlay:c4,renderViewport:eZ}),$J=z.getScrollContainer({onScroll:()=>f1()}),F2=bZ({canShowInsertionLeaf:Boolean(J),canShowTableLeaf:Boolean(J),commentState:S0,editorState:H,editorViewportState:b0,getScrollTop:g,layoutWidth:Q0,onVisibilityChange:_$,scrollContentHeight:e0,scrollTo:h,viewportHeight:g4}),x4=CZ({applyNextState:n,editorState:H,editorStateRef:A,editorViewportState:b0,inputRef:N,keybindings:Z,onActivity:F2.markActivity}),H1=PZ({applyNextState:n,autoScrollDuringDrag:l,canvasRef:q,commentState:S0,editorStateRef:A,editorViewportState:b0,focusInput:x4.focus,onActivity:F2.markActivity,readCurrentState:e,resolvePoint:x}),F$=H1.leaf?.kind==="comment"?H1.leaf.threadIndex:null,MJ=_2((k)=>{V(k),f1()}),d4=RZ({editorState:H,editorStateRef:A,editorViewportState:b0,onViewportScroll:MJ,scrollContainerRef:I4,scheduleOverlayRender:_$,userPresence:_8}),u0=mZ({applyNextState:n,autoScrollDuringDrag:l,canShowSelectionLeaf:k1,editorState:H,editorStateRef:A,editorViewportState:b0,focusInput:x4.focus,onActivity:F2.markActivity,resolvePoint:x,threads:S0.threads});B2(()=>{f1()},[H.documentIndex,Q0,T,E,f1,g4]),B2(()=>{B$()},[P0.end.offset,P0.end.regionId,P0.start.offset,P0.start.regionId,B$,p4.block?.blockId]),B2(()=>{b8()},[r4,S0.liveRanges,F$,b8]),B2(()=>{if(!j)return;let k=null,I=window,J0=()=>{f1(),k=I.requestAnimationFrame(J0)};return k=I.requestAnimationFrame(J0),()=>{if(k!==null)I.cancelAnimationFrame(k)}},[j,f1]);let ZJ=()=>{let k=H1.leaf,I=k??u0.leaf??F2.leaf,J0=!k&&Boolean(u0.leaf),q0=I4.current?.getBoundingClientRect()??null,D0=I?.kind==="thread"?{...I,thread:S0.threads[I.threadIndex]??null}:null,U0=I?.kind==="comment"?{animateInitialComment:!1,link:I.link,thread:I.thread,threadIndex:I.threadIndex}:D0?.thread?{animateInitialComment:D0.animateInitialComment??!1,link:null,thread:D0.thread,threadIndex:D0.threadIndex}:null,a4=U0?.thread&&Z1(U0.thread)?"resolved":"default";return{annotationThreadLeaf:U0,visibleLeaf:I,visibleLeafAnchor:I?{isSelection:J0,left:(q0?.left??0)+I.left,onPointerEnter:k?H1.leafHandlers.onPointerEnter:void 0,onPointerLeave:k?H1.leafHandlers.onPointerLeave:void 0,top:(q0?.top??0)+I.top-B8+(J0?QB:0)}:void 0,visibleLeafStatus:a4}},{annotationThreadLeaf:v0,visibleLeaf:B0,visibleLeafAnchor:b$,visibleLeafStatus:JJ}=ZJ(),XJ=(()=>{if(!B0)return null;switch(B0.kind){case"insertion":return M0(QZ,{onInsert:(k)=>{n(Y2(e(),k))},onInsertTable:(k)=>{n(t6(e(),k))}},void 0,!1,void 0,this);case"table":return M0(GZ,{canDeleteColumn:B0.columnCount>1,canDeleteRow:B0.rowCount>1,onDeleteColumn:()=>{n($3(e()))},onDeleteRow:()=>{n(Z3(e()))},onDeleteTable:()=>{n(J3(e()))},onInsertColumn:(k)=>{n(e6(e(),k))},onInsertRow:(k)=>{n(M3(e(),k))}},void 0,!1,void 0,this);case"link":return M0(NZ,{canEdit:k1,onDelete:()=>{let k=Q3(e(),B0.regionId,B0.startOffset,B0.endOffset);if(k)n(k)},onSave:(k)=>{let I=Y3(e(),B0.regionId,B0.startOffset,B0.endOffset,k);if(I)n(I)},title:B0.title,url:B0.url},void 0,!1,void 0,this);case"create":return M0(x3,{activeMarks:B0.activeMarks,canEdit:k1,link:null,mode:"create",mentionSources:l4,onCreateThread:(k)=>{let I=e(),J0=i2(I).comments.length,q0=q3(I,B0.selection,k.trim());if(!q0)return;n(q0),u0.promoteLeafToThread(J0,!0)},onToggleBold:()=>{n(Z4(e()))},onToggleItalic:()=>{n(J4(e()))},onToggleStrikethrough:()=>{n(X4(e()))},onToggleUnderline:()=>{n(Y4(e()))}},void 0,!1,void 0,this);default:return v0?M0(x3,{animateInitialComment:v0.animateInitialComment,canEdit:k1,link:v0.link,mode:"thread",mentionSources:l4,onDeleteComment:(k)=>{n(A3(e(),v0.threadIndex,k))},onDeleteThread:()=>{n(G3(e(),v0.threadIndex))},onEditComment:(k,I)=>{n(N3(e(),v0.threadIndex,k,I))},onReply:(k)=>{n(U3(e(),v0.threadIndex,k))},onToggleResolved:()=>{n(B3(e(),v0.threadIndex,!Z1(v0.thread)))},thread:v0.thread},void 0,!1,void 0,this):null}})();B2(()=>{D(!0)},[]),B2(()=>{F8(H,B.current||m)},[m,H,F8,L1]),YB(()=>{if(M===G.current)return;let k=A.current,I=xZ(k,a2(C)),J0=I.state,q0=I.didReconcile?g():0;A.current=J0,P(J0),G.current=M,B.current=m,h(q0)},[m,M,C,g,h]);let YJ=$?`documint ${$}`:"documint";return M0(xM,{themeStyles:O,children:M0("section",{className:YJ,"data-active-block":y.activeBlockType??"","data-active-comment-thread":y.activeCommentThreadIndex??"","data-active-span":y.activeSpanKind??"",style:{...O,height:"100%",minHeight:0},children:[M0("style",{children:sZ},void 0,!1,void 0,this),M0("div",{...$J,className:"documint-scroll-container",style:{height:"100%",minHeight:0},children:[M0("textarea",{...x4.inputHandlers,ref:N,autoCapitalize:"sentences",className:"documint-input",spellCheck:!1,tabIndex:-1},void 0,!1,void 0,this),M0(BM,{insetX:T.paddingX,insetY:T.paddingY,onSelect:d4.scrollToPresence,presence:d4.presence},void 0,!1,void 0,this),M0("div",{...z.scrollContent,className:"documint-scroll-content",children:[M0("canvas",{...x4.canvasHandlers,...H1.canvasHandlers,"aria-label":"Documint editor",className:"documint-content-canvas",style:{cursor:H1.cursor},ref:q,tabIndex:0},void 0,!1,void 0,this),M0("canvas",{"aria-hidden":"true",className:"documint-overlay-canvas",ref:U},void 0,!1,void 0,this),u0.handles?M0(KB,{children:[M0("div",{"aria-hidden":"true",className:"documint-selection-handle documint-selection-handle-start",style:{left:`${u0.handles.start.left}px`,top:`${u0.handles.start.top}px`},...u0.startHandleProps,children:M0("span",{className:"documint-selection-handle-knob"},void 0,!1,void 0,this)},void 0,!1,void 0,this),M0("div",{"aria-hidden":"true",className:"documint-selection-handle documint-selection-handle-end",style:{left:`${u0.handles.end.left}px`,top:`${u0.handles.end.top}px`},...u0.endHandleProps,children:M0("span",{className:"documint-selection-handle-knob"},void 0,!1,void 0,this)},void 0,!1,void 0,this)]},void 0,!0,void 0,this):null,B0&&b$?M0(KZ,{anchor:b$,status:JJ,children:XJ},void 0,!1,void 0,this):null]},void 0,!0,void 0,this),!_?M0("div",{className:"documint-fallback",children:M0(A8,{blocks:C.blocks},void 0,!1,void 0,this)},void 0,!1,void 0,this):null]},void 0,!0,void 0,this)]},void 0,!0,void 0,this)},void 0,!1,void 0,this)}function nZ($,M){let Z=new Map($.documentIndex.regions.map((q,U)=>[q.id,U])),J=G8(Z,$.selection.anchor.regionId,$.selection.anchor.offset),X=G8(Z,$.selection.focus.regionId,$.selection.focus.offset),[Y,Q]=J<=X?[J,X]:[X,J],K=J===X;for(let q of M){let U=G8(Z,q.regionId,q.startOffset),N=G8(Z,q.regionId,q.endOffset);if(K){if(Y>=U&&Y<=N)return q.threadIndex;continue}if(Math.max(Y,U)<Math.min(Q,N))return q.threadIndex}return null}function G8($,M,Z){return($.get(M)??-1)*1e6+Z}export{SZ as mintTheme,uZ as midnightTheme,v4 as lightTheme,o3 as defaultKeybindings,h4 as darkTheme,tZ as Documint};