documint 0.0.6 → 0.0.7
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/README.md +2 -2
- package/dist/index.js +34 -34
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import{useEffect as
|
|
2
|
-
`);return{id:
|
|
3
|
-
`);return{align:$.align??[],id:
|
|
4
|
-
`;case"image":return M.alt??"";case"inlineCode":return M.code;case"link":return
|
|
5
|
-
`);case"table":return M.rows.map((
|
|
1
|
+
import{useEffect as T2,useEffectEvent as j2,useLayoutEffect as WN,useMemo as M1,useRef as I1,useState as N9}from"react";function H1($){let M=X0($.children);return{children:$.children,id:D0($.path,"paragraph",M),plainText:M,type:"paragraph"}}function x($){return H1({children:w9(void 0,$.text)})}function $5($){let M=X0($.children);return{children:$.children,depth:$.depth,id:D0($.path,"heading",`${$.depth}:${M}`),plainText:M,type:"heading"}}function Z1($){return $5({children:w9(void 0,$.text),depth:$.depth})}function i0($){let M=$.marks??[];return{id:D0($.path,"text",`${$.text}:${M.join(",")}`),marks:M,text:$.text,type:"text"}}function M5($={}){return{id:D0($.path,"break","break"),type:"break"}}function d1($){return{code:$.code,id:D0($.path,"inlineCode",$.code),type:"inlineCode"}}function r1($){return{children:$.children,id:D0($.path,"link",`${$.url}:${X0($.children)}`),title:$.title??null,type:"link",url:$.url}}function E1($){let M=$.alt??null,Z=$.width??null;return{alt:M,id:D0($.path,"image",`${$.url}:${Z??""}:${M??""}`),title:$.title??null,type:"image",url:$.url,width:Z}}function Z5($){return{id:D0($.path,"unsupported",$.source),originalType:$.originalType,source:$.source,type:"unsupported"}}function s0($){let M=B1($.children);return{checked:$.checked??null,children:$.children,id:D0($.path,"listItem",M),plainText:M,spread:$.spread??!1,type:"listItem"}}function W1($){let M=$.items.map((Z)=>Z.plainText).join(`
|
|
2
|
+
`);return{id:D0($.path,"list",`${String($.ordered)}:${M}`),items:$.items,ordered:$.ordered,plainText:M,spread:$.spread??!1,start:$.start??null,type:"list"}}function W0($){let M=B1($.children);return{children:$.children,id:D0($.path,"blockquote",M),plainText:M,type:"blockquote"}}function w8($){return{id:D0($.path,"code",`${$.language??""}:${$.source}`),language:$.language??null,meta:$.meta??null,plainText:$.source,source:$.source,type:"code"}}function J1($){let M=X0($.children);return{children:$.children,id:D0($.path,"tableCell",M),plainText:M}}function c1($){return{cells:$.cells,id:D0($.path,"tableRow",String($.cells.length))}}function y1($){let M=$.rows.map((Z)=>Z.cells.map((J)=>J.plainText).join(" | ")).join(`
|
|
3
|
+
`);return{align:$.align??[],id:D0($.path,"table",M),plainText:M,rows:$.rows,type:"table"}}function J5(){return{id:"",plainText:"",type:"thematicBreak"}}function X5($){return{id:D0($.path,"unsupported",$.source),originalType:$.originalType,plainText:$.source,source:$.source,type:"unsupported"}}function P9($){return{attributes:$.attributes,body:$.body,id:D0($.path,"directive",`${$.name}{${$.attributes}}:${$.body}`),name:$.name,plainText:$.body,type:"directive"}}function z0($){let M=[];for(let Z of $){let J=M.at(-1);if(J?.type==="text"&&Z.type==="text"&&J.marks.join(",")===Z.marks.join(",")){M[M.length-1]=i0({marks:J.marks,path:J.id,text:J.text+Z.text});continue}M.push(Z)}return M}function u0($,M){return $.type==="heading"?$5({children:M,depth:$.depth}):H1({children:M})}function j0($,M){return s0({checked:$.checked,children:M,spread:$.spread})}function e($,M,Z={}){return W1({items:M,ordered:Z.ordered??$.ordered,spread:Z.spread??$.spread,start:Z.start??$.start})}function w0($,M){return y1({align:$.align,rows:M})}function L2($,M){return w8({language:$.language,meta:$.meta,source:M})}function C2($,M){return X5({originalType:$.originalType,source:M})}function w9($,M){return M.length>0?[i0({path:$?`${$}.children.0`:void 0,text:M})]:[]}function D0($,M,Z){return $?Y0(M,$,Z):""}function a1($,M=[],Z){return{blocks:$.map((J,X)=>T8(J,X)),comments:M,frontMatter:Z}}function P1($,M,Z,J){let X=J.map((K,q)=>T8(K,M+q)),Y=$.blocks.slice(M+Z),Q=J.length===Z?Y:Y.map((K,q)=>T8(K,M+X.length+q));return{blocks:[...$.blocks.slice(0,M),...X,...Q],comments:$.comments,frontMatter:$.frontMatter}}function T9($,M,Z,J){return{blocks:$.blocks,comments:[...$.comments.slice(0,M),...J,...$.comments.slice(M+Z)],frontMatter:$.frontMatter}}function j9($,M,Z,J){if(J!==void 0)return b9($,J,M,Z);for(let X=0;X<$.blocks.length;X+=1){let Y=b9($,X,M,Z);if(Y)return Y}return null}function b9($,M,Z,J){let X=$.blocks[M];if(!X)return null;let Y=O9(X,Z,J);return Y?P1($,M,1,[Y]):null}function O9($,M,Z){if($.id===M)return Z($);switch($.type){case"blockquote":{let J=b8($.children,M,Z);return J?W0({children:J}):null}case"listItem":{let J=b8($.children,M,Z);return J?j0($,J):null}case"list":{let J=b8($.items,M,Z);return J?e($,J):null}default:return null}}function b8($,M,Z){let J=!1,X=$.map((Y)=>{let Q=O9(Y,M,Z);if(!Q)return Y;return J=!0,Q});return J?X:null}function X0($){return $.map((M)=>{switch(M.type){case"break":return`
|
|
4
|
+
`;case"image":return M.alt??"";case"inlineCode":return M.code;case"link":return X0(M.children);case"text":return M.text;case"unsupported":return M.source}}).join("")}function B1($){return $.map((M)=>{switch(M.type){case"blockquote":case"listItem":return B1(M.children);case"code":return M.source;case"directive":return M.body;case"heading":case"paragraph":return X0(M.children);case"list":return M.items.map((Z)=>Z.plainText).join(`
|
|
5
|
+
`);case"table":return M.rows.map((Z)=>Z.cells.map((J)=>J.plainText).join(" | ")).join(`
|
|
6
6
|
`);case"thematicBreak":return"";case"unsupported":return M.source}}).join(`
|
|
7
|
-
`).trim()}function
|
|
8
|
-
`);return{id:
|
|
9
|
-
`);return{align:$.align,id:Z0("table",M,Z),plainText:Z,rows:J,type:"table"}}case"thematicBreak":return{id:Z0("thematicBreak",M,"thematic-break"),plainText:"",type:"thematicBreak"};case"unsupported":return{id:Z0("unsupported",M,$.source),originalType:$.originalType,plainText:$.source,source:$.source,type:"unsupported"}}}function dZ($,M){return{cells:$.cells.map((J,Z)=>{let X=J.children.map((Q,K)=>e4(Q,`${M}.cells.${Z}.children.${K}`)),Y=q0(X);return{children:X,id:Z0("tableCell",`${M}.cells.${Z}`,Y),plainText:Y}}),id:Z0("tableRow",M,String($.cells.length))}}function e4($,M){switch($.type){case"break":return{id:Z0("break",M,"break"),type:"break"};case"image":return{alt:$.alt,id:Z0("image",M,`${$.url}:${$.width??""}:${$.alt??""}`),title:$.title,type:"image",url:$.url,width:$.width};case"inlineCode":return{code:$.code,id:Z0("inlineCode",M,$.code),type:"inlineCode"};case"link":{let J=$.children.map((X,Y)=>e4(X,`${M}.children.${Y}`)),Z=q0(J);return{children:J,id:Z0("link",M,`${$.url}:${Z}`),title:$.title,type:"link",url:$.url}}case"text":return{id:Z0("text",M,`${$.text}:${$.marks.join(",")}`),marks:$.marks,text:$.text,type:"text"};case"unsupported":return{id:Z0("unsupported",M,$.source),originalType:$.originalType,source:$.source,type:"unsupported"}}}function P2($){return $.map((M)=>{switch(M.type){case"blockquote":return{...M,children:P2(M.children)};case"heading":case"paragraph":return T0(M,H8(M.children));case"list":return{...M,items:M.items.map((J)=>({...J,children:P2(J.children)}))};case"listItem":return{...M,children:P2(M.children)};case"table":return u0(M,M.rows.map((J)=>({...J,cells:J.cells.map((Z)=>({...Z,children:H8(Z.children)}))})));default:return M}})}function H8($){let M=[...$];for(let J=M.length-1;J>=0;J-=1){let Z=M[J];if(Z.type==="text"){let X=Z.text.replace(/[ \t]+$/u,"");if(X.length===Z.text.length)return M;if(X.length===0){M.splice(J,1);continue}return M[J]={...Z,text:X},M}if(Z.type==="link"){let X=H8(Z.children);if(X.length===Z.children.length&&X.every((Y,Q)=>Y===Z.children[Q]))return M;if(X.length===0){M.splice(J,1);continue}return M[J]={...Z,children:X},M}return M}return M}function Z0($,M,J){let Z=2166136261;for(let X of`${$}:${M}:${J}`)Z^=X.charCodeAt(0),Z=Math.imul(Z,16777619);return`${$}-${(Z>>>0).toString(36)}`}function z8($,M){E8($.blocks,M,F9(),H9())}function rZ($,M){E8($,M,F9(),H9())}function x1($,M){let J=null,Z={enterBlock(X){if(X.id===M)return J=X,"stop"}};if(Array.isArray($))rZ($,Z);else z8($,Z);return J}function E8($,M,J,Z){for(let[X,Y]of $.entries()){if(J.stopped)return;let Q=`${Z.pathPrefix}.${X}`,K={blockAncestors:Z.blockAncestors,depth:Z.depth,parentBlock:Z.parentBlock,path:Q},q=M.enterBlock?.(Y,K);if(r1(q,J))return;if(q!=="skip")switch(Y.type){case"list":_9(Y.items,Y,M,J,Z,Q);break;case"blockquote":case"listItem":_9(Y.children,Y,M,J,Z,Q);break;case"heading":case"paragraph":W8(Y.children,M,J,{block:Y,blockAncestors:[...Z.blockAncestors,Y],inlineAncestors:[],parentInline:null,pathPrefix:`${Q}.children`});break;case"table":cZ(Y,M,J,{blockAncestors:[...Z.blockAncestors,Y],pathPrefix:Q});break;case"code":case"directive":case"thematicBreak":case"unsupported":break}if(J.stopped)return;if(r1(M.leaveBlock?.(Y,K),J))return}}function W8($,M,J,Z){for(let[X,Y]of $.entries()){if(J.stopped)return;let Q=`${Z.pathPrefix}.${X}`,K={block:Z.block,blockAncestors:Z.blockAncestors,inlineAncestors:Z.inlineAncestors,parentInline:Z.parentInline,path:Q},q=M.enterInline?.(Y,K);if(r1(q,J))return;if(q!=="skip"){if(Y.type==="link")xZ(Y.children,Y,M,J,Z,Q)}if(J.stopped)return;if(r1(M.leaveInline?.(Y,K),J))return}}function F9(){return{stopped:!1}}function H9(){return{blockAncestors:[],depth:0,parentBlock:null,pathPrefix:"root"}}function _9($,M,J,Z,X,Y){E8($,J,Z,{blockAncestors:[...X.blockAncestors,M],depth:X.depth+1,parentBlock:M,pathPrefix:`${Y}.children`})}function xZ($,M,J,Z,X,Y){W8($,J,Z,{block:X.block,blockAncestors:X.blockAncestors,inlineAncestors:[...X.inlineAncestors,M],parentInline:M,pathPrefix:`${Y}.children`})}function cZ($,M,J,Z){for(let[X,Y]of $.rows.entries())for(let[Q,K]of Y.cells.entries()){if(J.stopped)return;let q=`${Z.pathPrefix}.rows.${X}.cells.${Q}`,D={blockAncestors:Z.blockAncestors,cellIndex:Q,path:q,row:Y,rowIndex:X,table:$},A=M.enterTableCell?.(K,D);if(r1(A,J))return;if(A!=="skip")W8(K.children,M,J,{block:$,blockAncestors:Z.blockAncestors,inlineAncestors:[],parentInline:null,pathPrefix:`${q}.children`});if(J.stopped)return;if(r1(M.leaveTableCell?.(K,D),J))return}}function r1($,M){if($!=="stop")return!1;return M.stopped=!0,!0}var B8="text";function P8($){return $==="text"||$==="code"||$==="tableCell"}function y8($){return $===B8?void 0:$}function E9($){switch($){case"heading":case"paragraph":return"text";case"code":return"code";default:return null}}function $5($){let M=[];return z8($,{enterBlock(J){switch(J.type){case"heading":case"paragraph":M.push({containerKind:"text",containerOrdinal:M.length,id:J.id,text:q0(J.children)});break;case"code":M.push({containerKind:"code",containerOrdinal:M.length,id:J.id,text:J.source});break}},enterTableCell(J){M.push({containerKind:"tableCell",containerOrdinal:M.length,id:J.id,text:q0(J.children)})}}),M}function b8($,M,J){return{prefix:$.slice(Math.max(0,M-z9),M),suffix:$.slice(J,Math.min($.length,J+z9))}}function y2($,M,J){let Z=O0(M,0,$.text.length),X=O0(J,Z,$.text.length),{prefix:Y,suffix:Q}=b8($.text,Z,X);return{kind:y8($.containerKind),prefix:Y||void 0,suffix:Q||void 0}}function b2($,M,J){let Z=O0(M,0,$.text.length),X=O0(J,Z,$.text.length);return $.text.slice(Z,X)}function v0($,M){if(M.length===0)return[];let J=[],Z=0;while(Z<=$.length){let X=$.indexOf(M,Z);if(X===-1)break;J.push(X),Z=X+Math.max(1,M.length)}return J}function c1($,M,J){if(M.length===0||J.length===0)return[];let Z=[];for(let X of v0($,M)){let Y=X+M.length,Q=$.indexOf(J,Y);if(Q!==-1)Z.push({startOffset:Y,endOffset:Q})}return Z}function w8($,M,J){if(!M)return!1;return $.slice(Math.max(0,J-M.length),J)===M}function T8($,M,J){if(!M)return!1;return $.slice(J,J+M.length)===M}var z9=24;function O0($,M,J){return Math.min(Math.max($,M),J)}var W9=48,B9=64,aZ=32;function w2($,M){let J=$.anchor.kind??B8,Z=$5(M).filter((Q)=>Q.containerKind===J),X=sZ($,Z);if(X.length>0)return P9($,X,null);let Y=iZ($,Z);if(Y.length>0)return P9($,Y,"repaired");return{match:null,repair:null,status:"stale"}}function sZ($,M){let J=[],Z=$.quote;if(Z.length===0)return J;for(let X of M)for(let Y of v0(X.text,Z))J.push({container:X,endOffset:Y+Z.length,score:tZ($,X,Y),startOffset:Y});return J.sort((X,Y)=>Y.score-X.score),J}function iZ($,M){let J=[];for(let Z of M)J.push(...oZ($,Z));return J.sort((Z,X)=>X.score-Z.score),J}function oZ($,M){let J=[],Z=$.quote.length,X=M.text,Y=$.anchor.prefix??"",Q=$.anchor.suffix??"";if(Y.length>0&&Q.length>0){for(let K of c1(X,Y,Q))J.push({container:M,endOffset:K.endOffset,score:O8($,M,K.startOffset,K.endOffset,Z),startOffset:K.startOffset});return J}if(Y.length>0){for(let K of v0(X,Y)){let q=K+Y.length,D=O0(q+Z,q,X.length);J.push({container:M,endOffset:D,score:O8($,M,q,D,Z),startOffset:q})}return J}if(Q.length>0)for(let K of v0(X,Q)){let q=K,D=O0(q-Z,0,q);J.push({container:M,endOffset:q,score:O8($,M,D,q,Z),startOffset:D})}return J}function P9($,M,J){let[Z,X]=M;if(!Z)return{match:null,repair:null,status:"stale"};if(X&&Z.score===X.score)return{match:null,repair:null,status:"ambiguous"};let Y=y2(Z.container,Z.startOffset,Z.endOffset),Q=b2(Z.container,Z.startOffset,Z.endOffset),K=J??(Q===$.quote&&(Y.prefix??"")===($.anchor.prefix??"")&&(Y.suffix??"")===($.anchor.suffix??"")?"matched":"repaired");return{match:nZ(Z.container,Z.startOffset,Z.endOffset),repair:{anchor:Y,quote:Q},status:K}}function nZ($,M,J){return{containerId:$.id,containerKind:$.containerKind,containerOrdinal:$.containerOrdinal,endOffset:J,startOffset:M}}function tZ($,M,J){let Z=0;if(w8(M.text,$.anchor.prefix,J))Z+=W9;if(T8(M.text,$.anchor.suffix,J+$.quote.length))Z+=W9;return Z}function O8($,M,J,Z,X){let Y=0;if(w8(M.text,$.anchor.prefix,J))Y+=B9;if(T8(M.text,$.anchor.suffix,Z))Y+=B9;if(Y+=Math.max(0,aZ-Math.abs(X-(Z-J))),$.quote.length>0){let Q=M.text.slice(J,Z);if(Q.length>0)Y+=eZ($.quote,Q),Y+=$X($.quote,Q)}return Y}function eZ($,M){let J=0;while(J<$.length&&J<M.length&&$[J]===M[J])J+=1;return J}function $X($,M){let J=0;while(J<$.length&&J<M.length&&$[$.length-1-J]===M[M.length-1-J])J+=1;return J}function j8($){if(!$||typeof $!=="object"||Array.isArray($))return null;let M=$,J=JX(M.anchor),Z=typeof M.quote==="string"?M.quote:null,X=Array.isArray(M.comments)?M.comments.flatMap((Y)=>{let Q=MX(Y);return Q?[Q]:[]}):[];if(!J||!Z||X.length===0)return null;return{quote:Z,anchor:J,comments:X,resolvedAt:typeof M.resolvedAt==="string"?M.resolvedAt:void 0}}function MX($){if(!$||typeof $!=="object"||Array.isArray($))return null;let M=$;if(typeof M.body!=="string"||typeof M.updatedAt!=="string")return null;return{body:M.body,updatedAt:M.updatedAt}}function JX($){if(!$||typeof $!=="object"||Array.isArray($))return null;let{kind:M,prefix:J,suffix:Z}=$;if("kind"in $&&!P8(M)||"prefix"in $&&typeof J!=="string"||"suffix"in $&&typeof Z!=="string")return null;return{kind:P8(M)?y8(M):void 0,prefix:typeof J==="string"?J:void 0,suffix:typeof Z==="string"?Z:void 0}}function L8($){let M=$.createdAt??new Date().toISOString();return{comments:[y9({body:$.body,updatedAt:M})],quote:$.quote,anchor:$.anchor}}function C8($,M){let J=y9(M);return{...$,comments:[...$.comments,J]}}function R8($,M,J,Z=new Date().toISOString()){let X=J.trim();if(X.length===0)return $;let Y=!1,Q=$.comments.map((K,q)=>{if(q!==M||K.body===X)return K;return Y=!0,{...K,body:X,updatedAt:Z}});if(!Y)return $;return{...$,comments:Q}}function f8($,M){let J=$.comments.filter((Z,X)=>X!==M);if(J.length===$.comments.length)return $;if(J.length===0)return null;return{...$,comments:J}}function m8($,M,J=new Date().toISOString()){if(J1($)===M)return $;return{...$,resolvedAt:M?J:void 0}}function J1($){return $.resolvedAt!=null}function S8($){return $.filter((M)=>J1(M)).length}function k8($){if($.comments.length===0)return null;return $.comments.reduce((M,J)=>J.updatedAt>M?J.updatedAt:M,$.comments[0].updatedAt)}function y9($){let M=$.updatedAt??new Date().toISOString();return{body:$.body,updatedAt:M}}var ZX=240,XX=0.5625,YX=120,b9=48;function M5($,M,J){let Z=$.image?M.images.get($.image.url)??null:null,X=$.image?.width??null,Y=Math.min(J,X??ZX),Q=Math.max(YX,Math.round(Y*XX));if(!Z||Z.intrinsicWidth<=0||Z.intrinsicHeight<=0)return{height:Q,width:Y};let K=Math.min(J,X??Z.intrinsicWidth),q=Math.min(1,K/Z.intrinsicWidth);return{height:Math.max(b9,Math.round(Z.intrinsicHeight*q)),width:Math.max(b9,Math.round(Z.intrinsicWidth*q))}}function J5($,M,J,Z){let X=$.documentIndex.regionIndex.get($.selection.anchor.regionId);if(!Z.image||!X)return null;let Y=j0(M.layout,X.id,Z.start);if(!Y)return null;let Q=Y.left+h0($,Y),K=Q+W0(Y,Z.start-Y.start)-Y.left,q=Q+W0(Y,Z.end-Y.start)-Y.left,{height:D}=M5(Z,J,Y.width),A=Y.top+Math.max(0,Math.floor((Y.height-D)/2));return{left:K,top:A,width:q-K,height:D}}function w9($,M){if(!$.image)return`${$.kind}:missing-image`;let J=M.images.get($.image.url);return`${$.kind}:${$.image.url}:${$.image.width??0}:${J?.status??"loading"}:${J?.intrinsicWidth??0}:${J?.intrinsicHeight??0}`}function B1(){return{graphemeWidths:new Map,lineBoundaries:new Map,measuredContainerHeights:new Map,measuredLines:new Map,preparedText:new Map,viewportPlans:new WeakMap}}function T9($,M,J){return T2($.preparedText,M,J,256)}function O9($,M,J){return T2($.measuredLines,M,J,512)}function j9($,M,J){return T2($.lineBoundaries,M,J,1024)}function L9($,M,J){return T2($.measuredContainerHeights,M,J,1024)}function C9($,M){let J=$.graphemeWidths.get(M);if(J)return J;let Z=new Map;return T2($.graphemeWidths,M,Z,64),Z}function R9($,M,J){return $.viewportPlans.get(M)?.get(J)??null}function f9($,M,J,Z){let X=$.viewportPlans.get(M)??new Map;return X.set(J,Z),$.viewportPlans.set(M,X),Z}function T2($,M,J,Z){if($.has(M))$.delete(M);if($.set(M,J),$.size>Z){let X=$.keys().next().value;if(X!==void 0)$.delete(X)}return J}var QX=["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"],KX=["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 DX($){if($<=255)return QX[$];if(1424<=$&&$<=1524)return"R";if(1536<=$&&$<=1791)return KX[$&255];if(1792<=$&&$<=2220)return"AL";return"L"}function qX($){let M=$.length;if(M===0)return null;let J=Array(M),Z=0;for(let D=0;D<M;D++){let A=DX($.charCodeAt(D));if(A==="R"||A==="AL"||A==="AN")Z++;J[D]=A}if(Z===0)return null;let X=M/Z<0.3?0:1,Y=new Int8Array(M);for(let D=0;D<M;D++)Y[D]=X;let Q=X&1?"R":"L",K=Q,q=K;for(let D=0;D<M;D++)if(J[D]==="NSM")J[D]=q;else q=J[D];q=K;for(let D=0;D<M;D++){let A=J[D];if(A==="EN")J[D]=q==="AL"?"AN":"EN";else if(A==="R"||A==="L"||A==="AL")q=A}for(let D=0;D<M;D++)if(J[D]==="AL")J[D]="R";for(let D=1;D<M-1;D++){if(J[D]==="ES"&&J[D-1]==="EN"&&J[D+1]==="EN")J[D]="EN";if(J[D]==="CS"&&(J[D-1]==="EN"||J[D-1]==="AN")&&J[D+1]===J[D-1])J[D]=J[D-1]}for(let D=0;D<M;D++){if(J[D]!=="EN")continue;let A;for(A=D-1;A>=0&&J[A]==="ET";A--)J[A]="EN";for(A=D+1;A<M&&J[A]==="ET";A++)J[A]="EN"}for(let D=0;D<M;D++){let A=J[D];if(A==="WS"||A==="ES"||A==="ET"||A==="CS")J[D]="ON"}q=K;for(let D=0;D<M;D++){let A=J[D];if(A==="EN")J[D]=q==="L"?"L":"EN";else if(A==="R"||A==="L")q=A}for(let D=0;D<M;D++){if(J[D]!=="ON")continue;let A=D+1;while(A<M&&J[A]==="ON")A++;let V=D>0?J[D-1]:K,U=A<M?J[A]:K,G=V!=="L"?"R":"L";if(G===(U!=="L"?"R":"L"))for(let N=D;N<A;N++)J[N]=G;D=A-1}for(let D=0;D<M;D++)if(J[D]==="ON")J[D]=Q;for(let D=0;D<M;D++){let A=J[D];if((Y[D]&1)===0){if(A==="R")Y[D]++;else if(A==="AN"||A==="EN")Y[D]+=2}else if(A==="L"||A==="AN"||A==="EN")Y[D]++}return Y}function m9($,M){let J=qX($);if(J===null)return null;let Z=new Int8Array(M.length);for(let X=0;X<M.length;X++)Z[X]=J[M[X]];return Z}var AX=/[ \t\n\r\f]+/g,UX=/[\t\n\r\f]| {2,}|^ | $/;function VX($){let M=$??"normal";return M==="pre-wrap"?{mode:M,preserveOrdinarySpaces:!0,preserveHardBreaks:!0}:{mode:M,preserveOrdinarySpaces:!1,preserveHardBreaks:!1}}function GX($){if(!UX.test($))return $;let M=$.replace(AX," ");if(M.charCodeAt(0)===32)M=M.slice(1);if(M.length>0&&M.charCodeAt(M.length-1)===32)M=M.slice(0,-1);return M}function NX($){if(!/[\r\f]/.test($))return $.replace(/\r\n/g,`
|
|
7
|
+
`).trim()}function O8($){return $.every((M)=>M.type==="text"&&M.marks.length===0)}function K5($){if($.length!==1)return!1;let M=$[0];return M.type==="paragraph"&&O8(M.children)}function L9($){switch($.kind){case"text":return $.text;case"inlines":return X0($.inlines);case"blocks":return B1($.blocks)}}function A0($){switch($.type){case"blockquote":case"listItem":return $.children;case"list":return $.items;default:return null}}function w1($,M){if(M.length===0)return null;switch($.type){case"blockquote":return W0({children:M});case"list":return e($,M);case"listItem":return j0($,M);default:return null}}function T8($,M){return Y5($,`root.${M}`)}function Y5($,M){switch($.type){case"blockquote":{let Z=$.children.map((X,Y)=>Y5(X,`${M}.children.${Y}`)),J=B1(Z);return{children:Z,id:Y0("blockquote",M,J),plainText:J,type:"blockquote"}}case"code":return{id:Y0("code",M,`${$.language??""}:${$.source}`),language:$.language,meta:$.meta,plainText:$.source,source:$.source,type:"code"};case"directive":return{attributes:$.attributes,body:$.body,id:Y0("directive",M,`${$.name}{${$.attributes}}:${$.body}`),name:$.name,plainText:$.body,type:"directive"};case"heading":{let Z=$.children.map((X,Y)=>Q5(X,`${M}.children.${Y}`)),J=X0(Z);return{children:Z,depth:$.depth,id:Y0("heading",M,`${$.depth}:${J}`),plainText:J,type:"heading"}}case"list":{let Z=$.items.map((X,Y)=>Y5(X,`${M}.children.${Y}`)),J=Z.map((X)=>X.plainText).join(`
|
|
8
|
+
`);return{id:Y0("list",M,`${String($.ordered)}:${J}`),items:Z,ordered:$.ordered,plainText:J,spread:$.spread,start:$.start,type:"list"}}case"listItem":{let Z=$.children.map((X,Y)=>Y5(X,`${M}.children.${Y}`)),J=B1(Z);return{checked:$.checked,children:Z,id:Y0("listItem",M,J),plainText:J,spread:$.spread,type:"listItem"}}case"paragraph":{let Z=$.children.map((X,Y)=>Q5(X,`${M}.children.${Y}`)),J=X0(Z);return{children:Z,id:Y0("paragraph",M,J),plainText:J,type:"paragraph"}}case"table":{let Z=$.rows.map((X,Y)=>zX(X,`${M}.rows.${Y}`)),J=Z.map((X)=>X.cells.map((Y)=>Y.plainText).join(" | ")).join(`
|
|
9
|
+
`);return{align:$.align,id:Y0("table",M,J),plainText:J,rows:Z,type:"table"}}case"thematicBreak":return{id:Y0("thematicBreak",M,"thematic-break"),plainText:"",type:"thematicBreak"};case"unsupported":return{id:Y0("unsupported",M,$.source),originalType:$.originalType,plainText:$.source,source:$.source,type:"unsupported"}}}function zX($,M){return{cells:$.cells.map((Z,J)=>{let X=Z.children.map((Q,K)=>Q5(Q,`${M}.cells.${J}.children.${K}`)),Y=X0(X);return{children:X,id:Y0("tableCell",`${M}.cells.${J}`,Y),plainText:Y}}),id:Y0("tableRow",M,String($.cells.length))}}function Q5($,M){switch($.type){case"break":return{id:Y0("break",M,"break"),type:"break"};case"image":return{alt:$.alt,id:Y0("image",M,`${$.url}:${$.width??""}:${$.alt??""}`),title:$.title,type:"image",url:$.url,width:$.width};case"inlineCode":return{code:$.code,id:Y0("inlineCode",M,$.code),type:"inlineCode"};case"link":{let Z=$.children.map((X,Y)=>Q5(X,`${M}.children.${Y}`)),J=X0(Z);return{children:Z,id:Y0("link",M,`${$.url}:${J}`),title:$.title,type:"link",url:$.url}}case"text":return{id:Y0("text",M,`${$.text}:${$.marks.join(",")}`),marks:$.marks,text:$.text,type:"text"};case"unsupported":return{id:Y0("unsupported",M,$.source),originalType:$.originalType,source:$.source,type:"unsupported"}}}function R2($){return $.map((M)=>{switch(M.type){case"blockquote":return{...M,children:R2(M.children)};case"heading":case"paragraph":return u0(M,j8(M.children));case"list":return{...M,items:M.items.map((Z)=>({...Z,children:R2(Z.children)}))};case"listItem":return{...M,children:R2(M.children)};case"table":return w0(M,M.rows.map((Z)=>({...Z,cells:Z.cells.map((J)=>({...J,children:j8(J.children)}))})));default:return M}})}function j8($){let M=[...$];for(let Z=M.length-1;Z>=0;Z-=1){let J=M[Z];if(J.type==="text"){let X=J.text.replace(/[ \t]+$/u,"");if(X.length===J.text.length)return M;if(X.length===0){M.splice(Z,1);continue}return M[Z]={...J,text:X},M}if(J.type==="link"){let X=j8(J.children);if(X.length===J.children.length&&X.every((Y,Q)=>Y===J.children[Q]))return M;if(X.length===0){M.splice(Z,1);continue}return M[Z]={...J,children:X},M}return M}return M}function Y0($,M,Z){let J=2166136261;for(let X of`${$}:${M}:${Z}`)J^=X.charCodeAt(0),J=Math.imul(J,16777619);return`${$}-${(J>>>0).toString(36)}`}function L8($,M){C8($.blocks,M,R9(),S9())}function HX($,M){C8($,M,R9(),S9())}function s1($,M){let Z=null,J={enterBlock(X){if(X.id===M)return Z=X,"stop"}};if(Array.isArray($))HX($,J);else L8($,J);return Z}function C8($,M,Z,J){for(let[X,Y]of $.entries()){if(Z.stopped)return;let Q=`${J.pathPrefix}.${X}`,K={blockAncestors:J.blockAncestors,depth:J.depth,parentBlock:J.parentBlock,path:Q},q=M.enterBlock?.(Y,K);if(i1(q,Z))return;if(q!=="skip")switch(Y.type){case"list":C9(Y.items,Y,M,Z,J,Q);break;case"blockquote":case"listItem":C9(Y.children,Y,M,Z,J,Q);break;case"heading":case"paragraph":R8(Y.children,M,Z,{block:Y,blockAncestors:[...J.blockAncestors,Y],inlineAncestors:[],parentInline:null,pathPrefix:`${Q}.children`});break;case"table":WX(Y,M,Z,{blockAncestors:[...J.blockAncestors,Y],pathPrefix:Q});break;case"code":case"directive":case"thematicBreak":case"unsupported":break}if(Z.stopped)return;if(i1(M.leaveBlock?.(Y,K),Z))return}}function R8($,M,Z,J){for(let[X,Y]of $.entries()){if(Z.stopped)return;let Q=`${J.pathPrefix}.${X}`,K={block:J.block,blockAncestors:J.blockAncestors,inlineAncestors:J.inlineAncestors,parentInline:J.parentInline,path:Q},q=M.enterInline?.(Y,K);if(i1(q,Z))return;if(q!=="skip"){if(Y.type==="link")EX(Y.children,Y,M,Z,J,Q)}if(Z.stopped)return;if(i1(M.leaveInline?.(Y,K),Z))return}}function R9(){return{stopped:!1}}function S9(){return{blockAncestors:[],depth:0,parentBlock:null,pathPrefix:"root"}}function C9($,M,Z,J,X,Y){C8($,Z,J,{blockAncestors:[...X.blockAncestors,M],depth:X.depth+1,parentBlock:M,pathPrefix:`${Y}.children`})}function EX($,M,Z,J,X,Y){R8($,Z,J,{block:X.block,blockAncestors:X.blockAncestors,inlineAncestors:[...X.inlineAncestors,M],parentInline:M,pathPrefix:`${Y}.children`})}function WX($,M,Z,J){for(let[X,Y]of $.rows.entries())for(let[Q,K]of Y.cells.entries()){if(Z.stopped)return;let q=`${J.pathPrefix}.rows.${X}.cells.${Q}`,D={blockAncestors:J.blockAncestors,cellIndex:Q,path:q,row:Y,rowIndex:X,table:$},V=M.enterTableCell?.(K,D);if(i1(V,Z))return;if(V!=="skip")R8(K.children,M,Z,{block:$,blockAncestors:J.blockAncestors,inlineAncestors:[],parentInline:null,pathPrefix:`${q}.children`});if(Z.stopped)return;if(i1(M.leaveTableCell?.(K,D),Z))return}}function i1($,M){if($!=="stop")return!1;return M.stopped=!0,!0}var S8="text";function k8($){return $==="text"||$==="code"||$==="tableCell"}function m8($){return $===S8?void 0:$}function m9($){switch($){case"heading":case"paragraph":return"text";case"code":return"code";default:return null}}function D5($){let M=[];return L8($,{enterBlock(Z){switch(Z.type){case"heading":case"paragraph":M.push({containerKind:"text",containerOrdinal:M.length,id:Z.id,text:X0(Z.children)});break;case"code":M.push({containerKind:"code",containerOrdinal:M.length,id:Z.id,text:Z.source});break}},enterTableCell(Z){M.push({containerKind:"tableCell",containerOrdinal:M.length,id:Z.id,text:X0(Z.children)})}}),M}function f8($,M,Z){return{prefix:$.slice(Math.max(0,M-k9),M),suffix:$.slice(Z,Math.min($.length,Z+k9))}}function S2($,M,Z){let J=O0(M,0,$.text.length),X=O0(Z,J,$.text.length),{prefix:Y,suffix:Q}=f8($.text,J,X);return{kind:m8($.containerKind),prefix:Y||void 0,suffix:Q||void 0}}function k2($,M,Z){let J=O0(M,0,$.text.length),X=O0(Z,J,$.text.length);return $.text.slice(J,X)}function h0($,M){if(M.length===0)return[];let Z=[],J=0;while(J<=$.length){let X=$.indexOf(M,J);if(X===-1)break;Z.push(X),J=X+Math.max(1,M.length)}return Z}function o1($,M,Z){if(M.length===0||Z.length===0)return[];let J=[];for(let X of h0($,M)){let Y=X+M.length,Q=$.indexOf(Z,Y);if(Q!==-1)J.push({startOffset:Y,endOffset:Q})}return J}function v8($,M,Z){if(!M)return!1;return $.slice(Math.max(0,Z-M.length),Z)===M}function u8($,M,Z){if(!M)return!1;return $.slice(Z,Z+M.length)===M}var k9=24;function O0($,M,Z){return Math.min(Math.max($,M),Z)}var f9=48,v9=64,yX=32;function m2($,M){let Z=$.anchor.kind??S8,J=D5(M).filter((Q)=>Q.containerKind===Z),X=BX($,J);if(X.length>0)return u9($,X,null);let Y=PX($,J);if(Y.length>0)return u9($,Y,"repaired");return{match:null,repair:null,status:"stale"}}function BX($,M){let Z=[],J=$.quote;if(J.length===0)return Z;for(let X of M)for(let Y of h0(X.text,J))Z.push({container:X,endOffset:Y+J.length,score:TX($,X,Y),startOffset:Y});return Z.sort((X,Y)=>Y.score-X.score),Z}function PX($,M){let Z=[];for(let J of M)Z.push(...wX($,J));return Z.sort((J,X)=>X.score-J.score),Z}function wX($,M){let Z=[],J=$.quote.length,X=M.text,Y=$.anchor.prefix??"",Q=$.anchor.suffix??"";if(Y.length>0&&Q.length>0){for(let K of o1(X,Y,Q))Z.push({container:M,endOffset:K.endOffset,score:h8($,M,K.startOffset,K.endOffset,J),startOffset:K.startOffset});return Z}if(Y.length>0){for(let K of h0(X,Y)){let q=K+Y.length,D=O0(q+J,q,X.length);Z.push({container:M,endOffset:D,score:h8($,M,q,D,J),startOffset:q})}return Z}if(Q.length>0)for(let K of h0(X,Q)){let q=K,D=O0(q-J,0,q);Z.push({container:M,endOffset:q,score:h8($,M,D,q,J),startOffset:D})}return Z}function u9($,M,Z){let[J,X]=M;if(!J)return{match:null,repair:null,status:"stale"};if(X&&J.score===X.score)return{match:null,repair:null,status:"ambiguous"};let Y=S2(J.container,J.startOffset,J.endOffset),Q=k2(J.container,J.startOffset,J.endOffset),K=Z??(Q===$.quote&&(Y.prefix??"")===($.anchor.prefix??"")&&(Y.suffix??"")===($.anchor.suffix??"")?"matched":"repaired");return{match:bX(J.container,J.startOffset,J.endOffset),repair:{anchor:Y,quote:Q},status:K}}function bX($,M,Z){return{containerId:$.id,containerKind:$.containerKind,containerOrdinal:$.containerOrdinal,endOffset:Z,startOffset:M}}function TX($,M,Z){let J=0;if(v8(M.text,$.anchor.prefix,Z))J+=f9;if(u8(M.text,$.anchor.suffix,Z+$.quote.length))J+=f9;return J}function h8($,M,Z,J,X){let Y=0;if(v8(M.text,$.anchor.prefix,Z))Y+=v9;if(u8(M.text,$.anchor.suffix,J))Y+=v9;if(Y+=Math.max(0,yX-Math.abs(X-(J-Z))),$.quote.length>0){let Q=M.text.slice(Z,J);if(Q.length>0)Y+=jX($.quote,Q),Y+=OX($.quote,Q)}return Y}function jX($,M){let Z=0;while(Z<$.length&&Z<M.length&&$[Z]===M[Z])Z+=1;return Z}function OX($,M){let Z=0;while(Z<$.length&&Z<M.length&&$[$.length-1-Z]===M[M.length-1-Z])Z+=1;return Z}function I8($){if(!$||typeof $!=="object"||Array.isArray($))return null;let M=$,Z=CX(M.anchor),J=typeof M.quote==="string"?M.quote:null,X=Array.isArray(M.comments)?M.comments.flatMap((Y)=>{let Q=LX(Y);return Q?[Q]:[]}):[];if(!Z||!J||X.length===0)return null;return{quote:J,anchor:Z,comments:X,resolvedAt:typeof M.resolvedAt==="string"?M.resolvedAt:void 0}}function LX($){if(!$||typeof $!=="object"||Array.isArray($))return null;let M=$;if(typeof M.body!=="string"||typeof M.updatedAt!=="string")return null;return{body:M.body,updatedAt:M.updatedAt}}function CX($){if(!$||typeof $!=="object"||Array.isArray($))return null;let{kind:M,prefix:Z,suffix:J}=$;if("kind"in $&&!k8(M)||"prefix"in $&&typeof Z!=="string"||"suffix"in $&&typeof J!=="string")return null;return{kind:k8(M)?m8(M):void 0,prefix:typeof Z==="string"?Z:void 0,suffix:typeof J==="string"?J:void 0}}function g8($){let M=$.createdAt??new Date().toISOString();return{comments:[h9({body:$.body,updatedAt:M})],quote:$.quote,anchor:$.anchor}}function p8($,M){let Z=h9(M);return{...$,comments:[...$.comments,Z]}}function l8($,M,Z,J=new Date().toISOString()){let X=Z.trim();if(X.length===0)return $;let Y=!1,Q=$.comments.map((K,q)=>{if(q!==M||K.body===X)return K;return Y=!0,{...K,body:X,updatedAt:J}});if(!Y)return $;return{...$,comments:Q}}function x8($,M){let Z=$.comments.filter((J,X)=>X!==M);if(Z.length===$.comments.length)return $;if(Z.length===0)return null;return{...$,comments:Z}}function d8($,M,Z=new Date().toISOString()){if(X1($)===M)return $;return{...$,resolvedAt:M?Z:void 0}}function X1($){return $.resolvedAt!=null}function r8($){return $.filter((M)=>X1(M)).length}function c8($){if($.comments.length===0)return null;return $.comments.reduce((M,Z)=>Z.updatedAt>M?Z.updatedAt:M,$.comments[0].updatedAt)}function h9($){let M=$.updatedAt??new Date().toISOString();return{body:$.body,updatedAt:M}}var RX=240,SX=0.5625,kX=120,I9=48;function q5($,M,Z){let J=$.image?M.images.get($.image.url)??null:null,X=$.image?.width??null,Y=Math.min(Z,X??RX),Q=Math.max(kX,Math.round(Y*SX));if(!J||J.intrinsicWidth<=0||J.intrinsicHeight<=0)return{height:Q,width:Y};let K=Math.min(Z,X??J.intrinsicWidth),q=Math.min(1,K/J.intrinsicWidth);return{height:Math.max(I9,Math.round(J.intrinsicHeight*q)),width:Math.max(I9,Math.round(J.intrinsicWidth*q))}}function V5($,M,Z,J){let X=$.documentIndex.regionIndex.get($.selection.anchor.regionId);if(!J.image||!X)return null;let Y=L0(M.layout,X.id,J.start);if(!Y)return null;let Q=Y.left+I0($,Y),K=Q+y0(Y,J.start-Y.start)-Y.left,q=Q+y0(Y,J.end-Y.start)-Y.left,{height:D}=q5(J,Z,Y.width),V=Y.top+Math.max(0,Math.floor((Y.height-D)/2));return{left:K,top:V,width:q-K,height:D}}function g9($,M){if(!$.image)return`${$.kind}:missing-image`;let Z=M.images.get($.image.url);return`${$.kind}:${$.image.url}:${$.image.width??0}:${Z?.status??"loading"}:${Z?.intrinsicWidth??0}:${Z?.intrinsicHeight??0}`}function b1(){return{graphemeWidths:new Map,lineBoundaries:new Map,measuredContainerHeights:new Map,measuredLines:new Map,preparedText:new Map,viewportPlans:new WeakMap}}function p9($,M,Z){return f2($.preparedText,M,Z,256)}function l9($,M,Z){return f2($.measuredLines,M,Z,512)}function x9($,M,Z){return f2($.lineBoundaries,M,Z,1024)}function d9($,M,Z){return f2($.measuredContainerHeights,M,Z,1024)}function r9($,M){let Z=$.graphemeWidths.get(M);if(Z)return Z;let J=new Map;return f2($.graphemeWidths,M,J,64),J}function c9($,M,Z){return $.viewportPlans.get(M)?.get(Z)??null}function a9($,M,Z,J){let X=$.viewportPlans.get(M)??new Map;return X.set(Z,J),$.viewportPlans.set(M,X),J}function f2($,M,Z,J){if($.has(M))$.delete(M);if($.set(M,Z),$.size>J){let X=$.keys().next().value;if(X!==void 0)$.delete(X)}return Z}var mX=["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"],fX=["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 vX($){if($<=255)return mX[$];if(1424<=$&&$<=1524)return"R";if(1536<=$&&$<=1791)return fX[$&255];if(1792<=$&&$<=2220)return"AL";return"L"}function uX($){let M=$.length;if(M===0)return null;let Z=Array(M),J=0;for(let D=0;D<M;D++){let V=vX($.charCodeAt(D));if(V==="R"||V==="AL"||V==="AN")J++;Z[D]=V}if(J===0)return null;let X=M/J<0.3?0:1,Y=new Int8Array(M);for(let D=0;D<M;D++)Y[D]=X;let Q=X&1?"R":"L",K=Q,q=K;for(let D=0;D<M;D++)if(Z[D]==="NSM")Z[D]=q;else q=Z[D];q=K;for(let D=0;D<M;D++){let V=Z[D];if(V==="EN")Z[D]=q==="AL"?"AN":"EN";else if(V==="R"||V==="L"||V==="AL")q=V}for(let D=0;D<M;D++)if(Z[D]==="AL")Z[D]="R";for(let D=1;D<M-1;D++){if(Z[D]==="ES"&&Z[D-1]==="EN"&&Z[D+1]==="EN")Z[D]="EN";if(Z[D]==="CS"&&(Z[D-1]==="EN"||Z[D-1]==="AN")&&Z[D+1]===Z[D-1])Z[D]=Z[D-1]}for(let D=0;D<M;D++){if(Z[D]!=="EN")continue;let V;for(V=D-1;V>=0&&Z[V]==="ET";V--)Z[V]="EN";for(V=D+1;V<M&&Z[V]==="ET";V++)Z[V]="EN"}for(let D=0;D<M;D++){let V=Z[D];if(V==="WS"||V==="ES"||V==="ET"||V==="CS")Z[D]="ON"}q=K;for(let D=0;D<M;D++){let V=Z[D];if(V==="EN")Z[D]=q==="L"?"L":"EN";else if(V==="R"||V==="L")q=V}for(let D=0;D<M;D++){if(Z[D]!=="ON")continue;let V=D+1;while(V<M&&Z[V]==="ON")V++;let G=D>0?Z[D-1]:K,U=V<M?Z[V]:K,A=G!=="L"?"R":"L";if(A===(U!=="L"?"R":"L"))for(let N=D;N<V;N++)Z[N]=A;D=V-1}for(let D=0;D<M;D++)if(Z[D]==="ON")Z[D]=Q;for(let D=0;D<M;D++){let V=Z[D];if((Y[D]&1)===0){if(V==="R")Y[D]++;else if(V==="AN"||V==="EN")Y[D]+=2}else if(V==="L"||V==="AN"||V==="EN")Y[D]++}return Y}function i9($,M){let Z=uX($);if(Z===null)return null;let J=new Int8Array(M.length);for(let X=0;X<M.length;X++)J[X]=Z[M[X]];return J}var hX=/[ \t\n\r\f]+/g,IX=/[\t\n\r\f]| {2,}|^ | $/;function gX($){let M=$??"normal";return M==="pre-wrap"?{mode:M,preserveOrdinarySpaces:!0,preserveHardBreaks:!0}:{mode:M,preserveOrdinarySpaces:!1,preserveHardBreaks:!1}}function pX($){if(!IX.test($))return $;let M=$.replace(hX," ");if(M.charCodeAt(0)===32)M=M.slice(1);if(M.length>0&&M.charCodeAt(M.length-1)===32)M=M.slice(0,-1);return M}function lX($){if(!/[\r\f]/.test($))return $.replace(/\r\n/g,`
|
|
10
10
|
`);return $.replace(/\r\n/g,`
|
|
11
11
|
`).replace(/[\r\f]/g,`
|
|
12
|
-
`)}var
|
|
13
|
-
`)return"hard-break"}if($===" ")return"space";if($===" "||$===" "||$===""||$==="\uFEFF")return"glue";if($==="")return"zero-width-break";if($==="")return"soft-hyphen";return"text"}function i0($){return $.length===1?$[0]:$.join("")}function CX($,M,J,Z){let X=[],Y=null,Q=[],K=J,q=!1,D=0;for(let A of $){let V=LX(A,Z),U=V==="text"&&M;if(Y!==null&&V===Y&&U===q){Q.push(A),D+=A.length;continue}if(Y!==null)X.push({text:i0(Q),isWordLike:q,kind:Y,start:K});Y=V,Q=[A],K=J+D,q=U,D+=A.length}if(Y!==null)X.push({text:i0(Q),isWordLike:q,kind:Y,start:K});return X}function h8($){return $==="space"||$==="preserved-space"||$==="zero-width-break"||$==="hard-break"}var RX=/^[A-Za-z][A-Za-z0-9+.-]*:$/;function fX($,M){let J=$.texts[M];if(J.startsWith("www."))return!0;return RX.test(J)&&M+1<$.len&&$.kinds[M+1]==="text"&&$.texts[M+1]==="//"}function mX($){return $.includes("?")&&($.includes("://")||$.startsWith("www."))}function SX($){let M=$.texts.slice(),J=$.isWordLike.slice(),Z=$.kinds.slice(),X=$.starts.slice();for(let Q=0;Q<$.len;Q++){if(Z[Q]!=="text"||!fX($,Q))continue;let K=[M[Q]],q=Q+1;while(q<$.len&&!h8(Z[q])){K.push(M[q]),J[Q]=!0;let D=M[q].includes("?");if(Z[q]="text",M[q]="",q++,D)break}M[Q]=i0(K)}let Y=0;for(let Q=0;Q<M.length;Q++){let K=M[Q];if(K.length===0)continue;if(Y!==Q)M[Y]=K,J[Y]=J[Q],Z[Y]=Z[Q],X[Y]=X[Q];Y++}return M.length=Y,J.length=Y,Z.length=Y,X.length=Y,{len:Y,texts:M,isWordLike:J,kinds:Z,starts:X}}function kX($){let M=[],J=[],Z=[],X=[];for(let Y=0;Y<$.len;Y++){let Q=$.texts[Y];if(M.push(Q),J.push($.isWordLike[Y]),Z.push($.kinds[Y]),X.push($.starts[Y]),!mX(Q))continue;let K=Y+1;if(K>=$.len||h8($.kinds[K]))continue;let q=[],D=$.starts[K],A=K;while(A<$.len&&!h8($.kinds[A]))q.push($.texts[A]),A++;if(q.length>0)M.push(i0(q)),J.push(!0),Z.push("text"),X.push(D),Y=A-1}return{len:M.length,texts:M,isWordLike:J,kinds:Z,starts:X}}var uX=new Set([":","-","/","×",",",".","+","–","—"]),S9=/^[A-Za-z0-9_]+[,:;]*$/,k9=/[,:;]+$/;function v9($){for(let M of $)if(u9.test(M))return!0;return!1}function g8($){if($.length===0)return!1;for(let M of $){if(u9.test(M)||uX.has(M))continue;return!1}return!0}function vX($){let M=[],J=[],Z=[],X=[];for(let Y=0;Y<$.len;Y++){let Q=$.texts[Y],K=$.kinds[Y];if(K==="text"&&g8(Q)&&v9(Q)){let q=[Q],D=Y+1;while(D<$.len&&$.kinds[D]==="text"&&g8($.texts[D]))q.push($.texts[D]),D++;M.push(i0(q)),J.push(!0),Z.push("text"),X.push($.starts[Y]),Y=D-1;continue}M.push(Q),J.push($.isWordLike[Y]),Z.push(K),X.push($.starts[Y])}return{len:M.length,texts:M,isWordLike:J,kinds:Z,starts:X}}function hX($){let M=[],J=[],Z=[],X=[];for(let Y=0;Y<$.len;Y++){let Q=$.texts[Y],K=$.kinds[Y],q=$.isWordLike[Y];if(K==="text"&&q&&S9.test(Q)){let D=[Q],A=k9.test(Q),V=Y+1;while(A&&V<$.len&&$.kinds[V]==="text"&&$.isWordLike[V]&&S9.test($.texts[V])){let U=$.texts[V];D.push(U),A=k9.test(U),V++}M.push(i0(D)),J.push(!0),Z.push("text"),X.push($.starts[Y]),Y=V-1;continue}M.push(Q),J.push(q),Z.push(K),X.push($.starts[Y])}return{len:M.length,texts:M,isWordLike:J,kinds:Z,starts:X}}function gX($){let M=[],J=[],Z=[],X=[];for(let Y=0;Y<$.len;Y++){let Q=$.texts[Y];if($.kinds[Y]==="text"&&Q.includes("-")){let K=Q.split("-"),q=K.length>1;for(let D=0;D<K.length;D++){let A=K[D];if(!q)break;if(A.length===0||!v9(A)||!g8(A))q=!1}if(q){let D=0;for(let A=0;A<K.length;A++){let V=K[A],U=A<K.length-1?`${V}-`:V;M.push(U),J.push(!0),Z.push("text"),X.push($.starts[Y]+D),D+=U.length}continue}}M.push(Q),J.push($.isWordLike[Y]),Z.push($.kinds[Y]),X.push($.starts[Y])}return{len:M.length,texts:M,isWordLike:J,kinds:Z,starts:X}}function IX($){let M=[],J=[],Z=[],X=[],Y=0;while(Y<$.len){let Q=[$.texts[Y]],K=$.isWordLike[Y],q=$.kinds[Y],D=$.starts[Y];if(q==="glue"){let A=[Q[0]],V=D;Y++;while(Y<$.len&&$.kinds[Y]==="glue")A.push($.texts[Y]),Y++;let U=i0(A);if(Y<$.len&&$.kinds[Y]==="text")Q[0]=U,Q.push($.texts[Y]),K=$.isWordLike[Y],q="text",D=V,Y++;else{M.push(U),J.push(!1),Z.push("glue"),X.push(V);continue}}else Y++;if(q==="text")while(Y<$.len&&$.kinds[Y]==="glue"){let A=[];while(Y<$.len&&$.kinds[Y]==="glue")A.push($.texts[Y]),Y++;let V=i0(A);if(Y<$.len&&$.kinds[Y]==="text"){Q.push(V,$.texts[Y]),K=K||$.isWordLike[Y],Y++;continue}Q.push(V)}M.push(i0(Q)),J.push(K),Z.push(q),X.push(D)}return{len:M.length,texts:M,isWordLike:J,kinds:Z,starts:X}}function pX($){let M=$.texts.slice(),J=$.isWordLike.slice(),Z=$.kinds.slice(),X=$.starts.slice();for(let Y=0;Y<M.length-1;Y++){if(Z[Y]!=="text"||Z[Y+1]!=="text")continue;if(!s0(M[Y])||!s0(M[Y+1]))continue;let Q=bX(M[Y]);if(Q===null)continue;M[Y]=Q.head,M[Y+1]=Q.tail+M[Y+1],X[Y+1]=X[Y]+Q.head.length}return{len:M.length,texts:M,isWordLike:J,kinds:Z,starts:X}}function lX($,M,J){let Z=FX(),X=0,Y=[],Q=[],K=[],q=[];for(let U of Z.segment($))for(let G of CX(U.segment,U.isWordLike??!1,U.index,J)){let _=G.kind==="text";if(M.carryCJKAfterClosingQuote&&_&&X>0&&K[X-1]==="text"&&s0(G.text)&&s0(Y[X-1])&&d8(Y[X-1]))Y[X-1]+=G.text,Q[X-1]=Q[X-1]||G.isWordLike;else if(_&&X>0&&K[X-1]==="text"&&PX(G.text)&&s0(Y[X-1]))Y[X-1]+=G.text,Q[X-1]=Q[X-1]||G.isWordLike;else if(_&&X>0&&K[X-1]==="text"&&OX(Y[X-1]))Y[X-1]+=G.text,Q[X-1]=Q[X-1]||G.isWordLike;else if(_&&X>0&&K[X-1]==="text"&&G.isWordLike&&v8(G.text)&&TX(Y[X-1]))Y[X-1]+=G.text,Q[X-1]=!0;else if(_&&!G.isWordLike&&X>0&&K[X-1]==="text"&&G.text.length===1&&G.text!=="-"&&G.text!=="—"&&wX(Y[X-1],G.text))Y[X-1]+=G.text;else if(_&&!G.isWordLike&&X>0&&K[X-1]==="text"&&(BX(G.text)||G.text==="-"&&Q[X-1]))Y[X-1]+=G.text;else Y[X]=G.text,Q[X]=G.isWordLike,K[X]=G.kind,q[X]=G.start,X++}for(let U=1;U<X;U++)if(K[U]==="text"&&!Q[U]&&l8(Y[U])&&K[U-1]==="text")Y[U-1]+=Y[U],Q[U-1]=Q[U-1]||Q[U],Y[U]="";for(let U=X-2;U>=0;U--)if(K[U]==="text"&&!Q[U]&&yX(Y[U])){let G=U+1;while(G<X&&Y[G]==="")G++;if(G<X&&K[G]==="text")Y[G]=Y[U]+Y[G],q[G]=q[U],Y[U]=""}let D=0;for(let U=0;U<X;U++){let G=Y[U];if(G.length===0)continue;if(D!==U)Y[D]=G,Q[D]=Q[U],K[D]=K[U],q[D]=q[U];D++}Y.length=D,Q.length=D,K.length=D,q.length=D;let A=IX({len:D,texts:Y,isWordLike:Q,kinds:K,starts:q}),V=pX(hX(gX(vX(kX(SX(A))))));for(let U=0;U<V.len-1;U++){let G=jX(V.texts[U]);if(G===null)continue;if(V.kinds[U]!=="space"&&V.kinds[U]!=="preserved-space"||V.kinds[U+1]!=="text"||!v8(V.texts[U+1]))continue;V.texts[U]=G.space,V.isWordLike[U]=!1,V.kinds[U]=V.kinds[U]==="preserved-space"?"preserved-space":"space",V.texts[U+1]=G.marks+V.texts[U+1],V.starts[U+1]=V.starts[U]+G.space.length}return V}function dX($,M){if($.len===0)return[];if(!M.preserveHardBreaks)return[{startSegmentIndex:0,endSegmentIndex:$.len,consumedEndSegmentIndex:$.len}];let J=[],Z=0;for(let X=0;X<$.len;X++){if($.kinds[X]!=="hard-break")continue;J.push({startSegmentIndex:Z,endSegmentIndex:X,consumedEndSegmentIndex:X+1}),Z=X+1}if(Z<$.len)J.push({startSegmentIndex:Z,endSegmentIndex:$.len,consumedEndSegmentIndex:$.len});return J}function h9($,M,J="normal"){let Z=VX(J),X=Z.mode==="pre-wrap"?NX($):GX($);if(X.length===0)return{normalized:X,chunks:[],len:0,texts:[],isWordLike:[],kinds:[],starts:[]};let Y=lX(X,M,Z);return{normalized:X,chunks:dX(Y,Z),...Y}}var s1=null,g9=new Map,i1=null,rX=/\p{Emoji_Presentation}/u,xX=/[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u,r8=null,I9=new Map;function x8(){if(s1!==null)return s1;if(typeof OffscreenCanvas<"u")return s1=new OffscreenCanvas(1,1).getContext("2d"),s1;if(typeof document<"u")return s1=document.createElement("canvas").getContext("2d"),s1;throw Error("Text measurement requires OffscreenCanvas or a DOM canvas context.")}function cX($){let M=g9.get($);if(!M)M=new Map,g9.set($,M);return M}function Z1($,M){let J=M.get($);if(J===void 0)J={width:x8().measureText($).width,containsCJK:s0($)},M.set($,J);return J}function o1(){if(i1!==null)return i1;if(typeof navigator>"u")return i1={lineFitEpsilon:0.005,carryCJKAfterClosingQuote:!1,preferPrefixWidthsForBreakableRuns:!1,preferEarlySoftHyphenBreak:!1},i1;let $=navigator.userAgent,J=navigator.vendor==="Apple Computer, Inc."&&$.includes("Safari/")&&!$.includes("Chrome/")&&!$.includes("Chromium/")&&!$.includes("CriOS/")&&!$.includes("FxiOS/")&&!$.includes("EdgiOS/"),Z=$.includes("Chrome/")||$.includes("Chromium/")||$.includes("CriOS/")||$.includes("Edg/");return i1={lineFitEpsilon:J?0.015625:0.005,carryCJKAfterClosingQuote:Z,preferPrefixWidthsForBreakableRuns:J,preferEarlySoftHyphenBreak:J},i1}function aX($){let M=$.match(/(\d+(?:\.\d+)?)\s*px/);return M?parseFloat(M[1]):16}function c8(){if(r8===null)r8=new Intl.Segmenter(void 0,{granularity:"grapheme"});return r8}function sX($){return rX.test($)||$.includes("️")}function p9($){return xX.test($)}function iX($,M){let J=I9.get($);if(J!==void 0)return J;let Z=x8();Z.font=$;let X=Z.measureText("\uD83D\uDE00").width;if(J=0,X>M+0.5&&typeof document<"u"&&document.body!==null){let Y=document.createElement("span");Y.style.font=$,Y.style.display="inline-block",Y.style.visibility="hidden",Y.style.position="absolute",Y.textContent="\uD83D\uDE00",document.body.appendChild(Y);let Q=Y.getBoundingClientRect().width;if(document.body.removeChild(Y),X-Q>0.5)J=X-Q}return I9.set($,J),J}function oX($){let M=0,J=c8();for(let Z of J.segment($))if(sX(Z.segment))M++;return M}function nX($,M){if(M.emojiCount===void 0)M.emojiCount=oX($);return M.emojiCount}function X1($,M,J){if(J===0)return M.width;return M.width-nX($,M)*J}function l9($,M,J,Z){if(M.graphemeWidths!==void 0)return M.graphemeWidths;let X=[],Y=c8();for(let Q of Y.segment($)){let K=Z1(Q.segment,J);X.push(X1(Q.segment,K,Z))}return M.graphemeWidths=X.length>1?X:null,M.graphemeWidths}function d9($,M,J,Z){if(M.graphemePrefixWidths!==void 0)return M.graphemePrefixWidths;let X=[],Y=c8(),Q="";for(let K of Y.segment($)){Q+=K.segment;let q=Z1(Q,J);X.push(X1(Q,q,Z))}return M.graphemePrefixWidths=X.length>1?X:null,M.graphemePrefixWidths}function r9($,M){let J=x8();J.font=$;let Z=cX($),X=aX($),Y=M?iX($,X):0;return{cache:Z,fontSize:X,emojiCorrection:Y}}function X5($){return $==="space"||$==="preserved-space"||$==="tab"||$==="zero-width-break"||$==="soft-hyphen"}function tX($,M){while(M<$.widths.length){let J=$.kinds[M];if(J!=="space"&&J!=="zero-width-break"&&J!=="soft-hyphen")break;M++}return M}function eX($,M){if(M<=0)return 0;let J=$%M;if(Math.abs(J)<=0.000001)return M;return M-J}function x9($,M,J,Z){if(!Z||M===null)return $[J];return M[J]-(J>0?M[J-1]:0)}function $Y($,M,J,Z,X,Y){let Q=0,K=M;while(Q<$.length){let q=Y?M+$[Q]:K+$[Q];if((Q+1<$.length?q+X:q)>J+Z)break;K=q,Q++}return{fitCount:Q,fittedWidth:K}}function MY($,M,J){let{widths:Z,kinds:X,breakableWidths:Y,breakablePrefixWidths:Q}=$;if(Z.length===0)return 0;let K=o1(),q=K.lineFitEpsilon,D=0,A=0,V=!1,U=0,G=0,_=0,N=0,H=-1,E=0;function L(){H=-1,E=0}function W(P=_,y=N,F=A){D++,J?.({startSegmentIndex:U,startGraphemeIndex:G,endSegmentIndex:P,endGraphemeIndex:y,width:F}),A=0,V=!1,L()}function R(P,y){V=!0,U=P,G=0,_=P+1,N=0,A=y}function f(P,y,F){V=!0,U=P,G=y,_=P,N=y+1,A=F}function I(P,y){if(!V){R(P,y);return}A+=y,_=P+1,N=0}function B(P,y){if(!X5(X[P]))return;H=P+1,E=A-y}function b(P){z(P,0)}function z(P,y){let F=Y[P],C=Q[P]??null;for(let v=y;v<F.length;v++){let h=x9(F,C,v,K.preferPrefixWidthsForBreakableRuns);if(!V){f(P,v,h);continue}if(A+h>M+q)W(),f(P,v,h);else A+=h,_=P,N=v+1}if(V&&_===P&&N===F.length)_=P+1,N=0}let T=0;while(T<Z.length){if(!V){if(T=tX($,T),T>=Z.length)break}let P=Z[T],y=X[T];if(!V){if(P>M&&Y[T]!==null)b(T);else R(T,P);B(T,P),T++;continue}if(A+P>M+q){if(X5(y)){I(T,P),W(T+1,0,A-P),T++;continue}if(H>=0){if(_>H||_===H&&N>0){W();continue}W(H,0,E);continue}if(P>M&&Y[T]!==null){W(),b(T),T++;continue}W();continue}I(T,P),B(T,P),T++}if(V)W();return D}function c9($,M,J){if($.simpleLineWalkFastPath)return MY($,M,J);let{widths:Z,lineEndFitAdvances:X,lineEndPaintAdvances:Y,kinds:Q,breakableWidths:K,breakablePrefixWidths:q,discretionaryHyphenWidth:D,tabStopAdvance:A,chunks:V}=$;if(Z.length===0||V.length===0)return 0;let U=o1(),G=U.lineFitEpsilon,_=0,N=0,H=!1,E=0,L=0,W=0,R=0,f=-1,I=0,B=0,b=null;function z(){f=-1,I=0,B=0,b=null}function T(w=W,m=R,S=N){_++,J?.({startSegmentIndex:E,startGraphemeIndex:L,endSegmentIndex:w,endGraphemeIndex:m,width:S}),N=0,H=!1,z()}function P(w,m){H=!0,E=w,L=0,W=w+1,R=0,N=m}function y(w,m,S){H=!0,E=w,L=m,W=w,R=m+1,N=S}function F(w,m){if(!H){P(w,m);return}N+=m,W=w+1,R=0}function C(w,m){if(!X5(Q[w]))return;let S=Q[w]==="tab"?0:X[w],c=Q[w]==="tab"?m:Y[w];f=w+1,I=N-m+S,B=N-m+c,b=Q[w]}function v(w){h(w,0)}function h(w,m){let S=K[w],c=q[w]??null;for(let l=m;l<S.length;l++){let F0=x9(S,c,l,U.preferPrefixWidthsForBreakableRuns);if(!H){y(w,l,F0);continue}if(N+F0>M+G)T(),y(w,l,F0);else N+=F0,W=w,R=l+1}if(H&&W===w&&R===S.length)W=w+1,R=0}function g(w){if(b!=="soft-hyphen")return!1;let m=K[w];if(m===null)return!1;let S=U.preferPrefixWidthsForBreakableRuns?q[w]??m:m,c=S!==m,{fitCount:l,fittedWidth:F0}=$Y(S,N,M,G,D,c);if(l===0)return!1;if(N=F0,W=w,R=l,z(),l===m.length)return W=w+1,R=0,!0;return T(w,l,F0+D),h(w,l),!0}function O(w){_++,J?.({startSegmentIndex:w.startSegmentIndex,startGraphemeIndex:0,endSegmentIndex:w.consumedEndSegmentIndex,endGraphemeIndex:0,width:0}),z()}for(let w=0;w<V.length;w++){let m=V[w];if(m.startSegmentIndex===m.endSegmentIndex){O(m);continue}H=!1,N=0,E=m.startSegmentIndex,L=0,W=m.startSegmentIndex,R=0,z();let S=m.startSegmentIndex;while(S<m.endSegmentIndex){let c=Q[S],l=c==="tab"?eX(N,A):Z[S];if(c==="soft-hyphen"){if(H)W=S+1,R=0,f=S+1,I=N+D,B=N+D,b=c;S++;continue}if(!H){if(l>M&&K[S]!==null)v(S);else P(S,l);C(S,l),S++;continue}if(N+l>M+G){let x0=N+(c==="tab"?0:X[S]),f0=N+(c==="tab"?l:Y[S]);if(b==="soft-hyphen"&&U.preferEarlySoftHyphenBreak&&I<=M+G){T(f,0,B);continue}if(b==="soft-hyphen"&&g(S)){S++;continue}if(X5(c)&&x0<=M+G){F(S,l),T(S+1,0,f0),S++;continue}if(f>=0&&I<=M+G){if(W>f||W===f&&R>0){T();continue}let m0=f;T(m0,0,B),S=m0;continue}if(l>M&&K[S]!==null){T(),v(S),S++;continue}T();continue}F(S,l),C(S,l),S++}if(H){let c=f===m.consumedEndSegmentIndex?B:N;T(m.consumedEndSegmentIndex,0,c)}}return _}var a8=null,a9=new WeakMap;function i9(){if(a8===null)a8=new Intl.Segmenter(void 0,{granularity:"grapheme"});return a8}function JY($){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 ZY($,M,J){let Z=i9(),X=o1(),{cache:Y,emojiCorrection:Q}=r9(M,p9($.normalized)),K=X1("-",Z1("-",Y),Q),D=X1(" ",Z1(" ",Y),Q)*8;if($.len===0)return JY(J);let A=[],V=[],U=[],G=[],_=$.chunks.length<=1,N=J?[]:null,H=[],E=[],L=J?[]:null,W=Array.from({length:$.len}),R=Array.from({length:$.len});function f(b,z,T,P,y,F,C,v){if(y!=="text"&&y!=="space"&&y!=="zero-width-break")_=!1;if(A.push(z),V.push(T),U.push(P),G.push(y),N?.push(F),H.push(C),E.push(v),L!==null)L.push(b)}for(let b=0;b<$.len;b++){W[b]=A.length;let z=$.texts[b],T=$.isWordLike[b],P=$.kinds[b],y=$.starts[b];if(P==="soft-hyphen"){f(z,0,K,K,P,y,null,null),R[b]=A.length;continue}if(P==="hard-break"){f(z,0,0,0,P,y,null,null),R[b]=A.length;continue}if(P==="tab"){f(z,0,0,0,P,y,null,null),R[b]=A.length;continue}let F=Z1(z,Y);if(P==="text"&&F.containsCJK){let g="",O=0;for(let w of Z.segment(z)){let m=w.segment;if(g.length===0){g=m,O=w.index;continue}if(O2.has(g)||I8.has(m)||a1.has(m)||X.carryCJKAfterClosingQuote&&s0(m)&&d8(g)){g+=m;continue}let S=Z1(g,Y),c=X1(g,S,Q);f(g,c,c,c,"text",y+O,null,null),g=m,O=w.index}if(g.length>0){let w=Z1(g,Y),m=X1(g,w,Q);f(g,m,m,m,"text",y+O,null,null)}R[b]=A.length;continue}let C=X1(z,F,Q),v=P==="space"||P==="preserved-space"||P==="zero-width-break"?0:C,h=P==="space"||P==="zero-width-break"?0:C;if(T&&z.length>1){let g=l9(z,F,Y,Q),O=X.preferPrefixWidthsForBreakableRuns?d9(z,F,Y,Q):null;f(z,C,v,h,P,y,g,O)}else f(z,C,v,h,P,y,null,null);R[b]=A.length}let I=XY($.chunks,W,R),B=N===null?null:m9($.normalized,N);if(L!==null)return{widths:A,lineEndFitAdvances:V,lineEndPaintAdvances:U,kinds:G,simpleLineWalkFastPath:_,segLevels:B,breakableWidths:H,breakablePrefixWidths:E,discretionaryHyphenWidth:K,tabStopAdvance:D,chunks:I,segments:L};return{widths:A,lineEndFitAdvances:V,lineEndPaintAdvances:U,kinds:G,simpleLineWalkFastPath:_,segLevels:B,breakableWidths:H,breakablePrefixWidths:E,discretionaryHyphenWidth:K,tabStopAdvance:D,chunks:I}}function XY($,M,J){let Z=[];for(let X=0;X<$.length;X++){let Y=$[X],Q=Y.startSegmentIndex<M.length?M[Y.startSegmentIndex]:J[J.length-1]??0,K=Y.endSegmentIndex<M.length?M[Y.endSegmentIndex]:J[J.length-1]??0,q=Y.consumedEndSegmentIndex<M.length?M[Y.consumedEndSegmentIndex]:J[J.length-1]??0;Z.push({startSegmentIndex:Q,endSegmentIndex:K,consumedEndSegmentIndex:q})}return Z}function YY($,M,J,Z){let X=h9($,o1(),Z?.whiteSpace);return ZY(X,M,J)}function o9($,M,J){return YY($,M,!0,J)}function QY($){return $}function s9($,M,J){let Z=J.get($);if(Z!==void 0)return Z;Z=[];let X=i9();for(let Y of X.segment(M[$]))Z.push(Y.segment);return J.set($,Z),Z}function KY($){let M=a9.get($);if(M!==void 0)return M;return M=new Map,a9.set($,M),M}function DY($,M,J,Z){return Z>0&&$[Z-1]==="soft-hyphen"&&!(M===Z&&J>0)}function qY($,M,J,Z,X,Y,Q){let K="",q=DY(M,Z,X,Y);for(let D=Z;D<Y;D++){if(M[D]==="soft-hyphen"||M[D]==="hard-break")continue;if(D===Z&&X>0)K+=s9(D,$,J).slice(X).join("");else K+=$[D]}if(Q>0){if(q)K+="-";K+=s9(Y,$,J).slice(Z===Y?X:0,Q).join("")}else if(q)K+="-";return K}function AY($,M,J,Z,X,Y,Q){return{text:qY($.segments,$.kinds,M,Z,X,Y,Q),width:J,start:{segmentIndex:Z,graphemeIndex:X},end:{segmentIndex:Y,graphemeIndex:Q}}}function UY($,M,J){return AY($,M,J.width,J.startSegmentIndex,J.startGraphemeIndex,J.endSegmentIndex,J.endGraphemeIndex)}function n9($,M,J){let Z=[];if($.widths.length===0)return{lineCount:0,height:0,lines:Z};let X=KY($),Y=c9(QY($),M,(Q)=>{Z.push(UY($,X,Q))});return{lineCount:Y,height:Y*J,lines:Z}}var t9=[{fontSize:32,lineHeight:36},{fontSize:26,lineHeight:32},{fontSize:21,lineHeight:28},{fontSize:21,lineHeight:28},{fontSize:19,lineHeight:26},{fontSize:18,lineHeight:26}],Y5;function n1($){if($?.type==="heading"){let{fontSize:M}=M$($.depth);return`700 ${M}px "Iowan Old Style", "Palatino Linotype", serif`}switch($?.type){case"code":return"15px ui-monospace, SFMono-Regular, Menlo, monospace";default:return'16px "Iowan Old Style", "Palatino Linotype", serif'}}function P1($,M){if($?.type==="heading")return M$($.depth).lineHeight;if($?.type==="code")return 22;return M}function M$($){return t9[$-1]??t9.at(-1)}function t1($,M,J,Z,X,Y,Q){let K=`${K5(M,Q)}:${X}:${Y}:${J}`,q=$.measuredLines.get(K);if(q)return q;let D=GY($,M,J,Z,X,Y,Q);return O9($,K,D)}function Q5($,M,J,Z,X,Y,Q,K){let q=`${K5(M,K)}:${J}:${Z}:${Y}:${Q}`,D=$.lineBoundaries.get(q);if(D)return D;let A=Z$();if(!A)return $$(X);let V=[{left:0,offset:0}],U=0,G=M.inlines.filter((_)=>_.end>J&&_.start<Z);if(G.length===0)return $$(X);for(let _ of G){let N=Math.max(J,_.start),H=Math.min(Z,_.end),E=M.text.slice(N,H),L=N-J;if(_.kind==="image"){let W=M5(_,K,Q).width;U+=W,L+=E.length,V.push({left:U,offset:L});continue}A.font=J$(Y,_.marks);for(let W of Array.from(E))U+=X$($,A,W),L+=W.length,V.push({left:U,offset:L})}return j9($,q,V)}function VY($,M,J,Z){let X=`${J}::${Z}::${M}`,Y=$.preparedText.get(X);if(Y)return Y;let Q=o9(M,J,{whiteSpace:Z});return T9($,X,Q)}function GY($,M,J,Z,X,Y,Q){let K=M.text;if(K.length===0)return[{end:0,height:Y,start:0,text:"",width:0}];if(zY(M))return _Y($,M,J,X,Y,Q);try{let q=VY($,K,J,yY(Z));return n9(q,X,Y).lines.map((A)=>({end:e9(q.segments,A.end),height:Y,start:e9(q.segments,A.start),text:A.text,width:A.width}))}catch{return NY(K,X,Y)}}function e9($,M){let J=0;for(let Y=0;Y<M.segmentIndex;Y+=1)J+=$[Y]?.length??0;let Z=$[M.segmentIndex]??"",X=Array.from(Z);for(let Y=0;Y<M.graphemeIndex;Y+=1)J+=X[Y]?.length??0;return J}function $$($){let M=[{left:0,offset:0}],J=0,Z=0;for(let X of Array.from($))J+=9,Z+=X.length,M.push({left:J,offset:Z});return M}function NY($,M,J){let Z=Math.max(1,Math.floor(M/9)),X=bY($,Z),Y=0;return X.map((Q)=>{let K=Y,q=K+Q.length;return Y=q,{end:q,height:J,start:K,text:Q,width:Q.length*9}})}function _Y($,M,J,Z,X,Y){let Q=HY($,Z$(),M,J,Z,X,Y);if(Q.length===0)return[{end:0,height:X,start:0,text:"",width:0}];return FY(Q,M.text,Z,X)}function FY($,M,J,Z){let X=[],Y=0;while(Y<$.length){let Q=$[Y].start;if($[Y].text===`
|
|
14
|
-
`){X.push({end:Q,height:
|
|
15
|
-
`)break;let _=K+
|
|
16
|
-
`){let
|
|
17
|
-
`?D+1:D;continue}if(
|
|
18
|
-
`?0:
|
|
19
|
-
`),Z=[];for(let X of J){if(X.length===0){Z.push("");continue}let Y=X;while(Y.length>M){let Q=Y.slice(0,M),K=Q.lastIndexOf(" ");if(K<=0){Z.push(Q),Y=Y.slice(M);continue}Z.push(Q.slice(0,K)),Y=Y.slice(K+1)}Z.push(Y)}return Z}var j2=10,e1=8,s8=120;function Y$($,M,J,Z,X,Y,Q,K,q,D){let A=Math.max(1,...Y.rows.map((N)=>N.cells.length)),U=Math.max(s8,q.width-Q-q.paddingX)/A,G=wY(Z),_=K;for(let N=0;N<Y.rows.length;N+=1){let H=TY(G.get(N)??[],X,Y,U,j2,q.lineHeight,D),E=Math.max(q.lineHeight+e1*2,...H.map((L)=>L.measuredLines.reduce((W,R)=>W+R.height,0)+e1*2));for(let L of H){let W=Q+L.cellIndex*U,R=_+e1;for(let f of L.measuredLines){let I={blockId:L.container.blockId,boundaries:Q5(X,L.container,f.start,f.end,f.text,L.font,U-j2*2,D),regionId:L.container.id,end:f.end,font:L.font,height:f.height,left:W+j2,start:f.start,text:f.text,top:R,width:f.width};$.push(I),i8(M,I),R+=f.height}J.set(L.container.id,{bottom:_+E,left:W,right:W+U,top:_})}jY(M,Y.id,_,_+E),_+=E}return _+q.blockGap}function wY($){let M=new Map;for(let J of $){let Z=OY(J.path);if(!Z)continue;let X=M.get(Z.rowIndex)??[];X.push({cellIndex:Z.cellIndex,container:J}),M.set(Z.rowIndex,X)}return M}function TY($,M,J,Z,X,Y,Q){return[...$].sort((K,q)=>K.cellIndex-q.cellIndex).map(({cellIndex:K,container:q})=>{let D=n1(J),A=P1(J,Y),V=t1(M,q,D,J,Math.max(40,Z-X*2),A,Q);return{cellIndex:K,container:q,font:D,lineHeight:A,measuredLines:V}})}function OY($){let M=/\.rows\.(\d+)\.cells\.(\d+)$/.exec($);if(!M)return null;return{cellIndex:Number(M[2]),rowIndex:Number(M[1])}}function jY($,M,J,Z){let X=$.get(M);$.set(M,{bottom:X?Math.max(X.bottom,Z):Z,top:X?Math.min(X.top,J):J})}var LY={blockGap:16,charWidth:9,indentWidth:24,lineHeight:24,paddingX:16,paddingY:12},CY=24,RY=16,fY=6,mY=10,SY=4;function D5($){let M=Math.max(12,Math.floor($.width/9)),J=Math.max(1,Math.ceil($.text.length/M));return{estimatedHeight:J*24,lineCount:J,width:$.width}}function q5($,M,J=B1(),Z=null){let X=Z??{images:new Map},Y={...LY,...M},Q=[],K=new Map,q=new Map($.regions.map((N)=>[N.id,{textLength:N.text.length}])),D=new Map($.blocks.map((N)=>[N.id,N.depth])),A=new Map($.blocks.map((N)=>[N.id,N])),V=C2($.document.blocks),U=new Map,G=Y.paddingY;for(let N=0;N<$.regions.length;N+=1){let H=$.regions[N],E=D.get(H.blockId)??0,L=Y.paddingX+E*Y.indentWidth,W=Math.max(40,Y.width-L-Y.paddingX),R=V.get(H.blockId)??null;if(R?.type==="table"){let B=A.get(H.blockId)?.regionIds??[],b=$.regions.slice(N,N+B.length);G=Y$(Q,U,K,b,J,R,L,G,Y,X),N+=b.length-1;continue}G=kY(Q,U,K,H,J,R,L,G,W,Y,X);let f=U5(A,V,$.regions,N,Y.blockGap);G+=f;let I=U.get(H.blockId);if(I)I.bottom=Math.max(I.bottom,G)}return{blocks:$.blocks.map((N)=>{let H=U.get(N.id),E=H?.top??Y.paddingY;return{bottom:H?.bottom??E+Y.lineHeight/2,depth:N.depth,id:N.id,top:E,type:N.type}}),regionBounds:vY(Q,K),regionLineIndices:uY(Q),regionMetrics:q,height:Math.max(G,Y.paddingY),lines:Q,options:Y,width:Y.width}}function kY($,M,J,Z,X,Y,Q,K,q,D,A){let V=n1(Y),U=P1(Y,D.lineHeight),G=t1(X,Z,V,Y,q,U,A),_=K;for(let N of G){let H={blockId:Z.blockId,boundaries:Q5(X,Z,N.start,N.end,N.text,V,q,A),regionId:Z.id,end:N.end,font:V,height:N.height,left:Q,start:N.start,text:N.text,top:_,width:N.width};$.push(H),i8(M,H),_+=N.height}return hY($,Z.id,J),_}function uY($){let M=[...$].sort((Z,X)=>Z.top-X.top||Z.left-X.left),J=new Map;$.length=0,$.push(...M);for(let[Z,X]of $.entries()){let Y=J.get(X.regionId)??[];Y.push(Z),J.set(X.regionId,Y)}return J}function vY($,M){let J=new Map(M);for(let Z of $){let X=J.get(Z.regionId),Y={bottom:Z.top+Z.height,left:Z.left,right:Z.left+Z.width,top:Z.top};J.set(Z.regionId,X?{bottom:Math.max(X.bottom,Y.bottom),left:Math.min(X.left,Y.left),right:Math.max(X.right,Y.right),top:Math.min(X.top,Y.top)}:Y)}return J}function hY($,M,J){let Z=$.filter((X)=>X.regionId===M);if(Z.length===0)return;J.set(M,{bottom:Math.max(...Z.map((X)=>X.top+X.height)),left:Math.min(...Z.map((X)=>X.left)),right:Math.max(...Z.map((X)=>X.left+X.width)),top:Math.min(...Z.map((X)=>X.top))})}function i8($,M){let J=$.get(M.blockId),Z=M.top+M.height;$.set(M.blockId,{bottom:J?Math.max(J.bottom,Z):Z,top:J?Math.min(J.top,M.top):M.top})}function A$($,M){let J=0,Z=$.lines.length-1;while(J<=Z){let X=J+Z>>1,Y=$.lines[X];if(M<Y.top){Z=X-1;continue}if(M>=Y.top+Y.height){J=X+1;continue}return{index:X,line:Y}}return null}function o8($,M){let J=[...$.regionBounds.entries()].find(([,Y])=>{return M.x>=Y.left&&M.x<=Y.right&&M.y>=Y.top&&M.y<=Y.bottom});if(J)return A5($,J[0],M.y);let Z=A$($,M.y);if(!Z)return null;let X=gY($,M.y,Z.index);if(X.length===1)return X[0]??null;return X.find((Y)=>{let Q=$.regionBounds.get(Y.line.regionId);return Q?M.x>=Q.left&&M.x<=Q.right:!1})??[...X].sort((Y,Q)=>{let K=$.regionBounds.get(Y.line.regionId),q=$.regionBounds.get(Q.line.regionId),D=Q$(M.x,K),A=Q$(M.x,q);return D-A})[0]??null}function n8($,M,J){if($.lines.length===0)return{endIndex:0,startIndex:0};let Z=M+J,X=K$($,M),Y=K$($,Z);if(X>0){let Q=$.lines[X-1];if(Q.top+Q.height>M)X-=1}if(Y<$.lines.length){if($.lines[Y].top<Z)Y+=1}return{endIndex:Y,startIndex:X}}function g0($,M,J){if(!$.regionMetrics.get(J.regionId))return null;let X=j0($,J.regionId,J.offset);if(!X)return null;return{blockId:X.blockId,regionId:X.regionId,height:X.height,left:W0(X,J.offset-X.start),offset:J.offset,top:X.top}}function j0($,M,J){return L2($,M,J)?.line??null}function A5($,M,J){let Z=$.regionLineIndices.get(M);if(!Z||Z.length===0)return null;let X=Z[0],Y=Number.POSITIVE_INFINITY;for(let Q of Z){let K=$.lines[Q],q=J<K.top?K.top-J:J>K.top+K.height?J-(K.top+K.height):0;if(q<Y)Y=q,X=Q;if(q===0)break}return{index:X,line:$.lines[X]}}function L2($,M,J){let Z=$.regionLineIndices.get(M);if(!Z||Z.length===0)return null;let X=0,Y=Z.length-1;while(X<=Y){let A=X+Y>>1,V=Z[A],U=$.lines[V];if(J<U.start){Y=A-1;continue}if(J>U.end){X=A+1;continue}return{index:V,line:U}}let Q=Z[0],K=Z[Z.length-1],q=$.lines[Q],D=$.lines[K];if(J<=q.start)return{index:Q,line:q};if(J>=D.end)return{index:K,line:D};return null}function gY($,M,J){let Z=[];for(let X=J;X>=0;X-=1){let Y=$.lines[X];if(M<Y.top||M>=Y.top+Y.height)break;Z.unshift({index:X,line:Y})}for(let X=J+1;X<$.lines.length;X+=1){let Y=$.lines[X];if(M<Y.top||M>=Y.top+Y.height)break;Z.push({index:X,line:Y})}return Z}function Q$($,M){if(!M)return Number.POSITIVE_INFINITY;if($<M.left)return M.left-$;if($>M.right)return $-M.right;return 0}function W0($,M){return $.left+IY($.boundaries,M)}function C2($){let M=new Map,J=(Z)=>{for(let X of Z)if(M.set(X.id,X),X.type==="blockquote"||X.type==="listItem")J(X.children);else if(X.type==="list")J(X.items)};return J($),M}function IY($,M){for(let Z of $)if(Z.offset===M)return Z.left;return $.filter((Z)=>Z.offset<=M).at(-1)?.left??0}function K$($,M){let J=0,Z=$.lines.length;while(J<Z){let X=J+Z>>1,Y=$.lines[X];if(Y.top+Y.height<=M)J=X+1;else Z=X}return J}function U$($,M){if($.length===0)return 0;for(let J=1;J<$.length;J+=1){let Z=$[J-1],X=$[J],Y=Z.left+(X.left-Z.left)/2;if(M<=Y)return Z.offset;if(M<=X.left)return X.offset}return $.at(-1)?.offset??0}function U5($,M,J,Z,X){let Y=J[Z],Q=J[Z+1];if(!Y||!Q)return X;if(D$($,Y.blockId,Q.blockId,"list"))return fY;if(D$($,Y.blockId,Q.blockId,"blockquote"))return mY;if(Y.blockId===Q.blockId)return SY;return X+pY(M.get(Y.blockId))}function pY($){if($?.type!=="heading")return 0;if($.depth===1)return CY;return $.depth===2?RY:0}function D$($,M,J,Z){let X=q$($,M,Z),Y=q$($,J,Z);for(let Q of X)if(Y.has(Q))return!0;return!1}function q$($,M,J){let Z=new Set,X=$.get(M)??null;while(X){if(X.type===J)Z.add(X.id);X=X.parentBlockId?$.get(X.parentBlockId)??null:null}return Z}function t8($,M,J,Z=[],X=B1(),Y=null){let Q=Y??{images:new Map},K=C2($.document.blocks),q=new Map($.blocks.map((W)=>[W.id,W])),D=new Set(Z),A=Math.max(0,J.top-J.overscan),V=J.top+J.height+J.overscan,U=cY(X,$,K,q,M,Q),G=V$(U,A),_=V$(U,V);if(G>0){let W=U.entries[G-1];if(W&&W.bottom>A)G-=1}if(_<U.entries.length){let W=U.entries[_];if(W&&W.top<V)_+=1}for(let W of D){let R=U.containerIndices.get(W);if(R===void 0)continue;G=Math.min(G,R),_=Math.max(_,R+1)}if(!Number.isFinite(G)||!Number.isFinite(_))return{estimateRegionBounds:U.estimateRegionBounds,layout:q5({...$,regions:[]},M,X,Q),totalHeight:U.totalHeight,viewport:J};let N=rY($,q,U.containerIndices,G,_),H=U.entries[N.startIndex]?.top??M.paddingY??0,E=q5({...$,regions:$.regions.slice(N.startIndex,N.endIndex)},M,X,Q),L=dY(E,H,U.totalHeight);return lY(X,$,L,M,Q),{estimateRegionBounds:U.estimateRegionBounds,layout:L,totalHeight:U.totalHeight,viewport:J}}function lY($,M,J,Z,X){for(let[Y,Q]of J.regionBounds){let K=Q.bottom-Q.top,q=M.regionIndex.get(Y);L9($,G$(q??{path:Y,inlines:[],text:""},Z,X),K)}}function dY($,M,J){return{...$,blocks:$.blocks.map((Z)=>({...Z,bottom:Z.bottom+M,top:Z.top+M})),regionBounds:new Map([...$.regionBounds.entries()].map(([Z,X])=>[Z,{bottom:X.bottom+M,left:X.left,right:X.right,top:X.top+M}])),height:J,lines:$.lines.map((Z)=>({...Z,top:Z.top+M}))}}function rY($,M,J,Z,X){let Y=Z,Q=X;for(let K=Z;K<X;K+=1){let q=$.regions[K],D=M.get(q.blockId);if(!D)continue;if(D.type==="table"){let A=J.get(D.regionIds[0]??""),V=J.get(D.regionIds[D.regionIds.length-1]??"");if(A!==void 0)Y=Math.min(Y,A);if(V!==void 0)Q=Math.max(Q,V+1)}}return{endIndex:Q,startIndex:Y}}function xY($,M,J,Z,X,Y){let Q=G$(M,X,Y),K=$.measuredContainerHeights.get(Q);if(K!==void 0)return K;let q=X.paddingX??0,D=X.indentWidth??24,A=P1(J,X.lineHeight??24),V=q+Z*D,U=Math.max(40,X.width-V-q);if(M.inlines.some((N)=>N.kind==="image")){let N=n1(J);return t1($,M,N,J,U,A,Y).reduce((H,E)=>H+E.height,0)}let G=D5({text:M.text,width:U});return Math.max(A,G.lineCount*A)}function cY($,M,J,Z,X,Y){let Q=oY(M,X,Y),K=R9($,M,Q);if(K)return K;let q=X.paddingY??0,D=[],A=new Map;for(let V=0;V<M.regions.length;V+=1){let U=M.regions[V],G=J.get(U.blockId)??null;if(G?.type==="table"){let E=aY({block:G,blockMap:J,containerIndices:A,entries:D,index:V,options:X,runtimeBlocks:Z,totalHeight:q,regions:M.regions});if(E){V=E.nextIndex-1,q=E.totalHeight;continue}}let _=xY($,U,G,Z.get(U.blockId)?.depth??0,X,Y),N=q,H=N+_;D.push({bottom:H,top:N}),A.set(U.id,V),q=H+U5(Z,J,M.regions,V,X.blockGap??16)}return f9($,M,Q,{containerIndices:A,entries:D,estimateRegionBounds(V){let U=A.get(V);return U===void 0?null:D[U]??null},totalHeight:q})}function aY({block:$,blockMap:M,containerIndices:J,entries:Z,index:X,options:Y,runtimeBlocks:Q,totalHeight:K,regions:q}){let D=Q.get($.id),A=D?.regionIds??[];if(A.length===0)return null;let V=q.slice(X,X+A.length);if(V.length===0||V[0]?.blockId!==$.id)return null;let U=Y.paddingX??0,G=Y.indentWidth??24,_=D?.depth??0,N=U+_*G,H=Math.max(s8,Y.width-N-U),E=Math.max(1,...$.rows.map((B)=>B.cells.length)),L=H/E,W=Math.max(40,L-j2*2),R=P1($,Y.lineHeight??24),f=sY(V,X),I=K;for(let B=0;B<$.rows.length;B+=1){let b=f.get(B)??[],z=Math.max(R+e1*2,...b.map(({region:P})=>iY(P,W,R)+e1*2)),T=I+z;for(let{index:P,region:y}of b)Z[P]={bottom:T,top:I},J.set(y.id,P);I=T}for(let B=X;B<X+V.length;B+=1){let b=q[B];if(!b||Z[B])continue;Z[B]={bottom:I,top:I},J.set(b.id,B)}return{nextIndex:X+V.length,totalHeight:I+U5(Q,M,q,X+V.length-1,Y.blockGap??16)}}function sY($,M){let J=new Map;for(let[Z,X]of $.entries()){let Y=X.tableCellPosition?.rowIndex;if(Y===void 0)continue;let Q=J.get(Y)??[];Q.push({index:M+Z,region:X}),J.set(Y,Q)}return J}function iY($,M,J){let Z=D5({text:$.text,width:M});return Math.max(J,Z.lineCount*J)}function oY($,M,J){return[M.width,M.paddingX??0,M.paddingY??0,M.indentWidth??24,M.lineHeight??24,M.blockGap??16,nY($,J)].join(":")}function V$($,M){let J=0,Z=$.entries.length;while(J<Z){let X=J+Z>>1;if($.entries[X].bottom<=M)J=X+1;else Z=X}return J}function G$($,M,J){return`${K5($,J)}:${M.width}:${M.paddingX??0}:${M.indentWidth??24}:${M.lineHeight??24}`}function nY($,M){return $.regions.flatMap((J)=>J.inlines.filter((Z)=>Z.kind==="image"&&Z.image).map((Z)=>{let X=Z.image?M.images.get(Z.image.url):null;return`${Z.image?.url??""}:${Z.image?.width??0}:${X?.status??"loading"}:${X?.intrinsicWidth??0}:${X?.intrinsicHeight??0}`})).join("|")}var V5=null;function tY($){let M=/(\d+(?:\.\d+)?)\s*px/.exec($);return M?Number.parseFloat(M[1]):16}function Y1($){V5??=new Map;let M=V5.get($);if(M)return M;let J=F$(),Z=Math.max(12,Math.round(tY($)));if(!J){let U={ascent:Math.round(Z*0.8),descent:Math.max(2,Z-Math.round(Z*0.8)),emHeight:Z};return V5.set($,U),U}J.font=$;let X=J.measureText("Hg"),Y=Math.round(X.actualBoundingBoxAscent||0),Q=Math.round(X.actualBoundingBoxDescent||0),K=Y+Q,q=Math.max(Z,K),D=K>0?Y:Math.round(q*0.8),A=K>0?Q:Math.max(2,q-D),V={ascent:D,descent:A,emHeight:q};return V5.set($,V),V}function eY($,M){let{emHeight:J}=Y1(M);return Math.max(0,Math.floor(($-J)/2))}function N$($,M){let{ascent:J}=Y1(M);return eY($,M)+J}var G5;function _$($,M){let J=F$();if(!J||$.length===0)return 0;return J.font=M,J.measureText($).width}function F$(){if(G5!==void 0)return G5;return G5=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):typeof document<"u"?document.createElement("canvas"):null)?.getContext("2d")??null,G5}var $Q=18,MQ=14,JQ=22;function y0($,M,J){let Z=XQ($,J);if(!Z)return null;return H$($,M,Z,J.x)}function e8($,M,J){let Z=$.lines[$.lines.length-1];if(!Z||J.y<=Z.top+Z.height)return null;return H$($,M,Z,J.x)}function H$($,M,J,Z){let X=$.regionMetrics.get(J.regionId);if(!X)return null;let Y=Math.max(0,Z-h0(M,J)-J.left),Q=U$(J.boundaries,Y),K=Math.min(X.textLength,J.start+Q);return{regionId:J.regionId,offset:K,left:W0(J,Q),top:J.top,height:J.height}}function $6($,M,J,Z){let X=Y6(M,Z.regionId);if(!X)return null;let Y=y0($,M,J);if(Y)return{regionId:Y.regionId,offset:Y.offset};let Q=J.y<QQ($);return{regionId:Z.regionId,offset:Q?0:X.text.length}}function M6($,M,J){let Z=y0($,M,J);if(!Z)return null;let X=Y6(M,Z.regionId);if(!X||X.text.length===0)return null;let Y=Z.offset<X.text.length&&/\w/.test(X.text[Z.offset]??"")?Z.offset:Z.offset>0&&/\w/.test(X.text[Z.offset-1]??"")?Z.offset-1:Z.offset,Q=KQ(X.text,Y);if(Q.start===Q.end)return null;return{anchor:{regionId:Z.regionId,offset:Q.start},focus:{regionId:Z.regionId,offset:Q.end}}}function z$($,M,J){let Z=YQ($,J);if(!Z||Z.start!==0)return null;let X=$2(M,Z.blockId,"listItem");if(!X)return null;if(f2(M,X.id)?.kind!=="task")return null;let Q=R2(Z),K=Q.left-4,q=Q.left+Q.size+4,D=Q.top-4,A=Q.top+Q.size+4;return J.x>=K&&J.x<=q&&J.y>=D&&J.y<=A?{listItemId:X.id}:null}function E$($,M,J){let Z=y0($,M,J);if(!Z)return null;let X=Y6(M,Z.regionId);if(!X)return null;let Y=X.inlines.find((K)=>K.link&&Z.offset>=K.start&&Z.offset<K.end);if(!Y?.link)return null;let Q=X6($,M,Z.regionId,Y.start);if(!Q)return null;return{anchorBottom:Q.anchorBottom,anchorLeft:Q.anchorLeft,endOffset:Y.end,regionId:Z.regionId,startOffset:Y.start,title:Y.link.title,url:Y.link.url}}function J6($,M,J,Z){let X=z$($,M,J);if(X)return{kind:"task-toggle",listItemId:X.listItemId};let Y=y0($,M,J);if(!Y)return null;let Q=W$(Y.regionId,Y.offset,Z),K=Q!==null?B$(Q,$,M,Z):null,q=E$($,M,J);if(q)return{anchorBottom:K?.anchorBottom??q.anchorBottom,anchorLeft:K?.anchorLeft??q.anchorLeft,endOffset:q.endOffset,kind:"link",commentThreadIndex:Q,regionId:q.regionId,startOffset:q.startOffset,title:q.title,url:q.url};return{anchorBottom:K?.anchorBottom??Y.top+Y.height,anchorLeft:K?.anchorLeft??Y.left,kind:"text",commentThreadIndex:Q}}function Z6($,M,J,Z){let X=M.documentIndex.regionIndex.get(J.regionId);if(!X)return null;let Y=W$(J.regionId,J.offset,Z),Q=Y!==null?B$(Y,$,M,Z):null,K=X.inlines.find((q)=>J.offset>=q.start&&J.offset<=q.end)??null;if(K?.link){let q=X6($,M,J.regionId,K.start);if(!q)return null;return{anchorBottom:Q?.anchorBottom??q.anchorBottom,anchorLeft:Q?.anchorLeft??q.anchorLeft,commentThreadIndex:Y,endOffset:K.end,kind:"link",regionId:J.regionId,startOffset:K.start,title:K.link.title,url:K.link.url}}if(Q)return{anchorBottom:Q.anchorBottom,anchorLeft:Q.anchorLeft,commentThreadIndex:Y,kind:"text"};return null}function I0($,M,J){let Z=j0(M,J.regionId,J.offset);if(!Z)return J.left;return J.left+h0($,Z)+ZQ($,Z,J.offset)}function Q1($,M,J){return W0(M,J)+h0($,M)}function h0($,M){let J=$2($,M.blockId,"listItem");if(!J)return 0;return f2($,J.id)?.kind==="task"?JQ:$Q}function R2($){return{left:$.left,size:MQ,top:$.top+3}}function $2($,M,J){let Z=$.documentIndex.blockIndex.get(M)??null;while(Z){if(Z.type===J)return Z;let X=Z.parentBlockId;Z=X?$.documentIndex.blockIndex.get(X)??null:null}return null}function f2($,M){return $.documentIndex.listItemMarkers.get(M)??null}function W$($,M,J){for(let Z of J)if(Z.regionId===$&&M>=Z.startOffset&&M<=Z.endOffset)return Z.threadIndex;return null}function B$($,M,J,Z){let X=Z.find((Y)=>Y.threadIndex===$);if(!X)return null;return X6(M,J,X.regionId,X.startOffset)}function X6($,M,J,Z){let X=j0($,J,Z);if(!X)return null;return{anchorBottom:X.top+X.height,anchorLeft:W0(X,Z)+h0(M,X)}}function ZQ($,M,J){if(J<=M.end)return 0;let Z=$.documentIndex.regionIndex.get(M.regionId);if(!Z)return 0;let X=Z.text.slice(M.end,J);if(!/^[ \t]+$/u.test(X))return 0;return _$(X,M.font)}function XQ($,M){for(let[Z,X]of $.regionBounds)if(M.x>=X.left&&M.x<=X.right&&M.y>=X.top&&M.y<=X.bottom)return A5($,Z,M.y)?.line??null;let J=o8($,M)?.line??null;if(J)return J;for(let Z of $.blocks)if(M.y>=Z.top&&M.y<=Z.bottom){for(let X=$.lines.length-1;X>=0;X--)if($.lines[X].blockId===Z.id)return $.lines[X]}return null}function YQ($,M){return $.lines.find((J)=>M.y>=J.top-4&&M.y<=J.top+J.height+4)??$.lines.filter((J)=>Math.abs(M.y-(J.top+J.height/2))<=10).sort((J,Z)=>Math.abs(M.y-(J.top+J.height/2))-Math.abs(M.y-(Z.top+Z.height/2)))[0]??null}function Y6($,M){return $.documentIndex.regionIndex.get(M)??null}function QQ($){return $.lines[0]?.top??0}function KQ($,M){let J=M,Z=M;while(J>0&&/\w/.test($[J-1]??""))J-=1;while(Z<$.length&&/\w/.test($[Z]??""))Z+=1;return{end:Z,start:J}}function Q6($,M,J,Z=null){let X={height:M.height,overscan:Math.max(160,M.height),top:M.top},Y=t8($.documentIndex,M,X,[$.selection.anchor.regionId,$.selection.focus.regionId],J,Z);return{blockMap:C2($.documentIndex.document.blocks),estimateRegionBounds:Y.estimateRegionBounds,regionBounds:new Map(Y.layout.regionBounds),layout:Y.layout,paintHeight:Math.max(240,X.height+X.overscan*2),paintTop:Math.max(0,X.top-X.overscan),totalHeight:Y.totalHeight,viewport:{height:X.height,top:X.top}}}function N5($,M,J){return y0(M.layout,$,J)??e8(M.layout,$,J)}function m2($,M,J,Z){return $6(M.layout,$,J,Z)}function K6($,M,J){return M6(M.layout,$,J)}function D6($,M,J,Z){return J6(M.layout,$,J,Z)}function q6($,M,J,Z){return Z6(M.layout,$,J,Z)}function A6($,M,J){return g0(M.layout,$.documentIndex,J)}function o0($,M,J){let Z=g0(M.layout,$.documentIndex,J);if(!Z)return null;return{...Z,left:I0($,M.layout,Z)}}function P$($,M,J,Z,X){let Y=Z-J,Q=X-Y;if(Z<=$)return{end:M+Q,start:$+Q};if(J>=M)return{end:M,start:$};let K=Math.max(0,Math.min(J,M)-$),q=Math.max(0,M-Math.max(Z,$)),D=$<J?$:J;return{end:D+K+X+q,start:D}}function V6($,M,J){let Z=J.trim();if(Z.length===0||M.startOffset===M.endOffset)return null;let X=$.regionIndex.get(M.regionId)??null,Y=X?U6($,X):null;if(!Y)return null;return L8({anchor:y2(Y,M.startOffset,M.endOffset),body:Z,quote:b2(Y,M.startOffset,M.endOffset)})}function L0($){let M="documentIndex"in $?$.documentIndex:$,J=_5(M),Z=M.document.comments,X=[...Z],Y=[];for(let[Q,K]of Z.entries()){let q=w2(K,M.document);if(!q.match)continue;let A=J.findBySemanticMatch(q.match.containerId,q.match.containerOrdinal)?.runtimeContainer??null;if(!A)continue;if(q.repair)X[Q]={...K,anchor:q.repair.anchor,quote:q.repair.quote};Y.push({endOffset:q.match.endOffset,resolution:q,regionId:A.id,resolved:K.resolvedAt!=null,startOffset:q.match.startOffset,threadIndex:Q})}return{liveRanges:Y,threads:X}}function G6($,M,J,Z,X,Y){if($.document.comments.length===0)return M.document.comments;let Q=$.commentContainerIndex.get(J.semanticRegionId)??[],K=new Set(Q);if(Q.length===0)return M.document.comments;let q=L0($),D=new Map(q.liveRanges.map((G)=>[G.threadIndex,G])),A=U6($,J),V=M2(M,J.path),U=V?U6(M,V):null;if(!A||!U)return M.document.comments;return M.document.comments.map((G,_)=>{if(!K.has(_))return G;let N=D.get(_),H=N?.resolution.match??null;if(!N||!H||H.containerId!==A.id)return G;let E=P$(H.startOffset,H.endOffset,Z,X,Y.length);return{...G,anchor:y2(U,E.start,E.end),quote:b2(U,E.start,E.end)}})}function U6($,M){let J=DQ($,M);if(!J)return null;return{containerKind:J,containerOrdinal:-1,id:M.semanticRegionId,text:M.text}}function DQ($,M){if($.tableCellIndex.has(M.id))return"tableCell";return E9(M.blockType)}function F5($,M){if(M.length===0)return[];let J=_5($),Z=J.list();return M.map((X)=>({...X,cursorPoint:qQ(X,Z,J),viewport:null}))}function qQ($,M,J){if(!$.cursor)return null;let Z=AQ(M,$.cursor),X=UQ(Z,$.cursor);if(X.length!==1)return null;let Y=X[0],Q=J.resolveRuntimeContainer(Y.container.id);if(!Q)return null;return{offset:Math.max(0,Math.min(Y.offset,Q.text.length)),regionId:Q.id}}function AQ($,M){return M.kind?$.filter((J)=>J.containerKind===M.kind):$}function UQ($,M){if(M.prefix&&M.suffix)return VQ($,M.prefix,M.suffix);if(M.prefix)return y$($,M.prefix,"after");if(M.suffix)return y$($,M.suffix,"before");return[]}function y$($,M,J){let Z=[];for(let X of $)for(let Y of v0(X.text,M))Z.push({container:X,offset:J==="after"?Y+M.length:Y});return Z}function VQ($,M,J){let Z=[];for(let X of $)for(let Y of c1(X.text,M,J))Z.push({container:X,offset:Y.startOffset});return Z}var GQ=48;function S2($,M,J){let Z="documentIndex"in $?$.documentIndex:$;if(J.length===0)return[];return J.map((X)=>({...X,viewport:NQ(Z,M,X)}))}function NQ($,M,J){if(!J.cursorPoint)return{status:"unresolved"};let Z=g0(M.layout,$,J.cursorPoint),X=Z?{bottom:Z.top+Z.height,top:Z.top}:M.estimateRegionBounds(J.cursorPoint.regionId);if(!X)return{status:"unresolved"};return{scrollTop:FQ(M,X),status:_Q(M,X)}}function _Q($,M){let J=$.viewport.top,Z=J+$.viewport.height;if(M.bottom<J)return"above";if(M.top>Z)return"below";return"visible"}function FQ($,M){let J=Math.max(0,$.totalHeight-$.viewport.height),Z=M.top-Math.min(GQ,$.viewport.height/4);return Math.max(0,Math.min(J,Z))}function _5($){let M=$5($.document),J=new Map(M.map((X)=>[X.id,X])),Z=new Map($.regions.map((X)=>[X.semanticRegionId,X]));return{findBySemanticMatch(X,Y){let Q=J.get(X)??M[Y]??null;if(!Q)return null;return{runtimeContainer:Z.get(Q.id)??null,semanticContainer:Q}},list(X){return X?M.filter((Y)=>Y.containerKind===X):M},resolveRuntimeContainer(X){return Z.get(X)??null}}}var k2="",b$=1e6;function u2($,M,J){return`${$}:${M}:${J}`}function J2($){let M=uQ($),J=_6(M.blocks.map((Z,X)=>h2(Z,X)));return F6(M,J)}function h2($,M){let J=[],Z=[],X=[],Y=new Set,Q=0;function K(D,A,V,U,G=null){if(Z.length>0)X.push(`
|
|
20
|
-
`),Q+=1;let _=
|
|
21
|
-
${M.text}`:M.text}function
|
|
22
|
-
`)}function
|
|
23
|
-
`});break;case"image":X({id:Y.id,image:{alt:Y.alt,title:Y.title,url:Y.url,width:Y.width},inlineCode:!1,kind:"image",link:M,marks:[],originalType:null,text:
|
|
24
|
-
`.slice(M,J);case"image":return k2.slice(M,J);case"inlineCode":return $.code.slice(M,J);case"link":return z6($.children,M,J);case"text":return $.text.slice(M,J);case"unsupported":return $.source.slice(M,J)}}function W6($,M,J,Z){let X=lQ($.children,M,J,Z);if(X===null)return null;let Y=D0(O$($.children,M,J,Z,X,`${$.path}.children`));return Y.length>0?b1($,Y,M,J):null}function B6($,M,J){let Z=0,X=null,Y=(Q)=>{for(let K of Q){let q=b0(K),D=Z,A=D+q;if(Z=A,J<=D||M>=A)continue;if(K.type==="text"){let V=Math.max(M,D);if(Math.min(J,A)>V)X=X===null?new Set(K.marks):new Set(K.marks.filter((G)=>X?.has(G)));continue}if(K.type==="link"){let V=Z;Z=D,Y(K.children),Z=V}}};return Y($.children),X?[...X]:[]}function lQ($,M,J,Z){let X=0,Y=!1,Q=!0,K=(q)=>{for(let D of q){let A=b0(D),V=X,U=V+A;if(X=U,J<=V||M>=U)continue;if(D.type==="text"){let G=Math.max(M,V);if(Math.min(J,U)>G)Y=!0,Q&&=D.marks.includes(Z);continue}if(D.type==="link"){let G=X;X=V,K(D.children),X=G}}};return K($),Y?Q:null}function O$($,M,J,Z,X,Y){let Q=[],K=0;for(let[q,D]of $.entries()){let A=K,V=b0(D),U=A+V,G=`${Y}.${q}`;if(K=U,J<=A||M>=U){Q.push(D);continue}if(D.type==="text"){Q.push(...dQ(D,Math.max(0,M-A),Math.min(V,J-A),Z,X,G));continue}if(D.type==="link"){let _=D0(O$(D.children,Math.max(0,M-A),Math.min(V,J-A),Z,X,`${G}.children`));if(_.length>0)Q.push({...D,children:_});continue}Q.push(D)}return Q}function dQ($,M,J,Z,X,Y){let Q=$.text.slice(0,M),K=$.text.slice(M,J),q=$.text.slice(J),D=X?$.marks.filter((A)=>A!==Z):rQ($.marks,Z);return[y1(Q,$.marks,`${Y}.before`),y1(K,D,`${Y}.selected`),y1(q,$.marks,`${Y}.after`)].filter(Boolean)}function rQ($,M){return $.includes(M)?$:[...$,M].sort()}function P6($,M,J){let Z=xQ($.children,M,J,`${$.path}.children`);return Z.length>0?b1($,Z,M,J):null}function xQ($,M,J,Z){let X=j$($,M,J);if(X)return g2($,M,J,Z,y1(X.code,[],`${Z}.selected`));let Y=z6($,M,J);if(Y.length===0)return $;return g2($,M,J,Z,E6(Y,`${Z}.selected`))}function j$($,M,J){let Z=0;for(let X of $){let Y=b0(X),Q=Z,K=Q+Y;if(Z=K,M===Q&&J===K&&X.type==="inlineCode")return X;if(X.type==="link"){let q=j$(X.children,Math.max(0,M-Q),Math.min(Y,J-Q));if(q)return q}}return null}function y6($,M,J,Z,X){return E5($,M,J,Z,(Y,Q,K)=>L$(Y,Q,K,X))}function L$($,M,J,Z){let X=D0(cQ($.children,M,J,Z,`${$.path}.children`)??[]);return X.length>0?b1($,X,M,J):null}function cQ($,M,J,Z,X){let Y=[],Q=0,K=!1;for(let[q,D]of $.entries()){let A=`${X}.${q}`,V=b0(D),U=Q,G=U+V;if(Q=G,!K&&D.type==="link"&&M===U&&J===G){if(Z===null)Y.push(...D.children);else Y.push(I1({children:D.children,path:A,title:D.title,url:Z}));K=!0;continue}Y.push(D)}return K?Y:null}function X2($,M){let J=$.regionIndex.get(M);if(!J)return null;let Z=x1($.document.blocks,J.blockId);if(!Z)return null;return b6(Z,J.path,J.semanticRegionId)}function aQ($,M,J,Z,X){if(J>=Z)return null;let Y=X2($,M);return Y?X(Y,J,Z):null}function E5($,M,J,Z,X){let Y=aQ($,M,J,Z,X);return Y?{kind:"replace-block",block:Y.block,blockId:Y.blockId,selection:Y.selection}:null}function b6($,M,J){if($.type==="heading"||$.type==="paragraph")return{block:$,children:$.children,kind:"inlineBlock",path:M.replace(/\.children$/,"")};if($.type!=="table")return null;let Z=/^(.*\.rows\.\d+\.cells\.\d+)$/.exec(M);if(!Z)return null;for(let X of $.rows)for(let Y of X.cells)if(Y.id===J)return{block:$,blockPath:Z[1].replace(/\.rows\.\d+\.cells\.\d+$/,""),cell:Y,children:Y.children,kind:"tableCell",path:Z[1]};return null}function R$($,M,J){let Z=X2($,M.focus.regionId);if(!Z)return null;let X=Math.min(M.anchor.offset,M.focus.offset),Y=Math.max(M.anchor.offset,M.focus.offset);return{kind:"replace-block",...I2(Z,X,Y,J)}}function I2($,M,J,Z){let X=`${$.path}.children`,Y=Z(`${X}.selected`),Q=g2($.children,M,J,X,Y);return b1($,Q,M+1,M+1)}function b1($,M,J,Z){switch($.kind){case"inlineBlock":return{block:T0($.block,M),blockId:$.block.id,selection:C$(`${$.path}.children`,J,Z)};case"tableCell":{let X=M1({children:M,path:$.path}),Y=$.block.rows.map((Q)=>({...Q,cells:Q.cells.map((K)=>K.id===$.cell.id?X:K)}));return{block:u0($.block,Y),blockId:$.block.id,selection:C$($.path,J,Z)}}}}function C$($,M,J){return{endOffset:J,kind:"region-range-path",path:$,startOffset:M}}function G0($,M,J=0){return{childIndices:M,kind:"descendant-primary-region",offset:J,rootIndex:$}}function $0($,M=0){return{kind:"root-primary-region",offset:M,rootIndex:$}}function T1($,M,J,Z=0){return{cellIndex:J,kind:"table-cell",offset:Z,rootIndex:$,rowIndex:M}}function K1($,M){return $.regionIndex.get(M)??null}function M2($,M){return $.regionPathIndex.get(M)??null}function Y2($,M,J,Z){let X=$.tableCellRegionIndex.get(u2(M,J,Z));return X?$.regionIndex.get(X)??null:null}function sQ($){return $.anchor.regionId===$.focus.regionId&&$.anchor.offset===$.focus.offset}function Y0($,M){let J="documentIndex"in $?$.documentIndex:$,Z="documentIndex"in $?$.selection:M,X=sQ(Z),Y=f$(J,Z.anchor),Q=f$(J,Z.focus);if(Y<=Q)return{collapsed:X,end:Z.focus,start:Z.anchor};return{collapsed:X,end:Z.anchor,start:Z.focus}}function p2($,M){if(!M)return null;if("kind"in M){if(M.kind==="root-primary-region"){let Z=$.document.blocks[M.rootIndex],X=Z?w6($,Z):null;return X?w1(X.id,W5(X.text,M.offset)):null}if(M.kind==="descendant-primary-region"){let Z=$.document.blocks[M.rootIndex],X=Z?iQ(Z,M.childIndices):null,Y=X?w6($,X):null;return Y?w1(Y.id,W5(Y.text,M.offset)):null}if(M.kind==="table-cell"){let Z=$.document.blocks[M.rootIndex];if(!Z||Z.type!=="table")return null;let X=Y2($,Z.id,M.rowIndex,M.cellIndex);return X?w1(X.id,W5(X.text,M.offset)):null}let J=M2($,M.path);if(!J)return null;if(M.kind==="region-path")return w1(J.id,W5(J.text,M.offset));return{anchor:{regionId:J.id,offset:Math.max(0,Math.min(M.startOffset,J.text.length))},focus:{regionId:J.id,offset:Math.max(0,Math.min(M.endOffset,J.text.length))}}}return M}function f$($,M){let J=$.regionOrderIndex.get(M.regionId);if(J===void 0)throw Error(`Unknown canvas region: ${M.regionId}`);return J*b$+M.offset}function w1($,M){let J={offset:M,regionId:$};return{anchor:J,focus:J}}function W5($,M){return M==="end"?$.length:Math.max(0,Math.min(M,$.length))}function iQ($,M){let J=$;for(let Z of M){if(!J)return null;let X=m$(J);if(!X)return null;J=X[Z]??null}return J}function w6($,M){let J=$.blockIndex.get(M.id);if(!J)return null;let Z=J.regionIds[0];if(Z)return $.regionIndex.get(Z)??null;let X=m$(M);if(!X)return null;for(let Y of X){let Q=w6($,Y);if(Q)return Q}return null}function m$($){switch($.type){case"list":return $.items;case"blockquote":case"listItem":return $.children;default:return null}}function l2($){let M=$.documentIndex.regionIndex.get($.selection.anchor.regionId)??null,J=M?$.documentIndex.blockIndex.get(M.blockId)??null:null,Z=$.selection.anchor.offset,X=M?.inlines.find((Y)=>Z>Y.start&&Z<Y.end)??M?.inlines.find((Y)=>Y.end===Z)??M?.inlines.find((Y)=>Y.start===Z)??null;return{block:J?{blockId:J.id,depth:J.depth,nodeType:J.type,text:M?.text??""}:null,span:X?.link?{kind:"link",url:X.link.url}:X&&X.marks.length>0?{kind:"marks",marks:X.marks}:{kind:"none"}}}function B5($){let M=$.documentIndex.regionIndex.get($.selection.anchor.regionId)??null,J=$.selection.anchor.offset,Z=M?.inlines.find((X)=>J>X.start&&J<X.end)??M?.inlines.find((X)=>X.end===J)??M?.inlines.find((X)=>X.start===J)??null;return Z?.kind==="image"?Z:null}function P5($){let M=Y0($.documentIndex,$.selection);if(M.start.regionId!==M.end.regionId||M.start.offset===M.end.offset)return[];let J=$.documentIndex.regionIndex.get(M.start.regionId);if(!J)return[];let Z=x1($.documentIndex.document.blocks,J.blockId);if(!Z)return[];let X=b6(Z,J.path,J.semanticRegionId);return X?B6(X,M.start.offset,M.end.offset):[]}var T6=new Map([["rgba(0, 0, 0, 0)",[0,0,0,0]]]);function d2($){switch($.kind){case"active-block-flash":return 300;case"deleted-text-fade":return 180;case"inserted-text-highlight":return 1000;case"list-marker-pop":return 500;case"punctuation-pulse":return 140}}function j6($,M){let J=M??nQ();return $.animations.some((Z)=>J-Z.startedAt<d2(Z))}function k$($,M){return L6($,M,"inserted-text-highlight",(J)=>J.regionPath)}function u$($,M){return c$($,M,"active-block-flash",(J)=>J.blockPath)}function v$($,M){return L6($,M,"deleted-text-fade",(J)=>J.regionPath)}function h$($,M){return L6($,M,"punctuation-pulse",(J)=>J.regionPath)}function g$($,M){return c$($,M,"list-marker-pop",(J)=>J.blockPath)}function I$($,M,J){let Z=new Set([$,M]);for(let X of J){if(X.endOffset<=$||X.startOffset>=M)continue;Z.add(Math.max($,X.startOffset)),Z.add(Math.min(M,X.endOffset))}return[...Z].sort((X,Y)=>X-Y)}function p$($,M,J){return $.find((Z)=>Z.startOffset<J&&Z.endOffset>M)??null}function l$($,M,J){if(!M)return $;return x2(J.insertHighlightText,$,M.progress)}function d$($,M){return x2($,"rgba(0, 0, 0, 0)",M.progress)}function b5($,M){return x2($,"rgba(0, 0, 0, 0)",M.progress)}function r$($,M){return x2(M.insertHighlightText,"rgba(0, 0, 0, 0)",$.progress)}function x$($){let M=Math.min(1,$.progress*2);return 0.1+0.9*oQ(M)}function r2($,M,J){let Z=Math.max(0,M.progress*2-1);return x2(J.insertHighlightText,$,Z)}function L6($,M,J,Z){let X=new Map;for(let Y of $.animations){if(Y.kind!==J)continue;let Q=d2(Y),K=M-Y.startedAt;if(K>=Q)continue;let q={...Y,progress:Math.max(0,Math.min(1,K/Q))},D=Z(Y),A=X.get(D);if(A)A.push(q);else X.set(D,[q])}return X}function c$($,M,J,Z){let X=new Map;for(let Y of $.animations){if(Y.kind!==J)continue;let Q=d2(Y),K=M-Y.startedAt;if(K>=Q)continue;X.set(Z(Y),{...Y,progress:Math.max(0,Math.min(1,K/Q))})}return X}function oQ($){return 1-(1-$)*(1-$)*(1-$)}function x2($,M,J){let Z=S$($),X=S$(M);return`rgba(${O6(y5(Z[0],X[0],J))}, ${O6(y5(Z[1],X[1],J))}, ${O6(y5(Z[2],X[2],J))}, ${y5(Z[3],X[3],J)})`}function nQ(){return typeof performance<"u"?performance.now():Date.now()}function S$($){let M=T6.get($);if(M)return M;let J=tQ($)??eQ($)??$K($)??T6.get("rgba(0, 0, 0, 0)");return T6.set($,J),J}function tQ($){let M=$.trim();if(!M.startsWith("#"))return null;let J=M.slice(1);if(J.length===3)return[Number.parseInt(`${J[0]}${J[0]}`,16),Number.parseInt(`${J[1]}${J[1]}`,16),Number.parseInt(`${J[2]}${J[2]}`,16),1];if(J.length===6)return[Number.parseInt(J.slice(0,2),16),Number.parseInt(J.slice(2,4),16),Number.parseInt(J.slice(4,6),16),1];return null}function eQ($){let M=/^rgb\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec($.trim());if(!M)return null;return[Number(M[1]),Number(M[2]),Number(M[3]),1]}function $K($){let M=/^rgba\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec($.trim());if(!M)return null;return[Number(M[1]),Number(M[2]),Number(M[3]),Number(M[4])]}function y5($,M,J){return $+(M-$)*J}function O6($){return Math.round($)}function C6($,M,J=O1()){if(M<=0)return $;let Z=T5($);if(!Z)return $;let X=$.selection.focus.offset,Y=Math.max(0,X-M);if(X<=Y)return $;return c2($,{endOffset:X,kind:"inserted-text-highlight",regionPath:Z.path,startOffset:Y,startedAt:J})}function a$($,M,J,Z){let X=T5($);if(!X)return M;let Y=X.text.slice(J,Z);if(Y.length===0)return M;if(!X.inlines.some((K)=>K.start<=J&&K.end>=Z&&K.kind==="text"&&K.link===null&&K.marks.length===0))return M;return c2(M,{kind:"deleted-text-fade",regionPath:X.path,startOffset:J,startedAt:O1(),text:Y})}function s$($,M=O1()){let J=T5($),Z=$.selection.focus.offset-1;if(!J||Z<0||J.text[Z]!==".")return $;return c2($,{kind:"punctuation-pulse",offset:Z,regionPath:J.path,startedAt:M})}function i$($,M,J=O1()){return c2($,{blockPath:M,kind:"list-marker-pop",startedAt:J})}function o$($,M,J=O1()){return c2($,{blockPath:M,kind:"active-block-flash",startedAt:J})}function R6($,M){return $.filter((J)=>J.startedAt+d2(J)>M)}function O1(){return typeof performance<"u"?performance.now():Date.now()}function w5($,M){let J=Math.max(-1/0,...$.animations.map((Z)=>Z.startedAt));return M.animations.some((Z)=>Z.startedAt>J)}function n$($){let M=T5($);return(M?$.documentIndex.blockIndex.get(M.blockId)??null:null)?.path??""}function T5($){return $.documentIndex.regionIndex.get($.selection.focus.regionId)??null}function c2($,M){let J=R6($.animations,M.startedAt);return{...$,animations:[...J,M]}}function a2($,M,J,Z){return MK(m6($.inlines,M,J,Z))}function m6($,M,J,Z){let Y=JK($,M,J,{didInsert:!1,generatedRunCount:0,replacementText:Z});return KK(DK(Y))}function MK($){let M=[];for(let J=0;J<$.length;J+=1){let Z=$[J];if(Z.link){let Y=[],Q=Z.link;while(J<$.length&&S6($[J].link,Q)){let K=e$($[J]);if(K)Y.push(K);J+=1}if(J-=1,Y.length>0)M.push(I1({children:D0(Y),title:Q.title,url:Q.url}));continue}let X=e$(Z);if(X)M.push(X)}return D0(M)}function JK($,M,J,Z){let X=[];for(let[Y,Q]of $.entries()){if(!Z.didInsert&&M===J&&M===Q.start)f6(X,Z,t$($[Y-1]??null,Q));if(J<=Q.start||M>=Q.end){X.push(O5(Q));continue}let K=Math.max(0,M-Q.start),q=Math.min(Q.text.length,J-Q.start),D=!Z.didInsert&&Z.replacementText.length>0?Z.replacementText:"",A=ZK(Q,K,q,D,Z);if(K!==q||D.length>0)Z.didInsert=!0;X.push(...A)}if(!Z.didInsert)f6(X,Z,t$($.at(-1)??null,null));return X}function ZK($,M,J,Z,X){switch($.kind){case"text":case"inlineCode":case"unsupported":return XK($,M,J,Z);case"break":return YK($,M,J,Z,X);case"image":return QK($,M,J,Z)}}function XK($,M,J,Z){let X=$.text.slice(0,M)+Z+$.text.slice(J);return X.length>0?[{...O5($),text:X}]:[]}function YK($,M,J,Z,X){if(M===J)return[O5($)];let Y=[];if(Z.length>0)f6(Y,X,$.link);return Y}function QK($,M,J,Z){if(M===0&&J===$.text.length)return Z.length>0?[$7(Z,$.link,0)]:[];return[O5($)]}function f6($,M,J){if(M.replacementText.length===0){M.didInsert=!0;return}$.push($7(M.replacementText,J,M.generatedRunCount)),M.generatedRunCount+=1,M.didInsert=!0}function $7($,M,J){return{id:`generated:${J}`,image:null,inlineCode:!1,kind:"text",link:M,marks:[],originalType:null,text:$}}function t$($,M){return $?.link&&M?.link&&S6($.link,M.link)?$.link:null}function O5($){return{id:$.id,image:$.image,inlineCode:$.inlineCode,kind:$.kind,link:$.link,marks:$.marks,originalType:$.originalType,text:$.text}}function KK($){let M=[],J=0;for(let Z of $){let X=J,Y=X+Z.text.length;M.push({...Z,end:Y,start:X}),J=Y}return M}function DK($){let M=[];for(let J of $){let Z=M.at(-1);if(Z&&qK(Z,J)){M[M.length-1]={...Z,text:Z.text+J.text};continue}M.push(J)}return M}function qK($,M){return $.kind===M.kind&&$.inlineCode===M.inlineCode&&S6($.link,M.link)&&UK($.image,M.image)&&$.originalType===M.originalType&&$.marks.join(",")===M.marks.join(",")}function e$($){switch($.kind){case"break":return c4();case"image":return $.image?AK($.image):null;case"inlineCode":return g1({code:$.text});case"text":return $.text.length>0?E0({marks:$.marks,text:$.text}):null;case"unsupported":return a4({originalType:$.originalType??"unsupported",source:$.text})}}function AK($){return H1({alt:$.alt,title:$.title,url:$.url,width:$.width})}function S6($,M){return $?.url===M?.url&&$?.title===M?.title}function UK($,M){return $?.url===M?.url&&$?.title===M?.title&&$?.alt===M?.alt&&$?.width===M?.width}function J7($,M,J){let Z=Y0($,M);if(Z.start.regionId===Z.end.regionId)return VK($,Z,J);return FK($,Z,J)}function VK($,M,J){let Z=K1($,M.start.regionId);if(!Z)throw Error(`Unknown region: ${M.start.regionId}`);let X=z5($,Z.blockId,(D)=>GK(D,Z,M.start.offset,M.end.offset,J));if(!X)throw Error(`Failed to replace block for canvas region: ${Z.id}`);let Y=Z2($,X,Z.rootIndex,1),Q=Q7($,Y,Z,M.start.offset,M.end.offset,J),K=M2(Q,Z.path);if(!K)throw Error(`Failed to remap region after replacement: ${Z.path}`);let q=M.start.offset+J.length;return{documentIndex:Q,selection:w1(K.id,q)}}function GK($,M,J,Z,X){switch($.type){case"heading":case"paragraph":return NK($,M,J,Z,X);case"code":return o4($,M7(M,J,Z,X));case"table":return _K($,M,J,Z,X);case"unsupported":return n4($,M7(M,J,Z,X));default:throw Error(`Canvas text replacement is not supported for block type: ${$.type}`)}}function NK($,M,J,Z,X){return T0($,a2(M,J,Z,X))}function _K($,M,J,Z,X){let Y=M.tableCellPosition?.rowIndex,Q=M.tableCellPosition?.cellIndex;if(Y===void 0||Q===void 0)throw Error(`Unable to resolve table cell position for region: ${M.id}`);let K=a2(M,J,Z,X),q=$.rows.map((D,A)=>{if(A!==Y)return D;let V=D.cells.map((U,G)=>{if(G!==Q)return U;return M1({children:K})});return{...D,cells:V}});return u0($,q)}function M7($,M,J,Z){return m6($.inlines,M,J,Z).map((X)=>X.text).join("")}function s2($){return $!==null&&($.type==="heading"||$.type==="paragraph")}function FK($,M,J){let Z=K1($,M.start.regionId),X=K1($,M.end.regionId);if(!Z||!X)throw Error("Unknown cross-region selection endpoints.");let Y=$.document.blocks[Z.rootIndex],Q=$.document.blocks[X.rootIndex];if(!Y||!Q)throw Error("Unknown root blocks for cross-region selection.");let K=Z7(Y,Z,M.start.offset),q=X7(Q,X,M.end.offset),D=HK(K,q,J),A=D.blocks.length>0?D.blocks:[d({text:""})],V=Z.rootIndex,U=X.rootIndex-Z.rootIndex+1,G=W1($.document,V,U,A),_=Z2($,G,V,U),N=Q7($,_,Z,M.start.offset,Z.text.length,s2(K)?J:""),H=N.roots[V+D.caretLocalIndex]?.regions[0]??null;return{documentIndex:N,selection:w1(H?.id??Z.id,H?D.caretOffset:0)}}function HK($,M,J){if(s2($)&&s2(M))return{blocks:[zK($,M,J)],caretLocalIndex:0,caretOffset:$.plainText.length+J.length};if(s2($)){let Y=[J.length>0?EK($,J):$];if(M)Y.push(M);return{blocks:Y,caretLocalIndex:0,caretOffset:$.plainText.length+J.length}}if(s2(M)){let X=J.length>0?WK(M,J):M,Y=[];if($)Y.push($);let Q=Y.length;return Y.push(X),{blocks:Y,caretLocalIndex:Q,caretOffset:J.length}}let Z=[];if($)Z.push($);if(J.length>0){let X=Z.length;if(Z.push(d({text:J})),M)Z.push(M);return{blocks:Z,caretLocalIndex:X,caretOffset:J.length}}if(M){let X=Z.length;return Z.push(M),{blocks:Z,caretLocalIndex:X,caretOffset:0}}return{blocks:Z,caretLocalIndex:0,caretOffset:0}}function zK($,M,J){let Z=J.length>0?[E0({text:J})]:[];return T0($,D0([...$.children,...Z,...M.children]))}function EK($,M){return T0($,D0([...$.children,E0({text:M})]))}function WK($,M){return T0($,D0([E0({text:M}),...$.children]))}function Z7($,M,J){if($.type==="table")return null;if($.id===M.blockId)return BK($,M,J);return Y7($,(Z)=>yK(Z,M,J))}function X7($,M,J){if($.type==="table")return null;if($.id===M.blockId)return PK($,M,J);return Y7($,(Z)=>bK(Z,M,J))}function BK($,M,J){if(J===0)return null;switch($.type){case"heading":case"paragraph":return T0($,a2(M,J,M.text.length,""));case"code":return o4($,M.text.slice(0,J));case"unsupported":return n4($,M.text.slice(0,J));default:return null}}function PK($,M,J){if(J===M.text.length)return null;switch($.type){case"heading":case"paragraph":return T0($,a2(M,0,J,""));case"code":return o4($,M.text.slice(J));case"unsupported":return n4($,M.text.slice(J));default:return null}}function Y7($,M){switch($.type){case"blockquote":{let J=M($.children);return J.length===0?null:H0({children:J})}case"list":{let J=M($.items);return J.length===0?null:e($,J)}case"listItem":{let J=M($.children);return J.length===0?null:P0($,J)}default:return null}}function yK($,M,J){let Z=$.findIndex((Q)=>j5(Q,M));if(Z===-1)return[];let X=$.slice(0,Z),Y=Z7($[Z],M,J);return Y?[...X,Y]:X}function bK($,M,J){let Z=$.findIndex((Q)=>j5(Q,M));if(Z===-1)return[];let X=$.slice(Z+1),Y=X7($[Z],M,J);return Y?[Y,...X]:X}function j5($,M){if($.id===M.blockId)return!0;switch($.type){case"blockquote":case"listItem":return $.children.some((J)=>j5(J,M));case"list":return $.items.some((J)=>j5(J,M));default:return!1}}function Q7($,M,J,Z,X,Y){if($.document.comments.length===0)return M;let Q=G6($,M,J,Z,X,Y);return Q===M.document.comments?M:H5(M,{...M.document,comments:Q})}function i2($){let M=J2($),J=A7(M);return{animations:[],documentIndex:M,future:[],history:[],selection:{anchor:J,focus:J}}}function p0($){let M=L0($.documentIndex);return d1(P2($.documentIndex.document.blocks),M.threads,$.documentIndex.document.frontMatter)}function o($,M){if(!M)return null;switch(M.kind){case"keep-state":return $;case"set-selection":return X0($,M.selection);case"replace-block":{let J=z5($.documentIndex,M.blockId,()=>M.block);return J?L5($,J2(J),M.selection??null):null}case"splice-blocks":{let J=W1($.documentIndex.document,M.rootIndex,M.count??1,M.blocks);return L5($,J2(J),M.selection??null)}case"splice-text":{let J=J7($.documentIndex,M.selection,M.text);return L5($,J.documentIndex,J.selection)}case"splice-comments":{let J=V9($.documentIndex.document,M.index,M.count,M.threads);return L5($,H5($.documentIndex,J),null)}}}function L5($,M,J){let Z=wK($,M),X=p2(Z.documentIndex,J)??$.selection,Y=U7($,Z,X);return X0(Z,X,Y)}function X0($,M,J){let Z="regionId"in M?{anchor:C5($.documentIndex,M),focus:C5($.documentIndex,M)}:{anchor:C5($.documentIndex,M.anchor),focus:C5($.documentIndex,M.focus)},X={...$,selection:Z};return J??U7($,X)?o$(X,n$(X)):X}function z0($,M,J,Z){let X={regionId:M,offset:J};return X0($,Z?{anchor:$.selection.anchor,focus:X}:X)}function wK($,M){let J=A7(M);return{animations:R6($.animations,O1()),documentIndex:M,future:[],history:[...$.history,{document:$.documentIndex.document,selection:$.selection}],selection:{anchor:J,focus:J}}}function k6($){let M=$.history.at(-1);if(!M)return $;return q7(M,{future:[D7($),...$.future],history:$.history.slice(0,-1)})}function u6($){let M=$.future[0];if(!M)return $;return q7(M,{future:$.future.slice(1),history:[...$.history,D7($)]})}function D7($){return{document:$.documentIndex.document,selection:$.selection}}function q7($,M){return{animations:[],documentIndex:J2($.document),future:M.future,history:M.history,selection:$.selection}}function A7($){return $.regions[0]?{regionId:$.regions[0].id,offset:0}:{regionId:"empty",offset:0}}function C5($,M){let J=K1($,M.regionId);if(!J)return M;return{regionId:J.id,offset:Math.max(0,Math.min(M.offset,J.text.length))}}function U7($,M,J){let Z=K7($.documentIndex,$.selection),X=K7(M.documentIndex,J??M.selection);return X!==null&&X!==Z}function K7($,M){let J=$.regionIndex.get(M.focus.regionId),Z=J?$.blockIndex.get(J.blockId)??null:null;if(!J||!Z?.path)return null;return Z.type==="table"?`cell:${J.path}`:`block:${Z.path}`}function t2($,M){let J=$.regionIndex.get(M.anchor.regionId);if(!J)return{kind:"unsupported"};if(J.blockType==="code"){let K=$.blockIndex.get(J.blockId);return K?{kind:"code",region:J,rootIndex:K.rootIndex}:{kind:"unsupported"}}let Z=h6($,J.id);if(Z)return{kind:"tableCell",...Z};let X=K2($,M);if(X)return{kind:"listItem",...X};let Y=TK($,M);if(Y)return{kind:"blockquoteTextBlock",...Y};let Q=Q2($,M);if(Q)return{kind:"rootTextBlock",...Q};return{kind:"unsupported"}}function e2($,M){let J=$.blockIndex.get(M);if(!J)throw Error(`Unknown root block: ${M}`);return J.rootIndex}function v6($,M,J){let Z=M?$.blockIndex.get(M)??null:null;while(Z){if(Z.type===J)return Z;let X=Z.parentBlockId;Z=X?$.blockIndex.get(X)??null:null}return null}function o2($){let M=$.split("."),J=[];for(let Z=0;Z<M.length-1;Z+=1)if(M[Z]==="children"){let X=Number(M[Z+1]);if(Number.isInteger(X))J.push(X)}return J}function Q2($,M){let J=$.regionIndex.get(M.anchor.regionId);if(!J)return null;let Z=$.blockIndex.get(J.blockId);if(!Z)return null;let X=Z.rootIndex,Y=$.document.blocks[X];if(!Y||Y.type!=="heading"&&Y.type!=="paragraph")return null;return{block:Y,region:J,rootIndex:X}}function TK($,M){let J=$.regionIndex.get(M.anchor.regionId);if(!J)return null;let Z=$.blockIndex.get(J.blockId),X=v6($,Z?.id??null,"blockquote");if(!Z||!X||Z.parentBlockId!==X.id)return null;let Y=X.rootIndex,Q=$.document.blocks[Y];if(!Q||Q.type!=="blockquote")return null;let K=Q.children.findIndex((D)=>D.id===Z.id),q=Q.children[K];if(!q||q.type!=="heading"&&q.type!=="paragraph")return null;return{block:q,blockChildIndices:o2(Z.path),childIndex:K,region:J,quote:Q,rootIndex:Y}}function n2($,M){return x1($.document.blocks,M)}function K2($,M){let J=$.regionIndex.get(M.anchor.regionId);if(!J)return null;let Z=$.blockIndex.get(J.blockId),X=v6($,Z?.id??null,"listItem"),Y=v6($,Z?.id??null,"list");if(!Z||!X||!Y)return null;let Q=n2($,Y.id);if(!Q||Q.type!=="list")return null;let K=Q.items.findIndex((_)=>_.id===X.id),q=Q.items[K];if(!q)return null;let D=Y.parentBlockId?$.blockIndex.get(Y.parentBlockId)??null:null,A=D?.parentBlockId?$.blockIndex.get(D.parentBlockId)??null:null,V=D?.type==="listItem"?n2($,D.id):null,U=A?.type==="list"?n2($,A.id):null,G=U?.type==="list"&&V?U.items.findIndex((_)=>_.id===V.id):-1;return{region:J,item:q,itemChildIndices:o2(X.path),itemIndex:K,list:Q,listChildIndices:o2(Y.path),parentItem:V?.type==="listItem"?V:null,parentItemChildIndices:D?.type==="listItem"?o2(D.path):null,parentItemIndex:G>=0?G:null,parentList:U?.type==="list"?U:null,parentListChildIndices:A?.type==="list"?o2(A.path):null,rootIndex:Y.rootIndex}}function h6($,M){let J=$.regionIndex.get(M);if(!J)return null;let Z=$.tableCellIndex.get(J.id),X=$.blockIndex.get(J.blockId),Y=X?.type==="table"?$.document.blocks[X.rootIndex]:null;if(!Z||!X||!Y||Y.type!=="table")return null;return{cellIndex:Z.cellIndex,rootIndex:X.rootIndex,rowIndex:Z.rowIndex,table:Y}}function $4($,M,J){return a0({checked:M,children:[d({text:$})],spread:J})}function D2($,M){let J=$.children[0];if(!J||J.type!=="paragraph")return null;return P0($,[d({text:M}),...$.children.slice(1)])}function V7($,M){return M.reduce((J,Z)=>`${J}.children.${Z}`,`root.${$}`)}function G7($,M){if($.selection.anchor.regionId!==$.selection.focus.regionId||$.selection.anchor.offset!==$.selection.focus.offset)return null;let J=K1($.documentIndex,$.selection.focus.regionId);if(!J)return null;if(M==="forward"&&$.selection.focus.offset>=J.text.length)return null;let Z=M==="backward"?OK(J.text,$.selection.focus.offset):$.selection.focus.offset,X=M==="backward"?$.selection.focus.offset:jK(J.text,$.selection.focus.offset);if(Z===X)return null;return{action:{kind:"splice-text",selection:{anchor:{regionId:J.id,offset:Z},focus:{regionId:J.id,offset:X}},text:""},startOffset:Z,endOffset:X}}function OK($,M){let J=Array.from($.slice(0,M));if(J.length===0)return 0;return M-J.at(-1).length}function jK($,M){let J=Array.from($.slice(M))[0];return J?M+J.length:$.length}function N7($,M,J){let Z=$.regionIndex.get(M.anchor.regionId);if(!Z)return null;let X=Y0($,M),Y=X.start.regionId===X.end.regionId&&X.start.regionId===Z.id?Z.text.slice(0,X.start.offset)+J+Z.text.slice(X.end.offset):J;return LK($,M,Z.id,Y)??RK($,M,Z.id,Y)??CK($,M,Z.id,Y)??fK($,M,Z.id,Y)??kK($,Z.blockId,Z.rootIndex,Y)??{kind:"splice-text",selection:M,text:J}}function LK($,M,J,Z){let X=K2($,M),Y=hK(Z);if(!X||!Y||X.region.id!==J)return null;let Q=D2(X.item,Y.text);if(!Q)return null;return{kind:"replace-block",block:e(X.list,X.list.items.map((K,q)=>q===X.itemIndex?Q:K),{ordered:Y.ordered,start:Y.ordered?1:null}),blockId:X.list.id,selection:G0(X.rootIndex,[...X.listChildIndices,X.itemIndex,0])}}function CK($,M,J,Z){if(!I6($,M,J))return null;if(/^\s*([-+*])\s\[( |x|X)\]\s$/.exec(Z)){let Q=Z.toLowerCase().includes("[x]");return g6($,M,{checked:Q,ordered:!1,start:null})}if(/^\s*[-+*]\s$/.test(Z))return g6($,M,{checked:null,ordered:!1,start:null});let Y=/^\s*(\d+)\.\s$/.exec(Z);if(Y)return g6($,M,{checked:null,ordered:!0,start:Number(Y[1])});return null}function RK($,M,J,Z){let X=Q2($,M),Y=gK(Z);if(!X||X.region.id!==J||X.block.type!=="heading"||!Y)return null;return{kind:"splice-blocks",blocks:[$1({depth:Y.depth,text:Y.text})],rootIndex:X.rootIndex,selection:$0(X.rootIndex)}}function fK($,M,J,Z){return mK($,M,J,Z)??SK($,M,J,Z)}function mK($,M,J,Z){if(!I6($,M,J))return null;let X=/^(#{1,6})\s$/.exec(Z);if(!X)return null;return uK($,M,X[1].length)}function SK($,M,J,Z){if(!I6($,M,J)||!/^>\s$/.test(Z))return null;return vK($,M)}function kK($,M,J,Z){if(!/^(?:(?:-\s?){3}|(?:\*\s?){3}|(?:_\s?){3})$/.test(Z))return null;return{kind:"splice-blocks",blocks:[s4(),d({text:""})],rootIndex:e2($,M),selection:$0(J+1)}}function g6($,M,J){let Z=e2($,$.regionIndex.get(M.anchor.regionId).blockId);return{kind:"splice-blocks",blocks:[z1({items:[a0({checked:J.checked,children:[d({text:""})],spread:!1})],ordered:J.ordered,spread:!1,start:J.start})],rootIndex:Z,selection:G0(Z,[0,0])}}function uK($,M,J){let Z=e2($,$.regionIndex.get(M.anchor.regionId).blockId);return{kind:"splice-blocks",blocks:[$1({depth:J,text:""})],rootIndex:Z,selection:$0(Z)}}function vK($,M){let J=e2($,$.regionIndex.get(M.anchor.regionId).blockId);return{kind:"splice-blocks",blocks:[H0({children:[d({text:""})]})],rootIndex:J,selection:G0(J,[0])}}function I6($,M,J){let Z=Q2($,M);return Z?.region.id===J&&Z.block.type==="paragraph"}function hK($){let M=/^[-+*]\s(.+)$/.exec($);if(M)return{ordered:!1,text:M[1]};let J=/^\d+\.\s(.+)$/.exec($);if(J)return{ordered:!0,text:J[1]};return null}function gK($){let M=/^(#{1,6})\s(.+)$/.exec($);return M?{depth:M[1].length,text:M[2]}:null}function D1($,M,J,Z=0){return G0($,[...M,J,0],Z)}function p6($,M){let J=$.region.text,Z=$.item,X=typeof Z.checked==="boolean"?!1:Z.checked;if(M===0){let D=$4("",X,Z.spread);return{kind:"replace-block",block:e($.list,[...$.list.items.slice(0,$.itemIndex),D,Z,...$.list.items.slice($.itemIndex+1)]),blockId:$.list.id,listItemInsertedPath:R5(D,$.rootIndex,[...$.listChildIndices,$.itemIndex]),selection:D1($.rootIndex,$.listChildIndices,$.itemIndex)}}if(M===J.length){let D=$4("",X,Z.spread);return{kind:"replace-block",block:e($.list,[...$.list.items.slice(0,$.itemIndex+1),D,...$.list.items.slice($.itemIndex+1)]),blockId:$.list.id,listItemInsertedPath:R5(D,$.rootIndex,[...$.listChildIndices,$.itemIndex+1]),selection:D1($.rootIndex,$.listChildIndices,$.itemIndex+1)}}let Y=J.slice(0,M),Q=J.slice(M),K=$4(Q,X,Z.spread),q=P0(Z,[d({text:Y})]);return{kind:"replace-block",block:e($.list,[...$.list.items.slice(0,$.itemIndex),q,K,...$.list.items.slice($.itemIndex+1)]),blockId:$.list.id,listItemInsertedPath:R5(K,$.rootIndex,[...$.listChildIndices,$.itemIndex+1]),selection:D1($.rootIndex,$.listChildIndices,$.itemIndex+1)}}function _7($,M){if(M!==0||$.region.text.length!==0)return p6($,M);if($.parentItem&&$.parentItemIndex!==null&&$.parentItemChildIndices&&$.parentList&&$.parentListChildIndices)return IK($);let J=$.list.items.slice(0,$.itemIndex),Z=$.list.items.slice($.itemIndex+1),X=[];if(J.length>0)X.push(e($.list,J));if(X.push(d({text:""})),Z.length>0)X.push(e($.list,Z));return{kind:"splice-blocks",blocks:X,rootIndex:$.rootIndex,selection:$0($.rootIndex+(J.length>0?1:0))}}function F7($){if(typeof $.item.checked==="boolean"){let M=a0({checked:null,children:$.item.children,spread:$.item.spread});return{kind:"replace-block",block:e($.list,$.list.items.map((J,Z)=>Z===$.itemIndex?M:J)),blockId:$.list.id}}if($.itemIndex>0){let M=$.list.items[$.itemIndex-1];if(!M)return null;if($.item.plainText.length===0)return{kind:"replace-block",block:e($.list,$.list.items.filter((Z,X)=>X!==$.itemIndex)),blockId:$.list.id,selection:D1($.rootIndex,$.listChildIndices,$.itemIndex-1,"end")};let J=D2(M,`${M.plainText}${$.item.plainText}`);if(!J)return null;return{kind:"replace-block",block:e($.list,$.list.items.flatMap((Z,X)=>{if(X===$.itemIndex-1)return[J];if(X===$.itemIndex)return[];return[Z]})),blockId:$.list.id,selection:D1($.rootIndex,$.listChildIndices,$.itemIndex-1,M.plainText.length)}}return{kind:"splice-blocks",blocks:[d({text:$.item.plainText})],rootIndex:$.rootIndex,selection:$0($.rootIndex)}}function H7($){if($.itemIndex===0)return null;let M=$.list.items[$.itemIndex-1];if(!M)return null;let J=pK(M,$.item,$);return{kind:"replace-block",block:e($.list,$.list.items.flatMap((Z,X)=>{if(X===$.itemIndex-1)return[J.item];if(X===$.itemIndex)return[];return[Z]})),blockId:$.list.id,selection:G0($.rootIndex,J.regionChildIndices)}}function z7($){if(!$.parentItem||$.parentItemIndex===null||!$.parentItemChildIndices||!$.parentList||!$.parentListChildIndices)return null;let M=$.list.items.filter((X,Y)=>Y!==$.itemIndex),J=$.parentItem.children.flatMap((X)=>{if(X.type!=="list"||X.id!==$.list.id)return[X];if(M.length===0)return[];return[e($.list,M)]}),Z=P0($.parentItem,J);return{kind:"replace-block",block:e($.parentList,[...$.parentList.items.slice(0,$.parentItemIndex),Z,$.item,...$.parentList.items.slice($.parentItemIndex+1)]),blockId:$.parentList.id,selection:D1($.rootIndex,$.parentListChildIndices,$.parentItemIndex+1)}}function l6($,M){let J=$.itemIndex+M;if(J<0||J>=$.list.items.length)return null;let Z=[...$.list.items],[X]=Z.splice($.itemIndex,1);if(!X)return null;return Z.splice(J,0,X),{kind:"replace-block",block:e($.list,Z),blockId:$.list.id,selection:D1($.rootIndex,$.listChildIndices,J)}}function IK($){if(!$.parentItem||$.parentItemIndex===null||!$.parentItemChildIndices||!$.parentList||!$.parentListChildIndices)return null;let M=$.list.items.filter((Q,K)=>K!==$.itemIndex),J=$.parentItem.children.flatMap((Q)=>{if(Q.type!=="list"||Q.id!==$.list.id)return[Q];if(M.length===0)return[];return[e($.list,M)]}),Z=P0($.parentItem,J),X=typeof $.parentItem.checked==="boolean"?!1:$.parentItem.checked,Y=$4("",X,$.parentItem.spread);return{kind:"replace-block",block:e($.parentList,[...$.parentList.items.slice(0,$.parentItemIndex),Z,Y,...$.parentList.items.slice($.parentItemIndex+1)]),blockId:$.parentList.id,listItemInsertedPath:R5(Y,$.rootIndex,[...$.parentListChildIndices,$.parentItemIndex+1]),selection:D1($.rootIndex,$.parentListChildIndices,$.parentItemIndex+1)}}function R5($,M,J){return typeof $.checked==="boolean"?void 0:V7(M,J)}function pK($,M,J){let Z=$.children.findIndex((Y)=>Y.type==="list"&&Y.ordered===J.list.ordered&&Y.start===J.list.start);if(Z>=0){let Y=$.children[Z];if(!Y||Y.type!=="list")return{item:$,regionChildIndices:[...J.listChildIndices,J.itemIndex-1,0]};return{item:P0($,$.children.map((Q,K)=>K===Z?e(Y,[...Y.items,M]):Q)),regionChildIndices:[...J.listChildIndices,J.itemIndex-1,Z,Y.items.length,0]}}let X=z1({items:[M],ordered:J.list.ordered,spread:J.list.spread,start:J.list.start});return{item:P0($,[...$.children,X]),regionChildIndices:[...J.listChildIndices,J.itemIndex-1,$.children.length,0,0]}}function E7($,M){let J=$.region.text.length,Z=$.region.text.slice(0,M),X=$.region.text.slice(M),Y=M===0&&J>0?$.rootIndex:$.rootIndex+1;if($.block.type==="paragraph")return{kind:"splice-blocks",blocks:M===0?[d({text:""}),$.block]:M===J?[$.block,d({text:""})]:[d({text:Z}),d({text:X})],rootIndex:$.rootIndex,selection:$0(Y)};return{kind:"splice-blocks",blocks:M===0?[d({text:""}),$.block]:M===J?[$.block,d({text:""})]:[$1({depth:$.block.depth,text:Z}),d({text:X})],rootIndex:$.rootIndex,selection:$0(Y)}}function W7($,M){let J=$.region.text,Z=J.slice(0,M),X=J.slice(M),Y=$.block.type==="heading"?sK($.block,Z,X,$.blockChildIndices,M,J.length):aK($.block,Z,X,$.blockChildIndices,M,J.length);return{kind:"splice-blocks",blocks:[H0({children:[...$.quote.children.slice(0,$.childIndex),...Y.blocks,...$.quote.children.slice($.childIndex+1)]})],rootIndex:$.rootIndex,selection:G0($.rootIndex,Y.focusChildIndices)}}function B7($,M){if(M!==0||$.region.text.length!==0||$.block.type!=="paragraph")return null;let J=$.quote.children.slice(0,$.childIndex),Z=$.quote.children.slice($.childIndex+1),X=[];if(J.length>0)X.push(H0({children:J}));if(X.push(d({text:""})),Z.length>0)X.push(H0({children:Z}));return{kind:"splice-blocks",blocks:X,rootIndex:$.rootIndex,selection:$0($.rootIndex+(J.length>0?1:0))}}function P7($,M){let J=rK($);if(J)return J;if($.rootIndex===0)return null;let Z=M.document.blocks[$.rootIndex-1],X=M.document.blocks[$.rootIndex+1];if(!Z)return null;if($.block.plainText.length===0){let Y=lK($,Z,X);if(Y)return Y;return{kind:"splice-blocks",blocks:[],rootIndex:$.rootIndex,selection:Z.type==="paragraph"||Z.type==="heading"?$0($.rootIndex-1,"end"):Z.type==="list"?G0($.rootIndex-1,[Z.items.length-1,0],"end"):Z.type==="blockquote"?G0($.rootIndex-1,[Z.children.length-1],"end"):$0($.rootIndex-1,"end")}}if(Z.type==="paragraph")return{kind:"splice-blocks",count:2,blocks:[d({text:`${Z.plainText}${$.block.plainText}`})],rootIndex:$.rootIndex-1,selection:$0($.rootIndex-1,Z.plainText.length)};if(Z.type==="heading")return{kind:"splice-blocks",count:2,blocks:[$1({depth:Z.depth,text:`${Z.plainText}${$.block.plainText}`})],rootIndex:$.rootIndex-1,selection:$0($.rootIndex-1,Z.plainText.length)};if(Z.type==="list"){let Y=Z.items.length-1,Q=Z.items[Y];if(Q){let K=D2(Q,`${Q.plainText}${$.block.plainText}`);if(K)return{kind:"splice-blocks",count:2,blocks:[e(Z,Z.items.map((q,D)=>D===Y?K:q))],rootIndex:$.rootIndex-1,selection:G0($.rootIndex-1,[Y,0],Q.plainText.length)}}}return null}function y7($){if($.region.text.length===0)return cK($);if($.childIndex>0)return xK($);return{kind:"splice-blocks",blocks:$.quote.children,rootIndex:$.rootIndex,selection:$0($.rootIndex)}}function d6($,M,J){if($.block.type!=="heading")return null;let Z=Math.max(1,Math.min(6,$.block.depth+M));if(Z===$.block.depth)return{kind:"keep-state"};return{kind:"splice-blocks",blocks:[$1({depth:Z,text:$.block.plainText})],rootIndex:$.rootIndex,selection:$0($.rootIndex,J)}}function lK($,M,J){if($.block.type!=="paragraph"||$.block.plainText.length!==0||M.type!=="list"||J?.type!=="list"||!dK(M,J))return null;let Z=M.items.length-1;return{kind:"splice-blocks",count:3,blocks:[e(M,[...M.items,...J.items])],rootIndex:$.rootIndex-1,selection:G0($.rootIndex-1,[Z,0],"end")}}function dK($,M){return $.ordered===M.ordered&&$.start===M.start}function rK($){if($.block.type!=="heading")return null;return{kind:"splice-blocks",blocks:[d({text:$.block.plainText})],rootIndex:$.rootIndex,selection:$0($.rootIndex)}}function xK($){let J=$.quote.children[$.childIndex-1].plainText,Z=$.block.plainText,X=$.quote.children.filter((Y,Q)=>Q!==$.childIndex).map((Y,Q)=>Q===$.childIndex-1?d({text:`${J}${Z}`}):Y);return{kind:"splice-blocks",blocks:[H0({children:X})],rootIndex:$.rootIndex,selection:G0($.rootIndex,[$.childIndex-1],J.length)}}function cK($){if($.quote.children.length===1)return{kind:"splice-blocks",blocks:[d({text:""})],rootIndex:$.rootIndex,selection:$0($.rootIndex)};let M=Math.max(0,$.childIndex-1),J=$.childIndex>0?"end":0;return{kind:"splice-blocks",blocks:[H0({children:$.quote.children.filter((Z,X)=>X!==$.childIndex)})],rootIndex:$.rootIndex,selection:G0($.rootIndex,[M],J)}}function aK($,M,J,Z,X,Y){return{blocks:X===0?[d({text:""}),$]:X===Y?[$,d({text:""})]:[d({text:M}),d({text:J})],focusChildIndices:X===0?Z:[...Z.slice(0,-1),Z.at(-1)+1]}}function sK($,M,J,Z,X,Y){return{blocks:X===0?[d({text:""}),$]:X===Y?[$,d({text:""})]:[$1({depth:$.depth,text:M}),d({text:J})],focusChildIndices:X===0?Z:[...Z.slice(0,-1),Z.at(-1)+1]}}function b7($,M,J){let Z=Q2($,M),X=Math.max(2,J);if(!Z||Z.block.type!=="paragraph"||Z.block.plainText.length>0||M.anchor.regionId!==M.focus.regionId||M.anchor.offset!==0||M.focus.offset!==0)return null;return{kind:"splice-blocks",blocks:[E1({rows:Array.from({length:2},()=>x6(X))})],rootIndex:Z.rootIndex,selection:T1(Z.rootIndex,0,0)}}function r6($,M,J,Z){let X=Z<0?tK(J.table,J.rowIndex,J.cellIndex):eK(J.table,J.rowIndex,J.cellIndex);if(!X)return Z>0&&$D(J.table,J.rowIndex,J.cellIndex)?iK(J):{kind:"keep-state"};let Y=J.table.rows[X.rowIndex]?.cells[X.cellIndex];if(!Y)return{kind:"keep-state"};return{kind:"set-selection",selection:nK($,M,J.table,X.rowIndex,X.cellIndex,Math.min(M.focus.offset,Y.plainText.length))}}function w7($,M){let J=X2($,M.focus.regionId);if(!J||J.kind!=="tableCell")return null;let Z=Math.min(M.anchor.offset,M.focus.offset),X=Math.max(M.anchor.offset,M.focus.offset),Y=I2(J,Z,X,(Q)=>c4({path:Q}));return{kind:"replace-block",block:Y.block,blockId:Y.blockId,selection:Y.selection}}function T7($,M){let J=M==="left"?$.cellIndex:$.cellIndex+1;return q2($,E1({align:f7($.table.align,J,0,[null]),rows:$.table.rows.map((Z)=>p1({cells:oK(Z.cells,J,0,[R7()])}))}),T1($.rootIndex,$.rowIndex,J))}function O7($){let M=Math.max(0,...$.table.rows.map((J)=>J.cells.length));if(M<=1)return null;return q2($,E1({align:f7($.table.align,$.cellIndex,1,[]),rows:$.table.rows.map((J)=>p1({cells:J.cells.filter((Z,X)=>X!==$.cellIndex)}))}),T1($.rootIndex,$.rowIndex,Math.min($.cellIndex,M-2)))}function j7($,M){let J=M==="above"?$.rowIndex:$.rowIndex+1,Z=Math.max(1,...$.table.rows.map((X)=>X.cells.length));return q2($,u0($.table,[...$.table.rows.slice(0,J),x6(Z),...$.table.rows.slice(J)]),T1($.rootIndex,J,Math.min($.cellIndex,Z-1)))}function L7($){if($.table.rows.length<=1)return null;let M=$.table.rows.filter((X,Y)=>Y!==$.rowIndex),J=Math.min($.rowIndex,M.length-1),Z=M[J]?.cells.length??1;return q2($,u0($.table,M),T1($.rootIndex,J,Math.min($.cellIndex,Z-1)))}function C7($){return q2($,d({text:""}),$0($.rootIndex))}function x6($){return p1({cells:Array.from({length:$},()=>R7())})}function R7(){return M1({children:[]})}function iK($){let M=$.table.rows.length,J=Math.max(1,...$.table.rows.map((Z)=>Z.cells.length));return q2($,u0($.table,[...$.table.rows,x6(J)]),T1($.rootIndex,M,0))}function q2($,M,J){return{kind:"replace-block",block:M,blockId:$.table.id,selection:J}}function oK($,M,J,Z){return[...$.slice(0,M),...Z,...$.slice(M+J)]}function f7($,M,J,Z){return[...$.slice(0,M),...Z,...$.slice(M+J)]}function nK($,M,J,Z,X,Y){let Q=Y2($,J.id,Z,X);if(!Q)return M;return{anchor:{regionId:Q.id,offset:Y},focus:{regionId:Q.id,offset:Y}}}function tK($,M,J){if(J>0)return{cellIndex:J-1,rowIndex:M};if(M>0){let Z=$.rows[M-1];if(!Z||Z.cells.length===0)return null;return{cellIndex:Z.cells.length-1,rowIndex:M-1}}return null}function eK($,M,J){let Z=$.rows[M];if(!Z)return null;if(J+1<Z.cells.length)return{cellIndex:J+1,rowIndex:M};let X=$.rows[M+1];if(!X||X.cells.length===0)return null;return{cellIndex:0,rowIndex:M+1}}function $D($,M,J){let Z=$.rows[M];return Boolean(Z&&M===$.rows.length-1&&J===Z.cells.length-1)}function M4($,M){let J=N7($.documentIndex,$.selection,M),Z=o($,J);if(!Z)return null;if(J?.kind==="splice-text"&&M.length>0)Z=C6(Z,M.length);if(M===".")Z=s$(Z);return Z}function f5($){let M=t2($.documentIndex,$.selection),J=Y0($.documentIndex,$.selection).start.offset;switch(M.kind){case"code":return o($,{kind:"splice-text",selection:$.selection,text:`
|
|
25
|
-
`});case"tableCell":return o($,w7($.documentIndex,$.selection));case"listItem":{let Z=_7(M,J);return MD({state:o($,Z)??o($,p6(M,J)),action:Z})}case"blockquoteTextBlock":return o($,B7(M,J))??o($,W7(M,J));case"rootTextBlock":return o($,E7(M,J));case"unsupported":return null}}function m5($,M){let J=o($,{kind:"splice-text",selection:$.selection,text:M});return M.length>0?C6(J,M.length):J}function S5($){return m5($,"")}function c6($){if(YM($))return S5($);let M=QM($,"backward");if(M)return M;let J=Y0($.documentIndex,$.selection);if(J.start.regionId!==J.end.regionId||J.start.offset!==0||J.end.offset!==0)return null;let Z=t2($.documentIndex,$.selection);switch(Z.kind){case"listItem":return o($,F7(Z));case"blockquoteTextBlock":return o($,y7(Z));case"rootTextBlock":return o($,P7(Z,$.documentIndex));default:return null}}function a6($){if(YM($))return S5($);return QM($,"forward")}function m7($,M,J){return z0($,M,J,!0)}function S7($){let M=$.documentIndex.regions,J=M[0],Z=M.at(-1);if(!J||!Z)return $;return X0($,{anchor:{regionId:J.id,offset:0},focus:{regionId:Z.id,offset:Z.text.length}})}function k7($){let M=t2($.documentIndex,$.selection);switch(M.kind){case"tableCell":return o($,r6($.documentIndex,$.selection,M,1));case"rootTextBlock":return o($,d6(M,1,$.selection.focus.offset));case"listItem":return o($,H7(M));default:return null}}function u7($){let M=t2($.documentIndex,$.selection);switch(M.kind){case"tableCell":return o($,r6($.documentIndex,$.selection,M,-1));case"rootTextBlock":return o($,d6(M,-1,$.selection.focus.offset));case"listItem":return o($,z7(M));default:return null}}var v7=j1(K2,($,M)=>l6(M,-1)),h7=j1(K2,($,M)=>l6(M,1));function g7($,M){let J=n2($.documentIndex,M);if(!J||J.type!=="listItem"||typeof J.checked!=="boolean")return null;return o($,{kind:"replace-block",block:{...J,checked:!J.checked},blockId:M})}function I7($,M){return o($,b7($.documentIndex,$.selection,M))}var p7=j1(J4,($,M,J)=>T7(M,J)),l7=j1(J4,($,M)=>O7(M)),d7=j1(J4,($,M,J)=>j7(M,J)),r7=j1(J4,($,M)=>L7(M)),x7=j1(J4,($,M)=>C7(M));function k5($){return g5($,"bold")}function u5($){return g5($,"italic")}function v5($){return g5($,"strikethrough")}function h5($){return g5($,"underline")}function c7($){return ZM($,P6)}function a7($,M,J,Z,X){return XM($,M,J,Z,X)}function s7($,M,J,Z){return XM($,M,J,Z,null)}function i7($,M,J){return o($,R$($.documentIndex,$.selection,(Z)=>H1({alt:J??null,path:Z,url:M})))}function o7($,M,J,Z){let X=X2($.documentIndex,M);if(!X)return null;let{image:Y}=J,Q=I2(X,J.start,J.end,(K)=>H1({alt:Y.alt,path:K,title:Y.title,url:Y.url,width:Z}));return o($,{kind:"replace-block",block:Q.block,blockId:Q.blockId})}function n7($,M,J){let Z=V6($.documentIndex,M,J);if(!Z)return null;return KM($,$.documentIndex.document.comments.length,0,[Z])}function t7($,M,J){return Z4($,M,(Z)=>C8(Z,{body:J.trim()}))}function e7($,M,J,Z){return Z4($,M,(X)=>R8(X,J,Z))}function $M($,M,J){return Z4($,M,(Z)=>f8(Z,J))}function MM($,M){return Z4($,M,()=>null)}function JM($,M,J){return Z4($,M,(Z)=>m8(Z,J))}function s6($){return k6($)}function i6($){return u6($)}function j1($,M){return(J,...Z)=>{let X=$(J.documentIndex,J.selection);return X?o(J,M(J,X,...Z)):null}}function J4($,M){return h6($,M.focus.regionId)}function MD($){if(!$.state||!$.action||$.action.kind!=="replace-block"||!$.action.listItemInsertedPath)return $.state;return i$($.state,$.action.listItemInsertedPath)}function g5($,M){return ZM($,(J,Z,X)=>W6(J,Z,X,M))}function ZM($,M){let J=Y0($.documentIndex,$.selection);if(J.start.regionId!==J.end.regionId||J.start.offset===J.end.offset)return null;return o($,E5($.documentIndex,J.start.regionId,J.start.offset,J.end.offset,M))}function XM($,M,J,Z,X){return o($,y6($.documentIndex,M,J,Z,X))}function YM($){let M=Y0($.documentIndex,$.selection);return M.start.regionId!==M.end.regionId||M.start.offset!==M.end.offset}function QM($,M){let J=G7($,M);if(!J)return null;let Z=o($,J.action);if(!Z)return null;return a$($,Z,J.startOffset,J.endOffset)}function Z4($,M,J){let X=L0($.documentIndex).threads[M];if(!X)return null;let Y=J(X);if(Y===X)return null;return KM($,M,1,Y?[Y]:[])}function KM($,M,J,Z){return o($,{kind:"splice-comments",count:J,index:M,threads:Z})}var DM=1;function qM($,M,J){let Z=$.documentIndex.regionOrderIndex.get($.selection.focus.regionId);if(Z===void 0)return $;let X=$.documentIndex.regions[Z],Y=$.selection.focus.offset+M;if(Y>=0&&Y<=X.text.length)return z0($,X.id,Y,J);if(M<0){let K=$.documentIndex.regions[Z-1];if(!K)return $;return z0($,K.id,K.text.length,J)}let Q=$.documentIndex.regions[Z+1];if(!Q)return $;return z0($,Q.id,0,J)}function AM($,M,J,Z,X){let Y=L2(M,J.regionId,J.offset);if(!Y)return $;let Q=M.lines[Y.index+Z];if(!Q)return $;let K=y0(M,$,{x:I0($,M,J)+DM,y:Q.top+Q.height/2});if(!K)return $;return z0($,K.regionId,K.offset,X)}function UM($,M,J,Z){let X=GM($,M);if(!X)return $;return z0($,X.regionId,J==="Home"?X.start:X.end,Z)}function VM($,M,J,Z,X){let Y=GM($,M);if(!Y)return $;let K=Math.max(1,Math.floor(480/M.options.lineHeight)),q=L2(M,Y.regionId,$.selection.focus.offset),D=q?M.lines[q.index+Z*K]:null;if(!D)return $;let A=y0(M,$,{x:I0($,M,J)+DM,y:D.top+D.height/2});if(!A)return $;return z0($,A.regionId,A.offset,X)}function GM($,M){return j0(M,$.selection.focus.regionId,$.selection.focus.offset)}var JD=1;function NM($,M,J,Z,X){let Y=$.documentIndex.regionIndex.get($.selection.focus.regionId)??null;if(!Y)return null;let Q=$.documentIndex.tableCellIndex.get(Y.id)??null,K=$.documentIndex.blockIndex.get(Y.blockId)??null;if(!Q||K?.type!=="table")return null;let q=ZD($,K.id,Q.rowIndex+Z,Q.cellIndex)??XD($,K.id,Z);if(!q)return $;let D=M.regionBounds.get(Y.id),A=M.regionBounds.get(q.id);if(!D||!A)return $;let V=A.top+YD(J.top+J.height/2-D.top,0,Math.max(0,A.bottom-A.top-1)),U=y0(M,$,{x:I0($,M,J)+JD,y:V});if(!U)return $;return z0($,U.regionId,U.offset,X)}function ZD($,M,J,Z){return Y2($.documentIndex,M,J,Z)}function XD($,M,J){let Z=$.documentIndex.blockIndex.get(M),X=$.documentIndex.regions,Y=Z?$.documentIndex.roots[Z.rootIndex]?.regionRange:void 0;if(!Y)return null;return J<0?X[Y.start-1]??null:X[Y.end]??null}function YD($,M,J){return Math.max(M,Math.min(J,$))}function o6($,M,J=!1){return qM($,M,J)}function n6($,M,J,Z=!1){return QD($,M,J,Z)}function t6($,M,J,Z=!1){return KD($,M,J,Z)}function e6($,M,J,Z=!1){return UM($,M,J,Z)}function $3($,M,J=!1){return DD($,M,J)}function QD($,M,J,Z){let X=_M($,M);if(!X)return $;return NM($,M,X,J,Z)??AM($,M,X,J,Z)}function KD($,M,J,Z){let X=_M($,M);if(!X)return $;return VM($,M,X,J,Z)}function DD($,M,J){let Z=$.documentIndex.regions,X=M==="start"?Z[0]:Z.at(-1);if(!X)return $;return z0($,X.id,M==="start"?0:X.text.length,J)}function _M($,M){return g0(M,$.documentIndex,{regionId:$.selection.focus.regionId,offset:$.selection.focus.offset})}function HM($,M,J,Z,X,Y,Q){let K=J.image?Z.images.get(J.image.url):null,q=UD(J,Z,Q),D=VD(M,Y,Q,q);if($.fillStyle=X.imageSurfaceBackground,$.fillRect(D.left,D.top,D.width,D.height),K?.status==="loaded"&&K.source)$.drawImage(K.source,D.left,D.top,D.width,D.height);else qD($,X,{...D,status:K?.status==="error"?"error":"loading"});$.strokeStyle=X.imageSurfaceBorder,$.strokeRect(D.left,D.top,D.width,D.height)}function qD($,M,J){let Z=J.status==="loading"?"Loading image":"Image unavailable",X=GD(J),Y=J.top+J.height/2+X.size*0.9;if($.save(),$.beginPath(),$.rect(J.left,J.top,J.width,J.height),$.clip(),J.status==="loading")AD($,M,J);$.strokeStyle=M.imagePlaceholderIcon,$.lineWidth=1.5,$.strokeRect(X.left,X.top,X.size,X.size),$.beginPath(),$.arc(X.left+X.size*0.28,X.top+X.size*0.3,X.size*0.1,0,Math.PI*2),$.moveTo(X.left+X.size*0.12,X.top+X.size*0.82),$.lineTo(X.left+X.size*0.42,X.top+X.size*0.5),$.lineTo(X.left+X.size*0.58,X.top+X.size*0.66),$.lineTo(X.left+X.size*0.78,X.top+X.size*0.38),$.lineTo(X.left+X.size*0.88,X.top+X.size*0.82),$.stroke(),$.font='500 12px "Iowan Old Style", "Palatino Linotype", serif',$.fillStyle=M.imagePlaceholderText,$.textAlign="center",$.textBaseline="middle",$.fillText(Z,J.left+J.width/2,Y),$.restore()}function AD($,M,J){let Z=Math.max(48,Math.round(J.width*0.22)),X=J.width+Z*2,Y=performance.now()%1800/1800,Q=J.left-Z+X*Y,K=$.createLinearGradient(Q,J.top,Q+Z,J.top);K.addColorStop(0,"rgba(255,255,255,0)"),K.addColorStop(0.5,M.imageLoadingOverlay),K.addColorStop(1,"rgba(255,255,255,0)"),$.fillStyle=K,$.fillRect(J.left,J.top,J.width,J.height)}function UD($,M,J){if(!$.image)return FM(J);let Z=M.images.get($.image.url);if(!Z||Z.intrinsicWidth<=0||Z.intrinsicHeight<=0)return FM(J);return Math.max(48,Math.round(J*(Z.intrinsicHeight/Z.intrinsicWidth)))}function VD($,M,J,Z){return{height:Z,left:M,top:$.top+Math.max(0,Math.floor(($.height-Z)/2)),width:J}}function GD($){let M=Math.max(18,Math.min(34,Math.round(Math.min($.width,$.height)*0.18)));return{left:$.left+Math.max(12,Math.round(($.width-M)/2)),size:M,top:$.top+Math.max(12,Math.round($.height/2-M*0.95))}}function FM($){return Math.max(48,Math.round($*0.5625))}var zM=2,EM=8,ND=3,_D=1.5,FD=2,A2={elbow:{x:6.5,y:10.5},end:{x:11.5,y:3.5},start:{x:3.5,y:7.5}};function WM($,M,J,Z,X,Y,Q=null){if(!J||M.start!==0)return;if(Q){let K=x$(Q),q=BD(J,M,Z,X,$);$.save(),$.translate(q.x,q.y),$.scale(K,K),$.translate(-q.x,-q.y)}if(J.kind==="task")HD($,M,J.checked,Y,Q);else if($.fillStyle=Q?r2(Y.listMarkerText,Q,Y):Y.listMarkerText,J.kind==="ordered")WD($,J.label,Z,X);else $.fillText(J.label,M.left-zM,X);if(Q)$.restore()}function HD($,M,J,Z,X=null){let Y=R2(M);if(zD($,Y,J,Z,X),!J)return;ED($,Y,Z,X)}function zD($,M,J,Z,X=null){let Y=J?Z.checkboxCheckedFill:Z.checkboxUncheckedFill,Q=J?Z.checkboxCheckedStroke:Z.checkboxUncheckedStroke;$.fillStyle=X?r2(Y,X,Z):Y,$.strokeStyle=X?r2(Q,X,Z):Q,$.beginPath(),$.lineWidth=_D,$.roundRect(M.left,M.top,M.size,M.size,ND),$.fill(),$.stroke()}function ED($,M,J,Z=null){$.strokeStyle=Z?r2(J.checkboxCheckmark,Z,J):J.checkboxCheckmark,$.lineWidth=FD,$.beginPath(),$.moveTo(M.left+A2.start.x,M.top+A2.start.y),$.lineTo(M.left+A2.elbow.x,M.top+A2.elbow.y),$.lineTo(M.left+A2.end.x,M.top+A2.end.y),$.stroke()}function WD($,M,J,Z){let X=$.textAlign;$.textAlign="right",$.fillText(M,J-EM,Z),$.textAlign=X}function BD($,M,J,Z,X){if($.kind==="task"){let K=R2(M);return{x:K.left+K.size/2,y:K.top+K.size/2}}let Y=X.measureText($.label),Q=Z-(Y.actualBoundingBoxAscent-Y.actualBoundingBoxDescent)/2;if($.kind==="ordered")return{x:J-EM-Y.width/2,y:Q};return{x:M.left-zM+Y.width/2,y:Q}}var PD=80;function PM({context:$,containerBounds:M,isHeaderRow:J,lineHeight:Z,theme:X}){let Y=bM(M,Z);$.fillStyle=J?X.tableHeaderBackground:X.tableBodyBackground,$.fillRect(Y.left,Y.top,Y.width,Y.height),wM($,Y,X)}function yM({activeBlockFlashes:$,activeBlockId:M,activeRegionId:J,context:Z,editorState:X,endIndex:Y,layout:Q,regionBounds:K,startIndex:q,theme:D,verticalBleed:A}){if(!M||!J)return;let V=X.documentIndex.blockIndex.get(M)??null;if(V?.type!=="table")return;if((X.documentIndex.regionIndex.get(J)??null)?.blockId!==M)return;let G=K.get(J)??null,_=Q.regionLineIndices.get(J)??null;if(!G||!_||_.length===0)return;let N=Q.lines[_[0]]??null;if(!N)return;let H=bM(G,N.height);if(H.width===0)return;let E=BM({context:Z,endIndex:Y,fillStyle:D.activeBlockBackground,layout:Q,left:H.left,lineIndices:_,startIndex:q,verticalBleed:A,width:H.width}),L=V.path?$.get(V.path)??null:null;if(L)BM({context:Z,endIndex:Y,fillStyle:b5(D.activeBlockFlash,L),layout:Q,left:H.left,lineIndices:_,startIndex:q,verticalBleed:A,width:H.width});if(!E)return;wM(Z,H,D)}function BM({context:$,endIndex:M,fillStyle:J,layout:Z,left:X,lineIndices:Y,startIndex:Q,verticalBleed:K,width:q}){$.fillStyle=J;let D=!1;for(let A of Y){if(A<Q)continue;if(A>=M)break;let V=Z.lines[A];$.fillRect(X,V.top-K,q,V.height),D=!0}return D}function bM($,M){return{height:Math.max($.bottom-$.top,M),left:$.left,top:$.top,width:Math.max($.right-$.left,PD)}}function wM($,M,J){$.strokeStyle=J.tableBorder,$.strokeRect(M.left,M.top,M.width,M.height)}var M3=2,yD=3,bD=12,wD=6,TD=3,OD=1,jD=2,LD=2,CD=8,RD=12,fD=28,mD=4,SD=5,kD=2,uD=3,vD=6,TM=3,hD=12,gD=10,ID=2,pD=2,lD=1,dD=2,J3=2,OM=1.25,rD=5,xD=1,jM=4,cD=4,aD=1.5;function sD({activeBlockId:$,activeRegionId:M,activeThreadIndex:J,containerLineBounds:Z,context:X,devicePixelRatio:Y,editorState:Q,height:K,layout:q,liveCommentRanges:D,normalizedSelection:A,now:V=Eq(),resources:U,runtimeBlockMap:G,theme:_,viewportTop:N,width:H}){X.save(),X.scale(Y,Y),X.clearRect(0,0,H,K),X.fillStyle=_.background,X.fillRect(0,0,H,K),X.textBaseline="alphabetic",X.translate(0,-N);let E=iD(Q,A),{endIndex:L,startIndex:W}=n8(q,N,K),R=u$(Q,V),f=v$(Q,V),I=k$(Q,V),B=g$(Q,V),b=h$(Q,V),z=nD(q,Q,$,W,L),T=oD(q,Q,G,W,L,H);for(let P=W;P<L;P+=1){let y=q.lines[P];Mq({containerLineBounds:Z,context:X,editorState:Q,line:y,runtimeBlockMap:G,theme:_,width:H})}yM({activeBlockFlashes:R,activeBlockId:$,activeRegionId:M,context:X,editorState:Q,endIndex:L,layout:q,regionBounds:Z,startIndex:W,theme:_,verticalBleed:M3});for(let P=W;P<L;P+=1){let y=q.lines[P];Jq({activeBlockId:$,activeBlockFlashes:R,activeDeletedTextFades:f,activeThreadIndex:J,activeInsertedTextHighlights:I,activeListMarkerPops:B,activePunctuationPulses:b,context:X,editorState:Q,line:y,liveCommentRanges:D,normalizedSelection:A,resources:U,runtimeBlockMap:G,selectionRegionOrderRange:E,theme:_,width:H})}tD(X,T,_),eD(X,z,_),X.restore()}function iD($,M){let J=$.documentIndex.regionOrderIndex,Z=J.get(M.start.regionId),X=J.get(M.end.regionId);return Z===void 0||X===void 0?null:{end:X,start:Z}}function oD($,M,J,Z,X,Y){let Q=new Map;for(let K=Z;K<X;K+=1){let q=$.lines[K],D=J.get(q.blockId);if(D?.type!=="heading"||D.depth!==1&&D.depth!==2)continue;let A=Q.get(D.id),V={bottom:q.top+q.height,left:q.left+h0(M,q),right:Y-$.options.paddingX};Q.set(D.id,A?{bottom:Math.max(A.bottom,V.bottom),left:A.left,right:A.right}:V)}return Q}function nD($,M,J,Z,X){let Y=new Map;for(let Q=Z;Q<X;Q+=1){let K=$.lines[Q],q=$2(M,K.blockId,"blockquote");if(!q)continue;let D=Y.get(q.id),A={bottom:K.top+K.height,isActive:K.blockId===J,left:$.options.paddingX+(q.depth+1)*$.options.indentWidth-10,top:K.top};Y.set(q.id,D?{bottom:Math.max(D.bottom,A.bottom),isActive:D.isActive||A.isActive,left:D.left,top:Math.min(D.top,A.top)}:A)}return Y}function tD($,M,J){$.fillStyle=J.headingRule;for(let Z of M.values())$.fillRect(Z.left,Z.bottom+rD,Math.max(J3,Z.right-Z.left),xD)}function eD($,M,J){for(let Z of M.values())$.fillStyle=Z.isActive?J.blockquoteRuleActive:J.blockquoteRule,$.fillRect(Z.left,Z.top+yD,TD,Math.max(bD,Z.bottom-Z.top-wD))}function $q({context:$,devicePixelRatio:M,editorState:J,height:Z,layout:X,normalizedSelection:Y,presence:Q,showCaret:K,theme:q,viewportTop:D,width:A}){$.save(),$.scale(M,M),$.clearRect(0,0,A,Z);let V=Y.start.regionId===Y.end.regionId&&Y.start.offset!==Y.end.offset,U=K&&!V;if($.translate(0,-D),U)LM($,J,X,{color:q.caret,offset:J.selection.focus.offset,regionId:J.selection.focus.regionId});if(Q)for(let G of Q){if(!G.cursorPoint)continue;LM($,J,X,{color:G.color??q.leafAccent,offset:G.cursorPoint.offset,regionId:G.cursorPoint.regionId})}$.restore()}function LM($,M,J,Z){let X=g0(J,M.documentIndex,{regionId:Z.regionId,offset:Z.offset});if(!X)return;let Y=I0(M,J,X),Q=Aq(J,X);$.fillStyle=Z.color,$.fillRect(Y,Q.top,jD,Q.height)}function Mq({containerLineBounds:$,context:M,editorState:J,line:Z,runtimeBlockMap:X,theme:Y,width:Q}){let K=X.get(Z.blockId)??null,q=$.get(Z.regionId)??null,D=J.documentIndex.tableCellIndex.get(Z.regionId)??null;Zq(M,Z,K,q,D,Y,Q)}function Jq({activeBlockId:$,activeBlockFlashes:M,activeDeletedTextFades:J,activeThreadIndex:Z,activeInsertedTextHighlights:X,activeListMarkerPops:Y,activePunctuationPulses:Q,context:K,editorState:q,line:D,liveCommentRanges:A,normalizedSelection:V,resources:U,runtimeBlockMap:G,selectionRegionOrderRange:_,theme:N,width:H}){let E=G.get(D.blockId)??null,L=q.documentIndex.blockIndex.get(D.blockId)?.path??null,W=q.documentIndex.regionIndex.get(D.regionId)??null,R=W?.path??"",f=$2(q,D.blockId,"listItem"),I=f?f2(q,f.id):null,B=f?Y.get(f.path)??null:null,b=D.left+h0(q,D),z=Gq(D),T=E?.type==="code"?N.codeText:Fq(E,N);K.font=D.font,Xq(K,D,E,L,$,M,N,H),Yq(K,q,D,V,_,N),Qq(K,q,D,A,Z,N),WM(K,D,I,b,z,N,B),Kq(K,D,W,b,z,X.get(R)??[],T,U,N),Dq(K,D,W,b,z,J.get(R)??[],T),qq(K,D,W,b,z,Q.get(R)??[],N)}function Zq($,M,J,Z,X,Y,Q){if(!Z||M.start!==0)return;if(J?.type==="code"){let K=Math.max(0,M.left-RD);$.fillStyle=Y.codeBackground,$.fillRect(K,Z.top-mD,Math.max(Z.right-M.left+fD,Q-K),Z.bottom-Z.top+CD);return}if(J?.type!=="table")return;PM({context:$,containerBounds:Z,isHeaderRow:X?.rowIndex===0,lineHeight:M.height,theme:Y})}function Xq($,M,J,Z,X,Y,Q,K){if(M.blockId!==X||J?.type==="table")return;let q=Z?Y.get(Z)??null:null;if($.fillStyle=Q.activeBlockBackground,$.fillRect(0,M.top-M3,K,M.height),!q)return;$.fillStyle=b5(Q.activeBlockFlash,q),$.fillRect(0,M.top-M3,K,M.height)}function Yq($,M,J,Z,X,Y){if(!X)return;let Q=M.documentIndex.regionOrderIndex.get(J.regionId);if(Q===void 0||Q<X.start||Q>X.end)return;let K=Q===X.start?Math.max(J.start,Z.start.offset):J.start,q=Q===X.end?Math.min(J.end,Z.end.offset):J.end;if(q<=K)return;$.fillStyle=Y.selectionBackground,$.fillRect(Q1(M,J,K-J.start),J.top+lD,Math.max(pD,Q1(M,J,q-J.start)-Q1(M,J,K-J.start)),J.height-dD)}function Qq($,M,J,Z,X,Y){for(let Q of Z){if(Q.regionId!==J.regionId)continue;let K=Math.max(Q.startOffset,J.start),q=Math.min(Q.endOffset,J.end);if(q<=K)continue;$.fillStyle=zq(Q,X,Y),$.fillRect(Q1(M,J,K-J.start),J.top+J.height-SD,Math.max(kD,Q1(M,J,q-J.start)-Q1(M,J,K-J.start)),uD)}}function Kq($,M,J,Z,X,Y,Q,K,q){if(!J){$.fillStyle=Q,$.fillText(M.text,Z,X);return}let D=J.inlines.filter((A)=>A.end>M.start&&A.start<M.end);if(D.length===0){$.fillStyle=Q,$.fillText(M.text,Z,X);return}for(let A of D){let V=Math.max(M.start,A.start),U=Math.min(M.end,A.end);if(J.text.slice(V,U).length===0)continue;let{left:_,right:N}=X3(M,Z,V,U),H=Hq(M.font,A.marks);if($.font=H,A.kind==="image"){let E=Math.max(24,N-_);HM($,M,A,K,q,_,E);continue}if(A.kind==="inlineCode"){let E=Nq(M,H),L=_q(M,H);$.fillStyle=q.inlineCodeBackground,$.fillRect(_-TM,E,Math.max(gD,N-_+TM*2),L),CM($,M,J.text,Z,X,V,U,q.inlineCodeText,Y,q,{strikethrough:!1,underline:!1});continue}CM($,M,J.text,Z,X,V,U,A.link?q.linkText:Q,Y,q,{strikethrough:A.marks.includes("strikethrough"),underline:A.marks.includes("underline")||Boolean(A.link)})}}function CM($,M,J,Z,X,Y,Q,K,q,D,A){let V=I$(Y,Q,q);for(let U=0;U<V.length-1;U+=1){let G=V[U],_=V[U+1];if(_<=G)continue;let N=J.slice(G,_);if(N.length===0)continue;let{left:H,right:E}=X3(M,Z,G,_),L=p$(q,G,_),W=l$(K,L,D);if($.fillStyle=W,$.fillText(N,H,X),A.strikethrough)$.fillRect(H,Vq(X,M.height,$.font),Math.max(J3,E-H),OM);if(A.underline)$.fillRect(H,Uq(X,M.height,$.font),Math.max(J3,E-H),OM)}}function Dq($,M,J,Z,X,Y,Q){if(!J||Y.length===0)return;for(let K of Y){if(K.startOffset<M.start||K.startOffset>M.end)continue;let q=Z+(W0(M,K.startOffset-M.start)-M.left);$.fillStyle=d$(Q,K),$.fillText(K.text,q,X)}}function qq($,M,J,Z,X,Y,Q){if(!J||Y.length===0)return;for(let K of Y){if(K.offset<M.start||K.offset>=M.end)continue;let{left:q,right:D}=X3(M,Z,K.offset,K.offset+1),A=Math.max(jM,(D-q)/2+jM+cD*K.progress),{ascent:V,descent:U}=Y1(M.font),G=X-Math.max(1,V*0.42)+Math.max(0.5,U*0.15);$.strokeStyle=r$(K,Q),$.lineWidth=aD,$.beginPath(),$.arc((q+D)/2,G,A,0,Math.PI*2),$.stroke()}}function Aq($,M){let J=j0($,M.regionId,M.offset),Z=J?.font??'16px "Iowan Old Style", "Palatino Linotype", serif',{ascent:X,descent:Y}=Y1(Z),Q=Math.max(1,X+Y),K=Math.min(M.height-LD,Q),q=J?Math.max(J.top,J.top+Z3(J.height,Z)-OD):M.top+Math.max(0,Math.floor((M.height-K)/2));return{height:K,top:q}}function Uq($,M,J){let{descent:Z}=Y1(J),X=Math.max(1,Math.round(Math.max(2,Z)*0.35)),Y=$+Z-X,Q=$-I5(M,J);return Math.min(Q+M-4,Y)}function Vq($,M,J){let{ascent:Z}=Y1(J),X=$-I5(M,J);return Math.max(X+2,$-Math.round(Z*0.32))}function Gq($){return $.top+I5($.height,$.font)}function I5($,M){return N$($,M)}function Nq($,M){let J=Z3($.height,M);return $.top+J+ID}function _q($,M){let J=Z3($.height,M);return Math.max(hD,$.height-J-vD)}function Z3($,M){let{ascent:J}=Y1(M);return I5($,M)-J}function Fq($,M){switch($?.type){case"heading":return M.headingText;case"blockquote":return M.blockquoteText;case"table":return M.headingText;default:return M.paragraphText}}function X3($,M,J,Z){return{left:M+(W0($,J-$.start)-$.left),right:M+(W0($,Z-$.start)-$.left)}}function Hq($,M){let J=[];if(M.includes("italic"))J.push("italic");if(M.includes("bold"))J.push("700");return J.length>0?`${J.join(" ")} ${$}`:$}function zq($,M,J){if($.resolved)return $.threadIndex===M?J.commentHighlightResolvedActive:J.commentHighlightResolved;return $.threadIndex===M?J.commentHighlightActive:J.commentHighlight}function Eq(){return typeof performance<"u"?performance.now():Date.now()}function Y3($,M,J,Z){sD({activeBlockId:Z.activeBlockId,activeRegionId:Z.activeRegionId,activeThreadIndex:Z.activeThreadIndex,containerLineBounds:M.regionBounds,context:J,devicePixelRatio:Z.devicePixelRatio,editorState:$,height:Z.height,layout:M.layout,liveCommentRanges:Z.liveCommentRanges,normalizedSelection:Z.normalizedSelection,now:Z.now,resources:Z.resources??{images:new Map},runtimeBlockMap:M.blockMap,theme:Z.theme,viewportTop:M.paintTop,width:Z.width})}function Q3($,M,J,Z){$q({context:J,devicePixelRatio:Z.devicePixelRatio,editorState:$,height:Z.height,layout:M.layout,normalizedSelection:Z.normalizedSelection,presence:Z.presence,showCaret:Z.showCaret,theme:Z.theme,viewportTop:M.paintTop,width:Z.width})}import{forwardRef as bq,createElement as wq}from"react";var p5=(...$)=>$.filter((M,J,Z)=>{return Boolean(M)&&M.trim()!==""&&Z.indexOf(M)===J}).join(" ").trim();var RM=($)=>$.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var fM=($)=>$.replace(/^([A-Z])|[\s-_]+(\w)/g,(M,J,Z)=>Z?Z.toUpperCase():J.toLowerCase());var K3=($)=>{let M=fM($);return M.charAt(0).toUpperCase()+M.slice(1)};import{forwardRef as yq,createElement as kM}from"react";var l5={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};var mM=($)=>{for(let M in $)if(M.startsWith("aria-")||M==="role"||M==="title")return!0;return!1};import{createContext as Wq,useContext as Bq,useMemo as eH,createElement as $z}from"react";var Pq=Wq({});var SM=()=>Bq(Pq);var uM=yq(({color:$,size:M,strokeWidth:J,absoluteStrokeWidth:Z,className:X="",children:Y,iconNode:Q,...K},q)=>{let{size:D=24,strokeWidth:A=2,absoluteStrokeWidth:V=!1,color:U="currentColor",className:G=""}=SM()??{},_=Z??V?Number(J??A)*24/Number(M??D):J??A;return kM("svg",{ref:q,...l5,width:M??D??l5.width,height:M??D??l5.height,stroke:$??U,strokeWidth:_,className:p5("lucide",G,X),...!Y&&!mM(K)&&{"aria-hidden":"true"},...K},[...Q.map(([N,H])=>kM(N,H)),...Array.isArray(Y)?Y:[Y]])});var u=($,M)=>{let J=bq(({className:Z,...X},Y)=>wq(uM,{ref:Y,iconNode:M,className:p5(`lucide-${RM(K3($))}`,`lucide-${$}`,Z),...X}));return J.displayName=K3($),J};var Tq=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],q1=u("columns-2",Tq);var Oq=[["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"}]],A1=u("rows-3",Oq);var jq=[["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"}]],U1=u("send-horizontal",jq);var Lq=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],X4=u("arrow-down",Lq);var Cq=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],Y4=u("arrow-up",Cq);var Rq=[["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"}]],Q4=u("bold",Rq);var fq=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],L1=u("check",fq);var mq=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],K4=u("chevron-down",mq);var Sq=[["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"}]],D4=u("heading-1",Sq);var kq=[["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"}]],q4=u("heading-2",kq);var uq=[["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"}]],A4=u("heading-3",uq);var vq=[["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"}]],U4=u("heading-4",vq);var hq=[["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"}]],V4=u("heading-5",hq);var gq=[["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"}]],G4=u("heading-6",gq);var Iq=[["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M6 20V4",key:"1w1bmo"}],["path",{d:"M18 20V4",key:"o2hl4u"}]],N4=u("heading",Iq);var pq=[["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"}]],_4=u("italic",pq);var lq=[["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"}]],F4=u("list-ordered",lq);var dq=[["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"}]],H4=u("list-todo",dq);var rq=[["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"}]],z4=u("list",rq);var xq=[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}],["path",{d:"M12 8v6",key:"1ib9pf"}],["path",{d:"M9 11h6",key:"1fldmi"}]],E4=u("message-square-plus",xq);var cq=[["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=u("pencil",cq);var aq=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],U2=u("plus",aq);var sq=[["path",{d:"M16 4H9a3 3 0 0 0-2.83 4",key:"43sutm"}],["path",{d:"M14 12a4 4 0 0 1 0 8H6",key:"nlfj13"}],["line",{x1:"4",x2:"20",y1:"12",y2:"12",key:"1e0a9i"}]],W4=u("strikethrough",sq);var iq=[["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"}]],V1=u("table-2",iq);var oq=[["path",{d:"M17 5H3",key:"1cn7zz"}],["path",{d:"M21 12H8",key:"scolzb"}],["path",{d:"M21 19H8",key:"13qgcb"}],["path",{d:"M3 12v7",key:"1ri8j3"}]],B4=u("text-quote",oq);var nq=[["path",{d:"M10 11v6",key:"nco0om"}],["path",{d:"M14 11v6",key:"outv1u"}],["path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6",key:"miytrc"}],["path",{d:"M3 6h18",key:"d0wm0j"}],["path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2",key:"e791ji"}]],w0=u("trash-2",nq);var tq=[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4",key:"9kb039"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20",key:"nun2al"}]],P4=u("underline",tq);var eq=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],y4=u("x",eq);import{jsx as V2,jsxs as ZA}from"react/jsx-runtime";function vM({insetX:$,insetY:M,onSelect:J,presence:Z}){if(!Z)return null;return V2("div",{"aria-label":"Presence",className:"documint-presence-indicators",style:{paddingRight:`${$}px`,top:`${M}px`},children:Z.map((X)=>V2($A,{onSelect:()=>J(X),presence:X},X.id))})}function $A({onSelect:$,presence:M}){let J=M.viewport,Z=MA(M),X=J?.status==="above"?Y4:X4,Y=J!==null&&J.status!=="unresolved",Q=J?.status==="above"||J?.status==="below";return ZA("button",{"aria-label":JA(M),className:"documint-presence-indicator","data-status":J?.status??"unresolved",disabled:!Y,onClick:Y?$:void 0,style:{"--documint-presence-color":M.color??"var(--documint-leaf-accent)"},type:"button",children:[V2("span",{className:"documint-presence-indicator-avatar",children:M.avatarUrl?V2("img",{alt:"","aria-hidden":"true",className:"documint-presence-indicator-image",draggable:!1,src:M.avatarUrl}):Z}),Q?V2("span",{className:"documint-presence-indicator-direction","aria-hidden":"true",children:V2(X,{className:"documint-presence-indicator-arrow",size:14,strokeWidth:2.3})}):null]})}function MA($){return hM($).charAt(0).toLocaleUpperCase()}function JA($){let M=hM($),J=$.viewport?.status??"unresolved";if(J==="above")return`${M} above viewport`;if(J==="below")return`${M} below viewport`;if(J==="unresolved")return`${M} unresolved`;return`${M} in viewport`}function hM($){return($.fullName??$.username).trim()||"Presence"}var i=`
|
|
26
|
-
`,
|
|
27
|
-
|
|
28
|
-
`,tA="-",eA=".",$U="***",MU=" ",z3=3,JU=5,ZU=4,DJ=2,XU=2,YU=1,QU=/([\\`*_[\]])/g,KU=/([\\)&])/g,DU=/(["\\])/g;function i5($,M={}){if($.blocks.length===0&&$.comments.length===0&&$.frontMatter===void 0)return"";let J=$.blocks.map((X)=>o5(X,0,M));if($.comments.length>0)J.push(TU($.comments));if($.frontMatter!==void 0)J.unshift($.frontMatter);let Z=J.join(O4);return Z.endsWith(i)?Z:`${Z}${i}`}function o5($,M,J){let Z=N1(M);switch($.type){case"blockquote":return qU($,M,J);case"code":return AU($,M);case"directive":return OU($,M);case"heading":return AJ($,M);case"list":return UU($,M,J);case"listItem":return UJ($,M,!1,1,J);case"paragraph":return`${Z}${E3(j4($.children))}`;case"table":return GU($,M,J);case"thematicBreak":return`${Z}${$U}`;case"unsupported":return M===0?$.source:NJ($.source,M)}}function qU($,M,J){let Z=$.children.map((Y)=>o5(Y,0,J)).join(O4),X=N1(M);return Z.split(i).map((Y)=>`${X}${G2}${Y.length>0?` ${Y}`:""}`).join(i)}function AU($,M){let J=[$.language??"",$.meta??""].filter(Boolean).join(" ").trim(),Z=N1(M),X=`${Z}${w4}${J?J:""}`,Y=$.source.length>0?$.source.split(i).map((Q)=>`${Z}${Q}`).join(i):Z;return`${X}${i}${Y}${i}${Z}${w4}`}function AJ($,M){let J=E3(j4($.children)),Z=`${N1(M)}${"#".repeat($.depth)}`;return J.length>0?`${Z} ${J}`:Z}function UU($,M,J){let Z=$.start??1;return $.items.map((X)=>UJ(X,M,$.ordered,Z,J)).join($.spread?O4:i)}function UJ($,M,J,Z,X){let Y=J?`${Z}${eA}`:tA,Q=$.checked===null?"":`[${$.checked?"x":" "}] `,K=`${N1(M)}${Y} ${Q}`,q=M+Y.length+1,D=$.children;if(D.length===0)return Q.length>0?K:K.trimEnd();let[A,...V]=D,U=VU(A,K,Q.length>0,X),G=V.map((_)=>o5(_,q,X)).join($.spread?O4:i);if(!G)return U;return`${U}${$.spread?O4:i}${G}`}function VU($,M,J,Z){switch($.type){case"paragraph":{let X=E3(j4($.children));if(X.length===0)return J?M:M.trimEnd();return`${M}${X}`}case"heading":return`${M}${AJ($,0)}`;case"directive":case"unsupported":{let X=$.type==="directive"?W3($):$.source,[Y,...Q]=X.split(i);return[M+Y,...Q.map((K)=>`${N1(M.length)}${K}`)].join(i)}default:{let X=M.length;return`${M.trimEnd()}${i}${o5($,X,Z)}`}}}function GU($,M,J){let Z=$.rows.map((A)=>A.cells.map((V)=>j4(V.children))),X=Math.max(1,...Z.map((A)=>A.length)),Y=Z[0]??[],Q=Array.from({length:X},(A,V)=>Math.max(z3,HU($.align[V]),...J.padTableColumns?Z.map((U)=>U[V]?.length??0):[Y[V]?.length??0])),K=NU(Q,$.align,M),q=qJ(Y,Q,$.align,M,J),D=Z.slice(1).map((A)=>qJ(A,Q,$.align,M,J));return[q??_U(Q,M),K,...D].join(i)}function qJ($,M,J,Z,X){let Y=M.map((Q,K)=>{let q=$[K]??"";if(!X.padTableColumns)return q;return zU(q,Q,J[K])});return`${" ".repeat(Z)}| ${Y.join(" | ")} |`}function NU($,M,J){let Z=$.map((X,Y)=>FU(M[Y],X));return`${" ".repeat(J)}| ${Z.join(" | ")} |`}function _U($,M){return`${N1(M)}| ${$.map((J)=>"".padEnd(J," ")).join(" | ")} |`}function FU($,M){let J=Math.max(z3,M-($==="center"?XU:$?YU:0));switch($){case"center":return`:${"-".repeat(Math.max(1,J))}:`;case"left":return`:${"-".repeat(Math.max(DJ,J))}`;case"right":return`${"-".repeat(Math.max(DJ,J))}:`;default:return"-".repeat(J)}}function HU($){return $==="center"?JU:$?ZU:z3}function zU($,M,J){if(J==="right")return $.padStart(M," ");return $.padEnd(M," ")}function j4($){return WU($).map((M)=>EU(M)).join("")}function E3($){return $.replace(/^ +/gm,(M)=>MU.repeat(M.length))}function EU($){switch($.type){case"break":return i;case"image":return jU($);case"inlineCode":return yU($.code);case"link":return LU($);case"text":return PU(VJ($.text),$.marks);case"unsupported":return $.source}}function WU($){let M=[];for(let J of $){let Z=M.at(-1);if(Z?.type==="text"&&J.type==="text"&&BU(Z.marks,J.marks)){M[M.length-1]={...Z,text:Z.text+J.text};continue}M.push(J)}return M}function BU($,M){return $.length===M.length&&$.every((J,Z)=>J===M[Z])}function PU($,M){return M.reduce((J,Z)=>{switch(Z){case"bold":return`**${J}**`;case"italic":return`*${J}*`;case"strikethrough":return`~~${J}~~`;case"underline":return`${G1}${J}${b4}`}},$)}function yU($){let M=0,J=0;for(let Q of $){if(Q==="`"){if(J+=1,J>M)M=J;continue}J=0}let Z=M>0?M+1:1,X="`".repeat(Z),Y=$.startsWith("`")||$.endsWith("`")?` ${$} `:$;return`${X}${Y}${X}`}function VJ($){return $.replace(QU,"\\$1")}function bU($){return $.replace(KU,"\\$1")}function wU($){return $?` "${$.replace(DU,"\\$1")}"`:""}function TU($){return W3({attributes:"",body:JSON.stringify($,null,2),name:r5})}function OU($,M){let J=W3($);return M===0?J:NJ(J,M)}function W3($){let M=$.attributes?`{${$.attributes}}`:"";return`:::${$.name}${M}${i}${$.body}${i}${d5}`}function jU($){let M=VJ($.alt??""),J=GJ($.url,$.title),Z=$.width?`{width=${$.width}}`:"";return`![${M}]${J}${Z}`}function LU($){return`[${j4($.children)}]${GJ($.url,$.title)}`}function GJ($,M){return`(${bU($)}${wU(M)})`}function N1($){return" ".repeat($)}function NJ($,M){let J=N1(M);return $.split(i).map((Z)=>`${J}${Z}`).join(i)}import{createContext as CU,useContext as RU}from"react";import{createPortal as fU}from"react-dom";import{jsx as HJ}from"react/jsx-runtime";var _J=CU(void 0);function FJ({children:$,themeStyles:M}){return HJ(_J.Provider,{value:M,children:$})}function n5({children:$}){let M=RU(_J);if(typeof document>"u")return null;return fU(HJ("div",{className:"documint-overlay",style:{display:"contents",...M},children:$}),document.body)}import{useEffect as t5,useRef as RJ,useState as R1}from"react";import{forwardRef as SU,useCallback as F2,useEffect as kU,useImperativeHandle as uU,useLayoutEffect as vU,useMemo as hU,useRef as WJ,useState as B3}from"react";var mU=["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 zJ($,M,{topGap:J=8}={}){if(!$.isConnected)return null;let Z=getComputedStyle($),X=document.createElement("div");for(let D of mU)X.style.setProperty(D,Z.getPropertyValue(D));Object.assign(X.style,{position:"absolute",top:"0",left:"0",visibility:"hidden",whiteSpace:"pre-wrap",wordWrap:"break-word",width:`${$.clientWidth}px`}),X.textContent=$.value.slice(0,M);let Y=document.createElement("span");Y.textContent=$.value.slice(M)||".",X.appendChild(Y),document.body.appendChild(X);let Q=$.getBoundingClientRect(),K=parseFloat(Z.lineHeight)||Y.offsetHeight,q={left:Q.left+Y.offsetLeft+parseFloat(Z.borderLeftWidth)-$.scrollLeft,top:Q.top+Y.offsetTop+parseFloat(Z.borderTopWidth)+K+J-$.scrollTop};return document.body.removeChild(X),q}import{jsx as R0,jsxs as BJ,Fragment as aU}from"react/jsx-runtime";var gU=240,IU="documint-leaf-menu-item documint-completion-item",L4=SU(function({actions:M,completionSources:J,onChange:Z,placeholder:X,readOnly:Y=!1,rows:Q=3,value:K},q){let D=WJ(null);uU(q,()=>D.current,[]);let A=hU(()=>rU(J),[J]),[V,U]=B3(null),[G,_]=B3(0),[N,H]=B3(null),E=F2((B,b)=>{if(!A.length){U(null);return}let z=xU(B,b,A);if(!z){U(null);return}U(z),_(0)},[A]),L=F2((B)=>{let b=B.currentTarget.value,z=B.currentTarget.selectionEnd??b.length;Z(b),E(b,z)},[Z,E]),W=F2((B)=>{let b=B.currentTarget;E(b.value,b.selectionEnd??b.value.length)},[E]),R=F2(()=>{U(null)},[]),f=F2((B)=>{if(!D.current||!V)return;let z=`${V.trigger}${B.label} `,T=K.slice(0,V.triggerStart),P=K.slice(V.caret),y=T+z+P,F=V.triggerStart+z.length;Z(y),U(null),requestAnimationFrame(()=>{let C=D.current;if(!C)return;C.focus(),C.setSelectionRange(F,F)})},[V,Z,K]),I=F2((B)=>{if(V&&V.matches.length>0){if(B.key==="ArrowDown"){B.preventDefault(),B.stopPropagation(),_((b)=>(b+1)%V.matches.length);return}if(B.key==="ArrowUp"){B.preventDefault(),B.stopPropagation(),_((b)=>(b-1+V.matches.length)%V.matches.length);return}if(B.key==="Enter"||B.key==="Tab"){B.preventDefault(),B.stopPropagation();let b=V.matches[G];if(b)f(b);return}if(B.key==="Escape"){B.preventDefault(),B.stopPropagation(),U(null);return}}if(B.key==="Escape"&&M.kind==="edit")B.preventDefault(),M.onCancel()},[M,V,G,f]);return vU(()=>{if(!V){H(null);return}let B=()=>{let b=D.current;if(!b)return;H(zJ(b,V.triggerStart))};return B(),window.addEventListener("scroll",B,!0),window.addEventListener("resize",B),()=>{window.removeEventListener("scroll",B,!0),window.removeEventListener("resize",B)}},[V]),BJ("div",{className:"documint-leaf-input-field",children:[R0("textarea",{className:"documint-leaf-input",onBlur:R,onChange:L,onKeyDown:I,onSelect:W,placeholder:X,readOnly:Y,ref:D,rows:Q,value:K}),pU(M),V&&N&&V.matches.length>0?R0(n5,{children:R0(lU,{activeIndex:G,left:N.left,matches:V.matches,onHover:_,onSelect:f,top:N.top})}):null]})});function pU($){if($.kind==="edit")return BJ(aU,{children:[R0(P3,{className:"documint-leaf-input-cancel",icon:y4,label:"Cancel editing",onClick:$.onCancel}),R0(P3,{className:"documint-leaf-input-save",disabled:$.saveDisabled??!1,icon:L1,label:"Save",onClick:$.onSave})]});return R0(P3,{className:"documint-leaf-input-submit",disabled:$.submitDisabled??!1,icon:U1,iconSize:15,label:$.submitLabel,onClick:$.onSubmit})}function P3({className:$,disabled:M=!1,icon:J,iconSize:Z=14,label:X,onClick:Y}){return R0("button",{"aria-label":X,className:`documint-leaf-action ${$}`,disabled:M,onClick:Y,title:X,type:"button",children:R0(J,{size:Z,strokeWidth:2.2})})}function lU({activeIndex:$,left:M,matches:J,onHover:Z,onSelect:X,top:Y}){let Q=WJ(null);return kU(()=>{let K=Q.current;if(!K)return;let q=K.children[$];if(q instanceof HTMLElement)q.scrollIntoView({block:"nearest"})},[$]),R0("div",{className:"documint-leaf-menu documint-completion-popover",ref:Q,role:"listbox",style:{position:"fixed",left:M,top:Y,maxHeight:gU,overflowY:"auto"},children:J.map((K,q)=>{let D=q===$;return R0("button",{"aria-selected":D,className:`${IU}${D?" is-active":""}`,onPointerDown:dU,onPointerEnter:()=>Z(q),onClick:()=>X(K),role:"option",type:"button",children:R0("span",{children:K.label})},K.label)})})}function dU($){$.preventDefault()}function rU($){if(!$?.length)return[];return $.map((M)=>({trigger:M.trigger,items:[...M.items].sort((J,Z)=>J.label.localeCompare(Z.label,void 0,{sensitivity:"base"}))}))}function xU($,M,J){for(let Z=M-1;Z>=0;Z-=1){let X=$[Z];if(EJ(X))return null;let Y=J.find((K)=>K.trigger===X);if(!Y)continue;if(Z>0&&!EJ($[Z-1]))return null;let Q=$.slice(Z+1,M);return{trigger:Y.trigger,query:Q,triggerStart:Z,caret:M,matches:cU(Y.items,Q)}}return null}function EJ($){return $===void 0||$===" "||$===`
|
|
29
|
-
`||$==="\t"}function
|
|
30
|
-
`||$==="\t"}import{jsx as PJ,jsxs as nU}from"react/jsx-runtime";function w3({value:$,completionSources:M,onEdit:J}){return PJ("p",{onDoubleClick:J,children:oU($,M)})}function oU($,M){let J=y3($,M);if(J.length===1&&J[0].kind==="text")return $;return J.map((Z,X)=>Z.kind==="token"?nU("span",{className:"documint-mention",children:[Z.trigger,Z.label]},X):PJ(iU,{children:Z.text},X))}import{Children as yJ,isValidElement as bJ,useEffect as tU,useRef as eU,useState as $V}from"react";import{jsx as A0,jsxs as j3}from"react/jsx-runtime";var T3=($)=>{$.preventDefault()},O3=($)=>$.isPrimary&&$.button===0;function MV({children:$}){return A0("div",{className:"documint-leaf-toolbar",children:yJ.map($,JV)})}function JV($){if(!bJ($))return null;if($.type===TJ){let M=$.props;return A0(wJ,{children:A0(ZV,{...M})})}if($.type===OJ){let{className:M}=$.props;return A0("div",{className:C4("documint-leaf-toolbar-divider",M)})}if($.type===jJ){let M=$.props;return A0(XV,{...M})}return null}function ZV({active:$=!1,className:M,disabled:J=!1,icon:Z,label:X,onClick:Y}){return A0("button",{"aria-label":X,className:C4("documint-leaf-toolbar-button",$?"active":null,M),disabled:J,onPointerDown:(Q)=>{if(T3(Q),!J&&O3(Q))Y()},title:X,type:"button",children:A0(Z,{size:15,strokeWidth:2.2})})}function XV({children:$,className:M,icon:J,label:Z,onSelect:X}){let Y=eU(null),[Q,K]=$V(!1);return tU(()=>{if(!Q)return;let q=(D)=>{if(Y.current&&D.target instanceof Node&&!Y.current.contains(D.target))K(!1)};return window.addEventListener("pointerdown",q),()=>{window.removeEventListener("pointerdown",q)}},[Q]),A0(wJ,{children:j3("div",{className:"documint-leaf-toolbar-menu-shell",ref:Y,children:[A0(YV,{className:M,icon:J,isOpen:Q,label:Z,onClick:()=>K((q)=>!q)}),Q?A0("div",{className:"documint-leaf-menu",role:"menu",children:yJ.map($,(q)=>QV(q,(D)=>{K(!1),X(D)}))}):null]})})}function YV({className:$,icon:M,isOpen:J,label:Z,onClick:X}){return j3("button",{"aria-expanded":J,"aria-haspopup":"menu","aria-label":Z,className:C4("documint-leaf-toolbar-button",J?"active":null,$),onPointerDown:(Y)=>{if(T3(Y),O3(Y))X()},title:Z,type:"button",children:[A0(M,{size:15,strokeWidth:2.2}),A0(K4,{className:C4("documint-leaf-toolbar-menu-chevron",J?"is-open":null),size:13,strokeWidth:2.2})]})}function QV($,M){if(!bJ($))return null;if($.type===CJ){let{className:Q}=$.props;return A0("div",{className:C4("documint-leaf-menu-divider",Q),role:"separator"})}if($.type!==LJ)return null;let{disabled:J=!1,icon:Z,text:X,value:Y}=$.props;return j3("button",{className:"documint-leaf-menu-item",disabled:J,onPointerDown:(Q)=>{if(T3(Q),!J&&O3(Q))M(Y)},role:"menuitem",type:"button",children:[A0(Z,{size:15,strokeWidth:2.2}),A0("span",{children:X})]})}function C4(...$){return $.filter(Boolean).join(" ")}function wJ({children:$}){return A0("div",{className:"documint-leaf-toolbar-group",children:$})}function TJ($){return null}function OJ($){return null}function jJ($){return null}function LJ($){return null}function CJ($){return null}var r=Object.assign(MV,{Button:TJ,Divider:OJ,Menu:jJ,MenuDivider:CJ,MenuItem:LJ});import{jsx as n,jsxs as l0,Fragment as AV}from"react/jsx-runtime";var KV=!1,DV=220,f1=()=>{};function L3($){let M=$.mode==="create",J=$.mode==="create"?$:null,Z=$.mode==="thread"?$:null,X=$.canEdit,Y=$.link,Q=Z?.thread??null,K=Q?.comments??[],q=K[0]??null,D=Q?J1(Q):!1,A=Z?.animateInitialComment??!1,[V,U]=R1(null),[G,_]=R1(""),[N,H]=R1(""),[E,L]=R1(""),[W,R]=R1(!A),[f,I]=R1(KV),[B,b]=R1(!1),z=RJ(null),T=RJ(null),P=$.mentionSources,y=Q?k8(Q):null,F=y?fJ(y):"",C=X&&!D,v=C&&G.trim().length>0,h=C&&N.trim().length>0,g=X&&E.trim().length>0,O=M||B,w=!M||f,m=!M&&Boolean(Q),S=Boolean(q),c=M?f:!0,l=Z?.onDeleteComment??f1,F0=Z?.onDeleteThread??f1,x0=Z?.onToggleResolved??f1,f0=J?.activeMarks??[],m0=J?.onToggleBold??f1,c0=J?.onToggleItalic??f1,K8=J?.onToggleStrikethrough??f1,D8=J?.onToggleUnderline??f1,h4=X?M?"Add a comment":"Reply to this comment":"Comment editing is disabled",q8=M?E:N;t5(()=>{if(V!==null&&(V<0||V>=K.length))U(null),_("")},[K.length,V]),t5(()=>{if(!S||!A){R(!0);return}R(!1);let a=requestAnimationFrame(()=>{R(!0)});return()=>{cancelAnimationFrame(a)}},[A,q,S]),t5(()=>{if(!Z||!A){b(!1);return}b(!0);let a=window.setTimeout(()=>{b(!1)},DV);return()=>{window.clearTimeout(a)}},[A,Z]),t5(()=>{if(!M||!f||!X)return;let a=requestAnimationFrame(()=>{T.current?.focus()});return()=>{cancelAnimationFrame(a)}},[X,M,f]);let W2=()=>{U(null),_("")},g4=(a,I4)=>{if(!m||!C)return;U(a),_(I4)},S0=(a)=>{if(!Z)return;Z.onEditComment(a,G),W2()},B0=()=>{if(!Z)return;Z.onReply(N),H("")},k1=()=>{if(!J||!g)return;J.onCreateThread(E),L("")},A8=O?`documint-comment-leaf documint-comment-leaf-create${c?" is-expanded":""}`:"documint-comment-leaf",u1=m||S||w?n(qV,{canCreate:g,canEdit:X,canMutateThread:C,canReply:h,canSaveEditedComment:v,comments:K,composerRef:T,editDraft:G,editingCommentIndex:V,isComposerVisible:w,isInitialCommentVisible:W,isResolved:D,link:Y,mentionSources:P,mode:$.mode,onBeginEditingComment:g4,onCancelEditing:W2,onChangeCreateDraft:L,onChangeEditDraft:_,onChangeReplyDraft:H,onDeleteComment:l,onDeleteThread:F0,onSubmitCreate:k1,onSubmitEditedComment:S0,onSubmitReply:B0,onToggleResolved:x0,rootComment:q,showRootComment:S,showThreadChrome:m,threadAge:F,composerPlaceholder:h4,composerValue:q8}):null;return n("div",{className:A8,ref:z,children:l0("div",{className:O?"documint-comment-leaf-create-shell":void 0,children:[O?l0(r,{children:[n(r.Button,{className:"documint-comment-leaf-create-button",icon:E4,label:"Add comment",onClick:()=>I(!0)}),n(r.Divider,{className:"documint-comment-leaf-create-divider"}),n(r.Button,{active:f0.includes("bold"),className:"documint-comment-leaf-create-mark",icon:Q4,label:"Bold",onClick:m0}),n(r.Button,{active:f0.includes("italic"),className:"documint-comment-leaf-create-mark",icon:_4,label:"Italic",onClick:c0}),n(r.Button,{active:f0.includes("underline"),className:"documint-comment-leaf-create-mark",icon:P4,label:"Underline",onClick:D8}),n(r.Button,{active:f0.includes("strikethrough"),className:"documint-comment-leaf-create-mark",icon:W4,label:"Strikethrough",onClick:K8})]}):null,n("div",{className:O?"documint-comment-leaf-create-content":void 0,children:u1})]})})}function qV({canCreate:$,canEdit:M,canMutateThread:J,canReply:Z,canSaveEditedComment:X,comments:Y,composerRef:Q,editDraft:K,editingCommentIndex:q,isComposerVisible:D,isInitialCommentVisible:A,isResolved:V,link:U,mentionSources:G,mode:_,onBeginEditingComment:N,onCancelEditing:H,onChangeCreateDraft:E,onChangeEditDraft:L,onChangeReplyDraft:W,onDeleteComment:R,onDeleteThread:f,onSubmitCreate:I,onSubmitEditedComment:B,onSubmitReply:b,onToggleResolved:z,rootComment:T,showRootComment:P,showThreadChrome:y,threadAge:F,composerPlaceholder:C,composerValue:v}){return l0(AV,{children:[y?l0("div",{className:"documint-comment-leaf-header",children:[n("span",{className:"documint-comment-leaf-age",children:F}),l0("div",{className:"documint-comment-leaf-actions",children:[n("button",{className:"documint-leaf-action","aria-label":V?"Reopen comment":"Resolve comment",disabled:!M,onClick:z,title:V?"Reopen comment":"Resolve comment",type:"button",children:n(L1,{size:14,strokeWidth:2.2})}),n("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Delete comment thread",disabled:!M,onClick:f,title:"Delete comment thread",type:"button",children:n(w0,{size:14,strokeWidth:2.2})})]})]}):null,y&&U?l0("div",{className:"documint-comment-leaf-link",children:[U.title?n("div",{className:"documint-link-leaf-title",children:U.title}):null,n("div",{className:"documint-link-leaf-url",children:U.url})]}):null,l0("div",{className:`documint-comment-thread${P?"":" is-empty"}`,children:[n("article",{className:P?`documint-comment-message documint-comment-message-root${A?" is-visible":""}`:"documint-comment-message documint-comment-message-root is-hidden",children:T?n(w3,{completionSources:G,onEdit:()=>N(0,T.body),value:T.body}):null}),Y.slice(1).map((h,g)=>{let O=g+1,w=q===O;return l0("article",{className:"documint-comment-message",children:[!w?l0("div",{className:"documint-comment-message-meta",children:[n("span",{children:fJ(h.updatedAt)}),J?l0("div",{className:"documint-comment-leaf-actions",children:[n("button",{className:"documint-leaf-action","aria-label":"Edit comment",disabled:!J,onClick:()=>{N(O,h.body)},title:"Edit comment",type:"button",children:n(C1,{size:14,strokeWidth:2.2})}),n("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Delete comment",disabled:!J,onClick:()=>R(O),title:"Delete comment",type:"button",children:n(w0,{size:14,strokeWidth:2.2})})]}):null]}):null,w?n(L4,{actions:{kind:"edit",onCancel:H,onSave:()=>B(O),saveDisabled:!X},completionSources:G,onChange:L,readOnly:!M,rows:3,value:K}):n(w3,{completionSources:G,onEdit:()=>N(O,h.body),value:h.body})]},`${h.updatedAt}:${O}`)})]}),n("div",{className:`documint-comment-reply${y?"":" is-standalone"}${D?" is-visible":""}`,children:n(L4,{actions:_==="create"?{kind:"compose",onSubmit:I,submitDisabled:!$,submitLabel:"Create comment"}:{kind:"compose",onSubmit:b,submitDisabled:!Z,submitLabel:"Reply"},completionSources:G,onChange:_==="create"?E:W,placeholder:C,readOnly:!M,ref:Q,rows:3,value:v})})]})}function fJ($){let M=new Date($);if(Number.isNaN(M.getTime()))return $;let J=M.getTime()-Date.now(),Z=60000,X=60*Z,Y=24*X,Q=7*Y,K=30*Y,q=365*Y,D=new Intl.RelativeTimeFormat(void 0,{numeric:"auto"});if(Math.abs(J)<Z)return"just now";if(Math.abs(J)<X)return D.format(Math.round(J/Z),"minute");if(Math.abs(J)<Y)return D.format(Math.round(J/X),"hour");if(Math.abs(J)<Q)return D.format(Math.round(J/Y),"day");if(Math.abs(J)<q)return D.format(Math.round(J/K),"month");return D.format(Math.round(J/q),"year")}import{jsx as d0,jsxs as GV}from"react/jsx-runtime";var UV=[{icon:D4,label:"Heading 1",text:"# "},{icon:q4,label:"Heading 2",text:"## "},{icon:A4,label:"Heading 3",text:"### "},{icon:U4,label:"Heading 4",text:"#### "},{icon:V4,label:"Heading 5",text:"##### "},{icon:G4,label:"Heading 6",text:"###### "}],VV=[{columns:2,text:"2 columns"},{columns:3,text:"3 columns"},{columns:4,text:"4 columns"},{columns:5,text:"5 columns"}];function mJ({onInsert:$,onInsertTable:M}){return GV(r,{children:[d0(r.Button,{icon:z4,label:"Insert bulleted list",onClick:()=>$("- ")}),d0(r.Button,{icon:F4,label:"Insert numbered list",onClick:()=>$("1. ")}),d0(r.Button,{icon:H4,label:"Insert task list",onClick:()=>$("- [ ] ")}),d0(r.Divider,{}),d0(r.Menu,{icon:N4,label:"Insert heading",onSelect:$,children:UV.map(({icon:J,label:Z,text:X})=>d0(r.MenuItem,{icon:J,text:Z,value:X},X))}),d0(r.Menu,{icon:V1,label:"Insert table",onSelect:(J)=>M(Number(J)),children:VV.map(({columns:J,text:Z})=>d0(r.MenuItem,{icon:V1,text:Z,value:String(J)},J))}),d0(r.Divider,{}),d0(r.Button,{icon:B4,label:"Insert blockquote",onClick:()=>$("> ")})]})}import{jsx as C3,jsxs as NV}from"react/jsx-runtime";function SJ({anchor:$,children:M,status:J="default"}){let Z=!$.isSelection;return C3(n5,{children:NV("div",{className:"documint-leaf-anchor","data-selection":$.isSelection?"true":"false",onPointerEnter:$.onPointerEnter,onPointerLeave:$.onPointerLeave,style:{left:`${$.left}px`,top:`${$.top}px`},children:[Z?C3("div",{className:"documint-leaf-bridge"}):null,C3("div",{className:"documint-leaf-shell","data-status":J,children:M})]})})}import{useEffect as kJ,useRef as _V,useState as uJ}from"react";import{jsx as n0,jsxs as R3}from"react/jsx-runtime";function vJ({canEdit:$,onDelete:M,onSave:J,title:Z,url:X}){let[Y,Q]=uJ(X),[K,q]=uJ(!1),D=_V(null),A=FV(),V=Y.trim(),U=$&&V.length>0,G=$&&!K,_=`${A}click to open`,N=`documint-link-leaf-row${K?" is-editing":""}`;return kJ(()=>{if(K)return;Q(X)},[K,X]),kJ(()=>{if(!K)return;D.current?.focus()},[K]),R3("div",{className:"documint-link-leaf",children:[Z?n0("div",{className:"documint-link-leaf-title",children:Z}):null,R3("div",{className:N,children:[K?n0(L4,{actions:{kind:"edit",onCancel:()=>{Q(X),q(!1)},onSave:()=>{J(V),q(!1)},saveDisabled:!U},onChange:Q,readOnly:!$,ref:D,rows:3,value:Y}):n0("div",{className:"documint-link-leaf-url",children:X}),G?R3("div",{className:"documint-link-leaf-actions",children:[n0("button",{className:"documint-leaf-action","aria-label":"Edit link",onClick:()=>{if(!$)return;Q(X),q(!0)},title:"Edit link",type:"button",children:n0(C1,{size:14,strokeWidth:2.2})}),n0("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Remove link",onClick:M,title:"Remove link",type:"button",children:n0(w0,{size:14,strokeWidth:2.2})})]}):null]}),n0("div",{className:"documint-link-leaf-divider"}),n0("div",{className:"documint-link-leaf-hint",children:_})]})}function FV(){if(typeof navigator>"u")return"Ctrl+";let $=navigator.platform||navigator.userAgent;return/Mac|iPhone|iPad|iPod/.test($)?"CMD+":"CTRL+"}import{jsx as t0,jsxs as S3}from"react/jsx-runtime";var HV=[{text:"Column left",value:"left"},{text:"Column right",value:"right"}],zV=[{text:"Row above",value:"above"},{text:"Row below",value:"below"}],f3={text:"Delete column",value:"delete"},m3={text:"Delete row",value:"delete"},hJ={text:"Delete table",value:"delete"};function gJ({canDeleteColumn:$,canDeleteRow:M,onDeleteColumn:J,onDeleteRow:Z,onDeleteTable:X,onInsertColumn:Y,onInsertRow:Q}){return S3(r,{children:[S3(r.Menu,{icon:q1,label:"Column actions",onSelect:(K)=>{if(K===f3.value){J();return}Y(K)},children:[HV.map(({text:K,value:q})=>t0(r.MenuItem,{icon:U2,text:K,value:q},q)),t0(r.MenuDivider,{}),t0(r.MenuItem,{disabled:!$,icon:w0,text:f3.text,value:f3.value})]}),S3(r.Menu,{icon:A1,label:"Row actions",onSelect:(K)=>{if(K===m3.value){Z();return}Q(K)},children:[zV.map(({text:K,value:q})=>t0(r.MenuItem,{icon:U2,text:K,value:q},q)),t0(r.MenuDivider,{}),t0(r.MenuItem,{disabled:!M,icon:w0,text:m3.text,value:m3.value})]}),t0(r.Divider,{}),t0(r.Menu,{icon:V1,label:"Table actions",onSelect:()=>X(),children:t0(r.MenuItem,{icon:w0,text:hJ.text,value:hJ.value})})]})}import{useEffect as IJ,useEffectEvent as pJ,useLayoutEffect as lJ,useMemo as EV,useRef as k3,useState as dJ}from"react";function e5($,M){if(!$||$.kind==="task-toggle")return null;if($.commentThreadIndex!==null){let J=M[$.commentThreadIndex]??null;if(!J)return null;return{kind:"comment",left:$.anchorLeft,link:$.kind==="link"?{title:$.title,url:$.url}:null,thread:J,threadIndex:$.commentThreadIndex,top:$.anchorBottom}}if($.kind!=="link")return null;return{endOffset:$.endOffset,kind:"link",left:$.anchorLeft,regionId:$.regionId,startOffset:$.startOffset,title:$.title,top:$.anchorBottom,url:$.url}}var WV=600,BV=530,H2=24;function xJ({canShowInsertionLeaf:$,canShowTableLeaf:M,commentState:J,editorState:Z,editorViewportState:X,getScrollTop:Y,layoutWidth:Q,onVisibilityChange:K,resources:q,scrollContentHeight:D,scrollTo:A,viewportHeight:V}){let U=EV(()=>Y0(Z),[Z]),[G,_]=dJ(null),[N,H]=dJ(null),E=U.start.regionId===U.end.regionId&&U.start.offset===U.end.offset,L=k3(!0),W=k3(0),R=k3(null),f=pJ(()=>{K()}),I=pJ(()=>{W.current=typeof performance<"u"?performance.now():Date.now(),L.current=!0,f()});return lJ(()=>{let B=PV({canShowInsertionLeaf:$,canShowTableLeaf:M,commentState:J,normalizedSelection:U,state:Z,viewport:X.get()});_((b)=>TV(b,B)?b:B)},[$,M,J,Z,X]),lJ(()=>{let B=q?jV(Z,X.get(),U,q):null;H((b)=>LV(b,B)?b:B)},[Z,X,U,q]),IJ(()=>{let B=Z.selection.focus,b={layoutWidth:Q,offset:B.offset,regionId:B.regionId,scrollContentHeight:D,viewportHeight:V};if(OV(R.current,b))return;let z=A6(Z,X.get(),B);if(!z)return;let T=Y(),P=T+H2,y=T+V-H2;if(z.top<P){let F=A(Math.max(0,z.top-H2));if(rJ(z,F,V,H2))R.current=b;return}if(z.top+z.height>y){let F=A(Math.max(0,z.top+z.height-V+H2));if(rJ(z,F,V,H2))R.current=b;return}R.current=b},[Z,Z.selection.focus.offset,Z.selection.focus.regionId,X,Q,D,A,V]),IJ(()=>{if(L.current=!0,f(),!E||typeof window>"u")return;let B=window.setInterval(()=>{if((typeof performance<"u"?performance.now():Date.now())-W.current<WV){if(!L.current)L.current=!0,f();return}L.current=!L.current,f()},BV);return()=>{window.clearInterval(B)}},[E]),{imageAtCursor:N,leaf:G,isVisible:()=>L.current,markActivity:I}}function PV({canShowInsertionLeaf:$,canShowTableLeaf:M,commentState:J,normalizedSelection:Z,state:X,viewport:Y}){if(!Y)return null;let Q=X.selection.focus;if(Z.start.regionId!==Z.end.regionId||Z.start.offset!==Z.end.offset)return null;let K=$?wV(X,Y):null;if(K)return K;let q=M?yV(X,Y):null;if(q)return q;return e5(q6(X,Y,Q,J.liveRanges),J.threads)}function yV($,M){let J=$.selection.focus,Z=$.documentIndex.regionIndex.get(J.regionId),X=Z?$.documentIndex.tableCellIndex.get(Z.id)??null:null;if(!Z||!X)return null;let Y=$.documentIndex.blockIndex.get(Z.blockId),Q=Y?.type==="table"?$.documentIndex.document.blocks[Y.rootIndex]:null;if(!Y||!Q||Q.type!=="table")return null;let K=o0($,M,J),q=bV(M,Z.id),D=Math.max(1,...Q.rows.map((A)=>A.cells.length));return K&&q!==null?{cellIndex:X.cellIndex,columnCount:D,kind:"table",left:q,rowCount:Q.rows.length,rowIndex:X.rowIndex,top:K.top+K.height}:null}function bV($,M){let J=$.layout.lines.find((Z)=>Z.regionId===M);return J?J.left:null}function wV($,M){let J=$.selection.focus,Z=$.documentIndex.regionIndex.get(J.regionId);if(!Z||Z.blockType!=="paragraph"||Z.text.length>0)return null;if(J.offset!==0)return null;let X=$.documentIndex.blockIndex.get(Z.blockId);if(!X||X.parentBlockId!==null)return null;let Y=o0($,M,J);return Y?{kind:"insertion",left:Y.left,top:Y.top+Y.height}:null}function TV($,M){if($===M)return!0;if(!$||!M||$.kind!==M.kind)return!1;switch($.kind){case"comment":return M.kind==="comment"&&$.left===M.left&&$.link?.title===M.link?.title&&$.link?.url===M.link?.url&&$.thread===M.thread&&$.threadIndex===M.threadIndex&&$.top===M.top;case"insertion":return M.kind==="insertion"&&$.left===M.left&&$.top===M.top;case"link":return M.kind==="link"&&$.endOffset===M.endOffset&&$.left===M.left&&$.regionId===M.regionId&&$.startOffset===M.startOffset&&$.title===M.title&&$.top===M.top&&$.url===M.url;case"table":return M.kind==="table"&&$.cellIndex===M.cellIndex&&$.columnCount===M.columnCount&&$.left===M.left&&$.rowCount===M.rowCount&&$.rowIndex===M.rowIndex&&$.top===M.top}}function OV($,M){return $?.layoutWidth===M.layoutWidth&&$.regionId===M.regionId&&$.offset===M.offset&&$.scrollContentHeight===M.scrollContentHeight&&$.viewportHeight===M.viewportHeight}function rJ($,M,J,Z){return $.top>=M+Z&&$.top+$.height<=M+J-Z}function jV($,M,J,Z){if(!M)return null;if(J.start.regionId!==J.end.regionId||J.start.offset!==J.end.offset)return null;let X=B5($);if(!X)return null;let Y=J5($,M,Z,X),Q=X.image?Z.images.get(X.image.url)?.intrinsicWidth??null:null,K=$.selection.anchor.regionId;return Y?{bounds:Y,maxWidth:Q,regionId:K,run:X}:null}function LV($,M){if($===M)return!0;if(!$||!M)return!1;return $.regionId===M.regionId&&$.maxWidth===M.maxWidth&&$.bounds.left===M.bounds.left&&$.bounds.top===M.bounds.top&&$.bounds.width===M.bounds.width&&$.bounds.height===M.bounds.height}import{useMemo as u3,useRef as R4,useEffectEvent as v3}from"react";var CV=48;function cJ($,M,J){let Z=R4(null),X=R4(null),Y=R4(null),Q=R4(null),K=R4(1),q=v3((G,_)=>{if(!$)return;G.preventDefault(),G.stopPropagation(),G.currentTarget.setPointerCapture(G.pointerId),Q.current=G.pointerId,Z.current=G.clientX,X.current=G.clientY,Y.current=$.run.image?.width??$.bounds.width,K.current=_}),D=v3((G)=>{if(Q.current!==G.pointerId||Z.current===null||X.current===null||Y.current===null||!$?.run.image)return;let _=G.clientX-Z.current,N=G.clientY-X.current,H=Math.min($.maxWidth??1/0,Math.max(CV,Math.round(Y.current+K.current*(_+N)))),E=o7(M,$.regionId,$.run,H);if(E)J(E)}),A=v3((G)=>{if(G.currentTarget.hasPointerCapture(G.pointerId))G.currentTarget.releasePointerCapture(G.pointerId);Q.current=null,Z.current=null,X.current=null,Y.current=null}),V=u3(()=>({onPointerDown:(G)=>q(G,-1),onPointerMove:D,onPointerUp:A,onPointerCancel:A}),[]),U=u3(()=>({onPointerDown:(G)=>q(G,1),onPointerMove:D,onPointerUp:A,onPointerCancel:A}),[]);return u3(()=>{if(!$)return null;let{bounds:G}=$;return{start:{left:G.left,top:G.top,props:V},end:{left:G.left+G.width,top:G.top+G.height,props:U}}},[$])}import{useEffect as aJ,useEffectEvent as sJ,useMemo as iJ,useRef as RV,useState as fV}from"react";function oJ($,M){let[J,Z]=fV(new Map),X=sJ((q)=>{if(typeof Image>"u")return;let D=[...J.keys()].filter((A)=>!q.has(A));if(D.length>0)Z((A)=>{let V=new Map(A);for(let U of D)V.delete(U);return V});for(let A of q){let V=J.get(A)?.status;if(V==="loaded"||V==="loading")continue;Z((U)=>h3(U,A,f4("loading"))),mV(A,M).then((U)=>{Z((G)=>{if(!G.has(A))return U?.close(),G;return h3(G,A,U?f4("loaded",U):f4("error"))})})}});aJ(()=>{X($)},[$]);let Y=RV(new Map);aJ(()=>{for(let[q,D]of Y.current)if(!J.has(q))D.source?.close();Y.current=J},[J]);let Q=sJ(async(q)=>{if(!M?.writeFile)return null;try{let D=await M.writeFile(q),A=await createImageBitmap(q).catch(()=>null);return Z((V)=>h3(V,D,A?f4("loaded",A):f4("error"))),D}catch{return null}}),K=iJ(()=>J.size===0?null:{images:J},[J]);return iJ(()=>({resources:K,persistImage:Q}),[K,Q])}async function mV($,M){if(/^(https?:|data:|blob:)/i.test($))return SV($);if(!M?.readFile)return null;try{let J=await M.readFile($);return J?await createImageBitmap(J):null}catch{return null}}function SV($){return new Promise((M)=>{let J=new Image;J.decoding="async",J.crossOrigin="anonymous",J.onload=async()=>{try{M(await createImageBitmap(J))}catch{M(null)}},J.onerror=()=>M(null),J.src=$})}function h3($,M,J){let Z=new Map($);return Z.set(M,J),Z}function f4($,M){return{intrinsicHeight:M?.height??0,intrinsicWidth:M?.width??0,source:M??null,status:$}}import{useEffect as nJ,useEffectEvent as _0,useRef as m4,useState as kV}from"react";var uV=48;function tJ({applyNextState:$,autoScrollDuringDrag:M,canvasRef:J,commentState:Z,editorStateRef:X,editorViewportState:Y,focusInput:Q,onActivity:K,readCurrentState:q,resolvePoint:D}){let[A,V]=kV(null),U=m4(null),G=m4(!1),_=m4(null),N=m4(null),H=m4(null),E=e5(A,Z.threads),L=A?.kind==="task-toggle"||E?.kind==="link"?"pointer":"text";nJ(()=>{if(A&&A.kind!=="task-toggle"&&!E)V(null)},[A,E]),nJ(()=>()=>{if(U.current!==null)window.clearTimeout(U.current)},[]);let W=_0(()=>{if(U.current!==null)window.clearTimeout(U.current),U.current=null}),R=_0(()=>{W(),U.current=window.setTimeout(()=>{if(U.current=null,!G.current)V(null)},uV)}),f=_0(()=>{if(!G.current)W(),V(null)}),I=_0((O)=>{if(!O){f();return}if(O.kind==="task-toggle"){W(),V((w)=>w?.kind==="task-toggle"&&w.listItemId===O.listItemId?w:O);return}if(O.commentThreadIndex!==null){if(!(Z.threads[O.commentThreadIndex]??null)){f();return}W();let m=O.commentThreadIndex;V((S)=>S?.kind!=="task-toggle"&&S?.commentThreadIndex===m?S:O);return}if(O.kind!=="link"){f();return}W(),V((w)=>w?.kind==="link"&&w.title===O.title&&w.url===O.url&&w.startOffset===O.startOffset&&w.endOffset===O.endOffset?w:O)}),B=_0((O)=>{let w=X.current;if(!w)return null;let m=D(O);if(!m)return null;return D6(w,Y.get(),m,Z.liveRanges)}),b=_0((O)=>{let w=J.current;if(w&&_.current===O)w.releasePointerCapture(O)}),z=_0(()=>{_.current=null,N.current=null}),T=_0((O)=>{b(O.pointerId),z()}),P=_0((O)=>{if(H.current=O.pointerType,O.pointerType==="touch")return;let w=J.current,m=q(),S=D(O);if(!S)return;if(B(O)?.kind==="task-toggle")return;let l=N5(m,Y.get(),S);if(!w||!l)return;if(_.current=O.pointerId,K(),w.setPointerCapture(O.pointerId),O.shiftKey)N.current=m.selection.anchor,$(m7(m,l.regionId,l.offset));else N.current={offset:l.offset,regionId:l.regionId},$(X0(m,{offset:l.offset,regionId:l.regionId}));Q({offset:l.offset,regionId:l.regionId})}),y=_0((O)=>{let w=N.current,m=q(),S=D(O);if(!S)return;if(_.current!==O.pointerId||!w){I(B(O));return}let c=m2(m,Y.get(),S,w);if(!c)return;K(),M(O),$(X0(m,{anchor:w,focus:c}))}),F=_0(()=>{if(!G.current)R()}),C=_0((O)=>{let w=H.current==="touch";H.current=null;let m=B(O);if(m?.kind==="task-toggle"){let F0=q(),x0=g7(F0,m.listItemId);if(x0)O.preventDefault(),O.stopPropagation(),K(),$(x0);return}if(m?.kind==="link"&&(O.metaKey||O.ctrlKey)){O.preventDefault(),O.stopPropagation(),O.currentTarget.ownerDocument.defaultView?.open(m.url,"_blank","noopener,noreferrer");return}if(!w){Q();return}let S=q(),c=D(O),l=c?N5(S,Y.get(),c):null;if(l)K(),$(X0(S,{offset:l.offset,regionId:l.regionId})),Q({offset:l.offset,regionId:l.regionId});else Q()}),v=_0((O)=>{let w=q(),m=D(O),S=B(O);if(!m||S?.kind==="task-toggle")return;let c=K6(w,Y.get(),m);if(!c)return;O.preventDefault(),O.stopPropagation(),K(),$(X0(w,c)),Q()}),h=_0(()=>{G.current=!0,W()}),g=_0(()=>{G.current=!1,R()});return{canvasHandlers:{onClick:C,onDoubleClick:v,onPointerCancel:T,onPointerDown:P,onPointerLeave:F,onPointerMove:y,onPointerUp:T},cursor:L,leaf:E,leafHandlers:{onPointerEnter:h,onPointerLeave:g}}}import{useEffect as l3,useEffectEvent as U0,useLayoutEffect as hV,useRef as YZ,useState as gV}from"react";import{useEffect as jC1}from"react";var g3=[{key:"Backspace",command:"deleteBackward"},{key:"Enter",command:"insertLineBreak"},{key:"Home",command:"moveToLineStart"},{key:"End",command:"moveToLineEnd"},{key:"Tab",command:"indent"},{key:"Tab",shiftKey:!0,command:"dedent"},{key:"ArrowLeft",modKey:!0,shiftKey:"any",command:"moveToLineStart"},{key:"ArrowRight",modKey:!0,shiftKey:"any",command:"moveToLineEnd"},{key:"ArrowUp",modKey:!0,shiftKey:"any",command:"moveToDocumentStart"},{key:"ArrowDown",modKey:!0,shiftKey:"any",command:"moveToDocumentEnd"},{key:"ArrowUp",altKey:!0,shiftKey:!0,command:"moveListItemUp"},{key:"ArrowDown",altKey:!0,shiftKey:!0,command:"moveListItemDown"},{key:"a",modKey:!0,command:"selectAll"},{key:"b",modKey:!0,command:"toggleBold"},{key:"e",modKey:!0,command:"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 eJ($,M=g3){return M.find((J)=>{let Z=J.shiftKey==="any"?!0:(J.shiftKey??!1)===($.shiftKey??!1);return J.key.toLowerCase()===$.key.toLowerCase()&&(J.altKey??!1)===($.altKey??!1)&&Z&&(J.modKey??!1)===Boolean($.metaKey||$.ctrlKey)})?.command??null}function ZZ($){let M=$.documentIndex.regions.find((Y)=>Y.id===$.selection.anchor.regionId),J=$.documentIndex.regions.find((Y)=>Y.id===$.selection.focus.regionId),Z=(M?.start??0)+$.selection.anchor.offset,X=(J?.start??0)+$.selection.focus.offset;return{end:Math.max(Z,X),start:Math.min(Z,X)}}function I3($){let M=p3($);if(!M)return"";let J=$.documentIndex.regions.find((Z)=>Z.id===M.regionId);if(!J)return"";return J.text.slice(M.startOffset,M.endOffset)}function p3($){let M=vV($);if(M.start.regionId!==M.end.regionId||M.start.offset===M.end.offset)return null;return{endOffset:M.end.offset,regionId:M.start.regionId,startOffset:M.start.offset}}var $Z=28,MZ=18;function XZ($,M){if(!$)return;let J=$.getBoundingClientRect();if(M.clientY<J.top+$Z){$.scrollTop=Math.max(0,$.scrollTop-MZ);return}if(M.clientY>J.bottom-$Z)$.scrollTop+=MZ}function vV($){let M=JZ($.documentIndex.regions,$.selection.anchor.regionId,$.selection.anchor.offset),J=JZ($.documentIndex.regions,$.selection.focus.regionId,$.selection.focus.offset);return M<=J?{end:$.selection.focus,start:$.selection.anchor}:{end:$.selection.anchor,start:$.selection.focus}}function JZ($,M,J){let Z=$.findIndex((X)=>X.id===M);if(Z===-1)return-1;return Z*1e6+J}var IV=1024,QZ=16;function qZ({applyNextState:$,editorState:M,editorStateRef:J,editorViewportState:Z,inputRef:X,keybindings:Y,onActivity:Q,onImagePaste:K}){let q=pV(),D=()=>J.current??M,A=YZ(!1),V=YZ(!1),U=U0((F)=>{if(!F)return;Q(),$(F)}),G=U0(()=>{let F=X.current;if(!F)return;if(typeof document>"u")return;let C=document.execCommand;if(typeof C!=="function")return;try{A.current=!0,C.call(document,"insertText",!1,""),C.call(document,"delete")}catch{}finally{A.current=!1,S4(F,D())}}),_=U0(()=>{if(V.current)return;V.current=!0,G()}),N=U0(()=>{G()}),H=U0((F)=>{if(!q)return;let C=X.current;if(!C)return;let v=Z.get(),h=o0(D(),v,F);if(!h)return;C.style.top=`${h.top}px`,C.style.left=`${h.left}px`,C.style.height=`${h.height}px`}),E=U0((F)=>{let C=X.current;if(!C)return;H(F??D().selection.focus),C.focus({preventScroll:!q}),S4(C,D()),_()}),L=U0((F,C)=>{let h=DZ(C,$8(F)).replace(/\r\n/g,`
|
|
31
|
-
`).split(/(\n)/),g=F;for(let
|
|
32
|
-
`?f5(g):M4(g,O);if(!w)continue;g=w}return g===F?null:g}),W=U0((F,C,v)=>{let h=F.selection.focus,g={regionId:h.regionId,offset:Math.max(0,h.offset-C)},O=X0(F,{anchor:g,focus:h});return m5(O,v)}),R=U0((F)=>{if(A.current)return;let C=D(),v=rV(F.inputType);if(F.inputType==="insertText"){if(!F.data)return;F.preventDefault();let h=KZ(F.target);if(h>0){U(W(C,h,F.data));return}let g=dV(C,F.data);if(g>0){let O=F.data.slice(g);if(O.length>0)U(L(C,O));return}U(L(C,F.data));return}if(F.inputType==="insertReplacementText"){if(!F.data)return;F.preventDefault();let h=KZ(F.target);U(W(C,h,F.data));return}if(lV(F.inputType)){F.preventDefault(),U(f5(C));return}if(v==="backward"){F.preventDefault(),U(c6(C));return}if(v==="forward"){F.preventDefault(),U(a6(C));return}if(F.inputType==="historyUndo"){F.preventDefault(),U(s6(C)),N();return}if(F.inputType==="historyRedo"){F.preventDefault(),U(i6(C)),N();return}}),f=U0((F)=>{let C=D(),v=F.currentTarget.value,h=$8(C);if(A.current)return;if(DZ(v,h).length===0){S4(F.currentTarget,C);return}U(L(C,v))}),I=U0((F)=>{let C=cV(D(),Z.get(),F.nativeEvent,Y);if(!C)return;F.preventDefault(),U(C)}),B=U0((F)=>{let C=I3(D());if(!C)return;F.preventDefault(),F.clipboardData.setData("text/plain",C)}),b=U0((F)=>{let C=D(),v=I3(C);if(!v)return;F.preventDefault(),F.clipboardData.setData("text/plain",v),U(S5(C))}),z=U0(async(F)=>{let v=(K?[...F.clipboardData.items].find((g)=>g.kind==="file"&&g.type.startsWith("image/")):void 0)?.getAsFile()??null;if(v&&K){F.preventDefault();let g=await K(v);if(g)U(i7(D(),g));return}let h=F.clipboardData.getData("text/plain");if(h.length===0)return;F.preventDefault(),U(m5(D(),h))}),T=U0(()=>{Q();let F=X.current;if(F)S4(F,D())}),P=U0((F)=>{if(Q(),F.target.matches(":focus-visible"))E()});l3(()=>{let F=X.current;if(!F)return;S4(F,M)},[M,X]),hV(()=>{H(M.selection.focus)},[M,H]),l3(()=>{let F=X.current;if(!F)return;let C=(v)=>R(v);return F.addEventListener("beforeinput",C),()=>F.removeEventListener("beforeinput",C)},[X,R]);let y={onCopy:B,onCut:b,onPaste:z,...q?{}:{onKeyDown:I}};return{canvasHandlers:{...y,onFocus:P},focus:E,inputHandlers:{...y,onFocus:T,onInput:f}}}var AZ="";function pV(){let[$,M]=gV(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function")return!1;return window.matchMedia("(pointer: coarse)").matches});return l3(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function")return;let J=window.matchMedia("(pointer: coarse)"),Z=(X)=>M(X.matches);return J.addEventListener?.("change",Z),()=>J.removeEventListener?.("change",Z)},[]),$}function lV($){return $==="insertLineBreak"||$==="insertParagraph"}function KZ($){let M=$,J=M?.selectionStart??0,Z=M?.selectionEnd??J;return Math.max(0,Z-J)}function dV($,M){if(M.length<QZ)return 0;let J=$8($,M.length),Z=Math.min(J.length,M.length);for(let X=Z;X>=QZ;X--)if(J.endsWith(M.slice(0,X)))return X;return 0}function rV($){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 xV($){return $.replaceAll(AZ,"")}function $8($,M=IV){let{anchor:J,focus:Z}=$.selection;if(J.regionId!==Z.regionId||J.offset!==Z.offset)return"";let X=$.documentIndex.regionIndex.get(Z.regionId);if(!X)return"";return X.text.slice(Math.max(0,Z.offset-M),Z.offset)}function DZ($,M){let J=xV($);return J.startsWith(M)?J.slice(M.length):J}function S4($,M){let J=$8(M),Z=`${AZ}${J}`;$.value=Z,$.setSelectionRange(Z.length,Z.length)}function cV($,M,J,Z){if(J.key==="Delete")return a6($);let X=eJ(J,Z);if(X){if(X==="moveToLineStart"||X==="moveToLineEnd")return e6($,M.layout,X==="moveToLineStart"?"Home":"End",J.shiftKey);if(X==="moveToDocumentStart"||X==="moveToDocumentEnd")return $3($,X==="moveToDocumentStart"?"start":"end",J.shiftKey);switch(X){case"insertLineBreak":return f5($);case"deleteBackward":return c6($);case"indent":return k7($);case"dedent":return u7($);case"moveListItemUp":return v7($);case"moveListItemDown":return h7($);case"toggleBold":return k5($);case"toggleItalic":return u5($);case"toggleStrikethrough":return v5($);case"toggleUnderline":return h5($);case"toggleCode":return c7($);case"undo":return s6($);case"redo":return i6($);case"selectAll":return S7($)}}if(J.key==="ArrowLeft"||J.key==="ArrowRight")return o6($,J.key==="ArrowLeft"?-1:1,J.shiftKey);if(J.key==="ArrowUp"||J.key==="ArrowDown")return n6($,M.layout,J.key==="ArrowUp"?-1:1,J.shiftKey);if(J.key==="PageUp"||J.key==="PageDown")return t6($,M.layout,J.key==="PageUp"?-1:1,J.shiftKey);if(J.key.length===1&&!J.altKey&&!J.ctrlKey&&!J.metaKey)return M4($,J.key);return null}import{useEffectEvent as d3,useLayoutEffect as aV,useMemo as sV,useState as iV}from"react";function UZ({editorState:$,editorStateRef:M,editorViewportState:J,onViewportScroll:Z,scrollContainerRef:X,scheduleOverlayRender:Y,userPresence:Q}){let K=sV(()=>{if(!Q||Q.length===0)return;return F5($.documentIndex,Q)},[$.documentIndex,Q]),[q,D]=iV(void 0),A=d3(()=>{if(K===void 0){if(q!==void 0)D(void 0)}else D(S2(M.current??$,J.get(),K));Y()}),V=d3((G)=>{if(K===void 0){if(q!==void 0)D(void 0);return}let _=S2(M.current??$,G,K);if(oV(q,_))return;D(_)});aV(()=>{A()},[K]);let U=d3((G)=>{if(!G.viewport||G.viewport.status==="unresolved")return;let _=X.current;if(!_)return;_.scrollTop=G.viewport.scrollTop,Z(_)});return{presence:q,scrollToPresence:U,refreshPresence:V}}function oV($,M){if($===M)return!0;if($===void 0||M===void 0||$.length!==M.length)return!1;return $.every((J,Z)=>{let X=M[Z];return J.id===X.id&&nV(J.viewport,X.viewport)})}function nV($,M){if($===M)return!0;if($===null||M===null)return!1;if($.status==="unresolved")return M.status==="unresolved";if(M.status==="unresolved")return!1;return $.status===M.status&&$.scrollTop===M.scrollTop}import{useEffect as tV,useEffectEvent as m1,useRef as k4}from"react";function VZ({editorStateRef:$,renderContent:M,renderOverlay:J,renderViewport:Z}){let X=k4(null),Y=k4(!1),Q=k4(!1),K=k4(!1),q=k4(!1),D=m1(()=>{if(typeof window>"u"){Z();return}Y.current=!0,G()}),A=m1(()=>{if(typeof window>"u"){M(),J();return}Q.current=!0,G()}),V=m1(()=>{if(typeof window>"u"){M();return}K.current=!0,G()}),U=m1(()=>{if(typeof window>"u"){J();return}q.current=!0,G()}),G=m1(()=>{if(typeof window>"u"||X.current!==null)return;X.current=window.requestAnimationFrame(()=>{_()})}),_=m1(()=>{X.current=null;let H=Y.current,E=Q.current,L=K.current,W=q.current;if(Y.current=!1,Q.current=!1,K.current=!1,q.current=!1,H){Z(),N();return}if(E){M(),J(),N();return}if(L)M(),N();if(W)J()}),N=m1(()=>{let H=$.current;if(!H||!j6(H,performance.now()))return;K.current=!0,G()});return tV(()=>{return()=>{if(typeof window>"u"||X.current===null)return;window.cancelAnimationFrame(X.current),X.current=null}},[]),{scheduleContentPaint:V,scheduleFullPaint:A,scheduleFullRender:D,scheduleOverlayPaint:U}}import{useEffectEvent as r3,useLayoutEffect as GZ,useMemo as x3,useRef as c3,useState as NZ}from"react";function _Z({applyNextState:$,autoScrollDuringDrag:M,canShowSelectionLeaf:J,editorState:Z,editorStateRef:X,editorViewportState:Y,focusInput:Q,onActivity:K,resolvePoint:q,threads:D}){let A=x3(()=>Y0(Z),[Z]),V=x3(()=>p3(Z),[Z]),U=x3(()=>P5(Z),[Z]),[G,_]=NZ(null),[N,H]=NZ(null),E=c3(null),L=c3(null),W=c3(null);GZ(()=>{let z=eV(Z,Y.get(),A);_((T)=>XG(T,z)?T:z)},[Z,Y,A.end.offset,A.end.regionId,A.start.offset,A.start.regionId]),GZ(()=>{let z=MG({canShowSelectionLeaf:J,currentLeaf:N,activeMarks:U,handles:G,selectionRange:V,threads:D});H((T)=>ZG(T,z)?T:z)},[U,J,G,N,V,D]);let R=r3((z,T=!0)=>{H((P)=>P?.kind==="create"?{animateInitialComment:T,kind:"thread",left:P.left,threadIndex:z,top:P.top}:P)}),f=r3((z)=>{if(z&&W.current===z.pointerId&&z.currentTarget.hasPointerCapture(z.pointerId))z.currentTarget.releasePointerCapture(z.pointerId);E.current=null,L.current=null,W.current=null}),I=r3((z)=>{let T=X.current,P=L.current,y=q(z);if(!y||!T||!P||W.current!==z.pointerId)return;let F=m2(T,Y.get(),y,P);if(!F)return;z.preventDefault(),z.stopPropagation(),K(),M(z),$(X0(T,{anchor:P,focus:F}))}),B=(z)=>({onPointerCancel:(T)=>{f(T)},onPointerDown:(T)=>{let P=X.current??Z,y=QG(A,z),F=z==="start"?A.start:A.end;if(!G)return;T.preventDefault(),T.stopPropagation(),W.current=T.pointerId,L.current=y,E.current=z,T.currentTarget.setPointerCapture(T.pointerId),K(),Q(),$(X0(P,{anchor:y,focus:F}))},onPointerMove:(T)=>{if(E.current!==z)return;I(T)},onPointerUp:(T)=>{if(E.current===z)I(T);f(T)}});return{handle:G?{start:{...G.start,props:B("start")},end:{...G.end,props:B("end")}}:null,leaf:N,promoteLeafToThread:R}}function eV($,M,J){if(J.collapsed)return null;let Z=o0($,M,J.start),X=o0($,M,J.end);if(!Z||!X)return null;return{end:{left:X.left,top:X.top+X.height},start:{left:Z.left,top:Z.top}}}function $G($,M,J){return{activeMarks:J,kind:"create",left:M.start.left,selection:$,top:M.end.top}}function MG({activeMarks:$,canShowSelectionLeaf:M,currentLeaf:J,handles:Z,selectionRange:X,threads:Y}){if(!M||!X||!Z)return null;if(J?.kind==="thread")return Y[J.threadIndex]?J:null;return $G(X,Z,$)}function JG($,M){return $?.kind==="create"&&$.left===M.left&&$.selection.regionId===M.selection.regionId&&$.selection.startOffset===M.selection.startOffset&&$.selection.endOffset===M.selection.endOffset&&YG($.activeMarks,M.activeMarks)&&$.top===M.top}function ZG($,M){if($===M)return!0;if(!$||!M||$.kind!==M.kind)return!1;if($.kind==="create"&&M.kind==="create")return JG($,M);return $.kind==="thread"&&M.kind==="thread"&&$.animateInitialComment===M.animateInitialComment&&$.left===M.left&&$.threadIndex===M.threadIndex&&$.top===M.top}function XG($,M){if($===M)return!0;if(!$||!M)return!1;return $.start.left===M.start.left&&$.start.top===M.start.top&&$.end.left===M.end.left&&$.end.top===M.end.top}function YG($,M){return $.length===M.length&&$.every((J,Z)=>J===M[Z])}function QG($,M){return M==="start"?$.end:$.start}import{useEffect as KG,useMemo as zZ,useState as DG}from"react";var u4={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)"},v4={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)"},FZ={...u4,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)"},HZ={...v4,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 EZ($){let M=zZ(()=>AG($),[$]),[J,Z]=DG(M.light),X=zZ(()=>UG(J),[J]);return KG(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function"){Z(M.light);return}let Y=window.matchMedia("(prefers-color-scheme: dark)"),Q=()=>{Z(Y.matches?M.dark:M.light)};if(Q(),typeof Y.addEventListener==="function")return Y.addEventListener("change",Q),()=>{Y.removeEventListener("change",Q)};return Y.addListener(Q),()=>{Y.removeListener(Q)}},[M]),{theme:J,themeStyles:X}}function qG($){return"light"in $&&"dark"in $}function AG($){if(!$)return{dark:v4,light:u4};if(qG($))return $;return{dark:$,light:$}}function UG($){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 NG,useEffectEvent as r0,useRef as a3,useState as M8}from"react";import{useMemo as VG}from"react";function WZ($){return VG(()=>GG({current:null},$),[$])}function GG($,M){return{peek(){return $.current},get(){let J=$.current;if(J!==null)return J;let Z=M();return $.current=Z,Z},invalidate(){$.current=null}}}function BZ($,M){let J=M.getBoundingClientRect();return{x:$.clientX-J.left+M.scrollLeft,y:$.clientY-J.top+M.scrollTop}}function PZ({editorState:$,editorStateRef:M,renderResources:J,theme:Z}){let X=a3(B1()),Y=a3(null),Q=a3({height:240,top:0}),[K,q]=M8(0),[D,A]=M8(240),[V,U]=M8(0),[G,_]=M8(240),N=_G(K),H=r0(()=>{let y=M.current??$,F=Q.current;return Q6(y,{height:F.height,paddingX:Z.paddingX,paddingY:Z.paddingY,top:F.top,width:N},X.current,J)}),E=WZ(H),L=r0((y)=>{_((F)=>{let C=HG(y,Q.current.height);return F===C?F:C})}),W=r0((y)=>{Q.current={...Q.current,top:y},U((F)=>F===y?F:y),E.invalidate()}),R=r0((y)=>{let F=FG(y),C=F.top!==Q.current.top;if(Q.current=F,U((v)=>v===F.top?v:F.top),C)E.invalidate()}),f=r0((y)=>{let F=Y.current;if(!F)return W(y),y;F.scrollTop=y;let C=F.scrollTop;return W(C),C}),I=r0(()=>{return Y.current?.scrollTop??Q.current.top}),B=r0((y,F)=>{let C=y!==null&&y.documentIndex!==F.documentIndex,v=E.peek();if(!(!C||!v||v.layout.regionLineIndices.has(F.selection.focus.regionId)))E.invalidate()}),b=r0(()=>{return E.invalidate(),E.get()}),z=r0((y)=>{let F=Y.current;return F?BZ(y,F):null}),T=r0((y)=>{XZ(Y.current,y)});return NG(()=>{let y=Y.current;if(!y||typeof ResizeObserver>"u")return;let F=new ResizeObserver((C)=>{let v=C[0];if(!v)return;let h=Math.max(0,Math.floor(v.contentRect.width)),g=yZ(y);Q.current={...Q.current,height:g},q((O)=>O===h?O:h),A((O)=>O===g?O:g)});return F.observe(y),()=>F.disconnect()},[Y]),{actions:{autoScrollDuringDrag:T,getScrollTop:I,observePreparedViewport:L,observeScrollContainer:R,prepareNextPaint:b,reconcileEditorState:B,resolvePoint:z,scrollTo:f},props:{getScrollContainer:(y)=>({onScroll:(F)=>{R(F.currentTarget),y?.onScroll?.(F)},ref:Y}),scrollContent:{style:{height:`${G}px`}}},refs:{scrollContainer:Y},state:{layoutWidth:N,preparedViewport:E,scrollContentHeight:G,surfaceWidth:K,viewportHeight:D,viewportTop:V}}}function _G($){return Math.max(240,Math.floor($||480))}function yZ($){return Math.max(240,$.clientHeight)}function FG($){return{height:yZ($),top:$.scrollTop}}function HG($,M){return Math.max(M,Math.ceil($.totalHeight+24))}function zG(){if(typeof window>"u")return 1;return Math.max(1,window.devicePixelRatio||1)}function s3($,{paintHeight:M,paintTop:J,width:Z}){if(!$)return null;let X=Math.max(240,Math.ceil(M)),Y=zG();$.width=Math.ceil(Z*Y),$.height=Math.ceil(X*Y),$.style.width=`${Z}px`,$.style.height=`${X}px`,$.style.transform=`translateY(${J}px)`;let Q=$.getContext("2d");if(!Q)return null;return{context:Q,devicePixelRatio:Y,height:X,width:Z}}function i3($,M){return $.activeBlockType===M.activeBlockType&&$.activeCommentThreadIndex===M.activeCommentThreadIndex&&$.activeSpanKind===M.activeSpanKind&&$.canonicalContent===M.canonicalContent&&$.characterCount===M.characterCount&&$.commentThreadCount===M.commentThreadCount&&$.layoutWidth===M.layoutWidth&&$.resolvedCommentCount===M.resolvedCommentCount&&$.selectionFrom===M.selectionFrom&&$.selectionTo===M.selectionTo}function bZ($,M){if(!M?.length||!$?.length)return;let J=new Map($.map((X)=>[X.id,X])),Z=[];for(let X of M){let Y=J.get(X.userId);if(!Y)continue;Z.push({...Y,color:X.color,cursor:X.cursor})}return Z.length===0?void 0:Z}function TZ($,M){if(!$)return{didReconcile:!1,state:M};let J=EG($,M)??jG($,M);return J?{didReconcile:!0,state:J}:{didReconcile:!1,state:M}}function EG($,M){let J=WG($,M);return J?X0(M,J,!1):null}function WG($,M){if(t3($.selection.anchor,$.selection.focus)){let Y=o3($,M,$.selection.focus,"neutral");return Y?{anchor:Y,focus:Y}:null}let J=TG($),Z=o3($,M,$.selection.anchor,J.anchor),X=o3($,M,$.selection.focus,J.focus);return Z&&X?{anchor:Z,focus:X}:null}function o3($,M,J,Z){let X=$.documentIndex.regionIndex.get(J.regionId);if(!X)return null;let Y=n3(X,M);if(!Y)return null;return{offset:PG(X.text,Y.text,J.offset,Z),regionId:Y.id}}function n3($,M){let J=M.documentIndex.regionIndex.get($.id);if(J)return J;if($.text.length===0)return null;let Z=BG($,M);if(Z)return Z;return M.documentIndex.regionPathIndex.get($.path)??null}function BG($,M){let J=null;for(let Z of M.documentIndex.regions){if(Z.blockType!==$.blockType||Z.text!==$.text)continue;if(J)return null;J=Z}return J}function PG($,M,J,Z){let X=O0(J,0,$.length),{prefix:Y,suffix:Q}=b8($,X,X),K=yG(M,Y,Q);if(K!==null)return K;let q=bG(M,Y),D=wG(M,Q);if(Z==="before-suffix")return D??q??O0(J,0,M.length);return q??D??O0(J,0,M.length)}function yG($,M,J){let Z=c1($,M,J).filter((X)=>X.startOffset===X.endOffset);return Z.length===1?Z[0].startOffset:null}function bG($,M){let J=v0($,M);return J.length===1?J[0]+M.length:null}function wG($,M){let J=v0($,M);return J.length===1?J[0]:null}function TG($){let{anchor:M,focus:J}=$.selection;if(t3(M,J))return{anchor:"neutral",focus:"neutral"};return OG($,M,J)<=0?{anchor:"before-suffix",focus:"after-prefix"}:{anchor:"after-prefix",focus:"before-suffix"}}function OG($,M,J){let Z=$.documentIndex.regionOrderIndex.get(M.regionId),X=$.documentIndex.regionOrderIndex.get(J.regionId);if(Z===void 0||X===void 0)return 0;return Z===X?M.offset-J.offset:Z-X}function jG($,M){if(!t3($.selection.anchor,$.selection.focus))return null;let J=LG($);if(!J)return null;let Z=CG($,M,J);if(Z===null)return null;return RG(M,Z)}function LG($){let M=$.documentIndex.regionIndex.get($.selection.focus.regionId);if(!M||M.blockType!=="paragraph"||M.text.length>0)return null;return $.documentIndex.blockIndex.get(M.blockId)?.parentBlockId===null?M:null}function CG($,M,J){let Z=wZ($,J.rootIndex,"before"),X=wZ($,J.rootIndex,"after"),Y=Z?n3(Z,M):null,Q=X?n3(X,M):null;if(Y&&Q)return Y.rootIndex<Q.rootIndex?Q.rootIndex:null;if(Y)return Y.rootIndex+1;if(Q)return Q.rootIndex;return null}function RG($,M){let J=W1($.documentIndex.document,M,0,[d({text:""})]),Z={...$,documentIndex:Z2($.documentIndex,J,M,0)},X=p2(Z.documentIndex,$0(M));return X?X0(Z,X,!1):null}function wZ($,M,J){let Z=J==="before"?-1:1;for(let X=M+Z;X>=0&&X<$.documentIndex.roots.length;X+=Z){let Y=fG($,X,J);if(Y)return Y}return null}function fG($,M,J){let Z=$.documentIndex.roots[M]?.regions??[],X=J==="before"?Z.length-1:0,Y=J==="before"?-1:1;for(let Q=X;Q>=0&&Q<Z.length;Q+=Y){let K=Z[Q];if(K&&K.text.length>0)return K}return null}function t3($,M){return $.regionId===M.regionId&&$.offset===M.offset}import{jsx as x,jsxs as Z8,Fragment as IG}from"react/jsx-runtime";function X8({blocks:$}){return x(IG,{children:$.map((M)=>mG(M))})}function mG($){switch($.type){case"blockquote":return x("blockquote",{className:"preview-block preview-block-blockquote",children:x(X8,{blocks:$.children})},$.id);case"code":return Z8("div",{className:"preview-block preview-block-code",children:[x("div",{className:"preview-rich-header",children:uG($.language,$.meta)}),x("pre",{children:x("code",{children:$.source||" "})})]},$.id);case"heading":{let M=`h${$.depth}`;return x(M,{className:"preview-block preview-block-heading",children:J8($.children)},$.id)}case"list":return $.ordered?x("ol",{className:"preview-block preview-block-list",start:$.start??1,children:$.items.map((M)=>e3(M))},$.id):x("ul",{className:"preview-block preview-block-list",children:$.items.map((M)=>e3(M))},$.id);case"listItem":return e3($);case"paragraph":return x("p",{className:"preview-block preview-block-paragraph",children:J8($.children)},$.id);case"table":return Z8("div",{className:"preview-block preview-block-table",children:[x("div",{className:"preview-rich-header",children:vG($.rows.length,$.rows[0]?.cells.length??0,$.align.filter((M)=>M!==null).length)}),x("div",{className:"preview-table-scroll",children:x("table",{children:x("tbody",{children:$.rows.map((M)=>x("tr",{children:M.cells.map((J)=>x("td",{children:J8(J.children)},J.id))},M.id))})})})]},$.id);case"thematicBreak":return x("hr",{className:"preview-block preview-block-rule"},$.id);case"directive":return x("pre",{className:`preview-block preview-block-directive preview-block-directive-${$.name}`,children:$.body},$.id);case"unsupported":return x("pre",{className:"preview-block preview-block-unsupported",children:$.source},$.id)}}function e3($){return x("li",{className:"preview-block preview-block-list-item",children:x(X8,{blocks:$.children})},$.id)}function J8($){return $.map((M)=>{switch(M.type){case"break":return x("br",{},M.id);case"image":return Z8("span",{className:"preview-inline preview-inline-image",children:[x("img",{alt:M.alt??"",src:M.url,title:M.title??""}),Z8("span",{children:[x("strong",{children:hG(M.alt)}),x("small",{children:gG(M.url,M.title)})]})]},M.id);case"inlineCode":return x("code",{className:"preview-inline preview-inline-code",children:M.code},M.id);case"link":return SG(M);case"text":return x("span",{className:"preview-inline",children:kG(M.text,M.marks)},M.id);case"unsupported":return x("span",{className:"preview-inline preview-inline-unsupported",children:M.source},M.id)}})}function SG($){return x("a",{className:"preview-inline preview-inline-link",href:$.url,children:J8($.children)},$.id)}function kG($,M){let J=$;for(let Z of M)switch(Z){case"strikethrough":J=x("del",{children:J});break;case"italic":J=x("em",{children:J});break;case"bold":J=x("strong",{children:J});break;case"underline":J=x("ins",{children:J});break}return J}function uG($,M){return[$??"plain text",M].filter(Boolean).join(" • ")}function vG($,M,J){let Z=J>0?`${J} aligned ${J===1?"column":"columns"}`:"no alignment";return`${$} ${$===1?"row":"rows"} • ${M} ${M===1?"column":"columns"} • ${Z}`}function hG($){return $?.trim()?$:"Untitled image"}function gG($,M){return M?.trim()?`${M} • ${$}`:$}var OZ=`/* Base Documint host and SSR-fallback styles. */
|
|
12
|
+
`)}var a8=null,xX;function dX(){if(a8===null)a8=new Intl.Segmenter(xX,{granularity:"word"});return a8}var rX=/\p{Script=Arabic}/u,U5=/\p{M}/u,n9=/\p{Nd}/u;function i8($){return rX.test($)}function o0($){for(let M of $){let Z=M.codePointAt(0);if(Z>=19968&&Z<=40959||Z>=13312&&Z<=19903||Z>=131072&&Z<=173791||Z>=173824&&Z<=177983||Z>=177984&&Z<=178207||Z>=178208&&Z<=183983||Z>=183984&&Z<=191471||Z>=196608&&Z<=201551||Z>=63744&&Z<=64255||Z>=194560&&Z<=195103||Z>=12288&&Z<=12351||Z>=12352&&Z<=12447||Z>=12448&&Z<=12543||Z>=44032&&Z<=55215||Z>=65280&&Z<=65519)return!0}return!1}var n8=new Set([",",".","!",":",";","?","、","。","・",")","〕","〉","》","」","』","】","〗","〙","〛","ー","々","〻","ゝ","ゞ","ヽ","ヾ"]),v2=new Set(['"',"(","[","{","“","‘","«","‹","(","〔","〈","《","「","『","【","〖","〘","〚"]),t8=new Set(["'","’"]),n1=new Set([".",",","!","?",":",";","،","؛","؟","।","॥","၊","။","၌","၍","၏",")","]","}","%",'"',"”","’","»","›","…"]),cX=new Set([":",".","،","؛"]),aX=new Set(["၏"]),iX=new Set(["”","’","»","›","」","』","】","》","〉","〕",")"]);function sX($){if(e8($))return!0;let M=!1;for(let Z of $){if(n1.has(Z)){M=!0;continue}if(M&&U5.test(Z))continue;return!1}return M}function oX($){for(let M of $)if(!n8.has(M)&&!n1.has(M))return!1;return $.length>0}function nX($){if(e8($))return!0;for(let M of $)if(!v2.has(M)&&!t8.has(M)&&!U5.test(M))return!1;return $.length>0}function e8($){let M=!1;for(let Z of $){if(Z==="\\"||U5.test(Z))continue;if(v2.has(Z)||n1.has(Z)||t8.has(Z)){M=!0;continue}return!1}return M}function tX($){let M=Array.from($),Z=M.length;while(Z>0){let J=M[Z-1];if(U5.test(J)){Z--;continue}if(v2.has(J)||t8.has(J)){Z--;continue}break}if(Z<=0||Z===M.length)return null;return{head:M.slice(0,Z).join(""),tail:M.slice(Z).join("")}}function eX($,M){if($.length===0)return!1;for(let Z of $)if(Z!==M)return!1;return!0}function $Y($){if(!i8($)||$.length===0)return!1;return cX.has($[$.length-1])}function MY($){if($.length===0)return!1;return aX.has($[$.length-1])}function ZY($){if($.length<2||$[0]!==" ")return null;let M=$.slice(1);if(/^\p{M}+$/u.test(M))return{space:" ",marks:M};return null}function $6($){for(let M=$.length-1;M>=0;M--){let Z=$[M];if(iX.has(Z))return!0;if(!n1.has(Z))return!1}return!1}function JY($,M){if(M.preserveOrdinarySpaces||M.preserveHardBreaks){if($===" ")return"preserved-space";if($==="\t")return"tab";if(M.preserveHardBreaks&&$===`
|
|
13
|
+
`)return"hard-break"}if($===" ")return"space";if($===" "||$===" "||$===""||$==="\uFEFF")return"glue";if($==="")return"zero-width-break";if($==="")return"soft-hyphen";return"text"}function n0($){return $.length===1?$[0]:$.join("")}function XY($,M,Z,J){let X=[],Y=null,Q=[],K=Z,q=!1,D=0;for(let V of $){let G=JY(V,J),U=G==="text"&&M;if(Y!==null&&G===Y&&U===q){Q.push(V),D+=V.length;continue}if(Y!==null)X.push({text:n0(Q),isWordLike:q,kind:Y,start:K});Y=G,Q=[V],K=Z+D,q=U,D+=V.length}if(Y!==null)X.push({text:n0(Q),isWordLike:q,kind:Y,start:K});return X}function s8($){return $==="space"||$==="preserved-space"||$==="zero-width-break"||$==="hard-break"}var YY=/^[A-Za-z][A-Za-z0-9+.-]*:$/;function QY($,M){let Z=$.texts[M];if(Z.startsWith("www."))return!0;return YY.test(Z)&&M+1<$.len&&$.kinds[M+1]==="text"&&$.texts[M+1]==="//"}function KY($){return $.includes("?")&&($.includes("://")||$.startsWith("www."))}function DY($){let M=$.texts.slice(),Z=$.isWordLike.slice(),J=$.kinds.slice(),X=$.starts.slice();for(let Q=0;Q<$.len;Q++){if(J[Q]!=="text"||!QY($,Q))continue;let K=[M[Q]],q=Q+1;while(q<$.len&&!s8(J[q])){K.push(M[q]),Z[Q]=!0;let D=M[q].includes("?");if(J[q]="text",M[q]="",q++,D)break}M[Q]=n0(K)}let Y=0;for(let Q=0;Q<M.length;Q++){let K=M[Q];if(K.length===0)continue;if(Y!==Q)M[Y]=K,Z[Y]=Z[Q],J[Y]=J[Q],X[Y]=X[Q];Y++}return M.length=Y,Z.length=Y,J.length=Y,X.length=Y,{len:Y,texts:M,isWordLike:Z,kinds:J,starts:X}}function qY($){let M=[],Z=[],J=[],X=[];for(let Y=0;Y<$.len;Y++){let Q=$.texts[Y];if(M.push(Q),Z.push($.isWordLike[Y]),J.push($.kinds[Y]),X.push($.starts[Y]),!KY(Q))continue;let K=Y+1;if(K>=$.len||s8($.kinds[K]))continue;let q=[],D=$.starts[K],V=K;while(V<$.len&&!s8($.kinds[V]))q.push($.texts[V]),V++;if(q.length>0)M.push(n0(q)),Z.push(!0),J.push("text"),X.push(D),Y=V-1}return{len:M.length,texts:M,isWordLike:Z,kinds:J,starts:X}}var VY=new Set([":","-","/","×",",",".","+","–","—"]),s9=/^[A-Za-z0-9_]+[,:;]*$/,o9=/[,:;]+$/;function t9($){for(let M of $)if(n9.test(M))return!0;return!1}function o8($){if($.length===0)return!1;for(let M of $){if(n9.test(M)||VY.has(M))continue;return!1}return!0}function UY($){let M=[],Z=[],J=[],X=[];for(let Y=0;Y<$.len;Y++){let Q=$.texts[Y],K=$.kinds[Y];if(K==="text"&&o8(Q)&&t9(Q)){let q=[Q],D=Y+1;while(D<$.len&&$.kinds[D]==="text"&&o8($.texts[D]))q.push($.texts[D]),D++;M.push(n0(q)),Z.push(!0),J.push("text"),X.push($.starts[Y]),Y=D-1;continue}M.push(Q),Z.push($.isWordLike[Y]),J.push(K),X.push($.starts[Y])}return{len:M.length,texts:M,isWordLike:Z,kinds:J,starts:X}}function GY($){let M=[],Z=[],J=[],X=[];for(let Y=0;Y<$.len;Y++){let Q=$.texts[Y],K=$.kinds[Y],q=$.isWordLike[Y];if(K==="text"&&q&&s9.test(Q)){let D=[Q],V=o9.test(Q),G=Y+1;while(V&&G<$.len&&$.kinds[G]==="text"&&$.isWordLike[G]&&s9.test($.texts[G])){let U=$.texts[G];D.push(U),V=o9.test(U),G++}M.push(n0(D)),Z.push(!0),J.push("text"),X.push($.starts[Y]),Y=G-1;continue}M.push(Q),Z.push(q),J.push(K),X.push($.starts[Y])}return{len:M.length,texts:M,isWordLike:Z,kinds:J,starts:X}}function AY($){let M=[],Z=[],J=[],X=[];for(let Y=0;Y<$.len;Y++){let Q=$.texts[Y];if($.kinds[Y]==="text"&&Q.includes("-")){let K=Q.split("-"),q=K.length>1;for(let D=0;D<K.length;D++){let V=K[D];if(!q)break;if(V.length===0||!t9(V)||!o8(V))q=!1}if(q){let D=0;for(let V=0;V<K.length;V++){let G=K[V],U=V<K.length-1?`${G}-`:G;M.push(U),Z.push(!0),J.push("text"),X.push($.starts[Y]+D),D+=U.length}continue}}M.push(Q),Z.push($.isWordLike[Y]),J.push($.kinds[Y]),X.push($.starts[Y])}return{len:M.length,texts:M,isWordLike:Z,kinds:J,starts:X}}function NY($){let M=[],Z=[],J=[],X=[],Y=0;while(Y<$.len){let Q=[$.texts[Y]],K=$.isWordLike[Y],q=$.kinds[Y],D=$.starts[Y];if(q==="glue"){let V=[Q[0]],G=D;Y++;while(Y<$.len&&$.kinds[Y]==="glue")V.push($.texts[Y]),Y++;let U=n0(V);if(Y<$.len&&$.kinds[Y]==="text")Q[0]=U,Q.push($.texts[Y]),K=$.isWordLike[Y],q="text",D=G,Y++;else{M.push(U),Z.push(!1),J.push("glue"),X.push(G);continue}}else Y++;if(q==="text")while(Y<$.len&&$.kinds[Y]==="glue"){let V=[];while(Y<$.len&&$.kinds[Y]==="glue")V.push($.texts[Y]),Y++;let G=n0(V);if(Y<$.len&&$.kinds[Y]==="text"){Q.push(G,$.texts[Y]),K=K||$.isWordLike[Y],Y++;continue}Q.push(G)}M.push(n0(Q)),Z.push(K),J.push(q),X.push(D)}return{len:M.length,texts:M,isWordLike:Z,kinds:J,starts:X}}function _Y($){let M=$.texts.slice(),Z=$.isWordLike.slice(),J=$.kinds.slice(),X=$.starts.slice();for(let Y=0;Y<M.length-1;Y++){if(J[Y]!=="text"||J[Y+1]!=="text")continue;if(!o0(M[Y])||!o0(M[Y+1]))continue;let Q=tX(M[Y]);if(Q===null)continue;M[Y]=Q.head,M[Y+1]=Q.tail+M[Y+1],X[Y+1]=X[Y]+Q.head.length}return{len:M.length,texts:M,isWordLike:Z,kinds:J,starts:X}}function FY($,M,Z){let J=dX(),X=0,Y=[],Q=[],K=[],q=[];for(let U of J.segment($))for(let A of XY(U.segment,U.isWordLike??!1,U.index,Z)){let _=A.kind==="text";if(M.carryCJKAfterClosingQuote&&_&&X>0&&K[X-1]==="text"&&o0(A.text)&&o0(Y[X-1])&&$6(Y[X-1]))Y[X-1]+=A.text,Q[X-1]=Q[X-1]||A.isWordLike;else if(_&&X>0&&K[X-1]==="text"&&oX(A.text)&&o0(Y[X-1]))Y[X-1]+=A.text,Q[X-1]=Q[X-1]||A.isWordLike;else if(_&&X>0&&K[X-1]==="text"&&MY(Y[X-1]))Y[X-1]+=A.text,Q[X-1]=Q[X-1]||A.isWordLike;else if(_&&X>0&&K[X-1]==="text"&&A.isWordLike&&i8(A.text)&&$Y(Y[X-1]))Y[X-1]+=A.text,Q[X-1]=!0;else if(_&&!A.isWordLike&&X>0&&K[X-1]==="text"&&A.text.length===1&&A.text!=="-"&&A.text!=="—"&&eX(Y[X-1],A.text))Y[X-1]+=A.text;else if(_&&!A.isWordLike&&X>0&&K[X-1]==="text"&&(sX(A.text)||A.text==="-"&&Q[X-1]))Y[X-1]+=A.text;else Y[X]=A.text,Q[X]=A.isWordLike,K[X]=A.kind,q[X]=A.start,X++}for(let U=1;U<X;U++)if(K[U]==="text"&&!Q[U]&&e8(Y[U])&&K[U-1]==="text")Y[U-1]+=Y[U],Q[U-1]=Q[U-1]||Q[U],Y[U]="";for(let U=X-2;U>=0;U--)if(K[U]==="text"&&!Q[U]&&nX(Y[U])){let A=U+1;while(A<X&&Y[A]==="")A++;if(A<X&&K[A]==="text")Y[A]=Y[U]+Y[A],q[A]=q[U],Y[U]=""}let D=0;for(let U=0;U<X;U++){let A=Y[U];if(A.length===0)continue;if(D!==U)Y[D]=A,Q[D]=Q[U],K[D]=K[U],q[D]=q[U];D++}Y.length=D,Q.length=D,K.length=D,q.length=D;let V=NY({len:D,texts:Y,isWordLike:Q,kinds:K,starts:q}),G=_Y(GY(AY(UY(qY(DY(V))))));for(let U=0;U<G.len-1;U++){let A=ZY(G.texts[U]);if(A===null)continue;if(G.kinds[U]!=="space"&&G.kinds[U]!=="preserved-space"||G.kinds[U+1]!=="text"||!i8(G.texts[U+1]))continue;G.texts[U]=A.space,G.isWordLike[U]=!1,G.kinds[U]=G.kinds[U]==="preserved-space"?"preserved-space":"space",G.texts[U+1]=A.marks+G.texts[U+1],G.starts[U+1]=G.starts[U]+A.space.length}return G}function zY($,M){if($.len===0)return[];if(!M.preserveHardBreaks)return[{startSegmentIndex:0,endSegmentIndex:$.len,consumedEndSegmentIndex:$.len}];let Z=[],J=0;for(let X=0;X<$.len;X++){if($.kinds[X]!=="hard-break")continue;Z.push({startSegmentIndex:J,endSegmentIndex:X,consumedEndSegmentIndex:X+1}),J=X+1}if(J<$.len)Z.push({startSegmentIndex:J,endSegmentIndex:$.len,consumedEndSegmentIndex:$.len});return Z}function e9($,M,Z="normal"){let J=gX(Z),X=J.mode==="pre-wrap"?lX($):pX($);if(X.length===0)return{normalized:X,chunks:[],len:0,texts:[],isWordLike:[],kinds:[],starts:[]};let Y=FY(X,M,J);return{normalized:X,chunks:zY(Y,J),...Y}}var t1=null,$7=new Map,e1=null,HY=/\p{Emoji_Presentation}/u,EY=/[\p{Emoji_Presentation}\p{Extended_Pictographic}\p{Regional_Indicator}\uFE0F\u20E3]/u,M6=null,M7=new Map;function Z6(){if(t1!==null)return t1;if(typeof OffscreenCanvas<"u")return t1=new OffscreenCanvas(1,1).getContext("2d"),t1;if(typeof document<"u")return t1=document.createElement("canvas").getContext("2d"),t1;throw Error("Text measurement requires OffscreenCanvas or a DOM canvas context.")}function WY($){let M=$7.get($);if(!M)M=new Map,$7.set($,M);return M}function Y1($,M){let Z=M.get($);if(Z===void 0)Z={width:Z6().measureText($).width,containsCJK:o0($)},M.set($,Z);return Z}function $2(){if(e1!==null)return e1;if(typeof navigator>"u")return e1={lineFitEpsilon:0.005,carryCJKAfterClosingQuote:!1,preferPrefixWidthsForBreakableRuns:!1,preferEarlySoftHyphenBreak:!1},e1;let $=navigator.userAgent,Z=navigator.vendor==="Apple Computer, Inc."&&$.includes("Safari/")&&!$.includes("Chrome/")&&!$.includes("Chromium/")&&!$.includes("CriOS/")&&!$.includes("FxiOS/")&&!$.includes("EdgiOS/"),J=$.includes("Chrome/")||$.includes("Chromium/")||$.includes("CriOS/")||$.includes("Edg/");return e1={lineFitEpsilon:Z?0.015625:0.005,carryCJKAfterClosingQuote:J,preferPrefixWidthsForBreakableRuns:Z,preferEarlySoftHyphenBreak:Z},e1}function yY($){let M=$.match(/(\d+(?:\.\d+)?)\s*px/);return M?parseFloat(M[1]):16}function J6(){if(M6===null)M6=new Intl.Segmenter(void 0,{granularity:"grapheme"});return M6}function BY($){return HY.test($)||$.includes("️")}function Z7($){return EY.test($)}function PY($,M){let Z=M7.get($);if(Z!==void 0)return Z;let J=Z6();J.font=$;let X=J.measureText("\uD83D\uDE00").width;if(Z=0,X>M+0.5&&typeof document<"u"&&document.body!==null){let Y=document.createElement("span");Y.style.font=$,Y.style.display="inline-block",Y.style.visibility="hidden",Y.style.position="absolute",Y.textContent="\uD83D\uDE00",document.body.appendChild(Y);let Q=Y.getBoundingClientRect().width;if(document.body.removeChild(Y),X-Q>0.5)Z=X-Q}return M7.set($,Z),Z}function wY($){let M=0,Z=J6();for(let J of Z.segment($))if(BY(J.segment))M++;return M}function bY($,M){if(M.emojiCount===void 0)M.emojiCount=wY($);return M.emojiCount}function Q1($,M,Z){if(Z===0)return M.width;return M.width-bY($,M)*Z}function J7($,M,Z,J){if(M.graphemeWidths!==void 0)return M.graphemeWidths;let X=[],Y=J6();for(let Q of Y.segment($)){let K=Y1(Q.segment,Z);X.push(Q1(Q.segment,K,J))}return M.graphemeWidths=X.length>1?X:null,M.graphemeWidths}function X7($,M,Z,J){if(M.graphemePrefixWidths!==void 0)return M.graphemePrefixWidths;let X=[],Y=J6(),Q="";for(let K of Y.segment($)){Q+=K.segment;let q=Y1(Q,Z);X.push(Q1(Q,q,J))}return M.graphemePrefixWidths=X.length>1?X:null,M.graphemePrefixWidths}function Y7($,M){let Z=Z6();Z.font=$;let J=WY($),X=yY($),Y=M?PY($,X):0;return{cache:J,fontSize:X,emojiCorrection:Y}}function G5($){return $==="space"||$==="preserved-space"||$==="tab"||$==="zero-width-break"||$==="soft-hyphen"}function TY($,M){while(M<$.widths.length){let Z=$.kinds[M];if(Z!=="space"&&Z!=="zero-width-break"&&Z!=="soft-hyphen")break;M++}return M}function jY($,M){if(M<=0)return 0;let Z=$%M;if(Math.abs(Z)<=0.000001)return M;return M-Z}function Q7($,M,Z,J){if(!J||M===null)return $[Z];return M[Z]-(Z>0?M[Z-1]:0)}function OY($,M,Z,J,X,Y){let Q=0,K=M;while(Q<$.length){let q=Y?M+$[Q]:K+$[Q];if((Q+1<$.length?q+X:q)>Z+J)break;K=q,Q++}return{fitCount:Q,fittedWidth:K}}function LY($,M,Z){let{widths:J,kinds:X,breakableWidths:Y,breakablePrefixWidths:Q}=$;if(J.length===0)return 0;let K=$2(),q=K.lineFitEpsilon,D=0,V=0,G=!1,U=0,A=0,_=0,N=0,z=-1,E=0;function L(){z=-1,E=0}function W(B=_,P=N,F=V){D++,Z?.({startSegmentIndex:U,startGraphemeIndex:A,endSegmentIndex:B,endGraphemeIndex:P,width:F}),V=0,G=!1,L()}function R(B,P){G=!0,U=B,A=0,_=B+1,N=0,V=P}function S(B,P,F){G=!0,U=B,A=P,_=B,N=P+1,V=F}function I(B,P){if(!G){R(B,P);return}V+=P,_=B+1,N=0}function y(B,P){if(!G5(X[B]))return;z=B+1,E=V-P}function b(B){H(B,0)}function H(B,P){let F=Y[B],C=Q[B]??null;for(let u=P;u<F.length;u++){let h=Q7(F,C,u,K.preferPrefixWidthsForBreakableRuns);if(!G){S(B,u,h);continue}if(V+h>M+q)W(),S(B,u,h);else V+=h,_=B,N=u+1}if(G&&_===B&&N===F.length)_=B+1,N=0}let j=0;while(j<J.length){if(!G){if(j=TY($,j),j>=J.length)break}let B=J[j],P=X[j];if(!G){if(B>M&&Y[j]!==null)b(j);else R(j,B);y(j,B),j++;continue}if(V+B>M+q){if(G5(P)){I(j,B),W(j+1,0,V-B),j++;continue}if(z>=0){if(_>z||_===z&&N>0){W();continue}W(z,0,E);continue}if(B>M&&Y[j]!==null){W(),b(j),j++;continue}W();continue}I(j,B),y(j,B),j++}if(G)W();return D}function K7($,M,Z){if($.simpleLineWalkFastPath)return LY($,M,Z);let{widths:J,lineEndFitAdvances:X,lineEndPaintAdvances:Y,kinds:Q,breakableWidths:K,breakablePrefixWidths:q,discretionaryHyphenWidth:D,tabStopAdvance:V,chunks:G}=$;if(J.length===0||G.length===0)return 0;let U=$2(),A=U.lineFitEpsilon,_=0,N=0,z=!1,E=0,L=0,W=0,R=0,S=-1,I=0,y=0,b=null;function H(){S=-1,I=0,y=0,b=null}function j(T=W,k=R,m=N){_++,Z?.({startSegmentIndex:E,startGraphemeIndex:L,endSegmentIndex:T,endGraphemeIndex:k,width:m}),N=0,z=!1,H()}function B(T,k){z=!0,E=T,L=0,W=T+1,R=0,N=k}function P(T,k,m){z=!0,E=T,L=k,W=T,R=k+1,N=m}function F(T,k){if(!z){B(T,k);return}N+=k,W=T+1,R=0}function C(T,k){if(!G5(Q[T]))return;let m=Q[T]==="tab"?0:X[T],a=Q[T]==="tab"?k:Y[T];S=T+1,I=N-k+m,y=N-k+a,b=Q[T]}function u(T){h(T,0)}function h(T,k){let m=K[T],a=q[T]??null;for(let l=k;l<m.length;l++){let F0=Q7(m,a,l,U.preferPrefixWidthsForBreakableRuns);if(!z){P(T,l,F0);continue}if(N+F0>M+A)j(),P(T,l,F0);else N+=F0,W=T,R=l+1}if(z&&W===T&&R===m.length)W=T+1,R=0}function g(T){if(b!=="soft-hyphen")return!1;let k=K[T];if(k===null)return!1;let m=U.preferPrefixWidthsForBreakableRuns?q[T]??k:k,a=m!==k,{fitCount:l,fittedWidth:F0}=OY(m,N,M,A,D,a);if(l===0)return!1;if(N=F0,W=T,R=l,H(),l===k.length)return W=T+1,R=0,!0;return j(T,l,F0+D),h(T,l),!0}function w(T){_++,Z?.({startSegmentIndex:T.startSegmentIndex,startGraphemeIndex:0,endSegmentIndex:T.consumedEndSegmentIndex,endGraphemeIndex:0,width:0}),H()}for(let T=0;T<G.length;T++){let k=G[T];if(k.startSegmentIndex===k.endSegmentIndex){w(k);continue}z=!1,N=0,E=k.startSegmentIndex,L=0,W=k.startSegmentIndex,R=0,H();let m=k.startSegmentIndex;while(m<k.endSegmentIndex){let a=Q[m],l=a==="tab"?jY(N,V):J[m];if(a==="soft-hyphen"){if(z)W=m+1,R=0,S=m+1,I=N+D,y=N+D,b=a;m++;continue}if(!z){if(l>M&&K[m]!==null)u(m);else B(m,l);C(m,l),m++;continue}if(N+l>M+A){let c0=N+(a==="tab"?0:X[m]),k0=N+(a==="tab"?l:Y[m]);if(b==="soft-hyphen"&&U.preferEarlySoftHyphenBreak&&I<=M+A){j(S,0,y);continue}if(b==="soft-hyphen"&&g(m)){m++;continue}if(G5(a)&&c0<=M+A){F(m,l),j(m+1,0,k0),m++;continue}if(S>=0&&I<=M+A){if(W>S||W===S&&R>0){j();continue}let m0=S;j(m0,0,y),m=m0;continue}if(l>M&&K[m]!==null){j(),u(m),m++;continue}j();continue}F(m,l),C(m,l),m++}if(z){let a=S===k.consumedEndSegmentIndex?y:N;j(k.consumedEndSegmentIndex,0,a)}}return _}var X6=null,D7=new WeakMap;function V7(){if(X6===null)X6=new Intl.Segmenter(void 0,{granularity:"grapheme"});return X6}function CY($){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 RY($,M,Z){let J=V7(),X=$2(),{cache:Y,emojiCorrection:Q}=Y7(M,Z7($.normalized)),K=Q1("-",Y1("-",Y),Q),D=Q1(" ",Y1(" ",Y),Q)*8;if($.len===0)return CY(Z);let V=[],G=[],U=[],A=[],_=$.chunks.length<=1,N=Z?[]:null,z=[],E=[],L=Z?[]:null,W=Array.from({length:$.len}),R=Array.from({length:$.len});function S(b,H,j,B,P,F,C,u){if(P!=="text"&&P!=="space"&&P!=="zero-width-break")_=!1;if(V.push(H),G.push(j),U.push(B),A.push(P),N?.push(F),z.push(C),E.push(u),L!==null)L.push(b)}for(let b=0;b<$.len;b++){W[b]=V.length;let H=$.texts[b],j=$.isWordLike[b],B=$.kinds[b],P=$.starts[b];if(B==="soft-hyphen"){S(H,0,K,K,B,P,null,null),R[b]=V.length;continue}if(B==="hard-break"){S(H,0,0,0,B,P,null,null),R[b]=V.length;continue}if(B==="tab"){S(H,0,0,0,B,P,null,null),R[b]=V.length;continue}let F=Y1(H,Y);if(B==="text"&&F.containsCJK){let g="",w=0;for(let T of J.segment(H)){let k=T.segment;if(g.length===0){g=k,w=T.index;continue}if(v2.has(g)||n8.has(k)||n1.has(k)||X.carryCJKAfterClosingQuote&&o0(k)&&$6(g)){g+=k;continue}let m=Y1(g,Y),a=Q1(g,m,Q);S(g,a,a,a,"text",P+w,null,null),g=k,w=T.index}if(g.length>0){let T=Y1(g,Y),k=Q1(g,T,Q);S(g,k,k,k,"text",P+w,null,null)}R[b]=V.length;continue}let C=Q1(H,F,Q),u=B==="space"||B==="preserved-space"||B==="zero-width-break"?0:C,h=B==="space"||B==="zero-width-break"?0:C;if(j&&H.length>1){let g=J7(H,F,Y,Q),w=X.preferPrefixWidthsForBreakableRuns?X7(H,F,Y,Q):null;S(H,C,u,h,B,P,g,w)}else S(H,C,u,h,B,P,null,null);R[b]=V.length}let I=SY($.chunks,W,R),y=N===null?null:i9($.normalized,N);if(L!==null)return{widths:V,lineEndFitAdvances:G,lineEndPaintAdvances:U,kinds:A,simpleLineWalkFastPath:_,segLevels:y,breakableWidths:z,breakablePrefixWidths:E,discretionaryHyphenWidth:K,tabStopAdvance:D,chunks:I,segments:L};return{widths:V,lineEndFitAdvances:G,lineEndPaintAdvances:U,kinds:A,simpleLineWalkFastPath:_,segLevels:y,breakableWidths:z,breakablePrefixWidths:E,discretionaryHyphenWidth:K,tabStopAdvance:D,chunks:I}}function SY($,M,Z){let J=[];for(let X=0;X<$.length;X++){let Y=$[X],Q=Y.startSegmentIndex<M.length?M[Y.startSegmentIndex]:Z[Z.length-1]??0,K=Y.endSegmentIndex<M.length?M[Y.endSegmentIndex]:Z[Z.length-1]??0,q=Y.consumedEndSegmentIndex<M.length?M[Y.consumedEndSegmentIndex]:Z[Z.length-1]??0;J.push({startSegmentIndex:Q,endSegmentIndex:K,consumedEndSegmentIndex:q})}return J}function kY($,M,Z,J){let X=e9($,$2(),J?.whiteSpace);return RY(X,M,Z)}function U7($,M,Z){return kY($,M,!0,Z)}function mY($){return $}function q7($,M,Z){let J=Z.get($);if(J!==void 0)return J;J=[];let X=V7();for(let Y of X.segment(M[$]))J.push(Y.segment);return Z.set($,J),J}function fY($){let M=D7.get($);if(M!==void 0)return M;return M=new Map,D7.set($,M),M}function vY($,M,Z,J){return J>0&&$[J-1]==="soft-hyphen"&&!(M===J&&Z>0)}function uY($,M,Z,J,X,Y,Q){let K="",q=vY(M,J,X,Y);for(let D=J;D<Y;D++){if(M[D]==="soft-hyphen"||M[D]==="hard-break")continue;if(D===J&&X>0)K+=q7(D,$,Z).slice(X).join("");else K+=$[D]}if(Q>0){if(q)K+="-";K+=q7(Y,$,Z).slice(J===Y?X:0,Q).join("")}else if(q)K+="-";return K}function hY($,M,Z,J,X,Y,Q){return{text:uY($.segments,$.kinds,M,J,X,Y,Q),width:Z,start:{segmentIndex:J,graphemeIndex:X},end:{segmentIndex:Y,graphemeIndex:Q}}}function IY($,M,Z){return hY($,M,Z.width,Z.startSegmentIndex,Z.startGraphemeIndex,Z.endSegmentIndex,Z.endGraphemeIndex)}function G7($,M,Z){let J=[];if($.widths.length===0)return{lineCount:0,height:0,lines:J};let X=fY($),Y=K7(mY($),M,(Q)=>{J.push(IY($,X,Q))});return{lineCount:Y,height:Y*Z,lines:J}}var A7=[{fontSize:32,lineHeight:36},{fontSize:26,lineHeight:32},{fontSize:21,lineHeight:28},{fontSize:21,lineHeight:28},{fontSize:19,lineHeight:26},{fontSize:18,lineHeight:26}],A5;function M2($){if($?.type==="heading"){let{fontSize:M}=F7($.depth);return`700 ${M}px "Iowan Old Style", "Palatino Linotype", serif`}switch($?.type){case"code":return"15px ui-monospace, SFMono-Regular, Menlo, monospace";default:return'16px "Iowan Old Style", "Palatino Linotype", serif'}}function T1($,M){if($?.type==="heading")return F7($.depth).lineHeight;if($?.type==="code")return 22;return M}function F7($){return A7[$-1]??A7.at(-1)}function Z2($,M,Z,J,X,Y,Q){let K=`${_5(M,Q)}:${X}:${Y}:${Z}`,q=$.measuredLines.get(K);if(q)return q;let D=pY($,M,Z,J,X,Y,Q);return l9($,K,D)}function N5($,M,Z,J,X,Y,Q,K){let q=`${_5(M,K)}:${Z}:${J}:${Y}:${Q}`,D=$.lineBoundaries.get(q);if(D)return D;let V=H7();if(!V)return _7(X);let G=[{left:0,offset:0}],U=0,A=M.inlines.filter((_)=>_.end>Z&&_.start<J);if(A.length===0)return _7(X);for(let _ of A){let N=Math.max(Z,_.start),z=Math.min(J,_.end),E=M.text.slice(N,z),L=N-Z;if(_.kind==="image"){let W=q5(_,K,Q).width;U+=W,L+=E.length,G.push({left:U,offset:L});continue}V.font=z7(Y,_.marks);for(let W of Array.from(E))U+=E7($,V,W),L+=W.length,G.push({left:U,offset:L})}return x9($,q,G)}function gY($,M,Z,J){let X=`${Z}::${J}::${M}`,Y=$.preparedText.get(X);if(Y)return Y;let Q=U7(M,Z,{whiteSpace:J});return p9($,X,Q)}function pY($,M,Z,J,X,Y,Q){let K=M.text;if(K.length===0)return[{end:0,height:Y,start:0,text:"",width:0}];if(cY(M))return xY($,M,Z,X,Y,Q);try{let q=gY($,K,Z,nY(J));return G7(q,X,Y).lines.map((V)=>({end:N7(q.segments,V.end),height:Y,start:N7(q.segments,V.start),text:V.text,width:V.width}))}catch{return lY(K,X,Y)}}function N7($,M){let Z=0;for(let Y=0;Y<M.segmentIndex;Y+=1)Z+=$[Y]?.length??0;let J=$[M.segmentIndex]??"",X=Array.from(J);for(let Y=0;Y<M.graphemeIndex;Y+=1)Z+=X[Y]?.length??0;return Z}function _7($){let M=[{left:0,offset:0}],Z=0,J=0;for(let X of Array.from($))Z+=9,J+=X.length,M.push({left:Z,offset:J});return M}function lY($,M,Z){let J=Math.max(1,Math.floor(M/9)),X=tY($,J),Y=0;return X.map((Q)=>{let K=Y,q=K+Q.length;return Y=q,{end:q,height:Z,start:K,text:Q,width:Q.length*9}})}function xY($,M,Z,J,X,Y){let Q=rY($,H7(),M,Z,J,X,Y);if(Q.length===0)return[{end:0,height:X,start:0,text:"",width:0}];return dY(Q,M.text,J,X)}function dY($,M,Z,J){let X=[],Y=0;while(Y<$.length){let Q=$[Y].start;if($[Y].text===`
|
|
14
|
+
`){X.push({end:Q,height:J,start:Q,text:"",width:0}),Y+=1;continue}let K=0,q=0,D=Y,V=-1,G=J;while(D<$.length){let A=$[D];if(A.text===`
|
|
15
|
+
`)break;let _=K+A.width;if(_>Z&&D>Y)break;if(K=_,G=Math.max(G,A.height),A.breakable)V=D,q=K;D+=1}if(D===$.length||$[D]?.text===`
|
|
16
|
+
`){let A=$[D-1]?.end??Q;X.push({end:A,height:G,start:Q,text:M.slice(Q,A),width:K}),Y=D<$.length&&$[D]?.text===`
|
|
17
|
+
`?D+1:D;continue}if(V>=Y){let A=$[V].end;X.push({end:A,height:G,start:Q,text:M.slice(Q,A),width:q}),Y=V+1;continue}let U=$[Math.max(Y,D-1)].end;X.push({end:U,height:G,start:Q,text:M.slice(Q,U),width:K}),Y=Math.max(Y+1,D)}return X}function rY($,M,Z,J,X,Y,Q){let K=[];for(let q of Z.inlines){if(q.kind==="image"){let V=q5(q,Q,X);K.push({breakable:!0,end:q.end,height:V.height,start:q.start,text:q.text,width:V.width});continue}if(M)M.font=z7(J,q.marks);let D=q.start;for(let V of Array.from(q.text)){let G=D,U=G+V.length;K.push({breakable:/\s/.test(V),end:U,height:Y,start:G,text:V,width:V===`
|
|
18
|
+
`?0:E7($,M,V)}),D=U}}return K}function cY($){return $.inlines.some((M)=>M.kind==="image"||oY(M))}function _5($,M){return[$.path,sY($.text),aY($,M)].join(":")}function aY($,M){return $.inlines.map((Z)=>`${Z.start}-${Z.end}:${iY(Z,M)}`).join("|")}function iY($,M){if($.kind==="image"&&$.image)return g9($,M);return`${$.kind}:${$.inlineCode?1:0}:${$.marks.join(",")}:${$.link?.url??""}`}function sY($){let M=2166136261;for(let Z of $)M^=Z.charCodeAt(0),M=Math.imul(M,16777619);return(M>>>0).toString(36)}function oY($){return $.marks.includes("italic")||$.marks.includes("bold")}function z7($,M){let Z=[];if(M.includes("italic"))Z.push("italic");if(M.includes("bold"))Z.push("700");return Z.length>0?`${Z.join(" ")} ${$}`:$}function H7(){if(A5!==void 0)return A5;return A5=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):typeof document<"u"?document.createElement("canvas"):null)?.getContext("2d")??null,A5}function E7($,M,Z){if(!M)return 9;let J=M.font,X=r9($,J),Y=X.get(Z);if(Y!==void 0)return Y;let Q=M.measureText(Z).width;return X.set(Z,Q),Q}function nY($){return $?.type==="code"?"pre-wrap":"normal"}function tY($,M){if($.length===0)return[""];let Z=$.split(`
|
|
19
|
+
`),J=[];for(let X of Z){if(X.length===0){J.push("");continue}let Y=X;while(Y.length>M){let Q=Y.slice(0,M),K=Q.lastIndexOf(" ");if(K<=0){J.push(Q),Y=Y.slice(M);continue}J.push(Q.slice(0,K)),Y=Y.slice(K+1)}J.push(Y)}return J}var u2=10,J2=8,Y6=120;function W7($,M,Z,J,X,Y,Q,K,q,D){let V=Math.max(1,...Y.rows.map((N)=>N.cells.length)),U=Math.max(Y6,q.width-Q-q.paddingX)/V,A=eY(J),_=K;for(let N=0;N<Y.rows.length;N+=1){let z=$Q(A.get(N)??[],X,Y,U,u2,q.lineHeight,D),E=Math.max(q.lineHeight+J2*2,...z.map((L)=>L.measuredLines.reduce((W,R)=>W+R.height,0)+J2*2));for(let L of z){let W=Q+L.cellIndex*U,R=_+J2;for(let S of L.measuredLines){let I={blockId:L.container.blockId,boundaries:N5(X,L.container,S.start,S.end,S.text,L.font,U-u2*2,D),regionId:L.container.id,end:S.end,font:L.font,height:S.height,left:W+u2,start:S.start,text:S.text,top:R,width:S.width};$.push(I),Q6(M,I),R+=S.height}Z.set(L.container.id,{bottom:_+E,left:W,right:W+U,top:_})}ZQ(M,Y.id,_,_+E),_+=E}return _+q.blockGap}function eY($){let M=new Map;for(let Z of $){let J=MQ(Z.path);if(!J)continue;let X=M.get(J.rowIndex)??[];X.push({cellIndex:J.cellIndex,container:Z}),M.set(J.rowIndex,X)}return M}function $Q($,M,Z,J,X,Y,Q){return[...$].sort((K,q)=>K.cellIndex-q.cellIndex).map(({cellIndex:K,container:q})=>{let D=M2(Z),V=T1(Z,Y),G=Z2(M,q,D,Z,Math.max(40,J-X*2),V,Q);return{cellIndex:K,container:q,font:D,lineHeight:V,measuredLines:G}})}function MQ($){let M=/\.rows\.(\d+)\.cells\.(\d+)$/.exec($);if(!M)return null;return{cellIndex:Number(M[2]),rowIndex:Number(M[1])}}function ZQ($,M,Z,J){let X=$.get(M);$.set(M,{bottom:X?Math.max(X.bottom,J):J,top:X?Math.min(X.top,Z):Z})}var JQ={blockGap:16,charWidth:9,indentWidth:24,lineHeight:24,paddingX:16,paddingY:12},XQ=24,YQ=16,QQ=6,KQ=10,DQ=4;function F5($){let M=Math.max(12,Math.floor($.width/9)),Z=Math.max(1,Math.ceil($.text.length/M));return{estimatedHeight:Z*24,lineCount:Z,width:$.width}}function z5($,M,Z=b1(),J=null){let X=J??{images:new Map},Y={...JQ,...M},Q=[],K=new Map,q=new Map($.regions.map((N)=>[N.id,{textLength:N.text.length}])),D=new Map($.blocks.map((N)=>[N.id,N.depth])),V=new Map($.blocks.map((N)=>[N.id,N])),G=I2($.document.blocks),U=new Map,A=Y.paddingY;for(let N=0;N<$.regions.length;N+=1){let z=$.regions[N],E=D.get(z.blockId)??0,L=Y.paddingX+E*Y.indentWidth,W=Math.max(40,Y.width-L-Y.paddingX),R=G.get(z.blockId)??null;if(R?.type==="table"){let y=V.get(z.blockId)?.regionIds??[],b=$.regions.slice(N,N+y.length);A=W7(Q,U,K,b,Z,R,L,A,Y,X),N+=b.length-1;continue}A=qQ(Q,U,K,z,Z,R,L,A,W,Y,X);let S=E5(V,G,$.regions,N,Y.blockGap);A+=S;let I=U.get(z.blockId);if(I)I.bottom=Math.max(I.bottom,A)}return{blocks:$.blocks.map((N)=>{let z=U.get(N.id),E=z?.top??Y.paddingY;return{bottom:z?.bottom??E+Y.lineHeight/2,depth:N.depth,id:N.id,top:E,type:N.type}}),regionBounds:UQ(Q,K),regionLineIndices:VQ(Q),regionMetrics:q,height:Math.max(A,Y.paddingY),lines:Q,options:Y,width:Y.width}}function qQ($,M,Z,J,X,Y,Q,K,q,D,V){let G=M2(Y),U=T1(Y,D.lineHeight),A=Z2(X,J,G,Y,q,U,V),_=K;for(let N of A){let z={blockId:J.blockId,boundaries:N5(X,J,N.start,N.end,N.text,G,q,V),regionId:J.id,end:N.end,font:G,height:N.height,left:Q,start:N.start,text:N.text,top:_,width:N.width};$.push(z),Q6(M,z),_+=N.height}return GQ($,J.id,Z),_}function VQ($){let M=[...$].sort((J,X)=>J.top-X.top||J.left-X.left),Z=new Map;$.length=0,$.push(...M);for(let[J,X]of $.entries()){let Y=Z.get(X.regionId)??[];Y.push(J),Z.set(X.regionId,Y)}return Z}function UQ($,M){let Z=new Map(M);for(let J of $){let X=Z.get(J.regionId),Y={bottom:J.top+J.height,left:J.left,right:J.left+J.width,top:J.top};Z.set(J.regionId,X?{bottom:Math.max(X.bottom,Y.bottom),left:Math.min(X.left,Y.left),right:Math.max(X.right,Y.right),top:Math.min(X.top,Y.top)}:Y)}return Z}function GQ($,M,Z){let J=$.filter((X)=>X.regionId===M);if(J.length===0)return;Z.set(M,{bottom:Math.max(...J.map((X)=>X.top+X.height)),left:Math.min(...J.map((X)=>X.left)),right:Math.max(...J.map((X)=>X.left+X.width)),top:Math.min(...J.map((X)=>X.top))})}function Q6($,M){let Z=$.get(M.blockId),J=M.top+M.height;$.set(M.blockId,{bottom:Z?Math.max(Z.bottom,J):J,top:Z?Math.min(Z.top,M.top):M.top})}function b7($,M){let Z=0,J=$.lines.length-1;while(Z<=J){let X=Z+J>>1,Y=$.lines[X];if(M<Y.top){J=X-1;continue}if(M>=Y.top+Y.height){Z=X+1;continue}return{index:X,line:Y}}return null}function K6($,M){let Z=[...$.regionBounds.entries()].find(([,Y])=>{return M.x>=Y.left&&M.x<=Y.right&&M.y>=Y.top&&M.y<=Y.bottom});if(Z)return H5($,Z[0],M.y);let J=b7($,M.y);if(!J)return null;let X=AQ($,M.y,J.index);if(X.length===1)return X[0]??null;return X.find((Y)=>{let Q=$.regionBounds.get(Y.line.regionId);return Q?M.x>=Q.left&&M.x<=Q.right:!1})??[...X].sort((Y,Q)=>{let K=$.regionBounds.get(Y.line.regionId),q=$.regionBounds.get(Q.line.regionId),D=y7(M.x,K),V=y7(M.x,q);return D-V})[0]??null}function D6($,M,Z){if($.lines.length===0)return{endIndex:0,startIndex:0};let J=M+Z,X=B7($,M),Y=B7($,J);if(X>0){let Q=$.lines[X-1];if(Q.top+Q.height>M)X-=1}if(Y<$.lines.length){if($.lines[Y].top<J)Y+=1}return{endIndex:Y,startIndex:X}}function g0($,M,Z){if(!$.regionMetrics.get(Z.regionId))return null;let X=L0($,Z.regionId,Z.offset);if(!X)return null;return{blockId:X.blockId,regionId:X.regionId,height:X.height,left:y0(X,Z.offset-X.start),offset:Z.offset,top:X.top}}function L0($,M,Z){return h2($,M,Z)?.line??null}function H5($,M,Z){let J=$.regionLineIndices.get(M);if(!J||J.length===0)return null;let X=J[0],Y=Number.POSITIVE_INFINITY;for(let Q of J){let K=$.lines[Q],q=Z<K.top?K.top-Z:Z>K.top+K.height?Z-(K.top+K.height):0;if(q<Y)Y=q,X=Q;if(q===0)break}return{index:X,line:$.lines[X]}}function h2($,M,Z){let J=$.regionLineIndices.get(M);if(!J||J.length===0)return null;let X=0,Y=J.length-1;while(X<=Y){let V=X+Y>>1,G=J[V],U=$.lines[G];if(Z<U.start){Y=V-1;continue}if(Z>U.end){X=V+1;continue}return{index:G,line:U}}let Q=J[0],K=J[J.length-1],q=$.lines[Q],D=$.lines[K];if(Z<=q.start)return{index:Q,line:q};if(Z>=D.end)return{index:K,line:D};return null}function AQ($,M,Z){let J=[];for(let X=Z;X>=0;X-=1){let Y=$.lines[X];if(M<Y.top||M>=Y.top+Y.height)break;J.unshift({index:X,line:Y})}for(let X=Z+1;X<$.lines.length;X+=1){let Y=$.lines[X];if(M<Y.top||M>=Y.top+Y.height)break;J.push({index:X,line:Y})}return J}function y7($,M){if(!M)return Number.POSITIVE_INFINITY;if($<M.left)return M.left-$;if($>M.right)return $-M.right;return 0}function y0($,M){return $.left+NQ($.boundaries,M)}function I2($){let M=new Map,Z=(J)=>{for(let X of J)if(M.set(X.id,X),X.type==="blockquote"||X.type==="listItem")Z(X.children);else if(X.type==="list")Z(X.items)};return Z($),M}function NQ($,M){for(let J of $)if(J.offset===M)return J.left;return $.filter((J)=>J.offset<=M).at(-1)?.left??0}function B7($,M){let Z=0,J=$.lines.length;while(Z<J){let X=Z+J>>1,Y=$.lines[X];if(Y.top+Y.height<=M)Z=X+1;else J=X}return Z}function T7($,M){if($.length===0)return 0;for(let Z=1;Z<$.length;Z+=1){let J=$[Z-1],X=$[Z],Y=J.left+(X.left-J.left)/2;if(M<=Y)return J.offset;if(M<=X.left)return X.offset}return $.at(-1)?.offset??0}function E5($,M,Z,J,X){let Y=Z[J],Q=Z[J+1];if(!Y||!Q)return X;if(P7($,Y.blockId,Q.blockId,"list"))return QQ;if(P7($,Y.blockId,Q.blockId,"blockquote"))return KQ;if(Y.blockId===Q.blockId)return DQ;return X+_Q(M.get(Y.blockId))}function _Q($){if($?.type!=="heading")return 0;if($.depth===1)return XQ;return $.depth===2?YQ:0}function P7($,M,Z,J){let X=w7($,M,J),Y=w7($,Z,J);for(let Q of X)if(Y.has(Q))return!0;return!1}function w7($,M,Z){let J=new Set,X=$.get(M)??null;while(X){if(X.type===Z)J.add(X.id);X=X.parentBlockId?$.get(X.parentBlockId)??null:null}return J}function q6($,M,Z,J=[],X=b1(),Y=null){let Q=Y??{images:new Map},K=I2($.document.blocks),q=new Map($.blocks.map((W)=>[W.id,W])),D=new Set(J),V=Math.max(0,Z.top-Z.overscan),G=Z.top+Z.height+Z.overscan,U=WQ(X,$,K,q,M,Q),A=j7(U,V),_=j7(U,G);if(A>0){let W=U.entries[A-1];if(W&&W.bottom>V)A-=1}if(_<U.entries.length){let W=U.entries[_];if(W&&W.top<G)_+=1}for(let W of D){let R=U.containerIndices.get(W);if(R===void 0)continue;A=Math.min(A,R),_=Math.max(_,R+1)}if(!Number.isFinite(A)||!Number.isFinite(_))return{estimateRegionBounds:U.estimateRegionBounds,layout:z5({...$,regions:[]},M,X,Q),totalHeight:U.totalHeight,viewport:Z};let N=HQ($,q,U.containerIndices,A,_),z=U.entries[N.startIndex]?.top??M.paddingY??0,E=z5({...$,regions:$.regions.slice(N.startIndex,N.endIndex)},M,X,Q),L=zQ(E,z,U.totalHeight);return FQ(X,$,L,M,Q),{estimateRegionBounds:U.estimateRegionBounds,layout:L,totalHeight:U.totalHeight,viewport:Z}}function FQ($,M,Z,J,X){for(let[Y,Q]of Z.regionBounds){let K=Q.bottom-Q.top,q=M.regionIndex.get(Y);d9($,O7(q??{path:Y,inlines:[],text:""},J,X),K)}}function zQ($,M,Z){return{...$,blocks:$.blocks.map((J)=>({...J,bottom:J.bottom+M,top:J.top+M})),regionBounds:new Map([...$.regionBounds.entries()].map(([J,X])=>[J,{bottom:X.bottom+M,left:X.left,right:X.right,top:X.top+M}])),height:Z,lines:$.lines.map((J)=>({...J,top:J.top+M}))}}function HQ($,M,Z,J,X){let Y=J,Q=X;for(let K=J;K<X;K+=1){let q=$.regions[K],D=M.get(q.blockId);if(!D)continue;if(D.type==="table"){let V=Z.get(D.regionIds[0]??""),G=Z.get(D.regionIds[D.regionIds.length-1]??"");if(V!==void 0)Y=Math.min(Y,V);if(G!==void 0)Q=Math.max(Q,G+1)}}return{endIndex:Q,startIndex:Y}}function EQ($,M,Z,J,X,Y){let Q=O7(M,X,Y),K=$.measuredContainerHeights.get(Q);if(K!==void 0)return K;let q=X.paddingX??0,D=X.indentWidth??24,V=T1(Z,X.lineHeight??24),G=q+J*D,U=Math.max(40,X.width-G-q);if(M.inlines.some((N)=>N.kind==="image")){let N=M2(Z);return Z2($,M,N,Z,U,V,Y).reduce((z,E)=>z+E.height,0)}let A=F5({text:M.text,width:U});return Math.max(V,A.lineCount*V)}function WQ($,M,Z,J,X,Y){let Q=wQ(M,X,Y),K=c9($,M,Q);if(K)return K;let q=X.paddingY??0,D=[],V=new Map;for(let G=0;G<M.regions.length;G+=1){let U=M.regions[G],A=Z.get(U.blockId)??null;if(A?.type==="table"){let E=yQ({block:A,blockMap:Z,containerIndices:V,entries:D,index:G,options:X,runtimeBlocks:J,totalHeight:q,regions:M.regions});if(E){G=E.nextIndex-1,q=E.totalHeight;continue}}let _=EQ($,U,A,J.get(U.blockId)?.depth??0,X,Y),N=q,z=N+_;D.push({bottom:z,top:N}),V.set(U.id,G),q=z+E5(J,Z,M.regions,G,X.blockGap??16)}return a9($,M,Q,{containerIndices:V,entries:D,estimateRegionBounds(G){let U=V.get(G);return U===void 0?null:D[U]??null},totalHeight:q})}function yQ({block:$,blockMap:M,containerIndices:Z,entries:J,index:X,options:Y,runtimeBlocks:Q,totalHeight:K,regions:q}){let D=Q.get($.id),V=D?.regionIds??[];if(V.length===0)return null;let G=q.slice(X,X+V.length);if(G.length===0||G[0]?.blockId!==$.id)return null;let U=Y.paddingX??0,A=Y.indentWidth??24,_=D?.depth??0,N=U+_*A,z=Math.max(Y6,Y.width-N-U),E=Math.max(1,...$.rows.map((y)=>y.cells.length)),L=z/E,W=Math.max(40,L-u2*2),R=T1($,Y.lineHeight??24),S=BQ(G,X),I=K;for(let y=0;y<$.rows.length;y+=1){let b=S.get(y)??[],H=Math.max(R+J2*2,...b.map(({region:B})=>PQ(B,W,R)+J2*2)),j=I+H;for(let{index:B,region:P}of b)J[B]={bottom:j,top:I},Z.set(P.id,B);I=j}for(let y=X;y<X+G.length;y+=1){let b=q[y];if(!b||J[y])continue;J[y]={bottom:I,top:I},Z.set(b.id,y)}return{nextIndex:X+G.length,totalHeight:I+E5(Q,M,q,X+G.length-1,Y.blockGap??16)}}function BQ($,M){let Z=new Map;for(let[J,X]of $.entries()){let Y=X.tableCellPosition?.rowIndex;if(Y===void 0)continue;let Q=Z.get(Y)??[];Q.push({index:M+J,region:X}),Z.set(Y,Q)}return Z}function PQ($,M,Z){let J=F5({text:$.text,width:M});return Math.max(Z,J.lineCount*Z)}function wQ($,M,Z){return[M.width,M.paddingX??0,M.paddingY??0,M.indentWidth??24,M.lineHeight??24,M.blockGap??16,bQ($,Z)].join(":")}function j7($,M){let Z=0,J=$.entries.length;while(Z<J){let X=Z+J>>1;if($.entries[X].bottom<=M)Z=X+1;else J=X}return Z}function O7($,M,Z){return`${_5($,Z)}:${M.width}:${M.paddingX??0}:${M.indentWidth??24}:${M.lineHeight??24}`}function bQ($,M){return $.regions.flatMap((Z)=>Z.inlines.filter((J)=>J.kind==="image"&&J.image).map((J)=>{let X=J.image?M.images.get(J.image.url):null;return`${J.image?.url??""}:${J.image?.width??0}:${X?.status??"loading"}:${X?.intrinsicWidth??0}:${X?.intrinsicHeight??0}`})).join("|")}var W5=null;function TQ($){let M=/(\d+(?:\.\d+)?)\s*px/.exec($);return M?Number.parseFloat(M[1]):16}function K1($){W5??=new Map;let M=W5.get($);if(M)return M;let Z=R7(),J=Math.max(12,Math.round(TQ($)));if(!Z){let U={ascent:Math.round(J*0.8),descent:Math.max(2,J-Math.round(J*0.8)),emHeight:J};return W5.set($,U),U}Z.font=$;let X=Z.measureText("Hg"),Y=Math.round(X.actualBoundingBoxAscent||0),Q=Math.round(X.actualBoundingBoxDescent||0),K=Y+Q,q=Math.max(J,K),D=K>0?Y:Math.round(q*0.8),V=K>0?Q:Math.max(2,q-D),G={ascent:D,descent:V,emHeight:q};return W5.set($,G),G}function jQ($,M){let{emHeight:Z}=K1(M);return Math.max(0,Math.floor(($-Z)/2))}function L7($,M){let{ascent:Z}=K1(M);return jQ($,M)+Z}var y5;function C7($,M){let Z=R7();if(!Z||$.length===0)return 0;return Z.font=M,Z.measureText($).width}function R7(){if(y5!==void 0)return y5;return y5=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(1,1):typeof document<"u"?document.createElement("canvas"):null)?.getContext("2d")??null,y5}var OQ=18,LQ=14,CQ=22;function b0($,M,Z){let J=SQ($,Z);if(!J)return null;return S7($,M,J,Z.x)}function V6($,M,Z){let J=$.lines[$.lines.length-1];if(!J||Z.y<=J.top+J.height)return null;return S7($,M,J,Z.x)}function S7($,M,Z,J){let X=$.regionMetrics.get(Z.regionId);if(!X)return null;let Y=Math.max(0,J-I0(M,Z)-Z.left),Q=T7(Z.boundaries,Y),K=Math.min(X.textLength,Z.start+Q);return{regionId:Z.regionId,offset:K,left:y0(Z,Q),top:Z.top,height:Z.height}}function U6($,M,Z,J){let X=F6(M,J.regionId);if(!X)return null;let Y=b0($,M,Z);if(Y)return{regionId:Y.regionId,offset:Y.offset};let Q=Z.y<mQ($);return{regionId:J.regionId,offset:Q?0:X.text.length}}function G6($,M,Z){let J=b0($,M,Z);if(!J)return null;let X=F6(M,J.regionId);if(!X||X.text.length===0)return null;let Y=J.offset<X.text.length&&/\w/.test(X.text[J.offset]??"")?J.offset:J.offset>0&&/\w/.test(X.text[J.offset-1]??"")?J.offset-1:J.offset,Q=fQ(X.text,Y);if(Q.start===Q.end)return null;return{anchor:{regionId:J.regionId,offset:Q.start},focus:{regionId:J.regionId,offset:Q.end}}}function k7($,M,Z){let J=kQ($,Z);if(!J||J.start!==0)return null;let X=X2(M,J.blockId,"listItem");if(!X)return null;if(p2(M,X.id)?.kind!=="task")return null;let Q=g2(J),K=Q.left-4,q=Q.left+Q.size+4,D=Q.top-4,V=Q.top+Q.size+4;return Z.x>=K&&Z.x<=q&&Z.y>=D&&Z.y<=V?{listItemId:X.id}:null}function m7($,M,Z){let J=b0($,M,Z);if(!J)return null;let X=F6(M,J.regionId);if(!X)return null;let Y=X.inlines.find((K)=>K.link&&J.offset>=K.start&&J.offset<K.end);if(!Y?.link)return null;let Q=_6($,M,J.regionId,Y.start);if(!Q)return null;return{anchorBottom:Q.anchorBottom,anchorLeft:Q.anchorLeft,endOffset:Y.end,regionId:J.regionId,startOffset:Y.start,title:Y.link.title,url:Y.link.url}}function A6($,M,Z,J){let X=k7($,M,Z);if(X)return{kind:"task-toggle",listItemId:X.listItemId};let Y=b0($,M,Z);if(!Y)return null;let Q=f7(Y.regionId,Y.offset,J),K=Q!==null?v7(Q,$,M,J):null,q=m7($,M,Z);if(q)return{anchorBottom:K?.anchorBottom??q.anchorBottom,anchorLeft:K?.anchorLeft??q.anchorLeft,endOffset:q.endOffset,kind:"link",commentThreadIndex:Q,regionId:q.regionId,startOffset:q.startOffset,title:q.title,url:q.url};return{anchorBottom:K?.anchorBottom??Y.top+Y.height,anchorLeft:K?.anchorLeft??Y.left,kind:"text",commentThreadIndex:Q}}function N6($,M,Z,J){let X=M.documentIndex.regionIndex.get(Z.regionId);if(!X)return null;let Y=f7(Z.regionId,Z.offset,J),Q=Y!==null?v7(Y,$,M,J):null,K=X.inlines.find((q)=>Z.offset>=q.start&&Z.offset<=q.end)??null;if(K?.link){let q=_6($,M,Z.regionId,K.start);if(!q)return null;return{anchorBottom:Q?.anchorBottom??q.anchorBottom,anchorLeft:Q?.anchorLeft??q.anchorLeft,commentThreadIndex:Y,endOffset:K.end,kind:"link",regionId:Z.regionId,startOffset:K.start,title:K.link.title,url:K.link.url}}if(Q)return{anchorBottom:Q.anchorBottom,anchorLeft:Q.anchorLeft,commentThreadIndex:Y,kind:"text"};return null}function p0($,M,Z){let J=L0(M,Z.regionId,Z.offset);if(!J)return Z.left;return Z.left+I0($,J)+RQ($,J,Z.offset)}function D1($,M,Z){return y0(M,Z)+I0($,M)}function I0($,M){let Z=X2($,M.blockId,"listItem");if(!Z)return 0;return p2($,Z.id)?.kind==="task"?CQ:OQ}function g2($){return{left:$.left,size:LQ,top:$.top+3}}function X2($,M,Z){let J=$.documentIndex.blockIndex.get(M)??null;while(J){if(J.type===Z)return J;let X=J.parentBlockId;J=X?$.documentIndex.blockIndex.get(X)??null:null}return null}function p2($,M){return $.documentIndex.listItemMarkers.get(M)??null}function f7($,M,Z){for(let J of Z)if(J.regionId===$&&M>=J.startOffset&&M<=J.endOffset)return J.threadIndex;return null}function v7($,M,Z,J){let X=J.find((Y)=>Y.threadIndex===$);if(!X)return null;return _6(M,Z,X.regionId,X.startOffset)}function _6($,M,Z,J){let X=L0($,Z,J);if(!X)return null;return{anchorBottom:X.top+X.height,anchorLeft:y0(X,J)+I0(M,X)}}function RQ($,M,Z){if(Z<=M.end)return 0;let J=$.documentIndex.regionIndex.get(M.regionId);if(!J)return 0;let X=J.text.slice(M.end,Z);if(!/^[ \t]+$/u.test(X))return 0;return C7(X,M.font)}function SQ($,M){for(let[J,X]of $.regionBounds)if(M.x>=X.left&&M.x<=X.right&&M.y>=X.top&&M.y<=X.bottom)return H5($,J,M.y)?.line??null;let Z=K6($,M)?.line??null;if(Z)return Z;for(let J of $.blocks)if(M.y>=J.top&&M.y<=J.bottom){for(let X=$.lines.length-1;X>=0;X--)if($.lines[X].blockId===J.id)return $.lines[X]}return null}function kQ($,M){return $.lines.find((Z)=>M.y>=Z.top-4&&M.y<=Z.top+Z.height+4)??$.lines.filter((Z)=>Math.abs(M.y-(Z.top+Z.height/2))<=10).sort((Z,J)=>Math.abs(M.y-(Z.top+Z.height/2))-Math.abs(M.y-(J.top+J.height/2)))[0]??null}function F6($,M){return $.documentIndex.regionIndex.get(M)??null}function mQ($){return $.lines[0]?.top??0}function fQ($,M){let Z=M,J=M;while(Z>0&&/\w/.test($[Z-1]??""))Z-=1;while(J<$.length&&/\w/.test($[J]??""))J+=1;return{end:J,start:Z}}function z6($,M,Z,J=null){let X={height:M.height,overscan:Math.max(160,M.height),top:M.top},Y=q6($.documentIndex,M,X,[$.selection.anchor.regionId,$.selection.focus.regionId],Z,J);return{blockMap:I2($.documentIndex.document.blocks),estimateRegionBounds:Y.estimateRegionBounds,regionBounds:new Map(Y.layout.regionBounds),layout:Y.layout,paintHeight:Math.max(240,X.height+X.overscan*2),paintTop:Math.max(0,X.top-X.overscan),totalHeight:Y.totalHeight,viewport:{height:X.height,top:X.top}}}function B5($,M,Z){return b0(M.layout,$,Z)??V6(M.layout,$,Z)}function l2($,M,Z,J){return U6(M.layout,$,Z,J)}function H6($,M,Z){return G6(M.layout,$,Z)}function E6($,M,Z,J){return A6(M.layout,$,Z,J)}function W6($,M,Z,J){return N6(M.layout,$,Z,J)}function y6($,M,Z){return g0(M.layout,$.documentIndex,Z)}function t0($,M,Z){let J=g0(M.layout,$.documentIndex,Z);if(!J)return null;return{...J,left:p0($,M.layout,J)}}function u7($,M,Z,J,X){let Y=J-Z,Q=X-Y;if(J<=$)return{end:M+Q,start:$+Q};if(Z>=M)return{end:M,start:$};let K=Math.max(0,Math.min(Z,M)-$),q=Math.max(0,M-Math.max(J,$)),D=$<Z?$:Z;return{end:D+K+X+q,start:D}}function P6($,M,Z){let J=Z.trim();if(J.length===0||M.startOffset===M.endOffset)return null;let X=$.regionIndex.get(M.regionId)??null,Y=X?B6($,X):null;if(!Y)return null;return g8({anchor:S2(Y,M.startOffset,M.endOffset),body:J,quote:k2(Y,M.startOffset,M.endOffset)})}function C0($){let M="documentIndex"in $?$.documentIndex:$,Z=P5(M),J=M.document.comments,X=[...J],Y=[];for(let[Q,K]of J.entries()){let q=m2(K,M.document);if(!q.match)continue;let V=Z.findBySemanticMatch(q.match.containerId,q.match.containerOrdinal)?.runtimeContainer??null;if(!V)continue;if(q.repair)X[Q]={...K,anchor:q.repair.anchor,quote:q.repair.quote};Y.push({endOffset:q.match.endOffset,resolution:q,regionId:V.id,resolved:K.resolvedAt!=null,startOffset:q.match.startOffset,threadIndex:Q})}return{liveRanges:Y,threads:X}}function w6($,M,Z,J,X,Y){if($.document.comments.length===0)return M.document.comments;let Q=$.commentContainerIndex.get(Z.semanticRegionId)??[],K=new Set(Q);if(Q.length===0)return M.document.comments;let q=C0($),D=new Map(q.liveRanges.map((A)=>[A.threadIndex,A])),V=B6($,Z),G=Y2(M,Z.path),U=G?B6(M,G):null;if(!V||!U)return M.document.comments;return M.document.comments.map((A,_)=>{if(!K.has(_))return A;let N=D.get(_),z=N?.resolution.match??null;if(!N||!z||z.containerId!==V.id)return A;let E=u7(z.startOffset,z.endOffset,J,X,Y.length);return{...A,anchor:S2(U,E.start,E.end),quote:k2(U,E.start,E.end)}})}function B6($,M){let Z=vQ($,M);if(!Z)return null;return{containerKind:Z,containerOrdinal:-1,id:M.semanticRegionId,text:M.text}}function vQ($,M){if($.tableCellIndex.has(M.id))return"tableCell";return m9(M.blockType)}function w5($,M){if(M.length===0)return[];let Z=P5($),J=Z.list();return M.map((X)=>({...X,cursorPoint:uQ(X,J,Z),viewport:null}))}function uQ($,M,Z){if(!$.cursor)return null;let J=hQ(M,$.cursor),X=IQ(J,$.cursor);if(X.length!==1)return null;let Y=X[0],Q=Z.resolveRuntimeContainer(Y.container.id);if(!Q)return null;return{offset:Math.max(0,Math.min(Y.offset,Q.text.length)),regionId:Q.id}}function hQ($,M){return M.kind?$.filter((Z)=>Z.containerKind===M.kind):$}function IQ($,M){if(M.prefix&&M.suffix)return gQ($,M.prefix,M.suffix);if(M.prefix)return h7($,M.prefix,"after");if(M.suffix)return h7($,M.suffix,"before");return[]}function h7($,M,Z){let J=[];for(let X of $)for(let Y of h0(X.text,M))J.push({container:X,offset:Z==="after"?Y+M.length:Y});return J}function gQ($,M,Z){let J=[];for(let X of $)for(let Y of o1(X.text,M,Z))J.push({container:X,offset:Y.startOffset});return J}var pQ=48;function x2($,M,Z){let J="documentIndex"in $?$.documentIndex:$;if(Z.length===0)return[];return Z.map((X)=>({...X,viewport:lQ(J,M,X)}))}function lQ($,M,Z){if(!Z.cursorPoint)return{status:"unresolved"};let J=g0(M.layout,$,Z.cursorPoint),X=J?{bottom:J.top+J.height,top:J.top}:M.estimateRegionBounds(Z.cursorPoint.regionId);if(!X)return{status:"unresolved"};return{scrollTop:dQ(M,X),status:xQ(M,X)}}function xQ($,M){let Z=$.viewport.top,J=Z+$.viewport.height;if(M.bottom<Z)return"above";if(M.top>J)return"below";return"visible"}function dQ($,M){let Z=Math.max(0,$.totalHeight-$.viewport.height),J=M.top-Math.min(pQ,$.viewport.height/4);return Math.max(0,Math.min(Z,J))}function P5($){let M=D5($.document),Z=new Map(M.map((X)=>[X.id,X])),J=new Map($.regions.map((X)=>[X.semanticRegionId,X]));return{findBySemanticMatch(X,Y){let Q=Z.get(X)??M[Y]??null;if(!Q)return null;return{runtimeContainer:J.get(Q.id)??null,semanticContainer:Q}},list(X){return X?M.filter((Y)=>Y.containerKind===X):M},resolveRuntimeContainer(X){return J.get(X)??null}}}var d2="",I7=1e6;function r2($,M,Z){return`${$}:${M}:${Z}`}function Q2($){let M=VK($),Z=T6(M.blocks.map((J,X)=>a2(J,X)));return j6(M,Z)}function a2($,M){let Z=[],J=[],X=[],Y=new Set,Q=0;function K(D,V,G,U,A=null){if(J.length>0)X.push(`
|
|
20
|
+
`),Q+=1;let _=G.map((E)=>E.text).join(""),N=Q,z=N+_.length;X.push(_),Q=z;for(let E of G)if(E.image)Y.add(E.image.url);J.push({blockId:D.id,blockType:D.type,end:z,id:`${D.id}:${V}`,path:V,rootIndex:M,inlines:G,semanticRegionId:U,start:N,tableCellPosition:A,text:_})}function q(D,V,G,U){let A={childBlockIds:[],depth:G,end:Q,id:D.id,parentBlockId:U,path:V,regionIds:[],rootIndex:M,start:Q,type:D.type};switch(Z.push(A),D.type){case"blockquote":case"listItem":for(let[_,N]of D.children.entries())A.childBlockIds.push(N.id),q(N,`${V}.children.${_}`,G+1,D.id);break;case"code":{K(D,`${V}.source`,[{end:D.source.length,id:`${D.id}:code`,image:null,inlineCode:!1,kind:"text",link:null,marks:[],originalType:null,start:0,text:D.source}],D.id),A.regionIds.push(J.at(-1).id);break}case"heading":case"paragraph":K(D,`${V}.children`,b6(D.children),D.id),A.regionIds.push(J.at(-1).id);break;case"list":for(let[_,N]of D.items.entries())A.childBlockIds.push(N.id),q(N,`${V}.children.${_}`,G+1,D.id);break;case"table":for(let[_,N]of D.rows.entries())for(let[z,E]of N.cells.entries())K(D,`${V}.rows.${_}.cells.${z}`,b6(E.children),E.id,{cellIndex:z,rowIndex:_}),A.regionIds.push(J.at(-1).id);break;case"thematicBreak":break;case"directive":break;case"unsupported":K(D,`${V}.source`,[{end:D.source.length,id:`${D.id}:unsupported`,image:null,inlineCode:!1,kind:"unsupported",link:null,marks:[],originalType:D.originalType,start:0,text:D.source}],D.id),A.regionIds.push(J.at(-1).id);break}A.end=Q}return q($,`root.${M}`,0,null),{blockRange:{end:Z.length,start:0},blocks:Z,end:Q,imageUrls:Y,length:Q,regionRange:J.length>0?{end:J.length,start:0}:void 0,regions:J,rootIndex:M,start:0,text:X.join("")}}function T6($,M=null){let Z=[],J=0,X=0,Y=0,Q=!1;for(let[K,q]of $.entries()){if(q.regions.length>0&&Q)Y+=1;let D={...q,blockRange:{end:J+q.blocks.length,start:J},end:Y+q.length,regionRange:q.regions.length>0?{end:X+q.regions.length,start:X}:void 0,start:Y},V=M?.[K];if(Z.push(cQ(V,q,D)?V:g7(q,D)),J=D.blockRange.end,X=D.regionRange?.end??X,q.regions.length>0)Y=D.end,Q=!0}return Z}function K2($,M,Z,J){let X=M.blocks.length-($.roots.length-J);if(X<0)throw Error("Editor model splice received an invalid replacement count.");if(Z===$.roots.length&&X===1){let q=M.blocks[Z];if(q)return rQ($,M,q)}let Y=X===J,Q=[...$.roots.slice(0,Z),...M.blocks.slice(Z,Z+X).map((q,D)=>a2(q,Z+D)),...Y?$.roots.slice(Z+J):M.blocks.slice(Z+X).map((q,D)=>a2(q,Z+X+D))],K=T6(Q,$.roots);return j6(M,K,$)}function rQ($,M,Z){let J=$.roots.length,X=a2(Z,J),Y=$.roots.some((V)=>V.regions.length>0),Q=X.regions.length>0&&Y?$.length+1:$.length,K=g7(X,{...X,blockRange:{end:$.blocks.length+X.blocks.length,start:$.blocks.length},end:Q+X.length,regionRange:X.regions.length>0?{end:$.regions.length+X.regions.length,start:$.regions.length}:void 0,start:Q}),q=[...$.blocks,...K.blocks],D=[...$.regions,...K.regions];return{blockIndex:nQ($.blockIndex,K.blocks),blocks:q,commentContainerIndex:M.comments===$.document.comments?$.commentContainerIndex:p7(M),document:M,engine:"canvas",imageUrls:KK($.imageUrls,K.imageUrls),length:K.end,listItemMarkers:M.blocks===$.document.blocks?$.listItemMarkers:JK($.listItemMarkers,Z),regionIndex:tQ($.regionIndex,K.regions),regionOrderIndex:eQ($.regionOrderIndex,K.regions,$.regions.length),regionPathIndex:$K($.regionPathIndex,K.regions),regions:D,roots:[...$.roots,K],tableCellIndex:MK($.tableCellIndex,K.regions),tableCellRegionIndex:ZK($.tableCellRegionIndex,K.regions),text:XK($.text,K)}}function b5($,M){if(M.blocks!==$.document.blocks)throw Error("Editor model document replacement requires preserving root blocks.");return j6(M,$.roots,$)}function T5($,M,Z){let J=$.blockIndex.get(M);if(!J)return null;return j9($.document,M,Z,J.rootIndex)}function j6($,M,Z=null){let J=M.flatMap((V)=>V.blocks),X=M.flatMap((V)=>V.regions),{regionIndex:Y,regionOrderIndex:Q,regionPathIndex:K,tableCellIndex:q,tableCellRegionIndex:D}=oQ(X);return{blockIndex:sQ(J),blocks:J,commentContainerIndex:$.comments===Z?.document.comments?Z.commentContainerIndex:p7($),document:$,engine:"canvas",imageUrls:QK(M,Z?.imageUrls),length:M.at(-1)?.end??0,listItemMarkers:$.blocks===Z?.document.blocks?Z.listItemMarkers:qK($.blocks),regionIndex:Y,regionOrderIndex:Q,regionPathIndex:K,regions:X,roots:M,tableCellIndex:q,tableCellRegionIndex:D,text:YK(M)}}function g7($,M){let Z=M.start-$.start;return{...M,blocks:Z===0?$.blocks:aQ($.blocks,Z),regions:Z===0?$.regions:iQ($.regions,Z)}}function cQ($,M,Z){return Boolean($&&M===$&&$.start===Z.start&&$.end===Z.end&&$.blockRange.start===Z.blockRange.start&&$.blockRange.end===Z.blockRange.end&&$.regionRange?.start===Z.regionRange?.start&&$.regionRange?.end===Z.regionRange?.end)}function aQ($,M){return $.map((Z)=>({...Z,end:Z.end+M,start:Z.start+M}))}function iQ($,M){return $.map((Z)=>({...Z,end:Z.end+M,start:Z.start+M}))}function sQ($){let M=new Map;for(let Z of $)M.set(Z.id,Z);return M}function oQ($){let M=new Map,Z=new Map,J=new Map,X=new Map,Y=new Map;for(let[Q,K]of $.entries()){if(M.set(K.id,K),Z.set(K.id,Q),J.set(K.path,K),!K.tableCellPosition)continue;X.set(K.id,K.tableCellPosition),Y.set(r2(K.blockId,K.tableCellPosition.rowIndex,K.tableCellPosition.cellIndex),K.id)}return{regionIndex:M,regionOrderIndex:Z,regionPathIndex:J,tableCellIndex:X,tableCellRegionIndex:Y}}function nQ($,M){let Z=new Map($);for(let J of M)Z.set(J.id,J);return Z}function tQ($,M){let Z=new Map($);for(let J of M)Z.set(J.id,J);return Z}function eQ($,M,Z){let J=new Map($);for(let[X,Y]of M.entries())J.set(Y.id,Z+X);return J}function $K($,M){let Z=new Map($);for(let J of M)Z.set(J.path,J);return Z}function MK($,M){let Z=new Map($);for(let J of M)if(J.tableCellPosition)Z.set(J.id,J.tableCellPosition);return Z}function ZK($,M){let Z=new Map($);for(let J of M){if(!J.tableCellPosition)continue;Z.set(r2(J.blockId,J.tableCellPosition.rowIndex,J.tableCellPosition.cellIndex),J.id)}return Z}function JK($,M){let Z=new Map($);return c2(Z,[M]),Z}function XK($,M){if(M.regions.length===0)return $;return $.length>0?`${$}
|
|
21
|
+
${M.text}`:M.text}function YK($){return $.filter((M)=>M.regions.length>0).map((M)=>M.text).join(`
|
|
22
|
+
`)}function QK($,M){let Z=new Set;for(let J of $)for(let X of J.imageUrls)Z.add(X);return M&&DK(M,Z)?M:Z}function KK($,M){if(M.size===0)return $;let Z=null;for(let J of M){if($.has(J))continue;Z??=new Set($),Z.add(J)}return Z??$}function DK($,M){if($.size!==M.size)return!1;for(let Z of $)if(!M.has(Z))return!1;return!0}function p7($){let M=new Map;for(let[Z,J]of $.comments.entries()){let X=m2(J,$).match?.containerId??null;if(!X)continue;let Y=M.get(X)??[];Y.push(Z),M.set(X,Y)}return M}function qK($){let M=new Map;return c2(M,$),M}function c2($,M,Z=null){for(let J of M){if(J.type==="list"){for(let[X,Y]of J.items.entries())c2($,[Y],{index:X,ordered:J.ordered,start:J.start});continue}if(J.type==="listItem"){if(typeof J.checked==="boolean")$.set(J.id,{checked:J.checked,kind:"task"});else if(Z?.ordered)$.set(J.id,{kind:"ordered",label:`${(Z.start??1)+Z.index}.`});else $.set(J.id,{kind:"bullet",label:"•"});c2($,J.children,Z)}if(J.type==="blockquote")c2($,J.children,Z)}}function VK($){if($.blocks.length>0)return $;return a1([x({text:""})],$.comments,$.frontMatter)}function b6($,M=null){let Z=[],J=0,X=(Y)=>{let Q=J,K=Q+Y.text.length;Z.push({...Y,end:K,start:Q}),J=K};for(let Y of $)switch(Y.type){case"break":X({id:Y.id,image:null,inlineCode:!1,kind:"break",link:M,marks:[],originalType:null,text:`
|
|
23
|
+
`});break;case"image":X({id:Y.id,image:{alt:Y.alt,title:Y.title,url:Y.url,width:Y.width},inlineCode:!1,kind:"image",link:M,marks:[],originalType:null,text:UK(Y.alt)});break;case"inlineCode":X({id:Y.id,image:null,inlineCode:!0,kind:"inlineCode",link:M,marks:[],originalType:null,text:Y.code});break;case"link":for(let Q of b6(Y.children,{title:Y.title,url:Y.url}))X(Q);break;case"text":X({id:Y.id,image:null,inlineCode:!1,kind:"text",link:M,marks:Y.marks,originalType:null,text:Y.text});break;case"unsupported":X({id:Y.id,image:null,inlineCode:!1,kind:"unsupported",link:M,marks:[],originalType:Y.originalType,text:Y.source});break}return Z}function UK($){return d2}function H0($){switch($.type){case"break":return 1;case"image":return d2.length;case"inlineCode":return $.code.length;case"link":return X0($.children).length;case"text":return $.text.length;case"unsupported":return $.source.length}}function i2($,M,Z,J,X){let Y=[],Q=0,K=!1;for(let[q,D]of $.entries()){let V=`${J}.${q}`,G=H0(D),U=Q,A=U+G;if(Q=A,Z<=U||M>=A){Y.push(D);continue}if(!K)Y.push(...GK(D,Math.max(0,M-U),V)),Y.push(...X),K=!0;Y.push(...AK(D,Math.min(G,Z-U),V))}if(!K)Y.push(...X);return z0(Y)}function GK($,M,Z){if(M<=0)return[];return O6($,0,M,`${Z}.before`)}function AK($,M,Z){let J=H0($);if(M>=J)return[];return O6($,M,J,`${Z}.after`)}function O6($,M,Z,J){if(M>=Z)return[];switch($.type){case"text":return z0([j1($.text.slice(M,Z),$.marks,J)].filter(Boolean));case"inlineCode":return[C6($.code.slice(M,Z),J)];case"link":{let X=z0(NK($.children,M,Z,`${J}.children`));return X.length>0?[{...$,children:X}]:[]}default:return[]}}function L6($,M,Z){let J=0,X="";for(let Y of $){let Q=H0(Y),K=J,q=K+Q;if(J=q,Z<=K||M>=q)continue;X+=_K(Y,Math.max(0,M-K),Math.min(Q,Z-K))}return X}function j1($,M,Z){if($.length===0)return null;return i0({marks:M,path:Z,text:$})}function C6($,M){return d1({code:$,path:M})}function NK($,M,Z,J){let X=[],Y=0;for(let[Q,K]of $.entries()){let q=H0(K),D=Y,V=D+q;if(Y=V,Z<=D||M>=V)continue;X.push(...O6(K,Math.max(0,M-D),Math.min(q,Z-D),`${J}.${Q}`))}return X}function _K($,M,Z){if(M>=Z)return"";switch($.type){case"break":return`
|
|
24
|
+
`.slice(M,Z);case"image":return d2.slice(M,Z);case"inlineCode":return $.code.slice(M,Z);case"link":return L6($.children,M,Z);case"text":return $.text.slice(M,Z);case"unsupported":return $.source.slice(M,Z)}}function R6($,M,Z,J){let X=FK($.children,M,Z,J);if(X===null)return null;let Y=z0(l7($.children,M,Z,J,X,`${$.path}.children`));return Y.length>0?O1($,Y,M,Z):null}function S6($,M,Z){let J=0,X=null,Y=(Q)=>{for(let K of Q){let q=H0(K),D=J,V=D+q;if(J=V,Z<=D||M>=V)continue;if(K.type==="text"){let G=Math.max(M,D);if(Math.min(Z,V)>G)X=X===null?new Set(K.marks):new Set(K.marks.filter((A)=>X?.has(A)));continue}if(K.type==="link"){let G=J;J=D,Y(K.children),J=G}}};return Y($.children),X?[...X]:[]}function FK($,M,Z,J){let X=0,Y=!1,Q=!0,K=(q)=>{for(let D of q){let V=H0(D),G=X,U=G+V;if(X=U,Z<=G||M>=U)continue;if(D.type==="text"){let A=Math.max(M,G);if(Math.min(Z,U)>A)Y=!0,Q&&=D.marks.includes(J);continue}if(D.type==="link"){let A=X;X=G,K(D.children),X=A}}};return K($),Y?Q:null}function l7($,M,Z,J,X,Y){let Q=[],K=0;for(let[q,D]of $.entries()){let V=K,G=H0(D),U=V+G,A=`${Y}.${q}`;if(K=U,Z<=V||M>=U){Q.push(D);continue}if(D.type==="text"){Q.push(...zK(D,Math.max(0,M-V),Math.min(G,Z-V),J,X,A));continue}if(D.type==="link"){let _=z0(l7(D.children,Math.max(0,M-V),Math.min(G,Z-V),J,X,`${A}.children`));if(_.length>0)Q.push({...D,children:_});continue}Q.push(D)}return Q}function zK($,M,Z,J,X,Y){let Q=$.text.slice(0,M),K=$.text.slice(M,Z),q=$.text.slice(Z),D=X?$.marks.filter((V)=>V!==J):HK($.marks,J);return[j1(Q,$.marks,`${Y}.before`),j1(K,D,`${Y}.selected`),j1(q,$.marks,`${Y}.after`)].filter(Boolean)}function HK($,M){return $.includes(M)?$:[...$,M].sort()}function k6($,M,Z){let J=EK($.children,M,Z,`${$.path}.children`);return J.length>0?O1($,J,M,Z):null}function EK($,M,Z,J){let X=x7($,M,Z);if(X){let Q=j1(X.code,[],`${J}.selected`);return i2($,M,Z,J,Q?[Q]:[])}let Y=L6($,M,Z);if(Y.length===0)return $;return i2($,M,Z,J,[C6(Y,`${J}.selected`)])}function x7($,M,Z){let J=0;for(let X of $){let Y=H0(X),Q=J,K=Q+Y;if(J=K,M===Q&&Z===K&&X.type==="inlineCode")return X;if(X.type==="link"){let q=x7(X.children,Math.max(0,M-Q),Math.min(Y,Z-Q));if(q)return q}}return null}function m6($,M,Z,J,X){return j5($,M,Z,J,(Y,Q,K)=>d7(Y,Q,K,X))}function d7($,M,Z,J){let X=z0(WK($.children,M,Z,J,`${$.path}.children`)??[]);return X.length>0?O1($,X,M,Z):null}function WK($,M,Z,J,X){let Y=[],Q=0,K=!1;for(let[q,D]of $.entries()){let V=`${X}.${q}`,G=H0(D),U=Q,A=U+G;if(Q=A,!K&&D.type==="link"&&M===U&&Z===A){if(J===null)Y.push(...D.children);else Y.push(r1({children:D.children,path:V,title:D.title,url:J}));K=!0;continue}Y.push(D)}return K?Y:null}function D2($,M){let Z=$.regionIndex.get(M);if(!Z)return null;let J=s1($.document.blocks,Z.blockId);if(!J)return null;return f6(J,Z.path,Z.semanticRegionId)}function yK($,M,Z,J,X){if(Z>=J)return null;let Y=D2($,M);return Y?X(Y,Z,J):null}function j5($,M,Z,J,X){let Y=yK($,M,Z,J,X);return Y?{kind:"replace-block",block:Y.block,blockId:Y.blockId,selection:Y.selection}:null}function f6($,M,Z){if($.type==="heading"||$.type==="paragraph")return{block:$,children:$.children,kind:"inlineBlock",path:M.replace(/\.children$/,"")};if($.type!=="table")return null;let J=/^(.*\.rows\.\d+\.cells\.\d+)$/.exec(M);if(!J)return null;for(let X of $.rows)for(let Y of X.cells)if(Y.id===Z)return{block:$,blockPath:J[1].replace(/\.rows\.\d+\.cells\.\d+$/,""),cell:Y,children:Y.children,kind:"tableCell",path:J[1]};return null}function c7($,M,Z){let J=s7($,M);if(!J)return null;return{kind:"replace-block",...s2(J.inlineRegion,J.startOffset,J.endOffset,Z)}}function a7($,M,Z){let J=s7($,M);if(!J)return null;return{kind:"replace-block",...i7(J.inlineRegion,J.startOffset,J.endOffset,Z)}}function i7($,M,Z,J){let X=`${$.path}.children`,Y=i2($.children,M,Z,X,J),Q=J.reduce((q,D)=>q+H0(D),0),K=M+Q;return O1($,Y,K,K)}function s2($,M,Z,J){let X=J(`${$.path}.children.selected`);return i7($,M,Z,[X])}function s7($,M){let Z=D2($,M.focus.regionId);if(!Z)return null;return{inlineRegion:Z,startOffset:Math.min(M.anchor.offset,M.focus.offset),endOffset:Math.max(M.anchor.offset,M.focus.offset)}}function O1($,M,Z,J){switch($.kind){case"inlineBlock":return{block:u0($.block,M),blockId:$.block.id,selection:r7(`${$.path}.children`,Z,J)};case"tableCell":{let X=J1({children:M,path:$.path}),Y=$.block.rows.map((Q)=>({...Q,cells:Q.cells.map((K)=>K.id===$.cell.id?X:K)}));return{block:w0($.block,Y),blockId:$.block.id,selection:r7($.path,Z,J)}}}}function r7($,M,Z){return{endOffset:Z,kind:"region-range-path",path:$,startOffset:M}}function q0($,M,Z=0){return{childIndices:M,kind:"descendant-primary-region",offset:Z,rootIndex:$}}function $0($,M=0){return{kind:"root-primary-region",offset:M,rootIndex:$}}function L1($,M,Z,J=0){return{cellIndex:Z,kind:"table-cell",offset:J,rootIndex:$,rowIndex:M}}function B0($,M){return $.regionIndex.get(M)??null}function Y2($,M){return $.regionPathIndex.get(M)??null}function V2($,M,Z,J){let X=$.tableCellRegionIndex.get(r2(M,Z,J));return X?$.regionIndex.get(X)??null:null}function BK($){return $.anchor.regionId===$.focus.regionId&&$.anchor.offset===$.focus.offset}function J0($,M){let Z="documentIndex"in $?$.documentIndex:$,J="documentIndex"in $?$.selection:M,X=BK(J),Y=o7(Z,J.anchor),Q=o7(Z,J.focus);if(Y<=Q)return{collapsed:X,end:J.focus,start:J.anchor};return{collapsed:X,end:J.anchor,start:J.focus}}function o2($,M){if(!M)return null;if("kind"in M){if(M.kind==="root-primary-region"){let J=$.document.blocks[M.rootIndex],X=J?v6($,J):null;return X?q2(X.id,O5(X.text,M.offset)):null}if(M.kind==="descendant-primary-region"){let J=$.document.blocks[M.rootIndex],X=J?PK(J,M.childIndices):null,Y=X?v6($,X):null;return Y?q2(Y.id,O5(Y.text,M.offset)):null}if(M.kind==="table-cell"){let J=$.document.blocks[M.rootIndex];if(!J||J.type!=="table")return null;let X=V2($,J.id,M.rowIndex,M.cellIndex);return X?q2(X.id,O5(X.text,M.offset)):null}let Z=Y2($,M.path);if(!Z)return null;if(M.kind==="region-path")return q2(Z.id,O5(Z.text,M.offset));return{anchor:{regionId:Z.id,offset:Math.max(0,Math.min(M.startOffset,Z.text.length))},focus:{regionId:Z.id,offset:Math.max(0,Math.min(M.endOffset,Z.text.length))}}}return M}function o7($,M){let Z=$.regionOrderIndex.get(M.regionId);if(Z===void 0)throw Error(`Unknown canvas region: ${M.regionId}`);return Z*I7+M.offset}function q2($,M){let Z={offset:M,regionId:$};return{anchor:Z,focus:Z}}function O5($,M){return M==="end"?$.length:Math.max(0,Math.min(M,$.length))}function PK($,M){let Z=$;for(let J of M){if(!Z)return null;let X=A0(Z);if(!X)return null;Z=X[J]??null}return Z}function v6($,M){let Z=$.blockIndex.get(M.id);if(!Z)return null;let J=Z.regionIds[0];if(J)return $.regionIndex.get(J)??null;let X=A0(M);if(!X)return null;for(let Y of X){let Q=v6($,Y);if(Q)return Q}return null}function n2($){let M=$.documentIndex.regionIndex.get($.selection.anchor.regionId)??null,Z=M?$.documentIndex.blockIndex.get(M.blockId)??null:null,J=$.selection.anchor.offset,X=M?.inlines.find((Y)=>J>Y.start&&J<Y.end)??M?.inlines.find((Y)=>Y.end===J)??M?.inlines.find((Y)=>Y.start===J)??null;return{block:Z?{blockId:Z.id,depth:Z.depth,nodeType:Z.type,text:M?.text??""}:null,span:X?.link?{kind:"link",url:X.link.url}:X&&X.marks.length>0?{kind:"marks",marks:X.marks}:{kind:"none"}}}function L5($){let M=$.documentIndex.regionIndex.get($.selection.anchor.regionId)??null,Z=$.selection.anchor.offset,J=M?.inlines.find((X)=>Z>X.start&&Z<X.end)??M?.inlines.find((X)=>X.end===Z)??M?.inlines.find((X)=>X.start===Z)??null;return J?.kind==="image"?J:null}function C5($){let M=J0($.documentIndex,$.selection);if(M.start.regionId!==M.end.regionId||M.start.offset===M.end.offset)return[];let Z=$.documentIndex.regionIndex.get(M.start.regionId);if(!Z)return[];let J=s1($.documentIndex.document.blocks,Z.blockId);if(!J)return[];let X=f6(J,Z.path,Z.semanticRegionId);return X?S6(X,M.start.offset,M.end.offset):[]}var u6=new Map([["rgba(0, 0, 0, 0)",[0,0,0,0]]]);function t2($){switch($.kind){case"active-block-flash":return 300;case"deleted-text-fade":return 180;case"inserted-text-highlight":return 1000;case"list-marker-pop":return 500;case"punctuation-pulse":return 140}}function I6($,M){let Z=M??bK();return $.animations.some((J)=>Z-J.startedAt<t2(J))}function t7($,M){return g6($,M,"inserted-text-highlight",(Z)=>Z.regionPath)}function e7($,M){return q$($,M,"active-block-flash",(Z)=>Z.blockPath)}function $$($,M){return g6($,M,"deleted-text-fade",(Z)=>Z.regionPath)}function M$($,M){return g6($,M,"punctuation-pulse",(Z)=>Z.regionPath)}function Z$($,M){return q$($,M,"list-marker-pop",(Z)=>Z.blockPath)}function J$($,M,Z){let J=new Set([$,M]);for(let X of Z){if(X.endOffset<=$||X.startOffset>=M)continue;J.add(Math.max($,X.startOffset)),J.add(Math.min(M,X.endOffset))}return[...J].sort((X,Y)=>X-Y)}function X$($,M,Z){return $.find((J)=>J.startOffset<Z&&J.endOffset>M)??null}function Y$($,M,Z){if(!M)return $;return $4(Z.insertHighlightText,$,M.progress)}function Q$($,M){return $4($,"rgba(0, 0, 0, 0)",M.progress)}function S5($,M){return $4($,"rgba(0, 0, 0, 0)",M.progress)}function K$($,M){return $4(M.insertHighlightText,"rgba(0, 0, 0, 0)",$.progress)}function D$($){let M=Math.min(1,$.progress*2);return 0.1+0.9*wK(M)}function e2($,M,Z){let J=Math.max(0,M.progress*2-1);return $4(Z.insertHighlightText,$,J)}function g6($,M,Z,J){let X=new Map;for(let Y of $.animations){if(Y.kind!==Z)continue;let Q=t2(Y),K=M-Y.startedAt;if(K>=Q)continue;let q={...Y,progress:Math.max(0,Math.min(1,K/Q))},D=J(Y),V=X.get(D);if(V)V.push(q);else X.set(D,[q])}return X}function q$($,M,Z,J){let X=new Map;for(let Y of $.animations){if(Y.kind!==Z)continue;let Q=t2(Y),K=M-Y.startedAt;if(K>=Q)continue;X.set(J(Y),{...Y,progress:Math.max(0,Math.min(1,K/Q))})}return X}function wK($){return 1-(1-$)*(1-$)*(1-$)}function $4($,M,Z){let J=n7($),X=n7(M);return`rgba(${h6(R5(J[0],X[0],Z))}, ${h6(R5(J[1],X[1],Z))}, ${h6(R5(J[2],X[2],Z))}, ${R5(J[3],X[3],Z)})`}function bK(){return typeof performance<"u"?performance.now():Date.now()}function n7($){let M=u6.get($);if(M)return M;let Z=TK($)??jK($)??OK($)??u6.get("rgba(0, 0, 0, 0)");return u6.set($,Z),Z}function TK($){let M=$.trim();if(!M.startsWith("#"))return null;let Z=M.slice(1);if(Z.length===3)return[Number.parseInt(`${Z[0]}${Z[0]}`,16),Number.parseInt(`${Z[1]}${Z[1]}`,16),Number.parseInt(`${Z[2]}${Z[2]}`,16),1];if(Z.length===6)return[Number.parseInt(Z.slice(0,2),16),Number.parseInt(Z.slice(2,4),16),Number.parseInt(Z.slice(4,6),16),1];return null}function jK($){let M=/^rgb\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec($.trim());if(!M)return null;return[Number(M[1]),Number(M[2]),Number(M[3]),1]}function OK($){let M=/^rgba\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)\s*\)$/i.exec($.trim());if(!M)return null;return[Number(M[1]),Number(M[2]),Number(M[3]),Number(M[4])]}function R5($,M,Z){return $+(M-$)*Z}function h6($){return Math.round($)}function k5($,M,Z=C1()){if(M<=0)return $;let J=f5($);if(!J)return $;let X=$.selection.focus.offset,Y=Math.max(0,X-M);if(X<=Y)return $;return M4($,{endOffset:X,kind:"inserted-text-highlight",regionPath:J.path,startOffset:Y,startedAt:Z})}function V$($,M,Z,J){let X=f5($);if(!X)return M;let Y=X.text.slice(Z,J);if(Y.length===0)return M;if(!X.inlines.some((K)=>K.start<=Z&&K.end>=J&&K.kind==="text"&&K.link===null&&K.marks.length===0))return M;return M4(M,{kind:"deleted-text-fade",regionPath:X.path,startOffset:Z,startedAt:C1(),text:Y})}function U$($,M=C1()){let Z=f5($),J=$.selection.focus.offset-1;if(!Z||J<0||Z.text[J]!==".")return $;return M4($,{kind:"punctuation-pulse",offset:J,regionPath:Z.path,startedAt:M})}function G$($,M,Z=C1()){return M4($,{blockPath:M,kind:"list-marker-pop",startedAt:Z})}function A$($,M,Z=C1()){return M4($,{blockPath:M,kind:"active-block-flash",startedAt:Z})}function p6($,M){return $.filter((Z)=>Z.startedAt+t2(Z)>M)}function C1(){return typeof performance<"u"?performance.now():Date.now()}function m5($,M){let Z=Math.max(-1/0,...$.animations.map((J)=>J.startedAt));return M.animations.some((J)=>J.startedAt>Z)}function N$($){let M=f5($);return(M?$.documentIndex.blockIndex.get(M.blockId)??null:null)?.path??""}function f5($){return $.documentIndex.regionIndex.get($.selection.focus.regionId)??null}function M4($,M){let Z=p6($.animations,M.startedAt);return{...$,animations:[...Z,M]}}function U2($,M,Z,J){return x6(G2($.inlines,M,Z,J))}function G2($,M,Z,J){let Y=LK($,M,Z,{didInsert:!1,generatedRunCount:0,replacementText:J});return mK(fK(Y))}function x6($){let M=[];for(let Z=0;Z<$.length;Z+=1){let J=$[Z];if(J.link){let Y=[],Q=J.link;while(Z<$.length&&d6($[Z].link,Q)){let K=F$($[Z]);if(K)Y.push(K);Z+=1}if(Z-=1,Y.length>0)M.push(r1({children:z0(Y),title:Q.title,url:Q.url}));continue}let X=F$(J);if(X)M.push(X)}return z0(M)}function LK($,M,Z,J){let X=[];for(let[Y,Q]of $.entries()){if(!J.didInsert&&M===Z&&M===Q.start)l6(X,J,_$($[Y-1]??null,Q));if(Z<=Q.start||M>=Q.end){X.push(v5(Q));continue}let K=Math.max(0,M-Q.start),q=Math.min(Q.text.length,Z-Q.start),D=!J.didInsert&&J.replacementText.length>0?J.replacementText:"",V=CK(Q,K,q,D,J);if(K!==q||D.length>0)J.didInsert=!0;X.push(...V)}if(!J.didInsert)l6(X,J,_$($.at(-1)??null,null));return X}function CK($,M,Z,J,X){switch($.kind){case"text":case"inlineCode":case"unsupported":return RK($,M,Z,J);case"break":return SK($,M,Z,J,X);case"image":return kK($,M,Z,J)}}function RK($,M,Z,J){let X=$.text.slice(0,M)+J+$.text.slice(Z);return X.length>0?[{...v5($),text:X}]:[]}function SK($,M,Z,J,X){if(M===Z)return[v5($)];let Y=[];if(J.length>0)l6(Y,X,$.link);return Y}function kK($,M,Z,J){if(M===0&&Z===$.text.length)return J.length>0?[z$(J,$.link,0)]:[];return[v5($)]}function l6($,M,Z){if(M.replacementText.length===0){M.didInsert=!0;return}$.push(z$(M.replacementText,Z,M.generatedRunCount)),M.generatedRunCount+=1,M.didInsert=!0}function z$($,M,Z){return{id:`generated:${Z}`,image:null,inlineCode:!1,kind:"text",link:M,marks:[],originalType:null,text:$}}function _$($,M){return $?.link&&M?.link&&d6($.link,M.link)?$.link:null}function v5($){return{id:$.id,image:$.image,inlineCode:$.inlineCode,kind:$.kind,link:$.link,marks:$.marks,originalType:$.originalType,text:$.text}}function mK($){let M=[],Z=0;for(let J of $){let X=Z,Y=X+J.text.length;M.push({...J,end:Y,start:X}),Z=Y}return M}function fK($){let M=[];for(let Z of $){let J=M.at(-1);if(J&&vK(J,Z)){M[M.length-1]={...J,text:J.text+Z.text};continue}M.push(Z)}return M}function vK($,M){return $.kind===M.kind&&$.inlineCode===M.inlineCode&&d6($.link,M.link)&&hK($.image,M.image)&&$.originalType===M.originalType&&$.marks.join(",")===M.marks.join(",")}function F$($){switch($.kind){case"break":return M5();case"image":return $.image?uK($.image):null;case"inlineCode":return d1({code:$.text});case"text":return $.text.length>0?i0({marks:$.marks,text:$.text}):null;case"unsupported":return Z5({originalType:$.originalType??"unsupported",source:$.text})}}function uK($){return E1({alt:$.alt,title:$.title,url:$.url,width:$.width})}function d6($,M){return $?.url===M?.url&&$?.title===M?.title}function hK($,M){return $?.url===M?.url&&$?.title===M?.title&&$?.alt===M?.alt&&$?.width===M?.width}function y$($,M,Z){let J=[],X=0,Y={childIndices:[],offset:0},Q="",K=$!==null;if($)J.push($),Y=H$($);let q=0;if($&&M.length>0){let D=M[0];if(u5($)&&D.type==="paragraph"){let V=r6($,$.children,D.children);J[J.length-1]=V,Y={childIndices:[],offset:V.plainText.length},q=1,Q=D.plainText}else if(E$($,D)){let V=W$($,D);J[J.length-1]=V,Y=B$(V),q=1}}for(let D=q;D<M.length;D+=1){let V=M[D];J.push(V),X=J.length-1,Y=H$(V)}if(Z){let D=J.length-1,V=J[D]??null,G=q>=M.length&&$!==null,U=null;if(V){if(!G&&V.type==="paragraph"&&u5(Z)){if(U=r6(Z,V.children,Z.children),$===null&&M.length===1)K=!0,Q=V.plainText}else if(G&&u5(V)&&u5(Z))U=r6(V,V.children,Z.children);else if(E$(V,Z))U=W$(V,Z),Y={childIndices:[A0(V).length-1],offset:"end"}}else if($===null&&M.length===0)K=!0;if(U)J[D]=U;else J.push(Z)}return{blocks:J,caretLocalIndex:X,caretChildIndices:Y.childIndices,caretOffset:Y.offset,startRegionInsertedText:Q,startRegionPreservedAtRoot0:K}}function Z4($,M,Z){if($.type==="table")return null;if($.id===M.blockId)return IK($,M,Z);return P$($,(J)=>pK(J,M,Z))}function J4($,M,Z){if($.type==="table")return null;if($.id===M.blockId)return gK($,M,Z);return P$($,(J)=>lK(J,M,Z))}function R1($,M){if($.id===M.blockId)return!0;let Z=A0($);return Z!==null&&Z.some((J)=>R1(J,M))}function H$($){return A0($)?B$($):{childIndices:[],offset:$.plainText.length}}function B$($){return{childIndices:[A0($).length-1],offset:"end"}}function r6($,M,Z){return u0($,z0([...M,...Z]))}function u5($){return $!==null&&($.type==="heading"||$.type==="paragraph")}function E$($,M){return $.type===M.type&&A0($)!==null}function W$($,M){let Z=A0($),J=A0(M);return w1($,[...Z,...J])}function IK($,M,Z){if(Z===0)return null;switch($.type){case"heading":case"paragraph":return u0($,U2(M,Z,M.text.length,""));case"code":return L2($,M.text.slice(0,Z));case"unsupported":return C2($,M.text.slice(0,Z));default:return null}}function gK($,M,Z){if(Z===M.text.length)return null;switch($.type){case"heading":case"paragraph":return u0($,U2(M,0,Z,""));case"code":return L2($,M.text.slice(Z));case"unsupported":return C2($,M.text.slice(Z));default:return null}}function P$($,M){let Z=A0($);return Z?w1($,M(Z)):null}function pK($,M,Z){let J=$.findIndex((Q)=>R1(Q,M));if(J===-1)return[];let X=$.slice(0,J),Y=Z4($[J],M,Z);return Y?[...X,Y]:X}function lK($,M,Z){let J=$.findIndex((Q)=>R1(Q,M));if(J===-1)return[];let X=$.slice(J+1),Y=J4($[J],M,Z);return Y?[Y,...X]:X}function b$($,M,Z){let J=J0($,M);if(J.start.regionId===J.end.regionId)return xK($,J,Z);let X=Z.length>0?[x({text:Z})]:[];return c6($,M,X)}function c6($,M,Z){let J=J0($,M),X=B0($,J.start.regionId),Y=B0($,J.end.regionId);if(!X||!Y)throw Error("Unknown selection endpoints.");let Q=$.document.blocks[X.rootIndex],K=$.document.blocks[Y.rootIndex];if(!Q||!K)throw Error("Unknown root blocks for selection.");let q=Z4(Q,X,J.start.offset),D=J4(K,Y,J.end.offset),V=y$(q,Z,D),G=V.blocks.length>0?V.blocks:[x({text:""})],U=X.rootIndex,A=Y.rootIndex-X.rootIndex+1,_=P1($.document,U,A,G),N=K2($,_,U,A),z=X===Y?J.end.offset:X.text.length;return{documentIndex:V.startRegionPreservedAtRoot0?T$($,N,X,J.start.offset,z,V.startRegionInsertedText):N,selection:q0(U+V.caretLocalIndex,V.caretChildIndices,V.caretOffset)}}function xK($,M,Z){let J=B0($,M.start.regionId);if(!J)throw Error(`Unknown region: ${M.start.regionId}`);let X=T5($,J.blockId,(q)=>dK(q,J,M.start.offset,M.end.offset,Z));if(!X)throw Error(`Failed to replace block for region: ${J.id}`);let Y=K2($,X,J.rootIndex,1),Q=T$($,Y,J,M.start.offset,M.end.offset,Z),K=Y2(Q,J.path);if(!K)throw Error(`Failed to remap region after replacement: ${J.path}`);return{documentIndex:Q,selection:q2(K.id,M.start.offset+Z.length)}}function dK($,M,Z,J,X){switch($.type){case"heading":case"paragraph":return u0($,U2(M,Z,J,X));case"code":return L2($,w$(M,Z,J,X));case"table":return rK($,M,Z,J,X);case"unsupported":return C2($,w$(M,Z,J,X));default:throw Error(`Region text replacement is not supported for block type: ${$.type}`)}}function rK($,M,Z,J,X){let Y=M.tableCellPosition?.rowIndex,Q=M.tableCellPosition?.cellIndex;if(Y===void 0||Q===void 0)throw Error(`Unable to resolve table cell position for region: ${M.id}`);let K=U2(M,Z,J,X),q=$.rows.map((D,V)=>{if(V!==Y)return D;let G=D.cells.map((U,A)=>A===Q?J1({children:K}):U);return{...D,cells:G}});return w0($,q)}function w$($,M,Z,J){return G2($.inlines,M,Z,J).map((X)=>X.text).join("")}function T$($,M,Z,J,X,Y){if($.document.comments.length===0)return M;let Q=w6($,M,Z,J,X,Y);return Q===M.document.comments?M:b5(M,{...M.document,comments:Q})}function Y4($){let M=Q2($),Z=C$(M);return{animations:[],documentIndex:M,future:[],history:[],selection:{anchor:Z,focus:Z}}}function l0($){let M=C0($.documentIndex);return a1(R2($.documentIndex.document.blocks),M.threads,$.documentIndex.document.frontMatter)}function d($,M){if(!M)return null;switch(M.kind){case"keep-state":return $;case"set-selection":return Q0($,M.selection);case"replace-block":{let Z=T5($.documentIndex,M.blockId,()=>M.block);return Z?X4($,Q2(Z),M.selection??null):null}case"splice-blocks":{let Z=P1($.documentIndex.document,M.rootIndex,M.count??1,M.blocks);return X4($,Q2(Z),M.selection??null)}case"splice-text":{let Z=b$($.documentIndex,M.selection,M.text);return X4($,Z.documentIndex,Z.selection)}case"splice-fragment":{let Z=c6($.documentIndex,M.selection,M.fragment);return X4($,Z.documentIndex,Z.selection)}case"splice-comments":{let Z=T9($.documentIndex.document,M.index,M.count,M.threads);return X4($,b5($.documentIndex,Z),null)}}}function X4($,M,Z){let J=cK($,M),X=o2(J.documentIndex,Z)??$.selection,Y=R$($,J,X);return Q0(J,X,Y)}function Q0($,M,Z){let J="regionId"in M?{anchor:h5($.documentIndex,M),focus:h5($.documentIndex,M)}:{anchor:h5($.documentIndex,M.anchor),focus:h5($.documentIndex,M.focus)},X={...$,selection:J};return Z??R$($,X)?A$(X,N$(X)):X}function E0($,M,Z,J){let X={regionId:M,offset:Z};return Q0($,J?{anchor:$.selection.anchor,focus:X}:X)}function cK($,M){let Z=C$(M);return{animations:p6($.animations,C1()),documentIndex:M,future:[],history:[...$.history,{document:$.documentIndex.document,selection:$.selection}],selection:{anchor:Z,focus:Z}}}function a6($){let M=$.history.at(-1);if(!M)return $;return L$(M,{future:[O$($),...$.future],history:$.history.slice(0,-1)})}function i6($){let M=$.future[0];if(!M)return $;return L$(M,{future:$.future.slice(1),history:[...$.history,O$($)]})}function O$($){return{document:$.documentIndex.document,selection:$.selection}}function L$($,M){return{animations:[],documentIndex:Q2($.document),future:M.future,history:M.history,selection:$.selection}}function C$($){return $.regions[0]?{regionId:$.regions[0].id,offset:0}:{regionId:"empty",offset:0}}function h5($,M){let Z=B0($,M.regionId);if(!Z)return M;return{regionId:Z.id,offset:Math.max(0,Math.min(M.offset,Z.text.length))}}function R$($,M,Z){let J=j$($.documentIndex,$.selection),X=j$(M.documentIndex,Z??M.selection);return X!==null&&X!==J}function j$($,M){let Z=$.regionIndex.get(M.focus.regionId),J=Z?$.blockIndex.get(Z.blockId)??null:null;if(!Z||!J?.path)return null;return J.type==="table"?`cell:${Z.path}`:`block:${J.path}`}function D4($,M){let Z=$.regionIndex.get(M.anchor.regionId);if(!Z)return{kind:"unsupported"};if(Z.blockType==="code"){let K=$.blockIndex.get(Z.blockId);return K?{kind:"code",region:Z,rootIndex:K.rootIndex}:{kind:"unsupported"}}let J=o6($,Z.id);if(J)return{kind:"tableCell",...J};let X=N2($,M);if(X)return{kind:"listItem",...X};let Y=aK($,M);if(Y)return{kind:"blockquoteTextBlock",...Y};let Q=A2($,M);if(Q)return{kind:"rootTextBlock",...Q};return{kind:"unsupported"}}function q4($,M){let Z=$.blockIndex.get(M);if(!Z)throw Error(`Unknown root block: ${M}`);return Z.rootIndex}function s6($,M,Z){let J=M?$.blockIndex.get(M)??null:null;while(J){if(J.type===Z)return J;let X=J.parentBlockId;J=X?$.blockIndex.get(X)??null:null}return null}function Q4($){let M=$.split("."),Z=[];for(let J=0;J<M.length-1;J+=1)if(M[J]==="children"){let X=Number(M[J+1]);if(Number.isInteger(X))Z.push(X)}return Z}function A2($,M){let Z=$.regionIndex.get(M.anchor.regionId);if(!Z)return null;let J=$.blockIndex.get(Z.blockId);if(!J)return null;let X=J.rootIndex,Y=$.document.blocks[X];if(!Y||Y.type!=="heading"&&Y.type!=="paragraph")return null;return{block:Y,region:Z,rootIndex:X}}function aK($,M){let Z=$.regionIndex.get(M.anchor.regionId);if(!Z)return null;let J=$.blockIndex.get(Z.blockId),X=s6($,J?.id??null,"blockquote");if(!J||!X||J.parentBlockId!==X.id)return null;let Y=X.rootIndex,Q=$.document.blocks[Y];if(!Q||Q.type!=="blockquote")return null;let K=Q.children.findIndex((D)=>D.id===J.id),q=Q.children[K];if(!q||q.type!=="heading"&&q.type!=="paragraph")return null;return{block:q,blockChildIndices:Q4(J.path),childIndex:K,region:Z,quote:Q,rootIndex:Y}}function K4($,M){return s1($.document.blocks,M)}function N2($,M){let Z=$.regionIndex.get(M.anchor.regionId);if(!Z)return null;let J=$.blockIndex.get(Z.blockId),X=s6($,J?.id??null,"listItem"),Y=s6($,J?.id??null,"list");if(!J||!X||!Y)return null;let Q=K4($,Y.id);if(!Q||Q.type!=="list")return null;let K=Q.items.findIndex((_)=>_.id===X.id),q=Q.items[K];if(!q)return null;let D=Y.parentBlockId?$.blockIndex.get(Y.parentBlockId)??null:null,V=D?.parentBlockId?$.blockIndex.get(D.parentBlockId)??null:null,G=D?.type==="listItem"?K4($,D.id):null,U=V?.type==="list"?K4($,V.id):null,A=U?.type==="list"&&G?U.items.findIndex((_)=>_.id===G.id):-1;return{region:Z,item:q,itemChildIndices:Q4(X.path),itemIndex:K,list:Q,listChildIndices:Q4(Y.path),parentItem:G?.type==="listItem"?G:null,parentItemChildIndices:D?.type==="listItem"?Q4(D.path):null,parentItemIndex:A>=0?A:null,parentList:U?.type==="list"?U:null,parentListChildIndices:V?.type==="list"?Q4(V.path):null,rootIndex:Y.rootIndex}}function o6($,M){let Z=$.regionIndex.get(M);if(!Z)return null;let J=$.tableCellIndex.get(Z.id),X=$.blockIndex.get(Z.blockId),Y=X?.type==="table"?$.document.blocks[X.rootIndex]:null;if(!J||!X||!Y||Y.type!=="table")return null;return{cellIndex:J.cellIndex,rootIndex:X.rootIndex,rowIndex:J.rowIndex,table:Y}}function V4($,M,Z){return s0({checked:M,children:[x({text:$})],spread:Z})}function _2($,M){let Z=$.children[0];if(!Z||Z.type!=="paragraph")return null;return j0($,[x({text:M}),...$.children.slice(1)])}function S$($,M){return M.reduce((Z,J)=>`${Z}.children.${J}`,`root.${$}`)}function k$($,M){if($.selection.anchor.regionId!==$.selection.focus.regionId||$.selection.anchor.offset!==$.selection.focus.offset)return null;let Z=B0($.documentIndex,$.selection.focus.regionId);if(!Z)return null;if(M==="forward"&&$.selection.focus.offset>=Z.text.length)return null;let J=M==="backward"?iK(Z.text,$.selection.focus.offset):$.selection.focus.offset,X=M==="backward"?$.selection.focus.offset:sK(Z.text,$.selection.focus.offset);if(J===X)return null;return{action:{kind:"splice-text",selection:{anchor:{regionId:Z.id,offset:J},focus:{regionId:Z.id,offset:X}},text:""},startOffset:J,endOffset:X}}function iK($,M){let Z=Array.from($.slice(0,M));if(Z.length===0)return 0;return M-Z.at(-1).length}function sK($,M){let Z=Array.from($.slice(M))[0];return Z?M+Z.length:$.length}function m$($,M,Z){let J=$.regionIndex.get(M.anchor.regionId);if(!J)return null;let X=J0($,M),Y=X.start.regionId===X.end.regionId&&X.start.regionId===J.id?J.text.slice(0,X.start.offset)+Z+J.text.slice(X.end.offset):Z;return oK($,M,J.id,Y)??tK($,M,J.id,Y)??nK($,M,J.id,Y)??eK($,M,J.id,Y)??ZD($,J.blockId,J.rootIndex,Y)??{kind:"splice-text",selection:M,text:Z}}function oK($,M,Z,J){let X=N2($,M),Y=YD(J);if(!X||!Y||X.region.id!==Z)return null;let Q=_2(X.item,Y.text);if(!Q)return null;return{kind:"replace-block",block:e(X.list,X.list.items.map((K,q)=>q===X.itemIndex?Q:K),{ordered:Y.ordered,start:Y.ordered?1:null}),blockId:X.list.id,selection:q0(X.rootIndex,[...X.listChildIndices,X.itemIndex,0])}}function nK($,M,Z,J){if(!t6($,M,Z))return null;if(/^\s*([-+*])\s\[( |x|X)\]\s$/.exec(J)){let Q=J.toLowerCase().includes("[x]");return n6($,M,{checked:Q,ordered:!1,start:null})}if(/^\s*[-+*]\s$/.test(J))return n6($,M,{checked:null,ordered:!1,start:null});let Y=/^\s*(\d+)\.\s$/.exec(J);if(Y)return n6($,M,{checked:null,ordered:!0,start:Number(Y[1])});return null}function tK($,M,Z,J){let X=A2($,M),Y=QD(J);if(!X||X.region.id!==Z||X.block.type!=="heading"||!Y)return null;return{kind:"splice-blocks",blocks:[Z1({depth:Y.depth,text:Y.text})],rootIndex:X.rootIndex,selection:$0(X.rootIndex)}}function eK($,M,Z,J){return $D($,M,Z,J)??MD($,M,Z,J)}function $D($,M,Z,J){if(!t6($,M,Z))return null;let X=/^(#{1,6})\s$/.exec(J);if(!X)return null;return JD($,M,X[1].length)}function MD($,M,Z,J){if(!t6($,M,Z)||!/^>\s$/.test(J))return null;return XD($,M)}function ZD($,M,Z,J){if(!/^(?:(?:-\s?){3}|(?:\*\s?){3}|(?:_\s?){3})$/.test(J))return null;return{kind:"splice-blocks",blocks:[J5(),x({text:""})],rootIndex:q4($,M),selection:$0(Z+1)}}function n6($,M,Z){let J=q4($,$.regionIndex.get(M.anchor.regionId).blockId);return{kind:"splice-blocks",blocks:[W1({items:[s0({checked:Z.checked,children:[x({text:""})],spread:!1})],ordered:Z.ordered,spread:!1,start:Z.start})],rootIndex:J,selection:q0(J,[0,0])}}function JD($,M,Z){let J=q4($,$.regionIndex.get(M.anchor.regionId).blockId);return{kind:"splice-blocks",blocks:[Z1({depth:Z,text:""})],rootIndex:J,selection:$0(J)}}function XD($,M){let Z=q4($,$.regionIndex.get(M.anchor.regionId).blockId);return{kind:"splice-blocks",blocks:[W0({children:[x({text:""})]})],rootIndex:Z,selection:q0(Z,[0])}}function t6($,M,Z){let J=A2($,M);return J?.region.id===Z&&J.block.type==="paragraph"}function YD($){let M=/^[-+*]\s(.+)$/.exec($);if(M)return{ordered:!1,text:M[1]};let Z=/^\d+\.\s(.+)$/.exec($);if(Z)return{ordered:!0,text:Z[1]};return null}function QD($){let M=/^(#{1,6})\s(.+)$/.exec($);return M?{depth:M[1].length,text:M[2]}:null}function v$($,M){let Z=J0($,M);if(Z.collapsed)return null;let J=B0($,Z.start.regionId),X=B0($,Z.end.regionId);if(!J||!X)return null;let Y=$.document.blocks[J.rootIndex],Q=$.document.blocks[X.rootIndex];if(!Y||!Q)return null;if(J===X)return{kind:"single-region",normalized:Z,region:J,root:Y,wholeRegion:Z.start.offset===0&&Z.end.offset===J.text.length};return{kind:"multi-region",normalized:Z,startRegion:J,endRegion:X,sameRoot:J.rootIndex===X.rootIndex,startRoot:Y,endRoot:Q}}function I5($,M){let Z=J0($,M),J=B0($,Z.start.regionId),X=B0($,Z.end.regionId);if(!J||!X)return null;let Y=f$(J)||f$(X);return{normalized:Z,sameRegion:J===X,startRegion:J,endRegion:X,structuralBlocked:Y,prefersVerbatimFallback:J.blockType==="code"||X.blockType==="code"}}function f$($){return $.blockType==="table"||$.blockType==="code"}function e6($,M){let Z=v$($,M);if(!Z)return null;switch(Z.kind){case"single-region":if(!Z.wholeRegion||Z.region.blockType==="table"){let X=DD(Z.region,Z.normalized.start.offset,Z.normalized.end.offset);return KD(X)}let J=h$(Z.root,Z.region);return J?u$([J]):null;case"multi-region":{let X=Z.sameRoot?qD($,Z.startRoot,Z.startRegion,Z.normalized.start.offset,Z.endRegion,Z.normalized.end.offset):GD($,Z.startRegion,Z.normalized.start.offset,Z.endRegion,Z.normalized.end.offset);return X.length>0?u$(X):null}}}function KD($){if($.length===0)return null;if(O8($))return{kind:"text",text:X0($)};return{kind:"inlines",inlines:$}}function u$($){if(K5($))return{kind:"text",text:$[0].plainText};return{kind:"blocks",blocks:$}}function h$($,M){if($.id===M.blockId)return $;let Z=A0($);if(!Z)return null;let J=Z.find((Y)=>R1(Y,M)),X=J?h$(J,M):null;return X?w1($,[X]):null}function DD($,M,Z){let J=G2($.inlines,Z,$.text.length,""),X=G2(J,0,M,"");return x6(X)}function qD($,M,Z,J,X,Y){if(M.type==="table")return UD($,M,Z,J,X,Y);let Q=I$(M,Z,J,X,Y);return Q?[Q]:[]}function VD($,M,Z,J,X){let Y=$.roots[M.rootIndex],Q=Y?.regions[0],K=Y?.regions.at(-1);return M===Q&&J===K&&Z===0&&X===K.text.length}function UD($,M,Z,J,X,Y){if(VD($,Z,J,X,Y))return[M];let Q=Z.tableCellPosition?.rowIndex,K=Z.tableCellPosition?.cellIndex,q=X.tableCellPosition?.rowIndex,D=X.tableCellPosition?.cellIndex;if(Q===void 0||K===void 0||q===void 0||D===void 0)return[];if(Q!==0||K!==0||J!==0)return[];let V=M.rows[q];if(!V)return[];let G=V.cells.length-1;if(D!==G||Y!==X.text.length)return[];return[w0(M,M.rows.slice(0,q+1))]}function I$($,M,Z,J,X){let Y=A0($);if(!Y)return null;let Q=Y.findIndex((q)=>R1(q,M)),K=Y.findIndex((q)=>R1(q,J));if(Q===-1||K===-1)return null;if(Q===K){let q=I$(Y[Q],M,Z,J,X);return q?w1($,[q]):null}return w1($,g$(Y,Q,M,Z,K,J,X))}function GD($,M,Z,J,X){return g$($.document.blocks,M.rootIndex,M,Z,J.rootIndex,J,X)}function g$($,M,Z,J,X,Y,Q){let K=J4($[M],Z,J),q=$.slice(M+1,X),D=Z4($[X],Y,Q);return[K,...q,D].filter((V)=>V!==null)}function $3($,M){let Z=I5($.documentIndex,$.selection);if(!Z)return null;switch(M.kind){case"text":return M.text.length>0?d($,{kind:"splice-text",selection:$.selection,text:M.text}):null;case"inlines":{if(M.inlines.length===0)return null;if(Z.sameRegion){let J=a7($.documentIndex,$.selection,M.inlines);if(J)return d($,J)}if(Z.structuralBlocked)return null;return d($,{kind:"splice-fragment",fragment:[H1({children:M.inlines})],selection:$.selection})}case"blocks":if(M.blocks.length===0||Z.structuralBlocked)return null;return d($,{kind:"splice-fragment",fragment:M.blocks,selection:$.selection})}}function q1($,M,Z,J=0){return q0($,[...M,Z,0],J)}function M3($,M){let Z=$.region.text,J=$.item,X=typeof J.checked==="boolean"?!1:J.checked;if(M===0){let D=V4("",X,J.spread);return{kind:"replace-block",block:e($.list,[...$.list.items.slice(0,$.itemIndex),D,J,...$.list.items.slice($.itemIndex+1)]),blockId:$.list.id,listItemInsertedPath:g5(D,$.rootIndex,[...$.listChildIndices,$.itemIndex]),selection:q1($.rootIndex,$.listChildIndices,$.itemIndex)}}if(M===Z.length){let D=V4("",X,J.spread);return{kind:"replace-block",block:e($.list,[...$.list.items.slice(0,$.itemIndex+1),D,...$.list.items.slice($.itemIndex+1)]),blockId:$.list.id,listItemInsertedPath:g5(D,$.rootIndex,[...$.listChildIndices,$.itemIndex+1]),selection:q1($.rootIndex,$.listChildIndices,$.itemIndex+1)}}let Y=Z.slice(0,M),Q=Z.slice(M),K=V4(Q,X,J.spread),q=j0(J,[x({text:Y})]);return{kind:"replace-block",block:e($.list,[...$.list.items.slice(0,$.itemIndex),q,K,...$.list.items.slice($.itemIndex+1)]),blockId:$.list.id,listItemInsertedPath:g5(K,$.rootIndex,[...$.listChildIndices,$.itemIndex+1]),selection:q1($.rootIndex,$.listChildIndices,$.itemIndex+1)}}function p$($,M){if(M!==0||$.region.text.length!==0)return M3($,M);if($.parentItem&&$.parentItemIndex!==null&&$.parentItemChildIndices&&$.parentList&&$.parentListChildIndices)return AD($);let Z=$.list.items.slice(0,$.itemIndex),J=$.list.items.slice($.itemIndex+1),X=[];if(Z.length>0)X.push(e($.list,Z));if(X.push(x({text:""})),J.length>0)X.push(e($.list,J));return{kind:"splice-blocks",blocks:X,rootIndex:$.rootIndex,selection:$0($.rootIndex+(Z.length>0?1:0))}}function l$($){if(typeof $.item.checked==="boolean"){let M=s0({checked:null,children:$.item.children,spread:$.item.spread});return{kind:"replace-block",block:e($.list,$.list.items.map((Z,J)=>J===$.itemIndex?M:Z)),blockId:$.list.id}}if($.itemIndex>0){let M=$.list.items[$.itemIndex-1];if(!M)return null;if($.item.plainText.length===0)return{kind:"replace-block",block:e($.list,$.list.items.filter((J,X)=>X!==$.itemIndex)),blockId:$.list.id,selection:q1($.rootIndex,$.listChildIndices,$.itemIndex-1,"end")};let Z=_2(M,`${M.plainText}${$.item.plainText}`);if(!Z)return null;return{kind:"replace-block",block:e($.list,$.list.items.flatMap((J,X)=>{if(X===$.itemIndex-1)return[Z];if(X===$.itemIndex)return[];return[J]})),blockId:$.list.id,selection:q1($.rootIndex,$.listChildIndices,$.itemIndex-1,M.plainText.length)}}return{kind:"splice-blocks",blocks:[x({text:$.item.plainText})],rootIndex:$.rootIndex,selection:$0($.rootIndex)}}function x$($){if($.itemIndex===0)return null;let M=$.list.items[$.itemIndex-1];if(!M)return null;let Z=ND(M,$.item,$);return{kind:"replace-block",block:e($.list,$.list.items.flatMap((J,X)=>{if(X===$.itemIndex-1)return[Z.item];if(X===$.itemIndex)return[];return[J]})),blockId:$.list.id,selection:q0($.rootIndex,Z.regionChildIndices)}}function d$($){if(!$.parentItem||$.parentItemIndex===null||!$.parentItemChildIndices||!$.parentList||!$.parentListChildIndices)return null;let M=$.list.items.filter((X,Y)=>Y!==$.itemIndex),Z=$.parentItem.children.flatMap((X)=>{if(X.type!=="list"||X.id!==$.list.id)return[X];if(M.length===0)return[];return[e($.list,M)]}),J=j0($.parentItem,Z);return{kind:"replace-block",block:e($.parentList,[...$.parentList.items.slice(0,$.parentItemIndex),J,$.item,...$.parentList.items.slice($.parentItemIndex+1)]),blockId:$.parentList.id,selection:q1($.rootIndex,$.parentListChildIndices,$.parentItemIndex+1)}}function Z3($,M){let Z=$.itemIndex+M;if(Z<0||Z>=$.list.items.length)return null;let J=[...$.list.items],[X]=J.splice($.itemIndex,1);if(!X)return null;return J.splice(Z,0,X),{kind:"replace-block",block:e($.list,J),blockId:$.list.id,selection:q1($.rootIndex,$.listChildIndices,Z)}}function AD($){if(!$.parentItem||$.parentItemIndex===null||!$.parentItemChildIndices||!$.parentList||!$.parentListChildIndices)return null;let M=$.list.items.filter((Q,K)=>K!==$.itemIndex),Z=$.parentItem.children.flatMap((Q)=>{if(Q.type!=="list"||Q.id!==$.list.id)return[Q];if(M.length===0)return[];return[e($.list,M)]}),J=j0($.parentItem,Z),X=typeof $.parentItem.checked==="boolean"?!1:$.parentItem.checked,Y=V4("",X,$.parentItem.spread);return{kind:"replace-block",block:e($.parentList,[...$.parentList.items.slice(0,$.parentItemIndex),J,Y,...$.parentList.items.slice($.parentItemIndex+1)]),blockId:$.parentList.id,listItemInsertedPath:g5(Y,$.rootIndex,[...$.parentListChildIndices,$.parentItemIndex+1]),selection:q1($.rootIndex,$.parentListChildIndices,$.parentItemIndex+1)}}function g5($,M,Z){return typeof $.checked==="boolean"?void 0:S$(M,Z)}function ND($,M,Z){let J=$.children.findIndex((Y)=>Y.type==="list"&&Y.ordered===Z.list.ordered&&Y.start===Z.list.start);if(J>=0){let Y=$.children[J];if(!Y||Y.type!=="list")return{item:$,regionChildIndices:[...Z.listChildIndices,Z.itemIndex-1,0]};return{item:j0($,$.children.map((Q,K)=>K===J?e(Y,[...Y.items,M]):Q)),regionChildIndices:[...Z.listChildIndices,Z.itemIndex-1,J,Y.items.length,0]}}let X=W1({items:[M],ordered:Z.list.ordered,spread:Z.list.spread,start:Z.list.start});return{item:j0($,[...$.children,X]),regionChildIndices:[...Z.listChildIndices,Z.itemIndex-1,$.children.length,0,0]}}function r$($,M){let Z=$.region.text.length,J=$.region.text.slice(0,M),X=$.region.text.slice(M),Y=M===0&&Z>0?$.rootIndex:$.rootIndex+1;if($.block.type==="paragraph")return{kind:"splice-blocks",blocks:M===0?[x({text:""}),$.block]:M===Z?[$.block,x({text:""})]:[x({text:J}),x({text:X})],rootIndex:$.rootIndex,selection:$0(Y)};return{kind:"splice-blocks",blocks:M===0?[x({text:""}),$.block]:M===Z?[$.block,x({text:""})]:[Z1({depth:$.block.depth,text:J}),x({text:X})],rootIndex:$.rootIndex,selection:$0(Y)}}function c$($,M){let Z=$.region.text,J=Z.slice(0,M),X=Z.slice(M),Y=$.block.type==="heading"?yD($.block,J,X,$.blockChildIndices,M,Z.length):WD($.block,J,X,$.blockChildIndices,M,Z.length);return{kind:"splice-blocks",blocks:[W0({children:[...$.quote.children.slice(0,$.childIndex),...Y.blocks,...$.quote.children.slice($.childIndex+1)]})],rootIndex:$.rootIndex,selection:q0($.rootIndex,Y.focusChildIndices)}}function a$($,M){if(M!==0||$.region.text.length!==0||$.block.type!=="paragraph")return null;let Z=$.quote.children.slice(0,$.childIndex),J=$.quote.children.slice($.childIndex+1),X=[];if(Z.length>0)X.push(W0({children:Z}));if(X.push(x({text:""})),J.length>0)X.push(W0({children:J}));return{kind:"splice-blocks",blocks:X,rootIndex:$.rootIndex,selection:$0($.rootIndex+(Z.length>0?1:0))}}function i$($,M){let Z=zD($);if(Z)return Z;if($.rootIndex===0)return null;let J=M.document.blocks[$.rootIndex-1],X=M.document.blocks[$.rootIndex+1];if(!J)return null;if($.block.plainText.length===0){let Y=_D($,J,X);if(Y)return Y;return{kind:"splice-blocks",blocks:[],rootIndex:$.rootIndex,selection:J.type==="paragraph"||J.type==="heading"?$0($.rootIndex-1,"end"):J.type==="list"?q0($.rootIndex-1,[J.items.length-1,0],"end"):J.type==="blockquote"?q0($.rootIndex-1,[J.children.length-1],"end"):$0($.rootIndex-1,"end")}}if(J.type==="paragraph")return{kind:"splice-blocks",count:2,blocks:[x({text:`${J.plainText}${$.block.plainText}`})],rootIndex:$.rootIndex-1,selection:$0($.rootIndex-1,J.plainText.length)};if(J.type==="heading")return{kind:"splice-blocks",count:2,blocks:[Z1({depth:J.depth,text:`${J.plainText}${$.block.plainText}`})],rootIndex:$.rootIndex-1,selection:$0($.rootIndex-1,J.plainText.length)};if(J.type==="list"){let Y=J.items.length-1,Q=J.items[Y];if(Q){let K=_2(Q,`${Q.plainText}${$.block.plainText}`);if(K)return{kind:"splice-blocks",count:2,blocks:[e(J,J.items.map((q,D)=>D===Y?K:q))],rootIndex:$.rootIndex-1,selection:q0($.rootIndex-1,[Y,0],Q.plainText.length)}}}return null}function s$($){if($.region.text.length===0)return ED($);if($.childIndex>0)return HD($);return{kind:"splice-blocks",blocks:$.quote.children,rootIndex:$.rootIndex,selection:$0($.rootIndex)}}function J3($,M,Z){if($.block.type!=="heading")return null;let J=Math.max(1,Math.min(6,$.block.depth+M));if(J===$.block.depth)return{kind:"keep-state"};return{kind:"splice-blocks",blocks:[Z1({depth:J,text:$.block.plainText})],rootIndex:$.rootIndex,selection:$0($.rootIndex,Z)}}function _D($,M,Z){if($.block.type!=="paragraph"||$.block.plainText.length!==0||M.type!=="list"||Z?.type!=="list"||!FD(M,Z))return null;let J=M.items.length-1;return{kind:"splice-blocks",count:3,blocks:[e(M,[...M.items,...Z.items])],rootIndex:$.rootIndex-1,selection:q0($.rootIndex-1,[J,0],"end")}}function FD($,M){return $.ordered===M.ordered&&$.start===M.start}function zD($){if($.block.type!=="heading")return null;return{kind:"splice-blocks",blocks:[x({text:$.block.plainText})],rootIndex:$.rootIndex,selection:$0($.rootIndex)}}function HD($){let Z=$.quote.children[$.childIndex-1].plainText,J=$.block.plainText,X=$.quote.children.filter((Y,Q)=>Q!==$.childIndex).map((Y,Q)=>Q===$.childIndex-1?x({text:`${Z}${J}`}):Y);return{kind:"splice-blocks",blocks:[W0({children:X})],rootIndex:$.rootIndex,selection:q0($.rootIndex,[$.childIndex-1],Z.length)}}function ED($){if($.quote.children.length===1)return{kind:"splice-blocks",blocks:[x({text:""})],rootIndex:$.rootIndex,selection:$0($.rootIndex)};let M=Math.max(0,$.childIndex-1),Z=$.childIndex>0?"end":0;return{kind:"splice-blocks",blocks:[W0({children:$.quote.children.filter((J,X)=>X!==$.childIndex)})],rootIndex:$.rootIndex,selection:q0($.rootIndex,[M],Z)}}function WD($,M,Z,J,X,Y){return{blocks:X===0?[x({text:""}),$]:X===Y?[$,x({text:""})]:[x({text:M}),x({text:Z})],focusChildIndices:X===0?J:[...J.slice(0,-1),J.at(-1)+1]}}function yD($,M,Z,J,X,Y){return{blocks:X===0?[x({text:""}),$]:X===Y?[$,x({text:""})]:[Z1({depth:$.depth,text:M}),x({text:Z})],focusChildIndices:X===0?J:[...J.slice(0,-1),J.at(-1)+1]}}function o$($,M,Z){let J=A2($,M),X=Math.max(2,Z);if(!J||J.block.type!=="paragraph"||J.block.plainText.length>0||M.anchor.regionId!==M.focus.regionId||M.anchor.offset!==0||M.focus.offset!==0)return null;return{kind:"splice-blocks",blocks:[y1({rows:Array.from({length:2},()=>Y3(X))})],rootIndex:J.rootIndex,selection:L1(J.rootIndex,0,0)}}function X3($,M,Z,J){let X=J<0?bD(Z.table,Z.rowIndex,Z.cellIndex):TD(Z.table,Z.rowIndex,Z.cellIndex);if(!X)return J>0&&jD(Z.table,Z.rowIndex,Z.cellIndex)?BD(Z):{kind:"keep-state"};let Y=Z.table.rows[X.rowIndex]?.cells[X.cellIndex];if(!Y)return{kind:"keep-state"};return{kind:"set-selection",selection:wD($,M,Z.table,X.rowIndex,X.cellIndex,Math.min(M.focus.offset,Y.plainText.length))}}function n$($,M){let Z=D2($,M.focus.regionId);if(!Z||Z.kind!=="tableCell")return null;let J=Math.min(M.anchor.offset,M.focus.offset),X=Math.max(M.anchor.offset,M.focus.offset),Y=s2(Z,J,X,(Q)=>M5({path:Q}));return{kind:"replace-block",block:Y.block,blockId:Y.blockId,selection:Y.selection}}function t$($,M){let Z=M==="left"?$.cellIndex:$.cellIndex+1;return F2($,y1({align:XM($.table.align,Z,0,[null]),rows:$.table.rows.map((J)=>c1({cells:PD(J.cells,Z,0,[JM()])}))}),L1($.rootIndex,$.rowIndex,Z))}function e$($){let M=Math.max(0,...$.table.rows.map((Z)=>Z.cells.length));if(M<=1)return null;return F2($,y1({align:XM($.table.align,$.cellIndex,1,[]),rows:$.table.rows.map((Z)=>c1({cells:Z.cells.filter((J,X)=>X!==$.cellIndex)}))}),L1($.rootIndex,$.rowIndex,Math.min($.cellIndex,M-2)))}function $M($,M){let Z=M==="above"?$.rowIndex:$.rowIndex+1,J=Math.max(1,...$.table.rows.map((X)=>X.cells.length));return F2($,w0($.table,[...$.table.rows.slice(0,Z),Y3(J),...$.table.rows.slice(Z)]),L1($.rootIndex,Z,Math.min($.cellIndex,J-1)))}function MM($){if($.table.rows.length<=1)return null;let M=$.table.rows.filter((X,Y)=>Y!==$.rowIndex),Z=Math.min($.rowIndex,M.length-1),J=M[Z]?.cells.length??1;return F2($,w0($.table,M),L1($.rootIndex,Z,Math.min($.cellIndex,J-1)))}function ZM($){return F2($,x({text:""}),$0($.rootIndex))}function Y3($){return c1({cells:Array.from({length:$},()=>JM())})}function JM(){return J1({children:[]})}function BD($){let M=$.table.rows.length,Z=Math.max(1,...$.table.rows.map((J)=>J.cells.length));return F2($,w0($.table,[...$.table.rows,Y3(Z)]),L1($.rootIndex,M,0))}function F2($,M,Z){return{kind:"replace-block",block:M,blockId:$.table.id,selection:Z}}function PD($,M,Z,J){return[...$.slice(0,M),...J,...$.slice(M+Z)]}function XM($,M,Z,J){return[...$.slice(0,M),...J,...$.slice(M+Z)]}function wD($,M,Z,J,X,Y){let Q=V2($,Z.id,J,X);if(!Q)return M;return{anchor:{regionId:Q.id,offset:Y},focus:{regionId:Q.id,offset:Y}}}function bD($,M,Z){if(Z>0)return{cellIndex:Z-1,rowIndex:M};if(M>0){let J=$.rows[M-1];if(!J||J.cells.length===0)return null;return{cellIndex:J.cells.length-1,rowIndex:M-1}}return null}function TD($,M,Z){let J=$.rows[M];if(!J)return null;if(Z+1<J.cells.length)return{cellIndex:Z+1,rowIndex:M};let X=$.rows[M+1];if(!X||X.cells.length===0)return null;return{cellIndex:0,rowIndex:M+1}}function jD($,M,Z){let J=$.rows[M];return Boolean(J&&M===$.rows.length-1&&Z===J.cells.length-1)}function U4($,M){let Z=m$($.documentIndex,$.selection,M),J=d($,Z);if(!J)return null;if(Z?.kind==="splice-text"&&M.length>0)J=k5(J,M.length);if(M===".")J=U$(J);return J}function p5($){let M=D4($.documentIndex,$.selection),Z=J0($.documentIndex,$.selection).start.offset;switch(M.kind){case"code":return d($,{kind:"splice-text",selection:$.selection,text:`
|
|
25
|
+
`});case"tableCell":return d($,n$($.documentIndex,$.selection));case"listItem":{let J=p$(M,Z);return RD({state:d($,J)??d($,M3(M,Z)),action:J})}case"blockquoteTextBlock":return d($,a$(M,Z))??d($,c$(M,Z));case"rootTextBlock":return d($,r$(M,Z));case"unsupported":return null}}function l5($,M){let Z=d($,{kind:"splice-text",selection:$.selection,text:M});return M.length>0?k5(Z,M.length):Z}function x5($){return l5($,"")}function Q3($){return e6($.documentIndex,$.selection)}function YM($,M,Z){let J=$3($,M);if(J)return OD(J,M);if(M.kind==="text")return null;return CD($,M,Z)}function OD($,M){let Z=LD(M);return Z>0?k5($,Z):$}function LD($){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 CD($,M,Z){let J=I5($.documentIndex,$.selection);if(!J)return null;let X=J.prefersVerbatimFallback&&Z&&Z.length>0?Z:L9(M);return X.length>0?l5($,X):null}function K3($){if(SM($))return x5($);let M=kM($,"backward");if(M)return M;let Z=J0($.documentIndex,$.selection);if(Z.start.regionId!==Z.end.regionId||Z.start.offset!==0||Z.end.offset!==0)return null;let J=D4($.documentIndex,$.selection);switch(J.kind){case"listItem":return d($,l$(J));case"blockquoteTextBlock":return d($,s$(J));case"rootTextBlock":return d($,i$(J,$.documentIndex));default:return null}}function D3($){if(SM($))return x5($);return kM($,"forward")}function QM($,M,Z){return E0($,M,Z,!0)}function KM($){let M=$.documentIndex.regions,Z=M[0],J=M.at(-1);if(!Z||!J)return $;return Q0($,{anchor:{regionId:Z.id,offset:0},focus:{regionId:J.id,offset:J.text.length}})}function DM($){let M=D4($.documentIndex,$.selection);switch(M.kind){case"tableCell":return d($,X3($.documentIndex,$.selection,M,1));case"rootTextBlock":return d($,J3(M,1,$.selection.focus.offset));case"listItem":return d($,x$(M));default:return null}}function qM($){let M=D4($.documentIndex,$.selection);switch(M.kind){case"tableCell":return d($,X3($.documentIndex,$.selection,M,-1));case"rootTextBlock":return d($,J3(M,-1,$.selection.focus.offset));case"listItem":return d($,d$(M));default:return null}}var VM=S1(N2,($,M)=>Z3(M,-1)),UM=S1(N2,($,M)=>Z3(M,1));function GM($,M){let Z=K4($.documentIndex,M);if(!Z||Z.type!=="listItem"||typeof Z.checked!=="boolean")return null;return d($,{kind:"replace-block",block:{...Z,checked:!Z.checked},blockId:M})}function AM($,M){return d($,o$($.documentIndex,$.selection,M))}var NM=S1(G4,($,M,Z)=>t$(M,Z)),_M=S1(G4,($,M)=>e$(M)),FM=S1(G4,($,M,Z)=>$M(M,Z)),zM=S1(G4,($,M)=>MM(M)),HM=S1(G4,($,M)=>ZM(M));function d5($){return i5($,"bold")}function r5($){return i5($,"italic")}function c5($){return i5($,"strikethrough")}function a5($){return i5($,"underline")}function EM($){return CM($,k6)}function WM($,M,Z,J,X){return RM($,M,Z,J,X)}function yM($,M,Z,J){return RM($,M,Z,J,null)}function BM($,M,Z){return d($,c7($.documentIndex,$.selection,(J)=>E1({alt:Z??null,path:J,url:M})))}function PM($,M,Z,J){let X=D2($.documentIndex,M);if(!X)return null;let{image:Y}=Z,Q=s2(X,Z.start,Z.end,(K)=>E1({alt:Y.alt,path:K,title:Y.title,url:Y.url,width:J}));return d($,{kind:"replace-block",block:Q.block,blockId:Q.blockId})}function wM($,M,Z){let J=P6($.documentIndex,M,Z);if(!J)return null;return mM($,$.documentIndex.document.comments.length,0,[J])}function bM($,M,Z){return A4($,M,(J)=>p8(J,{body:Z.trim()}))}function TM($,M,Z,J){return A4($,M,(X)=>l8(X,Z,J))}function jM($,M,Z){return A4($,M,(J)=>x8(J,Z))}function OM($,M){return A4($,M,()=>null)}function LM($,M,Z){return A4($,M,(J)=>d8(J,Z))}function q3($){return a6($)}function V3($){return i6($)}function S1($,M){return(Z,...J)=>{let X=$(Z.documentIndex,Z.selection);return X?d(Z,M(Z,X,...J)):null}}function G4($,M){return o6($,M.focus.regionId)}function RD($){if(!$.state||!$.action||$.action.kind!=="replace-block"||!$.action.listItemInsertedPath)return $.state;return G$($.state,$.action.listItemInsertedPath)}function i5($,M){return CM($,(Z,J,X)=>R6(Z,J,X,M))}function CM($,M){let Z=J0($.documentIndex,$.selection);if(Z.start.regionId!==Z.end.regionId||Z.start.offset===Z.end.offset)return null;return d($,j5($.documentIndex,Z.start.regionId,Z.start.offset,Z.end.offset,M))}function RM($,M,Z,J,X){return d($,m6($.documentIndex,M,Z,J,X))}function SM($){let M=J0($.documentIndex,$.selection);return M.start.regionId!==M.end.regionId||M.start.offset!==M.end.offset}function kM($,M){let Z=k$($,M);if(!Z)return null;let J=d($,Z.action);if(!J)return null;return V$($,J,Z.startOffset,Z.endOffset)}function A4($,M,Z){let X=C0($.documentIndex).threads[M];if(!X)return null;let Y=Z(X);if(Y===X)return null;return mM($,M,1,Y?[Y]:[])}function mM($,M,Z,J){return d($,{kind:"splice-comments",count:Z,index:M,threads:J})}var fM=1;function vM($,M,Z){let J=$.documentIndex.regionOrderIndex.get($.selection.focus.regionId);if(J===void 0)return $;let X=$.documentIndex.regions[J],Y=$.selection.focus.offset+M;if(Y>=0&&Y<=X.text.length)return E0($,X.id,Y,Z);if(M<0){let K=$.documentIndex.regions[J-1];if(!K)return $;return E0($,K.id,K.text.length,Z)}let Q=$.documentIndex.regions[J+1];if(!Q)return $;return E0($,Q.id,0,Z)}function uM($,M,Z,J,X){let Y=h2(M,Z.regionId,Z.offset);if(!Y)return $;let Q=M.lines[Y.index+J];if(!Q)return $;let K=b0(M,$,{x:p0($,M,Z)+fM,y:Q.top+Q.height/2});if(!K)return $;return E0($,K.regionId,K.offset,X)}function hM($,M,Z,J){let X=gM($,M);if(!X)return $;return E0($,X.regionId,Z==="Home"?X.start:X.end,J)}function IM($,M,Z,J,X){let Y=gM($,M);if(!Y)return $;let K=Math.max(1,Math.floor(480/M.options.lineHeight)),q=h2(M,Y.regionId,$.selection.focus.offset),D=q?M.lines[q.index+J*K]:null;if(!D)return $;let V=b0(M,$,{x:p0($,M,Z)+fM,y:D.top+D.height/2});if(!V)return $;return E0($,V.regionId,V.offset,X)}function gM($,M){return L0(M,$.selection.focus.regionId,$.selection.focus.offset)}var SD=1;function pM($,M,Z,J,X){let Y=$.documentIndex.regionIndex.get($.selection.focus.regionId)??null;if(!Y)return null;let Q=$.documentIndex.tableCellIndex.get(Y.id)??null,K=$.documentIndex.blockIndex.get(Y.blockId)??null;if(!Q||K?.type!=="table")return null;let q=kD($,K.id,Q.rowIndex+J,Q.cellIndex)??mD($,K.id,J);if(!q)return $;let D=M.regionBounds.get(Y.id),V=M.regionBounds.get(q.id);if(!D||!V)return $;let G=V.top+fD(Z.top+Z.height/2-D.top,0,Math.max(0,V.bottom-V.top-1)),U=b0(M,$,{x:p0($,M,Z)+SD,y:G});if(!U)return $;return E0($,U.regionId,U.offset,X)}function kD($,M,Z,J){return V2($.documentIndex,M,Z,J)}function mD($,M,Z){let J=$.documentIndex.blockIndex.get(M),X=$.documentIndex.regions,Y=J?$.documentIndex.roots[J.rootIndex]?.regionRange:void 0;if(!Y)return null;return Z<0?X[Y.start-1]??null:X[Y.end]??null}function fD($,M,Z){return Math.max(M,Math.min(Z,$))}function U3($,M,Z=!1){return vM($,M,Z)}function G3($,M,Z,J=!1){return vD($,M,Z,J)}function A3($,M,Z,J=!1){return uD($,M,Z,J)}function N3($,M,Z,J=!1){return hM($,M,Z,J)}function _3($,M,Z=!1){return hD($,M,Z)}function vD($,M,Z,J){let X=lM($,M);if(!X)return $;return pM($,M,X,Z,J)??uM($,M,X,Z,J)}function uD($,M,Z,J){let X=lM($,M);if(!X)return $;return IM($,M,X,Z,J)}function hD($,M,Z){let J=$.documentIndex.regions,X=M==="start"?J[0]:J.at(-1);if(!X)return $;return E0($,X.id,M==="start"?0:X.text.length,Z)}function lM($,M){return g0(M,$.documentIndex,{regionId:$.selection.focus.regionId,offset:$.selection.focus.offset})}function dM($,M,Z,J,X,Y,Q){let K=Z.image?J.images.get(Z.image.url):null,q=pD(Z,J,Q),D=lD(M,Y,Q,q);if($.fillStyle=X.imageSurfaceBackground,$.fillRect(D.left,D.top,D.width,D.height),K?.status==="loaded"&&K.source)$.drawImage(K.source,D.left,D.top,D.width,D.height);else ID($,X,{...D,status:K?.status==="error"?"error":"loading"});$.strokeStyle=X.imageSurfaceBorder,$.strokeRect(D.left,D.top,D.width,D.height)}function ID($,M,Z){let J=Z.status==="loading"?"Loading image":"Image unavailable",X=xD(Z),Y=Z.top+Z.height/2+X.size*0.9;if($.save(),$.beginPath(),$.rect(Z.left,Z.top,Z.width,Z.height),$.clip(),Z.status==="loading")gD($,M,Z);$.strokeStyle=M.imagePlaceholderIcon,$.lineWidth=1.5,$.strokeRect(X.left,X.top,X.size,X.size),$.beginPath(),$.arc(X.left+X.size*0.28,X.top+X.size*0.3,X.size*0.1,0,Math.PI*2),$.moveTo(X.left+X.size*0.12,X.top+X.size*0.82),$.lineTo(X.left+X.size*0.42,X.top+X.size*0.5),$.lineTo(X.left+X.size*0.58,X.top+X.size*0.66),$.lineTo(X.left+X.size*0.78,X.top+X.size*0.38),$.lineTo(X.left+X.size*0.88,X.top+X.size*0.82),$.stroke(),$.font='500 12px "Iowan Old Style", "Palatino Linotype", serif',$.fillStyle=M.imagePlaceholderText,$.textAlign="center",$.textBaseline="middle",$.fillText(J,Z.left+Z.width/2,Y),$.restore()}function gD($,M,Z){let J=Math.max(48,Math.round(Z.width*0.22)),X=Z.width+J*2,Y=performance.now()%1800/1800,Q=Z.left-J+X*Y,K=$.createLinearGradient(Q,Z.top,Q+J,Z.top);K.addColorStop(0,"rgba(255,255,255,0)"),K.addColorStop(0.5,M.imageLoadingOverlay),K.addColorStop(1,"rgba(255,255,255,0)"),$.fillStyle=K,$.fillRect(Z.left,Z.top,Z.width,Z.height)}function pD($,M,Z){if(!$.image)return xM(Z);let J=M.images.get($.image.url);if(!J||J.intrinsicWidth<=0||J.intrinsicHeight<=0)return xM(Z);return Math.max(48,Math.round(Z*(J.intrinsicHeight/J.intrinsicWidth)))}function lD($,M,Z,J){return{height:J,left:M,top:$.top+Math.max(0,Math.floor(($.height-J)/2)),width:Z}}function xD($){let M=Math.max(18,Math.min(34,Math.round(Math.min($.width,$.height)*0.18)));return{left:$.left+Math.max(12,Math.round(($.width-M)/2)),size:M,top:$.top+Math.max(12,Math.round($.height/2-M*0.95))}}function xM($){return Math.max(48,Math.round($*0.5625))}var rM=2,cM=8,dD=3,rD=1.5,cD=2,z2={elbow:{x:6.5,y:10.5},end:{x:11.5,y:3.5},start:{x:3.5,y:7.5}};function aM($,M,Z,J,X,Y,Q=null){if(!Z||M.start!==0)return;if(Q){let K=D$(Q),q=nD(Z,M,J,X,$);$.save(),$.translate(q.x,q.y),$.scale(K,K),$.translate(-q.x,-q.y)}if(Z.kind==="task")aD($,M,Z.checked,Y,Q);else if($.fillStyle=Q?e2(Y.listMarkerText,Q,Y):Y.listMarkerText,Z.kind==="ordered")oD($,Z.label,J,X);else $.fillText(Z.label,M.left-rM,X);if(Q)$.restore()}function aD($,M,Z,J,X=null){let Y=g2(M);if(iD($,Y,Z,J,X),!Z)return;sD($,Y,J,X)}function iD($,M,Z,J,X=null){let Y=Z?J.checkboxCheckedFill:J.checkboxUncheckedFill,Q=Z?J.checkboxCheckedStroke:J.checkboxUncheckedStroke;$.fillStyle=X?e2(Y,X,J):Y,$.strokeStyle=X?e2(Q,X,J):Q,$.beginPath(),$.lineWidth=rD,$.roundRect(M.left,M.top,M.size,M.size,dD),$.fill(),$.stroke()}function sD($,M,Z,J=null){$.strokeStyle=J?e2(Z.checkboxCheckmark,J,Z):Z.checkboxCheckmark,$.lineWidth=cD,$.beginPath(),$.moveTo(M.left+z2.start.x,M.top+z2.start.y),$.lineTo(M.left+z2.elbow.x,M.top+z2.elbow.y),$.lineTo(M.left+z2.end.x,M.top+z2.end.y),$.stroke()}function oD($,M,Z,J){let X=$.textAlign;$.textAlign="right",$.fillText(M,Z-cM,J),$.textAlign=X}function nD($,M,Z,J,X){if($.kind==="task"){let K=g2(M);return{x:K.left+K.size/2,y:K.top+K.size/2}}let Y=X.measureText($.label),Q=J-(Y.actualBoundingBoxAscent-Y.actualBoundingBoxDescent)/2;if($.kind==="ordered")return{x:Z-cM-Y.width/2,y:Q};return{x:M.left-rM+Y.width/2,y:Q}}var tD=80;function sM({context:$,containerBounds:M,isHeaderRow:Z,lineHeight:J,theme:X}){let Y=nM(M,J);$.fillStyle=Z?X.tableHeaderBackground:X.tableBodyBackground,$.fillRect(Y.left,Y.top,Y.width,Y.height),tM($,Y,X)}function oM({activeBlockFlashes:$,activeBlockId:M,activeRegionId:Z,context:J,editorState:X,endIndex:Y,layout:Q,regionBounds:K,startIndex:q,theme:D,verticalBleed:V}){if(!M||!Z)return;let G=X.documentIndex.blockIndex.get(M)??null;if(G?.type!=="table")return;if((X.documentIndex.regionIndex.get(Z)??null)?.blockId!==M)return;let A=K.get(Z)??null,_=Q.regionLineIndices.get(Z)??null;if(!A||!_||_.length===0)return;let N=Q.lines[_[0]]??null;if(!N)return;let z=nM(A,N.height);if(z.width===0)return;let E=iM({context:J,endIndex:Y,fillStyle:D.activeBlockBackground,layout:Q,left:z.left,lineIndices:_,startIndex:q,verticalBleed:V,width:z.width}),L=G.path?$.get(G.path)??null:null;if(L)iM({context:J,endIndex:Y,fillStyle:S5(D.activeBlockFlash,L),layout:Q,left:z.left,lineIndices:_,startIndex:q,verticalBleed:V,width:z.width});if(!E)return;tM(J,z,D)}function iM({context:$,endIndex:M,fillStyle:Z,layout:J,left:X,lineIndices:Y,startIndex:Q,verticalBleed:K,width:q}){$.fillStyle=Z;let D=!1;for(let V of Y){if(V<Q)continue;if(V>=M)break;let G=J.lines[V];$.fillRect(X,G.top-K,q,G.height),D=!0}return D}function nM($,M){return{height:Math.max($.bottom-$.top,M),left:$.left,top:$.top,width:Math.max($.right-$.left,tD)}}function tM($,M,Z){$.strokeStyle=Z.tableBorder,$.strokeRect(M.left,M.top,M.width,M.height)}var F3=2,eD=3,$q=12,Mq=6,Zq=3,Jq=1,Xq=2,Yq=2,Qq=8,Kq=12,Dq=28,qq=4,Vq=5,Uq=2,Gq=3,Aq=6,eM=3,Nq=12,_q=10,Fq=2,zq=2,Hq=1,Eq=2,z3=2,$Z=1.25,Wq=5,yq=1,MZ=4,Bq=4,Pq=1.5;function wq({activeBlockId:$,activeRegionId:M,activeThreadIndex:Z,containerLineBounds:J,context:X,devicePixelRatio:Y,editorState:Q,height:K,layout:q,liveCommentRanges:D,normalizedSelection:V,now:G=sq(),resources:U,runtimeBlockMap:A,theme:_,viewportTop:N,width:z}){X.save(),X.scale(Y,Y),X.clearRect(0,0,z,K),X.fillStyle=_.background,X.fillRect(0,0,z,K),X.textBaseline="alphabetic",X.translate(0,-N);let E=bq(Q,V),{endIndex:L,startIndex:W}=D6(q,N,K),R=e7(Q,G),S=$$(Q,G),I=t7(Q,G),y=Z$(Q,G),b=M$(Q,G),H=jq(q,Q,$,W,L),j=Tq(q,Q,A,W,L,z);for(let B=W;B<L;B+=1){let P=q.lines[B];Rq({containerLineBounds:J,context:X,editorState:Q,line:P,runtimeBlockMap:A,theme:_,width:z})}oM({activeBlockFlashes:R,activeBlockId:$,activeRegionId:M,context:X,editorState:Q,endIndex:L,layout:q,regionBounds:J,startIndex:W,theme:_,verticalBleed:F3});for(let B=W;B<L;B+=1){let P=q.lines[B];Sq({activeBlockId:$,activeBlockFlashes:R,activeDeletedTextFades:S,activeThreadIndex:Z,activeInsertedTextHighlights:I,activeListMarkerPops:y,activePunctuationPulses:b,context:X,editorState:Q,line:P,liveCommentRanges:D,normalizedSelection:V,resources:U,runtimeBlockMap:A,selectionRegionOrderRange:E,theme:_,width:z})}Oq(X,j,_),Lq(X,H,_),X.restore()}function bq($,M){let Z=$.documentIndex.regionOrderIndex,J=Z.get(M.start.regionId),X=Z.get(M.end.regionId);return J===void 0||X===void 0?null:{end:X,start:J}}function Tq($,M,Z,J,X,Y){let Q=new Map;for(let K=J;K<X;K+=1){let q=$.lines[K],D=Z.get(q.blockId);if(D?.type!=="heading"||D.depth!==1&&D.depth!==2)continue;let V=Q.get(D.id),G={bottom:q.top+q.height,left:q.left+I0(M,q),right:Y-$.options.paddingX};Q.set(D.id,V?{bottom:Math.max(V.bottom,G.bottom),left:V.left,right:V.right}:G)}return Q}function jq($,M,Z,J,X){let Y=new Map;for(let Q=J;Q<X;Q+=1){let K=$.lines[Q],q=X2(M,K.blockId,"blockquote");if(!q)continue;let D=Y.get(q.id),V={bottom:K.top+K.height,isActive:K.blockId===Z,left:$.options.paddingX+(q.depth+1)*$.options.indentWidth-10,top:K.top};Y.set(q.id,D?{bottom:Math.max(D.bottom,V.bottom),isActive:D.isActive||V.isActive,left:D.left,top:Math.min(D.top,V.top)}:V)}return Y}function Oq($,M,Z){$.fillStyle=Z.headingRule;for(let J of M.values())$.fillRect(J.left,J.bottom+Wq,Math.max(z3,J.right-J.left),yq)}function Lq($,M,Z){for(let J of M.values())$.fillStyle=J.isActive?Z.blockquoteRuleActive:Z.blockquoteRule,$.fillRect(J.left,J.top+eD,Zq,Math.max($q,J.bottom-J.top-Mq))}function Cq({context:$,devicePixelRatio:M,editorState:Z,height:J,layout:X,normalizedSelection:Y,presence:Q,showCaret:K,theme:q,viewportTop:D,width:V}){$.save(),$.scale(M,M),$.clearRect(0,0,V,J);let G=Y.start.regionId===Y.end.regionId&&Y.start.offset!==Y.end.offset,U=K&&!G;if($.translate(0,-D),U)ZZ($,Z,X,{color:q.caret,offset:Z.selection.focus.offset,regionId:Z.selection.focus.regionId});if(Q)for(let A of Q){if(!A.cursorPoint)continue;ZZ($,Z,X,{color:A.color??q.leafAccent,offset:A.cursorPoint.offset,regionId:A.cursorPoint.regionId})}$.restore()}function ZZ($,M,Z,J){let X=g0(Z,M.documentIndex,{regionId:J.regionId,offset:J.offset});if(!X)return;let Y=p0(M,Z,X),Q=gq(Z,X);$.fillStyle=J.color,$.fillRect(Y,Q.top,Xq,Q.height)}function Rq({containerLineBounds:$,context:M,editorState:Z,line:J,runtimeBlockMap:X,theme:Y,width:Q}){let K=X.get(J.blockId)??null,q=$.get(J.regionId)??null,D=Z.documentIndex.tableCellIndex.get(J.regionId)??null;kq(M,J,K,q,D,Y,Q)}function Sq({activeBlockId:$,activeBlockFlashes:M,activeDeletedTextFades:Z,activeThreadIndex:J,activeInsertedTextHighlights:X,activeListMarkerPops:Y,activePunctuationPulses:Q,context:K,editorState:q,line:D,liveCommentRanges:V,normalizedSelection:G,resources:U,runtimeBlockMap:A,selectionRegionOrderRange:_,theme:N,width:z}){let E=A.get(D.blockId)??null,L=q.documentIndex.blockIndex.get(D.blockId)?.path??null,W=q.documentIndex.regionIndex.get(D.regionId)??null,R=W?.path??"",S=X2(q,D.blockId,"listItem"),I=S?p2(q,S.id):null,y=S?Y.get(S.path)??null:null,b=D.left+I0(q,D),H=xq(D),j=E?.type==="code"?N.codeText:cq(E,N);K.font=D.font,mq(K,D,E,L,$,M,N,z),fq(K,q,D,G,_,N),vq(K,q,D,V,J,N),aM(K,D,I,b,H,N,y),uq(K,D,W,b,H,X.get(R)??[],j,U,N),hq(K,D,W,b,H,Z.get(R)??[],j),Iq(K,D,W,b,H,Q.get(R)??[],N)}function kq($,M,Z,J,X,Y,Q){if(!J||M.start!==0)return;if(Z?.type==="code"){let K=Math.max(0,M.left-Kq);$.fillStyle=Y.codeBackground,$.fillRect(K,J.top-qq,Math.max(J.right-M.left+Dq,Q-K),J.bottom-J.top+Qq);return}if(Z?.type!=="table")return;sM({context:$,containerBounds:J,isHeaderRow:X?.rowIndex===0,lineHeight:M.height,theme:Y})}function mq($,M,Z,J,X,Y,Q,K){if(M.blockId!==X||Z?.type==="table")return;let q=J?Y.get(J)??null:null;if($.fillStyle=Q.activeBlockBackground,$.fillRect(0,M.top-F3,K,M.height),!q)return;$.fillStyle=S5(Q.activeBlockFlash,q),$.fillRect(0,M.top-F3,K,M.height)}function fq($,M,Z,J,X,Y){if(!X)return;let Q=M.documentIndex.regionOrderIndex.get(Z.regionId);if(Q===void 0||Q<X.start||Q>X.end)return;let K=Q===X.start?Math.max(Z.start,J.start.offset):Z.start,q=Q===X.end?Math.min(Z.end,J.end.offset):Z.end;if(q<=K)return;$.fillStyle=Y.selectionBackground,$.fillRect(D1(M,Z,K-Z.start),Z.top+Hq,Math.max(zq,D1(M,Z,q-Z.start)-D1(M,Z,K-Z.start)),Z.height-Eq)}function vq($,M,Z,J,X,Y){for(let Q of J){if(Q.regionId!==Z.regionId)continue;let K=Math.max(Q.startOffset,Z.start),q=Math.min(Q.endOffset,Z.end);if(q<=K)continue;$.fillStyle=iq(Q,X,Y),$.fillRect(D1(M,Z,K-Z.start),Z.top+Z.height-Vq,Math.max(Uq,D1(M,Z,q-Z.start)-D1(M,Z,K-Z.start)),Gq)}}function uq($,M,Z,J,X,Y,Q,K,q){if(!Z){$.fillStyle=Q,$.fillText(M.text,J,X);return}let D=Z.inlines.filter((V)=>V.end>M.start&&V.start<M.end);if(D.length===0){$.fillStyle=Q,$.fillText(M.text,J,X);return}for(let V of D){let G=Math.max(M.start,V.start),U=Math.min(M.end,V.end);if(Z.text.slice(G,U).length===0)continue;let{left:_,right:N}=E3(M,J,G,U),z=aq(M.font,V.marks);if($.font=z,V.kind==="image"){let E=Math.max(24,N-_);dM($,M,V,K,q,_,E);continue}if(V.kind==="inlineCode"){let E=dq(M,z),L=rq(M,z);$.fillStyle=q.inlineCodeBackground,$.fillRect(_-eM,E,Math.max(_q,N-_+eM*2),L),JZ($,M,Z.text,J,X,G,U,q.inlineCodeText,Y,q,{strikethrough:!1,underline:!1});continue}JZ($,M,Z.text,J,X,G,U,V.link?q.linkText:Q,Y,q,{strikethrough:V.marks.includes("strikethrough"),underline:V.marks.includes("underline")||Boolean(V.link)})}}function JZ($,M,Z,J,X,Y,Q,K,q,D,V){let G=J$(Y,Q,q);for(let U=0;U<G.length-1;U+=1){let A=G[U],_=G[U+1];if(_<=A)continue;let N=Z.slice(A,_);if(N.length===0)continue;let{left:z,right:E}=E3(M,J,A,_),L=X$(q,A,_),W=Y$(K,L,D);if($.fillStyle=W,$.fillText(N,z,X),V.strikethrough)$.fillRect(z,lq(X,M.height,$.font),Math.max(z3,E-z),$Z);if(V.underline)$.fillRect(z,pq(X,M.height,$.font),Math.max(z3,E-z),$Z)}}function hq($,M,Z,J,X,Y,Q){if(!Z||Y.length===0)return;for(let K of Y){if(K.startOffset<M.start||K.startOffset>M.end)continue;let q=J+(y0(M,K.startOffset-M.start)-M.left);$.fillStyle=Q$(Q,K),$.fillText(K.text,q,X)}}function Iq($,M,Z,J,X,Y,Q){if(!Z||Y.length===0)return;for(let K of Y){if(K.offset<M.start||K.offset>=M.end)continue;let{left:q,right:D}=E3(M,J,K.offset,K.offset+1),V=Math.max(MZ,(D-q)/2+MZ+Bq*K.progress),{ascent:G,descent:U}=K1(M.font),A=X-Math.max(1,G*0.42)+Math.max(0.5,U*0.15);$.strokeStyle=K$(K,Q),$.lineWidth=Pq,$.beginPath(),$.arc((q+D)/2,A,V,0,Math.PI*2),$.stroke()}}function gq($,M){let Z=L0($,M.regionId,M.offset),J=Z?.font??'16px "Iowan Old Style", "Palatino Linotype", serif',{ascent:X,descent:Y}=K1(J),Q=Math.max(1,X+Y),K=Math.min(M.height-Yq,Q),q=Z?Math.max(Z.top,Z.top+H3(Z.height,J)-Jq):M.top+Math.max(0,Math.floor((M.height-K)/2));return{height:K,top:q}}function pq($,M,Z){let{descent:J}=K1(Z),X=Math.max(1,Math.round(Math.max(2,J)*0.35)),Y=$+J-X,Q=$-s5(M,Z);return Math.min(Q+M-4,Y)}function lq($,M,Z){let{ascent:J}=K1(Z),X=$-s5(M,Z);return Math.max(X+2,$-Math.round(J*0.32))}function xq($){return $.top+s5($.height,$.font)}function s5($,M){return L7($,M)}function dq($,M){let Z=H3($.height,M);return $.top+Z+Fq}function rq($,M){let Z=H3($.height,M);return Math.max(Nq,$.height-Z-Aq)}function H3($,M){let{ascent:Z}=K1(M);return s5($,M)-Z}function cq($,M){switch($?.type){case"heading":return M.headingText;case"blockquote":return M.blockquoteText;case"table":return M.headingText;default:return M.paragraphText}}function E3($,M,Z,J){return{left:M+(y0($,Z-$.start)-$.left),right:M+(y0($,J-$.start)-$.left)}}function aq($,M){let Z=[];if(M.includes("italic"))Z.push("italic");if(M.includes("bold"))Z.push("700");return Z.length>0?`${Z.join(" ")} ${$}`:$}function iq($,M,Z){if($.resolved)return $.threadIndex===M?Z.commentHighlightResolvedActive:Z.commentHighlightResolved;return $.threadIndex===M?Z.commentHighlightActive:Z.commentHighlight}function sq(){return typeof performance<"u"?performance.now():Date.now()}function W3($,M,Z,J){wq({activeBlockId:J.activeBlockId,activeRegionId:J.activeRegionId,activeThreadIndex:J.activeThreadIndex,containerLineBounds:M.regionBounds,context:Z,devicePixelRatio:J.devicePixelRatio,editorState:$,height:J.height,layout:M.layout,liveCommentRanges:J.liveCommentRanges,normalizedSelection:J.normalizedSelection,now:J.now,resources:J.resources??{images:new Map},runtimeBlockMap:M.blockMap,theme:J.theme,viewportTop:M.paintTop,width:J.width})}function y3($,M,Z,J){Cq({context:Z,devicePixelRatio:J.devicePixelRatio,editorState:$,height:J.height,layout:M.layout,normalizedSelection:J.normalizedSelection,presence:J.presence,showCaret:J.showCaret,theme:J.theme,viewportTop:M.paintTop,width:J.width})}import{forwardRef as $V,createElement as MV}from"react";var o5=(...$)=>$.filter((M,Z,J)=>{return Boolean(M)&&M.trim()!==""&&J.indexOf(M)===Z}).join(" ").trim();var XZ=($)=>$.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();var YZ=($)=>$.replace(/^([A-Z])|[\s-_]+(\w)/g,(M,Z,J)=>J?J.toUpperCase():Z.toLowerCase());var B3=($)=>{let M=YZ($);return M.charAt(0).toUpperCase()+M.slice(1)};import{forwardRef as eq,createElement as DZ}from"react";var n5={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 QZ=($)=>{for(let M in $)if(M.startsWith("aria-")||M==="role"||M==="title")return!0;return!1};import{createContext as oq,useContext as nq,useMemo as nH,createElement as tH}from"react";var tq=oq({});var KZ=()=>nq(tq);var qZ=eq(({color:$,size:M,strokeWidth:Z,absoluteStrokeWidth:J,className:X="",children:Y,iconNode:Q,...K},q)=>{let{size:D=24,strokeWidth:V=2,absoluteStrokeWidth:G=!1,color:U="currentColor",className:A=""}=KZ()??{},_=J??G?Number(Z??V)*24/Number(M??D):Z??V;return DZ("svg",{ref:q,...n5,width:M??D??n5.width,height:M??D??n5.height,stroke:$??U,strokeWidth:_,className:o5("lucide",A,X),...!Y&&!QZ(K)&&{"aria-hidden":"true"},...K},[...Q.map(([N,z])=>DZ(N,z)),...Array.isArray(Y)?Y:[Y]])});var v=($,M)=>{let Z=$V(({className:J,...X},Y)=>MV(qZ,{ref:Y,iconNode:M,className:o5(`lucide-${XZ(B3($))}`,`lucide-${$}`,J),...X}));return Z.displayName=B3($),Z};var ZV=[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M12 3v18",key:"108xh3"}]],V1=v("columns-2",ZV);var JV=[["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"}]],U1=v("rows-3",JV);var XV=[["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"}]],G1=v("send-horizontal",XV);var YV=[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]],N4=v("arrow-down",YV);var QV=[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]],_4=v("arrow-up",QV);var KV=[["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"}]],F4=v("bold",KV);var DV=[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]],k1=v("check",DV);var qV=[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]],z4=v("chevron-down",qV);var VV=[["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"}]],H4=v("heading-1",VV);var UV=[["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"}]],E4=v("heading-2",UV);var GV=[["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"}]],W4=v("heading-3",GV);var AV=[["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"}]],y4=v("heading-4",AV);var NV=[["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"}]],B4=v("heading-5",NV);var _V=[["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"}]],P4=v("heading-6",_V);var FV=[["path",{d:"M6 12h12",key:"8npq4p"}],["path",{d:"M6 20V4",key:"1w1bmo"}],["path",{d:"M18 20V4",key:"o2hl4u"}]],w4=v("heading",FV);var zV=[["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"}]],b4=v("italic",zV);var HV=[["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"}]],T4=v("list-ordered",HV);var EV=[["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"}]],j4=v("list-todo",EV);var WV=[["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"}]],O4=v("list",WV);var yV=[["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"}]],L4=v("message-square-plus",yV);var BV=[["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"}]],m1=v("pencil",BV);var PV=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"M12 5v14",key:"s699le"}]],H2=v("plus",PV);var wV=[["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"}]],C4=v("strikethrough",wV);var bV=[["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"}]],A1=v("table-2",bV);var TV=[["path",{d:"M17 5H3",key:"1cn7zz"}],["path",{d:"M21 12H8",key:"scolzb"}],["path",{d:"M21 19H8",key:"13qgcb"}],["path",{d:"M3 12v7",key:"1ri8j3"}]],R4=v("text-quote",TV);var jV=[["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"}]],T0=v("trash-2",jV);var OV=[["path",{d:"M6 4v6a6 6 0 0 0 12 0V4",key:"9kb039"}],["line",{x1:"4",x2:"20",y1:"20",y2:"20",key:"nun2al"}]],S4=v("underline",OV);var LV=[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]],k4=v("x",LV);import{jsx as E2,jsxs as kV}from"react/jsx-runtime";function VZ({insetX:$,insetY:M,onSelect:Z,presence:J}){if(!J)return null;return E2("div",{"aria-label":"Presence",className:"documint-presence-indicators",style:{paddingRight:`${$}px`,top:`${M}px`},children:J.map((X)=>E2(CV,{onSelect:()=>Z(X),presence:X},X.id))})}function CV({onSelect:$,presence:M}){let Z=M.viewport,J=RV(M),X=Z?.status==="above"?_4:N4,Y=Z!==null&&Z.status!=="unresolved",Q=Z?.status==="above"||Z?.status==="below";return kV("button",{"aria-label":SV(M),className:"documint-presence-indicator","data-status":Z?.status??"unresolved",disabled:!Y,onClick:Y?$:void 0,style:{"--documint-presence-color":M.color??"var(--documint-leaf-accent)"},type:"button",children:[E2("span",{className:"documint-presence-indicator-avatar",children:M.avatarUrl?E2("img",{alt:"","aria-hidden":"true",className:"documint-presence-indicator-image",draggable:!1,src:M.avatarUrl}):J}),Q?E2("span",{className:"documint-presence-indicator-direction","aria-hidden":"true",children:E2(X,{className:"documint-presence-indicator-arrow",size:14,strokeWidth:2.3})}):null]})}function RV($){return UZ($).charAt(0).toLocaleUpperCase()}function SV($){let M=UZ($),Z=$.viewport?.status??"unresolved";if(Z==="above")return`${M} above viewport`;if(Z==="below")return`${M} below viewport`;if(Z==="unresolved")return`${M} unresolved`;return`${M} in viewport`}function UZ($){return($.fullName??$.username).trim()||"Presence"}var o=`
|
|
26
|
+
`,N1="<ins>",m4="</ins>",W2=">",f4="```",t5=":::",P3=/^:::([A-Za-z][-\w]*)(.*)$/,e5="documint-comments";var $8="`",j3="\\",b3="![",T3="[",_Z="(",GZ=")",FZ=" ",zZ=":",mV=/[A-Za-z]/,fV=/[-A-Za-z0-9_]/,vV=/^\{width=([1-9]\d*)\}/,uV=/\\([\\`*_[\]{}()#+\-.!~|])/g,HZ=/\\(.)/g,hV=[{delimiter:"**",mark:"bold"},{delimiter:"~~",mark:"strikethrough"},{delimiter:"*",mark:"italic"}];function y2($,M=[]){return O3($,0,$.length,M)}function O3($,M,Z,J){let X=[],Y=M,Q=M;while(Y<Z){let K=IV($,Y,Z,J);if(K){AZ(X,$.slice(Q,Y),J),X.push(...K.nodes),Y=K.end,Q=Y;continue}if($[Y]===j3){Y+=Math.min(2,Z-Y);continue}Y+=1}return AZ(X,$.slice(Q,Z),J),gV(X)}function IV($,M,Z,J){switch($[M]){case zZ:return nV($,M,Z);case"<":return sV($,M,Z,J);case $8:return rV($,M,Z);case"!":return cV($,M,Z);case T3:return aV($,M,Z,J);case"*":case"~":return lV($,M,Z,J);default:return null}}function AZ($,M,Z){if(M.length===0)return;$.push(i0({marks:Z,text:PZ(M)}))}function L3($,M){return Z5({originalType:$,source:M})}function gV($){let M=[];for(let Z of $){let J=M.at(-1);if(J?.type==="text"&&Z.type==="text"&&xV(J.marks,Z.marks)){M[M.length-1]=i0({marks:J.marks,text:J.text+Z.text});continue}M.push(Z)}return M}function pV($,M,Z){for(let J of hV){if(!$.startsWith(J.delimiter,M))continue;let X=$.indexOf(J.delimiter,M+J.delimiter.length);if(X<0||X>=Z)continue;return{contentEnd:X,contentStart:M+J.delimiter.length,end:X+J.delimiter.length,mark:J.mark}}return null}function lV($,M,Z,J){let X=pV($,M,Z);if(!X)return null;return{end:X.end,nodes:O3($,X.contentStart,X.contentEnd,[...J,X.mark])}}function xV($,M){return $.length===M.length&&$.every((Z,J)=>Z===M[J])}function dV($,M,Z){if($[M]!==$8)return null;let J=1;while(M+J<Z&&$[M+J]===$8)J+=1;let X=$8.repeat(J),Y=$.indexOf(X,M+J);if(Y<0||Y>=Z)return null;return{end:Y+J,value:$.slice(M+J,Y)}}function rV($,M,Z){let J=dV($,M,Z);if(!J)return null;return{end:J.end,nodes:[d1({code:J.value})]}}function cV($,M,Z){if(!$.startsWith(b3,M))return null;let J=WZ($,M+1,Z);if(J<0||$[J+1]!==_Z)return null;let X=EZ($,J+1,Z);if(!X)return null;let Y=iV($,X.end,Z);return{end:Y?.end??X.end,nodes:[E1({alt:PZ($.slice(M+b3.length,J)),title:X.title,url:X.url,width:Y?.width??null})]}}function aV($,M,Z,J){if($[M]!==T3||$.startsWith(b3,M-1))return null;let X=WZ($,M,Z);if(X<0||$[X+1]!==_Z)return null;let Y=EZ($,X+1,Z);if(!Y)return null;return{end:Y.end,nodes:[r1({children:y2($.slice(M+T3.length,X),J),title:Y.title,url:Y.url})]}}function EZ($,M,Z){let J=w3($,M+1,Z),X=J;while(X<Z&&$[X]!==GZ&&$[X]!==FZ){if($[X]===j3){X+=2;continue}X+=1}if(X===J)return null;let Y=tV($.slice(J,X));J=w3($,X,Z);let Q=null;if(J<Z&&$[J]==='"'){let K=BZ($,'"',J+1,Z);if(K<0)return null;Q=$.slice(J+1,K).replace(HZ,"$1"),J=w3($,K+1,Z)}if($[J]!==GZ)return null;return{end:J+1,title:Q,url:Y}}function iV($,M,Z){let J=vV.exec($.slice(M,Z));if(!J)return null;return{end:M+J[0].length,width:Number(J[1])}}function sV($,M,Z,J){if(!$.startsWith(N1,M))return oV($,M,Z);let X=$.indexOf(m4,M+N1.length);if(X<0||X>=Z)return{end:M+N1.length,nodes:[L3("html",N1)]};return{end:X+m4.length,nodes:O3($,M+N1.length,X,[...J,"underline"])}}function oV($,M,Z){if($[M]!=="<")return null;let J=$.indexOf(">",M+1);if(J<0||J>=Z)return null;return{end:J+1,nodes:[L3("html",$.slice(M,J+1))]}}function nV($,M,Z){if($[M]!==zZ||!mV.test($[M+1]??""))return null;let J=M+2;while(J<Z&&fV.test($[J]??""))J+=1;let X=NZ($,J,Z,"[","]"),Q=NZ($,X?.end??J,Z,"{","}")?.end??X?.end??J;return{end:Q,nodes:[L3("textDirective",$.slice(M,Q))]}}function NZ($,M,Z,J,X){if($[M]!==J)return null;let Y=yZ($,X,M+1,Z);if(Y<0)return null;return{end:Y+1}}function WZ($,M,Z){return yZ($,"]",M+1,Z)}function yZ($,M,Z,J){return BZ($,M,Z,J)}function BZ($,M,Z,J){for(let X=Z;X<J;X+=1){if($[X]===j3){X+=1;continue}if($[X]===M)return X}return-1}function w3($,M,Z){while(M<Z&&$[M]===FZ)M+=1;return M}function PZ($){return $.replace(uV,"$1")}function tV($){return $.replace(HZ,"$1")}var eV=/^:?-+:?$/;function TZ($,M){let Z=bZ($),J=$.lines[$.index+1]??"",X=C3(Z,M),Y=C3(J,M);if(!wZ(X)||!R3(Y))return null;let Q=[M8(X)],K=$U(Y);$.index+=2;while($.index<$.lines.length){let q=bZ($),D=C3(q,M);if(MU(q)||!wZ(D))break;Q.push(M8(D)),$.index+=1}return y1({align:K,rows:Q.map((q)=>c1({cells:q.map((D)=>J1({children:y2(D)}))}))})}function wZ($){let M=$.trim();return/\|/.test($)&&M.startsWith("|")&&M.endsWith("|")}function R3($){let M=M8($);return M.length>0&&M.every((Z)=>eV.test(Z.trim()))}function $U($){return M8($).map((M)=>{let Z=M.trim();if(Z.startsWith(":")&&Z.endsWith(":"))return"center";if(Z.startsWith(":"))return"left";if(Z.endsWith(":"))return"right";return null})}function M8($){return $.trim().slice(1,-1).split("|").map((Z)=>Z.trim())}function bZ($){return $.lines[$.index]??""}function MU($){return $.trim()===""}function C3($,M){return $.slice(M)}var ZU=3,JU=/^\d+\.$/,XU=/^\[( |x|X)\](?:\s|$)/,jZ=/^```([^\s`]*)?(?:\s+(.*))?$/,OZ=/^::(?!:)[A-Za-z][-\w]*/,LZ=/^(#{1,6})\s+(.*)$/,YU=/\s+#+\s*$/u,QU=/^(\s*)([-+*]|\d+\.)(?:\s+(.*)|\s*)$/,KU=/^(\*\s*){3,}$/,DU=/^(-\s*){3,}$/,qU=/^(_\s*){3,}$/;function J8($,M,Z){let J=[];while($.index<$.lines.length){let X=N0($);if($.index===$.lines.length-1&&X==="")break;if(v4(X)){$.index+=1;continue}if(B2(X)>M+ZU)break;let Q=VU($,M,Z);if(!Q)break;J.push(Q)}return J}function VU($,M,Z){return UU($,M,Z)??GU($,M)??AU($,M)??_U($,M)??FU($,M)??zU($,M)??TZ($,M)??HU($,M,Z)??EU($,M)??WU($,M)}function UU($,M,Z){let J=N0($);if(!BU(J,M))return null;let X=[];while($.index<$.lines.length){let Y=N0($),Q=B2(Y);if(v4(Y)){X.push(""),$.index+=1;continue}if(Q<M)break;let K=R0(Y,M);if(!K.startsWith(W2))break;let q=K.slice(1);if(q.startsWith(" "))q=q.slice(1);X.push(q),$.index+=1}return W0({children:J8({index:0,lines:X},0,Z)})}function GU($,M){let Z=N0($),J=R0(Z,M),X=jZ.exec(J);if(!X)return null;$.index+=1;let Y=[];while($.index<$.lines.length){let Q=N0($),K=R0(Q,M);if(K.trim()===f4){$.index+=1;break}Y.push(K),$.index+=1}return w8({language:X[1]?X[1]:null,meta:X[2]?X[2]:null,source:Y.join(o)})}function AU($,M){let Z=N0($),J=R0(Z,M),X=P3.exec(J);if(!X)return null;let Y=X[1],Q=[];$.index+=1;while($.index<$.lines.length){let K=N0($),q=R0(K,M);if($.index+=1,q.trim()===t5)break;Q.push(q)}return P9({attributes:NU(X[2]??""),body:Q.join(o),name:Y})}function NU($){let M=$.trim();if(M.startsWith("{")&&M.endsWith("}"))return M.slice(1,-1);return M}function _U($,M){let Z=N0($),J=R0(Z,M);if(!OZ.test(J))return null;return $.index+=1,X5({originalType:"leafDirective",source:J})}function FU($,M){let Z=N0($),J=LZ.exec(R0(Z,M));if(!J)return null;return $.index+=1,$5({children:y2(J[2].replace(YU,"")),depth:J[1].length})}function zU($,M){let Z=R0(N0($),M).trim();if(!CZ(Z))return null;return $.index+=1,J5()}function HU($,M,Z){let J=Z8(N0($),M);if(!J)return null;let X=[],Y=!1;while($.index<$.lines.length){let Q=N0($),K=Z8(Q,M);if(!K||K.ordered!==J.ordered)break;$.index+=1;let q=[K.content],D=!1;while($.index<$.lines.length){let V=N0($),G=B2(V);if(v4(V)){let U=bU($.lines,$.index+1);if(U<0||B2($.lines[U]??"")<=M)break;D=!0,q.push(""),$.index+=1;continue}if(G<K.contentIndent)break;if(G===M&&Z8(V,M))break;q.push(PU(V,K.contentIndent)),$.index+=1}Y||=D,X.push(s0({checked:K.checked,children:yU(q,Z),spread:D}))}return W1({items:X,ordered:J.ordered,spread:Y,start:J.ordered&&Z.preserveOrderedListStart?J.start??1:null})}function EU($,M){let Z=R0(N0($),M).trim();if(!RZ(Z))return null;return $.index+=1,X5({originalType:"html",source:Z})}function WU($,M){let Z=[];while($.index<$.lines.length){let J=N0($),X=B2(J);if(v4(J))break;if(X<M)break;let Y=R0(J,M);if(Z.length>0&&wU(J,Y,M))break;Z.push(Y),$.index+=1}return H1({children:y2(Z.join(o))})}function yU($,M){let Z=J8({index:0,lines:$},0,M);if(Z.length>0)return Z;return[H1({children:[]})]}function Z8($,M){let Z=QU.exec($);if(!Z||Z[1].length!==M)return null;let J=Z[2],X=JU.test(J),Y=X?Number(J.slice(0,-1)):null,Q=Z[3]??"",K=null;if(XU.test(Q)){if(K=Q[1]==="x"||Q[1]==="X",Q=Q.slice(3),Q.startsWith(" "))Q=Q.slice(1)}let q=Q.length>0?Z[0].length-Z[1].length-Z[2].length-Q.length:Z[0].length-Z[1].length-Z[2].length;return{checked:K,content:Q,contentIndent:M+Z[2].length+q,ordered:X,start:Y}}function BU($,M){return R0($,M).startsWith(W2)}function R0($,M){return $.slice(M)}function PU($,M){let Z=B2($);if(Z>=M)return $.slice(M);return $.trim()===""?"":$.slice(Math.min(Z,M))}function CZ($){return KU.test($)||DU.test($)||qU.test($)}function RZ($){return $.startsWith("<")&&$.endsWith(">")}function B2($){let M=0;while(M<$.length&&$[M]===" ")M+=1;return M}function wU($,M,Z){return M.startsWith(W2)||jZ.test(M)||P3.test(M)||OZ.test(M)||LZ.test(M)||CZ(M.trim())||R3(M)||Z8($,Z)!==null||RZ(M.trim())}function N0($){return $.lines[$.index]??""}function v4($){return $.trim()===""}function bU($,M){for(let Z=M;Z<$.length;Z+=1)if(!v4($[Z]??""))return Z;return-1}function kZ($){let M=$.at(-1),Z=M&&SZ(M)?M:null;return{blocks:$.filter((X)=>!SZ(X)),comments:Z?TU(Z.body):[]}}function TU($){let M;try{M=JSON.parse($)}catch{return[]}if(!Array.isArray(M))return[];return M.flatMap((Z)=>{let J=I8(Z);return J?[J]:[]})}function SZ($){return $.type==="directive"&&$.name===e5}var mZ="---";function u4($,M={}){let J={index:0,lines:$.replace(/\r\n/g,o).split(o)},X=jU(J),Y=J8(J,0,M),{comments:Q,blocks:K}=kZ(Y);return a1(K,Q,X)}function jU($){if($.lines[0]!==mZ)return;for(let M=1;M<$.lines.length;M+=1)if($.lines[M]===mZ){let Z=$.lines.slice(0,M+1).join(o);return $.index=M+1,Z}return}var P2=`
|
|
27
|
+
|
|
28
|
+
`,OU="-",LU=".",CU="***",RU=" ",S3=3,SU=5,kU=4,fZ=2,mU=2,fU=1,vU=/([\\`*_[\]])/g,uU=/([\\)&])/g,hU=/(["\\])/g;function X8($,M={}){if($.blocks.length===0&&$.comments.length===0&&$.frontMatter===void 0)return"";let Z=[];if($.frontMatter!==void 0)Z.push($.frontMatter);if($.blocks.length>0)Z.push(k3($.blocks,M));if($.comments.length>0)Z.push(ZG($.comments));let J=Z.join(P2);return J.endsWith(o)?J:`${J}${o}`}function k3($,M={}){return $.map((Z)=>Y8(Z,0,M)).join(P2)}function Y8($,M,Z){let J=_1(M);switch($.type){case"blockquote":return IU($,M,Z);case"code":return gU($,M);case"directive":return JG($,M);case"heading":return uZ($,M);case"list":return pU($,M,Z);case"listItem":return hZ($,M,!1,1,Z);case"paragraph":return`${J}${m3(f1($.children))}`;case"table":return xU($,M,Z);case"thematicBreak":return`${J}${CU}`;case"unsupported":return M===0?$.source:pZ($.source,M)}}function IU($,M,Z){let J=$.children.map((Y)=>Y8(Y,0,Z)).join(P2),X=_1(M);return J.split(o).map((Y)=>`${X}${W2}${Y.length>0?` ${Y}`:""}`).join(o)}function gU($,M){let Z=[$.language??"",$.meta??""].filter(Boolean).join(" ").trim(),J=_1(M),X=`${J}${f4}${Z?Z:""}`,Y=$.source.length>0?$.source.split(o).map((Q)=>`${J}${Q}`).join(o):J;return`${X}${o}${Y}${o}${J}${f4}`}function uZ($,M){let Z=m3(f1($.children)),J=`${_1(M)}${"#".repeat($.depth)}`;return Z.length>0?`${J} ${Z}`:J}function pU($,M,Z){let J=$.start??1;return $.items.map((X)=>hZ(X,M,$.ordered,J,Z)).join($.spread?P2:o)}function hZ($,M,Z,J,X){let Y=Z?`${J}${LU}`:OU,Q=$.checked===null?"":`[${$.checked?"x":" "}] `,K=`${_1(M)}${Y} ${Q}`,q=M+Y.length+1,D=$.children;if(D.length===0)return Q.length>0?K:K.trimEnd();let[V,...G]=D,U=lU(V,K,Q.length>0,X),A=G.map((_)=>Y8(_,q,X)).join($.spread?P2:o);if(!A)return U;return`${U}${$.spread?P2:o}${A}`}function lU($,M,Z,J){switch($.type){case"paragraph":{let X=m3(f1($.children));if(X.length===0)return Z?M:M.trimEnd();return`${M}${X}`}case"heading":return`${M}${uZ($,0)}`;case"directive":case"unsupported":{let X=$.type==="directive"?f3($):$.source,[Y,...Q]=X.split(o);return[M+Y,...Q.map((K)=>`${_1(M.length)}${K}`)].join(o)}default:{let X=M.length;return`${M.trimEnd()}${o}${Y8($,X,J)}`}}}function xU($,M,Z){let J=$.rows.map((V)=>V.cells.map((G)=>f1(G.children))),X=Math.max(1,...J.map((V)=>V.length)),Y=J[0]??[],Q=Array.from({length:X},(V,G)=>Math.max(S3,aU($.align[G]),...Z.padTableColumns?J.map((U)=>U[G]?.length??0):[Y[G]?.length??0])),K=dU(Q,$.align,M),q=vZ(Y,Q,$.align,M,Z),D=J.slice(1).map((V)=>vZ(V,Q,$.align,M,Z));return[q??rU(Q,M),K,...D].join(o)}function vZ($,M,Z,J,X){let Y=M.map((Q,K)=>{let q=$[K]??"";if(!X.padTableColumns)return q;return iU(q,Q,Z[K])});return`${" ".repeat(J)}| ${Y.join(" | ")} |`}function dU($,M,Z){let J=$.map((X,Y)=>cU(M[Y],X));return`${" ".repeat(Z)}| ${J.join(" | ")} |`}function rU($,M){return`${_1(M)}| ${$.map((Z)=>"".padEnd(Z," ")).join(" | ")} |`}function cU($,M){let Z=Math.max(S3,M-($==="center"?mU:$?fU:0));switch($){case"center":return`:${"-".repeat(Math.max(1,Z))}:`;case"left":return`:${"-".repeat(Math.max(fZ,Z))}`;case"right":return`${"-".repeat(Math.max(fZ,Z))}:`;default:return"-".repeat(Z)}}function aU($){return $==="center"?SU:$?kU:S3}function iU($,M,Z){if(Z==="right")return $.padStart(M," ");return $.padEnd(M," ")}function f1($){return oU($).map((M)=>sU(M)).join("")}function m3($){return $.replace(/^ +/gm,(M)=>RU.repeat(M.length))}function sU($){switch($.type){case"break":return o;case"image":return XG($);case"inlineCode":return eU($.code);case"link":return YG($);case"text":return tU(IZ($.text),$.marks);case"unsupported":return $.source}}function oU($){let M=[];for(let Z of $){let J=M.at(-1);if(J?.type==="text"&&Z.type==="text"&&nU(J.marks,Z.marks)){M[M.length-1]={...J,text:J.text+Z.text};continue}M.push(Z)}return M}function nU($,M){return $.length===M.length&&$.every((Z,J)=>Z===M[J])}function tU($,M){return M.reduce((Z,J)=>{switch(J){case"bold":return`**${Z}**`;case"italic":return`*${Z}*`;case"strikethrough":return`~~${Z}~~`;case"underline":return`${N1}${Z}${m4}`}},$)}function eU($){let M=0,Z=0;for(let Q of $){if(Q==="`"){if(Z+=1,Z>M)M=Z;continue}Z=0}let J=M>0?M+1:1,X="`".repeat(J),Y=$.startsWith("`")||$.endsWith("`")?` ${$} `:$;return`${X}${Y}${X}`}function IZ($){return $.replace(vU,"\\$1")}function $G($){return $.replace(uU,"\\$1")}function MG($){return $?` "${$.replace(hU,"\\$1")}"`:""}function ZG($){return f3({attributes:"",body:JSON.stringify($,null,2),name:e5})}function JG($,M){let Z=f3($);return M===0?Z:pZ(Z,M)}function f3($){let M=$.attributes?`{${$.attributes}}`:"";return`:::${$.name}${M}${o}${$.body}${o}${t5}`}function XG($){let M=IZ($.alt??""),Z=gZ($.url,$.title),J=$.width?`{width=${$.width}}`:"";return`![${M}]${Z}${J}`}function YG($){return`[${f1($.children)}]${gZ($.url,$.title)}`}function gZ($,M){return`(${$G($)}${MG(M)})`}function _1($){return" ".repeat($)}function pZ($,M){let Z=_1(M);return $.split(o).map((J)=>`${Z}${J}`).join(o)}function v3($){if($.length===0)return{kind:"text",text:""};let{blocks:M}=u4($);if(K5(M))return{kind:"text",text:M[0]?.plainText??""};if(M.length===1&&M[0]?.type==="paragraph")return{kind:"inlines",inlines:M[0].children};return{kind:"blocks",blocks:M}}function Q8($){switch($.kind){case"text":return $.text;case"inlines":return f1($.inlines);case"blocks":return k3($.blocks)}}import{createContext as QG,useContext as KG}from"react";import{createPortal as DG}from"react-dom";import{jsx as dZ}from"react/jsx-runtime";var lZ=QG(void 0);function xZ({children:$,themeStyles:M}){return dZ(lZ.Provider,{value:M,children:$})}function K8({children:$}){let M=KG(lZ);if(typeof document>"u")return null;return DG(dZ("div",{className:"documint-overlay",style:{display:"contents",...M},children:$}),document.body)}import{useEffect as D8,useRef as XJ,useState as v1}from"react";import{forwardRef as VG,useCallback as w2,useEffect as UG,useImperativeHandle as GG,useLayoutEffect as AG,useMemo as NG,useRef as aZ,useState as u3}from"react";var qG=["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 rZ($,M,{topGap:Z=8}={}){if(!$.isConnected)return null;let J=getComputedStyle($),X=document.createElement("div");for(let D of qG)X.style.setProperty(D,J.getPropertyValue(D));Object.assign(X.style,{position:"absolute",top:"0",left:"0",visibility:"hidden",whiteSpace:"pre-wrap",wordWrap:"break-word",width:`${$.clientWidth}px`}),X.textContent=$.value.slice(0,M);let Y=document.createElement("span");Y.textContent=$.value.slice(M)||".",X.appendChild(Y),document.body.appendChild(X);let Q=$.getBoundingClientRect(),K=parseFloat(J.lineHeight)||Y.offsetHeight,q={left:Q.left+Y.offsetLeft+parseFloat(J.borderLeftWidth)-$.scrollLeft,top:Q.top+Y.offsetTop+parseFloat(J.borderTopWidth)+K+Z-$.scrollTop};return document.body.removeChild(X),q}import{jsx as S0,jsxs as iZ,Fragment as PG}from"react/jsx-runtime";var _G=240,FG="documint-leaf-menu-item documint-completion-item",h4=VG(function({actions:M,completionSources:Z,onChange:J,placeholder:X,readOnly:Y=!1,rows:Q=3,value:K},q){let D=aZ(null);GG(q,()=>D.current,[]);let V=NG(()=>WG(Z),[Z]),[G,U]=u3(null),[A,_]=u3(0),[N,z]=u3(null),E=w2((y,b)=>{if(!V.length){U(null);return}let H=yG(y,b,V);if(!H){U(null);return}U(H),_(0)},[V]),L=w2((y)=>{let b=y.currentTarget.value,H=y.currentTarget.selectionEnd??b.length;J(b),E(b,H)},[J,E]),W=w2((y)=>{let b=y.currentTarget;E(b.value,b.selectionEnd??b.value.length)},[E]),R=w2(()=>{U(null)},[]),S=w2((y)=>{if(!D.current||!G)return;let H=`${G.trigger}${y.label} `,j=K.slice(0,G.triggerStart),B=K.slice(G.caret),P=j+H+B,F=G.triggerStart+H.length;J(P),U(null),requestAnimationFrame(()=>{let C=D.current;if(!C)return;C.focus(),C.setSelectionRange(F,F)})},[G,J,K]),I=w2((y)=>{if(G&&G.matches.length>0){if(y.key==="ArrowDown"){y.preventDefault(),y.stopPropagation(),_((b)=>(b+1)%G.matches.length);return}if(y.key==="ArrowUp"){y.preventDefault(),y.stopPropagation(),_((b)=>(b-1+G.matches.length)%G.matches.length);return}if(y.key==="Enter"||y.key==="Tab"){y.preventDefault(),y.stopPropagation();let b=G.matches[A];if(b)S(b);return}if(y.key==="Escape"){y.preventDefault(),y.stopPropagation(),U(null);return}}if(y.key==="Escape"&&M.kind==="edit")y.preventDefault(),M.onCancel()},[M,G,A,S]);return AG(()=>{if(!G){z(null);return}let y=()=>{let b=D.current;if(!b)return;z(rZ(b,G.triggerStart))};return y(),window.addEventListener("scroll",y,!0),window.addEventListener("resize",y),()=>{window.removeEventListener("scroll",y,!0),window.removeEventListener("resize",y)}},[G]),iZ("div",{className:"documint-leaf-input-field",children:[S0("textarea",{className:"documint-leaf-input",onBlur:R,onChange:L,onKeyDown:I,onSelect:W,placeholder:X,readOnly:Y,ref:D,rows:Q,value:K}),zG(M),G&&N&&G.matches.length>0?S0(K8,{children:S0(HG,{activeIndex:A,left:N.left,matches:G.matches,onHover:_,onSelect:S,top:N.top})}):null]})});function zG($){if($.kind==="edit")return iZ(PG,{children:[S0(h3,{className:"documint-leaf-input-cancel",icon:k4,label:"Cancel editing",onClick:$.onCancel}),S0(h3,{className:"documint-leaf-input-save",disabled:$.saveDisabled??!1,icon:k1,label:"Save",onClick:$.onSave})]});return S0(h3,{className:"documint-leaf-input-submit",disabled:$.submitDisabled??!1,icon:G1,iconSize:15,label:$.submitLabel,onClick:$.onSubmit})}function h3({className:$,disabled:M=!1,icon:Z,iconSize:J=14,label:X,onClick:Y}){return S0("button",{"aria-label":X,className:`documint-leaf-action ${$}`,disabled:M,onClick:Y,title:X,type:"button",children:S0(Z,{size:J,strokeWidth:2.2})})}function HG({activeIndex:$,left:M,matches:Z,onHover:J,onSelect:X,top:Y}){let Q=aZ(null);return UG(()=>{let K=Q.current;if(!K)return;let q=K.children[$];if(q instanceof HTMLElement)q.scrollIntoView({block:"nearest"})},[$]),S0("div",{className:"documint-leaf-menu documint-completion-popover",ref:Q,role:"listbox",style:{position:"fixed",left:M,top:Y,maxHeight:_G,overflowY:"auto"},children:Z.map((K,q)=>{let D=q===$;return S0("button",{"aria-selected":D,className:`${FG}${D?" is-active":""}`,onPointerDown:EG,onPointerEnter:()=>J(q),onClick:()=>X(K),role:"option",type:"button",children:S0("span",{children:K.label})},K.label)})})}function EG($){$.preventDefault()}function WG($){if(!$?.length)return[];return $.map((M)=>({trigger:M.trigger,items:[...M.items].sort((Z,J)=>Z.label.localeCompare(J.label,void 0,{sensitivity:"base"}))}))}function yG($,M,Z){for(let J=M-1;J>=0;J-=1){let X=$[J];if(cZ(X))return null;let Y=Z.find((K)=>K.trigger===X);if(!Y)continue;if(J>0&&!cZ($[J-1]))return null;let Q=$.slice(J+1,M);return{trigger:Y.trigger,query:Q,triggerStart:J,caret:M,matches:BG(Y.items,Q)}}return null}function cZ($){return $===void 0||$===" "||$===`
|
|
29
|
+
`||$==="\t"}function BG($,M){if(!M)return $;let Z=M.toLowerCase();return $.filter((J)=>J.label.toLowerCase().includes(Z))}import{Fragment as bG}from"react";function I3($,M){if(!M?.length||!M.some((Q)=>$.includes(Q.trigger)))return[{kind:"text",text:$}];let Z=new Map;for(let Q of M){let K=[...Q.items].sort((q,D)=>D.label.length-q.label.length);Z.set(Q.trigger,K)}let J=[],X=0,Y=0;while(X<$.length){let Q=$[X],K=Z.get(Q);if(K!==void 0&&(X===0||wG($[X-1]))){let D=K.find((V)=>$.startsWith(V.label,X+1));if(D){if(X>Y)J.push({kind:"text",text:$.slice(Y,X)});J.push({kind:"token",trigger:Q,label:D.label,id:D.id}),X+=1+D.label.length,Y=X;continue}}X+=1}if(Y<$.length)J.push({kind:"text",text:$.slice(Y)});return J}function g3($,M){let Z=[],J=new Set;for(let X of I3($,M)){if(X.kind!=="token"||X.trigger!=="@"||!X.id)continue;if(J.has(X.id))continue;J.add(X.id),Z.push(X.id)}return Z}function wG($){return $===void 0||$===" "||$===`
|
|
30
|
+
`||$==="\t"}import{jsx as sZ,jsxs as jG}from"react/jsx-runtime";function p3({value:$,completionSources:M,onEdit:Z}){return sZ("p",{onDoubleClick:Z,children:TG($,M)})}function TG($,M){let Z=I3($,M);if(Z.length===1&&Z[0].kind==="text")return $;return Z.map((J,X)=>J.kind==="token"?jG("span",{className:"documint-mention",children:[J.trigger,J.label]},X):sZ(bG,{children:J.text},X))}import{Children as oZ,isValidElement as nZ,useEffect as OG,useRef as LG,useState as CG}from"react";import{jsx as V0,jsxs as d3}from"react/jsx-runtime";var l3=($)=>{$.preventDefault()},x3=($)=>$.isPrimary&&$.button===0;function RG({children:$}){return V0("div",{className:"documint-leaf-toolbar",children:oZ.map($,SG)})}function SG($){if(!nZ($))return null;if($.type===eZ){let M=$.props;return V0(tZ,{children:V0(kG,{...M})})}if($.type===$J){let{className:M}=$.props;return V0("div",{className:I4("documint-leaf-toolbar-divider",M)})}if($.type===MJ){let M=$.props;return V0(mG,{...M})}return null}function kG({active:$=!1,className:M,disabled:Z=!1,icon:J,label:X,onClick:Y}){return V0("button",{"aria-label":X,className:I4("documint-leaf-toolbar-button",$?"active":null,M),disabled:Z,onPointerDown:(Q)=>{if(l3(Q),!Z&&x3(Q))Y()},title:X,type:"button",children:V0(J,{size:15,strokeWidth:2.2})})}function mG({children:$,className:M,icon:Z,label:J,onSelect:X}){let Y=LG(null),[Q,K]=CG(!1);return OG(()=>{if(!Q)return;let q=(D)=>{if(Y.current&&D.target instanceof Node&&!Y.current.contains(D.target))K(!1)};return window.addEventListener("pointerdown",q),()=>{window.removeEventListener("pointerdown",q)}},[Q]),V0(tZ,{children:d3("div",{className:"documint-leaf-toolbar-menu-shell",ref:Y,children:[V0(fG,{className:M,icon:Z,isOpen:Q,label:J,onClick:()=>K((q)=>!q)}),Q?V0("div",{className:"documint-leaf-menu",role:"menu",children:oZ.map($,(q)=>vG(q,(D)=>{K(!1),X(D)}))}):null]})})}function fG({className:$,icon:M,isOpen:Z,label:J,onClick:X}){return d3("button",{"aria-expanded":Z,"aria-haspopup":"menu","aria-label":J,className:I4("documint-leaf-toolbar-button",Z?"active":null,$),onPointerDown:(Y)=>{if(l3(Y),x3(Y))X()},title:J,type:"button",children:[V0(M,{size:15,strokeWidth:2.2}),V0(z4,{className:I4("documint-leaf-toolbar-menu-chevron",Z?"is-open":null),size:13,strokeWidth:2.2})]})}function vG($,M){if(!nZ($))return null;if($.type===JJ){let{className:Q}=$.props;return V0("div",{className:I4("documint-leaf-menu-divider",Q),role:"separator"})}if($.type!==ZJ)return null;let{disabled:Z=!1,icon:J,text:X,value:Y}=$.props;return d3("button",{className:"documint-leaf-menu-item",disabled:Z,onPointerDown:(Q)=>{if(l3(Q),!Z&&x3(Q))M(Y)},role:"menuitem",type:"button",children:[V0(J,{size:15,strokeWidth:2.2}),V0("span",{children:X})]})}function I4(...$){return $.filter(Boolean).join(" ")}function tZ({children:$}){return V0("div",{className:"documint-leaf-toolbar-group",children:$})}function eZ($){return null}function $J($){return null}function MJ($){return null}function ZJ($){return null}function JJ($){return null}var r=Object.assign(RG,{Button:eZ,Divider:$J,Menu:MJ,MenuDivider:JJ,MenuItem:ZJ});import{jsx as n,jsxs as x0,Fragment as gG}from"react/jsx-runtime";var uG=!1,hG=220,u1=()=>{};function r3($){let M=$.mode==="create",Z=$.mode==="create"?$:null,J=$.mode==="thread"?$:null,X=$.canEdit,Y=$.link,Q=J?.thread??null,K=Q?.comments??[],q=K[0]??null,D=Q?X1(Q):!1,V=J?.animateInitialComment??!1,[G,U]=v1(null),[A,_]=v1(""),[N,z]=v1(""),[E,L]=v1(""),[W,R]=v1(!V),[S,I]=v1(uG),[y,b]=v1(!1),H=XJ(null),j=XJ(null),B=$.mentionSources,P=Q?c8(Q):null,F=P?YJ(P):"",C=X&&!D,u=C&&A.trim().length>0,h=C&&N.trim().length>0,g=X&&E.trim().length>0,w=M||y,T=!M||S,k=!M&&Boolean(Q),m=Boolean(q),a=M?S:!0,l=J?.onDeleteComment??u1,F0=J?.onDeleteThread??u1,c0=J?.onToggleResolved??u1,k0=Z?.activeMarks??[],m0=Z?.onToggleBold??u1,a0=Z?.onToggleItalic??u1,z8=Z?.onToggleStrikethrough??u1,H8=Z?.onToggleUnderline??u1,a4=X?M?"Add a comment":"Reply to this comment":"Comment editing is disabled",E8=M?E:N;D8(()=>{if(G!==null&&(G<0||G>=K.length))U(null),_("")},[K.length,G]),D8(()=>{if(!m||!V){R(!0);return}R(!1);let i=requestAnimationFrame(()=>{R(!0)});return()=>{cancelAnimationFrame(i)}},[V,q,m]),D8(()=>{if(!J||!V){b(!1);return}b(!0);let i=window.setTimeout(()=>{b(!1)},hG);return()=>{window.clearTimeout(i)}},[V,J]),D8(()=>{if(!M||!S||!X)return;let i=requestAnimationFrame(()=>{j.current?.focus()});return()=>{cancelAnimationFrame(i)}},[X,M,S]);let O2=()=>{U(null),_("")},i4=(i,s4)=>{if(!k||!C)return;U(i),_(s4)},f0=(i)=>{if(!J)return;J.onEditComment(i,A),O2()},P0=()=>{if(!J)return;J.onReply(N),z("")},g1=()=>{if(!Z||!g)return;Z.onCreateThread(E),L("")},W8=w?`documint-comment-leaf documint-comment-leaf-create${a?" is-expanded":""}`:"documint-comment-leaf",p1=k||m||T?n(IG,{canCreate:g,canEdit:X,canMutateThread:C,canReply:h,canSaveEditedComment:u,comments:K,composerRef:j,editDraft:A,editingCommentIndex:G,isComposerVisible:T,isInitialCommentVisible:W,isResolved:D,link:Y,mentionSources:B,mode:$.mode,onBeginEditingComment:i4,onCancelEditing:O2,onChangeCreateDraft:L,onChangeEditDraft:_,onChangeReplyDraft:z,onDeleteComment:l,onDeleteThread:F0,onSubmitCreate:g1,onSubmitEditedComment:f0,onSubmitReply:P0,onToggleResolved:c0,rootComment:q,showRootComment:m,showThreadChrome:k,threadAge:F,composerPlaceholder:a4,composerValue:E8}):null;return n("div",{className:W8,ref:H,children:x0("div",{className:w?"documint-comment-leaf-create-shell":void 0,children:[w?x0(r,{children:[n(r.Button,{className:"documint-comment-leaf-create-button",icon:L4,label:"Add comment",onClick:()=>I(!0)}),n(r.Divider,{className:"documint-comment-leaf-create-divider"}),n(r.Button,{active:k0.includes("bold"),className:"documint-comment-leaf-create-mark",icon:F4,label:"Bold",onClick:m0}),n(r.Button,{active:k0.includes("italic"),className:"documint-comment-leaf-create-mark",icon:b4,label:"Italic",onClick:a0}),n(r.Button,{active:k0.includes("underline"),className:"documint-comment-leaf-create-mark",icon:S4,label:"Underline",onClick:H8}),n(r.Button,{active:k0.includes("strikethrough"),className:"documint-comment-leaf-create-mark",icon:C4,label:"Strikethrough",onClick:z8})]}):null,n("div",{className:w?"documint-comment-leaf-create-content":void 0,children:p1})]})})}function IG({canCreate:$,canEdit:M,canMutateThread:Z,canReply:J,canSaveEditedComment:X,comments:Y,composerRef:Q,editDraft:K,editingCommentIndex:q,isComposerVisible:D,isInitialCommentVisible:V,isResolved:G,link:U,mentionSources:A,mode:_,onBeginEditingComment:N,onCancelEditing:z,onChangeCreateDraft:E,onChangeEditDraft:L,onChangeReplyDraft:W,onDeleteComment:R,onDeleteThread:S,onSubmitCreate:I,onSubmitEditedComment:y,onSubmitReply:b,onToggleResolved:H,rootComment:j,showRootComment:B,showThreadChrome:P,threadAge:F,composerPlaceholder:C,composerValue:u}){return x0(gG,{children:[P?x0("div",{className:"documint-comment-leaf-header",children:[n("span",{className:"documint-comment-leaf-age",children:F}),x0("div",{className:"documint-comment-leaf-actions",children:[n("button",{className:"documint-leaf-action","aria-label":G?"Reopen comment":"Resolve comment",disabled:!M,onClick:H,title:G?"Reopen comment":"Resolve comment",type:"button",children:n(k1,{size:14,strokeWidth:2.2})}),n("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Delete comment thread",disabled:!M,onClick:S,title:"Delete comment thread",type:"button",children:n(T0,{size:14,strokeWidth:2.2})})]})]}):null,P&&U?x0("div",{className:"documint-comment-leaf-link",children:[U.title?n("div",{className:"documint-link-leaf-title",children:U.title}):null,n("div",{className:"documint-link-leaf-url",children:U.url})]}):null,x0("div",{className:`documint-comment-thread${B?"":" is-empty"}`,children:[n("article",{className:B?`documint-comment-message documint-comment-message-root${V?" is-visible":""}`:"documint-comment-message documint-comment-message-root is-hidden",children:j?n(p3,{completionSources:A,onEdit:()=>N(0,j.body),value:j.body}):null}),Y.slice(1).map((h,g)=>{let w=g+1,T=q===w;return x0("article",{className:"documint-comment-message",children:[!T?x0("div",{className:"documint-comment-message-meta",children:[n("span",{children:YJ(h.updatedAt)}),Z?x0("div",{className:"documint-comment-leaf-actions",children:[n("button",{className:"documint-leaf-action","aria-label":"Edit comment",disabled:!Z,onClick:()=>{N(w,h.body)},title:"Edit comment",type:"button",children:n(m1,{size:14,strokeWidth:2.2})}),n("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Delete comment",disabled:!Z,onClick:()=>R(w),title:"Delete comment",type:"button",children:n(T0,{size:14,strokeWidth:2.2})})]}):null]}):null,T?n(h4,{actions:{kind:"edit",onCancel:z,onSave:()=>y(w),saveDisabled:!X},completionSources:A,onChange:L,readOnly:!M,rows:3,value:K}):n(p3,{completionSources:A,onEdit:()=>N(w,h.body),value:h.body})]},`${h.updatedAt}:${w}`)})]}),n("div",{className:`documint-comment-reply${P?"":" is-standalone"}${D?" is-visible":""}`,children:n(h4,{actions:_==="create"?{kind:"compose",onSubmit:I,submitDisabled:!$,submitLabel:"Create comment"}:{kind:"compose",onSubmit:b,submitDisabled:!J,submitLabel:"Reply"},completionSources:A,onChange:_==="create"?E:W,placeholder:C,readOnly:!M,ref:Q,rows:3,value:u})})]})}function YJ($){let M=new Date($);if(Number.isNaN(M.getTime()))return $;let Z=M.getTime()-Date.now(),J=60000,X=60*J,Y=24*X,Q=7*Y,K=30*Y,q=365*Y,D=new Intl.RelativeTimeFormat(void 0,{numeric:"auto"});if(Math.abs(Z)<J)return"just now";if(Math.abs(Z)<X)return D.format(Math.round(Z/J),"minute");if(Math.abs(Z)<Y)return D.format(Math.round(Z/X),"hour");if(Math.abs(Z)<Q)return D.format(Math.round(Z/Y),"day");if(Math.abs(Z)<q)return D.format(Math.round(Z/K),"month");return D.format(Math.round(Z/q),"year")}import{jsx as d0,jsxs as xG}from"react/jsx-runtime";var pG=[{icon:H4,label:"Heading 1",text:"# "},{icon:E4,label:"Heading 2",text:"## "},{icon:W4,label:"Heading 3",text:"### "},{icon:y4,label:"Heading 4",text:"#### "},{icon:B4,label:"Heading 5",text:"##### "},{icon:P4,label:"Heading 6",text:"###### "}],lG=[{columns:2,text:"2 columns"},{columns:3,text:"3 columns"},{columns:4,text:"4 columns"},{columns:5,text:"5 columns"}];function QJ({onInsert:$,onInsertTable:M}){return xG(r,{children:[d0(r.Button,{icon:O4,label:"Insert bulleted list",onClick:()=>$("- ")}),d0(r.Button,{icon:T4,label:"Insert numbered list",onClick:()=>$("1. ")}),d0(r.Button,{icon:j4,label:"Insert task list",onClick:()=>$("- [ ] ")}),d0(r.Divider,{}),d0(r.Menu,{icon:w4,label:"Insert heading",onSelect:$,children:pG.map(({icon:Z,label:J,text:X})=>d0(r.MenuItem,{icon:Z,text:J,value:X},X))}),d0(r.Menu,{icon:A1,label:"Insert table",onSelect:(Z)=>M(Number(Z)),children:lG.map(({columns:Z,text:J})=>d0(r.MenuItem,{icon:A1,text:J,value:String(Z)},Z))}),d0(r.Divider,{}),d0(r.Button,{icon:R4,label:"Insert blockquote",onClick:()=>$("> ")})]})}import{jsx as c3,jsxs as dG}from"react/jsx-runtime";function KJ({anchor:$,children:M,status:Z="default"}){let J=!$.isSelection;return c3(K8,{children:dG("div",{className:"documint-leaf-anchor","data-selection":$.isSelection?"true":"false",onPointerEnter:$.onPointerEnter,onPointerLeave:$.onPointerLeave,style:{left:`${$.left}px`,top:`${$.top}px`},children:[J?c3("div",{className:"documint-leaf-bridge"}):null,c3("div",{className:"documint-leaf-shell","data-status":Z,children:M})]})})}import{useEffect as DJ,useRef as rG,useState as qJ}from"react";import{jsx as e0,jsxs as a3}from"react/jsx-runtime";function VJ({canEdit:$,onDelete:M,onSave:Z,title:J,url:X}){let[Y,Q]=qJ(X),[K,q]=qJ(!1),D=rG(null),V=cG(),G=Y.trim(),U=$&&G.length>0,A=$&&!K,_=`${V}click to open`,N=`documint-link-leaf-row${K?" is-editing":""}`;return DJ(()=>{if(K)return;Q(X)},[K,X]),DJ(()=>{if(!K)return;D.current?.focus()},[K]),a3("div",{className:"documint-link-leaf",children:[J?e0("div",{className:"documint-link-leaf-title",children:J}):null,a3("div",{className:N,children:[K?e0(h4,{actions:{kind:"edit",onCancel:()=>{Q(X),q(!1)},onSave:()=>{Z(G),q(!1)},saveDisabled:!U},onChange:Q,readOnly:!$,ref:D,rows:3,value:Y}):e0("div",{className:"documint-link-leaf-url",children:X}),A?a3("div",{className:"documint-link-leaf-actions",children:[e0("button",{className:"documint-leaf-action","aria-label":"Edit link",onClick:()=>{if(!$)return;Q(X),q(!0)},title:"Edit link",type:"button",children:e0(m1,{size:14,strokeWidth:2.2})}),e0("button",{className:"documint-leaf-action documint-leaf-action-danger","aria-label":"Remove link",onClick:M,title:"Remove link",type:"button",children:e0(T0,{size:14,strokeWidth:2.2})})]}):null]}),e0("div",{className:"documint-link-leaf-divider"}),e0("div",{className:"documint-link-leaf-hint",children:_})]})}function cG(){if(typeof navigator>"u")return"Ctrl+";let $=navigator.platform||navigator.userAgent;return/Mac|iPhone|iPad|iPod/.test($)?"CMD+":"CTRL+"}import{jsx as $1,jsxs as o3}from"react/jsx-runtime";var aG=[{text:"Column left",value:"left"},{text:"Column right",value:"right"}],iG=[{text:"Row above",value:"above"},{text:"Row below",value:"below"}],i3={text:"Delete column",value:"delete"},s3={text:"Delete row",value:"delete"},UJ={text:"Delete table",value:"delete"};function GJ({canDeleteColumn:$,canDeleteRow:M,onDeleteColumn:Z,onDeleteRow:J,onDeleteTable:X,onInsertColumn:Y,onInsertRow:Q}){return o3(r,{children:[o3(r.Menu,{icon:V1,label:"Column actions",onSelect:(K)=>{if(K===i3.value){Z();return}Y(K)},children:[aG.map(({text:K,value:q})=>$1(r.MenuItem,{icon:H2,text:K,value:q},q)),$1(r.MenuDivider,{}),$1(r.MenuItem,{disabled:!$,icon:T0,text:i3.text,value:i3.value})]}),o3(r.Menu,{icon:U1,label:"Row actions",onSelect:(K)=>{if(K===s3.value){J();return}Q(K)},children:[iG.map(({text:K,value:q})=>$1(r.MenuItem,{icon:H2,text:K,value:q},q)),$1(r.MenuDivider,{}),$1(r.MenuItem,{disabled:!M,icon:T0,text:s3.text,value:s3.value})]}),$1(r.Divider,{}),$1(r.Menu,{icon:A1,label:"Table actions",onSelect:()=>X(),children:$1(r.MenuItem,{icon:T0,text:UJ.text,value:UJ.value})})]})}import{useEffect as AJ,useEffectEvent as NJ,useLayoutEffect as _J,useMemo as sG,useRef as n3,useState as FJ}from"react";function q8($,M){if(!$||$.kind==="task-toggle")return null;if($.commentThreadIndex!==null){let Z=M[$.commentThreadIndex]??null;if(!Z)return null;return{kind:"comment",left:$.anchorLeft,link:$.kind==="link"?{title:$.title,url:$.url}:null,thread:Z,threadIndex:$.commentThreadIndex,top:$.anchorBottom}}if($.kind!=="link")return null;return{endOffset:$.endOffset,kind:"link",left:$.anchorLeft,regionId:$.regionId,startOffset:$.startOffset,title:$.title,top:$.anchorBottom,url:$.url}}var oG=600,nG=530,b2=24;function HJ({canShowInsertionLeaf:$,canShowTableLeaf:M,commentState:Z,editorState:J,editorViewportState:X,getScrollTop:Y,layoutWidth:Q,onVisibilityChange:K,resources:q,scrollContentHeight:D,scrollTo:V,viewportHeight:G}){let U=sG(()=>J0(J),[J]),[A,_]=FJ(null),[N,z]=FJ(null),E=U.start.regionId===U.end.regionId&&U.start.offset===U.end.offset,L=n3(!0),W=n3(0),R=n3(null),S=NJ(()=>{K()}),I=NJ(()=>{W.current=typeof performance<"u"?performance.now():Date.now(),L.current=!0,S()});return _J(()=>{let y=tG({canShowInsertionLeaf:$,canShowTableLeaf:M,commentState:Z,normalizedSelection:U,state:J,viewport:X.get()});_((b)=>ZA(b,y)?b:y)},[$,M,Z,J,X]),_J(()=>{let y=q?XA(J,X.get(),U,q):null;z((b)=>YA(b,y)?b:y)},[J,X,U,q]),AJ(()=>{let y=J.selection.focus,b={layoutWidth:Q,offset:y.offset,regionId:y.regionId,scrollContentHeight:D,viewportHeight:G};if(JA(R.current,b))return;let H=y6(J,X.get(),y);if(!H)return;let j=Y(),B=j+b2,P=j+G-b2;if(H.top<B){let F=V(Math.max(0,H.top-b2));if(zJ(H,F,G,b2))R.current=b;return}if(H.top+H.height>P){let F=V(Math.max(0,H.top+H.height-G+b2));if(zJ(H,F,G,b2))R.current=b;return}R.current=b},[J,J.selection.focus.offset,J.selection.focus.regionId,X,Q,D,V,G]),AJ(()=>{if(L.current=!0,S(),!E||typeof window>"u")return;let y=window.setInterval(()=>{if((typeof performance<"u"?performance.now():Date.now())-W.current<oG){if(!L.current)L.current=!0,S();return}L.current=!L.current,S()},nG);return()=>{window.clearInterval(y)}},[E]),{imageAtCursor:N,leaf:A,isVisible:()=>L.current,markActivity:I}}function tG({canShowInsertionLeaf:$,canShowTableLeaf:M,commentState:Z,normalizedSelection:J,state:X,viewport:Y}){if(!Y)return null;let Q=X.selection.focus;if(J.start.regionId!==J.end.regionId||J.start.offset!==J.end.offset)return null;let K=$?MA(X,Y):null;if(K)return K;let q=M?eG(X,Y):null;if(q)return q;return q8(W6(X,Y,Q,Z.liveRanges),Z.threads)}function eG($,M){let Z=$.selection.focus,J=$.documentIndex.regionIndex.get(Z.regionId),X=J?$.documentIndex.tableCellIndex.get(J.id)??null:null;if(!J||!X)return null;let Y=$.documentIndex.blockIndex.get(J.blockId),Q=Y?.type==="table"?$.documentIndex.document.blocks[Y.rootIndex]:null;if(!Y||!Q||Q.type!=="table")return null;let K=t0($,M,Z),q=$A(M,J.id),D=Math.max(1,...Q.rows.map((V)=>V.cells.length));return K&&q!==null?{cellIndex:X.cellIndex,columnCount:D,kind:"table",left:q,rowCount:Q.rows.length,rowIndex:X.rowIndex,top:K.top+K.height}:null}function $A($,M){let Z=$.layout.lines.find((J)=>J.regionId===M);return Z?Z.left:null}function MA($,M){let Z=$.selection.focus,J=$.documentIndex.regionIndex.get(Z.regionId);if(!J||J.blockType!=="paragraph"||J.text.length>0)return null;if(Z.offset!==0)return null;let X=$.documentIndex.blockIndex.get(J.blockId);if(!X||X.parentBlockId!==null)return null;let Y=t0($,M,Z);return Y?{kind:"insertion",left:Y.left,top:Y.top+Y.height}:null}function ZA($,M){if($===M)return!0;if(!$||!M||$.kind!==M.kind)return!1;switch($.kind){case"comment":return M.kind==="comment"&&$.left===M.left&&$.link?.title===M.link?.title&&$.link?.url===M.link?.url&&$.thread===M.thread&&$.threadIndex===M.threadIndex&&$.top===M.top;case"insertion":return M.kind==="insertion"&&$.left===M.left&&$.top===M.top;case"link":return M.kind==="link"&&$.endOffset===M.endOffset&&$.left===M.left&&$.regionId===M.regionId&&$.startOffset===M.startOffset&&$.title===M.title&&$.top===M.top&&$.url===M.url;case"table":return M.kind==="table"&&$.cellIndex===M.cellIndex&&$.columnCount===M.columnCount&&$.left===M.left&&$.rowCount===M.rowCount&&$.rowIndex===M.rowIndex&&$.top===M.top}}function JA($,M){return $?.layoutWidth===M.layoutWidth&&$.regionId===M.regionId&&$.offset===M.offset&&$.scrollContentHeight===M.scrollContentHeight&&$.viewportHeight===M.viewportHeight}function zJ($,M,Z,J){return $.top>=M+J&&$.top+$.height<=M+Z-J}function XA($,M,Z,J){if(!M)return null;if(Z.start.regionId!==Z.end.regionId||Z.start.offset!==Z.end.offset)return null;let X=L5($);if(!X)return null;let Y=V5($,M,J,X),Q=X.image?J.images.get(X.image.url)?.intrinsicWidth??null:null,K=$.selection.anchor.regionId;return Y?{bounds:Y,maxWidth:Q,regionId:K,run:X}:null}function YA($,M){if($===M)return!0;if(!$||!M)return!1;return $.regionId===M.regionId&&$.maxWidth===M.maxWidth&&$.bounds.left===M.bounds.left&&$.bounds.top===M.bounds.top&&$.bounds.width===M.bounds.width&&$.bounds.height===M.bounds.height}import{useMemo as t3,useRef as g4,useEffectEvent as e3}from"react";var QA=48;function EJ($,M,Z){let J=g4(null),X=g4(null),Y=g4(null),Q=g4(null),K=g4(1),q=e3((A,_)=>{if(!$)return;A.preventDefault(),A.stopPropagation(),A.currentTarget.setPointerCapture(A.pointerId),Q.current=A.pointerId,J.current=A.clientX,X.current=A.clientY,Y.current=$.run.image?.width??$.bounds.width,K.current=_}),D=e3((A)=>{if(Q.current!==A.pointerId||J.current===null||X.current===null||Y.current===null||!$?.run.image)return;let _=A.clientX-J.current,N=A.clientY-X.current,z=Math.min($.maxWidth??1/0,Math.max(QA,Math.round(Y.current+K.current*(_+N)))),E=PM(M,$.regionId,$.run,z);if(E)Z(E)}),V=e3((A)=>{if(A.currentTarget.hasPointerCapture(A.pointerId))A.currentTarget.releasePointerCapture(A.pointerId);Q.current=null,J.current=null,X.current=null,Y.current=null}),G=t3(()=>({onPointerDown:(A)=>q(A,-1),onPointerMove:D,onPointerUp:V,onPointerCancel:V}),[]),U=t3(()=>({onPointerDown:(A)=>q(A,1),onPointerMove:D,onPointerUp:V,onPointerCancel:V}),[]);return t3(()=>{if(!$)return null;let{bounds:A}=$;return{start:{left:A.left,top:A.top,props:G},end:{left:A.left+A.width,top:A.top+A.height,props:U}}},[$])}import{useEffect as WJ,useEffectEvent as yJ,useMemo as BJ,useRef as KA,useState as DA}from"react";function PJ($,M){let[Z,J]=DA(new Map),X=yJ((q)=>{if(typeof Image>"u")return;let D=[...Z.keys()].filter((V)=>!q.has(V));if(D.length>0)J((V)=>{let G=new Map(V);for(let U of D)G.delete(U);return G});for(let V of q){let G=Z.get(V)?.status;if(G==="loaded"||G==="loading")continue;J((U)=>$9(U,V,p4("loading"))),qA(V,M).then((U)=>{J((A)=>{if(!A.has(V))return U?.close(),A;return $9(A,V,U?p4("loaded",U):p4("error"))})})}});WJ(()=>{X($)},[$]);let Y=KA(new Map);WJ(()=>{for(let[q,D]of Y.current)if(!Z.has(q))D.source?.close();Y.current=Z},[Z]);let Q=yJ(async(q)=>{if(!M?.writeFile)return null;try{let D=await M.writeFile(q),V=await createImageBitmap(q).catch(()=>null);return J((G)=>$9(G,D,V?p4("loaded",V):p4("error"))),D}catch{return null}}),K=BJ(()=>Z.size===0?null:{images:Z},[Z]);return BJ(()=>({resources:K,persistImage:Q}),[K,Q])}async function qA($,M){if(/^(https?:|data:|blob:)/i.test($))return VA($);if(!M?.readFile)return null;try{let Z=await M.readFile($);return Z?await createImageBitmap(Z):null}catch{return null}}function VA($){return new Promise((M)=>{let Z=new Image;Z.decoding="async",Z.crossOrigin="anonymous",Z.onload=async()=>{try{M(await createImageBitmap(Z))}catch{M(null)}},Z.onerror=()=>M(null),Z.src=$})}function $9($,M,Z){let J=new Map($);return J.set(M,Z),J}function p4($,M){return{intrinsicHeight:M?.height??0,intrinsicWidth:M?.width??0,source:M??null,status:$}}import{useEffect as wJ,useEffectEvent as _0,useRef as l4,useState as UA}from"react";var GA=48;function bJ({applyNextState:$,autoScrollDuringDrag:M,canvasRef:Z,commentState:J,editorStateRef:X,editorViewportState:Y,focusInput:Q,onActivity:K,readCurrentState:q,resolvePoint:D}){let[V,G]=UA(null),U=l4(null),A=l4(!1),_=l4(null),N=l4(null),z=l4(null),E=q8(V,J.threads),L=V?.kind==="task-toggle"||E?.kind==="link"?"pointer":"text";wJ(()=>{if(V&&V.kind!=="task-toggle"&&!E)G(null)},[V,E]),wJ(()=>()=>{if(U.current!==null)window.clearTimeout(U.current)},[]);let W=_0(()=>{if(U.current!==null)window.clearTimeout(U.current),U.current=null}),R=_0(()=>{W(),U.current=window.setTimeout(()=>{if(U.current=null,!A.current)G(null)},GA)}),S=_0(()=>{if(!A.current)W(),G(null)}),I=_0((w)=>{if(!w){S();return}if(w.kind==="task-toggle"){W(),G((T)=>T?.kind==="task-toggle"&&T.listItemId===w.listItemId?T:w);return}if(w.commentThreadIndex!==null){if(!(J.threads[w.commentThreadIndex]??null)){S();return}W();let k=w.commentThreadIndex;G((m)=>m?.kind!=="task-toggle"&&m?.commentThreadIndex===k?m:w);return}if(w.kind!=="link"){S();return}W(),G((T)=>T?.kind==="link"&&T.title===w.title&&T.url===w.url&&T.startOffset===w.startOffset&&T.endOffset===w.endOffset?T:w)}),y=_0((w)=>{let T=X.current;if(!T)return null;let k=D(w);if(!k)return null;return E6(T,Y.get(),k,J.liveRanges)}),b=_0((w)=>{let T=Z.current;if(T&&_.current===w)T.releasePointerCapture(w)}),H=_0(()=>{_.current=null,N.current=null}),j=_0((w)=>{b(w.pointerId),H()}),B=_0((w)=>{if(z.current=w.pointerType,w.pointerType==="touch")return;let T=Z.current,k=q(),m=D(w);if(!m)return;if(y(w)?.kind==="task-toggle")return;let l=B5(k,Y.get(),m);if(!T||!l)return;if(_.current=w.pointerId,K(),T.setPointerCapture(w.pointerId),w.shiftKey)N.current=k.selection.anchor,$(QM(k,l.regionId,l.offset));else N.current={offset:l.offset,regionId:l.regionId},$(Q0(k,{offset:l.offset,regionId:l.regionId}));Q({offset:l.offset,regionId:l.regionId})}),P=_0((w)=>{let T=N.current,k=q(),m=D(w);if(!m)return;if(_.current!==w.pointerId||!T){I(y(w));return}let a=l2(k,Y.get(),m,T);if(!a)return;K(),M(w),$(Q0(k,{anchor:T,focus:a}))}),F=_0(()=>{if(!A.current)R()}),C=_0((w)=>{let T=z.current==="touch";z.current=null;let k=y(w);if(k?.kind==="task-toggle"){let F0=q(),c0=GM(F0,k.listItemId);if(c0)w.preventDefault(),w.stopPropagation(),K(),$(c0);return}if(k?.kind==="link"&&(w.metaKey||w.ctrlKey)){w.preventDefault(),w.stopPropagation(),w.currentTarget.ownerDocument.defaultView?.open(k.url,"_blank","noopener,noreferrer");return}if(!T){Q();return}let m=q(),a=D(w),l=a?B5(m,Y.get(),a):null;if(l)K(),$(Q0(m,{offset:l.offset,regionId:l.regionId})),Q({offset:l.offset,regionId:l.regionId});else Q()}),u=_0((w)=>{let T=q(),k=D(w),m=y(w);if(!k||m?.kind==="task-toggle")return;let a=H6(T,Y.get(),k);if(!a)return;w.preventDefault(),w.stopPropagation(),K(),$(Q0(T,a)),Q()}),h=_0(()=>{A.current=!0,W()}),g=_0(()=>{A.current=!1,R()});return{canvasHandlers:{onClick:C,onDoubleClick:u,onPointerCancel:j,onPointerDown:B,onPointerLeave:F,onPointerMove:P,onPointerUp:j},cursor:L,leaf:E,leafHandlers:{onPointerEnter:h,onPointerLeave:g}}}import{useEffect as Z9,useEffectEvent as U0,useLayoutEffect as AA,useRef as jJ,useState as NA}from"react";import{useEffect as RR1}from"react";var M9=[{key:"Backspace",command:"deleteBackward"},{key:"Enter",command:"insertLineBreak"},{key:"Home",command:"moveToLineStart"},{key:"End",command:"moveToLineEnd"},{key:"Tab",command:"indent"},{key:"Tab",shiftKey:!0,command:"dedent"},{key:"ArrowLeft",modKey:!0,shiftKey:"any",command:"moveToLineStart"},{key:"ArrowRight",modKey:!0,shiftKey:"any",command:"moveToLineEnd"},{key:"ArrowUp",modKey:!0,shiftKey:"any",command:"moveToDocumentStart"},{key:"ArrowDown",modKey:!0,shiftKey:"any",command:"moveToDocumentEnd"},{key:"ArrowUp",altKey:!0,shiftKey:!0,command:"moveListItemUp"},{key:"ArrowDown",altKey:!0,shiftKey:!0,command:"moveListItemDown"},{key:"a",modKey:!0,command:"selectAll"},{key:"b",modKey:!0,command:"toggleBold"},{key:"e",modKey:!0,command:"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 TJ($,M=M9){return M.find((Z)=>{let J=Z.shiftKey==="any"?!0:(Z.shiftKey??!1)===($.shiftKey??!1);return Z.key.toLowerCase()===$.key.toLowerCase()&&(Z.altKey??!1)===($.altKey??!1)&&J&&(Z.modKey??!1)===Boolean($.metaKey||$.ctrlKey)})?.command??null}var _A=1024,OJ=16;function RJ({applyNextState:$,editorState:M,editorStateRef:Z,editorViewportState:J,inputRef:X,keybindings:Y,onActivity:Q,onImagePaste:K}){let q=FA(),D=()=>Z.current??M,V=jJ(!1),G=jJ(!1),U=U0((F)=>{if(!F)return;Q(),$(F)}),A=U0(()=>{let F=X.current;if(!F)return;if(typeof document>"u")return;let C=document.execCommand;if(typeof C!=="function")return;try{V.current=!0,C.call(document,"insertText",!1,""),C.call(document,"delete")}catch{}finally{V.current=!1,x4(F,D())}}),_=U0(()=>{if(G.current)return;G.current=!0,A()}),N=U0(()=>{A()}),z=U0((F)=>{if(!q)return;let C=X.current;if(!C)return;let u=J.get(),h=t0(D(),u,F);if(!h)return;C.style.top=`${h.top}px`,C.style.left=`${h.left}px`,C.style.height=`${h.height}px`}),E=U0((F)=>{let C=X.current;if(!C)return;z(F??D().selection.focus),C.focus({preventScroll:!q}),x4(C,D()),_()}),L=U0((F,C)=>{let h=CJ(C,V8(F)).replace(/\r\n/g,`
|
|
31
|
+
`).split(/(\n)/),g=F;for(let w of h){if(w.length===0)continue;let T=w===`
|
|
32
|
+
`?p5(g):U4(g,w);if(!T)continue;g=T}return g===F?null:g}),W=U0((F,C,u)=>{let h=F.selection.focus,g={regionId:h.regionId,offset:Math.max(0,h.offset-C)},w=Q0(F,{anchor:g,focus:h});return l5(w,u)}),R=U0((F)=>{if(V.current)return;let C=D(),u=EA(F.inputType);if(F.inputType==="insertText"){if(!F.data)return;F.preventDefault();let h=LJ(F.target);if(h>0){U(W(C,h,F.data));return}let g=HA(C,F.data);if(g>0){let w=F.data.slice(g);if(w.length>0)U(L(C,w));return}U(L(C,F.data));return}if(F.inputType==="insertReplacementText"){if(!F.data)return;F.preventDefault();let h=LJ(F.target);U(W(C,h,F.data));return}if(zA(F.inputType)){F.preventDefault(),U(p5(C));return}if(u==="backward"){F.preventDefault(),U(K3(C));return}if(u==="forward"){F.preventDefault(),U(D3(C));return}if(F.inputType==="historyUndo"){F.preventDefault(),U(q3(C)),N();return}if(F.inputType==="historyRedo"){F.preventDefault(),U(V3(C)),N();return}}),S=U0((F)=>{let C=D(),u=F.currentTarget.value,h=V8(C);if(V.current)return;if(CJ(u,h).length===0){x4(F.currentTarget,C);return}U(L(C,u))}),I=U0((F)=>{let C=yA(D(),J.get(),F.nativeEvent,Y);if(!C)return;F.preventDefault(),U(C)}),y=U0((F)=>{let C=Q3(D());if(!C)return;F.preventDefault(),F.clipboardData.setData("text/plain",Q8(C))}),b=U0((F)=>{let C=D(),u=Q3(C);if(!u)return;F.preventDefault(),F.clipboardData.setData("text/plain",Q8(u)),U(x5(C))}),H=U0(async(F)=>{let u=(K?[...F.clipboardData.items].find((w)=>w.kind==="file"&&w.type.startsWith("image/")):void 0)?.getAsFile()??null;if(u&&K){F.preventDefault();let w=await K(u);if(w)U(BM(D(),w));return}let h=F.clipboardData.getData("text/plain");if(h.length===0)return;F.preventDefault();let g=v3(h);U(YM(D(),g,h))}),j=U0(()=>{Q();let F=X.current;if(F)x4(F,D())}),B=U0((F)=>{if(Q(),F.target.matches(":focus-visible"))E()});Z9(()=>{let F=X.current;if(!F)return;x4(F,M)},[M,X]),AA(()=>{z(M.selection.focus)},[M,z]),Z9(()=>{let F=X.current;if(!F)return;let C=(u)=>R(u);return F.addEventListener("beforeinput",C),()=>F.removeEventListener("beforeinput",C)},[X,R]);let P={onCopy:y,onCut:b,onPaste:H,...q?{}:{onKeyDown:I}};return{canvasHandlers:{...P,onFocus:B},focus:E,inputHandlers:{...P,onFocus:j,onInput:S}}}var SJ="";function FA(){let[$,M]=NA(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function")return!1;return window.matchMedia("(pointer: coarse)").matches});return Z9(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function")return;let Z=window.matchMedia("(pointer: coarse)"),J=(X)=>M(X.matches);return Z.addEventListener?.("change",J),()=>Z.removeEventListener?.("change",J)},[]),$}function zA($){return $==="insertLineBreak"||$==="insertParagraph"}function LJ($){let M=$,Z=M?.selectionStart??0,J=M?.selectionEnd??Z;return Math.max(0,J-Z)}function HA($,M){if(M.length<OJ)return 0;let Z=V8($,M.length),J=Math.min(Z.length,M.length);for(let X=J;X>=OJ;X--)if(Z.endsWith(M.slice(0,X)))return X;return 0}function EA($){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 WA($){return $.replaceAll(SJ,"")}function V8($,M=_A){let{anchor:Z,focus:J}=$.selection;if(Z.regionId!==J.regionId||Z.offset!==J.offset)return"";let X=$.documentIndex.regionIndex.get(J.regionId);if(!X)return"";return X.text.slice(Math.max(0,J.offset-M),J.offset)}function CJ($,M){let Z=WA($);return Z.startsWith(M)?Z.slice(M.length):Z}function x4($,M){let Z=V8(M),J=`${SJ}${Z}`;$.value=J,$.setSelectionRange(J.length,J.length)}function yA($,M,Z,J){if(Z.key==="Delete")return D3($);let X=TJ(Z,J);if(X){if(X==="moveToLineStart"||X==="moveToLineEnd")return N3($,M.layout,X==="moveToLineStart"?"Home":"End",Z.shiftKey);if(X==="moveToDocumentStart"||X==="moveToDocumentEnd")return _3($,X==="moveToDocumentStart"?"start":"end",Z.shiftKey);switch(X){case"insertLineBreak":return p5($);case"deleteBackward":return K3($);case"indent":return DM($);case"dedent":return qM($);case"moveListItemUp":return VM($);case"moveListItemDown":return UM($);case"toggleBold":return d5($);case"toggleItalic":return r5($);case"toggleStrikethrough":return c5($);case"toggleUnderline":return a5($);case"toggleCode":return EM($);case"undo":return q3($);case"redo":return V3($);case"selectAll":return KM($)}}if(Z.key==="ArrowLeft"||Z.key==="ArrowRight")return U3($,Z.key==="ArrowLeft"?-1:1,Z.shiftKey);if(Z.key==="ArrowUp"||Z.key==="ArrowDown")return G3($,M.layout,Z.key==="ArrowUp"?-1:1,Z.shiftKey);if(Z.key==="PageUp"||Z.key==="PageDown")return A3($,M.layout,Z.key==="PageUp"?-1:1,Z.shiftKey);if(Z.key.length===1&&!Z.altKey&&!Z.ctrlKey&&!Z.metaKey)return U4($,Z.key);return null}import{useEffectEvent as J9,useLayoutEffect as BA,useMemo as PA,useState as wA}from"react";function kJ({editorState:$,editorStateRef:M,editorViewportState:Z,onViewportScroll:J,scrollContainerRef:X,scheduleOverlayRender:Y,userPresence:Q}){let K=PA(()=>{if(!Q||Q.length===0)return;return w5($.documentIndex,Q)},[$.documentIndex,Q]),[q,D]=wA(void 0),V=J9(()=>{if(K===void 0){if(q!==void 0)D(void 0)}else D(x2(M.current??$,Z.get(),K));Y()}),G=J9((A)=>{if(K===void 0){if(q!==void 0)D(void 0);return}let _=x2(M.current??$,A,K);if(bA(q,_))return;D(_)});BA(()=>{V()},[K]);let U=J9((A)=>{if(!A.viewport||A.viewport.status==="unresolved")return;let _=X.current;if(!_)return;_.scrollTop=A.viewport.scrollTop,J(_)});return{presence:q,scrollToPresence:U,refreshPresence:G}}function bA($,M){if($===M)return!0;if($===void 0||M===void 0||$.length!==M.length)return!1;return $.every((Z,J)=>{let X=M[J];return Z.id===X.id&&TA(Z.viewport,X.viewport)})}function TA($,M){if($===M)return!0;if($===null||M===null)return!1;if($.status==="unresolved")return M.status==="unresolved";if(M.status==="unresolved")return!1;return $.status===M.status&&$.scrollTop===M.scrollTop}import{useEffect as jA,useEffectEvent as h1,useRef as d4}from"react";function mJ({editorStateRef:$,renderContent:M,renderOverlay:Z,renderViewport:J}){let X=d4(null),Y=d4(!1),Q=d4(!1),K=d4(!1),q=d4(!1),D=h1(()=>{if(typeof window>"u"){J();return}Y.current=!0,A()}),V=h1(()=>{if(typeof window>"u"){M(),Z();return}Q.current=!0,A()}),G=h1(()=>{if(typeof window>"u"){M();return}K.current=!0,A()}),U=h1(()=>{if(typeof window>"u"){Z();return}q.current=!0,A()}),A=h1(()=>{if(typeof window>"u"||X.current!==null)return;X.current=window.requestAnimationFrame(()=>{_()})}),_=h1(()=>{X.current=null;let z=Y.current,E=Q.current,L=K.current,W=q.current;if(Y.current=!1,Q.current=!1,K.current=!1,q.current=!1,z){J(),N();return}if(E){M(),Z(),N();return}if(L)M(),N();if(W)Z()}),N=h1(()=>{let z=$.current;if(!z||!I6(z,performance.now()))return;K.current=!0,A()});return jA(()=>{return()=>{if(typeof window>"u"||X.current===null)return;window.cancelAnimationFrame(X.current),X.current=null}},[]),{scheduleContentPaint:G,scheduleFullPaint:V,scheduleFullRender:D,scheduleOverlayPaint:U}}import{useEffectEvent as X9,useLayoutEffect as pJ,useMemo as Y9,useRef as Q9,useState as lJ}from"react";function hJ($){let M=$.documentIndex.regions.find((Y)=>Y.id===$.selection.anchor.regionId),Z=$.documentIndex.regions.find((Y)=>Y.id===$.selection.focus.regionId),J=(M?.start??0)+$.selection.anchor.offset,X=(Z?.start??0)+$.selection.focus.offset;return{end:Math.max(J,X),start:Math.min(J,X)}}function IJ($){let M=OA($);if(M.start.regionId!==M.end.regionId||M.start.offset===M.end.offset)return null;return{endOffset:M.end.offset,regionId:M.start.regionId,startOffset:M.start.offset}}var fJ=28,vJ=18;function gJ($,M){if(!$)return;let Z=$.getBoundingClientRect();if(M.clientY<Z.top+fJ){$.scrollTop=Math.max(0,$.scrollTop-vJ);return}if(M.clientY>Z.bottom-fJ)$.scrollTop+=vJ}function OA($){let M=uJ($.documentIndex.regions,$.selection.anchor.regionId,$.selection.anchor.offset),Z=uJ($.documentIndex.regions,$.selection.focus.regionId,$.selection.focus.offset);return M<=Z?{end:$.selection.focus,start:$.selection.anchor}:{end:$.selection.anchor,start:$.selection.focus}}function uJ($,M,Z){let J=$.findIndex((X)=>X.id===M);if(J===-1)return-1;return J*1e6+Z}function xJ({applyNextState:$,autoScrollDuringDrag:M,canShowSelectionLeaf:Z,editorState:J,editorStateRef:X,editorViewportState:Y,focusInput:Q,onActivity:K,resolvePoint:q,threads:D}){let V=Y9(()=>J0(J),[J]),G=Y9(()=>IJ(J),[J]),U=Y9(()=>C5(J),[J]),[A,_]=lJ(null),[N,z]=lJ(null),E=Q9(null),L=Q9(null),W=Q9(null);pJ(()=>{let H=LA(J,Y.get(),V);_((j)=>mA(j,H)?j:H)},[J,Y,V.end.offset,V.end.regionId,V.start.offset,V.start.regionId]),pJ(()=>{let H=RA({canShowSelectionLeaf:Z,currentLeaf:N,activeMarks:U,handles:A,selectionRange:G,threads:D});z((j)=>kA(j,H)?j:H)},[U,Z,A,N,G,D]);let R=X9((H,j=!0)=>{z((B)=>B?.kind==="create"?{animateInitialComment:j,kind:"thread",left:B.left,threadIndex:H,top:B.top}:B)}),S=X9((H)=>{if(H&&W.current===H.pointerId&&H.currentTarget.hasPointerCapture(H.pointerId))H.currentTarget.releasePointerCapture(H.pointerId);E.current=null,L.current=null,W.current=null}),I=X9((H)=>{let j=X.current,B=L.current,P=q(H);if(!P||!j||!B||W.current!==H.pointerId)return;let F=l2(j,Y.get(),P,B);if(!F)return;H.preventDefault(),H.stopPropagation(),K(),M(H),$(Q0(j,{anchor:B,focus:F}))}),y=(H)=>({onPointerCancel:(j)=>{S(j)},onPointerDown:(j)=>{let B=X.current??J,P=vA(V,H),F=H==="start"?V.start:V.end;if(!A)return;j.preventDefault(),j.stopPropagation(),W.current=j.pointerId,L.current=P,E.current=H,j.currentTarget.setPointerCapture(j.pointerId),K(),Q(),$(Q0(B,{anchor:P,focus:F}))},onPointerMove:(j)=>{if(E.current!==H)return;I(j)},onPointerUp:(j)=>{if(E.current===H)I(j);S(j)}});return{handle:A?{start:{...A.start,props:y("start")},end:{...A.end,props:y("end")}}:null,leaf:N,promoteLeafToThread:R}}function LA($,M,Z){if(Z.collapsed)return null;let J=t0($,M,Z.start),X=t0($,M,Z.end);if(!J||!X)return null;return{end:{left:X.left,top:X.top+X.height},start:{left:J.left,top:J.top}}}function CA($,M,Z){return{activeMarks:Z,kind:"create",left:M.start.left,selection:$,top:M.end.top}}function RA({activeMarks:$,canShowSelectionLeaf:M,currentLeaf:Z,handles:J,selectionRange:X,threads:Y}){if(!M||!X||!J)return null;if(Z?.kind==="thread")return Y[Z.threadIndex]?Z:null;return CA(X,J,$)}function SA($,M){return $?.kind==="create"&&$.left===M.left&&$.selection.regionId===M.selection.regionId&&$.selection.startOffset===M.selection.startOffset&&$.selection.endOffset===M.selection.endOffset&&fA($.activeMarks,M.activeMarks)&&$.top===M.top}function kA($,M){if($===M)return!0;if(!$||!M||$.kind!==M.kind)return!1;if($.kind==="create"&&M.kind==="create")return SA($,M);return $.kind==="thread"&&M.kind==="thread"&&$.animateInitialComment===M.animateInitialComment&&$.left===M.left&&$.threadIndex===M.threadIndex&&$.top===M.top}function mA($,M){if($===M)return!0;if(!$||!M)return!1;return $.start.left===M.start.left&&$.start.top===M.start.top&&$.end.left===M.end.left&&$.end.top===M.end.top}function fA($,M){return $.length===M.length&&$.every((Z,J)=>Z===M[J])}function vA($,M){return M==="start"?$.end:$.start}import{useEffect as uA,useMemo as cJ,useState as hA}from"react";var r4={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)"},c4={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)"},dJ={...r4,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)"},rJ={...c4,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 aJ($){let M=cJ(()=>gA($),[$]),[Z,J]=hA(M.light),X=cJ(()=>pA(Z),[Z]);return uA(()=>{if(typeof window>"u"||typeof window.matchMedia!=="function"){J(M.light);return}let Y=window.matchMedia("(prefers-color-scheme: dark)"),Q=()=>{J(Y.matches?M.dark:M.light)};if(Q(),typeof Y.addEventListener==="function")return Y.addEventListener("change",Q),()=>{Y.removeEventListener("change",Q)};return Y.addListener(Q),()=>{Y.removeListener(Q)}},[M]),{theme:Z,themeStyles:X}}function IA($){return"light"in $&&"dark"in $}function gA($){if(!$)return{dark:c4,light:r4};if(IA($))return $;return{dark:$,light:$}}function pA($){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 dA,useEffectEvent as r0,useRef as K9,useState as U8}from"react";import{useMemo as lA}from"react";function iJ($){return lA(()=>xA({current:null},$),[$])}function xA($,M){return{peek(){return $.current},get(){let Z=$.current;if(Z!==null)return Z;let J=M();return $.current=J,J},invalidate(){$.current=null}}}function sJ($,M){let Z=M.getBoundingClientRect();return{x:$.clientX-Z.left+M.scrollLeft,y:$.clientY-Z.top+M.scrollTop}}function oJ({editorState:$,editorStateRef:M,renderResources:Z,theme:J}){let X=K9(b1()),Y=K9(null),Q=K9({height:240,top:0}),[K,q]=U8(0),[D,V]=U8(240),[G,U]=U8(0),[A,_]=U8(240),N=rA(K),z=r0(()=>{let P=M.current??$,F=Q.current;return z6(P,{height:F.height,paddingX:J.paddingX,paddingY:J.paddingY,top:F.top,width:N},X.current,Z)}),E=iJ(z),L=r0((P)=>{_((F)=>{let C=aA(P,Q.current.height);return F===C?F:C})}),W=r0((P)=>{Q.current={...Q.current,top:P},U((F)=>F===P?F:P),E.invalidate()}),R=r0((P)=>{let F=cA(P),C=F.top!==Q.current.top;if(Q.current=F,U((u)=>u===F.top?u:F.top),C)E.invalidate()}),S=r0((P)=>{let F=Y.current;if(!F)return W(P),P;F.scrollTop=P;let C=F.scrollTop;return W(C),C}),I=r0(()=>{return Y.current?.scrollTop??Q.current.top}),y=r0((P,F)=>{let C=P!==null&&P.documentIndex!==F.documentIndex,u=E.peek();if(!(!C||!u||u.layout.regionLineIndices.has(F.selection.focus.regionId)))E.invalidate()}),b=r0(()=>{return E.invalidate(),E.get()}),H=r0((P)=>{let F=Y.current;return F?sJ(P,F):null}),j=r0((P)=>{gJ(Y.current,P)});return dA(()=>{let P=Y.current;if(!P||typeof ResizeObserver>"u")return;let F=new ResizeObserver((C)=>{let u=C[0];if(!u)return;let h=Math.max(0,Math.floor(u.contentRect.width)),g=nJ(P);Q.current={...Q.current,height:g},q((w)=>w===h?w:h),V((w)=>w===g?w:g)});return F.observe(P),()=>F.disconnect()},[Y]),{actions:{autoScrollDuringDrag:j,getScrollTop:I,observePreparedViewport:L,observeScrollContainer:R,prepareNextPaint:b,reconcileEditorState:y,resolvePoint:H,scrollTo:S},props:{getScrollContainer:(P)=>({onScroll:(F)=>{R(F.currentTarget),P?.onScroll?.(F)},ref:Y}),scrollContent:{style:{height:`${A}px`}}},refs:{scrollContainer:Y},state:{layoutWidth:N,preparedViewport:E,scrollContentHeight:A,surfaceWidth:K,viewportHeight:D,viewportTop:G}}}function rA($){return Math.max(240,Math.floor($||480))}function nJ($){return Math.max(240,$.clientHeight)}function cA($){return{height:nJ($),top:$.scrollTop}}function aA($,M){return Math.max(M,Math.ceil($.totalHeight+24))}function iA(){if(typeof window>"u")return 1;return Math.max(1,window.devicePixelRatio||1)}function D9($,{paintHeight:M,paintTop:Z,width:J}){if(!$)return null;let X=Math.max(240,Math.ceil(M)),Y=iA();$.width=Math.ceil(J*Y),$.height=Math.ceil(X*Y),$.style.width=`${J}px`,$.style.height=`${X}px`,$.style.transform=`translateY(${Z}px)`;let Q=$.getContext("2d");if(!Q)return null;return{context:Q,devicePixelRatio:Y,height:X,width:J}}function q9($,M){return $.activeBlockType===M.activeBlockType&&$.activeCommentThreadIndex===M.activeCommentThreadIndex&&$.activeSpanKind===M.activeSpanKind&&$.canonicalContent===M.canonicalContent&&$.characterCount===M.characterCount&&$.commentThreadCount===M.commentThreadCount&&$.layoutWidth===M.layoutWidth&&$.resolvedCommentCount===M.resolvedCommentCount&&$.selectionFrom===M.selectionFrom&&$.selectionTo===M.selectionTo}function tJ($,M){if(!M?.length||!$?.length)return;let Z=new Map($.map((X)=>[X.id,X])),J=[];for(let X of M){let Y=Z.get(X.userId);if(!Y)continue;J.push({...Y,color:X.color,cursor:X.cursor})}return J.length===0?void 0:J}function $X($,M){if(!$)return{didReconcile:!1,state:M};let Z=sA($,M)??XN($,M);return Z?{didReconcile:!0,state:Z}:{didReconcile:!1,state:M}}function sA($,M){let Z=oA($,M);return Z?Q0(M,Z,!1):null}function oA($,M){if(G9($.selection.anchor,$.selection.focus)){let Y=V9($,M,$.selection.focus,"neutral");return Y?{anchor:Y,focus:Y}:null}let Z=ZN($),J=V9($,M,$.selection.anchor,Z.anchor),X=V9($,M,$.selection.focus,Z.focus);return J&&X?{anchor:J,focus:X}:null}function V9($,M,Z,J){let X=$.documentIndex.regionIndex.get(Z.regionId);if(!X)return null;let Y=U9(X,M);if(!Y)return null;return{offset:tA(X.text,Y.text,Z.offset,J),regionId:Y.id}}function U9($,M){let Z=M.documentIndex.regionIndex.get($.id);if(Z)return Z;if($.text.length===0)return null;let J=nA($,M);if(J)return J;return M.documentIndex.regionPathIndex.get($.path)??null}function nA($,M){let Z=null;for(let J of M.documentIndex.regions){if(J.blockType!==$.blockType||J.text!==$.text)continue;if(Z)return null;Z=J}return Z}function tA($,M,Z,J){let X=O0(Z,0,$.length),{prefix:Y,suffix:Q}=f8($,X,X),K=eA(M,Y,Q);if(K!==null)return K;let q=$N(M,Y),D=MN(M,Q);if(J==="before-suffix")return D??q??O0(Z,0,M.length);return q??D??O0(Z,0,M.length)}function eA($,M,Z){let J=o1($,M,Z).filter((X)=>X.startOffset===X.endOffset);return J.length===1?J[0].startOffset:null}function $N($,M){let Z=h0($,M);return Z.length===1?Z[0]+M.length:null}function MN($,M){let Z=h0($,M);return Z.length===1?Z[0]:null}function ZN($){let{anchor:M,focus:Z}=$.selection;if(G9(M,Z))return{anchor:"neutral",focus:"neutral"};return JN($,M,Z)<=0?{anchor:"before-suffix",focus:"after-prefix"}:{anchor:"after-prefix",focus:"before-suffix"}}function JN($,M,Z){let J=$.documentIndex.regionOrderIndex.get(M.regionId),X=$.documentIndex.regionOrderIndex.get(Z.regionId);if(J===void 0||X===void 0)return 0;return J===X?M.offset-Z.offset:J-X}function XN($,M){if(!G9($.selection.anchor,$.selection.focus))return null;let Z=YN($);if(!Z)return null;let J=QN($,M,Z);if(J===null)return null;return KN(M,J)}function YN($){let M=$.documentIndex.regionIndex.get($.selection.focus.regionId);if(!M||M.blockType!=="paragraph"||M.text.length>0)return null;return $.documentIndex.blockIndex.get(M.blockId)?.parentBlockId===null?M:null}function QN($,M,Z){let J=eJ($,Z.rootIndex,"before"),X=eJ($,Z.rootIndex,"after"),Y=J?U9(J,M):null,Q=X?U9(X,M):null;if(Y&&Q)return Y.rootIndex<Q.rootIndex?Q.rootIndex:null;if(Y)return Y.rootIndex+1;if(Q)return Q.rootIndex;return null}function KN($,M){let Z=P1($.documentIndex.document,M,0,[x({text:""})]),J={...$,documentIndex:K2($.documentIndex,Z,M,0)},X=o2(J.documentIndex,$0(M));return X?Q0(J,X,!1):null}function eJ($,M,Z){let J=Z==="before"?-1:1;for(let X=M+J;X>=0&&X<$.documentIndex.roots.length;X+=J){let Y=DN($,X,Z);if(Y)return Y}return null}function DN($,M,Z){let J=$.documentIndex.roots[M]?.regions??[],X=Z==="before"?J.length-1:0,Y=Z==="before"?-1:1;for(let Q=X;Q>=0&&Q<J.length;Q+=Y){let K=J[Q];if(K&&K.text.length>0)return K}return null}function G9($,M){return $.regionId===M.regionId&&$.offset===M.offset}import{jsx as c,jsxs as A8,Fragment as FN}from"react/jsx-runtime";function N8({blocks:$}){return c(FN,{children:$.map((M)=>qN(M))})}function qN($){switch($.type){case"blockquote":return c("blockquote",{className:"preview-block preview-block-blockquote",children:c(N8,{blocks:$.children})},$.id);case"code":return A8("div",{className:"preview-block preview-block-code",children:[c("div",{className:"preview-rich-header",children:GN($.language,$.meta)}),c("pre",{children:c("code",{children:$.source||" "})})]},$.id);case"heading":{let M=`h${$.depth}`;return c(M,{className:"preview-block preview-block-heading",children:G8($.children)},$.id)}case"list":return $.ordered?c("ol",{className:"preview-block preview-block-list",start:$.start??1,children:$.items.map((M)=>A9(M))},$.id):c("ul",{className:"preview-block preview-block-list",children:$.items.map((M)=>A9(M))},$.id);case"listItem":return A9($);case"paragraph":return c("p",{className:"preview-block preview-block-paragraph",children:G8($.children)},$.id);case"table":return A8("div",{className:"preview-block preview-block-table",children:[c("div",{className:"preview-rich-header",children:AN($.rows.length,$.rows[0]?.cells.length??0,$.align.filter((M)=>M!==null).length)}),c("div",{className:"preview-table-scroll",children:c("table",{children:c("tbody",{children:$.rows.map((M)=>c("tr",{children:M.cells.map((Z)=>c("td",{children:G8(Z.children)},Z.id))},M.id))})})})]},$.id);case"thematicBreak":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"unsupported":return c("pre",{className:"preview-block preview-block-unsupported",children:$.source},$.id)}}function A9($){return c("li",{className:"preview-block preview-block-list-item",children:c(N8,{blocks:$.children})},$.id)}function G8($){return $.map((M)=>{switch(M.type){case"break":return c("br",{},M.id);case"image":return A8("span",{className:"preview-inline preview-inline-image",children:[c("img",{alt:M.alt??"",src:M.url,title:M.title??""}),A8("span",{children:[c("strong",{children:NN(M.alt)}),c("small",{children:_N(M.url,M.title)})]})]},M.id);case"inlineCode":return c("code",{className:"preview-inline preview-inline-code",children:M.code},M.id);case"link":return VN(M);case"text":return c("span",{className:"preview-inline",children:UN(M.text,M.marks)},M.id);case"unsupported":return c("span",{className:"preview-inline preview-inline-unsupported",children:M.source},M.id)}})}function VN($){return c("a",{className:"preview-inline preview-inline-link",href:$.url,children:G8($.children)},$.id)}function UN($,M){let Z=$;for(let J of M)switch(J){case"strikethrough":Z=c("del",{children:Z});break;case"italic":Z=c("em",{children:Z});break;case"bold":Z=c("strong",{children:Z});break;case"underline":Z=c("ins",{children:Z});break}return Z}function GN($,M){return[$??"plain text",M].filter(Boolean).join(" • ")}function AN($,M,Z){let J=Z>0?`${Z} aligned ${Z===1?"column":"columns"}`:"no alignment";return`${$} ${$===1?"row":"rows"} • ${M} ${M===1?"column":"columns"} • ${J}`}function NN($){return $?.trim()?$:"Untitled image"}function _N($,M){return M?.trim()?`${M} • ${$}`:$}var MX=`/* Base Documint host and SSR-fallback styles. */
|
|
33
33
|
|
|
34
34
|
.documint {
|
|
35
35
|
display: grid;
|
|
@@ -365,7 +365,7 @@ ${M.text}`:M.text}function RQ($){return $.filter((M)=>M.regions.length>0).map((M
|
|
|
365
365
|
white-space: nowrap;
|
|
366
366
|
}
|
|
367
367
|
}
|
|
368
|
-
`;var
|
|
368
|
+
`;var ZX=`/* Leaf overlay styles, ordered outer → inner:
|
|
369
369
|
1. Anchor — viewport positioning + hover bridge
|
|
370
370
|
2. Shell — bordered container (with state and content variants)
|
|
371
371
|
3. Menu — shared dropdown surface (toolbar menus, completion popover)
|
|
@@ -875,7 +875,7 @@ ${M.text}`:M.text}function RQ($){return $.filter((M)=>M.regions.length>0).map((M
|
|
|
875
875
|
font-weight: 500;
|
|
876
876
|
white-space: nowrap;
|
|
877
877
|
}
|
|
878
|
-
`;var
|
|
878
|
+
`;var JX=`/* Toolbar-specific styles (button, group, divider, and the menu trigger
|
|
879
879
|
shell + chevron). The menu container/item/divider styles themselves
|
|
880
880
|
live one level up in \`overlays/leaves/styles.css\` as \`.documint-leaf-menu*\`
|
|
881
881
|
so they can be shared by the toolbar's nested menu and other surfaces
|
|
@@ -957,6 +957,6 @@ ${M.text}`:M.text}function RQ($){return $.filter((M)=>M.regions.length>0).map((M
|
|
|
957
957
|
transform: rotate(180deg);
|
|
958
958
|
}
|
|
959
959
|
}
|
|
960
|
-
`;var
|
|
961
|
-
${
|
|
962
|
-
${
|
|
960
|
+
`;var XX=`${MX}
|
|
961
|
+
${ZX}
|
|
962
|
+
${JX}`;import{jsx as K0,jsxs as F8,Fragment as BN}from"react/jsx-runtime";var yN=2,YX={activeBlockType:null,activeCommentThreadIndex:null,activeSpanKind:null,canonicalContent:"",characterCount:0,commentThreadCount:0,layoutWidth:0,resolvedCommentCount:0,selectionFrom:0,selectionTo:0};function KX({className:$,content:M,keybindings:Z,onCommentChanged:J,onContentChanged:X,onStateChanged:Y,presence:Q,storage:K,theme:q,users:D}){let V=I1(null),G=I1(null),U=I1(null),A=I1(null),_=I1(M),N=I1(""),z=I1(YX),[E,L]=N9(!1),{theme:W,themeStyles:R}=aJ(q),[S,I]=N9(YX),y=M1(()=>u4(M),[M]),b=M1(()=>X8(y),[y]),[H,j]=N9(()=>Y4(y)),B=PJ(H.documentIndex.imageUrls,K),P=B.resources,F=M1(()=>[...P?.images.values()??[]].some((O)=>O.status==="loading"),[P]);A.current=H,N.current||=b;let C=oJ({editorState:H,editorStateRef:A,renderResources:P,theme:W}),{actions:u,props:h,refs:g,state:w}=C,{autoScrollDuringDrag:T,getScrollTop:k,observePreparedViewport:m,observeScrollContainer:a,prepareNextPaint:l,reconcileEditorState:F0,resolvePoint:c0,scrollTo:k0}=u,{layoutWidth:m0,preparedViewport:a0,scrollContentHeight:z8,surfaceWidth:H8,viewportHeight:a4,viewportTop:E8}=w,{scrollContainer:O2}=g,i4=M1(()=>n2(H),[H]),f0=M1(()=>C0(H),[H]),P0=M1(()=>J0(H),[H]),g1=M1(()=>{if(!D?.length)return;return[{trigger:"@",items:D.map((O)=>({label:O.fullName??O.username,id:O.id}))}]},[D]),W8=M1(()=>tJ(D,Q),[D,Q]),y8=M1(()=>QX(H,f0.liveRanges),[f0.liveRanges,H]),p1=Boolean(X),i=()=>A.current??H,s4=j2((O,f)=>{let p=n2(O),s=C0(O),t=hJ(O),Z0={activeBlockType:p.block?.nodeType??null,activeCommentThreadIndex:QX(O,s.liveRanges),activeSpanKind:p.span.kind==="none"?null:p.span.kind,canonicalContent:f,characterCount:f.length,commentThreadCount:s.threads.length,layoutWidth:m0,resolvedCommentCount:r8(s.threads),selectionFrom:t.start,selectionTo:t.end};if(I((e4)=>q9(e4,Z0)?e4:Z0),!q9(z.current,Z0))z.current=Z0,Y?.(Z0)}),M0=j2((O)=>{if(!O)return;let f=A.current??H,p=f.documentIndex!==O.documentIndex,s=m5(f,O);if(A.current=O,j(O),F0(f,O),s)P8();if(!p)return;let t=l0(O),Z0=X8(t);N.current=Z0,_.current=Z0,X?.(Z0,t)}),B8=(O)=>{J?.(O)},_9=(O)=>{let f=l0(i()).comments[O],p=f?.comments.at(-1);if(!f||!p)return;B8({kind:"added",comment:p,mentionedUserIds:g3(p.body,g1),thread:f,threadIndex:O})},DX=(O,f,p)=>{let s=l0(i()).comments[O],t=s?.comments[f];if(!s||!t)return;B8({kind:"edited",comment:t,previousBody:p,mentionedUserIds:g3(t.body,g1),thread:s,threadIndex:O})},F9=(O,f,p)=>{B8({kind:"deleted",comment:p,thread:f,threadIndex:O})},z9=j2((O=a0.peek())=>{if(!O)return;let f=D9(V.current,{paintHeight:O.paintHeight,paintTop:O.paintTop,width:m0});if(!f)return;let{context:p,devicePixelRatio:s,height:t,width:Z0}=f;W3(H,O,p,{activeBlockId:i4.block?.blockId??null,activeRegionId:H.selection.focus.regionId,activeThreadIndex:y9??y8,devicePixelRatio:s,height:t,liveCommentRanges:f0.liveRanges,normalizedSelection:P0,now:performance.now(),resources:P,theme:W,width:Z0})}),H9=j2((O=a0.peek())=>{if(!O)return;let f=D9(G.current,{paintHeight:O.paintHeight,paintTop:O.paintTop,width:m0});if(!f)return;let{context:p,devicePixelRatio:s,height:t,width:Z0}=f;y3(H,O,p,{devicePixelRatio:s,height:t,normalizedSelection:P0,presence:n4.presence,showCaret:P0.start.regionId!==P0.end.regionId||P0.start.offset!==P0.end.offset||x1.isVisible(),theme:W,width:Z0})}),qX=j2(()=>{let O=l();m(O),n4.refreshPresence(O),z9(O),H9(O)}),{scheduleContentPaint:P8,scheduleFullPaint:E9,scheduleFullRender:l1,scheduleOverlayPaint:W9}=mJ({editorStateRef:A,renderContent:z9,renderOverlay:H9,renderViewport:qX}),VX=h.getScrollContainer({onScroll:()=>l1()}),x1=HJ({canShowInsertionLeaf:Boolean(X),canShowTableLeaf:Boolean(X),commentState:f0,editorState:H,editorViewportState:a0,getScrollTop:k,layoutWidth:m0,onVisibilityChange:W9,resources:P,scrollContentHeight:z8,scrollTo:k0,viewportHeight:a4}),UX=EJ(x1.imageAtCursor,H,M0),o4=RJ({applyNextState:M0,editorState:H,editorStateRef:A,editorViewportState:a0,inputRef:U,keybindings:Z,onActivity:x1.markActivity,onImagePaste:B.persistImage}),F1=bJ({applyNextState:M0,autoScrollDuringDrag:T,canvasRef:V,commentState:f0,editorStateRef:A,editorViewportState:a0,focusInput:o4.focus,onActivity:x1.markActivity,readCurrentState:i,resolvePoint:c0}),y9=F1.leaf?.kind==="comment"?F1.leaf.threadIndex:null,GX=j2((O)=>{a(O),l1()}),n4=kJ({editorState:H,editorStateRef:A,editorViewportState:a0,onViewportScroll:GX,scrollContainerRef:O2,scheduleOverlayRender:W9,userPresence:W8}),t4=xJ({applyNextState:M0,autoScrollDuringDrag:T,canShowSelectionLeaf:p1,editorState:H,editorStateRef:A,editorViewportState:a0,focusInput:o4.focus,onActivity:x1.markActivity,resolvePoint:c0,threads:f0.threads}),z1=t4.handle??UX;T2(()=>{l1()},[H.documentIndex,m0,W,P,l1,a4]),T2(()=>{E9()},[P0.end.offset,P0.end.regionId,P0.start.offset,P0.start.regionId,E9,i4.block?.blockId]),T2(()=>{P8()},[y8,f0.liveRanges,y9,P8]),T2(()=>{if(!F)return;let O=null,f=window,p=()=>{l1(),O=f.requestAnimationFrame(p)};return O=f.requestAnimationFrame(p),()=>{if(O!==null)f.cancelAnimationFrame(O)}},[F,l1]);let AX=()=>{let O=F1.leaf,f=O??t4.leaf??x1.leaf,p=!O&&Boolean(t4.leaf),s=O2.current?.getBoundingClientRect()??null,t=f?.kind==="thread"?{...f,thread:f0.threads[f.threadIndex]??null}:null,Z0=f?.kind==="comment"?{animateInitialComment:!1,link:f.link,thread:f.thread,threadIndex:f.threadIndex}:t?.thread?{animateInitialComment:t.animateInitialComment??!1,link:null,thread:t.thread,threadIndex:t.threadIndex}:null,e4=Z0?.thread&&X1(Z0.thread)?"resolved":"default";return{annotationThreadLeaf:Z0,visibleLeaf:f,visibleLeafAnchor:f?{isSelection:p,left:(s?.left??0)+f.left,onPointerEnter:O?F1.leafHandlers.onPointerEnter:void 0,onPointerLeave:O?F1.leafHandlers.onPointerLeave:void 0,top:(s?.top??0)+f.top-E8+(p?yN:0)}:void 0,visibleLeafStatus:e4}},{annotationThreadLeaf:v0,visibleLeaf:G0,visibleLeafAnchor:B9,visibleLeafStatus:NX}=AX(),_X=(()=>{if(!G0)return null;switch(G0.kind){case"insertion":return K0(QJ,{onInsert:(O)=>{M0(U4(i(),O))},onInsertTable:(O)=>{M0(AM(i(),O))}});case"table":return K0(GJ,{canDeleteColumn:G0.columnCount>1,canDeleteRow:G0.rowCount>1,onDeleteColumn:()=>{M0(_M(i()))},onDeleteRow:()=>{M0(zM(i()))},onDeleteTable:()=>{M0(HM(i()))},onInsertColumn:(O)=>{M0(NM(i(),O))},onInsertRow:(O)=>{M0(FM(i(),O))}});case"link":return K0(VJ,{canEdit:p1,onDelete:()=>{let O=yM(i(),G0.regionId,G0.startOffset,G0.endOffset);if(O)M0(O)},onSave:(O)=>{let f=WM(i(),G0.regionId,G0.startOffset,G0.endOffset,O);if(f)M0(f)},title:G0.title,url:G0.url});case"create":return K0(r3,{activeMarks:G0.activeMarks,canEdit:p1,link:null,mode:"create",mentionSources:g1,onCreateThread:(O)=>{let f=i(),p=l0(f).comments.length,s=wM(f,G0.selection,O.trim());if(!s)return;M0(s),t4.promoteLeafToThread(p,!0),_9(p)},onToggleBold:()=>{M0(d5(i()))},onToggleItalic:()=>{M0(r5(i()))},onToggleStrikethrough:()=>{M0(c5(i()))},onToggleUnderline:()=>{M0(a5(i()))}});default:return v0?K0(r3,{animateInitialComment:v0.animateInitialComment,canEdit:p1,link:v0.link,mode:"thread",mentionSources:g1,onDeleteComment:(O)=>{let{threadIndex:f}=v0,p=i(),s=l0(p).comments[f],t=s?.comments[O],Z0=jM(p,f,O);if(!Z0)return;if(M0(Z0),s&&t)F9(f,s,t)},onDeleteThread:()=>{let{threadIndex:O}=v0,f=i(),p=l0(f).comments[O],s=OM(f,O);if(!s)return;if(M0(s),p)for(let t of p.comments)F9(O,p,t)},onEditComment:(O,f)=>{let{threadIndex:p}=v0,s=i(),t=l0(s).comments[p]?.comments[O]?.body,Z0=TM(s,p,O,f);if(!Z0)return;if(M0(Z0),t!==void 0)DX(p,O,t)},onReply:(O)=>{let{threadIndex:f}=v0,p=bM(i(),f,O);if(!p)return;M0(p),_9(f)},onToggleResolved:()=>{M0(LM(i(),v0.threadIndex,!X1(v0.thread)))},thread:v0.thread}):null}})();T2(()=>{L(!0)},[]),T2(()=>{s4(H,N.current||b)},[b,H,s4,H8]),WN(()=>{if(M===_.current)return;let O=A.current,f=$X(O,Y4(y)),p=f.state,s=f.didReconcile?k():0;A.current=p,j(p),_.current=M,N.current=b,k0(s)},[b,M,y,k,k0]);let FX=$?`documint ${$}`:"documint";return K0(xZ,{themeStyles:R,children:F8("section",{className:FX,"data-active-block":S.activeBlockType??"","data-active-comment-thread":S.activeCommentThreadIndex??"","data-active-span":S.activeSpanKind??"",style:{...R,height:"100%",minHeight:0},children:[K0("style",{children:XX}),F8("div",{...VX,className:"documint-scroll-container",style:{height:"100%",minHeight:0},children:[K0("textarea",{...o4.inputHandlers,ref:U,autoCapitalize:"sentences",className:"documint-input",spellCheck:!1,tabIndex:-1}),K0(VZ,{insetX:W.paddingX,insetY:W.paddingY,onSelect:n4.scrollToPresence,presence:n4.presence}),F8("div",{...h.scrollContent,className:"documint-scroll-content",children:[K0("canvas",{...o4.canvasHandlers,...F1.canvasHandlers,"aria-label":"Documint editor",className:"documint-content-canvas",style:{cursor:F1.cursor},ref:V,tabIndex:0}),K0("canvas",{"aria-hidden":"true",className:"documint-overlay-canvas",ref:G}),z1&&F8(BN,{children:[K0("div",{"aria-hidden":"true",className:"documint-resize-handle",style:{left:`${z1.start.left}px`,top:`${z1.start.top}px`},...z1.start.props,children:K0("span",{className:"documint-resize-handle-knob"})}),K0("div",{"aria-hidden":"true",className:"documint-resize-handle",style:{left:`${z1.end.left}px`,top:`${z1.end.top}px`},...z1.end.props,children:K0("span",{className:"documint-resize-handle-knob"})})]}),G0&&B9?K0(KJ,{anchor:B9,status:NX,children:_X}):null]}),!E?K0("div",{className:"documint-fallback",children:K0(N8,{blocks:y.blocks})}):null]})]})})}function QX($,M){let Z=new Map($.documentIndex.regions.map((q,D)=>[q.id,D])),J=_8(Z,$.selection.anchor.regionId,$.selection.anchor.offset),X=_8(Z,$.selection.focus.regionId,$.selection.focus.offset),[Y,Q]=J<=X?[J,X]:[X,J],K=J===X;for(let q of M){let D=_8(Z,q.regionId,q.startOffset),V=_8(Z,q.regionId,q.endOffset);if(K){if(Y>=D&&Y<=V)return q.threadIndex;continue}if(Math.max(Y,D)<Math.min(Q,V))return q.threadIndex}return null}function _8($,M,Z){return($.get(M)??-1)*1e6+Z}export{dJ as mintTheme,rJ as midnightTheme,r4 as lightTheme,M9 as defaultKeybindings,c4 as darkTheme,KX as Documint};
|