documint 0.0.8 → 0.0.10
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.d.ts +2 -14
- package/dist/index.js +91 -52
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,38 +1,37 @@
|
|
|
1
|
-
import{useEffect as
|
|
2
|
-
`);return{id:
|
|
3
|
-
`);return{align
|
|
4
|
-
`;case"image":return
|
|
5
|
-
`);case"table":return
|
|
6
|
-
`);case"divider":return"";case"raw":return
|
|
7
|
-
`).trim()}function
|
|
8
|
-
`);return{id:
|
|
9
|
-
`);return{align:$.align,id:J0("table",Y,Z),plainText:Z,rows:X,type:"table"}}case"divider":return{id:J0("divider",Y,"divider"),plainText:"",type:"divider"};case"raw":return{id:J0("raw",Y,$.source),originalType:$.originalType,plainText:$.source,source:$.source,type:"raw"}}}function zK($,Y){return{cells:$.cells.map((X,Z)=>{let J=X.children.map((Q,M)=>W5(Q,`${Y}.cells.${Z}.children.${M}`)),K=X0(J);return{children:J,id:J0("tableCell",`${Y}.cells.${Z}`,K),plainText:K}}),id:J0("tableRow",Y,String($.cells.length))}}function W5($,Y){switch($.type){case"lineBreak":return{id:J0("lineBreak",Y,"lineBreak"),type:"lineBreak"};case"image":return{alt:$.alt,id:J0("image",Y,`${$.url}:${$.width??""}:${$.alt??""}`),title:$.title,type:"image",url:$.url,width:$.width};case"code":return{code:$.code,id:J0("code",Y,$.code),type:"code"};case"link":{let X=$.children.map((J,K)=>W5(J,`${Y}.children.${K}`)),Z=X0(X);return{children:X,id:J0("link",Y,`${$.url}:${Z}`),title:$.title,type:"link",url:$.url}}case"text":return{id:J0("text",Y,`${$.text}:${$.marks.join(",")}`),marks:$.marks,text:$.text,type:"text"};case"raw":return{id:J0("raw",Y,$.source),originalType:$.originalType,source:$.source,type:"raw"}}}function X7($){return Z2($,(Y,{recurse:X})=>{switch(Y.type){case"blockquote":case"list":case"listItem":return X();case"heading":case"paragraph":return O0(Y,K8(Y.children));case"table":return B0(Y,Y.rows.map((Z)=>({...Z,cells:Z.cells.map((J)=>({...J,children:K8(J.children)}))})));default:return Y}})}function K8($){let Y=null,X=()=>Y??=[...$];for(let Z=$.length-1;Z>=0;Z-=1){let J=$[Z];if(J.type==="text"){let K=J.text.replace(/[ \t]+$/u,"");if(K.length===J.text.length)return Y??$;let Q=X();if(K.length===0){Q.splice(Z,1);continue}return Q[Z]={...J,text:K},Q}if(J.type==="link"){let K=K8(J.children);if(K===J.children)return Y??$;let Q=X();if(K.length===0){Q.splice(Z,1);continue}return Q[Z]={...J,children:K},Q}return Y??$}return Y??$}function J0($,Y,X){let Z=2166136261;for(let J of`${$}:${Y}:${X}`)Z^=J.charCodeAt(0),Z=Math.imul(Z,16777619);return`${$}-${(Z>>>0).toString(36)}`}var M8="text";function q8($){return $==="text"||$==="code"||$==="tableCell"}function D8($){return $===M8?void 0:$}function J7($){switch($){case"heading":case"paragraph":return"text";case"code":return"code";default:return null}}function y5($){let Y=[];return $8($,{enterBlock(X){switch(X.type){case"heading":case"paragraph":Y.push({containerKind:"text",containerOrdinal:Y.length,id:X.id,text:X0(X.children)});break;case"code":Y.push({containerKind:"code",containerOrdinal:Y.length,id:X.id,text:X.source});break}},enterTableCell(X){Y.push({containerKind:"tableCell",containerOrdinal:Y.length,id:X.id,text:X0(X.children)})}}),Y}function U8($,Y,X){return{prefix:$.slice(Math.max(0,Y-Z7),Y),suffix:$.slice(X,Math.min($.length,X+Z7))}}function p2($,Y,X){let Z=b0(Y,0,$.text.length),J=b0(X,Z,$.text.length),{prefix:K,suffix:Q}=U8($.text,Z,J);return{kind:D8($.containerKind),prefix:K||void 0,suffix:Q||void 0}}function x2($,Y,X){let Z=b0(Y,0,$.text.length),J=b0(X,Z,$.text.length);return $.text.slice(Z,J)}function a0($,Y){if(Y.length===0)return[];let X=[],Z=0;while(Z<=$.length){let J=$.indexOf(Y,Z);if(J===-1)break;X.push(J),Z=J+Math.max(1,Y.length)}return X}function K2($,Y,X){if(Y.length===0||X.length===0)return[];let Z=[];for(let J of a0($,Y)){let K=J+Y.length,Q=$.indexOf(X,K);if(Q!==-1)Z.push({startOffset:K,endOffset:Q})}return Z}function G8($,Y,X){if(!Y)return!1;return $.slice(Math.max(0,X-Y.length),X)===Y}function V8($,Y,X){if(!Y)return!1;return $.slice(X,X+Y.length)===Y}var Z7=24;function b0($,Y,X){return Math.min(Math.max($,Y),X)}var K7=48,Q7=64,FK=32;function l2($,Y){let X=$.anchor.kind??M8,Z=y5(Y).filter((Q)=>Q.containerKind===X),J=EK($,Z);if(J.length>0)return M7($,J,null);let K=WK($,Z);if(K.length>0)return M7($,K,"repaired");return{match:null,repair:null,status:"stale"}}function EK($,Y){let X=[],Z=$.quote;if(Z.length===0)return X;for(let J of Y)for(let K of a0(J.text,Z))X.push({container:J,endOffset:K+Z.length,score:TK($,J,K),startOffset:K});return X.sort((J,K)=>K.score-J.score),X}function WK($,Y){let X=[];for(let Z of Y)X.push(...PK($,Z));return X.sort((Z,J)=>J.score-Z.score),X}function PK($,Y){let X=[],Z=$.quote.length,J=Y.text,K=$.anchor.prefix??"",Q=$.anchor.suffix??"";if(K.length>0&&Q.length>0){for(let M of K2(J,K,Q))X.push({container:Y,endOffset:M.endOffset,score:N8($,Y,M.startOffset,M.endOffset,Z),startOffset:M.startOffset});return X}if(K.length>0){for(let M of a0(J,K)){let D=M+K.length,q=b0(D+Z,D,J.length);X.push({container:Y,endOffset:q,score:N8($,Y,D,q,Z),startOffset:D})}return X}if(Q.length>0)for(let M of a0(J,Q)){let D=M,q=b0(D-Z,0,D);X.push({container:Y,endOffset:D,score:N8($,Y,q,D,Z),startOffset:q})}return X}function M7($,Y,X){let[Z,J]=Y;if(!Z)return{match:null,repair:null,status:"stale"};if(J&&Z.score===J.score)return{match:null,repair:null,status:"ambiguous"};let K=p2(Z.container,Z.startOffset,Z.endOffset),Q=x2(Z.container,Z.startOffset,Z.endOffset),M=X??(Q===$.quote&&(K.prefix??"")===($.anchor.prefix??"")&&(K.suffix??"")===($.anchor.suffix??"")?"matched":"repaired");return{match:yK(Z.container,Z.startOffset,Z.endOffset),repair:{anchor:K,quote:Q},status:M}}function yK($,Y,X){return{containerId:$.id,containerKind:$.containerKind,containerOrdinal:$.containerOrdinal,endOffset:X,startOffset:Y}}function TK($,Y,X){let Z=0;if(G8(Y.text,$.anchor.prefix,X))Z+=K7;if(V8(Y.text,$.anchor.suffix,X+$.quote.length))Z+=K7;return Z}function N8($,Y,X,Z,J){let K=0;if(G8(Y.text,$.anchor.prefix,X))K+=Q7;if(V8(Y.text,$.anchor.suffix,Z))K+=Q7;if(K+=Math.max(0,FK-Math.abs(J-(Z-X))),$.quote.length>0){let Q=Y.text.slice(X,Z);if(Q.length>0)K+=jK($.quote,Q),K+=wK($.quote,Q)}return K}function jK($,Y){let X=0;while(X<$.length&&X<Y.length&&$[X]===Y[X])X+=1;return X}function wK($,Y){let X=0;while(X<$.length&&X<Y.length&&$[$.length-1-X]===Y[Y.length-1-X])X+=1;return X}function A8($){if(!$||typeof $!=="object"||Array.isArray($))return null;let Y=$,X=BK(Y.anchor),Z=typeof Y.quote==="string"?Y.quote:null,J=Array.isArray(Y.comments)?Y.comments.flatMap((K)=>{let Q=OK(K);return Q?[Q]:[]}):[];if(!X||!Z||J.length===0)return null;return{quote:Z,anchor:X,comments:J,resolvedAt:typeof Y.resolvedAt==="string"?Y.resolvedAt:void 0}}function OK($){if(!$||typeof $!=="object"||Array.isArray($))return null;let Y=$;if(typeof Y.body!=="string"||typeof Y.updatedAt!=="string")return null;return{body:Y.body,updatedAt:Y.updatedAt}}function BK($){if(!$||typeof $!=="object"||Array.isArray($))return null;let{kind:Y,prefix:X,suffix:Z}=$;if("kind"in $&&!q8(Y)||"prefix"in $&&typeof X!=="string"||"suffix"in $&&typeof Z!=="string")return null;return{kind:q8(Y)?D8(Y):void 0,prefix:typeof X==="string"?X:void 0,suffix:typeof Z==="string"?Z:void 0}}function _8($){let Y=$.createdAt??new Date().toISOString();return{comments:[q7({body:$.body,updatedAt:Y})],quote:$.quote,anchor:$.anchor}}function H8($,Y){let X=q7(Y);return{...$,comments:[...$.comments,X]}}function z8($,Y,X,Z=new Date().toISOString()){let J=X.trim();if(J.length===0)return $;let K=!1,Q=$.comments.map((M,D)=>{if(D!==Y||M.body===J)return M;return K=!0,{...M,body:J,updatedAt:Z}});if(!K)return $;return{...$,comments:Q}}function F8($,Y){let X=$.comments.filter((Z,J)=>J!==Y);if(X.length===$.comments.length)return $;if(X.length===0)return null;return{...$,comments:X}}function E8($,Y,X=new Date().toISOString()){if(U1($)===Y)return $;return{...$,resolvedAt:Y?X:void 0}}function U1($){return $.resolvedAt!=null}function W8($){return $.filter((Y)=>U1(Y)).length}function P8($){if($.comments.length===0)return null;return $.comments.reduce((Y,X)=>X.updatedAt>Y?X.updatedAt:Y,$.comments[0].updatedAt)}function q7($){let Y=$.updatedAt??new Date().toISOString();return{body:$.body,updatedAt:Y}}function D7($,Y,X,Z,J){let K=Z-X,Q=J-K;if(Z<=$)return{end:Y+Q,start:$+Q};if(X>=Y)return{end:Y,start:$};let M=Math.max(0,Math.min(X,Y)-$),D=Math.max(0,Y-Math.max(Z,$)),q=$<X?$:X;return{end:q+M+J+D,start:q}}function T8($,Y,X){let Z=X.trim();if(Z.length===0||Y.startOffset===Y.endOffset)return null;let J=$.regionIndex.get(Y.regionId)??null,K=J?y8($,J):null;if(!K)return null;return _8({anchor:p2(K,Y.startOffset,Y.endOffset),body:Z,quote:x2(K,Y.startOffset,Y.endOffset)})}function S0($){let Y="documentIndex"in $?$.documentIndex:$,X=T5(Y),Z=Y.document.comments,J=[...Z],K=[];for(let[Q,M]of Z.entries()){let D=l2(M,Y.document);if(!D.match)continue;let U=X.findBySemanticMatch(D.match.containerId,D.match.containerOrdinal)?.runtimeContainer??null;if(!U)continue;if(D.repair)J[Q]={...M,anchor:D.repair.anchor,quote:D.repair.quote};K.push({endOffset:D.match.endOffset,resolution:D,regionId:U.id,resolved:M.resolvedAt!=null,startOffset:D.match.startOffset,threadIndex:Q})}return{liveRanges:K,threads:J}}function j8($,Y,X,Z,J,K){if($.document.comments.length===0)return Y.document.comments;let Q=$.commentContainerIndex.get(X.semanticRegionId)??[],M=new Set(Q);if(Q.length===0)return Y.document.comments;let D=S0($),q=new Map(D.liveRanges.map((N)=>[N.threadIndex,N])),U=y8($,X),V=Q2(Y,X.path),G=V?y8(Y,V):null;if(!U||!G)return Y.document.comments;return Y.document.comments.map((N,A)=>{if(!M.has(A))return N;let _=q.get(A),z=_?.resolution.match??null;if(!_||!z||z.containerId!==U.id)return N;let F=D7(z.startOffset,z.endOffset,Z,J,K.length);return{...N,anchor:p2(G,F.start,F.end),quote:x2(G,F.start,F.end)}})}function y8($,Y){let X=CK($,Y);if(!X)return null;return{containerKind:X,containerOrdinal:-1,id:Y.semanticRegionId,text:Y.text}}function CK($,Y){if($.tableCellIndex.has(Y.id))return"tableCell";return J7(Y.blockType)}function j5($,Y){if(Y.length===0)return[];let X=T5($),Z=X.list();return Y.map((J)=>({...J,cursorPoint:LK(J,Z,X),viewport:null}))}function LK($,Y,X){if(!$.cursor)return null;let Z=RK(Y,$.cursor),J=bK(Z,$.cursor);if(J.length!==1)return null;let K=J[0],Q=X.resolveRuntimeContainer(K.container.id);if(!Q)return null;return{offset:Math.max(0,Math.min(K.offset,Q.text.length)),regionId:Q.id}}function RK($,Y){return Y.kind?$.filter((X)=>X.containerKind===Y.kind):$}function bK($,Y){if(Y.prefix&&Y.suffix)return SK($,Y.prefix,Y.suffix);if(Y.prefix)return U7($,Y.prefix,"after");if(Y.suffix)return U7($,Y.suffix,"before");return[]}function U7($,Y,X){let Z=[];for(let J of $)for(let K of a0(J.text,Y))Z.push({container:J,offset:X==="after"?K+Y.length:K});return Z}function SK($,Y,X){let Z=[];for(let J of $)for(let K of K2(J.text,Y,X))Z.push({container:J,offset:K.startOffset});return Z}var vK=48;function d2($,Y,X){let Z="documentIndex"in $?$.documentIndex:$;if(X.length===0)return[];return X.map((J)=>({...J,viewport:fK(Z,Y,J)}))}function fK($,Y,X){if(!X.cursorPoint)return{status:"unresolved"};let Z=v0(Y.layout,$,X.cursorPoint),J=Z?{bottom:Z.top+Z.height,top:Z.top}:Y.estimateRegionBounds(X.cursorPoint.regionId);if(!J)return{status:"unresolved"};return{scrollTop:hK(Y,J),status:mK(Y,J)}}function mK($,Y){let X=$.viewport.top,Z=X+$.viewport.height;if(Y.bottom<X)return"above";if(Y.top>Z)return"below";return"visible"}function hK($,Y){let X=Math.max(0,$.totalHeight-$.viewport.height),Z=Y.top-Math.min(vK,$.viewport.height/4);return Math.max(0,Math.min(X,Z))}function T5($){let Y=y5($.document),X=new Map(Y.map((J)=>[J.id,J])),Z=new Map($.regions.map((J)=>[J.semanticRegionId,J]));return{findBySemanticMatch(J,K){let Q=X.get(J)??Y[K]??null;if(!Q)return null;return{runtimeContainer:Z.get(Q.id)??null,semanticContainer:Q}},list(J){return J?Y.filter((K)=>K.containerKind===J):Y},resolveRuntimeContainer(J){return Z.get(J)??null}}}var c2="",G7=1e6;function a2($,Y,X){return`${$}:${Y}:${X}`}function M2($){let Y=XQ($),X=O8(Y.blocks.map((Z,J)=>s2(Z,J)));return B8(Y,X)}function s2($,Y){let X=[],Z=[],J=[],K=new Set,Q=0;function M(q,U,V,G,N=null){if(Z.length>0)J.push(`
|
|
10
|
-
`)
|
|
11
|
-
${
|
|
12
|
-
`)}function
|
|
13
|
-
`});break;case"image":
|
|
14
|
-
`.slice(Y,X);case"image":return c2.slice(Y,X);case"code":return $.code.slice(Y,X);case"link":return L8($.children,Y,X);case"text":return $.text.slice(Y,X);case"raw":return $.source.slice(Y,X)}}function b8($,Y,X,Z){let J=qQ($.children,Y,X,Z);if(J===null)return null;let K=Z0(A7($.children,Y,X,Z,J,`${$.path}.children`));return K.length>0?S1($,K,Y,X):null}function S8($,Y,X){let Z=0,J=null,K=(Q)=>{for(let M of Q){let D=W0(M),q=Z,U=q+D;if(Z=U,X<=q||Y>=U)continue;if(M.type==="text"){let V=Math.max(Y,q);if(Math.min(X,U)>V)J=J===null?new Set(M.marks):new Set(M.marks.filter((N)=>J?.has(N)));continue}if(M.type==="link"){let V=Z;Z=q,K(M.children),Z=V}}};return K($.children),J?[...J]:[]}function qQ($,Y,X,Z){let J=0,K=!1,Q=!0,M=(D)=>{for(let q of D){let U=W0(q),V=J,G=V+U;if(J=G,X<=V||Y>=G)continue;if(q.type==="text"){let N=Math.max(Y,V);if(Math.min(X,G)>N)K=!0,Q&&=q.marks.includes(Z);continue}if(q.type==="link"){let N=J;J=V,M(q.children),J=N}}};return M($),K?Q:null}function A7($,Y,X,Z,J,K){let Q=[],M=0;for(let[D,q]of $.entries()){let U=M,V=W0(q),G=U+V,N=`${K}.${D}`;if(M=G,X<=U||Y>=G){Q.push(q);continue}if(q.type==="text"){Q.push(...DQ(q,Math.max(0,Y-U),Math.min(V,X-U),Z,J,N));continue}if(q.type==="link"){let A=Z0(A7(q.children,Math.max(0,Y-U),Math.min(V,X-U),Z,J,`${N}.children`));if(A.length>0)Q.push({...q,children:A});continue}Q.push(q)}return Q}function DQ($,Y,X,Z,J,K){let Q=$.text.slice(0,Y),M=$.text.slice(Y,X),D=$.text.slice(X),q=J?$.marks.filter((U)=>U!==Z):UQ($.marks,Z);return[b1(Q,$.marks,`${K}.before`),b1(M,q,`${K}.selected`),b1(D,$.marks,`${K}.after`)].filter(Boolean)}function UQ($,Y){return $.includes(Y)?$:[...$,Y].sort()}function v8($,Y,X){let Z=GQ($.children,Y,X,`${$.path}.children`);return Z.length>0?S1($,Z,Y,X):null}function GQ($,Y,X,Z){let J=_7($,Y,X);if(J){let Q=b1(J.code,[],`${Z}.selected`);return i2($,Y,X,Z,Q?[Q]:[])}let K=L8($,Y,X);if(K.length===0)return $;return i2($,Y,X,Z,[R8(K,`${Z}.selected`)])}function _7($,Y,X){let Z=0;for(let J of $){let K=W0(J),Q=Z,M=Q+K;if(Z=M,Y===Q&&X===M&&J.type==="code")return J;if(J.type==="link"){let D=_7(J.children,Math.max(0,Y-Q),Math.min(K,X-Q));if(D)return D}}return null}function B5($,Y,X,Z,J){return C5($,Y,X,Z,(K,Q,M)=>H7(K,Q,M,J))}function H7($,Y,X,Z){let J=Z0(VQ($.children,Y,X,Z,`${$.path}.children`)??[]);return J.length>0?S1($,J,Y,X):null}function VQ($,Y,X,Z,J){let K=[],Q=0,M=!1;for(let[D,q]of $.entries()){let U=`${J}.${D}`,V=W0(q),G=Q,N=G+V;if(Q=N,!M&&q.type==="link"&&Y===G&&X===N){if(Z===null)K.push(...q.children);else K.push($2({children:q.children,path:U,title:q.title,url:Z}));M=!0;continue}K.push(q)}return M?K:null}function D2($,Y){let X=$.regionIndex.get(Y);if(!X)return null;let Z=c0($.document.blocks,X.blockId);if(!Z)return null;return f8(Z,X.path,X.semanticRegionId)}function NQ($,Y,X,Z,J){if(X>=Z)return null;let K=D2($,Y);return K?J(K,X,Z):null}function C5($,Y,X,Z,J){let K=NQ($,Y,X,Z,J);return K?{kind:"replace-block",block:K.block,blockId:K.blockId,selection:K.selection}:null}function f8($,Y,X){if($.type==="heading"||$.type==="paragraph")return{block:$,children:$.children,kind:"inlineBlock",path:Y.replace(/\.children$/,"")};if($.type!=="table")return null;let Z=/^(.*\.rows\.\d+\.cells\.\d+)$/.exec(Y);if(!Z)return null;for(let J of $.rows)for(let K of J.cells)if(K.id===X)return{block:$,blockPath:Z[1].replace(/\.rows\.\d+\.cells\.\d+$/,""),cell:K,children:K.children,kind:"tableCell",path:Z[1]};return null}function m8($,Y,X){let Z=W7($,Y);if(!Z)return null;return{kind:"replace-block",...o2(Z.inlineRegion,Z.startOffset,Z.endOffset,X)}}function F7($,Y,X){let Z=W7($,Y);if(!Z)return null;return{kind:"replace-block",...E7(Z.inlineRegion,Z.startOffset,Z.endOffset,X)}}function E7($,Y,X,Z){let J=`${$.path}.children`,K=i2($.children,Y,X,J,Z),Q=Z.reduce((D,q)=>D+W0(q),0),M=Y+Q;return S1($,K,M,M)}function o2($,Y,X,Z){let J=Z(`${$.path}.children.selected`);return E7($,Y,X,[J])}function W7($,Y){let X=D2($,Y.focus.regionId);if(!X)return null;return{inlineRegion:X,startOffset:Math.min(Y.anchor.offset,Y.focus.offset),endOffset:Math.max(Y.anchor.offset,Y.focus.offset)}}function S1($,Y,X,Z){switch($.kind){case"inlineBlock":return{block:O0($.block,Y),blockId:$.block.id,selection:z7(`${$.path}.children`,X,Z)};case"tableCell":{let J=D1({children:Y,path:$.path}),K=$.block.rows.map((Q)=>({...Q,cells:Q.cells.map((M)=>M.id===$.cell.id?J:M)}));return{block:B0($.block,K),blockId:$.block.id,selection:z7($.path,X,Z)}}}}function z7($,Y,X){return{endOffset:X,kind:"region-range-path",path:$,startOffset:Y}}function H0($,Y,X=0){return{childIndices:Y,kind:"descendant-primary-region",offset:X,rootIndex:$}}function $0($,Y=0){return{kind:"root-primary-region",offset:Y,rootIndex:$}}function h8($,Y=0){return{kind:"region",offset:Y,regionId:$}}function v1($,Y,X,Z=0){return{cellIndex:X,kind:"table-cell",offset:Z,rootIndex:$,rowIndex:Y}}function P0($,Y){return $.regionIndex.get(Y)??null}function Q2($,Y){return $.regionPathIndex.get(Y)??null}function V2($,Y,X,Z){let J=$.tableCellRegionIndex.get(a2(Y,X,Z));return J?$.regionIndex.get(J)??null:null}function f1($,Y){let X=$.regionOrderIndex.get(Y);if(X===void 0||X===0)return null;return $.regions[X-1]??null}function n2($,Y){let X=$.regionOrderIndex.get(Y);if(X===void 0)return null;return $.regions[X+1]??null}function r0($){return $.regionIds.length===0&&!G1($)}function G1($){return $.type==="blockquote"||$.type==="list"||$.type==="listItem"}function k8($,Y){return y7($.blocks,Y,-1)}function t2($,Y){return y7($.blocks,Y,1)}function y7($,Y,X){let Z=$.findIndex((J)=>J.id===Y);if(Z===-1)return null;for(let J=Z+X;J>=0&&J<$.length;J+=X){let K=$[J];if(G1(K))continue;return K}return null}function u8($,Y){return $.roots[Y]?.regions[0]??null}function AQ($){return $.anchor.regionId===$.focus.regionId&&$.anchor.offset===$.focus.offset}function Y0($,Y){let X="documentIndex"in $?$.documentIndex:$,Z="documentIndex"in $?$.selection:Y,J=AQ(Z),K=P7(X,Z.anchor),Q=P7(X,Z.focus);if(K<=Q)return{collapsed:J,end:Z.focus,start:Z.anchor};return{collapsed:J,end:Z.anchor,start:Z.focus}}function e2($,Y){if(!Y)return null;if(Y.kind==="root-primary-region"){let Z=$.document.blocks[Y.rootIndex],J=Z?L5($,Z):null;return J?U2(J.id,G2(J.text,Y.offset)):null}if(Y.kind==="descendant-primary-region"){let Z=$.document.blocks[Y.rootIndex],J=Z?_Q(Z,Y.childIndices):null,K=J?L5($,J):null;return K?U2(K.id,G2(K.text,Y.offset)):null}if(Y.kind==="region"){let Z=P0($,Y.regionId);return Z?U2(Z.id,G2(Z.text,Y.offset)):null}if(Y.kind==="block-primary-region"){let Z=c0($.document,Y.blockId),J=Z?L5($,Z):null;return J?U2(J.id,G2(J.text,Y.offset)):null}if(Y.kind==="table-cell"){let Z=$.document.blocks[Y.rootIndex];if(!Z||Z.type!=="table")return null;let J=V2($,Z.id,Y.rowIndex,Y.cellIndex);return J?U2(J.id,G2(J.text,Y.offset)):null}let X=Q2($,Y.path);if(!X)return null;if(Y.kind==="region-path")return U2(X.id,G2(X.text,Y.offset));return{anchor:{regionId:X.id,offset:Math.max(0,Math.min(Y.startOffset,X.text.length))},focus:{regionId:X.id,offset:Math.max(0,Math.min(Y.endOffset,X.text.length))}}}function U2($,Y){let X={offset:Y,regionId:$};return{anchor:X,focus:X}}function P7($,Y){let X=$.regionOrderIndex.get(Y.regionId);if(X===void 0)throw Error(`Unknown canvas region: ${Y.regionId}`);return X*G7+Y.offset}function G2($,Y){return Y==="end"?$.length:Math.max(0,Math.min(Y,$.length))}function _Q($,Y){let X=$;for(let Z of Y){if(!X)return null;let J=_0(X);if(!J)return null;X=J[Z]??null}return X}function L5($,Y){let X=$.blockIndex.get(Y.id);if(!X)return null;let Z=X.regionIds[0];if(Z)return $.regionIndex.get(Z)??null;let J=_0(Y);if(!J)return null;for(let K of J){let Q=L5($,K);if(Q)return Q}return null}function $4($){let Y=$.documentIndex.regionIndex.get($.selection.anchor.regionId)??null,X=Y?$.documentIndex.blockIndex.get(Y.blockId)??null:null,Z=T7($);return{block:X?{blockId:X.id,depth:X.depth,nodeType:X.type,text:Y?.text??""}:null,span:Z?.link?{kind:"link",url:Z.link.url}:Z&&Z.marks.length>0?{kind:"marks",marks:Z.marks}:{kind:"none"}}}function R5($){let Y=T7($);return Y?.kind==="image"?Y:null}function b5($){let Y=Y0($.documentIndex,$.selection);if(Y.start.regionId!==Y.end.regionId||Y.start.offset===Y.end.offset)return[];let X=$.documentIndex.regionIndex.get(Y.start.regionId);if(!X)return[];let Z=c0($.documentIndex.document.blocks,X.blockId);if(!Z)return[];let J=f8(Z,X.path,X.semanticRegionId);return J?S8(J,Y.start.offset,Y.end.offset):[]}function T7($){let Y=$.documentIndex.regionIndex.get($.selection.anchor.regionId)??null;if(!Y)return null;let X=$.selection.anchor.offset;return Y.inlines.find((Z)=>X>Z.start&&X<Z.end)??Y.inlines.find((Z)=>Z.end===X)??Y.inlines.find((Z)=>Z.start===X)??null}var v5="rgba(0, 0, 0, 0)";function N2($,Y,X){let Z=j7($),J=j7(Y);return`rgba(${I8(S5(Z[0],J[0],X))}, ${I8(S5(Z[1],J[1],X))}, ${I8(S5(Z[2],J[2],X))}, ${S5(Z[3],J[3],X)})`}var g8=new Map([["rgba(0, 0, 0, 0)",[0,0,0,0]]]);function j7($){let Y=g8.get($);if(Y)return Y;let X=HQ($)??zQ($)??FQ($)??g8.get("rgba(0, 0, 0, 0)");return g8.set($,X),X}function HQ($){let Y=$.trim();if(!Y.startsWith("#"))return null;let X=Y.slice(1);if(X.length===3)return[Number.parseInt(`${X[0]}${X[0]}`,16),Number.parseInt(`${X[1]}${X[1]}`,16),Number.parseInt(`${X[2]}${X[2]}`,16),1];if(X.length===6)return[Number.parseInt(X.slice(0,2),16),Number.parseInt(X.slice(2,4),16),Number.parseInt(X.slice(4,6),16),1];return null}function zQ($){let Y=/^rgb\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec($.trim());if(!Y)return null;return[Number(Y[1]),Number(Y[2]),Number(Y[3]),1]}function FQ($){let Y=/^rgba\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec($.trim());if(!Y)return null;return[Number(Y[1]),Number(Y[2]),Number(Y[3]),Number(Y[4])]}function S5($,Y,X){return $+(Y-$)*X}function I8($){return Math.round($)}var EQ=300,WQ=180,PQ=1000,yQ=500,TQ=140,jQ=0.1,wQ=0.9,OQ=2,BQ=2;function Y4($){switch($.kind){case"active-block-flash":return EQ;case"deleted-text-fade":return WQ;case"inserted-text-highlight":return PQ;case"list-marker-pop":return yQ;case"punctuation-pulse":return TQ}}function p8($,Y){let X=Y??LQ();return $.animations.some((Z)=>X-Z.startedAt<Y4(Z))}function w7($,Y){return x8($,Y,"inserted-text-highlight",(X)=>X.regionPath)}function O7($,Y){return h7($,Y,"active-block-flash",(X)=>X.blockPath)}function B7($,Y){return x8($,Y,"deleted-text-fade",(X)=>X.regionPath)}function C7($,Y){return x8($,Y,"punctuation-pulse",(X)=>X.regionPath)}function L7($,Y){return h7($,Y,"list-marker-pop",(X)=>X.blockPath)}function R7($,Y,X){let Z=new Set([$,Y]);for(let J of X){if(J.endOffset<=$||J.startOffset>=Y)continue;Z.add(Math.max($,J.startOffset)),Z.add(Math.min(Y,J.endOffset))}return[...Z].sort((J,K)=>J-K)}function b7($,Y,X){return $.find((Z)=>Z.startOffset<X&&Z.endOffset>Y)??null}function S7($,Y,X){if(!Y)return $;return N2(X.insertHighlightText,$,Y.progress)}function v7($,Y){return N2($,v5,Y.progress)}function f5($,Y){return N2($,v5,Y.progress)}function f7($,Y){return N2(Y.insertHighlightText,v5,$.progress)}function m7($){let Y=Math.min(1,$.progress*OQ);return jQ+wQ*CQ(Y)}function X4($,Y,X){let Z=Math.max(0,Y.progress*BQ-1);return N2(X.insertHighlightText,$,Z)}function x8($,Y,X,Z){let J=new Map;for(let K of $.animations){if(K.kind!==X)continue;let Q=Y4(K),M=Y-K.startedAt;if(M>=Q)continue;let D={...K,progress:Math.max(0,Math.min(1,M/Q))},q=Z(K),U=J.get(q);if(U)U.push(D);else J.set(q,[D])}return J}function h7($,Y,X,Z){let J=new Map;for(let K of $.animations){if(K.kind!==X)continue;let Q=Y4(K),M=Y-K.startedAt;if(M>=Q)continue;J.set(Z(K),{...K,progress:Math.max(0,Math.min(1,M/Q))})}return J}function CQ($){return 1-(1-$)*(1-$)*(1-$)}function LQ(){return typeof performance<"u"?performance.now():Date.now()}function m5($,Y,X=m1()){if(Y<=0)return $;let Z=k5($);if(!Z)return $;let J=$.selection.focus.offset,K=Math.max(0,J-Y);if(J<=K)return $;return Z4($,{endOffset:J,kind:"inserted-text-highlight",regionPath:Z.path,startOffset:K,startedAt:X})}function k7($,Y,X,Z){let J=k5($);if(!J)return Y;let K=J.text.slice(X,Z);if(K.length===0)return Y;if(!J.inlines.some((M)=>M.start<=X&&M.end>=Z&&M.kind==="text"&&M.link===null&&M.marks.length===0))return Y;return Z4(Y,{kind:"deleted-text-fade",regionPath:J.path,startOffset:X,startedAt:m1(),text:K})}function u7($,Y=m1()){let X=k5($),Z=$.selection.focus.offset-1;if(!X||Z<0||X.text[Z]!==".")return $;return Z4($,{kind:"punctuation-pulse",offset:Z,regionPath:X.path,startedAt:Y})}function g7($,Y,X=m1()){return Z4($,{blockPath:Y,kind:"list-marker-pop",startedAt:X})}function I7($,Y,X=m1()){return Z4($,{blockPath:Y,kind:"active-block-flash",startedAt:X})}function l8($,Y){return $.filter((X)=>X.startedAt+Y4(X)>Y)}function m1(){return typeof performance<"u"?performance.now():Date.now()}function h5($,Y){let X=Math.max(-1/0,...$.animations.map((Z)=>Z.startedAt));return Y.animations.some((Z)=>Z.startedAt>X)}function p7($){let Y=k5($);return(Y?$.documentIndex.blockIndex.get(Y.blockId)??null:null)?.path??""}function k5($){return $.documentIndex.regionIndex.get($.selection.focus.regionId)??null}function Z4($,Y){let X=l8($.animations,Y.startedAt);return{...$,animations:[...X,Y]}}function A2($,Y,X,Z){return c8(_2($.inlines,Y,X,Z))}function _2($,Y,X,Z){let K=RQ($,Y,X,{didInsert:!1,generatedRunCount:0,replacementText:Z});return mQ(hQ(K))}function c8($){let Y=[];for(let X=0;X<$.length;X+=1){let Z=$[X];if(Z.link){let K=[],Q=Z.link;while(X<$.length&&a8($[X].link,Q)){let M=l7($[X]);if(M)K.push(M);X+=1}if(X-=1,K.length>0)Y.push($2({children:Z0(K),title:Q.title,url:Q.url}));continue}let J=l7(Z);if(J)Y.push(J)}return Z0(Y)}function RQ($,Y,X,Z){let J=[];for(let[K,Q]of $.entries()){if(!Z.didInsert&&Y===X&&Y===Q.start)d8(J,Z,x7($[K-1]??null,Q));if(X<=Q.start||Y>=Q.end){J.push(u5(Q));continue}let M=Math.max(0,Y-Q.start),D=Math.min(Q.text.length,X-Q.start),q=!Z.didInsert&&Z.replacementText.length>0?Z.replacementText:"",U=bQ(Q,M,D,q,Z);if(M!==D||q.length>0)Z.didInsert=!0;J.push(...U)}if(!Z.didInsert)d8(J,Z,x7($.at(-1)??null,null));return J}function bQ($,Y,X,Z,J){switch($.kind){case"text":case"code":case"raw":return SQ($,Y,X,Z);case"lineBreak":return vQ($,Y,X,Z,J);case"image":return fQ($,Y,X,Z)}}function SQ($,Y,X,Z){let J=$.text.slice(0,Y)+Z+$.text.slice(X);return J.length>0?[{...u5($),text:J}]:[]}function vQ($,Y,X,Z,J){if(Y===X)return[u5($)];let K=[];if(Z.length>0)d8(K,J,$.link);return K}function fQ($,Y,X,Z){if(Y===0&&X===$.text.length)return Z.length>0?[d7(Z,$.link,0)]:[];return[u5($)]}function d8($,Y,X){if(Y.replacementText.length===0){Y.didInsert=!0;return}$.push(d7(Y.replacementText,X,Y.generatedRunCount)),Y.generatedRunCount+=1,Y.didInsert=!0}function d7($,Y,X){return{id:`generated:${X}`,image:null,inlineCode:!1,kind:"text",link:Y,marks:[],originalType:null,text:$}}function x7($,Y){return $?.link&&Y?.link&&a8($.link,Y.link)?$.link:null}function u5($){return{id:$.id,image:$.image,inlineCode:$.inlineCode,kind:$.kind,link:$.link,marks:$.marks,originalType:$.originalType,text:$.text}}function mQ($){let Y=[],X=0;for(let Z of $){let J=X,K=J+Z.text.length;Y.push({...Z,end:K,start:J}),X=K}return Y}function hQ($){let Y=[];for(let X of $){let Z=Y.at(-1);if(Z&&kQ(Z,X)){Y[Y.length-1]={...Z,text:Z.text+X.text};continue}Y.push(X)}return Y}function kQ($,Y){return $.kind===Y.kind&&$.inlineCode===Y.inlineCode&&a8($.link,Y.link)&&gQ($.image,Y.image)&&$.originalType===Y.originalType&&$.marks.join(",")===Y.marks.join(",")}function l7($){switch($.kind){case"lineBreak":return l0();case"image":return $.image?uQ($.image):null;case"code":return e1({code:$.text});case"text":return $.text.length>0?q1({marks:$.marks,text:$.text}):null;case"raw":return z5({originalType:$.originalType??"raw",source:$.text})}}function uQ($){return j1({alt:$.alt,title:$.title,url:$.url,width:$.width})}function a8($,Y){return $?.url===Y?.url&&$?.title===Y?.title}function gQ($,Y){return $?.url===Y?.url&&$?.title===Y?.title&&$?.alt===Y?.alt&&$?.width===Y?.width}function s7($,Y,X){let Z=[],J=0,K={childIndices:[],offset:0},Q="",M=$!==null;if($)Z.push($),K=c7($);let D=0;if($&&Y.length>0){let q=Y[0];if(g5($)&&q.type==="paragraph"){let U=r8($,$.children,q.children);Z[Z.length-1]=U,K={childIndices:[],offset:U.plainText.length},D=1,Q=q.plainText}else if(a7($,q)){let U=r7($,q);Z[Z.length-1]=U,K=i7(U),D=1}}for(let q=D;q<Y.length;q+=1){let U=Y[q];Z.push(U),J=Z.length-1,K=c7(U)}if(X){let q=Z.length-1,U=Z[q]??null,V=D>=Y.length&&$!==null,G=null;if(U){if(!V&&U.type==="paragraph"&&g5(X)){if(G=r8(X,U.children,X.children),$===null&&Y.length===1)M=!0,Q=U.plainText}else if(V&&g5(U)&&g5(X))G=r8(U,U.children,X.children);else if(a7(U,X))G=r7(U,X),K={childIndices:[_0(U).length-1],offset:"end"}}else if($===null&&Y.length===0)M=!0;if(G)Z[q]=G;else Z.push(X)}return{blocks:Z,caretLocalIndex:J,caretChildIndices:K.childIndices,caretOffset:K.offset,startRegionInsertedText:Q,startRegionPreservedAtRoot0:M}}function J4($,Y,X){if($.type==="table")return null;if($.id===Y.blockId)return IQ($,Y,X);return o7($,(Z)=>xQ(Z,Y,X))}function K4($,Y,X){if($.type==="table")return null;if($.id===Y.blockId)return pQ($,Y,X);return o7($,(Z)=>lQ(Z,Y,X))}function h1($,Y){if($.id===Y.blockId)return!0;let X=_0($);return X!==null&&X.some((Z)=>h1(Z,Y))}function c7($){return _0($)?i7($):{childIndices:[],offset:$.plainText.length}}function i7($){return{childIndices:[_0($).length-1],offset:"end"}}function r8($,Y,X){return O0($,Z0([...Y,...X]))}function g5($){return $!==null&&($.type==="heading"||$.type==="paragraph")}function a7($,Y){return $.type===Y.type&&_0($)!==null}function r7($,Y){let X=_0($),Z=_0(Y);return R1($,[...X,...Z])}function IQ($,Y,X){if(X===0)return null;switch($.type){case"heading":case"paragraph":return O0($,A2(Y,X,Y.text.length,""));case"code":return g2($,Y.text.slice(0,X));case"raw":return I2($,Y.text.slice(0,X));default:return null}}function pQ($,Y,X){if(X===Y.text.length)return null;switch($.type){case"heading":case"paragraph":return O0($,A2(Y,0,X,""));case"code":return g2($,Y.text.slice(X));case"raw":return I2($,Y.text.slice(X));default:return null}}function o7($,Y){let X=_0($);return X?R1($,Y(X)):null}function xQ($,Y,X){let Z=$.findIndex((Q)=>h1(Q,Y));if(Z===-1)return[];let J=$.slice(0,Z),K=J4($[Z],Y,X);return K?[...J,K]:J}function lQ($,Y,X){let Z=$.findIndex((Q)=>h1(Q,Y));if(Z===-1)return[];let J=$.slice(Z+1),K=K4($[Z],Y,X);return K?[K,...J]:J}function t7($,Y,X){let Z=Y0($,Y);if(Z.start.regionId===Z.end.regionId)return dQ($,Z,X);let J=X.length>0?[i({text:X})]:[];return s8($,Y,J)}function s8($,Y,X){let Z=Y0($,Y),J=P0($,Z.start.regionId),K=P0($,Z.end.regionId);if(!J||!K)throw Error("Unknown selection endpoints.");let Q=$.document.blocks[J.rootIndex],M=$.document.blocks[K.rootIndex];if(!Q||!M)throw Error("Unknown root blocks for selection.");let D=J4(Q,J,Z.start.offset),q=K4(M,K,Z.end.offset),U=s7(D,X,q),V=U.blocks.length>0?U.blocks:[i({text:""})],G=J.rootIndex,N=K.rootIndex-J.rootIndex+1,A=L1($.document,G,N,V),_=q2($,A,G,N),z=J===K?Z.end.offset:J.text.length;return{documentIndex:U.startRegionPreservedAtRoot0?e7($,_,J,Z.start.offset,z,U.startRegionInsertedText):_,selection:H0(G+U.caretLocalIndex,U.caretChildIndices,U.caretOffset)}}function dQ($,Y,X){let Z=P0($,Y.start.regionId);if(!Z)throw Error(`Unknown region: ${Y.start.regionId}`);let J=O5($,Z.blockId,(D)=>cQ(D,Z,Y.start.offset,Y.end.offset,X));if(!J)throw Error(`Failed to replace block for region: ${Z.id}`);let K=q2($,J,Z.rootIndex,1),Q=e7($,K,Z,Y.start.offset,Y.end.offset,X),M=Q2(Q,Z.path);if(!M)throw Error(`Failed to remap region after replacement: ${Z.path}`);return{documentIndex:Q,selection:h8(M.id,Y.start.offset+X.length)}}function cQ($,Y,X,Z,J){switch($.type){case"heading":case"paragraph":return O0($,A2(Y,X,Z,J));case"code":return g2($,n7(Y,X,Z,J));case"table":return aQ($,Y,X,Z,J);case"raw":return I2($,n7(Y,X,Z,J));default:throw Error(`Region text replacement is not supported for block type: ${$.type}`)}}function aQ($,Y,X,Z,J){let K=Y.tableCellPosition?.rowIndex,Q=Y.tableCellPosition?.cellIndex;if(K===void 0||Q===void 0)throw Error(`Unable to resolve table cell position for region: ${Y.id}`);let M=A2(Y,X,Z,J),D=$.rows.map((q,U)=>{if(U!==K)return q;let V=q.cells.map((G,N)=>N===Q?D1({children:M}):G);return{...q,cells:V}});return B0($,D)}function n7($,Y,X,Z){return _2($.inlines,Y,X,Z).map((J)=>J.text).join("")}function e7($,Y,X,Z,J,K){if($.document.comments.length===0)return Y;let Q=j8($,Y,X,Z,J,K);return Q===Y.document.comments?Y:w5(Y,{...Y.document,comments:Q})}function M4($){let Y=M2($),X=Z$(Y);return{animations:[],documentIndex:Y,future:[],history:[],selection:{anchor:X,focus:X}}}function s0($){let Y=S0($.documentIndex);return J2(X7($.documentIndex.document.blocks),Y.threads,$.documentIndex.document.frontMatter)}function f0($,Y){if(!Y)return null;switch(Y.kind){case"keep-state":return $;case"set-selection":return K0($,Y.selection);case"replace-block":{let X=O5($.documentIndex,Y.blockId,()=>Y.block);return X?Q4($,M2(X),Y.selection??null):null}case"splice-blocks":{let X=L1($.documentIndex.document,Y.rootIndex,Y.count??1,Y.blocks);return Q4($,M2(X),Y.selection??null)}case"splice-text":{let X=t7($.documentIndex,Y.selection,Y.text);return Q4($,X.documentIndex,X.selection)}case"splice-fragment":{let X=s8($.documentIndex,Y.selection,Y.blocks);return Q4($,X.documentIndex,X.selection)}case"splice-comments":{let X=t9($.documentIndex.document,Y.index,Y.count,Y.threads);return Q4($,w5($.documentIndex,X),null)}}}function Q4($,Y,X){let Z=rQ($,Y),J=e2(Z.documentIndex,X)??$.selection,K=J$($,Z,J);return K0(Z,J,K)}function K0($,Y,X){let Z="regionId"in Y?{anchor:I5($.documentIndex,Y),focus:I5($.documentIndex,Y)}:{anchor:I5($.documentIndex,Y.anchor),focus:I5($.documentIndex,Y.focus)},J={...$,selection:Z};return X??J$($,J)?I7(J,p7(J)):J}function y0($,Y,X,Z){let J={regionId:Y,offset:X};return K0($,Z?{anchor:$.selection.anchor,focus:J}:J)}function rQ($,Y){let X=Z$(Y);return{animations:l8($.animations,m1()),documentIndex:Y,future:[],history:[...$.history,{document:$.documentIndex.document,selection:$.selection}],selection:{anchor:X,focus:X}}}function i8($){let Y=$.history.at(-1);if(!Y)return $;return X$(Y,{future:[Y$($),...$.future],history:$.history.slice(0,-1)})}function o8($){let Y=$.future[0];if(!Y)return $;return X$(Y,{future:$.future.slice(1),history:[...$.history,Y$($)]})}function Y$($){return{document:$.documentIndex.document,selection:$.selection}}function X$($,Y){return{animations:[],documentIndex:M2($.document),future:Y.future,history:Y.history,selection:$.selection}}function Z$($){return $.regions[0]?{regionId:$.regions[0].id,offset:0}:{regionId:"empty",offset:0}}function I5($,Y){let X=P0($,Y.regionId);if(!X)return Y;return{regionId:X.id,offset:Math.max(0,Math.min(Y.offset,X.text.length))}}function J$($,Y,X){let Z=$$($.documentIndex,$.selection),J=$$(Y.documentIndex,X??Y.selection);return J!==null&&J!==Z}function $$($,Y){let X=$.regionIndex.get(Y.focus.regionId),Z=X?$.blockIndex.get(X.blockId)??null:null;if(!X||!Z?.path)return null;return Z.type==="table"?`cell:${X.path}`:`block:${Z.path}`}function U4($,Y){let X=$.regionIndex.get(Y.anchor.regionId);if(!X)return{kind:"unsupported"};if(X.blockType==="code"){let M=$.blockIndex.get(X.blockId);return M?{kind:"code",region:X,rootIndex:M.rootIndex,...D4($,X,Y)}:{kind:"unsupported"}}let Z=t8($,X.id);if(Z)return{kind:"tableCell",...Z,...D4($,X,Y)};let J=z2($,Y);if(J)return{kind:"listItem",...J};let K=sQ($,Y);if(K)return{kind:"blockquoteTextBlock",...K};let Q=H2($,Y);if(Q)return{kind:"rootTextBlock",...Q};return{kind:"unsupported"}}function K$($,Y,X){let Z=U4($,Y),J=Z.kind==="unsupported"?!1:X==="backward"?Z.atStart:Z.atEnd;switch(Z.kind){case"rootTextBlock":return{...Z,kind:"rootTextBlock",direction:X,atBoundary:J,previousRoot:$.document.blocks[Z.rootIndex-1]??null,nextRoot:$.document.blocks[Z.rootIndex+1]??null};case"listItem":return{...Z,kind:"listItem",direction:X,atBoundary:J,previousItem:Z.list.items[Z.itemIndex-1]??null,nextItem:Z.list.items[Z.itemIndex+1]??null,previousRoot:$.document.blocks[Z.rootIndex-1]??null,nextRoot:$.document.blocks[Z.rootIndex+1]??null};case"blockquoteTextBlock":return{...Z,kind:"blockquoteTextBlock",direction:X,atBoundary:J,previousSibling:Z.quote.children[Z.childIndex-1]??null,nextSibling:Z.quote.children[Z.childIndex+1]??null};default:return{kind:"unsupported",direction:X,atBoundary:!1}}}function n8($,Y,X){let Z=Y?$.blockIndex.get(Y)??null:null;while(Z){if(Z.type===X)return Z;let J=Z.parentBlockId;Z=J?$.blockIndex.get(J)??null:null}return null}function V1($){let Y=$.split("."),X=[];for(let Z=0;Z<Y.length-1;Z+=1)if(Y[Z]==="children"){let J=Number(Y[Z+1]);if(Number.isInteger(J))X.push(J)}return X}function H2($,Y){let X=$.regionIndex.get(Y.anchor.regionId);if(!X)return null;let Z=$.blockIndex.get(X.blockId);if(!Z)return null;let J=Z.rootIndex,K=$.document.blocks[J];if(!K||K.type!=="heading"&&K.type!=="paragraph")return null;return{...D4($,X,Y),block:K,region:X,rootIndex:J}}function sQ($,Y){let X=$.regionIndex.get(Y.anchor.regionId);if(!X)return null;let Z=$.blockIndex.get(X.blockId),J=n8($,Z?.id??null,"blockquote");if(!Z||!J||Z.parentBlockId!==J.id)return null;let K=J.rootIndex,Q=$.document.blocks[K];if(!Q||Q.type!=="blockquote")return null;let M=Q.children.findIndex((q)=>q.id===Z.id),D=Q.children[M];if(!D||D.type!=="heading"&&D.type!=="paragraph")return null;return{...D4($,X,Y),block:D,blockChildIndices:V1(Z.path),childIndex:M,region:X,quote:Q,rootIndex:K}}function q4($,Y){return c0($.document.blocks,Y)}function z2($,Y){let X=$.regionIndex.get(Y.anchor.regionId);if(!X)return null;let Z=$.blockIndex.get(X.blockId),J=n8($,Z?.id??null,"listItem"),K=n8($,Z?.id??null,"list");if(!Z||!J||!K)return null;let Q=q4($,K.id);if(!Q||Q.type!=="list")return null;let M=Q.items.findIndex((A)=>A.id===J.id),D=Q.items[M];if(!D)return null;let q=K.parentBlockId?$.blockIndex.get(K.parentBlockId)??null:null,U=q?.parentBlockId?$.blockIndex.get(q.parentBlockId)??null:null,V=q?.type==="listItem"?q4($,q.id):null,G=U?.type==="list"?q4($,U.id):null,N=G?.type==="list"&&V?G.items.findIndex((A)=>A.id===V.id):-1;return{...D4($,X,Y),region:X,item:D,itemChildIndices:V1(J.path),itemIndex:M,list:Q,listChildIndices:V1(K.path),parentItem:V?.type==="listItem"?V:null,parentItemChildIndices:q?.type==="listItem"?V1(q.path):null,parentItemIndex:N>=0?N:null,parentList:G?.type==="list"?G:null,parentListChildIndices:U?.type==="list"?V1(U.path):null,rootIndex:K.rootIndex}}function t8($,Y){let X=$.regionIndex.get(Y);if(!X)return null;let Z=$.tableCellIndex.get(X.id),J=$.blockIndex.get(X.blockId),K=J?.type==="table"?$.document.blocks[J.rootIndex]:null;if(!Z||!J||!K||K.type!=="table")return null;return{cellIndex:Z.cellIndex,region:X,rootIndex:J.rootIndex,rowIndex:Z.rowIndex,table:K}}function D4($,Y,X){let Z=Y0($,X),J=Z.start.regionId===Y.id?Z.start.offset:X.anchor.offset;return{atEnd:J===Y.text.length,atStart:J===0,empty:Y.text.length===0,offset:J}}function G4($,Y,X){return w1({checked:Y,children:[i({text:$})],spread:X})}function Q$($,Y){let X=$.children[0];if(!X||X.type!=="paragraph")return null;return d0($,[i({text:Y}),...$.children.slice(1)])}function M$($,Y){return Y.reduce((X,Z)=>`${X}.children.${Z}`,`root.${$}`)}function q$($,Y){if($.selection.anchor.regionId!==$.selection.focus.regionId||$.selection.anchor.offset!==$.selection.focus.offset)return null;let X=P0($.documentIndex,$.selection.focus.regionId);if(!X)return null;if(Y==="forward"&&$.selection.focus.offset>=X.text.length)return null;let Z=Y==="backward"?iQ(X.text,$.selection.focus.offset):$.selection.focus.offset,J=Y==="backward"?$.selection.focus.offset:oQ(X.text,$.selection.focus.offset);if(Z===J)return null;return{kind:"splice-text",selection:{anchor:{regionId:X.id,offset:Z},focus:{regionId:X.id,offset:J}},text:""}}function iQ($,Y){let X=Array.from($.slice(0,Y));if(X.length===0)return 0;return Y-X.at(-1).length}function oQ($,Y){let X=Array.from($.slice(Y))[0];return X?Y+X.length:$.length}function D$($,Y,X){if(Y.anchor.regionId!==Y.focus.regionId)return null;let Z=$.regionIndex.get(Y.anchor.regionId);if(!Z)return null;let J=tQ($,Y,Z);if(!J)return null;let{start:K,end:Q}=nQ($,Y);return eQ(Z,X,K,Q,J)}function nQ($,Y){if(Y.anchor.offset===Y.focus.offset)return{start:Y.anchor.offset,end:Y.anchor.offset};let X=Y0($,Y);return{start:X.start.offset,end:X.end.offset}}function tQ($,Y,X){switch(X.blockType){case"heading":{let Z=H2($,Y);return Z?.block.type==="heading"?{kind:"heading",rootIndex:Z.rootIndex}:null}case"paragraph":{let Z=z2($,Y);if(Z)return{kind:"list-item",item:Z};let J=H2($,Y);return J?.block.type==="paragraph"?{kind:"root-paragraph",rootIndex:J.rootIndex}:null}default:return null}}function eQ($,Y,X,Z,J){if(J.kind==="root-paragraph"&&!$M($,Y,Z))return null;let K=$.text.slice(0,X)+Y+$.text.slice(Z);switch(J.kind){case"root-paragraph":return e8(YM,K,J);case"heading":return e8(XM,K,J);case"list-item":return e8(ZM,K,J.item)}}function $M($,Y,X){let Z=X<$.text.length?$.text:Y;return Z.length>0&&/\s/.test(Z[Z.length-1])}function e8($,Y,X){for(let{pattern:Z,apply:J}of $){let K=Z.exec(Y);if(K)return J(K,X)}return null}var YM=[{pattern:F2(/\[[ xX]?\]/,{allowIndent:!0}),apply:($,{rootIndex:Y})=>$3(Y,{checked:$[1].toLowerCase().includes("x"),ordered:!1,start:null})},{pattern:F2(/[-+*]/,{allowIndent:!0}),apply:($,{rootIndex:Y})=>$3(Y,{checked:null,ordered:!1,start:null})},{pattern:F2(/\d+\./,{allowIndent:!0}),apply:($,{rootIndex:Y})=>$3(Y,{checked:null,ordered:!0,start:Number($[1].slice(0,-1))})},{pattern:F2(/#{1,6}/,{allowIndent:!1}),apply:($,{rootIndex:Y})=>({kind:"splice-blocks",blocks:[t1({depth:$[1].length,text:""})],rootIndex:Y,selection:$0(Y)})},{pattern:F2(/>/,{allowIndent:!1}),apply:($,{rootIndex:Y})=>({kind:"splice-blocks",blocks:[R0({children:[i({text:""})]})],rootIndex:Y,selection:H0(Y,[0])})},{pattern:F2(/---/,{allowIndent:!1}),apply:($,{rootIndex:Y})=>({kind:"splice-blocks",blocks:[F5(),i({text:""})],rootIndex:Y,selection:$0(Y+1)})}],XM=[{pattern:p5(/#{1,6}/),apply:($,{rootIndex:Y})=>({kind:"splice-blocks",blocks:[t1({depth:$[1].length,text:$[2]})],rootIndex:Y,selection:$0(Y)})}],ZM=[{pattern:p5(/\d+\./),apply:($,Y)=>Y3($,Y,{ordered:!0,start:1,checked:Y.item.checked})},{pattern:p5(/\[[ xX]?\]/),apply:($,Y)=>Y3($,Y,{ordered:!1,start:null,checked:$[1].toLowerCase().includes("x")})},{pattern:p5(/[-+*]/),apply:($,Y)=>Y3($,Y,{ordered:!1,start:null,checked:null})}];function F2($,Y){let X=Y.allowIndent?"\\s*":"";return new RegExp(`^${X}(${$.source})\\s$`)}function p5($){return new RegExp(`^\\s*(${$.source})\\s(.+)$`)}function $3($,Y){return{kind:"splice-blocks",blocks:[O1({items:[w1({checked:Y.checked,children:[i({text:""})],spread:!1})],ordered:Y.ordered,spread:!1,start:Y.start})],rootIndex:$,selection:H0($,[0,0])}}function Y3($,Y,X){let Z=Q$(Y.item,$[2]);if(!Z)return null;return{kind:"replace-block",block:M0(Y.list,Y.list.items.map((J,K)=>K===Y.itemIndex?{...Z,checked:X.checked}:J),{ordered:X.ordered,start:X.start}),blockId:Y.list.id,selection:H0(Y.rootIndex,[...Y.listChildIndices,Y.itemIndex,0])}}function U$($,Y,X){return D$($,Y,X)??{kind:"splice-text",selection:Y,text:X}}function G$($,Y){let X=$.region.text.length,Z=$.region.text.slice(0,Y),J=$.region.text.slice(Y),K=Y===0&&X>0?$.rootIndex:$.rootIndex+1;return{kind:"splice-blocks",blocks:A$($.block,Z,J,Y,X),rootIndex:$.rootIndex,selection:$0(K)}}function V$($,Y){let X=$.region.text,Z=X.slice(0,Y),J=X.slice(Y),K=A$($.block,Z,J,Y,X.length),Q=Y===0?$.blockChildIndices:[...$.blockChildIndices.slice(0,-1),$.blockChildIndices.at(-1)+1];return{kind:"splice-blocks",blocks:[R0({children:[...$.quote.children.slice(0,$.childIndex),...K,...$.quote.children.slice($.childIndex+1)]})],rootIndex:$.rootIndex,selection:H0($.rootIndex,Q)}}function N$($,Y){if(Y!==0||$.region.text.length!==0||$.block.type!=="paragraph")return null;let X=$.quote.children.slice(0,$.childIndex),Z=$.quote.children.slice($.childIndex+1),J=[];if(X.length>0)J.push(R0({children:X}));if(J.push(i({text:""})),Z.length>0)J.push(R0({children:Z}));return{kind:"splice-blocks",blocks:J,rootIndex:$.rootIndex,selection:$0($.rootIndex+(X.length>0?1:0))}}function X3($,Y,X){if($.block.type!=="heading")return null;let Z=Math.max(1,Math.min(6,$.block.depth+Y));if(Z===$.block.depth)return{kind:"keep-state"};return{kind:"splice-blocks",blocks:[t1({depth:Z,text:$.block.plainText})],rootIndex:$.rootIndex,selection:$0($.rootIndex,X)}}function A$($,Y,X,Z,J){if(Z===0)return[i({text:""}),$];if(Z===J)return[$,i({text:""})];return[$.type==="heading"?t1({depth:$.depth,text:Y}):i({text:Y}),i({text:X})]}function V4($,Y,X,Z=0){return H0($,[...Y,X,0],Z)}function Z3($,Y){let X=$.region.text,Z=$.item,J=typeof Z.checked==="boolean"?!1:Z.checked;if(Y===0){let q=G4("",J,Z.spread);return{kind:"replace-block",block:M0($.list,[...$.list.items.slice(0,$.itemIndex),q,Z,...$.list.items.slice($.itemIndex+1)]),blockId:$.list.id,listItemInsertedPath:x5(q,$.rootIndex,[...$.listChildIndices,$.itemIndex]),selection:V4($.rootIndex,$.listChildIndices,$.itemIndex)}}if(Y===X.length){let q=G4("",J,Z.spread);return{kind:"replace-block",block:M0($.list,[...$.list.items.slice(0,$.itemIndex+1),q,...$.list.items.slice($.itemIndex+1)]),blockId:$.list.id,listItemInsertedPath:x5(q,$.rootIndex,[...$.listChildIndices,$.itemIndex+1]),selection:V4($.rootIndex,$.listChildIndices,$.itemIndex+1)}}let K=X.slice(0,Y),Q=X.slice(Y),M=G4(Q,J,Z.spread),D=d0(Z,[i({text:K})]);return{kind:"replace-block",block:M0($.list,[...$.list.items.slice(0,$.itemIndex),D,M,...$.list.items.slice($.itemIndex+1)]),blockId:$.list.id,listItemInsertedPath:x5(M,$.rootIndex,[...$.listChildIndices,$.itemIndex+1]),selection:V4($.rootIndex,$.listChildIndices,$.itemIndex+1)}}function _$($,Y){if(Y!==0||$.region.text.length!==0)return Z3($,Y);if($.parentItem&&$.parentItemIndex!==null&&$.parentItemChildIndices&&$.parentList&&$.parentListChildIndices)return JM($);let X=$.list.items.slice(0,$.itemIndex),Z=$.list.items.slice($.itemIndex+1),J=[];if(X.length>0)J.push(M0($.list,X));if(J.push(i({text:""})),Z.length>0)J.push(M0($.list,Z));return{kind:"splice-blocks",blocks:J,rootIndex:$.rootIndex,selection:$0($.rootIndex+(X.length>0?1:0))}}function H$($){if($.itemIndex===0)return null;let Y=$.list.items[$.itemIndex-1];if(!Y)return null;let X=KM(Y,$.item,$);return{kind:"replace-block",block:M0($.list,$.list.items.flatMap((Z,J)=>{if(J===$.itemIndex-1)return[X.item];if(J===$.itemIndex)return[];return[Z]})),blockId:$.list.id,selection:H0($.rootIndex,X.regionChildIndices)}}function z$($){return F$($,()=>({insertedItem:$.item}))}function J3($,Y){let X=$.itemIndex+Y;if(X<0||X>=$.list.items.length)return null;let Z=[...$.list.items],[J]=Z.splice($.itemIndex,1);if(!J)return null;return Z.splice(X,0,J),{kind:"replace-block",block:M0($.list,Z),blockId:$.list.id,selection:V4($.rootIndex,$.listChildIndices,X)}}function JM($){return F$($,(Y)=>{let X=typeof Y.checked==="boolean"?!1:Y.checked;return{insertedItem:G4("",X,Y.spread),trackInsertedPath:!0}})}function F$($,Y){if(!$.parentItem||$.parentItemIndex===null||!$.parentItemChildIndices||!$.parentList||!$.parentListChildIndices)return null;let X=$.list.items.filter((D,q)=>q!==$.itemIndex),Z=$.parentItem.children.flatMap((D)=>{if(D.type!=="list"||D.id!==$.list.id)return[D];if(X.length===0)return[];return[M0($.list,X)]}),J=d0($.parentItem,Z),{insertedItem:K,trackInsertedPath:Q=!1}=Y($.parentItem),M=Q?x5(K,$.rootIndex,[...$.parentListChildIndices,$.parentItemIndex+1]):void 0;return{kind:"replace-block",block:M0($.parentList,[...$.parentList.items.slice(0,$.parentItemIndex),J,K,...$.parentList.items.slice($.parentItemIndex+1)]),blockId:$.parentList.id,listItemInsertedPath:M,selection:V4($.rootIndex,$.parentListChildIndices,$.parentItemIndex+1)}}function x5($,Y,X){return typeof $.checked==="boolean"?void 0:M$(Y,X)}function KM($,Y,X){let Z=$.children.findIndex((K)=>K.type==="list"&&K.ordered===X.list.ordered&&K.start===X.list.start);if(Z>=0){let K=$.children[Z];if(!K||K.type!=="list")return{item:$,regionChildIndices:[...X.listChildIndices,X.itemIndex-1,0]};return{item:d0($,$.children.map((Q,M)=>M===Z?M0(K,[...K.items,Y]):Q)),regionChildIndices:[...X.listChildIndices,X.itemIndex-1,Z,K.items.length,0]}}let J=O1({items:[Y],ordered:X.list.ordered,spread:X.list.spread,start:X.list.start});return{item:d0($,[...$.children,J]),regionChildIndices:[...X.listChildIndices,X.itemIndex-1,$.children.length,0,0]}}function E$($,Y,X){let Z=H2($,Y),J=Math.max(2,X);if(!Z||Z.block.type!=="paragraph"||Z.block.plainText.length>0||Y.anchor.regionId!==Y.focus.regionId||Y.anchor.offset!==0||Y.focus.offset!==0)return null;return{kind:"splice-blocks",blocks:[B1({rows:Array.from({length:2},()=>Q3(J))})],rootIndex:Z.rootIndex,selection:v1(Z.rootIndex,0,0)}}function K3($,Y,X,Z){let J=Z<0?DM(X.table,X.rowIndex,X.cellIndex):UM(X.table,X.rowIndex,X.cellIndex);if(!J)return Z>0&&GM(X.table,X.rowIndex,X.cellIndex)?QM(X):{kind:"keep-state"};let K=X.table.rows[J.rowIndex]?.cells[J.cellIndex];if(!K)return{kind:"keep-state"};return{kind:"set-selection",selection:qM($,Y,X.table,J.rowIndex,J.cellIndex,Math.min(Y.focus.offset,K.plainText.length))}}function W$($,Y){let X=D2($,Y.focus.regionId);if(!X||X.kind!=="tableCell")return null;let Z=Math.min(Y.anchor.offset,Y.focus.offset),J=Math.max(Y.anchor.offset,Y.focus.offset),K=o2(X,Z,J,(Q)=>l0({path:Q}));return{kind:"replace-block",block:K.block,blockId:K.blockId,selection:K.selection}}function P$($,Y){let X=Y==="left"?$.cellIndex:$.cellIndex+1;return E2($,B1({align:B$($.table.align,X,0,[null]),rows:$.table.rows.map((Z)=>Y2({cells:MM(Z.cells,X,0,[O$()])}))}),v1($.rootIndex,$.rowIndex,X))}function y$($){let Y=Math.max(0,...$.table.rows.map((X)=>X.cells.length));if(Y<=1)return null;return E2($,B1({align:B$($.table.align,$.cellIndex,1,[]),rows:$.table.rows.map((X)=>Y2({cells:X.cells.filter((Z,J)=>J!==$.cellIndex)}))}),v1($.rootIndex,$.rowIndex,Math.min($.cellIndex,Y-2)))}function T$($,Y){let X=Y==="above"?$.rowIndex:$.rowIndex+1,Z=Math.max(1,...$.table.rows.map((J)=>J.cells.length));return E2($,B0($.table,[...$.table.rows.slice(0,X),Q3(Z),...$.table.rows.slice(X)]),v1($.rootIndex,X,Math.min($.cellIndex,Z-1)))}function j$($){if($.table.rows.length<=1)return null;let Y=$.table.rows.filter((J,K)=>K!==$.rowIndex),X=Math.min($.rowIndex,Y.length-1),Z=Y[X]?.cells.length??1;return E2($,B0($.table,Y),v1($.rootIndex,X,Math.min($.cellIndex,Z-1)))}function w$($){return E2($,i({text:""}),$0($.rootIndex))}function Q3($){return Y2({cells:Array.from({length:$},()=>O$())})}function O$(){return D1({children:[]})}function QM($){let Y=$.table.rows.length,X=Math.max(1,...$.table.rows.map((Z)=>Z.cells.length));return E2($,B0($.table,[...$.table.rows,Q3(X)]),v1($.rootIndex,Y,0))}function E2($,Y,X){return{kind:"replace-block",block:Y,blockId:$.table.id,selection:X}}function MM($,Y,X,Z){return[...$.slice(0,Y),...Z,...$.slice(Y+X)]}function B$($,Y,X,Z){return[...$.slice(0,Y),...Z,...$.slice(Y+X)]}function qM($,Y,X,Z,J,K){let Q=V2($,X.id,Z,J);if(!Q)return Y;return{anchor:{regionId:Q.id,offset:K},focus:{regionId:Q.id,offset:K}}}function DM($,Y,X){if(X>0)return{cellIndex:X-1,rowIndex:Y};if(Y>0){let Z=$.rows[Y-1];if(!Z||Z.cells.length===0)return null;return{cellIndex:Z.cells.length-1,rowIndex:Y-1}}return null}function UM($,Y,X){let Z=$.rows[Y];if(!Z)return null;if(X+1<Z.cells.length)return{cellIndex:X+1,rowIndex:Y};let J=$.rows[Y+1];if(!J||J.cells.length===0)return null;return{cellIndex:0,rowIndex:Y+1}}function GM($,Y,X){let Z=$.rows[Y];return Boolean(Z&&Y===$.rows.length-1&&X===Z.cells.length-1)}function C$($,Y,X){switch(X.kind){case"code":return{kind:"splice-text",selection:Y,text:`
|
|
15
|
-
`};case"tableCell":return
|
|
16
|
-
`}),r5=Q0(($,Y)=>({kind:"splice-text",selection:$.selection,text:Y}),{animate:($,Y,X,Z)=>{if(Z.length>0)return m5(Y,Z.length)}}),U3=($)=>r5($,""),G3=GY(VY,($)=>_Y($,"backward"),($)=>NY($,"backward")),V3=GY(VY,($)=>_Y($,"forward"),($)=>NY($,"forward")),N3=($)=>M3($.documentIndex,$.selection);function I$($,Y,X){let Z=q3($,Y);if(Z){let J=bM(Y);return J>0?m5(Z,J):Z}if(Y.kind==="text")return null;return SM($,Y,X)}function bM($){switch($.kind){case"text":return $.text.length;case"inlines":return X0($.inlines).length;case"blocks":return $.blocks.length===1&&$.blocks[0].type==="paragraph"?$.blocks[0].plainText.length:0}}function SM($,Y,X){let Z=l5($.documentIndex,$.selection);if(!Z)return null;let J=Z.prefersVerbatimFallback&&X&&X.length>0?X:Y7(Y);return J.length>0?r5($,J):null}function p$($,Y,X){return y0($,Y,X,!0)}function x$($){let Y=$.documentIndex.regions,X=Y[0],Z=Y.at(-1);if(!X||!Z)return $;return K0($,{anchor:{regionId:X.id,offset:0},focus:{regionId:Z.id,offset:Z.text.length}})}var s5=($)=>t5($,"bold"),i5=($)=>t5($,"italic"),o5=($)=>t5($,"strikethrough"),n5=($)=>t5($,"underline"),l$=($)=>AY($,v8),d$=Q0(($,Y,X,Z,J)=>B5($.documentIndex,Y,X,Z,J)),c$=Q0(($,Y,X,Z)=>B5($.documentIndex,Y,X,Z,null)),a$=Q0(($,Y,X)=>m8($.documentIndex,$.selection,(Z)=>j1({alt:X??null,path:Z,url:Y}))),r$=Q0(($,Y,X,Z)=>{let J=D2($.documentIndex,Y);if(!J)return null;let{image:K}=X,Q=o2(J,X.start,X.end,(M)=>j1({alt:K.alt,path:M,title:K.title,url:K.url,width:Z}));return{kind:"replace-block",block:Q.block,blockId:Q.blockId}}),A3=($)=>i8($),_3=($)=>o8($),s$=Q0(($,Y)=>{switch(Y.kind){case"tableCell":return K3($.documentIndex,$.selection,Y,1);case"rootTextBlock":return X3(Y,1,$.selection.focus.offset);case"listItem":return H$(Y);default:return null}},{context:U4}),i$=Q0(($,Y)=>{switch(Y.kind){case"tableCell":return K3($.documentIndex,$.selection,Y,-1);case"rootTextBlock":return X3(Y,-1,$.selection.focus.offset);case"listItem":return z$(Y);default:return null}},{context:U4}),o$=Q0(($,Y)=>J3(Y,-1),{context:z2}),n$=Q0(($,Y)=>J3(Y,1),{context:z2}),t$=Q0(($,Y)=>{let X=q4($.documentIndex,Y);if(!X||X.type!=="listItem"||typeof X.checked!=="boolean")return null;return{kind:"replace-block",block:{...X,checked:!X.checked},blockId:Y}}),e$=Q0(($,Y)=>E$($.documentIndex,$.selection,Y)),$Y=Q0(($,Y,X)=>P$(Y,X),{context:A4}),YY=Q0(($,Y)=>y$(Y),{context:A4}),XY=Q0(($,Y,X)=>T$(Y,X),{context:A4}),ZY=Q0(($,Y)=>j$(Y),{context:A4}),JY=Q0(($,Y)=>w$(Y),{context:A4}),KY=Q0(($,Y,X)=>{let Z=T8($.documentIndex,Y,X);if(!Z)return null;return{kind:"splice-comments",count:0,index:$.documentIndex.document.comments.length,threads:[Z]}}),QY=($,Y,X)=>_4($,Y,(Z)=>H8(Z,{body:X.trim()})),MY=($,Y,X,Z)=>_4($,Y,(J)=>z8(J,X,Z)),qY=($,Y,X)=>_4($,Y,(Z)=>F8(Z,X)),DY=($,Y)=>_4($,Y,()=>null),UY=($,Y,X)=>_4($,Y,(Z)=>E8(Z,X));function Q0($,Y){return(X,...Z)=>{let J=[];if(Y?.context){let M=Y.context(X.documentIndex,X.selection);if(!M)return null;J.push(M)}let K=$(X,...J,...Z);if(!K)return null;let Q=f0(X,K);return Y?.animate?.(X,Q,K,...Z)??Q}}function GY(...$){return(Y,...X)=>{for(let Z of $){let J=Z(Y,...X);if(J)return J}return null}}function A4($,Y){return t8($,Y.focus.regionId)}function VY($){return vM($)?U3($):null}function NY($,Y){let X=K$($.documentIndex,$.selection,Y);return f0($,u$($.documentIndex,X))}function t5($,Y){return AY($,(X,Z,J)=>b8(X,Z,J,Y))}function AY($,Y){let X=Y0($.documentIndex,$.selection);if(X.start.regionId!==X.end.regionId||X.start.offset===X.end.offset)return null;return f0($,C5($.documentIndex,X.start.regionId,X.start.offset,X.end.offset,Y))}function vM($){let Y=Y0($.documentIndex,$.selection);return Y.start.regionId!==Y.end.regionId||Y.start.offset!==Y.end.offset}function _Y($,Y){let X=q$($,Y);if(!X)return null;let Z=f0($,X);if(!Z)return null;return k7($,Z,X.selection.anchor.offset,X.selection.focus.offset)}function _4($,Y,X){let J=S0($.documentIndex).threads[Y];if(!J)return null;let K=X(J);if(K===J)return null;return f0($,{kind:"splice-comments",count:1,index:Y,threads:K?[K]:[]})}function k1(){return{graphemeWidths:new Map,lineBoundaries:new Map,measuredContainerHeights:new Map,measuredLines:new Map,preparedText:new Map,viewportPlans:new WeakMap}}function HY($,Y,X){return H4($.preparedText,Y,X,256)}function zY($,Y,X){return H4($.measuredLines,Y,X,512)}function FY($,Y,X){return H4($.lineBoundaries,Y,X,1024)}function EY($,Y,X){return H4($.measuredContainerHeights,Y,X,1024)}function WY($,Y){let X=$.graphemeWidths.get(Y);if(X)return X;let Z=new Map;return H4($.graphemeWidths,Y,Z,64),Z}function PY($,Y,X){return $.viewportPlans.get(Y)?.get(X)??null}function yY($,Y,X,Z){let J=$.viewportPlans.get(Y)??new Map;return J.set(X,Z),$.viewportPlans.set(Y,J),Z}function H4($,Y,X,Z){if($.has(Y))$.delete(Y);if($.set(Y,X),$.size>Z){let J=$.keys().next().value;if(J!==void 0)$.delete(J)}return X}var e5={blockGap:16,charWidth:9,indentWidth:24,lineHeight:24,paddingX:16,paddingY:12};function $6($,Y,X,Z,J){if(TY($,X,Z,"list"))return 6;if(TY($,X,Z,"blockquote"))return 10;if(X===Z)return 4;return J+fM(Y.get(X))}function fM($){if($?.type!=="heading")return 0;if($.depth===1)return 24;return $.depth===2?16:0}function TY($,Y,X,Z){let J=jY($,Y,Z),K=jY($,X,Z);for(let Q of J)if(K.has(Q))return!0;return!1}function jY($,Y,X){let Z=new Set,J=$.get(Y)??null;while(J){if(J.type===X)Z.add(J.id);J=J.parentBlockId?$.get(J.parentBlockId)??null:null}return Z}var mM=["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"],hM=["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 kM($){if($<=255)return mM[$];if(1424<=$&&$<=1524)return"R";if(1536<=$&&$<=1791)return hM[$&255];if(1792<=$&&$<=2220)return"AL";return"L"}function uM($){let Y=$.length;if(Y===0)return null;let X=Array(Y),Z=0;for(let q=0;q<Y;q++){let U=kM($.charCodeAt(q));if(U==="R"||U==="AL"||U==="AN")Z++;X[q]=U}if(Z===0)return null;let J=Y/Z<0.3?0:1,K=new Int8Array(Y);for(let q=0;q<Y;q++)K[q]=J;let Q=J&1?"R":"L",M=Q,D=M;for(let q=0;q<Y;q++)if(X[q]==="NSM")X[q]=D;else D=X[q];D=M;for(let q=0;q<Y;q++){let U=X[q];if(U==="EN")X[q]=D==="AL"?"AN":"EN";else if(U==="R"||U==="L"||U==="AL")D=U}for(let q=0;q<Y;q++)if(X[q]==="AL")X[q]="R";for(let q=1;q<Y-1;q++){if(X[q]==="ES"&&X[q-1]==="EN"&&X[q+1]==="EN")X[q]="EN";if(X[q]==="CS"&&(X[q-1]==="EN"||X[q-1]==="AN")&&X[q+1]===X[q-1])X[q]=X[q-1]}for(let q=0;q<Y;q++){if(X[q]!=="EN")continue;let U;for(U=q-1;U>=0&&X[U]==="ET";U--)X[U]="EN";for(U=q+1;U<Y&&X[U]==="ET";U++)X[U]="EN"}for(let q=0;q<Y;q++){let U=X[q];if(U==="WS"||U==="ES"||U==="ET"||U==="CS")X[q]="ON"}D=M;for(let q=0;q<Y;q++){let U=X[q];if(U==="EN")X[q]=D==="L"?"L":"EN";else if(U==="R"||U==="L")D=U}for(let q=0;q<Y;q++){if(X[q]!=="ON")continue;let U=q+1;while(U<Y&&X[U]==="ON")U++;let V=q>0?X[q-1]:M,G=U<Y?X[U]:M,N=V!=="L"?"R":"L";if(N===(G!=="L"?"R":"L"))for(let _=q;_<U;_++)X[_]=N;q=U-1}for(let q=0;q<Y;q++)if(X[q]==="ON")X[q]=Q;for(let q=0;q<Y;q++){let U=X[q];if((K[q]&1)===0){if(U==="R")K[q]++;else if(U==="AN"||U==="EN")K[q]+=2}else if(U==="L"||U==="AN"||U==="EN")K[q]++}return K}function wY($,Y){let X=uM($);if(X===null)return null;let Z=new Int8Array(Y.length);for(let J=0;J<Y.length;J++)Z[J]=X[Y[J]];return Z}var gM=/[ \t\n\r\f]+/g,IM=/[\t\n\r\f]| {2,}|^ | $/;function pM($){let Y=$??"normal";return Y==="pre-wrap"?{mode:Y,preserveOrdinarySpaces:!0,preserveHardBreaks:!0}:{mode:Y,preserveOrdinarySpaces:!1,preserveHardBreaks:!1}}function xM($){if(!IM.test($))return $;let Y=$.replace(gM," ");if(Y.charCodeAt(0)===32)Y=Y.slice(1);if(Y.length>0&&Y.charCodeAt(Y.length-1)===32)Y=Y.slice(0,-1);return Y}function lM($){if(!/[\r\f]/.test($))return $.replace(/\r\n/g,`
|
|
17
|
-
`);return $.replace(/\r\n/g,`
|
|
1
|
+
import{useEffect as YF,useEffectEvent as v2,useLayoutEffect as $V,useMemo as N1,useRef as f2,useState as GE}from"react";function c0(N){let F=F0(N.children);return{children:N.children,id:J0(N.path,"paragraph",F),plainText:F,type:"paragraph"}}function s(N){return c0({children:r8(void 0,N.text)})}function VF(N){let F=F0(N.children);return{children:N.children,depth:N.depth,id:J0(N.path,"heading",`${N.depth}:${F}`),plainText:F,type:"heading"}}function t1(N){return VF({children:r8(void 0,N.text),depth:N.depth})}function w0(N){let F=N.marks??[];return{id:J0(N.path,"text",`${N.text}:${F.join(",")}`),marks:F,text:N.text,type:"text"}}function a0(N={}){return{id:J0(N.path,"lineBreak","lineBreak"),type:"lineBreak"}}function K1(N){return{code:N.code,id:J0(N.path,"code",N.code),type:"code"}}function C1(N){return{children:N.children,id:J0(N.path,"link",`${N.url}:${F0(N.children)}`),title:N.title??null,type:"link",url:N.url}}function S1(N){let F=N.alt??null,M=N.width??null;return{alt:F,id:J0(N.path,"image",`${N.url}:${M??""}:${F??""}`),title:N.title??null,type:"image",url:N.url,width:M}}function GF(N){return{id:J0(N.path,"raw",N.source),originalType:N.originalType,source:N.source,type:"raw"}}function R1(N){let F=f1(N.children);return{checked:N.checked??null,children:N.children,id:J0(N.path,"listItem",F),plainText:F,spread:N.spread??!1,type:"listItem"}}function b1(N){let F=N.items.map((M)=>M.plainText).join(`
|
|
2
|
+
`);return{id:J0(N.path,"list",`${String(N.ordered)}:${F}`),items:N.items,ordered:N.ordered,plainText:F,spread:N.spread??!1,start:N.start??null,type:"list"}}function m0(N){let F=f1(N.children);return{children:N.children,id:J0(N.path,"blockquote",F),plainText:F,type:"blockquote"}}function N3(N){return{id:J0(N.path,"code",`${N.language??""}:${N.source}`),language:N.language??null,meta:N.meta??null,plainText:N.source,source:N.source,type:"code"}}function q1(N){let F=F0(N.children);return{children:N.children,id:J0(N.path,"tableCell",F),plainText:F}}function e1(N){return{cells:N.cells,id:J0(N.path,"tableRow",String(N.cells.length))}}function v1(N){let F=N.rows.map((M)=>M.cells.map((A)=>A.plainText).join(" | ")).join(`
|
|
3
|
+
`);return{align:N.align??[],id:J0(N.path,"table",F),plainText:F,rows:N.rows,type:"table"}}function zF(){return{id:"",plainText:"",type:"divider"}}function F3(N){return{id:J0(N.path,"raw",N.source),originalType:N.originalType,plainText:N.source,source:N.source,type:"raw"}}function a8(N){return{attributes:N.attributes,body:N.body,id:J0(N.path,"directive",`${N.name}{${N.attributes}}:${N.body}`),name:N.name,plainText:N.body,type:"directive"}}function Q0(N){let F=[];for(let M of N){let A=F.at(-1);if(A?.type==="text"&&M.type==="text"&&A.marks.join(",")===M.marks.join(",")){F[F.length-1]=w0({marks:A.marks,path:A.id,text:A.text+M.text});continue}F.push(M)}return F}function j0(N,F){return N.type==="heading"?VF({children:F,depth:N.depth}):c0({children:F})}function r0(N,F){return R1({checked:N.checked,children:F,spread:N.spread})}function Y0(N,F,M={}){return b1({items:F,ordered:M.ordered??N.ordered,spread:M.spread??N.spread,start:M.start??N.start})}function C0(N,F){return v1({align:N.align,rows:F})}function h2(N,F){return N3({language:N.language,meta:N.meta,source:F})}function g2(N,F){return F3({originalType:N.originalType,source:F})}function r8(N,F){return F.length>0?[w0({path:N?`${N}.children.0`:void 0,text:F})]:[]}function J0(N,F,M){return N?A0(F,N,M):""}function M3(N,F){A3(N.blocks,F,i8(),o8())}function PE(N,F){A3(N,F,i8(),o8())}function s0(N,F){let M=null,A={enterBlock(D){if(D.id===F)return M=D,"stop"}};if(Array.isArray(N))PE(N,A);else M3(N,A);return M}function A3(N,F,M,A){for(let[D,E]of N.entries()){if(M.stopped)return;let $=`${A.pathPrefix}.${D}`,Y={blockAncestors:A.blockAncestors,depth:A.depth,parentBlock:A.parentBlock,path:$},Z=F.enterBlock?.(E,Y);if(N2(Z,M))return;if(Z!=="skip")switch(E.type){case"list":s8(E.items,E,F,M,A,$);break;case"blockquote":case"listItem":s8(E.children,E,F,M,A,$);break;case"heading":case"paragraph":D3(E.children,F,M,{block:E,blockAncestors:[...A.blockAncestors,E],inlineAncestors:[],parentInline:null,pathPrefix:`${$}.children`});break;case"table":LE(E,F,M,{blockAncestors:[...A.blockAncestors,E],pathPrefix:$});break;case"code":case"directive":case"divider":case"raw":break}if(M.stopped)return;if(N2(F.leaveBlock?.(E,Y),M))return}}function D3(N,F,M,A){for(let[D,E]of N.entries()){if(M.stopped)return;let $=`${A.pathPrefix}.${D}`,Y={block:A.block,blockAncestors:A.blockAncestors,inlineAncestors:A.inlineAncestors,parentInline:A.parentInline,path:$},Z=F.enterInline?.(E,Y);if(N2(Z,M))return;if(Z!=="skip"){if(E.type==="link")TE(E.children,E,F,M,A,$)}if(M.stopped)return;if(N2(F.leaveInline?.(E,Y),M))return}}function i8(){return{stopped:!1}}function o8(){return{blockAncestors:[],depth:0,parentBlock:null,pathPrefix:"root"}}function s8(N,F,M,A,D,E){A3(N,M,A,{blockAncestors:[...D.blockAncestors,F],depth:D.depth+1,parentBlock:F,pathPrefix:`${E}.children`})}function TE(N,F,M,A,D,E){D3(N,M,A,{block:D.block,blockAncestors:D.blockAncestors,inlineAncestors:[...D.inlineAncestors,F],parentInline:F,pathPrefix:`${E}.children`})}function LE(N,F,M,A){for(let[D,E]of N.rows.entries())for(let[$,Y]of E.cells.entries()){if(M.stopped)return;let Z=`${A.pathPrefix}.rows.${D}.cells.${$}`,X={blockAncestors:A.blockAncestors,cellIndex:$,path:Z,row:E,rowIndex:D,table:N},Q=F.enterTableCell?.(Y,X);if(N2(Q,M))return;if(Q!=="skip")D3(Y.children,F,M,{block:N,blockAncestors:A.blockAncestors,inlineAncestors:[],parentInline:null,pathPrefix:`${Z}.children`});if(M.stopped)return;if(N2(F.leaveTableCell?.(Y,X),M))return}}function N2(N,F){if(N!=="stop")return!1;return F.stopped=!0,!0}function F2(N,F,M="root",A=null){let D=!1,E=[];for(let[$,Y]of N.entries()){let Z=`${M}.${$}`,X=F(Y,{parent:A,path:Z,recurse:()=>wE(Y,F,`${Z}.children`)});if(X===null){D=!0;continue}if(Array.isArray(X)){D=!0,E.push(...X);continue}if(X!==Y)D=!0;E.push(X)}return D?E:N}function wE(N,F,M){switch(N.type){case"blockquote":case"listItem":{let A=F2(N.children,F,M,N);return A===N.children?N:{...N,children:A}}case"list":{let A=F2(N.items,F,M,N);return A===N.items?N:{...N,items:A}}default:return N}}function M2(N,F=[],M){return{blocks:N.map((A,D)=>$3(A,D)),comments:F,frontMatter:M}}function m1(N,F,M,A){let D=A.map((Y,Z)=>$3(Y,F+Z)),E=N.blocks.slice(F+M),$=A.length===M?E:E.map((Y,Z)=>$3(Y,F+D.length+Z));return{blocks:[...N.blocks.slice(0,F),...D,...$],comments:N.comments,frontMatter:N.frontMatter}}function t8(N,F,M,A){return{blocks:N.blocks,comments:[...N.comments.slice(0,F),...A,...N.comments.slice(F+M)],frontMatter:N.frontMatter}}function e8(N,F,M,A){if(A!==void 0)return n8(N,A,F,M);for(let D=0;D<N.blocks.length;D+=1){let E=n8(N,D,F,M);if(E)return E}return null}function n8(N,F,M,A){let D=N.blocks[F];if(!D)return null;let E=N5(D,M,A);return E?m1(N,F,1,[E]):null}function N5(N,F,M){if(N.id===F)return M(N);switch(N.type){case"blockquote":{let A=E3(N.children,F,M);return A?m0({children:A}):null}case"listItem":{let A=E3(N.children,F,M);return A?r0(N,A):null}case"list":{let A=E3(N.items,F,M);return A?Y0(N,A):null}default:return null}}function E3(N,F,M){let A=!1,D=N.map((E)=>{let $=N5(E,F,M);if(!$)return E;return A=!0,$});return A?D:null}function F0(N){return N.map((F)=>{switch(F.type){case"lineBreak":return`
|
|
4
|
+
`;case"image":return F.alt??"";case"code":return F.code;case"link":return F0(F.children);case"text":return F.text;case"raw":return F.source}}).join("")}function f1(N){return N.map((F)=>{switch(F.type){case"blockquote":case"listItem":return f1(F.children);case"code":return F.source;case"directive":return F.body;case"heading":case"paragraph":return F0(F.children);case"list":return F.items.map((M)=>M.plainText).join(`
|
|
5
|
+
`);case"table":return F.rows.map((M)=>M.cells.map((A)=>A.plainText).join(" | ")).join(`
|
|
6
|
+
`);case"divider":return"";case"raw":return F.source}}).join(`
|
|
7
|
+
`).trim()}function Z3(N){return N.every((F)=>F.type==="text"&&F.marks.length===0)}function BF(N){if(N.length!==1)return!1;let F=N[0];return F.type==="paragraph"&&Z3(F.children)}function F5(N){switch(N.kind){case"text":return N.text;case"inlines":return F0(N.inlines);case"blocks":return f1(N.blocks)}}function G0(N){switch(N.type){case"blockquote":case"listItem":return N.children;case"list":return N.items;default:return null}}function k1(N,F){if(F.length===0)return null;switch(N.type){case"blockquote":return m0({children:F});case"list":return Y0(N,F);case"listItem":return r0(N,F);default:return null}}function $3(N,F){return _F(N,`root.${F}`)}function _F(N,F){switch(N.type){case"blockquote":{let M=N.children.map((D,E)=>_F(D,`${F}.children.${E}`)),A=f1(M);return{children:M,id:A0("blockquote",F,A),plainText:A,type:"blockquote"}}case"code":return{id:A0("code",F,`${N.language??""}:${N.source}`),language:N.language,meta:N.meta,plainText:N.source,source:N.source,type:"code"};case"directive":return{attributes:N.attributes,body:N.body,id:A0("directive",F,`${N.name}{${N.attributes}}:${N.body}`),name:N.name,plainText:N.body,type:"directive"};case"heading":{let M=N.children.map((D,E)=>HF(D,`${F}.children.${E}`)),A=F0(M);return{children:M,depth:N.depth,id:A0("heading",F,`${N.depth}:${A}`),plainText:A,type:"heading"}}case"list":{let M=N.items.map((D,E)=>_F(D,`${F}.children.${E}`)),A=M.map((D)=>D.plainText).join(`
|
|
8
|
+
`);return{id:A0("list",F,`${String(N.ordered)}:${A}`),items:M,ordered:N.ordered,plainText:A,spread:N.spread,start:N.start,type:"list"}}case"listItem":{let M=N.children.map((D,E)=>_F(D,`${F}.children.${E}`)),A=f1(M);return{checked:N.checked,children:M,id:A0("listItem",F,A),plainText:A,spread:N.spread,type:"listItem"}}case"paragraph":{let M=N.children.map((D,E)=>HF(D,`${F}.children.${E}`)),A=F0(M);return{children:M,id:A0("paragraph",F,A),plainText:A,type:"paragraph"}}case"table":{let M=N.rows.map((D,E)=>jE(D,`${F}.rows.${E}`)),A=M.map((D)=>D.cells.map((E)=>E.plainText).join(" | ")).join(`
|
|
9
|
+
`);return{align:N.align,id:A0("table",F,A),plainText:A,rows:M,type:"table"}}case"divider":return{id:A0("divider",F,"divider"),plainText:"",type:"divider"};case"raw":return{id:A0("raw",F,N.source),originalType:N.originalType,plainText:N.source,source:N.source,type:"raw"}}}function jE(N,F){return{cells:N.cells.map((M,A)=>{let D=M.children.map(($,Y)=>HF($,`${F}.cells.${A}.children.${Y}`)),E=F0(D);return{children:D,id:A0("tableCell",`${F}.cells.${A}`,E),plainText:E}}),id:A0("tableRow",F,String(N.cells.length))}}function HF(N,F){switch(N.type){case"lineBreak":return{id:A0("lineBreak",F,"lineBreak"),type:"lineBreak"};case"image":return{alt:N.alt,id:A0("image",F,`${N.url}:${N.width??""}:${N.alt??""}`),title:N.title,type:"image",url:N.url,width:N.width};case"code":return{code:N.code,id:A0("code",F,N.code),type:"code"};case"link":{let M=N.children.map((D,E)=>HF(D,`${F}.children.${E}`)),A=F0(M);return{children:M,id:A0("link",F,`${N.url}:${A}`),title:N.title,type:"link",url:N.url}}case"text":return{id:A0("text",F,`${N.text}:${N.marks.join(",")}`),marks:N.marks,text:N.text,type:"text"};case"raw":return{id:A0("raw",F,N.source),originalType:N.originalType,source:N.source,type:"raw"}}}function M5(N){return F2(N,(F,{recurse:M})=>{switch(F.type){case"blockquote":case"list":case"listItem":return M();case"heading":case"paragraph":return j0(F,Y3(F.children));case"table":return C0(F,F.rows.map((A)=>({...A,cells:A.cells.map((D)=>({...D,children:Y3(D.children)}))})));default:return F}})}function Y3(N){let F=null,M=()=>F??=[...N];for(let A=N.length-1;A>=0;A-=1){let D=N[A];if(D.type==="text"){let E=D.text.replace(/[ \t]+$/u,"");if(E.length===D.text.length)return F??N;let $=M();if(E.length===0){$.splice(A,1);continue}return $[A]={...D,text:E},$}if(D.type==="link"){let E=Y3(D.children);if(E===D.children)return F??N;let $=M();if(E.length===0){$.splice(A,1);continue}return $[A]={...D,children:E},$}return F??N}return F??N}function A0(N,F,M){let A=2166136261;for(let D of`${N}:${F}:${M}`)A^=D.charCodeAt(0),A=Math.imul(A,16777619);return`${N}-${(A>>>0).toString(36)}`}var X3="text";function Q3(N){return N==="text"||N==="code"||N==="tableCell"}function J3(N){return N===X3?void 0:N}function D5(N){switch(N){case"heading":case"paragraph":return"text";case"code":return"code";default:return null}}function WF(N){let F=[];return M3(N,{enterBlock(M){switch(M.type){case"heading":case"paragraph":F.push({containerKind:"text",containerOrdinal:F.length,id:M.id,text:F0(M.children)});break;case"code":F.push({containerKind:"code",containerOrdinal:F.length,id:M.id,text:M.source});break}},enterTableCell(M){F.push({containerKind:"tableCell",containerOrdinal:F.length,id:M.id,text:F0(M.children)})}}),F}function K3(N,F,M){return{prefix:N.slice(Math.max(0,F-A5),F),suffix:N.slice(M,Math.min(N.length,M+A5))}}function I2(N,F,M){let A=k0(F,0,N.text.length),D=k0(M,A,N.text.length),{prefix:E,suffix:$}=K3(N.text,A,D);return{kind:J3(N.containerKind),prefix:E||void 0,suffix:$||void 0}}function u2(N,F,M){let A=k0(F,0,N.text.length),D=k0(M,A,N.text.length);return N.text.slice(A,D)}function i0(N,F){if(F.length===0)return[];let M=[],A=0;while(A<=N.length){let D=N.indexOf(F,A);if(D===-1)break;M.push(D),A=D+Math.max(1,F.length)}return M}function A2(N,F,M){if(F.length===0||M.length===0)return[];let A=[];for(let D of i0(N,F)){let E=D+F.length,$=N.indexOf(M,E);if($!==-1)A.push({startOffset:E,endOffset:$})}return A}function q3(N,F,M){if(!F)return!1;return N.slice(Math.max(0,M-F.length),M)===F}function U3(N,F,M){if(!F)return!1;return N.slice(M,M+F.length)===F}var A5=24;function k0(N,F,M){return Math.min(Math.max(N,F),M)}var E5=48,$5=64,CE=32;function p2(N,F){let M=N.anchor.kind??X3,A=WF(F).filter(($)=>$.containerKind===M),D=SE(N,A);if(D.length>0)return Y5(N,D,null);let E=RE(N,A);if(E.length>0)return Y5(N,E,"repaired");return{match:null,repair:null,status:"stale"}}function SE(N,F){let M=[],A=N.quote;if(A.length===0)return M;for(let D of F)for(let E of i0(D.text,A))M.push({container:D,endOffset:E+A.length,score:fE(N,D,E),startOffset:E});return M.sort((D,E)=>E.score-D.score),M}function RE(N,F){let M=[];for(let A of F)M.push(...bE(N,A));return M.sort((A,D)=>D.score-A.score),M}function bE(N,F){let M=[],A=N.quote.length,D=F.text,E=N.anchor.prefix??"",$=N.anchor.suffix??"";if(E.length>0&&$.length>0){for(let Y of A2(D,E,$))M.push({container:F,endOffset:Y.endOffset,score:V3(N,F,Y.startOffset,Y.endOffset,A),startOffset:Y.startOffset});return M}if(E.length>0){for(let Y of i0(D,E)){let Z=Y+E.length,X=k0(Z+A,Z,D.length);M.push({container:F,endOffset:X,score:V3(N,F,Z,X,A),startOffset:Z})}return M}if($.length>0)for(let Y of i0(D,$)){let Z=Y,X=k0(Z-A,0,Z);M.push({container:F,endOffset:Z,score:V3(N,F,X,Z,A),startOffset:X})}return M}function Y5(N,F,M){let[A,D]=F;if(!A)return{match:null,repair:null,status:"stale"};if(D&&A.score===D.score)return{match:null,repair:null,status:"ambiguous"};let E=I2(A.container,A.startOffset,A.endOffset),$=u2(A.container,A.startOffset,A.endOffset),Y=M??($===N.quote&&(E.prefix??"")===(N.anchor.prefix??"")&&(E.suffix??"")===(N.anchor.suffix??"")?"matched":"repaired");return{match:vE(A.container,A.startOffset,A.endOffset),repair:{anchor:E,quote:$},status:Y}}function vE(N,F,M){return{containerId:N.id,containerKind:N.containerKind,containerOrdinal:N.containerOrdinal,endOffset:M,startOffset:F}}function fE(N,F,M){let A=0;if(q3(F.text,N.anchor.prefix,M))A+=E5;if(U3(F.text,N.anchor.suffix,M+N.quote.length))A+=E5;return A}function V3(N,F,M,A,D){let E=0;if(q3(F.text,N.anchor.prefix,M))E+=$5;if(U3(F.text,N.anchor.suffix,A))E+=$5;if(E+=Math.max(0,CE-Math.abs(D-(A-M))),N.quote.length>0){let $=F.text.slice(M,A);if($.length>0)E+=mE(N.quote,$),E+=kE(N.quote,$)}return E}function mE(N,F){let M=0;while(M<N.length&&M<F.length&&N[M]===F[M])M+=1;return M}function kE(N,F){let M=0;while(M<N.length&&M<F.length&&N[N.length-1-M]===F[F.length-1-M])M+=1;return M}function G3(N){if(!N||typeof N!=="object"||Array.isArray(N))return null;let F=N,M=gE(F.anchor),A=typeof F.quote==="string"?F.quote:null,D=Array.isArray(F.comments)?F.comments.flatMap((E)=>{let $=hE(E);return $?[$]:[]}):[];if(!M||!A||D.length===0)return null;return{quote:A,anchor:M,comments:D,resolvedAt:typeof F.resolvedAt==="string"?F.resolvedAt:void 0}}function hE(N){if(!N||typeof N!=="object"||Array.isArray(N))return null;let F=N;if(typeof F.body!=="string"||typeof F.updatedAt!=="string")return null;return{body:F.body,updatedAt:F.updatedAt}}function gE(N){if(!N||typeof N!=="object"||Array.isArray(N))return null;let{kind:F,prefix:M,suffix:A}=N;if("kind"in N&&!Q3(F)||"prefix"in N&&typeof M!=="string"||"suffix"in N&&typeof A!=="string")return null;return{kind:Q3(F)?J3(F):void 0,prefix:typeof M==="string"?M:void 0,suffix:typeof A==="string"?A:void 0}}function z3(N){let F=N.createdAt??new Date().toISOString();return{comments:[Z5({body:N.body,updatedAt:F})],quote:N.quote,anchor:N.anchor}}function _3(N,F){let M=Z5(F);return{...N,comments:[...N.comments,M]}}function H3(N,F,M,A=new Date().toISOString()){let D=M.trim();if(D.length===0)return N;let E=!1,$=N.comments.map((Y,Z)=>{if(Z!==F||Y.body===D)return Y;return E=!0,{...Y,body:D,updatedAt:A}});if(!E)return N;return{...N,comments:$}}function B3(N,F){let M=N.comments.filter((A,D)=>D!==F);if(M.length===N.comments.length)return N;if(M.length===0)return null;return{...N,comments:M}}function W3(N,F,M=new Date().toISOString()){if(M1(N)===F)return N;return{...N,resolvedAt:F?M:void 0}}function M1(N){return N.resolvedAt!=null}function y3(N){if(N.comments.length===0)return null;return N.comments.reduce((F,M)=>M.updatedAt>F?M.updatedAt:F,N.comments[0].updatedAt)}function Z5(N){let F=N.updatedAt??new Date().toISOString();return{body:N.body,updatedAt:F}}function X5(N,F,M,A,D){let E=A-M,$=D-E;if(A<=N)return{end:F+$,start:N+$};if(M>=F)return{end:F,start:N};let Y=Math.max(0,Math.min(M,F)-N),Z=Math.max(0,F-Math.max(A,N)),X=N<M?N:M;return{end:X+Y+D+Z,start:X}}function P3(N,F,M){let A=M.trim();if(A.length===0||F.startOffset===F.endOffset)return null;let D=N.regionIndex.get(F.regionId)??null,E=D?O3(N,D):null;if(!E)return null;return z3({anchor:I2(E,F.startOffset,F.endOffset),body:A,quote:u2(E,F.startOffset,F.endOffset)})}function o0(N){let F="documentIndex"in N?N.documentIndex:N,M=yF(F),A=F.document.comments,D=[...A],E=[];for(let[$,Y]of A.entries()){let Z=p2(Y,F.document);if(!Z.match)continue;let Q=M.findBySemanticMatch(Z.match.containerId,Z.match.containerOrdinal)?.runtimeContainer??null;if(!Q)continue;if(Z.repair)D[$]={...Y,anchor:Z.repair.anchor,quote:Z.repair.quote};E.push({endOffset:Z.match.endOffset,resolution:Z,regionId:Q.id,resolved:Y.resolvedAt!=null,startOffset:Z.match.startOffset,threadIndex:$})}return{liveRanges:E,threads:D}}function T3(N,F,M,A,D,E){if(N.document.comments.length===0)return F.document.comments;let $=N.commentContainerIndex.get(M.semanticRegionId)??[],Y=new Set($);if($.length===0)return F.document.comments;let Z=o0(N),X=new Map(Z.liveRanges.map((q)=>[q.threadIndex,q])),Q=O3(N,M),K=D2(F,M.path),J=K?O3(F,K):null;if(!Q||!J)return F.document.comments;return F.document.comments.map((q,U)=>{if(!Y.has(U))return q;let V=X.get(U),G=V?.resolution.match??null;if(!V||!G||G.containerId!==Q.id)return q;let _=X5(G.startOffset,G.endOffset,A,D,E.length);return{...q,anchor:I2(J,_.start,_.end),quote:u2(J,_.start,_.end)}})}function O3(N,F){let M=IE(N,F);if(!M)return null;return{containerKind:M,containerOrdinal:-1,id:F.semanticRegionId,text:F.text}}function IE(N,F){if(N.tableCellIndex.has(F.id))return"tableCell";return D5(F.blockType)}function OF(N,F){if(F.length===0)return[];let M=yF(N),A=M.list();return F.map((D)=>({...D,cursorPoint:uE(D,A,M),viewport:null}))}function uE(N,F,M){if(!N.cursor)return null;let A=pE(F,N.cursor),D=xE(A,N.cursor);if(D.length!==1)return null;let E=D[0],$=M.resolveRuntimeContainer(E.container.id);if(!$)return null;return{offset:Math.max(0,Math.min(E.offset,$.text.length)),regionId:$.id}}function pE(N,F){return F.kind?N.filter((M)=>M.containerKind===F.kind):N}function xE(N,F){if(F.prefix&&F.suffix)return lE(N,F.prefix,F.suffix);if(F.prefix)return Q5(N,F.prefix,"after");if(F.suffix)return Q5(N,F.suffix,"before");return[]}function Q5(N,F,M){let A=[];for(let D of N)for(let E of i0(D.text,F))A.push({container:D,offset:M==="after"?E+F.length:E});return A}function lE(N,F,M){let A=[];for(let D of N)for(let E of A2(D.text,F,M))A.push({container:D,offset:E.startOffset});return A}var dE=48;function x2(N,F,M){let A="documentIndex"in N?N.documentIndex:N;if(M.length===0)return[];return M.map((D)=>({...D,viewport:cE(A,F,D)}))}function PF(N,F,M){let A="documentIndex"in N?N.documentIndex:N,D=J5(A,F,M);if(!D)return"unresolved";return K5(F,D)}function cE(N,F,M){if(!M.cursorPoint)return{status:"unresolved"};let A=J5(N,F,M.cursorPoint);if(!A)return{status:"unresolved"};return{scrollTop:aE(F,A),status:K5(F,A)}}function J5(N,F,M){let A=h0(F.layout,N,M);if(A)return{bottom:A.top+A.height,top:A.top};return F.estimateRegionBounds(M.regionId)}function K5(N,F){let M=N.viewport.top,A=M+N.viewport.height;if(F.bottom<M)return"above";if(F.top>A)return"below";return"visible"}function aE(N,F){let M=Math.max(0,N.totalHeight-N.viewport.height),A=F.top-Math.min(dE,N.viewport.height/4);return Math.max(0,Math.min(M,A))}function yF(N){let F=WF(N.document),M=new Map(F.map((D)=>[D.id,D])),A=new Map(N.regions.map((D)=>[D.semanticRegionId,D]));return{findBySemanticMatch(D,E){let $=M.get(D)??F[E]??null;if(!$)return null;return{runtimeContainer:A.get($.id)??null,semanticContainer:$}},list(D){return D?F.filter((E)=>E.containerKind===D):F},resolveRuntimeContainer(D){return A.get(D)??null}}}var l2="",q5=1e6;function d2(N,F,M){return`${N}:${F}:${M}`}function E2(N){let F=K$(N),M=w3(F.blocks.map((A,D)=>a2(A,D)));return j3(F,M)}function a2(N,F){let M=[],A=[],D=[],E=new Set,$=0;function Y(X,Q,K,J,q=null){if(A.length>0)D.push(`
|
|
10
|
+
`),$+=1;let U=K.map((_)=>_.text).join(""),V=$,G=V+U.length;D.push(U),$=G;for(let _ of K)if(_.image)E.add(_.image.url);A.push({blockId:X.id,blockType:X.type,end:G,id:`${X.id}:${Q}`,path:Q,rootIndex:F,inlines:K,semanticRegionId:J,start:V,tableCellPosition:q,text:U})}function Z(X,Q,K,J){let q={childBlockIds:[],depth:K,end:$,id:X.id,parentBlockId:J,path:Q,regionIds:[],rootIndex:F,start:$,type:X.type};switch(M.push(q),X.type){case"blockquote":case"listItem":for(let[U,V]of X.children.entries())q.childBlockIds.push(V.id),Z(V,`${Q}.children.${U}`,K+1,X.id);break;case"code":{Y(X,`${Q}.source`,[{end:X.source.length,id:`${X.id}:code`,image:null,inlineCode:!1,kind:"text",link:null,marks:[],originalType:null,start:0,text:X.source}],X.id),q.regionIds.push(A.at(-1).id);break}case"heading":case"paragraph":Y(X,`${Q}.children`,L3(X.children),X.id),q.regionIds.push(A.at(-1).id);break;case"list":for(let[U,V]of X.items.entries())q.childBlockIds.push(V.id),Z(V,`${Q}.children.${U}`,K+1,X.id);break;case"table":for(let[U,V]of X.rows.entries())for(let[G,_]of V.cells.entries())Y(X,`${Q}.rows.${U}.cells.${G}`,L3(_.children),_.id,{cellIndex:G,rowIndex:U}),q.regionIds.push(A.at(-1).id);break;case"divider":break;case"directive":break;case"raw":Y(X,`${Q}.source`,[{end:X.source.length,id:`${X.id}:raw`,image:null,inlineCode:!1,kind:"raw",link:null,marks:[],originalType:X.originalType,start:0,text:X.source}],X.id),q.regionIds.push(A.at(-1).id);break}q.end=$}return Z(N,`root.${F}`,0,null),{blockRange:{end:M.length,start:0},blocks:M,end:$,imageUrls:E,length:$,regionRange:A.length>0?{end:A.length,start:0}:void 0,regions:A,rootIndex:F,start:0,text:D.join("")}}function w3(N,F=null){let M=[],A=0,D=0,E=0,$=!1;for(let[Y,Z]of N.entries()){if(Z.regions.length>0&&$)E+=1;let X={...Z,blockRange:{end:A+Z.blocks.length,start:A},end:E+Z.length,regionRange:Z.regions.length>0?{end:D+Z.regions.length,start:D}:void 0,start:E},Q=F?.[Y];if(M.push(sE(Q,Z,X)?Q:U5(Z,X)),A=X.blockRange.end,D=X.regionRange?.end??D,Z.regions.length>0)E=X.end,$=!0}return M}function $2(N,F,M,A){let D=F.blocks.length-(N.roots.length-A);if(D<0)throw Error("Editor model splice received an invalid replacement count.");if(M===N.roots.length&&D===1){let Z=F.blocks[M];if(Z)return rE(N,F,Z)}let E=D===A,$=[...N.roots.slice(0,M),...F.blocks.slice(M,M+D).map((Z,X)=>a2(Z,M+X)),...E?N.roots.slice(M+A):F.blocks.slice(M+D).map((Z,X)=>a2(Z,M+D+X))],Y=w3($,N.roots);return j3(F,Y,N)}function rE(N,F,M){let A=N.roots.length,D=a2(M,A),E=N.roots.some((Q)=>Q.regions.length>0),$=D.regions.length>0&&E?N.length+1:N.length,Y=U5(D,{...D,blockRange:{end:N.blocks.length+D.blocks.length,start:N.blocks.length},end:$+D.length,regionRange:D.regions.length>0?{end:N.regions.length+D.regions.length,start:N.regions.length}:void 0,start:$}),Z=[...N.blocks,...Y.blocks],X=[...N.regions,...Y.regions];return{blockIndex:eE(N.blockIndex,Y.blocks),blocks:Z,commentContainerIndex:F.comments===N.document.comments?N.commentContainerIndex:V5(F),document:F,engine:"canvas",imageUrls:X$(N.imageUrls,Y.imageUrls),length:Y.end,listItemMarkers:F.blocks===N.document.blocks?N.listItemMarkers:E$(N.listItemMarkers,M),regionIndex:N$(N.regionIndex,Y.regions),regionOrderIndex:F$(N.regionOrderIndex,Y.regions,N.regions.length),regionPathIndex:M$(N.regionPathIndex,Y.regions),regions:X,roots:[...N.roots,Y],tableCellIndex:A$(N.tableCellIndex,Y.regions),tableCellRegionIndex:D$(N.tableCellRegionIndex,Y.regions),text:$$(N.text,Y)}}function TF(N,F){if(F.blocks!==N.document.blocks)throw Error("Editor model document replacement requires preserving root blocks.");return j3(F,N.roots,N)}function LF(N,F,M){let A=N.blockIndex.get(F);if(!A)return null;return e8(N.document,F,M,A.rootIndex)}function j3(N,F,M=null){let A=F.flatMap((Q)=>Q.blocks),D=F.flatMap((Q)=>Q.regions),{regionIndex:E,regionOrderIndex:$,regionPathIndex:Y,tableCellIndex:Z,tableCellRegionIndex:X}=tE(D);return{blockIndex:nE(A),blocks:A,commentContainerIndex:N.comments===M?.document.comments?M.commentContainerIndex:V5(N),document:N,engine:"canvas",imageUrls:Z$(F,M?.imageUrls),length:F.at(-1)?.end??0,listItemMarkers:N.blocks===M?.document.blocks?M.listItemMarkers:J$(N.blocks),regionIndex:E,regionOrderIndex:$,regionPathIndex:Y,regions:D,roots:F,tableCellIndex:Z,tableCellRegionIndex:X,text:Y$(F)}}function U5(N,F){let M=F.start-N.start;return{...F,blocks:M===0?N.blocks:iE(N.blocks,M),regions:M===0?N.regions:oE(N.regions,M)}}function sE(N,F,M){return Boolean(N&&F===N&&N.start===M.start&&N.end===M.end&&N.blockRange.start===M.blockRange.start&&N.blockRange.end===M.blockRange.end&&N.regionRange?.start===M.regionRange?.start&&N.regionRange?.end===M.regionRange?.end)}function iE(N,F){return N.map((M)=>({...M,end:M.end+F,start:M.start+F}))}function oE(N,F){return N.map((M)=>({...M,end:M.end+F,start:M.start+F}))}function nE(N){let F=new Map;for(let M of N)F.set(M.id,M);return F}function tE(N){let F=new Map,M=new Map,A=new Map,D=new Map,E=new Map;for(let[$,Y]of N.entries()){if(F.set(Y.id,Y),M.set(Y.id,$),A.set(Y.path,Y),!Y.tableCellPosition)continue;D.set(Y.id,Y.tableCellPosition),E.set(d2(Y.blockId,Y.tableCellPosition.rowIndex,Y.tableCellPosition.cellIndex),Y.id)}return{regionIndex:F,regionOrderIndex:M,regionPathIndex:A,tableCellIndex:D,tableCellRegionIndex:E}}function eE(N,F){let M=new Map(N);for(let A of F)M.set(A.id,A);return M}function N$(N,F){let M=new Map(N);for(let A of F)M.set(A.id,A);return M}function F$(N,F,M){let A=new Map(N);for(let[D,E]of F.entries())A.set(E.id,M+D);return A}function M$(N,F){let M=new Map(N);for(let A of F)M.set(A.path,A);return M}function A$(N,F){let M=new Map(N);for(let A of F)if(A.tableCellPosition)M.set(A.id,A.tableCellPosition);return M}function D$(N,F){let M=new Map(N);for(let A of F){if(!A.tableCellPosition)continue;M.set(d2(A.blockId,A.tableCellPosition.rowIndex,A.tableCellPosition.cellIndex),A.id)}return M}function E$(N,F){let M=new Map(N);return c2(M,[F]),M}function $$(N,F){if(F.regions.length===0)return N;return N.length>0?`${N}
|
|
11
|
+
${F.text}`:F.text}function Y$(N){return N.filter((F)=>F.regions.length>0).map((F)=>F.text).join(`
|
|
12
|
+
`)}function Z$(N,F){let M=new Set;for(let A of N)for(let D of A.imageUrls)M.add(D);return F&&Q$(F,M)?F:M}function X$(N,F){if(F.size===0)return N;let M=null;for(let A of F){if(N.has(A))continue;M??=new Set(N),M.add(A)}return M??N}function Q$(N,F){if(N.size!==F.size)return!1;for(let M of N)if(!F.has(M))return!1;return!0}function V5(N){let F=new Map;for(let[M,A]of N.comments.entries()){let D=p2(A,N).match?.containerId??null;if(!D)continue;let E=F.get(D)??[];E.push(M),F.set(D,E)}return F}function J$(N){let F=new Map;return c2(F,N),F}function c2(N,F,M=null){for(let A of F){if(A.type==="list"){for(let[D,E]of A.items.entries())c2(N,[E],{index:D,ordered:A.ordered,start:A.start});continue}if(A.type==="listItem"){if(typeof A.checked==="boolean")N.set(A.id,{checked:A.checked,kind:"task"});else if(M?.ordered)N.set(A.id,{kind:"ordered",label:`${(M.start??1)+M.index}.`});else N.set(A.id,{kind:"bullet",label:"•"});c2(N,A.children,M)}if(A.type==="blockquote")c2(N,A.children,M)}}function K$(N){if(N.blocks.length>0)return N;return M2([s({text:""})],N.comments,N.frontMatter)}function L3(N,F=null){let M=[],A=0,D=(E)=>{let $=A,Y=$+E.text.length;M.push({...E,end:Y,start:$}),A=Y};for(let E of N)switch(E.type){case"lineBreak":D({id:E.id,image:null,inlineCode:!1,kind:"lineBreak",link:F,marks:[],originalType:null,text:`
|
|
13
|
+
`});break;case"image":D({id:E.id,image:{alt:E.alt,title:E.title,url:E.url,width:E.width},inlineCode:!1,kind:"image",link:F,marks:[],originalType:null,text:q$(E.alt)});break;case"code":D({id:E.id,image:null,inlineCode:!0,kind:"code",link:F,marks:[],originalType:null,text:E.code});break;case"link":for(let $ of L3(E.children,{title:E.title,url:E.url}))D($);break;case"text":D({id:E.id,image:null,inlineCode:!1,kind:"text",link:F,marks:E.marks,originalType:null,text:E.text});break;case"raw":D({id:E.id,image:null,inlineCode:!1,kind:"raw",link:F,marks:[],originalType:E.originalType,text:E.source});break}return M}function q$(N){return l2}function P0(N){switch(N.type){case"lineBreak":return 1;case"image":return l2.length;case"code":return N.code.length;case"link":return F0(N.children).length;case"text":return N.text.length;case"raw":return N.source.length}}function A1(N){return`${N.path}.children.selected`}function g0(N,F,M,A){let D=`${N.path}.children`,E=wF(N.children,F,M,D,A),$=A.reduce((Z,X)=>Z+P0(X),0),Y=F+$;return r2(N,E,Y,Y)}function r2(N,F,M,A){switch(N.kind){case"inlineBlock":return{block:j0(N.block,F),blockId:N.block.id,selection:G5(`${N.path}.children`,M,A)};case"tableCell":{let D=q1({children:F,path:N.path}),E=N.block.rows.map(($)=>({...$,cells:$.cells.map((Y)=>Y.id===N.cell.id?D:Y)}));return{block:C0(N.block,E),blockId:N.block.id,selection:G5(N.path,M,A)}}}}function G5(N,F,M){return{endOffset:M,kind:"region-range-path",path:N,startOffset:F}}function wF(N,F,M,A,D){let E=[],$=0,Y=!1;for(let[Z,X]of N.entries()){let Q=`${A}.${Z}`,K=P0(X),J=$,q=J+K;if($=q,M<=J||F>=q){E.push(X);continue}if(!Y)E.push(...U$(X,Math.max(0,F-J),Q)),E.push(...D),Y=!0;E.push(...V$(X,Math.min(K,M-J),Q))}if(!Y)E.push(...D);return Q0(E)}function U$(N,F,M){if(F<=0)return[];return C3(N,0,F,`${M}.before`)}function V$(N,F,M){let A=P0(N);if(F>=A)return[];return C3(N,F,A,`${M}.after`)}function C3(N,F,M,A){if(F>=M)return[];switch(N.type){case"text":{let D=N.text.slice(F,M);return D.length>0?[w0({text:D,marks:N.marks,path:A})]:[]}case"code":return[K1({code:N.code.slice(F,M),path:A})];case"link":{let D=Q0(R3(N.children,F,M,`${A}.children`));return D.length>0?[{...N,children:D}]:[]}default:return[]}}function S3(N,F,M){let A=0,D="";for(let E of N){let $=P0(E),Y=A,Z=Y+$;if(A=Z,M<=Y||F>=Z)continue;D+=G$(E,Math.max(0,F-Y),Math.min($,M-Y))}return D}function R3(N,F,M,A){let D=[],E=0;for(let[$,Y]of N.entries()){let Z=P0(Y),X=E,Q=X+Z;if(E=Q,M<=X||F>=Q)continue;D.push(...C3(Y,Math.max(0,F-X),Math.min(Z,M-X),`${A}.${$}`))}return D}function G$(N,F,M){if(F>=M)return"";switch(N.type){case"lineBreak":return`
|
|
14
|
+
`.slice(F,M);case"image":return l2.slice(F,M);case"code":return N.code.slice(F,M);case"link":return S3(N.children,F,M);case"text":return N.text.slice(F,M);case"raw":return N.source.slice(F,M)}}function b3(N,F,M,A){let D=z$(N.children,F,M,A);if(D===null)return null;let E=Q0(z5(N.children,F,M,A,D,`${N.path}.children`));return E.length>0?r2(N,E,F,M):null}function v3(N,F,M){let A=0,D=null,E=($)=>{for(let Y of $){let Z=P0(Y),X=A,Q=X+Z;if(A=Q,M<=X||F>=Q)continue;if(Y.type==="text"){let K=Math.max(F,X);if(Math.min(M,Q)>K)D=D===null?new Set(Y.marks):new Set(Y.marks.filter((q)=>D?.has(q)));continue}if(Y.type==="link"){let K=A;A=X,E(Y.children),A=K}}};return E(N.children),D?[...D]:[]}function z$(N,F,M,A){let D=0,E=!1,$=!0,Y=(Z)=>{for(let X of Z){let Q=P0(X),K=D,J=K+Q;if(D=J,M<=K||F>=J)continue;if(X.type==="text"){let q=Math.max(F,K);if(Math.min(M,J)>q)E=!0,$&&=X.marks.includes(A);continue}if(X.type==="link"){let q=D;D=K,Y(X.children),D=q}}};return Y(N),E?$:null}function z5(N,F,M,A,D,E){let $=[],Y=0;for(let[Z,X]of N.entries()){let Q=Y,K=P0(X),J=Q+K,q=`${E}.${Z}`;if(Y=J,M<=Q||F>=J){$.push(X);continue}if(X.type==="text"){$.push(..._$(X,Math.max(0,F-Q),Math.min(K,M-Q),A,D,q));continue}if(X.type==="link"){let U=Q0(z5(X.children,Math.max(0,F-Q),Math.min(K,M-Q),A,D,`${q}.children`));if(U.length>0)$.push({...X,children:U});continue}$.push(X)}return $}function _$(N,F,M,A,D,E){let $=N.text.slice(0,F),Y=N.text.slice(F,M),Z=N.text.slice(M),X=D?N.marks.filter((J)=>J!==A):H$(N.marks,A),Q=[],K=(J,q,U)=>{if(J.length>0)Q.push(w0({text:J,marks:q,path:`${E}.${U}`}))};return K($,N.marks,"before"),K(Y,X,"selected"),K(Z,N.marks,"after"),Q}function H$(N,F){return N.includes(F)?N:[...N,F].sort()}function f3(N,F,M){let A=B$(N.children,F,M,`${N.path}.children`);return A.length>0?r2(N,A,F,M):null}function B$(N,F,M,A){let D=_5(N,F,M);if(D){let $=D.code.length>0?[w0({text:D.code,marks:[],path:`${A}.selected`})]:[];return wF(N,F,M,A,$)}let E=S3(N,F,M);if(E.length===0)return N;return wF(N,F,M,A,[K1({code:E,path:`${A}.selected`})])}function _5(N,F,M){let A=0;for(let D of N){let E=P0(D),$=A,Y=$+E;if(A=Y,F===$&&M===Y&&D.type==="code")return D;if(D.type==="link"){let Z=_5(D.children,Math.max(0,F-$),Math.min(E,M-$));if(Z)return Z}}return null}function m3(N,F,M,A){let D=R3(N.children,F,M,`${N.path}.children`);if(D.length===0)return null;return g0(N,F,M,[C1({children:D,path:A1(N),title:null,url:A})])}function k3(N,F,M,A){let D=H5(N.children,F,M);if(!D)return null;return g0(N,F,M,[C1({children:D.children,path:A1(N),title:D.title,url:A})])}function h3(N,F,M){let A=H5(N.children,F,M);if(!A)return null;return g0(N,F,M,A.children)}function H5(N,F,M){let A=0;for(let D of N){let E=P0(D);if(D.type==="link"&&A===F&&A+E===M)return D;A+=E}return null}function Y2(N,F){let M=N.regionIndex.get(F);if(!M)return null;let A=s0(N.document.blocks,M.blockId);if(!A)return null;return g3(A,M.path,M.semanticRegionId)}function g3(N,F,M){if(N.type==="heading"||N.type==="paragraph")return{block:N,children:N.children,kind:"inlineBlock",path:F.replace(/\.children$/,"")};if(N.type!=="table")return null;let A=/^(.*\.rows\.\d+\.cells\.\d+)$/.exec(F);if(!A)return null;for(let D of N.rows)for(let E of D.cells)if(E.id===M)return{block:N,blockPath:A[1].replace(/\.rows\.\d+\.cells\.\d+$/,""),cell:E,children:E.children,kind:"tableCell",path:A[1]};return null}function jF(N,F,M,A,D){if(M>=A)return null;let E=Y2(N,F);if(!E)return null;let $=D(E,M,A);return $?{kind:"replace-block",block:$.block,blockId:$.blockId,selection:$.selection}:null}function I3(N,F,M){let A=W5(N,F);if(!A)return null;let D=M(A1(A.inlineRegion));return{kind:"replace-block",...g0(A.inlineRegion,A.startOffset,A.endOffset,[D])}}function B5(N,F,M){let A=W5(N,F);if(!A)return null;return{kind:"replace-block",...g0(A.inlineRegion,A.startOffset,A.endOffset,M)}}function W5(N,F){let M=Y2(N,F.focus.regionId);if(!M)return null;return{inlineRegion:M,startOffset:Math.min(F.anchor.offset,F.focus.offset),endOffset:Math.max(F.anchor.offset,F.focus.offset)}}function z0(N,F,M=0){return{childIndices:F,kind:"descendant-primary-region",offset:M,rootIndex:N}}function e(N,F=0){return{kind:"root-primary-region",offset:F,rootIndex:N}}function u3(N,F=0){return{kind:"region",offset:F,regionId:N}}function h1(N,F,M,A=0){return{cellIndex:M,kind:"table-cell",offset:A,rootIndex:N,rowIndex:F}}function W0(N,F){return N.regionIndex.get(F)??null}function D2(N,F){return N.regionPathIndex.get(F)??null}function Q2(N,F,M,A){let D=N.tableCellRegionIndex.get(d2(F,M,A));return D?N.regionIndex.get(D)??null:null}function g1(N,F){let M=N.regionOrderIndex.get(F);if(M===void 0||M===0)return null;return N.regions[M-1]??null}function s2(N,F){let M=N.regionOrderIndex.get(F);if(M===void 0)return null;return N.regions[M+1]??null}function n0(N){return N.regionIds.length===0&&!U1(N)}function U1(N){return N.type==="blockquote"||N.type==="list"||N.type==="listItem"}function p3(N,F){return O5(N.blocks,F,-1)}function i2(N,F){return O5(N.blocks,F,1)}function O5(N,F,M){let A=N.findIndex((D)=>D.id===F);if(A===-1)return null;for(let D=A+M;D>=0&&D<N.length;D+=M){let E=N[D];if(U1(E))continue;return E}return null}function x3(N,F){return N.roots[F]?.regions[0]??null}function W$(N){return N.anchor.regionId===N.focus.regionId&&N.anchor.offset===N.focus.offset}function N0(N,F){let M="documentIndex"in N?N.documentIndex:N,A="documentIndex"in N?N.selection:F,D=W$(A),E=y5(M,A.anchor),$=y5(M,A.focus);if(E<=$)return{collapsed:D,end:A.focus,start:A.anchor};return{collapsed:D,end:A.anchor,start:A.focus}}function o2(N,F){if(!F)return null;if(F.kind==="root-primary-region"){let A=N.document.blocks[F.rootIndex],D=A?CF(N,A):null;return D?Z2(D.id,X2(D.text,F.offset)):null}if(F.kind==="descendant-primary-region"){let A=N.document.blocks[F.rootIndex],D=A?y$(A,F.childIndices):null,E=D?CF(N,D):null;return E?Z2(E.id,X2(E.text,F.offset)):null}if(F.kind==="region"){let A=W0(N,F.regionId);return A?Z2(A.id,X2(A.text,F.offset)):null}if(F.kind==="block-primary-region"){let A=s0(N.document,F.blockId),D=A?CF(N,A):null;return D?Z2(D.id,X2(D.text,F.offset)):null}if(F.kind==="table-cell"){let A=N.document.blocks[F.rootIndex];if(!A||A.type!=="table")return null;let D=Q2(N,A.id,F.rowIndex,F.cellIndex);return D?Z2(D.id,X2(D.text,F.offset)):null}let M=D2(N,F.path);if(!M)return null;if(F.kind==="region-path")return Z2(M.id,X2(M.text,F.offset));return{anchor:{regionId:M.id,offset:Math.max(0,Math.min(F.startOffset,M.text.length))},focus:{regionId:M.id,offset:Math.max(0,Math.min(F.endOffset,M.text.length))}}}function Z2(N,F){let M={offset:F,regionId:N};return{anchor:M,focus:M}}function y5(N,F){let M=N.regionOrderIndex.get(F.regionId);if(M===void 0)throw Error(`Unknown canvas region: ${F.regionId}`);return M*q5+F.offset}function X2(N,F){return F==="end"?N.length:Math.max(0,Math.min(F,N.length))}function y$(N,F){let M=N;for(let A of F){if(!M)return null;let D=G0(M);if(!D)return null;M=D[A]??null}return M}function CF(N,F){let M=N.blockIndex.get(F.id);if(!M)return null;let A=M.regionIds[0];if(A)return N.regionIndex.get(A)??null;let D=G0(F);if(!D)return null;for(let E of D){let $=CF(N,E);if($)return $}return null}function SF(N){let F=N.documentIndex.regionIndex.get(N.selection.anchor.regionId)??null,M=F?N.documentIndex.blockIndex.get(F.blockId)??null:null,A=P5(N);return{block:M?{blockId:M.id,depth:M.depth,nodeType:M.type,text:F?.text??""}:null,span:A?.link?{kind:"link",url:A.link.url}:A&&A.marks.length>0?{kind:"marks",marks:A.marks}:{kind:"none"}}}function RF(N){let F=P5(N);return F?.kind==="image"?F:null}function bF(N){let F=N0(N.documentIndex,N.selection);if(F.start.regionId!==F.end.regionId||F.start.offset===F.end.offset)return[];let M=N.documentIndex.regionIndex.get(F.start.regionId);if(!M)return[];let A=s0(N.documentIndex.document.blocks,M.blockId);if(!A)return[];let D=g3(A,M.path,M.semanticRegionId);return D?v3(D,F.start.offset,F.end.offset):[]}function P5(N){let F=N.documentIndex.regionIndex.get(N.selection.anchor.regionId)??null;if(!F)return null;let M=N.selection.anchor.offset;return F.inlines.find((A)=>M>A.start&&M<A.end)??F.inlines.find((A)=>A.end===M)??F.inlines.find((A)=>A.start===M)??null}var fF="rgba(0, 0, 0, 0)";function J2(N,F,M){let A=T5(N),D=T5(F);return`rgba(${d3(vF(A[0],D[0],M))}, ${d3(vF(A[1],D[1],M))}, ${d3(vF(A[2],D[2],M))}, ${vF(A[3],D[3],M)})`}var l3=new Map([["rgba(0, 0, 0, 0)",[0,0,0,0]]]);function T5(N){let F=l3.get(N);if(F)return F;let M=O$(N)??P$(N)??T$(N)??l3.get("rgba(0, 0, 0, 0)");return l3.set(N,M),M}function O$(N){let F=N.trim();if(!F.startsWith("#"))return null;let M=F.slice(1);if(M.length===3)return[Number.parseInt(`${M[0]}${M[0]}`,16),Number.parseInt(`${M[1]}${M[1]}`,16),Number.parseInt(`${M[2]}${M[2]}`,16),1];if(M.length===6)return[Number.parseInt(M.slice(0,2),16),Number.parseInt(M.slice(2,4),16),Number.parseInt(M.slice(4,6),16),1];return null}function P$(N){let F=/^rgb\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec(N.trim());if(!F)return null;return[Number(F[1]),Number(F[2]),Number(F[3]),1]}function T$(N){let F=/^rgba\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec(N.trim());if(!F)return null;return[Number(F[1]),Number(F[2]),Number(F[3]),Number(F[4])]}function vF(N,F,M){return N+(F-N)*M}function d3(N){return Math.round(N)}var L$=300,w$=180,j$=1000,C$=500,S$=140,R$=0.1,b$=0.9,v$=2,f$=2;function n2(N){switch(N.kind){case"active-block-flash":return L$;case"deleted-text-fade":return w$;case"inserted-text-highlight":return j$;case"list-marker-pop":return C$;case"punctuation-pulse":return S$}}function c3(N,F){let M=F??k$();return N.animations.some((A)=>M-A.startedAt<n2(A))}function L5(N,F){return a3(N,F,"inserted-text-highlight",(M)=>M.regionPath)}function w5(N,F){return h5(N,F,"active-block-flash",(M)=>M.blockPath)}function j5(N,F){return a3(N,F,"deleted-text-fade",(M)=>M.regionPath)}function C5(N,F){return a3(N,F,"punctuation-pulse",(M)=>M.regionPath)}function S5(N,F){return h5(N,F,"list-marker-pop",(M)=>M.blockPath)}function R5(N,F,M){let A=new Set([N,F]);for(let D of M){if(D.endOffset<=N||D.startOffset>=F)continue;A.add(Math.max(N,D.startOffset)),A.add(Math.min(F,D.endOffset))}return[...A].sort((D,E)=>D-E)}function b5(N,F,M){return N.find((A)=>A.startOffset<M&&A.endOffset>F)??null}function v5(N,F,M){if(!F)return N;return J2(M.insertHighlightText,N,F.progress)}function f5(N,F){return J2(N,fF,F.progress)}function mF(N,F){return J2(N,fF,F.progress)}function m5(N,F){return J2(F.insertHighlightText,fF,N.progress)}function k5(N){let F=Math.min(1,N.progress*v$);return R$+b$*m$(F)}function t2(N,F,M){let A=Math.max(0,F.progress*f$-1);return J2(M.insertHighlightText,N,A)}function a3(N,F,M,A){let D=new Map;for(let E of N.animations){if(E.kind!==M)continue;let $=n2(E),Y=F-E.startedAt;if(Y>=$)continue;let Z={...E,progress:Math.max(0,Math.min(1,Y/$))},X=A(E),Q=D.get(X);if(Q)Q.push(Z);else D.set(X,[Z])}return D}function h5(N,F,M,A){let D=new Map;for(let E of N.animations){if(E.kind!==M)continue;let $=n2(E),Y=F-E.startedAt;if(Y>=$)continue;D.set(A(E),{...E,progress:Math.max(0,Math.min(1,Y/$))})}return D}function m$(N){return 1-(1-N)*(1-N)*(1-N)}function k$(){return typeof performance<"u"?performance.now():Date.now()}function kF(N,F,M=I1()){if(F<=0)return N;let A=gF(N);if(!A)return N;let D=N.selection.focus.offset,E=Math.max(0,D-F);if(D<=E)return N;return e2(N,{endOffset:D,kind:"inserted-text-highlight",regionPath:A.path,startOffset:E,startedAt:M})}function g5(N,F,M,A){let D=gF(N);if(!D)return F;let E=D.text.slice(M,A);if(E.length===0)return F;if(!D.inlines.some((Y)=>Y.start<=M&&Y.end>=A&&Y.kind==="text"&&Y.link===null&&Y.marks.length===0))return F;return e2(F,{kind:"deleted-text-fade",regionPath:D.path,startOffset:M,startedAt:I1(),text:E})}function I5(N,F=I1()){let M=gF(N),A=N.selection.focus.offset-1;if(!M||A<0||M.text[A]!==".")return N;return e2(N,{kind:"punctuation-pulse",offset:A,regionPath:M.path,startedAt:F})}function u5(N,F,M=I1()){return e2(N,{blockPath:F,kind:"list-marker-pop",startedAt:M})}function p5(N,F,M=I1()){return e2(N,{blockPath:F,kind:"active-block-flash",startedAt:M})}function r3(N,F){return N.filter((M)=>M.startedAt+n2(M)>F)}function I1(){return typeof performance<"u"?performance.now():Date.now()}function hF(N,F){let M=Math.max(-1/0,...N.animations.map((A)=>A.startedAt));return F.animations.some((A)=>A.startedAt>M)}function x5(N){let F=gF(N);return(F?N.documentIndex.blockIndex.get(F.blockId)??null:null)?.path??""}function gF(N){return N.documentIndex.regionIndex.get(N.selection.focus.regionId)??null}function e2(N,F){let M=r3(N.animations,F.startedAt);return{...N,animations:[...M,F]}}function K2(N,F,M,A){return i3(q2(N.inlines,F,M,A))}function q2(N,F,M,A){let E=h$(N,F,M,{didInsert:!1,generatedRunCount:0,replacementText:A});return x$(l$(E))}function i3(N){let F=[];for(let M=0;M<N.length;M+=1){let A=N[M];if(A.link){let E=[],$=A.link;while(M<N.length&&o3(N[M].link,$)){let Y=d5(N[M]);if(Y)E.push(Y);M+=1}if(M-=1,E.length>0)F.push(C1({children:Q0(E),title:$.title,url:$.url}));continue}let D=d5(A);if(D)F.push(D)}return Q0(F)}function h$(N,F,M,A){let D=[];for(let[E,$]of N.entries()){if(!A.didInsert&&F===M&&F===$.start)s3(D,A,l5(N[E-1]??null,$));if(M<=$.start||F>=$.end){D.push(IF($));continue}let Y=Math.max(0,F-$.start),Z=Math.min($.text.length,M-$.start),X=!A.didInsert&&A.replacementText.length>0?A.replacementText:"",Q=g$($,Y,Z,X,A);if(Y!==Z||X.length>0)A.didInsert=!0;D.push(...Q)}if(!A.didInsert)s3(D,A,l5(N.at(-1)??null,null));return D}function g$(N,F,M,A,D){switch(N.kind){case"text":case"code":case"raw":return I$(N,F,M,A);case"lineBreak":return u$(N,F,M,A,D);case"image":return p$(N,F,M,A)}}function I$(N,F,M,A){let D=N.text.slice(0,F)+A+N.text.slice(M);return D.length>0?[{...IF(N),text:D}]:[]}function u$(N,F,M,A,D){if(F===M)return[IF(N)];let E=[];if(A.length>0)s3(E,D,N.link);return E}function p$(N,F,M,A){if(F===0&&M===N.text.length)return A.length>0?[c5(A,N.link,0)]:[];return[IF(N)]}function s3(N,F,M){if(F.replacementText.length===0){F.didInsert=!0;return}N.push(c5(F.replacementText,M,F.generatedRunCount)),F.generatedRunCount+=1,F.didInsert=!0}function c5(N,F,M){return{id:`generated:${M}`,image:null,inlineCode:!1,kind:"text",link:F,marks:[],originalType:null,text:N}}function l5(N,F){return N?.link&&F?.link&&o3(N.link,F.link)?N.link:null}function IF(N){return{id:N.id,image:N.image,inlineCode:N.inlineCode,kind:N.kind,link:N.link,marks:N.marks,originalType:N.originalType,text:N.text}}function x$(N){let F=[],M=0;for(let A of N){let D=M,E=D+A.text.length;F.push({...A,end:E,start:D}),M=E}return F}function l$(N){let F=[];for(let M of N){let A=F.at(-1);if(A&&d$(A,M)){F[F.length-1]={...A,text:A.text+M.text};continue}F.push(M)}return F}function d$(N,F){return N.kind===F.kind&&N.inlineCode===F.inlineCode&&o3(N.link,F.link)&&a$(N.image,F.image)&&N.originalType===F.originalType&&N.marks.join(",")===F.marks.join(",")}function d5(N){switch(N.kind){case"lineBreak":return a0();case"image":return N.image?c$(N.image):null;case"code":return K1({code:N.text});case"text":return N.text.length>0?w0({marks:N.marks,text:N.text}):null;case"raw":return GF({originalType:N.originalType??"raw",source:N.text})}}function c$(N){return S1({alt:N.alt,title:N.title,url:N.url,width:N.width})}function o3(N,F){return N?.url===F?.url&&N?.title===F?.title}function a$(N,F){return N?.url===F?.url&&N?.title===F?.title&&N?.alt===F?.alt&&N?.width===F?.width}function i5(N,F,M){let A=[],D=0,E={childIndices:[],offset:0},$="",Y=N!==null;if(N)A.push(N),E=a5(N);let Z=0;if(N&&F.length>0){let X=F[0];if(uF(N)&&X.type==="paragraph"){let Q=n3(N,N.children,X.children);A[A.length-1]=Q,E={childIndices:[],offset:Q.plainText.length},Z=1,$=X.plainText}else if(r5(N,X)){let Q=s5(N,X);A[A.length-1]=Q,E=o5(Q),Z=1}}for(let X=Z;X<F.length;X+=1){let Q=F[X];A.push(Q),D=A.length-1,E=a5(Q)}if(M){let X=A.length-1,Q=A[X]??null,K=Z>=F.length&&N!==null,J=null;if(Q){if(!K&&Q.type==="paragraph"&&uF(M)){if(J=n3(M,Q.children,M.children),N===null&&F.length===1)Y=!0,$=Q.plainText}else if(K&&uF(Q)&&uF(M))J=n3(Q,Q.children,M.children);else if(r5(Q,M))J=s5(Q,M),E={childIndices:[G0(Q).length-1],offset:"end"}}else if(N===null&&F.length===0)Y=!0;if(J)A[X]=J;else A.push(M)}return{blocks:A,caretLocalIndex:D,caretChildIndices:E.childIndices,caretOffset:E.offset,startRegionInsertedText:$,startRegionPreservedAtRoot0:Y}}function NN(N,F,M){if(N.type==="table")return null;if(N.id===F.blockId)return r$(N,F,M);return n5(N,(A)=>i$(A,F,M))}function FN(N,F,M){if(N.type==="table")return null;if(N.id===F.blockId)return s$(N,F,M);return n5(N,(A)=>o$(A,F,M))}function u1(N,F){if(N.id===F.blockId)return!0;let M=G0(N);return M!==null&&M.some((A)=>u1(A,F))}function a5(N){return G0(N)?o5(N):{childIndices:[],offset:N.plainText.length}}function o5(N){return{childIndices:[G0(N).length-1],offset:"end"}}function n3(N,F,M){return j0(N,Q0([...F,...M]))}function uF(N){return N!==null&&(N.type==="heading"||N.type==="paragraph")}function r5(N,F){return N.type===F.type&&G0(N)!==null}function s5(N,F){let M=G0(N),A=G0(F);return k1(N,[...M,...A])}function r$(N,F,M){if(M===0)return null;switch(N.type){case"heading":case"paragraph":return j0(N,K2(F,M,F.text.length,""));case"code":return h2(N,F.text.slice(0,M));case"raw":return g2(N,F.text.slice(0,M));default:return null}}function s$(N,F,M){if(M===F.text.length)return null;switch(N.type){case"heading":case"paragraph":return j0(N,K2(F,0,M,""));case"code":return h2(N,F.text.slice(M));case"raw":return g2(N,F.text.slice(M));default:return null}}function n5(N,F){let M=G0(N);return M?k1(N,F(M)):null}function i$(N,F,M){let A=N.findIndex(($)=>u1($,F));if(A===-1)return[];let D=N.slice(0,A),E=NN(N[A],F,M);return E?[...D,E]:D}function o$(N,F,M){let A=N.findIndex(($)=>u1($,F));if(A===-1)return[];let D=N.slice(A+1),E=FN(N[A],F,M);return E?[E,...D]:D}function e5(N,F,M){let A=N0(N,F);if(A.start.regionId===A.end.regionId)return n$(N,A,M);let D=M.length>0?[s({text:M})]:[];return t3(N,F,D)}function t3(N,F,M){let A=N0(N,F),D=W0(N,A.start.regionId),E=W0(N,A.end.regionId);if(!D||!E)throw Error("Unknown selection endpoints.");let $=N.document.blocks[D.rootIndex],Y=N.document.blocks[E.rootIndex];if(!$||!Y)throw Error("Unknown root blocks for selection.");let Z=NN($,D,A.start.offset),X=FN(Y,E,A.end.offset),Q=i5(Z,M,X),K=Q.blocks.length>0?Q.blocks:[s({text:""})],J=D.rootIndex,q=E.rootIndex-D.rootIndex+1,U=m1(N.document,J,q,K),V=$2(N,U,J,q),G=D===E?A.end.offset:D.text.length;return{documentIndex:Q.startRegionPreservedAtRoot0?N9(N,V,D,A.start.offset,G,Q.startRegionInsertedText):V,selection:z0(J+Q.caretLocalIndex,Q.caretChildIndices,Q.caretOffset)}}function n$(N,F,M){let A=W0(N,F.start.regionId);if(!A)throw Error(`Unknown region: ${F.start.regionId}`);let D=LF(N,A.blockId,(Z)=>t$(Z,A,F.start.offset,F.end.offset,M));if(!D)throw Error(`Failed to replace block for region: ${A.id}`);let E=$2(N,D,A.rootIndex,1),$=N9(N,E,A,F.start.offset,F.end.offset,M),Y=D2($,A.path);if(!Y)throw Error(`Failed to remap region after replacement: ${A.path}`);return{documentIndex:$,selection:u3(Y.id,F.start.offset+M.length)}}function t$(N,F,M,A,D){switch(N.type){case"heading":case"paragraph":return j0(N,K2(F,M,A,D));case"code":return h2(N,t5(F,M,A,D));case"table":return e$(N,F,M,A,D);case"raw":return g2(N,t5(F,M,A,D));default:throw Error(`Region text replacement is not supported for block type: ${N.type}`)}}function e$(N,F,M,A,D){let E=F.tableCellPosition?.rowIndex,$=F.tableCellPosition?.cellIndex;if(E===void 0||$===void 0)throw Error(`Unable to resolve table cell position for region: ${F.id}`);let Y=K2(F,M,A,D),Z=N.rows.map((X,Q)=>{if(Q!==E)return X;let K=X.cells.map((J,q)=>q===$?q1({children:Y}):J);return{...X,cells:K}});return C0(N,Z)}function t5(N,F,M,A){return q2(N.inlines,F,M,A).map((D)=>D.text).join("")}function N9(N,F,M,A,D,E){if(N.document.comments.length===0)return F;let $=T3(N,F,M,A,D,E);return $===F.document.comments?F:TF(F,{...F.document,comments:$})}function AN(N){let F=E2(N),M=D9(F);return{animations:[],documentIndex:F,future:[],history:[],selection:{anchor:M,focus:M}}}function S0(N){let F=o0(N.documentIndex);return M2(M5(N.documentIndex.document.blocks),F.threads,N.documentIndex.document.frontMatter)}function I0(N,F){if(!F)return null;switch(F.kind){case"keep-state":return N;case"set-selection":return D0(N,F.selection);case"replace-block":{let M=LF(N.documentIndex,F.blockId,()=>F.block);return M?MN(N,E2(M),F.selection??null):null}case"splice-blocks":{let M=m1(N.documentIndex.document,F.rootIndex,F.count??1,F.blocks);return MN(N,E2(M),F.selection??null)}case"splice-text":{let M=e5(N.documentIndex,F.selection,F.text);return MN(N,M.documentIndex,M.selection)}case"splice-fragment":{let M=t3(N.documentIndex,F.selection,F.blocks);return MN(N,M.documentIndex,M.selection)}case"splice-comments":{let M=t8(N.documentIndex.document,F.index,F.count,F.threads);return MN(N,TF(N.documentIndex,M),null)}}}function MN(N,F,M){let A=NY(N,F),D=o2(A.documentIndex,M)??N.selection,E=E9(N,A,D);return D0(A,D,E)}function D0(N,F,M){let A="regionId"in F?{anchor:pF(N.documentIndex,F),focus:pF(N.documentIndex,F)}:{anchor:pF(N.documentIndex,F.anchor),focus:pF(N.documentIndex,F.focus)},D={...N,selection:A};return M??E9(N,D)?p5(D,x5(D)):D}function y0(N,F,M,A){let D={regionId:F,offset:M};return D0(N,A?{anchor:N.selection.anchor,focus:D}:D)}function NY(N,F){let M=D9(F);return{animations:r3(N.animations,I1()),documentIndex:F,future:[],history:[...N.history,{document:N.documentIndex.document,selection:N.selection}],selection:{anchor:M,focus:M}}}function e3(N){let F=N.history.at(-1);if(!F)return N;return A9(F,{future:[M9(N),...N.future],history:N.history.slice(0,-1)})}function N4(N){let F=N.future[0];if(!F)return N;return A9(F,{future:N.future.slice(1),history:[...N.history,M9(N)]})}function M9(N){return{document:N.documentIndex.document,selection:N.selection}}function A9(N,F){return{animations:[],documentIndex:E2(N.document),future:F.future,history:F.history,selection:N.selection}}function D9(N){return N.regions[0]?{regionId:N.regions[0].id,offset:0}:{regionId:"empty",offset:0}}function pF(N,F){let M=W0(N,F.regionId);if(!M)return F;return{regionId:M.id,offset:Math.max(0,Math.min(F.offset,M.text.length))}}function E9(N,F,M){let A=F9(N.documentIndex,N.selection),D=F9(F.documentIndex,M??F.selection);return D!==null&&D!==A}function F9(N,F){let M=N.regionIndex.get(F.focus.regionId),A=M?N.blockIndex.get(M.blockId)??null:null;if(!M||!A?.path)return null;return A.type==="table"?`cell:${M.path}`:`block:${A.path}`}function $N(N,F){let M=N.regionIndex.get(F.anchor.regionId);if(!M)return{kind:"unsupported"};if(M.blockType==="code"){let Y=N.blockIndex.get(M.blockId);return Y?{kind:"code",region:M,rootIndex:Y.rootIndex,...EN(N,M,F)}:{kind:"unsupported"}}let A=M4(N,M.id);if(A)return{kind:"tableCell",...A,...EN(N,M,F)};let D=V2(N,F);if(D)return{kind:"listItem",...D};let E=FY(N,F);if(E)return{kind:"blockquoteTextBlock",...E};let $=U2(N,F);if($)return{kind:"rootTextBlock",...$};return{kind:"unsupported"}}function $9(N,F,M){let A=$N(N,F),D=A.kind==="unsupported"?!1:M==="backward"?A.atStart:A.atEnd;switch(A.kind){case"rootTextBlock":return{...A,kind:"rootTextBlock",direction:M,atBoundary:D,previousRoot:N.document.blocks[A.rootIndex-1]??null,nextRoot:N.document.blocks[A.rootIndex+1]??null};case"listItem":return{...A,kind:"listItem",direction:M,atBoundary:D,previousItem:A.list.items[A.itemIndex-1]??null,nextItem:A.list.items[A.itemIndex+1]??null,previousRoot:N.document.blocks[A.rootIndex-1]??null,nextRoot:N.document.blocks[A.rootIndex+1]??null};case"blockquoteTextBlock":return{...A,kind:"blockquoteTextBlock",direction:M,atBoundary:D,previousSibling:A.quote.children[A.childIndex-1]??null,nextSibling:A.quote.children[A.childIndex+1]??null};default:return{kind:"unsupported",direction:M,atBoundary:!1}}}function F4(N,F,M){let A=F?N.blockIndex.get(F)??null:null;while(A){if(A.type===M)return A;let D=A.parentBlockId;A=D?N.blockIndex.get(D)??null:null}return null}function V1(N){let F=N.split("."),M=[];for(let A=0;A<F.length-1;A+=1)if(F[A]==="children"){let D=Number(F[A+1]);if(Number.isInteger(D))M.push(D)}return M}function U2(N,F){let M=N.regionIndex.get(F.anchor.regionId);if(!M)return null;let A=N.blockIndex.get(M.blockId);if(!A)return null;let D=A.rootIndex,E=N.document.blocks[D];if(!E||E.type!=="heading"&&E.type!=="paragraph")return null;return{...EN(N,M,F),block:E,region:M,rootIndex:D}}function FY(N,F){let M=N.regionIndex.get(F.anchor.regionId);if(!M)return null;let A=N.blockIndex.get(M.blockId),D=F4(N,A?.id??null,"blockquote");if(!A||!D||A.parentBlockId!==D.id)return null;let E=D.rootIndex,$=N.document.blocks[E];if(!$||$.type!=="blockquote")return null;let Y=$.children.findIndex((X)=>X.id===A.id),Z=$.children[Y];if(!Z||Z.type!=="heading"&&Z.type!=="paragraph")return null;return{...EN(N,M,F),block:Z,blockChildIndices:V1(A.path),childIndex:Y,region:M,quote:$,rootIndex:E}}function DN(N,F){return s0(N.document.blocks,F)}function V2(N,F){let M=N.regionIndex.get(F.anchor.regionId);if(!M)return null;let A=N.blockIndex.get(M.blockId),D=F4(N,A?.id??null,"listItem"),E=F4(N,A?.id??null,"list");if(!A||!D||!E)return null;let $=DN(N,E.id);if(!$||$.type!=="list")return null;let Y=$.items.findIndex((U)=>U.id===D.id),Z=$.items[Y];if(!Z)return null;let X=E.parentBlockId?N.blockIndex.get(E.parentBlockId)??null:null,Q=X?.parentBlockId?N.blockIndex.get(X.parentBlockId)??null:null,K=X?.type==="listItem"?DN(N,X.id):null,J=Q?.type==="list"?DN(N,Q.id):null,q=J?.type==="list"&&K?J.items.findIndex((U)=>U.id===K.id):-1;return{...EN(N,M,F),region:M,item:Z,itemChildIndices:V1(D.path),itemIndex:Y,list:$,listChildIndices:V1(E.path),parentItem:K?.type==="listItem"?K:null,parentItemChildIndices:X?.type==="listItem"?V1(X.path):null,parentItemIndex:q>=0?q:null,parentList:J?.type==="list"?J:null,parentListChildIndices:Q?.type==="list"?V1(Q.path):null,rootIndex:E.rootIndex}}function M4(N,F){let M=N.regionIndex.get(F);if(!M)return null;let A=N.tableCellIndex.get(M.id),D=N.blockIndex.get(M.blockId),E=D?.type==="table"?N.document.blocks[D.rootIndex]:null;if(!A||!D||!E||E.type!=="table")return null;return{cellIndex:A.cellIndex,region:M,rootIndex:D.rootIndex,rowIndex:A.rowIndex,table:E}}function EN(N,F,M){let A=N0(N,M),D=A.start.regionId===F.id?A.start.offset:M.anchor.offset;return{atEnd:D===F.text.length,atStart:D===0,empty:F.text.length===0,offset:D}}function YN(N,F,M){return R1({checked:F,children:[s({text:N})],spread:M})}function Y9(N,F){let M=N.children[0];if(!M||M.type!=="paragraph")return null;return r0(N,[s({text:F}),...N.children.slice(1)])}function Z9(N,F){return F.reduce((M,A)=>`${M}.children.${A}`,`root.${N}`)}function X9(N,F){if(N.selection.anchor.regionId!==N.selection.focus.regionId||N.selection.anchor.offset!==N.selection.focus.offset)return null;let M=W0(N.documentIndex,N.selection.focus.regionId);if(!M)return null;if(F==="forward"&&N.selection.focus.offset>=M.text.length)return null;let A=F==="backward"?MY(M.text,N.selection.focus.offset):N.selection.focus.offset,D=F==="backward"?N.selection.focus.offset:AY(M.text,N.selection.focus.offset);if(A===D)return null;return{kind:"splice-text",selection:{anchor:{regionId:M.id,offset:A},focus:{regionId:M.id,offset:D}},text:""}}function MY(N,F){let M=Array.from(N.slice(0,F));if(M.length===0)return 0;return F-M.at(-1).length}function AY(N,F){let M=Array.from(N.slice(F))[0];return M?F+M.length:N.length}function Q9(N,F,M){if(F.anchor.regionId!==F.focus.regionId)return null;let A=N.regionIndex.get(F.anchor.regionId);if(!A)return null;let D=EY(N,F,A);if(!D)return null;let{start:E,end:$}=DY(N,F);return $Y(A,M,E,$,D)}function DY(N,F){if(F.anchor.offset===F.focus.offset)return{start:F.anchor.offset,end:F.anchor.offset};let M=N0(N,F);return{start:M.start.offset,end:M.end.offset}}function EY(N,F,M){switch(M.blockType){case"heading":{let A=U2(N,F);return A?.block.type==="heading"?{kind:"heading",rootIndex:A.rootIndex}:null}case"paragraph":{let A=V2(N,F);if(A)return{kind:"list-item",item:A};let D=U2(N,F);return D?.block.type==="paragraph"?{kind:"root-paragraph",rootIndex:D.rootIndex}:null}default:return null}}function $Y(N,F,M,A,D){if(D.kind==="root-paragraph"&&!YY(N,F,A))return null;let E=N.text.slice(0,M)+F+N.text.slice(A);switch(D.kind){case"root-paragraph":return A4(ZY,E,D);case"heading":return A4(XY,E,D);case"list-item":return A4(QY,E,D.item)}}function YY(N,F,M){let A=M<N.text.length?N.text:F;return A.length>0&&/\s/.test(A[A.length-1])}function A4(N,F,M){for(let{pattern:A,apply:D}of N){let E=A.exec(F);if(E)return D(E,M)}return null}var ZY=[{pattern:G2(/\[[ xX]?\]/,{allowIndent:!0}),apply:(N,{rootIndex:F})=>D4(F,{checked:N[1].toLowerCase().includes("x"),ordered:!1,start:null})},{pattern:G2(/[-+*]/,{allowIndent:!0}),apply:(N,{rootIndex:F})=>D4(F,{checked:null,ordered:!1,start:null})},{pattern:G2(/\d+\./,{allowIndent:!0}),apply:(N,{rootIndex:F})=>D4(F,{checked:null,ordered:!0,start:Number(N[1].slice(0,-1))})},{pattern:G2(/#{1,6}/,{allowIndent:!1}),apply:(N,{rootIndex:F})=>({kind:"splice-blocks",blocks:[t1({depth:N[1].length,text:""})],rootIndex:F,selection:e(F)})},{pattern:G2(/>/,{allowIndent:!1}),apply:(N,{rootIndex:F})=>({kind:"splice-blocks",blocks:[m0({children:[s({text:""})]})],rootIndex:F,selection:z0(F,[0])})},{pattern:G2(/---/,{allowIndent:!1}),apply:(N,{rootIndex:F})=>({kind:"splice-blocks",blocks:[zF(),s({text:""})],rootIndex:F,selection:e(F+1)})}],XY=[{pattern:xF(/#{1,6}/),apply:(N,{rootIndex:F})=>({kind:"splice-blocks",blocks:[t1({depth:N[1].length,text:N[2]})],rootIndex:F,selection:e(F)})}],QY=[{pattern:xF(/\d+\./),apply:(N,F)=>E4(N,F,{ordered:!0,start:1,checked:F.item.checked})},{pattern:xF(/\[[ xX]?\]/),apply:(N,F)=>E4(N,F,{ordered:!1,start:null,checked:N[1].toLowerCase().includes("x")})},{pattern:xF(/[-+*]/),apply:(N,F)=>E4(N,F,{ordered:!1,start:null,checked:null})}];function G2(N,F){let M=F.allowIndent?"\\s*":"";return new RegExp(`^${M}(${N.source})\\s$`)}function xF(N){return new RegExp(`^\\s*(${N.source})\\s(.+)$`)}function D4(N,F){return{kind:"splice-blocks",blocks:[b1({items:[R1({checked:F.checked,children:[s({text:""})],spread:!1})],ordered:F.ordered,spread:!1,start:F.start})],rootIndex:N,selection:z0(N,[0,0])}}function E4(N,F,M){let A=Y9(F.item,N[2]);if(!A)return null;return{kind:"replace-block",block:Y0(F.list,F.list.items.map((D,E)=>E===F.itemIndex?{...A,checked:M.checked}:D),{ordered:M.ordered,start:M.start}),blockId:F.list.id,selection:z0(F.rootIndex,[...F.listChildIndices,F.itemIndex,0])}}function J9(N,F,M){return Q9(N,F,M)??{kind:"splice-text",selection:F,text:M}}function K9(N,F){let M=N.region.text.length,A=N.region.text.slice(0,F),D=N.region.text.slice(F),E=F===0&&M>0?N.rootIndex:N.rootIndex+1;return{kind:"splice-blocks",blocks:V9(N.block,A,D,F,M),rootIndex:N.rootIndex,selection:e(E)}}function q9(N,F){let M=N.region.text,A=M.slice(0,F),D=M.slice(F),E=V9(N.block,A,D,F,M.length),$=F===0?N.blockChildIndices:[...N.blockChildIndices.slice(0,-1),N.blockChildIndices.at(-1)+1];return{kind:"splice-blocks",blocks:[m0({children:[...N.quote.children.slice(0,N.childIndex),...E,...N.quote.children.slice(N.childIndex+1)]})],rootIndex:N.rootIndex,selection:z0(N.rootIndex,$)}}function U9(N,F){if(F!==0||N.region.text.length!==0||N.block.type!=="paragraph")return null;let M=N.quote.children.slice(0,N.childIndex),A=N.quote.children.slice(N.childIndex+1),D=[];if(M.length>0)D.push(m0({children:M}));if(D.push(s({text:""})),A.length>0)D.push(m0({children:A}));return{kind:"splice-blocks",blocks:D,rootIndex:N.rootIndex,selection:e(N.rootIndex+(M.length>0?1:0))}}function $4(N,F,M){if(N.block.type!=="heading")return null;let A=Math.max(1,Math.min(6,N.block.depth+F));if(A===N.block.depth)return{kind:"keep-state"};return{kind:"splice-blocks",blocks:[t1({depth:A,text:N.block.plainText})],rootIndex:N.rootIndex,selection:e(N.rootIndex,M)}}function V9(N,F,M,A,D){if(A===0)return[s({text:""}),N];if(A===D)return[N,s({text:""})];return[N.type==="heading"?t1({depth:N.depth,text:F}):s({text:F}),s({text:M})]}function ZN(N,F,M,A=0){return z0(N,[...F,M,0],A)}function Y4(N,F){let M=N.region.text,A=N.item,D=typeof A.checked==="boolean"?!1:A.checked;if(F===0){let X=YN("",D,A.spread);return{kind:"replace-block",block:Y0(N.list,[...N.list.items.slice(0,N.itemIndex),X,A,...N.list.items.slice(N.itemIndex+1)]),blockId:N.list.id,listItemInsertedPath:lF(X,N.rootIndex,[...N.listChildIndices,N.itemIndex]),selection:ZN(N.rootIndex,N.listChildIndices,N.itemIndex)}}if(F===M.length){let X=YN("",D,A.spread);return{kind:"replace-block",block:Y0(N.list,[...N.list.items.slice(0,N.itemIndex+1),X,...N.list.items.slice(N.itemIndex+1)]),blockId:N.list.id,listItemInsertedPath:lF(X,N.rootIndex,[...N.listChildIndices,N.itemIndex+1]),selection:ZN(N.rootIndex,N.listChildIndices,N.itemIndex+1)}}let E=M.slice(0,F),$=M.slice(F),Y=YN($,D,A.spread),Z=r0(A,[s({text:E})]);return{kind:"replace-block",block:Y0(N.list,[...N.list.items.slice(0,N.itemIndex),Z,Y,...N.list.items.slice(N.itemIndex+1)]),blockId:N.list.id,listItemInsertedPath:lF(Y,N.rootIndex,[...N.listChildIndices,N.itemIndex+1]),selection:ZN(N.rootIndex,N.listChildIndices,N.itemIndex+1)}}function G9(N,F){if(F!==0||N.region.text.length!==0)return Y4(N,F);if(N.parentItem&&N.parentItemIndex!==null&&N.parentItemChildIndices&&N.parentList&&N.parentListChildIndices)return JY(N);let M=N.list.items.slice(0,N.itemIndex),A=N.list.items.slice(N.itemIndex+1),D=[];if(M.length>0)D.push(Y0(N.list,M));if(D.push(s({text:""})),A.length>0)D.push(Y0(N.list,A));return{kind:"splice-blocks",blocks:D,rootIndex:N.rootIndex,selection:e(N.rootIndex+(M.length>0?1:0))}}function z9(N){if(N.itemIndex===0)return null;let F=N.list.items[N.itemIndex-1];if(!F)return null;let M=KY(F,N.item,N);return{kind:"replace-block",block:Y0(N.list,N.list.items.flatMap((A,D)=>{if(D===N.itemIndex-1)return[M.item];if(D===N.itemIndex)return[];return[A]})),blockId:N.list.id,selection:z0(N.rootIndex,M.regionChildIndices)}}function _9(N){return H9(N,()=>({insertedItem:N.item}))}function Z4(N,F){let M=N.itemIndex+F;if(M<0||M>=N.list.items.length)return null;let A=[...N.list.items],[D]=A.splice(N.itemIndex,1);if(!D)return null;return A.splice(M,0,D),{kind:"replace-block",block:Y0(N.list,A),blockId:N.list.id,selection:ZN(N.rootIndex,N.listChildIndices,M)}}function JY(N){return H9(N,(F)=>{let M=typeof F.checked==="boolean"?!1:F.checked;return{insertedItem:YN("",M,F.spread),trackInsertedPath:!0}})}function H9(N,F){if(!N.parentItem||N.parentItemIndex===null||!N.parentItemChildIndices||!N.parentList||!N.parentListChildIndices)return null;let M=N.list.items.filter((Z,X)=>X!==N.itemIndex),A=N.parentItem.children.flatMap((Z)=>{if(Z.type!=="list"||Z.id!==N.list.id)return[Z];if(M.length===0)return[];return[Y0(N.list,M)]}),D=r0(N.parentItem,A),{insertedItem:E,trackInsertedPath:$=!1}=F(N.parentItem),Y=$?lF(E,N.rootIndex,[...N.parentListChildIndices,N.parentItemIndex+1]):void 0;return{kind:"replace-block",block:Y0(N.parentList,[...N.parentList.items.slice(0,N.parentItemIndex),D,E,...N.parentList.items.slice(N.parentItemIndex+1)]),blockId:N.parentList.id,listItemInsertedPath:Y,selection:ZN(N.rootIndex,N.parentListChildIndices,N.parentItemIndex+1)}}function lF(N,F,M){return typeof N.checked==="boolean"?void 0:Z9(F,M)}function KY(N,F,M){let A=N.children.findIndex((E)=>E.type==="list"&&E.ordered===M.list.ordered&&E.start===M.list.start);if(A>=0){let E=N.children[A];if(!E||E.type!=="list")return{item:N,regionChildIndices:[...M.listChildIndices,M.itemIndex-1,0]};return{item:r0(N,N.children.map(($,Y)=>Y===A?Y0(E,[...E.items,F]):$)),regionChildIndices:[...M.listChildIndices,M.itemIndex-1,A,E.items.length,0]}}let D=b1({items:[F],ordered:M.list.ordered,spread:M.list.spread,start:M.list.start});return{item:r0(N,[...N.children,D]),regionChildIndices:[...M.listChildIndices,M.itemIndex-1,N.children.length,0,0]}}function B9(N,F,M){let A=U2(N,F),D=Math.max(2,M);if(!A||A.block.type!=="paragraph"||A.block.plainText.length>0||F.anchor.regionId!==F.focus.regionId||F.anchor.offset!==0||F.focus.offset!==0)return null;return{kind:"splice-blocks",blocks:[v1({rows:Array.from({length:2},()=>Q4(D))})],rootIndex:A.rootIndex,selection:h1(A.rootIndex,0,0)}}function X4(N,F,M,A){let D=A<0?GY(M.table,M.rowIndex,M.cellIndex):zY(M.table,M.rowIndex,M.cellIndex);if(!D)return A>0&&_Y(M.table,M.rowIndex,M.cellIndex)?qY(M):{kind:"keep-state"};let E=M.table.rows[D.rowIndex]?.cells[D.cellIndex];if(!E)return{kind:"keep-state"};return{kind:"set-selection",selection:VY(N,F,M.table,D.rowIndex,D.cellIndex,Math.min(F.focus.offset,E.plainText.length))}}function W9(N,F){let M=Y2(N,F.focus.regionId);if(!M||M.kind!=="tableCell")return null;let A=Math.min(F.anchor.offset,F.focus.offset),D=Math.max(F.anchor.offset,F.focus.offset),E=g0(M,A,D,[a0({path:A1(M)})]);return{kind:"replace-block",block:E.block,blockId:E.blockId,selection:E.selection}}function y9(N,F){let M=F==="left"?N.cellIndex:N.cellIndex+1;return z2(N,v1({align:j9(N.table.align,M,0,[null]),rows:N.table.rows.map((A)=>e1({cells:UY(A.cells,M,0,[w9()])}))}),h1(N.rootIndex,N.rowIndex,M))}function O9(N){let F=Math.max(0,...N.table.rows.map((M)=>M.cells.length));if(F<=1)return null;return z2(N,v1({align:j9(N.table.align,N.cellIndex,1,[]),rows:N.table.rows.map((M)=>e1({cells:M.cells.filter((A,D)=>D!==N.cellIndex)}))}),h1(N.rootIndex,N.rowIndex,Math.min(N.cellIndex,F-2)))}function P9(N,F){let M=F==="above"?N.rowIndex:N.rowIndex+1,A=Math.max(1,...N.table.rows.map((D)=>D.cells.length));return z2(N,C0(N.table,[...N.table.rows.slice(0,M),Q4(A),...N.table.rows.slice(M)]),h1(N.rootIndex,M,Math.min(N.cellIndex,A-1)))}function T9(N){if(N.table.rows.length<=1)return null;let F=N.table.rows.filter((D,E)=>E!==N.rowIndex),M=Math.min(N.rowIndex,F.length-1),A=F[M]?.cells.length??1;return z2(N,C0(N.table,F),h1(N.rootIndex,M,Math.min(N.cellIndex,A-1)))}function L9(N){return z2(N,s({text:""}),e(N.rootIndex))}function Q4(N){return e1({cells:Array.from({length:N},()=>w9())})}function w9(){return q1({children:[]})}function qY(N){let F=N.table.rows.length,M=Math.max(1,...N.table.rows.map((A)=>A.cells.length));return z2(N,C0(N.table,[...N.table.rows,Q4(M)]),h1(N.rootIndex,F,0))}function z2(N,F,M){return{kind:"replace-block",block:F,blockId:N.table.id,selection:M}}function UY(N,F,M,A){return[...N.slice(0,F),...A,...N.slice(F+M)]}function j9(N,F,M,A){return[...N.slice(0,F),...A,...N.slice(F+M)]}function VY(N,F,M,A,D,E){let $=Q2(N,M.id,A,D);if(!$)return F;return{anchor:{regionId:$.id,offset:E},focus:{regionId:$.id,offset:E}}}function GY(N,F,M){if(M>0)return{cellIndex:M-1,rowIndex:F};if(F>0){let A=N.rows[F-1];if(!A||A.cells.length===0)return null;return{cellIndex:A.cells.length-1,rowIndex:F-1}}return null}function zY(N,F,M){let A=N.rows[F];if(!A)return null;if(M+1<A.cells.length)return{cellIndex:M+1,rowIndex:F};let D=N.rows[F+1];if(!D||D.cells.length===0)return null;return{cellIndex:0,rowIndex:F+1}}function _Y(N,F,M){let A=N.rows[F];return Boolean(A&&F===N.rows.length-1&&M===A.cells.length-1)}function C9(N,F,M){switch(M.kind){case"code":return{kind:"splice-text",selection:F,text:`
|
|
15
|
+
`};case"tableCell":return W9(N,F);case"listItem":return G9(M,M.offset)??Y4(M,M.offset);case"blockquoteTextBlock":return U9(M,M.offset)??q9(M,M.offset);case"rootTextBlock":return K9(M,M.offset);case"unsupported":return null}}function R9(N,F){let M=N0(N,F);if(M.collapsed)return null;let A=W0(N,M.start.regionId),D=W0(N,M.end.regionId);if(!A||!D)return null;let E=N.document.blocks[A.rootIndex],$=N.document.blocks[D.rootIndex];if(!E||!$)return null;if(A===D)return{kind:"single-region",normalized:M,region:A,root:E,wholeRegion:M.start.offset===0&&M.end.offset===A.text.length};return{kind:"multi-region",normalized:M,startRegion:A,endRegion:D,sameRoot:A.rootIndex===D.rootIndex,startRoot:E,endRoot:$}}function dF(N,F){let M=N0(N,F),A=W0(N,M.start.regionId),D=W0(N,M.end.regionId);if(!A||!D)return null;let E=S9(A)||S9(D);return{normalized:M,sameRegion:A===D,startRegion:A,endRegion:D,structuralBlocked:E,prefersVerbatimFallback:A.blockType==="code"||D.blockType==="code"}}function S9(N){return N.blockType==="table"||N.blockType==="code"}function J4(N,F){let M=R9(N,F);if(!M)return null;switch(M.kind){case"single-region":if(!M.wholeRegion||M.region.blockType==="table"){let D=BY(M.region,M.normalized.start.offset,M.normalized.end.offset);return HY(D)}let A=v9(M.root,M.region);return A?b9([A]):null;case"multi-region":{let D=M.sameRoot?WY(N,M.startRoot,M.startRegion,M.normalized.start.offset,M.endRegion,M.normalized.end.offset):PY(N,M.startRegion,M.normalized.start.offset,M.endRegion,M.normalized.end.offset);return D.length>0?b9(D):null}}}function HY(N){if(N.length===0)return null;if(Z3(N))return{kind:"text",text:F0(N)};return{kind:"inlines",inlines:N}}function b9(N){if(BF(N))return{kind:"text",text:N[0].plainText};return{kind:"blocks",blocks:N}}function v9(N,F){if(N.id===F.blockId)return N;let M=G0(N);if(!M)return null;let A=M.find((E)=>u1(E,F)),D=A?v9(A,F):null;return D?k1(N,[D]):null}function BY(N,F,M){let A=q2(N.inlines,M,N.text.length,""),D=q2(A,0,F,"");return i3(D)}function WY(N,F,M,A,D,E){if(F.type==="table")return OY(N,F,M,A,D,E);let $=f9(F,M,A,D,E);return $?[$]:[]}function yY(N,F,M,A,D){let E=N.roots[F.rootIndex],$=E?.regions[0],Y=E?.regions.at(-1);return F===$&&A===Y&&M===0&&D===Y.text.length}function OY(N,F,M,A,D,E){if(yY(N,M,A,D,E))return[F];let $=M.tableCellPosition?.rowIndex,Y=M.tableCellPosition?.cellIndex,Z=D.tableCellPosition?.rowIndex,X=D.tableCellPosition?.cellIndex;if($===void 0||Y===void 0||Z===void 0||X===void 0)return[];if($!==0||Y!==0||A!==0)return[];let Q=F.rows[Z];if(!Q)return[];let K=Q.cells.length-1;if(X!==K||E!==D.text.length)return[];return[C0(F,F.rows.slice(0,Z+1))]}function f9(N,F,M,A,D){let E=G0(N);if(!E)return null;let $=E.findIndex((Z)=>u1(Z,F)),Y=E.findIndex((Z)=>u1(Z,A));if($===-1||Y===-1)return null;if($===Y){let Z=f9(E[$],F,M,A,D);return Z?k1(N,[Z]):null}return k1(N,m9(E,$,F,M,Y,A,D))}function PY(N,F,M,A,D){return m9(N.document.blocks,F.rootIndex,F,M,A.rootIndex,A,D)}function m9(N,F,M,A,D,E,$){let Y=FN(N[F],M,A),Z=N.slice(F+1,D),X=NN(N[D],E,$);return[Y,...Z,X].filter((Q)=>Q!==null)}function K4(N,F){let M=dF(N.documentIndex,N.selection);if(!M)return null;switch(F.kind){case"text":return F.text.length>0?I0(N,{kind:"splice-text",selection:N.selection,text:F.text}):null;case"inlines":{if(F.inlines.length===0)return null;if(M.sameRegion){let A=B5(N.documentIndex,N.selection,F.inlines);if(A)return I0(N,A)}if(M.structuralBlocked)return null;return I0(N,{kind:"splice-fragment",blocks:[c0({children:F.inlines})],selection:N.selection})}case"blocks":if(F.blocks.length===0||M.structuralBlocked)return null;return I0(N,{kind:"splice-fragment",blocks:F.blocks,selection:N.selection})}}function k9(N,F,M,A){let D=A==="backward"?p3(N,F.blockId):i2(N,F.blockId);if(D&&n0(D))return TY(F,D,A);let E=A==="backward"?g1(N,F.id):s2(N,F.id);if(!E)return null;if(M)return wY(N,F,E,A);let $=A==="backward"?F:E,Y=A==="backward"?E:F;if(!LY(Y))return null;return jY(N,$,Y)}function TY(N,F,M){if(F.parentBlockId!==null)return null;let A=M==="backward"?N.rootIndex-1:N.rootIndex,D=M==="backward"?0:"end";return{kind:"splice-blocks",rootIndex:F.rootIndex,count:1,blocks:[],selection:aF(N,A,D)}}function LY(N){return N.blockType==="paragraph"||N.blockType==="heading"}function wY(N,F,M,A){let D=N.document.blocks[F.rootIndex];if(!D)return null;let E=cF(D,F,M.blockId,void 0),$=A==="backward"?M.text.length:0,Z=F.rootIndex===M.rootIndex?SY(E,M.rootIndex,M.blockId,$):RY(M,F.rootIndex,E.length,$);if(!Z)return null;return{kind:"splice-blocks",rootIndex:F.rootIndex,count:1,blocks:E,selection:Z}}function jY(N,F,M){let A=s0(N.document,M.blockId),D=s0(N.document,F.blockId);if(!A||A.type!=="paragraph"&&A.type!=="heading")return null;let E=M.text.length,$=CY(A,D),Y=aF(M,M.rootIndex,E);if(F.rootIndex===M.rootIndex){let V=N.document.blocks[F.rootIndex];if(!V)return null;let G=cF(V,F,M.blockId,$);return{kind:"splice-blocks",rootIndex:F.rootIndex,count:1,blocks:G,selection:Y}}let Z=N.document.blocks[M.rootIndex],X=N.document.blocks[F.rootIndex];if(!Z||!X)return null;let Q=cF(Z,F,M.blockId,$);if(Q.length!==1)return null;let K=Q[0],J=cF(X,F,M.blockId,void 0),q=Math.min(M.rootIndex,F.rootIndex),U=M.rootIndex<F.rootIndex?[K,...J]:[...J,K];return{kind:"splice-blocks",rootIndex:q,count:2,blocks:U,selection:Y}}function aF(N,F,M=0){let A=V1(N.path);if(A.length===0)return e(F,M);return z0(F,A,M)}function CY(N,F){let M=F&&(F.type==="paragraph"||F.type==="heading")?F.children:[];return j0(N,Q0([...N.children,...M]))}function SY(N,F,M,A){for(let D=0;D<N.length;D+=1){let E=N[D],$=q4(E,M);if($){if($.length===0)return e(F+D,A);return z0(F+D,$,A)}}return null}function RY(N,F,M,A){let D=V1(N.path),E=M-1,$=N.rootIndex<F?N.rootIndex:N.rootIndex+E;if(D.length===0)return e($,A);return z0($,D,A)}function q4(N,F){if(N.id===F)return[];switch(N.type){case"list":for(let M=0;M<N.items.length;M+=1){let A=q4(N.items[M],F);if(A)return[M,...A]}return null;case"listItem":case"blockquote":for(let M=0;M<N.children.length;M+=1){let A=q4(N.children[M],F);if(A)return[M,...A]}return null;default:return null}}function cF(N,F,M,A){return F2([N],(D,{parent:E,recurse:$})=>{if(D.type==="listItem"){let Z=D.children[0];if(Z&&Z.id===F.blockId)return bY(D)}if(D.id===F.blockId&&E?.type!=="listItem")return[];if(D.id===M&&A!==void 0)return A;let Y=$();if(Y.type==="listItem"){let Z=Y.children[0];if(!Z||Z.type!=="paragraph"&&Z.type!=="heading")return[]}return Y})}function bY(N){if(N.type==="listItem")return N.children.filter((F)=>F.type==="list").flatMap((F)=>F.items);return[]}function h9(N,F){let M=x3(N,F.rootIndex);if(!M||M.id!==F.id)return null;let A=N.document.blocks[F.rootIndex];if(!A)return null;let D=vY(A);if(!D)return null;return{kind:"splice-blocks",rootIndex:F.rootIndex,count:1,blocks:D,selection:e(F.rootIndex)}}function vY(N){switch(N.type){case"heading":return[c0({children:N.children})];case"blockquote":return[...N.children];case"list":return g9(N.items);default:return null}}function g9(N){return N.flatMap((F)=>{let M=[fY(F)];for(let A of F.children)if(A.type==="list")M.push(...g9(A.items));return M})}function fY(N){let F=N.children[0];if(F&&(F.type==="paragraph"||F.type==="heading"))return c0({children:F.children});return s({text:""})}function I9(N,F){if(F.kind==="unsupported"||!F.atBoundary)return null;if(F.direction==="backward"){let M=mY(F,N);if(M)return M}return k9(N,F.region,F.empty,F.direction)}function mY(N,F){let M=h9(F,N.region);if(M)return M;if(N.kind==="rootTextBlock"){let A=kY(N,F);if(A)return A}return null}function kY(N,F){if(N.block.type!=="paragraph"||N.block.plainText.length!==0)return null;let M=F.document.blocks[N.rootIndex-1],A=F.document.blocks[N.rootIndex+1];if(!M||M.type!=="list"||!A||A.type!=="list"||!hY(M,A))return null;let D=g1(F,N.region.id),E=D?aF(D,N.rootIndex-1,"end"):e(N.rootIndex-1,"end");return{kind:"splice-blocks",count:3,blocks:[Y0(M,[...M.items,...A.items])],rootIndex:N.rootIndex-1,selection:E}}function hY(N,F){return N.ordered===F.ordered&&N.start===F.start}var XN=E0((N,F)=>J9(N.documentIndex,N.selection,F),{animate:(N,F,M,A)=>{if(M.kind!=="splice-text")return;if(A===".")return I5(F);return kF(F,A.length)}}),rF=E0((N,F)=>C9(N.documentIndex,N.selection,F),{context:$N,animate:(N,F,M)=>{if(M.kind!=="replace-block"||!M.listItemInsertedPath)return;return u5(F,M.listItemInsertedPath)}}),u9=E0((N)=>I3(N.documentIndex,N.selection,(F)=>a0({path:F}))??{kind:"splice-text",selection:N.selection,text:`
|
|
16
|
+
`}),sF=E0((N,F)=>({kind:"splice-text",selection:N.selection,text:F}),{animate:(N,F,M,A)=>{if(A.length>0)return kF(F,A.length)}}),U4=(N)=>sF(N,""),V4=qM(UM,(N)=>GM(N,"backward"),(N)=>VM(N,"backward")),G4=qM(UM,(N)=>GM(N,"forward"),(N)=>VM(N,"forward")),z4=(N)=>J4(N.documentIndex,N.selection);function p9(N,F,M){let A=K4(N,F);if(A){let D=gY(F);return D>0?kF(A,D):A}if(F.kind==="text")return null;return IY(N,F,M)}function gY(N){switch(N.kind){case"text":return N.text.length;case"inlines":return F0(N.inlines).length;case"blocks":return N.blocks.length===1&&N.blocks[0].type==="paragraph"?N.blocks[0].plainText.length:0}}function IY(N,F,M){let A=dF(N.documentIndex,N.selection);if(!A)return null;let D=A.prefersVerbatimFallback&&M&&M.length>0?M:F5(F);return D.length>0?sF(N,D):null}function x9(N,F,M){return y0(N,F,M,!0)}function l9(N){let F=N.documentIndex.regions,M=F[0],A=F.at(-1);if(!M||!A)return N;return D0(N,{anchor:{regionId:M.id,offset:0},focus:{regionId:A.id,offset:A.text.length}})}var iF=(N)=>eF(N,"bold"),oF=(N)=>eF(N,"italic"),nF=(N)=>eF(N,"strikethrough"),tF=(N)=>eF(N,"underline"),d9=(N)=>B4(N,f3),c9=E0((N,F,M,A,D)=>jF(N.documentIndex,F,M,A,(E,$,Y)=>k3(E,$,Y,D))),a9=E0((N,F,M,A)=>jF(N.documentIndex,F,M,A,h3)),r9=(N,F)=>B4(N,(M,A,D)=>m3(M,A,D,F)),s9=E0((N,F,M)=>I3(N.documentIndex,N.selection,(A)=>S1({alt:M??null,path:A,url:F}))),i9=E0((N,F,M,A)=>{let D=Y2(N.documentIndex,F);if(!D)return null;let{image:E}=M,$=g0(D,M.start,M.end,[S1({alt:E.alt,path:A1(D),title:E.title,url:E.url,width:A})]);return{kind:"replace-block",block:$.block,blockId:$.blockId}}),_4=(N)=>e3(N),H4=(N)=>N4(N),o9=E0((N,F)=>{switch(F.kind){case"tableCell":return X4(N.documentIndex,N.selection,F,1);case"rootTextBlock":return $4(F,1,N.selection.focus.offset);case"listItem":return z9(F);default:return null}},{context:$N}),n9=E0((N,F)=>{switch(F.kind){case"tableCell":return X4(N.documentIndex,N.selection,F,-1);case"rootTextBlock":return $4(F,-1,N.selection.focus.offset);case"listItem":return _9(F);default:return null}},{context:$N}),t9=E0((N,F)=>Z4(F,-1),{context:V2}),e9=E0((N,F)=>Z4(F,1),{context:V2}),NM=E0((N,F)=>{let M=DN(N.documentIndex,F);if(!M||M.type!=="listItem"||typeof M.checked!=="boolean")return null;return{kind:"replace-block",block:{...M,checked:!M.checked},blockId:F}}),FM=E0((N,F)=>B9(N.documentIndex,N.selection,F)),MM=E0((N,F,M)=>y9(F,M),{context:QN}),AM=E0((N,F)=>O9(F),{context:QN}),DM=E0((N,F,M)=>P9(F,M),{context:QN}),EM=E0((N,F)=>T9(F),{context:QN}),$M=E0((N,F)=>L9(F),{context:QN}),YM=E0((N,F,M)=>{let A=P3(N.documentIndex,F,M);if(!A)return null;return{kind:"splice-comments",count:0,index:N.documentIndex.document.comments.length,threads:[A]}}),ZM=(N,F,M)=>JN(N,F,(A)=>_3(A,{body:M.trim()})),XM=(N,F,M,A)=>JN(N,F,(D)=>H3(D,M,A)),QM=(N,F,M)=>JN(N,F,(A)=>B3(A,M)),JM=(N,F)=>JN(N,F,()=>null),KM=(N,F,M)=>JN(N,F,(A)=>W3(A,M));function E0(N,F){return(M,...A)=>{let D=[];if(F?.context){let Y=F.context(M.documentIndex,M.selection);if(!Y)return null;D.push(Y)}let E=N(M,...D,...A);if(!E)return null;let $=I0(M,E);return F?.animate?.(M,$,E,...A)??$}}function qM(...N){return(F,...M)=>{for(let A of N){let D=A(F,...M);if(D)return D}return null}}function QN(N,F){return M4(N,F.focus.regionId)}function UM(N){return uY(N)?U4(N):null}function VM(N,F){let M=$9(N.documentIndex,N.selection,F);return I0(N,I9(N.documentIndex,M))}function eF(N,F){return B4(N,(M,A,D)=>b3(M,A,D,F))}function B4(N,F){let M=N0(N.documentIndex,N.selection);if(M.start.regionId!==M.end.regionId||M.start.offset===M.end.offset)return null;return I0(N,jF(N.documentIndex,M.start.regionId,M.start.offset,M.end.offset,F))}function uY(N){let F=N0(N.documentIndex,N.selection);return F.start.regionId!==F.end.regionId||F.start.offset!==F.end.offset}function GM(N,F){let M=X9(N,F);if(!M)return null;let A=I0(N,M);if(!A)return null;return g5(N,A,M.selection.anchor.offset,M.selection.focus.offset)}function JN(N,F,M){let D=o0(N.documentIndex).threads[F];if(!D)return null;let E=M(D);if(E===D)return null;return I0(N,{kind:"splice-comments",count:1,index:F,threads:E?[E]:[]})}function p1(){return{graphemeWidths:new Map,lineBoundaries:new Map,measuredContainerHeights:new Map,measuredLines:new Map,preparedText:new Map,viewportPlans:new WeakMap}}function zM(N,F,M){return KN(N.preparedText,F,M,256)}function _M(N,F,M){return KN(N.measuredLines,F,M,512)}function HM(N,F,M){return KN(N.lineBoundaries,F,M,1024)}function BM(N,F,M){return KN(N.measuredContainerHeights,F,M,1024)}function WM(N,F){let M=N.graphemeWidths.get(F);if(M)return M;let A=new Map;return KN(N.graphemeWidths,F,A,64),A}function yM(N,F,M){return N.viewportPlans.get(F)?.get(M)??null}function OM(N,F,M,A){let D=N.viewportPlans.get(F)??new Map;return D.set(M,A),N.viewportPlans.set(F,D),A}function KN(N,F,M,A){if(N.has(F))N.delete(F);if(N.set(F,M),N.size>A){let D=N.keys().next().value;if(D!==void 0)N.delete(D)}return M}var N6={blockGap:16,charWidth:9,indentWidth:24,lineHeight:24,paddingX:16,paddingY:12};function F6(N,F,M,A,D){if(PM(N,M,A,"list"))return 6;if(PM(N,M,A,"blockquote"))return 10;if(M===A)return 4;return D+pY(F.get(M))}function pY(N){if(N?.type!=="heading")return 0;if(N.depth===1)return 24;return N.depth===2?16:0}function PM(N,F,M,A){let D=TM(N,F,A),E=TM(N,M,A);for(let $ of D)if(E.has($))return!0;return!1}function TM(N,F,M){let A=new Set,D=N.get(F)??null;while(D){if(D.type===M)A.add(D.id);D=D.parentBlockId?N.get(D.parentBlockId)??null:null}return A}var LM=["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","ES","CS","ES","CS","CS","EN","EN","EN","EN","EN","EN","EN","EN","EN","EN","CS","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","BN","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"],W4=[[697,698,"ON"],[706,719,"ON"],[722,735,"ON"],[741,749,"ON"],[751,767,"ON"],[768,879,"NSM"],[884,885,"ON"],[894,894,"ON"],[900,901,"ON"],[903,903,"ON"],[1014,1014,"ON"],[1155,1161,"NSM"],[1418,1418,"ON"],[1421,1422,"ON"],[1423,1423,"ET"],[1424,1424,"R"],[1425,1469,"NSM"],[1470,1470,"R"],[1471,1471,"NSM"],[1472,1472,"R"],[1473,1474,"NSM"],[1475,1475,"R"],[1476,1477,"NSM"],[1478,1478,"R"],[1479,1479,"NSM"],[1480,1535,"R"],[1536,1541,"AN"],[1542,1543,"ON"],[1544,1544,"AL"],[1545,1546,"ET"],[1547,1547,"AL"],[1548,1548,"CS"],[1549,1549,"AL"],[1550,1551,"ON"],[1552,1562,"NSM"],[1563,1610,"AL"],[1611,1631,"NSM"],[1632,1641,"AN"],[1642,1642,"ET"],[1643,1644,"AN"],[1645,1647,"AL"],[1648,1648,"NSM"],[1649,1749,"AL"],[1750,1756,"NSM"],[1757,1757,"AN"],[1758,1758,"ON"],[1759,1764,"NSM"],[1765,1766,"AL"],[1767,1768,"NSM"],[1769,1769,"ON"],[1770,1773,"NSM"],[1774,1775,"AL"],[1776,1785,"EN"],[1786,1808,"AL"],[1809,1809,"NSM"],[1810,1839,"AL"],[1840,1866,"NSM"],[1867,1957,"AL"],[1958,1968,"NSM"],[1969,1983,"AL"],[1984,2026,"R"],[2027,2035,"NSM"],[2036,2037,"R"],[2038,2041,"ON"],[2042,2044,"R"],[2045,2045,"NSM"],[2046,2069,"R"],[2070,2073,"NSM"],[2074,2074,"R"],[2075,2083,"NSM"],[2084,2084,"R"],[2085,2087,"NSM"],[2088,2088,"R"],[2089,2093,"NSM"],[2094,2136,"R"],[2137,2139,"NSM"],[2140,2143,"R"],[2144,2191,"AL"],[2192,2193,"AN"],[2194,2198,"AL"],[2199,2207,"NSM"],[2208,2249,"AL"],[2250,2273,"NSM"],[2274,2274,"AN"],[2275,2306,"NSM"],[2362,2362,"NSM"],[2364,2364,"NSM"],[2369,2376,"NSM"],[2381,2381,"NSM"],[2385,2391,"NSM"],[2402,2403,"NSM"],[2433,2433,"NSM"],[2492,2492,"NSM"],[2497,2500,"NSM"],[2509,2509,"NSM"],[2530,2531,"NSM"],[2546,2547,"ET"],[2555,2555,"ET"],[2558,2558,"NSM"],[2561,2562,"NSM"],[2620,2620,"NSM"],[2625,2626,"NSM"],[2631,2632,"NSM"],[2635,2637,"NSM"],[2641,2641,"NSM"],[2672,2673,"NSM"],[2677,2677,"NSM"],[2689,2690,"NSM"],[2748,2748,"NSM"],[2753,2757,"NSM"],[2759,2760,"NSM"],[2765,2765,"NSM"],[2786,2787,"NSM"],[2801,2801,"ET"],[2810,2815,"NSM"],[2817,2817,"NSM"],[2876,2876,"NSM"],[2879,2879,"NSM"],[2881,2884,"NSM"],[2893,2893,"NSM"],[2901,2902,"NSM"],[2914,2915,"NSM"],[2946,2946,"NSM"],[3008,3008,"NSM"],[3021,3021,"NSM"],[3059,3064,"ON"],[3065,3065,"ET"],[3066,3066,"ON"],[3072,3072,"NSM"],[3076,3076,"NSM"],[3132,3132,"NSM"],[3134,3136,"NSM"],[3142,3144,"NSM"],[3146,3149,"NSM"],[3157,3158,"NSM"],[3170,3171,"NSM"],[3192,3198,"ON"],[3201,3201,"NSM"],[3260,3260,"NSM"],[3276,3277,"NSM"],[3298,3299,"NSM"],[3328,3329,"NSM"],[3387,3388,"NSM"],[3393,3396,"NSM"],[3405,3405,"NSM"],[3426,3427,"NSM"],[3457,3457,"NSM"],[3530,3530,"NSM"],[3538,3540,"NSM"],[3542,3542,"NSM"],[3633,3633,"NSM"],[3636,3642,"NSM"],[3647,3647,"ET"],[3655,3662,"NSM"],[3761,3761,"NSM"],[3764,3772,"NSM"],[3784,3790,"NSM"],[3864,3865,"NSM"],[3893,3893,"NSM"],[3895,3895,"NSM"],[3897,3897,"NSM"],[3898,3901,"ON"],[3953,3966,"NSM"],[3968,3972,"NSM"],[3974,3975,"NSM"],[3981,3991,"NSM"],[3993,4028,"NSM"],[4038,4038,"NSM"],[4141,4144,"NSM"],[4146,4151,"NSM"],[4153,4154,"NSM"],[4157,4158,"NSM"],[4184,4185,"NSM"],[4190,4192,"NSM"],[4209,4212,"NSM"],[4226,4226,"NSM"],[4229,4230,"NSM"],[4237,4237,"NSM"],[4253,4253,"NSM"],[4957,4959,"NSM"],[5008,5017,"ON"],[5120,5120,"ON"],[5760,5760,"WS"],[5787,5788,"ON"],[5906,5908,"NSM"],[5938,5939,"NSM"],[5970,5971,"NSM"],[6002,6003,"NSM"],[6068,6069,"NSM"],[6071,6077,"NSM"],[6086,6086,"NSM"],[6089,6099,"NSM"],[6107,6107,"ET"],[6109,6109,"NSM"],[6128,6137,"ON"],[6144,6154,"ON"],[6155,6157,"NSM"],[6158,6158,"BN"],[6159,6159,"NSM"],[6277,6278,"NSM"],[6313,6313,"NSM"],[6432,6434,"NSM"],[6439,6440,"NSM"],[6450,6450,"NSM"],[6457,6459,"NSM"],[6464,6464,"ON"],[6468,6469,"ON"],[6622,6655,"ON"],[6679,6680,"NSM"],[6683,6683,"NSM"],[6742,6742,"NSM"],[6744,6750,"NSM"],[6752,6752,"NSM"],[6754,6754,"NSM"],[6757,6764,"NSM"],[6771,6780,"NSM"],[6783,6783,"NSM"],[6832,6877,"NSM"],[6880,6891,"NSM"],[6912,6915,"NSM"],[6964,6964,"NSM"],[6966,6970,"NSM"],[6972,6972,"NSM"],[6978,6978,"NSM"],[7019,7027,"NSM"],[7040,7041,"NSM"],[7074,7077,"NSM"],[7080,7081,"NSM"],[7083,7085,"NSM"],[7142,7142,"NSM"],[7144,7145,"NSM"],[7149,7149,"NSM"],[7151,7153,"NSM"],[7212,7219,"NSM"],[7222,7223,"NSM"],[7376,7378,"NSM"],[7380,7392,"NSM"],[7394,7400,"NSM"],[7405,7405,"NSM"],[7412,7412,"NSM"],[7416,7417,"NSM"],[7616,7679,"NSM"],[8125,8125,"ON"],[8127,8129,"ON"],[8141,8143,"ON"],[8157,8159,"ON"],[8173,8175,"ON"],[8189,8190,"ON"],[8192,8202,"WS"],[8203,8205,"BN"],[8207,8207,"R"],[8208,8231,"ON"],[8232,8232,"WS"],[8233,8233,"B"],[8234,8238,"BN"],[8239,8239,"CS"],[8240,8244,"ET"],[8245,8259,"ON"],[8260,8260,"CS"],[8261,8286,"ON"],[8287,8287,"WS"],[8288,8303,"BN"],[8304,8304,"EN"],[8308,8313,"EN"],[8314,8315,"ES"],[8316,8318,"ON"],[8320,8329,"EN"],[8330,8331,"ES"],[8332,8334,"ON"],[8352,8399,"ET"],[8400,8432,"NSM"],[8448,8449,"ON"],[8451,8454,"ON"],[8456,8457,"ON"],[8468,8468,"ON"],[8470,8472,"ON"],[8478,8483,"ON"],[8485,8485,"ON"],[8487,8487,"ON"],[8489,8489,"ON"],[8494,8494,"ET"],[8506,8507,"ON"],[8512,8516,"ON"],[8522,8525,"ON"],[8528,8543,"ON"],[8585,8587,"ON"],[8592,8721,"ON"],[8722,8722,"ES"],[8723,8723,"ET"],[8724,9013,"ON"],[9083,9108,"ON"],[9110,9257,"ON"],[9280,9290,"ON"],[9312,9351,"ON"],[9352,9371,"EN"],[9450,9899,"ON"],[9901,10239,"ON"],[10496,11123,"ON"],[11126,11263,"ON"],[11493,11498,"ON"],[11503,11505,"NSM"],[11513,11519,"ON"],[11647,11647,"NSM"],[11744,11775,"NSM"],[11776,11869,"ON"],[11904,11929,"ON"],[11931,12019,"ON"],[12032,12245,"ON"],[12272,12287,"ON"],[12288,12288,"WS"],[12289,12292,"ON"],[12296,12320,"ON"],[12330,12333,"NSM"],[12336,12336,"ON"],[12342,12343,"ON"],[12349,12351,"ON"],[12441,12442,"NSM"],[12443,12444,"ON"],[12448,12448,"ON"],[12539,12539,"ON"],[12736,12773,"ON"],[12783,12783,"ON"],[12829,12830,"ON"],[12880,12895,"ON"],[12924,12926,"ON"],[12977,12991,"ON"],[13004,13007,"ON"],[13175,13178,"ON"],[13278,13279,"ON"],[13311,13311,"ON"],[19904,19967,"ON"],[42128,42182,"ON"],[42509,42511,"ON"],[42607,42610,"NSM"],[42611,42611,"ON"],[42612,42621,"NSM"],[42622,42623,"ON"],[42654,42655,"NSM"],[42736,42737,"NSM"],[42752,42785,"ON"],[42888,42888,"ON"],[43010,43010,"NSM"],[43014,43014,"NSM"],[43019,43019,"NSM"],[43045,43046,"NSM"],[43048,43051,"ON"],[43052,43052,"NSM"],[43064,43065,"ET"],[43124,43127,"ON"],[43204,43205,"NSM"],[43232,43249,"NSM"],[43263,43263,"NSM"],[43302,43309,"NSM"],[43335,43345,"NSM"],[43392,43394,"NSM"],[43443,43443,"NSM"],[43446,43449,"NSM"],[43452,43453,"NSM"],[43493,43493,"NSM"],[43561,43566,"NSM"],[43569,43570,"NSM"],[43573,43574,"NSM"],[43587,43587,"NSM"],[43596,43596,"NSM"],[43644,43644,"NSM"],[43696,43696,"NSM"],[43698,43700,"NSM"],[43703,43704,"NSM"],[43710,43711,"NSM"],[43713,43713,"NSM"],[43756,43757,"NSM"],[43766,43766,"NSM"],[43882,43883,"ON"],[44005,44005,"NSM"],[44008,44008,"NSM"],[44013,44013,"NSM"],[64285,64285,"R"],[64286,64286,"NSM"],[64287,64296,"R"],[64297,64297,"ES"],[64298,64335,"R"],[64336,64450,"AL"],[64451,64466,"ON"],[64467,64829,"AL"],[64830,64847,"ON"],[64848,64911,"AL"],[64912,64913,"ON"],[64914,64967,"AL"],[64968,64975,"ON"],[64976,65007,"BN"],[65008,65020,"AL"],[65021,65023,"ON"],[65024,65039,"NSM"],[65040,65049,"ON"],[65056,65071,"NSM"],[65072,65103,"ON"],[65104,65104,"CS"],[65105,65105,"ON"],[65106,65106,"CS"],[65108,65108,"ON"],[65109,65109,"CS"],[65110,65118,"ON"],[65119,65119,"ET"],[65120,65121,"ON"],[65122,65123,"ES"],[65124,65126,"ON"],[65128,65128,"ON"],[65129,65130,"ET"],[65131,65131,"ON"],[65136,65278,"AL"],[65279,65279,"BN"],[65281,65282,"ON"],[65283,65285,"ET"],[65286,65290,"ON"],[65291,65291,"ES"],[65292,65292,"CS"],[65293,65293,"ES"],[65294,65295,"CS"],[65296,65305,"EN"],[65306,65306,"CS"],[65307,65312,"ON"],[65339,65344,"ON"],[65371,65381,"ON"],[65504,65505,"ET"],[65506,65508,"ON"],[65509,65510,"ET"],[65512,65518,"ON"],[65520,65528,"BN"],[65529,65533,"ON"],[65534,65535,"BN"],[65793,65793,"ON"],[65856,65932,"ON"],[65936,65948,"ON"],[65952,65952,"ON"],[66045,66045,"NSM"],[66272,66272,"NSM"],[66273,66299,"EN"],[66422,66426,"NSM"],[67584,67870,"R"],[67871,67871,"ON"],[67872,68096,"R"],[68097,68099,"NSM"],[68100,68100,"R"],[68101,68102,"NSM"],[68103,68107,"R"],[68108,68111,"NSM"],[68112,68151,"R"],[68152,68154,"NSM"],[68155,68158,"R"],[68159,68159,"NSM"],[68160,68324,"R"],[68325,68326,"NSM"],[68327,68408,"R"],[68409,68415,"ON"],[68416,68863,"R"],[68864,68899,"AL"],[68900,68903,"NSM"],[68904,68911,"AL"],[68912,68921,"AN"],[68922,68927,"AL"],[68928,68937,"AN"],[68938,68968,"R"],[68969,68973,"NSM"],[68974,68974,"ON"],[68975,69215,"R"],[69216,69246,"AN"],[69247,69290,"R"],[69291,69292,"NSM"],[69293,69311,"R"],[69312,69327,"AL"],[69328,69336,"ON"],[69337,69369,"AL"],[69370,69375,"NSM"],[69376,69423,"R"],[69424,69445,"AL"],[69446,69456,"NSM"],[69457,69487,"AL"],[69488,69505,"R"],[69506,69509,"NSM"],[69510,69631,"R"],[69633,69633,"NSM"],[69688,69702,"NSM"],[69714,69733,"ON"],[69744,69744,"NSM"],[69747,69748,"NSM"],[69759,69761,"NSM"],[69811,69814,"NSM"],[69817,69818,"NSM"],[69826,69826,"NSM"],[69888,69890,"NSM"],[69927,69931,"NSM"],[69933,69940,"NSM"],[70003,70003,"NSM"],[70016,70017,"NSM"],[70070,70078,"NSM"],[70089,70092,"NSM"],[70095,70095,"NSM"],[70191,70193,"NSM"],[70196,70196,"NSM"],[70198,70199,"NSM"],[70206,70206,"NSM"],[70209,70209,"NSM"],[70367,70367,"NSM"],[70371,70378,"NSM"],[70400,70401,"NSM"],[70459,70460,"NSM"],[70464,70464,"NSM"],[70502,70508,"NSM"],[70512,70516,"NSM"],[70587,70592,"NSM"],[70606,70606,"NSM"],[70608,70608,"NSM"],[70610,70610,"NSM"],[70625,70626,"NSM"],[70712,70719,"NSM"],[70722,70724,"NSM"],[70726,70726,"NSM"],[70750,70750,"NSM"],[70835,70840,"NSM"],[70842,70842,"NSM"],[70847,70848,"NSM"],[70850,70851,"NSM"],[71090,71093,"NSM"],[71100,71101,"NSM"],[71103,71104,"NSM"],[71132,71133,"NSM"],[71219,71226,"NSM"],[71229,71229,"NSM"],[71231,71232,"NSM"],[71264,71276,"ON"],[71339,71339,"NSM"],[71341,71341,"NSM"],[71344,71349,"NSM"],[71351,71351,"NSM"],[71453,71453,"NSM"],[71455,71455,"NSM"],[71458,71461,"NSM"],[71463,71467,"NSM"],[71727,71735,"NSM"],[71737,71738,"NSM"],[71995,71996,"NSM"],[71998,71998,"NSM"],[72003,72003,"NSM"],[72148,72151,"NSM"],[72154,72155,"NSM"],[72160,72160,"NSM"],[72193,72198,"NSM"],[72201,72202,"NSM"],[72243,72248,"NSM"],[72251,72254,"NSM"],[72263,72263,"NSM"],[72273,72278,"NSM"],[72281,72283,"NSM"],[72330,72342,"NSM"],[72344,72345,"NSM"],[72544,72544,"NSM"],[72546,72548,"NSM"],[72550,72550,"NSM"],[72752,72758,"NSM"],[72760,72765,"NSM"],[72850,72871,"NSM"],[72874,72880,"NSM"],[72882,72883,"NSM"],[72885,72886,"NSM"],[73009,73014,"NSM"],[73018,73018,"NSM"],[73020,73021,"NSM"],[73023,73029,"NSM"],[73031,73031,"NSM"],[73104,73105,"NSM"],[73109,73109,"NSM"],[73111,73111,"NSM"],[73459,73460,"NSM"],[73472,73473,"NSM"],[73526,73530,"NSM"],[73536,73536,"NSM"],[73538,73538,"NSM"],[73562,73562,"NSM"],[73685,73692,"ON"],[73693,73696,"ET"],[73697,73713,"ON"],[78912,78912,"NSM"],[78919,78933,"NSM"],[90398,90409,"NSM"],[90413,90415,"NSM"],[92912,92916,"NSM"],[92976,92982,"NSM"],[94031,94031,"NSM"],[94095,94098,"NSM"],[94178,94178,"ON"],[94180,94180,"NSM"],[113821,113822,"NSM"],[113824,113827,"BN"],[117760,117973,"ON"],[118000,118009,"EN"],[118010,118012,"ON"],[118016,118451,"ON"],[118458,118480,"ON"],[118496,118512,"ON"],[118528,118573,"NSM"],[118576,118598,"NSM"],[119143,119145,"NSM"],[119155,119162,"BN"],[119163,119170,"NSM"],[119173,119179,"NSM"],[119210,119213,"NSM"],[119273,119274,"ON"],[119296,119361,"ON"],[119362,119364,"NSM"],[119365,119365,"ON"],[119552,119638,"ON"],[120513,120513,"ON"],[120539,120539,"ON"],[120571,120571,"ON"],[120597,120597,"ON"],[120629,120629,"ON"],[120655,120655,"ON"],[120687,120687,"ON"],[120713,120713,"ON"],[120745,120745,"ON"],[120771,120771,"ON"],[120782,120831,"EN"],[121344,121398,"NSM"],[121403,121452,"NSM"],[121461,121461,"NSM"],[121476,121476,"NSM"],[121499,121503,"NSM"],[121505,121519,"NSM"],[122880,122886,"NSM"],[122888,122904,"NSM"],[122907,122913,"NSM"],[122915,122916,"NSM"],[122918,122922,"NSM"],[123023,123023,"NSM"],[123184,123190,"NSM"],[123566,123566,"NSM"],[123628,123631,"NSM"],[123647,123647,"ET"],[124140,124143,"NSM"],[124398,124399,"NSM"],[124643,124643,"NSM"],[124646,124646,"NSM"],[124654,124655,"NSM"],[124661,124661,"NSM"],[124928,125135,"R"],[125136,125142,"NSM"],[125143,125251,"R"],[125252,125258,"NSM"],[125259,126063,"R"],[126064,126143,"AL"],[126144,126207,"R"],[126208,126287,"AL"],[126288,126463,"R"],[126464,126703,"AL"],[126704,126705,"ON"],[126706,126719,"AL"],[126720,126975,"R"],[126976,127019,"ON"],[127024,127123,"ON"],[127136,127150,"ON"],[127153,127167,"ON"],[127169,127183,"ON"],[127185,127221,"ON"],[127232,127242,"EN"],[127243,127247,"ON"],[127279,127279,"ON"],[127338,127343,"ON"],[127405,127405,"ON"],[127584,127589,"ON"],[127744,128728,"ON"],[128732,128748,"ON"],[128752,128764,"ON"],[128768,128985,"ON"],[128992,129003,"ON"],[129008,129008,"ON"],[129024,129035,"ON"],[129040,129095,"ON"],[129104,129113,"ON"],[129120,129159,"ON"],[129168,129197,"ON"],[129200,129211,"ON"],[129216,129217,"ON"],[129232,129240,"ON"],[129280,129623,"ON"],[129632,129645,"ON"],[129648,129660,"ON"],[129664,129674,"ON"],[129678,129734,"ON"],[129736,129736,"ON"],[129741,129756,"ON"],[129759,129770,"ON"],[129775,129784,"ON"],[129792,129938,"ON"],[129940,130031,"ON"],[130032,130041,"EN"],[130042,130042,"ON"],[131070,131071,"BN"],[196606,196607,"BN"],[262142,262143,"BN"],[327678,327679,"BN"],[393214,393215,"BN"],[458750,458751,"BN"],[524286,524287,"BN"],[589822,589823,"BN"],[655358,655359,"BN"],[720894,720895,"BN"],[786430,786431,"BN"],[851966,851967,"BN"],[917502,917759,"BN"],[917760,917999,"NSM"],[918000,921599,"BN"],[983038,983039,"BN"],[1048574,1048575,"BN"],[1114110,1114111,"BN"]];function xY(N){if(N<=255)return LM[N];let F=0,M=W4.length-1;while(F<=M){let A=F+M>>1,D=W4[A];if(N<D[0]){M=A-1;continue}if(N>D[1]){F=A+1;continue}return D[2]}return"L"}function lY(N){let F=N.length;if(F===0)return null;let M=Array(F),A=!1;for(let X=0;X<F;){let Q=N.charCodeAt(X),K=Q,J=1;if(Q>=55296&&Q<=56319&&X+1<F){let U=N.charCodeAt(X+1);if(U>=56320&&U<=57343)K=(Q-55296<<10)+(U-56320)+65536,J=2}let q=xY(K);if(q==="R"||q==="AL"||q==="AN")A=!0;for(let U=0;U<J;U++)M[X+U]=q;X+=J}if(!A)return null;let D=0;for(let X=0;X<F;X++){let Q=M[X];if(Q==="L"){D=0;break}if(Q==="R"||Q==="AL"){D=1;break}}let E=new Int8Array(F);for(let X=0;X<F;X++)E[X]=D;let $=D&1?"R":"L",Y=$,Z=Y;for(let X=0;X<F;X++)if(M[X]==="NSM")M[X]=Z;else Z=M[X];Z=Y;for(let X=0;X<F;X++){let Q=M[X];if(Q==="EN")M[X]=Z==="AL"?"AN":"EN";else if(Q==="R"||Q==="L"||Q==="AL")Z=Q}for(let X=0;X<F;X++)if(M[X]==="AL")M[X]="R";for(let X=1;X<F-1;X++){if(M[X]==="ES"&&M[X-1]==="EN"&&M[X+1]==="EN")M[X]="EN";if(M[X]==="CS"&&(M[X-1]==="EN"||M[X-1]==="AN")&&M[X+1]===M[X-1])M[X]=M[X-1]}for(let X=0;X<F;X++){if(M[X]!=="EN")continue;let Q;for(Q=X-1;Q>=0&&M[Q]==="ET";Q--)M[Q]="EN";for(Q=X+1;Q<F&&M[Q]==="ET";Q++)M[Q]="EN"}for(let X=0;X<F;X++){let Q=M[X];if(Q==="WS"||Q==="ES"||Q==="ET"||Q==="CS")M[X]="ON"}Z=Y;for(let X=0;X<F;X++){let Q=M[X];if(Q==="EN")M[X]=Z==="L"?"L":"EN";else if(Q==="R"||Q==="L")Z=Q}for(let X=0;X<F;X++){if(M[X]!=="ON")continue;let Q=X+1;while(Q<F&&M[Q]==="ON")Q++;let K=X>0?M[X-1]:Y,J=Q<F?M[Q]:Y,q=K!=="L"?"R":"L";if(q===(J!=="L"?"R":"L"))for(let V=X;V<Q;V++)M[V]=q;X=Q-1}for(let X=0;X<F;X++)if(M[X]==="ON")M[X]=$;for(let X=0;X<F;X++){let Q=M[X];if((E[X]&1)===0){if(Q==="R")E[X]++;else if(Q==="AN"||Q==="EN")E[X]+=2}else if(Q==="L"||Q==="AN"||Q==="EN")E[X]++}return E}function wM(N,F){let M=lY(N);if(M===null)return null;let A=new Int8Array(F.length);for(let D=0;D<F.length;D++)A[D]=M[F[D]];return A}var dY=/[ \t\n\r\f]+/g,cY=/[\t\n\r\f]| {2,}|^ | $/;function aY(N){let F=N??"normal";return F==="pre-wrap"?{mode:F,preserveOrdinarySpaces:!0,preserveHardBreaks:!0}:{mode:F,preserveOrdinarySpaces:!1,preserveHardBreaks:!1}}function rY(N){if(!cY.test(N))return N;let F=N.replace(dY," ");if(F.charCodeAt(0)===32)F=F.slice(1);if(F.length>0&&F.charCodeAt(F.length-1)===32)F=F.slice(0,-1);return F}function sY(N){if(!/[\r\f]/.test(N))return N;return N.replace(/\r\n/g,`
|
|
18
17
|
`).replace(/[\r\f]/g,`
|
|
19
|
-
`)}var
|
|
20
|
-
`)return"hard-break"}if($===" ")return"space";if($===" "||$===" "||$===""||$==="\uFEFF")return"glue";if($==="")return"zero-width-break";if($==="")return"soft-hyphen";return"text"}function Y1($){return $.length===1?$[0]:$.join("")}function Kq($,Y,X,Z){let J=[],K=null,Q=[],M=X,D=!1,q=0;for(let U of $){let V=Jq(U,Z),G=V==="text"&&Y;if(K!==null&&V===K&&G===D){Q.push(U),q+=U.length;continue}if(K!==null)J.push({text:Y1(Q),isWordLike:D,kind:K,start:M});K=V,Q=[U],M=X+q,D=G,q+=U.length}if(K!==null)J.push({text:Y1(Q),isWordLike:D,kind:K,start:M});return J}function F3($){return $==="space"||$==="preserved-space"||$==="zero-width-break"||$==="hard-break"}var Qq=/^[A-Za-z][A-Za-z0-9+.-]*:$/;function Mq($,Y){let X=$.texts[Y];if(X.startsWith("www."))return!0;return Qq.test(X)&&Y+1<$.len&&$.kinds[Y+1]==="text"&&$.texts[Y+1]==="//"}function qq($){return $.includes("?")&&($.includes("://")||$.startsWith("www."))}function Dq($){let Y=$.texts.slice(),X=$.isWordLike.slice(),Z=$.kinds.slice(),J=$.starts.slice();for(let Q=0;Q<$.len;Q++){if(Z[Q]!=="text"||!Mq($,Q))continue;let M=[Y[Q]],D=Q+1;while(D<$.len&&!F3(Z[D])){M.push(Y[D]),X[Q]=!0;let q=Y[D].includes("?");if(Z[D]="text",Y[D]="",D++,q)break}Y[Q]=Y1(M)}let K=0;for(let Q=0;Q<Y.length;Q++){let M=Y[Q];if(M.length===0)continue;if(K!==Q)Y[K]=M,X[K]=X[Q],Z[K]=Z[Q],J[K]=J[Q];K++}return Y.length=K,X.length=K,Z.length=K,J.length=K,{len:K,texts:Y,isWordLike:X,kinds:Z,starts:J}}function Uq($){let Y=[],X=[],Z=[],J=[];for(let K=0;K<$.len;K++){let Q=$.texts[K];if(Y.push(Q),X.push($.isWordLike[K]),Z.push($.kinds[K]),J.push($.starts[K]),!qq(Q))continue;let M=K+1;if(M>=$.len||F3($.kinds[M]))continue;let D=[],q=$.starts[M],U=M;while(U<$.len&&!F3($.kinds[U]))D.push($.texts[U]),U++;if(D.length>0)Y.push(Y1(D)),X.push(!0),Z.push("text"),J.push(q),K=U-1}return{len:Y.length,texts:Y,isWordLike:X,kinds:Z,starts:J}}var Gq=new Set([":","-","/","×",",",".","+","–","—"]),OY=/^[A-Za-z0-9_]+[,:;]*$/,BY=/[,:;]+$/;function LY($){for(let Y of $)if(CY.test(Y))return!0;return!1}function E3($){if($.length===0)return!1;for(let Y of $){if(CY.test(Y)||Gq.has(Y))continue;return!1}return!0}function Vq($){let Y=[],X=[],Z=[],J=[];for(let K=0;K<$.len;K++){let Q=$.texts[K],M=$.kinds[K];if(M==="text"&&E3(Q)&&LY(Q)){let D=[Q],q=K+1;while(q<$.len&&$.kinds[q]==="text"&&E3($.texts[q]))D.push($.texts[q]),q++;Y.push(Y1(D)),X.push(!0),Z.push("text"),J.push($.starts[K]),K=q-1;continue}Y.push(Q),X.push($.isWordLike[K]),Z.push(M),J.push($.starts[K])}return{len:Y.length,texts:Y,isWordLike:X,kinds:Z,starts:J}}function Nq($){let Y=[],X=[],Z=[],J=[];for(let K=0;K<$.len;K++){let Q=$.texts[K],M=$.kinds[K],D=$.isWordLike[K];if(M==="text"&&D&&OY.test(Q)){let q=[Q],U=BY.test(Q),V=K+1;while(U&&V<$.len&&$.kinds[V]==="text"&&$.isWordLike[V]&&OY.test($.texts[V])){let G=$.texts[V];q.push(G),U=BY.test(G),V++}Y.push(Y1(q)),X.push(!0),Z.push("text"),J.push($.starts[K]),K=V-1;continue}Y.push(Q),X.push(D),Z.push(M),J.push($.starts[K])}return{len:Y.length,texts:Y,isWordLike:X,kinds:Z,starts:J}}function Aq($){let Y=[],X=[],Z=[],J=[];for(let K=0;K<$.len;K++){let Q=$.texts[K];if($.kinds[K]==="text"&&Q.includes("-")){let M=Q.split("-"),D=M.length>1;for(let q=0;q<M.length;q++){let U=M[q];if(!D)break;if(U.length===0||!LY(U)||!E3(U))D=!1}if(D){let q=0;for(let U=0;U<M.length;U++){let V=M[U],G=U<M.length-1?`${V}-`:V;Y.push(G),X.push(!0),Z.push("text"),J.push($.starts[K]+q),q+=G.length}continue}}Y.push(Q),X.push($.isWordLike[K]),Z.push($.kinds[K]),J.push($.starts[K])}return{len:Y.length,texts:Y,isWordLike:X,kinds:Z,starts:J}}function _q($){let Y=[],X=[],Z=[],J=[],K=0;while(K<$.len){let Q=[$.texts[K]],M=$.isWordLike[K],D=$.kinds[K],q=$.starts[K];if(D==="glue"){let U=[Q[0]],V=q;K++;while(K<$.len&&$.kinds[K]==="glue")U.push($.texts[K]),K++;let G=Y1(U);if(K<$.len&&$.kinds[K]==="text")Q[0]=G,Q.push($.texts[K]),M=$.isWordLike[K],D="text",q=V,K++;else{Y.push(G),X.push(!1),Z.push("glue"),J.push(V);continue}}else K++;if(D==="text")while(K<$.len&&$.kinds[K]==="glue"){let U=[];while(K<$.len&&$.kinds[K]==="glue")U.push($.texts[K]),K++;let V=Y1(U);if(K<$.len&&$.kinds[K]==="text"){Q.push(V,$.texts[K]),M=M||$.isWordLike[K],K++;continue}Q.push(V)}Y.push(Y1(Q)),X.push(M),Z.push(D),J.push(q)}return{len:Y.length,texts:Y,isWordLike:X,kinds:Z,starts:J}}function Hq($){let Y=$.texts.slice(),X=$.isWordLike.slice(),Z=$.kinds.slice(),J=$.starts.slice();for(let K=0;K<Y.length-1;K++){if(Z[K]!=="text"||Z[K+1]!=="text")continue;if(!$1(Y[K])||!$1(Y[K+1]))continue;let Q=eM(Y[K]);if(Q===null)continue;Y[K]=Q.head,Y[K+1]=Q.tail+Y[K+1],J[K+1]=J[K]+Q.head.length}return{len:Y.length,texts:Y,isWordLike:X,kinds:Z,starts:J}}function zq($,Y,X){let Z=cM(),J=0,K=[],Q=[],M=[],D=[];for(let G of Z.segment($))for(let N of Kq(G.segment,G.isWordLike??!1,G.index,X)){let A=N.kind==="text";if(Y.carryCJKAfterClosingQuote&&A&&J>0&&M[J-1]==="text"&&$1(N.text)&&$1(K[J-1])&&T3(K[J-1]))K[J-1]+=N.text,Q[J-1]=Q[J-1]||N.isWordLike;else if(A&&J>0&&M[J-1]==="text"&&nM(N.text)&&$1(K[J-1]))K[J-1]+=N.text,Q[J-1]=Q[J-1]||N.isWordLike;else if(A&&J>0&&M[J-1]==="text"&&Xq(K[J-1]))K[J-1]+=N.text,Q[J-1]=Q[J-1]||N.isWordLike;else if(A&&J>0&&M[J-1]==="text"&&N.isWordLike&&z3(N.text)&&Yq(K[J-1]))K[J-1]+=N.text,Q[J-1]=!0;else if(A&&!N.isWordLike&&J>0&&M[J-1]==="text"&&N.text.length===1&&N.text!=="-"&&N.text!=="—"&&$q(K[J-1],N.text))K[J-1]+=N.text;else if(A&&!N.isWordLike&&J>0&&M[J-1]==="text"&&(oM(N.text)||N.text==="-"&&Q[J-1]))K[J-1]+=N.text;else K[J]=N.text,Q[J]=N.isWordLike,M[J]=N.kind,D[J]=N.start,J++}for(let G=1;G<J;G++)if(M[G]==="text"&&!Q[G]&&y3(K[G])&&M[G-1]==="text")K[G-1]+=K[G],Q[G-1]=Q[G-1]||Q[G],K[G]="";for(let G=J-2;G>=0;G--)if(M[G]==="text"&&!Q[G]&&tM(K[G])){let N=G+1;while(N<J&&K[N]==="")N++;if(N<J&&M[N]==="text")K[N]=K[G]+K[N],D[N]=D[G],K[G]=""}let q=0;for(let G=0;G<J;G++){let N=K[G];if(N.length===0)continue;if(q!==G)K[q]=N,Q[q]=Q[G],M[q]=M[G],D[q]=D[G];q++}K.length=q,Q.length=q,M.length=q,D.length=q;let U=_q({len:q,texts:K,isWordLike:Q,kinds:M,starts:D}),V=Hq(Nq(Aq(Vq(Uq(Dq(U))))));for(let G=0;G<V.len-1;G++){let N=Zq(V.texts[G]);if(N===null)continue;if(V.kinds[G]!=="space"&&V.kinds[G]!=="preserved-space"||V.kinds[G+1]!=="text"||!z3(V.texts[G+1]))continue;V.texts[G]=N.space,V.isWordLike[G]=!1,V.kinds[G]=V.kinds[G]==="preserved-space"?"preserved-space":"space",V.texts[G+1]=N.marks+V.texts[G+1],V.starts[G+1]=V.starts[G]+N.space.length}return V}function Fq($,Y){if($.len===0)return[];if(!Y.preserveHardBreaks)return[{startSegmentIndex:0,endSegmentIndex:$.len,consumedEndSegmentIndex:$.len}];let X=[],Z=0;for(let J=0;J<$.len;J++){if($.kinds[J]!=="hard-break")continue;X.push({startSegmentIndex:Z,endSegmentIndex:J,consumedEndSegmentIndex:J+1}),Z=J+1}if(Z<$.len)X.push({startSegmentIndex:Z,endSegmentIndex:$.len,consumedEndSegmentIndex:$.len});return X}function RY($,Y,X="normal"){let Z=pM(X),J=Z.mode==="pre-wrap"?lM($):xM($);if(J.length===0)return{normalized:J,chunks:[],len:0,texts:[],isWordLike:[],kinds:[],starts:[]};let K=zq(J,Y,Z);return{normalized:J,chunks:Fq(K,Z),...K}}var P2=null,bY=new Map,y2=null,Eq=/\p{Emoji_Presentation}/u,Wq=/[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u,j3=null,SY=new Map;function w3(){if(P2!==null)return P2;if(typeof OffscreenCanvas<"u")return P2=new OffscreenCanvas(1,1).getContext("2d"),P2;if(typeof document<"u")return P2=document.createElement("canvas").getContext("2d"),P2;throw Error("Text measurement requires OffscreenCanvas or a DOM canvas context.")}function Pq($){let Y=bY.get($);if(!Y)Y=new Map,bY.set($,Y);return Y}function N1($,Y){let X=Y.get($);if(X===void 0)X={width:w3().measureText($).width,containsCJK:$1($)},Y.set($,X);return X}function T2(){if(y2!==null)return y2;if(typeof navigator>"u")return y2={lineFitEpsilon:0.005,carryCJKAfterClosingQuote:!1,preferPrefixWidthsForBreakableRuns:!1,preferEarlySoftHyphenBreak:!1},y2;let $=navigator.userAgent,X=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 y2={lineFitEpsilon:X?0.015625:0.005,carryCJKAfterClosingQuote:Z,preferPrefixWidthsForBreakableRuns:X,preferEarlySoftHyphenBreak:X},y2}function yq($){let Y=$.match(/(\d+(?:\.\d+)?)\s*px/);return Y?parseFloat(Y[1]):16}function O3(){if(j3===null)j3=new Intl.Segmenter(void 0,{granularity:"grapheme"});return j3}function Tq($){return Eq.test($)||$.includes("️")}function vY($){return Wq.test($)}function jq($,Y){let X=SY.get($);if(X!==void 0)return X;let Z=w3();Z.font=$;let J=Z.measureText("\uD83D\uDE00").width;if(X=0,J>Y+0.5&&typeof document<"u"&&document.body!==null){let K=document.createElement("span");K.style.font=$,K.style.display="inline-block",K.style.visibility="hidden",K.style.position="absolute",K.textContent="\uD83D\uDE00",document.body.appendChild(K);let Q=K.getBoundingClientRect().width;if(document.body.removeChild(K),J-Q>0.5)X=J-Q}return SY.set($,X),X}function wq($){let Y=0,X=O3();for(let Z of X.segment($))if(Tq(Z.segment))Y++;return Y}function Oq($,Y){if(Y.emojiCount===void 0)Y.emojiCount=wq($);return Y.emojiCount}function A1($,Y,X){if(X===0)return Y.width;return Y.width-Oq($,Y)*X}function fY($,Y,X,Z){if(Y.graphemeWidths!==void 0)return Y.graphemeWidths;let J=[],K=O3();for(let Q of K.segment($)){let M=N1(Q.segment,X);J.push(A1(Q.segment,M,Z))}return Y.graphemeWidths=J.length>1?J:null,Y.graphemeWidths}function mY($,Y,X,Z){if(Y.graphemePrefixWidths!==void 0)return Y.graphemePrefixWidths;let J=[],K=O3(),Q="";for(let M of K.segment($)){Q+=M.segment;let D=N1(Q,X);J.push(A1(Q,D,Z))}return Y.graphemePrefixWidths=J.length>1?J:null,Y.graphemePrefixWidths}function hY($,Y){let X=w3();X.font=$;let Z=Pq($),J=yq($),K=Y?jq($,J):0;return{cache:Z,fontSize:J,emojiCorrection:K}}function X6($){return $==="space"||$==="preserved-space"||$==="tab"||$==="zero-width-break"||$==="soft-hyphen"}function Bq($,Y){while(Y<$.widths.length){let X=$.kinds[Y];if(X!=="space"&&X!=="zero-width-break"&&X!=="soft-hyphen")break;Y++}return Y}function Cq($,Y){if(Y<=0)return 0;let X=$%Y;if(Math.abs(X)<=0.000001)return Y;return Y-X}function kY($,Y,X,Z){if(!Z||Y===null)return $[X];return Y[X]-(X>0?Y[X-1]:0)}function Lq($,Y,X,Z,J,K){let Q=0,M=Y;while(Q<$.length){let D=K?Y+$[Q]:M+$[Q];if((Q+1<$.length?D+J:D)>X+Z)break;M=D,Q++}return{fitCount:Q,fittedWidth:M}}function Rq($,Y,X){let{widths:Z,kinds:J,breakableWidths:K,breakablePrefixWidths:Q}=$;if(Z.length===0)return 0;let M=T2(),D=M.lineFitEpsilon,q=0,U=0,V=!1,G=0,N=0,A=0,_=0,z=-1,F=0;function B(){z=-1,F=0}function W(C=A,T=_,H=U){q++,X?.({startSegmentIndex:G,startGraphemeIndex:N,endSegmentIndex:C,endGraphemeIndex:T,width:H}),U=0,V=!1,B()}function S(C,T){V=!0,G=C,N=0,A=C+1,_=0,U=T}function b(C,T,H){V=!0,G=C,N=T,A=C,_=T+1,U=H}function k(C,T){if(!V){S(C,T);return}U+=T,A=C+1,_=0}function P(C,T){if(!X6(J[C]))return;z=C+1,F=U-T}function y(C){E(C,0)}function E(C,T){let H=K[C],R=Q[C]??null;for(let u=T;u<H.length;u++){let g=kY(H,R,u,M.preferPrefixWidthsForBreakableRuns);if(!V){b(C,u,g);continue}if(U+g>Y+D)W(),b(C,u,g);else U+=g,A=C,_=u+1}if(V&&A===C&&_===H.length)A=C+1,_=0}let w=0;while(w<Z.length){if(!V){if(w=Bq($,w),w>=Z.length)break}let C=Z[w],T=J[w];if(!V){if(C>Y&&K[w]!==null)y(w);else S(w,C);P(w,C),w++;continue}if(U+C>Y+D){if(X6(T)){k(w,C),W(w+1,0,U-C),w++;continue}if(z>=0){if(A>z||A===z&&_>0){W();continue}W(z,0,F);continue}if(C>Y&&K[w]!==null){W(),y(w),w++;continue}W();continue}k(w,C),P(w,C),w++}if(V)W();return q}function uY($,Y,X){if($.simpleLineWalkFastPath)return Rq($,Y,X);let{widths:Z,lineEndFitAdvances:J,lineEndPaintAdvances:K,kinds:Q,breakableWidths:M,breakablePrefixWidths:D,discretionaryHyphenWidth:q,tabStopAdvance:U,chunks:V}=$;if(Z.length===0||V.length===0)return 0;let G=T2(),N=G.lineFitEpsilon,A=0,_=0,z=!1,F=0,B=0,W=0,S=0,b=-1,k=0,P=0,y=null;function E(){b=-1,k=0,P=0,y=null}function w(O=W,v=S,f=_){A++,X?.({startSegmentIndex:F,startGraphemeIndex:B,endSegmentIndex:O,endGraphemeIndex:v,width:f}),_=0,z=!1,E()}function C(O,v){z=!0,F=O,B=0,W=O+1,S=0,_=v}function T(O,v,f){z=!0,F=O,B=v,W=O,S=v+1,_=f}function H(O,v){if(!z){C(O,v);return}_+=v,W=O+1,S=0}function R(O,v){if(!X6(Q[O]))return;let f=Q[O]==="tab"?0:J[O],a=Q[O]==="tab"?v:K[O];b=O+1,k=_-v+f,P=_-v+a,y=Q[O]}function u(O){g(O,0)}function g(O,v){let f=M[O],a=D[O]??null;for(let x=v;x<f.length;x++){let E0=kY(f,a,x,G.preferPrefixWidthsForBreakableRuns);if(!z){T(O,x,E0);continue}if(_+E0>Y+N)w(),T(O,x,E0);else _+=E0,W=O,S=x+1}if(z&&W===O&&S===f.length)W=O+1,S=0}function I(O){if(y!=="soft-hyphen")return!1;let v=M[O];if(v===null)return!1;let f=G.preferPrefixWidthsForBreakableRuns?D[O]??v:v,a=f!==v,{fitCount:x,fittedWidth:E0}=Lq(f,_,Y,N,q,a);if(x===0)return!1;if(_=E0,W=O,S=x,E(),x===v.length)return W=O+1,S=0,!0;return w(O,x,E0+q),g(O,x),!0}function j(O){A++,X?.({startSegmentIndex:O.startSegmentIndex,startGraphemeIndex:0,endSegmentIndex:O.consumedEndSegmentIndex,endGraphemeIndex:0,width:0}),E()}for(let O=0;O<V.length;O++){let v=V[O];if(v.startSegmentIndex===v.endSegmentIndex){j(v);continue}z=!1,_=0,F=v.startSegmentIndex,B=0,W=v.startSegmentIndex,S=0,E();let f=v.startSegmentIndex;while(f<v.endSegmentIndex){let a=Q[f],x=a==="tab"?Cq(_,U):Z[f];if(a==="soft-hyphen"){if(z)W=f+1,S=0,b=f+1,k=_+q,P=_+q,y=a;f++;continue}if(!z){if(x>Y&&M[f]!==null)u(f);else C(f,x);R(f,x),f++;continue}if(_+x>Y+N){let t0=_+(a==="tab"?0:J[f]),u0=_+(a==="tab"?x:K[f]);if(y==="soft-hyphen"&&G.preferEarlySoftHyphenBreak&&k<=Y+N){w(b,0,P);continue}if(y==="soft-hyphen"&&I(f)){f++;continue}if(X6(a)&&t0<=Y+N){H(f,x),w(f+1,0,u0),f++;continue}if(b>=0&&k<=Y+N){if(W>b||W===b&&S>0){w();continue}let g0=b;w(g0,0,P),f=g0;continue}if(x>Y&&M[f]!==null){w(),u(f),f++;continue}w();continue}H(f,x),R(f,x),f++}if(z){let a=b===v.consumedEndSegmentIndex?P:_;w(v.consumedEndSegmentIndex,0,a)}}return A}var B3=null,gY=new WeakMap;function pY(){if(B3===null)B3=new Intl.Segmenter(void 0,{granularity:"grapheme"});return B3}function bq($){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 Sq($,Y,X){let Z=pY(),J=T2(),{cache:K,emojiCorrection:Q}=hY(Y,vY($.normalized)),M=A1("-",N1("-",K),Q),q=A1(" ",N1(" ",K),Q)*8;if($.len===0)return bq(X);let U=[],V=[],G=[],N=[],A=$.chunks.length<=1,_=X?[]:null,z=[],F=[],B=X?[]:null,W=Array.from({length:$.len}),S=Array.from({length:$.len});function b(y,E,w,C,T,H,R,u){if(T!=="text"&&T!=="space"&&T!=="zero-width-break")A=!1;if(U.push(E),V.push(w),G.push(C),N.push(T),_?.push(H),z.push(R),F.push(u),B!==null)B.push(y)}for(let y=0;y<$.len;y++){W[y]=U.length;let E=$.texts[y],w=$.isWordLike[y],C=$.kinds[y],T=$.starts[y];if(C==="soft-hyphen"){b(E,0,M,M,C,T,null,null),S[y]=U.length;continue}if(C==="hard-break"){b(E,0,0,0,C,T,null,null),S[y]=U.length;continue}if(C==="tab"){b(E,0,0,0,C,T,null,null),S[y]=U.length;continue}let H=N1(E,K);if(C==="text"&&H.containsCJK){let I="",j=0;for(let O of Z.segment(E)){let v=O.segment;if(I.length===0){I=v,j=O.index;continue}if(z4.has(I)||W3.has(v)||W2.has(v)||J.carryCJKAfterClosingQuote&&$1(v)&&T3(I)){I+=v;continue}let f=N1(I,K),a=A1(I,f,Q);b(I,a,a,a,"text",T+j,null,null),I=v,j=O.index}if(I.length>0){let O=N1(I,K),v=A1(I,O,Q);b(I,v,v,v,"text",T+j,null,null)}S[y]=U.length;continue}let R=A1(E,H,Q),u=C==="space"||C==="preserved-space"||C==="zero-width-break"?0:R,g=C==="space"||C==="zero-width-break"?0:R;if(w&&E.length>1){let I=fY(E,H,K,Q),j=J.preferPrefixWidthsForBreakableRuns?mY(E,H,K,Q):null;b(E,R,u,g,C,T,I,j)}else b(E,R,u,g,C,T,null,null);S[y]=U.length}let k=vq($.chunks,W,S),P=_===null?null:wY($.normalized,_);if(B!==null)return{widths:U,lineEndFitAdvances:V,lineEndPaintAdvances:G,kinds:N,simpleLineWalkFastPath:A,segLevels:P,breakableWidths:z,breakablePrefixWidths:F,discretionaryHyphenWidth:M,tabStopAdvance:q,chunks:k,segments:B};return{widths:U,lineEndFitAdvances:V,lineEndPaintAdvances:G,kinds:N,simpleLineWalkFastPath:A,segLevels:P,breakableWidths:z,breakablePrefixWidths:F,discretionaryHyphenWidth:M,tabStopAdvance:q,chunks:k}}function vq($,Y,X){let Z=[];for(let J=0;J<$.length;J++){let K=$[J],Q=K.startSegmentIndex<Y.length?Y[K.startSegmentIndex]:X[X.length-1]??0,M=K.endSegmentIndex<Y.length?Y[K.endSegmentIndex]:X[X.length-1]??0,D=K.consumedEndSegmentIndex<Y.length?Y[K.consumedEndSegmentIndex]:X[X.length-1]??0;Z.push({startSegmentIndex:Q,endSegmentIndex:M,consumedEndSegmentIndex:D})}return Z}function fq($,Y,X,Z){let J=RY($,T2(),Z?.whiteSpace);return Sq(J,Y,X)}function xY($,Y,X){return fq($,Y,!0,X)}function mq($){return $}function IY($,Y,X){let Z=X.get($);if(Z!==void 0)return Z;Z=[];let J=pY();for(let K of J.segment(Y[$]))Z.push(K.segment);return X.set($,Z),Z}function hq($){let Y=gY.get($);if(Y!==void 0)return Y;return Y=new Map,gY.set($,Y),Y}function kq($,Y,X,Z){return Z>0&&$[Z-1]==="soft-hyphen"&&!(Y===Z&&X>0)}function uq($,Y,X,Z,J,K,Q){let M="",D=kq(Y,Z,J,K);for(let q=Z;q<K;q++){if(Y[q]==="soft-hyphen"||Y[q]==="hard-break")continue;if(q===Z&&J>0)M+=IY(q,$,X).slice(J).join("");else M+=$[q]}if(Q>0){if(D)M+="-";M+=IY(K,$,X).slice(Z===K?J:0,Q).join("")}else if(D)M+="-";return M}function gq($,Y,X,Z,J,K,Q){return{text:uq($.segments,$.kinds,Y,Z,J,K,Q),width:X,start:{segmentIndex:Z,graphemeIndex:J},end:{segmentIndex:K,graphemeIndex:Q}}}function Iq($,Y,X){return gq($,Y,X.width,X.startSegmentIndex,X.startGraphemeIndex,X.endSegmentIndex,X.endGraphemeIndex)}function lY($,Y,X){let Z=[];if($.widths.length===0)return{lineCount:0,height:0,lines:Z};let J=hq($),K=uY(mq($),Y,(Q)=>{Z.push(Iq($,J,Q))});return{lineCount:K,height:K*X,lines:Z}}function F4($,Y,X){let Z=$.image?Y.images.get($.image.url)??null:null,J=$.image?.width??null,K=Math.min(X,J??240),Q=Math.max(120,Math.round(K*0.5625));if(!Z||Z.intrinsicWidth<=0||Z.intrinsicHeight<=0)return{height:Q,width:K};let M=Math.min(X,J??Z.intrinsicWidth),D=Math.min(1,M/Z.intrinsicWidth);return{height:Math.max(48,Math.round(Z.intrinsicHeight*D)),width:Math.max(48,Math.round(Z.intrinsicWidth*D))}}function dY($,Y){if(!$.image)return`${$.kind}:missing-image`;let X=Y.images.get($.image.url);return`${$.kind}:${$.image.url}:${$.image.width??0}:${X?.status??"loading"}:${X?.intrinsicWidth??0}:${X?.intrinsicHeight??0}`}var cY=[{fontSize:32,lineHeight:36},{fontSize:26,lineHeight:32},{fontSize:21,lineHeight:28},{fontSize:21,lineHeight:28},{fontSize:19,lineHeight:26},{fontSize:18,lineHeight:26}],Z6;function j2($){if($?.type==="heading"){let{fontSize:Y}=iY($.depth);return`700 ${Y}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 _1($,Y){if($?.type==="heading")return iY($.depth).lineHeight;if($?.type==="code")return 22;return Y}function iY($){return cY[$-1]??cY.at(-1)}function w2($,Y,X,Z,J,K,Q){let M=`${K6(Y,Q)}:${J}:${K}:${X}`,D=$.measuredLines.get(M);if(D)return D;let q=xq($,Y,X,Z,J,K,Q);return zY($,M,q)}function J6($,Y,X,Z,J,K,Q,M){let D=`${K6(Y,M)}:${X}:${Z}:${K}:${Q}`,q=$.lineBoundaries.get(D);if(q)return q;let U=nY();if(!U)return rY(J);let V=[{left:0,offset:0}],G=0,N=Y.inlines.filter((A)=>A.end>X&&A.start<Z);if(N.length===0)return rY(J);for(let A of N){let _=Math.max(X,A.start),z=Math.min(Z,A.end),F=Y.text.slice(_,z),B=_-X;if(A.kind==="image"){let W=F4(A,M,Q).width;G+=W,B+=F.length,V.push({left:G,offset:B});continue}U.font=oY(K,A.marks);for(let W of Array.from(F))G+=tY($,U,W),B+=W.length,V.push({left:G,offset:B})}return FY($,D,V)}function pq($,Y,X,Z){let J=`${X}::${Z}::${Y}`,K=$.preparedText.get(J);if(K)return K;let Q=xY(Y,X,{whiteSpace:Z});return HY($,J,Q)}function xq($,Y,X,Z,J,K,Q){let M=Y.text;if(M.length===0)return[{end:0,height:K,start:0,text:"",width:0}];if(rq(Y))return dq($,Y,X,J,K,Q);try{let D=pq($,M,X,tq(Z));return lY(D,J,K).lines.map((U)=>({end:aY(D.segments,U.end),height:K,start:aY(D.segments,U.start),text:U.text,width:U.width}))}catch{return lq(M,J,K)}}function aY($,Y){let X=0;for(let K=0;K<Y.segmentIndex;K+=1)X+=$[K]?.length??0;let Z=$[Y.segmentIndex]??"",J=Array.from(Z);for(let K=0;K<Y.graphemeIndex;K+=1)X+=J[K]?.length??0;return X}function rY($){let Y=[{left:0,offset:0}],X=0,Z=0;for(let J of Array.from($))X+=9,Z+=J.length,Y.push({left:X,offset:Z});return Y}function lq($,Y,X){let Z=Math.max(1,Math.floor(Y/9)),J=eq($,Z),K=0;return J.map((Q)=>{let M=K,D=M+Q.length;return K=D,{end:D,height:X,start:M,text:Q,width:Q.length*9}})}function dq($,Y,X,Z,J,K){let Q=aq($,nY(),Y,X,Z,J,K);if(Q.length===0)return[{end:0,height:J,start:0,text:"",width:0}];return cq(Q,Y.text,Z,J)}function cq($,Y,X,Z){let J=[],K=0;while(K<$.length){let M=$[K].start;if($[K].text===`
|
|
21
|
-
`){
|
|
22
|
-
`)break;let
|
|
23
|
-
`){let
|
|
24
|
-
`?
|
|
25
|
-
`)
|
|
26
|
-
`?0:
|
|
27
|
-
`),
|
|
28
|
-
`).reduce((K,Q)=>K+Math.max(1,Math.ceil(Q.length/Z)),0);return{estimatedHeight:J*X,lineCount:J,width:$.width}}function M6($,Y,X=k1(),Z=null){let J=Z??{images:new Map},K={...e5,...Y},Q=[],M=new Map,D=new Map($.regions.map((z)=>[z.id,{textLength:z.text.length}])),q=$.blockIndex,U=W4($.document.blocks),V=new Map,G=new Set($.regions.map((z)=>z.id)),N=K.paddingY,A=null;for(let z of $.blocks){let F=U.get(z.id)??null;if(!F||G1(F))continue;let B=r0(z),W=z.regionIds.filter((P)=>G.has(P));if(!B&&W.length===0)continue;if(A!==null){N+=$6(q,U,A,z.id,K.blockGap);let P=$.blockIndex.get(A);if(P&&!r0(P)){let y=V.get(A);if(y)y.bottom=Math.max(y.bottom,N)}}let S=z.depth,b=K.paddingX+S*K.indentWidth,k=Math.max(40,K.width-b-K.paddingX);if(B)N=ZD(V,z.id,N,K);else if(F.type==="table"){let P=W.map((y)=>$.regionIndex.get(y)).filter((y)=>y!==void 0);N=eY(Q,V,M,P,X,F,b,N,K,J)}else for(let P of W){let y=$.regionIndex.get(P);if(!y)continue;N=JD(Q,V,M,y,X,F,b,N,k,K,J)}A=z.id}let _=[];for(let z of $.blocks){let F=U.get(z.id);if(!F||G1(F))continue;let B=V.get(z.id);if(!B)continue;_.push({bottom:B.bottom,depth:z.depth,id:z.id,top:B.top,type:z.type})}return{blocks:_,regionBounds:M,regionLineIndices:KD(Q),regionMetrics:D,height:Math.max(N,K.paddingY),lines:Q,options:K,width:K.width}}function ZD($,Y,X,Z){let J=Z.lineHeight;return $.set(Y,{top:X,bottom:X+J}),X+J}function JD($,Y,X,Z,J,K,Q,M,D,q,U){let V=j2(K),G=_1(K,q.lineHeight),N=w2(J,Z,V,K,D,G,U),A=M;for(let _ of N){let z={blockId:Z.blockId,boundaries:J6(J,Z,_.start,_.end,_.text,V,D,U),regionId:Z.id,end:_.end,font:V,height:_.height,left:Q,start:_.start,text:_.text,top:A,width:_.width};$.push(z),L3(Y,z),QD(X,z),A+=_.height}return A}function KD($){let Y=[...$].sort((Z,J)=>Z.top-J.top||Z.left-J.left),X=new Map;$.length=0,$.push(...Y);for(let[Z,J]of $.entries()){let K=X.get(J.regionId)??[];K.push(Z),X.set(J.regionId,K)}return X}function QD($,Y){let X=$.get(Y.regionId),Z=Y.left+Y.width,J=Y.top+Y.height;$.set(Y.regionId,X?{bottom:Math.max(X.bottom,J),left:Math.min(X.left,Y.left),right:Math.max(X.right,Z),top:Math.min(X.top,Y.top)}:{bottom:J,left:Y.left,right:Z,top:Y.top})}function L3($,Y){let X=$.get(Y.blockId),Z=Y.top+Y.height;$.set(Y.blockId,{bottom:X?Math.max(X.bottom,Z):Z,top:X?Math.min(X.top,Y.top):Y.top})}function W4($){let Y=new Map,X=(Z)=>{for(let J of Z)if(Y.set(J.id,J),J.type==="blockquote"||J.type==="listItem")X(J.children);else if(J.type==="list")X(J.items)};return X($),Y}var q6=null;function MD($){let Y=/(\d+(?:\.\d+)?)\s*px/.exec($);return Y?Number.parseFloat(Y[1]):16}function H1($){q6??=new Map;let Y=q6.get($);if(Y)return Y;let X=YX(),Z=Math.max(12,Math.round(MD($)));if(!X){let G={ascent:Math.round(Z*0.8),descent:Math.max(2,Z-Math.round(Z*0.8)),emHeight:Z};return q6.set($,G),G}X.font=$;let J=X.measureText("Hg"),K=Math.round(J.actualBoundingBoxAscent||0),Q=Math.round(J.actualBoundingBoxDescent||0),M=K+Q,D=Math.max(Z,M),q=M>0?K:Math.round(D*0.8),U=M>0?Q:Math.max(2,D-q),V={ascent:q,descent:U,emHeight:D};return q6.set($,V),V}function P4($,Y){let{emHeight:X}=H1(Y);return Math.max(0,Math.floor(($-X)/2))}function y4($,Y){let{ascent:X}=H1(Y);return P4($,Y)+X}var D6;function $X($,Y){let X=YX();if(!X||$.length===0)return 0;return X.font=Y,X.measureText($).width}function YX(){if(D6!==void 0)return D6;return D6=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):typeof document<"u"?document.createElement("canvas"):null)?.getContext("2d")??null,D6}function R3($,Y){let X=0,Z=$.lines.length-1;while(X<=Z){let J=X+Z>>1,K=$.lines[J];if(Y<K.top){Z=J-1;continue}if(Y>=K.top+K.height){X=J+1;continue}return{index:J,line:K}}return null}function U6($,Y){let X=[...$.regionBounds.entries()].find(([,K])=>{return Y.x>=K.left&&Y.x<=K.right&&Y.y>=K.top&&Y.y<=K.bottom});if(X)return T4($,X[0],Y.y);let Z=R3($,Y.y);if(!Z)return null;let J=qD($,Y.y,Z.index);if(J.length===1)return J[0]??null;return J.find((K)=>{let Q=$.regionBounds.get(K.line.regionId);return Q?Y.x>=Q.left&&Y.x<=Q.right:!1})??[...J].sort((K,Q)=>{let M=$.regionBounds.get(K.line.regionId),D=$.regionBounds.get(Q.line.regionId),q=ZX(Y.x,M),U=ZX(Y.x,D);return q-U})[0]??null}function G6($,Y,X){if($.blocks.length===0)return{endIndex:0,startIndex:0};let Z=Y+X,J=XX($,Y),K=XX($,Z);if(J>0){if($.blocks[J-1].bottom>Y)J-=1}if(K<$.blocks.length){if($.blocks[K].top<Z)K+=1}return{endIndex:K,startIndex:J}}function XX($,Y){let X=0,Z=$.blocks.length;while(X<Z){let J=X+Z>>1;if($.blocks[J].bottom<=Y)X=J+1;else Z=J}return X}function V6($,Y,X){if($.lines.length===0)return{endIndex:0,startIndex:0};let Z=Y+X,J=JX($,Y),K=JX($,Z);if(J>0){let Q=$.lines[J-1];if(Q.top+Q.height>Y)J-=1}if(K<$.lines.length){if($.lines[K].top<Z)K+=1}return{endIndex:K,startIndex:J}}function C0($,Y,X){return B2($,Y,X)?.line??null}function T4($,Y,X){let Z=$.regionLineIndices.get(Y);if(!Z||Z.length===0)return null;let J=Z[0],K=Number.POSITIVE_INFINITY;for(let Q of Z){let M=$.lines[Q],D=X<M.top?M.top-X:X>M.top+M.height?X-(M.top+M.height):0;if(D<K)K=D,J=Q;if(D===0)break}return{index:J,line:$.lines[J]}}function B2($,Y,X){let Z=$.regionLineIndices.get(Y);if(!Z||Z.length===0)return null;let J=0,K=Z.length-1;while(J<=K){let U=J+K>>1,V=Z[U],G=$.lines[V];if(X<G.start){K=U-1;continue}if(X>G.end){J=U+1;continue}return{index:V,line:G}}let Q=Z[0],M=Z[Z.length-1],D=$.lines[Q],q=$.lines[M];if(X<=D.start)return{index:Q,line:D};if(X>=q.end)return{index:M,line:q};return null}function qD($,Y,X){let Z=[];for(let J=X;J>=0;J-=1){let K=$.lines[J];if(Y<K.top||Y>=K.top+K.height)break;Z.unshift({index:J,line:K})}for(let J=X+1;J<$.lines.length;J+=1){let K=$.lines[J];if(Y<K.top||Y>=K.top+K.height)break;Z.push({index:J,line:K})}return Z}function ZX($,Y){if(!Y)return Number.POSITIVE_INFINITY;if($<Y.left)return Y.left-$;if($>Y.right)return $-Y.right;return 0}function G0($,Y){return $.left+DD($.boundaries,Y)}function DD($,Y){for(let Z of $)if(Z.offset===Y)return Z.left;return $.filter((Z)=>Z.offset<=Y).at(-1)?.left??0}function JX($,Y){let X=0,Z=$.lines.length;while(X<Z){let J=X+Z>>1,K=$.lines[J];if(K.top+K.height<=Y)X=J+1;else Z=J}return X}function b3($,Y){if($.length===0)return 0;for(let X=1;X<$.length;X+=1){let Z=$[X-1],J=$[X],K=Z.left+(J.left-Z.left)/2;if(Y<=K)return Z.offset;if(Y<=J.left)return J.offset}return $.at(-1)?.offset??0}var UD=18,GD=14,VD=22;function X1($,Y,X){return G0(Y,X)+T0($,Y)}function T0($,Y){let X=Z1($,Y.blockId,"listItem");if(!X)return 0;return g1($,X.id)?.kind==="task"?VD:UD}function u1($){return{left:$.left,size:GD,top:$.top+3}}function Z1($,Y,X){let Z=$.documentIndex.blockIndex.get(Y)??null;while(Z){if(Z.type===X)return Z;let J=Z.parentBlockId;Z=J?$.documentIndex.blockIndex.get(J)??null:null}return null}function g1($,Y){return $.documentIndex.listItemMarkers.get(Y)??null}function v0($,Y,X){if(!$.regionMetrics.get(X.regionId))return null;let J=C0($,X.regionId,X.offset);if(!J)return null;return{blockId:J.blockId,regionId:J.regionId,height:J.height,left:G0(J,X.offset-J.start),offset:X.offset,top:J.top}}function m0($,Y,X){let Z=C0(Y,X.regionId,X.offset);if(!Z)return X.left;return X.left+T0($,Z)+ND($,Z,X.offset)}function ND($,Y,X){if(X<=Y.end)return 0;let Z=$.documentIndex.regionIndex.get(Y.regionId);if(!Z)return 0;let J=Z.text.slice(Y.end,X);if(!/^[ \t]+$/u.test(J))return 0;return $X(J,Y.font)}function j0($,Y,X){let Z=AD($,Y,X);if(!Z)return null;let J=Z.snapToLineStart?Z.line.left:X.x;return KX($,Y,Z.line,J)}function N6($,Y,X){let Z=$.lines[$.lines.length-1];if(!Z||X.y<=Z.top+Z.height)return null;return KX($,Y,Z,X.x)}function A6($,Y,X,Z){let J=QX(Y,Z.regionId);if(!J)return null;let K=j0($,Y,X);if(K)return{regionId:K.regionId,offset:K.offset};let Q=X.y<_D($);return{regionId:Z.regionId,offset:Q?0:J.text.length}}function _6($,Y,X){let Z=j0($,Y,X);if(!Z)return null;let J=QX(Y,Z.regionId);if(!J||J.text.length===0)return null;let K=Z.offset<J.text.length&&/\w/.test(J.text[Z.offset]??"")?Z.offset:Z.offset>0&&/\w/.test(J.text[Z.offset-1]??"")?Z.offset-1:Z.offset,Q=HD(J.text,K);if(Q.start===Q.end)return null;return{anchor:{regionId:Z.regionId,offset:Q.start},focus:{regionId:Z.regionId,offset:Q.end}}}function KX($,Y,X,Z){let J=$.regionMetrics.get(X.regionId);if(!J)return null;let K=Math.max(0,Z-T0(Y,X)-X.left),Q=b3(X.boundaries,K),M=Math.min(J.textLength,X.start+Q);return{regionId:X.regionId,offset:M,left:G0(X,Q),top:X.top,height:X.height}}function AD($,Y,X){for(let[J,K]of $.regionBounds)if(X.x>=K.left&&X.x<=K.right&&X.y>=K.top&&X.y<=K.bottom){let Q=T4($,J,X.y)?.line??null;return Q?{line:Q}:null}let Z=U6($,X)?.line??null;if(Z)return{line:Z};for(let J of $.blocks){if(X.y<J.top||X.y>J.bottom)continue;for(let Q=$.lines.length-1;Q>=0;Q--)if($.lines[Q].blockId===J.id)return{line:$.lines[Q]};let K=Y.documentIndex.blockIndex.get(J.id);if(K&&r0(K)){let Q=t2(Y.documentIndex,J.id);if(Q){let M=$.lines.find((D)=>D.blockId===Q.id);if(M)return{line:M,snapToLineStart:!0}}}}return null}function QX($,Y){return $.documentIndex.regionIndex.get(Y)??null}function _D($){return $.lines[0]?.top??0}function HD($,Y){let X=Y,Z=Y;while(X>0&&/\w/.test($[X-1]??""))X-=1;while(Z<$.length&&/\w/.test($[Z]??""))Z+=1;return{end:Z,start:X}}function S3($,Y,X){let Z=zD($,X);if(!Z||Z.start!==0)return null;let J=Z1(Y,Z.blockId,"listItem");if(!J)return null;if(g1(Y,J.id)?.kind!=="task")return null;let Q=u1(Z),M=Q.left-4,D=Q.left+Q.size+4,q=Q.top-4,U=Q.top+Q.size+4;return X.x>=M&&X.x<=D&&X.y>=q&&X.y<=U?{listItemId:J.id}:null}function v3($,Y,X){let Z=j0($,Y,X);if(!Z)return null;let J=FD(Y,Z.regionId);if(!J)return null;let K=J.inlines.find((M)=>M.link&&Z.offset>=M.start&&Z.offset<M.end);if(!K?.link)return null;let Q=f3($,Y,Z.regionId,K.start);if(!Q)return null;return{anchorBottom:Q.anchorBottom,anchorLeft:Q.anchorLeft,endOffset:K.end,regionId:Z.regionId,startOffset:K.start,title:K.link.title,url:K.link.url}}function H6($,Y,X,Z){let J=S3($,Y,X);if(J)return{kind:"task-toggle",listItemId:J.listItemId};let K=j0($,Y,X);if(!K)return null;let Q=MX(K.regionId,K.offset,Z),M=Q!==null?qX(Q,$,Y,Z):null,D=v3($,Y,X);if(D)return{anchorBottom:M?.anchorBottom??D.anchorBottom,anchorLeft:M?.anchorLeft??D.anchorLeft,endOffset:D.endOffset,kind:"link",commentThreadIndex:Q,regionId:D.regionId,startOffset:D.startOffset,title:D.title,url:D.url};return{anchorBottom:M?.anchorBottom??K.top+K.height,anchorLeft:M?.anchorLeft??K.left,kind:"text",commentThreadIndex:Q}}function z6($,Y,X,Z){let J=Y.documentIndex.regionIndex.get(X.regionId);if(!J)return null;let K=MX(X.regionId,X.offset,Z),Q=K!==null?qX(K,$,Y,Z):null,M=J.inlines.find((D)=>X.offset>=D.start&&X.offset<=D.end)??null;if(M?.link){let D=f3($,Y,X.regionId,M.start);if(!D)return null;return{anchorBottom:Q?.anchorBottom??D.anchorBottom,anchorLeft:Q?.anchorLeft??D.anchorLeft,commentThreadIndex:K,endOffset:M.end,kind:"link",regionId:X.regionId,startOffset:M.start,title:M.link.title,url:M.link.url}}if(Q)return{anchorBottom:Q.anchorBottom,anchorLeft:Q.anchorLeft,commentThreadIndex:K,kind:"text"};return null}function j4($,Y,X,Z){let J=$.documentIndex.regionIndex.get($.selection.anchor.regionId);if(!Z.image||!J)return null;let K=C0(Y.layout,J.id,Z.start);if(!K)return null;let Q=K.left+T0($,K),M=Q+G0(K,Z.start-K.start)-K.left,D=Q+G0(K,Z.end-K.start)-K.left,{height:q}=F4(Z,X,K.width),U=K.top+Math.max(0,Math.floor((K.height-q)/2));return{left:M,top:U,width:D-M,height:q}}function MX($,Y,X){for(let Z of X)if(Z.regionId===$&&Y>=Z.startOffset&&Y<=Z.endOffset)return Z.threadIndex;return null}function qX($,Y,X,Z){let J=Z.find((K)=>K.threadIndex===$);if(!J)return null;return f3(Y,X,J.regionId,J.startOffset)}function f3($,Y,X,Z){let J=C0($,X,Z);if(!J)return null;return{anchorBottom:J.top+J.height,anchorLeft:G0(J,Z)+T0(Y,J)}}function zD($,Y){return $.lines.find((X)=>Y.y>=X.top-4&&Y.y<=X.top+X.height+4)??$.lines.filter((X)=>Math.abs(Y.y-(X.top+X.height/2))<=10).sort((X,Z)=>Math.abs(Y.y-(X.top+X.height/2))-Math.abs(Y.y-(Z.top+Z.height/2)))[0]??null}function FD($,Y){return $.documentIndex.regionIndex.get(Y)??null}function DX($,Y,X,Z,J,K){let Q=m3(Y,J,K),M=$.measuredContainerHeights.get(Q);if(M!==void 0)return M;let D=J.paddingX??0,q=J.indentWidth??24,U=_1(X,J.lineHeight??24),V=D+Z*q,G=Math.max(40,J.width-V-D);if(Y.inlines.some((_)=>_.kind==="image")){let _=j2(X);return w2($,Y,_,X,G,U,K).reduce((z,F)=>z+F.height,0)}let N=Q6({charWidth:J.charWidth,lineHeight:U,text:Y.text,width:G});return Math.max(U,N.lineCount*U)}function UX($,Y,X,Z){let J=Q6({charWidth:Z,lineHeight:X,text:$.text,width:Y});return Math.max(X,J.lineCount*X)}function m3($,Y,X){return`${K6($,X)}:${Y.width}:${Y.paddingX??0}:${Y.indentWidth??24}:${Y.lineHeight??24}`}function h3($,Y){let X=0,Z=$.entries.length;while(X<Z){let J=X+Z>>1;if($.entries[J].bottom<=Y)X=J+1;else Z=J}return X}function GX($,Y,X,Z,J){let K=Z,Q=J;for(let M=Z;M<J;M+=1){let D=$.regions[M],q=Y.get(D.blockId);if(!q)continue;if(q.type==="table"){let U=X.get(q.regionIds[0]??""),V=X.get(q.regionIds[q.regionIds.length-1]??"");if(U!==void 0)K=Math.min(K,U);if(V!==void 0)Q=Math.max(Q,V+1)}}return{endIndex:Q,startIndex:K}}function VX($,Y,X){return{...$,blocks:$.blocks.map((Z)=>({...Z,bottom:Z.bottom+Y,top:Z.top+Y})),regionBounds:new Map([...$.regionBounds.entries()].map(([Z,J])=>[Z,{bottom:J.bottom+Y,left:J.left,right:J.right,top:J.top+Y}])),height:X,lines:$.lines.map((Z)=>({...Z,top:Z.top+Y}))}}function NX($,Y,X,Z,J){for(let[K,Q]of X.regionBounds){let M=Q.bottom-Q.top,D=Y.regionIndex.get(K);EY($,m3(D??{path:K,inlines:[],text:""},Z,J),M)}}function k3($,Y,X,Z=[],J=k1(),K=null){let Q=K??{images:new Map},M=W4($.document.blocks),D=$.blockIndex,q=new Set(Z),U=Math.max(0,X.top-X.overscan),V=X.top+X.height+X.overscan,G=WD(J,$,M,D,Y,Q),N=h3(G,U),A=h3(G,V);if(N>0){let W=G.entries[N-1];if(W&&W.bottom>U)N-=1}if(A<G.entries.length){let W=G.entries[A];if(W&&W.top<V)A+=1}for(let W of q){let S=G.containerIndices.get(W);if(S===void 0)continue;N=Math.min(N,S),A=Math.max(A,S+1)}if(!Number.isFinite(N)||!Number.isFinite(A))return{estimateRegionBounds:G.estimateRegionBounds,layout:M6({...$,regions:[]},Y,J,Q),totalHeight:G.totalHeight,viewport:X};let _=GX($,D,G.containerIndices,N,A),z=G.entries[_.startIndex]?.top??Y.paddingY??0,F=M6({...$,regions:$.regions.slice(_.startIndex,_.endIndex)},Y,J,Q),B=VX(F,z,G.totalHeight);return NX(J,$,B,Y,Q),{estimateRegionBounds:G.estimateRegionBounds,layout:B,totalHeight:G.totalHeight,viewport:X}}function WD($,Y,X,Z,J,K){let Q=TD(Y,J,K),M=PY($,Y,Q);if(M)return M;let D=J.blockGap??16,q=J.lineHeight??24,U=J.paddingY??0,V=[],G=new Map,N=0,A=null;for(let _ of Y.blocks){let z=X.get(_.id)??null;if(!z||G1(z))continue;let F=r0(_);if(!F&&_.regionIds.length===0)continue;if(A!==null)U+=$6(Z,X,A,_.id,D);if(F)U+=q;else if(z.type==="table"){let B=PD({block:z,containerIndices:G,entries:V,index:N,options:J,runtimeBlocks:Z,totalHeight:U,regions:Y.regions});if(B)N=B.nextIndex,U=B.totalHeight}else for(let B of _.regionIds){let W=Y.regions[N];if(!W){N+=1;continue}let S=DX($,W,z,_.depth,J,K),b=U,k=b+S;V[N]={bottom:k,top:b},G.set(W.id,N),U=k,N+=1}A=_.id}return yY($,Y,Q,{containerIndices:G,entries:V,estimateRegionBounds(_){let z=G.get(_);return z===void 0?null:V[z]??null},totalHeight:U})}function PD({block:$,containerIndices:Y,entries:X,index:Z,options:J,runtimeBlocks:K,totalHeight:Q,regions:M}){let D=K.get($.id),q=D?.regionIds??[];if(q.length===0)return null;let U=M.slice(Z,Z+q.length);if(U.length===0||U[0]?.blockId!==$.id)return null;let V=J.paddingX??0,G=J.indentWidth??24,N=D?.depth??0,A=V+N*G,_=Math.max(C3,J.width-A-V),z=Math.max(1,...$.rows.map((k)=>k.cells.length)),F=_/z,B=Math.max(40,F-E4*2),W=_1($,J.lineHeight??24),S=yD(U,Z),b=Q;for(let k=0;k<$.rows.length;k+=1){let P=S.get(k)??[],y=Math.max(W+O2*2,...P.map(({region:w})=>UX(w,B,W,J.charWidth)+O2*2)),E=b+y;for(let{index:w,region:C}of P)X[w]={bottom:E,top:b},Y.set(C.id,w);b=E}for(let k=Z;k<Z+U.length;k+=1){let P=M[k];if(!P||X[k])continue;X[k]={bottom:b,top:b},Y.set(P.id,k)}return{nextIndex:Z+U.length,totalHeight:b}}function yD($,Y){let X=new Map;for(let[Z,J]of $.entries()){let K=J.tableCellPosition?.rowIndex;if(K===void 0)continue;let Q=X.get(K)??[];Q.push({index:Y+Z,region:J}),X.set(K,Q)}return X}function TD($,Y,X){return[Y.width,Y.paddingX??0,Y.paddingY??0,Y.indentWidth??24,Y.lineHeight??24,Y.blockGap??16,jD($,X)].join(":")}function jD($,Y){if($.imageUrls.size===0)return"";return $.regions.flatMap((X)=>X.inlines.filter((Z)=>Z.kind==="image"&&Z.image).map((Z)=>{let J=Z.image?Y.images.get(Z.image.url):null;return`${Z.image?.url??""}:${Z.image?.width??0}:${J?.status??"loading"}:${J?.intrinsicWidth??0}:${J?.intrinsicHeight??0}`})).join("|")}function u3($,Y,X,Z=null){let J={height:Y.height,overscan:Math.max(160,Y.height),top:Y.top},K=k3($.documentIndex,Y,J,[$.selection.anchor.regionId,$.selection.focus.regionId],X,Z);return{blockMap:W4($.documentIndex.document.blocks),estimateRegionBounds:K.estimateRegionBounds,regionBounds:new Map(K.layout.regionBounds),layout:K.layout,paintHeight:Math.max(240,J.height+J.overscan*2),paintTop:Math.max(0,J.top-J.overscan),totalHeight:K.totalHeight,viewport:{height:J.height,top:J.top}}}function F6($,Y,X){return j0(Y.layout,$,X)??N6(Y.layout,$,X)}function w4($,Y,X,Z){return A6(Y.layout,$,X,Z)}function g3($,Y,X){return _6(Y.layout,$,X)}function I3($,Y,X,Z){return H6(Y.layout,$,X,Z)}function p3($,Y,X,Z){return z6(Y.layout,$,X,Z)}function x3($,Y,X){return v0(Y.layout,$.documentIndex,X)}function J1($,Y,X){let Z=v0(Y.layout,$.documentIndex,X);if(!Z)return null;return{...Z,left:m0($,Y.layout,Z)}}var AX=1;function _X($,Y,X){let Z=$.documentIndex.regionOrderIndex.get($.selection.focus.regionId);if(Z===void 0)return $;let J=$.documentIndex.regions[Z],K=$.selection.focus.offset+Y;if(K>=0&&K<=J.text.length)return y0($,J.id,K,X);if(Y<0){let M=f1($.documentIndex,J.id);if(!M)return $;return y0($,M.id,M.text.length,X)}let Q=n2($.documentIndex,J.id);if(!Q)return $;return y0($,Q.id,0,X)}function HX($,Y,X,Z,J){let K=B2(Y,X.regionId,X.offset);if(!K)return $;let Q=Y.lines[K.index+Z];if(!Q)return $;let M=j0(Y,$,{x:m0($,Y,X)+AX,y:Q.top+Q.height/2});if(!M)return $;return y0($,M.regionId,M.offset,J)}function zX($,Y,X,Z){let J=EX($,Y);if(!J)return $;return y0($,J.regionId,X==="Home"?J.start:J.end,Z)}function FX($,Y,X,Z,J){let K=EX($,Y);if(!K)return $;let M=Math.max(1,Math.floor(480/Y.options.lineHeight)),D=B2(Y,K.regionId,$.selection.focus.offset),q=D?Y.lines[D.index+Z*M]:null;if(!q)return $;let U=j0(Y,$,{x:m0($,Y,X)+AX,y:q.top+q.height/2});if(!U)return $;return y0($,U.regionId,U.offset,J)}function EX($,Y){return C0(Y,$.selection.focus.regionId,$.selection.focus.offset)}var wD=1;function WX($,Y,X,Z,J){let K=$.documentIndex.regionIndex.get($.selection.focus.regionId)??null;if(!K)return null;let Q=$.documentIndex.tableCellIndex.get(K.id)??null,M=$.documentIndex.blockIndex.get(K.blockId)??null;if(!Q||M?.type!=="table")return null;let D=OD($,M.id,Q.rowIndex+Z,Q.cellIndex)??BD($,M.id,Z);if(!D)return $;let q=Y.regionBounds.get(K.id),U=Y.regionBounds.get(D.id);if(!q||!U)return $;let V=U.top+CD(X.top+X.height/2-q.top,0,Math.max(0,U.bottom-U.top-1)),G=j0(Y,$,{x:m0($,Y,X)+wD,y:V});if(!G)return $;return y0($,G.regionId,G.offset,J)}function OD($,Y,X,Z){return V2($.documentIndex,Y,X,Z)}function BD($,Y,X){let Z=$.documentIndex.blockIndex.get(Y),J=$.documentIndex.regions,K=Z?$.documentIndex.roots[Z.rootIndex]?.regionRange:void 0;if(!K)return null;return X<0?J[K.start-1]??null:J[K.end]??null}function CD($,Y,X){return Math.max(Y,Math.min(X,$))}function l3($,Y,X=!1){return _X($,Y,X)}function d3($,Y,X,Z=!1){return LD($,Y,X,Z)}function c3($,Y,X,Z=!1){return RD($,Y,X,Z)}function a3($,Y,X,Z=!1){return zX($,Y,X,Z)}function r3($,Y,X=!1){return bD($,Y,X)}function LD($,Y,X,Z){let J=PX($,Y);if(!J)return $;return WX($,Y,J,X,Z)??HX($,Y,J,X,Z)}function RD($,Y,X,Z){let J=PX($,Y);if(!J)return $;return FX($,Y,J,X,Z)}function bD($,Y,X){let Z=$.documentIndex.regions,J=Y==="start"?Z[0]:Z.at(-1);if(!J)return $;return y0($,J.id,Y==="start"?0:J.text.length,X)}function PX($,Y){return v0(Y,$.documentIndex,{regionId:$.selection.focus.regionId,offset:$.selection.focus.offset})}var SD=80;function TX({context:$,containerBounds:Y,isHeaderRow:X,lineHeight:Z,theme:J}){let K=wX(Y,Z);$.fillStyle=X?J.tableHeaderBackground:J.tableBodyBackground,$.fillRect(K.left,K.top,K.width,K.height),OX($,K,J)}function jX({activeBlockFlashes:$,activeBlockId:Y,activeRegionId:X,context:Z,editorState:J,endIndex:K,layout:Q,regionBounds:M,startIndex:D,theme:q,verticalBleed:U}){if(!Y||!X)return;let V=J.documentIndex.blockIndex.get(Y)??null;if(V?.type!=="table")return;if((J.documentIndex.regionIndex.get(X)??null)?.blockId!==Y)return;let N=M.get(X)??null,A=Q.regionLineIndices.get(X)??null;if(!N||!A||A.length===0)return;let _=Q.lines[A[0]]??null;if(!_)return;let z=wX(N,_.height);if(z.width===0)return;let F=yX({context:Z,endIndex:K,fillStyle:q.activeBlockBackground,layout:Q,left:z.left,lineIndices:A,startIndex:D,verticalBleed:U,width:z.width}),B=V.path?$.get(V.path)??null:null;if(B)yX({context:Z,endIndex:K,fillStyle:f5(q.activeBlockFlash,B),layout:Q,left:z.left,lineIndices:A,startIndex:D,verticalBleed:U,width:z.width});if(!F)return;OX(Z,z,q)}function yX({context:$,endIndex:Y,fillStyle:X,layout:Z,left:J,lineIndices:K,startIndex:Q,verticalBleed:M,width:D}){$.fillStyle=X;let q=!1;for(let U of K){if(U<Q)continue;if(U>=Y)break;let V=Z.lines[U];$.fillRect(J,V.top-M,D,V.height),q=!0}return q}function wX($,Y){return{height:Math.max($.bottom-$.top,Y),left:$.left,top:$.top,width:Math.max($.right-$.left,SD)}}function OX($,Y,X){$.strokeStyle=X.tableBorder,$.strokeRect(Y.left,Y.top,Y.width,Y.height)}var E6=2,vD=3,fD=12,mD=6,hD=3,kD=8,uD=12,gD=28,ID=4,BX=1,pD=5,xD=2,lD=1;function CX($,Y,X,Z,J,K,Q){if(!Z||Y.start!==0)return;if(X?.type==="code"){let M=Math.max(0,Y.left-uD);$.fillStyle=K.codeBackground,$.fillRect(M,Z.top-ID,Math.max(Z.right-Y.left+gD,Q-M),Z.bottom-Z.top+kD);return}if(X?.type!=="table")return;TX({context:$,containerBounds:Z,isHeaderRow:J?.rowIndex===0,lineHeight:Y.height,theme:K})}function LX($,Y,X,Z,J,K,Q,M){if(Y.blockId!==J||X?.type==="table")return;let D=Z?K.get(Z)??null:null;if($.fillStyle=Q.activeBlockBackground,$.fillRect(0,Y.top-E6,M,Y.height),!D)return;$.fillStyle=f5(Q.activeBlockFlash,D),$.fillRect(0,Y.top-E6,M,Y.height)}function RX($,Y,X,Z,J,K){let Q=new Map;for(let M=Z;M<J;M+=1){let D=$.lines[M],q=X.get(D.blockId);if(q?.type!=="heading"||q.depth!==1&&q.depth!==2)continue;let U=Q.get(q.id),V={bottom:D.top+D.height,left:D.left+T0(Y,D),right:K-$.options.paddingX};Q.set(q.id,U?{bottom:Math.max(U.bottom,V.bottom),left:U.left,right:U.right}:V)}return Q}function bX($,Y,X,Z,J,K){for(let Q=X;Q<Z;Q+=1){let M=Y.blocks[Q];if(M.type==="divider"){let D=Y.options.paddingX+M.depth*Y.options.indentWidth,q=K-Y.options.paddingX,U=Math.round(M.top+(M.bottom-M.top-BX)/2);vX($,{color:J.dividerRule??J.headingRule,left:D,right:q,thickness:BX,top:U})}}}function SX($,Y,X){for(let Z of Y.values())vX($,{color:X.headingRule,left:Z.left,minimumWidth:xD,right:Z.right,thickness:lD,top:Z.bottom+pD})}function vX($,Y){$.fillStyle=Y.color,$.fillRect(Y.left,Y.top,Math.max(Y.minimumWidth??0,Y.right-Y.left),Y.thickness)}function fX($,Y,X,Z,J){let K=new Map;for(let Q=Z;Q<J;Q+=1){let M=$.lines[Q],D=Z1(Y,M.blockId,"blockquote");if(!D)continue;let q=K.get(D.id),U={bottom:M.top+M.height,isActive:M.blockId===X,left:$.options.paddingX+(D.depth+1)*$.options.indentWidth-10,top:M.top};K.set(D.id,q?{bottom:Math.max(q.bottom,U.bottom),isActive:q.isActive||U.isActive,left:q.left,top:Math.min(q.top,U.top)}:U)}return K}function mX($,Y,X){for(let Z of Y.values())$.fillStyle=Z.isActive?X.blockquoteRuleActive:X.blockquoteRule,$.fillRect(Z.left,Z.top+vD,hD,Math.max(fD,Z.bottom-Z.top-mD))}var dD=1,cD=2,aD=2;function s3({context:$,devicePixelRatio:Y,editorState:X,height:Z,layout:J,normalizedSelection:K,presence:Q,showCaret:M,theme:D,viewportTop:q,width:U}){$.save(),$.scale(Y,Y),$.clearRect(0,0,U,Z);let V=K.start.regionId===K.end.regionId&&K.start.offset!==K.end.offset,G=M&&!V;if($.translate(0,-q),G)hX($,X,J,{color:D.caret,offset:X.selection.focus.offset,regionId:X.selection.focus.regionId});if(Q)for(let N of Q){if(!N.cursorPoint)continue;hX($,X,J,{color:N.color??D.leafAccent,offset:N.cursorPoint.offset,regionId:N.cursorPoint.regionId})}$.restore()}function hX($,Y,X,Z){let J=v0(X,Y.documentIndex,{regionId:Z.regionId,offset:Z.offset});if(!J)return;let K=m0(Y,X,J),Q=rD(X,J);$.fillStyle=Z.color,$.fillRect(K,Q.top,cD,Q.height)}function rD($,Y){let X=C0($,Y.regionId,Y.offset),Z=X?.font??'16px "Iowan Old Style", "Palatino Linotype", serif',{ascent:J,descent:K}=H1(Z),Q=Math.max(1,J+K),M=Math.min(Y.height-aD,Q),D=X?Math.max(X.top,X.top+P4(X.height,Z)-dD):Y.top+Math.max(0,Math.floor((Y.height-M)/2));return{height:M,top:D}}var kX=2,uX=8,sD=3,iD=1.5,oD=2,C2={elbow:{x:6.5,y:10.5},end:{x:11.5,y:3.5},start:{x:3.5,y:7.5}};function gX($,Y,X,Z,J,K,Q=null){if(!X||Y.start!==0)return;if(Q){let M=m7(Q),D=YU(X,Y,Z,J,$);$.save(),$.translate(D.x,D.y),$.scale(M,M),$.translate(-D.x,-D.y)}if(X.kind==="task")nD($,Y,X.checked,K,Q);else if($.fillStyle=Q?X4(K.listMarkerText,Q,K):K.listMarkerText,X.kind==="ordered")$U($,X.label,Z,J);else $.fillText(X.label,Y.left-kX,J);if(Q)$.restore()}function nD($,Y,X,Z,J=null){let K=u1(Y);if(tD($,K,X,Z,J),!X)return;eD($,K,Z,J)}function tD($,Y,X,Z,J=null){let K=X?Z.checkboxCheckedFill:Z.checkboxUncheckedFill,Q=X?Z.checkboxCheckedStroke:Z.checkboxUncheckedStroke;$.fillStyle=J?X4(K,J,Z):K,$.strokeStyle=J?X4(Q,J,Z):Q,$.beginPath(),$.lineWidth=iD,$.roundRect(Y.left,Y.top,Y.size,Y.size,sD),$.fill(),$.stroke()}function eD($,Y,X,Z=null){$.strokeStyle=Z?X4(X.checkboxCheckmark,Z,X):X.checkboxCheckmark,$.lineWidth=oD,$.beginPath(),$.moveTo(Y.left+C2.start.x,Y.top+C2.start.y),$.lineTo(Y.left+C2.elbow.x,Y.top+C2.elbow.y),$.lineTo(Y.left+C2.end.x,Y.top+C2.end.y),$.stroke()}function $U($,Y,X,Z){let J=$.textAlign;$.textAlign="right",$.fillText(Y,X-uX,Z),$.textAlign=J}function YU($,Y,X,Z,J){if($.kind==="task"){let M=u1(Y);return{x:M.left+M.size/2,y:M.top+M.size/2}}let K=J.measureText($.label),Q=Z-(K.actualBoundingBoxAscent-K.actualBoundingBoxDescent)/2;if($.kind==="ordered")return{x:X-uX-K.width/2,y:Q};return{x:Y.left-kX+K.width/2,y:Q}}var XU=2,ZU=1,JU=2,KU=5,QU=2,MU=3;function IX($,Y){let X=$.documentIndex.regionOrderIndex,Z=X.get(Y.start.regionId),J=X.get(Y.end.regionId);return Z===void 0||J===void 0?null:{end:J,start:Z}}function pX($,Y,X,Z,J,K){if(!J)return;let Q=Y.documentIndex.regionOrderIndex.get(X.regionId);if(Q===void 0||Q<J.start||Q>J.end)return;let M=Q===J.start?Math.max(X.start,Z.start.offset):X.start,D=Q===J.end?Math.min(X.end,Z.end.offset):X.end;if(D<=M)return;$.fillStyle=K.selectionBackground,$.fillRect(X1(Y,X,M-X.start),X.top+ZU,Math.max(XU,X1(Y,X,D-X.start)-X1(Y,X,M-X.start)),X.height-JU)}function xX($,Y,X,Z,J,K){for(let Q of Z){if(Q.regionId!==X.regionId)continue;let M=Math.max(Q.startOffset,X.start),D=Math.min(Q.endOffset,X.end);if(D<=M)continue;$.fillStyle=qU(Q,J,K),$.fillRect(X1(Y,X,M-X.start),X.top+X.height-KU,Math.max(QU,X1(Y,X,D-X.start)-X1(Y,X,M-X.start)),MU)}}function qU($,Y,X){if($.resolved)return $.threadIndex===Y?X.commentHighlightResolvedActive:X.commentHighlightResolved;return $.threadIndex===Y?X.commentHighlightActive:X.commentHighlight}function dX($,Y,X,Z,J,K,Q){let M=X.image?Z.images.get(X.image.url):null,D=GU(X,Z,Q),q=VU(Y,K,Q,D);if($.fillStyle=J.imageSurfaceBackground,$.fillRect(q.left,q.top,q.width,q.height),M?.status==="loaded"&&M.source)$.drawImage(M.source,q.left,q.top,q.width,q.height);else DU($,J,{...q,status:M?.status==="error"?"error":"loading"});$.strokeStyle=J.imageSurfaceBorder,$.strokeRect(q.left,q.top,q.width,q.height)}function DU($,Y,X){let Z=X.status==="loading"?"Loading image":"Image unavailable",J=NU(X),K=X.top+X.height/2+J.size*0.9;if($.save(),$.beginPath(),$.rect(X.left,X.top,X.width,X.height),$.clip(),X.status==="loading")UU($,Y,X);$.strokeStyle=Y.imagePlaceholderIcon,$.lineWidth=1.5,$.strokeRect(J.left,J.top,J.size,J.size),$.beginPath(),$.arc(J.left+J.size*0.28,J.top+J.size*0.3,J.size*0.1,0,Math.PI*2),$.moveTo(J.left+J.size*0.12,J.top+J.size*0.82),$.lineTo(J.left+J.size*0.42,J.top+J.size*0.5),$.lineTo(J.left+J.size*0.58,J.top+J.size*0.66),$.lineTo(J.left+J.size*0.78,J.top+J.size*0.38),$.lineTo(J.left+J.size*0.88,J.top+J.size*0.82),$.stroke(),$.font='500 12px "Iowan Old Style", "Palatino Linotype", serif',$.fillStyle=Y.imagePlaceholderText,$.textAlign="center",$.textBaseline="middle",$.fillText(Z,X.left+X.width/2,K),$.restore()}function UU($,Y,X){let Z=Math.max(48,Math.round(X.width*0.22)),J=X.width+Z*2,K=performance.now()%1800/1800,Q=X.left-Z+J*K,M=$.createLinearGradient(Q,X.top,Q+Z,X.top);M.addColorStop(0,"rgba(255,255,255,0)"),M.addColorStop(0.5,Y.imageLoadingOverlay),M.addColorStop(1,"rgba(255,255,255,0)"),$.fillStyle=M,$.fillRect(X.left,X.top,X.width,X.height)}function GU($,Y,X){if(!$.image)return lX(X);let Z=Y.images.get($.image.url);if(!Z||Z.intrinsicWidth<=0||Z.intrinsicHeight<=0)return lX(X);return Math.max(48,Math.round(X*(Z.intrinsicHeight/Z.intrinsicWidth)))}function VU($,Y,X,Z){return{height:Z,left:Y,top:$.top+Math.max(0,Math.floor(($.height-Z)/2)),width:X}}function NU($){let Y=Math.max(18,Math.min(34,Math.round(Math.min($.width,$.height)*0.18)));return{left:$.left+Math.max(12,Math.round(($.width-Y)/2)),size:Y,top:$.top+Math.max(12,Math.round($.height/2-Y*0.95))}}function lX($){return Math.max(48,Math.round($*0.5625))}var AU=6,cX=3,_U=12,HU=10,zU=2,aX=4,FU=4,EU=1.5,rX=2,sX=1.25;function oX($,Y,X,Z,J,K,Q,M,D){if(!X){$.fillStyle=Q,$.fillText(Y.text,Z,J);return}let q=X.inlines.filter((U)=>U.end>Y.start&&U.start<Y.end);if(q.length===0){$.fillStyle=Q,$.fillText(Y.text,Z,J);return}for(let U of q){let V=Math.max(Y.start,U.start),G=Math.min(Y.end,U.end);if(X.text.slice(V,G).length===0)continue;let{left:A,right:_}=i3(Y,Z,V,G),z=TU(Y.font,U.marks);if($.font=z,U.kind==="image"){let F=Math.max(24,_-A);dX($,Y,U,M,D,A,F);continue}if(U.kind==="code"){WU($,Y,z,D,A,_),iX($,Y,X.text,Z,J,V,G,D.inlineCodeText,K,D,{strikethrough:!1,underline:!1});continue}iX($,Y,X.text,Z,J,V,G,U.link?D.linkText:Q,K,D,{strikethrough:U.marks.includes("strikethrough"),underline:U.marks.includes("underline")||Boolean(U.link)})}}function iX($,Y,X,Z,J,K,Q,M,D,q,U){let V=R7(K,Q,D);for(let G=0;G<V.length-1;G+=1){let N=V[G],A=V[G+1];if(A<=N)continue;let _=X.slice(N,A);if(_.length===0)continue;let{left:z,right:F}=i3(Y,Z,N,A),B=b7(D,N,A),W=S7(M,B,q);if($.fillStyle=W,$.fillText(_,z,J),U.strikethrough)$.fillRect(z,PU(J,Y.height,$.font),Math.max(rX,F-z),sX);if(U.underline)$.fillRect(z,yU(J,Y.height,$.font),Math.max(rX,F-z),sX)}}function nX($,Y,X,Z,J,K,Q){if(!X||K.length===0)return;for(let M of K){if(M.startOffset<Y.start||M.startOffset>Y.end)continue;let D=Z+(G0(Y,M.startOffset-Y.start)-Y.left);$.fillStyle=v7(Q,M),$.fillText(M.text,D,J)}}function tX($,Y,X,Z,J,K,Q){if(!X||K.length===0)return;for(let M of K){if(M.offset<Y.start||M.offset>=Y.end)continue;let{left:D,right:q}=i3(Y,Z,M.offset,M.offset+1),U=Math.max(aX,(q-D)/2+aX+FU*M.progress),{ascent:V,descent:G}=H1(Y.font),N=J-Math.max(1,V*0.42)+Math.max(0.5,G*0.15);$.strokeStyle=f7(M,Q),$.lineWidth=EU,$.beginPath(),$.arc((D+q)/2,N,U,0,Math.PI*2),$.stroke()}}function WU($,Y,X,Z,J,K){let Q=P4(Y.height,X),M=Y.top+Q+zU,D=Math.max(_U,Y.height-Q-AU);$.fillStyle=Z.inlineCodeBackground,$.fillRect(J-cX,M,Math.max(HU,K-J+cX*2),D)}function PU($,Y,X){let{ascent:Z}=H1(X),J=$-y4(Y,X);return Math.max(J+2,$-Math.round(Z*0.32))}function yU($,Y,X){let{descent:Z}=H1(X),J=Math.max(1,Math.round(Math.max(2,Z)*0.35)),K=$+Z-J,Q=$-y4(Y,X);return Math.min(Q+Y-4,K)}function TU($,Y){let X=[];if(Y.includes("italic"))X.push("italic");if(Y.includes("bold"))X.push("700");return X.length>0?`${X.join(" ")} ${$}`:$}function i3($,Y,X,Z){return{left:Y+(G0($,X-$.start)-$.left),right:Y+(G0($,Z-$.start)-$.left)}}function o3($,Y,X,Z){jU({activeBlockId:Z.activeBlockId,activeRegionId:Z.activeRegionId,activeThreadIndex:Z.activeThreadIndex,containerLineBounds:Y.regionBounds,context:X,devicePixelRatio:Z.devicePixelRatio,editorState:$,height:Z.height,layout:Y.layout,liveCommentRanges:Z.liveCommentRanges,normalizedSelection:Z.normalizedSelection,now:Z.now,resources:Z.resources??{images:new Map},runtimeBlockMap:Y.blockMap,theme:Z.theme,viewportTop:Y.paintTop,width:Z.width})}function n3($,Y,X,Z){s3({context:X,devicePixelRatio:Z.devicePixelRatio,editorState:$,height:Z.height,layout:Y.layout,normalizedSelection:Z.normalizedSelection,presence:Z.presence,showCaret:Z.showCaret,theme:Z.theme,viewportTop:Y.paintTop,width:Z.width})}function jU({activeBlockId:$,activeRegionId:Y,activeThreadIndex:X,containerLineBounds:Z,context:J,devicePixelRatio:K,editorState:Q,height:M,layout:D,liveCommentRanges:q,normalizedSelection:U,now:V=CU(),resources:G,runtimeBlockMap:N,theme:A,viewportTop:_,width:z}){J.save(),J.scale(K,K),J.clearRect(0,0,z,M),J.fillStyle=A.background,J.fillRect(0,0,z,M),J.textBaseline="alphabetic",J.translate(0,-_);let{endIndex:F,startIndex:B}=V6(D,_,M),W=IX(Q,U),S=O7(Q,V),b=B7(Q,V),k=w7(Q,V),P=L7(Q,V),y=C7(Q,V),E=fX(D,Q,$,B,F),w=RX(D,Q,N,B,F,z);for(let T=B;T<F;T+=1){let H=D.lines[T];CX(J,H,N.get(H.blockId)??null,Z.get(H.regionId)??null,Q.documentIndex.tableCellIndex.get(H.regionId)??null,A,z)}let C=G6(D,_,M);bX(J,D,C.startIndex,C.endIndex,A,z),jX({activeBlockFlashes:S,activeBlockId:$,activeRegionId:Y,context:J,editorState:Q,endIndex:F,layout:D,regionBounds:Z,startIndex:B,theme:A,verticalBleed:E6});for(let T=B;T<F;T+=1){let H=D.lines[T];wU({activeBlockId:$,activeBlockFlashes:S,activeDeletedTextFades:b,activeInsertedTextHighlights:k,activeListMarkerPops:P,activePunctuationPulses:y,activeThreadIndex:X,context:J,editorState:Q,line:H,liveCommentRanges:q,normalizedSelection:U,resources:G,runtimeBlockMap:N,selectionRegionOrderRange:W,theme:A,width:z})}SX(J,w,A),mX(J,E,A),J.restore()}function wU({activeBlockId:$,activeBlockFlashes:Y,activeDeletedTextFades:X,activeInsertedTextHighlights:Z,activeListMarkerPops:J,activePunctuationPulses:K,activeThreadIndex:Q,context:M,editorState:D,line:q,liveCommentRanges:U,normalizedSelection:V,resources:G,runtimeBlockMap:N,selectionRegionOrderRange:A,theme:_,width:z}){let F=N.get(q.blockId)??null,B=D.documentIndex.blockIndex.get(q.blockId)?.path??null,W=D.documentIndex.regionIndex.get(q.regionId)??null,S=W?.path??"",b=Z1(D,q.blockId,"listItem"),k=b?g1(D,b.id):null,P=b?J.get(b.path)??null:null,y=q.left+T0(D,q),E=OU(q),w=F?.type==="code"?_.codeText:BU(F,_);M.font=q.font,LX(M,q,F,B,$,Y,_,z),pX(M,D,q,V,A,_),xX(M,D,q,U,Q,_),gX(M,q,k,y,E,_,P),oX(M,q,W,y,E,Z.get(S)??[],w,G,_),nX(M,q,W,y,E,X.get(S)??[],w),tX(M,q,W,y,E,K.get(S)??[],_)}function OU($){return $.top+y4($.height,$.font)}function BU($,Y){switch($?.type){case"heading":return Y.headingText;case"blockquote":return Y.blockquoteText;case"table":return Y.headingText;default:return Y.paragraphText}}function CU(){return typeof performance<"u"?performance.now():Date.now()}import{forwardRef as vU,createElement as fU}from"react";var W6=(...$)=>$.filter((Y,X,Z)=>{return Boolean(Y)&&Y.trim()!==""&&Z.indexOf(Y)===X}).join(" ").trim();var eX=($)=>$.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var $Z=($)=>$.replace(/^([A-Z])|[\s-_]+(\w)/g,(Y,X,Z)=>Z?Z.toUpperCase():X.toLowerCase());var t3=($)=>{let Y=$Z($);return Y.charAt(0).toUpperCase()+Y.slice(1)};import{forwardRef as SU,createElement as ZZ}from"react";var P6={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 YZ=($)=>{for(let Y in $)if(Y.startsWith("aria-")||Y==="role"||Y==="title")return!0;return!1};import{createContext as LU,useContext as RU,useMemo as uW,createElement as gW}from"react";var bU=LU({});var XZ=()=>RU(bU);var JZ=SU(({color:$,size:Y,strokeWidth:X,absoluteStrokeWidth:Z,className:J="",children:K,iconNode:Q,...M},D)=>{let{size:q=24,strokeWidth:U=2,absoluteStrokeWidth:V=!1,color:G="currentColor",className:N=""}=XZ()??{},A=Z??V?Number(X??U)*24/Number(Y??q):X??U;return ZZ("svg",{ref:D,...P6,width:Y??q??P6.width,height:Y??q??P6.height,stroke:$??G,strokeWidth:A,className:W6("lucide",N,J),...!K&&!YZ(M)&&{"aria-hidden":"true"},...M},[...Q.map(([_,z])=>ZZ(_,z)),...Array.isArray(K)?K:[K]])});var m=($,Y)=>{let X=vU(({className:Z,...J},K)=>fU(JZ,{ref:K,iconNode:Y,className:W6(`lucide-${eX(t3($))}`,`lucide-${$}`,Z),...J}));return X.displayName=t3($),X};var mU=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],z1=m("columns-2",mU);var hU=[["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"}]],F1=m("rows-3",hU);var kU=[["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"}]],E1=m("send-horizontal",kU);var uU=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],O4=m("arrow-down",uU);var gU=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],B4=m("arrow-up",gU);var IU=[["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"}]],C4=m("bold",IU);var pU=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],I1=m("check",pU);var xU=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],L4=m("chevron-down",xU);var lU=[["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"}]],R4=m("heading-1",lU);var dU=[["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"}]],b4=m("heading-2",dU);var cU=[["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"}]],S4=m("heading-3",cU);var aU=[["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"}]],v4=m("heading-4",aU);var rU=[["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=m("heading-5",rU);var sU=[["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"}]],m4=m("heading-6",sU);var iU=[["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M6 20V4",key:"1w1bmo"}],["path",{d:"M18 20V4",key:"o2hl4u"}]],h4=m("heading",iU);var oU=[["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"}]],k4=m("italic",oU);var nU=[["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"}]],u4=m("list-ordered",nU);var tU=[["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"}]],g4=m("list-todo",tU);var eU=[["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"}]],I4=m("list",eU);var $G=[["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"}]],p4=m("message-square-plus",$G);var YG=[["path",{d:"M5 12h14",key:"1ays0h"}]],x4=m("minus",YG);var XG=[["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"}]],p1=m("pencil",XG);var ZG=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],L2=m("plus",ZG);var JG=[["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"}]],l4=m("strikethrough",JG);var KG=[["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"}]],W1=m("table-2",KG);var QG=[["path",{d:"M17 5H3",key:"1cn7zz"}],["path",{d:"M21 12H8",key:"scolzb"}],["path",{d:"M21 19H8",key:"13qgcb"}],["path",{d:"M3 12v7",key:"1ri8j3"}]],d4=m("text-quote",QG);var MG=[["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"}]],L0=m("trash-2",MG);var qG=[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4",key:"9kb039"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20",key:"nun2al"}]],c4=m("underline",qG);var DG=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],a4=m("x",DG);import{jsx as R2,jsxs as NG}from"react/jsx-runtime";function KZ({insetX:$,insetY:Y,onSelect:X,presence:Z}){if(!Z)return null;return R2("div",{"aria-label":"Presence",className:"documint-presence-indicators",style:{paddingRight:`${$}px`,top:`${Y}px`},children:Z.map((J)=>R2(UG,{onSelect:()=>X(J),presence:J},J.id))})}function UG({onSelect:$,presence:Y}){let X=Y.viewport,Z=GG(Y),J=X?.status==="above"?B4:O4,K=X!==null&&X.status!=="unresolved",Q=X?.status==="above"||X?.status==="below";return NG("button",{"aria-label":VG(Y),className:"documint-presence-indicator","data-status":X?.status??"unresolved",disabled:!K,onClick:K?$:void 0,style:{"--documint-presence-color":Y.color??"var(--documint-leaf-accent)"},type:"button",children:[R2("span",{className:"documint-presence-indicator-avatar",children:Y.avatarUrl?R2("img",{alt:"","aria-hidden":"true",className:"documint-presence-indicator-image",draggable:!1,src:Y.avatarUrl}):Z}),Q?R2("span",{className:"documint-presence-indicator-direction","aria-hidden":"true",children:R2(J,{className:"documint-presence-indicator-arrow",size:14,strokeWidth:2.3})}):null]})}function GG($){return QZ($).charAt(0).toLocaleUpperCase()}function VG($){let Y=QZ($),X=$.viewport?.status??"unresolved";if(X==="above")return`${Y} above viewport`;if(X==="below")return`${Y} below viewport`;if(X==="unresolved")return`${Y} unresolved`;return`${Y} in viewport`}function QZ($){return($.fullName??$.username).trim()||"Presence"}var l=`
|
|
29
|
-
`,b2="<ins>",r4="</ins>",S2=">",s4="```",y6=":::",T6="documint-comments";var o4="\\",w6="`",GZ=":",i4=" ",$9="![",Y9="[",VZ="(",MZ=")",qZ=/[\p{L}\p{N}]/u,AG=/[A-Za-z]/,_G=/[-A-Za-z0-9_]/,j6=/\{width=([1-9]\d*)\}/y,HG=/\\([\\`*_[\]{}()#+\-.!~|])/g,NZ=/\\(.)/g,AZ=[{delimiter:"**",mark:"bold",requireWordBoundary:!1},{delimiter:"~~",mark:"strikethrough",requireWordBoundary:!1},{delimiter:"*",mark:"italic",requireWordBoundary:!1},{delimiter:"_",mark:"italic",requireWordBoundary:!0}],zG=new Set(AZ.map(($)=>$.delimiter[0]));function n4($){return O6($,0,$.length,[])}function O6($,Y,X,Z){let J=[],K=Y,Q=Y;while(K<X){let M=FG($,K,X,Z);if(M){let D=Math.max(Q,K-(M.trimLeading??0));DZ(J,$.slice(Q,D),Z),J.push(...M.nodes),K=M.end,Q=K;continue}if($[K]===o4){K+=Math.min(2,X-K);continue}K+=1}return DZ(J,$.slice(Q,X),Z),Z0(J)}function FG($,Y,X,Z){let J=$[Y];switch(J){case GZ:return EG($,Y,X);case"<":return TG($,Y,X)??WG($,Y,X,Z)??PG($,Y,X);case o4:return jG($,Y,X);case l:return wG($,Y);case w6:return OG($,Y,X);case"!":return BG($,Y,X);case Y9:return CG($,Y,X,Z)}if(J!==void 0&&zG.has(J))return RG($,Y,X,Z);return null}function EG($,Y,X){if($[Y]!==GZ||!AG.test($[Y+1]??""))return null;let Z=Y+2;while(Z<X&&_G.test($[Z]??""))Z+=1;let J=UZ($,Z,X,"[","]"),Q=UZ($,J?.end??Z,X,"{","}")?.end??J?.end??Z;return{end:Q,nodes:[FZ("textDirective",$.slice(Y,Q))]}}function WG($,Y,X,Z){if(!$.startsWith(b2,Y))return null;let J=$.indexOf(r4,Y+b2.length);if(J<0||J>=X)return null;return{end:J+r4.length,nodes:O6($,Y+b2.length,J,[...Z,"underline"])}}function PG($,Y,X){if($[Y]!=="<")return null;let Z=$.indexOf(">",Y+1);if(Z<0||Z>=X)return null;return{end:Z+1,nodes:[FZ("html",$.slice(Y,Z+1))]}}var yG=/^<br\s*\/?>/i;function TG($,Y,X){if($[Y]!=="<")return null;let Z=yG.exec($.slice(Y,X));if(!Z)return null;let J=Y+Z[0].length;return{end:$[J]===l?J+1:J,nodes:[l0()]}}function jG($,Y,X){if($[Y]!==o4||$[Y+1]!==l||Y+1>=X)return null;return{end:Y+2,nodes:[l0()]}}function wG($,Y){if($[Y]!==l||$[Y-1]!==i4||$[Y-2]!==i4)return null;let X=0;while($[Y-1-X]===i4)X+=1;return{end:Y+1,nodes:[l0()],trimLeading:X}}function OG($,Y,X){if($[Y]!==w6)return null;let Z=1;while(Y+Z<X&&$[Y+Z]===w6)Z+=1;let J=w6.repeat(Z),K=$.indexOf(J,Y+Z);if(K<0||K>=X)return null;return{end:K+Z,nodes:[e1({code:$.slice(Y+Z,K)})]}}function BG($,Y,X){if(!$.startsWith($9,Y))return null;let Z=HZ($,Y+1,X);if(Z<0||$[Z+1]!==VZ)return null;let J=_Z($,Z+1,X);if(!J)return null;let K=LG($,J.end,X);return{end:K?.end??J.end,nodes:[j1({alt:zZ($.slice(Y+$9.length,Z)),title:J.title,url:J.url,width:K?.width??null})]}}function CG($,Y,X,Z){if($[Y]!==Y9||$.startsWith($9,Y-1))return null;let J=HZ($,Y,X);if(J<0||$[J+1]!==VZ)return null;let K=_Z($,J+1,X);if(!K)return null;return{end:K.end,nodes:[$2({children:O6($,Y+Y9.length,J,Z),title:K.title,url:K.url})]}}function _Z($,Y,X){let Z=e3($,Y+1,X),J=Z;while(J<X&&$[J]!==MZ&&$[J]!==i4){if($[J]===o4){J+=2;continue}J+=1}if(J===Z)return null;let K=bG($.slice(Z,J));Z=e3($,J,X);let Q=null;if(Z<X&&$[Z]==='"'){let M=B6($,'"',Z+1,X);if(M<0)return null;Q=$.slice(Z+1,M).replace(NZ,"$1"),Z=e3($,M+1,X)}if($[Z]!==MZ)return null;return{end:Z+1,title:Q,url:K}}function LG($,Y,X){j6.lastIndex=Y;let Z=j6.exec($);if(!Z||j6.lastIndex>X)return null;return{end:j6.lastIndex,width:Number(Z[1])}}function RG($,Y,X,Z){for(let J of AZ){if(!$.startsWith(J.delimiter,Y))continue;let K=B6($,J.delimiter,Y+J.delimiter.length,X);if(K<0)continue;if(J.requireWordBoundary){let M=Y>0?$[Y-1]:"",D=$[K+J.delimiter.length]??"";if(qZ.test(M)||qZ.test(D))continue}let Q=Y+J.delimiter.length;return{end:K+J.delimiter.length,nodes:O6($,Q,K,[...Z,J.mark])}}return null}function DZ($,Y,X){if(Y.length===0)return;$.push(q1({marks:X,text:zZ(Y)}))}function UZ($,Y,X,Z,J){if($[Y]!==Z)return null;let K=B6($,J,Y+1,X);if(K<0)return null;return{end:K+1}}function HZ($,Y,X){return B6($,"]",Y+1,X)}function B6($,Y,X,Z){for(let J=X;J<Z;J+=1){if($[J]===o4){J+=1;continue}if($.startsWith(Y,J))return J}return-1}function e3($,Y,X){while(Y<X&&$[Y]===i4)Y+=1;return Y}function zZ($){return $.replace(HG,"$1")}function bG($){return $.replace(NZ,"$1")}function FZ($,Y){return z5({originalType:$,source:Y})}var SG=/^:?-+:?$/;function WZ($,Y){let X=q0($),Z=Z9($,1),J=z0(X,Y),K=z0(Z,Y);if(!EZ(J)||!X9(K))return null;let Q=[C6(J)],M=vG(K);$.index+=2;while($.index<$.lines.length){let D=q0($),q=z0(D,Y);if(P1(D)||!EZ(q))break;Q.push(C6(q)),$.index+=1}return B1({align:M,rows:Q.map((D)=>Y2({cells:D.map((q)=>D1({children:n4(q)}))}))})}function X9($){let Y=C6($);return Y.length>0&&Y.every((X)=>SG.test(X.trim()))}function EZ($){let Y=$.trim();return Y.startsWith("|")&&Y.endsWith("|")}function vG($){return C6($).map((Y)=>{let X=Y.trim();if(X.startsWith(":")&&X.endsWith(":"))return"center";if(X.startsWith(":"))return"left";if(X.endsWith(":"))return"right";return null})}function C6($){let Y=$.trim();if(!Y.startsWith("|")||!Y.endsWith("|"))return[];return Y.slice(1,-1).split("|").map((X)=>X.trim())}var fG=3,PZ=/^(#{1,6})\s+(.*)$/,mG=/\s+#+\s*$/u,hG=/^(\s*)([-+*]|\d+\.)(?:\s+(.*)|\s*)$/,kG=/^\d+\.$/,uG=/^\[( |x|X)\](?:\s|$)/,yZ=/^```([^\s`]*)?(?:\s+(.*))?$/,TZ=/^:::([A-Za-z][-\w]*)(.*)$/,gG=[/^(\*\s*){3,}$/,/^(-\s*){3,}$/,/^(_\s*){3,}$/];function R6($,Y,X){let Z=[];while($.index<$.lines.length){let J=q0($);if($.index===$.lines.length-1&&J==="")break;if(P1(J)){$.index+=1;continue}if(v2(J)>Y+fG)break;let K=IG($,Y,X);if(!K)break;Z.push(K)}return Z}function IG($,Y,X){return pG($,Y,X)??xG($,Y)??lG($,Y)??cG($,Y)??aG($,Y)??WZ($,Y)??rG($,Y,X)??iG($,Y)??oG($,Y)}function pG($,Y,X){let Z=q0($);if(!z0(Z,Y).startsWith(S2))return null;let J=[];while($.index<$.lines.length){let K=q0($),Q=v2(K);if(P1(K)){J.push(""),$.index+=1;continue}if(Q<Y)break;let M=z0(K,Y);if(!M.startsWith(S2))break;let D=M.slice(1);if(D.startsWith(" "))D=D.slice(1);J.push(D),$.index+=1}return R0({children:R6({index:0,lines:J},0,X)})}function xG($,Y){let X=q0($),Z=z0(X,Y),J=yZ.exec(Z);if(!J)return null;$.index+=1;let K=[];while($.index<$.lines.length){let Q=q0($),M=z0(Q,Y);if(M.trim()===s4){$.index+=1;break}K.push(M),$.index+=1}return t6({language:J[1]?J[1]:null,meta:J[2]?J[2]:null,source:K.join(l)})}function lG($,Y){let X=q0($),Z=z0(X,Y),J=TZ.exec(Z);if(!J)return null;let K=J[1],Q=[];$.index+=1;while($.index<$.lines.length){let M=q0($),D=z0(M,Y);if(D.trim()===y6){$.index+=1;break}Q.push(D),$.index+=1}return a9({attributes:dG(J[2]??""),body:Q.join(l),name:K})}function dG($){let Y=$.trim();if(Y.startsWith("{")&&Y.endsWith("}"))return Y.slice(1,-1);return Y}function cG($,Y){let X=q0($),Z=PZ.exec(z0(X,Y));if(!Z)return null;return $.index+=1,H5({children:n4(Z[2].replace(mG,"")),depth:Z[1].length})}function aG($,Y){let X=z0(q0($),Y).trim();if(!jZ(X))return null;return $.index+=1,F5()}function rG($,Y,X){let Z=L6(q0($),Y);if(!Z)return null;let J=[],K=!1;while($.index<$.lines.length){let Q=q0($),M=L6(Q,Y);if(!M||M.ordered!==Z.ordered)break;$.index+=1;let D=[M.content],q=!1;while($.index<$.lines.length){let U=q0($),V=v2(U);if(P1(U)){let G=eG($.lines,$.index+1);if(G<0||v2($.lines[G]??"")<=Y)break;q=!0,D.push(""),$.index+=1;continue}if(V<M.contentIndent)break;if(V===Y&&L6(U,Y))break;D.push(tG(U,M.contentIndent)),$.index+=1}K||=q,J.push(w1({checked:M.checked,children:sG(D,X),spread:q}))}return O1({items:J,ordered:Z.ordered,spread:K,start:Z.ordered&&X.preserveOrderedListStart?Z.start??1:null})}function L6($,Y){let X=hG.exec($);if(!X||X[1].length!==Y)return null;let Z=X[2],J=kG.test(Z),K=J?Number(Z.slice(0,-1)):null,Q=X[3]??"",M=null;if(uG.test(Q)){if(M=Q[1]==="x"||Q[1]==="X",Q=Q.slice(3),Q.startsWith(" "))Q=Q.slice(1)}let D=X[0].length-X[1].length-X[2].length-Q.length;return{checked:M,content:Q,contentIndent:Y+X[2].length+D,ordered:J,start:K}}function sG($,Y){let X=R6({index:0,lines:$},0,Y);if(X.length>0)return X;return[x0({children:[]})]}function iG($,Y){let X=z0(q0($),Y).trim();if(!wZ(X))return null;return $.index+=1,e6({originalType:"html",source:X})}function oG($,Y){let X=[];while($.index<$.lines.length){let Z=q0($),J=v2(Z);if(P1(Z))break;if(J<Y)break;let K=z0(Z,Y);if(X.length>0&&nG(Z,K,Y))break;X.push(K),$.index+=1}return x0({children:n4(X.join(l))})}function nG($,Y,X){let Z=Y.trim();return Y.startsWith(S2)||yZ.test(Y)||TZ.test(Y)||PZ.test(Y)||jZ(Z)||X9(Y)||L6($,X)!==null||wZ(Z)}function v2($){let Y=0;while(Y<$.length&&$[Y]===" ")Y+=1;return Y}function tG($,Y){let X=v2($);if(X>=Y)return $.slice(Y);return $.trim()===""?"":$.slice(Math.min(X,Y))}function eG($,Y){for(let X=Y;X<$.length;X+=1)if(!P1($[X]??""))return X;return-1}function jZ($){return gG.some((Y)=>Y.test($))}function wZ($){return $.startsWith("<")&&$.endsWith(">")}function BZ($){let Y=$.at(-1),X=Y&&OZ(Y)?Y:null;return{blocks:$.filter((J)=>!OZ(J)),comments:X?$V(X.body):[]}}function $V($){let Y;try{Y=JSON.parse($)}catch{return[]}if(!Array.isArray(Y))return[];return Y.flatMap((X)=>{let Z=A8(X);return Z?[Z]:[]})}function OZ($){return $.type==="directive"&&$.name===T6}var CZ="---";function t4($,Y={}){let Z={index:0,lines:$.replace(/\r\n/g,l).split(l)},J=YV(Z),K=R6(Z,0,Y),{comments:Q,blocks:M}=BZ(K);return J2(M,Q,J)}function YV($){if($.lines[0]!==CZ)return;for(let Y=1;Y<$.lines.length;Y+=1)if($.lines[Y]===CZ){let X=$.lines.slice(0,Y+1).join(l);return $.index=Y+1,X}return}function q0($){return Z9($,0)}function Z9($,Y){return $.lines[$.index+Y]??""}function P1($){return $.trim()===""}function z0($,Y){return $.slice(Y)}var XV=/([\\`*_[\]])/g,ZV=/([\\)&])/g,JV=/(["\\])/g;function i0($){return Z0($).map((Y)=>KV(Y)).join("")}function KV($){switch($.type){case"lineBreak":return"<br>";case"image":return qV($);case"code":return MV($.code);case"link":return DV($);case"text":return QV(RZ($.text),$.marks);case"raw":return $.source}}function QV($,Y){return Y.reduce((X,Z)=>{switch(Z){case"bold":return`**${X}**`;case"italic":return`*${X}*`;case"strikethrough":return`~~${X}~~`;case"underline":return`${b2}${X}${r4}`}},$)}function MV($){let Y=0,X=0;for(let Q of $){if(Q==="`"){if(X+=1,X>Y)Y=X;continue}X=0}let Z=Y>0?Y+1:1,J="`".repeat(Z),K=$.startsWith("`")||$.endsWith("`")?` ${$} `:$;return`${J}${K}${J}`}function qV($){let Y=RZ($.alt??""),X=LZ($.url,$.title),Z=$.width?`{width=${$.width}}`:"";return`![${Y}]${X}${Z}`}function DV($){return`[${i0($.children)}]${LZ($.url,$.title)}`}function LZ($,Y){return`(${UV($)}${GV(Y)})`}function RZ($){return $.replace(XV,"\\$1")}function UV($){return $.replace(ZV,"\\$1")}function GV($){return $?` "${$.replace(JV,"\\$1")}"`:""}var SZ=3;function vZ($,Y,X){let Z=$.rows.map((U)=>U.cells.map((V)=>i0(V.children))),J=Math.max(1,...Z.map((U)=>U.length)),K=Z[0]??[],Q=Array.from({length:J},(U,V)=>Math.max(_V($.align[V]),...X.padTableColumns?Z.map((G)=>G[V]?.length??0):[K[V]?.length??0])),M=VV(Q,$.align,Y),D=bZ(K,Q,$.align,Y,X),q=Z.slice(1).map((U)=>bZ(U,Q,$.align,Y,X));return[D??NV(Q,Y),M,...q].join(l)}function bZ($,Y,X,Z,J){let K=Y.map((Q,M)=>{let D=$[M]??"";if(!J.padTableColumns)return D;return HV(D,Q,X[M])});return`${" ".repeat(Z)}| ${K.join(" | ")} |`}function VV($,Y,X){let Z=$.map((J,K)=>AV(Y[K],J));return`${" ".repeat(X)}| ${Z.join(" | ")} |`}function NV($,Y){return`${" ".repeat(Y)}| ${$.map((X)=>"".padEnd(X," ")).join(" | ")} |`}function AV($,Y){let X=fZ($),Z=Math.max(SZ,Y-X),J="-".repeat(Z);switch($){case"center":return`:${J}:`;case"left":return`:${J}`;case"right":return`${J}:`;default:return J}}function _V($){return SZ+fZ($)}function fZ($){if($==="center")return 2;return $?1:0}function HV($,Y,X){if(X==="right")return $.padStart(Y," ");return $.padEnd(Y," ")}var x1=`
|
|
30
|
-
|
|
31
|
-
`,
|
|
32
|
-
|
|
33
|
-
`||$==="\t"}import{jsx as cZ,jsxs as sV}from"react/jsx-runtime";function U9({value:$,completionSources:Y,onEdit:X}){return cZ("p",{onDoubleClick:X,children:rV($,Y)})}function rV($,Y){let X=q9($,Y);if(X.length===1&&X[0].kind==="text")return $;return X.map((Z,J)=>Z.kind==="token"?sV("span",{className:"documint-mention",children:[Z.trigger,Z.label]},J):cZ(aV,{children:Z.text},J))}import{Children as aZ,isValidElement as rZ,useEffect as iV,useRef as oV,useState as nV}from"react";import{jsx as V0,jsxs as N9}from"react/jsx-runtime";var G9=($)=>{$.preventDefault()},V9=($)=>$.isPrimary&&$.button===0;function tV({children:$}){return V0("div",{className:"documint-leaf-toolbar",children:aZ.map($,eV)})}function eV($){if(!rZ($))return null;if($.type===iZ){let Y=$.props;return V0(sZ,{children:V0($N,{...Y})})}if($.type===oZ){let{className:Y}=$.props;return V0("div",{className:Y5("documint-leaf-toolbar-divider",Y)})}if($.type===nZ){let Y=$.props;return V0(YN,{...Y})}return null}function $N({active:$=!1,className:Y,disabled:X=!1,icon:Z,label:J,onClick:K}){return V0("button",{"aria-label":J,className:Y5("documint-leaf-toolbar-button",$?"active":null,Y),disabled:X,onPointerDown:(Q)=>{if(G9(Q),!X&&V9(Q))K()},title:J,type:"button",children:V0(Z,{size:15,strokeWidth:2.2})})}function YN({children:$,className:Y,icon:X,label:Z,onSelect:J}){let K=oV(null),[Q,M]=nV(!1);return iV(()=>{if(!Q)return;let D=(q)=>{if(K.current&&q.target instanceof Node&&!K.current.contains(q.target))M(!1)};return window.addEventListener("pointerdown",D),()=>{window.removeEventListener("pointerdown",D)}},[Q]),V0(sZ,{children:N9("div",{className:"documint-leaf-toolbar-menu-shell",ref:K,children:[V0(XN,{className:Y,icon:X,isOpen:Q,label:Z,onClick:()=>M((D)=>!D)}),Q?V0("div",{className:"documint-leaf-menu",role:"menu",children:aZ.map($,(D)=>ZN(D,(q)=>{M(!1),J(q)}))}):null]})})}function XN({className:$,icon:Y,isOpen:X,label:Z,onClick:J}){return N9("button",{"aria-expanded":X,"aria-haspopup":"menu","aria-label":Z,className:Y5("documint-leaf-toolbar-button",X?"active":null,$),onPointerDown:(K)=>{if(G9(K),V9(K))J()},title:Z,type:"button",children:[V0(Y,{size:15,strokeWidth:2.2}),V0(L4,{className:Y5("documint-leaf-toolbar-menu-chevron",X?"is-open":null),size:13,strokeWidth:2.2})]})}function ZN($,Y){if(!rZ($))return null;if($.type===eZ){let{className:Q}=$.props;return V0("div",{className:Y5("documint-leaf-menu-divider",Q),role:"separator"})}if($.type!==tZ)return null;let{disabled:X=!1,icon:Z,text:J,value:K}=$.props;return N9("button",{className:"documint-leaf-menu-item",disabled:X,onPointerDown:(Q)=>{if(G9(Q),!X&&V9(Q))Y(K)},role:"menuitem",type:"button",children:[V0(Z,{size:15,strokeWidth:2.2}),V0("span",{children:J})]})}function Y5(...$){return $.filter(Boolean).join(" ")}function sZ({children:$}){return V0("div",{className:"documint-leaf-toolbar-group",children:$})}function iZ($){return null}function oZ($){return null}function nZ($){return null}function tZ($){return null}function eZ($){return null}var d=Object.assign(tV,{Button:iZ,Divider:oZ,Menu:nZ,MenuDivider:eZ,MenuItem:tZ});import{jsx as o,jsxs as o0,Fragment as MN}from"react/jsx-runtime";var JN=!1,KN=220,c1=()=>{};function A9($){let Y=$.mode==="create",X=$.mode==="create"?$:null,Z=$.mode==="thread"?$:null,J=$.canEdit,K=$.link,Q=Z?.thread??null,M=Q?.comments??[],D=M[0]??null,q=Q?U1(Q):!1,U=Z?.animateInitialComment??!1,[V,G]=d1(null),[N,A]=d1(""),[_,z]=d1(""),[F,B]=d1(""),[W,S]=d1(!U),[b,k]=d1(JN),[P,y]=d1(!1),E=$J(null),w=$J(null),C=$.mentionSources,T=Q?P8(Q):null,H=T?YJ(T):"",R=J&&!q,u=R&&N.trim().length>0,g=R&&_.trim().length>0,I=J&&F.trim().length>0,j=Y||P,O=!Y||b,v=!Y&&Boolean(Q),f=Boolean(D),a=Y?b:!0,x=Z?.onDeleteComment??c1,E0=Z?.onDeleteThread??c1,t0=Z?.onToggleResolved??c1,u0=X?.activeMarks??[],g0=X?.onToggleBold??c1,e0=X?.onToggleItalic??c1,c6=X?.onToggleStrikethrough??c1,a6=X?.onToggleUnderline??c1,D5=J?Y?"Add a comment":"Reply to this comment":"Comment editing is disabled",r6=Y?F:_;h6(()=>{if(V!==null&&(V<0||V>=M.length))G(null),A("")},[M.length,V]),h6(()=>{if(!f||!U){S(!0);return}S(!1);let r=requestAnimationFrame(()=>{S(!0)});return()=>{cancelAnimationFrame(r)}},[U,D,f]),h6(()=>{if(!Z||!U){y(!1);return}y(!0);let r=window.setTimeout(()=>{y(!1)},KN);return()=>{window.clearTimeout(r)}},[U,Z]),h6(()=>{if(!Y||!b||!J)return;let r=requestAnimationFrame(()=>{w.current?.focus()});return()=>{cancelAnimationFrame(r)}},[J,Y,b]);let u2=()=>{G(null),A("")},U5=(r,G5)=>{if(!v||!R)return;G(r),A(G5)},I0=(r)=>{if(!Z)return;Z.onEditComment(r,N),u2()},w0=()=>{if(!Z)return;Z.onReply(_),z("")},s1=()=>{if(!X||!I)return;X.onCreateThread(F),B("")},s6=j?`documint-comment-leaf documint-comment-leaf-create${a?" is-expanded":""}`:"documint-comment-leaf",i1=v||f||O?o(QN,{canCreate:I,canEdit:J,canMutateThread:R,canReply:g,canSaveEditedComment:u,comments:M,composerRef:w,editDraft:N,editingCommentIndex:V,isComposerVisible:O,isInitialCommentVisible:W,isResolved:q,link:K,mentionSources:C,mode:$.mode,onBeginEditingComment:U5,onCancelEditing:u2,onChangeCreateDraft:B,onChangeEditDraft:A,onChangeReplyDraft:z,onDeleteComment:x,onDeleteThread:E0,onSubmitCreate:s1,onSubmitEditedComment:I0,onSubmitReply:w0,onToggleResolved:t0,rootComment:D,showRootComment:f,showThreadChrome:v,threadAge:H,composerPlaceholder:D5,composerValue:r6}):null;return o("div",{className:s6,ref:E,children:o0("div",{className:j?"documint-comment-leaf-create-shell":void 0,children:[j?o0(d,{children:[o(d.Button,{className:"documint-comment-leaf-create-button",icon:p4,label:"Add comment",onClick:()=>k(!0)}),o(d.Divider,{className:"documint-comment-leaf-create-divider"}),o(d.Button,{active:u0.includes("bold"),className:"documint-comment-leaf-create-mark",icon:C4,label:"Bold",onClick:g0}),o(d.Button,{active:u0.includes("italic"),className:"documint-comment-leaf-create-mark",icon:k4,label:"Italic",onClick:e0}),o(d.Button,{active:u0.includes("underline"),className:"documint-comment-leaf-create-mark",icon:c4,label:"Underline",onClick:a6}),o(d.Button,{active:u0.includes("strikethrough"),className:"documint-comment-leaf-create-mark",icon:l4,label:"Strikethrough",onClick:c6})]}):null,o("div",{className:j?"documint-comment-leaf-create-content":void 0,children:i1})]})})}function QN({canCreate:$,canEdit:Y,canMutateThread:X,canReply:Z,canSaveEditedComment:J,comments:K,composerRef:Q,editDraft:M,editingCommentIndex:D,isComposerVisible:q,isInitialCommentVisible:U,isResolved:V,link:G,mentionSources:N,mode:A,onBeginEditingComment:_,onCancelEditing:z,onChangeCreateDraft:F,onChangeEditDraft:B,onChangeReplyDraft:W,onDeleteComment:S,onDeleteThread:b,onSubmitCreate:k,onSubmitEditedComment:P,onSubmitReply:y,onToggleResolved:E,rootComment:w,showRootComment:C,showThreadChrome:T,threadAge:H,composerPlaceholder:R,composerValue:u}){return o0(MN,{children:[T?o0("div",{className:"documint-comment-leaf-header",children:[o("span",{className:"documint-comment-leaf-age",children:H}),o0("div",{className:"documint-comment-leaf-actions",children:[o("button",{className:"documint-leaf-action","aria-label":V?"Reopen comment":"Resolve comment",disabled:!Y,onClick:E,title:V?"Reopen comment":"Resolve comment",type:"button",children:o(I1,{size:14,strokeWidth:2.2})}),o("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Delete comment thread",disabled:!Y,onClick:b,title:"Delete comment thread",type:"button",children:o(L0,{size:14,strokeWidth:2.2})})]})]}):null,T&&G?o0("div",{className:"documint-comment-leaf-link",children:[G.title?o("div",{className:"documint-link-leaf-title",children:G.title}):null,o("div",{className:"documint-link-leaf-url",children:G.url})]}):null,o0("div",{className:`documint-comment-thread${C?"":" is-empty"}`,children:[o("article",{className:C?`documint-comment-message documint-comment-message-root${U?" is-visible":""}`:"documint-comment-message documint-comment-message-root is-hidden",children:w?o(U9,{completionSources:N,onEdit:()=>_(0,w.body),value:w.body}):null}),K.slice(1).map((g,I)=>{let j=I+1,O=D===j;return o0("article",{className:"documint-comment-message",children:[!O?o0("div",{className:"documint-comment-message-meta",children:[o("span",{children:YJ(g.updatedAt)}),X?o0("div",{className:"documint-comment-leaf-actions",children:[o("button",{className:"documint-leaf-action","aria-label":"Edit comment",disabled:!X,onClick:()=>{_(j,g.body)},title:"Edit comment",type:"button",children:o(p1,{size:14,strokeWidth:2.2})}),o("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Delete comment",disabled:!X,onClick:()=>S(j),title:"Delete comment",type:"button",children:o(L0,{size:14,strokeWidth:2.2})})]}):null]}):null,O?o($5,{actions:{kind:"edit",onCancel:z,onSave:()=>P(j),saveDisabled:!J},completionSources:N,onChange:B,readOnly:!Y,rows:3,value:M}):o(U9,{completionSources:N,onEdit:()=>_(j,g.body),value:g.body})]},`${g.updatedAt}:${j}`)})]}),o("div",{className:`documint-comment-reply${T?"":" is-standalone"}${q?" is-visible":""}`,children:o($5,{actions:A==="create"?{kind:"compose",onSubmit:k,submitDisabled:!$,submitLabel:"Create comment"}:{kind:"compose",onSubmit:y,submitDisabled:!Z,submitLabel:"Reply"},completionSources:N,onChange:A==="create"?F:W,placeholder:R,readOnly:!Y,ref:Q,rows:3,value:u})})]})}function YJ($){let Y=new Date($);if(Number.isNaN(Y.getTime()))return $;let X=Y.getTime()-Date.now(),Z=60000,J=60*Z,K=24*J,Q=7*K,M=30*K,D=365*K,q=new Intl.RelativeTimeFormat(void 0,{numeric:"auto"});if(Math.abs(X)<Z)return"just now";if(Math.abs(X)<J)return q.format(Math.round(X/Z),"minute");if(Math.abs(X)<K)return q.format(Math.round(X/J),"hour");if(Math.abs(X)<Q)return q.format(Math.round(X/K),"day");if(Math.abs(X)<D)return q.format(Math.round(X/M),"month");return q.format(Math.round(X/D),"year")}import{jsx as k0,jsxs as UN}from"react/jsx-runtime";var qN=[{icon:R4,label:"Heading 1",text:"# "},{icon:b4,label:"Heading 2",text:"## "},{icon:S4,label:"Heading 3",text:"### "},{icon:v4,label:"Heading 4",text:"#### "},{icon:f4,label:"Heading 5",text:"##### "},{icon:m4,label:"Heading 6",text:"###### "}],DN=[{columns:2,text:"2 columns"},{columns:3,text:"3 columns"},{columns:4,text:"4 columns"},{columns:5,text:"5 columns"}];function XJ({onInsert:$,onInsertTable:Y}){return UN(d,{children:[k0(d.Button,{icon:I4,label:"Insert bulleted list",onClick:()=>$("- ")}),k0(d.Button,{icon:u4,label:"Insert numbered list",onClick:()=>$("1. ")}),k0(d.Button,{icon:g4,label:"Insert task list",onClick:()=>$("- [ ] ")}),k0(d.Divider,{}),k0(d.Menu,{icon:h4,label:"Insert heading",onSelect:$,children:qN.map(({icon:X,label:Z,text:J})=>k0(d.MenuItem,{icon:X,text:Z,value:J},J))}),k0(d.Menu,{icon:W1,label:"Insert table",onSelect:(X)=>Y(Number(X)),children:DN.map(({columns:X,text:Z})=>k0(d.MenuItem,{icon:W1,text:Z,value:String(X)},X))}),k0(d.Divider,{}),k0(d.Button,{icon:d4,label:"Insert blockquote",onClick:()=>$("> ")}),k0(d.Button,{icon:x4,label:"Insert divider",onClick:()=>$("--- ")})]})}import{jsx as _9,jsxs as GN}from"react/jsx-runtime";function ZJ({anchor:$,children:Y,status:X="default"}){let Z=!$.isSelection;return _9(m6,{children:GN("div",{className:"documint-leaf-anchor","data-selection":$.isSelection?"true":"false",onPointerEnter:$.onPointerEnter,onPointerLeave:$.onPointerLeave,style:{left:`${$.left}px`,top:`${$.top}px`},children:[Z?_9("div",{className:"documint-leaf-bridge"}):null,_9("div",{className:"documint-leaf-shell","data-status":X,children:Y})]})})}import{useEffect as JJ,useRef as VN,useState as KJ}from"react";import{jsx as K1,jsxs as H9}from"react/jsx-runtime";function QJ({canEdit:$,onDelete:Y,onSave:X,title:Z,url:J}){let[K,Q]=KJ(J),[M,D]=KJ(!1),q=VN(null),U=NN(),V=K.trim(),G=$&&V.length>0,N=$&&!M,A=`${U}click to open`,_=`documint-link-leaf-row${M?" is-editing":""}`;return JJ(()=>{if(M)return;Q(J)},[M,J]),JJ(()=>{if(!M)return;q.current?.focus()},[M]),H9("div",{className:"documint-link-leaf",children:[Z?K1("div",{className:"documint-link-leaf-title",children:Z}):null,H9("div",{className:_,children:[M?K1($5,{actions:{kind:"edit",onCancel:()=>{Q(J),D(!1)},onSave:()=>{X(V),D(!1)},saveDisabled:!G},onChange:Q,readOnly:!$,ref:q,rows:3,value:K}):K1("div",{className:"documint-link-leaf-url",children:J}),N?H9("div",{className:"documint-link-leaf-actions",children:[K1("button",{className:"documint-leaf-action","aria-label":"Edit link",onClick:()=>{if(!$)return;Q(J),D(!0)},title:"Edit link",type:"button",children:K1(p1,{size:14,strokeWidth:2.2})}),K1("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Remove link",onClick:Y,title:"Remove link",type:"button",children:K1(L0,{size:14,strokeWidth:2.2})})]}):null]}),K1("div",{className:"documint-link-leaf-divider"}),K1("div",{className:"documint-link-leaf-hint",children:A})]})}function NN(){if(typeof navigator>"u")return"Ctrl+";let $=navigator.platform||navigator.userAgent;return/Mac|iPhone|iPad|iPod/.test($)?"CMD+":"CTRL+"}import{jsx as Q1,jsxs as E9}from"react/jsx-runtime";var AN=[{text:"Column left",value:"left"},{text:"Column right",value:"right"}],_N=[{text:"Row above",value:"above"},{text:"Row below",value:"below"}],z9={text:"Delete column",value:"delete"},F9={text:"Delete row",value:"delete"},MJ={text:"Delete table",value:"delete"};function qJ({canDeleteColumn:$,canDeleteRow:Y,onDeleteColumn:X,onDeleteRow:Z,onDeleteTable:J,onInsertColumn:K,onInsertRow:Q}){return E9(d,{children:[E9(d.Menu,{icon:z1,label:"Column actions",onSelect:(M)=>{if(M===z9.value){X();return}K(M)},children:[AN.map(({text:M,value:D})=>Q1(d.MenuItem,{icon:L2,text:M,value:D},D)),Q1(d.MenuDivider,{}),Q1(d.MenuItem,{disabled:!$,icon:L0,text:z9.text,value:z9.value})]}),E9(d.Menu,{icon:F1,label:"Row actions",onSelect:(M)=>{if(M===F9.value){Z();return}Q(M)},children:[_N.map(({text:M,value:D})=>Q1(d.MenuItem,{icon:L2,text:M,value:D},D)),Q1(d.MenuDivider,{}),Q1(d.MenuItem,{disabled:!Y,icon:L0,text:F9.text,value:F9.value})]}),Q1(d.Divider,{}),Q1(d.Menu,{icon:W1,label:"Table actions",onSelect:()=>J(),children:Q1(d.MenuItem,{icon:L0,text:MJ.text,value:MJ.value})})]})}import{useEffect as DJ,useEffectEvent as UJ,useLayoutEffect as GJ,useMemo as HN,useRef as W9,useState as VJ}from"react";function k6($,Y){if(!$||$.kind==="task-toggle")return null;if($.commentThreadIndex!==null){let X=Y[$.commentThreadIndex]??null;if(!X)return null;return{kind:"comment",left:$.anchorLeft,link:$.kind==="link"?{title:$.title,url:$.url}:null,thread:X,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 zN=600,FN=530,m2=24;function AJ({canShowInsertionLeaf:$,canShowTableLeaf:Y,commentState:X,editorState:Z,editorViewportState:J,getScrollTop:K,layoutWidth:Q,onVisibilityChange:M,resources:D,scrollContentHeight:q,scrollTo:U,viewportHeight:V}){let G=HN(()=>Y0(Z),[Z]),[N,A]=VJ(null),[_,z]=VJ(null),F=G.start.regionId===G.end.regionId&&G.start.offset===G.end.offset,B=W9(!0),W=W9(0),S=W9(null),b=UJ(()=>{M()}),k=UJ(()=>{W.current=typeof performance<"u"?performance.now():Date.now(),B.current=!0,b()});return GJ(()=>{let P=EN({canShowInsertionLeaf:$,canShowTableLeaf:Y,commentState:X,normalizedSelection:G,state:Z,viewport:J.get()});A((y)=>TN(y,P)?y:P)},[$,Y,X,Z,J]),GJ(()=>{let P=D?wN(Z,J.get(),G,D):null;z((y)=>ON(y,P)?y:P)},[Z,J,G,D]),DJ(()=>{let P=Z.selection.focus,y={layoutWidth:Q,offset:P.offset,regionId:P.regionId,scrollContentHeight:q,viewportHeight:V};if(jN(S.current,y))return;let E=x3(Z,J.get(),P);if(!E)return;let w=K(),C=w+m2,T=w+V-m2;if(E.top<C){let H=U(Math.max(0,E.top-m2));if(NJ(E,H,V,m2))S.current=y;return}if(E.top+E.height>T){let H=U(Math.max(0,E.top+E.height-V+m2));if(NJ(E,H,V,m2))S.current=y;return}S.current=y},[Z,Z.selection.focus.offset,Z.selection.focus.regionId,J,Q,q,U,V]),DJ(()=>{if(B.current=!0,b(),!F||typeof window>"u")return;let P=window.setInterval(()=>{if((typeof performance<"u"?performance.now():Date.now())-W.current<zN){if(!B.current)B.current=!0,b();return}B.current=!B.current,b()},FN);return()=>{window.clearInterval(P)}},[F]),{imageAtCursor:_,leaf:N,isVisible:()=>B.current,markActivity:k}}function EN({canShowInsertionLeaf:$,canShowTableLeaf:Y,commentState:X,normalizedSelection:Z,state:J,viewport:K}){if(!K)return null;let Q=J.selection.focus;if(Z.start.regionId!==Z.end.regionId||Z.start.offset!==Z.end.offset)return null;let M=$?yN(J,K):null;if(M)return M;let D=Y?WN(J,K):null;if(D)return D;return k6(p3(J,K,Q,X.liveRanges),X.threads)}function WN($,Y){let X=$.selection.focus,Z=$.documentIndex.regionIndex.get(X.regionId),J=Z?$.documentIndex.tableCellIndex.get(Z.id)??null:null;if(!Z||!J)return null;let K=$.documentIndex.blockIndex.get(Z.blockId),Q=K?.type==="table"?$.documentIndex.document.blocks[K.rootIndex]:null;if(!K||!Q||Q.type!=="table")return null;let M=J1($,Y,X),D=PN(Y,Z.id),q=Math.max(1,...Q.rows.map((U)=>U.cells.length));return M&&D!==null?{cellIndex:J.cellIndex,columnCount:q,kind:"table",left:D,rowCount:Q.rows.length,rowIndex:J.rowIndex,top:M.top+M.height}:null}function PN($,Y){let X=$.layout.lines.find((Z)=>Z.regionId===Y);return X?X.left:null}function yN($,Y){let X=$.selection.focus,Z=$.documentIndex.regionIndex.get(X.regionId);if(!Z||Z.blockType!=="paragraph"||Z.text.length>0)return null;if(X.offset!==0)return null;let J=$.documentIndex.blockIndex.get(Z.blockId);if(!J||J.parentBlockId!==null)return null;let K=J1($,Y,X);return K?{kind:"insertion",left:K.left,top:K.top+K.height}:null}function TN($,Y){if($===Y)return!0;if(!$||!Y||$.kind!==Y.kind)return!1;switch($.kind){case"comment":return Y.kind==="comment"&&$.left===Y.left&&$.link?.title===Y.link?.title&&$.link?.url===Y.link?.url&&$.thread===Y.thread&&$.threadIndex===Y.threadIndex&&$.top===Y.top;case"insertion":return Y.kind==="insertion"&&$.left===Y.left&&$.top===Y.top;case"link":return Y.kind==="link"&&$.endOffset===Y.endOffset&&$.left===Y.left&&$.regionId===Y.regionId&&$.startOffset===Y.startOffset&&$.title===Y.title&&$.top===Y.top&&$.url===Y.url;case"table":return Y.kind==="table"&&$.cellIndex===Y.cellIndex&&$.columnCount===Y.columnCount&&$.left===Y.left&&$.rowCount===Y.rowCount&&$.rowIndex===Y.rowIndex&&$.top===Y.top}}function jN($,Y){return $?.layoutWidth===Y.layoutWidth&&$.regionId===Y.regionId&&$.offset===Y.offset&&$.scrollContentHeight===Y.scrollContentHeight&&$.viewportHeight===Y.viewportHeight}function NJ($,Y,X,Z){return $.top>=Y+Z&&$.top+$.height<=Y+X-Z}function wN($,Y,X,Z){if(!Y)return null;if(X.start.regionId!==X.end.regionId||X.start.offset!==X.end.offset)return null;let J=R5($);if(!J)return null;let K=j4($,Y,Z,J),Q=J.image?Z.images.get(J.image.url)?.intrinsicWidth??null:null,M=$.selection.anchor.regionId;return K?{bounds:K,maxWidth:Q,regionId:M,run:J}:null}function ON($,Y){if($===Y)return!0;if(!$||!Y)return!1;return $.regionId===Y.regionId&&$.maxWidth===Y.maxWidth&&$.bounds.left===Y.bounds.left&&$.bounds.top===Y.bounds.top&&$.bounds.width===Y.bounds.width&&$.bounds.height===Y.bounds.height}import{useMemo as P9,useRef as X5,useEffectEvent as y9}from"react";var BN=48;function _J($,Y,X){let Z=X5(null),J=X5(null),K=X5(null),Q=X5(null),M=X5(1),D=y9((N,A)=>{if(!$)return;N.preventDefault(),N.stopPropagation(),N.currentTarget.setPointerCapture(N.pointerId),Q.current=N.pointerId,Z.current=N.clientX,J.current=N.clientY,K.current=$.run.image?.width??$.bounds.width,M.current=A}),q=y9((N)=>{if(Q.current!==N.pointerId||Z.current===null||J.current===null||K.current===null||!$?.run.image)return;let A=N.clientX-Z.current,_=N.clientY-J.current,z=Math.min($.maxWidth??1/0,Math.max(BN,Math.round(K.current+M.current*(A+_)))),F=r$(Y,$.regionId,$.run,z);if(F)X(F)}),U=y9((N)=>{if(N.currentTarget.hasPointerCapture(N.pointerId))N.currentTarget.releasePointerCapture(N.pointerId);Q.current=null,Z.current=null,J.current=null,K.current=null}),V=P9(()=>({onPointerDown:(N)=>D(N,-1),onPointerMove:q,onPointerUp:U,onPointerCancel:U}),[]),G=P9(()=>({onPointerDown:(N)=>D(N,1),onPointerMove:q,onPointerUp:U,onPointerCancel:U}),[]);return P9(()=>{if(!$)return null;let{bounds:N}=$;return{start:{left:N.left,top:N.top,props:V},end:{left:N.left+N.width,top:N.top+N.height,props:G}}},[$])}import{useEffect as HJ,useEffectEvent as zJ,useMemo as FJ,useRef as CN,useState as LN}from"react";function EJ($,Y){let[X,Z]=LN(new Map),J=zJ((D)=>{if(typeof Image>"u")return;let q=[...X.keys()].filter((U)=>!D.has(U));if(q.length>0)Z((U)=>{let V=new Map(U);for(let G of q)V.delete(G);return V});for(let U of D){let V=X.get(U)?.status;if(V==="loaded"||V==="loading")continue;Z((G)=>T9(G,U,Z5("loading"))),RN(U,Y).then((G)=>{Z((N)=>{if(!N.has(U))return G?.close(),N;return T9(N,U,G?Z5("loaded",G):Z5("error"))})})}});HJ(()=>{J($)},[$]);let K=CN(new Map);HJ(()=>{for(let[D,q]of K.current)if(!X.has(D))q.source?.close();K.current=X},[X]);let Q=zJ(async(D)=>{if(!Y?.writeFile)return null;try{let q=await Y.writeFile(D),U=await createImageBitmap(D).catch(()=>null);return Z((V)=>T9(V,q,U?Z5("loaded",U):Z5("error"))),q}catch{return null}}),M=FJ(()=>X.size===0?null:{images:X},[X]);return FJ(()=>({resources:M,persistImage:Q}),[M,Q])}async function RN($,Y){if(/^(https?:|data:|blob:)/i.test($))return bN($);if(!Y?.readFile)return null;try{let X=await Y.readFile($);return X?await createImageBitmap(X):null}catch{return null}}function bN($){return new Promise((Y)=>{let X=new Image;X.decoding="async",X.crossOrigin="anonymous",X.onload=async()=>{try{Y(await createImageBitmap(X))}catch{Y(null)}},X.onerror=()=>Y(null),X.src=$})}function T9($,Y,X){let Z=new Map($);return Z.set(Y,X),Z}function Z5($,Y){return{intrinsicHeight:Y?.height??0,intrinsicWidth:Y?.width??0,source:Y??null,status:$}}import{useEffect as WJ,useEffectEvent as F0,useRef as J5,useState as SN}from"react";var vN=48;function PJ({applyNextState:$,autoScrollDuringDrag:Y,canvasRef:X,commentState:Z,editorStateRef:J,editorViewportState:K,focusInput:Q,onActivity:M,readCurrentState:D,resolvePoint:q}){let[U,V]=SN(null),G=J5(null),N=J5(!1),A=J5(null),_=J5(null),z=J5(null),F=k6(U,Z.threads),B=U?.kind==="task-toggle"||F?.kind==="link"?"pointer":"text";WJ(()=>{if(U&&U.kind!=="task-toggle"&&!F)V(null)},[U,F]),WJ(()=>()=>{if(G.current!==null)window.clearTimeout(G.current)},[]);let W=F0(()=>{if(G.current!==null)window.clearTimeout(G.current),G.current=null}),S=F0(()=>{W(),G.current=window.setTimeout(()=>{if(G.current=null,!N.current)V(null)},vN)}),b=F0(()=>{if(!N.current)W(),V(null)}),k=F0((j)=>{if(!j){b();return}if(j.kind==="task-toggle"){W(),V((O)=>O?.kind==="task-toggle"&&O.listItemId===j.listItemId?O:j);return}if(j.commentThreadIndex!==null){if(!(Z.threads[j.commentThreadIndex]??null)){b();return}W();let v=j.commentThreadIndex;V((f)=>f?.kind!=="task-toggle"&&f?.commentThreadIndex===v?f:j);return}if(j.kind!=="link"){b();return}W(),V((O)=>O?.kind==="link"&&O.title===j.title&&O.url===j.url&&O.startOffset===j.startOffset&&O.endOffset===j.endOffset?O:j)}),P=F0((j)=>{let O=J.current;if(!O)return null;let v=q(j);if(!v)return null;return I3(O,K.get(),v,Z.liveRanges)}),y=F0((j)=>{let O=X.current;if(O&&A.current===j)O.releasePointerCapture(j)}),E=F0(()=>{A.current=null,_.current=null}),w=F0((j)=>{y(j.pointerId),E()}),C=F0((j)=>{if(z.current=j.pointerType,j.pointerType==="touch")return;let O=X.current,v=D(),f=q(j);if(!f)return;if(P(j)?.kind==="task-toggle")return;let x=F6(v,K.get(),f);if(!O||!x)return;if(A.current=j.pointerId,M(),O.setPointerCapture(j.pointerId),j.shiftKey)_.current=v.selection.anchor,$(p$(v,x.regionId,x.offset));else _.current={offset:x.offset,regionId:x.regionId},$(K0(v,{offset:x.offset,regionId:x.regionId}));Q({offset:x.offset,regionId:x.regionId})}),T=F0((j)=>{let O=_.current,v=D(),f=q(j);if(!f)return;if(A.current!==j.pointerId||!O){k(P(j));return}let a=w4(v,K.get(),f,O);if(!a)return;M(),Y(j),$(K0(v,{anchor:O,focus:a}))}),H=F0(()=>{if(!N.current)S()}),R=F0((j)=>{let O=z.current==="touch";z.current=null;let v=P(j);if(v?.kind==="task-toggle"){let E0=D(),t0=t$(E0,v.listItemId);if(t0)j.preventDefault(),j.stopPropagation(),M(),$(t0);return}if(v?.kind==="link"&&(j.metaKey||j.ctrlKey)){j.preventDefault(),j.stopPropagation(),j.currentTarget.ownerDocument.defaultView?.open(v.url,"_blank","noopener,noreferrer");return}if(!O){Q();return}let f=D(),a=q(j),x=a?F6(f,K.get(),a):null;if(x)M(),$(K0(f,{offset:x.offset,regionId:x.regionId})),Q({offset:x.offset,regionId:x.regionId});else Q()}),u=F0((j)=>{let O=D(),v=q(j),f=P(j);if(!v||f?.kind==="task-toggle")return;let a=g3(O,K.get(),v);if(!a)return;j.preventDefault(),j.stopPropagation(),M(),$(K0(O,a)),Q()}),g=F0(()=>{N.current=!0,W()}),I=F0(()=>{N.current=!1,S()});return{canvasHandlers:{onClick:R,onDoubleClick:u,onPointerCancel:w,onPointerDown:C,onPointerLeave:H,onPointerMove:T,onPointerUp:w},cursor:B,leaf:F,leafHandlers:{onPointerEnter:g,onPointerLeave:I}}}import{useEffect as w9,useEffectEvent as N0,useLayoutEffect as fN,useRef as TJ,useState as mN}from"react";import{useEffect as Sv1}from"react";var j9=[{key:"Backspace",command:"deleteBackward"},{key:"Enter",shiftKey:!0,command:"insertSoftLineBreak"},{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:"toggleCode"},{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 yJ($,Y=j9){return Y.find((X)=>{let Z=X.shiftKey==="any"?!0:(X.shiftKey??!1)===($.shiftKey??!1);return X.key.toLowerCase()===$.key.toLowerCase()&&(X.altKey??!1)===($.altKey??!1)&&Z&&(X.modKey??!1)===Boolean($.metaKey||$.ctrlKey)})?.command??null}var hN=1024,jJ=16;function BJ({applyNextState:$,editorState:Y,editorStateRef:X,editorViewportState:Z,inputRef:J,keybindings:K,onActivity:Q,onImagePaste:M}){let D=kN(),q=()=>X.current??Y,U=TJ(!1),V=TJ(!1),G=N0((H)=>{if(!H)return;Q(),$(H)}),N=N0(()=>{let H=J.current;if(!H)return;if(typeof document>"u")return;let R=document.execCommand;if(typeof R!=="function")return;try{U.current=!0,R.call(document,"insertText",!1,""),R.call(document,"delete")}catch{}finally{U.current=!1,K5(H,q())}}),A=N0(()=>{if(V.current)return;V.current=!0,N()}),_=N0(()=>{N()}),z=N0((H)=>{if(!D)return;let R=J.current;if(!R)return;let u=Z.get(),g=J1(q(),u,H);if(!g)return;R.style.top=`${g.top}px`,R.style.left=`${g.left}px`,R.style.height=`${g.height}px`}),F=N0((H)=>{let R=J.current;if(!R)return;z(H??q().selection.focus),R.focus({preventScroll:!D}),K5(R,q()),A()}),B=N0((H,R)=>{let g=OJ(R,u6(H)).replace(/\r\n/g,`
|
|
34
|
-
`).split(/(\n)/),
|
|
35
|
-
`?a5(I):N4(I,j);if(!O)continue;I=O}return I===H?null:I}),W=N0((H,R,u)=>{let g=H.selection.focus,I={regionId:g.regionId,offset:Math.max(0,g.offset-R)},j=K0(H,{anchor:I,focus:g});return r5(j,u)}),S=N0((H)=>{if(U.current)return;let R=q(),u=IN(H.inputType);if(H.inputType==="insertText"){if(!H.data)return;H.preventDefault();let g=wJ(H.target);if(g>0){G(W(R,g,H.data));return}let I=gN(R,H.data);if(I>0){let j=H.data.slice(I);if(j.length>0)G(B(R,j));return}G(B(R,H.data));return}if(H.inputType==="insertReplacementText"){if(!H.data)return;H.preventDefault();let g=wJ(H.target);G(W(R,g,H.data));return}if(uN(H.inputType)){H.preventDefault(),G(a5(R));return}if(u==="backward"){H.preventDefault(),G(G3(R));return}if(u==="forward"){H.preventDefault(),G(V3(R));return}if(H.inputType==="historyUndo"){H.preventDefault(),G(A3(R)),_();return}if(H.inputType==="historyRedo"){H.preventDefault(),G(_3(R)),_();return}}),b=N0((H)=>{let R=q(),u=H.currentTarget.value,g=u6(R);if(U.current)return;if(OJ(u,g).length===0){K5(H.currentTarget,R);return}G(B(R,u))}),k=N0((H)=>{let R=xN(q(),Z.get(),H.nativeEvent,K);if(!R)return;H.preventDefault(),G(R)}),P=N0((H)=>{let R=N3(q());if(!R)return;H.preventDefault(),H.clipboardData.setData("text/plain",f6(R))}),y=N0((H)=>{let R=q(),u=N3(R);if(!u)return;H.preventDefault(),H.clipboardData.setData("text/plain",f6(u)),G(U3(R))}),E=N0(async(H)=>{let u=(M?[...H.clipboardData.items].find((j)=>j.kind==="file"&&j.type.startsWith("image/")):void 0)?.getAsFile()??null;if(u&&M){H.preventDefault();let j=await M(u);if(j)G(a$(q(),j));return}let g=H.clipboardData.getData("text/plain");if(g.length===0)return;H.preventDefault();let I=K9(g);G(I$(q(),I,g))}),w=N0(()=>{Q();let H=J.current;if(H)K5(H,q())}),C=N0((H)=>{if(Q(),H.target.matches(":focus-visible"))F()});w9(()=>{let H=J.current;if(!H)return;K5(H,Y)},[Y,J]),fN(()=>{z(Y.selection.focus)},[Y,z]),w9(()=>{let H=J.current;if(!H)return;let R=(u)=>S(u);return H.addEventListener("beforeinput",R),()=>H.removeEventListener("beforeinput",R)},[J,S]);let T={onCopy:P,onCut:y,onPaste:E,...D?{}:{onKeyDown:k}};return{canvasHandlers:{...T,onFocus:C},focus:F,inputHandlers:{...T,onFocus:w,onInput:b}}}var CJ="";function kN(){let[$,Y]=mN(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function")return!1;return window.matchMedia("(pointer: coarse)").matches});return w9(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function")return;let X=window.matchMedia("(pointer: coarse)"),Z=(J)=>Y(J.matches);return X.addEventListener?.("change",Z),()=>X.removeEventListener?.("change",Z)},[]),$}function uN($){return $==="insertLineBreak"||$==="insertParagraph"}function wJ($){let Y=$,X=Y?.selectionStart??0,Z=Y?.selectionEnd??X;return Math.max(0,Z-X)}function gN($,Y){if(Y.length<jJ)return 0;let X=u6($,Y.length),Z=Math.min(X.length,Y.length);for(let J=Z;J>=jJ;J--)if(X.endsWith(Y.slice(0,J)))return J;return 0}function IN($){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 pN($){return $.replaceAll(CJ,"")}function u6($,Y=hN){let{anchor:X,focus:Z}=$.selection;if(X.regionId!==Z.regionId||X.offset!==Z.offset)return"";let J=$.documentIndex.regionIndex.get(Z.regionId);if(!J)return"";return J.text.slice(Math.max(0,Z.offset-Y),Z.offset)}function OJ($,Y){let X=pN($);return X.startsWith(Y)?X.slice(Y.length):X}function K5($,Y){let X=u6(Y),Z=`${CJ}${X}`;$.value=Z,$.setSelectionRange(Z.length,Z.length)}function xN($,Y,X,Z){if(X.key==="Delete")return V3($);let J=yJ(X,Z);if(J){if(J==="moveToLineStart"||J==="moveToLineEnd")return a3($,Y.layout,J==="moveToLineStart"?"Home":"End",X.shiftKey);if(J==="moveToDocumentStart"||J==="moveToDocumentEnd")return r3($,J==="moveToDocumentStart"?"start":"end",X.shiftKey);switch(J){case"insertLineBreak":return a5($);case"insertSoftLineBreak":return g$($);case"deleteBackward":return G3($);case"indent":return s$($);case"dedent":return i$($);case"moveListItemUp":return o$($);case"moveListItemDown":return n$($);case"toggleBold":return s5($);case"toggleItalic":return i5($);case"toggleStrikethrough":return o5($);case"toggleUnderline":return n5($);case"toggleCode":return l$($);case"undo":return A3($);case"redo":return _3($);case"selectAll":return x$($)}}if(X.key==="ArrowLeft"||X.key==="ArrowRight")return l3($,X.key==="ArrowLeft"?-1:1,X.shiftKey);if(X.key==="ArrowUp"||X.key==="ArrowDown")return d3($,Y.layout,X.key==="ArrowUp"?-1:1,X.shiftKey);if(X.key==="PageUp"||X.key==="PageDown")return c3($,Y.layout,X.key==="PageUp"?-1:1,X.shiftKey);if(X.key.length===1&&!X.altKey&&!X.ctrlKey&&!X.metaKey)return N4($,X.key);return null}import{useEffectEvent as O9,useLayoutEffect as lN,useMemo as dN,useState as cN}from"react";function LJ({editorState:$,editorStateRef:Y,editorViewportState:X,onViewportScroll:Z,scrollContainerRef:J,scheduleOverlayRender:K,userPresence:Q}){let M=dN(()=>{if(!Q||Q.length===0)return;return j5($.documentIndex,Q)},[$.documentIndex,Q]),[D,q]=cN(void 0),U=O9(()=>{if(M===void 0){if(D!==void 0)q(void 0)}else q(d2(Y.current??$,X.get(),M));K()}),V=O9((N)=>{if(M===void 0){if(D!==void 0)q(void 0);return}let A=d2(Y.current??$,N,M);if(aN(D,A))return;q(A)});lN(()=>{U()},[M]);let G=O9((N)=>{if(!N.viewport||N.viewport.status==="unresolved")return;let A=J.current;if(!A)return;A.scrollTop=N.viewport.scrollTop,Z(A)});return{presence:D,scrollToPresence:G,refreshPresence:V}}function aN($,Y){if($===Y)return!0;if($===void 0||Y===void 0||$.length!==Y.length)return!1;return $.every((X,Z)=>{let J=Y[Z];return X.id===J.id&&rN(X.viewport,J.viewport)})}function rN($,Y){if($===Y)return!0;if($===null||Y===null)return!1;if($.status==="unresolved")return Y.status==="unresolved";if(Y.status==="unresolved")return!1;return $.status===Y.status&&$.scrollTop===Y.scrollTop}import{useEffect as sN,useEffectEvent as a1,useRef as Q5}from"react";function RJ({editorStateRef:$,renderContent:Y,renderOverlay:X,renderViewport:Z}){let J=Q5(null),K=Q5(!1),Q=Q5(!1),M=Q5(!1),D=Q5(!1),q=a1(()=>{if(typeof window>"u"){Z();return}K.current=!0,N()}),U=a1(()=>{if(typeof window>"u"){Y(),X();return}Q.current=!0,N()}),V=a1(()=>{if(typeof window>"u"){Y();return}M.current=!0,N()}),G=a1(()=>{if(typeof window>"u"){X();return}D.current=!0,N()}),N=a1(()=>{if(typeof window>"u"||J.current!==null)return;J.current=window.requestAnimationFrame(()=>{A()})}),A=a1(()=>{J.current=null;let z=K.current,F=Q.current,B=M.current,W=D.current;if(K.current=!1,Q.current=!1,M.current=!1,D.current=!1,z){Z(),_();return}if(F){Y(),X(),_();return}if(B)Y(),_();if(W)X()}),_=a1(()=>{let z=$.current;if(!z||!p8(z,performance.now()))return;M.current=!0,N()});return sN(()=>{return()=>{if(typeof window>"u"||J.current===null)return;window.cancelAnimationFrame(J.current),J.current=null}},[]),{scheduleContentPaint:V,scheduleFullPaint:U,scheduleFullRender:q,scheduleOverlayPaint:G}}import{useEffectEvent as B9,useLayoutEffect as kJ,useMemo as C9,useRef as L9,useState as uJ}from"react";function fJ($){let Y=$.documentIndex.regions.find((K)=>K.id===$.selection.anchor.regionId),X=$.documentIndex.regions.find((K)=>K.id===$.selection.focus.regionId),Z=(Y?.start??0)+$.selection.anchor.offset,J=(X?.start??0)+$.selection.focus.offset;return{end:Math.max(Z,J),start:Math.min(Z,J)}}function mJ($){let Y=iN($);if(Y.start.regionId!==Y.end.regionId||Y.start.offset===Y.end.offset)return null;return{endOffset:Y.end.offset,regionId:Y.start.regionId,startOffset:Y.start.offset}}var bJ=28,SJ=18;function hJ($,Y){if(!$)return;let X=$.getBoundingClientRect();if(Y.clientY<X.top+bJ){$.scrollTop=Math.max(0,$.scrollTop-SJ);return}if(Y.clientY>X.bottom-bJ)$.scrollTop+=SJ}function iN($){let Y=vJ($.documentIndex.regions,$.selection.anchor.regionId,$.selection.anchor.offset),X=vJ($.documentIndex.regions,$.selection.focus.regionId,$.selection.focus.offset);return Y<=X?{end:$.selection.focus,start:$.selection.anchor}:{end:$.selection.anchor,start:$.selection.focus}}function vJ($,Y,X){let Z=$.findIndex((J)=>J.id===Y);if(Z===-1)return-1;return Z*1e6+X}function gJ({applyNextState:$,autoScrollDuringDrag:Y,canShowSelectionLeaf:X,editorState:Z,editorStateRef:J,editorViewportState:K,focusInput:Q,onActivity:M,resolvePoint:D,threads:q}){let U=C9(()=>Y0(Z),[Z]),V=C9(()=>mJ(Z),[Z]),G=C9(()=>b5(Z),[Z]),[N,A]=uJ(null),[_,z]=uJ(null),F=L9(null),B=L9(null),W=L9(null);kJ(()=>{let E=oN(Z,K.get(),U);A((w)=>YA(w,E)?w:E)},[Z,K,U.end.offset,U.end.regionId,U.start.offset,U.start.regionId]),kJ(()=>{let E=tN({canShowSelectionLeaf:X,currentLeaf:_,activeMarks:G,handles:N,selectionRange:V,threads:q});z((w)=>$A(w,E)?w:E)},[G,X,N,_,V,q]);let S=B9((E,w=!0)=>{z((C)=>C?.kind==="create"?{animateInitialComment:w,kind:"thread",left:C.left,threadIndex:E,top:C.top}:C)}),b=B9((E)=>{if(E&&W.current===E.pointerId&&E.currentTarget.hasPointerCapture(E.pointerId))E.currentTarget.releasePointerCapture(E.pointerId);F.current=null,B.current=null,W.current=null}),k=B9((E)=>{let w=J.current,C=B.current,T=D(E);if(!T||!w||!C||W.current!==E.pointerId)return;let H=w4(w,K.get(),T,C);if(!H)return;E.preventDefault(),E.stopPropagation(),M(),Y(E),$(K0(w,{anchor:C,focus:H}))}),P=(E)=>({onPointerCancel:(w)=>{b(w)},onPointerDown:(w)=>{let C=J.current??Z,T=ZA(U,E),H=E==="start"?U.start:U.end;if(!N)return;w.preventDefault(),w.stopPropagation(),W.current=w.pointerId,B.current=T,F.current=E,w.currentTarget.setPointerCapture(w.pointerId),M(),Q(),$(K0(C,{anchor:T,focus:H}))},onPointerMove:(w)=>{if(F.current!==E)return;k(w)},onPointerUp:(w)=>{if(F.current===E)k(w);b(w)}});return{handle:N?{start:{...N.start,props:P("start")},end:{...N.end,props:P("end")}}:null,leaf:_,promoteLeafToThread:S}}function oN($,Y,X){if(X.collapsed)return null;let Z=J1($,Y,X.start),J=J1($,Y,X.end);if(!Z||!J)return null;return{end:{left:J.left,top:J.top+J.height},start:{left:Z.left,top:Z.top}}}function nN($,Y,X){return{activeMarks:X,kind:"create",left:Y.start.left,selection:$,top:Y.end.top}}function tN({activeMarks:$,canShowSelectionLeaf:Y,currentLeaf:X,handles:Z,selectionRange:J,threads:K}){if(!Y||!J||!Z)return null;if(X?.kind==="thread")return K[X.threadIndex]?X:null;return nN(J,Z,$)}function eN($,Y){return $?.kind==="create"&&$.left===Y.left&&$.selection.regionId===Y.selection.regionId&&$.selection.startOffset===Y.selection.startOffset&&$.selection.endOffset===Y.selection.endOffset&&XA($.activeMarks,Y.activeMarks)&&$.top===Y.top}function $A($,Y){if($===Y)return!0;if(!$||!Y||$.kind!==Y.kind)return!1;if($.kind==="create"&&Y.kind==="create")return eN($,Y);return $.kind==="thread"&&Y.kind==="thread"&&$.animateInitialComment===Y.animateInitialComment&&$.left===Y.left&&$.threadIndex===Y.threadIndex&&$.top===Y.top}function YA($,Y){if($===Y)return!0;if(!$||!Y)return!1;return $.start.left===Y.start.left&&$.start.top===Y.start.top&&$.end.left===Y.end.left&&$.end.top===Y.end.top}function XA($,Y){return $.length===Y.length&&$.every((X,Z)=>X===Y[Z])}function ZA($,Y){return Y==="start"?$.end:$.start}import{useEffect as JA,useMemo as xJ,useState as KA}from"react";var M5={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)"},q5={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)"},IJ={...M5,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)"},pJ={...q5,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 lJ($){let Y=xJ(()=>MA($),[$]),[X,Z]=KA(Y.light),J=xJ(()=>qA(X),[X]);return JA(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function"){Z(Y.light);return}let K=window.matchMedia("(prefers-color-scheme: dark)"),Q=()=>{Z(K.matches?Y.dark:Y.light)};if(Q(),typeof K.addEventListener==="function")return K.addEventListener("change",Q),()=>{K.removeEventListener("change",Q)};return K.addListener(Q),()=>{K.removeListener(Q)}},[Y]),{theme:X,themeStyles:J}}function QA($){return"light"in $&&"dark"in $}function MA($){if(!$)return{dark:q5,light:M5};if(QA($))return $;return{dark:$,light:$}}function qA($){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 GA,useEffectEvent as n0,useRef as R9,useState as g6}from"react";import{useMemo as DA}from"react";function dJ($){return DA(()=>UA({current:null},$),[$])}function UA($,Y){return{peek(){return $.current},get(){let X=$.current;if(X!==null)return X;let Z=Y();return $.current=Z,Z},invalidate(){$.current=null}}}function cJ($,Y){let X=Y.getBoundingClientRect();return{x:$.clientX-X.left+Y.scrollLeft,y:$.clientY-X.top+Y.scrollTop}}function aJ({editorState:$,editorStateRef:Y,renderResources:X,theme:Z}){let J=R9(k1()),K=R9(null),Q=R9({height:240,top:0}),[M,D]=g6(0),[q,U]=g6(240),[V,G]=g6(0),[N,A]=g6(240),_=VA(M),z=n0(()=>{let T=Y.current??$,H=Q.current;return u3(T,{height:H.height,paddingX:Z.paddingX,paddingY:Z.paddingY,top:H.top,width:_},J.current,X)}),F=dJ(z),B=n0((T)=>{A((H)=>{let R=AA(T,Q.current.height);return H===R?H:R})}),W=n0((T)=>{Q.current={...Q.current,top:T},G((H)=>H===T?H:T),F.invalidate()}),S=n0((T)=>{let H=NA(T),R=H.top!==Q.current.top;if(Q.current=H,G((u)=>u===H.top?u:H.top),R)F.invalidate()}),b=n0((T)=>{let H=K.current;if(!H)return W(T),T;H.scrollTop=T;let R=H.scrollTop;return W(R),R}),k=n0(()=>{return K.current?.scrollTop??Q.current.top}),P=n0((T,H)=>{let R=T!==null&&T.documentIndex!==H.documentIndex,u=F.peek();if(!(!R||!u||u.layout.regionLineIndices.has(H.selection.focus.regionId)))F.invalidate()}),y=n0(()=>{return F.invalidate(),F.get()}),E=n0((T)=>{let H=K.current;return H?cJ(T,H):null}),w=n0((T)=>{hJ(K.current,T)});return GA(()=>{let T=K.current;if(!T||typeof ResizeObserver>"u")return;let H=new ResizeObserver((R)=>{let u=R[0];if(!u)return;let g=Math.max(0,Math.floor(u.contentRect.width)),I=rJ(T);Q.current={...Q.current,height:I},D((j)=>j===g?j:g),U((j)=>j===I?j:I)});return H.observe(T),()=>H.disconnect()},[K]),{actions:{autoScrollDuringDrag:w,getScrollTop:k,observePreparedViewport:B,observeScrollContainer:S,prepareNextPaint:y,reconcileEditorState:P,resolvePoint:E,scrollTo:b},props:{getScrollContainer:(T)=>({onScroll:(H)=>{S(H.currentTarget),T?.onScroll?.(H)},ref:K}),scrollContent:{style:{height:`${N}px`}}},refs:{scrollContainer:K},state:{layoutWidth:_,preparedViewport:F,scrollContentHeight:N,surfaceWidth:M,viewportHeight:q,viewportTop:V}}}function VA($){return Math.max(240,Math.floor($||480))}function rJ($){return Math.max(240,$.clientHeight)}function NA($){return{height:rJ($),top:$.scrollTop}}function AA($,Y){return Math.max(Y,Math.ceil($.totalHeight+24))}function _A(){if(typeof window>"u")return 1;return Math.max(1,window.devicePixelRatio||1)}function b9($,{paintHeight:Y,paintTop:X,width:Z}){if(!$)return null;let J=Math.max(240,Math.ceil(Y)),K=_A();$.width=Math.ceil(Z*K),$.height=Math.ceil(J*K),$.style.width=`${Z}px`,$.style.height=`${J}px`,$.style.transform=`translateY(${X}px)`;let Q=$.getContext("2d");if(!Q)return null;return{context:Q,devicePixelRatio:K,height:J,width:Z}}function S9($,Y){return $.activeBlockType===Y.activeBlockType&&$.activeCommentThreadIndex===Y.activeCommentThreadIndex&&$.activeSpanKind===Y.activeSpanKind&&$.canonicalContent===Y.canonicalContent&&$.characterCount===Y.characterCount&&$.commentThreadCount===Y.commentThreadCount&&$.layoutWidth===Y.layoutWidth&&$.resolvedCommentCount===Y.resolvedCommentCount&&$.selectionFrom===Y.selectionFrom&&$.selectionTo===Y.selectionTo}function sJ($,Y){if(!Y?.length||!$?.length)return;let X=new Map($.map((J)=>[J.id,J])),Z=[];for(let J of Y){let K=X.get(J.userId);if(!K)continue;Z.push({...K,color:J.color,cursor:J.cursor})}return Z.length===0?void 0:Z}function oJ($,Y){if(!$)return{didReconcile:!1,state:Y};let X=HA($,Y)??wA($,Y);return X?{didReconcile:!0,state:X}:{didReconcile:!1,state:Y}}function HA($,Y){let X=zA($,Y);return X?K0(Y,X,!1):null}function zA($,Y){if(m9($.selection.anchor,$.selection.focus)){let K=v9($,Y,$.selection.focus,"neutral");return K?{anchor:K,focus:K}:null}let X=TA($),Z=v9($,Y,$.selection.anchor,X.anchor),J=v9($,Y,$.selection.focus,X.focus);return Z&&J?{anchor:Z,focus:J}:null}function v9($,Y,X,Z){let J=$.documentIndex.regionIndex.get(X.regionId);if(!J)return null;let K=f9(J,Y);if(!K)return null;return{offset:EA(J.text,K.text,X.offset,Z),regionId:K.id}}function f9($,Y){let X=Y.documentIndex.regionIndex.get($.id);if(X)return X;if($.text.length===0)return null;let Z=FA($,Y);if(Z)return Z;return Y.documentIndex.regionPathIndex.get($.path)??null}function FA($,Y){let X=null;for(let Z of Y.documentIndex.regions){if(Z.blockType!==$.blockType||Z.text!==$.text)continue;if(X)return null;X=Z}return X}function EA($,Y,X,Z){let J=b0(X,0,$.length),{prefix:K,suffix:Q}=U8($,J,J),M=WA(Y,K,Q);if(M!==null)return M;let D=PA(Y,K),q=yA(Y,Q);if(Z==="before-suffix")return q??D??b0(X,0,Y.length);return D??q??b0(X,0,Y.length)}function WA($,Y,X){let Z=K2($,Y,X).filter((J)=>J.startOffset===J.endOffset);return Z.length===1?Z[0].startOffset:null}function PA($,Y){let X=a0($,Y);return X.length===1?X[0]+Y.length:null}function yA($,Y){let X=a0($,Y);return X.length===1?X[0]:null}function TA($){let{anchor:Y,focus:X}=$.selection;if(m9(Y,X))return{anchor:"neutral",focus:"neutral"};return jA($,Y,X)<=0?{anchor:"before-suffix",focus:"after-prefix"}:{anchor:"after-prefix",focus:"before-suffix"}}function jA($,Y,X){let Z=$.documentIndex.regionOrderIndex.get(Y.regionId),J=$.documentIndex.regionOrderIndex.get(X.regionId);if(Z===void 0||J===void 0)return 0;return Z===J?Y.offset-X.offset:Z-J}function wA($,Y){if(!m9($.selection.anchor,$.selection.focus))return null;let X=OA($);if(!X)return null;let Z=BA($,Y,X);if(Z===null)return null;return CA(Y,Z)}function OA($){let Y=$.documentIndex.regionIndex.get($.selection.focus.regionId);if(!Y||Y.blockType!=="paragraph"||Y.text.length>0)return null;return $.documentIndex.blockIndex.get(Y.blockId)?.parentBlockId===null?Y:null}function BA($,Y,X){let Z=iJ($,X.rootIndex,"before"),J=iJ($,X.rootIndex,"after"),K=Z?f9(Z,Y):null,Q=J?f9(J,Y):null;if(K&&Q)return K.rootIndex<Q.rootIndex?Q.rootIndex:null;if(K)return K.rootIndex+1;if(Q)return Q.rootIndex;return null}function CA($,Y){let X=L1($.documentIndex.document,Y,0,[i({text:""})]),Z={...$,documentIndex:q2($.documentIndex,X,Y,0)},J=e2(Z.documentIndex,$0(Y));return J?K0(Z,J,!1):null}function iJ($,Y,X){let Z=X==="before"?-1:1;for(let J=Y+Z;J>=0&&J<$.documentIndex.roots.length;J+=Z){let K=LA($,J,X);if(K)return K}return null}function LA($,Y,X){let Z=$.documentIndex.roots[Y]?.regions??[],J=X==="before"?Z.length-1:0,K=X==="before"?-1:1;for(let Q=J;Q>=0&&Q<Z.length;Q+=K){let M=Z[Q];if(M&&M.text.length>0)return M}return null}function m9($,Y){return $.regionId===Y.regionId&&$.offset===Y.offset}import{jsx as c,jsxs as p6,Fragment as kA}from"react/jsx-runtime";function x6({blocks:$}){return c(kA,{children:$.map((Y)=>RA(Y))})}function RA($){switch($.type){case"blockquote":return c("blockquote",{className:"preview-block preview-block-blockquote",children:c(x6,{blocks:$.children})},$.id);case"code":return p6("div",{className:"preview-block preview-block-code",children:[c("div",{className:"preview-rich-header",children:vA($.language,$.meta)}),c("pre",{children:c("code",{children:$.source||" "})})]},$.id);case"heading":{let Y=`h${$.depth}`;return c(Y,{className:"preview-block preview-block-heading",children:I6($.children)},$.id)}case"list":return $.ordered?c("ol",{className:"preview-block preview-block-list",start:$.start??1,children:$.items.map((Y)=>h9(Y))},$.id):c("ul",{className:"preview-block preview-block-list",children:$.items.map((Y)=>h9(Y))},$.id);case"listItem":return h9($);case"paragraph":return c("p",{className:"preview-block preview-block-paragraph",children:I6($.children)},$.id);case"table":return p6("div",{className:"preview-block preview-block-table",children:[c("div",{className:"preview-rich-header",children:fA($.rows.length,$.rows[0]?.cells.length??0,$.align.filter((Y)=>Y!==null).length)}),c("div",{className:"preview-table-scroll",children:c("table",{children:c("tbody",{children:$.rows.map((Y)=>c("tr",{children:Y.cells.map((X)=>c("td",{children:I6(X.children)},X.id))},Y.id))})})})]},$.id);case"divider":return c("hr",{className:"preview-block preview-block-rule"},$.id);case"directive":return c("pre",{className:`preview-block preview-block-directive preview-block-directive-${$.name}`,children:$.body},$.id);case"raw":return c("pre",{className:"preview-block preview-block-unsupported",children:$.source},$.id)}}function h9($){return c("li",{className:"preview-block preview-block-list-item",children:c(x6,{blocks:$.children})},$.id)}function I6($){return $.map((Y)=>{switch(Y.type){case"lineBreak":return c("br",{},Y.id);case"image":return p6("span",{className:"preview-inline preview-inline-image",children:[c("img",{alt:Y.alt??"",src:Y.url,title:Y.title??""}),p6("span",{children:[c("strong",{children:mA(Y.alt)}),c("small",{children:hA(Y.url,Y.title)})]})]},Y.id);case"code":return c("code",{className:"preview-inline preview-inline-code",children:Y.code},Y.id);case"link":return bA(Y);case"text":return c("span",{className:"preview-inline",children:SA(Y.text,Y.marks)},Y.id);case"raw":return c("span",{className:"preview-inline preview-inline-unsupported",children:Y.source},Y.id)}})}function bA($){return c("a",{className:"preview-inline preview-inline-link",href:$.url,children:I6($.children)},$.id)}function SA($,Y){let X=$;for(let Z of Y)switch(Z){case"strikethrough":X=c("del",{children:X});break;case"italic":X=c("em",{children:X});break;case"bold":X=c("strong",{children:X});break;case"underline":X=c("ins",{children:X});break}return X}function vA($,Y){return[$??"plain text",Y].filter(Boolean).join(" • ")}function fA($,Y,X){let Z=X>0?`${X} aligned ${X===1?"column":"columns"}`:"no alignment";return`${$} ${$===1?"row":"rows"} • ${Y} ${Y===1?"column":"columns"} • ${Z}`}function mA($){return $?.trim()?$:"Untitled image"}function hA($,Y){return Y?.trim()?`${Y} • ${$}`:$}var nJ=`/* Base Documint host and SSR-fallback styles. */
|
|
18
|
+
`)}var y4=null,iY;function oY(){if(y4===null)y4=new Intl.Segmenter(iY,{granularity:"word"});return y4}var nY=/\p{Script=Arabic}/u,M6=/\p{M}/u,mM=/\p{Nd}/u;function jM(N){return nY.test(N)}function CM(N){return N>=19968&&N<=40959||N>=13312&&N<=19903||N>=131072&&N<=173791||N>=173824&&N<=177983||N>=177984&&N<=178207||N>=178208&&N<=183983||N>=183984&&N<=191471||N>=191472&&N<=192093||N>=194560&&N<=195103||N>=196608&&N<=201551||N>=201552&&N<=205743||N>=205744&&N<=210041||N>=63744&&N<=64255||N>=12288&&N<=12351||N>=12352&&N<=12447||N>=12448&&N<=12543||N>=12592&&N<=12687||N>=44032&&N<=55215||N>=65280&&N<=65519}function u0(N){for(let F=0;F<N.length;F++){let M=N.charCodeAt(F);if(M<12288)continue;if(M>=55296&&M<=56319&&F+1<N.length){let A=N.charCodeAt(F+1);if(A>=56320&&A<=57343){let D=(M-55296<<10)+(A-56320)+65536;if(CM(D))return!0;F++;continue}}if(CM(M))return!0}return!1}function tY(N){let F=E6(N);return F!==null&&(D6.has(F)||G1.has(F))}var eY=new Set([" "," ","","\uFEFF"]);function NZ(N){return u0(N)}function FZ(N){let F=E6(N);return F!==null&&eY.has(F)}function A6(N){return!tY(N)&&!FZ(N)}var D6=new Set([",",".","!",":",";","?","、","。","・",")","〕","〉","》","」","』","】","〗","〙","〛","ー","々","〻","ゝ","ゞ","ヽ","ヾ"]),UN=new Set(['"',"(","[","{","“","‘","«","‹","(","〔","〈","《","「","『","【","〖","〘","〚"]),P4=new Set(["'","’"]),G1=new Set([".",",","!","?",":",";","،","؛","؟","।","॥","၊","။","၌","၍","၏",")","]","}","%",'"',"”","’","»","›","…"]),MZ=new Set([":",".","،","؛"]),AZ=new Set(["၏"]),DZ=new Set(["”","’","»","›","」","』","】","》","〉","〕",")"]);function EZ(N){if(T4(N))return!0;let F=!1;for(let M of N){if(G1.has(M)){F=!0;continue}if(F&&M6.test(M))continue;return!1}return F}function $Z(N){for(let F of N)if(!D6.has(F)&&!G1.has(F))return!1;return N.length>0}function YZ(N){if(T4(N))return!0;for(let F of N)if(!UN.has(F)&&!P4.has(F)&&!M6.test(F))return!1;return N.length>0}function T4(N){let F=!1;for(let M of N){if(M==="\\"||M6.test(M))continue;if(UN.has(M)||G1.has(M)||P4.has(M)){F=!0;continue}return!1}return F}function kM(N,F){let M=F-1;if(M<=0)return Math.max(M,0);let A=N.charCodeAt(M);if(A<56320||A>57343)return M;let D=M-1;if(D<0)return M;let E=N.charCodeAt(D);return E>=55296&&E<=56319?D:M}function E6(N){if(N.length===0)return null;let F=kM(N,N.length);return N.slice(F)}function ZZ(N){let F=Array.from(N),M=F.length;while(M>0){let A=F[M-1];if(M6.test(A)){M--;continue}if(UN.has(A)||P4.has(A)){M--;continue}break}if(M<=0||M===F.length)return null;return{head:F.slice(0,M).join(""),tail:F.slice(M).join("")}}function XZ(N,F,M){return M==="text"&&!F&&N.length===1&&N!=="-"&&N!=="—"?N:null}function SM(N,F,M,A){let D=F[A],E=N[A];if(D==null)return E;let $=M[A];if(E.length===$)return E;let Y=D.repeat($);return N[A]=Y,Y}function RM(N,F){return N&&F!==null&&MZ.has(F)}function QZ(N){let F=E6(N);return F!==null&&AZ.has(F)}function JZ(N){if(N.length<2||N[0]!==" ")return null;let F=N.slice(1);if(/^\p{M}+$/u.test(F))return{space:" ",marks:F};return null}function $6(N){let F=N.length;while(F>0){let M=kM(N,F),A=N.slice(M,F);if(DZ.has(A))return!0;if(!G1.has(A))return!1;F=M}return!1}function KZ(N,F){if(F.preserveOrdinarySpaces||F.preserveHardBreaks){if(N===" ")return"preserved-space";if(N==="\t")return"tab";if(F.preserveHardBreaks&&N===`
|
|
19
|
+
`)return"hard-break"}if(N===" ")return"space";if(N===" "||N===" "||N===""||N==="\uFEFF")return"glue";if(N==="")return"zero-width-break";if(N==="")return"soft-hyphen";return"text"}var qZ=/[\x20\t\n\xA0\xAD\u200B\u202F\u2060\uFEFF]/;function R0(N){return N.length===1?N[0]:N.join("")}function UZ(N,F){let M=[];for(let A=N.length-1;A>=0;A--)M.push(N[A]);return M.push(F),R0(M)}function VZ(N,F,M,A){if(!qZ.test(N))return[{text:N,isWordLike:F,kind:"text",start:M}];let D=[],E=null,$=[],Y=M,Z=!1,X=0;for(let Q of N){let K=KZ(Q,A),J=K==="text"&&F;if(E!==null&&K===E&&J===Z){$.push(Q),X+=Q.length;continue}if(E!==null)D.push({text:R0($),isWordLike:Z,kind:E,start:Y});E=K,$=[Q],Y=M+X,Z=J,X+=Q.length}if(E!==null)D.push({text:R0($),isWordLike:Z,kind:E,start:Y});return D}function O4(N){return N==="space"||N==="preserved-space"||N==="zero-width-break"||N==="hard-break"}var GZ=/^[A-Za-z][A-Za-z0-9+.-]*:$/;function zZ(N,F){let M=N.texts[F];if(M.startsWith("www."))return!0;return GZ.test(M)&&F+1<N.len&&N.kinds[F+1]==="text"&&N.texts[F+1]==="//"}function _Z(N){return N.includes("?")&&(N.includes("://")||N.startsWith("www."))}function HZ(N){let F=N.texts.slice(),M=N.isWordLike.slice(),A=N.kinds.slice(),D=N.starts.slice();for(let $=0;$<N.len;$++){if(A[$]!=="text"||!zZ(N,$))continue;let Y=[F[$]],Z=$+1;while(Z<N.len&&!O4(A[Z])){Y.push(F[Z]),M[$]=!0;let X=F[Z].includes("?");if(A[Z]="text",F[Z]="",Z++,X)break}F[$]=R0(Y)}let E=0;for(let $=0;$<F.length;$++){let Y=F[$];if(Y.length===0)continue;if(E!==$)F[E]=Y,M[E]=M[$],A[E]=A[$],D[E]=D[$];E++}return F.length=E,M.length=E,A.length=E,D.length=E,{len:E,texts:F,isWordLike:M,kinds:A,starts:D}}function BZ(N){let F=[],M=[],A=[],D=[];for(let E=0;E<N.len;E++){let $=N.texts[E];if(F.push($),M.push(N.isWordLike[E]),A.push(N.kinds[E]),D.push(N.starts[E]),!_Z($))continue;let Y=E+1;if(Y>=N.len||O4(N.kinds[Y]))continue;let Z=[],X=N.starts[Y],Q=Y;while(Q<N.len&&!O4(N.kinds[Q]))Z.push(N.texts[Q]),Q++;if(Z.length>0)F.push(R0(Z)),M.push(!0),A.push("text"),D.push(X),E=Q-1}return{len:F.length,texts:F,isWordLike:M,kinds:A,starts:D}}var WZ=new Set([":","-","/","×",",",".","+","–","—"]),bM=/^[A-Za-z0-9_]+[,:;]*$/,vM=/[,:;]+$/;function hM(N){for(let F of N)if(mM.test(F))return!0;return!1}function qN(N){if(N.length===0)return!1;for(let F of N){if(mM.test(F)||WZ.has(F))continue;return!1}return!0}function yZ(N){let F=[],M=[],A=[],D=[];for(let E=0;E<N.len;E++){let $=N.texts[E],Y=N.kinds[E];if(Y==="text"&&qN($)&&hM($)){let Z=[$],X=E+1;while(X<N.len&&N.kinds[X]==="text"&&qN(N.texts[X]))Z.push(N.texts[X]),X++;F.push(R0(Z)),M.push(!0),A.push("text"),D.push(N.starts[E]),E=X-1;continue}F.push($),M.push(N.isWordLike[E]),A.push(Y),D.push(N.starts[E])}return{len:F.length,texts:F,isWordLike:M,kinds:A,starts:D}}function OZ(N){let F=[],M=[],A=[],D=[];for(let E=0;E<N.len;E++){let $=N.texts[E],Y=N.kinds[E],Z=N.isWordLike[E];if(Y==="text"&&Z&&bM.test($)){let X=[$],Q=vM.test($),K=E+1;while(Q&&K<N.len&&N.kinds[K]==="text"&&N.isWordLike[K]&&bM.test(N.texts[K])){let J=N.texts[K];X.push(J),Q=vM.test(J),K++}F.push(R0(X)),M.push(!0),A.push("text"),D.push(N.starts[E]),E=K-1;continue}F.push($),M.push(Z),A.push(Y),D.push(N.starts[E])}return{len:F.length,texts:F,isWordLike:M,kinds:A,starts:D}}function PZ(N){let F=[],M=[],A=[],D=[];for(let E=0;E<N.len;E++){let $=N.texts[E];if(N.kinds[E]==="text"&&$.includes("-")){let Y=$.split("-"),Z=Y.length>1;for(let X=0;X<Y.length;X++){let Q=Y[X];if(!Z)break;if(Q.length===0||!hM(Q)||!qN(Q))Z=!1}if(Z){let X=0;for(let Q=0;Q<Y.length;Q++){let K=Y[Q],J=Q<Y.length-1?`${K}-`:K;F.push(J),M.push(!0),A.push("text"),D.push(N.starts[E]+X),X+=J.length}continue}}F.push($),M.push(N.isWordLike[E]),A.push(N.kinds[E]),D.push(N.starts[E])}return{len:F.length,texts:F,isWordLike:M,kinds:A,starts:D}}function TZ(N){let F=[],M=[],A=[],D=[],E=0;while(E<N.len){let $=[N.texts[E]],Y=N.isWordLike[E],Z=N.kinds[E],X=N.starts[E];if(Z==="glue"){let Q=[$[0]],K=X;E++;while(E<N.len&&N.kinds[E]==="glue")Q.push(N.texts[E]),E++;let J=R0(Q);if(E<N.len&&N.kinds[E]==="text")$[0]=J,$.push(N.texts[E]),Y=N.isWordLike[E],Z="text",X=K,E++;else{F.push(J),M.push(!1),A.push("glue"),D.push(K);continue}}else E++;if(Z==="text")while(E<N.len&&N.kinds[E]==="glue"){let Q=[];while(E<N.len&&N.kinds[E]==="glue")Q.push(N.texts[E]),E++;let K=R0(Q);if(E<N.len&&N.kinds[E]==="text"){$.push(K,N.texts[E]),Y=Y||N.isWordLike[E],E++;continue}$.push(K)}F.push(R0($)),M.push(Y),A.push(Z),D.push(X)}return{len:F.length,texts:F,isWordLike:M,kinds:A,starts:D}}function LZ(N){let F=N.texts.slice(),M=N.isWordLike.slice(),A=N.kinds.slice(),D=N.starts.slice();for(let E=0;E<F.length-1;E++){if(A[E]!=="text"||A[E+1]!=="text")continue;if(!u0(F[E])||!u0(F[E+1]))continue;let $=ZZ(F[E]);if($===null)continue;F[E]=$.head,F[E+1]=$.tail+F[E+1],D[E+1]=D[E]+$.head.length}return{len:F.length,texts:F,isWordLike:M,kinds:A,starts:D}}function fM(N,F,M){let A=oY(),D=0,E=[],$=[],Y=[],Z=[],X=[],Q=[],K=[],J=[],q=[],U=[],V=[],G=[];for(let H of A.segment(N))for(let B of VZ(H.segment,H.isWordLike??!1,H.index,M)){let S=function(){if(Q[y]!==null)$[y]=[SM(E,Q,K,y)],Q[y]=null;$[y].push(B.text),Y[y]=Y[y]||B.isWordLike,J[y]=J[y]||O,q[y]=q[y]||P,U[y]=z,V[y]=b,G[y]=RM(q[y],C)},j=B.kind==="text",T=XZ(B.text,B.isWordLike,B.kind),O=u0(B.text),P=jM(B.text),C=E6(B.text),z=$6(B.text),b=QZ(B.text),y=D-1;if(F.carryCJKAfterClosingQuote&&j&&D>0&&Z[y]==="text"&&O&&J[y]&&U[y])S();else if(j&&D>0&&Z[y]==="text"&&$Z(B.text)&&J[y])S();else if(j&&D>0&&Z[y]==="text"&&V[y])S();else if(j&&D>0&&Z[y]==="text"&&B.isWordLike&&P&&G[y])S(),Y[y]=!0;else if(T!==null&&D>0&&Z[y]==="text"&&Q[y]===T)K[y]=(K[y]??1)+1;else if(j&&!B.isWordLike&&D>0&&Z[y]==="text"&&!J[y]&&(EZ(B.text)||B.text==="-"&&Y[y]))S();else E[D]=B.text,$[D]=[B.text],Y[D]=B.isWordLike,Z[D]=B.kind,X[D]=B.start,Q[D]=T,K[D]=T===null?0:1,J[D]=O,q[D]=P,U[D]=z,V[D]=b,G[D]=RM(P,C),D++}for(let H=0;H<D;H++){if(Q[H]!==null){E[H]=SM(E,Q,K,H);continue}E[H]=R0($[H])}for(let H=1;H<D;H++)if(Z[H]==="text"&&!Y[H]&&T4(E[H])&&Z[H-1]==="text"&&!J[H-1])E[H-1]+=E[H],Y[H-1]=Y[H-1]||Y[H],E[H]="";let _=Array.from({length:D},()=>null),w=-1;for(let H=D-1;H>=0;H--){let B=E[H];if(B.length===0)continue;if(Z[H]==="text"&&!Y[H]&&YZ(B)&&w>=0&&Z[w]==="text"){let j=_[w]??[];j.push(B),_[w]=j,X[w]=X[H],E[H]="";continue}w=H}for(let H=0;H<D;H++){let B=_[H];if(B==null)continue;E[H]=UZ(B,E[H])}let L=0;for(let H=0;H<D;H++){let B=E[H];if(B.length===0)continue;if(L!==H)E[L]=B,Y[L]=Y[H],Z[L]=Z[H],X[L]=X[H];L++}E.length=L,Y.length=L,Z.length=L,X.length=L;let m=TZ({len:L,texts:E,isWordLike:Y,kinds:Z,starts:X}),W=LZ(OZ(PZ(yZ(BZ(HZ(m))))));for(let H=0;H<W.len-1;H++){let B=JZ(W.texts[H]);if(B===null)continue;if(W.kinds[H]!=="space"&&W.kinds[H]!=="preserved-space"||W.kinds[H+1]!=="text"||!jM(W.texts[H+1]))continue;W.texts[H]=B.space,W.isWordLike[H]=!1,W.kinds[H]=W.kinds[H]==="preserved-space"?"preserved-space":"space",W.texts[H+1]=B.marks+W.texts[H+1],W.starts[H+1]=W.starts[H]+B.space.length}return W}function wZ(N,F){if(N.len===0)return[];if(!F.preserveHardBreaks)return[{startSegmentIndex:0,endSegmentIndex:N.len,consumedEndSegmentIndex:N.len}];let M=[],A=0;for(let D=0;D<N.len;D++){if(N.kinds[D]!=="hard-break")continue;M.push({startSegmentIndex:A,endSegmentIndex:D,consumedEndSegmentIndex:D+1}),A=D+1}if(A<N.len)M.push({startSegmentIndex:A,endSegmentIndex:N.len,consumedEndSegmentIndex:N.len});return M}function jZ(N){if(N.len<=1)return N;let F=[],M=[],A=[],D=[],E=null,$=!1,Y=0,Z=!1,X=!1;function Q(){if(E===null)return;F.push(R0(E)),M.push($),A.push("text"),D.push(Y),E=null}for(let K=0;K<N.len;K++){let J=N.texts[K],q=N.kinds[K],U=N.isWordLike[K],V=N.starts[K];if(q==="text"){let G=NZ(J),_=A6(J);if(E!==null&&Z&&X){E.push(J),$=$||U,Z=Z||G,X=_;continue}Q(),E=[J],$=U,Y=V,Z=G,X=_;continue}Q(),F.push(J),M.push(U),A.push(q),D.push(V)}return Q(),{len:F.length,texts:F,isWordLike:M,kinds:A,starts:D}}function gM(N,F,M="normal",A="normal"){let D=aY(M),E=D.mode==="pre-wrap"?sY(N):rY(N);if(E.length===0)return{normalized:E,chunks:[],len:0,texts:[],isWordLike:[],kinds:[],starts:[]};let $=A==="keep-all"?jZ(fM(E,F,D)):fM(E,F,D);return{normalized:E,chunks:wZ($,D),...$}}var _2=null,IM=new Map,H2=null,CZ=96,SZ=/\p{Emoji_Presentation}/u,RZ=/[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u,L4=null,uM=new Map;function w4(){if(_2!==null)return _2;if(typeof OffscreenCanvas<"u")return _2=new OffscreenCanvas(1,1).getContext("2d"),_2;if(typeof document<"u")return _2=document.createElement("canvas").getContext("2d"),_2;throw Error("Text measurement requires OffscreenCanvas or a DOM canvas context.")}function bZ(N){let F=IM.get(N);if(!F)F=new Map,IM.set(N,F);return F}function D1(N,F){let M=F.get(N);if(M===void 0)M={width:w4().measureText(N).width,containsCJK:u0(N)},F.set(N,M);return M}function B2(){if(H2!==null)return H2;if(typeof navigator>"u")return H2={lineFitEpsilon:0.005,carryCJKAfterClosingQuote:!1,preferPrefixWidthsForBreakableRuns:!1,preferEarlySoftHyphenBreak:!1},H2;let N=navigator.userAgent,M=navigator.vendor==="Apple Computer, Inc."&&N.includes("Safari/")&&!N.includes("Chrome/")&&!N.includes("Chromium/")&&!N.includes("CriOS/")&&!N.includes("FxiOS/")&&!N.includes("EdgiOS/"),A=N.includes("Chrome/")||N.includes("Chromium/")||N.includes("CriOS/")||N.includes("Edg/");return H2={lineFitEpsilon:M?0.015625:0.005,carryCJKAfterClosingQuote:A,preferPrefixWidthsForBreakableRuns:M,preferEarlySoftHyphenBreak:M},H2}function vZ(N){let F=N.match(/(\d+(?:\.\d+)?)\s*px/);return F?parseFloat(F[1]):16}function pM(){if(L4===null)L4=new Intl.Segmenter(void 0,{granularity:"grapheme"});return L4}function fZ(N){return SZ.test(N)||N.includes("️")}function xM(N){return RZ.test(N)}function mZ(N,F){let M=uM.get(N);if(M!==void 0)return M;let A=w4();A.font=N;let D=A.measureText("\uD83D\uDE00").width;if(M=0,D>F+0.5&&typeof document<"u"&&document.body!==null){let E=document.createElement("span");E.style.font=N,E.style.display="inline-block",E.style.visibility="hidden",E.style.position="absolute",E.textContent="\uD83D\uDE00",document.body.appendChild(E);let $=E.getBoundingClientRect().width;if(document.body.removeChild(E),D-$>0.5)M=D-$}return uM.set(N,M),M}function kZ(N){let F=0,M=pM();for(let A of M.segment(N))if(fZ(A.segment))F++;return F}function hZ(N,F){if(F.emojiCount===void 0)F.emojiCount=kZ(N);return F.emojiCount}function z1(N,F,M){if(M===0)return F.width;return F.width-hZ(N,F)*M}function lM(N,F,M,A,D){if(F.breakableFitAdvances!==void 0&&F.breakableFitMode===D)return F.breakableFitAdvances;F.breakableFitMode=D;let E=pM(),$=[];for(let Q of E.segment(N))$.push(Q.segment);if($.length<=1)return F.breakableFitAdvances=null,F.breakableFitAdvances;if(D==="sum-graphemes"){let Q=[];for(let K of $){let J=D1(K,M);Q.push(z1(K,J,A))}return F.breakableFitAdvances=Q,F.breakableFitAdvances}if(D==="pair-context"||$.length>CZ){let Q=[],K=null,J=0;for(let q of $){let U=D1(q,M),V=z1(q,U,A);if(K===null)Q.push(V);else{let G=K+q,_=D1(G,M);Q.push(z1(G,_,A)-J)}K=q,J=V}return F.breakableFitAdvances=Q,F.breakableFitAdvances}let Y=[],Z="",X=0;for(let Q of $){Z+=Q;let K=D1(Z,M),J=z1(Z,K,A);Y.push(J-X),X=J}return F.breakableFitAdvances=Y,F.breakableFitAdvances}function dM(N,F){let M=w4();M.font=N;let A=bZ(N),D=vZ(N),E=F?mZ(N,D):0;return{cache:A,fontSize:D,emojiCorrection:E}}function gZ(N){return N==="space"||N==="zero-width-break"||N==="soft-hyphen"}function rM(N){return N==="space"||N==="preserved-space"||N==="tab"||N==="zero-width-break"||N==="soft-hyphen"}function sM(N,F,M=N.widths.length){while(F<M){let A=N.kinds[F];if(!gZ(A))break;F++}return F}function IZ(N,F){if(F<=0)return 0;let M=N%F;if(Math.abs(M)<=0.000001)return F;return F-M}function uZ(N,F,M){return N.letterSpacing!==0&&F&&N.spacingGraphemeCounts[M]>0?N.letterSpacing:0}function j4(N,F){return F===0?0:N+F}function pZ(N,F){return N.letterSpacing!==0&&N.spacingGraphemeCounts[F]>0?N.letterSpacing:0}function xZ(N,F,M,A,D){let E=F==="tab"?D+pZ(N,M):N.lineEndFitAdvances[M];return j4(A,E)}function cM(N,F,M,A){let D=F==="tab"?0:N.lineEndFitAdvances[M];return j4(A,D)}function aM(N,F,M,A,D){let E=F==="tab"?D:N.lineEndPaintAdvances[M];return j4(A,E)}function lZ(N,F,M){return N.letterSpacing!==0&&F?M+N.letterSpacing:M}function dZ(N,F){return N.letterSpacing===0?F:F+N.letterSpacing}function cZ(N,F,M,A,D,E){let $=0,Y=F;while($<N.length){let Z=Y+N[$]+E;if(($+1<N.length?Z+D:Z)>M+A)break;Y=Z,$++}return{fitCount:$,fittedWidth:Y}}function aZ(N,F,M){let{widths:A,kinds:D,breakableFitAdvances:E}=N;if(A.length===0)return 0;let Y=B2().lineFitEpsilon,Z=F+Y,X=0,Q=0,K=!1,J=0,q=0,U=0,V=0,G=-1,_=0;function w(){G=-1,_=0}function L(T=U,O=V,P=Q){X++,M?.(P,J,q,T,O),Q=0,K=!1,w()}function m(T,O){K=!0,J=T,q=0,U=T+1,V=0,Q=O}function W(T,O,P){K=!0,J=T,q=O,U=T,V=O+1,Q=P}function H(T,O){if(!K){m(T,O);return}Q+=O,U=T+1,V=0}function B(T,O){let P=E[T];for(let C=O;C<P.length;C++){let z=P[C];if(!K)W(T,C,z);else if(Q+z>Z)L(),W(T,C,z);else Q+=z,U=T,V=C+1}if(K&&U===T&&V===P.length)U=T+1,V=0}let j=0;while(j<A.length){if(!K){if(j=sM(N,j),j>=A.length)break}let T=A[j],O=D[j],P=rM(O);if(!K){if(T>Z&&E[j]!==null)B(j,0);else m(j,T);if(P)G=j+1,_=Q-T;j++;continue}if(Q+T>Z){if(P){H(j,T),L(j+1,0,Q-T),j++;continue}if(G>=0){if(U>G||U===G&&V>0){L();continue}L(G,0,_);continue}if(T>Z&&E[j]!==null){L(),B(j,0),j++;continue}L();continue}if(H(j,T),P)G=j+1,_=Q-T;j++}if(K)L();return X}function iM(N,F,M){if(N.simpleLineWalkFastPath)return aZ(N,F,M);let{widths:A,kinds:D,breakableFitAdvances:E,discretionaryHyphenWidth:$,chunks:Y}=N;if(A.length===0||Y.length===0)return 0;let Z=B2(),X=Z.lineFitEpsilon,Q=F+X,K=0,J=0,q=!1,U=0,V=0,G=0,_=0,w=-1,L=0,m=0,W=null;function H(){w=-1,L=0,m=0,W=null}function B(y=G,S=_,R=J){K++,M?.(R,U,V,y,S),J=0,q=!1,H()}function j(y,S){q=!0,U=y,V=0,G=y+1,_=0,J=S}function T(y,S,R){q=!0,U=y,V=S,G=y,_=S+1,J=R}function O(y,S){if(!q){j(y,S);return}J+=S,G=y+1,_=0}function P(y,S,R,k,f,g){if(!S)return;let I=cM(N,y,R,f),c=aM(N,y,R,f,k);w=R+1,L=J-g+I,m=J-g+c,W=y}function C(y,S){let R=E[y];for(let k=S;k<R.length;k++){let f=R[k];if(!q)T(y,k,f);else{let g=lZ(N,!0,f),I=J+g;if(dZ(N,I)>Q)B(),T(y,k,f);else J=I,G=y,_=k+1}}if(q&&G===y&&_===R.length)G=y+1,_=0}function z(y){if(W!=="soft-hyphen")return!1;let S=E[y];if(S==null)return!1;let{fitCount:R,fittedWidth:k}=cZ(S,J,F,X,$,N.letterSpacing);if(R===0)return!1;if(J=k,G=y,_=R,H(),R===S.length)return G=y+1,_=0,!0;return B(y,R,k+$),C(y,R),!0}function b(y){K++,M?.(0,y.startSegmentIndex,0,y.consumedEndSegmentIndex,0),H()}for(let y=0;y<Y.length;y++){let S=Y[y];if(S.startSegmentIndex===S.endSegmentIndex){b(S);continue}q=!1,J=0,U=S.startSegmentIndex,V=0,G=S.startSegmentIndex,_=0,H();let R=S.startSegmentIndex;while(R<S.endSegmentIndex){if(!q){if(R=sM(N,R,S.endSegmentIndex),R>=S.endSegmentIndex)break}let k=D[R],f=rM(k),g=uZ(N,q,R),I=k==="tab"?IZ(J+g,N.tabStopAdvance):A[R],c=g+I,$0=xZ(N,k,R,g,I);if(k==="soft-hyphen"){if(q)G=R+1,_=0,w=R+1,L=J+$,m=J+$,W=k;R++;continue}if(!q){if($0>Q&&E[R]!==null)C(R,0);else j(R,I);P(k,f,R,I,g,c),R++;continue}if(J+$0>Q){let U0=J+cM(N,k,R,g),v0=J+aM(N,k,R,g,I);if(W==="soft-hyphen"&&Z.preferEarlySoftHyphenBreak&&L<=Q){B(w,0,m);continue}if(W==="soft-hyphen"&&z(R)){R++;continue}if(f&&U0<=Q){O(R,c),B(R+1,0,v0),R++;continue}if(w>=0&&L<=Q){if(G>w||G===w&&_>0){B();continue}let Q1=w;B(Q1,0,m),R=Q1;continue}if($0>Q&&E[R]!==null){B(),C(R,0),R++;continue}B();continue}O(R,c),P(k,f,R,I,g,c),R++}if(q){let k=w===S.consumedEndSegmentIndex?m:J;B(S.consumedEndSegmentIndex,0,k)}}return K}var C4=null,oM=new WeakMap;function rZ(){if(C4===null)C4=new Intl.Segmenter(void 0,{granularity:"grapheme"});return C4}function nM(N,F,M){let A=M.get(N);if(A!==void 0)return A;A=[];let D=rZ();for(let E of D.segment(F[N]))A.push(E.segment);return M.set(N,A),A}function sZ(N,F,M,A){return A>0&&N[A-1]==="soft-hyphen"&&!(F===A&&M>0)}function tM(N,F,M,A){for(let D=M;D<A;D++)N+=F[D];return N}function eM(N){let F=oM.get(N);if(F!==void 0)return F;return F=new Map,oM.set(N,F),F}function N7(N,F,M,A,D,E){let $="",Y=sZ(N.kinds,M,A,D);for(let Z=M;Z<D;Z++){if(N.kinds[Z]==="soft-hyphen"||N.kinds[Z]==="hard-break")continue;if(Z===M&&A>0){let X=nM(Z,N.segments,F);$=tM($,X,A,X.length)}else $+=N.segments[Z]}if(E>0){if(Y)$+="-";let Z=nM(D,N.segments,F);$=tM($,Z,M===D?A:0,E)}else if(Y)$+="-";return $}var S4=null;function M7(){if(S4===null)S4=new Intl.Segmenter(void 0,{granularity:"grapheme"});return S4}function iZ(N){if(N)return{widths:[],lineEndFitAdvances:[],lineEndPaintAdvances:[],kinds:[],simpleLineWalkFastPath:!0,segLevels:null,breakableFitAdvances:[],letterSpacing:0,spacingGraphemeCounts:[],discretionaryHyphenWidth:0,tabStopAdvance:0,chunks:[],segments:[]};return{widths:[],lineEndFitAdvances:[],lineEndPaintAdvances:[],kinds:[],simpleLineWalkFastPath:!0,segLevels:null,breakableFitAdvances:[],letterSpacing:0,spacingGraphemeCounts:[],discretionaryHyphenWidth:0,tabStopAdvance:0,chunks:[]}}function oZ(N,F){let M=[],A=[],D=0,E=!1,$=!1,Y=!1;function Z(){if(A.length===0)return;M.push({text:A.length===1?A[0]:A.join(""),start:D}),A=[],E=!1,$=!1,Y=!1}function X(K,J,q){A=[K],D=J,E=q,$=$6(K),Y=UN.has(K)}function Q(K,J){A.push(K),E=E||J;let q=$6(K);if(K.length===1&&G1.has(K))$=$||q;else $=q;Y=!1}for(let K of M7().segment(N)){let J=K.segment,q=u0(J);if(A.length===0){X(J,K.index,q);continue}if(Y||D6.has(J)||G1.has(J)||F.carryCJKAfterClosingQuote&&q&&$){Q(J,q);continue}if(!E&&!q){Q(J,q);continue}Z(),X(J,K.index,q)}return Z(),M}function nZ(N){if(N.length<=1)return N;let F=[],M=[N[0].text],A=N[0].start,D=u0(N[0].text),E=A6(N[0].text);function $(){F.push({text:M.length===1?M[0]:M.join(""),start:A})}for(let Y=1;Y<N.length;Y++){let Z=N[Y],X=u0(Z.text),Q=A6(Z.text);if(D&&E){M.push(Z.text),D=D||X,E=Q;continue}$(),M=[Z.text],A=Z.start,D=X,E=Q}return $(),F}function F7(N,F){if(F==="zero-width-break"||F==="soft-hyphen"||F==="hard-break")return 0;if(F==="tab")return 1;let M=0,A=M7();for(let D of A.segment(N))M++;return M}function tZ(N,F,M){return F>1?N+(F-1)*M:N}function eZ(N,F,M,A,D){let E=B2(),{cache:$,emojiCorrection:Y}=dM(F,xM(N.normalized)),Z=z1("-",D1("-",$),Y)+(D===0?0:D),Q=z1(" ",D1(" ",$),Y)*8,K=D!==0;if(N.len===0)return iZ(M);let J=[],q=[],U=[],V=[],G=N.chunks.length<=1&&!K,_=M?[]:null,w=[],L=[],m=M?[]:null,W=Array.from({length:N.len});function H(O,P,C,z,b,y,S,R){if(b!=="text"&&b!=="space"&&b!=="zero-width-break")G=!1;if(J.push(P),q.push(C),U.push(z),V.push(b),_?.push(y),w.push(S),K)L.push(R);if(m!==null)m.push(O)}function B(O,P,C,z,b){let y=D1(O,$),S=K?F7(O,P):0,R=tZ(z1(O,y,Y),S,D),k=P==="space"||P==="preserved-space"||P==="zero-width-break"?0:R,f=k===0?0:k+(S>0?D:0),g=P==="space"||P==="zero-width-break"?0:R;if(b&&z&&O.length>1){let I="sum-graphemes";if(D!==0)I="segment-prefixes";else if(qN(O))I="pair-context";else if(E.preferPrefixWidthsForBreakableRuns)I="segment-prefixes";let c=lM(O,y,$,Y,I);H(O,R,f,g,P,C,c,S);return}H(O,R,f,g,P,C,null,S)}for(let O=0;O<N.len;O++){W[O]=J.length;let P=N.texts[O],C=N.isWordLike[O],z=N.kinds[O],b=N.starts[O];if(z==="soft-hyphen"){H(P,0,Z,Z,z,b,null,0);continue}if(z==="hard-break"){H(P,0,0,0,z,b,null,0);continue}if(z==="tab"){H(P,0,0,0,z,b,null,K?F7(P,z):0);continue}let y=D1(P,$);if(z==="text"&&y.containsCJK){let S=oZ(P,E),R=A==="keep-all"?nZ(S):S;for(let k=0;k<R.length;k++){let f=R[k];B(f.text,"text",b+f.start,C,A==="keep-all"||!u0(f.text))}continue}B(P,z,b,C,!0)}let j=NX(N.chunks,W,J.length),T=_===null?null:wM(N.normalized,_);if(m!==null)return{widths:J,lineEndFitAdvances:q,lineEndPaintAdvances:U,kinds:V,simpleLineWalkFastPath:G,segLevels:T,breakableFitAdvances:w,letterSpacing:D,spacingGraphemeCounts:L,discretionaryHyphenWidth:Z,tabStopAdvance:Q,chunks:j,segments:m};return{widths:J,lineEndFitAdvances:q,lineEndPaintAdvances:U,kinds:V,simpleLineWalkFastPath:G,segLevels:T,breakableFitAdvances:w,letterSpacing:D,spacingGraphemeCounts:L,discretionaryHyphenWidth:Z,tabStopAdvance:Q,chunks:j}}function NX(N,F,M){let A=[];for(let D=0;D<N.length;D++){let E=N[D],$=E.startSegmentIndex<F.length?F[E.startSegmentIndex]:M,Y=E.endSegmentIndex<F.length?F[E.endSegmentIndex]:M,Z=E.consumedEndSegmentIndex<F.length?F[E.consumedEndSegmentIndex]:M;A.push({startSegmentIndex:$,endSegmentIndex:Y,consumedEndSegmentIndex:Z})}return A}function FX(N,F,M,A){let D=A?.wordBreak??"normal",E=A?.letterSpacing??0,$=gM(N,B2(),A?.whiteSpace,D);return eZ($,F,M,D,E)}function A7(N,F,M){return FX(N,F,!0,M)}function MX(N){return N}function AX(N,F,M,A,D,E,$){return{text:N7(N,F,A,D,E,$),width:M,start:{segmentIndex:A,graphemeIndex:D},end:{segmentIndex:E,graphemeIndex:$}}}function D7(N,F,M){let A=[];if(N.widths.length===0)return{lineCount:0,height:0,lines:A};let D=eM(N),E=iM(MX(N),F,($,Y,Z,X,Q)=>{A.push(AX(N,D,$,Y,Z,X,Q))});return{lineCount:E,height:E*M,lines:A}}function VN(N,F,M){let A=N.image?F.images.get(N.image.url)??null:null,D=N.image?.width??null,E=Math.min(M,D??240),$=Math.max(120,Math.round(E*0.5625));if(!A||A.intrinsicWidth<=0||A.intrinsicHeight<=0)return{height:$,width:E};let Y=Math.min(M,D??A.intrinsicWidth),Z=Math.min(1,Y/A.intrinsicWidth);return{height:Math.max(48,Math.round(A.intrinsicHeight*Z)),width:Math.max(48,Math.round(A.intrinsicWidth*Z))}}function E7(N,F){if(!N.image)return`${N.kind}:missing-image`;let M=F.images.get(N.image.url);return`${N.kind}:${N.image.url}:${N.image.width??0}:${M?.status??"loading"}:${M?.intrinsicWidth??0}:${M?.intrinsicHeight??0}`}var $7=[{fontSize:32,lineHeight:36},{fontSize:26,lineHeight:32},{fontSize:21,lineHeight:28},{fontSize:21,lineHeight:28},{fontSize:19,lineHeight:26},{fontSize:18,lineHeight:26}],Y6;function W2(N){if(N?.type==="heading"){let{fontSize:F}=Q7(N.depth);return`700 ${F}px "Iowan Old Style", "Palatino Linotype", serif`}switch(N?.type){case"code":return"15px ui-monospace, SFMono-Regular, Menlo, monospace";default:return'16px "Iowan Old Style", "Palatino Linotype", serif'}}function _1(N,F){if(N?.type==="heading")return Q7(N.depth).lineHeight;if(N?.type==="code")return 22;return F}function Q7(N){return $7[N-1]??$7.at(-1)}function y2(N,F,M,A,D,E,$){let Y=`${X6(F,$)}:${D}:${E}:${M}`,Z=N.measuredLines.get(Y);if(Z)return Z;let X=EX(N,F,M,A,D,E,$);return _M(N,Y,X)}function Z6(N,F,M,A,D,E,$,Y){let Z=`${X6(F,Y)}:${M}:${A}:${E}:${$}`,X=N.lineBoundaries.get(Z);if(X)return X;let Q=K7();if(!Q)return Z7(D);let K=[{left:0,offset:0}],J=0,q=F.inlines.filter((U)=>U.end>M&&U.start<A);if(q.length===0)return Z7(D);for(let U of q){let V=Math.max(M,U.start),G=Math.min(A,U.end),_=F.text.slice(V,G),w=V-M;if(U.kind==="image"){let L=VN(U,Y,$).width;J+=L,w+=_.length,K.push({left:J,offset:w});continue}Q.font=J7(E,U.marks);for(let L of Array.from(_))J+=q7(N,Q,L),w+=L.length,K.push({left:J,offset:w})}return HM(N,Z,K)}function DX(N,F,M,A){let D=`${M}::${A}::${F}`,E=N.preparedText.get(D);if(E)return E;let $=A7(F,M,{whiteSpace:A});return zM(N,D,$)}function EX(N,F,M,A,D,E,$){let Y=F.text;if(Y.length===0)return[{end:0,height:E,start:0,text:"",width:0}];if(QX(F))return YX(N,F,M,D,E,$);try{let Z=DX(N,Y,M,VX(A));return D7(Z,D,E).lines.map((Q)=>({end:Y7(Z.segments,Q.end),height:E,start:Y7(Z.segments,Q.start),text:Q.text,width:Q.width}))}catch{return $X(Y,D,E)}}function Y7(N,F){let M=0;for(let E=0;E<F.segmentIndex;E+=1)M+=N[E]?.length??0;let A=N[F.segmentIndex]??"",D=Array.from(A);for(let E=0;E<F.graphemeIndex;E+=1)M+=D[E]?.length??0;return M}function Z7(N){let F=[{left:0,offset:0}],M=0,A=0;for(let D of Array.from(N))M+=9,A+=D.length,F.push({left:M,offset:A});return F}function $X(N,F,M){let A=Math.max(1,Math.floor(F/9)),D=GX(N,A),E=0;return D.map(($)=>{let Y=E,Z=Y+$.length;return E=Z,{end:Z,height:M,start:Y,text:$,width:$.length*9}})}function YX(N,F,M,A,D,E){let $=XX(N,K7(),F,M,A,D,E);if($.length===0)return[{end:0,height:D,start:0,text:"",width:0}];return ZX($,F.text,A,D)}function ZX(N,F,M,A){let D=[],E=0;while(E<N.length){let Y=N[E].start;if(N[E].text===`
|
|
20
|
+
`){D.push({end:Y,height:A,start:Y,text:"",width:0}),E+=1;continue}let Z=0,X=0,Q=E,K=-1,J=A;while(Q<N.length){let U=N[Q];if(U.text===`
|
|
21
|
+
`)break;let V=Z+U.width;if(V>M&&Q>E)break;if(Z=V,J=Math.max(J,U.height),U.breakable)K=Q,X=Z;Q+=1}if(Q===N.length||N[Q]?.text===`
|
|
22
|
+
`){let U=N[Q-1]?.end??Y;D.push({end:U,height:J,start:Y,text:F.slice(Y,U),width:Z}),E=Q<N.length&&N[Q]?.text===`
|
|
23
|
+
`?Q+1:Q;continue}if(K>=E){let U=N[K].end;D.push({end:U,height:J,start:Y,text:F.slice(Y,U),width:X}),E=K+1;continue}let q=N[Math.max(E,Q-1)].end;D.push({end:q,height:J,start:Y,text:F.slice(Y,q),width:Z}),E=Math.max(E+1,Q)}let $=N.at(-1);if($?.text===`
|
|
24
|
+
`)D.push({end:$.end,height:A,start:$.end,text:"",width:0});return D}function XX(N,F,M,A,D,E,$){let Y=[];for(let Z of M.inlines){if(Z.kind==="image"){let Q=VN(Z,$,D);Y.push({breakable:!0,end:Z.end,height:Q.height,start:Z.start,text:Z.text,width:Q.width});continue}if(F)F.font=J7(A,Z.marks);let X=Z.start;for(let Q of Array.from(Z.text)){let K=X,J=K+Q.length;Y.push({breakable:/\s/.test(Q),end:J,height:E,start:K,text:Q,width:Q===`
|
|
25
|
+
`?0:q7(N,F,Q)}),X=J}}return Y}function QX(N){return N.inlines.some((F)=>F.kind==="image"||F.kind==="lineBreak"||UX(F))}var X7=new WeakMap;function X6(N,F){let M=X7.get(N.inlines);if(M&&M.path===N.path&&M.text===N.text)return M.identity;let A=[N.path,qX(N.text),JX(N,F)].join(":");if(!N.inlines.some((D)=>D.kind==="image"))X7.set(N.inlines,{identity:A,path:N.path,text:N.text});return A}function JX(N,F){return N.inlines.map((M)=>`${M.start}-${M.end}:${KX(M,F)}`).join("|")}function KX(N,F){if(N.kind==="image"&&N.image)return E7(N,F);return`${N.kind}:${N.inlineCode?1:0}:${N.marks.join(",")}:${N.link?.url??""}`}function qX(N){let F=2166136261;for(let M of N)F^=M.charCodeAt(0),F=Math.imul(F,16777619);return(F>>>0).toString(36)}function UX(N){return N.marks.includes("italic")||N.marks.includes("bold")}function J7(N,F){let M=[];if(F.includes("italic"))M.push("italic");if(F.includes("bold"))M.push("700");return M.length>0?`${M.join(" ")} ${N}`:N}function K7(){if(Y6!==void 0)return Y6;return Y6=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):typeof document<"u"?document.createElement("canvas"):null)?.getContext("2d")??null,Y6}function q7(N,F,M){if(!F)return 9;let A=F.font,D=WM(N,A),E=D.get(M);if(E!==void 0)return E;let $=F.measureText(M).width;return D.set(M,$),$}function VX(N){return N?.type==="code"?"pre-wrap":"normal"}function GX(N,F){if(N.length===0)return[""];let M=N.split(`
|
|
26
|
+
`),A=[];for(let D of M){if(D.length===0){A.push("");continue}let E=D;while(E.length>F){let $=E.slice(0,F),Y=$.lastIndexOf(" ");if(Y<=0){A.push($),E=E.slice(F);continue}A.push($.slice(0,Y)),E=E.slice(Y+1)}A.push(E)}return A}var GN=10,O2=8,R4=120;function U7(N,F,M,A,D,E,$,Y,Z,X){let Q=Math.max(1,...E.rows.map((V)=>V.cells.length)),J=Math.max(R4,Z.width-$-Z.paddingX)/Q,q=zX(A),U=Y;for(let V=0;V<E.rows.length;V+=1){let G=_X(q.get(V)??[],D,E,J,GN,Z.lineHeight,X),_=Math.max(Z.lineHeight+O2*2,...G.map((w)=>w.measuredLines.reduce((L,m)=>L+m.height,0)+O2*2));for(let w of G){let L=$+w.cellIndex*J,m=U+O2;for(let W of w.measuredLines){let H={blockId:w.container.blockId,boundaries:Z6(D,w.container,W.start,W.end,W.text,w.font,J-GN*2,X),regionId:w.container.id,end:W.end,font:w.font,height:W.height,left:L+GN,start:W.start,text:W.text,top:m,width:W.width};N.push(H),b4(F,H),m+=W.height}M.set(w.container.id,{bottom:U+_,left:L,right:L+J,top:U})}HX(F,E.id,U,U+_),U+=_}return U}function zX(N){let F=new Map;for(let M of N){let A=M.tableCellPosition;if(!A)continue;let D=F.get(A.rowIndex)??[];D.push({cellIndex:A.cellIndex,container:M}),F.set(A.rowIndex,D)}return F}function _X(N,F,M,A,D,E,$){return[...N].sort((Y,Z)=>Y.cellIndex-Z.cellIndex).map(({cellIndex:Y,container:Z})=>{let X=W2(M),Q=_1(M,E),K=y2(F,Z,X,M,Math.max(40,A-D*2),Q,$);return{cellIndex:Y,container:Z,font:X,lineHeight:Q,measuredLines:K}})}function HX(N,F,M,A){let D=N.get(F);N.set(F,{bottom:D?Math.max(D.bottom,A):A,top:D?Math.min(D.top,M):M})}function Q6(N){let F=N.charWidth??N6.charWidth,M=N.lineHeight??N6.lineHeight,A=Math.max(12,Math.floor(N.width/F)),D=N.text.split(`
|
|
27
|
+
`).reduce((E,$)=>E+Math.max(1,Math.ceil($.length/A)),0);return{estimatedHeight:D*M,lineCount:D,width:N.width}}function J6(N,F,M=p1(),A=null){let D=A??{images:new Map},E={...N6,...F},$=[],Y=new Map,Z=new Map(N.regions.map((G)=>[G.id,{textLength:G.text.length}])),X=N.blockIndex,Q=zN(N.document.blocks),K=new Map,J=new Set(N.regions.map((G)=>G.id)),q=E.paddingY,U=null;for(let G of N.blocks){let _=Q.get(G.id)??null;if(!_||U1(_))continue;let w=n0(G),L=G.regionIds.filter((B)=>J.has(B));if(!w&&L.length===0)continue;if(U!==null){q+=F6(X,Q,U,G.id,E.blockGap);let B=N.blockIndex.get(U);if(B&&!n0(B)){let j=K.get(U);if(j)j.bottom=Math.max(j.bottom,q)}}let m=G.depth,W=E.paddingX+m*E.indentWidth,H=Math.max(40,E.width-W-E.paddingX);if(w)q=BX(K,G.id,q,E);else if(_.type==="table"){let B=L.map((j)=>N.regionIndex.get(j)).filter((j)=>j!==void 0);q=U7($,K,Y,B,M,_,W,q,E,D)}else for(let B of L){let j=N.regionIndex.get(B);if(!j)continue;q=WX($,K,Y,j,M,_,W,q,H,E,D)}U=G.id}let V=[];for(let G of N.blocks){let _=Q.get(G.id);if(!_||U1(_))continue;let w=K.get(G.id);if(!w)continue;V.push({bottom:w.bottom,depth:G.depth,id:G.id,top:w.top,type:G.type})}return{blocks:V,regionBounds:Y,regionLineIndices:yX($),regionMetrics:Z,height:Math.max(q,E.paddingY),lines:$,options:E,width:E.width}}function BX(N,F,M,A){let D=A.lineHeight;return N.set(F,{top:M,bottom:M+D}),M+D}function WX(N,F,M,A,D,E,$,Y,Z,X,Q){let K=W2(E),J=_1(E,X.lineHeight),q=y2(D,A,K,E,Z,J,Q),U=Y;for(let V of q){let G={blockId:A.blockId,boundaries:Z6(D,A,V.start,V.end,V.text,K,Z,Q),regionId:A.id,end:V.end,font:K,height:V.height,left:$,start:V.start,text:V.text,top:U,width:V.width};N.push(G),b4(F,G),OX(M,G),U+=V.height}return U}function yX(N){let F=[...N].sort((A,D)=>A.top-D.top||A.left-D.left),M=new Map;N.length=0,N.push(...F);for(let[A,D]of N.entries()){let E=M.get(D.regionId)??[];E.push(A),M.set(D.regionId,E)}return M}function OX(N,F){let M=N.get(F.regionId),A=F.left+F.width,D=F.top+F.height;N.set(F.regionId,M?{bottom:Math.max(M.bottom,D),left:Math.min(M.left,F.left),right:Math.max(M.right,A),top:Math.min(M.top,F.top)}:{bottom:D,left:F.left,right:A,top:F.top})}function b4(N,F){let M=N.get(F.blockId),A=F.top+F.height;N.set(F.blockId,{bottom:M?Math.max(M.bottom,A):A,top:M?Math.min(M.top,F.top):F.top})}function zN(N){let F=new Map,M=(A)=>{for(let D of A)if(F.set(D.id,D),D.type==="blockquote"||D.type==="listItem")M(D.children);else if(D.type==="list")M(D.items)};return M(N),F}var K6=null;function PX(N){let F=/(\d+(?:\.\d+)?)\s*px/.exec(N);return F?Number.parseFloat(F[1]):16}function H1(N){K6??=new Map;let F=K6.get(N);if(F)return F;let M=G7(),A=Math.max(12,Math.round(PX(N)));if(!M){let J={ascent:Math.round(A*0.8),descent:Math.max(2,A-Math.round(A*0.8)),emHeight:A};return K6.set(N,J),J}M.font=N;let D=M.measureText("Hg"),E=Math.round(D.actualBoundingBoxAscent||0),$=Math.round(D.actualBoundingBoxDescent||0),Y=E+$,Z=Math.max(A,Y),X=Y>0?E:Math.round(Z*0.8),Q=Y>0?$:Math.max(2,Z-X),K={ascent:X,descent:Q,emHeight:Z};return K6.set(N,K),K}function _N(N,F){let{emHeight:M}=H1(F);return Math.max(0,Math.floor((N-M)/2))}function HN(N,F){let{ascent:M}=H1(F);return _N(N,F)+M}var q6;function V7(N,F){let M=G7();if(!M||N.length===0)return 0;return M.font=F,M.measureText(N).width}function G7(){if(q6!==void 0)return q6;return q6=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):typeof document<"u"?document.createElement("canvas"):null)?.getContext("2d")??null,q6}function B7(N,F){let M=0,A=N.lines.length-1;while(M<=A){let D=M+A>>1,E=N.lines[D];if(F<E.top){A=D-1;continue}if(F>=E.top+E.height){M=D+1;continue}return{index:D,line:E}}return null}function U6(N,F){let M=[...N.regionBounds.entries()].find(([,E])=>{return F.x>=E.left&&F.x<=E.right&&F.y>=E.top&&F.y<=E.bottom});if(M)return BN(N,M[0],F.y);let A=B7(N,F.y);if(!A)return null;let D=TX(N,F.y,A.index);if(D.length===1)return D[0]??null;return D.find((E)=>{let $=N.regionBounds.get(E.line.regionId);return $?F.x>=$.left&&F.x<=$.right:!1})??[...D].sort((E,$)=>{let Y=N.regionBounds.get(E.line.regionId),Z=N.regionBounds.get($.line.regionId),X=_7(F.x,Y),Q=_7(F.x,Z);return X-Q})[0]??null}function V6(N,F,M){if(N.blocks.length===0)return{endIndex:0,startIndex:0};let A=F+M,D=z7(N,F),E=z7(N,A);if(D>0){if(N.blocks[D-1].bottom>F)D-=1}if(E<N.blocks.length){if(N.blocks[E].top<A)E+=1}return{endIndex:E,startIndex:D}}function z7(N,F){let M=0,A=N.blocks.length;while(M<A){let D=M+A>>1;if(N.blocks[D].bottom<=F)M=D+1;else A=D}return M}function G6(N,F,M){if(N.lines.length===0)return{endIndex:0,startIndex:0};let A=F+M,D=H7(N,F),E=H7(N,A);if(D>0){let $=N.lines[D-1];if($.top+$.height>F)D-=1}if(E<N.lines.length){if(N.lines[E].top<A)E+=1}return{endIndex:E,startIndex:D}}function p0(N,F,M){return P2(N,F,M)?.line??null}function BN(N,F,M){let A=N.regionLineIndices.get(F);if(!A||A.length===0)return null;let D=A[0],E=Number.POSITIVE_INFINITY;for(let $ of A){let Y=N.lines[$],Z=M<Y.top?Y.top-M:M>Y.top+Y.height?M-(Y.top+Y.height):0;if(Z<E)E=Z,D=$;if(Z===0)break}return{index:D,line:N.lines[D]}}function P2(N,F,M){let A=N.regionLineIndices.get(F);if(!A||A.length===0)return null;let D=0,E=A.length-1;while(D<=E){let Q=D+E>>1,K=A[Q],J=N.lines[K];if(M<J.start){E=Q-1;continue}if(M>J.end){D=Q+1;continue}return{index:K,line:J}}let $=A[0],Y=A[A.length-1],Z=N.lines[$],X=N.lines[Y];if(M<=Z.start)return{index:$,line:Z};if(M>=X.end)return{index:Y,line:X};return null}function TX(N,F,M){let A=[];for(let D=M;D>=0;D-=1){let E=N.lines[D];if(F<E.top||F>=E.top+E.height)break;A.unshift({index:D,line:E})}for(let D=M+1;D<N.lines.length;D+=1){let E=N.lines[D];if(F<E.top||F>=E.top+E.height)break;A.push({index:D,line:E})}return A}function _7(N,F){if(!F)return Number.POSITIVE_INFINITY;if(N<F.left)return F.left-N;if(N>F.right)return N-F.right;return 0}function _0(N,F){return N.left+LX(N.boundaries,F)}function LX(N,F){for(let A of N)if(A.offset===F)return A.left;return N.filter((A)=>A.offset<=F).at(-1)?.left??0}function H7(N,F){let M=0,A=N.lines.length;while(M<A){let D=M+A>>1,E=N.lines[D];if(E.top+E.height<=F)M=D+1;else A=D}return M}function v4(N,F){if(N.length===0)return 0;for(let M=1;M<N.length;M+=1){let A=N[M-1],D=N[M],E=A.left+(D.left-A.left)/2;if(F<=E)return A.offset;if(F<=D.left)return D.offset}return N.at(-1)?.offset??0}var wX=18,jX=14,CX=22;function E1(N,F,M){return _0(F,M)+T0(N,F)}function T0(N,F){let M=$1(N,F.blockId,"listItem");if(!M)return 0;return l1(N,M.id)?.kind==="task"?CX:wX}function x1(N){return{left:N.left,size:jX,top:N.top+3}}function $1(N,F,M){let A=N.documentIndex.blockIndex.get(F)??null;while(A){if(A.type===M)return A;let D=A.parentBlockId;A=D?N.documentIndex.blockIndex.get(D)??null:null}return null}function l1(N,F){return N.documentIndex.listItemMarkers.get(F)??null}function h0(N,F,M){if(!N.regionMetrics.get(M.regionId))return null;let D=p0(N,M.regionId,M.offset);if(!D)return null;return{blockId:D.blockId,regionId:D.regionId,height:D.height,left:_0(D,M.offset-D.start),offset:M.offset,top:D.top}}function x0(N,F,M){let A=p0(F,M.regionId,M.offset);if(!A)return M.left;return M.left+T0(N,A)+SX(N,A,M.offset)}function SX(N,F,M){if(M<=F.end)return 0;let A=N.documentIndex.regionIndex.get(F.regionId);if(!A)return 0;let D=A.text.slice(F.end,M);if(!/^[ \t]+$/u.test(D))return 0;return V7(D,F.font)}function O0(N,F,M){let A=RX(N,F,M);if(!A)return null;let D=A.snapToLineStart?A.line.left:M.x;return W7(N,F,A.line,D)}function z6(N,F,M){let A=N.lines[N.lines.length-1];if(!A||M.y<=A.top+A.height)return null;return W7(N,F,A,M.x)}function _6(N,F,M,A){let D=y7(F,A.regionId);if(!D)return null;let E=O0(N,F,M);if(E)return{regionId:E.regionId,offset:E.offset};let $=M.y<bX(N);return{regionId:A.regionId,offset:$?0:D.text.length}}function H6(N,F,M){let A=O0(N,F,M);if(!A)return null;let D=y7(F,A.regionId);if(!D||D.text.length===0)return null;let E=A.offset<D.text.length&&/\w/.test(D.text[A.offset]??"")?A.offset:A.offset>0&&/\w/.test(D.text[A.offset-1]??"")?A.offset-1:A.offset,$=vX(D.text,E);if($.start===$.end)return null;return{anchor:{regionId:A.regionId,offset:$.start},focus:{regionId:A.regionId,offset:$.end}}}function W7(N,F,M,A){let D=N.regionMetrics.get(M.regionId);if(!D)return null;let E=Math.max(0,A-T0(F,M)-M.left),$=v4(M.boundaries,E),Y=Math.min(D.textLength,M.start+$);return{regionId:M.regionId,offset:Y,left:_0(M,$),top:M.top,height:M.height}}function RX(N,F,M){for(let[D,E]of N.regionBounds)if(M.x>=E.left&&M.x<=E.right&&M.y>=E.top&&M.y<=E.bottom){let $=BN(N,D,M.y)?.line??null;return $?{line:$}:null}let A=U6(N,M)?.line??null;if(A)return{line:A};for(let D of N.blocks){if(M.y<D.top||M.y>D.bottom)continue;for(let $=N.lines.length-1;$>=0;$--)if(N.lines[$].blockId===D.id)return{line:N.lines[$]};let E=F.documentIndex.blockIndex.get(D.id);if(E&&n0(E)){let $=i2(F.documentIndex,D.id);if($){let Y=N.lines.find((Z)=>Z.blockId===$.id);if(Y)return{line:Y,snapToLineStart:!0}}}}return null}function y7(N,F){return N.documentIndex.regionIndex.get(F)??null}function bX(N){return N.lines[0]?.top??0}function vX(N,F){let M=F,A=F;while(M>0&&/\w/.test(N[M-1]??""))M-=1;while(A<N.length&&/\w/.test(N[A]??""))A+=1;return{end:A,start:M}}function f4(N,F,M){let A=fX(N,M);if(!A||A.start!==0)return null;let D=$1(F,A.blockId,"listItem");if(!D)return null;if(l1(F,D.id)?.kind!=="task")return null;let $=x1(A),Y=$.left-4,Z=$.left+$.size+4,X=$.top-4,Q=$.top+$.size+4;return M.x>=Y&&M.x<=Z&&M.y>=X&&M.y<=Q?{listItemId:D.id}:null}function m4(N,F,M){let A=O0(N,F,M);if(!A)return null;let D=mX(F,A.regionId);if(!D)return null;let E=D.inlines.find(($)=>$.link&&A.offset>=$.start&&A.offset<$.end);if(!E?.link)return null;return{endOffset:E.end,regionId:A.regionId,startOffset:E.start,title:E.link.title,url:E.link.url}}function B6(N,F,M,A){let D=f4(N,F,M);if(D)return{kind:"task-toggle",listItemId:D.listItemId};let E=O0(N,F,M);if(!E)return null;let $=O7(E.regionId,E.offset,A),Y=m4(N,F,M);if(Y)return{endOffset:Y.endOffset,kind:"link",commentThreadIndex:$,regionId:Y.regionId,startOffset:Y.startOffset,title:Y.title,url:Y.url};return{kind:"text",commentThreadIndex:$}}function W6(N,F,M,A){let D=F.documentIndex.regionIndex.get(M.regionId);if(!D)return null;let E=O7(M.regionId,M.offset,A),$=D.inlines.find((Y)=>M.offset>=Y.start&&M.offset<=Y.end)??null;if($?.link)return{commentThreadIndex:E,endOffset:$.end,kind:"link",regionId:M.regionId,startOffset:$.start,title:$.link.title,url:$.link.url};if(E!==null)return{commentThreadIndex:E,kind:"text"};return null}function WN(N,F,M,A){let D=N.documentIndex.regionIndex.get(N.selection.anchor.regionId);if(!A.image||!D)return null;let E=p0(F.layout,D.id,A.start);if(!E)return null;let $=E.left+T0(N,E),Y=$+_0(E,A.start-E.start)-E.left,Z=$+_0(E,A.end-E.start)-E.left,{height:X}=VN(A,M,E.width),Q=E.top+Math.max(0,Math.floor((E.height-X)/2));return{left:Y,top:Q,width:Z-Y,height:X}}function O7(N,F,M){for(let A of M)if(A.regionId===N&&F>=A.startOffset&&F<=A.endOffset)return A.threadIndex;return null}function fX(N,F){return N.lines.find((M)=>F.y>=M.top-4&&F.y<=M.top+M.height+4)??N.lines.filter((M)=>Math.abs(F.y-(M.top+M.height/2))<=10).sort((M,A)=>Math.abs(F.y-(M.top+M.height/2))-Math.abs(F.y-(A.top+A.height/2)))[0]??null}function mX(N,F){return N.documentIndex.regionIndex.get(F)??null}function P7(N,F,M,A,D,E){let $=k4(F,D,E),Y=N.measuredContainerHeights.get($);if(Y!==void 0)return Y;let Z=D.paddingX??0,X=D.indentWidth??24,Q=_1(M,D.lineHeight??24),K=Z+A*X,J=Math.max(40,D.width-K-Z);if(F.inlines.some((V)=>V.kind==="image")){let V=W2(M);return y2(N,F,V,M,J,Q,E).reduce((G,_)=>G+_.height,0)}let q=Q6({charWidth:D.charWidth,lineHeight:Q,text:F.text,width:J});return Math.max(Q,q.lineCount*Q)}function T7(N,F,M,A){let D=Q6({charWidth:A,lineHeight:M,text:N.text,width:F});return Math.max(M,D.lineCount*M)}function k4(N,F,M){return`${X6(N,M)}:${F.width}:${F.paddingX??0}:${F.indentWidth??24}:${F.lineHeight??24}`}function h4(N,F){let M=0,A=N.entries.length;while(M<A){let D=M+A>>1;if(N.entries[D].bottom<=F)M=D+1;else A=D}return M}function L7(N,F,M,A,D){let E=A,$=D;for(let Y=A;Y<D;Y+=1){let Z=N.regions[Y],X=F.get(Z.blockId);if(!X)continue;if(X.type==="table"){let Q=M.get(X.regionIds[0]??""),K=M.get(X.regionIds[X.regionIds.length-1]??"");if(Q!==void 0)E=Math.min(E,Q);if(K!==void 0)$=Math.max($,K+1)}}return{endIndex:$,startIndex:E}}function w7(N,F,M){return{...N,blocks:N.blocks.map((A)=>({...A,bottom:A.bottom+F,top:A.top+F})),regionBounds:new Map([...N.regionBounds.entries()].map(([A,D])=>[A,{bottom:D.bottom+F,left:D.left,right:D.right,top:D.top+F}])),height:M,lines:N.lines.map((A)=>({...A,top:A.top+F}))}}function j7(N,F,M,A,D){for(let[E,$]of M.regionBounds){let Y=$.bottom-$.top,Z=F.regionIndex.get(E);BM(N,k4(Z??{path:E,inlines:[],text:""},A,D),Y)}}function g4(N,F,M,A=[],D=p1(),E=null){let $=E??{images:new Map},Y=zN(N.document.blocks),Z=N.blockIndex,X=new Set(A),Q=Math.max(0,M.top-M.overscan),K=M.top+M.height+M.overscan,J=hX(D,N,Y,Z,F,$),q=h4(J,Q),U=h4(J,K);if(q>0){let L=J.entries[q-1];if(L&&L.bottom>Q)q-=1}if(U<J.entries.length){let L=J.entries[U];if(L&&L.top<K)U+=1}for(let L of X){let m=J.containerIndices.get(L);if(m===void 0)continue;q=Math.min(q,m),U=Math.max(U,m+1)}if(!Number.isFinite(q)||!Number.isFinite(U))return{estimateRegionBounds:J.estimateRegionBounds,layout:J6({...N,regions:[]},F,D,$),totalHeight:J.totalHeight,viewport:M};let V=L7(N,Z,J.containerIndices,q,U),G=J.entries[V.startIndex]?.top??F.paddingY??0,_=J6({...N,regions:N.regions.slice(V.startIndex,V.endIndex)},F,D,$),w=w7(_,G,J.totalHeight);return j7(D,N,w,F,$),{estimateRegionBounds:J.estimateRegionBounds,layout:w,totalHeight:J.totalHeight,viewport:M}}function hX(N,F,M,A,D,E){let $=uX(F,D,E),Y=yM(N,F,$);if(Y)return Y;let Z=D.blockGap??16,X=D.lineHeight??24,Q=D.paddingY??0,K=[],J=new Map,q=0,U=null;for(let V of F.blocks){let G=M.get(V.id)??null;if(!G||U1(G))continue;let _=n0(V);if(!_&&V.regionIds.length===0)continue;if(U!==null)Q+=F6(A,M,U,V.id,Z);if(_)Q+=X;else if(G.type==="table"){let w=gX({block:G,containerIndices:J,entries:K,index:q,options:D,runtimeBlocks:A,totalHeight:Q,regions:F.regions});if(w)q=w.nextIndex,Q=w.totalHeight}else for(let w of V.regionIds){let L=F.regions[q];if(!L){q+=1;continue}let m=P7(N,L,G,V.depth,D,E),W=Q,H=W+m;K[q]={bottom:H,top:W},J.set(L.id,q),Q=H,q+=1}U=V.id}return OM(N,F,$,{containerIndices:J,entries:K,estimateRegionBounds(V){let G=J.get(V);return G===void 0?null:K[G]??null},totalHeight:Q})}function gX({block:N,containerIndices:F,entries:M,index:A,options:D,runtimeBlocks:E,totalHeight:$,regions:Y}){let Z=E.get(N.id),X=Z?.regionIds??[];if(X.length===0)return null;let Q=Y.slice(A,A+X.length);if(Q.length===0||Q[0]?.blockId!==N.id)return null;let K=D.paddingX??0,J=D.indentWidth??24,q=Z?.depth??0,U=K+q*J,V=Math.max(R4,D.width-U-K),G=Math.max(1,...N.rows.map((H)=>H.cells.length)),_=V/G,w=Math.max(40,_-GN*2),L=_1(N,D.lineHeight??24),m=IX(Q,A),W=$;for(let H=0;H<N.rows.length;H+=1){let B=m.get(H)??[],j=Math.max(L+O2*2,...B.map(({region:O})=>T7(O,w,L,D.charWidth)+O2*2)),T=W+j;for(let{index:O,region:P}of B)M[O]={bottom:T,top:W},F.set(P.id,O);W=T}for(let H=A;H<A+Q.length;H+=1){let B=Y[H];if(!B||M[H])continue;M[H]={bottom:W,top:W},F.set(B.id,H)}return{nextIndex:A+Q.length,totalHeight:W}}function IX(N,F){let M=new Map;for(let[A,D]of N.entries()){let E=D.tableCellPosition?.rowIndex;if(E===void 0)continue;let $=M.get(E)??[];$.push({index:F+A,region:D}),M.set(E,$)}return M}function uX(N,F,M){return[F.width,F.paddingX??0,F.paddingY??0,F.indentWidth??24,F.lineHeight??24,F.blockGap??16,pX(N,M)].join(":")}function pX(N,F){if(N.imageUrls.size===0)return"";return N.regions.flatMap((M)=>M.inlines.filter((A)=>A.kind==="image"&&A.image).map((A)=>{let D=A.image?F.images.get(A.image.url):null;return`${A.image?.url??""}:${A.image?.width??0}:${D?.status??"loading"}:${D?.intrinsicWidth??0}:${D?.intrinsicHeight??0}`})).join("|")}function I4(N,F,M,A=null){let D={height:F.height,overscan:Math.max(160,F.height),top:F.top},E=g4(N.documentIndex,F,D,[N.selection.anchor.regionId,N.selection.focus.regionId],M,A);return{blockMap:zN(N.documentIndex.document.blocks),estimateRegionBounds:E.estimateRegionBounds,regionBounds:new Map(E.layout.regionBounds),layout:E.layout,paintHeight:Math.max(240,D.height+D.overscan*2),paintTop:Math.max(0,D.top-D.overscan),totalHeight:E.totalHeight,viewport:{height:D.height,top:D.top}}}function y6(N,F,M){return O0(F.layout,N,M)??z6(F.layout,N,M)}function yN(N,F,M,A){return _6(F.layout,N,M,A)}function u4(N,F,M){return H6(F.layout,N,M)}function p4(N,F,M,A){return B6(F.layout,N,M,A)}function x4(N,F,M,A){return W6(F.layout,N,M,A)}function l4(N,F,M){return h0(F.layout,N.documentIndex,M)}function B1(N,F,M){let A=h0(F.layout,N.documentIndex,M);if(!A)return null;return{...A,left:x0(N,F.layout,A)}}var C7=1;function S7(N,F,M){let A=N.documentIndex.regionOrderIndex.get(N.selection.focus.regionId);if(A===void 0)return N;let D=N.documentIndex.regions[A],E=N.selection.focus.offset+F;if(E>=0&&E<=D.text.length)return y0(N,D.id,E,M);if(F<0){let Y=g1(N.documentIndex,D.id);if(!Y)return N;return y0(N,Y.id,Y.text.length,M)}let $=s2(N.documentIndex,D.id);if(!$)return N;return y0(N,$.id,0,M)}function R7(N,F,M,A,D){let E=P2(F,M.regionId,M.offset);if(!E)return N;let $=F.lines[E.index+A];if(!$)return N;let Y=O0(F,N,{x:x0(N,F,M)+C7,y:$.top+$.height/2});if(!Y)return N;return y0(N,Y.regionId,Y.offset,D)}function b7(N,F,M,A){let D=f7(N,F);if(!D)return N;return y0(N,D.regionId,M==="Home"?D.start:D.end,A)}function v7(N,F,M,A,D){let E=f7(N,F);if(!E)return N;let Y=Math.max(1,Math.floor(480/F.options.lineHeight)),Z=P2(F,E.regionId,N.selection.focus.offset),X=Z?F.lines[Z.index+A*Y]:null;if(!X)return N;let Q=O0(F,N,{x:x0(N,F,M)+C7,y:X.top+X.height/2});if(!Q)return N;return y0(N,Q.regionId,Q.offset,D)}function f7(N,F){return p0(F,N.selection.focus.regionId,N.selection.focus.offset)}var xX=1;function m7(N,F,M,A,D){let E=N.documentIndex.regionIndex.get(N.selection.focus.regionId)??null;if(!E)return null;let $=N.documentIndex.tableCellIndex.get(E.id)??null,Y=N.documentIndex.blockIndex.get(E.blockId)??null;if(!$||Y?.type!=="table")return null;let Z=lX(N,Y.id,$.rowIndex+A,$.cellIndex)??dX(N,Y.id,A);if(!Z)return N;let X=F.regionBounds.get(E.id),Q=F.regionBounds.get(Z.id);if(!X||!Q)return N;let K=Q.top+cX(M.top+M.height/2-X.top,0,Math.max(0,Q.bottom-Q.top-1)),J=O0(F,N,{x:x0(N,F,M)+xX,y:K});if(!J)return N;return y0(N,J.regionId,J.offset,D)}function lX(N,F,M,A){return Q2(N.documentIndex,F,M,A)}function dX(N,F,M){let A=N.documentIndex.blockIndex.get(F),D=N.documentIndex.regions,E=A?N.documentIndex.roots[A.rootIndex]?.regionRange:void 0;if(!E)return null;return M<0?D[E.start-1]??null:D[E.end]??null}function cX(N,F,M){return Math.max(F,Math.min(M,N))}function d4(N,F,M=!1){return S7(N,F,M)}function c4(N,F,M,A=!1){return aX(N,F,M,A)}function a4(N,F,M,A=!1){return rX(N,F,M,A)}function r4(N,F,M,A=!1){return b7(N,F,M,A)}function s4(N,F,M=!1){return sX(N,F,M)}function aX(N,F,M,A){let D=k7(N,F);if(!D)return N;return m7(N,F,D,M,A)??R7(N,F,D,M,A)}function rX(N,F,M,A){let D=k7(N,F);if(!D)return N;return v7(N,F,D,M,A)}function sX(N,F,M){let A=N.documentIndex.regions,D=F==="start"?A[0]:A.at(-1);if(!D)return N;return y0(N,D.id,F==="start"?0:D.text.length,M)}function k7(N,F){return h0(F,N.documentIndex,{regionId:N.selection.focus.regionId,offset:N.selection.focus.offset})}var iX=80;function g7({context:N,containerBounds:F,isHeaderRow:M,lineHeight:A,theme:D}){let E=u7(F,A);N.fillStyle=M?D.tableHeaderBackground:D.tableBodyBackground,N.fillRect(E.left,E.top,E.width,E.height),p7(N,E,D)}function I7({activeBlockFlashes:N,activeBlockId:F,activeRegionId:M,context:A,editorState:D,endIndex:E,layout:$,regionBounds:Y,startIndex:Z,theme:X,verticalBleed:Q}){if(!F||!M)return;let K=D.documentIndex.blockIndex.get(F)??null;if(K?.type!=="table")return;if((D.documentIndex.regionIndex.get(M)??null)?.blockId!==F)return;let q=Y.get(M)??null,U=$.regionLineIndices.get(M)??null;if(!q||!U||U.length===0)return;let V=$.lines[U[0]]??null;if(!V)return;let G=u7(q,V.height);if(G.width===0)return;let _=h7({context:A,endIndex:E,fillStyle:X.activeBlockBackground,layout:$,left:G.left,lineIndices:U,startIndex:Z,verticalBleed:Q,width:G.width}),w=K.path?N.get(K.path)??null:null;if(w)h7({context:A,endIndex:E,fillStyle:mF(X.activeBlockFlash,w),layout:$,left:G.left,lineIndices:U,startIndex:Z,verticalBleed:Q,width:G.width});if(!_)return;p7(A,G,X)}function h7({context:N,endIndex:F,fillStyle:M,layout:A,left:D,lineIndices:E,startIndex:$,verticalBleed:Y,width:Z}){N.fillStyle=M;let X=!1;for(let Q of E){if(Q<$)continue;if(Q>=F)break;let K=A.lines[Q];N.fillRect(D,K.top-Y,Z,K.height),X=!0}return X}function u7(N,F){return{height:Math.max(N.bottom-N.top,F),left:N.left,top:N.top,width:Math.max(N.right-N.left,iX)}}function p7(N,F,M){N.strokeStyle=M.tableBorder,N.strokeRect(F.left,F.top,F.width,F.height)}var O6=2,oX=3,nX=12,tX=6,eX=3,NQ=8,FQ=12,MQ=28,AQ=4,x7=1,DQ=5,EQ=2,$Q=1;function l7(N,F,M,A,D,E,$){if(!A||F.start!==0)return;if(M?.type==="code"){let Y=Math.max(0,F.left-FQ);N.fillStyle=E.codeBackground,N.fillRect(Y,A.top-AQ,Math.max(A.right-F.left+MQ,$-Y),A.bottom-A.top+NQ);return}if(M?.type!=="table")return;g7({context:N,containerBounds:A,isHeaderRow:D?.rowIndex===0,lineHeight:F.height,theme:E})}function d7(N,F,M,A,D,E,$,Y){if(F.blockId!==D||M?.type==="table")return;let Z=A?E.get(A)??null:null;if(N.fillStyle=$.activeBlockBackground,N.fillRect(0,F.top-O6,Y,F.height),!Z)return;N.fillStyle=mF($.activeBlockFlash,Z),N.fillRect(0,F.top-O6,Y,F.height)}function c7(N,F,M,A,D,E){let $=new Map;for(let Y=A;Y<D;Y+=1){let Z=N.lines[Y],X=M.get(Z.blockId);if(X?.type!=="heading"||X.depth!==1&&X.depth!==2)continue;let Q=$.get(X.id),K={bottom:Z.top+Z.height,left:Z.left+T0(F,Z),right:E-N.options.paddingX};$.set(X.id,Q?{bottom:Math.max(Q.bottom,K.bottom),left:Q.left,right:Q.right}:K)}return $}function a7(N,F,M,A,D,E){for(let $=M;$<A;$+=1){let Y=F.blocks[$];if(Y.type==="divider"){let Z=F.options.paddingX+Y.depth*F.options.indentWidth,X=E-F.options.paddingX,Q=Math.round(Y.top+(Y.bottom-Y.top-x7)/2);s7(N,{color:D.dividerRule??D.headingRule,left:Z,right:X,thickness:x7,top:Q})}}}function r7(N,F,M){for(let A of F.values())s7(N,{color:M.headingRule,left:A.left,minimumWidth:EQ,right:A.right,thickness:$Q,top:A.bottom+DQ})}function s7(N,F){N.fillStyle=F.color,N.fillRect(F.left,F.top,Math.max(F.minimumWidth??0,F.right-F.left),F.thickness)}function i7(N,F,M,A,D){let E=new Map;for(let $=A;$<D;$+=1){let Y=N.lines[$],Z=$1(F,Y.blockId,"blockquote");if(!Z)continue;let X=E.get(Z.id),Q={bottom:Y.top+Y.height,isActive:Y.blockId===M,left:N.options.paddingX+(Z.depth+1)*N.options.indentWidth-10,top:Y.top};E.set(Z.id,X?{bottom:Math.max(X.bottom,Q.bottom),isActive:X.isActive||Q.isActive,left:X.left,top:Math.min(X.top,Q.top)}:Q)}return E}function o7(N,F,M){for(let A of F.values())N.fillStyle=A.isActive?M.blockquoteRuleActive:M.blockquoteRule,N.fillRect(A.left,A.top+oX,eX,Math.max(nX,A.bottom-A.top-tX))}var YQ=1,ZQ=2,XQ=2;function i4({context:N,devicePixelRatio:F,editorState:M,height:A,layout:D,normalizedSelection:E,presence:$,showCaret:Y,theme:Z,viewportTop:X,width:Q}){N.save(),N.scale(F,F),N.clearRect(0,0,Q,A);let K=E.start.regionId===E.end.regionId&&E.start.offset!==E.end.offset,J=Y&&!K;if(N.translate(0,-X),J)n7(N,M,D,{color:Z.caret,offset:M.selection.focus.offset,regionId:M.selection.focus.regionId});if($)for(let q of $){if(!q.cursorPoint)continue;n7(N,M,D,{color:q.color??Z.leafAccent,offset:q.cursorPoint.offset,regionId:q.cursorPoint.regionId})}N.restore()}function n7(N,F,M,A){let D=h0(M,F.documentIndex,{regionId:A.regionId,offset:A.offset});if(!D)return;let E=x0(F,M,D),$=QQ(M,D);N.fillStyle=A.color,N.fillRect(E,$.top,ZQ,$.height)}function QQ(N,F){let M=p0(N,F.regionId,F.offset),A=M?.font??'16px "Iowan Old Style", "Palatino Linotype", serif',{ascent:D,descent:E}=H1(A),$=Math.max(1,D+E),Y=Math.min(F.height-XQ,$),Z=M?Math.max(M.top,M.top+_N(M.height,A)-YQ):F.top+Math.max(0,Math.floor((F.height-Y)/2));return{height:Y,top:Z}}var t7=2,e7=8,JQ=3,KQ=1.5,qQ=2,T2={elbow:{x:6.5,y:10.5},end:{x:11.5,y:3.5},start:{x:3.5,y:7.5}};function NA(N,F,M,A,D,E,$=null){if(!M||F.start!==0)return;if($){let Y=k5($),Z=_Q(M,F,A,D,N);N.save(),N.translate(Z.x,Z.y),N.scale(Y,Y),N.translate(-Z.x,-Z.y)}if(M.kind==="task")UQ(N,F,M.checked,E,$);else if(N.fillStyle=$?t2(E.listMarkerText,$,E):E.listMarkerText,M.kind==="ordered")zQ(N,M.label,A,D);else N.fillText(M.label,F.left-t7,D);if($)N.restore()}function UQ(N,F,M,A,D=null){let E=x1(F);if(VQ(N,E,M,A,D),!M)return;GQ(N,E,A,D)}function VQ(N,F,M,A,D=null){let E=M?A.checkboxCheckedFill:A.checkboxUncheckedFill,$=M?A.checkboxCheckedStroke:A.checkboxUncheckedStroke;N.fillStyle=D?t2(E,D,A):E,N.strokeStyle=D?t2($,D,A):$,N.beginPath(),N.lineWidth=KQ,N.roundRect(F.left,F.top,F.size,F.size,JQ),N.fill(),N.stroke()}function GQ(N,F,M,A=null){N.strokeStyle=A?t2(M.checkboxCheckmark,A,M):M.checkboxCheckmark,N.lineWidth=qQ,N.beginPath(),N.moveTo(F.left+T2.start.x,F.top+T2.start.y),N.lineTo(F.left+T2.elbow.x,F.top+T2.elbow.y),N.lineTo(F.left+T2.end.x,F.top+T2.end.y),N.stroke()}function zQ(N,F,M,A){let D=N.textAlign;N.textAlign="right",N.fillText(F,M-e7,A),N.textAlign=D}function _Q(N,F,M,A,D){if(N.kind==="task"){let Y=x1(F);return{x:Y.left+Y.size/2,y:Y.top+Y.size/2}}let E=D.measureText(N.label),$=A-(E.actualBoundingBoxAscent-E.actualBoundingBoxDescent)/2;if(N.kind==="ordered")return{x:M-e7-E.width/2,y:$};return{x:F.left-t7+E.width/2,y:$}}var HQ=2,BQ=1,WQ=2,yQ=5,OQ=2,PQ=3;function FA(N,F){let M=N.documentIndex.regionOrderIndex,A=M.get(F.start.regionId),D=M.get(F.end.regionId);return A===void 0||D===void 0?null:{end:D,start:A}}function MA(N,F,M,A,D,E){if(!D)return;let $=F.documentIndex.regionOrderIndex.get(M.regionId);if($===void 0||$<D.start||$>D.end)return;let Y=$===D.start?Math.max(M.start,A.start.offset):M.start,Z=$===D.end?Math.min(M.end,A.end.offset):M.end;if(Z<=Y)return;N.fillStyle=E.selectionBackground,N.fillRect(E1(F,M,Y-M.start),M.top+BQ,Math.max(HQ,E1(F,M,Z-M.start)-E1(F,M,Y-M.start)),M.height-WQ)}function AA(N,F,M,A,D,E){for(let $ of A){if($.regionId!==M.regionId)continue;let Y=Math.max($.startOffset,M.start),Z=Math.min($.endOffset,M.end);if(Z<=Y)continue;N.fillStyle=TQ($,D,E),N.fillRect(E1(F,M,Y-M.start),M.top+M.height-yQ,Math.max(OQ,E1(F,M,Z-M.start)-E1(F,M,Y-M.start)),PQ)}}function TQ(N,F,M){if(N.resolved)return N.threadIndex===F?M.commentHighlightResolvedActive:M.commentHighlightResolved;return N.threadIndex===F?M.commentHighlightActive:M.commentHighlight}function EA(N,F,M,A,D,E,$){let Y=M.image?A.images.get(M.image.url):null,Z=jQ(M,A,$),X=CQ(F,E,$,Z);if(N.fillStyle=D.imageSurfaceBackground,N.fillRect(X.left,X.top,X.width,X.height),Y?.status==="loaded"&&Y.source)N.drawImage(Y.source,X.left,X.top,X.width,X.height);else LQ(N,D,{...X,status:Y?.status==="error"?"error":"loading"});N.strokeStyle=D.imageSurfaceBorder,N.strokeRect(X.left,X.top,X.width,X.height)}function LQ(N,F,M){let A=M.status==="loading"?"Loading image":"Image unavailable",D=SQ(M),E=M.top+M.height/2+D.size*0.9;if(N.save(),N.beginPath(),N.rect(M.left,M.top,M.width,M.height),N.clip(),M.status==="loading")wQ(N,F,M);N.strokeStyle=F.imagePlaceholderIcon,N.lineWidth=1.5,N.strokeRect(D.left,D.top,D.size,D.size),N.beginPath(),N.arc(D.left+D.size*0.28,D.top+D.size*0.3,D.size*0.1,0,Math.PI*2),N.moveTo(D.left+D.size*0.12,D.top+D.size*0.82),N.lineTo(D.left+D.size*0.42,D.top+D.size*0.5),N.lineTo(D.left+D.size*0.58,D.top+D.size*0.66),N.lineTo(D.left+D.size*0.78,D.top+D.size*0.38),N.lineTo(D.left+D.size*0.88,D.top+D.size*0.82),N.stroke(),N.font='500 12px "Iowan Old Style", "Palatino Linotype", serif',N.fillStyle=F.imagePlaceholderText,N.textAlign="center",N.textBaseline="middle",N.fillText(A,M.left+M.width/2,E),N.restore()}function wQ(N,F,M){let A=Math.max(48,Math.round(M.width*0.22)),D=M.width+A*2,E=performance.now()%1800/1800,$=M.left-A+D*E,Y=N.createLinearGradient($,M.top,$+A,M.top);Y.addColorStop(0,"rgba(255,255,255,0)"),Y.addColorStop(0.5,F.imageLoadingOverlay),Y.addColorStop(1,"rgba(255,255,255,0)"),N.fillStyle=Y,N.fillRect(M.left,M.top,M.width,M.height)}function jQ(N,F,M){if(!N.image)return DA(M);let A=F.images.get(N.image.url);if(!A||A.intrinsicWidth<=0||A.intrinsicHeight<=0)return DA(M);return Math.max(48,Math.round(M*(A.intrinsicHeight/A.intrinsicWidth)))}function CQ(N,F,M,A){return{height:A,left:F,top:N.top+Math.max(0,Math.floor((N.height-A)/2)),width:M}}function SQ(N){let F=Math.max(18,Math.min(34,Math.round(Math.min(N.width,N.height)*0.18)));return{left:N.left+Math.max(12,Math.round((N.width-F)/2)),size:F,top:N.top+Math.max(12,Math.round(N.height/2-F*0.95))}}function DA(N){return Math.max(48,Math.round(N*0.5625))}var RQ=6,$A=3,bQ=12,vQ=10,fQ=2,YA=4,mQ=4,kQ=1.5,ZA=2,XA=1.25;function JA(N,F,M,A,D,E,$,Y,Z){if(!M){N.fillStyle=$,N.fillText(F.text,A,D);return}let X=M.inlines.filter((Q)=>Q.end>F.start&&Q.start<F.end);if(X.length===0){N.fillStyle=$,N.fillText(F.text,A,D);return}for(let Q of X){let K=Math.max(F.start,Q.start),J=Math.min(F.end,Q.end);if(M.text.slice(K,J).length===0)continue;let{left:U,right:V}=o4(F,A,K,J),G=uQ(F.font,Q.marks);if(N.font=G,Q.kind==="image"){let _=Math.max(24,V-U);EA(N,F,Q,Y,Z,U,_);continue}if(Q.kind==="code"){hQ(N,F,G,Z,U,V),QA(N,F,M.text,A,D,K,J,Z.inlineCodeText,E,Z,{strikethrough:!1,underline:!1});continue}QA(N,F,M.text,A,D,K,J,Q.link?Z.linkText:$,E,Z,{strikethrough:Q.marks.includes("strikethrough"),underline:Q.marks.includes("underline")||Boolean(Q.link)})}}function QA(N,F,M,A,D,E,$,Y,Z,X,Q){let K=R5(E,$,Z);for(let J=0;J<K.length-1;J+=1){let q=K[J],U=K[J+1];if(U<=q)continue;let V=M.slice(q,U);if(V.length===0)continue;let{left:G,right:_}=o4(F,A,q,U),w=b5(Z,q,U),L=v5(Y,w,X);if(N.fillStyle=L,N.fillText(V,G,D),Q.strikethrough)N.fillRect(G,gQ(D,F.height,N.font),Math.max(ZA,_-G),XA);if(Q.underline)N.fillRect(G,IQ(D,F.height,N.font),Math.max(ZA,_-G),XA)}}function KA(N,F,M,A,D,E,$){if(!M||E.length===0)return;for(let Y of E){if(Y.startOffset<F.start||Y.startOffset>F.end)continue;let Z=A+(_0(F,Y.startOffset-F.start)-F.left);N.fillStyle=f5($,Y),N.fillText(Y.text,Z,D)}}function qA(N,F,M,A,D,E,$){if(!M||E.length===0)return;for(let Y of E){if(Y.offset<F.start||Y.offset>=F.end)continue;let{left:Z,right:X}=o4(F,A,Y.offset,Y.offset+1),Q=Math.max(YA,(X-Z)/2+YA+mQ*Y.progress),{ascent:K,descent:J}=H1(F.font),q=D-Math.max(1,K*0.42)+Math.max(0.5,J*0.15);N.strokeStyle=m5(Y,$),N.lineWidth=kQ,N.beginPath(),N.arc((Z+X)/2,q,Q,0,Math.PI*2),N.stroke()}}function hQ(N,F,M,A,D,E){let $=_N(F.height,M),Y=F.top+$+fQ,Z=Math.max(bQ,F.height-$-RQ);N.fillStyle=A.inlineCodeBackground,N.fillRect(D-$A,Y,Math.max(vQ,E-D+$A*2),Z)}function gQ(N,F,M){let{ascent:A}=H1(M),D=N-HN(F,M);return Math.max(D+2,N-Math.round(A*0.32))}function IQ(N,F,M){let{descent:A}=H1(M),D=Math.max(1,Math.round(Math.max(2,A)*0.35)),E=N+A-D,$=N-HN(F,M);return Math.min($+F-4,E)}function uQ(N,F){let M=[];if(F.includes("italic"))M.push("italic");if(F.includes("bold"))M.push("700");return M.length>0?`${M.join(" ")} ${N}`:N}function o4(N,F,M,A){return{left:F+(_0(N,M-N.start)-N.left),right:F+(_0(N,A-N.start)-N.left)}}function n4(N,F,M,A){pQ({activeBlockId:A.activeBlockId,activeRegionId:A.activeRegionId,activeThreadIndex:A.activeThreadIndex,containerLineBounds:F.regionBounds,context:M,devicePixelRatio:A.devicePixelRatio,editorState:N,height:A.height,layout:F.layout,liveCommentRanges:A.liveCommentRanges,normalizedSelection:A.normalizedSelection,now:A.now,resources:A.resources??{images:new Map},runtimeBlockMap:F.blockMap,theme:A.theme,viewportTop:F.paintTop,width:A.width})}function t4(N,F,M,A){i4({context:M,devicePixelRatio:A.devicePixelRatio,editorState:N,height:A.height,layout:F.layout,normalizedSelection:A.normalizedSelection,presence:A.presence,showCaret:A.showCaret,theme:A.theme,viewportTop:F.paintTop,width:A.width})}function pQ({activeBlockId:N,activeRegionId:F,activeThreadIndex:M,containerLineBounds:A,context:D,devicePixelRatio:E,editorState:$,height:Y,layout:Z,liveCommentRanges:X,normalizedSelection:Q,now:K=cQ(),resources:J,runtimeBlockMap:q,theme:U,viewportTop:V,width:G}){D.save(),D.scale(E,E),D.clearRect(0,0,G,Y),D.fillStyle=U.background,D.fillRect(0,0,G,Y),D.textBaseline="alphabetic",D.translate(0,-V);let{endIndex:_,startIndex:w}=G6(Z,V,Y),L=FA($,Q),m=w5($,K),W=j5($,K),H=L5($,K),B=S5($,K),j=C5($,K),T=i7(Z,$,N,w,_),O=c7(Z,$,q,w,_,G);for(let C=w;C<_;C+=1){let z=Z.lines[C];l7(D,z,q.get(z.blockId)??null,A.get(z.regionId)??null,$.documentIndex.tableCellIndex.get(z.regionId)??null,U,G)}let P=V6(Z,V,Y);a7(D,Z,P.startIndex,P.endIndex,U,G),I7({activeBlockFlashes:m,activeBlockId:N,activeRegionId:F,context:D,editorState:$,endIndex:_,layout:Z,regionBounds:A,startIndex:w,theme:U,verticalBleed:O6});for(let C=w;C<_;C+=1){let z=Z.lines[C];xQ({activeBlockId:N,activeBlockFlashes:m,activeDeletedTextFades:W,activeInsertedTextHighlights:H,activeListMarkerPops:B,activePunctuationPulses:j,activeThreadIndex:M,context:D,editorState:$,line:z,liveCommentRanges:X,normalizedSelection:Q,resources:J,runtimeBlockMap:q,selectionRegionOrderRange:L,theme:U,width:G})}r7(D,O,U),o7(D,T,U),D.restore()}function xQ({activeBlockId:N,activeBlockFlashes:F,activeDeletedTextFades:M,activeInsertedTextHighlights:A,activeListMarkerPops:D,activePunctuationPulses:E,activeThreadIndex:$,context:Y,editorState:Z,line:X,liveCommentRanges:Q,normalizedSelection:K,resources:J,runtimeBlockMap:q,selectionRegionOrderRange:U,theme:V,width:G}){let _=q.get(X.blockId)??null,w=Z.documentIndex.blockIndex.get(X.blockId)?.path??null,L=Z.documentIndex.regionIndex.get(X.regionId)??null,m=L?.path??"",W=$1(Z,X.blockId,"listItem"),H=W?l1(Z,W.id):null,B=W?D.get(W.path)??null:null,j=X.left+T0(Z,X),T=lQ(X),O=_?.type==="code"?V.codeText:dQ(_,V);Y.font=X.font,d7(Y,X,_,w,N,F,V,G),MA(Y,Z,X,K,U,V),AA(Y,Z,X,Q,$,V),NA(Y,X,H,j,T,V,B),JA(Y,X,L,j,T,A.get(m)??[],O,J,V),KA(Y,X,L,j,T,M.get(m)??[],O),qA(Y,X,L,j,T,E.get(m)??[],V)}function lQ(N){return N.top+HN(N.height,N.font)}function dQ(N,F){switch(N?.type){case"heading":return F.headingText;case"blockquote":return F.blockquoteText;case"table":return F.headingText;default:return F.paragraphText}}function cQ(){return typeof performance<"u"?performance.now():Date.now()}import{forwardRef as oQ,createElement as nQ}from"react";var P6=(...N)=>N.filter((F,M,A)=>{return Boolean(F)&&F.trim()!==""&&A.indexOf(F)===M}).join(" ").trim();var UA=(N)=>N.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var VA=(N)=>N.replace(/^([A-Z])|[\s-_]+(\w)/g,(F,M,A)=>A?A.toUpperCase():M.toLowerCase());var e4=(N)=>{let F=VA(N);return F.charAt(0).toUpperCase()+F.slice(1)};import{forwardRef as iQ,createElement as _A}from"react";var T6={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 GA=(N)=>{for(let F in N)if(F.startsWith("aria-")||F==="role"||F==="title")return!0;return!1};import{createContext as aQ,useContext as rQ,useMemo as JW,createElement as KW}from"react";var sQ=aQ({});var zA=()=>rQ(sQ);var HA=iQ(({color:N,size:F,strokeWidth:M,absoluteStrokeWidth:A,className:D="",children:E,iconNode:$,...Y},Z)=>{let{size:X=24,strokeWidth:Q=2,absoluteStrokeWidth:K=!1,color:J="currentColor",className:q=""}=zA()??{},U=A??K?Number(M??Q)*24/Number(F??X):M??Q;return _A("svg",{ref:Z,...T6,width:F??X??T6.width,height:F??X??T6.height,stroke:N??J,strokeWidth:U,className:P6("lucide",q,D),...!E&&!GA(Y)&&{"aria-hidden":"true"},...Y},[...$.map(([V,G])=>_A(V,G)),...Array.isArray(E)?E:[E]])});var h=(N,F)=>{let M=oQ(({className:A,...D},E)=>nQ(HA,{ref:E,iconNode:F,className:P6(`lucide-${UA(e4(N))}`,`lucide-${N}`,A),...D}));return M.displayName=e4(N),M};var tQ=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],W1=h("columns-2",tQ);var eQ=[["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"}]],y1=h("rows-3",eQ);var NJ=[["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"}]],O1=h("send-horizontal",NJ);var FJ=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],ON=h("arrow-down",FJ);var MJ=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],PN=h("arrow-up",MJ);var AJ=[["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"}]],TN=h("bold",AJ);var DJ=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],d1=h("check",DJ);var EJ=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],LN=h("chevron-down",EJ);var $J=[["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"}]],wN=h("heading-1",$J);var YJ=[["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"}]],jN=h("heading-2",YJ);var ZJ=[["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"}]],CN=h("heading-3",ZJ);var XJ=[["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"}]],SN=h("heading-5",XJ);var QJ=[["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"}]],RN=h("heading-4",QJ);var JJ=[["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"}]],bN=h("heading-6",JJ);var KJ=[["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M6 20V4",key:"1w1bmo"}],["path",{d:"M18 20V4",key:"o2hl4u"}]],vN=h("heading",KJ);var qJ=[["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"}]],fN=h("italic",qJ);var UJ=[["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"}]],mN=h("list-ordered",UJ);var VJ=[["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"}]],kN=h("list-todo",VJ);var GJ=[["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"}]],hN=h("list",GJ);var zJ=[["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"}]],gN=h("message-square-plus",zJ);var _J=[["path",{d:"M5 12h14",key:"1ays0h"}]],IN=h("minus",_J);var HJ=[["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"}]],c1=h("pencil",HJ);var BJ=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],L2=h("plus",BJ);var WJ=[["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"}]],uN=h("strikethrough",WJ);var yJ=[["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"}]],P1=h("table-2",yJ);var OJ=[["path",{d:"M17 5H3",key:"1cn7zz"}],["path",{d:"M21 12H8",key:"scolzb"}],["path",{d:"M21 19H8",key:"13qgcb"}],["path",{d:"M3 12v7",key:"1ri8j3"}]],pN=h("text-quote",OJ);var PJ=[["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"}]],b0=h("trash-2",PJ);var TJ=[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4",key:"9kb039"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20",key:"nun2al"}]],xN=h("underline",TJ);var LJ=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],lN=h("x",LJ);import{jsx as w2,jsxs as SJ}from"react/jsx-runtime";function BA({insetX:N,insetY:F,onSelect:M,presence:A}){if(!A)return null;return w2("div",{"aria-label":"Presence",className:"documint-presence-indicators",style:{paddingRight:`${N}px`,top:`${F}px`},children:A.map((D)=>w2(wJ,{onSelect:()=>M(D),presence:D},D.id))})}function wJ({onSelect:N,presence:F}){let M=F.viewport,A=jJ(F),D=M?.status==="above"?PN:ON,E=M!==null&&M.status!=="unresolved",$=M?.status==="above"||M?.status==="below";return SJ("button",{"aria-label":CJ(F),className:"documint-presence-indicator","data-status":M?.status??"unresolved",disabled:!E,onClick:E?N:void 0,style:{"--documint-presence-color":F.color??"var(--documint-leaf-accent)"},type:"button",children:[w2("span",{className:"documint-presence-indicator-avatar",children:F.avatarUrl?w2("img",{alt:"","aria-hidden":"true",className:"documint-presence-indicator-image",draggable:!1,src:F.avatarUrl}):A}),$?w2("span",{className:"documint-presence-indicator-direction","aria-hidden":"true",children:w2(D,{className:"documint-presence-indicator-arrow",size:14,strokeWidth:2.3})}):null]})}function jJ(N){return WA(N).charAt(0).toLocaleUpperCase()}function CJ(N){let F=WA(N),M=N.viewport?.status??"unresolved";if(M==="above")return`${F} above viewport`;if(M==="below")return`${F} below viewport`;if(M==="unresolved")return`${F} unresolved`;return`${F} in viewport`}function WA(N){return(N.fullName??N.username).trim()||"Presence"}var x=`
|
|
28
|
+
`,j2="<ins>",dN="</ins>",C2=">",cN="```",L6=":::",w6="documint-comments";var rN="\\",C6="`",LA=":",aN=" ",F8="![",M8="[",wA="(",yA=")",OA=/[\p{L}\p{N}]/u,RJ=/[A-Za-z]/,bJ=/[-A-Za-z0-9_]/,j6=/\{width=([1-9]\d*)\}/y,vJ=/\\([\\`*_[\]{}()#+\-.!~|])/g,jA=/\\(.)/g,CA=[{delimiter:"**",mark:"bold",requireWordBoundary:!1},{delimiter:"~~",mark:"strikethrough",requireWordBoundary:!1},{delimiter:"*",mark:"italic",requireWordBoundary:!1},{delimiter:"_",mark:"italic",requireWordBoundary:!0}],fJ=new Set(CA.map((N)=>N.delimiter[0]));function sN(N){return S6(N,0,N.length,[])}function S6(N,F,M,A){let D=[],E=F,$=F;while(E<M){let Y=mJ(N,E,M,A);if(Y){let Z=Math.max($,E-(Y.trimLeading??0));PA(D,N.slice($,Z),A),D.push(...Y.nodes),E=Y.end,$=E;continue}if(N[E]===rN){E+=Math.min(2,M-E);continue}E+=1}return PA(D,N.slice($,M),A),Q0(D)}function mJ(N,F,M,A){let D=N[F];switch(D){case LA:return kJ(N,F,M);case"<":return uJ(N,F,M)??hJ(N,F,M,A)??gJ(N,F,M);case rN:return pJ(N,F,M);case x:return xJ(N,F);case C6:return lJ(N,F,M);case"!":return dJ(N,F,M);case M8:return cJ(N,F,M,A)}if(D!==void 0&&fJ.has(D))return rJ(N,F,M,A);return null}function kJ(N,F,M){if(N[F]!==LA||!RJ.test(N[F+1]??""))return null;let A=F+2;while(A<M&&bJ.test(N[A]??""))A+=1;let D=TA(N,A,M,"[","]"),$=TA(N,D?.end??A,M,"{","}")?.end??D?.end??A;return{end:$,nodes:[vA("textDirective",N.slice(F,$))]}}function hJ(N,F,M,A){if(!N.startsWith(j2,F))return null;let D=N.indexOf(dN,F+j2.length);if(D<0||D>=M)return null;return{end:D+dN.length,nodes:S6(N,F+j2.length,D,[...A,"underline"])}}function gJ(N,F,M){if(N[F]!=="<")return null;let A=N.indexOf(">",F+1);if(A<0||A>=M)return null;return{end:A+1,nodes:[vA("html",N.slice(F,A+1))]}}var IJ=/^<br\s*\/?>/i;function uJ(N,F,M){if(N[F]!=="<")return null;let A=IJ.exec(N.slice(F,M));if(!A)return null;let D=F+A[0].length;return{end:N[D]===x?D+1:D,nodes:[a0()]}}function pJ(N,F,M){if(N[F]!==rN||N[F+1]!==x||F+1>=M)return null;return{end:F+2,nodes:[a0()]}}function xJ(N,F){if(N[F]!==x||N[F-1]!==aN||N[F-2]!==aN)return null;let M=0;while(N[F-1-M]===aN)M+=1;return{end:F+1,nodes:[a0()],trimLeading:M}}function lJ(N,F,M){if(N[F]!==C6)return null;let A=1;while(F+A<M&&N[F+A]===C6)A+=1;let D=C6.repeat(A),E=N.indexOf(D,F+A);if(E<0||E>=M)return null;return{end:E+A,nodes:[K1({code:N.slice(F+A,E)})]}}function dJ(N,F,M){if(!N.startsWith(F8,F))return null;let A=RA(N,F+1,M);if(A<0||N[A+1]!==wA)return null;let D=SA(N,A+1,M);if(!D)return null;let E=aJ(N,D.end,M);return{end:E?.end??D.end,nodes:[S1({alt:bA(N.slice(F+F8.length,A)),title:D.title,url:D.url,width:E?.width??null})]}}function cJ(N,F,M,A){if(N[F]!==M8||N.startsWith(F8,F-1))return null;let D=RA(N,F,M);if(D<0||N[D+1]!==wA)return null;let E=SA(N,D+1,M);if(!E)return null;return{end:E.end,nodes:[C1({children:S6(N,F+M8.length,D,A),title:E.title,url:E.url})]}}function SA(N,F,M){let A=N8(N,F+1,M),D=A;while(D<M&&N[D]!==yA&&N[D]!==aN){if(N[D]===rN){D+=2;continue}D+=1}if(D===A)return null;let E=sJ(N.slice(A,D));A=N8(N,D,M);let $=null;if(A<M&&N[A]==='"'){let Y=R6(N,'"',A+1,M);if(Y<0)return null;$=N.slice(A+1,Y).replace(jA,"$1"),A=N8(N,Y+1,M)}if(N[A]!==yA)return null;return{end:A+1,title:$,url:E}}function aJ(N,F,M){j6.lastIndex=F;let A=j6.exec(N);if(!A||j6.lastIndex>M)return null;return{end:j6.lastIndex,width:Number(A[1])}}function rJ(N,F,M,A){for(let D of CA){if(!N.startsWith(D.delimiter,F))continue;let E=R6(N,D.delimiter,F+D.delimiter.length,M);if(E<0)continue;if(D.requireWordBoundary){let Y=F>0?N[F-1]:"",Z=N[E+D.delimiter.length]??"";if(OA.test(Y)||OA.test(Z))continue}let $=F+D.delimiter.length;return{end:E+D.delimiter.length,nodes:S6(N,$,E,[...A,D.mark])}}return null}function PA(N,F,M){if(F.length===0)return;N.push(w0({marks:M,text:bA(F)}))}function TA(N,F,M,A,D){if(N[F]!==A)return null;let E=R6(N,D,F+1,M);if(E<0)return null;return{end:E+1}}function RA(N,F,M){return R6(N,"]",F+1,M)}function R6(N,F,M,A){for(let D=M;D<A;D+=1){if(N[D]===rN){D+=1;continue}if(N.startsWith(F,D))return D}return-1}function N8(N,F,M){while(F<M&&N[F]===aN)F+=1;return F}function bA(N){return N.replace(vJ,"$1")}function sJ(N){return N.replace(jA,"$1")}function vA(N,F){return GF({originalType:N,source:F})}var iJ=/^:?-+:?$/;function mA(N,F){let M=Z0(N),A=D8(N,1),D=H0(M,F),E=H0(A,F);if(!fA(D)||!A8(E))return null;let $=[b6(D)],Y=oJ(E);N.index+=2;while(N.index<N.lines.length){let Z=Z0(N),X=H0(Z,F);if(T1(Z)||!fA(X))break;$.push(b6(X)),N.index+=1}return v1({align:Y,rows:$.map((Z)=>e1({cells:Z.map((X)=>q1({children:sN(X)}))}))})}function A8(N){let F=b6(N);return F.length>0&&F.every((M)=>iJ.test(M.trim()))}function fA(N){let F=N.trim();return F.startsWith("|")&&F.endsWith("|")}function oJ(N){return b6(N).map((F)=>{let M=F.trim();if(M.startsWith(":")&&M.endsWith(":"))return"center";if(M.startsWith(":"))return"left";if(M.endsWith(":"))return"right";return null})}function b6(N){let F=N.trim();if(!F.startsWith("|")||!F.endsWith("|"))return[];return F.slice(1,-1).split("|").map((M)=>M.trim())}var nJ=3,kA=/^(#{1,6})\s+(.*)$/,tJ=/\s+#+\s*$/u,eJ=/^(\s*)([-+*]|\d+\.)(?:\s+(.*)|\s*)$/,NK=/^\d+\.$/,FK=/^\[( |x|X)\](?:\s|$)/,hA=/^```([^\s`]*)?(?:\s+(.*))?$/,gA=/^:::([A-Za-z][-\w]*)(.*)$/,MK=[/^(\*\s*){3,}$/,/^(-\s*){3,}$/,/^(_\s*){3,}$/];function f6(N,F,M){let A=[];while(N.index<N.lines.length){let D=Z0(N);if(N.index===N.lines.length-1&&D==="")break;if(T1(D)){N.index+=1;continue}if(S2(D)>F+nJ)break;let E=AK(N,F,M);if(!E)break;A.push(E)}return A}function AK(N,F,M){return DK(N,F,M)??EK(N,F)??$K(N,F)??ZK(N,F)??XK(N,F)??mA(N,F)??QK(N,F,M)??KK(N,F)??qK(N,F)}function DK(N,F,M){let A=Z0(N);if(!H0(A,F).startsWith(C2))return null;let D=[];while(N.index<N.lines.length){let E=Z0(N),$=S2(E);if(T1(E)){D.push(""),N.index+=1;continue}if($<F)break;let Y=H0(E,F);if(!Y.startsWith(C2))break;let Z=Y.slice(1);if(Z.startsWith(" "))Z=Z.slice(1);D.push(Z),N.index+=1}return m0({children:f6({index:0,lines:D},0,M)})}function EK(N,F){let M=Z0(N),A=H0(M,F),D=hA.exec(A);if(!D)return null;N.index+=1;let E=[];while(N.index<N.lines.length){let $=Z0(N),Y=H0($,F);if(Y.trim()===cN){N.index+=1;break}E.push(Y),N.index+=1}return N3({language:D[1]?D[1]:null,meta:D[2]?D[2]:null,source:E.join(x)})}function $K(N,F){let M=Z0(N),A=H0(M,F),D=gA.exec(A);if(!D)return null;let E=D[1],$=[];N.index+=1;while(N.index<N.lines.length){let Y=Z0(N),Z=H0(Y,F);if(Z.trim()===L6){N.index+=1;break}$.push(Z),N.index+=1}return a8({attributes:YK(D[2]??""),body:$.join(x),name:E})}function YK(N){let F=N.trim();if(F.startsWith("{")&&F.endsWith("}"))return F.slice(1,-1);return F}function ZK(N,F){let M=Z0(N),A=kA.exec(H0(M,F));if(!A)return null;return N.index+=1,VF({children:sN(A[2].replace(tJ,"")),depth:A[1].length})}function XK(N,F){let M=H0(Z0(N),F).trim();if(!IA(M))return null;return N.index+=1,zF()}function QK(N,F,M){let A=v6(Z0(N),F);if(!A)return null;let D=[],E=!1;while(N.index<N.lines.length){let $=Z0(N),Y=v6($,F);if(!Y||Y.ordered!==A.ordered)break;N.index+=1;let Z=[Y.content],X=!1;while(N.index<N.lines.length){let Q=Z0(N),K=S2(Q);if(T1(Q)){let J=GK(N.lines,N.index+1);if(J<0||S2(N.lines[J]??"")<=F)break;X=!0,Z.push(""),N.index+=1;continue}if(K<Y.contentIndent)break;if(K===F&&v6(Q,F))break;Z.push(VK(Q,Y.contentIndent)),N.index+=1}E||=X,D.push(R1({checked:Y.checked,children:JK(Z,M),spread:X}))}return b1({items:D,ordered:A.ordered,spread:E,start:A.ordered&&M.preserveOrderedListStart?A.start??1:null})}function v6(N,F){let M=eJ.exec(N);if(!M||M[1].length!==F)return null;let A=M[2],D=NK.test(A),E=D?Number(A.slice(0,-1)):null,$=M[3]??"",Y=null;if(FK.test($)){if(Y=$[1]==="x"||$[1]==="X",$=$.slice(3),$.startsWith(" "))$=$.slice(1)}let Z=M[0].length-M[1].length-M[2].length-$.length;return{checked:Y,content:$,contentIndent:F+M[2].length+Z,ordered:D,start:E}}function JK(N,F){let M=f6({index:0,lines:N},0,F);if(M.length>0)return M;return[c0({children:[]})]}function KK(N,F){let M=H0(Z0(N),F).trim();if(!uA(M))return null;return N.index+=1,F3({originalType:"html",source:M})}function qK(N,F){let M=[];while(N.index<N.lines.length){let A=Z0(N),D=S2(A);if(T1(A))break;if(D<F)break;let E=H0(A,F);if(M.length>0&&UK(A,E,F))break;M.push(E),N.index+=1}return c0({children:sN(M.join(x))})}function UK(N,F,M){let A=F.trim();return F.startsWith(C2)||hA.test(F)||gA.test(F)||kA.test(F)||IA(A)||A8(F)||v6(N,M)!==null||uA(A)}function S2(N){let F=0;while(F<N.length&&N[F]===" ")F+=1;return F}function VK(N,F){let M=S2(N);if(M>=F)return N.slice(F);return N.trim()===""?"":N.slice(Math.min(M,F))}function GK(N,F){for(let M=F;M<N.length;M+=1)if(!T1(N[M]??""))return M;return-1}function IA(N){return MK.some((F)=>F.test(N))}function uA(N){return N.startsWith("<")&&N.endsWith(">")}function xA(N){let F=N.at(-1),M=F&&pA(F)?F:null;return{blocks:N.filter((D)=>!pA(D)),comments:M?zK(M.body):[]}}function zK(N){let F;try{F=JSON.parse(N)}catch{return[]}if(!Array.isArray(F))return[];return F.flatMap((M)=>{let A=G3(M);return A?[A]:[]})}function pA(N){return N.type==="directive"&&N.name===w6}var lA="---";function iN(N,F={}){let A={index:0,lines:N.replace(/\r\n/g,x).split(x)},D=_K(A),E=f6(A,0,F),{comments:$,blocks:Y}=xA(E);return M2(Y,$,D)}function _K(N){if(N.lines[0]!==lA)return;for(let F=1;F<N.lines.length;F+=1)if(N.lines[F]===lA){let M=N.lines.slice(0,F+1).join(x);return N.index=F+1,M}return}function Z0(N){return D8(N,0)}function D8(N,F){return N.lines[N.index+F]??""}function T1(N){return N.trim()===""}function H0(N,F){return N.slice(F)}var HK=/([\\`*_[\]])/g,BK=/([\\)&])/g,WK=/(["\\])/g;function t0(N){return Q0(N).map((F)=>yK(F)).join("")}function yK(N){switch(N.type){case"lineBreak":return"<br>";case"image":return TK(N);case"code":return PK(N.code);case"link":return LK(N);case"text":return OK(cA(N.text),N.marks);case"raw":return N.source}}function OK(N,F){return F.reduce((M,A)=>{switch(A){case"bold":return`**${M}**`;case"italic":return`*${M}*`;case"strikethrough":return`~~${M}~~`;case"underline":return`${j2}${M}${dN}`}},N)}function PK(N){let F=0,M=0;for(let $ of N){if($==="`"){if(M+=1,M>F)F=M;continue}M=0}let A=F>0?F+1:1,D="`".repeat(A),E=N.startsWith("`")||N.endsWith("`")?` ${N} `:N;return`${D}${E}${D}`}function TK(N){let F=cA(N.alt??""),M=dA(N.url,N.title),A=N.width?`{width=${N.width}}`:"";return`![${F}]${M}${A}`}function LK(N){return`[${t0(N.children)}]${dA(N.url,N.title)}`}function dA(N,F){return`(${wK(N)}${jK(F)})`}function cA(N){return N.replace(HK,"\\$1")}function wK(N){return N.replace(BK,"\\$1")}function jK(N){return N?` "${N.replace(WK,"\\$1")}"`:""}var rA=3;function sA(N,F,M){let A=N.rows.map((Q)=>Q.cells.map((K)=>t0(K.children))),D=Math.max(1,...A.map((Q)=>Q.length)),E=A[0]??[],$=Array.from({length:D},(Q,K)=>Math.max(bK(N.align[K]),...M.padTableColumns?A.map((J)=>J[K]?.length??0):[E[K]?.length??0])),Y=CK($,N.align,F),Z=aA(E,$,N.align,F,M),X=A.slice(1).map((Q)=>aA(Q,$,N.align,F,M));return[Z??SK($,F),Y,...X].join(x)}function aA(N,F,M,A,D){let E=F.map(($,Y)=>{let Z=N[Y]??"";if(!D.padTableColumns)return Z;return vK(Z,$,M[Y])});return`${" ".repeat(A)}| ${E.join(" | ")} |`}function CK(N,F,M){let A=N.map((D,E)=>RK(F[E],D));return`${" ".repeat(M)}| ${A.join(" | ")} |`}function SK(N,F){return`${" ".repeat(F)}| ${N.map((M)=>"".padEnd(M," ")).join(" | ")} |`}function RK(N,F){let M=iA(N),A=Math.max(rA,F-M),D="-".repeat(A);switch(N){case"center":return`:${D}:`;case"left":return`:${D}`;case"right":return`${D}:`;default:return D}}function bK(N){return rA+iA(N)}function iA(N){if(N==="center")return 2;return N?1:0}function vK(N,F,M){if(M==="right")return N.padStart(F," ");return N.padEnd(F," ")}var a1=`
|
|
29
|
+
|
|
30
|
+
`,fK="-",mK=".",kK="---",hK=" ";function oN(N,F={}){return N.map((M)=>m6(M,0,F)).join(a1)}function m6(N,F,M){let A=r1(F);switch(N.type){case"blockquote":return gK(N,F,M);case"code":return IK(N,F);case"directive":return uK(N,F);case"heading":return oA(N,F);case"list":return pK(N,F,M);case"listItem":return nA(N,F,!1,1,M);case"paragraph":return`${A}${E8(t0(N.children))}`;case"table":return sA(N,F,M);case"divider":return`${A}${kK}`;case"raw":return F===0?N.source:tA(N.source,F)}}function gK(N,F,M){let A=N.children.map((E)=>m6(E,0,M)).join(a1),D=r1(F);return A.split(x).map((E)=>`${D}${C2}${E.length>0?` ${E}`:""}`).join(x)}function IK(N,F){let M=[N.language??"",N.meta??""].filter(Boolean).join(" ").trim(),A=r1(F),D=`${A}${cN}${M?M:""}`,E=N.source.length>0?N.source.split(x).map(($)=>`${A}${$}`).join(x):A;return`${D}${x}${E}${x}${A}${cN}`}function uK(N,F){let M=k6(N);return F===0?M:tA(M,F)}function k6(N){let F=N.attributes?`{${N.attributes}}`:"";return`:::${N.name}${F}${x}${N.body}${x}${L6}`}function oA(N,F){let M=E8(t0(N.children)),A=`${r1(F)}${"#".repeat(N.depth)}`;return M.length>0?`${A} ${M}`:A}function pK(N,F,M){let A=N.start??1;return N.items.map((D)=>nA(D,F,N.ordered,A,M)).join(N.spread?a1:x)}function nA(N,F,M,A,D){let E=M?`${A}${mK}`:fK,$=N.checked===null?"":`[${N.checked?"x":" "}] `,Y=`${r1(F)}${E} ${$}`,Z=F+E.length+1,X=N.children;if(X.length===0)return $.length>0?Y:Y.trimEnd();let[Q,...K]=X,J=xK(Q,Y,$.length>0,D),q=K.map((U)=>m6(U,Z,D)).join(N.spread?a1:x);if(!q)return J;return`${J}${N.spread?a1:x}${q}`}function xK(N,F,M,A){switch(N.type){case"paragraph":{let D=E8(t0(N.children));if(D.length===0)return M?F:F.trimEnd();return`${F}${D}`}case"heading":return`${F}${oA(N,0)}`;case"directive":case"raw":{let D=N.type==="directive"?k6(N):N.source,[E,...$]=D.split(x);return[F+E,...$.map((Y)=>`${r1(F.length)}${Y}`)].join(x)}default:{let D=F.length;return`${F.trimEnd()}${x}${m6(N,D,A)}`}}}function E8(N){return N.replace(/^ +/gm,(F)=>hK.repeat(F.length))}function r1(N){return" ".repeat(N)}function tA(N,F){let M=r1(F);return N.split(x).map((A)=>`${M}${A}`).join(x)}function h6(N,F={}){if(N.blocks.length===0&&N.comments.length===0&&N.frontMatter===void 0)return"";let M=[];if(N.frontMatter!==void 0)M.push(N.frontMatter);if(N.blocks.length>0)M.push(oN(N.blocks,F));if(N.comments.length>0)M.push(lK(N.comments));let A=M.join(a1);return A.endsWith(x)?A:`${A}${x}`}function lK(N){return k6({attributes:"",body:JSON.stringify(N,null,2),name:w6})}function $8(N){if(N.length===0)return{kind:"text",text:""};let{blocks:F}=iN(N);if(BF(F))return{kind:"text",text:F[0]?.plainText??""};if(F.length===1&&F[0]?.type==="paragraph")return{kind:"inlines",inlines:F[0].children};return{kind:"blocks",blocks:F}}function g6(N){switch(N.kind){case"text":return N.text;case"inlines":return t0(N.inlines);case"blocks":return oN(N.blocks)}}import{createContext as dK,useContext as cK}from"react";import{createPortal as aK}from"react-dom";import{jsx as FD}from"react/jsx-runtime";var eA=dK(void 0);function ND({children:N,themeStyles:F}){return FD(eA.Provider,{value:F,children:N})}function I6({children:N}){let F=cK(eA);if(typeof document>"u")return null;return aK(FD("div",{className:"documint-overlay",style:{display:"contents",...F},children:N}),document.body)}import{useEffect as u6,useRef as VD,useState as s1}from"react";import{forwardRef as sK,useCallback as R2,useEffect as iK,useImperativeHandle as oK,useLayoutEffect as nK,useMemo as tK,useRef as DD,useState as Y8}from"react";var rK=["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 MD(N,F,{topGap:M=8}={}){if(!N.isConnected)return null;let A=getComputedStyle(N),D=document.createElement("div");for(let X of rK)D.style.setProperty(X,A.getPropertyValue(X));Object.assign(D.style,{position:"absolute",top:"0",left:"0",visibility:"hidden",whiteSpace:"pre-wrap",wordWrap:"break-word",width:`${N.clientWidth}px`}),D.textContent=N.value.slice(0,F);let E=document.createElement("span");E.textContent=N.value.slice(F)||".",D.appendChild(E),document.body.appendChild(D);let $=N.getBoundingClientRect(),Y=parseFloat(A.lineHeight)||E.offsetHeight,Z={left:$.left+E.offsetLeft+parseFloat(A.borderLeftWidth)-N.scrollLeft,top:$.top+E.offsetTop+parseFloat(A.borderTopWidth)+Y+M-N.scrollTop};return document.body.removeChild(D),Z}import{jsx as l0,jsxs as ED,Fragment as Yq}from"react/jsx-runtime";var eK=240,Nq="documint-leaf-menu-item documint-completion-item",nN=sK(function({actions:F,completionSources:M,onChange:A,placeholder:D,readOnly:E=!1,rows:$=3,value:Y},Z){let X=DD(null);oK(Z,()=>X.current,[]);let Q=tK(()=>Dq(M),[M]),[K,J]=Y8(null),[q,U]=Y8(0),[V,G]=Y8(null),_=R2((B,j)=>{if(!Q.length){J(null);return}let T=Eq(B,j,Q);if(!T){J(null);return}J(T),U(0)},[Q]),w=R2((B)=>{let j=B.currentTarget.value,T=B.currentTarget.selectionEnd??j.length;A(j),_(j,T)},[A,_]),L=R2((B)=>{let j=B.currentTarget;_(j.value,j.selectionEnd??j.value.length)},[_]),m=R2(()=>{J(null)},[]),W=R2((B)=>{if(!X.current||!K)return;let T=`${K.trigger}${B.label} `,O=Y.slice(0,K.triggerStart),P=Y.slice(K.caret),C=O+T+P,z=K.triggerStart+T.length;A(C),J(null),requestAnimationFrame(()=>{let b=X.current;if(!b)return;b.focus(),b.setSelectionRange(z,z)})},[K,A,Y]),H=R2((B)=>{if(K&&K.matches.length>0){if(B.key==="ArrowDown"){B.preventDefault(),B.stopPropagation(),U((j)=>(j+1)%K.matches.length);return}if(B.key==="ArrowUp"){B.preventDefault(),B.stopPropagation(),U((j)=>(j-1+K.matches.length)%K.matches.length);return}if(B.key==="Enter"||B.key==="Tab"){B.preventDefault(),B.stopPropagation();let j=K.matches[q];if(j)W(j);return}if(B.key==="Escape"){B.preventDefault(),B.stopPropagation(),J(null);return}}if(B.key==="Escape"&&F.kind==="edit")B.preventDefault(),F.onCancel()},[F,K,q,W]);return nK(()=>{if(!K){G(null);return}let B=()=>{let j=X.current;if(!j)return;G(MD(j,K.triggerStart))};return B(),window.addEventListener("scroll",B,!0),window.addEventListener("resize",B),()=>{window.removeEventListener("scroll",B,!0),window.removeEventListener("resize",B)}},[K]),ED("div",{className:"documint-leaf-input-field",children:[l0("textarea",{className:"documint-leaf-input",onBlur:m,onChange:w,onKeyDown:H,onSelect:L,placeholder:D,readOnly:E,ref:X,rows:$,value:Y}),Fq(F),K&&V&&K.matches.length>0?l0(I6,{children:l0(Mq,{activeIndex:q,left:V.left,matches:K.matches,onHover:U,onSelect:W,top:V.top})}):null]})});function Fq(N){if(N.kind==="edit")return ED(Yq,{children:[l0(Z8,{className:"documint-leaf-input-cancel",icon:lN,label:"Cancel editing",onClick:N.onCancel}),l0(Z8,{className:"documint-leaf-input-save",disabled:N.saveDisabled??!1,icon:d1,label:"Save",onClick:N.onSave})]});return l0(Z8,{className:"documint-leaf-input-submit",disabled:N.submitDisabled??!1,icon:O1,iconSize:15,label:N.submitLabel,onClick:N.onSubmit})}function Z8({className:N,disabled:F=!1,icon:M,iconSize:A=14,label:D,onClick:E}){return l0("button",{"aria-label":D,className:`documint-leaf-action ${N}`,disabled:F,onClick:E,title:D,type:"button",children:l0(M,{size:A,strokeWidth:2.2})})}function Mq({activeIndex:N,left:F,matches:M,onHover:A,onSelect:D,top:E}){let $=DD(null);return iK(()=>{let Y=$.current;if(!Y)return;let Z=Y.children[N];if(Z instanceof HTMLElement)Z.scrollIntoView({block:"nearest"})},[N]),l0("div",{className:"documint-leaf-menu documint-completion-popover",ref:$,role:"listbox",style:{position:"fixed",left:F,top:E,maxHeight:eK,overflowY:"auto"},children:M.map((Y,Z)=>{let X=Z===N;return l0("button",{"aria-selected":X,className:`${Nq}${X?" is-active":""}`,onPointerDown:Aq,onPointerEnter:()=>A(Z),onClick:()=>D(Y),role:"option",type:"button",children:l0("span",{children:Y.label})},Y.label)})})}function Aq(N){N.preventDefault()}function Dq(N){if(!N?.length)return[];return N.map((F)=>({trigger:F.trigger,items:[...F.items].sort((M,A)=>M.label.localeCompare(A.label,void 0,{sensitivity:"base"}))}))}function Eq(N,F,M){for(let A=F-1;A>=0;A-=1){let D=N[A];if(AD(D))return null;let E=M.find((Y)=>Y.trigger===D);if(!E)continue;if(A>0&&!AD(N[A-1]))return null;let $=N.slice(A+1,F);return{trigger:E.trigger,query:$,triggerStart:A,caret:F,matches:$q(E.items,$)}}return null}function AD(N){return N===void 0||N===" "||N===`
|
|
31
|
+
`||N==="\t"}function $q(N,F){if(!F)return N;let M=F.toLowerCase();return N.filter((A)=>A.label.toLowerCase().includes(M))}import{Fragment as Xq}from"react";function X8(N,F){if(!F?.length||!F.some(($)=>N.includes($.trigger)))return[{kind:"text",text:N}];let M=new Map;for(let $ of F){let Y=[...$.items].sort((Z,X)=>X.label.length-Z.label.length);M.set($.trigger,Y)}let A=[],D=0,E=0;while(D<N.length){let $=N[D],Y=M.get($);if(Y!==void 0&&(D===0||Zq(N[D-1]))){let X=Y.find((Q)=>N.startsWith(Q.label,D+1));if(X){if(D>E)A.push({kind:"text",text:N.slice(E,D)});A.push({kind:"token",trigger:$,label:X.label,id:X.id}),D+=1+X.label.length,E=D;continue}}D+=1}if(E<N.length)A.push({kind:"text",text:N.slice(E)});return A}function Q8(N,F){let M=[],A=new Set;for(let D of X8(N,F)){if(D.kind!=="token"||D.trigger!=="@"||!D.id)continue;if(A.has(D.id))continue;A.add(D.id),M.push(D.id)}return M}function Zq(N){return N===void 0||N===" "||N===`
|
|
32
|
+
`||N==="\t"}import{jsx as $D,jsxs as Jq}from"react/jsx-runtime";function J8({value:N,completionSources:F,onEdit:M}){return $D("p",{onDoubleClick:M,children:Qq(N,F)})}function Qq(N,F){let M=X8(N,F);if(M.length===1&&M[0].kind==="text")return N;return M.map((A,D)=>A.kind==="token"?Jq("span",{className:"documint-mention",children:[A.trigger,A.label]},D):$D(Xq,{children:A.text},D))}import{Children as YD,isValidElement as ZD,useEffect as Kq,useRef as qq,useState as Uq}from"react";import{jsx as K0,jsxs as U8}from"react/jsx-runtime";var K8=(N)=>{N.preventDefault()},q8=(N)=>N.isPrimary&&N.button===0;function Vq({children:N}){return K0("div",{className:"documint-leaf-toolbar",children:YD.map(N,Gq)})}function Gq(N){if(!ZD(N))return null;if(N.type===QD){let F=N.props;return K0(XD,{children:K0(zq,{...F})})}if(N.type===JD){let{className:F}=N.props;return K0("div",{className:tN("documint-leaf-toolbar-divider",F)})}if(N.type===KD){let F=N.props;return K0(_q,{...F})}return null}function zq({active:N=!1,className:F,disabled:M=!1,icon:A,label:D,onClick:E}){return K0("button",{"aria-label":D,className:tN("documint-leaf-toolbar-button",N?"active":null,F),disabled:M,onPointerDown:($)=>{if(K8($),!M&&q8($))E()},title:D,type:"button",children:K0(A,{size:15,strokeWidth:2.2})})}function _q({children:N,className:F,icon:M,label:A,onSelect:D}){let E=qq(null),[$,Y]=Uq(!1);return Kq(()=>{if(!$)return;let Z=(X)=>{if(E.current&&X.target instanceof Node&&!E.current.contains(X.target))Y(!1)};return window.addEventListener("pointerdown",Z),()=>{window.removeEventListener("pointerdown",Z)}},[$]),K0(XD,{children:U8("div",{className:"documint-leaf-toolbar-menu-shell",ref:E,children:[K0(Hq,{className:F,icon:M,isOpen:$,label:A,onClick:()=>Y((Z)=>!Z)}),$?K0("div",{className:"documint-leaf-menu",role:"menu",children:YD.map(N,(Z)=>Bq(Z,(X)=>{Y(!1),D(X)}))}):null]})})}function Hq({className:N,icon:F,isOpen:M,label:A,onClick:D}){return U8("button",{"aria-expanded":M,"aria-haspopup":"menu","aria-label":A,className:tN("documint-leaf-toolbar-button",M?"active":null,N),onPointerDown:(E)=>{if(K8(E),q8(E))D()},title:A,type:"button",children:[K0(F,{size:15,strokeWidth:2.2}),K0(LN,{className:tN("documint-leaf-toolbar-menu-chevron",M?"is-open":null),size:13,strokeWidth:2.2})]})}function Bq(N,F){if(!ZD(N))return null;if(N.type===UD){let{className:$}=N.props;return K0("div",{className:tN("documint-leaf-menu-divider",$),role:"separator"})}if(N.type!==qD)return null;let{disabled:M=!1,icon:A,text:D,value:E}=N.props;return U8("button",{className:"documint-leaf-menu-item",disabled:M,onPointerDown:($)=>{if(K8($),!M&&q8($))F(E)},role:"menuitem",type:"button",children:[K0(A,{size:15,strokeWidth:2.2}),K0("span",{children:D})]})}function tN(...N){return N.filter(Boolean).join(" ")}function XD({children:N}){return K0("div",{className:"documint-leaf-toolbar-group",children:N})}function QD(N){return null}function JD(N){return null}function KD(N){return null}function qD(N){return null}function UD(N){return null}var l=Object.assign(Vq,{Button:QD,Divider:JD,Menu:KD,MenuDivider:UD,MenuItem:qD});import{jsx as i,jsxs as e0,Fragment as Pq}from"react/jsx-runtime";var Wq=!1,yq=220,i1=()=>{};function V8(N){let F=N.mode==="create",M=N.mode==="create"?N:null,A=N.mode==="thread"?N:null,D=N.canEdit,E=N.link,$=A?.thread??null,Y=$?.comments??[],Z=Y[0]??null,X=$?M1($):!1,Q=A?.animateInitialComment??!1,[K,J]=s1(null),[q,U]=s1(""),[V,G]=s1(""),[_,w]=s1(""),[L,m]=s1(!Q),[W,H]=s1(Wq),[B,j]=s1(!1),T=VD(null),O=VD(null),P=N.mentionSources,C=$?y3($):null,z=C?GD(C):"",b=D&&!X,y=b&&q.trim().length>0,S=b&&V.trim().length>0,R=D&&_.trim().length>0,k=F||B,f=!F||W,g=!F&&Boolean($),I=Boolean(Z),c=F?W:!0,$0=A?.onDeleteComment??i1,t=A?.onDeleteThread??i1,U0=A?.onToggleResolved??i1,v0=M?.activeMarks??[],Q1=M?.onToggleBold??i1,m2=M?.onToggleItalic??i1,k2=M?.onToggleStrikethrough??i1,ZF=M?.onToggleUnderline??i1,F1=D?F?"Add a comment":"Reply to this comment":"Comment editing is disabled",L0=F?_:V;u6(()=>{if(K!==null&&(K<0||K>=Y.length))J(null),U("")},[Y.length,K]),u6(()=>{if(!I||!Q){m(!0);return}m(!1);let f0=requestAnimationFrame(()=>{m(!0)});return()=>{cancelAnimationFrame(f0)}},[Q,Z,I]),u6(()=>{if(!A||!Q){j(!1);return}j(!0);let f0=window.setTimeout(()=>{j(!1)},yq);return()=>{window.clearTimeout(f0)}},[Q,A]),u6(()=>{if(!F||!W||!D)return;let f0=requestAnimationFrame(()=>{O.current?.focus()});return()=>{cancelAnimationFrame(f0)}},[D,F,W]);let L1=()=>{J(null),U("")},i6=(f0,KF)=>{if(!g||!b)return;J(f0),U(KF)},XF=(f0)=>{if(!A)return;A.onEditComment(f0,q),L1()},n1=()=>{if(!A)return;A.onReply(V),G("")},n=()=>{if(!M||!R)return;M.onCreateThread(_),w("")},o=k?`documint-comment-leaf documint-comment-leaf-create${c?" is-expanded":""}`:"documint-comment-leaf",JF=g||I||f?i(Oq,{canCreate:R,canEdit:D,canMutateThread:b,canReply:S,canSaveEditedComment:y,comments:Y,composerRef:O,editDraft:q,editingCommentIndex:K,isComposerVisible:f,isInitialCommentVisible:L,isResolved:X,link:E,mentionSources:P,mode:N.mode,onBeginEditingComment:i6,onCancelEditing:L1,onChangeCreateDraft:w,onChangeEditDraft:U,onChangeReplyDraft:G,onDeleteComment:$0,onDeleteThread:t,onSubmitCreate:n,onSubmitEditedComment:XF,onSubmitReply:n1,onToggleResolved:U0,rootComment:Z,showRootComment:I,showThreadChrome:g,threadAge:z,composerPlaceholder:F1,composerValue:L0}):null;return i("div",{className:o,"data-resolved":X?"true":void 0,ref:T,children:e0("div",{className:k?"documint-comment-leaf-create-shell":void 0,children:[k?e0(l,{children:[i(l.Button,{className:"documint-comment-leaf-create-button",icon:gN,label:"Add comment",onClick:()=>H(!0)}),i(l.Divider,{className:"documint-comment-leaf-create-divider"}),i(l.Button,{active:v0.includes("bold"),className:"documint-comment-leaf-create-mark",icon:TN,label:"Bold",onClick:Q1}),i(l.Button,{active:v0.includes("italic"),className:"documint-comment-leaf-create-mark",icon:fN,label:"Italic",onClick:m2}),i(l.Button,{active:v0.includes("underline"),className:"documint-comment-leaf-create-mark",icon:xN,label:"Underline",onClick:ZF}),i(l.Button,{active:v0.includes("strikethrough"),className:"documint-comment-leaf-create-mark",icon:uN,label:"Strikethrough",onClick:k2})]}):null,i("div",{className:k?"documint-comment-leaf-create-content":void 0,children:JF})]})})}function Oq({canCreate:N,canEdit:F,canMutateThread:M,canReply:A,canSaveEditedComment:D,comments:E,composerRef:$,editDraft:Y,editingCommentIndex:Z,isComposerVisible:X,isInitialCommentVisible:Q,isResolved:K,link:J,mentionSources:q,mode:U,onBeginEditingComment:V,onCancelEditing:G,onChangeCreateDraft:_,onChangeEditDraft:w,onChangeReplyDraft:L,onDeleteComment:m,onDeleteThread:W,onSubmitCreate:H,onSubmitEditedComment:B,onSubmitReply:j,onToggleResolved:T,rootComment:O,showRootComment:P,showThreadChrome:C,threadAge:z,composerPlaceholder:b,composerValue:y}){return e0(Pq,{children:[C?e0("div",{className:"documint-comment-leaf-header",children:[i("span",{className:"documint-comment-leaf-age",children:z}),e0("div",{className:"documint-comment-leaf-actions",children:[i("button",{className:"documint-leaf-action","aria-label":K?"Reopen comment":"Resolve comment",disabled:!F,onClick:T,title:K?"Reopen comment":"Resolve comment",type:"button",children:i(d1,{size:14,strokeWidth:2.2})}),i("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Delete comment thread",disabled:!F,onClick:W,title:"Delete comment thread",type:"button",children:i(b0,{size:14,strokeWidth:2.2})})]})]}):null,C&&J?e0("div",{className:"documint-comment-leaf-link",children:[J.title?i("div",{className:"documint-link-leaf-title",children:J.title}):null,i("div",{className:"documint-link-leaf-url",children:J.url})]}):null,e0("div",{className:`documint-comment-thread${P?"":" is-empty"}`,children:[i("article",{className:P?`documint-comment-message documint-comment-message-root${Q?" is-visible":""}`:"documint-comment-message documint-comment-message-root is-hidden",children:O?i(J8,{completionSources:q,onEdit:()=>V(0,O.body),value:O.body}):null}),E.slice(1).map((S,R)=>{let k=R+1,f=Z===k;return e0("article",{className:"documint-comment-message",children:[!f?e0("div",{className:"documint-comment-message-meta",children:[i("span",{children:GD(S.updatedAt)}),M?e0("div",{className:"documint-comment-leaf-actions",children:[i("button",{className:"documint-leaf-action","aria-label":"Edit comment",disabled:!M,onClick:()=>{V(k,S.body)},title:"Edit comment",type:"button",children:i(c1,{size:14,strokeWidth:2.2})}),i("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Delete comment",disabled:!M,onClick:()=>m(k),title:"Delete comment",type:"button",children:i(b0,{size:14,strokeWidth:2.2})})]}):null]}):null,f?i(nN,{actions:{kind:"edit",onCancel:G,onSave:()=>B(k),saveDisabled:!D},completionSources:q,onChange:w,readOnly:!F,rows:3,value:Y}):i(J8,{completionSources:q,onEdit:()=>V(k,S.body),value:S.body})]},`${S.updatedAt}:${k}`)})]}),i("div",{className:`documint-comment-reply${C?"":" is-standalone"}${X?" is-visible":""}`,children:i(nN,{actions:U==="create"?{kind:"compose",onSubmit:H,submitDisabled:!N,submitLabel:"Create comment"}:{kind:"compose",onSubmit:j,submitDisabled:!A,submitLabel:"Reply"},completionSources:q,onChange:U==="create"?_:L,placeholder:b,readOnly:!F,ref:$,rows:3,value:y})})]})}function GD(N){let F=new Date(N);if(Number.isNaN(F.getTime()))return N;let M=F.getTime()-Date.now(),A=60000,D=60*A,E=24*D,$=7*E,Y=30*E,Z=365*E,X=new Intl.RelativeTimeFormat(void 0,{numeric:"auto"});if(Math.abs(M)<A)return"just now";if(Math.abs(M)<D)return X.format(Math.round(M/A),"minute");if(Math.abs(M)<E)return X.format(Math.round(M/D),"hour");if(Math.abs(M)<$)return X.format(Math.round(M/E),"day");if(Math.abs(M)<Z)return X.format(Math.round(M/Y),"month");return X.format(Math.round(M/Z),"year")}import{jsx as d0,jsxs as wq}from"react/jsx-runtime";var Tq=[{icon:wN,label:"Heading 1",text:"# "},{icon:jN,label:"Heading 2",text:"## "},{icon:CN,label:"Heading 3",text:"### "},{icon:RN,label:"Heading 4",text:"#### "},{icon:SN,label:"Heading 5",text:"##### "},{icon:bN,label:"Heading 6",text:"###### "}],Lq=[{columns:2,text:"2 columns"},{columns:3,text:"3 columns"},{columns:4,text:"4 columns"},{columns:5,text:"5 columns"}];function zD({onInsert:N,onInsertTable:F}){return wq(l,{children:[d0(l.Button,{icon:hN,label:"Insert bulleted list",onClick:()=>N("- ")}),d0(l.Button,{icon:mN,label:"Insert numbered list",onClick:()=>N("1. ")}),d0(l.Button,{icon:kN,label:"Insert task list",onClick:()=>N("- [ ] ")}),d0(l.Divider,{}),d0(l.Menu,{icon:vN,label:"Insert heading",onSelect:N,children:Tq.map(({icon:M,label:A,text:D})=>d0(l.MenuItem,{icon:M,text:A,value:D},D))}),d0(l.Menu,{icon:P1,label:"Insert table",onSelect:(M)=>F(Number(M)),children:Lq.map(({columns:M,text:A})=>d0(l.MenuItem,{icon:P1,text:A,value:String(M)},M))}),d0(l.Divider,{}),d0(l.Button,{icon:pN,label:"Insert blockquote",onClick:()=>N("> ")}),d0(l.Button,{icon:IN,label:"Insert divider",onClick:()=>N("--- ")})]})}import{useLayoutEffect as jq,useRef as Cq,useState as Sq}from"react";import{jsx as G8,jsxs as Rq}from"react/jsx-runtime";var _D=12;function HD({anchor:N,children:F}){let M=Cq(null),[A,D]=Sq("below");return jq(()=>{let E=M.current;if(!E||typeof window>"u")return;let $=()=>{let Z=E.getBoundingClientRect().height,X=window.visualViewport,Q=X?.height??window.innerHeight,K=X?.offsetTop??0,J=N.top-window.scrollY-K,q=Q-J;D(Z+_D>q?"above":"below")};$();let Y=new ResizeObserver($);return Y.observe(E),window.visualViewport?.addEventListener("resize",$),window.addEventListener("resize",$),()=>{Y.disconnect(),window.visualViewport?.removeEventListener("resize",$),window.removeEventListener("resize",$)}},[N.top]),G8(I6,{children:Rq("div",{className:"documint-leaf-anchor","data-bridge":N.bridge,"data-placement":A,onPointerEnter:N.onPointerEnter,onPointerLeave:N.onPointerLeave,style:{left:`${N.left}px`,top:`${N.top}px`,"--documint-leaf-anchor-height":`${N.anchorHeight}px`,"--documint-leaf-bridge-height":`${_D}px`,"--documint-leaf-padding-y":`${N.paddingY}px`},children:[N.bridge?G8("div",{className:"documint-leaf-bridge"}):null,G8("div",{className:"documint-leaf-shell",ref:M,children:F})]})})}import{useEffect as BD,useRef as bq,useState as WD}from"react";import{jsx as Y1,jsxs as z8}from"react/jsx-runtime";function yD({canEdit:N,onDelete:F,onSave:M,title:A,url:D}){let[E,$]=WD(D),[Y,Z]=WD(!1),X=bq(null),Q=vq(),K=E.trim(),J=N&&K.length>0,q=N&&!Y,U=`${Q}click to open`,V=`documint-link-leaf-row${Y?" is-editing":""}`;return BD(()=>{if(Y)return;$(D)},[Y,D]),BD(()=>{if(!Y)return;X.current?.focus()},[Y]),z8("div",{className:"documint-link-leaf",children:[A?Y1("div",{className:"documint-link-leaf-title",children:A}):null,z8("div",{className:V,children:[Y?Y1(nN,{actions:{kind:"edit",onCancel:()=>{$(D),Z(!1)},onSave:()=>{M(K),Z(!1)},saveDisabled:!J},onChange:$,readOnly:!N,ref:X,rows:3,value:E}):Y1("div",{className:"documint-link-leaf-url",children:D}),q?z8("div",{className:"documint-link-leaf-actions",children:[Y1("button",{className:"documint-leaf-action","aria-label":"Edit link",onClick:()=>{if(!N)return;$(D),Z(!0)},title:"Edit link",type:"button",children:Y1(c1,{size:14,strokeWidth:2.2})}),Y1("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Remove link",onClick:F,title:"Remove link",type:"button",children:Y1(b0,{size:14,strokeWidth:2.2})})]}):null]}),Y1("div",{className:"documint-link-leaf-divider"}),Y1("div",{className:"documint-link-leaf-hint",children:U})]})}function vq(){if(typeof navigator>"u")return"Ctrl+";let N=navigator.platform||navigator.userAgent;return/Mac|iPhone|iPad|iPod/.test(N)?"CMD+":"CTRL+"}import{jsx as Z1,jsxs as B8}from"react/jsx-runtime";var fq=[{text:"Column left",value:"left"},{text:"Column right",value:"right"}],mq=[{text:"Row above",value:"above"},{text:"Row below",value:"below"}],_8={text:"Delete column",value:"delete"},H8={text:"Delete row",value:"delete"},OD={text:"Delete table",value:"delete"};function PD({canDeleteColumn:N,canDeleteRow:F,onDeleteColumn:M,onDeleteRow:A,onDeleteTable:D,onInsertColumn:E,onInsertRow:$}){return B8(l,{children:[B8(l.Menu,{icon:W1,label:"Column actions",onSelect:(Y)=>{if(Y===_8.value){M();return}E(Y)},children:[fq.map(({text:Y,value:Z})=>Z1(l.MenuItem,{icon:L2,text:Y,value:Z},Z)),Z1(l.MenuDivider,{}),Z1(l.MenuItem,{disabled:!N,icon:b0,text:_8.text,value:_8.value})]}),B8(l.Menu,{icon:y1,label:"Row actions",onSelect:(Y)=>{if(Y===H8.value){A();return}$(Y)},children:[mq.map(({text:Y,value:Z})=>Z1(l.MenuItem,{icon:L2,text:Y,value:Z},Z)),Z1(l.MenuDivider,{}),Z1(l.MenuItem,{disabled:!F,icon:b0,text:H8.text,value:H8.value})]}),Z1(l.Divider,{}),Z1(l.Menu,{icon:P1,label:"Table actions",onSelect:()=>D(),children:Z1(l.MenuItem,{icon:b0,text:OD.text,value:OD.value})})]})}import{useEffect as TD,useEffectEvent as W8,useLayoutEffect as LD,useMemo as kq,useRef as y8,useState as O8}from"react";function eN(N,F){return N.anchor.regionId===F.anchor.regionId&&N.anchor.offset===F.anchor.offset&&N.leftOverride===F.leftOverride&&N.paddingY===F.paddingY}function p6(N,F,M){if(!N||N.kind==="task-toggle")return null;if(N.commentThreadIndex!==null){let A=F[N.commentThreadIndex]??null,D=M.find((E)=>E.threadIndex===N.commentThreadIndex);if(!A||!D)return null;return{anchor:{regionId:D.regionId,offset:D.startOffset},animateInitialComment:!1,kind:"thread",link:N.kind==="link"?{title:N.title,url:N.url}:null,resolved:M1(A),thread:A,threadIndex:N.commentThreadIndex}}if(N.kind!=="link")return null;return{anchor:{regionId:N.regionId,offset:N.startOffset},endOffset:N.endOffset,kind:"link",regionId:N.regionId,startOffset:N.startOffset,title:N.title,url:N.url}}var hq=600,gq=530,b2=24;function jD({canShowInsertionLeaf:N,canShowTableLeaf:F,commentState:M,editorState:A,editorViewportState:D,getScrollTop:E,layoutWidth:$,onVisibilityChange:Y,resources:Z,scrollContentHeight:X,scrollTo:Q,viewportHeight:K}){let J=kq(()=>N0(A),[A]),[q,U]=O8(null),[V,G]=O8(null),[_,w]=O8(!0),L=J.start.regionId===J.end.regionId&&J.start.offset===J.end.offset,m=y8(!0),W=y8(0),H=y8(null),B=W8(()=>{Y()}),j=W8(()=>{W.current=typeof performance<"u"?performance.now():Date.now(),m.current=!0,B()}),T=W8((O)=>{let P=PF(A,O,A.selection.focus),C=P!=="above"&&P!=="below";w((z)=>z===C?z:C)});return LD(()=>{let O=Iq({canShowInsertionLeaf:N,canShowTableLeaf:F,commentState:M,normalizedSelection:J,state:A,viewport:D.get()});U((P)=>lq(P,O)?P:O)},[N,F,M,A,D]),LD(()=>{let O=Z?cq(A,D.get(),J,Z):null;G((P)=>aq(P,O)?P:O)},[A,D,J,Z]),TD(()=>{let O=A.selection.focus,P={layoutWidth:$,offset:O.offset,regionId:O.regionId,scrollContentHeight:X,viewportHeight:K};if(dq(H.current,P))return;let C=l4(A,D.get(),O);if(!C)return;let z=E(),b=z+b2,y=z+K-b2;if(C.top<b){let S=Q(Math.max(0,C.top-b2));if(wD(C,S,K,b2))H.current=P;return}if(C.top+C.height>y){let S=Q(Math.max(0,C.top+C.height-K+b2));if(wD(C,S,K,b2))H.current=P;return}H.current=P},[A,A.selection.focus.offset,A.selection.focus.regionId,D,$,X,K]),TD(()=>{if(m.current=!0,B(),!L||!_||typeof window>"u")return;let O=window.setInterval(()=>{if((typeof performance<"u"?performance.now():Date.now())-W.current<hq){if(!m.current)m.current=!0,B();return}m.current=!m.current,B()},gq);return()=>{window.clearInterval(O)}},[L,_]),{caretInViewport:_,imageAtCursor:V,leaf:q,isVisible:()=>m.current,markActivity:j,refreshCaretViewportStatus:T}}function Iq({canShowInsertionLeaf:N,canShowTableLeaf:F,commentState:M,normalizedSelection:A,state:D,viewport:E}){if(!E)return null;let $=D.selection.focus;if(A.start.regionId!==A.end.regionId||A.start.offset!==A.end.offset)return null;let Y=N?xq(D):null;if(Y)return Y;let Z=F?uq(D,E):null;if(Z)return Z;return p6(x4(D,E,$,M.liveRanges),M.threads,M.liveRanges)}function uq(N,F){let M=N.selection.focus,A=N.documentIndex.regionIndex.get(M.regionId),D=A?N.documentIndex.tableCellIndex.get(A.id)??null:null;if(!A||!D)return null;let E=N.documentIndex.blockIndex.get(A.blockId),$=E?.type==="table"?N.documentIndex.document.blocks[E.rootIndex]:null;if(!E||!$||$.type!=="table")return null;let Y=pq(F,A.id),Z=Math.max(1,...$.rows.map((X)=>X.cells.length));return Y!==null?{anchor:M,cellIndex:D.cellIndex,columnCount:Z,kind:"table",leftOverride:Y,rowCount:$.rows.length,rowIndex:D.rowIndex}:null}function pq(N,F){let M=N.layout.lines.find((A)=>A.regionId===F);return M?M.left:null}function xq(N){let F=N.selection.focus,M=N.documentIndex.regionIndex.get(F.regionId);if(!M||M.blockType!=="paragraph"||M.text.length>0)return null;if(F.offset!==0)return null;let A=N.documentIndex.blockIndex.get(M.blockId);if(!A||A.parentBlockId!==null)return null;return{anchor:F,kind:"insertion"}}function lq(N,F){if(N===F)return!0;if(!N||!F||N.kind!==F.kind)return!1;if(!eN(N,F))return!1;switch(N.kind){case"thread":return F.kind==="thread"&&N.animateInitialComment===F.animateInitialComment&&N.link?.title===F.link?.title&&N.link?.url===F.link?.url&&N.thread===F.thread&&N.threadIndex===F.threadIndex;case"insertion":return F.kind==="insertion";case"link":return F.kind==="link"&&N.endOffset===F.endOffset&&N.regionId===F.regionId&&N.startOffset===F.startOffset&&N.title===F.title&&N.url===F.url;case"table":return F.kind==="table"&&N.cellIndex===F.cellIndex&&N.columnCount===F.columnCount&&N.rowCount===F.rowCount&&N.rowIndex===F.rowIndex}}function dq(N,F){return N?.layoutWidth===F.layoutWidth&&N.regionId===F.regionId&&N.offset===F.offset&&N.scrollContentHeight===F.scrollContentHeight&&N.viewportHeight===F.viewportHeight}function wD(N,F,M,A){return N.top>=F+A&&N.top+N.height<=F+M-A}function cq(N,F,M,A){if(!F)return null;if(M.start.regionId!==M.end.regionId||M.start.offset!==M.end.offset)return null;let D=RF(N);if(!D)return null;let E=WN(N,F,A,D),$=D.image?A.images.get(D.image.url)?.intrinsicWidth??null:null,Y=N.selection.anchor.regionId;return E?{bounds:E,maxWidth:$,regionId:Y,run:D}:null}function aq(N,F){if(N===F)return!0;if(!N||!F)return!1;return N.regionId===F.regionId&&N.maxWidth===F.maxWidth&&N.bounds.left===F.bounds.left&&N.bounds.top===F.bounds.top&&N.bounds.width===F.bounds.width&&N.bounds.height===F.bounds.height}import{useMemo as P8,useRef as NF,useEffectEvent as T8}from"react";var rq=48;function CD(N,F,M){let A=NF(null),D=NF(null),E=NF(null),$=NF(null),Y=NF(1),Z=T8((q,U)=>{if(!N)return;q.preventDefault(),q.stopPropagation(),q.currentTarget.setPointerCapture(q.pointerId),$.current=q.pointerId,A.current=q.clientX,D.current=q.clientY,E.current=N.run.image?.width??N.bounds.width,Y.current=U}),X=T8((q)=>{if($.current!==q.pointerId||A.current===null||D.current===null||E.current===null||!N?.run.image)return;let U=q.clientX-A.current,V=q.clientY-D.current,G=Math.min(N.maxWidth??1/0,Math.max(rq,Math.round(E.current+Y.current*(U+V)))),_=i9(F,N.regionId,N.run,G);if(_)M(_)}),Q=T8((q)=>{if(q.currentTarget.hasPointerCapture(q.pointerId))q.currentTarget.releasePointerCapture(q.pointerId);$.current=null,A.current=null,D.current=null,E.current=null}),K=P8(()=>({onPointerDown:(q)=>Z(q,-1),onPointerMove:X,onPointerUp:Q,onPointerCancel:Q}),[]),J=P8(()=>({onPointerDown:(q)=>Z(q,1),onPointerMove:X,onPointerUp:Q,onPointerCancel:Q}),[]);return P8(()=>{if(!N)return null;let{bounds:q}=N;return{start:{left:q.left,top:q.top,props:K},end:{left:q.left+q.width,top:q.top+q.height,props:J}}},[N])}import{useEffect as SD,useEffectEvent as RD,useMemo as bD,useRef as sq,useState as iq}from"react";function vD(N,F){let[M,A]=iq(new Map),D=RD((Z)=>{if(typeof createImageBitmap>"u")return;let X=[...M.keys()].filter((Q)=>!Z.has(Q));if(X.length>0)A((Q)=>{let K=new Map(Q);for(let J of X)K.delete(J);return K});for(let Q of Z){let K=M.get(Q)?.status;if(K==="loaded"||K==="loading")continue;A((J)=>L8(J,Q,FF("loading"))),oq(Q,F).then((J)=>{A((q)=>{if(!q.has(Q))return J?.close(),q;return L8(q,Q,J?FF("loaded",J):FF("error"))})})}});SD(()=>{D(N)},[N]);let E=sq(new Map);SD(()=>{for(let[Z,X]of E.current)if(!M.has(Z))X.source?.close();E.current=M},[M]);let $=RD(async(Z)=>{try{let X=await F.writeFile(Z),Q=await createImageBitmap(Z).catch(()=>null);return A((K)=>L8(K,X,Q?FF("loaded",Q):FF("error"))),X}catch{return null}}),Y=bD(()=>M.size===0?null:{images:M},[M]);return bD(()=>({resources:Y,persistImage:$}),[Y,$])}async function oq(N,F){try{let M=await F.readFile(N);return M?await createImageBitmap(M):null}catch{return null}}function L8(N,F,M){let A=new Map(N);return A.set(F,M),A}function FF(N,F){return{intrinsicHeight:F?.height??0,intrinsicWidth:F?.width??0,source:F??null,status:N}}import{useEffect as fD,useEffectEvent as B0,useRef as MF,useState as nq}from"react";var tq=48;function mD({applyNextState:N,autoScrollDuringDrag:F,canvasRef:M,commentState:A,editorStateRef:D,editorViewportState:E,focusInput:$,onActivity:Y,readCurrentState:Z,resolvePoint:X,storage:Q}){let[K,J]=nq(null),q=MF(null),U=MF(!1),V=MF(null),G=MF(null),_=MF(null),w=p6(K,A.threads,A.liveRanges),L=K?.kind==="task-toggle"||w?.kind==="link"?"pointer":"text";fD(()=>{if(K&&K.kind!=="task-toggle"&&!w)J(null)},[K,w]),fD(()=>()=>{if(q.current!==null)window.clearTimeout(q.current)},[]);let m=B0(()=>{if(q.current!==null)window.clearTimeout(q.current),q.current=null}),W=B0(()=>{m(),q.current=window.setTimeout(()=>{if(q.current=null,!U.current)J(null)},tq)}),H=B0(()=>{if(!U.current)m(),J(null)}),B=B0((f)=>{if(!f){H();return}if(f.kind==="task-toggle"){m(),J((g)=>g?.kind==="task-toggle"&&g.listItemId===f.listItemId?g:f);return}if(f.commentThreadIndex!==null){if(!(A.threads[f.commentThreadIndex]??null)){H();return}m();let I=f.commentThreadIndex;J((c)=>c?.kind!=="task-toggle"&&c?.commentThreadIndex===I?c:f);return}if(f.kind!=="link"){H();return}m(),J((g)=>g?.kind==="link"&&g.title===f.title&&g.url===f.url&&g.startOffset===f.startOffset&&g.endOffset===f.endOffset?g:f)}),j=B0((f)=>{let g=D.current;if(!g)return null;let I=X(f);if(!I)return null;return p4(g,E.get(),I,A.liveRanges)}),T=B0((f)=>{let g=M.current;if(g&&V.current===f)g.releasePointerCapture(f)}),O=B0(()=>{V.current=null,G.current=null}),P=B0((f)=>{T(f.pointerId),O()}),C=B0((f)=>{if(_.current=f.pointerType,f.pointerType==="touch")return;let g=M.current,I=Z(),c=X(f);if(!c)return;if(j(f)?.kind==="task-toggle")return;let t=y6(I,E.get(),c);if(!g||!t)return;if(V.current=f.pointerId,Y(),g.setPointerCapture(f.pointerId),f.shiftKey)G.current=I.selection.anchor,N(x9(I,t.regionId,t.offset));else G.current={offset:t.offset,regionId:t.regionId},N(D0(I,{offset:t.offset,regionId:t.regionId}));$({offset:t.offset,regionId:t.regionId})}),z=B0((f)=>{let g=G.current,I=Z(),c=X(f);if(!c)return;if(V.current!==f.pointerId||!g){B(j(f));return}let $0=yN(I,E.get(),c,g);if(!$0)return;Y(),F(f),N(D0(I,{anchor:g,focus:$0}))}),b=B0(()=>{if(!U.current)W()}),y=B0((f)=>{let g=_.current==="touch";_.current=null;let I=j(f);if(I?.kind==="task-toggle"){let U0=Z(),v0=NM(U0,I.listItemId);if(v0)f.preventDefault(),f.stopPropagation(),Y(),N(v0);return}if(I?.kind==="link"&&(f.metaKey||f.ctrlKey)){f.preventDefault(),f.stopPropagation(),Q.openFile(I.url);return}if(!g){$();return}let c=Z(),$0=X(f),t=$0?y6(c,E.get(),$0):null;if(t)Y(),N(D0(c,{offset:t.offset,regionId:t.regionId})),$({offset:t.offset,regionId:t.regionId});else $()}),S=B0((f)=>{let g=Z(),I=X(f),c=j(f);if(!I||c?.kind==="task-toggle")return;let $0=u4(g,E.get(),I);if(!$0)return;f.preventDefault(),f.stopPropagation(),Y(),N(D0(g,$0)),$()}),R=B0(()=>{U.current=!0,m()}),k=B0(()=>{U.current=!1,W()});return{canvasHandlers:{onClick:y,onDoubleClick:S,onPointerCancel:P,onPointerDown:C,onPointerLeave:b,onPointerMove:z,onPointerUp:P},cursor:L,leaf:w,leafHandlers:{onPointerEnter:R,onPointerLeave:k}}}import{useEffect as j8,useEffectEvent as q0,useLayoutEffect as eq,useRef as hD,useState as NU}from"react";import{useEffect as xf1}from"react";var w8=[{key:"Backspace",command:"deleteBackward"},{key:"Enter",shiftKey:!0,command:"insertSoftLineBreak"},{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:"toggleCode"},{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 kD(N,F=w8){return F.find((M)=>{let A=M.shiftKey==="any"?!0:(M.shiftKey??!1)===(N.shiftKey??!1);return M.key.toLowerCase()===N.key.toLowerCase()&&(M.altKey??!1)===(N.altKey??!1)&&A&&(M.modKey??!1)===Boolean(N.metaKey||N.ctrlKey)})?.command??null}var FU=1024,gD=16;function pD({applyNextState:N,editorState:F,editorStateRef:M,editorViewportState:A,inputRef:D,keybindings:E,onActivity:$,onImagePaste:Y}){let Z=MU(),X=()=>M.current??F,Q=hD(!1),K=hD(!1),J=q0((z)=>{if(!z)return;$(),N(z)}),q=q0(()=>{let z=D.current;if(!z)return;if(typeof document>"u")return;let b=document.execCommand;if(typeof b!=="function")return;try{Q.current=!0,b.call(document,"insertText",!1,""),b.call(document,"delete")}catch{}finally{Q.current=!1,AF(z,X())}}),U=q0(()=>{if(K.current)return;K.current=!0,q()}),V=q0(()=>{q()}),G=q0((z)=>{let b=D.current;if(!b)return;let y=A.get(),S=B1(X(),y,z);if(!S)return;b.style.top=`${S.top}px`,b.style.left=`${S.left}px`,b.style.height=`${S.height}px`}),_=q0((z)=>{let b=D.current;if(!b)return;G(z??X().selection.focus),b.focus({preventScroll:!Z}),AF(b,X()),U()}),w=q0((z,b)=>{let S=uD(b,x6(z)).replace(/\r\n/g,`
|
|
33
|
+
`).split(/(\n)/),R=z;for(let k of S){if(k.length===0)continue;let f=k===`
|
|
34
|
+
`?rF(R):XN(R,k);if(!f)continue;R=f}return R===z?null:R}),L=q0((z,b,y,S)=>{let R=z.selection.focus,k=Math.max(0,R.offset-y),f={regionId:R.regionId,offset:k},g={regionId:R.regionId,offset:Math.max(0,k-b)},I=D0(z,{anchor:g,focus:f});return sF(I,S)}),m=q0((z)=>{if(Q.current)return;let b=X(),y=EU(z.inputType);if(z.inputType==="insertText"){if(!z.data)return;z.preventDefault();let S=ID(z.target);if(S.charsToReplace>0){J(L(b,S.charsToReplace,S.trailingOffset,z.data));return}let R=DU(b,z.data);if(R>0){let k=z.data.slice(R);if(k.length>0)J(w(b,k));return}J(w(b,z.data));return}if(z.inputType==="insertReplacementText"){if(!z.data)return;z.preventDefault();let S=ID(z.target);J(L(b,S.charsToReplace,S.trailingOffset,z.data));return}if(AU(z.inputType)){z.preventDefault(),J(rF(b));return}if(y==="backward"){z.preventDefault(),J(V4(b));return}if(y==="forward"){z.preventDefault(),J(G4(b));return}if(z.inputType==="historyUndo"){z.preventDefault(),J(_4(b)),V();return}if(z.inputType==="historyRedo"){z.preventDefault(),J(H4(b)),V();return}}),W=q0((z)=>{let b=X(),y=z.currentTarget.value,S=x6(b);if(Q.current)return;if(uD(y,S).length===0){AF(z.currentTarget,b);return}J(w(b,y))}),H=q0((z)=>{let b=YU(X(),A.get(),z.nativeEvent,E);if(!b)return;z.preventDefault(),J(b)}),B=q0((z)=>{let b=z4(X());if(!b)return;z.preventDefault(),z.clipboardData.setData("text/plain",g6(b))}),j=q0((z)=>{let b=X(),y=z4(b);if(!y)return;z.preventDefault(),z.clipboardData.setData("text/plain",g6(y)),J(U4(b))}),T=q0(async(z)=>{let y=(Y?[...z.clipboardData.items].find((k)=>k.kind==="file"&&k.type.startsWith("image/")):void 0)?.getAsFile()??null;if(y&&Y){z.preventDefault();let k=await Y(y);if(k)J(s9(X(),k));return}let S=z.clipboardData.getData("text/plain");if(S.length===0)return;if(/^https?:\/\//.test(S)){let k=r9(X(),S);if(k){z.preventDefault(),J(k);return}}z.preventDefault();let R=$8(S);J(p9(X(),R,S))}),O=q0(()=>{$();let z=D.current;if(z)AF(z,X())}),P=q0((z)=>{if($(),z.target.matches(":focus-visible"))_()});j8(()=>{let z=D.current;if(!z)return;AF(z,F)},[F,D]),eq(()=>{G(F.selection.focus)},[F]),j8(()=>{let z=D.current;if(!z)return;let b=(y)=>m(y);return z.addEventListener("beforeinput",b),()=>z.removeEventListener("beforeinput",b)},[D]);let C={onCopy:B,onCut:j,onPaste:T,...Z?{}:{onKeyDown:H}};return{canvasHandlers:{...C,onFocus:P},focus:_,inputHandlers:{...C,onFocus:O,onInput:W}}}var xD="";function MU(){let[N,F]=NU(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function")return!1;return window.matchMedia("(pointer: coarse)").matches});return j8(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function")return;let M=window.matchMedia("(pointer: coarse)"),A=(D)=>F(D.matches);return M.addEventListener?.("change",A),()=>M.removeEventListener?.("change",A)},[]),N}function AU(N){return N==="insertLineBreak"||N==="insertParagraph"}function ID(N){let F=N,M=F?.selectionStart??0,A=F?.selectionEnd??M,D=F?.value.length??A;return{charsToReplace:Math.max(0,A-M),trailingOffset:Math.max(0,D-A)}}function DU(N,F){if(F.length<gD)return 0;let M=x6(N,F.length),A=Math.min(M.length,F.length);for(let D=A;D>=gD;D--)if(M.endsWith(F.slice(0,D)))return D;return 0}function EU(N){switch(N){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 $U(N){return N.replaceAll(xD,"")}function x6(N,F=FU){let{anchor:M,focus:A}=N.selection;if(M.regionId!==A.regionId||M.offset!==A.offset)return"";let D=N.documentIndex.regionIndex.get(A.regionId);if(!D)return"";return D.text.slice(Math.max(0,A.offset-F),A.offset)}function uD(N,F){let M=$U(N);return M.startsWith(F)?M.slice(F.length):M}function AF(N,F){let M=x6(F),A=`${xD}${M}`;N.value=A,N.setSelectionRange(A.length,A.length),N.scrollLeft=N.scrollWidth}function YU(N,F,M,A){if(M.key==="Delete")return G4(N);let D=kD(M,A);if(D){if(D==="moveToLineStart"||D==="moveToLineEnd")return r4(N,F.layout,D==="moveToLineStart"?"Home":"End",M.shiftKey);if(D==="moveToDocumentStart"||D==="moveToDocumentEnd")return s4(N,D==="moveToDocumentStart"?"start":"end",M.shiftKey);switch(D){case"insertLineBreak":return rF(N);case"insertSoftLineBreak":return u9(N);case"deleteBackward":return V4(N);case"indent":return o9(N);case"dedent":return n9(N);case"moveListItemUp":return t9(N);case"moveListItemDown":return e9(N);case"toggleBold":return iF(N);case"toggleItalic":return oF(N);case"toggleStrikethrough":return nF(N);case"toggleUnderline":return tF(N);case"toggleCode":return d9(N);case"undo":return _4(N);case"redo":return H4(N);case"selectAll":return l9(N)}}if(M.key==="ArrowLeft"||M.key==="ArrowRight")return d4(N,M.key==="ArrowLeft"?-1:1,M.shiftKey);if(M.key==="ArrowUp"||M.key==="ArrowDown")return c4(N,F.layout,M.key==="ArrowUp"?-1:1,M.shiftKey);if(M.key==="PageUp"||M.key==="PageDown")return a4(N,F.layout,M.key==="PageUp"?-1:1,M.shiftKey);if(M.key.length===1&&!M.altKey&&!M.ctrlKey&&!M.metaKey)return XN(N,M.key);return null}import{useEffectEvent as C8,useLayoutEffect as ZU,useMemo as XU,useState as QU}from"react";function lD({editorState:N,editorStateRef:F,editorViewportState:M,onViewportScroll:A,scrollContainerRef:D,scheduleOverlayRender:E,userPresence:$}){let Y=XU(()=>{if(!$||$.length===0)return;return OF(N.documentIndex,$)},[N.documentIndex,$]),[Z,X]=QU(void 0),Q=C8(()=>{if(Y===void 0){if(Z!==void 0)X(void 0)}else X(x2(F.current??N,M.get(),Y));E()}),K=C8((q)=>{if(Y===void 0){if(Z!==void 0)X(void 0);return}let U=x2(F.current??N,q,Y);if(JU(Z,U))return;X(U)});ZU(()=>{Q()},[Y]);let J=C8((q)=>{if(!q.viewport||q.viewport.status==="unresolved")return;let U=D.current;if(!U)return;U.scrollTop=q.viewport.scrollTop,A(U)});return{presence:Z,scrollToPresence:J,refreshPresence:K}}function JU(N,F){if(N===F)return!0;if(N===void 0||F===void 0||N.length!==F.length)return!1;return N.every((M,A)=>{let D=F[A];return M.id===D.id&&KU(M.viewport,D.viewport)})}function KU(N,F){if(N===F)return!0;if(N===null||F===null)return!1;if(N.status==="unresolved")return F.status==="unresolved";if(F.status==="unresolved")return!1;return N.status===F.status&&N.scrollTop===F.scrollTop}import{useEffect as qU,useEffectEvent as o1,useRef as DF}from"react";function dD({editorStateRef:N,renderContent:F,renderOverlay:M,renderViewport:A}){let D=DF(null),E=DF(!1),$=DF(!1),Y=DF(!1),Z=DF(!1),X=o1(()=>{if(typeof window>"u"){A();return}E.current=!0,q()}),Q=o1(()=>{if(typeof window>"u"){F(),M();return}$.current=!0,q()}),K=o1(()=>{if(typeof window>"u"){F();return}Y.current=!0,q()}),J=o1(()=>{if(typeof window>"u"){M();return}Z.current=!0,q()}),q=o1(()=>{if(typeof window>"u"||D.current!==null)return;D.current=window.requestAnimationFrame(()=>{U()})}),U=o1(()=>{D.current=null;let G=E.current,_=$.current,w=Y.current,L=Z.current;if(E.current=!1,$.current=!1,Y.current=!1,Z.current=!1,G){A(),V();return}if(_){F(),M(),V();return}if(w)F(),V();if(L)M()}),V=o1(()=>{let G=N.current;if(!G||!c3(G,performance.now()))return;Y.current=!0,q()});return qU(()=>{return()=>{if(typeof window>"u"||D.current===null)return;window.cancelAnimationFrame(D.current),D.current=null}},[]),{scheduleContentPaint:K,scheduleFullPaint:Q,scheduleFullRender:X,scheduleOverlayPaint:J}}import{useEffectEvent as S8,useLayoutEffect as oD,useMemo as R8,useRef as b8,useState as nD}from"react";function sD(N){let F=UU(N);if(F.start.regionId!==F.end.regionId||F.start.offset===F.end.offset)return null;return{endOffset:F.end.offset,regionId:F.start.regionId,startOffset:F.start.offset}}var cD=28,aD=18;function iD(N,F){if(!N)return;let M=N.getBoundingClientRect();if(F.clientY<M.top+cD){N.scrollTop=Math.max(0,N.scrollTop-aD);return}if(F.clientY>M.bottom-cD)N.scrollTop+=aD}function UU(N){let F=rD(N.documentIndex.regions,N.selection.anchor.regionId,N.selection.anchor.offset),M=rD(N.documentIndex.regions,N.selection.focus.regionId,N.selection.focus.offset);return F<=M?{end:N.selection.focus,start:N.selection.anchor}:{end:N.selection.anchor,start:N.selection.focus}}function rD(N,F,M){let A=N.findIndex((D)=>D.id===F);if(A===-1)return-1;return A*1e6+M}function tD({applyNextState:N,autoScrollDuringDrag:F,canShowSelectionLeaf:M,editorState:A,editorStateRef:D,editorViewportState:E,focusInput:$,onActivity:Y,resolvePoint:Z,threads:X}){let Q=R8(()=>N0(A),[A]),K=R8(()=>sD(A),[A]),J=R8(()=>bF(A),[A]),[q,U]=nD(null),[V,G]=nD(null),_=b8(null),w=b8(null),L=b8(null);oD(()=>{let T=VU(A,E.get(),Q);U((O)=>WU(O,T)?O:T)},[A,E,Q.end.offset,Q.end.regionId,Q.start.offset,Q.start.regionId]),oD(()=>{let T=_U({canShowSelectionLeaf:M,currentLeaf:V,activeMarks:J,handles:q,selectionRange:K,threads:X});G((O)=>BU(O,T)?O:T)},[J,M,q,V,K,X]);let m=S8((T,O=!0)=>{let P=D.current??A,C=S0(P).comments[T];if(!C)return;G((z)=>z?.kind==="annotation"?{anchor:z.anchor,animateInitialComment:O,kind:"thread",leftOverride:z.leftOverride,link:null,paddingY:z.paddingY,resolved:M1(C),thread:C,threadIndex:T}:z)}),W=S8((T)=>{if(T&&L.current===T.pointerId&&T.currentTarget.hasPointerCapture(T.pointerId))T.currentTarget.releasePointerCapture(T.pointerId);_.current=null,w.current=null,L.current=null}),H=S8((T)=>{let O=D.current,P=w.current,C=Z(T);if(!C||!O||!P||L.current!==T.pointerId)return;let z=yN(O,E.get(),C,P);if(!z)return;T.preventDefault(),T.stopPropagation(),Y(),F(T),N(D0(O,{anchor:P,focus:z}))}),B=(T)=>({onPointerCancel:(O)=>{W(O)},onPointerDown:(O)=>{let P=D.current??A,C=OU(Q,T),z=T==="start"?Q.start:Q.end;if(!q)return;O.preventDefault(),O.stopPropagation(),L.current=O.pointerId,w.current=C,_.current=T,O.currentTarget.setPointerCapture(O.pointerId),Y(),$(),N(D0(P,{anchor:C,focus:z}))},onPointerMove:(O)=>{if(_.current!==T)return;H(O)},onPointerUp:(O)=>{if(_.current===T)H(O);W(O)}});return{handle:q?{start:{...q.start,props:B("start")},end:{...q.end,props:B("end")}}:null,leaf:V,promoteLeafToThread:m}}function VU(N,F,M){if(M.collapsed)return null;let A=B1(N,F,M.start),D=B1(N,F,M.end);if(!A||!D)return null;return{end:{left:D.left,top:D.top+D.height},start:{left:A.left,top:A.top}}}var GU=2;function zU(N,F,M){return{activeMarks:M,anchor:{regionId:N.regionId,offset:N.endOffset},kind:"annotation",leftOverride:F.start.left,paddingY:GU,selection:N}}function _U({activeMarks:N,canShowSelectionLeaf:F,currentLeaf:M,handles:A,selectionRange:D,threads:E}){if(!F||!D||!A)return null;if(M?.kind==="thread"){let $=E[M.threadIndex];if(!$)return null;let Y=M1($);if(M.thread===$&&M.resolved===Y)return M;return{...M,resolved:Y,thread:$}}return zU(D,A,N)}function HU(N,F){return N?.kind==="annotation"&&eN(N,F)&&N.selection.regionId===F.selection.regionId&&N.selection.startOffset===F.selection.startOffset&&N.selection.endOffset===F.selection.endOffset&&yU(N.activeMarks,F.activeMarks)}function BU(N,F){if(N===F)return!0;if(!N||!F||N.kind!==F.kind)return!1;if(N.kind==="annotation"&&F.kind==="annotation")return HU(N,F);return N.kind==="thread"&&F.kind==="thread"&&eN(N,F)&&N.animateInitialComment===F.animateInitialComment&&N.thread===F.thread&&N.threadIndex===F.threadIndex}function WU(N,F){if(N===F)return!0;if(!N||!F)return!1;return N.start.left===F.start.left&&N.start.top===F.start.top&&N.end.left===F.end.left&&N.end.top===F.end.top}function yU(N,F){return N.length===F.length&&N.every((M,A)=>M===F[A])}function OU(N,F){return F==="start"?N.end:N.start}import{useEffect as PU,useMemo as FE,useState as TU}from"react";var EF={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)"},$F={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)"},eD={...EF,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)"},NE={...$F,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 ME(N){let F=FE(()=>wU(N),[N]),[M,A]=TU(F.light),D=FE(()=>jU(M),[M]);return PU(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function"){A(F.light);return}let E=window.matchMedia("(prefers-color-scheme: dark)"),$=()=>{A(E.matches?F.dark:F.light)};if($(),typeof E.addEventListener==="function")return E.addEventListener("change",$),()=>{E.removeEventListener("change",$)};return E.addListener($),()=>{E.removeListener($)}},[F]),{theme:M,themeStyles:D}}function LU(N){return"light"in N&&"dark"in N}function wU(N){if(!N)return{dark:$F,light:EF};if(LU(N))return N;return{dark:N,light:N}}function jU(N){return{"--documint-background":N.background,"--documint-leaf-button-bg":N.leafButtonBackground,"--documint-leaf-button-border":N.leafButtonBorder,"--documint-leaf-button-text":N.leafButtonText,"--documint-leaf-accent":N.leafAccent,"--documint-leaf-bg":N.leafBackground,"--documint-leaf-border":N.leafBorder,"--documint-leaf-font-family":'"Avenir Next", "Segoe UI", sans-serif',"--documint-leaf-shadow":N.leafShadow??void 0,"--documint-leaf-secondary-text":N.leafSecondaryText,"--documint-leaf-resolved-bg":N.leafResolvedBackground,"--documint-leaf-resolved-border":N.leafResolvedBorder,"--documint-leaf-text":N.leafText,"--documint-mention-bg":N.mentionBackground??void 0,"--documint-mention-text":N.mentionText??void 0,"--documint-selection-handle-bg":N.selectionHandleBackground,"--documint-selection-handle-border":N.selectionHandleBorder}}import{useEffect as SU,useEffectEvent as X1,useRef as v8,useState as l6}from"react";import{useRef as AE}from"react";function DE(N){let F=AE(N);F.current=N;let M=AE(null);if(M.current===null)M.current=CU({current:null},()=>F.current());return M.current}function CU(N,F){return{peek(){return N.current},get(){let M=N.current;if(M!==null)return M;let A=F();return N.current=A,A},invalidate(){N.current=null}}}function EE(N,F){let M=F.getBoundingClientRect();return{x:N.clientX-M.left+F.scrollLeft,y:N.clientY-M.top+F.scrollTop}}function $E({editorState:N,editorStateRef:F,renderResources:M,theme:A}){let D=v8(p1()),E=v8(null),$=v8({height:240,top:0}),[Y,Z]=l6(0),[X,Q]=l6(240),[K,J]=l6(0),[q,U]=l6(240),V=RU(Y),_=DE(()=>{let P=F.current??N,C=$.current;return I4(P,{height:C.height,paddingX:A.paddingX,paddingY:A.paddingY,top:C.top,width:V},D.current,M)}),w=X1((P)=>{U((C)=>{let z=vU(P,$.current.height);return C===z?C:z})}),L=X1((P)=>{$.current={...$.current,top:P},J((C)=>C===P?C:P),_.invalidate()}),m=X1((P)=>{let C=bU(P),z=C.top!==$.current.top;if($.current=C,J((b)=>b===C.top?b:C.top),z)_.invalidate()}),W=X1((P)=>{let C=E.current;if(!C)return L(P),P;C.scrollTop=P;let z=C.scrollTop;return L(z),z}),H=X1(()=>{return E.current?.scrollTop??$.current.top}),B=X1((P,C)=>{let z=P!==null&&P.documentIndex!==C.documentIndex,b=_.peek();if(!(!z||!b||b.layout.regionLineIndices.has(C.selection.focus.regionId)))_.invalidate()}),j=X1(()=>{_.invalidate()}),T=X1((P)=>{let C=E.current;return C?EE(P,C):null}),O=X1((P)=>{iD(E.current,P)});return SU(()=>{let P=E.current;if(!P||typeof ResizeObserver>"u")return;let C=new ResizeObserver((z)=>{let b=z[0];if(!b)return;let y=Math.max(0,Math.floor(b.contentRect.width)),S=YE(P);$.current={...$.current,height:S},Z((R)=>R===y?R:y),Q((R)=>R===S?R:S)});return C.observe(P),()=>C.disconnect()},[E]),{actions:{autoScrollDuringDrag:O,getScrollTop:H,invalidatePreparedLayout:j,observePreparedViewport:w,observeScrollContainer:m,reconcileEditorState:B,resolvePoint:T,scrollTo:W},props:{scrollContent:{style:{height:`${q}px`}}},refs:{scrollContainer:E},state:{layoutWidth:V,preparedViewport:_,scrollContentHeight:q,viewportHeight:X,viewportTop:K}}}function RU(N){return Math.max(240,Math.floor(N||480))}function YE(N){return Math.max(240,N.clientHeight)}function bU(N){return{height:YE(N),top:N.scrollTop}}function vU(N,F){return Math.max(F,Math.ceil(N.totalHeight+24))}function fU(){if(typeof window>"u")return 1;return Math.max(1,window.devicePixelRatio||1)}function f8(N,{paintHeight:F,paintTop:M,width:A}){if(!N)return null;let D=Math.max(240,Math.ceil(F)),E=fU();N.width=Math.ceil(A*E),N.height=Math.ceil(D*E),N.style.width=`${A}px`,N.style.height=`${D}px`,N.style.transform=`translateY(${M}px)`;let $=N.getContext("2d");if(!$)return null;return{context:$,devicePixelRatio:E,height:D,width:A}}function ZE(N,F){if(!F?.length||!N?.length)return;let M=new Map(N.map((D)=>[D.id,D])),A=[];for(let D of F){let E=M.get(D.userId);if(!E)continue;A.push({...E,color:D.color,cursor:D.cursor})}return A.length===0?void 0:A}var XE=/^(https?:|data:|blob:)/i;class m8{storage;view;constructor(N,F){this.storage=N;this.view=F}async readFile(N){if(XE.test(N))try{let F=await fetch(N);return F.ok?F.blob():null}catch{return null}return this.storage?.readFile(N)??null}writeFile(N){if(!this.storage?.writeFile)throw Error("No storage configured");return this.storage.writeFile(N)}openFile(N){if(XE.test(N))this.view?.open(N,"_blank","noopener,noreferrer");else this.storage?.openFile?.(N)}}function JE(N,F){if(!N)return{didReconcile:!1,state:F};let M=mU(N,F)??dU(N,F);return M?{didReconcile:!0,state:M}:{didReconcile:!1,state:F}}function mU(N,F){let M=kU(N,F);return M?D0(F,M,!1):null}function kU(N,F){if(g8(N.selection.anchor,N.selection.focus)){let E=k8(N,F,N.selection.focus,"neutral");return E?{anchor:E,focus:E}:null}let M=xU(N),A=k8(N,F,N.selection.anchor,M.anchor),D=k8(N,F,N.selection.focus,M.focus);return A&&D?{anchor:A,focus:D}:null}function k8(N,F,M,A){let D=N.documentIndex.regionIndex.get(M.regionId);if(!D)return null;let E=h8(D,F);if(!E)return null;return{offset:gU(D.text,E.text,M.offset,A),regionId:E.id}}function h8(N,F){let M=F.documentIndex.regionIndex.get(N.id);if(M)return M;if(N.text.length===0)return null;let A=hU(N,F);if(A)return A;return F.documentIndex.regionPathIndex.get(N.path)??null}function hU(N,F){let M=null;for(let A of F.documentIndex.regions){if(A.blockType!==N.blockType||A.text!==N.text)continue;if(M)return null;M=A}return M}function gU(N,F,M,A){let D=k0(M,0,N.length),{prefix:E,suffix:$}=K3(N,D,D),Y=IU(F,E,$);if(Y!==null)return Y;let Z=uU(F,E),X=pU(F,$);if(A==="before-suffix")return X??Z??k0(M,0,F.length);return Z??X??k0(M,0,F.length)}function IU(N,F,M){let A=A2(N,F,M).filter((D)=>D.startOffset===D.endOffset);return A.length===1?A[0].startOffset:null}function uU(N,F){let M=i0(N,F);return M.length===1?M[0]+F.length:null}function pU(N,F){let M=i0(N,F);return M.length===1?M[0]:null}function xU(N){let{anchor:F,focus:M}=N.selection;if(g8(F,M))return{anchor:"neutral",focus:"neutral"};return lU(N,F,M)<=0?{anchor:"before-suffix",focus:"after-prefix"}:{anchor:"after-prefix",focus:"before-suffix"}}function lU(N,F,M){let A=N.documentIndex.regionOrderIndex.get(F.regionId),D=N.documentIndex.regionOrderIndex.get(M.regionId);if(A===void 0||D===void 0)return 0;return A===D?F.offset-M.offset:A-D}function dU(N,F){if(!g8(N.selection.anchor,N.selection.focus))return null;let M=cU(N);if(!M)return null;let A=aU(N,F,M);if(A===null)return null;return rU(F,A)}function cU(N){let F=N.documentIndex.regionIndex.get(N.selection.focus.regionId);if(!F||F.blockType!=="paragraph"||F.text.length>0)return null;return N.documentIndex.blockIndex.get(F.blockId)?.parentBlockId===null?F:null}function aU(N,F,M){let A=QE(N,M.rootIndex,"before"),D=QE(N,M.rootIndex,"after"),E=A?h8(A,F):null,$=D?h8(D,F):null;if(E&&$)return E.rootIndex<$.rootIndex?$.rootIndex:null;if(E)return E.rootIndex+1;if($)return $.rootIndex;return null}function rU(N,F){let M=m1(N.documentIndex.document,F,0,[s({text:""})]),A={...N,documentIndex:$2(N.documentIndex,M,F,0)},D=o2(A.documentIndex,e(F));return D?D0(A,D,!1):null}function QE(N,F,M){let A=M==="before"?-1:1;for(let D=F+A;D>=0&&D<N.documentIndex.roots.length;D+=A){let E=sU(N,D,M);if(E)return E}return null}function sU(N,F,M){let A=N.documentIndex.roots[F]?.regions??[],D=M==="before"?A.length-1:0,E=M==="before"?-1:1;for(let $=D;$>=0&&$<A.length;$+=E){let Y=A[$];if(Y&&Y.text.length>0)return Y}return null}function g8(N,F){return N.regionId===F.regionId&&N.offset===F.offset}import{jsx as d,jsxs as c6,Fragment as MV}from"react/jsx-runtime";function a6({blocks:N}){return d(MV,{children:N.map((F)=>iU(F))})}function iU(N){switch(N.type){case"blockquote":return d("blockquote",{className:"preview-block preview-block-blockquote",children:d(a6,{blocks:N.children})},N.id);case"code":return c6("div",{className:"preview-block preview-block-code",children:[d("div",{className:"preview-rich-header",children:tU(N.language,N.meta)}),d("pre",{children:d("code",{children:N.source||" "})})]},N.id);case"heading":{let F=`h${N.depth}`;return d(F,{className:"preview-block preview-block-heading",children:d6(N.children)},N.id)}case"list":return N.ordered?d("ol",{className:"preview-block preview-block-list",start:N.start??1,children:N.items.map((F)=>I8(F))},N.id):d("ul",{className:"preview-block preview-block-list",children:N.items.map((F)=>I8(F))},N.id);case"listItem":return I8(N);case"paragraph":return d("p",{className:"preview-block preview-block-paragraph",children:d6(N.children)},N.id);case"table":return c6("div",{className:"preview-block preview-block-table",children:[d("div",{className:"preview-rich-header",children:eU(N.rows.length,N.rows[0]?.cells.length??0,N.align.filter((F)=>F!==null).length)}),d("div",{className:"preview-table-scroll",children:d("table",{children:d("tbody",{children:N.rows.map((F)=>d("tr",{children:F.cells.map((M)=>d("td",{children:d6(M.children)},M.id))},F.id))})})})]},N.id);case"divider":return d("hr",{className:"preview-block preview-block-rule"},N.id);case"directive":return d("pre",{className:`preview-block preview-block-directive preview-block-directive-${N.name}`,children:N.body},N.id);case"raw":return d("pre",{className:"preview-block preview-block-unsupported",children:N.source},N.id)}}function I8(N){return d("li",{className:"preview-block preview-block-list-item",children:d(a6,{blocks:N.children})},N.id)}function d6(N){return N.map((F)=>{switch(F.type){case"lineBreak":return d("br",{},F.id);case"image":return c6("span",{className:"preview-inline preview-inline-image",children:[d("img",{alt:F.alt??"",src:F.url,title:F.title??""}),c6("span",{children:[d("strong",{children:NV(F.alt)}),d("small",{children:FV(F.url,F.title)})]})]},F.id);case"code":return d("code",{className:"preview-inline preview-inline-code",children:F.code},F.id);case"link":return oU(F);case"text":return d("span",{className:"preview-inline",children:nU(F.text,F.marks)},F.id);case"raw":return d("span",{className:"preview-inline preview-inline-unsupported",children:F.source},F.id)}})}function oU(N){return d("a",{className:"preview-inline preview-inline-link",href:N.url,children:d6(N.children)},N.id)}function nU(N,F){let M=N;for(let A of F)switch(A){case"strikethrough":M=d("del",{children:M});break;case"italic":M=d("em",{children:M});break;case"bold":M=d("strong",{children:M});break;case"underline":M=d("ins",{children:M});break}return M}function tU(N,F){return[N??"plain text",F].filter(Boolean).join(" • ")}function eU(N,F,M){let A=M>0?`${M} aligned ${M===1?"column":"columns"}`:"no alignment";return`${N} ${N===1?"row":"rows"} • ${F} ${F===1?"column":"columns"} • ${A}`}function NV(N){return N?.trim()?N:"Untitled image"}function FV(N,F){return F?.trim()?`${F} • ${N}`:N}var KE=`/* Base Documint host and SSR-fallback styles. */
|
|
36
35
|
|
|
37
36
|
.documint {
|
|
38
37
|
display: grid;
|
|
@@ -368,7 +367,7 @@ ${Y.text}`:Y.text}function nK($){return $.filter((Y)=>Y.regions.length>0).map((Y
|
|
|
368
367
|
white-space: nowrap;
|
|
369
368
|
}
|
|
370
369
|
}
|
|
371
|
-
`;var
|
|
370
|
+
`;var qE=`/* Leaf overlay styles, ordered outer → inner:
|
|
372
371
|
1. Anchor — viewport positioning + hover bridge
|
|
373
372
|
2. Shell — bordered container (with state and content variants)
|
|
374
373
|
3. Menu — shared dropdown surface (toolbar menus, completion popover)
|
|
@@ -383,25 +382,61 @@ ${Y.text}`:Y.text}function nK($){return $.filter((Y)=>Y.regions.length>0).map((Y
|
|
|
383
382
|
|
|
384
383
|
/* -- Anchor: positioned wrapper rendered by LeafAnchor (via OverlayPortal) -- */
|
|
385
384
|
|
|
385
|
+
/* \`--documint-leaf-anchor-height\`, \`--documint-leaf-bridge-height\`, and
|
|
386
|
+
\`--documint-leaf-padding-y\` are JS-owned (set inline by \`LeafAnchor\`).
|
|
387
|
+
\`position: absolute\` against the initial containing block lets the
|
|
388
|
+
browser move the leaf with host-page scrolls naturally. */
|
|
386
389
|
.documint-leaf-anchor {
|
|
387
|
-
|
|
388
|
-
position: fixed;
|
|
390
|
+
position: absolute;
|
|
389
391
|
z-index: 1000;
|
|
390
|
-
padding-top: var(--documint-leaf-anchor-bridge-height);
|
|
391
|
-
margin-top: calc(var(--documint-leaf-anchor-bridge-height) * -1);
|
|
392
|
-
pointer-events: auto;
|
|
393
392
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
393
|
+
/* Hover: wrapper occupies the bridge gap so the bridge child can hand
|
|
394
|
+
off pointer events between anchor row and shell. */
|
|
395
|
+
&[data-bridge="true"] {
|
|
396
|
+
padding-top: var(--documint-leaf-bridge-height);
|
|
397
|
+
margin-top: calc(var(--documint-leaf-bridge-height) * -1);
|
|
398
|
+
pointer-events: auto;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
/* Bridgeless (cursor + selection): wrapper is pointer-event-transparent
|
|
402
|
+
so canvas gestures pass through the gap area to the underlying canvas.
|
|
403
|
+
The shell carries the visual gap via its own margin-top below. */
|
|
404
|
+
&[data-bridge="false"] {
|
|
398
405
|
pointer-events: none;
|
|
399
406
|
}
|
|
407
|
+
|
|
408
|
+
/* Above-flip: render the bridge below the shell (column-reverse) and
|
|
409
|
+
translate up by the anchor row's height + paddingY so the shell sits
|
|
410
|
+
a bridge-height gap above the anchor — symmetric with below-mode. */
|
|
411
|
+
&[data-placement="above"] {
|
|
412
|
+
padding-top: 0;
|
|
413
|
+
margin-top: 0;
|
|
414
|
+
display: flex;
|
|
415
|
+
flex-direction: column-reverse;
|
|
416
|
+
transform: translateY(calc(
|
|
417
|
+
-100%
|
|
418
|
+
- var(--documint-leaf-anchor-height, 0px)
|
|
419
|
+
- var(--documint-leaf-padding-y, 0px)
|
|
420
|
+
));
|
|
421
|
+
}
|
|
400
422
|
}
|
|
401
423
|
|
|
402
424
|
.documint-leaf-bridge {
|
|
403
425
|
width: 100%;
|
|
404
|
-
height: var(--documint-leaf-
|
|
426
|
+
height: var(--documint-leaf-bridge-height);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
/* Bridgeless: shell carries the gap to the anchor itself. */
|
|
430
|
+
.documint-leaf-anchor[data-bridge="false"] .documint-leaf-shell {
|
|
431
|
+
margin-top: calc(
|
|
432
|
+
var(--documint-leaf-bridge-height) + var(--documint-leaf-padding-y, 0px)
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/* Above-flip for bridgeless: the gap belongs below the shell. */
|
|
437
|
+
.documint-leaf-anchor[data-placement="above"][data-bridge="false"] .documint-leaf-shell {
|
|
438
|
+
margin-top: 0;
|
|
439
|
+
margin-bottom: var(--documint-leaf-bridge-height);
|
|
405
440
|
}
|
|
406
441
|
|
|
407
442
|
/* -- Shell: bordered, themed container that holds leaf content -- */
|
|
@@ -430,7 +465,11 @@ ${Y.text}`:Y.text}function nK($){return $.filter((Y)=>Y.regions.length>0).map((Y
|
|
|
430
465
|
padding: 0.8rem;
|
|
431
466
|
}
|
|
432
467
|
|
|
433
|
-
|
|
468
|
+
/* Comment-thread-specific resolved styling — \`data-resolved\` is set by
|
|
469
|
+
AnnotationLeaf on its own root, not by the shared shell. We target it
|
|
470
|
+
via :has() so the resolved state stays a comment concern instead of
|
|
471
|
+
leaking up into the generic LeafAnchor surface. */
|
|
472
|
+
&:has([data-resolved="true"]) {
|
|
434
473
|
border-color: var(--documint-leaf-resolved-border);
|
|
435
474
|
background: var(--documint-leaf-resolved-bg);
|
|
436
475
|
}
|
|
@@ -577,7 +616,7 @@ ${Y.text}`:Y.text}function nK($){return $.filter((Y)=>Y.regions.length>0).map((Y
|
|
|
577
616
|
}
|
|
578
617
|
}
|
|
579
618
|
|
|
580
|
-
.documint-leaf-shell[data-
|
|
619
|
+
.documint-leaf-shell:has([data-resolved="true"]) .documint-leaf-input {
|
|
581
620
|
border-color: var(--documint-leaf-resolved-border);
|
|
582
621
|
}
|
|
583
622
|
|
|
@@ -692,7 +731,7 @@ ${Y.text}`:Y.text}function nK($){return $.filter((Y)=>Y.regions.length>0).map((Y
|
|
|
692
731
|
}
|
|
693
732
|
}
|
|
694
733
|
|
|
695
|
-
.documint-leaf-shell[data-
|
|
734
|
+
.documint-leaf-shell:has([data-resolved="true"]) .documint-comment-reply {
|
|
696
735
|
border-top-color: color-mix(in srgb, var(--documint-leaf-resolved-border) 72%, transparent);
|
|
697
736
|
}
|
|
698
737
|
|
|
@@ -878,7 +917,7 @@ ${Y.text}`:Y.text}function nK($){return $.filter((Y)=>Y.regions.length>0).map((Y
|
|
|
878
917
|
font-weight: 500;
|
|
879
918
|
white-space: nowrap;
|
|
880
919
|
}
|
|
881
|
-
`;var
|
|
920
|
+
`;var UE=`/* Toolbar-specific styles (button, group, divider, and the menu trigger
|
|
882
921
|
shell + chevron). The menu container/item/divider styles themselves
|
|
883
922
|
live one level up in \`overlays/leaves/styles.css\` as \`.documint-leaf-menu*\`
|
|
884
923
|
so they can be shared by the toolbar's nested menu and other surfaces
|
|
@@ -960,6 +999,6 @@ ${Y.text}`:Y.text}function nK($){return $.filter((Y)=>Y.regions.length>0).map((Y
|
|
|
960
999
|
transform: rotate(180deg);
|
|
961
1000
|
}
|
|
962
1001
|
}
|
|
963
|
-
`;var
|
|
964
|
-
${
|
|
965
|
-
${
|
|
1002
|
+
`;var VE=`${KE}
|
|
1003
|
+
${qE}
|
|
1004
|
+
${UE}`;import{jsx as X0,jsxs as s6,Fragment as ZV}from"react/jsx-runtime";function zE({className:N,content:F,keybindings:M,onCommentChanged:A,onContentChanged:D,presence:E,storage:$,theme:Y,users:Z}){let X=f2(null),Q=f2(null),K=f2(null),J=f2(null),q=f2(F),U=f2(""),[V,G]=GE(!1),{theme:_,themeStyles:w}=ME(Y),L=N1(()=>iN(F),[F]),m=N1(()=>h6(L),[L]),[W,H]=GE(()=>AN(L)),B=N1(()=>new m8($,typeof window<"u"?window:null),[$]),j=vD(W.documentIndex.imageUrls,B),T=j.resources,O=N1(()=>[...T?.images.values()??[]].some((v)=>v.status==="loading"),[T]);J.current=W,U.current||=m;let P=$E({editorState:W,editorStateRef:J,renderResources:T,theme:_}),{actions:C,props:z,refs:b,state:y}=P,{autoScrollDuringDrag:S,getScrollTop:R,invalidatePreparedLayout:k,observePreparedViewport:f,observeScrollContainer:g,reconcileEditorState:I,resolvePoint:c,scrollTo:$0}=C,{layoutWidth:t,preparedViewport:U0,scrollContentHeight:v0,viewportHeight:Q1,viewportTop:m2}=y,{scrollContainer:k2}=b,ZF=N1(()=>SF(W),[W]),F1=N1(()=>o0(W),[W]),L0=N1(()=>N0(W),[W]),L1=N1(()=>{if(!Z?.length)return;return[{trigger:"@",items:Z.map((v)=>({label:v.fullName??v.username,id:v.id}))}]},[Z]),i6=N1(()=>ZE(Z,E),[Z,E]),XF=N1(()=>YV(W,F1.liveRanges),[F1.liveRanges,W]),n1=Boolean(D),n=()=>J.current??W,o=v2((v)=>{if(!v)return;let u=J.current??W,p=u.documentIndex!==v.documentIndex,r=hF(u,v);if(J.current=v,H(v),I(u,v),r)x8();if(!p)return;let M0=S0(v),V0=h6(M0);U.current=V0,q.current=V0,D?.(V0,M0)}),QF=(v)=>{A?.(v)},JF=(v)=>{let u=S0(n()).comments[v],p=u?.comments.at(-1);if(!u||!p)return;QF({kind:"added",comment:p,mentionedUserIds:Q8(p.body,L1),thread:u,threadIndex:v})},f0=(v,u,p)=>{let r=S0(n()).comments[v],M0=r?.comments[u];if(!r||!M0)return;QF({kind:"edited",comment:M0,previousBody:p,mentionedUserIds:Q8(M0.body,L1),thread:r,threadIndex:v})},KF=(v,u,p)=>{QF({kind:"deleted",comment:p,thread:u,threadIndex:v})},u8=v2((v=U0.peek())=>{if(!v)return;let u=f8(X.current,{paintHeight:v.paintHeight,paintTop:v.paintTop,width:t});if(!u)return;let{context:p,devicePixelRatio:r,height:M0,width:V0}=u;n4(W,v,p,{activeBlockId:ZF.block?.blockId??null,activeRegionId:W.selection.focus.regionId,activeThreadIndex:c8??XF,devicePixelRatio:r,height:M0,liveCommentRanges:F1.liveRanges,normalizedSelection:L0,now:performance.now(),resources:T,theme:_,width:V0})}),p8=v2((v=U0.peek())=>{if(!v)return;let u=f8(Q.current,{paintHeight:v.paintHeight,paintTop:v.paintTop,width:t});if(!u)return;let{context:p,devicePixelRatio:r,height:M0,width:V0}=u;t4(W,v,p,{devicePixelRatio:r,height:M0,normalizedSelection:L0,presence:UF.presence,showCaret:L0.start.regionId!==L0.end.regionId||L0.start.offset!==L0.end.offset||w1.isVisible(),theme:_,width:V0})}),_E=v2(()=>{let v=U0.get();f(v),UF.refreshPresence(v),w1.refreshCaretViewportStatus(v),u8(v),p8(v)}),{scheduleContentPaint:x8,scheduleFullPaint:HE,scheduleFullRender:o6,scheduleOverlayPaint:l8}=dD({editorStateRef:J,renderContent:u8,renderOverlay:p8,renderViewport:_E}),d8=v2((v)=>{g(v),o6()}),BE=v2((v)=>{d8(v.currentTarget)}),w1=jD({canShowInsertionLeaf:Boolean(D),canShowTableLeaf:Boolean(D),commentState:F1,editorState:W,editorViewportState:U0,getScrollTop:R,layoutWidth:t,onVisibilityChange:l8,resources:T,scrollContentHeight:v0,scrollTo:$0,viewportHeight:Q1}),WE=CD(w1.imageAtCursor,W,o),qF=pD({applyNextState:o,editorState:W,editorStateRef:J,editorViewportState:U0,inputRef:K,keybindings:M,onActivity:w1.markActivity,onImagePaste:j.persistImage}),J1=mD({applyNextState:o,autoScrollDuringDrag:S,canvasRef:X,commentState:F1,editorStateRef:J,editorViewportState:U0,focusInput:qF.focus,onActivity:w1.markActivity,readCurrentState:n,resolvePoint:c,storage:B}),c8=J1.leaf?.kind==="thread"?J1.leaf.threadIndex:null,UF=lD({editorState:W,editorStateRef:J,editorViewportState:U0,onViewportScroll:d8,scrollContainerRef:k2,scheduleOverlayRender:l8,userPresence:i6}),n6=tD({applyNextState:o,autoScrollDuringDrag:S,canShowSelectionLeaf:n1,editorState:W,editorStateRef:J,editorViewportState:U0,focusInput:qF.focus,onActivity:w1.markActivity,resolvePoint:c,threads:F1.threads}),j1=n6.handle??WE;YF(()=>{k(),o6()},[W.documentIndex,t,_,T,Q1]),YF(()=>{HE()},[L0.end.offset,L0.end.regionId,L0.start.offset,L0.start.regionId,ZF.block?.blockId]),YF(()=>{x8()},[XF,F1.liveRanges,c8]),YF(()=>{if(!O)return;let v=null,u=window,p=()=>{o6(),v=u.requestAnimationFrame(p)};return v=u.requestAnimationFrame(p),()=>{if(v!==null)u.cancelAnimationFrame(v)}},[O]);let a=J1.leaf??n6.leaf??w1.leaf,t6=(()=>{if(!a)return null;let v=B1(W,U0.get(),a.anchor);if(!v)return null;let u=v.top+v.height,p=m2+Q1;if(u<=m2||u>=p)return null;let r=k2.current?.getBoundingClientRect(),M0=typeof window<"u"?window.scrollX:0,V0=typeof window<"u"?window.scrollY:0,e6=a===J1.leaf;return{anchorHeight:v.height,bridge:e6,left:(r?.left??0)+M0+(a.leftOverride??v.left),onPointerEnter:e6?J1.leafHandlers.onPointerEnter:void 0,onPointerLeave:e6?J1.leafHandlers.onPointerLeave:void 0,paddingY:a.paddingY??0,top:(r?.top??0)+V0+u-m2}})(),yE=t6?(()=>{if(!a)return null;switch(a.kind){case"insertion":return X0(zD,{onInsert:(v)=>{o(XN(n(),v))},onInsertTable:(v)=>{o(FM(n(),v))}});case"table":return X0(PD,{canDeleteColumn:a.columnCount>1,canDeleteRow:a.rowCount>1,onDeleteColumn:()=>{o(AM(n()))},onDeleteRow:()=>{o(EM(n()))},onDeleteTable:()=>{o($M(n()))},onInsertColumn:(v)=>{o(MM(n(),v))},onInsertRow:(v)=>{o(DM(n(),v))}});case"link":return X0(yD,{canEdit:n1,onDelete:()=>{let v=a9(n(),a.regionId,a.startOffset,a.endOffset);if(v)o(v)},onSave:(v)=>{let u=c9(n(),a.regionId,a.startOffset,a.endOffset,v);if(u)o(u)},title:a.title,url:a.url});case"annotation":return X0(V8,{activeMarks:a.activeMarks,canEdit:n1,link:null,mode:"create",mentionSources:L1,onCreateThread:(v)=>{let u=n(),p=S0(u).comments.length,r=YM(u,a.selection,v.trim());if(!r)return;o(r),n6.promoteLeafToThread(p,!0),JF(p)},onToggleBold:()=>{o(iF(n()))},onToggleItalic:()=>{o(oF(n()))},onToggleStrikethrough:()=>{o(nF(n()))},onToggleUnderline:()=>{o(tF(n()))}});case"thread":return X0(V8,{animateInitialComment:a.animateInitialComment,canEdit:n1,link:a.link,mode:"thread",mentionSources:L1,onDeleteComment:(v)=>{let{threadIndex:u}=a,p=n(),r=S0(p).comments[u],M0=r?.comments[v],V0=QM(p,u,v);if(!V0)return;if(o(V0),r&&M0)KF(u,r,M0)},onDeleteThread:()=>{let{threadIndex:v}=a,u=n(),p=S0(u).comments[v],r=JM(u,v);if(!r)return;if(o(r),p)for(let M0 of p.comments)KF(v,p,M0)},onEditComment:(v,u)=>{let{threadIndex:p}=a,r=n(),M0=S0(r).comments[p]?.comments[v]?.body,V0=XM(r,p,v,u);if(!V0)return;if(o(V0),M0!==void 0)f0(p,v,M0)},onReply:(v)=>{let{threadIndex:u}=a,p=ZM(n(),u,v);if(!p)return;o(p),JF(u)},onToggleResolved:()=>{o(KM(n(),a.threadIndex,!a.resolved))},thread:a.thread})}})():null;YF(()=>{G(!0)},[]),$V(()=>{if(F===q.current)return;let v=J.current,u=JE(v,AN(L)),p=u.state,r=u.didReconcile?R():0;J.current=p,H(p),q.current=F,U.current=m,$0(r)},[m,F,L]);let OE=N?`documint ${N}`:"documint";return X0(ND,{themeStyles:w,children:s6("section",{className:OE,style:{...w,height:"100%",minHeight:0},children:[X0("style",{children:VE}),s6("div",{ref:k2,onScroll:BE,className:"documint-scroll-container",style:{height:"100%",minHeight:0},children:[X0("textarea",{...qF.inputHandlers,ref:K,autoCapitalize:"sentences",className:"documint-input",spellCheck:!1,tabIndex:-1,wrap:"off"}),X0(BA,{insetX:_.paddingX,insetY:_.paddingY,onSelect:UF.scrollToPresence,presence:UF.presence}),s6("div",{...z.scrollContent,className:"documint-scroll-content",children:[X0("canvas",{...qF.canvasHandlers,...J1.canvasHandlers,"aria-label":"Documint editor",className:"documint-content-canvas",style:{cursor:J1.cursor},ref:X,tabIndex:0}),X0("canvas",{"aria-hidden":"true",className:"documint-overlay-canvas",ref:Q}),j1&&s6(ZV,{children:[X0("div",{"aria-hidden":"true",className:"documint-resize-handle",style:{left:`${j1.start.left}px`,top:`${j1.start.top}px`},...j1.start.props,children:X0("span",{className:"documint-resize-handle-knob"})}),X0("div",{"aria-hidden":"true",className:"documint-resize-handle",style:{left:`${j1.end.left}px`,top:`${j1.end.top}px`},...j1.end.props,children:X0("span",{className:"documint-resize-handle-knob"})})]}),t6?X0(HD,{anchor:t6,children:yE}):null]}),!V?X0("div",{className:"documint-fallback",children:X0(a6,{blocks:L.blocks})}):null]})]})})}function YV(N,F){let M=new Map(N.documentIndex.regions.map((Z,X)=>[Z.id,X])),A=r6(M,N.selection.anchor.regionId,N.selection.anchor.offset),D=r6(M,N.selection.focus.regionId,N.selection.focus.offset),[E,$]=A<=D?[A,D]:[D,A],Y=A===D;for(let Z of F){let X=r6(M,Z.regionId,Z.startOffset),Q=r6(M,Z.regionId,Z.endOffset);if(Y){if(E>=X&&E<=Q)return Z.threadIndex;continue}if(Math.max(E,X)<Math.min($,Q))return Z.threadIndex}return null}function r6(N,F,M){return(N.get(F)??-1)*1e6+M}export{eD as mintTheme,NE as midnightTheme,EF as lightTheme,w8 as defaultKeybindings,$F as darkTheme,zE as Documint};
|