@datalking/begonia-browser-sdk 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser-command-table-state.d.ts +5 -0
- package/dist/browser-command-types.d.ts +3 -1
- package/dist/browser-comment-range-point.d.ts +56 -0
- package/dist/browser-editor-comments-controller.d.ts +2 -1
- package/dist/browser-editor-context-menu-open-at.d.ts +15 -0
- package/dist/browser-editor-contracts.d.ts +6 -0
- package/dist/browser-editor-domain-types.d.ts +48 -1
- package/dist/browser-editor-host.d.ts +0 -2
- package/dist/browser-editor-selection-geometry.d.ts +135 -1
- package/dist/browser-editor-types-controller.d.ts +46 -1
- package/dist/browser-editor-types-shared.d.ts +17 -0
- package/dist/browser-editor-viewport/browser-editor-viewport-bounds.d.ts +1 -1
- package/dist/browser-editor-viewport-session-state-types.d.ts +15 -0
- package/dist/browser-history-shortcut.d.ts +31 -0
- package/dist/browser-image-command-types.d.ts +28 -0
- package/dist/browser-insert-command-types.d.ts +5 -0
- package/dist/browser-page-review-target.d.ts +44 -0
- package/dist/browser-paginated-preview-controller.d.ts +6 -0
- package/dist/browser-paginated-preview-editor-binding.d.ts +76 -1
- package/dist/browser-paginated-preview-key-selection.d.ts +48 -0
- package/dist/browser-paginated-preview-position-hit.d.ts +28 -0
- package/dist/browser-paginated-preview-ui-controller.d.ts +1 -0
- package/dist/browser-table-target-resolution.d.ts +59 -0
- package/dist/command.js +5 -5
- package/dist/editor.d.ts +8 -0
- package/dist/editor.js +5 -4
- package/dist/header-footer/header-footer-band-geometry.d.ts +70 -0
- package/dist/header-footer/header-footer-band-press.d.ts +51 -0
- package/dist/header-footer/header-footer-edit-state.d.ts +44 -0
- package/dist/header-footer/header-footer-edit-target.d.ts +54 -0
- package/dist/header-footer/header-footer-editing-controller.d.ts +133 -0
- package/dist/header-footer/header-footer-exit-press.d.ts +54 -0
- package/dist/header-footer/header-footer-slot.d.ts +38 -0
- package/dist/header-footer/header-footer-story-blocks.d.ts +71 -0
- package/dist/header-footer/section-header-footer-links.d.ts +60 -0
- package/dist/header-footer/section-header-footer-variants.d.ts +55 -0
- package/dist/index.d.ts +35 -1
- package/dist/index.js +60 -5
- package/dist/ooxml.js +4 -4
- package/dist/paginated-editing/index.d.ts +7 -0
- package/dist/paginated-editing/paginated-caret-reveal.d.ts +51 -0
- package/dist/paginated-editing/paginated-column-keyboard.d.ts +50 -0
- package/dist/paginated-editing/paginated-editing-session.d.ts +8 -0
- package/dist/paginated-editing/paginated-editing-types.d.ts +169 -0
- package/dist/paginated-editing/paginated-ime-caret-measure.d.ts +26 -0
- package/dist/paginated-editing/paginated-input-anchor.d.ts +116 -0
- package/dist/paginated-editing/paginated-input-bridge.d.ts +169 -0
- package/dist/paginated-editing/paginated-table-boundary-keyboard.d.ts +24 -0
- package/dist/paginated-editing/paginated-table-boundary-keys.d.ts +33 -0
- package/dist/paginated-preview-selection-table/preview-selection-table-exit.d.ts +61 -0
- package/dist/paginated-preview-selection-table/preview-selection-table-resolve.d.ts +7 -2
- package/dist/preview.js +1 -1
- package/dist/theme/theme-presets.d.ts +14 -0
- package/dist/theme/theme-resolve.d.ts +21 -0
- package/dist/theme/theme-tokens.d.ts +118 -0
- package/dist/theme.js +1 -1
- package/dist/v1.d.ts +6 -0
- package/dist/v1.js +9 -9
- package/package.json +14 -14
- package/dist/browser-theme.d.ts +0 -26
package/dist/editor.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import{createEditorSessionController as
|
|
2
|
-
`}),
|
|
3
|
-
`});function k(e){return typeof e=="number"&&Number.isFinite(e)}function so(e){return Array.isArray(e)&&e.length>0&&no(e)}function ao(e){return!!e&&typeof e=="object"&&so(e.blockPath)}function lo(e){let r=s=>[s.blockPath.join("."),k(s.from)?Math.min(s.from,s.to??s.from):"",k(s.to)?Math.max(s.from??s.to,s.to):""].join(":"),t=[e?.target??null,...e?.targets??[]].filter(ao),o=s=>k(s.from)&&k(s.to)?0:1,n=s=>o(s)===0?Math.min(s.from,s.to):Number.POSITIVE_INFINITY,i=s=>o(s)===0?Math.max(s.from,s.to):Number.POSITIVE_INFINITY;return t.map((s,a)=>({target:s,index:a})).sort((s,a)=>o(s.target)-o(a.target)||n(s.target)-n(a.target)||i(s.target)-i(a.target)||s.index-a.index).reduce((s,a)=>{let c=r(a.target);return s.some(l=>r(l)===c)||s.push(a.target),s},[])}function lr(e,r,t){return Math.min(Math.max(e,r),t)}function co(e,r,t){if(!e||!k(t.from)||!k(t.to))return null;let o=re(e,r);if(!o)return null;let n=o.position+1,i=Math.max(n,o.position+o.node.nodeSize-1),s=Se(o,Math.min(t.from,t.to)),a=Se(o,Math.max(t.from,t.to)),c=lr(s,n,i),l=lr(a,c,i),d=h(o.document,io),u=E(o.node,o.position,c,d),p=E(o.node,o.position,l,d);return{start:Math.min(u,p),end:Math.max(u,p)}}function ve(e,r,t){if(!e||!t)return{target:null,selectionTarget:null};let o=null,n=null;for(let i of lo(t)){let s=te(e,i.blockPath,t.story);if(!s)continue;let a=s.segments[0]?.blockId;if(!a)continue;n||(o=i,n={kind:"text",segments:[{blockId:a,range:{start:0,end:0}}],...s.story?{story:s.story}:{}});let c=co(r,a,i);if(c)return{target:i,selectionTarget:{kind:"text",segments:[{blockId:a,range:c}],...s.story?{story:s.story}:{}}}}return{target:o,selectionTarget:n}}function cr(e,r,t){return ve(e,r,t).selectionTarget}import{isDocumentStoryLocator as Po,readSyntheticSideStoryDocStoryLocator as Ro,sameDocumentStoryLocator as Io}from"@datalking/begonia-doc-service/v1";import{readSyntheticSideStoryDocOriginPath as aa}from"@datalking/begonia-doc-service/v1";import{cloneSelectionTextRange as uo}from"@datalking/begonia-document-api/core";import{sameDocumentStoryLocator as ws}from"@datalking/begonia-doc-service/v1";function dr(e,r){return{kind:"text",segments:r.map(t=>({blockId:t.blockId,range:uo(t.range)})),...e.story?{story:structuredClone(e.story)}:{}}}function ur(e){return dr(e,e.segments)}import{canonicalizeRevisionIds as mo,normalizeRevisionIds as fo,selectionOverlapsRevisionRange as hs}from"@datalking/begonia-engine";import{orderOverlapRevisionIds as Ss}from"@datalking/begonia-engine";function po(e,r){return r.length>0?mo(e,r):[]}function be(e,r){let t=fo(e);return r&&r.length>0?po(t,r):t}import{projectAcceptedTextBetween as Fs}from"@datalking/begonia-engine";import{semanticNodeText as go}from"@datalking/begonia-document-model";import{isRevisionMarkHiddenInProjection as Ns,isRevisionNodeHiddenInProjection as wo}from"@datalking/begonia-engine";function mr(e,r,t=!1){return wo(e,r,t)}function Bo(e,r){return mr(e,"final",r)}function pr(e,r){let t=go(e),o=r?.resolveLeafText?.(e,t);return typeof o=="string"?o:t}function So(e,r,t){return t?"":pr(e,r)}function yo(e,r){return r?"":e.text??""}function fr(e,r){return e.isText?(e.text??"").length:e.childCount===0?pr(e,r).length:0}function vo(e,r,t,o,n,i,s){if(o.length===0)return t;r.push(o);let a=t+o.length;return e.push({atomic:s,text:o,startOffset:n,endOffset:i,visibleStart:t,visibleEnd:a}),a}function bo(e,r){let t=[],o=[],n=r?.blockSeparator??"",i=0,s=0,a=(l,d,u=!1)=>{let p=i,m=p+d;s=vo(t,o,s,l,p,m,u),i=m},c=(l,d=!1)=>{let u=Bo(l,d);if(l.isText){let m=fr(l,r);a(yo(l,u),m);return}if(l.childCount===0){let m=fr(l,r);a(So(l,r,u),m,!0);return}let p=!0;l.forEach(m=>{m.isBlock&&!p&&n.length>0&&a(n,n.length),c(m,u&&l.isInline),p=!1})};return c(e),{runs:t,text:o.join(""),maxOffset:i}}function ho(e,r,t,o){if(!Number.isInteger(t))return 0;if(t<=0)return o==="start"?e[0]?.startOffset??0:0;for(let[n,i]of e.entries()){if(t<i.visibleStart)return i.startOffset;if(t>i.visibleEnd)continue;if(t===i.visibleEnd){let c=e[n+1];return o==="start"&&c&&c.visibleStart===t?c.startOffset:i.endOffset}let s=i.visibleEnd-i.visibleStart,a=i.endOffset-i.startOffset;return i.atomic?o==="end"&&t>i.visibleStart?i.endOffset:i.startOffset:a===s?i.startOffset+(t-i.visibleStart):o==="end"&&t>i.visibleStart?i.endOffset:i.startOffset}return r}function oe(e,r,t="end",o={}){let{runs:n,text:i,maxOffset:s}=bo(e,o);return!Number.isInteger(r)||r<0||r>i.length?null:ho(n,s,r,t)}var Us=Object.freeze({blockSeparator:" "});import{NodeSelection as Zs}from"prosemirror-state";import{NodeSelection as Js,TextSelection as Xs}from"prosemirror-state";var fa=Object.freeze({success:!0}),pa=Object.freeze({success:!1,reason:"read-only"});import{parseAddressableBlockId as Eo}from"@datalking/begonia-doc-service/structure";function wr(e){return Eo(e)?.logicalId==null}var he=Object.freeze({blockSeparator:`
|
|
4
|
-
`});function ko(e,r){if(r.story===void 0)return!0;if(!Po(r.story))return!1;let t=Ro(e)??{kind:"story",storyType:"body"};return Io(t,r.story)}function Mo(e,r,t,o,n){let i=h(e,he),s=oe(r,o,n,i);return s==null?null:b(r,t,s,n,i)}function No(e,r,t,o,n){let i=h(e,he),s=oe(r,o,"start",i),a=oe(r,n,"end",i);if(s==null||a==null)return null;let c=b(r,t,Math.min(s,a),"start",i),l=b(r,t,Math.max(s,a),"end",i);return typeof c=="number"&&typeof l=="number"?{from:Math.min(c,l),to:Math.max(c,l)}:null}function Vo(e,r,t,o,n){let i=b(e,r,t,"start",n),s=b(e,r,o,"end",n);return typeof i=="number"&&typeof s=="number"?{from:Math.min(i,s),to:Math.max(i,s)}:null}function Ao(e,r){return r.collapsedAcceptedVisibleBias==="hidden-anchor"||e.range.start===0?"end":"start"}function Oo(e,r,t={}){let o=ee(e,r.blockId);if(!o)return null;let n=S(e,o);if(!n?.node.isBlock)return null;let i=h(e,he);if(wr(r.blockId)){if(r.range.start===r.range.end){let c=Mo(e,n.node,n.position,r.range.start,Ao(r,t));return typeof c=="number"?{from:c,to:c}:null}let a=No(e,n.node,n.position,r.range.start,r.range.end);return a||null}if(r.range.start===r.range.end){let a=er(n.node,n.position,r.range.start,i);return typeof a=="number"?{from:a,to:a}:null}if(t.strict)return Vo(n.node,n.position,r.range.start,r.range.end,i);let s=Qe(n.node,n.position,r.range.start,r.range.end,i);return s||null}function Ce(e,r,t={}){if(!r||!ko(e,r))return null;let o=[];for(let n of r.segments){let i=Oo(e,n,t);if(!i)return null;o.push(i)}return X(e,o,t)}function M(e){return typeof e?.readLayoutSource=="function"?e.readLayoutSource():null}function N(e){return e?.getResolvedProjection?.()??null}function _(e){return e?.getResolvedProjectionGeometryOptions?.()??null}function g(e){return{success:!1,reason:e}}function Fo(e){return!e||typeof e!="object"?!1:!!e&&"kind"in e&&e.kind==="text"&&Do(e.segments)}function gr(e){return typeof e=="number"&&Number.isFinite(e)}function jo(e){return!e||e.segments.length===0?!1:e.segments.every(r=>typeof r?.blockId=="string"&&r.blockId.trim().length>0&&gr(r.range?.start)&&gr(r.range?.end))}function Ho(e){return!e||typeof e!="object"?!1:!!e&&"type"in e&&"id"in e&&typeof e.id=="string"}function _o(e){return e?typeof e.id=="string"&&e.id.trim().length>0:!1}function xe(e){return!e||typeof e!="object"?!1:!!e&&"type"in e&&"childCount"in e&&"nodesBetween"in e&&typeof e.nodesBetween=="function"}function Br(e,r){return typeof e!="number"||!Number.isFinite(e)||typeof r!="number"||!Number.isFinite(r)?null:{from:Math.min(e,r),to:Math.max(e,r)}}function Uo(e){return{pageIndex:e.pageIndex,pageNumber:e.pageNumber,sectionId:e.sectionId??null,region:e.region,blockIndex:e.blockIndex,fragmentIndex:e.fragmentIndex,columnIndex:e.columnIndex,lineIndex:e.lineIndex,lineCount:e.lineCount,left:e.left,top:e.top,width:e.width,height:e.height}}function qo(e){return{pageIndex:e.pageIndex,pageNumber:e.pageNumber,sectionId:e.sectionId??null,region:e.region,blockIndex:e.blockIndex,fragmentIndex:e.fragmentIndex,columnIndex:e.columnIndex,lineIndex:e.lineIndex,lineCount:e.lineCount,left:e.left,top:e.top,width:1,height:e.height}}function Wo(e){return[e.pageIndex,e.pageNumber,e.sectionId??"",e.region,e.blockIndex,e.fragmentIndex,e.columnIndex,e.lineIndex,e.lineCount,e.left,e.top,e.width,e.height].join(":")}function Zo(e){let r=[],t=new Set;for(let o of e){let n=Wo(o);t.has(n)||(t.add(n),r.push(o))}return r}function Ko(e,r){let t=N(e),o=_(e)??{};if(!t)return[];if(r.from===r.to){let n=Lo(t,r.from,o);return n?[qo(n)]:[]}return zo(t,r.from,r.to,o).map(Uo)}function Te(e,r){if(r.segments.length===0)return null;let t=[];for(let o of r.segments){let n=$o(e,o);if(!n)return null;t.push(n)}return t}function Go(e,r){return e.syntheticRootPath&&typeof e.positionRoot=="number"?{from:e.positionRoot+r.from,to:e.positionRoot+r.to}:r}function $o(e,r){let t={kind:"text",segments:[r]},o=Ce(e,t,{strict:!0});if(o)return o;let n=re(e,r.blockId);if(!n||n.document===e)return null;let i=Ce(n.document,t,{strict:!0});return i?Go(n,i):null}function Yo(e){if(!e)return[];let r=(e.segments??[]).map(o=>Br(o.from,o.to)).filter(o=>o!=null).sort((o,n)=>o.from-n.from||o.to-n.to);if(r.length>0)return r;let t=Br(e.from,e.to);return t?[t]:[]}function Jo(e,r,t){if(!t||typeof r?.blocks?.read!="function")return null;let o=cr(r,e,t);return o?Te(e,o):null}function Xo(e,r="unresolved"){let[t]=e;return t?{success:!0,rect:t,rects:[...e],pageIndex:t.pageIndex,pageNumber:t.pageNumber}:g(r)}function U(e,r){let t=Zo(r.flatMap(o=>Ko(e,o)));return Xo(t,r.length>0?"not-mounted":"unresolved")}function V(e,r){let t=e.preview??null;if(!t||!N(t))return g("not-ready");let o=r.target??null;if(!o)return g("invalid-target");if(Fo(o)){if(!jo(o))return g("invalid-target");let n=M(t);if(!xe(n))return g("not-ready");let i=Te(n,o);return i?U(t,i):g("unresolved")}if(!Ho(o)||!_o(o))return g("invalid-target");if(o.type==="comment"){let n=M(t);if(!xe(n))return g("not-ready");let i=e.documentApi?.comments.target(o.id)??null,s=ar(e.documentApi,i),a=s?Te(n,s):null;if(a)return U(t,a);let c=Be(n,i);return c?U(t,[c]):g("unresolved")}if(o.type==="trackedChange"){let n=e.documentApi?.trackChanges.get(o.id)??null,i=M(t),s=xe(i)?Jo(i,e.documentApi,n):null;if(s)return U(t,s);let a=Yo(n);return a.length===0?g("unresolved"):U(t,a)}return g("invalid-target")}var Qo=Object.freeze([]),en=[],rn=Object.freeze({});function Ee(e){let r=e?.items??en,t=e?.permissions??rn;return{items:r,permissions:t,total:typeof e?.total=="number"?Math.max(0,Math.trunc(e.total)):r.length,activeCommentId:e?.activeCommentId??null,activeCommentIds:e?.activeCommentIds??Qo,enabled:e?.enabled??!1,visible:e?.visible??!1,readOnly:e?.readOnly??!1,showResolved:e?.showResolved??!1,visibility:e?.visibility??null}}function Sr(e){return structuredClone(e)}function Pe(e){return Ee(e?e.session.readState()?.comments??null:null)}function yr(e,r){return D(typeof r=="string"?[r]:[],B(Pe(e).items))[0]??null}function Re(e,r){let t=J(),o=()=>Sr(Ee(r.getSnapshot())),n=i=>r.subscribe(s=>{i(Sr(Ee(s)))});return{getSnapshot:o,subscribe:n,observe(i){return n(i)},create(i,s){return e.commentActions.createComment(i,s)},reply(i,s,a=null){return e.commentActions.replyComment(i,s,a)},setInternal(i,s){return e.commentActions.setCommentInternal(i,s)},resolve(i){return e.commentActions.resolveComment(i)},reopen(i){return e.commentActions.reopenComment(i)},setActive(i){return t.invalidate(),e.commentFocus.setActiveComment(i)},reveal(i){t.invalidate();let s=Pe(e).activeCommentId??null,a=typeof i=="string"?yr(e,i):null;a&&e.commentFocus.setActiveComment(a);let c=me(e,i);return!c.selected&&a&&e.commentFocus.setActiveComment(s),c},async scrollTo(i,s){let a=t.begin(),c=Pe(e).activeCommentId??null,l=typeof i=="string"?yr(e,i):null;l&&e.commentFocus.setActiveComment(l);let d=await fe(e,i,s,{continuation:a});return a.shouldContinue()?(!d.success&&l&&e.commentFocus.setActiveComment(c),d):{success:!1}},getAt(i){return Je(e,i,o().items)},getRect({id:i}){return V(e,{target:{type:"comment",id:i}})}}}var tn=["editing","suggesting","viewing"],on=["review","original","final","off"],nn=["paired","independent"],sn=["all","internal","external"];function ne(e,r){return typeof e=="string"&&r.includes(e)}function vr(e){return ne(e,tn)?e:null}function br(e){return ne(e,on)?e:null}function hr(e){return ne(e,nn)?e:null}function Cr(e){return ne(e,sn)?e:null}function an(e){return e==="paginated"||e==="web"?e:null}function xr(e){return an(e)??"paginated"}function q(e){return e==="vertical"||e==="horizontal"||e==="book"?e:null}function Tr(e,r){return r==="web"?"vertical":q(e)??"vertical"}function Er(e){let r=xr(e.flowMode),t=q(e.preferredPaginatedLayoutMode)??q(e.layoutMode)??"vertical";return{flowMode:r,layoutMode:Tr(q(e.layoutMode)??t,r),preferredPaginatedLayoutMode:t}}import{resolveEditorSelectionRootOffsets as Pr}from"@datalking/begonia-editor-contracts";import{listProjectionSelectionRects as ln,resolveProjectionCaretRect as cn}from"@datalking/begonia-page-layout";function dn(e){return e==="end"||e==="union"?e:"start"}function un(e){return e?{left:e.left,top:e.top,width:1,height:e.height}:null}function mn(e){if(e.length===0)return null;let r=e[0].left,t=e[0].top,o=e[0].left+e[0].width,n=e[0].top+e[0].height;for(let i of e.slice(1))r=Math.min(r,i.left),t=Math.min(t,i.top),o=Math.max(o,i.left+i.width),n=Math.max(n,i.top+i.height);return{left:r,top:t,width:Math.max(1,o-r),height:Math.max(1,n-t)}}function Ie(e,r){let t=N(e),o=_(e)??{};if(!t||!r||r.empty)return[];let n=Pr(r);return n?ln(t,n.from,n.to,o):[]}function ke(e,r,t={}){let o=N(e),n=_(e)??{};if(!o||!r||!r.empty)return null;let i=Pr(r);return i?cn(o,i.from,{bias:t.bias,measureText:n.measureText,measurementEpoch:n.measurementEpoch}):null}function Rr(e,r,t={}){let o=Ie(e,r);if(o.length===0)return un(ke(e,r));switch(dn(t.placement)){case"end":{let n=o.at(-1)??null;return n?{left:n.left,top:n.top,width:n.width,height:n.height}:null}case"union":return mn(o);default:{let n=o[0]??null;return n?{left:n.left,top:n.top,width:n.width,height:n.height}:null}}}import{cloneEditorSelectionSnapshot as fn}from"@datalking/begonia-editor-contracts";function Ir(e){return e?{empty:e.empty,target:e.target?ur(e.target):null,activeMarks:[...e.activeMarks],activeCommentIds:[...e.activeCommentIds],activeChangeIds:[...e.activeChangeIds],...typeof e.text=="string"?{text:e.text}:{}}:null}var Me=Object.freeze([]);function pn(e){return e?structuredClone(e):void 0}function wn(e){if(!e||!Array.isArray(e.segments))return null;let r=e.segments[0]??null,t=e.segments[e.segments.length-1]??null;if(!r||!t)return null;let o=pn(e.story);return{kind:"selection",start:{kind:"text",blockId:r.blockId,offset:r.range.start,...o?{story:o}:{}},end:{kind:"text",blockId:t.blockId,offset:t.range.end,...o?{story:o}:{}},segments:e.segments.map(n=>({blockId:n.blockId,start:n.range.start,end:n.range.end})),...o?{story:o}:{}}}function kr(e,r){if(!e)return null;let t=fn(e),o=Ir(r),n=o?.target??null;return{...t,target:n,selectionTarget:wn(n),activeMarks:o?.activeMarks??Me,activeCommentIds:o?.activeCommentIds??Me,activeChangeIds:o?.activeChangeIds??Me,quotedText:o?.text??""}}import{clonePageViewportAnchor as Lr,hasFreshViewportRequest as yl,normalizeViewportRequestKey as vl,samePageViewportAnchor as bl,sameViewportRequestKey as hl}from"@datalking/begonia-layout-renderer/core";import{hasLogicalViewportAnchorHint as ul}from"@datalking/begonia-layout-renderer/core";function w(e){return typeof e=="number"&&Number.isFinite(e)}function Nr(e,r=0){return w(e)?Math.max(0,Math.trunc(e)):r}function Ve(e){return w(e)&&Number.isInteger(e)&&e>=0?e:null}function P(e){return w(e)&&Number.isInteger(e)&&e>0?e:null}function Ne(e,r){if(!Array.isArray(e))return[];let t=e.filter(o=>w(o)&&Number.isInteger(o)&&o>=r);return[...new Set(t)].sort((o,n)=>o-n)}function gn(e){return e.map(r=>r+1)}function Mr(e){return e.map(r=>r-1)}function Bn(e,r){return e.length===r.length&&e.every((t,o)=>t===r[o])}function Ae(e,r){let t=Ne(r,1);if(t.length>0){let n=Ne(e,0);return n.length>0&&!Bn(Mr(t),n)?null:{pageIndexes:Mr(t),pageNumbers:t}}let o=Ne(e,0);return{pageIndexes:o,pageNumbers:gn(o)}}function Vr(e){return e==="vertical"||e==="horizontal"||e==="book"?e:null}function Ar(e){return e==="paginated"||e==="web"?e:null}function Or(e){return w(e)&&e>0?e:null}function zr(e,r){let t=Ar(e),o=Vr(r);return e!=null&&t==null||r!=null&&o==null?null:t==="web"?o!=null&&o!=="vertical"?null:{flowMode:t,layoutMode:"vertical"}:{flowMode:t,layoutMode:o}}function ze(e,r){let t=P(r),o=Ve(e);return t!=null&&o!=null&&o!==t-1?{pageIndex:null,pageNumber:null}:{pageIndex:t!=null?t-1:o,pageNumber:t??(o!=null?o+1:null)}}function yn(e){if(e.visiblePageNumbers.length>0){let o=P(e.firstVisiblePageNumber),n=P(e.lastVisiblePageNumber);return o!=null&&o!==e.visiblePageNumbers[0]||n!=null&&n!==e.visiblePageNumbers[e.visiblePageNumbers.length-1]?null:{firstVisiblePageNumber:e.visiblePageNumbers[0]??null,lastVisiblePageNumber:e.visiblePageNumbers[e.visiblePageNumbers.length-1]??null}}let r=P(e.firstVisiblePageNumber),t=P(e.lastVisiblePageNumber);return r!=null&&t!=null&&r>t?null:{firstVisiblePageNumber:r,lastVisiblePageNumber:t}}function vn(e){return!!(e&&typeof e=="object"&&(Object.hasOwn(e,"pageNumber")||Object.hasOwn(e,"pageIndex")))}function Dr(e,r,t){let o=w(r)?Math.max(0,r):Math.max(0,(w(t)?t:e)-e);return{size:o,end:e+o}}function Oe(e){let r=P(e?.pageNumber),t=Ve(e?.pageIndex);if(r==null&&t==null||r!=null&&t!=null&&t!==r-1)return null;let o=r??(t??0)+1;return{pageIndex:o-1,pageNumber:o}}function Fr(e,r=null){if(e&&typeof e=="object"&&vn(e)&&!Oe(e))return null;let t=Lr(e);if(t)return t;if(!e||typeof e!="object")return null;let o=Oe(e)??Oe(r);return o?Lr({...e,...o}):null}function ie(e){if(!e||typeof e!="object")return null;let r=zr(e.flowMode,e.layoutMode);if(!r)return null;let t=ze(e.currentPageIndex,e.currentPageNumber),o=ze(e.anchorPageIndex,e.anchorPageNumber),n=w(e.viewportTop)?e.viewportTop:0,i=w(e.viewportLeft)?e.viewportLeft:0,s=Dr(n,e.viewportHeight,e.viewportBottom),a=Dr(i,e.viewportWidth,e.viewportRight),c=Ae(e.visiblePageIndexes,e.visiblePageNumbers);if(!c)return null;let l=Ae(e.mountedPageIndexes,e.mountedPageNumbers);if(!l)return null;let d=yn({visiblePageNumbers:c.pageNumbers,firstVisiblePageNumber:e.firstVisiblePageNumber,lastVisiblePageNumber:e.lastVisiblePageNumber});if(!d)return null;let u=Fr(e.viewportAnchor,{pageIndex:o.pageIndex??t.pageIndex,pageNumber:o.pageNumber??t.pageNumber});return{totalPages:Nr(e.totalPages),currentPageIndex:t.pageIndex,currentPageNumber:t.pageNumber,anchorPageIndex:o.pageIndex,anchorPageNumber:o.pageNumber,viewportAnchor:u,visiblePageIndexes:c.pageIndexes,visiblePageNumbers:c.pageNumbers,mountedPageIndexes:l.pageIndexes,mountedPageNumbers:l.pageNumbers,firstVisiblePageNumber:d.firstVisiblePageNumber,lastVisiblePageNumber:d.lastVisiblePageNumber,viewportTop:n,viewportBottom:s.end,viewportHeight:s.size,viewportLeft:i,viewportRight:a.end,viewportWidth:a.size,topSpacer:w(e.topSpacer)?Math.max(0,e.topSpacer):0,bottomSpacer:w(e.bottomSpacer)?Math.max(0,e.bottomSpacer):0,leftSpacer:w(e.leftSpacer)?Math.max(0,e.leftSpacer):0,rightSpacer:w(e.rightSpacer)?Math.max(0,e.rightSpacer):0,layoutMode:r.layoutMode,flowMode:r.flowMode,scale:Or(e.scale)}}var bn=Object.freeze({percent:100,mode:"manual",value:100,fitZoom:null,min:10,max:400,viewportMetrics:null});function A(e){return{getSnapshot(){return e.get()},subscribe(r){return e.subscribe(r)},observe(r){return e.subscribe(r)}}}function hn(e){let r=Er(e);return{flowMode:r.flowMode,layoutMode:r.layoutMode,preferredPaginatedLayoutMode:r.preferredPaginatedLayoutMode,zoom:jr(e)}}function Cn(e){return kr(e.selection,e.selectionInfo)}function xn(e){return{editable:e.editable,documentMode:vr(e.documentMode),trackingEnabled:e.trackingEnabled,trackChanges:{enabled:e.review.enabled,visible:e.review.visible,mode:br(e.review.mode),replacementMode:hr(e.review.replacementMode)}}}function Tn(e){return{enabled:e.comments.enabled,visible:e.comments.visible,readOnly:e.comments.readOnly,allowResolve:e.comments.allowResolve??!1,showResolved:e.comments.showResolved,visibility:Cr(e.comments.visibility),useInternalExternalComments:e.comments.useInternalExternalComments??!1,suppressInternalExternal:e.comments.suppressInternalExternal??!1,enforceVisibilityPolicy:e.comments.enforceVisibilityPolicy??!1,total:e.comments.total??e.comments.items.length}}function jr(e){return e.zoom?{percent:e.zoom.percent,mode:e.zoom.mode==="fit-width"?"fit-width":"manual",value:typeof e.zoom.value=="number"?e.zoom.value:e.zoom.percent,fitZoom:typeof e.zoom.fitZoom=="number"?e.zoom.fitZoom:null,min:typeof e.zoom.min=="number"?e.zoom.min:10,max:typeof e.zoom.max=="number"?e.zoom.max:400,viewportMetrics:e.zoom.viewportMetrics}:bn}function En(e){if(!e.viewport)return null;let r=ie(e.viewport.value);return{value:r,requestKey:e.viewport.requestKey,previewNavigationRequest:e.viewport.previewNavigationRequest,totalPages:r?.totalPages??null,currentPageIndex:r?.currentPageIndex??null,currentPageNumber:r?.currentPageNumber??null}}function Hr(e,r){return{...A(r.select(hn)),setViewState(o){e.view.setViewState(o)},getZoomState(){return e.view.getZoomState()},setZoomMode(o){e.view.setZoomMode(o)}}}function _r(e,r){let t=A(r.select(Cn));return{...t,getRects(){return Ie(e.preview,t.getSnapshot())},getAnchorRect(o){return Rr(e.preview,t.getSnapshot(),o)},getCaretRect(o){return ke(e.preview,t.getSnapshot(),o)}}}function Ur(e,r){return{...A(r.select(xn)),setDocumentMode(o){e.documentMode.setDocumentMode(o)},setTrackChangesDisplayMode(o){e.documentMode.setTrackChangesDisplayMode(o)}}}function qr(e,r){return{...A(r.select(Tn)),setCommentsVisible(o){e.commentsDisplay.setCommentsVisible(o)},setCommentsShowResolved(o){e.commentsDisplay.setCommentsShowResolved(o)},setCommentsVisibility(o){e.commentsDisplay.setCommentsVisibility(o)}}}function Wr(e,r){return{...A(r.select(jr)),set(o){e.view.setViewState({zoomPercent:o})},setMode(o){e.view.setZoomMode(o)}}}function Zr(e,r){return{...A(r.select(En)),getHost(){return e.browserViewport.getHost?.()??null},getScrollContainer(){return e.browserViewport.getScrollContainer?.()??null},observeGeometry(o){return e.browserViewport.observeGeometry(o)},scrollIntoView(o){return e.browserViewport.scrollIntoView(o)},getRect(o){return V(e,o)},entitiesAtPoint(o){return e.browserViewport.entitiesAtPoint(o)},contextAtPoint(o){return e.browserViewport.contextAtPoint(o)},positionAtPoint(o){return e.browserViewport.positionAtPoint(o)},requestNavigation(o){return e.browserViewport.requestNavigation(o)},requestNavigationForTextTarget(o){return e.browserViewport.requestNavigationForTextTarget(o)},ackNavigationRequest(o){e.browserViewport.ackNavigationRequest(o)}}}import{isIntegerPath as Pn}from"@datalking/begonia-document-model";function O(e={}){return{revisionId:null,trackChange:null,target:null,selectionTarget:null,navigationRequest:null,...e}}function Rn(e){return Array.isArray(e)&&e.length>0&&Pn(e)}function se(e){return!!e&&typeof e=="object"&&Rn(e.blockPath)}function Gr(e){if(!e)return null;if(typeof e=="string")return e.length>0?e:null;let r="revisionId"in e?e.revisionId:"id"in e?e.id:null;return typeof r=="string"&&r.length>0?r:null}function In(e){return e?se(e.target)?e.target:(e.targets??[]).find(se)??null:null}function kn(e){let r="target"in e?e.target:null,t="targets"in e?e.targets:null;return se(r)||(t??[]).some(se)}function Mn(e,r){if(typeof r!="string"&&kn(r))return r;let t=Gr(r);return t?e.documentApi.trackChanges.get(t):null}function Nn(e,r){let t=M(de(e));return ve(e.documentApi,Vn(t)?t:null,r)}function Vn(e){return e!=null&&typeof e=="object"&&"type"in e&&"nodesBetween"in e&&typeof e.nodesBetween=="function"}function An(e,r){return(typeof r?.id=="string"&&r.id.length>0?r.id:typeof r?.revisionId=="string"&&r.revisionId.length>0?r.revisionId:null)??e}function x(e,r){if(!e||!r)return O();let t=f(e);if(!t)return O();let o=Gr(r),n=Mn(t,r);if(!n)return O({revisionId:o});let i=An(o,n),s=Nn(t,n),a=s.target??In(n);if(!a)return O({revisionId:i,trackChange:n});let c=s.selectionTarget;return O(c?{revisionId:i,trackChange:n,target:a,selectionTarget:c}:{revisionId:i,trackChange:n,target:a})}function On(e,r){let t=x(e,r),o=f(e);return!o||!t.selectionTarget?t:{...t,navigationRequest:o.browserViewport.requestNavigationForTextTarget(t.selectionTarget)}}function Kr(){return{success:!1}}function zn(e){let r=e.revisionId;if(typeof r=="string"&&r.length>0)return r;let t=e.trackChange?.id;return typeof t=="string"&&t.length>0?t:null}async function W(e,r,t={},o={}){let n=x(e,r),i=f(e);return!i||!n.selectionTarget?Kr():$(i.selectionHandles,async()=>{if(i.selectionTargets.selectTextTarget(n.selectionTarget))return i.browserViewport.scrollIntoView({target:n.selectionTarget,timeoutMs:t.timeoutMs,continuation:o.continuation});let s=zn(n);return s?i.browserViewport.scrollIntoView({target:{type:"trackedChange",id:s},timeoutMs:t.timeoutMs,continuation:o.continuation}):Kr()},{shouldContinue:o.continuation?.shouldContinue})}function $r(e){if(e==null||typeof e!="object")return!1;let r=Object.getPrototypeOf(e);return r===Object.prototype||r===null}function ae(e,r){if(Object.is(e,r))return!0;if(e==null||r==null)return!1;if(Array.isArray(e)||Array.isArray(r)){if(!Array.isArray(e)||!Array.isArray(r)||e.length!==r.length)return!1;for(let n=0;n<e.length;n+=1)if(!ae(e[n],r[n]))return!1;return!0}if(!$r(e)||!$r(r))return!1;let t=Object.keys(e),o=Object.keys(r);if(t.length!==o.length)return!1;for(let n of t)if(!Object.hasOwn(r,n)||!ae(e[n],r[n]))return!1;return!0}function Le(e,r,t){let o=e.filter(s=>typeof s.id=="string"&&s.id.length>0);if(o.length===0)return null;let n=r==null?-1:o.findIndex(s=>s.id===r),i=t==="next"?n<0||n>=o.length-1?0:n+1:n<=0?o.length-1:n-1;return o[i]?.id??null}function Ln(e){return e.find(r=>r.type==="trackedChange")??null}function Dn(e){return[...new Set(e.filter(r=>r.type==="trackedChange").map(r=>r.id))]}function Fn(e,r){return e.find(t=>t.id===r)??null}function jn(e,r){let t=Dn(r);if(t.length!==1)return null;let o=t[0]??Ln(r)?.id??null;if(!o)return null;let n=Fn(e,o);return!n||typeof n.id!="string"||n.id.length===0?null:{id:n.id,item:n}}function Yr(e,r,t){if(!r||typeof r!="object"||typeof r.clientX!="number"||typeof r.clientY!="number")return null;let o=f(e);return o?jn(t,o.browserViewport.entitiesAtPoint(r)):null}var Jr=Object.freeze([]),Hn=Object.freeze([]),_n=Object.freeze([]),Un=Object.freeze({});function De(e){return structuredClone(e)}function qn(){return{items:Hn,permissions:Un,timeline:_n,summary:null,total:0,activeRevisionId:null,activeRevisionIds:Jr,enabled:!1,visible:!1,mode:null,replacementMode:null}}function Wn(e,r){return ae(e,r)}function Zn(e){return e?{items:e.revisions,permissions:e.permissions,timeline:e.timeline,summary:e.summary,total:e.revisions.length,activeRevisionId:e.activeRevisionId??null,activeRevisionIds:e.activeRevisionIds??Jr,enabled:e.enabled,visible:e.visible,mode:e.mode,replacementMode:e.replacementMode}:qn()}function y(e){let t=f(e)?.session.readState();return Zn(t?.review)}function T(){return{revisionId:null,trackChange:null,target:null,selectionTarget:null,navigationRequest:null,selected:!1}}function L(e,r){let t=f(e);if(!t||!r)return T();let o=x(e,r);if(!o.selectionTarget)return{...o,selected:!1};let n=t.selectionTargets.selectTextTarget(o.selectionTarget),i=t.browserViewport.requestNavigationForTextTarget(o.selectionTarget);return{...o,navigationRequest:i,selected:n}}function C(e,r){let t=f(e);return t?t.reviewFocus.setActiveRevision(r):!1}function z(e,r){let t=f(e);return t?r==="next"?t.reviewFocus.nextActiveRevision():t.reviewFocus.previousActiveRevision():null}async function Kn(e,r,t,o){if(!f(e))return{success:!1};let i=y(e).activeRevisionId??null,s=x(e,r);s.revisionId&&C(e,s.revisionId);let a=await W(e,r,t,{continuation:o});return o.shouldContinue()?(!a.success&&s.revisionId&&C(e,i),a):{success:!1}}function Fe(e){let r=f(e);if(!r)throw new Error("createBrowserEditorTrackChangesController requires a valid browser editor UI source.");let t=y(e),o=null,n=new Set,i=J(),s=()=>{o||n.size===0||(o=r.session.subscribe(()=>{let l=y(e);if(Wn(t,l)){t=l;return}t=l;for(let d of[...n])d(De(t))}))},a=()=>{n.size>0||!o||(o(),o=null)},c=l=>(t=y(e),n.add(l),s(),l(De(t)),()=>{n.delete(l),a()});return{getSnapshot(){return t=y(e),De(t)},subscribe:c,observe(l){return c(l)},accept(l){return r.reviewActions.acceptRevision(l)},reject(l){return r.reviewActions.rejectRevision(l)},acceptAll(){return r.reviewActions.acceptAll()},rejectAll(){return r.reviewActions.rejectAll()},setActive(l){return i.invalidate(),C(e,l)},next(){return i.invalidate(),z(e,"next")},previous(){return i.invalidate(),z(e,"previous")},reveal(l){i.invalidate();let d=x(e,l);return d.revisionId&&C(e,d.revisionId),L(e,l)},revealNext(){i.invalidate();let l=z(e,"next");return l?L(e,l):T()},revealPrevious(){i.invalidate();let l=z(e,"previous");return l?L(e,l):T()},getAt(l){return t=y(e),Yr(e,l,t.items)},scrollTo(l,d){return Kn(e,l,d,i.begin())},navigateNext(l){let d=i.begin(),u=y(e).activeRevisionId??null,p=z(e,"next");return p?W(e,p,l,{continuation:d}).then(m=>d.shouldContinue()?(m.success||C(e,u),m):{success:!1}):Promise.resolve({success:!1})},navigatePrevious(l){let d=i.begin(),u=y(e).activeRevisionId??null,p=z(e,"previous");return p?W(e,p,l,{continuation:d}).then(m=>d.shouldContinue()?(m.success||C(e,u),m):{success:!1}):Promise.resolve({success:!1})},getRect({id:l}){return V(r,{target:{type:"trackedChange",id:l}})}}}function Gn(e,r){let t=f(e);if(!t)return T();let o=x(t,r);return o.revisionId&&C(t,o.revisionId),L(t,r)}function $n(e){let r=f(e);if(!r)return T();let t=y(r),o=Le(t.items,t.activeRevisionId,"next");return o&&C(r,o),o?L(r,o):T()}function Yn(e){let r=f(e);if(!r)return T();let t=y(r),o=Le(t.items,t.activeRevisionId,"previous");return o&&C(r,o),o?L(r,o):T()}function Xn(e){let r=Jn(e.session),t=_r(e,r),o=Hr(e,r),n=Ur(e,r),i=qr(e,r),s=Zr(e,r),a=Wr(e,r),c=Re(e,r.comments),l=Fe(e),d=Object.assign(r,{host:e,session:e.session,documentApi:e.documentApi,readCommandSnapshot(u){return e.readCommandSnapshot(u)},selection:t,selectionHandles:e.selectionHandles,linkSelection:e.linkSelection,activeLink:e.activeLink,view:o,documentMode:n,comments:c,commentsDisplay:i,commentActions:e.commentActions,commentFocus:e.commentFocus,reviewActions:e.reviewActions,reviewFocus:e.reviewFocus,trackChanges:l,selectionTargets:e.selectionTargets,viewport:s,zoom:a,browserViewport:e.browserViewport,preview:e.preview,overlayState:e.overlayState,overlays:e.overlays??{}});return Object.defineProperty(d,"actor",{configurable:!1,enumerable:!0,get(){return e.actor}}),d}function Qn(e,r){let t=null;for(let o of e??[]){let n=r.get(v(o));if(n){if(t==null){t=n;continue}if(t!==n)return null}}return t}function ei(e,r,t){let o=r.get(v(t));return o?(e??[]).some(n=>r.get(v(n))===o):!1}function ri(e){let r=Math.min(e.from,e.to),t=Math.max(e.from,e.to);return{start:r,selectionEnd:r===t?t+1:t,collapsed:r===t}}function ti(e){return e!=null&&Math.min(e.from,e.to)===Math.max(e.from,e.to)}function oi(e,r){if(!e||!r)return!1;let t=ri(e),o=Math.min(r.from,r.to),n=Math.max(r.from,r.to);return o===n?o<t.selectionEnd&&o>=t.start:o<t.selectionEnd&&n>t.start}function ni(e){let r=B(e.comments),t=new Set(r.values()),o=r.get(v(e.selectedCommentId))??"",n=ti(e.selection),i=Qn(e.selectionInfo?.activeCommentIds,r),s=ei(e.selectionInfo?.activeCommentIds,r,o),a=t.has(o);return a&&s?o:i||(a&&e.selectedCommentSelection&&(!n||oi(e.selection,e.selectedCommentSelection))?o:null)}function ii(e){let r=[],t=new Set;for(let o of e)typeof o!="string"||o.length===0||t.has(o)||(t.add(o),r.push(o));return r}function je(e){let r=ii(be(e.selectionInfo?.activeChangeIds,e.revisions));if(!e.revisions||e.revisions.length===0)return r;let t=new Set(e.revisions.map(o=>o.id));return r.filter(o=>t.has(o))}function si(e){let r=je(e);return r.length===1?r[0]??null:null}function ai(e){let r=je(e);return{activeRevisionIds:r,activeRevisionId:r.length===1?r[0]??null:null}}function li(e){let r=[],t=new Set;for(let o of e)typeof o!="string"||o.length===0||t.has(o)||(t.add(o),r.push(o));return r}function Xr(e,r){if(r==null)return[...e];let t=new Set(B(r).values());return e.filter(o=>t.has(o))}function ci(e){return Xr(D(e.selectionInfo?.activeCommentIds,B(e.comments)),e.comments)}function di(e){let r=ci(e);return{activeCommentIds:r,activeCommentId:r.length===1?r[0]??null:null}}function ui(e){return Xr(D(li([...e.explicitActiveCommentIds??[],e.explicitActiveCommentId]),B(e.comments)),e.comments)}function mi(e){let r=di(e);if(r.activeCommentIds.length>0)return r;let t=ui(e);return{activeCommentIds:t,activeCommentId:t.length===1?t[0]??null:null}}function fi(e){let r=e?.layoutMode??"vertical";return{flowMode:e?.flowMode??"paginated",layoutMode:r,preferredPaginatedLayoutMode:e?.preferredPaginatedLayoutMode??r,zoomPercent:e?.zoom?.percent??e?.zoomPercent??100,zoomMode:e?.zoom?.mode??"manual"}}function pi(e,r){switch(r.type){case"flow":return{flowMode:r.flowMode};case"toggle-pagination":return{flowMode:e.flowMode==="paginated"?"web":"paginated"};case"layout":return{flowMode:"paginated",layoutMode:r.layoutMode};case"zoom":return{zoomPercent:r.zoomPercent}}}function wi(e){return e.flowMode==="paginated"?e.layoutMode:e.preferredPaginatedLayoutMode}function gi(e){return e.zoomMode==="fit-width"?"manual":"fit-width"}function Bi(e,r,t){let o=[...r].filter(n=>Number.isFinite(n)&&n>0).sort((n,i)=>n-i);if(o.length===0)return e;if(t<0){for(let n=o.length-1;n>=0;n-=1){let i=o[n];if(i!==void 0&&i<e)return i}return e}for(let n of o)if(n>e)return n;return e}export{Re as createBrowserEditorCommentsController,Fe as createBrowserEditorTrackChangesController,Xn as createBrowserEditorUi,me as focusBrowserCommentTarget,On as requestBrowserTrackChangeNavigation,Be as resolveBrowserCommentTargetSelection,ni as resolveBrowserEditorActiveCommentId,si as resolveBrowserEditorActiveRevisionId,je as resolveBrowserEditorActiveRevisionIds,ai as resolveBrowserEditorActiveRevisionSelection,mi as resolveBrowserEditorFocusedActiveCommentState,de as resolveBrowserEditorPreviewBinding,x as resolveBrowserTrackChangeNavigation,pi as resolveBrowserViewIntentPatch,fi as resolveBrowserViewIntentSnapshot,wi as resolveBrowserViewLayoutMode,gi as resolveBrowserViewZoomMode,Bi as resolveBrowserZoomStep,Gn as revealBrowserTrackChange,$n as revealNextBrowserTrackChange,Yn as revealPreviousBrowserTrackChange,fe as scrollBrowserCommentTargetIntoView,W as scrollBrowserTrackChangeIntoView};
|
|
1
|
+
import{createEditorSessionController as Rp}from"@datalking/begonia-editor-ui";function Pe(e){return e?.trim()??""}function oe(e){let t=new Map,r=new Set;for(let n of e??[]){let i=Pe(n.id);i.length!==0&&(r.add(i),t.set(i,i))}let o=new Map;for(let n of e??[]){let i=Pe(n.id);if(i.length===0)continue;let s=Pe(n.wireId);if(s.length===0||r.has(s))continue;let l=o.get(s);l===void 0||l===i?o.set(s,i):o.set(s,null)}for(let[n,i]of o)i&&t.set(n,i);return t}function st(e,t){let r=Pe(e);return t.get(r)??r}function Ue(e,t){return[...new Set((e??[]).map(r=>st(r,t)).filter(r=>r.length>0))]}function Yi(){return{success:!1}}function $i(e,t){try{e.restoreSelectionHandle?.(t,{focus:!1})}catch{return}}function Zi(e){return e.shouldContinue?.()??!0}async function Pr(e,t,r={}){let o=e.captureEffectiveSelectionHandle();try{let n=await t();return Zi(r)?(n.success||$i(e,o),n):Yi()}catch{return Zi(r)&&$i(e,o),Yi()}finally{e.releaseSelectionHandle(o)}}function pd(e){return"host"in e}function V(e){return e?pd(e)?e.host:e:null}function wd(e){return"getState"in e&&typeof e.getState=="function"&&"subscribe"in e&&typeof e.subscribe=="function"&&"readLayoutSource"in e&&typeof e.readLayoutSource=="function"&&"readLayoutAdapter"in e&&typeof e.readLayoutAdapter=="function"&&"requestPreviewNavigation"in e&&typeof e.requestPreviewNavigation=="function"&&"ackPreviewNavigationRequest"in e&&typeof e.ackPreviewNavigationRequest=="function"&&"setViewState"in e&&typeof e.setViewState=="function"&&"setZoomViewportMetrics"in e&&typeof e.setZoomViewportMetrics=="function"}function No(e){return e?wd(e)?e:V(e)?.preview??null:null}function Cr(e={}){return{commentTarget:null,selected:!1,selectionTarget:null,navigationRequest:null,...e}}function Ji(e,t){return t?typeof t=="string"?e.documentApi.comments.target(t):t:null}function Qi(e){return e.documentApi.selection.current({includeText:!0}).target}function gd(e){return e&&"id"in e&&typeof e.id=="string"&&e.id.length>0?e.id:null}function Ao(){return{success:!1}}function Oo(e,t){let r=V(e);if(!r)return Cr();let o=Ji(r,t);if(!o)return Cr();if(!r.selectionTargets.selectCommentTarget(o))return Cr({commentTarget:o});let i=Qi(r);return Cr({commentTarget:o,selected:!0,selectionTarget:i,navigationRequest:r.browserViewport.requestNavigationForTextTarget(i)})}async function Vo(e,t,r={},o={}){let n=V(e);if(!n)return Ao();let i=Ji(n,t);return i?Pr(n.selectionHandles,async()=>{if(n.selectionTargets.selectCommentTarget(i)){let l=Qi(n);if(l)return n.browserViewport.scrollIntoView({target:l,timeoutMs:r.timeoutMs,continuation:o.continuation})}let s=gd(i);return s?n.browserViewport.scrollIntoView({target:{type:"comment",id:s},timeoutMs:r.timeoutMs,continuation:o.continuation}):Ao()},{shouldContinue:o.continuation?.shouldContinue}):Ao()}function hd(e,t,r){return{shouldContinue(){return e()===t},subscribe(o){return r(t,o)}}}function xr(){let e=0,t=new Set,r=()=>{let n=[...t];e+=1,t=new Set;for(let i of n)try{i()}catch{continue}return e},o=(n,i)=>n!==e?()=>{}:(t.add(i),()=>{n===e&&t.delete(i)});return{begin(){let n=r();return hd(()=>e,n,o)},invalidate(){r()}}}function bd(e){return e.find(t=>t.type==="comment")??null}function vd(e,t){return[...new Set(e.filter(r=>r.type==="comment").map(r=>st(r.id,t)).filter(r=>r.length>0))]}function Sd(e,t){let r=oe(e),o=st(t,r);return e.find(n=>st(n.id,r)===o||st(n.wireId,r)===o)??null}function Bd(e,t){let r=oe(e),o=vd(t,r);if(o.length!==1)return null;let n=o[0]??bd(t)?.id??null;if(!n)return null;let i=Sd(e,n);return!i||typeof i.id!="string"||i.id.length===0?null:{id:i.id,item:i}}function es(e,t,r){if(!t||typeof t!="object"||typeof t.clientX!="number"||typeof t.clientY!="number")return null;let o=V(e);return o?Bd(r,o.browserViewport.entitiesAtPoint(t)):null}import{listProjectionSelectionRects as sf,resolveProjectionCaretRect as lf}from"@datalking/begonia-page-layout";import{isDenseArray as af}from"@datalking/begonia-document-model";import{DELETION_MARK_NAME as Dd,INSERTION_MARK_NAME as Hd,semanticNodeText as Fd}from"@datalking/begonia-engine";import{pmPositionToAddressableTextOffset as yd,readAddressableText as Pd,resolveAddressableTextOffsetPosition as Cd,resolveAddressableTextOffsetRange as xd,resolveCollapsedAddressableTextOffsetPosition as Ed}from"@datalking/begonia-document-model";function Lt(e){return{includeDeletedText:!0,...e}}function Ne(e,t={}){return Pd(e,Lt(t))}function F(e,t,r,o={}){return yd(e,t,r,Lt(o))}function ne(e,t,r,o="end",n={}){return Cd(e,t,r,o,Lt(n))}function ts(e,t,r,o,n={}){return xd(e,t,r,o,Lt(n))}function lt(e,t,r,o={}){return Ed(e,t,r,Lt(o))}import{createDocumentNoteAwareTextOffsetOptions as kd}from"@datalking/begonia-doc-service/v1";function T(e,t={}){return kd(e,t)}import{readSyntheticSideStoryDocOriginPath as Td}from"@datalking/begonia-doc-service/v1";import{isDocumentNodePath as Do,isDocumentNodePathIndex as Ho}from"@datalking/begonia-document-model";function Lo(e){return Ho(e)}function Id(e){let t=e[0];return t===-101||t===-102||t===-211||t===-212?e.length>=2&&Lo(e[1])&&Do(e.slice(2))?e.slice(2):null:(t===-201||t===-202)&&e.length>=3&&Lo(e[1])&&Lo(e[2])&&Do(e.slice(3))?e.slice(3):null}function Rd(e,t){return e.length>=t.length&&t.every((r,o)=>e[o]===r)}function Md(e,t){let r=e,o=-1;for(let n of t){if(!Ho(n)||n>=r.childCount)return null;o+=1;for(let i=0;i<n;i+=1)o+=r.child(i).nodeSize;r=r.child(n)}return{node:r,position:o}}function Dt(e,t){if(!Array.isArray(t))return null;if(t.length===0)return[];if(Do(t))return[...t];let r=Id(t);if(!r)return null;let o=Td(e);return o&&Rd(t,o)?r:null}function at(e,t){let r=Dt(e,t);if(!r)return null;if(r.length===0)return 0;let o=0,n=e;for(let i of r){if(!Ho(i)||i>=n.childCount)return null;o+=1;for(let s=0;s<i;s+=1)o+=n.child(s).nodeSize;n=n.child(i)}return o}function J(e,t){let r=Dt(e,t);return r?Md(e,r):null}function rs(e){return typeof e=="number"?Math.max(0,e):null}import{hasVisibleSemanticContent as Nd,semanticNodeText as Ad}from"@datalking/begonia-document-model";var Od=new Set(["structural_revision_carrier","bookmark_anchor","bookmark_end","comment_anchor","comment_range_start","comment_range_end","permission_range_start","permission_range_end"]);function Vd(e){if(Od.has(e.type.name))return"";let t=Ad(e);return t.length>0?t:Nd(e)?"":""}function Ld(e,t,r){let o=Math.min(t,r),n=Math.max(t,r),i=e.textBetween(o,n,"",Vd);if(i.length===0)return!0;if(i.trim().length>0)return!1;let s=e.resolve(o),l=e.resolve(n);for(let a=Math.min(s.depth,l.depth);a>=0;a-=1)if(s.node(a)===l.node(a)&&s.node(a).isTextblock)return!0;return!1}function Ht(e,t,r={}){if(t.length===0)return null;let o=t[0],n=o;for(let i of t.slice(1)){if(i.from<n.from||i.from===n.from&&i.to<n.to||i.from<o.to)return null;if(i.from===o.to||Ld(e,o.to,i.from)){o={from:o.from,to:Math.max(o.to,i.to)},n=i;continue}return r.strict?null:o}return o}function jd(e){return e.startPath?e.startPath:e.segments?.find(t=>t.kind==="range")?.startPath??null}function zd(e){if(e.endPath)return e.endPath;for(let t=(e.segments?.length??0)-1;t>=0;t-=1){let r=e.segments?.[t];if(r?.kind==="range"&&r.endPath)return r.endPath}return null}function qd(e){return e.anchorPath?e.anchorPath:e.segments?.find(t=>t.kind==="anchor")?.anchorPath??null}function _d(e,t){let r=e,o=J(r,t),n=o?.node.type.name==="comment_anchor"?o.position:at(r,t);return rs(n)}function Er(e){return e.marks.some(t=>t.type.name===Hd||t.type.name===Dd)}function Kd(e,t,r){let o=!1;return e.nodesBetween(t,r,(n,i)=>{if(o)return!1;if(!(n.isText||n.isInline&&n.isLeaf&&Fd(n).length>0))return!0;let l=Math.max(t,i);return Math.min(r,i+n.nodeSize)<=l?!1:(o=Er(n),!o)}),o}function os(e,t){let r=e,o=J(r,t);return o?o.node.type.name!=="comment_range_start"?at(r,t):Er(o.node)?at(r,t):o.position:null}function Ud(e,t,r={}){if(t?.kind!=="range"||!t.startPath||!t.endPath)return null;let o=e,n=os(e,t.startPath),i=at(o,t.endPath);if(typeof n!="number"||typeof i!="number"||n>i)return null;let s={from:n,to:i},l=Kd(e,s.from,s.to),a=r.allowTrackedContentFallback??!0,c=T(o,{blockSeparator:`
|
|
2
|
+
`}),u=t.addressableBlockPath??t.blockPath??null,d=u?J(o,u):null,m=d?.node??null,f=t.text;if(!d||!m?.isBlock||typeof f!="string"||f.length===0)return s;let g=Ne(m,c),p=F(m,d.position,s.from,c),b=Math.max(p,F(m,d.position,s.to,c)),w=g.slice(p,b);if(w===f)return s;let y=w.indexOf(f);if(y<0||w.indexOf(f,y+1)>=0)return l&&!a?null:s;let x=p+y,E=x+f.length,O=ne(m,d.position,x,"start",c),k=ne(m,d.position,E,"end",c),Y=J(o,t.startPath)?.node??null,j=J(o,t.endPath)?.node??null,q=y===0&&!(l&&Y?.type.name==="comment_range_start"&&!Er(Y)),W=E===b&&!(l&&j?.type.name==="comment_range_end"&&!Er(j)),re=q?s.from:O,I=W?s.to:k;return typeof re!="number"||typeof I!="number"||I<=re?l&&!a?null:s:{from:Math.min(re,I),to:Math.max(re,I)}}function Wd(e){return e!=null}function Xd(e,t){let r=e,o=t.segments??[],n=t.source==="live",i=o.map(l=>Ud(e,l,{allowTrackedContentFallback:n}));if(o.length>0&&!n&&i.some(l=>l==null))return null;let s=i.filter(Wd);if(s.length===0){let l=jd(t),a=zd(t);if(!l||!a)return null;let c=os(e,l),u=at(r,a);return typeof c!="number"||typeof u!="number"?null:{from:Math.min(c,u),to:Math.max(c,u)}}return Ht(r,s,{strict:!n})}function We(e,t){if(!t)return null;if(t.targetKind==="range")return Xd(e,t);let r=qd(t);if(!r)return null;let o=_d(e,r);return typeof o!="number"?null:{from:o,to:o}}import{readSyntheticSideStoryDocContext as Zd,resolveSyntheticSideStoryPathPosition as Jd}from"@datalking/begonia-doc-service/v1";import{isDocumentNodePathIndex as Qd}from"@datalking/begonia-document-model";import{resolveAddressableBlockIdPath as Gd}from"@datalking/begonia-doc-service/v1";import{parseAddressableBlockId as Yd}from"@datalking/begonia-doc-service/structure";function ns(e){return e==="paragraph"||e==="heading"}function $d(e){return{readDocument(){return e},readNode(t){return J(e,t)?.node??null}}}function Ft(e,t){let r=Gd($d(e),t),o=Dt(e,r);if(o)return o;let n=Yd(t);if(!n?.path.length||!ns(n.nodeType))return null;let i=Dt(e,n.path),s=i?J(e,i)?.node??null:null;return s?.isBlock&&ns(s.type.name)?[...i]:null}import{parseAddressableBlockId as em}from"@datalking/begonia-doc-service/structure";function tm(e){return{schema:e.type.schema,port:{replaceDocument(){}},readDocument(){return e}}}function is(e,t){let r=e,o=-1;for(let n of t){if(!Qd(n)||n>=r.childCount)return null;o+=1;for(let i=0;i<n;i+=1)o+=r.child(i).nodeSize;r=r.child(n)}return{node:r,position:o}}function rm(e,t){let r=is(e,t);return r?.node.isBlock?{path:[...t],localPath:[...t],document:e,position:r.position,node:r.node,syntheticRootPath:null,positionRoot:null}:null}function om(e,t){let r=Zd(tm(e),t);if(!r)return null;let o=r.localizePath(t),n=r.globalizePath([]),i=Jd(e.type.schema,e,n),s=o?is(r.doc,o):null;return o&&s?.node.isBlock&&typeof i=="number"?{path:[...t],localPath:[...o],document:r.doc,position:s.position,node:s.node,syntheticRootPath:n,positionRoot:i}:null}function kr(e,t){let r=Ft(e,t);if(r)return rm(e,r);let o=em(t);return o?.path.some(n=>n<0)?om(e,o.path):null}function Fo(e,t){return e.syntheticRootPath&&typeof e.positionRoot=="number"?t-e.positionRoot:t}import{resolveDocumentStoryLocatorFromPath as nm}from"@datalking/begonia-doc-service/v1";import{addressableBlockTypeForNodeType as im,formatAddressableBlockId as sm,formatAddressableBlockIdWithLogicalId as lm}from"@datalking/begonia-doc-service/structure";function jo(e){return typeof e=="string"&&e.trim().length>0?e.trim():null}function jt(e,t){return e==="listItem"?jo(t.attrs?.listItemId):e==="paragraph"||e==="heading"?jo(t.attrs?.paraId)??jo(t.attrs?.sdBlockId):null}function am(e,t){return{kind:"text",segments:[{blockId:e,range:{start:0,end:0}}],...t?{story:t}:{}}}function cm(e,t,r){return r?structuredClone(r):nm({listSections:()=>e.sections?.list?.()??[],listFootnotes:()=>e.notes?.footnotes?.list?.()??e.notes?.list?.()??[],listEndnotes:()=>e.notes?.endnotes?.list?.()??[],listHeaderFooterParts:()=>e.headerFooters?.parts?.list?.()?.items??[]},t)}function Tr(e,t,r){if(!e||!Array.isArray(t)||t.length===0)return null;let o=e.blocks.read(t);if(!o)return null;let n=im(o.type.name);if(!n)return null;let i=jt(n,o),s=i?lm(n,t,i):sm(n,t);return am(s,cm(e,t,r)??void 0)}function zt(e){return typeof e=="number"&&Number.isFinite(e)&&e>=0?Math.trunc(e):null}function um(e,t){return JSON.stringify(e??null)===JSON.stringify(t??null)}function ss(e,t){return!Array.isArray(t)||t.length===0?null:Tr(e,t)}function dm(e,t){let r=Math.max(0,typeof e.text=="string"?e.text.length:typeof t.text=="string"?t.text.length:0),o=zt(e.startOffset)??zt(t.startOffset)??0,n=zt(e.endOffset)??zt(t.endOffset)??(r>0?o+r:o);return{start:o,end:Math.max(o,n)}}function mm(e){let t=e.segments?.filter(r=>r.kind==="range")??[];return t.length>0?t:[{kind:"range",startPath:null,endPath:null,anchorPath:null,blockPath:e.blockPath??null,addressableBlockPath:e.addressableBlockPath??null,startOffset:e.startOffset??null,endOffset:e.endOffset??null,text:e.text}]}function fm(e){let t=e.segments?.find(r=>r.kind==="anchor");return t?.addressableBlockPath??t?.blockPath??e.addressableBlockPath??e.blockPath??null}function Ir(e,t){if(!e||!t)return null;if(t.targetKind==="range"){let n=[],i;for(let s of mm(t)){let l=s.addressableBlockPath??s.blockPath??null,a=ss(e,l);if(!a)return null;if(i===void 0)i=a.story;else if(!um(i,a.story))return null;n.push({blockId:a.segments[0].blockId,range:dm(s,t)})}return n.length>0?{kind:"text",segments:n,...i?{story:i}:{}}:null}let r=ss(e,fm(t));if(!r)return null;let o=zt(t.anchorOffset)??0;return{kind:"text",segments:[{blockId:r.segments[0].blockId,range:{start:o,end:o}}],...r.story?{story:r.story}:{}}}import{isIntegerPath as pm}from"@datalking/begonia-document-model";var wm=Object.freeze({blockSeparator:`
|
|
3
|
+
`});function ct(e){return typeof e=="number"&&Number.isFinite(e)}function gm(e){return Array.isArray(e)&&e.length>0&&pm(e)}function hm(e){return!!e&&typeof e=="object"&&gm(e.blockPath)}function bm(e){let t=s=>[s.blockPath.join("."),ct(s.from)?Math.min(s.from,s.to??s.from):"",ct(s.to)?Math.max(s.from??s.to,s.to):""].join(":"),r=[e?.target??null,...e?.targets??[]].filter(hm),o=s=>ct(s.from)&&ct(s.to)?0:1,n=s=>o(s)===0?Math.min(s.from,s.to):Number.POSITIVE_INFINITY,i=s=>o(s)===0?Math.max(s.from,s.to):Number.POSITIVE_INFINITY;return r.map((s,l)=>({target:s,index:l})).sort((s,l)=>o(s.target)-o(l.target)||n(s.target)-n(l.target)||i(s.target)-i(l.target)||s.index-l.index).reduce((s,l)=>{let a=t(l.target);return s.some(c=>t(c)===a)||s.push(l.target),s},[])}function ls(e,t,r){return Math.min(Math.max(e,t),r)}function vm(e,t,r){if(!e||!ct(r.from)||!ct(r.to))return null;let o=kr(e,t);if(!o)return null;let n=o.position+1,i=Math.max(n,o.position+o.node.nodeSize-1),s=Fo(o,Math.min(r.from,r.to)),l=Fo(o,Math.max(r.from,r.to)),a=ls(s,n,i),c=ls(l,a,i),u=T(o.document,wm),d=F(o.node,o.position,a,u),m=F(o.node,o.position,c,u);return{start:Math.min(d,m),end:Math.max(d,m)}}function zo(e,t,r){if(!e||!r)return{target:null,selectionTarget:null};let o=null,n=null;for(let i of bm(r)){let s=Tr(e,i.blockPath,r.story);if(!s)continue;let l=s.segments[0]?.blockId;if(!l)continue;n||(o=i,n={kind:"text",segments:[{blockId:l,range:{start:0,end:0}}],...s.story?{story:s.story}:{}});let a=vm(t,l,i);if(a)return{target:i,selectionTarget:{kind:"text",segments:[{blockId:l,range:a}],...s.story?{story:s.story}:{}}}}return{target:o,selectionTarget:n}}function Rr(e,t,r){return zo(e,t,r).selectionTarget}import{isDocumentStoryLocator as Xm,readSyntheticSideStoryDocStoryLocator as Gm,sameDocumentStoryLocator as Ym}from"@datalking/begonia-doc-service/v1";import{readSyntheticSideStoryDocOriginPath as $y}from"@datalking/begonia-doc-service/v1";import{cloneSelectionTextRange as Sm}from"@datalking/begonia-document-api/core";import{sameDocumentStoryLocator as as}from"@datalking/begonia-doc-service/v1";function qo(e,t){return{kind:"text",segments:t.map(r=>({blockId:r.blockId,range:Sm(r.range)})),...e.story?{story:structuredClone(e.story)}:{}}}function Mr(e){return qo(e,e.segments)}function cs(e,t){return!e||!t||e.segments.length!==t.segments.length||(e.story||t.story)&&!as(e.story,t.story)?!1:e.segments.every((r,o)=>{let n=t.segments[o];return n?.blockId===r.blockId&&n.range.start===r.range.start&&n.range.end===r.range.end&&n.range.startAffinity===r.range.startAffinity&&n.range.endAffinity===r.range.endAffinity})}function us(e,t){return!e||!t||e.segments.length!==t.segments.length||(e.story||t.story)&&!as(e.story,t.story)?!1:e.segments.every((r,o)=>{let n=t.segments[o];return!!(n&&r.blockId===n.blockId&&r.range.start===r.range.end&&r.range.start>=n.range.start&&r.range.end<=n.range.end)})}function ut(e,t){return!e||!t?e===t:e.nodeType!==t.nodeType?!1:e.stableIdentity!=null&&t.stableIdentity!=null?e.stableIdentity===t.stableIdentity&&(e.nodeFingerprint==null||t.nodeFingerprint==null||e.nodeFingerprint===t.nodeFingerprint):e.path.length===t.path.length&&e.path.every((r,o)=>r===t.path[o])}import{canonicalizeRevisionIds as ym,normalizeRevisionIds as _o,selectionOverlapsRevisionRange as Pm}from"@datalking/begonia-engine";import{orderOverlapRevisionIds as Bm}from"@datalking/begonia-engine";function qt(e,t){return Bm(e,t)}function Cm(e){if("from"in e)return{from:e.from,to:e.to};let{anchor:t,head:r}=e.range.range;return t.story.storyType!=="body"||r.story.storyType!=="body"||t.path.length>0||r.path.length>0?null:{from:Math.min(t.offset,r.offset),to:Math.max(t.offset,r.offset)}}function xm(e,t){return t.length>0?ym(e,t):[]}function X(e,t){let r=_o(e);return t&&t.length>0?xm(r,t):r}function Em(e){return e==="paragraph"||e==="heading"}function km(e){return(e.target?.nodeType==="bookmark_anchor"||e.target?.nodeType==="structural_revision_carrier")&&Em(e.target.blockType)&&e.target.blockPath.length>0&&(e.text??"").trim().length===0}function Tm(e,t){let r=Cm(e);return r?qt(_o(t.filter(o=>Pm(r.from,r.to,o)).map(o=>o.id)),t):[]}function ae(e){return _o(e)}function ds(e,t){let r=ae(e),o=ae(t);return r.length===o.length&&r.every((n,i)=>n===o[i])}function _t(e,t){let r=X(e.trackedChangeIds,t),o=Tm(e,t),n=new Set(t.filter(km).map(l=>l.id));if(o.length===0)return r;if(r.length===0)return o;let i=new Set(o),s=qt(r.filter(l=>i.has(l)||n.has(l)),t);return s.length>0?s:o}function Nr(e,t){let r=_t(e,t),o=e.trackedChangeIds??[];return e.trackedChangeIds!=null&&r.length===o.length&&r.every((n,i)=>n===o[i])?e:{...e,trackedChangeIds:r}}function Ar(e,t,r){let o=e.activeChangeIds??[],n=_t("from"in t?{from:t.from,to:t.to,trackedChangeIds:o}:{range:t.range,trackedChangeIds:o},r);return e.activeChangeIds!=null&&n.length===o.length&&n.every((i,s)=>i===o[s])?e:{...e,activeChangeIds:n}}function Im(e,t){return e.length===t.length&&e.every((r,o)=>r===t[o])}function dt(e,t=[]){return X([...e?.activeChangeIds??[],...e?.selection.trackedChangeIds??[]],t)}function Ko(e,t,r=[]){if(!e||!t)return e===t;let o=Im(dt(e,r),dt(t,r));return e.selectionKind!==t.selectionKind||e.projectedMode!==t.projectedMode||e.selection.empty!==t.selection.empty||!o?!1:e.selectionKind==="node"||t.selectionKind==="node"?ut(e.nodeSelectionTarget,t.nodeSelectionTarget):e.selectionTarget||t.selectionTarget?cs(e.selectionTarget,t.selectionTarget):e.selection.from!==t.selection.from||e.selection.to!==t.selection.to?!1:e.text==null||t.text==null||e.text===t.text}import{createDocumentScopedMemo as Rm}from"@datalking/begonia-engine";function Mm(e){let t=2166136261;for(let r=0;r<e.length;r+=1)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}function Nm(e){try{return Mm(JSON.stringify(e.toJSON()))}catch{return null}}var ky=Rm({compute:(e,t)=>Nm(e)});import{projectAcceptedTextBetween as jm}from"@datalking/begonia-engine";import{semanticNodeText as Om}from"@datalking/begonia-document-model";import{isRevisionMarkHiddenInProjection as Ry,isRevisionNodeHiddenInProjection as Am}from"@datalking/begonia-engine";function ms(e,t,r=!1){return Am(e,t,r)}function Vm(e,t){return ms(e,"final",t)}function ps(e,t){let r=Om(e),o=t?.resolveLeafText?.(e,r);return typeof o=="string"?o:r}function Lm(e,t,r){return r?"":ps(e,t)}function Dm(e,t){return t?"":e.text??""}function fs(e,t){return e.isText?(e.text??"").length:e.childCount===0?ps(e,t).length:0}function Hm(e,t,r,o,n,i,s){if(o.length===0)return r;t.push(o);let l=r+o.length;return e.push({atomic:s,text:o,startOffset:n,endOffset:i,visibleStart:r,visibleEnd:l}),l}function Uo(e,t){let r=[],o=[],n=t?.blockSeparator??"",i=0,s=0,l=(c,u,d=!1)=>{let m=i,f=m+u;s=Hm(r,o,s,c,m,f,d),i=f},a=(c,u=!1)=>{let d=Vm(c,u);if(c.isText){let f=fs(c,t);l(Dm(c,d),f);return}if(c.childCount===0){let f=fs(c,t);l(Lm(c,t,d),f,!0);return}let m=!0;c.forEach(f=>{f.isBlock&&!m&&n.length>0&&l(n,n.length),a(f,d&&c.isInline),m=!1})};return a(e),{runs:r,text:o.join(""),maxOffset:i}}function Fm(e,t,r,o){if(!Number.isInteger(r))return 0;if(r<=0)return o==="start"?e[0]?.startOffset??0:0;for(let[n,i]of e.entries()){if(r<i.visibleStart)return i.startOffset;if(r>i.visibleEnd)continue;if(r===i.visibleEnd){let a=e[n+1];return o==="start"&&a&&a.visibleStart===r?a.startOffset:i.endOffset}let s=i.visibleEnd-i.visibleStart,l=i.endOffset-i.startOffset;return i.atomic?o==="end"&&r>i.visibleStart?i.endOffset:i.startOffset:l===s?i.startOffset+(r-i.visibleStart):o==="end"&&r>i.visibleStart?i.endOffset:i.startOffset}return t}function Or(e,t={}){let{text:r,maxOffset:o}=Uo(e,t);return{text:r,maxOffset:o}}function mt(e,t,r="end",o={}){let{runs:n,text:i,maxOffset:s}=Uo(e,o);return!Number.isInteger(t)||t<0||t>i.length?null:Fm(n,s,t,r)}function ft(e,t,r="end",o={}){let{runs:n}=Uo(e,o);if(!Number.isInteger(t)||t<=0)return 0;let i=0;for(let s of n){if(t<=s.startOffset)return i;if(t<=s.endOffset)return s.atomic&&t<s.endOffset?r==="end"?s.visibleEnd:s.visibleStart:s.visibleStart+(t-s.startOffset);i=s.visibleEnd}return i}var zm=Object.freeze({blockSeparator:" "});function qm(e){return e.empty??e.from===e.to}function _m(e,t){let r=Math.max(0,e.content.size),o=Math.min(r,Math.max(0,Math.min(t.from,t.to))),n=Math.min(r,Math.max(o,Math.max(t.from,t.to))),i=T(e,zm),s=[],l=!1;return e.nodesBetween(o,n,(a,c)=>{if(!a.isTextblock)return!0;l=!0;let u=Math.max(o,c+1),d=Math.min(n,c+a.nodeSize-1),m=F(a,c,u,i),f=Math.max(m,F(a,c,d,i)),g=Or(a,i),p=ft(a,m,"start",i),b=ft(a,f,"end",i);return s.push(g.text.slice(Math.min(p,b),Math.max(p,b))),!1}),l?s.join(" "):null}function ge(e,t,r){return qm(r)?"":_m(e,r)??jm(e,t,Math.min(r.from,r.to),Math.max(r.from,r.to)," ")}import{NodeSelection as Km}from"prosemirror-state";function R(e){return e instanceof Km||typeof e=="object"&&e!=null&&"node"in e&&e.node!=null&&"from"in e&&typeof e.from=="number"&&"to"in e&&typeof e.to=="number"&&"$from"in e&&e.$from!=null}import{NodeSelection as gs,TextSelection as Vr}from"prosemirror-state";function ws(e,t,r){try{return e.resolve(t).parent.inlineContent&&e.resolve(r).parent.inlineContent}catch{return!1}}function hs(e){return typeof e=="object"&&e!=null&&"parent"in e&&typeof e.parent=="object"&&e.parent!=null&&"inlineContent"in e.parent&&e.parent.inlineContent===!0}function Xe(e,t){return Math.max(1,Math.min(t,e.content.size))}function Lr(e,t){return Math.max(0,Math.min(t,e.content.size))}function M(e,t,r=t){let o=Xe(e.doc,t),n=Xe(e.doc,r),i=Math.min(o,n),s=Math.max(o,n),l=bs(e),a=c=>{if(!Ge(c))return null;if(l&&typeof c.toJSON=="function")try{let u=l.fromJSON(e.doc,c.toJSON());return Ge(u)?u:null}catch{}return c};if(ws(e.doc,i,s))try{return a(Vr.create(e.doc,o,n))}catch{}try{return a(Vr.between(e.doc.resolve(o),e.doc.resolve(n),n>=o?1:-1))}catch{if(o!==n)return null}try{return a(Vr.near(e.doc.resolve(o),n>=o?1:-1))}catch{return null}}function Ge(e){return e instanceof Vr||typeof e=="object"&&e!=null&&!("$anchorCell"in e)&&!("node"in e&&e.node!=null)&&"anchor"in e&&typeof e.anchor=="number"&&"head"in e&&typeof e.head=="number"&&"empty"in e&&typeof e.empty=="boolean"&&"$anchor"in e&&"$head"in e&&hs(e.$anchor)&&hs(e.$head)}function Dr(e,t){let r=R(e),o=R(t);if(r!==o||e.from!==t.from||e.to!==t.to||e.empty!==t.empty)return!1;let n=Ge(e),i=Ge(t);return!n&&!i?!0:n&&i&&e.anchor===t.anchor&&e.head===t.head}function bs(e){let t=e.selection.constructor,r=typeof t=="function"?Object.getPrototypeOf(t):null;return r&&typeof r.fromJSON=="function"?r:null}function Um(e,t){return Ge(e)?Ge(t)?t:null:R(e)?R(t)?t:null:t}function pt(e,t){let r=bs(e);if(r&&typeof t.toJSON=="function")try{return Um(t,r.fromJSON(e.doc,t.toJSON()))}catch{}if(R(t)){let o=Lr(e.doc,Math.min(t.from,t.to)),n=e.doc.nodeAt(o);if(!n||!gs.isSelectable(n))return null;try{return gs.create(e.doc,o)}catch{return null}}return Ge(t)?M(e,t.anchor,t.head):t}var rP=Object.freeze({success:!0}),oP=Object.freeze({success:!1,reason:"read-only"});function Kt(e,t,r={}){try{let o=pt(e.view.state,t);return o?(e.view.dispatch(e.view.state.tr.setSelection(o).scrollIntoView()),r.focus!==!1&&e.focus(),!0):!1}catch{return!1}}import{parseAddressableBlockId as Wm}from"@datalking/begonia-doc-service/structure";function wt(e){return Wm(e)?.logicalId==null}var Hr=Object.freeze({blockSeparator:`
|
|
4
|
+
`});function Wo(e,t){if(t.story===void 0)return!0;if(!Xm(t.story))return!1;let r=Gm(e)??{kind:"story",storyType:"body"};return Ym(r,t.story)}function $m(e,t,r,o,n){let i=T(e,Hr),s=mt(t,o,n,i);return s==null?null:ne(t,r,s,n,i)}function Zm(e,t,r,o,n){let i=T(e,Hr),s=mt(t,o,"start",i),l=mt(t,n,"end",i);if(s==null||l==null)return null;let a=ne(t,r,Math.min(s,l),"start",i),c=ne(t,r,Math.max(s,l),"end",i);return typeof a=="number"&&typeof c=="number"?{from:Math.min(a,c),to:Math.max(a,c)}:null}function Jm(e,t,r,o,n){let i=ne(e,t,r,"start",n),s=ne(e,t,o,"end",n);return typeof i=="number"&&typeof s=="number"?{from:Math.min(i,s),to:Math.max(i,s)}:null}function Qm(e,t){return t.collapsedAcceptedVisibleBias==="hidden-anchor"||e.range.start===0?"end":"start"}function ef(e,t,r={}){let o=Ft(e,t.blockId);if(!o)return null;let n=J(e,o);if(!n?.node.isBlock)return null;let i=T(e,Hr);if(wt(t.blockId)){if(t.range.start===t.range.end){let a=$m(e,n.node,n.position,t.range.start,Qm(t,r));return typeof a=="number"?{from:a,to:a}:null}let l=Zm(e,n.node,n.position,t.range.start,t.range.end);return l||null}if(t.range.start===t.range.end){let l=lt(n.node,n.position,t.range.start,i);return typeof l=="number"?{from:l,to:l}:null}if(r.strict)return Jm(n.node,n.position,t.range.start,t.range.end,i);let s=ts(n.node,n.position,t.range.start,t.range.end,i);return s||null}function tf(e,t){return ge(e,e.type.schema,t)}function rf(e,t){let r=e.indexOf(t);return r<0||e.indexOf(t,r+1)>=0?null:{start:r,end:r+t.length}}function of(e,t,r){if(!Wo(e,t)||t.segments.length!==1||r.length===0)return null;let[o]=t.segments,n=Ft(e,o.blockId);if(!n)return null;let i=J(e,n);if(!i?.node.isBlock)return null;let s=T(e,Hr),l=Or(i.node,s),a=rf(l.text,r);if(!a)return null;let c=mt(i.node,a.start,"start",s),u=mt(i.node,a.end,"end",s);if(c==null||u==null)return null;let d=ne(i.node,i.position,c,"start",s),m=ne(i.node,i.position,u,"end",s);return typeof d!="number"||typeof m!="number"?null:{selection:{from:Math.min(d,m),to:Math.max(d,m)},target:qo(t,[{blockId:o.blockId,range:{start:wt(o.blockId)?Math.min(a.start,a.end):Math.min(c,u),end:wt(o.blockId)?Math.max(a.start,a.end):Math.max(c,u)}}])}}function nf(e,t,r){return of(e,t,r)?.selection??null}function Ut(e,t,r={}){if(!t||!Wo(e,t))return null;let o=[];for(let n of t.segments){let i=ef(e,n,r);if(!i)return null;o.push(i)}return Ht(e,o,r)}function Wt(e,t,r,o={}){let n=Ut(e,t,o);return n&&(typeof r!="string"||r.length===0||tf(e,n)===r)?n:!t||typeof r!="string"||r.length===0?null:nf(e,t,r)}function Xo(e,t,r,o={}){if(!t||!Wo(e,t)||!r||r.length!==t.segments.length)return null;let n=[];for(let[i,s]of t.segments.entries()){let l=Wt(e,{kind:"text",segments:[s]},r[i]??null,{...o,strict:!0});if(!l)return null;n.push(l)}return Ht(e,n,o)}function vs(e,t){let r=e.view;if(!r?.state||typeof r.dispatch!="function")return!1;let o=Ut(r.state.doc,t,{strict:!0});if(!o)return!1;let n=M(r.state,o.from,o.to);return n?Kt(e,n):!1}function Q(e){return typeof e?.readLayoutSource=="function"?e.readLayoutSource():null}function Ss(e,t){if(e===t)return!0;if(e==null||t==null)return!1;let r=e,o=t;return r.type!==o.type?!1:typeof r.eq=="function"&&r.eq(o)===!0}function Ce(e){return e?.getResolvedProjection?.()??null}function ce(e){return e?.getResolvedProjectionGeometryOptions?.()??null}function Bs(e){return e?.getPointerCaretOrigin?.()??null}function ue(e){return{success:!1,reason:e}}function cf(e){return!e||typeof e!="object"?!1:!!e&&"kind"in e&&e.kind==="text"&&af(e.segments)}function ys(e){return typeof e=="number"&&Number.isFinite(e)}function uf(e){return!e||e.segments.length===0?!1:e.segments.every(t=>typeof t?.blockId=="string"&&t.blockId.trim().length>0&&ys(t.range?.start)&&ys(t.range?.end))}function df(e){return!e||typeof e!="object"?!1:!!e&&"type"in e&&"id"in e&&typeof e.id=="string"}function mf(e){return e?typeof e.id=="string"&&e.id.trim().length>0:!1}function Go(e){return!e||typeof e!="object"?!1:!!e&&"type"in e&&"childCount"in e&&"nodesBetween"in e&&typeof e.nodesBetween=="function"}function Ps(e,t){return typeof e!="number"||!Number.isFinite(e)||typeof t!="number"||!Number.isFinite(t)?null:{from:Math.min(e,t),to:Math.max(e,t)}}function ff(e){return{pageIndex:e.pageIndex,pageNumber:e.pageNumber,sectionId:e.sectionId??null,region:e.region,blockIndex:e.blockIndex,fragmentIndex:e.fragmentIndex,columnIndex:e.columnIndex,lineIndex:e.lineIndex,lineCount:e.lineCount,left:e.left,top:e.top,width:e.width,height:e.height}}function pf(e){return{pageIndex:e.pageIndex,pageNumber:e.pageNumber,sectionId:e.sectionId??null,region:e.region,blockIndex:e.blockIndex,fragmentIndex:e.fragmentIndex,columnIndex:e.columnIndex,lineIndex:e.lineIndex,lineCount:e.lineCount,left:e.left,top:e.top,width:1,height:e.height}}function wf(e){return[e.pageIndex,e.pageNumber,e.sectionId??"",e.region,e.blockIndex,e.fragmentIndex,e.columnIndex,e.lineIndex,e.lineCount,e.left,e.top,e.width,e.height].join(":")}function gf(e){let t=[],r=new Set;for(let o of e){let n=wf(o);r.has(n)||(r.add(n),t.push(o))}return t}function hf(e,t){let r=Ce(e),o=ce(e)??{};if(!r)return[];if(t.from===t.to){let n=lf(r,t.from,o);return n?[pf(n)]:[]}return sf(r,t.from,t.to,o).map(ff)}function Yo(e,t){if(t.segments.length===0)return null;let r=[];for(let o of t.segments){let n=vf(e,o);if(!n)return null;r.push(n)}return r}function bf(e,t){return e.syntheticRootPath&&typeof e.positionRoot=="number"?{from:e.positionRoot+t.from,to:e.positionRoot+t.to}:t}function vf(e,t){let r={kind:"text",segments:[t]},o=Ut(e,r,{strict:!0});if(o)return o;let n=kr(e,t.blockId);if(!n||n.document===e)return null;let i=Ut(n.document,r,{strict:!0});return i?bf(n,i):null}function Sf(e){if(!e)return[];let t=(e.segments??[]).map(o=>Ps(o.from,o.to)).filter(o=>o!=null).sort((o,n)=>o.from-n.from||o.to-n.to);if(t.length>0)return t;let r=Ps(e.from,e.to);return r?[r]:[]}function Bf(e,t,r){if(!r||typeof t?.blocks?.read!="function")return null;let o=Rr(t,e,r);return o?Yo(e,o):null}function yf(e,t="unresolved"){let[r]=e;return r?{success:!0,rect:r,rects:[...e],pageIndex:r.pageIndex,pageNumber:r.pageNumber}:ue(t)}function Xt(e,t){let r=gf(t.flatMap(o=>hf(e,o)));return yf(r,t.length>0?"not-mounted":"unresolved")}function gt(e,t){let r=e.preview??null;if(!r||!Ce(r))return ue("not-ready");let o=t.target??null;if(!o)return ue("invalid-target");if(cf(o)){if(!uf(o))return ue("invalid-target");let n=Q(r);if(!Go(n))return ue("not-ready");let i=Yo(n,o);return i?Xt(r,i):ue("unresolved")}if(!df(o)||!mf(o))return ue("invalid-target");if(o.type==="comment"){let n=Q(r);if(!Go(n))return ue("not-ready");let i=e.documentApi?.comments.target(o.id)??null,s=Ir(e.documentApi,i),l=s?Yo(n,s):null;if(l)return Xt(r,l);let a=We(n,i);return a?Xt(r,[a]):ue("unresolved")}if(o.type==="trackedChange"){let n=e.documentApi?.trackChanges.get(o.id)??null,i=Q(r),s=Go(i)?Bf(i,e.documentApi,n):null;if(s)return Xt(r,s);let l=Sf(n);return l.length===0?ue("unresolved"):Xt(r,l)}return ue("invalid-target")}var Pf=Object.freeze([]),Cf=[],xf=Object.freeze({});function $o(e){let t=e?.items??Cf,r=e?.permissions??xf;return{items:t,permissions:r,total:typeof e?.total=="number"&&Number.isFinite(e.total)?Math.max(0,Math.trunc(e.total)):t.length,activeCommentId:e?.activeCommentId??null,activeCommentIds:e?.activeCommentIds??Pf,enabled:e?.enabled??!1,visible:e?.visible??!1,readOnly:e?.readOnly??!1,showResolved:e?.showResolved??!1,visibility:e?.visibility??null}}function Cs(e){return structuredClone(e)}function Zo(e){return $o(e?e.session.readState()?.comments??null:null)}function xs(e,t){return Ue(typeof t=="string"?[t]:[],oe(Zo(e).items))[0]??null}function Jo(e,t){let r=xr(),o=()=>Cs($o(t.getSnapshot())),n=i=>t.subscribe(s=>{i(Cs($o(s)))});return{getSnapshot:o,subscribe:n,observe(i){return n(i)},create(i,s){return e.commentActions.createComment(i,s)},reply(i,s,l=null){return e.commentActions.replyComment(i,s,l)},setInternal(i,s){return e.commentActions.setCommentInternal(i,s)},resolve(i){return e.commentActions.resolveComment(i)},reopen(i){return e.commentActions.reopenComment(i)},setActive(i){return r.invalidate(),e.commentFocus.setActiveComment(i)},reveal(i){r.invalidate();let s=Zo(e).activeCommentId??null,l=typeof i=="string"?xs(e,i):null;l&&e.commentFocus.setActiveComment(l);let a=Oo(e,i);return!a.selected&&l&&e.commentFocus.setActiveComment(s),a},async scrollTo(i,s){let l=r.begin(),a=Zo(e).activeCommentId??null,c=typeof i=="string"?xs(e,i):null;c&&e.commentFocus.setActiveComment(c);let u=await Vo(e,i,s,{continuation:l});return l.shouldContinue()?(!u.success&&c&&e.commentFocus.setActiveComment(a),u):{success:!1}},getAt(i){return es(e,i,o().items)},getRect({id:i}){return gt(e,{target:{type:"comment",id:i}})}}}var Ef=["editing","suggesting","viewing"],kf=["review","original","final","off"],Tf=["paired","independent"],If=["all","internal","external"];function Fr(e,t){return typeof e=="string"&&t.includes(e)}function Es(e){return Fr(e,Ef)?e:null}function Qo(e){return Fr(e,kf)?e:null}function en(e){return Fr(e,Tf)?e:null}function tn(e){return Fr(e,If)?e:null}function ks(e){return e==="paginated"||e==="web"?e:null}function rn(e){return ks(e)??"paginated"}function ht(e){return e==="vertical"||e==="horizontal"||e==="book"?e:null}function on(e,t){return t==="web"?"vertical":ht(e)??"vertical"}function Ae(e){let t=rn(e.flowMode),r=ht(e.preferredPaginatedLayoutMode)??ht(e.layoutMode)??"vertical";return{flowMode:t,layoutMode:on(ht(e.layoutMode)??r,t),preferredPaginatedLayoutMode:r}}import{resolveEditorSelectionRootOffsets as dn}from"@datalking/begonia-editor-contracts";import{listProjectionRangeCellBoxes as Of,listProjectionSelectionRects as Vs,resolveProjectionCaretRect as Ls}from"@datalking/begonia-page-layout";function he(e,t,r,o={}){return F(e,t,r,o)}function nn(e,t,r,o={}){return lt(e,t,r,o)}function sn(e){return e+1}function Is(e,t){return Math.max(sn(t),t+e.nodeSize-1)}function Rs(e,t,r){return he(e,t,Is(e,t),r)}function Ms(e,t){return Number.isInteger(e)&&e>=0&&e<=t}function Rf(e,t,r,o){let n=sn(t),i=Is(e,t);for(;n<i;){let s=n+Math.floor((i-n)/2);he(e,t,s,o)<r?n=s+1:i=s}return n}function Ts(e,t,r,o="end",n={}){let i=Rs(e,t,n);if(!Ms(r,i))return null;let s=ne(e,t,r,o,n);if(s!=null)return s;let l=Rf(e,t,r,n);return o==="start"?Math.max(sn(t),l-1):l}function Gt(e,t,r,o={}){let n=Rs(e,t,o);if(!Ms(r,n))return null;let i=nn(e,t,r,o);if(i!=null)return i;let s=Ts(e,t,r,"start",o),l=Ts(e,t,r,"end",o);if(s==null||l==null)return s??l;if(s===l)return s;let a=he(e,t,s,o),c=he(e,t,l,o);return r-a<=c-r?s:l}import{semanticNodeText as Mf}from"@datalking/begonia-document-model";function Ns(e){return e.isInline&&e.isAtom?Mf(e):""}var Nf=" | ";function ln(e){if(e.type.name!=="table")return null;let t=[],r=0;return e.forEach((o,n)=>{let i=r,s=0;o.forEach((l,a)=>{let c=s===0?0:Nf.length,u=i+c,d=l.textBetween(0,l.content.size,"",Ns),m=d.trimEnd().length,f=0,g=0;l.forEach((p,b)=>{if(!p.isTextblock)return;let y=p.textBetween(0,p.content.size,"",Ns).length,x=Math.max(0,Math.min(y,m-f));t.push({contentStart:n+a+b+4,textLength:x,flattenedStart:u+g}),f+=y,g+=Math.max(1,y)}),i=u+g+Math.max(0,d.length-f),s+=1}),r=i+1}),t.length>0?t:null}function As(e,t,r){let o=ln(e);if(!o)return null;let n=r-t;for(let i of o){if(n<i.contentStart-1)continue;let s=n-i.contentStart;if(!(s>i.textLength))return t+i.flattenedStart+Math.max(0,s)}return null}function jr(e){return typeof e=="object"&&e!==null&&"resolve"in e&&"descendants"in e&&"content"in e}function an(e,t){let r=e.resolve(Math.max(0,Math.min(t,e.content.size)));for(let o=r.depth;o>0;o-=1){let n=r.node(o);if(n.isTextblock)return{node:n,blockPos:r.before(o)}}return null}function Os(e,t){if(!jr(e)||!Number.isFinite(t?.from))return null;let r=Math.round(t.from),o=an(e,r)??an(e,r+1);return o?{doc:e,...o}:null}function Af(e,t){let r=e.resolve(Math.max(0,Math.min(t,e.content.size)));for(let o=r.depth;o>0;o-=1){let n=r.node(o);if(n.type.name==="table")return As(n,r.before(o),t)}return null}function zr(e,t){if(!jr(e)||!Number.isFinite(t))return!1;let r=e.resolve(Math.max(0,Math.min(t,e.content.size)));for(let o=r.depth;o>0;o-=1)if(r.node(o).type.name==="table")return!0;return!1}function cn(e,t){if(!jr(e)||!Number.isFinite(t))return!1;let r=Math.round(t),o=e.resolve(Math.max(0,Math.min(r,e.content.size)));return!o.parent.isTextblock||o.parentOffset!==0?!1:zr(e,r)}function qr(e,t){if(!jr(e)||!Number.isFinite(t))return null;let r=Math.round(t),o=Af(e,r);if(o!=null)return o;if(zr(e,r))return null;let n=an(e,r);if(!n)return null;let i=he(n.node,n.blockPos,r,T(e));return Number.isFinite(i)?n.blockPos+Math.max(0,i):null}function Vf(e){let t=new Set;for(let r of e)t.add([r.blockIndex,r.originRow,r.originColumn,r.rowSpan,r.colSpan].join(":"));return t.size}function Lf(e,t={}){return t.paintSingleCellBox===!0?e.length>0:Vf(e)>1}function Df(e){return e==="end"||e==="union"?e:"start"}function un(e,t,r,o){for(let n=1;n<=8;n+=1){let i=qr(e,t+n*o);if(i!=null)return i}return r}function Yt(e,t){let r=Q(e),o=qr(r,t.from),n=qr(r,t.to);if(o!=null&&n!=null)return o<=n?{from:o,to:n}:{from:n,to:o};if(o==null&&n==null){if(zr(r,t.from)){if(t.from===t.to){let a=un(r,t.from,0,-1);if(a!=null)return{from:a,to:a}}return null}return t.from<=t.to?{from:t.from,to:t.to}:{from:t.to,to:t.from}}let i=o??n,s=o??un(r,Math.min(t.from,t.to),i,1),l=n??un(r,Math.max(t.from,t.to),i,-1);return s==null||l==null?{from:i,to:i}:s<=l?{from:s,to:l}:{from:l,to:s}}function Hf(e){return e?{left:e.left,top:e.top,width:1,height:e.height}:null}function Ds(e){if(e.length===0)return null;let t=e[0].left,r=e[0].top,o=e[0].left+e[0].width,n=e[0].top+e[0].height;for(let i of e.slice(1))t=Math.min(t,i.left),r=Math.min(r,i.top),o=Math.max(o,i.left+i.width),n=Math.max(n,i.top+i.height);return{left:t,top:r,width:Math.max(1,o-t),height:Math.max(1,n-r)}}function $t(e,t){let r=Ce(e),o=ce(e)??{};if(!r||!t||t.empty)return[];let n=dn(t);if(!n)return[];let i=Yt(e,n);return i?Vs(r,i.from,i.to,{...o,documentRegionsOnly:!0}):[]}function mn(e,t){let r=Ce(e),o=ce(e)??{};if(!r||!t)return[];if(!Number.isFinite(t.from)||!Number.isFinite(t.to))return[];let n=Yt(e,t);return n?Vs(r,n.from,n.to,o):[]}function Hs(e,t){let r=mn(e,t),o=Ds(r);return o?{bounds:o,rects:r,pageIndex:r[0].pageIndex}:null}function Fs(e,t,r={}){let o=Ce(e);if(!o||!t||t.empty)return[];let n=dn(t);if(!n)return[];let i=Yt(e,n);if(!i)return[];let s=Of(o,i.from,i.to);return Lf(s,r)?s:[]}function fn(e,t,r={}){let o=Ce(e),n=ce(e)??{};if(!o||!t||!t.empty)return null;let i=dn(t);if(!i)return null;let s=Yt(e,{...i,to:i.from});if(!s)return null;let l=Bs(e),a=l?.selectionOffset===i.from?l:null;return Ls(o,s.from,{bias:r.bias,pointer:a,preferredPageNumber:l?.pageNumber??null,cellLineBias:cn(Q(e),i.from)?"start":void 0,measureText:n.measureText,measurementEpoch:n.measurementEpoch,documentRegionsOnly:!0})}function js(e,t,r={}){let o=Ce(e),n=ce(e)??{};if(!o||!Number.isFinite(t))return null;let i=Yt(e,{from:t,to:t});return i?Ls(o,i.from,{bias:r.bias,cellLineBias:cn(Q(e),t)?"start":void 0,measureText:n.measureText,measurementEpoch:n.measurementEpoch}):null}function zs(e,t,r={}){let o=$t(e,t);if(o.length===0)return Hf(fn(e,t));switch(Df(r.placement)){case"end":{let n=o.at(-1)??null;return n?{left:n.left,top:n.top,width:n.width,height:n.height}:null}case"union":return Ds(o);default:{let n=o[0]??null;return n?{left:n.left,top:n.top,width:n.width,height:n.height}:null}}}import{cloneEditorSelectionSnapshot as Ff}from"@datalking/begonia-editor-contracts";function bt(e){return e?{empty:e.empty,target:e.target?Mr(e.target):null,activeMarks:[...e.activeMarks],activeCommentIds:[...e.activeCommentIds],activeChangeIds:[...e.activeChangeIds],...typeof e.text=="string"?{text:e.text}:{}}:null}var pn=Object.freeze([]);function jf(e){return e?structuredClone(e):void 0}function zf(e){if(!e||!Array.isArray(e.segments))return null;let t=e.segments[0]??null,r=e.segments[e.segments.length-1]??null;if(!t||!r)return null;let o=jf(e.story);return{kind:"selection",start:{kind:"text",blockId:t.blockId,offset:t.range.start,...o?{story:o}:{}},end:{kind:"text",blockId:r.blockId,offset:r.range.end,...o?{story:o}:{}},segments:e.segments.map(n=>({blockId:n.blockId,start:n.range.start,end:n.range.end})),...o?{story:o}:{}}}function _r(e,t){if(!e)return null;let r=Ff(e),o=bt(t),n=o?.target??null;return{...r,target:n,selectionTarget:zf(n),activeMarks:o?.activeMarks??pn,activeCommentIds:o?.activeCommentIds??pn,activeChangeIds:o?.activeChangeIds??pn,quotedText:o?.text??""}}import{clonePageViewportAnchor as $s,hasFreshViewportRequest as dC,normalizeViewportRequestKey as mC,samePageViewportAnchor as Uf,sameViewportRequestKey as fC}from"@datalking/begonia-layout-renderer/core";import{hasLogicalViewportAnchorHint as lC}from"@datalking/begonia-layout-renderer/core";var pe=1,_s=1e-6;function ee(e){return typeof e=="number"&&Number.isFinite(e)}function de(e,t,r=0){return e===t||Math.abs(e-t)<=r}function Ks(e,t,r=0){return e==null||t==null?e===t:de(e,t,r)}function Us(e,t=0){return ee(e)?Math.max(0,Math.trunc(e)):t}function gn(e){return ee(e)&&Number.isInteger(e)&&e>=0?e:null}function Ye(e){return ee(e)&&Number.isInteger(e)&&e>0?e:null}function wn(e,t){if(!Array.isArray(e))return[];let r=e.filter(o=>ee(o)&&Number.isInteger(o)&&o>=t);return[...new Set(r)].sort((o,n)=>o-n)}function qf(e){return e.map(t=>t+1)}function qs(e){return e.map(t=>t-1)}function _f(e,t){return e.length===t.length&&e.every((r,o)=>r===t[o])}function hn(e,t){let r=wn(t,1);if(r.length>0){let n=wn(e,0);return n.length>0&&!_f(qs(r),n)?null:{pageIndexes:qs(r),pageNumbers:r}}let o=wn(e,0);return{pageIndexes:o,pageNumbers:qf(o)}}function Ws(e){return e==="vertical"||e==="horizontal"||e==="book"?e:null}function Xs(e){return e==="paginated"||e==="web"?e:null}function Gs(e){return ee(e)&&e>0?e:null}function Ys(e,t){let r=Xs(e),o=Ws(t);return e!=null&&r==null||t!=null&&o==null?null:r==="web"?o!=null&&o!=="vertical"?null:{flowMode:r,layoutMode:"vertical"}:{flowMode:r,layoutMode:o}}function Zt(e,t){let r=Ye(t),o=gn(e);return r!=null&&o!=null&&o!==r-1?{pageIndex:null,pageNumber:null}:{pageIndex:r!=null?r-1:o,pageNumber:r??(o!=null?o+1:null)}}function Wf(e){if(e.visiblePageNumbers.length>0){let o=Ye(e.firstVisiblePageNumber),n=Ye(e.lastVisiblePageNumber);return o!=null&&o!==e.visiblePageNumbers[0]||n!=null&&n!==e.visiblePageNumbers[e.visiblePageNumbers.length-1]?null:{firstVisiblePageNumber:e.visiblePageNumbers[0]??null,lastVisiblePageNumber:e.visiblePageNumbers[e.visiblePageNumbers.length-1]??null}}let t=Ye(e.firstVisiblePageNumber),r=Ye(e.lastVisiblePageNumber);return t!=null&&r!=null&&t>r?null:{firstVisiblePageNumber:t,lastVisiblePageNumber:r}}function Xf(e){return!!(e&&typeof e=="object"&&(Object.hasOwn(e,"pageNumber")||Object.hasOwn(e,"pageIndex")))}function Zs(e,t,r){let o=ee(t)?Math.max(0,t):Math.max(0,(ee(r)?r:e)-e);return{size:o,end:e+o}}var Ur=10,Wr=500;function Kr(e,t){return e.length===t.length&&e.every((r,o)=>r===t[o])}function Xr(e,t){return Uf(e,t)}function bn(e){let t=Ye(e?.pageNumber),r=gn(e?.pageIndex);if(t==null&&r==null||t!=null&&r!=null&&r!==t-1)return null;let o=t??(r??0)+1;return{pageIndex:o-1,pageNumber:o}}function vn(e,t=null){if(e&&typeof e=="object"&&Xf(e)&&!bn(e))return null;let r=$s(e);if(r)return r;if(!e||typeof e!="object")return null;let o=bn(e)??bn(t);return o?$s({...e,...o}):null}function vt(e,t){let r=K(e),o=K(t);return!r||!o?r===o:Js(r,o)&&Kr(r.mountedPageIndexes,o.mountedPageIndexes)&&Kr(r.mountedPageNumbers,o.mountedPageNumbers)&&de(r.topSpacer,o.topSpacer,pe)&&de(r.bottomSpacer,o.bottomSpacer,pe)&&de(r.leftSpacer,o.leftSpacer,pe)&&de(r.rightSpacer,o.rightSpacer,pe)}function Js(e,t){let r=K(e),o=K(t);return!r||!o?r===o:r.totalPages===o.totalPages&&r.currentPageIndex===o.currentPageIndex&&r.currentPageNumber===o.currentPageNumber&&r.anchorPageIndex===o.anchorPageIndex&&r.anchorPageNumber===o.anchorPageNumber&&Xr(r.viewportAnchor,o.viewportAnchor)&&Kr(r.visiblePageIndexes,o.visiblePageIndexes)&&Kr(r.visiblePageNumbers,o.visiblePageNumbers)&&r.firstVisiblePageNumber===o.firstVisiblePageNumber&&r.lastVisiblePageNumber===o.lastVisiblePageNumber&&de(r.viewportTop,o.viewportTop,pe)&&de(r.viewportBottom,o.viewportBottom,pe)&&de(r.viewportHeight,o.viewportHeight,pe)&&de(r.viewportLeft,o.viewportLeft,pe)&&de(r.viewportRight,o.viewportRight,pe)&&de(r.viewportWidth,o.viewportWidth,pe)&&r.layoutMode===o.layoutMode&&r.flowMode===o.flowMode&&Ks(r.scale,o.scale,_s)}function K(e){if(!e||typeof e!="object")return null;let t=Ys(e.flowMode,e.layoutMode);if(!t)return null;let r=Zt(e.currentPageIndex,e.currentPageNumber),o=Zt(e.anchorPageIndex,e.anchorPageNumber),n=ee(e.viewportTop)?e.viewportTop:0,i=ee(e.viewportLeft)?e.viewportLeft:0,s=Zs(n,e.viewportHeight,e.viewportBottom),l=Zs(i,e.viewportWidth,e.viewportRight),a=hn(e.visiblePageIndexes,e.visiblePageNumbers);if(!a)return null;let c=hn(e.mountedPageIndexes,e.mountedPageNumbers);if(!c)return null;let u=Wf({visiblePageNumbers:a.pageNumbers,firstVisiblePageNumber:e.firstVisiblePageNumber,lastVisiblePageNumber:e.lastVisiblePageNumber});if(!u)return null;let d=vn(e.viewportAnchor,{pageIndex:o.pageIndex??r.pageIndex,pageNumber:o.pageNumber??r.pageNumber});return{totalPages:Us(e.totalPages),currentPageIndex:r.pageIndex,currentPageNumber:r.pageNumber,anchorPageIndex:o.pageIndex,anchorPageNumber:o.pageNumber,viewportAnchor:d,visiblePageIndexes:a.pageIndexes,visiblePageNumbers:a.pageNumbers,mountedPageIndexes:c.pageIndexes,mountedPageNumbers:c.pageNumbers,firstVisiblePageNumber:u.firstVisiblePageNumber,lastVisiblePageNumber:u.lastVisiblePageNumber,viewportTop:n,viewportBottom:s.end,viewportHeight:s.size,viewportLeft:i,viewportRight:l.end,viewportWidth:l.size,topSpacer:ee(e.topSpacer)?Math.max(0,e.topSpacer):0,bottomSpacer:ee(e.bottomSpacer)?Math.max(0,e.bottomSpacer):0,leftSpacer:ee(e.leftSpacer)?Math.max(0,e.leftSpacer):0,rightSpacer:ee(e.rightSpacer)?Math.max(0,e.rightSpacer):0,layoutMode:t.layoutMode,flowMode:t.flowMode,scale:Gs(e.scale)}}var ep=Object.freeze({percent:100,mode:"manual",value:100,fitZoom:null,min:10,max:400,viewportMetrics:null});function St(e){return{getSnapshot(){return e.get()},subscribe(t){return e.subscribe(t)},observe(t){return e.subscribe(t)}}}function tp(e){let t=Ae(e);return{flowMode:t.flowMode,layoutMode:t.layoutMode,preferredPaginatedLayoutMode:t.preferredPaginatedLayoutMode,zoom:tl(e)}}function rp(e){return _r(e.selection,e.selectionInfo)}function op(e){return{editable:e.editable,documentMode:Es(e.documentMode),trackingEnabled:e.trackingEnabled,trackChanges:{enabled:e.review.enabled,visible:e.review.visible,mode:Qo(e.review.mode),replacementMode:en(e.review.replacementMode)}}}function np(e){return{enabled:e.comments.enabled,visible:e.comments.visible,readOnly:e.comments.readOnly,allowResolve:e.comments.allowResolve??!1,showResolved:e.comments.showResolved,visibility:tn(e.comments.visibility),useInternalExternalComments:e.comments.useInternalExternalComments??!1,suppressInternalExternal:e.comments.suppressInternalExternal??!1,enforceVisibilityPolicy:e.comments.enforceVisibilityPolicy??!1,total:e.comments.total??e.comments.items.length}}function tl(e){return e.zoom?{percent:e.zoom.percent,mode:e.zoom.mode==="fit-width"?"fit-width":"manual",value:typeof e.zoom.value=="number"?e.zoom.value:e.zoom.percent,fitZoom:typeof e.zoom.fitZoom=="number"?e.zoom.fitZoom:null,min:typeof e.zoom.min=="number"?e.zoom.min:10,max:typeof e.zoom.max=="number"?e.zoom.max:400,viewportMetrics:e.zoom.viewportMetrics}:ep}function ip(e){if(!e.viewport)return null;let t=K(e.viewport.value);return{value:t,requestKey:e.viewport.requestKey,previewNavigationRequest:e.viewport.previewNavigationRequest,totalPages:t?.totalPages??null,currentPageIndex:t?.currentPageIndex??null,currentPageNumber:t?.currentPageNumber??null}}function rl(e,t){return{...St(t.select(tp)),setViewState(o){e.view.setViewState(o)},getZoomState(){return e.view.getZoomState()},setZoomMode(o){e.view.setZoomMode(o)}}}function ol(e,t){let r=St(t.select(rp));return{...r,getRects(){return $t(e.preview,r.getSnapshot())},getCellSelectionRects(o){return Fs(e.preview,r.getSnapshot(),o)},getAnchorRect(o){return zs(e.preview,r.getSnapshot(),o)},getCaretRect(o){return fn(e.preview,r.getSnapshot(),o)},getRangeRects(o){return mn(e.preview,o)},getCaretRectAtPosition(o,n){return js(e.preview,o,n)},getRangeBounds(o){return Hs(e.preview,o)}}}function nl(e,t){return{...St(t.select(op)),setDocumentMode(o){e.documentMode.setDocumentMode(o)},setTrackChangesDisplayMode(o){e.documentMode.setTrackChangesDisplayMode(o)}}}function il(e,t){return{...St(t.select(np)),setCommentsVisible(o){e.commentsDisplay.setCommentsVisible(o)},setCommentsShowResolved(o){e.commentsDisplay.setCommentsShowResolved(o)},setCommentsVisibility(o){e.commentsDisplay.setCommentsVisibility(o)}}}function sl(e,t){return{...St(t.select(tl)),set(o){e.view.setViewState({zoomPercent:o})},setMode(o){e.view.setZoomMode(o)}}}function ll(e,t){return{...St(t.select(ip)),getHost(){return e.browserViewport.getHost?.()??null},getScrollContainer(){return e.browserViewport.getScrollContainer?.()??null},observeGeometry(o){return e.browserViewport.observeGeometry(o)},scrollIntoView(o){return e.browserViewport.scrollIntoView(o)},getRect(o){return gt(e,o)},entitiesAtPoint(o){return e.browserViewport.entitiesAtPoint(o)},contextAtPoint(o){return e.browserViewport.contextAtPoint(o)},positionAtPoint(o){return e.browserViewport.positionAtPoint(o)},requestNavigation(o){return e.browserViewport.requestNavigation(o)},requestNavigationForTextTarget(o){return e.browserViewport.requestNavigationForTextTarget(o)},ackNavigationRequest(o){e.browserViewport.ackNavigationRequest(o)}}}import{isIntegerPath as sp}from"@datalking/begonia-document-model";function Bt(e={}){return{revisionId:null,trackChange:null,target:null,selectionTarget:null,navigationRequest:null,...e}}function lp(e){return Array.isArray(e)&&e.length>0&&sp(e)}function Gr(e){return!!e&&typeof e=="object"&&lp(e.blockPath)}function cl(e){if(!e)return null;if(typeof e=="string")return e.length>0?e:null;let t="revisionId"in e?e.revisionId:"id"in e?e.id:null;return typeof t=="string"&&t.length>0?t:null}function ap(e){return e?Gr(e.target)?e.target:(e.targets??[]).find(Gr)??null:null}function cp(e){let t="target"in e?e.target:null,r="targets"in e?e.targets:null;return Gr(t)||(r??[]).some(Gr)}function up(e,t){if(typeof t!="string"&&cp(t))return t;let r=cl(t);return r?e.documentApi.trackChanges.get(r):null}function dp(e,t){let r=Q(No(e));return zo(e.documentApi,mp(r)?r:null,t)}function mp(e){return e!=null&&typeof e=="object"&&"type"in e&&"nodesBetween"in e&&typeof e.nodesBetween=="function"}function fp(e,t){return(typeof t?.id=="string"&&t.id.length>0?t.id:typeof t?.revisionId=="string"&&t.revisionId.length>0?t.revisionId:null)??e}function Oe(e,t){if(!e||!t)return Bt();let r=V(e);if(!r)return Bt();let o=cl(t),n=up(r,t);if(!n)return Bt({revisionId:o});let i=fp(o,n),s=dp(r,n),l=s.target??ap(n);if(!l)return Bt({revisionId:i,trackChange:n});let a=s.selectionTarget;return Bt(a?{revisionId:i,trackChange:n,target:l,selectionTarget:a}:{revisionId:i,trackChange:n,target:l})}function pp(e,t){let r=Oe(e,t),o=V(e);return!o||!r.selectionTarget?r:{...r,navigationRequest:o.browserViewport.requestNavigationForTextTarget(r.selectionTarget)}}function al(){return{success:!1}}function wp(e){let t=e.revisionId;if(typeof t=="string"&&t.length>0)return t;let r=e.trackChange?.id;return typeof r=="string"&&r.length>0?r:null}async function Jt(e,t,r={},o={}){let n=Oe(e,t),i=V(e);return!i||!n.selectionTarget?al():Pr(i.selectionHandles,async()=>{if(i.selectionTargets.selectTextTarget(n.selectionTarget))return i.browserViewport.scrollIntoView({target:n.selectionTarget,timeoutMs:r.timeoutMs,continuation:o.continuation});let s=wp(n);return s?i.browserViewport.scrollIntoView({target:{type:"trackedChange",id:s},timeoutMs:r.timeoutMs,continuation:o.continuation}):al()},{shouldContinue:o.continuation?.shouldContinue})}function ul(e){if(e==null||typeof e!="object")return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function yt(e,t){if(Object.is(e,t))return!0;if(e==null||t==null)return!1;if(Array.isArray(e)||Array.isArray(t)){if(!Array.isArray(e)||!Array.isArray(t)||e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1)if(!yt(e[n],t[n]))return!1;return!0}if(!ul(e)||!ul(t))return!1;let r=Object.keys(e),o=Object.keys(t);if(r.length!==o.length)return!1;for(let n of r)if(!Object.hasOwn(t,n)||!yt(e[n],t[n]))return!1;return!0}function Sn(e,t,r){let o=e.filter(s=>typeof s.id=="string"&&s.id.length>0);if(o.length===0)return null;let n=t==null?-1:o.findIndex(s=>s.id===t),i=r==="next"?n<0||n>=o.length-1?0:n+1:n<=0?o.length-1:n-1;return o[i]?.id??null}function gp(e){return e.find(t=>t.type==="trackedChange")??null}function hp(e){return[...new Set(e.filter(t=>t.type==="trackedChange").map(t=>t.id))]}function bp(e,t){return e.find(r=>r.id===t)??null}function vp(e,t){let r=hp(t);if(r.length!==1)return null;let o=r[0]??gp(t)?.id??null;if(!o)return null;let n=bp(e,o);return!n||typeof n.id!="string"||n.id.length===0?null:{id:n.id,item:n}}function dl(e,t,r){if(!t||typeof t!="object"||typeof t.clientX!="number"||typeof t.clientY!="number")return null;let o=V(e);return o?vp(r,o.browserViewport.entitiesAtPoint(t)):null}var ml=Object.freeze([]),Sp=Object.freeze([]),Bp=Object.freeze([]),yp=Object.freeze({});function Bn(e){return structuredClone(e)}function Pp(){return{items:Sp,permissions:yp,timeline:Bp,summary:null,total:0,activeRevisionId:null,activeRevisionIds:ml,enabled:!1,visible:!1,mode:null,replacementMode:null}}function Cp(e,t){return yt(e,t)}function xp(e){return e?{items:e.revisions,permissions:e.permissions,timeline:e.timeline,summary:e.summary,total:e.revisions.length,activeRevisionId:e.activeRevisionId??null,activeRevisionIds:e.activeRevisionIds??ml,enabled:e.enabled,visible:e.visible,mode:e.mode,replacementMode:e.replacementMode}:Pp()}function be(e){let r=V(e)?.session.readState();return xp(r?.review)}function Ve(){return{revisionId:null,trackChange:null,target:null,selectionTarget:null,navigationRequest:null,selected:!1}}function Ct(e,t){let r=V(e);if(!r||!t)return Ve();let o=Oe(e,t);if(!o.selectionTarget)return{...o,selected:!1};let n=r.selectionTargets.selectTextTarget(o.selectionTarget),i=r.browserViewport.requestNavigationForTextTarget(o.selectionTarget);return{...o,navigationRequest:i,selected:n}}function xe(e,t){let r=V(e);return r?r.reviewFocus.setActiveRevision(t):!1}function Pt(e,t){let r=V(e);return r?t==="next"?r.reviewFocus.nextActiveRevision():r.reviewFocus.previousActiveRevision():null}async function Ep(e,t,r,o){if(!V(e))return{success:!1};let i=be(e).activeRevisionId??null,s=Oe(e,t);s.revisionId&&xe(e,s.revisionId);let l=await Jt(e,t,r,{continuation:o});return o.shouldContinue()?(!l.success&&s.revisionId&&xe(e,i),l):{success:!1}}function yn(e){let t=V(e);if(!t)throw new Error("createBrowserEditorTrackChangesController requires a valid browser editor UI source.");let r=be(e),o=null,n=new Set,i=xr(),s=()=>{o||n.size===0||(o=t.session.subscribe(()=>{let c=be(e);if(Cp(r,c)){r=c;return}r=c;for(let u of[...n])u(Bn(r))}))},l=()=>{n.size>0||!o||(o(),o=null)},a=c=>(r=be(e),n.add(c),s(),c(Bn(r)),()=>{n.delete(c),l()});return{getSnapshot(){return r=be(e),Bn(r)},subscribe:a,observe(c){return a(c)},accept(c){return t.reviewActions.acceptRevision(c)},reject(c){return t.reviewActions.rejectRevision(c)},acceptAll(){return t.reviewActions.acceptAll()},rejectAll(){return t.reviewActions.rejectAll()},setActive(c){return i.invalidate(),xe(e,c)},next(){return i.invalidate(),Pt(e,"next")},previous(){return i.invalidate(),Pt(e,"previous")},reveal(c){i.invalidate();let u=Oe(e,c);return u.revisionId&&xe(e,u.revisionId),Ct(e,c)},revealNext(){i.invalidate();let c=Pt(e,"next");return c?Ct(e,c):Ve()},revealPrevious(){i.invalidate();let c=Pt(e,"previous");return c?Ct(e,c):Ve()},getAt(c){return r=be(e),dl(e,c,r.items)},scrollTo(c,u){return Ep(e,c,u,i.begin())},navigateNext(c){let u=i.begin(),d=be(e).activeRevisionId??null,m=Pt(e,"next");return m?Jt(e,m,c,{continuation:u}).then(f=>u.shouldContinue()?(f.success||xe(e,d),f):{success:!1}):Promise.resolve({success:!1})},navigatePrevious(c){let u=i.begin(),d=be(e).activeRevisionId??null,m=Pt(e,"previous");return m?Jt(e,m,c,{continuation:u}).then(f=>u.shouldContinue()?(f.success||xe(e,d),f):{success:!1}):Promise.resolve({success:!1})},getRect({id:c}){return gt(t,{target:{type:"trackedChange",id:c}})}}}function kp(e,t){let r=V(e);if(!r)return Ve();let o=Oe(r,t);return o.revisionId&&xe(r,o.revisionId),Ct(r,t)}function Tp(e){let t=V(e);if(!t)return Ve();let r=be(t),o=Sn(r.items,r.activeRevisionId,"next");return o&&xe(t,o),o?Ct(t,o):Ve()}function Ip(e){let t=V(e);if(!t)return Ve();let r=be(t),o=Sn(r.items,r.activeRevisionId,"previous");return o&&xe(t,o),o?Ct(t,o):Ve()}function fl(e){let t=Rp(e.session),r=ol(e,t),o=rl(e,t),n=nl(e,t),i=il(e,t),s=ll(e,t),l=sl(e,t),a=Jo(e,t.comments),c=yn(e),u=Object.assign(t,{host:e,session:e.session,documentApi:e.documentApi,readCommandSnapshot(d){return e.readCommandSnapshot(d)},selection:r,selectionHandles:e.selectionHandles,linkSelection:e.linkSelection,activeLink:e.activeLink,view:o,documentMode:n,comments:a,commentsDisplay:i,commentActions:e.commentActions,commentFocus:e.commentFocus,reviewActions:e.reviewActions,reviewFocus:e.reviewFocus,trackChanges:c,selectionTargets:e.selectionTargets,viewport:s,zoom:l,browserViewport:e.browserViewport,preview:e.preview,overlayState:e.overlayState,overlays:e.overlays??{}});return Object.defineProperty(u,"actor",{configurable:!1,enumerable:!0,get(){return e.actor}}),u}function Mp(e,t){let r=null;for(let o of e??[]){let n=t.get(Pe(o));if(n){if(r==null){r=n;continue}if(r!==n)return null}}return r}function Np(e,t,r){let o=t.get(Pe(r));return o?(e??[]).some(n=>t.get(Pe(n))===o):!1}function Ap(e){let t=Math.min(e.from,e.to),r=Math.max(e.from,e.to);return{start:t,selectionEnd:t===r?r+1:r,collapsed:t===r}}function Op(e){return e!=null&&Math.min(e.from,e.to)===Math.max(e.from,e.to)}function Vp(e,t){if(!e||!t)return!1;let r=Ap(e),o=Math.min(t.from,t.to),n=Math.max(t.from,t.to);return o===n?o<r.selectionEnd&&o>=r.start:o<r.selectionEnd&&n>r.start}function Lp(e){let t=oe(e.comments),r=new Set(t.values()),o=t.get(Pe(e.selectedCommentId))??"",n=Op(e.selection),i=Mp(e.selectionInfo?.activeCommentIds,t),s=Np(e.selectionInfo?.activeCommentIds,t,o),l=r.has(o);return l&&s?o:i||(l&&e.selectedCommentSelection&&(!n||Vp(e.selection,e.selectedCommentSelection))?o:null)}function Dp(e){let t=[],r=new Set;for(let o of e)typeof o!="string"||o.length===0||r.has(o)||(r.add(o),t.push(o));return t}function Pn(e){let t=Dp(X(e.selectionInfo?.activeChangeIds,e.revisions));if(!e.revisions||e.revisions.length===0)return t;let r=new Set(e.revisions.map(o=>o.id));return t.filter(o=>r.has(o))}function Hp(e){let t=Pn(e);return t.length===1?t[0]??null:null}function Cn(e){let t=Pn(e);return{activeRevisionIds:t,activeRevisionId:t.length===1?t[0]??null:null}}function Fp(e){let t=[],r=new Set;for(let o of e)typeof o!="string"||o.length===0||r.has(o)||(r.add(o),t.push(o));return t}function pl(e,t){if(t==null)return[...e];let r=new Set(oe(t).values());return e.filter(o=>r.has(o))}function jp(e){return pl(Ue(e.selectionInfo?.activeCommentIds,oe(e.comments)),e.comments)}function zp(e){let t=jp(e);return{activeCommentIds:t,activeCommentId:t.length===1?t[0]??null:null}}function qp(e){return pl(Ue(Fp([...e.explicitActiveCommentIds??[],e.explicitActiveCommentId]),oe(e.comments)),e.comments)}function xn(e){let t=zp(e);if(t.activeCommentIds.length>0)return t;let r=qp(e);return{activeCommentIds:r,activeCommentId:r.length===1?r[0]??null:null}}function Qt(e){let t=e?.layoutMode??"vertical";return{flowMode:e?.flowMode??"paginated",layoutMode:t,preferredPaginatedLayoutMode:e?.preferredPaginatedLayoutMode??t,zoomPercent:e?.zoom?.percent??e?.zoomPercent??100,zoomMode:e?.zoom?.mode??"manual"}}function er(e,t){switch(t.type){case"flow":return{flowMode:t.flowMode};case"toggle-pagination":return{flowMode:e.flowMode==="paginated"?"web":"paginated"};case"layout":return{flowMode:"paginated",layoutMode:t.layoutMode,preferredPaginatedLayoutMode:t.layoutMode};case"zoom":return{zoomPercent:t.zoomPercent}}}function _p(e){return e.flowMode==="paginated"?e.layoutMode:e.preferredPaginatedLayoutMode}function Kp(e){return e.zoomMode==="fit-width"?"manual":"fit-width"}function Up(e,t,r){let o=[...new Set(t.filter(i=>Number.isFinite(i)&&i>0).map(i=>Math.min(Wr,Math.max(Ur,i))))].sort((i,s)=>i-s),n=e;if(o.length===0)return n;if(r<0){for(let i=o.length-1;i>=0;i-=1){let s=o[i];if(s!==void 0&&s<n)return s}return n}for(let i of o)if(i>n)return i;return n}import{moveProjectionCaretHorizontally as Wp,moveProjectionCaretToBoundary as Xp,resolveVerticalSelectionMove as Gp}from"@datalking/begonia-page-layout";function En(e){if(e.altKey)return null;let t=!!(e.ctrlKey||e.metaKey),r=e.shiftKey===!0;if(e.key==="Home"||e.key==="End"){let o=Xp({projection:e.projection,pos:e.head,boundary:e.key==="Home"?t?"documentStart":"lineStart":t?"documentEnd":"lineEnd"});return o==null?null:wl(e.anchor,o,r)}if(e.key==="ArrowUp"||e.key==="ArrowDown")return t?null:Gp({projection:e.projection,anchor:e.anchor,head:e.head,direction:e.key==="ArrowUp"?"up":"down",extend:r,measureText:e.measureText,measurementEpoch:e.measurementEpoch});if(e.key==="ArrowLeft"||e.key==="ArrowRight"){if(t)return null;let o=Wp(e.projection,e.head,e.key==="ArrowLeft"?"left":"right");return o==null?null:wl(e.anchor,o,r)}return null}function wl(e,t,r){let o=r?e:t;return{anchor:o,head:t,from:Math.min(o,t),to:Math.max(o,t),empty:o===t}}import{createPaginatedOverlayModel as cw,nextPaginatedEditorFocusLatch as uw,PAGINATED_CARET_ATTRIBUTE as Ml,resolvePaginatedCaretFocus as dw}from"@datalking/begonia-layout-renderer";import{resolvePaginatedRevealScrollDelta as hl,DEFAULT_PAGINATED_REVEAL_MARGIN_PX as bl}from"@datalking/begonia-layout-renderer";function vl(e){let t=e.caret.top-e.viewport.top;return hl({caretTop:t,caretBottom:t+Math.max(0,e.caret.height),viewportTop:0,viewportHeight:e.viewport.height,marginPx:e.marginPx??bl,maxStep:e.maxStep,scrollOffset:e.scrollOffset,scrollExtent:e.scrollExtent})}function Yp(e){let t=e.caret.left-e.viewport.left;return hl({caretTop:t,caretBottom:t+Math.max(0,e.caret.width),viewportTop:0,viewportHeight:e.viewport.width,marginPx:e.marginPx??bl,maxStep:e.maxStep,scrollOffset:e.scrollOffset,scrollExtent:e.scrollExtent})}function $e(e,t){return typeof e=="number"&&Number.isFinite(e)?e:t}function gl(e,t){return Number.isFinite(e)&&Number.isFinite(t)&&e>t+1}function $p(e,t){let r=e.scrollAxis!=="horizontal"?!0:gl(e.scrollHeight,t.height),o=e.scrollAxis==="horizontal"?!0:gl(e.scrollWidth??0,t.width);return{vertical:r,horizontal:o}}function kn(e){let t=!1;return{reveal(){if(t)return!1;let r=e.getScrollHost(),o=e.getCaretElement();if(!r||!o||typeof o.getBoundingClientRect!="function")return!1;let n=o.getBoundingClientRect(),i=r.getBoundingClientRect(),s=$e(i.height,0),l=$e(i.width,0),a=$p(r,{height:s,width:l}),c=!1;if(a.vertical){let u=vl({caret:{top:n.top,height:n.height},viewport:{top:i.top,height:s},scrollOffset:r.scrollTop,scrollExtent:r.scrollHeight,marginPx:e.marginPx,maxStep:e.maxStep});u!=null&&(r.scrollTop=$e(r.scrollTop,0)+u,c=!0)}if(a.horizontal){let u=Yp({caret:{left:$e(n.left,0),width:$e(n.width,0)},viewport:{left:$e(i.left,0),width:l},scrollOffset:r.scrollLeft,scrollExtent:r.scrollWidth,marginPx:e.marginPx,maxStep:e.maxStep});u!=null&&(r.scrollLeft=$e(r.scrollLeft,0)+u,c=!0)}return c},destroy(){t=!0}}}import{PAGINATED_CHROME_SELECTOR as ew}from"@datalking/begonia-layout-renderer";function Zp(){return{Element:typeof Element<"u"?Element:void 0,Node:typeof Node<"u"?Node:void 0,HTMLAnchorElement:typeof HTMLAnchorElement<"u"?HTMLAnchorElement:void 0,HTMLInputElement:typeof HTMLInputElement<"u"?HTMLInputElement:void 0,HTMLTextAreaElement:typeof HTMLTextAreaElement<"u"?HTMLTextAreaElement:void 0,HTMLSelectElement:typeof HTMLSelectElement<"u"?HTMLSelectElement:void 0,HTMLButtonElement:typeof HTMLButtonElement<"u"?HTMLButtonElement:void 0}}function Jp(e,t){if(!t)return!1;try{return e instanceof t}catch{return!1}}function Qp(e){if(typeof e!="object"||e===null)return null;try{let t=e.nodeType;return typeof t=="number"&&Number.isFinite(t)?t:null}catch{return null}}function tr(e,t=Zp()){return Jp(e,t.Element)?!0:Qp(e)===1}var tw=new Set(["Alt","AltGraph","CapsLock","Control","Fn","Hyper","Meta","NumLock","OS","ScrollLock","Shift","Super","Symbol","SymbolLock"]),rw=new Set(["Tab"]),ow=new Set(["button","checkbox","color","file","hidden","image","radio","range","reset","submit"]);function yl(e){if(!e||typeof e!="object")return!1;let t=e,r=typeof t.tagName=="string"?t.tagName.toUpperCase():"";if(r==="TEXTAREA"||r==="SELECT")return!0;if(r==="INPUT"){if(t.readOnly===!0||t.disabled===!0)return!1;let o=typeof t.type=="string"?t.type.toLowerCase():"text";return!ow.has(o)}return t.isContentEditable===!0}function Pl(e){if(!e||e.defaultPrevented===!0)return!1;let t=e.key;return!(typeof t!="string"||t.length===0||e.isComposing===!0||tw.has(t)||rw.has(t)||yl(e.target))}function nw(e){if(yl(e))return"typing";if(!e||typeof e!="object")return"body";let t=e.closest;return typeof t!="function"?"body":t.call(e,ew)?"band":"body"}function Cl(e){return!e||e.defaultPrevented===!0||(e.button??0)!==0?!1:nw(e.target)==="body"}var iw=new Set(["insertCompositionText","deleteCompositionText"]);function sw(e){return typeof e!="string"||e.length===0?!1:!iw.has(e)}function xl(e,t){return t==="compositionstart"||t==="compositionupdate"?!0:t==="compositionend"||t==="focusout"?!1:e}function Sl(e){return e?.ownerDocument??null}function Bl(e){return tr(e)?e:null}function Tn(e={getPreviewHost:()=>null}){let t=!1,r="",o=null,n=null,i=null,s=null,l=()=>{if(typeof e.focus!="function")return!1;try{return e.focus(),!0}catch{return!1}},a=(m,f)=>{let g=typeof f=="string"?f:"";m===t&&g===r||(t=m,r=g,e.onCompositionChange?.(t,r))},c=m=>{let f=Sl(m);if(!f||!e.onFocusChange||f===s&&i)return;i?.(),s=f;let g=x=>{let E=Bl(x.target),O=Bl(x.relatedTarget);e.onFocusChange?.({phase:x.type==="focusin"?"in":"out",target:E,relatedTarget:O})},p=f.defaultView,b=()=>{e.onFocusChange?.({phase:"out",target:null,relatedTarget:null})},w=()=>{e.onFocusChange?.({phase:"in",target:null,relatedTarget:null})};f.addEventListener("focusin",g,!0),f.addEventListener("focusout",g,!0),p?.addEventListener("blur",b),p?.addEventListener("focus",w);let y=()=>{f.visibilityState==="hidden"?b():w()};f.addEventListener("visibilitychange",y),i=()=>{f.removeEventListener("focusin",g,!0),f.removeEventListener("focusout",g,!0),p?.removeEventListener("blur",b),p?.removeEventListener("focus",w),f.removeEventListener("visibilitychange",y)}},u=m=>{o?.(),o=null;let f=Sl(m);if(!m||!f)return;let g=w=>{e.onKeyDown?.(),Pl(w)&&l()},p=w=>{Cl(w)&&l()},b=w=>{e.onContextMenu?.({clientX:w.clientX,clientY:w.clientY})===!0&&(w.preventDefault(),w.stopPropagation())};f.addEventListener("keydown",g,!0),m.addEventListener("pointerdown",p,!0),m.addEventListener("contextmenu",b),o=()=>{f.removeEventListener("keydown",g,!0),m.removeEventListener("pointerdown",p,!0),m.removeEventListener("contextmenu",b)},c(m)},d=m=>{if(n?.(),n=null,!m)return;let f=y=>{a(xl(t,y.type),y.type==="compositionstart"?"":y.data??"")},g=()=>{t&&a(!1,r)},p=y=>{let x=y.inputType;sw(x)&&g()},b=y=>{y.isComposing!==!0&&g()};m.addEventListener("compositionstart",f),m.addEventListener("compositionupdate",f),m.addEventListener("compositionend",f);let w="onbeforeinput"in m;m.addEventListener(w?"beforeinput":"input",w?p:b),n=()=>{m.removeEventListener("compositionstart",f),m.removeEventListener("compositionupdate",f),m.removeEventListener("compositionend",f),m.removeEventListener(w?"beforeinput":"input",w?p:b)},c(m)};return{isComposing(){return t},focus:l,setPreviewHost(m){u(m)},setEditorHost(m){d(m)},destroy(){o?.(),n?.(),i?.(),o=null,n=null,i=null,s=null,t=!1,r=""}}}function G(e,t){return typeof e=="number"&&Number.isFinite(e)?e:t}function lw(e){let t=G(e,1);return t>0?t:1}function kl(e){let t=e.caret,r=e.frame;if(!t||!r)return null;let o=G(t.left,Number.NaN),n=G(t.top,Number.NaN),i=G(t.height,Number.NaN),s=G(r.left,Number.NaN),l=G(r.top,Number.NaN);if(!Number.isFinite(o)||!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(s)||!Number.isFinite(l))return null;let a=lw(e.scale);return{left:s+o*a,top:l+n*a,height:i*a}}function Tl(e){return El(e.caret)??El(e.line)}function El(e){if(!e)return null;let t=G(e.left,Number.NaN),r=G(e.top,Number.NaN),o=G(e.height,Number.NaN);return!Number.isFinite(t)||!Number.isFinite(r)||!(o>0)?null:{left:t,top:r,height:o}}function Il(e){let t={left:G(e.offset?.left,0),top:G(e.offset?.top,0)},r=e.anchor,o=e.hostCaret;if(!r||!o)return{...t,moved:!1};let n=G(r.left,Number.NaN),i=G(r.top,Number.NaN),s=G(o.left,Number.NaN),l=G(o.top,Number.NaN);if(!Number.isFinite(n)||!Number.isFinite(i)||!Number.isFinite(s)||!Number.isFinite(l))return{...t,moved:!1};let a=t.left+(n-s),c=t.top+(i-l);return{left:a,top:c,moved:Math.abs(a-t.left)>=.5||Math.abs(c-t.top)>=.5}}function Rl(e){let t=e.ownerDocument,r=t.getSelection?.()??null,o=r?.focusNode??null;if(!r||!o||!e.contains(o))return null;let n=t.createRange();try{n.setStart(o,r.focusOffset)}catch{return null}n.collapse(!0);let i=n.getBoundingClientRect();return Tl({caret:{left:i.left,top:i.top,height:i.height},line:aw(t,o)})}function aw(e,t){let r=t.nodeType===1?t:t.parentElement;if(!r)return null;let o=e.createRange();try{o.selectNodeContents(r)}catch{return null}let n=o.getBoundingClientRect();if(n.height>0)return{left:n.left,top:n.top,height:n.height};let i=r.getBoundingClientRect();return{left:i.left,top:i.top,height:i.height}}var mw={overlay:{selectionByPage:new Map,caret:null},composing:!1,compositionText:"",compositionHeld:!1,focused:!1,revision:0};function Nl(){let e=globalThis.requestAnimationFrame;return typeof e!="function"?null:{request:t=>{e(()=>{t()})}}}function In(e,t){try{e.reportErrors?.(t)}catch{}}function fw(e,t){return e===t?!0:!e||!t?!1:e.pageNumber===t.pageNumber&&e.left===t.left&&e.top===t.top&&e.height===t.height}var Al=new Map;function Ol(e,t){if(e===t)return!0;if(e.size!==t.size)return!1;for(let[r,o]of e){let n=t.get(r);if(!n||n.length!==o.length)return!1;for(let i=0;i<o.length;i+=1){let s=o[i],l=n[i];if(s.pageNumber!==l.pageNumber||s.left!==l.left||s.top!==l.top||s.height!==l.height||s.width!==l.width)return!1}}return!0}function pw(e,t){return fw(e.caret,t.caret)&&Ol(e.selectionByPage,t.selectionByPage)&&Ol(e.cellSelectionByPage??Al,t.cellSelectionByPage??Al)}function ww(e){let t=mw,r=!1,o="",n=!1,i=!1,s=!1,l=null,a=null,c=!1,u=!1,d=!1,m=null,f=null,g=!1,p=null,b=new Set,w=()=>{let v=e.getEditorHost?.()??null,C=v?.ownerDocument??l?.ownerDocument??null;return dw({activeElement:C?.activeElement??null,editorHost:v,hadEditorFocus:g,focusTarget:p,editorId:e.editorId,windowFocused:C?C.hasFocus()&&C.visibilityState!=="hidden":!0})},y=(v,C=r)=>{let B=w();if(g=uw({hadEditorFocus:g,editorFocused:B.editorFocused,onUiSurface:B.onUiSurface}),!(pw(t.overlay,v)&&C===t.composing&&o===t.compositionText&&n===t.compositionHeld&&B.caretVisible===t.focused)){t={overlay:v,composing:C,compositionText:o,compositionHeld:n,focused:B.caretVisible,revision:t.revision+1};for(let L of[...b])try{L(t)}catch(z){In(e,z)}}},x=()=>{try{return cw({selectionRects:e.editor.selection.getRects(),caretRect:e.editor.selection.getCaretRect(),cellSelectionRects:e.editor.selection.getCellSelectionRects?.()})}catch(v){return In(e,v),t.overlay}},E=kn({getScrollHost:()=>a,getCaretElement:()=>l?.querySelector(`[${Ml}]`)??null}),O=v=>{let C=v.caret;if(!C){f=null;return}let B=`${C.pageNumber}:${C.left}:${C.top}:${C.height}`;B!==f&&(f=B,k())},k=()=>{if(s||u)return;u=!0;let v=()=>{u=!1,!s&&E.reveal()},C=Nl();if(C){C.request(v);return}queueMicrotask(v)},Y=v=>{let B=v.ownerDocument.defaultView?.getComputedStyle(v)??null,L=Number.parseFloat(B?.left??""),z=Number.parseFloat(B?.top??"");return{left:Number.isFinite(L)?L:0,top:Number.isFinite(z)?z:0}},j=()=>{let v=e.getEditorHost?.()??null,C=l;if(!v||!C)return;let B=C.querySelector(`[${Ml}]`),L=B?.offsetParent;if(!B||!L)return;let z=B.offsetHeight,_=B.getBoundingClientRect(),we=L.getBoundingClientRect(),Ke=kl({caret:{left:B.offsetLeft,top:B.offsetTop,height:z},frame:{left:we.left,top:we.top},scale:z>0?_.height/z:1});if(!Ke)return;let Me=Rl(v);if(!Me)return;let Z=Il({anchor:Ke,hostCaret:Me,offset:Y(v)});Z.moved&&(v.style.left=`${Z.left}px`,v.style.top=`${Z.top}px`)},q=()=>{if(s||d)return;d=!0;let v=()=>{if(d=!1,!s)try{j()}catch(B){In(e,B)}},C=Nl();if(C){C.request(v);return}queueMicrotask(v)},W=()=>{q()},re=v=>{m!==v&&(m?.removeEventListener("scroll",W,!0),m?.defaultView?.removeEventListener("resize",W),m=v,v?.addEventListener("scroll",W,!0),v?.defaultView?.addEventListener("resize",W))},I=Tn({getPreviewHost:()=>l,getEditorHost:()=>e.getEditorHost?.()??null,focus:()=>{e.focus?.()},onCompositionChange(v,C){r=v,v?(i=!1,o=C):i?o="":o=C,n=v,y(t.overlay,r),q()},onContextMenu:e.onContextMenu,onFocusChange:v=>{v.phase==="out"&&(r||o!==""||n)&&(r=!1,o="",n=!1,i=!0,y(t.overlay,!1)),p=v.phase==="out"?v.relatedTarget:v.target,$()}}),Ot=v=>{if(o==="")return v;let C=t.overlay.caret;return!C||v.caret===C?v:{...v,caret:C}},qe=()=>{if(c=!1,s)return;let v=Ot(x());y(v),O(v),q()},$=()=>{s||c||(c=!0,queueMicrotask(qe))},Vt=e.editor.selection.subscribe(()=>{$()}),ye=()=>{s||r||o===""&&!n||(i=!0,o="",n=!1,$())},_e=e.editor.preview.subscribeResolvedProjection?.(()=>{!r&&(o!==""||n)&&(o="",n=!1,i=!0),$()})??null;return qe(),{getSnapshot(){return t},subscribe(v){return b.add(v),()=>{b.delete(v)}},attachPreviewHost(v){s||(l=v,I.setPreviewHost(v),I.setEditorHost(e.getEditorHost?.()??null),k(),q(),re(v?.ownerDocument??null))},attachScrollHost(v){s||(a=v,k())},focus(){return I.focus()},reveal(){return E.reveal()},releaseComposition:ye,destroy(){s||(s=!0,u=!1,d=!1,re(null),b.clear(),Vt(),_e?.(),I.destroy(),E.destroy(),l=null,a=null)}}}import{readNodeAtPath as Ww,resolvePathToPosition as Xw}from"@datalking/begonia-document-api/structure";import{resolveLayoutTableBlockMetrics as ea}from"@datalking/begonia-layout-contracts";import{readNodeAtPath as Yl,resolvePathToPosition as $l}from"@datalking/begonia-document-api/structure";import{isDenseArray as Ee}from"@datalking/begonia-document-model/contracts";import{resolveLayoutTableBlockMetrics as Qr}from"@datalking/begonia-layout-contracts";import{resolveMeasuredTextOffsetAtPoint as qw,resolveProjectionTextOffsetAtPoint as _w}from"@datalking/begonia-page-layout";import{buildTableGridModel as Lw,readNodeAtPath as Dw,resolveRectAtLogicalPosition as Hw}from"@datalking/begonia-document-api/structure";import{isDenseArray as Fw}from"@datalking/begonia-document-model/contracts";import{resolveLayoutTableBlockMetrics as Dn,resolveTableCellVerticalOffset as jw}from"@datalking/begonia-layout-contracts";import{PREVIEW_TABLE_CELL_HORIZONTAL_PADDING as Rn,PREVIEW_TABLE_CELL_VERTICAL_PADDING as Mn,resolvePreviewTableCellPadding as Nn}from"@datalking/begonia-layout-renderer";import{readNodeAtPath as gw}from"@datalking/begonia-document-api/structure";import{resolveNodeAnchorPosition as hw}from"@datalking/begonia-doc-service/v1";function bw(e){return e.isBlock&&e.childCount===0}function vw(e,t,r){let o=Math.max(t+1,t+e.nodeSize-1),n=he(e,t,o,r);return n>0?n:bw(e)?1:0}function Sw(e,t,r,o=[]){let n=(i,s)=>{if(i.isTextblock||!i.firstChild?.isBlock){let l=vw(i,s,r);l>0&&o.push({node:i,from:s,flatLength:l});return}i.forEach((l,a)=>{l.isBlock&&n(l,s+a+1)})};return e.forEach((i,s)=>{i.isBlock&&n(i,t+s+1)}),o}function An(e,t,r){let o=T(e),n=gw(e,t),i=hw(e,t);if(!n||i==null)return null;let s=Sw(n,i,o),l=0,a=null;for(let u of s){let d=Math.max(0,Math.min(u.flatLength,r-l)),m=u.node.isLeaf?u.from+u.node.nodeSize:Gt(u.node,u.from,d,o);if(m!=null&&(a=m),r<=l+u.flatLength)return m??a;l+=u.flatLength}let c=Math.max(0,Math.min(r,l));return a??Gt(n,i,c,o)}import{resolveTableFragmentRows as Bw}from"@datalking/begonia-layout-contracts";function On(e,t,r){return e.originRow===t&&e.originColumn===r}function Vl(e,t,r,o){let n=Bw(e);if(!(n[t]??null)?.cells.some(a=>On(a,r,o)))return null;let s=n.find(a=>a.cells.some(c=>On(c,r,o)))??null,l=s?.cells.find(a=>On(a,r,o))??null;return!s||!l?null:{cellLayoutChildIndex:l.physicalIndex,cellLayoutIndex:s.fragmentRowIndex,sourceRowIndex:s.sourceRowIndex}}import{segmentTextGraphemes as Ll}from"@datalking/begonia-layout-contracts";function Ln(e){let t=Math.round(Number(e??1));return Number.isFinite(t)?Math.max(1,t):1}function xt(e){return{from:e,to:e}}function Dl(e,t){return e<=t?{from:e,to:t}:{from:t,to:e}}function rr(e,t){return Math.max(0,Math.min(Math.round(Number(t)||0),e.content.size))}function or(e,t,r,o,n){return nn(e,t,Math.max(0,r),n)??o}function yw(e,t,r){return rr(e,r+Math.max(1,t.nodeSize-1))}function Pw(e,t,r){return Math.max(0,Math.min(r,Math.round(Number(e)||0)-t))}function Cw(e,t,r,o,n){let i=yw(e,t,r);return Gt(t,r,o,n)??i}function Hl(e){return/\s/u.test(e)}function xw(e){return/^[\p{L}\p{N}\p{M}\u200c\u200d'\u2018\u2019_~-]+$/u.test(e)}function Ew(e){return/\p{Extended_Pictographic}/u.test(e)}function kw(e){return/^[\p{P}]+$/u.test(e)}function Tw(e){return/^[\p{S}]+$/u.test(e)}function Vn(e){return Hl(e)?"whitespace":xw(e)?"word":Ew(e)?"emoji":kw(e)?"punctuation":Tw(e)?"symbol":"other"}function Iw(e,t){let r=Ll(e);if(r.length===0)return null;let o=Math.max(0,Math.min(e.length,t)),n=[Math.max(0,Math.min(e.length-1,o)),Math.max(0,Math.min(e.length-1,o-1))],i=new Set;for(let s of n){let l=r.findIndex(a=>a.fromOffset<=s&&s<a.toOffset);if(!(l<0||i.has(l))&&(i.add(l),!Hl(r[l]?.text??"")))return l}return null}function Rw(e,t){let r=Ll(e),o=Iw(e,t);if(o==null)return null;let n=r[o];if(!n)return null;let i=Vn(n.text);if(i==="whitespace")return null;let s=o;for(;s>0&&Vn(r[s-1]?.text??"")===i;)s-=1;let l=o+1;for(;l<r.length&&Vn(r[l]?.text??"")===i;)l+=1;return{start:r[s]?.fromOffset??n.fromOffset,end:r[l-1]?.toOffset??n.toOffset}}function Mw(e,t,r,o){let n=Ne(e,o).length;return n<=0?xt(r):Dl(or(e,t,0,r,o),or(e,t,n,r,o))}function Nw(e,t,r,o,n){let i=Ne(e,n),s=Rw(i,r);return s?Dl(or(e,t,s.start,o,n),or(e,t,s.end,o,n)):xt(o)}function Aw(e,t){let r=rr(e,t),o=e.resolve(r);for(let n=o.depth;n>0;n-=1){let i=o.node(n);if(i.type.name==="table_cell"||i.type.name==="table_header"){let s=Ow(o,n,i);if(s)return s;let l=o.before(n);return{cellFrom:l,cellTo:l+i.nodeSize-1}}}return null}function Ow(e,t,r){if(r.childCount===0)return null;let o=e.start(t),n=e.end(t),i=r.firstChild,s=r.lastChild;if(!i||!s||n<=o)return null;let l=i.isTextblock?o+1:o,a=s.isTextblock?n-1:n;return a<l?null:{cellFrom:l,cellTo:a}}function Vw(e,t){let r=rr(e,t),o=e.resolve(r);for(let n=o.depth;n>0;n-=1){let i=o.node(n);if(i.isTextblock)return{blockNode:i,blockPos:o.before(n)}}return null}function Fl(e,t,r,o,n,i){return n>=3?Mw(e,t,o,i):n===2?Nw(e,t,r,o,i):xt(o)}function Yr(e){let{doc:t,rawPos:r}=e,o=T(t);if(Ln(e.clickCount)>=3){let a=Aw(t,r);if(a)return{from:a.cellFrom,to:a.cellTo}}let n=Vw(t,r);if(!n)return xt(rr(t,r));let i=rr(t,r),s=Math.max(0,he(n.blockNode,n.blockPos,i,o)),l=or(n.blockNode,n.blockPos,s,i,o);return Fl(n.blockNode,n.blockPos,s,l,Ln(e.clickCount),o)}function jl(e){let{doc:t,block:r,rawPos:o}=e,n=T(t);if(!Array.isArray(r.path)||r.path.length===0)return xt(o);let i=J(t,r.path);if(!i?.node.isTextblock)return xt(o);let s=i.node,l=i.position,a=Ne(s,n).length,c=Pw(o,r.from,a),u=Cw(t,s,l,c,n);return Fl(s,l,c,u,Ln(e.clickCount),n)}function Hn(e){let{doc:t,block:r,x:o,y:n}=e;if(r.type!=="table"||!r.path?.length)return null;let i=Dw(t,r.path);if(!i||i.type.name!=="table")return null;let s=Lw(i);if(s.invalidReason||s.rows.length===0||s.width<=0)return null;let l=Jr(r),a=$r(r,l.length);if(a.length===0)return null;let c=ql(i,r,s.width),u=Math.max(0,o-r.left),d=Math.max(0,n-r.top),m=Zr(d,l),f=a[m]??m,g=_l(u,c),p=Hw(s,f,g);if(!p)return null;let b=zw({doc:t,block:r,fragmentRowIndex:m,rowHeights:l,model:s,rect:p});if(!b)return null;let{cellLayoutChildIndex:w,cellLayoutIndex:y,cellPath:x,cellStartPos:E,rowTop:O}=b,k=zn(c,p.originColumn),Y=Ze(c.slice(p.originColumn,p.originColumn+p.colSpan)),j=Dn(r)?.cells?.[y]?.[w]??null,q=Fw(j?.lineSlices)?j.lineSlices:null;if(!q||q.length===0)return{cellPath:x,cellStartPos:E,cellLeft:k,cellWidth:Y,rowTop:O,lineIndex:0,lineCount:1,line:null,cellText:typeof j?.text=="string"?j.text:"",resolvedPos:E,lineTop:0,lineHeight:Math.max(1,N(r.lineHeight)),cellContentTop:0};let W=Nn(Dn(r)?.cellMargins,{vertical:Mn,horizontal:Rn}),re=Math.max(1,N(r.lineHeight)),I=Wl(j,q,re),Ot=Math.max(0,N(l[y])),qe=jw(j?.verticalAlign,Ot,Ze(I)+W.top+W.bottom),$=W.top+qe,Vt=Math.max(0,d-O-$),{lineIndex:ye,lineTop:_e}=Xl(I,Vt),v=q[ye]??null,C=Math.max(1,I[ye]??re);if(!v)return{cellPath:x,cellStartPos:E,cellLeft:k,cellWidth:Y,rowTop:O,lineIndex:ye,lineCount:Math.max(1,q.length),line:null,cellText:typeof j?.text=="string"?j.text:"",resolvedPos:E,lineTop:_e,lineHeight:C,cellContentTop:$};let B=Ul({block:r,cellLayout:j,height:C,line:v,lineCount:Math.max(1,q.length),lineIndex:ye,left:r.left+k+W.left,top:r.top+O+$+_e,width:Math.max(0,Y-W.left-W.right),x:o,measureText:e.measureText,measurementEpoch:e.measurementEpoch});return{cellPath:x,cellStartPos:E,cellLeft:k,cellWidth:Y,rowTop:O,lineIndex:ye,lineCount:Math.max(1,q.length),line:v,cellText:typeof j?.text=="string"?j.text:"",resolvedPos:An(t,x,B)??E,lineTop:_e,lineHeight:C,cellContentTop:$}}function zw(e){let{doc:t,block:r,fragmentRowIndex:o,rowHeights:n,model:i,rect:s}=e;if(!Array.isArray(r.path)||r.path.length===0)return null;let l=Vl(r,o,s.originRow,s.originColumn);if(!l)return null;let a=i.physicalRows[l.sourceRowIndex]?.find(d=>d.rect===s)??null;if(!a)return null;let c=[...r.path,l.sourceRowIndex,a.childIndex],u=Kl(t,c);return u==null?null:{cellLayoutChildIndex:l.cellLayoutChildIndex,cellLayoutIndex:l.cellLayoutIndex,cellPath:c,cellStartPos:u,rowTop:zn(n,l.cellLayoutIndex)}}function zl(e,t,r,o){return An(e,t,r)??o}function Fn(e){let t=Gl(e);return t==null?null:Yr({doc:e.doc,rawPos:t,clickCount:e.clickCount})}function jn(e){let t=Hn(e);if(!t)return null;let r=Nn(Dn(e.block)?.cellMargins,{vertical:Mn,horizontal:Rn}),{cellPath:o,cellLeft:n,cellStartPos:i,cellText:s,cellWidth:l,line:a,lineCount:c,lineIndex:u,resolvedPos:d,rowTop:m,lineTop:f,lineHeight:g,cellContentTop:p}=t,b=a?zl(e.doc,o,a.fromOffset,i):d,w=a?zl(e.doc,o,a.toOffset,d):d,y=Math.max(0,p-r.top),x=a?.text??s,E=Math.max(1,g||N(e.block.lineHeight)||N(e.hit.height)||1);return{...e.hit,lineIndex:u,lineCount:c,from:Math.min(b,w),to:Math.max(b,w),left:e.block.left+n+r.left,top:e.block.top+m+r.top+y+f,width:Math.max(0,l-r.left-r.right),height:E,text:x,label:x.trim()||e.hit.label,pos:d}}function N(e){try{let t=Number(e);return Number.isFinite(t)&&t>0?t:0}catch{return 0}}function Kw(e){try{let t=Number(e);return Number.isSafeInteger(t)&&t>=0?t:null}catch{return null}}function Ze(e){if(!Ee(e))return 0;let t=0;for(let r of e)t+=N(r);return t}function zn(e,t){if(!Ee(e))return 0;let r=Math.min(e.length,Math.max(0,Math.floor(t))),o=0;for(let n=0;n<r;n+=1)o+=N(e[n]);return o}function $r(e,t){let r=Qr(e)?.rowSourceIndexes,o=Array.isArray(r)&&Ee(r)?r:null;return Array.from({length:t},(n,i)=>Kw(o?.[i])??i)}function Uw(e,t){let r=Array.from({length:t},()=>0);return e.forEach(o=>{let n=0;o.forEach(i=>{let s=Math.max(1,Math.round(N(i.attrs.colSpan)||1)),l=N(i.attrs.width),a=l>0?l/s:0;for(let c=0;c<s;c+=1){let u=n+c;u<r.length&&(r[u]=Math.max(r[u]??0,a))}n+=s})}),r}function ql(e,t,r){let o=Qr(t)?.columnWidths,n=Array.isArray(o)&&Ee(o)?o.map(l=>N(l)):Array.isArray(e.attrs.columnWidths)&&Ee(e.attrs.columnWidths)?e.attrs.columnWidths.map(l=>N(l)):[],i=Uw(e,r),s=Math.max(24,(N(Qr(t)?.width)||N(t.width)||Ze(n)||Ze(i)||r*96)/Math.max(1,r));return Array.from({length:r},(l,a)=>{let c=n[a]??0,u=i[a]??0;return Math.max(24,c||u||s)})}function Zr(e,t){if(t.length===0)return 0;let r=0;for(let o=0;o<t.length;o+=1){let n=Math.max(1,N(t[o])||1);if(e<r+n)return o;r+=n}return t.length-1}function _l(e,t){if(t.length===0)return 0;let r=0;for(let o=0;o<t.length;o+=1){let n=Math.max(1,N(t[o])||1);if(e<r+n)return o;r+=n}return t.length-1}function Jr(e){let t=Qr(e)?.rowHeights;return Ee(t)?t.map(r=>Math.max(1,N(r)||1)):[]}function Zl(e,t){if(e.isTextblock)return[...t];for(let r=0;r<e.childCount;r+=1){let o=e.child(r),n=[...t,r],i=Zl(o,n);if(i)return i}return null}function Kl(e,t){let r=Yl(e,t);if(!r)return null;let o=Zl(r,t);if(o){let i=$l(e,o);return i==null?null:Yl(e,o)?.content.size===0?i:i+1}let n=$l(e,t);return n==null?null:n+1}function Ul(e){let{block:t,cellLayout:r,height:o,hit:n,left:i,line:s,lineCount:l,lineIndex:a,measureText:c,measurementEpoch:u,top:d,width:m,x:f}=e,g=Ql(Jl(r),s.fromOffset),p={pageNumber:n?.pageNumber??0,sectionIndex:n?.sectionIndex??0,sectionPageNumber:n?.sectionPageNumber??0,sectionId:n?.sectionId??null,region:n?.region??"body",blockIndex:n?.blockIndex??t.index,fragmentIndex:n?.fragmentIndex??0,columnIndex:n?.columnIndex??0,lineIndex:a,lineCount:l,from:s.fromOffset,to:s.toOffset,left:i,top:d,width:m,height:o,text:s.text,logicalText:s.text,nodeType:g?.nodeType??n?.nodeType??"table_cell",align:n?.align??t.align??null,direction:n?.direction??t.direction??null,fontSize:g?.fontSize??n?.fontSize??t.fontSize??null,tabs:g?.tabs??null,inlineSpans:g?.inlineSpans??r.inlineSpans??n?.inlineSpans??null,continuesToNext:n?.continuesToNext??!1,label:s.text},b=c?qw(p,f,c,u):_w(p,f);return Math.max(s.fromOffset,Math.min(s.toOffset,b))}function Wl(e,t,r){let o=e.lineHeights,n=Jl(e);return t.map((i,s)=>{let l=N(i.lineHeight);if(l>0)return l;let a=Ee(o)?N(o[s]):0;if(a>0)return a;let c=Ql(n,i.fromOffset),u=N(c?.lineHeight);return u>0?u:r})}function Jl(e){let t=Ee(e.segments)?e.segments:[],r=0;return t.map(o=>{let n={segment:o,fromOffset:r,toOffset:r+o.text.length};return r=n.toOffset,n})}function Ql(e,t){return e.find(r=>t<r.toOffset||r.segment.text.length===0&&t===r.fromOffset)?.segment??null}function Xl(e,t){if(!Ee(e)||e.length===0)return{lineIndex:0,lineTop:0};let r=N(t),o=0;for(let n=0;n<e.length;n+=1){let i=Math.max(1,N(e[n])||1);if(r<o+i||n===e.length-1)return{lineIndex:n,lineTop:o};o+=i}return{lineIndex:0,lineTop:0}}function Gl(e){return Hn(e)?.resolvedPos??null}function qn(e){let{block:t,doc:r,x:o,y:n}=e;if(t.type!=="table"||!Array.isArray(t.path)||t.path.length!==1)return null;let i=Ww(r,t.path);if(!i||i.type.name!=="table"||i.childCount===0)return null;let s=Jr(t);if(s.length===0)return null;let l=$r(t,s.length);if(l.length===0||n<t.top)return null;let a=Math.max(0,n-t.top),c=Zr(a,s);if((l[c]??c)!==i.childCount-1)return null;let d=N(ea(t)?.width)||Ze(ea(t)?.columnWidths??[])||N(t.width);if(d<=0||o<=t.left+d)return null;let m=Xw(r,t.path);return m==null?null:nr(r,m-1)}function nr(e,t){let r=e.nodeAt(t);if(!r||r.type.name!=="table")return null;let o=t+r.nodeSize;return e.resolve(o).nodeAfter?.isTextblock?{caretPos:o+1,insertAt:null}:{caretPos:o+1,insertAt:o}}function eo(e,t){if(t.childCount===0)return null;let r=t.child(t.childCount-1);if(r.childCount===0)return null;let o=r.child(r.childCount-1),n=e+1;for(let i=0;i<t.childCount-1;i+=1)n+=t.child(i).nodeSize;n+=1;for(let i=0;i<r.childCount-1;i+=1)n+=r.child(i).nodeSize;return ir(n,o)}function ir(e,t){if(t.isTextblock)return e+1+t.content.size;let r=[],o=e+1;for(let n=0;n<t.childCount;n+=1)r.push(o),o+=t.child(n).nodeSize;for(let n=t.childCount-1;n>=0;n-=1){let i=ir(r[n]??o,t.child(n));if(i!=null)return i}return null}function ta(e,t){let r=e.resolve(t);for(let o=r.depth;o>0;o-=1){let n=r.node(o);if(n.type.name!=="table")continue;let i=r.before(o);if(e.resolve(i).parent.type.name!=="doc")return null;let s=-1;for(let a=o+1;a<=r.depth;a+=1)if(r.node(a).type.name==="table_row"){s=a;break}if(s<0)return null;let l=r.index(o);return{table:n,tablePos:i,tableEnd:i+n.nodeSize,rowIndex:l,isLastRow:l===n.childCount-1}}return null}function Gw(e,t){let r=e.resolve(t);for(let o=r.depth;o>0;o-=1)if(r.node(o).type.name==="table_cell")return{cellPos:r.before(o),cell:r.node(o)};return null}function Yw(e){let t=ta(e.doc,e.from);if(!t||!t.isLastRow)return null;let r=eo(t.tablePos,t.table);if(r==null||e.from!==r)return null;let o=nr(e.doc,t.tablePos);return o?o.insertAt!=null?{pos:null,preventDefault:!0}:{pos:o.caretPos,preventDefault:!0}:null}function $w(e){let t=ta(e.doc,e.from);if(!t||!t.isLastRow)return null;let r=e.doc.resolve(e.from);if(!r.parent.isTextblock||r.parentOffset!==r.parent.content.size)return null;let o=Gw(e.doc,e.from);if(!o)return null;let n=ir(o.cellPos,o.cell);if(n==null||e.from!==n)return null;let i=nr(e.doc,t.tablePos);if(!i)return null;if(i.insertAt!=null)return{pos:null,preventDefault:!0};let s=e.doc.resolve(t.tableEnd).nodeAfter;return s?.isTextblock&&s.content.size===0?{pos:i.caretPos,preventDefault:!0}:null}function Zw(e){let t=e.doc.resolve(e.from);if(t.depth!==1||!t.parent.isTextblock||t.parentOffset!==0)return null;let r=t.index(0);if(r<=0)return null;let o=e.doc.child(r-1);if(o.type.name!=="table")return null;let n=t.before(1),i=eo(n-o.nodeSize,o);return i==null?null:{pos:i,preventDefault:!0}}function _n(e){return e.from!==e.to||e.shiftKey||e.altKey||e.ctrlKey||e.metaKey?null:e.key==="ArrowRight"?Yw(e):e.key==="ArrowDown"?$w(e):e.key==="ArrowLeft"?Zw(e):null}function Jw(e){let t=e.ownerDocument??e.getView()?.dom.ownerDocument??null;if(!t)return()=>{};let r=o=>{if(o.defaultPrevented||o.isComposing||o.keyCode===229)return;let n=e.getView();if(!n||!n.hasFocus())return;let i=_n({doc:n.state.doc,from:n.state.selection.from,to:n.state.selection.to,key:o.key,shiftKey:o.shiftKey,altKey:o.altKey,ctrlKey:o.ctrlKey,metaKey:o.metaKey});if(!i||(o.preventDefault(),i.pos==null))return;let s=M(n.state,i.pos);s&&n.dispatch(n.state.tr.setSelection(s))};return t.addEventListener("keydown",r,!0),()=>t.removeEventListener("keydown",r,!0)}import{isProjectionMultiColumnAtPosition as Qw}from"@datalking/begonia-page-layout";function eg(e){let t=e.ownerDocument??e.getView()?.dom.ownerDocument??null;if(!t)return()=>{};let r=o=>{if(o.defaultPrevented||o.isComposing||o.keyCode===229||o.altKey||o.ctrlKey||o.metaKey||o.key!=="ArrowUp"&&o.key!=="ArrowDown")return;let n=e.getView();if(!n||!n.hasFocus())return;let i=e.getProjection();if(!i)return;let s=e.getMeasurement?.()??null,l=n.state.selection;if(!Qw(i,l.head,{measureText:s?.measureText,measurementEpoch:s?.measurementEpoch}))return;let a=En({projection:i,anchor:l.anchor,head:l.head,key:o.key,shiftKey:o.shiftKey,measureText:s?.measureText,measurementEpoch:s?.measurementEpoch});if(!a)return;o.preventDefault();let c=M(n.state,a.anchor,a.head);c&&n.dispatch(n.state.tr.setSelection(c))};return t.addEventListener("keydown",r,!0),()=>t.removeEventListener("keydown",r,!0)}var tg=new Map([["z","undo"],["y","redo"]]);function rg(e){if(!e||typeof e!="object")return!1;let t=e,r=typeof t.tagName=="string"?t.tagName.toUpperCase():"";if(r==="TEXTAREA"||r==="SELECT")return!0;if(r==="INPUT"){if(t.readOnly===!0||t.disabled===!0)return!1;let o=typeof t.type=="string"?t.type.toLowerCase():"text";return o!=="button"&&o!=="checkbox"&&o!=="radio"}return t.isContentEditable===!0}function og(e){if(!e||e.isComposing===!0||e.defaultPrevented===!0||e.altKey===!0||e.ctrlKey!==!0&&e.metaKey!==!0)return null;let t=typeof e.key=="string"?e.key.toLowerCase():"",r=t.length===1?t:"";if(r.length===0||rg(e.target))return null;let o=tg.get(r);return o?o==="undo"?e.shiftKey===!0?"redo":"undo":e.shiftKey===!0?null:"redo":null}function ra(e,t){let r=t.readEffectiveSelection();return{selectionCapture:r,resolvedSelectionCapture:r,stale:!1}}function sr(e,t,r){if(!r)return{selectionCapture:null,resolvedSelectionCapture:null,stale:!1};let o=t.readSelectionCapture(r);return o?{selectionCapture:r,resolvedSelectionCapture:o,stale:!1}:{selectionCapture:r,resolvedSelectionCapture:null,stale:!0}}function ng(e,t){return e.selectionCapture?sr(e,t,e.selectionCapture):e.pointSelectionCapture?sr(e,t,e.pointSelectionCapture):ra(e,t)}function ig(e,t){let r=e.actionSelectionCapture??e.selectionCapture??null;if(!r)return e.pointSelectionCapture?{...sr(e,t,e.pointSelectionCapture),restoreSelection:!1}:{...ra(e,t),restoreSelection:!1};let o=sr(e,t,r);return e.pointSelectionCapture===r?{...o,restoreSelection:!1}:o.resolvedSelectionCapture&&!o.resolvedSelectionCapture.selection.empty?{...o,restoreSelection:!0}:e.pointSelectionCapture&&e.pointSelectionCapture!==r?{...sr(e,t,e.pointSelectionCapture),restoreSelection:!1}:{...o,restoreSelection:!0}}function Kn(e,t){let r=t??e.controller;if(!r)throw new Error("Browser context-menu selection policy requires a selection controller.");return{effectiveSelection:ng(e,r),actionSelection:ig(e,r)}}import{createSelectionTrackingBookmark as bg}from"@datalking/begonia-engine";import{NodeSelection as so}from"prosemirror-state";import{readPreservedSelection as RE}from"@datalking/begonia-engine";import{NodeSelection as fg}from"prosemirror-state";import{DELETION_MARK_NAME as sg}from"@datalking/begonia-engine";import{isDocumentNodePathIndex as lg}from"@datalking/begonia-document-model";function to(e){return typeof e=="string"&&e.trim().length>0?e.trim():null}function U(e){return t=>to(t.attrs[e])}function oa(...e){return t=>{for(let r of e){let o=to(t.attrs[r]);if(o)return o}return null}}function Un(e){let t=to(e.attrs.threadId);return t?`${t}\0${to(e.attrs.entryId)??t}`:null}function na(){return null}function ia(e){return e==="paragraph"||e==="heading"}function lr(e,t){return e===t||ia(e)&&ia(t)}var la=Object.freeze({bookmark_anchor:U("bookmarkId"),bookmark_end:U("bookmarkId"),comment_anchor:Un,comment_range_end:Un,comment_range_start:Un,column_break:U("columnBreakId"),endnote_reference:U("noteId"),heading:oa("paraId","sdBlockId","captionId"),horizontal_rule:na,image:U("imageId"),inline_ooxml_drawing:U("objectId"),ooxml_chart:U("objectId"),ooxml_math:U("objectId"),ooxml_shape:U("objectId"),page_break:U("pageBreakId"),paragraph:oa("paraId","sdBlockId","captionId"),footnote_reference:U("noteId"),permission_range_end:U("rangeId"),permission_range_start:U("rangeId"),section_break:U("sectionId"),table:na,template_block:U("fieldId"),template_field:U("fieldId")});function ag(e){let t=2166136261;for(let r=0;r<e.length;r+=1)t^=e.charCodeAt(r),t=Math.imul(t,16777619);return(t>>>0).toString(16).padStart(8,"0")}function Je(e){try{return ag(JSON.stringify(e.toJSON()))}catch{return null}}function aa(e,t){let r=e,o=-1;for(let n of t){if(!lg(n)||n>=r.childCount)return null;o+=1;for(let i=0;i<n;i+=1)o+=r.child(i).nodeSize;r=r.child(n)}return{node:r,position:o}}function cg(e,t,r,o,n,i){if(i==null)return null;let s=!1,l=!1;return e.descendants((a,c)=>c===o||!lr(a.type.name,t)||n(a)!==r?!0:(s=!0,Je(a)===i?(l=!0,!1):!0)),s&&!l?i:null}function sa(e,t,r){let o=aa(e,t.path);return!o||!lr(o.node.type.name,t.nodeType)||r(o.node)!==t.stableIdentity||t.nodeFingerprint!=null&&Je(o.node)!==t.nodeFingerprint?null:o}function ug(e,t,r){let o=[];return e.descendants((n,i)=>(lr(n.type.name,t.nodeType)&&r(n)===t.stableIdentity&&o.push({node:n,position:i}),!0)),o}function dg(e,t){return t.nodeFingerprint==null?[]:e.filter(r=>Je(r.node)===t.nodeFingerprint)}function ca(e){return!!e?.node.marks.some(t=>t.type.name===sg)}function mg(e){return e.filter(t=>!ca(t))}function Le(e){let t=e?.selection;if(!e||!R(t))return null;let r=t.node.type.name,o=r?la[r]:null;if(!r||!o)return null;let n=o(t.node),i=[];for(let a=0;a<t.$from.depth;a+=1)i.push(t.$from.index(a));i.push(t.$from.index(t.$from.depth));let s=Je(t.node),l=n?cg(e.doc,r,n,t.from,o,s):s;return{kind:"node",nodeType:r,stableIdentity:n,path:i,...l!=null?{nodeFingerprint:l}:{}}}function ua(e,t){let r=la[t.nodeType];if(t.stableIdentity&&r){let i=ug(e,t,r);if(i.length===0)return null;if(i.length===1){let a=i[0];return t.nodeFingerprint==null||sa(e,t,r)?.position===a.position||Je(a.node)===t.nodeFingerprint?a:null}let s=sa(e,t,r);if(t.nodeFingerprint==null){if(!ca(s))return s;let a=mg(i);return a.length===1?a[0]:s}let l=dg(i,t);return l.length!==1?null:s?.position===l[0]?.position?s:null}let o=aa(e,t.path);if(o!=null&&lr(o.node.type.name,t.nodeType)&&(t.nodeFingerprint==null||Je(o.node)===t.nodeFingerprint))return o;if(t.nodeFingerprint==null)return null;let n=[];return e.descendants((i,s)=>(lr(i.type.name,t.nodeType)&&Je(i)===t.nodeFingerprint&&n.push({node:i,position:s}),n.length<=1)),n.length===1?n[0]:null}function ro(e){return e.anchor!=null&&e.head!=null&&e.anchor>e.head?"backward":"forward"}function oo(e,t){let r=Math.min(e.from,e.to),o=Math.max(e.from,e.to);return t==="backward"?{anchor:o,head:r}:{anchor:r,head:o}}function no(e,t){if(!t)return null;let r=ua(e.doc,t);if(!r)return null;try{return e.apply(e.tr.setSelection(fg.create(e.doc,r.position)))}catch{return null}}function pg(e,t){if(!t.selectionTarget||!t.segmentTexts||t.selectionTarget.segments.length!==t.segmentTexts.length)return null;let r=t.selectionTarget.segments.map((o,n)=>Wt(e.doc,{kind:"text",segments:[o]},t.segmentTexts?.[n]??null,{strict:!0}));return r.every(o=>o!=null)?r:null}function wg(e,t){let r=pg(e,t);if(!r||r.length===0)return null;let o=r[0].from,n=r[0].to;for(let i of r.slice(1)){if(!i||i.from<n)return null;n=Math.max(n,i.to)}return{from:o,to:n}}function da(e,t){return t.selectionTarget?Xo(e.doc,t.selectionTarget,t.segmentTexts??null,{strict:!0})??Wt(e.doc,t.selectionTarget,t.text??null,{strict:!0})??wg(e,t):null}function io(e){return Math.max(0,Math.abs(e.to-e.from))}function gg(e,t,r){let o=ae([...ae(t.activeChangeIds),...ae(t.selection.trackedChangeIds)]);return t.selectionKind==="text"&&!t.selection.empty&&o.length>0&&io(t.selection)>0&&(io(r??{from:0,to:0})===0||(()=>{if(!r)return!1;let n=lo(e,t);return!n||n.empty||io(n)<=io(r)?!1:ge(e.doc,e.schema,n)===ge(e.doc,e.schema,r)})())}function lo(e,t){if(t.selectionKind==="node"){let o=Lr(e.doc,Math.min(t.selection.from,t.selection.to)),n=e.doc.nodeAt(o);if(n&&so.isSelectable(n))try{return so.create(e.doc,o)}catch{}}let r=oo(t.selection,ro(t.selection));return M(e,Xe(e.doc,r.anchor),Xe(e.doc,r.head))}function ma(e,t,r,o){if(r==="node"){let i=Lr(e.doc,Math.min(t.from,t.to)),s=e.doc.nodeAt(i);if(s&&so.isSelectable(s))try{return so.create(e.doc,i)}catch{return null}}let n=oo(t,o);return M(e,Xe(e.doc,n.anchor),Xe(e.doc,n.head))}function hg(e,t){let r=no(e,t.nodeSelectionTarget)?.selection;if(R(r))return r;let o=da(e,t);if(o){let i=ma(e,o,t.selectionKind,ro(t.selection));if(R(i))return i}let n=lo(e,t);return R(n)?n:null}function fa(e,t){if(t.selectionKind==="node")return hg(e.state,t);let r=da(e.state,t);return r?gg(e.state,t,r)?lo(e.state,t):ma(e.state,r,t.selectionKind,ro(t.selection)):lo(e.state,t)}function vg(e,t,r){return M(e,t,r)}function Sg(e){let t=e;return(t.selectionKind==="text"||t.selectionKind==="node")&&"selectionTarget"in e&&"nodeSelectionTarget"in e&&(t.selectionKind==="node"||typeof t.text=="string"||Array.isArray(t.segmentTexts)||Array.isArray(t.activeChangeIds))}function Bg(e,t){if(Sg(t))return fa({state:e},t);let r=Math.min(t.selection.from,t.selection.to),o=Math.max(t.selection.from,t.selection.to);return vg(e,r,o)}function yg(e){let t=e.view;return t?.state&&typeof t.dispatch=="function"?t:null}function De(e,t,r,o={}){let n=yg(e);if(!n)return!1;if(!t)return r(e);let i=o.restoreSelection??!0,s=n.state.selection,l=Bg(n.state,t);if(!l||Dr(s,l))return r(e);let c=bg(s),u=n.dispatch.bind(n);n.dispatch=(d=>{if(d.docChanged&&c)try{c=c.map(d.mapping)}catch{c=null}return u(d)});try{try{n.dispatch(n.state.tr.setSelection(l))}catch{return r(e)}return r(e)}finally{if(n.dispatch=u,i&&c)try{let d=c.resolve(n.state.doc);if(d){let m=pt(n.state,d);m&&n.dispatch(n.state.tr.setSelection(m))}}catch{}}}function Wn(e){return e.split(/\r?\n/).map(t=>t.trim()).filter(t=>t.length>0)}function Et(e){return typeof e=="object"&&e!==null}function Xn(e){return typeof e=="string"?e.trim()?e:null:!Et(e)||typeof e.text!="string"?null:{text:e.text,displayMode:e.displayMode==="block"?"block":e.displayMode==="inline"?"inline":void 0}}function pa(e){return typeof e=="string"?e.trim()?e:null:!Et(e)||typeof e.title!="string"?null:{title:e.title}}function wa(e){return typeof e=="string"?e.trim()?e:null:!Et(e)||typeof e.color!="string"?null:{color:e.color,kind:e.kind==="solid"||e.kind==="scheme"||e.kind==="none"||e.kind==="unknown"?e.kind:void 0}}function ga(e,t=0){if(typeof e=="string")return{id:null,name:e.trim()||`Series ${t+1}`,categories:[],values:[],color:null};if(!Et(e))return{id:null,name:`Series ${t+1}`,categories:[],values:[],color:null};let r=Array.isArray(e.categories)?e.categories.filter(n=>typeof n=="string"):[],o=Array.isArray(e.values)?e.values.map(n=>typeof n=="number"&&Number.isFinite(n)?n:null):[];return{id:typeof e.id=="string"?e.id:null,name:typeof e.name=="string"?e.name:`Series ${t+1}`,categories:r,values:o,color:typeof e.color=="string"?e.color:null}}function ha(e,t=0){return typeof e=="string"?{id:null,kind:"category",title:e.trim()||`Axis ${t+1}`,formatCode:null}:Et(e)?{id:typeof e.id=="string"?e.id:null,kind:e.kind==="category"||e.kind==="value"||e.kind==="series"||e.kind==="date"?e.kind:"category",title:typeof e.title=="string"?e.title:`Axis ${t+1}`,formatCode:typeof e.formatCode=="string"?e.formatCode:null}:{id:null,kind:"category",title:`Axis ${t+1}`,formatCode:null}}function ba(e,t=0){if(typeof e=="string"){let o=e.trim()||`Child ${t+1}`;return{parentId:null,child:{label:o,kind:"shape",text:o,shapeType:"shape"}}}if(!Et(e)){let o=`Child ${t+1}`;return{parentId:null,child:{label:o,kind:"shape",text:o,shapeType:"shape"}}}let r=typeof e.label=="string"&&e.label.trim()?e.label.trim():`Child ${t+1}`;return{parentId:typeof e.parentId=="string"&&e.parentId.trim()?e.parentId:null,child:{label:r,kind:e.kind==="shape"||e.kind==="group"||e.kind==="textBox"||e.kind==="connector"||e.kind==="picture"||e.kind==="wordArt"?e.kind:"shape",text:typeof e.text=="string"?e.text:r,shapeType:typeof e.shapeType=="string"?e.shapeType:"shape"}}}function ie(e){return e?e.surface??null:null}function ao(e){if(!e)return null;try{return e.surface??null}catch{return null}}function H(e){let t=ie(e);if(!t)throw new Error("Browser editor surface is not available on this controller.");return t}function Pg(e,t=!0){return{ok:!0,changed:t,value:e}}function se(e){return{ok:!1,changed:!1,reason:e}}function me(e){return e&&typeof e=="object"&&"reason"in e&&typeof e.reason=="string"?se(e.reason):Pg(e)}function ar(e){return typeof e=="object"&&e!==null}function Cg(e){return e==="block"?"block":"inline"}function Gn(e){return{chartType:"barChart",styleId:null,styleSource:null,title:e,subtitle:null,series:[],axes:[],legend:null,plotArea:null,textBody:{paragraphs:[e],plainText:e}}}function Yn(e){return{shapeType:"shape",label:e,textBody:{paragraphs:[e],plainText:e},geometry:null,transform:null,groupTransform:null,fill:null,stroke:null,anchor:null,connector:null,picture:null,wordArt:null,childCount:0,children:[],groupKind:null,isWatermark:null}}function xg(e,t){return{id:e.id??null,order:t,name:e.name??`Series ${t+1}`,categories:e.categories??[],values:e.values??[],color:e.color??null,marker:null,dataLabels:null,smooth:null,explosion:null}}function Eg(e,t){return{id:e.id??null,kind:e.kind??"category",title:e.title??`Axis ${t+1}`,formatCode:e.formatCode??null,orientation:null,visible:null,minimum:null,maximum:null,majorUnit:null,minorUnit:null,crossesAt:null,majorGridlines:null,minorGridlines:null}}function kg(e,t){let r=e.text?.trim()||e.label?.trim()||`Child ${t+1}`;return{kind:e.kind??"shape",id:null,label:e.label??r,textBody:{paragraphs:Wn(r),plainText:r},geometry:e.shapeType?{preset:e.shapeType,customPathCount:null,adjustments:[]}:null,transform:null,groupTransform:null,fill:null,stroke:null,connector:e.kind==="connector"?{connectorType:e.shapeType??null,beginShapeId:null,endShapeId:null}:null,picture:null,wordArt:e.kind==="wordArt"?{text:r,preset:e.shapeType??null}:null,children:[]}}function Tg(e){if(typeof e=="string"){let r=e.trim();return r?{text:r,displayMode:"inline",label:null}:null}if(!ar(e)||typeof e.text!="string")return null;let t=e.text.trim();return t?{text:t,displayMode:e.displayMode==="block"?"block":"inline",label:typeof e.label=="string"?e.label:null}:null}function Ig(e){if(typeof e=="string"){let o=e.trim()||"Chart";return{model:Gn(o),options:{label:o}}}if(!ar(e))return{model:Gn("Chart"),options:{label:"Chart"}};let t=typeof e.title=="string"&&e.title.trim()?e.title.trim():"Chart";return{model:ar(e.model)?e.model:Gn(t),options:{label:typeof e.label=="string"?e.label:t,objectId:typeof e.objectId=="string"?e.objectId:void 0}}}function Rg(e){if(typeof e=="string"){let o=e.trim()||"Shape";return{model:Yn(o),options:{label:o}}}if(!ar(e))return{model:Yn("Shape"),options:{label:"Shape"}};let t=typeof e.label=="string"&&e.label.trim()?e.label.trim():"Shape";return{model:ar(e.model)?e.model:Yn(t),options:{label:t,objectId:typeof e.objectId=="string"?e.objectId:void 0}}}function va(e){let t=e.getState().advancedOoxml.selected;return t?.family==="chart"?e.documentApi.ooxml.charts.getById(t.objectId):null}function Mg(e){let t=e.getState().advancedOoxml.selected;return t?.family==="math"?e.documentApi.ooxml.math.getById(t.objectId):null}function Ng(e){let t=e.getState().advancedOoxml.selected;return t?.family==="shape"?e.documentApi.ooxml.shapes.getById(t.objectId):null}function Sa(e,t,r){let o=H(e);switch(t){case"insert-math-inline":{let n=Tg(r);if(!n)return se("Expected inline math text for advanced OOXML insertion.");let i=e.documentApi.ooxml.math.createModelFromText(n.text,n.displayMode),s=o.trackingEnabled?e.appendMathToCurrentTextblockTracked(i,{source:"browser-ooxml"},{label:n.label??n.text}):e.appendMathToCurrentTextblock(i,{label:n.label??n.text});return me(s)}case"insert-chart-block":{let n=Ig(r),i=o.trackingEnabled?e.insertChartAfterCurrentBlockTracked(n.model,{source:"browser-ooxml"},n.options):e.insertChartAfterCurrentBlock(n.model,n.options);return me(i)}case"insert-shape-block":{let n=Rg(r),i=o.trackingEnabled?e.insertShapeAfterCurrentBlockTracked(n.model,{source:"browser-ooxml"},n.options):e.insertShapeAfterCurrentBlock(n.model,n.options);return me(i)}case"remove-selected-ooxml":return me(e.removeSelectedAdvancedOoxml());case"selected-math-set-plain-text":{let n=Xn(r);if(!n)return se("Expected math plain text for the selected OOXML equation.");let i=typeof n=="string"?e.setSelectedMathPlainText(n):e.setSelectedMathPlainText(n.text,n.displayMode);return me(i)}case"selected-math-toggle-display-mode":{let n=Mg(e);if(!n)return se("No advanced OOXML math node is selected.");let i=Cg(n.familyData?.displayMode)==="block"?"inline":"block";return me(e.setSelectedMathDisplayMode(i))}case"selected-chart-set-title":{let n=pa(r);return n?me(e.setSelectedChartTitle(typeof n=="string"?n:n.title)):se("Expected a chart title for the selected OOXML chart.")}case"selected-chart-add-series":{let n=va(e);if(!n)return se("No advanced OOXML chart node is selected.");let i=ga(r,n.familyData?.model?.series.length??0);return i?me(e.appendSelectedChartSeries(xg(i,n.familyData?.model?.series.length??0))):se("Expected a series payload for the selected OOXML chart.")}case"selected-chart-add-axis":{let n=va(e);if(!n)return se("No advanced OOXML chart node is selected.");let i=ha(r,n.familyData?.model?.axes.length??0);return i?me(e.appendSelectedChartAxis(Eg(i,n.familyData?.model?.axes.length??0))):se("Expected an axis payload for the selected OOXML chart.")}case"selected-shape-set-text-body":{let n=Xn(r);if(!n)return se("Expected replacement text for the selected OOXML shape.");let i=typeof n=="string"?n:n.text;return me(e.setSelectedShapeTextBody(Wn(i)))}case"selected-shape-set-fill":{let n=wa(r);if(!n)return se("Expected a fill color for the selected OOXML shape.");let i=e.setSelectedShapeFill(typeof n=="string"?{kind:"solid",color:n.trim()||null,secondaryColor:null,opacity:null}:{kind:n.kind??"solid",color:n.color.trim()||null,secondaryColor:null,opacity:null});return me(i)}case"selected-shape-add-child":{let n=Ng(e);if(!n)return se("No advanced OOXML shape node is selected.");let i=ba(r,n.familyData?.model?.children.length??0);if(!i)return se("Expected a child payload for the selected OOXML shape.");let s=kg(i.child,n.familyData?.model?.children.length??0);return me(i.parentId?e.appendSelectedShapeChildToParent(i.parentId,s):e.appendSelectedShapeChild(s))}default:return null}}function Ag(e){let t=e.documentApi?.images;if(!t?.list)return[];let r=t.list({});return Array.isArray(r)?r:r?.items??[]}function Og(e,t){return Ag(e).find(r=>r.id===t)??null}function ve(e,t=null){return{ok:e,changed:e,reason:t}}function Vg(e,t,r){let o=e.documentApi?.images;if(!o?.setSize)return ve(!1,"This host cannot resize images.");let n=Og(e,t);if(!n)return ve(!1,"No image with that id is in the document.");let i=co(r.width),s=co(r.height);if(i==null&&s==null)return ve(!1,"Expected a positive width or height.");let l=co(n.width),a=co(n.height),c=i,u=s;if(c!=null&&u==null){if(l==null||a==null)return ve(!1,"The image has no stored size to keep its proportions.");u=Math.round(c*a/l)}else if(u!=null&&c==null){if(l==null||a==null)return ve(!1,"The image has no stored size to keep its proportions.");c=Math.round(u*l/a)}if(c==null||u==null)return ve(!1,"Expected a positive width or height.");let d=r.unit==="pt"||r.unit==="twip"?r.unit:"px",m=o.setSize(t,{width:c,height:u,unit:d});return m?.success===!1?ve(!1,m.failure.message):ve(!0)}function co(e){let t=typeof e=="number"?e:Number(e);return Number.isFinite(t)&&t>0?t:null}function Ba(e,t,r){if(t!=="set-image-size")return null;if(typeof r!="object"||r===null)return ve(!1,"Expected an image id and size.");let o=r,n=typeof o.imageId=="string"?o.imageId:"";return n?Vg(e,n,{width:o.width,height:o.height,unit:o.unit}):ve(!1,"Expected an image id.")}var Lg=["selected-image-resize","selected-image-set-wrap","selected-image-set-alt","set-image-size"],Dg=new Set(Lg);function ya(e){return Dg.has(e)}var Hg=["inline","square","tight","through","topAndBottom","behind","inFront"],Fg=new Set(Hg);function Pa(e){return typeof e=="string"&&Fg.has(e)}function $n(e){let t=ie(e);if(!t)return null;let r=Le(t.view.state);return!r||r.nodeType!=="image"?null:Array.isArray(r.path)&&r.path.length>0?{path:r.path}:null}function Zn(){return{ok:!0,changed:!0,reason:null}}function ke(e){return{ok:!1,changed:!1,reason:e}}function uo(e){let t=typeof e=="number"?e:Number(e);return Number.isFinite(t)&&t>0?t:null}function Jn(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{}}function jg(e,t){let r=$n(e);if(!r)return ke("No image is selected.");let o=Jn(t),n=uo(o.width),i=uo(o.height);if(n==null&&i==null)return ke("Expected a positive width or height for the image.");let s={};if(n!=null&&(s.width=n),i!=null&&(s.height=i),o.lockAspectRatio===!0&&(n==null||i==null)){let a=e.documentApi.media.get(r.path),c=uo(a?.width),u=uo(a?.height);if(c!=null&&u!=null){let d=c/u;n!=null?s.height=Math.round(n/d):i!=null&&(s.width=Math.round(i*d))}}return e.documentApi.media.update(r.path,s)?.changed?Zn():ke("The image size was unchanged.")}function zg(e,t){let r=$n(e);if(!r)return ke("No image is selected.");let o=Jn(t),n=o.mode??o.wrapMode;if(!Pa(n))return ke("Expected a supported image wrap mode.");let i=n==="inline"?{displayMode:"inline",wrapMode:null}:n==="behind"||n==="inFront"?{displayMode:"float",wrapMode:n}:{displayMode:"float",wrapMode:n};return e.documentApi.media.update(r.path,i)?.changed?Zn():ke("The image wrapping was unchanged.")}function qg(e,t){let r=$n(e);if(!r)return ke("No image is selected.");let n=Jn(t).alt;return typeof n!="string"&&n!==null?ke("Expected alternative text for the image."):e.documentApi.media.update(r.path,{alt:n})?.changed?Zn():ke("The image description was unchanged.")}function Ca(e,t,r){let o=Ba(e,t,r);if(o)return o;switch(t){case"selected-image-resize":return jg(e,r);case"selected-image-set-wrap":return zg(e,r);case"selected-image-set-alt":return qg(e,r);default:return null}}var xa=new Set(["table_cell","table_header"]);function mo(e,t){let r=[];for(let o=1;o<=t;o+=1)r.push(e.index(o-1));return r}function fo(e,t){for(let r=e.depth;r>0;r-=1)if(t(e.node(r)))return r;return null}function Qn(e,t){let r=e.selection.$from,o=fo(r,c=>xa.has(c.type.name));if(o==null)return null;let n=fo(r,c=>c.type.name==="table");if(n==null||n>=o)return null;let i=mo(r,n),s=mo(r,o),l=t.find(c=>c.path.join(".")===i.join("."));if(!l)return null;let a=s.join(".");for(let c of l.rows)for(let u of c.cells)if(u.path.join(".")===a)return{tablePath:i,cellPath:s,rowIndex:u.rowIndex,columnIndex:u.columnIndex,rowCount:l.rowCount,columnCount:l.columnCount,colSpan:u.colSpan,rowSpan:u.rowSpan};return null}function Ea(e,t){let r=Qn(e,t);if(!r)return null;let o=e.selection.$to,n=fo(o,u=>xa.has(u.type.name)),i=fo(o,u=>u.type.name==="table");if(n==null||i==null||i>=n)return{start:r,end:r};let s=mo(o,i);if(s.join(".")!==r.tablePath.join("."))return{start:r,end:r};let l=mo(o,n),a=t.find(u=>u.path.join(".")===s.join(".")),c=l.join(".");for(let u of a?.rows??[])for(let d of u.cells)if(d.path.join(".")===c)return{start:r,end:{...r,cellPath:l,rowIndex:d.rowIndex,columnIndex:d.columnIndex,colSpan:d.colSpan,rowSpan:d.rowSpan}};return{start:r,end:r}}var ei=e=>({changed:!1,reason:e});function ka(e){return e.tables.list()}function _g(e,t){return Qn(t,ka(e))??ei("Place the caret inside a table first.")}function Kg(e){return"changed"in e}function Ug(e){return e.rowCount<=1}function Wg(e){return e.columnCount<=1}function Te(e){return e.success?{changed:!0,reason:null}:{changed:!1,reason:e.reason??"The table command failed."}}function Ta(e,t,r){if(!r.startsWith("table-"))return null;let o=_g(e,t);if(Kg(o))return o;let n=o,{tablePath:i,rowIndex:s,columnIndex:l}=n;switch(r){case"table-insert-row-above":return Te(e.tables.insertRow(i,s,[],{}));case"table-insert-row-below":return Te(e.tables.insertRow(i,s+1,[],{}));case"table-insert-column-left":return Te(e.tables.insertColumn(i,l,[]));case"table-insert-column-right":return Te(e.tables.insertColumn(i,l+1,[]));case"table-delete-row":return Te(Ug(n)?e.tables.delete(i):e.tables.removeRow(i,s));case"table-delete-column":return Te(Wg(n)?e.tables.delete(i):e.tables.removeColumn(i,l));case"table-delete":return Te(e.tables.delete(i));case"table-merge-cells":{let a=Ea(t,ka(e));return a?a.start.rowIndex===a.end.rowIndex&&a.start.columnIndex===a.end.columnIndex?ei("Select at least two cells to merge."):Te(e.tables.mergeCells({tablePath:i,start:{rowIndex:a.start.rowIndex,columnIndex:a.start.columnIndex},end:{rowIndex:a.end.rowIndex,columnIndex:a.end.columnIndex}})):ei("Select the cells to merge first.")}case"table-split-cell":return Te(e.tables.unmergeCells({tablePath:i,rowIndex:s,columnIndex:l}));default:return null}}import{normalizeHyperlinkHref as Ia}from"@datalking/begonia-document-model";var Ra=8,Ma=96;function le(e){return typeof e=="object"&&e!==null}function Xg(e,t=!0){return typeof e=="boolean"?e:le(e)&&typeof e.changed=="boolean"?e.changed:t}function P(e,t=Xg(e)){return{ok:!0,changed:t,value:e}}function D(e){return{ok:!1,changed:!1,reason:e}}function Aa(e){if(typeof e=="string"){let r=Ia(e);return r?{href:r,title:null}:null}if(!le(e))return null;let t=Ia(e.href);return t?{href:t,title:typeof e.title=="string"?e.title:e.title==null?null:String(e.title)}:null}function Oa(e){return typeof e=="string"?e.trim()?e:null:!le(e)||typeof e.text!="string"||e.text.trim().length===0?null:{text:e.text,isInternal:typeof e.isInternal=="boolean"?e.isInternal:void 0}}function kt(e){if(e==null)return null;if(typeof e!="string")return;let t=e.trim();if(t)return t.toLowerCase()==="none"?null:t}function ti(e){if(e==null)return null;if(typeof e=="number")return Number.isFinite(e)?Math.min(Ma,Math.max(Ra,e)):void 0;if(typeof e!="string")return;let t=e.trim();if(!t)return;if(t.toLowerCase()==="none")return null;let r=Number.parseFloat(t);return Number.isFinite(r)?Math.min(Ma,Math.max(Ra,r)):void 0}function oi(e){let t=kt(e);if(t!==void 0)return t;if(le(e)){if(Object.hasOwn(e,"color"))return kt(e.color);if(Object.hasOwn(e,"value"))return kt(e.value)}}function Va(e){let t=kt(e);if(t!==void 0)return t;if(le(e)){if(Object.hasOwn(e,"fontFamily"))return kt(e.fontFamily);if(Object.hasOwn(e,"value"))return kt(e.value)}}function La(e){let t=ti(e);if(t!==void 0)return t;if(le(e)){if(Object.hasOwn(e,"fontSize"))return ti(e.fontSize);if(Object.hasOwn(e,"value"))return ti(e.value)}}function Na(e){return Math.min(Wr,Math.max(Ur,e))}function ri(e){if(typeof e=="number")return Number.isFinite(e)&&e>0?Na(e):null;if(typeof e!="string")return null;let t=e.trim();if(!t)return null;let r=t.endsWith("%")?t.slice(0,-1).trim():t;if(!r||!/^(?:\d+(?:\.\d+)?|\.\d+)$/u.test(r))return null;let o=Number.parseFloat(r);return Number.isFinite(o)&&o>0?Na(o):null}function Da(e){let t=ri(e);if(t!=null)return t;if(!le(e))return null;let r=ri(e.zoomPercent);if(r!=null)return{zoomPercent:r};let o=ri(e.zoom);return o!=null?{zoom:o}:null}function Ha(e){return typeof e=="string"?e:!le(e)||typeof e.query!="string"?null:{query:e.query,options:le(e.options)?e.options:void 0}}function ni(e){return typeof e=="string"?e:!le(e)||typeof e.text!="string"?null:{text:e.text,hitId:typeof e.hitId=="string"?e.hitId:e.hitId==null?null:String(e.hitId)}}function Fa(e){return typeof e=="string"?e:!le(e)||typeof e.text!="string"?null:{text:e.text,diagnosticId:typeof e.diagnosticId=="string"?e.diagnosticId:e.diagnosticId==null?null:String(e.diagnosticId)}}function ja(e){if(typeof e=="string"){let n=e.trim();return n?{src:n}:null}if(!le(e))return null;let t=typeof e.src=="string"?e.src.trim():"";if(!t)return null;let r=n=>typeof n=="number"&&Number.isFinite(n)&&n>0?n:null,o=n=>typeof n=="string"&&n.trim()?n.trim():null;return{src:t,alt:o(e.alt),name:o(e.name),title:o(e.title),width:r(e.width),height:r(e.height),mime:o(e.mime)}}function za(e,t,r){let o=e.structure.createImage({src:r.src,alt:r.alt??null,name:r.name??null,title:r.title??null,width:r.width??null,height:r.height??null,mime:r.mime??null,displayMode:"block"});return t.insertBlock(o)?{changed:!0,reason:null}:{changed:!1,reason:"The image cannot be inserted at the current selection."}}var Gg=3,Yg=3;function qa(e,t){let r=Array.from({length:Gg},()=>Array.from({length:Yg},()=>"")),o=e.structure.createTable(r,{});return t.insertBlock(o)?{changed:!0,reason:null}:{changed:!1,reason:"The table cannot be inserted at the current selection."}}import{resolveCollapsedSelectionFormattingMarks as Ah}from"@datalking/begonia-engine";import{addressableBlockTypeForNodeType as Qa,formatAddressableBlockId as vh,formatAddressableBlockIdWithLogicalId as ec}from"@datalking/begonia-doc-service/structure";import{normalizeDocumentStoryLocator as Lk,readSyntheticSideStoryDocOriginPath as Sh,readSyntheticSideStoryDocStoryLocator as Bh}from"@datalking/begonia-doc-service/v1";import{hasVisibleSemanticContent as yh}from"@datalking/begonia-engine";import{DELETION_MARK_NAME as $g,INSERTION_MARK_NAME as Zg,collectRevisionSpans as Jg,createRevisionGroupingContext as Qg,listSelectionRevisionRanges as eh,logicalRevisionIdForRange as th,resolveParagraphLikeBlockInlineRangeAtPath as rh}from"@datalking/begonia-engine";import{groupLogicalRevisions as oh}from"@datalking/begonia-doc-service/v1";function _a(e){return e.threadId}function po(e){return`${e.threadId}\0${e.entryId}`}function Ka(e,t){let r=Math.min(e,t),o=Math.max(e,t),n=r===o;return{start:r,selectionEnd:n?o+1:o,collapsed:n}}function nh(e,t){return t<e.selectionEnd&&t+1>e.start}function Ua(e,t,r){return t<e.selectionEnd&&r>e.start}function ii(e,t,r,o={}){let n=o.includeLeadingBoundary??!0,i=o.includeTrailingBoundary??!0,s=n&&e.collapsed&&r>t&&e.start+1===t,l=i&&e.collapsed&&r>t&&e.start===r;return Ua(e,t,r)||s||l}function ih(e){return e.marks.some(t=>t.type.name===Zg||t.type.name===$g)}function sh(e,t){return t.target?.nodeType!=="bookmark_anchor"&&t.target?.nodeType!=="structural_revision_carrier"||(t.text??"").length>0||!t.target.blockPath.length?null:rh(e,t.target.blockPath)}function lh(e,t){if(e.type.name!=="comment_range_start"&&e.type.name!=="comment_range_end"&&e.type.name!=="comment_anchor")return null;let r=typeof e.attrs.threadId=="string"?e.attrs.threadId.trim():"";if(r.length===0)return null;let o=typeof e.attrs.entryId=="string"?e.attrs.entryId.trim():"";return{threadId:r,entryId:o||r,kind:e.type.name==="comment_range_start"?"start":e.type.name==="comment_range_end"?"end":"anchor",pos:t,tracked:ih(e)}}function ah(e){let t=[];return e.nodesBetween(0,e.content.size,(r,o)=>{let n=lh(r,o);return n&&t.push(n),!0}),t}function si(e,t,r){let o=e.get(t)??[];o.push(r),e.set(t,o)}function ch(e,t){let r=po(t),o=e.get(r)??{hasStart:!1,hasEnd:!1};t.kind==="start"&&(o.hasStart=!0),t.kind==="end"&&(o.hasEnd=!0),e.set(r,o)}function uh(e,t,r){return(e.get(po(r))??[]).find(o=>o.pos>=r.pos&&!t.has(o))??null}function dh(e,t,r){let o=e.get(po(r))??[];for(let n=o.length-1;n>=0;n-=1){let i=o[n];if(i&&i.pos<=r.pos&&!t.has(i))return i}return null}function mh(e,t){let r=Ka(t.from,t.to),o=ah(e),n=new Set,i=new Map,s=new Map,l=new Map,a=new Map,c=new Set;for(let u of o){if(ch(a,u),u.kind==="anchor"){si(l,po(u),u);continue}if(u.kind==="start"){si(i,_a(u),u);continue}let d=_a(u),m=i.get(d)??[],f=m.pop()??null;if(m.length>0?i.set(d,m):i.delete(d),!f){si(s,d,u);continue}ii(r,f.pos+1,u.pos,{includeLeadingBoundary:!f.tracked,includeTrailingBoundary:!u.tracked})&&n.add(f.threadId)}for(let u of i.values())for(let d of u){let m=uh(l,c,d);m&&(c.add(m),ii(r,d.pos+1,m.pos,{includeLeadingBoundary:!d.tracked,includeTrailingBoundary:!m.tracked})&&n.add(d.threadId))}for(let u of s.values())for(let d of u){let m=dh(l,c,d);m&&(c.add(m),ii(r,m.pos,d.pos,{includeLeadingBoundary:!m.tracked,includeTrailingBoundary:!d.tracked})&&n.add(d.threadId))}for(let[u,d]of l){let m=a.get(u);if(!(m?.hasStart||m?.hasEnd))for(let f of d)!f.tracked&&nh(r,f.pos)&&n.add(f.threadId)}return[...n]}function fh(e,t){let r=Jg(e.doc,e.schema),o=Qg(r),n=new Set;for(let i of eh(e)){let s=sh(e.doc,i);(!s||Ua(Ka(e.selection.from,e.selection.to),s.from,s.to))&&n.add(th(i,o,t))}return qt([...n],oh(r,t))}function Wa(e,t={}){return{activeCommentIds:mh(e.doc,e.selection),activeChangeIds:fh(e,t.reviewReplacementMode??"paired")}}import{hasVisibleSemanticContent as Ck}from"@datalking/begonia-document-model";function wo(e){return[...new Set((e??[]).filter(t=>typeof t=="string").map(t=>t.trim()).filter(t=>t.length>0))]}function Xa(e,t,r=!1){return t!=="node"||e.target==null||r||wo(e.activeChangeIds).length>0?e:{...e,target:null}}import{hasVisibleSemanticContent as Ya,isInlineFormatMarkEnabled as ph}from"@datalking/begonia-document-model";var wh=new Set(["strong","em","underline","strike"]);function go(e,t){for(let r of t){if(wh.has(r.type.name)&&!ph(r)){e.delete(r.type.name);continue}e.add(r.type.name)}}function gh(e){let t=new Set;return go(t,e),t}function Ga(e,t){let r=new Set(e);return go(r,t.marks),r}function $a(e){return e.isInline&&!e.isText&&Ya(e)}function hh(e){return e.isText||e.isInline&&e.isLeaf&&Ya(e)}function bh(e,t){return e.isText?{start:t,end:t+(e.text?.length??0)}:{start:t,end:t+e.nodeSize}}function Za(e,t,r){let o=null,n=(i,s,l)=>{let a=$a(i)?Ga(l,i):new Set(l);if(hh(i)){let u=bh(i,s),d=Math.max(u.start,t);if(Math.min(u.end,r)>d){let f=Ga(a,i);if(o==null)o=f;else for(let g of[...o])f.has(g)||o.delete(g)}return}if(i.childCount===0)return;let c=0;i.forEach(u=>{let d=s+1+c,m=d+u.nodeSize;c+=u.nodeSize,!(m<=t||d>=r)&&n(u,d,a)})};return n(e,-1,new Set),o??new Set}function Ja(e,t=null){if(t!=null)return gh(t);let r=new Set;for(let o=1;o<=e.depth;o+=1){let n=e.node(o);if(!$a(n))continue;let i=e.start(o),s=e.end(o);e.pos<i||e.pos>s||go(r,n.marks)}return go(r,e.marks()),r}var ho=Object.freeze({blockSeparator:`
|
|
5
|
+
`});function Ph(e,t){let r=[];for(let o=0;o<t;o+=1)r.push(e.index(o));return r}function bo(e){for(let t=1;t<=e.depth;t+=1){let r=e.node(t),o=Qa(r.type.name);if(o)return{type:o,path:Ph(e,t),node:r,pos:e.start(t)-1}}return null}function Ch(e,t,r,o){let n=e[e.length-1];if(n?.blockId===t){n.range.end=Math.max(n.range.end,o),n.range.start=Math.min(n.range.start,r);return}e.push({blockId:t,range:{start:r,end:o}})}function tc(e,t){let r=Sh(e);return r?[...r,...t]:[...t]}function ai(e,t,r){let o=tc(e,t.path);return r?vh(t.type,o):ec(t.type,o,jt(t.type,t.node))}function xh(e,t=null){return e.length===0?null:{kind:"text",segments:e,...t?{story:t}:{}}}function ci(e,t,r,o,n){return wt(e)?{start:ft(t,r,"start",n),end:ft(t,o,"end",n)}:{start:r,end:o}}function li(e){return e.node.isLeaf&&e.node.isInline&&e.$from.parent.inlineContent&&yh(e.node)}function rc(e){let t=Qa(e.node.type.name);return t==="listItem"?t:null}function Eh(e){return"$anchorCell"in e?!1:R(e)?li(e)||rc(e)!=null:!0}function kh(e,t){let r=t.$from.doc.resolve(t.from+1),o=bo(r);if(!o||o.node!==t.node)return null;let n=T(e,ho),i=Math.max(t.from,o.pos+1),s=Math.min(t.to,o.pos+o.node.nodeSize-1),l=F(o.node,o.pos,i,n),a=Math.max(l,F(o.node,o.pos,s,n)),c=ai(e,o,!1);return[{blockId:c,range:ci(c,o.node,l,a,n)}]}function Th(e,t){let r=bo(t.$from);if(!r||!r.node.isTextblock)return null;let o=T(e,ho),n=F(r.node,r.pos,t.from,o),i=Math.max(n,F(r.node,r.pos,t.to,o)),s=ai(e,r,!0);return[{blockId:s,range:ci(s,r.node,n,i,o)}]}function Ih(e,t){let r=R(t)&&li(t),o=T(e,ho);if(R(t)&&li(t)){let s=Th(e,t);if(s)return s}if(R(t)&&rc(t)){let s=kh(e,t);if(s)return s}let n=[],i=!1;return e.nodesBetween(t.from,t.to,(s,l)=>{if(i)return!1;if(!s.isTextblock)return!0;let a=e.resolve(l+1),c=bo(a);if(!c)return i=!0,!1;let u=Math.max(t.from,l+1),d=Math.min(t.to,l+s.nodeSize-1),m=F(c.node,c.pos,u,o),f=Math.max(m,F(c.node,c.pos,d,o)),g=ai(e,c,r),p=ci(g,c.node,m,f,o);return Ch(n,g,p.start,p.end),!1}),i?null:n}function Rh(e,t,r){return Za(e,t,r)}function Mh(e){let t=new Set,{from:r,to:o}=e.selection;if(r===o){for(let n of Ja(e.doc.resolve(r),e.storedMarks))t.add(n);return[...t]}for(let n of Rh(e.doc,r,o))t.add(n);return[...t]}function Qe(e,t={},r={}){let o=t??{},n=r??{},{selection:i,doc:s}=e,l=ui(s,i),{activeCommentIds:a,activeChangeIds:c}=Wa(e,{reviewReplacementMode:n.reviewReplacementMode}),u={empty:i.empty,target:l,activeMarks:Mh(e),activeCommentIds:a,activeChangeIds:c};return o.includeText&&!i.empty&&(u.text=ge(s,e.schema,i)),u}function ui(e,t){let r=Bh(e);return Eh(t)?xh(Ih(e,t)??[],r):null}function vo(e){let t=Qe(e).target;if(t)return t;if(!e.selection.empty)return null;let r=bo(e.selection.$from);if(!r)return null;let o=T(e.doc,ho),n=F(r.node,r.pos,e.selection.from,o);return{kind:"text",blockId:ec(r.type,tc(e.doc,r.path),jt(r.type,r.node)),range:{start:n,end:n}}}function Nh(e){return e?.selectionKind!=="node"&&e?.selectionTarget!=null}function Tt(e,t,r=null){return e?e.editable?r?.selectionKind==="node"?"Place the caret in text or select text before applying inline formatting.":Nh(r)?null:t&&R(t.selection)?"Place the caret in text or select text before applying inline formatting.":t?vo(t)?null:"Place the caret in text or select text before applying inline formatting.":r?.selectionTarget?null:"Place the caret in text or select text before applying inline formatting.":"Document is read-only in the current document mode.":"Editor is not ready."}var Oh=["color","highlight","fontFamily","fontSize","fontSizeCs","rFonts"];function et(e,t){return{ok:!0,changed:t,value:e}}function te(e){return{ok:!1,changed:!1,reason:e}}function nc(e,t){let r=H(e),o=Tt({editable:e.getState().editable},r.state,t);return o||(t?null:"Place the caret in text or select text before applying inline formatting.")}function ic(e,t,r){return e.empty&&!t?`Collapsed ${r} formatting requires a live editor surface. Select text to format in headless mode.`:null}function sc(e){return e.target&&"segments"in e.target?e.target:e.selectionTarget??null}function lc(e,t,r){let o=H(e),n=e.documentApi.format.apply({target:t,inline:r,participant:o.trackingEnabled?o.participant:void 0,context:o.trackingEnabled?{source:"formatting"}:void 0});return n.success?et(n,!0):n.failure.code==="NO_OP"?et(n,!1):te(n.failure.message)}function ac(e){return e?{...e}:{}}function Vh(e,t){if(Object.is(e,t))return!0;if(!e||!t||typeof e!="object"||typeof t!="object"||Array.isArray(e)||Array.isArray(t))return!1;let r=e,o=t,n=Object.keys(r).sort(),i=Object.keys(o).sort();return n.length===i.length&&n.every((s,l)=>s===i[l]&&Object.is(r[s],o[s]))}function Lh(e,t){let r=ac(e),o=!1;for(let n of Oh){if(t[n]===void 0)continue;let i=n==="fontSize"||n==="fontSizeCs"?typeof t[n]=="number"?t[n]:null:n==="rFonts"?t.rFonts&&typeof t.rFonts=="object"?structuredClone(t.rFonts):null:typeof t[n]=="string"?t[n]:null;(n==="rFonts"?Vh(r[n],i):Object.is(r[n],i))||(r[n]=i,o=!0)}return{changed:o,attrs:Object.values(r).some(n=>n!=null)?r:null}}function oc(e,t){let r=H(e);if(!r.view)return te("Collapsed text-style formatting requires a live editor surface. Select text to format in headless mode.");let{state:o,dispatch:n}=r.view,i=o.schema.marks.text_style;if(!i)return te("Inline text-style marks are not available on this surface.");let l=Ah(o).find(u=>u.type===i)??null,a=Lh(ac(l?.attrs),t);if(!a.changed)return et(l?.attrs??null,!1);let c=o.tr.removeStoredMark(i);return a.attrs&&(c=c.addStoredMark(i.create(a.attrs))),n(c),et(a.attrs,!0)}function cr(e,t,r=null,o={}){let n=r?e.readSelectionCapture(r):e.readEffectiveSelection();if(r&&!n)return te("Captured selection is no longer available after the document changed. Capture a new text selection or caret before applying inline formatting.");let i=nc(e,n);if(i)return te(i);if(!n)return te("Place the caret in text or select text before applying inline formatting.");let s=ic(n,H(e).view!=null,"text-style");if(s)return te(s);if(n.empty){if(r){let a=null;return De(H(e),n,()=>(a=oc(e,t),a.changed),{restoreSelection:o.restoreSelection??!1}),a??te("Inline formatting could not be applied.")}return oc(e,t)}let l=sc(n);return l?lc(e,l,t):te("Place the caret in text or select text before applying inline formatting.")}function di(e,t){switch(t){case"bold":return e.toggleBold();case"italic":return e.toggleItalic();case"underline":return e.toggleUnderline();case"strike":return e.toggleStrike()}}function Dh(e,t){let r=di(H(e),t);return et(r,r)}function Hh(e,t){return t==="bold"?e.selection.formatting.bold:t==="italic"?e.selection.formatting.italic:t==="underline"?e.selection.formatting.underline:e.selection.formatting.strike}function Se(e,t,r=null,o={}){let n=r?e.readSelectionCapture(r):e.readEffectiveSelection();if(r&&!n)return te("Captured selection is no longer available after the document changed. Capture a new text selection or caret before applying inline formatting.");let i=nc(e,n);if(i)return te(i);if(!n)return te("Place the caret in text or select text before applying inline formatting.");let s=ic(n,H(e).view!=null,"inline");if(s)return te(s);if(n.empty){if(r){let u=De(H(e),n,d=>di(d,t),{restoreSelection:o.restoreSelection??!1});return et(u,u)}return Dh(e,t)}let l=H(e);if(l.view&&!r){let u=De(l,n,d=>di(d,t),{restoreSelection:o.restoreSelection??!1});return et(u,u)}let a=sc(n);if(!a)return te("Place the caret in text or select text before applying inline formatting.");let c=!Hh(n,t);return lc(e,a,{[t]:c})}function So(e){return e.getZoomState().mode}function cc(e){return e.getZoomPercent()}function mi(e,t){return e.getState().preferredPaginatedLayoutMode!==t}function He(e,t){let r=H(e);return De(r,e.readEffectiveSelection(),t)}function Be(e){return e&&typeof e=="object"&&"reason"in e&&typeof e.reason=="string"?D(e.reason):P(e)}function Fh(e){return e===!1?D("Comment could not be created."):Be(e)}function jh(e,t,r){let o=ao(e),n=o?.view??null;if(!o||!n)return null;if(t==="insert-table")return fi(qa(e.documentApi,o));if(t==="insert-image"){let s=ja(r);return s?fi(za(e.documentApi,o,s)):D("Expected an image source for image insertion.")}let i=Ta(e.documentApi,n.state,t);return i?fi(i):null}function fi(e){return e.changed?P({changed:!0}):D(e.reason??"The command failed.")}function zh(e,t,r){let o=H(e);switch(t){case"font-size":{let n=La(r),i=n===null?null:Number(n);return n===void 0?D('Expected a font-size payload or "none".'):cr(e,{fontSize:i,fontSizeCs:i})}case"font-family":{let n=Va(r);return n===void 0?D('Expected a font-family payload or "none".'):cr(e,{fontFamily:n==null?null:String(n),rFonts:null})}case"text-color":{let n=oi(r);return n===void 0?D('Expected a text-color payload or "none".'):cr(e,{color:n==null?null:String(n)})}case"highlight-color":{let n=oi(r);return n===void 0?D('Expected a highlight-color payload or "none".'):cr(e,{highlight:n==null?null:String(n)})}case"zoom":{let n=Da(r);if(!n)return D("Expected a positive zoom percentage payload.");let i=typeof n=="number"?n:n.zoomPercent??n.zoom??null;if(i==null)return D("Expected a positive zoom percentage payload.");let s=cc(e),l=So(e);return e.setViewState(er(Qt(e.getState()),{type:"zoom",zoomPercent:i})),P(i,cc(e)!==s||So(e)!==l)}case"zoom-fit-width":{let n=So(e);e.setZoomMode(n==="fit-width"?"manual":"fit-width");let i=So(e);return P(i,i!==n)}case"document-mode-editing":{let n=e.getState().documentMode;return e.setDocumentMode("editing"),P("editing",e.getState().documentMode!==n)}case"document-mode-suggesting":{let n=e.getState().documentMode;return e.setDocumentMode("suggesting"),P("suggesting",e.getState().documentMode!==n)}case"document-mode-viewing":{let n=e.getState().documentMode;return e.setDocumentMode("viewing"),P("viewing",e.getState().documentMode!==n)}case"flow-mode-paginated":{let n=e.getFlowMode();return e.setViewState(er(Qt(e.getState()),{type:"flow",flowMode:"paginated"})),P("paginated",e.getFlowMode()!==n)}case"flow-mode-web":{let n=e.getFlowMode();return e.setViewState(er(Qt(e.getState()),{type:"flow",flowMode:"web"})),P("web",e.getFlowMode()!==n)}case"layout-mode-vertical":{let n=e.getState().preferredPaginatedLayoutMode,i=e.getLayoutMode();return e.setViewState({layoutMode:"vertical"}),P("vertical",e.getLayoutMode()!==i||mi(e,n))}case"layout-mode-horizontal":{let n=e.getState().preferredPaginatedLayoutMode,i=e.getLayoutMode();return e.setViewState({layoutMode:"horizontal"}),P("horizontal",e.getLayoutMode()!==i||mi(e,n))}case"layout-mode-book":{let n=e.getState().preferredPaginatedLayoutMode,i=e.getLayoutMode();return e.setViewState({layoutMode:"book"}),P("book",e.getLayoutMode()!==i||mi(e,n))}case"track-changes-display-review":{let n=e.getState().trackChanges.mode;return e.setTrackChangesDisplayMode("review"),P("review",e.getState().trackChanges.mode!==n)}case"track-changes-display-original":{let n=e.getState().trackChanges.mode;return e.setTrackChangesDisplayMode("original"),P("original",e.getState().trackChanges.mode!==n)}case"track-changes-display-final":{let n=e.getState().trackChanges.mode;return e.setTrackChangesDisplayMode("final"),P("final",e.getState().trackChanges.mode!==n)}case"track-changes-display-off":{let n=e.getState().trackChanges.mode;return e.setTrackChangesDisplayMode("off"),P("off",e.getState().trackChanges.mode!==n)}case"comments-visible":{let n=e.getState().commentsDisplay.visible;return e.setCommentsVisible(!0),P(!0,e.getState().commentsDisplay.visible!==n)}case"comments-hidden":{let n=e.getState().commentsDisplay.visible;return e.setCommentsVisible(!1),P(!1,e.getState().commentsDisplay.visible!==n)}case"comments-show-resolved":{let n=e.getState().commentsDisplay.showResolved;return e.setCommentsShowResolved(!0),P(!0,e.getState().commentsDisplay.showResolved!==n)}case"comments-hide-resolved":{let n=e.getState().commentsDisplay.showResolved;return e.setCommentsShowResolved(!1),P(!1,e.getState().commentsDisplay.showResolved!==n)}case"comments-visibility-all":{let n=e.getState().commentsDisplay.visibility;return e.setCommentsVisibility("all"),P("all",e.getState().commentsDisplay.visibility!==n)}case"comments-visibility-internal":{let n=e.getState().commentsDisplay.visibility;return e.setCommentsVisibility("internal"),P("internal",e.getState().commentsDisplay.visibility!==n)}case"comments-visibility-external":{let n=e.getState().commentsDisplay.visibility;return e.setCommentsVisibility("external"),P("external",e.getState().commentsDisplay.visibility!==n)}case"undo":return P(o.undo());case"redo":return P(o.redo());case"bold":return Se(e,"bold");case"italic":return Se(e,"italic");case"underline":return Se(e,"underline");case"strikethrough":return Se(e,"strike");case"paragraph":return P(He(e,n=>n.setParagraph()));case"heading-1":return P(He(e,n=>n.setHeading(1)));case"heading-2":return P(He(e,n=>n.setHeading(2)));case"heading-3":return P(He(e,n=>n.setHeading(3)));case"bullet-list":return P(He(e,n=>n.toggleBulletList()));case"numbered-list":return P(He(e,n=>n.toggleOrderedList()));case"align-left":case"align-center":case"align-right":case"align-justify":{let n=t.slice(6);return P(He(e,i=>i.setAlignment(n)))}case"indent-increase":case"indent-decrease":return P(He(e,n=>n.adjustIndent(t==="indent-increase"?"increase":"decrease")));case"link-set":{let n=Aa(r);return n?P(typeof n=="string"?e.setLink(n):e.setLink(n.href,n.title??null)):D("Expected a non-empty link payload.")}case"link-clear":return P(e.clearLink());case"comment-create":{let n=Oa(r);if(!n)return D("Expected non-empty comment text for comment creation.");let i=e.readEffectiveSelection();return Fh(typeof n=="string"?i?e.createCommentFromCapture(i,n):e.createComment(n):i?e.createCommentFromCapture(i,n.text,{isInternal:n.isInternal??void 0}):e.createComment(n.text,{isInternal:n.isInternal??void 0}))}case"tracking-toggle":return e.setDocumentMode(e.getState().documentMode==="suggesting"?"editing":"suggesting"),P(!0,!0);default:return null}}function uc(e,t,r){let o=zh(e,t,r);if(o)return o;let n=Sa(e,t,r);if(n)return n;let i=Ca(e,t,r);if(i)return i;let s=jh(e,t,r);if(s)return s;switch(t){case"search-set-query":{let l=Ha(r);if(!l)return D("Expected a search query payload.");let a=typeof l=="string"?e.search(l):e.search(l.query,l.options??{});return P(a,!0)}case"search-next":return(()=>{let l=e.nextSearchHit();return P(l,l!=null)})();case"search-previous":return(()=>{let l=e.previousSearchHit();return P(l,l!=null)})();case"search-clear":{let l=e.getState().search.query.length>0;return e.clearSearch(),P(void 0,l)}case"search-replace-active":{let l=ni(r);if(!l)return D("Expected replacement text for the active search hit.");let a=e.getState(),c=typeof l=="string"?a.search.activeHitId:l.hitId??a.search.activeHitId;if(!c)return D("No active search hit is available to replace.");let u=typeof l=="string"?e.replaceSearchHit(c,l):e.replaceSearchHit(c,l.text);return Be(u)}case"search-replace-all":{let l=ni(r);if(!l)return D("Expected replacement text for search replace-all.");let a=typeof l=="string"?e.replaceAllSearchHits(l):e.replaceAllSearchHits(l.text);return Be(a)}case"review-accept-all":return Be(e.acceptAll());case"track-changes-accept-selection":return Be(e.acceptSelection());case"review-reject-all":return Be(e.rejectAll());case"track-changes-reject-selection":return Be(e.rejectSelection());case"proofing-ignore-first":{let l=e.getState().proofing.diagnostics[0]?.diagnosticId;return l?Be(e.ignoreProofingDiagnostic(l)):D("No proofing diagnostic is available to ignore.")}case"proofing-accept-first":{let l=e.getState().proofing.diagnostics[0]?.diagnosticId;return l?Be(e.acceptProofingSuggestion(l)):D("No proofing diagnostic is available to accept.")}case"proofing-replace-first-tracked":{let l=Fa(r),c=e.getState().proofing.diagnostics[0],u=typeof l=="string"?c?.diagnosticId:l?.diagnosticId??c?.diagnosticId,d=typeof l=="string"?l:l?.text??c?.replacementText??c?.suggestion??"";return!u||!d?D("No tracked proofing replacement could be resolved."):Be(e.replaceProofingDiagnosticTracked(u,d))}default:return null}}var qh=["insert-math-inline","insert-chart-block","insert-shape-block","remove-selected-ooxml","selected-math-set-plain-text","selected-math-toggle-display-mode","selected-chart-set-title","selected-chart-add-series","selected-chart-add-axis","selected-shape-set-text-body","selected-shape-set-fill","selected-shape-add-child"],_h=new Set(qh);function dc(e){return _h.has(e)}var mc=Object.freeze([{id:"align-left",title:"Align Left",group:"block",description:"Align the selected blocks to the left edge of the text column.",keywords:["alignment","paragraph","start"],slash:!0},{id:"align-center",title:"Align Center",group:"block",description:"Center the selected blocks between the text column margins.",keywords:["alignment","paragraph","centre"],slash:!0},{id:"align-right",title:"Align Right",group:"block",description:"Align the selected blocks to the right edge of the text column.",keywords:["alignment","paragraph","end"],slash:!0},{id:"align-justify",title:"Justify",group:"block",description:"Stretch the selected blocks so both edges meet the text column.",keywords:["alignment","paragraph","both","full"],slash:!0},{id:"indent-increase",title:"Increase Indent",group:"block",description:"Push the selected blocks one indent step further from the margin.",keywords:["indent","paragraph","increase"],slash:!0},{id:"indent-decrease",title:"Decrease Indent",group:"block",description:"Pull the selected blocks one indent step back toward the margin.",keywords:["indent","paragraph","decrease"],slash:!0}]);var fc=Object.freeze([{id:"insert-table",title:"Insert Table",group:"insert",description:"Insert a three by three table after the current block.",keywords:["table","grid","insert"],slash:!0},{id:"insert-image",title:"Insert Image",group:"insert",description:"Insert a picture after the current block.",keywords:["image","picture","photo","insert"],slash:!0},{id:"table-insert-row-above",title:"Insert Row Above",group:"table",description:"Insert an empty row above the row the caret is in.",keywords:["table","row","insert"],slash:!1},{id:"table-insert-row-below",title:"Insert Row Below",group:"table",description:"Insert an empty row below the row the caret is in.",keywords:["table","row","insert"],slash:!1},{id:"table-insert-column-left",title:"Insert Column Left",group:"table",description:"Insert an empty column to the left of the caret column.",keywords:["table","column","insert"],slash:!1},{id:"table-insert-column-right",title:"Insert Column Right",group:"table",description:"Insert an empty column to the right of the caret column.",keywords:["table","column","insert"],slash:!1},{id:"table-delete-row",title:"Delete Row",group:"table",description:"Delete the row the caret is in, or the whole table if it is the last row.",keywords:["table","row","delete"],slash:!1},{id:"table-delete-column",title:"Delete Column",group:"table",description:"Delete the caret column, or the whole table if it is the last column.",keywords:["table","column","delete"],slash:!1},{id:"table-delete",title:"Delete Table",group:"table",description:"Delete the whole table the caret is in.",keywords:["table","delete"],slash:!1},{id:"table-merge-cells",title:"Merge Cells",group:"table",description:"Merge the selected cells into one cell spanning their rectangle.",keywords:["table","cell","merge"],slash:!1},{id:"table-split-cell",title:"Split Cell",group:"table",description:"Split the merged cell at the caret back into its parts.",keywords:["table","cell","split","unmerge"],slash:!1}]);function h(e,t,r,o,n=[],i=!0){return{id:e,title:t,group:r,description:o,keywords:n,slash:i}}var ur=Object.freeze([h("undo","Undo","history","Revert the latest local editing step.",["history"],!1),h("redo","Redo","history","Re-apply the latest reverted step.",["history"],!1),h("zoom","Zoom","view","Set the document zoom level as a percentage.",["view","scale","percent"],!1),h("zoom-fit-width","Fit Width","view","Toggle fit-width zoom mode for the current viewport.",["view","scale","fit","width"],!1),h("document-mode-editing","Editing Mode","review","Switch the editor into direct editing mode.",["edit","write","author"],!1),h("document-mode-suggesting","Suggesting Mode","review","Switch the editor into suggestion authoring mode.",["suggest","track changes","review"],!1),h("document-mode-viewing","Viewing Mode","review","Switch the editor into read-only viewing mode.",["view","read-only","preview"],!1),h("flow-mode-paginated","Paginated Layout","view","Switch the editor into paginated layout mode.",["pagination","pages","print"],!1),h("flow-mode-web","Web Layout","view","Switch the editor into continuous web layout mode.",["web","continuous","scroll"],!1),h("layout-mode-vertical","Vertical Spread","view","Arrange paginated pages in a vertical stack.",["vertical","stack"],!1),h("layout-mode-horizontal","Horizontal Spread","view","Arrange paginated pages in a horizontal strip.",["horizontal","row"],!1),h("layout-mode-book","Book Spread","view","Arrange paginated pages in facing book spreads.",["book","spread","facing"],!1),h("track-changes-display-review","Review Markup","review","Display the document with review markup visible.",["markup","review mode"],!1),h("track-changes-display-original","Original Document","review","Project the document back to its original review baseline.",["original","projection"],!1),h("track-changes-display-final","Final Document","review","Project the document forward to its final accepted review state.",["final","projection"],!1),h("track-changes-display-off","Hide Review Markup","review","Hide tracked-change markup without switching authoring mode.",["hide markup","off"],!1),h("bold","Bold","format","Toggle bold formatting.",["strong","weight"]),h("italic","Italic","format","Toggle italic formatting.",["emphasis"]),h("underline","Underline","format","Toggle underline formatting.",["decoration"]),h("strikethrough","Strikethrough","format","Toggle strikethrough formatting.",["strike","delete","decoration"]),h("font-size","Font Size","format","Set or clear the font size on the current text selection.",["type","points"],!1),h("font-family","Font Family","format","Set or clear the font family on the current text selection.",["typeface","font"],!1),h("text-color","Text Color","format","Set or clear the text color on the current text selection.",["color","foreground"],!1),h("highlight-color","Highlight Color","format","Set or clear text highlight on the current selection.",["highlight","background"],!1),h("paragraph","Paragraph","block","Reset the current block to body paragraph text.",["body","normal"]),h("heading-1","Heading 1","block","Promote the current block to the top heading level.",["title","h1"]),h("heading-2","Heading 2","block","Promote the current block to a section heading.",["section","h2"]),h("heading-3","Heading 3","block","Promote the current block to a subsection heading.",["subsection","h3"]),h("bullet-list","Bulleted List","block","Toggle a bulleted list around the current block.",["list","bullets","unordered"]),h("numbered-list","Numbered List","block","Toggle a numbered list around the current block.",["list","ordered","numbers"]),...mc,...fc,h("insert-math-inline","Insert Equation","insert","Append an editable math OOXML node to the active text block.",["equation","math","formula"]),h("insert-chart-block","Insert Chart","insert","Insert an editable chart OOXML block after the current block.",["chart","graph","series"]),h("insert-shape-block","Insert Shape","insert","Insert an editable shape OOXML block after the current block.",["shape","callout","diagram"]),h("remove-selected-ooxml","Remove Selected OOXML","insert","Remove the currently selected advanced OOXML node.",["equation","chart","shape","delete"]),h("selected-math-set-plain-text","Edit Selected Equation","insert","Replace the currently selected math OOXML node with plain-text math content.",["equation","math","formula"],!1),h("selected-math-toggle-display-mode","Toggle Equation Display Mode","insert","Switch the selected OOXML equation between inline and block display mode.",["equation","math","display"],!1),h("selected-chart-set-title","Edit Selected Chart Title","insert","Update the title on the currently selected chart OOXML node.",["chart","title"],!1),h("selected-chart-add-series","Add Selected Chart Series","insert","Append a new data series to the currently selected chart OOXML node.",["chart","series","data"],!1),h("selected-chart-add-axis","Add Selected Chart Axis","insert","Append a new axis to the currently selected chart OOXML node.",["chart","axis","scale"],!1),h("selected-shape-set-text-body","Edit Selected Shape Text","insert","Update the text body on the currently selected shape OOXML node.",["shape","text"],!1),h("selected-shape-set-fill","Edit Selected Shape Fill","insert","Update the fill color on the currently selected shape OOXML node.",["shape","fill","color"],!1),h("selected-shape-add-child","Add Selected Shape Child","insert","Append a child shape node to the currently selected OOXML shape.",["shape","group","child"],!1),h("link-set","Set Link","insert","Apply or update a link on the current selection.",["hyperlink","url"],!1),h("link-clear","Clear Link","insert","Remove link formatting from the current selection.",["unlink"],!1),h("comment-create","Create Comment","review","Create a comment at the current selection or caret.",["comment","annotation","note"],!1),h("comments-visible","Show Comments","review","Show comment highlights and threads in the browser editor.",["comments","visible"],!1),h("comments-hidden","Hide Comments","review","Hide comment highlights and threads in the browser editor.",["comments","hidden"],!1),h("comments-show-resolved","Show Resolved Comments","review","Include resolved comments in the comment list and review timeline.",["comments","resolved"],!1),h("comments-hide-resolved","Hide Resolved Comments","review","Filter resolved comments out of the comment list and review timeline.",["comments","resolved"],!1),h("comments-visibility-all","All Comments","review","Show both internal and external comments.",["comments","all"],!1),h("comments-visibility-internal","Internal Comments","review","Filter the comment display to internal comment threads.",["comments","internal"],!1),h("comments-visibility-external","External Comments","review","Filter the comment display to external comment threads.",["comments","external"],!1),h("tracking-toggle","Toggle Track Changes","review","Switch between direct editing and suggestion mode.",["suggesting","review","changes"]),h("track-changes-accept-selection","Accept Selection Changes","review","Accept tracked revisions that overlap the current selection.",["track changes","selection","accept"],!1),h("track-changes-reject-selection","Reject Selection Changes","review","Reject tracked revisions that overlap the current selection.",["track changes","selection","reject"],!1),h("search-set-query","Search","search","Run a document search query.",["find"],!1),h("search-next","Next Search Result","search","Advance to the next current search hit.",["find","next"],!1),h("search-previous","Previous Search Result","search","Move back to the previous current search hit.",["find","previous"],!1),h("search-clear","Clear Search","search","Clear the current search session.",["find","reset"]),h("search-replace-active","Replace Current Search Result","search","Replace the active current search hit.",["find","replace"],!1),h("search-replace-all","Replace All Search Results","search","Replace every current search hit.",["find","replace","all"],!1),h("review-accept-all","Accept All Changes","review","Accept all tracked revisions in the document.",["track changes","approve"]),h("review-reject-all","Reject All Changes","review","Reject all tracked revisions in the document.",["track changes","discard"]),h("proofing-ignore-first","Ignore First Proofing Issue","proofing","Ignore the first current proofing diagnostic.",["spelling","grammar","ignore"]),h("proofing-accept-first","Accept First Proofing Suggestion","proofing","Apply the first current proofing suggestion without tracking.",["spelling","grammar","fix"]),h("proofing-replace-first-tracked","Track First Proofing Fix","proofing","Apply the first current proofing suggestion with tracked changes.",["spelling","grammar","review"],!1)]),yT=Object.freeze(ur.map(e=>e.id)),It=Object.freeze(ur.filter(e=>!dc(e.id)&&!ya(e.id))),PT=Object.freeze(It.map(e=>e.id)),CT=new Map(ur.map(e=>[e.id,e]));function Kh(e){let t=e.members?.length?e.members:null;return t?t.every(r=>(r.text?.length??0)===0&&r.target?.nodeType!=="text"):(e.text?.length??0)===0&&e.target?.nodeType!=="text"}function Uh(e,t){if(!t||e.length===0)return!1;let r=new Map(t.map(o=>[o.id,o]));return e.every(o=>{let n=r.get(o);return n?Kh(n):!1})}function pi(e,t){return X([...e.activeChangeIds??[],...e.selection.trackedChangeIds??[]],t)}function wi(e){let t=X(e.liveSelectionInfo?.activeChangeIds,e.revisions);return t.length>0?t:X(e.liveSelection.trackedChangeIds,e.revisions)}function Wh(e){return e.liveSelection.empty&&e.liveSelection.from===e.liveSelection.to&&!e.effectiveSelection.selection.empty&&e.liveSelection.from>=e.effectiveSelection.selection.from&&e.liveSelection.from<=e.effectiveSelection.selection.to}function Xh(e,t){return e.length>0&&e.length<t.length&&e.every(r=>t.includes(r))}function Gh(e){return e.liveSelection.empty&&e.liveSelection.from===e.liveSelection.to&&e.liveReviewChangeIds.length>0&&e.effectiveReviewChangeIds.length>0&&!(Wh(e)&&Xh(e.liveReviewChangeIds,e.effectiveReviewChangeIds))&&!ds(e.liveReviewChangeIds,e.effectiveReviewChangeIds)}function Yh(e){let t=pi(e.effectiveSelection,e.revisions),r=wi({liveSelection:e.liveSelection,liveSelectionInfo:{activeChangeIds:[...e.liveActiveChangeIds]},revisions:e.revisions});return e.liveSelection.empty&&e.liveSelection.from===e.liveSelection.to&&!e.effectiveSelection.selection.empty&&e.liveSelection.from===(e.boundary==="start"?e.effectiveSelection.selection.from:e.effectiveSelection.selection.to)&&e.effectiveSelection.selection.from!==e.effectiveSelection.selection.to&&r.length===0&&t.length>0}function $h(e){return Yh({...e,boundary:"end"})}function Zh(e){let t=pi(e.effectiveSelection,e.revisions),r=wi({liveSelection:e.liveSelection,liveSelectionInfo:{activeChangeIds:[...e.liveActiveChangeIds]},revisions:e.revisions}),o=Uh(t,e.revisions);return e.liveSelection.empty&&e.liveSelection.from===e.liveSelection.to&&e.effectiveSelection.selection.empty&&e.liveSelection.from===e.effectiveSelection.selection.to&&r.length===0&&t.length>0&&!o}function Bo(e){let t=wi(e);if(!e.effectiveSelection)return t;if($h({liveSelection:e.liveSelection,liveActiveChangeIds:ae(e.liveSelectionInfo?.activeChangeIds),effectiveSelection:e.effectiveSelection,revisions:e.revisions}))return[];if(Zh({liveSelection:e.liveSelection,liveActiveChangeIds:ae(e.liveSelectionInfo?.activeChangeIds),effectiveSelection:e.effectiveSelection,revisions:e.revisions}))return[];let r=pi(e.effectiveSelection,e.revisions);return Gh({liveSelection:e.liveSelection,liveReviewChangeIds:t,effectiveReviewChangeIds:r,effectiveSelection:e.effectiveSelection})?t:r.length>0?r:t}import{readSyntheticSideStoryDocOriginPath as Jh}from"@datalking/begonia-doc-service/v1";var Qh="Detached side-story surfaces are read-only. Route mutations through the host document controller.";function eb(e){return Jh(e?.document??null)!=null}function gi(e){return e?eb(e)?Qh:e.editable?null:"Document is read-only in the current document mode.":"Editor is not ready."}function pc(e){return gi(e)==null}function tb(e){if(!e)return"Editor is not ready.";let t=gi({editable:e.editable,document:e.document});return t||(e.commentsDisplay.enabled?e.commentsDisplay.readOnly?"Comments are read-only in the current document mode.":null:"Comments are disabled for this editor.")}function hi(e,t,r=null){let o=tb(e);return o||(r?.target||r?.selectionTarget||t&&vo(t)?null:"Place the caret in text or select text before creating a comment.")}import{resolveTrackingToggleState as lb}from"@datalking/begonia-editor-contracts";function rb(e){return wo([...e.activeChangeIds??[],...e.selection?.trackedChangeIds??[]])}function wc(e,t=rb(e)){return Xa({empty:e.empty,target:e.selectionTarget,activeMarks:[...e.activeMarks??[]],activeCommentIds:[...e.activeCommentIds??[]],activeChangeIds:[...t],...typeof e.text=="string"?{text:e.text}:{}},e.selectionKind,e.selectionKind==="node"&&e.selectionTarget!=null&&e.nodeSelectionTarget!=null)}import{createEditorSelectionSnapshot as ab}from"@datalking/begonia-editor-contracts";import{resolveEditorSelectionRootOffsets as gc}from"@datalking/begonia-editor-contracts";function yo(e){let t=gc(e);return t?{...t,empty:e.empty,trackedChangeIds:e.trackedChangeIds}:null}function hc(e){let t=gc(e);return t?{kind:e.kind,...t,empty:e.empty,editable:e.editable,trackedChangeIds:[...e.trackedChangeIds],block:{...e.block},formatting:structuredClone(e.formatting)}:null}var bc=Object.freeze({canUndo:!1,canRedo:!1});function vc(e){if(typeof e!="function")return!1;try{return e()===!0}catch{return!1}}function Sc(e){if(!e)return bc;let t=vc(e.canUndo),r=vc(e.canRedo);return!t&&!r?bc:{canUndo:t,canRedo:r}}var ob=["align-left","align-center","align-right","align-justify"],Bc=["indent-increase","indent-decrease"];function nb(e){return ob.includes(e)||Bc.includes(e)}function yc(e,t,r,o){if(!nb(e.id))return null;if(Bc.includes(e.id)){let s=t.indentLeft??0;return o(e,r||e.id==="indent-decrease"&&s<=0,!1,s)}let n=e.id.slice(6),i=t.align??null;return o(e,r,i===n,i,t.mixedAttributes?.includes("align")===!0)}function Pc(e){if(!e)return!1;let{$from:t}=e.selection;for(let r=t.depth;r>0;r-=1){let o=t.node(r).type.name;if(o==="table_cell"||o==="table_header")return!0}return!1}function Cc(e){if(!e||e.selection.empty)return!1;let t=(()=>{let{$from:o}=e.selection;for(let n=o.depth;n>0;n-=1){let i=o.node(n).type.name;if(i==="table_cell"||i==="table_header")return i}return null})(),r=(()=>{let{$to:o}=e.selection;for(let n=o.depth;n>0;n-=1){let i=o.node(n).type.name;if(i==="table_cell"||i==="table_header")return i}return null})();return t==null||r==null?!1:e.selection.$from.pos!==e.selection.$to.pos}var ib=["insert-table","insert-image"],sb=["table-insert-row-above","table-insert-row-below","table-insert-column-left","table-insert-column-right","table-delete-row","table-delete-column","table-delete","table-split-cell"];function xc(e,t,r,o){if(ib.includes(e.id))return o(e,!t.editable,!1,t.selection.block.kind);if(sb.includes(e.id)){let n=Pc(r);return o(e,!t.editable||!n,n,null)}if(e.id==="table-merge-cells"){let n=Cc(r);return o(e,!t.editable||!n,n,null)}return null}function tt(e){let t=Ae(e);return t.flowMode==="web"?t.preferredPaginatedLayoutMode:t.layoutMode}function bi(e){return e.flowMode==="paginated"||e.flowMode==="web"}function vi(e){return e.zoom?.mode==="fit-width"?"fit-width":"manual"}function Si(e,t,r,o){return e!=null||!t||r?e:`Collapsed ${o} formatting requires a live editor surface. Select text to format in headless mode.`}function Bi(e,t){return e||!t}function Ec(e){let t=e&&typeof e=="object"?e.nodeType:null;return t==="paragraph"||t==="heading"}function kc(e,t){return t?t.selectionKind==="node"&&Ec(t.nodeSelectionTarget):Ec(Le(e??null))}function S(e,t=!0,r=!1,o=null,n=!1){return{active:r,disabled:t,...n?{mixed:!0}:{},value:o,title:e.title,description:e.description??null,group:e.group??null}}function Rt(e){let t=e?.catalog??It,r=e?.commandIds;if(!r||r.length===0)return t;let o=e?.catalog??ur,n=new Map(o.map(i=>[i.id,i]));return r.map(i=>n.get(i)).filter(i=>i!=null)}function Tc(e){return e.revisions}function Ic(e,t){let r=Ae(e),o=e.search.activeHitId?e.search.hits.findIndex(a=>a.hitId===e.search.activeHitId):-1,n=Tc(e),i=K(e.viewport),s=t?ab(t.selection,e.selection.range.revision,e.selection.range.range.anchor.story):e.toolbar.selection??e.selection,l=t?wc(t):e.selectionInfo;return{selection:Mc(s,l,n),documentMode:e.documentMode,editable:e.editable,trackChanges:e.trackChanges,flowMode:r.flowMode,layoutMode:r.layoutMode,preferredPaginatedLayoutMode:r.preferredPaginatedLayoutMode,zoomPercent:e.zoomPercent,viewport:i,totalPages:i?.totalPages??null,currentPageIndex:i?.currentPageIndex??null,currentPageNumber:i?.currentPageNumber??null,searchQuery:e.search.query,searchHitCount:e.search.hits.length,activeSearchHitId:e.search.activeHitId,activeSearchHitIndex:o,revisionCount:n.length,firstRevisionId:n[0]?.id??null,proofingDiagnosticCount:e.proofing.diagnostics.length,firstProofingDiagnosticId:e.proofing.diagnostics[0]?.diagnosticId??null}}function Rc(e,t,r,o,n,i){let s=i?.selection??hc(t.selection)??{from:0,to:0,empty:!0},l=t.trackChanges.enabled,a=Sc(e?.surface),c=Tc(t),u=Bo({liveSelection:yo(t.selection)??{from:0,to:0,empty:!0,trackedChangeIds:t.selection.trackedChangeIds},liveSelectionInfo:t.selectionInfo,revisions:c,effectiveSelection:i}),d=t.editable?Tt({editable:t.editable},o,i):"Document is read-only in the current document mode.",m=Si(d,s.empty,n,"inline"),f=Si(d,s.empty,n,"text-style"),g=t.editable?hi({editable:t.editable,commentsDisplay:t.commentsDisplay},o,i):hi({editable:t.editable,commentsDisplay:t.commentsDisplay},o,i),p=kc(o,i),b=Bi(!t.editable||!s.editable&&!p,n),w=s.formatting.mixed??{},y=Bi(d!=null,n);switch(r.id){case"bold":return S(r,m!=null,s.formatting.bold,s.formatting.bold,w.bold===!0);case"italic":return S(r,m!=null,s.formatting.italic,s.formatting.italic,w.italic===!0);case"underline":return S(r,m!=null,s.formatting.underline,s.formatting.underline,w.underline===!0);case"strikethrough":return S(r,m!=null,s.formatting.strike,s.formatting.strike,w.strike===!0);case"font-size":return S(r,f!=null,s.formatting.fontSize!=null||w.fontSize===!0,s.formatting.fontSize,w.fontSize===!0);case"font-family":return S(r,f!=null,s.formatting.fontFamily!=null||w.fontFamily===!0,s.formatting.fontFamily,w.fontFamily===!0);case"text-color":return S(r,f!=null,s.formatting.color!=null||w.color===!0,s.formatting.color,w.color===!0);case"highlight-color":return S(r,f!=null,s.formatting.highlight!=null||w.highlight===!0,s.formatting.highlight,w.highlight===!0);case"paragraph":return S(r,b,s.block.kind==="paragraph",s.block.kind);case"heading-1":return S(r,b,s.block.kind==="heading"&&s.block.headingLevel===1,s.block.headingLevel);case"heading-2":return S(r,b,s.block.kind==="heading"&&s.block.headingLevel===2,s.block.headingLevel);case"heading-3":return S(r,b,s.block.kind==="heading"&&s.block.headingLevel===3,s.block.headingLevel);case"bullet-list":return S(r,b,s.block.listKind==="bullet_list",s.block.listKind);case"numbered-list":return S(r,b,s.block.listKind==="ordered_list",s.block.listKind);case"zoom":return S(r,!1,!1,t.zoomPercent);case"zoom-fit-width":return S(r,!1,vi(t)==="fit-width",vi(t));case"document-mode-editing":return S(r,!1,t.documentMode==="editing",t.documentMode);case"document-mode-suggesting":return S(r,!t.trackChanges.enabled,t.documentMode==="suggesting",t.documentMode);case"document-mode-viewing":return S(r,!1,t.documentMode==="viewing",t.documentMode);case"flow-mode-paginated":return S(r,!1,t.flowMode==="paginated",t.flowMode);case"flow-mode-web":return S(r,!1,t.flowMode==="web",t.flowMode);case"layout-mode-vertical":return S(r,!1,tt(t)==="vertical",tt(t));case"layout-mode-horizontal":return S(r,!bi(t),tt(t)==="horizontal",tt(t));case"layout-mode-book":return S(r,!bi(t),tt(t)==="book",tt(t));case"track-changes-display-review":return S(r,!1,t.trackChanges.mode==="review",t.trackChanges.mode);case"track-changes-display-original":return S(r,t.documentMode!=="viewing",t.trackChanges.mode==="original",t.trackChanges.mode);case"track-changes-display-final":return S(r,t.documentMode!=="viewing",t.trackChanges.mode==="final",t.trackChanges.mode);case"track-changes-display-off":return S(r,!1,t.trackChanges.mode==="off",t.trackChanges.mode);case"comments-visible":return S(r,!t.commentsDisplay.enabled,t.commentsDisplay.visible,t.commentsDisplay.visible);case"comments-hidden":return S(r,!t.commentsDisplay.enabled,!t.commentsDisplay.visible,t.commentsDisplay.visible);case"comments-show-resolved":return S(r,!t.commentsDisplay.enabled,t.commentsDisplay.showResolved,t.commentsDisplay.showResolved);case"comments-hide-resolved":return S(r,!t.commentsDisplay.enabled,!t.commentsDisplay.showResolved,t.commentsDisplay.showResolved);case"comments-visibility-all":return S(r,!t.commentsDisplay.enabled||t.commentsDisplay.suppressInternalExternal,t.commentsDisplay.visibility==="all",t.commentsDisplay.visibility);case"comments-visibility-internal":return S(r,!t.commentsDisplay.enabled||t.commentsDisplay.suppressInternalExternal,t.commentsDisplay.visibility==="internal",t.commentsDisplay.visibility);case"comments-visibility-external":return S(r,!t.commentsDisplay.enabled,t.commentsDisplay.visibility==="external",t.commentsDisplay.visibility);case"tracking-toggle":{let O=lb({editable:t.editable,documentMode:t.documentMode,trackingEnabled:l,trackChangesAvailable:l});return S(r,O.disabled,O.active,t.documentMode)}case"comment-create":return S(r,g!=null,!1,t.comments.length);case"link-set":return S(r,y,s.formatting.link||w.linkHref===!0,s.formatting.linkHref,w.link===!0||w.linkHref===!0);case"link-clear":return S(r,y||!s.formatting.link&&w.linkHref!==!0,s.formatting.link||w.linkHref===!0,s.formatting.linkHref,w.link===!0||w.linkHref===!0);case"track-changes-accept-selection":case"track-changes-reject-selection":return S(r,u.length===0||!t.editable,u.length>0,u);case"review-accept-all":case"review-reject-all":return S(r,c.length===0||!t.editable,!1,c.length)}let E=(t.toolbar.commands??{})[r.id];if(E)return{...E,title:r.title,description:r.description??null,group:r.group??null};switch(r.id){case"search-set-query":return S(r,!1,t.search.query.length>0,t.search.query);case"search-next":case"search-previous":return S(r,t.search.hits.length===0,!1,t.search.activeHitId);case"search-clear":return S(r,t.search.query.length===0,!1,t.search.query);case"search-replace-active":return S(r,t.search.hits.length===0||!t.editable,!1,t.search.activeHitId);case"search-replace-all":return S(r,t.search.hits.length===0||!t.editable,!1,t.search.hits.length);case"proofing-ignore-first":case"proofing-accept-first":case"proofing-replace-first-tracked":return S(r,t.proofing.diagnostics.length===0||!t.editable,!1,t.proofing.diagnostics[0]?.diagnosticId??null);case"insert-math-inline":return S(r,!t.editable||!s.editable||p,!1,s.block.kind);case"insert-chart-block":case"insert-shape-block":return S(r,!t.editable,!1,t.selection.block.kind);case"remove-selected-ooxml":return S(r,t.advancedOoxml.selected==null||!t.editable,t.advancedOoxml.selected!=null,t.advancedOoxml.selected?.objectId??null);case"selected-math-set-plain-text":case"selected-math-toggle-display-mode":return S(r,t.advancedOoxml.selected?.family!=="math"||!t.editable,t.advancedOoxml.selected?.family==="math",t.advancedOoxml.selected?.objectId??null);case"selected-chart-set-title":case"selected-chart-add-series":case"selected-chart-add-axis":return S(r,t.advancedOoxml.selected?.family!=="chart"||!t.editable,t.advancedOoxml.selected?.family==="chart",t.advancedOoxml.selected?.objectId??null);case"selected-shape-set-text-body":case"selected-shape-set-fill":case"selected-shape-add-child":return S(r,t.advancedOoxml.selected?.family!=="shape"||!t.editable,t.advancedOoxml.selected?.family==="shape",t.advancedOoxml.selected?.objectId??null);case"undo":return S(r,!t.editable||!a.canUndo);case"redo":return S(r,!t.editable||!a.canRedo);default:{let O=yc(r,s.block,b,S);return O||(xc(r,t,o,S)??S(r))}}}function Mc(e,t,r){if(!e)return null;let o=Nr(e,r),n=t?Ar(t,o,r):null;return _r(o,n)}function Nc(e,t){let r=Ae(e),o=K(e.viewport?.value??null),n=e.selection?Nr(e.selection,e.review.revisions):e.selection,i=n??e.selection,s=e.selectionInfo&&i?Ar(e.selectionInfo,i,e.review.revisions):e.selectionInfo,l=e.advancedOoxml;return{...e,flowMode:r.flowMode,layoutMode:r.layoutMode,preferredPaginatedLayoutMode:r.preferredPaginatedLayoutMode,selection:n,selectionInfo:s,viewport:e.viewport?{...e.viewport,value:o,totalPages:o?.totalPages??null,currentPageIndex:o?.currentPageIndex??null,currentPageNumber:o?.currentPageNumber??null}:e.viewport,trackChanges:t?.trackChanges??{enabled:e.review.enabled,visible:e.review.visible,mode:e.review.mode,replacements:e.review.replacementMode},viewportRequestKey:t?.viewportRequestKey??e.viewport?.requestKey??null,previewNavigationRequest:t?.previewNavigationRequest??e.viewport?.previewNavigationRequest??null,advancedOoxml:t?.advancedOoxml??l}}import{cloneEditorSelectionSnapshot as Vc,deriveEditorUiSnapshot as wb}from"@datalking/begonia-editor-contracts";function Ie(e){return Object.freeze([...e])}var Fe=Object.freeze({history:Ie(["undo","redo"]),view:Ie(["zoom","zoom-fit-width","flow-mode-paginated","flow-mode-web","layout-mode-vertical","layout-mode-horizontal","layout-mode-book"]),formatting:Ie(["bold","italic","underline","strikethrough","font-size","font-family","text-color","highlight-color","link-set","link-clear"]),blocks:Ie(["paragraph","heading-1","heading-2","heading-3","bullet-list","numbered-list","align-left","align-center","align-right","align-justify","indent-increase","indent-decrease"]),review:Ie(["document-mode-editing","document-mode-suggesting","document-mode-viewing","comment-create","comments-visible","comments-hidden","comments-show-resolved","comments-hide-resolved","comments-visibility-all","comments-visibility-internal","comments-visibility-external","tracking-toggle","track-changes-accept-selection","track-changes-reject-selection","track-changes-display-review","track-changes-display-original","track-changes-display-final","track-changes-display-off","review-accept-all","review-reject-all"]),search:Ie(["search-set-query","search-next","search-previous","search-clear","search-replace-active","search-replace-all"]),proofing:Ie(["proofing-ignore-first","proofing-accept-first","proofing-replace-first-tracked"]),insert:Ie(["insert-table","insert-image","table-insert-row-above","table-insert-row-below","table-insert-column-left","table-insert-column-right","table-delete-row","table-delete-column","table-delete","table-merge-cells","table-split-cell"]),advancedOoxml:Ie(["insert-math-inline","insert-chart-block","insert-shape-block","remove-selected-ooxml","selected-math-set-plain-text","selected-math-toggle-display-mode","selected-chart-set-title","selected-chart-add-series","selected-chart-add-axis","selected-shape-set-text-body","selected-shape-set-fill","selected-shape-add-child"])}),Po=Object.freeze([{id:"history",label:"History",commandIds:Fe.history},{id:"view",label:"View",commandIds:Fe.view},{id:"formatting",label:"Formatting",commandIds:Fe.formatting},{id:"blocks",label:"Blocks",commandIds:Fe.blocks},{id:"insert",label:"Insert",commandIds:Fe.insert},{id:"review",label:"Review",commandIds:Fe.review},{id:"search",label:"Search",commandIds:Fe.search},{id:"proofing",label:"Proofing",commandIds:Fe.proofing}]),pI=Object.freeze(Po.flatMap(e=>[...e.commandIds]));function cb(e){return[{id:"commands",label:"Commands",commandIds:e.map(t=>t.id)}]}function ub(e,t){if(t&&t.length>0)return t;if(e.length===0)return[];let r=new Set(Po.flatMap(n=>n.commandIds));return e.every(n=>r.has(n.id))?Po:cb(e)}function db(e){return e?[...e]:[]}function mb(e,t){return{id:e.id,title:e.title,description:e.description??null,group:e.group??null,keywords:db(e.keywords),slash:e.slash??!1,state:t}}function fb(e,t,r){return e.flatMap(o=>{let n=t.get(o);return n?[mb(n,r[o]??null)]:[]})}function Ac(e){let t=ub(e.catalog,e.sections),r=new Map(e.catalog.map(o=>[o.id,o]));return t.map(o=>({id:o.id,label:o.label,items:fb(o.commandIds,r,e.commands)})).filter(o=>o.items.length>0)}import{normalizeCommittedDocument as PI}from"@datalking/begonia-document-model";import{createDocumentRuntimeKernel as xI}from"@datalking/begonia-document-api/v1";import{createDocumentScopedMemo as kI,resolveRevisionProjectedDocument as TI}from"@datalking/begonia-engine";import{preserveSyntheticSideStoryDocMetadata as vI,readSyntheticSideStoryDocOriginPath as SI}from"@datalking/begonia-doc-service/v1";function Oc(e,t){return e==="suggesting"&&t.enabled}var Lc=["undo","redo","bold","italic","underline","strikethrough","paragraph","heading-1","heading-2","heading-3","bullet-list","numbered-list","link-set","link-clear","align-left","align-center","align-right","align-justify","indent-increase","indent-decrease","tracking-toggle","track-changes-accept-selection","track-changes-reject-selection"];function gb(e){return Oc(e.documentMode,e.trackChanges)}function hb(e){return e.collaboration.collaborative??!1}function bb(e){return{selection:Vc(e.selection),editable:e.editable,trackingEnabled:gb(e),trackingAuthoringAvailable:e.trackChanges.enabled,documentMode:e.documentMode,collaborative:hb(e),canUndo:e.canUndo,canRedo:e.canRedo,commandStates:e.commandStates}}function vb(e,t=e.toolbar.commands){return{selection:e.selection,editable:e.editable,documentMode:e.documentMode,trackChanges:e.trackChanges,collaboration:e.collaboration,canUndo:t.undo?.disabled===!1,canRedo:t.redo?.disabled===!1,commandStates:t}}function Sb(e,t){return t?.commands??e.toolbar.commands}function Bb(e){return wb(bb(e))}function yb(e,t){let r=Bb(vb(e,Sb(e,t))),o=t?.catalog??[];return{...r,catalog:o,sections:Ac({catalog:o,commands:r.commands})}}function Co(e,t){let r=yb(e,t),o=e.zoom??{mode:"manual",value:e.zoomPercent,fitZoom:null,min:10,max:400,viewportMetrics:null},n=e.commentsDisplay??{enabled:!1,visible:!1,readOnly:!1,showResolved:!1,visibility:"all"},i=e.trackChanges??{enabled:!1,visible:!1,mode:"off",replacements:"paired"},s=e.collaboration??{collaborative:!1,mode:"none",reconfigurable:!1,providerName:null,roomId:null,status:"disconnected",connected:!1,synced:null,awarenessClientCount:null,message:null},l=Cn({revisions:e.revisions,selectionInfo:e.selectionInfo}),a=xn({comments:e.comments,selectionInfo:e.selectionInfo,explicitActiveCommentId:e.activeCommentId,explicitActiveCommentIds:e.activeCommentIds}),c=e.activeRevisionId??l.activeRevisionId,u=e.activeRevisionIds??l.activeRevisionIds;return{selection:Vc(e.selection),selectionInfo:bt(e.selectionInfo),trackingEnabled:r.trackingEnabled,collaborative:r.collaborative,commands:r.commands,editable:e.editable,documentMode:e.documentMode,flowMode:e.flowMode,layoutMode:e.layoutMode,preferredPaginatedLayoutMode:e.preferredPaginatedLayoutMode,commandCatalog:r.catalog,toolbar:r,viewport:{value:e.viewport,requestKey:e.viewportRequestKey,previewNavigationRequest:e.previewNavigationRequest,totalPages:e.viewport?.totalPages??null,currentPageIndex:e.viewport?.currentPageIndex??null,currentPageNumber:e.viewport?.currentPageNumber??null},zoom:{percent:e.zoomPercent,mode:o.mode,value:o.value,fitZoom:o.fitZoom,min:o.min,max:o.max,viewportMetrics:o.viewportMetrics},comments:{items:e.comments,permissions:e.commentPermissions,total:e.comments.length,activeCommentId:a.activeCommentId,activeCommentIds:a.activeCommentIds,enabled:n.enabled,visible:n.visible,readOnly:n.readOnly,allowResolve:n.allowResolve,showResolved:n.showResolved,visibility:n.visibility,useInternalExternalComments:n.useInternalExternalComments,suppressInternalExternal:n.suppressInternalExternal,enforceVisibilityPolicy:n.enforceVisibilityPolicy},review:{revisions:e.revisions,permissions:e.reviewPermissions,timeline:e.reviewTimeline,summary:e.reviewTimelineSummary,activeRevisionId:c,activeRevisionIds:u,enabled:i.enabled,visible:i.visible,mode:i.mode,replacementMode:i.replacements},search:{query:e.search.query,hits:e.search.hits,activeHitId:e.search.activeHitId},proofing:{diagnostics:e.proofing.diagnostics},advancedOoxml:{selected:e.advancedOoxml.selected},collaboration:{...s,connected:s.connected??!1}}}function yi(e,t=Rt(void 0)){let r=e.getState(),o=e.surface?.state,n=e.surface?.view!=null,i=e.readEffectiveSelection?.()??e.captureEffectiveSelection?.()??null;return{editor:r,context:Ic(r,i),catalog:t,commands:Object.fromEntries(t.map(s=>[s.id,Rc(e,r,s,o,n,i)]))}}function Dc(e,t=Rt(void 0)){let r=yi(e,t),o=e.getState();return{editor:Nc(Co(o,r),{trackChanges:o.trackChanges,viewportRequestKey:o.viewportRequestKey,previewNavigationRequest:o.previewNavigationRequest,advancedOoxml:{selected:o.advancedOoxml.selected}}),context:r.context,catalog:r.catalog,commands:r.commands}}import{documentWideMutationEffect as Pb}from"@datalking/begonia-editor-contracts";function Hc(e){return e?e.documentService.readDocument():null}function Fc(e){return ie(e)?.view??null}function jc(e){return ie(e)?.automation??null}function zc(e,t){let r=ie(e);return r?(r.replaceDocument(t,{origin:"api",intent:"replace-browser-document",effects:[Pb("content")]}),!0):!1}function Cb(e){return e?"documentApi"in e?ie(e):e:null}function qc(e,t){let r=Cb(e),o=r?.view;if(!o?.state||typeof o.dispatch!="function")return!1;let n=r,i=We(o.state.doc,t);if(!i)return!1;let s=M(o.state,i.from,i.to);return s?Kt(n,s):!1}var _c=Symbol("captureBrowserEditorPositionAtPointInternal");import{NodeSelection as Uc}from"prosemirror-state";function xb(e,t){return typeof t!="number"||!Number.isFinite(t)?null:Math.max(1,Math.min(Math.trunc(t),e.doc.content.size))}function Kc(e,t){return typeof t!="number"||!Number.isFinite(t)?null:Math.max(0,Math.min(Math.trunc(t),e.doc.content.size))}function Eb(e,t,r){let o=e.view.dom,n=e.view.dom.ownerDocument,i=typeof o.getBoundingClientRect=="function"?o.getBoundingClientRect():null;if(i&&Number.isFinite(i.left)&&Number.isFinite(i.right)&&Number.isFinite(i.top)&&Number.isFinite(i.bottom)&&(t<i.left||t>i.right||r<i.top||r>i.bottom))return!1;if(!o||!n||typeof n.elementFromPoint!="function"||typeof o.contains!="function")return!0;let s=n.elementFromPoint(t,r);return!s||o.contains(s)}function kb(e,t){let r=M(e,t,t);if(!r)return null;try{return e.apply(e.tr.setSelection(r))}catch{return null}}function Tb(e,t){try{return e.apply(e.tr.setSelection(Uc.create(e.doc,t)))}catch{return null}}function Ib(e,t){let r=e.doc.nodeAt(t);return!!(r&&Uc.isSelectable(r)&&(r.isLeaf||r.isAtom))}function Rb(e,t){return[Kc(e,t?.inside),Kc(e,t?.pos)].filter((o,n,i)=>o!=null&&i.indexOf(o)===n).find(o=>Ib(e,o))??null}function Wc(e){let t=e.surface.view;if(!t?.state||typeof t.posAtCoords!="function"||!Eb(e.surface,e.clientX,e.clientY))return null;let r=t.posAtCoords({left:e.clientX,top:e.clientY})??null;if((e.mode??"node-or-text")!=="text-only"){let s=Rb(t.state,r);if(s!=null){let l=Tb(t.state,s);if(l)return{pos:s,state:l}}}let n=xb(t.state,r?.pos);if(n==null)return null;let i=kb(t.state,n);return i?{pos:n,state:i}:null}function Mb(e){let t=e?.selectionTarget;if(t&&t.segments.length===1&&t.segments[0]?.range.start===t.segments[0]?.range.end){let i=t.segments[0];return{kind:"text",blockId:i.blockId,offset:i.range.start}}let r=e?.target;if(!r||typeof r!="object"||!("blockId"in r)||!("range"in r))return null;let o=typeof r.blockId=="string"?r.blockId:null,n=r.range;return!o||!n||typeof n!="object"||typeof n.start!="number"||typeof n.end!="number"||n.start!==n.end?null:{kind:"text",blockId:o,offset:n.start}}function Nb(e,t){let r=Wc({surface:e.surface,clientX:t.clientX,clientY:t.clientY});if(!r?.state.selection.empty)return null;let o=Qe(r.state).target,n=o?.segments[0];return!o||o.segments.length!==1||!n||n.range.start!==n.range.end?null:{point:{kind:"text",blockId:n.blockId,offset:n.range.start},target:{kind:"text",segments:[{blockId:n.blockId,range:{start:n.range.start,end:n.range.end}}]}}}function Ab(e,t){return e&&typeof e=="object"&&"kind"in e&&e.kind==="text"?t:e}function Xc(e){if(!e||typeof e!="object"||Object.isFrozen(e))return e;Object.freeze(e);for(let t of Object.values(e))Xc(t);return e}function Ob(e,t){let r=e.selectionTarget?.segments[0],o=t.segments[0];return e.selectionTarget?.segments.length===1&&r&&r.blockId===o.blockId&&r.range.start===o.range.start&&r.range.end===o.range.end?e:Xc(structuredClone({...e,selectionTarget:t,target:Ab(e.target,t)}))}function Mt(e,t){if(!t||typeof t!="object"||typeof t.clientX!="number"||typeof t.clientY!="number")return null;let r=e[_c]?.(t)??null;if(!r||!r.selection.empty)return null;let o=Nb(e,t),n=o?.point??Mb(r),i=o?.target??(n?{kind:"text",segments:[{blockId:n.blockId,range:{start:n.offset,end:n.offset}}],...r.selectionTarget?.story?{story:structuredClone(r.selectionTarget.story)}:{}}:null);if(!n||!i)return null;let s=o?Ob(r,o.target):r;return{point:n,target:i,capture:s}}function Gc(e){return{readDocument(){return Hc(e)},replaceDocument(t){return zc(e,t)},readView(){return Fc(e)},readAutomation(){return jc(e)}}}function Vb(e){return{positionAtPoint(t){return Mt(e,t)},selectTextTarget(t){return vs(e.surface,t)},selectCommentTarget(t){return qc(e,t)}}}function Yc(e){return{selectionHandles:e,linkSelection:e,activeLink:e,view:e,documentMode:e,commentsDisplay:e,commentActions:e,commentFocus:e,reviewActions:e,reviewFocus:e,selectionTargets:Vb(e)}}import{createCanonicalRevisionIdsByAlias as Lb,resolveCanonicalRevisionId as Db,resolveTrackedOverlapParentIdMap as Hb}from"@datalking/begonia-engine";var xo=3,Fb=[[0,0],[-xo,0],[xo,0],[0,-xo],[0,xo]];function Re(e,t){if(!e||typeof e.getAttribute!="function")return null;let r=e.getAttribute(t);return typeof r=="string"?r.trim():null}function Zc(e){return e?e.split(",").map(t=>t.trim()).filter(t=>t.length>0):[]}function jb(e,t){return!t||!e.includes(t)?[...e]:[t,...e.filter(r=>r!==t)]}function zb(e){let t=Zc(Re(e,"data-track-change-ids"));if(t.length>0)return jb(t,Re(e,"data-track-change-preferred-target-id"));let r=Re(e,"data-track-change-id");if(r)return[r];let o=Re(e,"data-change-id");return o?[o]:[]}function qb(e){return!!(Re(e,"data-ald-comment-anchor")||Re(e,"data-ald-comment-range-start")||Re(e,"data-ald-comment-range-end"))}function _b(e){let t=Zc(Re(e,"data-comment-ids"));if(t.length>0)return t;let r=Re(e,"data-thread-id");return r&&qb(e)?[r]:[]}function Jc(e,t){let r=e??null;for(;r;){if(r===t)return!0;r=r.parentElement??null}return!1}function Kb(e,t,r){if(!e||!Jc(e,t))return[];let o=[],n=e;for(;n;){for(let i of zb(n)){let s=`trackedChange:${i}`;r.has(s)||(r.add(s),o.push({kind:"trackedChange",id:i}))}for(let i of _b(n)){let s=`comment:${i}`;r.has(s)||(r.add(s),o.push({kind:"comment",id:i}))}if(n===t)break;n=n.parentElement??null}return o}function Ub(e,t,r){let o=e?.ownerDocument??null;if(!o)return[];let n=(()=>{if(typeof o.elementsFromPoint!="function")return[];try{return o.elementsFromPoint(t,r)??[]}catch{return[]}})();if(n.length>0)return n;let i=(()=>{if(typeof o.elementFromPoint!="function")return null;try{return o.elementFromPoint(t,r)}catch{return null}})();return i?[i]:[]}function Wb(e,t){return e.some(r=>Jc(r,t))}function $c(e,t){let r=Number(t);return Number.isFinite(r)?Math.max(0,Math.min(e,Math.max(0,r-1))):e}function Xb(e,t,r){let o=e.ownerDocument??null,n=o?.defaultView?.innerWidth??null,i=o?.defaultView?.innerHeight??null,s=[],l=new Set;for(let[a,c]of Fb.slice(1)){let u=$c(t+a,n),d=$c(r+c,i),m=`${u}:${d}`;l.has(m)||(l.add(m),s.push({x:u,y:d}))}return s}function Qc(e,t,r,o){let n=Ub(e,t,r);return{stack:n,candidates:n.flatMap(i=>Kb(i,e,o))}}function Gb(e,t,r,o){let n=[];for(let i of Xb(e,t,r))n.push(...Qc(e,i.x,i.y,o).candidates);return n}function Yb(e,t){let r=X(e,t??[]),o=r.length>0?r:[...e],n=o[0]??null;return!n||o.length>1&&!tv(o,t)?null:{status:"resolved",kind:"trackedChange",trackedChangeIds:[n],commentIds:[]}}function $b(e){return e.relationship==="child"||!!e.overlapParentId||(e.members??[]).some(t=>t.relationship==="child"||!!t.overlapParentId)}function Zb(e){return[e.overlapParentId,...(e.members??[]).map(t=>t.overlapParentId)]}function Jb(e,t,r){let o=new Set;for(let n of Zb(e)){let i=Db(n,t);i&&i!==e.id&&r.has(i)&&o.add(i)}return o.size===1?[...o][0]:null}function Qb(e){if(!e||e.length===0)return new Map;let t=Lb(e),r=new Set(e.map(o=>o.id));return Hb(e.map(o=>({id:o.id,overlapParentId:$b(o)?Jb(o,t,r):null})))}function ev(e,t){let r=[e],o=new Set(r),n=e;for(;;){let i=t.get(n);if(!i||o.has(i))return r;r.push(i),o.add(i),n=i}}function tv(e,t){if(e.length<=1)return!0;if(!t||t.length===0)return!1;let r=X(e,t);if(r.length<=1)return r.length===1;let o=ev(r[0],Qb(t)),n=new Map(o.map((s,l)=>[s,l])),i=-1;for(let s of r){let l=n.get(s);if(l==null||l<=i)return!1;i=l}return!0}function Pi(e){let t=e.host??null;if(!t)return[];let r=new Set,o=Qc(t,e.clientX,e.clientY,r),n=o.candidates.length>0?o.candidates:Wb(o.stack,t)?Gb(t,e.clientX,e.clientY,r):[];if(n.length===0)return[];let i=e.revisions??[],s=oe(e.comments),l=[],a=new Set;for(let c of n){let u=c.kind==="trackedChange"?X([c.id],i)[0]??c.id:Ue([c.id],s)[0]??null;if(!u)continue;let d=`${c.kind}:${u}`;a.has(d)||(a.add(d),l.push({kind:c.kind,id:u}))}return l}function eu(e){let t=Pi(e),r=t.filter(s=>s.kind==="trackedChange").map(s=>s.id),o=t.filter(s=>s.kind==="comment").map(s=>s.id),n=r.length+o.length;if(n===0)return{status:"none",kind:null,trackedChangeIds:[],commentIds:[]};let i=o.length===0?Yb(r,e.revisions):null;return i||(n>1?{status:"ambiguous",kind:null,trackedChangeIds:r,commentIds:o}:{status:"resolved",kind:r.length===1?"trackedChange":"comment",trackedChangeIds:r,commentIds:o})}function rv(e){return e?{empty:e.empty,target:e.selectionTarget?Mr(e.selectionTarget):null,activeMarks:[...e.activeMarks],activeCommentIds:[...e.activeCommentIds],activeChangeIds:[...e.activeChangeIds],...typeof e.text=="string"?{text:e.text}:{}}:null}function ov(e,t){let r=e.getState();return Pi({host:e.surface.view.dom,clientX:t.clientX,clientY:t.clientY,revisions:r.revisions,comments:r.comments}).map(n=>({type:n.kind,id:n.id}))}function nv(e,t,r,o,n){if(e)return!1;let i=t?.selectionTarget??n;if(t?.selectionKind==="node"||r?.selectionKind==="node")return ut(t?.nodeSelectionTarget,r?.nodeSelectionTarget);let s=r?.empty?r.selectionTarget:null;return us(s??o,i)}function iv(e,t,r){for(let o of r)if(e>=o.left&&e<=o.left+o.width&&t>=o.top&&t<=o.top+o.height)return!0;return!1}function sv(e,t,r,o){if(!e||!t||t.empty)return null;let n=$t(e,t);return n.length===0?null:iv(r,o,n)}function Ci(e,t){return!t||typeof t!="object"||typeof t.clientX!="number"||typeof t.clientY!="number"?[]:ov(e,t)}function tu(e,t,r=null){let o=e.getState(),n=Mt(e,t),i=e.readEffectiveSelection({includeText:!0}),s=e.readPointSelection({clientX:t?.clientX??0,clientY:t?.clientY??0,includeText:!1}),l=typeof t?.clientX=="number"?t.clientX:0,a=typeof t?.clientY=="number"?t.clientY:0,c=sv(r,o.selection,l,a);return{point:{x:l,y:a},entities:Ci(e,t),position:n,selection:bt(o.selectionInfo??rv(i)),insideSelection:c??nv(o.selection.empty,i,s,n?.target??null,o.selectionInfo?.target??null)}}function dr(e){return e!=null&&typeof e.contains=="function"}function xi(e){return typeof e=="string"?e.trim().toLowerCase():""}function lv(e){return e.ownerDocument?.defaultView?.getComputedStyle?.(e)??null}function ru(e){let t=lv(e);if(!t)return{horizontal:"",vertical:""};let r=xi(t.overflow);return{horizontal:xi(t.overflowX)||r,vertical:xi(t.overflowY)||r}}function Eo(e){return e==="auto"||e==="scroll"||e==="overlay"}function av(e){return{vertical:(e.scrollHeight??0)>(e.clientHeight??0),horizontal:(e.scrollWidth??0)>(e.clientWidth??0)}}function cv(e){let t=ru(e),r=av(e);return r.vertical&&Eo(t.vertical)||r.horizontal&&Eo(t.horizontal)}function uv(e){let t=ru(e);return Eo(t.vertical)||Eo(t.horizontal)}function Nt(e){let t=ko(e);return t?(dr(t.parentElement)?t.parentElement:null)??t:null}function ko(e){let t=e?.view?.dom??null;return dr(t)?t:null}function dv(e){let t=e??null;for(;dr(t);){if(cv(t))return t;t=t.parentElement}return null}function mv(e){let t=[],r=e??null;for(;dr(r);)uv(r)&&t.push(r),r=r.parentElement;return t}function mr(e){let t=e?.view?.dom??null;return dr(t)?dv(t):null}function ou(e){let t=ko(e);return t?mv(t):[]}import{createVirtualPagedPreviewAncestorMutationObserver as fv,resolveVirtualPagedPreviewClippingAncestorElements as su}from"@datalking/begonia-layout-renderer";var nu={passive:!0};function iu(e){if(typeof e.getState!="function")return null;let t=e.getState();return t.zoom?.value??t.zoomPercent??null}function fr(e){return typeof e.getState=="function"?e.getState():null}function Ei(e){return e?.commentsDisplay?.enabled===!0&&e.commentsDisplay.visible===!0}function ki(e){return typeof e.getViewportState=="function"?K(e.getViewportState()):null}function pv(e){let t=e;return{request(r){return typeof t?.requestAnimationFrame=="function"?{handle:t.requestAnimationFrame(r),mode:"animation-frame"}:{handle:typeof t?.setTimeout=="function"?t.setTimeout(()=>r(0),0):setTimeout(()=>r(0),0),mode:"timeout"}},cancel(r){if(r){if(r.mode==="animation-frame"&&typeof t?.cancelAnimationFrame=="function"){t.cancelAnimationFrame(r.handle);return}if(typeof t?.clearTimeout=="function"){t.clearTimeout(r.handle);return}clearTimeout(r.handle)}}}}function wv(e){let t=e;return typeof t?.ResizeObserver=="function"?t.ResizeObserver:null}function gv(e,t){let r=new Set;if(tr(e)){r.add(e);for(let o of su(e))r.add(o)}for(let o of t)tr(o)&&r.add(o);return[...r]}function hv(e,t,r,o){let n=new Set;r&&n.add(r);let i=ko(t);i&&n.add(i);for(let s of ou(t))n.add(s);if(e)for(let s of su(e))n.add(s);return n.size===0&&o&&n.add(o),[...n]}function bv(e,t){return e.length===t.length&&e.every((r,o)=>r===t[o])}function lu(e,t=null){let r=new Set,o=new Set,n=!1,i=null,s=ki(e),l=fr(e)?.flowMode??null,a=fr(e)?.layoutMode??null,c=Ei(fr(e)),u=iu(e),d=!1,m=null,f=null,g=null,p=[],b=null,w=[],y=null,x=null,E=!1,O=e.surface??null,k=()=>{E=!0,I("scroll")},Y=()=>{E=!0,I("resize")},j=()=>{let L=Nt(e.surface)?.ownerDocument?.defaultView??null;return pv(L)},q=()=>{let B=i;i=null,B?.cancel()},W=B=>{if(i?.token!==B)return;i=null;let L=[...o];if(o.clear(),n=!1,E&&(E=!1,$(),x?.sync()),r.size===0||L.length===0)return;let z=L.length===1?L[0]:"mixed";for(let _ of[...r])try{_({reason:z})}catch{}},re=()=>{let B=j(),L={},z=null;i={token:L,cancel(){B.cancel(z)}};try{z=B.request(()=>W(L))}catch(_){throw i?.token===L&&(i=null),_}},I=B=>{r.size!==0&&((B==="layout"||B==="zoom")&&n&&(o.delete("scroll"),n=!1),B==="scroll"&&(n=!1),o.add(B),!i&&re())},Ot=()=>{r.size!==0&&(o.has("scroll")||(n=!0),o.add("scroll"),!i&&re())},qe=()=>{g?.removeEventListener?.("scroll",k,!0),g?.removeEventListener?.("resize",Y);for(let B of p)B!==g&&B.removeEventListener?.("scroll",k,nu);y?.disconnect(),g=null,p=[],b=null,w=[],y=null},$=()=>{let B=Nt(e.surface),L=B?.ownerDocument?.defaultView??null,z=mr(e.surface),_=hv(B,e.surface,z,L),we=gv(B,_);if(B===b&&L===g&&_.length===p.length&&_.every((Z,yr)=>Z===p[yr])&&bv(we,w))return;qe(),b=B,g=L,p=_,w=we,g?.addEventListener?.("scroll",k,!0),g?.addEventListener?.("resize",Y);for(let Z of _)Z!==g&&Z.addEventListener?.("scroll",k,nu);let Ke=wv(g);if(!Ke)return;let Me=new Ke(()=>{$(),x?.sync(),I("resize")});for(let Z of we)Me.observe(Z);y=Me},Vt=()=>{x||(x=fv({getPreviewHost:()=>Nt(e.surface),getAdditionalHosts:()=>[mr(e.surface)],onMutation(){$(),x?.sync(),I("layout")}})),x.sync()},ye=()=>{let B=fr(e);if(!B)return;E=!0;let L=(e.surface??null)!==O;O=e.surface??null;let z=B.zoom?.value??B.zoomPercent??null;z!==u&&(d=!0,u=z);let _=ki(e),we=s,Ke=_?.scale!==we?.scale,Me=!vt(we,_);s=_;let Z=B.flowMode,yr=B.layoutMode,dd=Z!==l||yr!==a;l=Z,a=yr;let Gi=Ei(B),md=Gi!==c;if(c=Gi,Ke&&d){d=!1,I("zoom");return}if(d&&Z==="web"){d=!1,I("zoom");return}if(dd||Me&&_?.totalPages!==we?.totalPages){let fd=d?"zoom":"layout";d=!1,I(fd);return}if(md){I("layout");return}if(L){I("layout");return}Me&&Ot()},_e=()=>{if(E=!0,d){d=!1,I("zoom");return}I("layout")},v=()=>{if(m)return;O=e.surface??null,s=ki(e);let B=fr(e);l=B?.flowMode??null,a=B?.layoutMode??null,c=Ei(B),u=iu(e),d=!1,$(),Vt(),m=typeof e.subscribe=="function"?e.subscribe(ye):null,f=t?.subscribeResolvedProjection?.(_e)??null},C=()=>{m?.(),f?.(),m=null,f=null,qe(),x?.cleanup(),x=null,q(),o.clear(),n=!1,d=!1,E=!1};return{observe(B){return r.add(B),r.size===1&&v(),()=>{r.delete(B)&&r.size===0&&C()}}}}import{resolveProjectionCaretRect as vv}from"@datalking/begonia-page-layout";function At(e,t){return Math.max(0,Math.min(Math.max(0,t),e))}function je(e,t){return t>0?e/t:null}function cu(e){return Array.isArray(e)&&e.length>0?[...e]:null}function uu(e){return typeof e=="number"&&Number.isInteger(e)?e:null}function Sv(e,t){let r=Number.isFinite(e)?Math.max(0,Math.trunc(e)):0;return t==null?r:Math.min(t,r)}function du(e,t){let r=e.pages.findIndex(n=>n.pageNumber===t);if(r<0)return null;let o=e.pages[r]??null;return o?{pageIndex:r,page:o}:null}function Bv(e){return!e||e.kind!=="text"||!Array.isArray(e.segments)||e.segments.length===0?[]:e.segments.filter(t=>!!t?.blockId)}function yv(e,t){return e.targets?.resolve?.({kind:"block",blockId:t})??null}function Pv(e,t){let r=cu(t?.path??null);if(r)return e.blocks?.ancestorOf?.(r)??null;let o=uu(t?.anchorFrom);return o==null?null:e.blocks?.byAnchor?.(o)??null}function Cv(e,t){let r=yv(e,t.blockId);if(!r)return null;let o=Pv(e,r),n=uu(o?.from??r.anchorFrom);if(n==null)return null;let i=Sv(t.range.start,typeof r.text=="string"?r.text.length:null);return{absolutePos:n+i,anchorFrom:n,pathHint:cu(o?.path??r.path??null)}}function xv(e,t){return e.pageNumber===t.pageNumber&&e.region===t.region&&e.blockIndex===t.blockIndex&&e.fragmentIndex===t.fragmentIndex&&e.columnIndex===t.columnIndex}function Ev(e,t){return e.pageNumber===t.pageNumber&&e.region===t.region&&e.blockIndex===t.blockIndex&&e.fragmentIndex===t.fragmentIndex&&e.columnIndex===t.columnIndex&&e.lineIndex===t.lineIndex}function au(e){let t=new Set,r=[];for(let o of e){if(!Number.isFinite(o))continue;let n=o.toFixed(3);t.has(n)||(t.add(n),r.push(o))}return r}function kv(e){return e.left+Math.min(Math.max(0,e.width/2),Math.max(0,e.width-1))}function Tv(e){return e.top+Math.min(Math.max(0,e.height/2),Math.max(0,e.height-1))}function Iv(e,t,r,o){if(!r||typeof e.pagination.hitTest!="function")return null;let n=au([kv(r),o.left,r.left,r.left+Math.max(0,r.width-1)]),i=au([Tv(r),o.top+Math.max(0,o.height/2),o.top,r.top]);for(let s of i)for(let l of n){let a=e.pagination.hitTest(o.pageNumber,l,s,t);if(a&&xv(a,r))return a}return null}function Rv(e,t){return e.find(r=>Ev(r,t))??null}function Mv(e,t,r,o,n,i){let s=du(e,t.pageNumber);if(!s)return null;let l=Math.max(0,Number(s.page.pageSize.width??0)),a=Math.max(0,Number(s.page.pageSize.height??0)),c=At(t.top,a),u=At(t.left,l),d=n??i,m=d?t.top-d.top:null,f=d?t.left-d.left:null,g=m==null?null:At(m,d?.height??0),p=f==null?null:At(f,d?.width??0);return{pageIndex:s.pageIndex,pageNumber:t.pageNumber,offsetTopPx:c,offsetTopRatio:je(c,a),offsetLeftPx:u,offsetLeftRatio:je(u,l),offsetPx:c,offsetRatio:je(c,a),region:n?.region??t.region??i?.region??null,sectionId:n?.sectionId??t.sectionId??i?.sectionId??null,anchorFrom:r,pathHint:o,blockIdentity:n?.blockIdentity??i?.blockIdentity??null,fragmentIndex:n?.fragmentIndex??t.fragmentIndex??i?.fragmentIndex??null,columnIndex:n?.columnIndex??t.columnIndex??i?.columnIndex??null,placementOrderHint:n?.blockIndex??t.blockIndex??i?.blockIndex??null,blockOffsetTopPx:g,blockOffsetTopRatio:g==null||!d?null:je(g,d.height),blockOffsetLeftPx:p,blockOffsetLeftRatio:p==null||!d?null:je(p,d.width)}}function Nv(e,t,r,o={}){let n=Cv(e,r);if(!n)return null;let i=vv(t,n.absolutePos,{bias:"start",measureText:o.measureText,measurementEpoch:o.measurementEpoch});if(!i)return null;let s=e.pagination.lines?.(t)??[],l=Rv(s,i),a=Iv(e,t,l,i),c=typeof e.pagination.locateAnchor=="function"?e.pagination.locateAnchor(n.anchorFrom,t):null,u=Mv(t,i,n.anchorFrom,n.pathHint,a,c);return u?{anchorPageNumber:i.pageNumber,viewportAnchor:u}:null}function mu(e,t,r={}){let o=Bv(t);if(o.length===0)return null;let n=e.pagination.project();for(let i of o){let s=Nv(e,n,i,r);if(s)return s;let l=e.pagination.locateTarget({kind:"block",blockId:i.blockId},n);if(!l)continue;let a=du(n,l.pageNumber);if(!a)continue;let c=Math.max(0,Number(a.page.pageSize.width??0)),u=Math.max(0,Number(a.page.pageSize.height??0)),d=At(l.top,u),m=At(l.left,c);return{anchorPageNumber:l.pageNumber,viewportAnchor:{pageIndex:a.pageIndex,pageNumber:l.pageNumber,offsetTopPx:d,offsetTopRatio:je(d,u),offsetLeftPx:m,offsetLeftRatio:je(m,c),offsetPx:d,offsetRatio:je(d,u),region:l.region??null,sectionId:l.sectionId??null,anchorFrom:l.from,pathHint:l.pathHint?[...l.pathHint]:null,blockIdentity:l.blockIdentity??null,fragmentIndex:l.fragmentIndex,columnIndex:l.columnIndex,placementOrderHint:l.blockIndex,blockOffsetTopPx:0,blockOffsetTopRatio:0,blockOffsetLeftPx:0,blockOffsetLeftRatio:0}}}return null}function Ti(e,t,r=null){let o=mu(e.documentApi,t,ce(r)??{});if(!o)return null;let n={anchorPageNumber:o.anchorPageNumber,viewportAnchor:o.viewportAnchor};return e.requestPreviewNavigation(n)}import{TextSelection as Av}from"prosemirror-state";var Ov=1e3;function Vv(e){return typeof e!="number"||!Number.isFinite(e)?Ov:Math.max(0,Math.trunc(e))}function Lv(e){return e!=null&&typeof e=="object"&&"kind"in e&&e.kind==="text"&&Array.isArray(e.segments)}function Dv(e){return e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"&&"id"in e&&typeof e.id=="string"}function Hv(e){return e!=null&&typeof e=="object"&&"type"in e&&"nodesBetween"in e&&typeof e.nodesBetween=="function"}function fu(e){let t=Q(e);return Hv(t)?t:null}function Fv(e,t){let r=e.documentApi?.trackChanges.get(t)??null;return Rr(e.documentApi,fu(e.preview),r)}function jv(e,t){let r=e.documentApi?.comments.target(t)??null;if(!r)return null;let o=Ir(e.documentApi,r);if(o)return o;let n=fu(e.preview);if(!n)return null;let i=We(n,r);if(!i)return null;try{return ui(n,Av.create(n,i.from,i.to))}catch{return null}}function zv(e,t){return Lv(t)?t:Dv(t)?t.type==="comment"?jv(e,t.id):t.type==="trackedChange"?Fv(e,t.id):null:null}function qv(e,t){let r=e.readPendingNavigationRequest();return r?r.requestKey===t?"pending":"failed":"success"}function Ii(e){return e?.shouldContinue?.()??!0}function _v(e,t,r,o){return new Promise(n=>{let i=!1,s=()=>{},l=()=>{},a=null,c=m=>{let f=typeof m=="function"?m:()=>{};return i?(f(),()=>{}):f},u=m=>{i||(i=!0,s(),l(),a!=null&&clearTimeout(a),n(m))},d=()=>{if(!Ii(o)){u(!1);return}let m=qv(e,t);m!=="pending"&&u(m==="success")};s=c(e.subscribe(d)),i||(l=c(o?.subscribe?.(d))),i||(a=setTimeout(()=>u(!1),r),d())})}async function pu(e,t){let r=zv(e,t.target);if(!r)return{success:!1};if(!Ii(t.continuation))return{success:!1};let o=e.requestNavigationForTextTarget(r);return o?Ii(t.continuation)?{success:await _v(e,o.requestKey,Vv(t.timeoutMs),t.continuation)}:{success:!1}:{success:!1}}function pr(e){return K(e.getViewportState())}function wu(e,t){let r=pr(e);return e.subscribe(()=>{let o=pr(e);vt(r,o)||(r=o,t())})}function gu(e,t=null){let r=null;return{getSnapshot(){return pr(e)},subscribe(o){return wu(e,o)},observe(o){return o(pr(e)),wu(e,()=>{o(pr(e))})},observeGeometry(o){return r??=lu(e,t),r.observe(o)},scrollIntoView(o){return pu({documentApi:e.documentApi,preview:t,subscribe(n){return e.subscribe(()=>{n()})},readPendingNavigationRequest(){return e.getState().previewNavigationRequest??null},requestNavigationForTextTarget(n){return Ti(e,n,t)}},o)},getHost(){return Nt(e.surface)},getScrollContainer(){return mr(e.surface)},entitiesAtPoint(o){return Ci(e,o)},contextAtPoint(o){return tu(e,o,t)},positionAtPoint(o){return Mt(e,o)},requestNavigation(o){return e.requestPreviewNavigation(o)},requestNavigationForTextTarget(o){return Ti(e,o,t)},ackNavigationRequest(o){e.ackPreviewNavigationRequest(o)}}}import{createProseMirrorLayoutAdapter as qS}from"@datalking/begonia-editor-adapters";function hu(e){let t=e?.pages;if(!t||t.length===0)return[];let r=new Map;for(let o of t){let n=r.get(o.sectionIndex);n?n.push(o):r.set(o.sectionIndex,[o])}return Array.from(r.entries()).sort(([o],[n])=>o-n).map(([o,n])=>Kv(o,n))}function Kv(e,t){let r=t[0];return{sectionIndex:e,sectionId:r.sectionId,pageNumberStart:r.sectionPageNumber,pageCount:t.length,pageSize:r.pageSize,margins:r.margins,columnCount:r.columnCount,columnWidths:r.columnWidths}}import{NodeSelection as FS}from"prosemirror-state";function To(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function Uv(e){let t=e.selectionAnchor;return To(t?.resolvedSelectionPos)??To(t?.hit?.pos)}function Wv(e){return To(e.hit?.pos)??To(e.resolvedSelectionPos)}function bu(e,t){let r=Math.min(e.from,e.to),o=Math.max(e.from,e.to),n=Uv(t),i=Wv(t);return n!=null&&i!=null&&i<n?{anchor:o,head:r}:{anchor:r,head:o}}import{readSyntheticSideStoryDocOriginPath as eS}from"@datalking/begonia-doc-service/v1";import{isDocumentNodePath as yu,isDocumentNodePathIndex as tS,isIntegerPath as Pu}from"@datalking/begonia-document-model";import{readVirtualPagedPreviewInlineNodeTarget as rS}from"@datalking/begonia-layout-renderer";import{findProjectionPage as oS,isProjectionDocumentTextRegion as nS,resolveProjectionPageRegionBlocks as Cu}from"@datalking/begonia-page-layout";import{findProjectionPage as Xv,isProjectionDocumentTextRegion as Gv,listProjectionPagePlacements as Yv,pointHitsProjectionPlacement as $v}from"@datalking/begonia-page-layout";function vu(e,t,r,o){let n=Xv(e,t);return n?Yv(n).reduce((i,s)=>Gv(s.region)&&$v(s.block,r,o)?s.block:i,null):null}function A(e){return H(e)}function Io(e){return Math.max(28,e)}function Su(e){let t=Math.max(0,e.margins.top);if(!(t>0))return null;let r=Math.max(0,Math.min(t,e.regions.headerTop??t)),o=Math.max(0,e.regions.headerHeight??0),n=t-r,i=Io(o),s=o>n,l=Io(s?i:n),a=s?r:Math.max(0,t-l);return{kind:"header",top:a,left:e.margins.left,width:e.contentWidth,height:l,contentTop:s?0:r-a,contentHeight:i,marginDistance:r}}function Bu(e){let t=e.pageSize.height;if(!(t>0))return null;let r=Math.max(0,e.margins.bottom);if(!(r>0))return{kind:"footer",top:Math.max(0,t-28),left:e.margins.left,width:e.contentWidth,height:28,contentTop:0,contentHeight:28,marginDistance:0};let o=Math.max(0,Math.min(r,e.footerDistance??r)),n=Math.max(0,t-r),i=Math.max(0,t-o),s=i-n,l=Math.max(0,e.regions.footerHeight??0),a=Io(l),c=l>s,u=Io(c?a:s);return{kind:"footer",top:c?Math.max(0,i-u):n,left:e.margins.left,width:e.contentWidth,height:u,contentTop:c?0:Math.max(0,u-l),contentHeight:a,marginDistance:o}}var Zv=12;function Ri(e,t){return e.pages.find(r=>r.pageNumber===t)??null}function Jv(e,t,r){let o=Ri(e,t);return o?r<o.regions.bodyTop?"header":r>=o.regions.footerTop?"footer":null:null}function rt(e,t){let r=t.hit?.pageNumber??t.pageNumber,o=Jv(e,r,t.y);if(!o)return t.hit?.region??"body";if(!t.hit||t.hit.region!=="body")return o;let n=t.hit.top,i=t.hit.top+t.hit.height;return(o==="header"?Math.max(0,n-t.y):Math.max(0,t.y-i))>Math.max(Zv,t.hit.height/2)?o:t.hit.region}function wr(e,t){let r=t.hit?.pageNumber??t.pageNumber,o=Ri(e,r);if(!o)return!1;let n=t.y<o.regions.bodyTop,i=t.y>=o.regions.footerTop;return!n&&!i?!1:!Qv(n?o.headerBlocks:o.footerBlocks)}function Mi(e,t){let r=t.hit?.pageNumber??t.pageNumber,o=Ri(e,r);if(!o)return!1;let n=Su(o);if(n!=null&&t.y<n.top)return!0;let i=Bu(o);return i!=null&&t.y>i.top+i.height}function Qv(e){return Array.isArray(e)&&e.length>0}function Ro(e){return e?.selectionAnchor!=null}function xu(e,t,r){let o=ot(t,r);if(!Array.isArray(o?.path)||o.path.length===0)return!1;let n=eS(e);return n?Pu(o.path)&&Pu(n)&&o.path.length>=n.length&&n.every((s,l)=>o.path?.[l]===s)&&yu(o.path.slice(n.length)):yu(o.path)?rt(t,r)==="body"?!0:wr(t,r):!1}function ot(e,t){let r=t.hit?.pageNumber??t.pageNumber,o=oS(e,r);if(!o)return null;let n=vu(e,r,t.x,t.y);if(!t.hit)return n;if(!nS(t.hit.region))return Cu(o,t.hit.region)[t.hit.blockIndex]??n;let i=Cu(o,t.hit.region)[t.hit.blockIndex]??null;return n??i}function gr(e){return!!(e&&!e.drawing&&e.type!=="image"&&e.type!=="page_break"&&e.type!=="section_break")}function nt(e){let t=Math.round(Number(e??1));return Number.isFinite(t)?Math.max(1,t):1}function iS(e){let t=rS(e);return t?.nodeType==="ooxml_math"||t?.nodeType==="ooxml_chart"||t?.nodeType==="ooxml_shape"||t?.nodeType==="inline_ooxml_drawing"}function Eu(e,t){return t.shiftKey===!0?iS(t.target)||!gr(e):nt(t.clickCount)<=1?!0:!gr(e)}function ze(e,t){let r=Number(t),o=Number.isNaN(r)?1:Math.round(r);return Math.max(1,Math.min(o,A(e).view.state.doc.content.size))}function ku(e,t){let r=e,o=-1;for(let n of t){if(!tS(n)||n>=r.childCount)return null;o+=1;for(let i=0;i<n;i+=1)o+=r.child(i).nodeSize;r=r.child(n)}return o}function it(e,t){let r=ze(e,t.from),o=ze(e,t.to);return r<=o?{from:r,to:o}:{from:o,to:r}}function Tu(e,t){return{from:Math.min(e.from,e.to,t.from,t.to),to:Math.max(e.from,e.to,t.from,t.to)}}function sS(e){if(e.resolvedSelectionPos==null&&e.resolvedSelectionRange==null)return!1;let t=nt(e.clickCount);return e.resolvedSelectionClickCount==null?t<=1:nt(e.resolvedSelectionClickCount)===t}function Ni(e){let t=e.hit;if(!t||!sS(e))return!1;let r=e.resolvedSelectionRange;if(r){let o=Math.min(r.from,r.to),n=Math.max(r.from,r.to);return o===n?t.pos===o&&(e.resolvedSelectionPos==null||e.resolvedSelectionPos===o):t.pos>=o&&t.pos<=n&&(e.resolvedSelectionPos==null||e.resolvedSelectionPos===o)}return e.resolvedSelectionPos!=null&&t.pos===e.resolvedSelectionPos}import{readNodeAtPath as VS}from"@datalking/begonia-document-api/structure";import{NodeSelection as Ku}from"prosemirror-state";import{BEGONIA_BLOCK_POS_ATTRIBUTE as CM,BEGONIA_CELL_LINE_OFFSET_ATTRIBUTE as xM,BEGONIA_CELL_TEXT_START_ATTRIBUTE as EM,BEGONIA_PIECE_OFFSET_ATTRIBUTE as kM,BEGONIA_PROJECTION_OFFSET_ATTRIBUTE as TM}from"@datalking/begonia-layout-renderer";import{BEGONIA_CELL_LINE_OFFSET_ATTRIBUTE as mS,BEGONIA_CELL_TEXT_START_ATTRIBUTE as fS,BEGONIA_PIECE_OFFSET_ATTRIBUTE as pS,BEGONIA_PROJECTION_OFFSET_ATTRIBUTE as Ru}from"@datalking/begonia-layout-renderer";function lS(){let e=typeof document>"u"?null:document;return e&&(typeof e.caretPositionFromPoint=="function"||typeof e.caretRangeFromPoint=="function")?e:globalThis}function aS(e){return typeof e.caretPositionFromPoint=="function"?{kind:"position",read:(t,r)=>{let o=e.caretPositionFromPoint?.(t,r);return o?{offsetNode:o.offsetNode,offset:o.offset}:null}}:typeof e.caretRangeFromPoint=="function"?{kind:"range",read:(t,r)=>{let o=e.caretRangeFromPoint?.(t,r);return o?{offsetNode:o.startContainer,offset:o.startOffset}:null}}:null}function cS(e){if(!e)return!1;let{offsetNode:t,offset:r}=e;return t.nodeType===3&&Number.isFinite(r)&&r>=0&&r<=(t.textContent?.length??0)}function uS(e){let t=e?.ownerDocument;if(t&&typeof t.createRange=="function")return t;let r=typeof document>"u"?null:document;return r&&typeof r.createRange=="function"?r:null}function dS(e,t){let r=uS(e);if(!r)return null;let o=e.textContent?.length??0,n=Math.max(0,Math.min(t,o)),i;try{i=r.createRange(),i.setStart(e,n),i.setEnd(e,n)}catch{return null}let s=i.getBoundingClientRect();return i.detach?.(),!Number.isFinite(s?.left)||!Number.isFinite(s?.top)?null:{left:s.left,top:s.top,height:s.height}}function Iu(e,t,r=lS()){if(!Number.isFinite(e)||!Number.isFinite(t))return null;let o=aS(r);if(!o)return null;let n=o.read(e,t);return cS(n)?{node:n.offsetNode,offset:n.offset,rect:dS(n.offsetNode,n.offset)}:null}function hr(e,t){if(!e)return null;let r=e.getAttribute(t);if(r==null||r==="")return null;let o=Number(r);return Number.isFinite(o)?o:null}function Mu(e,t){if(!Number.isFinite(t)||t<0)return null;let r=e.parentElement;if(!r)return null;let o=null,n=null,i=null,s=r,l=0;for(;s&&l<32&&(o==null&&(o=hr(s,fS)),i==null&&(i=hr(s,mS)),n==null&&(n=hr(s,Ru)),!(o!=null&&n!=null&&i!=null));)s=s.parentElement,l+=1;if(n==null)return null;let a=hr(r,pS);if(a!=null)return(o??0)+n+a+t;let c=wS(r,n);return(o??0)+n+(i??0)+c+t}function wS(e,t){let r=0,o=e,n=0;for(;o&&n<64;){let i=hr(o,Ru);if(i!=null&&i===t)break;let s=o.previousSibling;for(;s;){let l=s.textContent;typeof l=="string"&&(r+=l.length),s=s.previousSibling}o=o.parentElement,n+=1}return r}import{readNodeAtPath as gS}from"@datalking/begonia-document-api/structure";function Nu(e,t,r){if(!Number.isFinite(r))return null;let o=ln(e);if(!o||o.length===0)return null;let n=Math.round(r)-t;for(let i of o){let s=n-i.flattenedStart;if(!(s<0||s>i.textLength))return t+i.contentStart+s}return null}function Au(e,t,r){if(!Number.isFinite(r))return null;if(t.type==="table"&&t.path?.length){let l=gS(e,t.path);return l&&l.type.name==="table"?Nu(l,t.from,r):null}let o=Os(e,t);if(!o)return null;let n=o.node,i=Math.max(0,Math.round(r)-o.blockPos);if(i>n.content.size)return null;let s=lt(n,o.blockPos,i,T(o.doc));return Number.isFinite(s)?s:null}function Ou(e){let{clientX:t,clientY:r,block:o,doc:n}=e;if(typeof t!="number"||typeof r!="number")return null;let i=Iu(t,r);if(!i)return null;let s=Mu(i.node,i.offset);if(s==null)return null;let l=Au(n,o,s);return l==null?null:{projectionOffset:s,documentPosition:l}}function Vu(e){return Ou(e)?.documentPosition??null}function Lu(e){return Ou(e)?.projectionOffset??null}function Du(e){let t=Q(e.editor),r=e.source==null?null:e.source,o=e.explicitProjection??null,n=e.boundToEditorDocument===!0||!!(t&&(Ss(e.source,t)||e.source==null&&e.explicitProjection==null)),i=n?null:r!=null?o==null?r:{source:r,projection:o}:t==null?o:null;return{sourceMatchesEditorDocument:n,lifecycleSourceIdentity:i}}import{buildTableGridModel as BS,readNodeAtPath as Ai,resolveRectAtLogicalPosition as yS}from"@datalking/begonia-document-api/structure";import{isDocumentNodePathIndex as PS}from"@datalking/begonia-document-model";import{readVirtualPagedPreviewInlineNodeTarget as CS}from"@datalking/begonia-layout-renderer";import{NodeSelection as xS}from"prosemirror-state";function Hu(e,t){let r=e,o=-1;for(let n of t){if(!PS(n)||n>=r.childCount)return null;o+=1;for(let i=0;i<n;i+=1)o+=r.child(i).nodeSize;r=r.child(n)}return o}function ES(e){return CS(e)}function kS(e,t,r,o,n={}){return!e.isInline||e.childCount!==0||!xS.isSelectable(e)||e.type.name!==t.nodeType||!n.ignoreObjectId&&t.objectId&&(typeof e.attrs.objectId=="string"?e.attrs.objectId:"")!==t.objectId?!1:t.fromOffset<o&&t.toOffset>r}function Oi(e,t,r,o,n={},i=0,s=[]){if(e.isText)return{positions:s,nextOffset:i+(e.text?.length??0)};if(e.childCount===0){let c=o(e),u=i+c.length;return kS(e,r,i,u,n)&&s.push(t),{positions:s,nextOffset:u}}let l=i,a=0;for(let c=0;c<e.childCount;c+=1){let u=e.child(c);l=Oi(u,t+a+1,r,o,n,l,s).nextOffset,a+=u.nodeSize}return{positions:s,nextOffset:l}}function TS(e,t,r){if(t.type!=="table"||!Array.isArray(t.path)||t.path.length===0||r.tableOriginRow==null||r.tableOriginColumn==null)return null;let o=A(e).view.state.doc,n=Ai(o,t.path);if(!n||n.type.name!=="table")return null;let i=BS(n);if(i.invalidReason)return null;let s=yS(i,r.tableOriginRow,r.tableOriginColumn);if(!s)return null;let l=i.physicalRows[s.originRow]?.find(d=>d.rect===s)??null;if(!l)return null;let a=[...t.path,s.originRow,l.childIndex],c=Ai(o,a),u=Hu(o,a);return!c||u==null?null:{node:c,nodePos:u}}function IS(e,t){if(!Array.isArray(t.path)||t.path.length===0)return null;let r=A(e).view.state.doc,o=Ai(r,t.path),n=Hu(r,t.path);return!o?.isTextblock||n==null?null:{node:o,nodePos:n}}function Vi(e,t,r){if(!t||!Array.isArray(t.path)||t.path.length===0)return null;let o=ES(r.target);if(!o)return null;let n=A(e).view.state.doc,i=T(n),s=u=>Ne(u,i),l=TS(e,t,o)??IS(e,t);if(!l)return null;let a=Oi(l.node,l.nodePos,o,s).positions;if(a.length===1)return a[0];if(a.length>1||!o.objectId)return null;let c=Oi(l.node,l.nodePos,o,s,{ignoreObjectId:!0}).positions;return c.length===1?c[0]:null}import{captureProjectionViewportLogicalAnchor as RS}from"@datalking/begonia-page-layout";function Fu(e,t){return Math.max(0,Math.min(Math.max(0,t),e))}function Li(e,t){return t>0?e/t:0}function Di(e){return e==="header"||e==="body"||e==="footer"}function MS(e,t,r){return Di(e)&&(r.hit==null||r.hit.region!==e)&&(t==null||t.region!==e)}function NS(e,t,r){return r&&(t==null||r.region===t||!Di(t))||!Di(t)?r:{region:t,sectionId:e.sectionId??null,anchorFrom:null,pathHint:null,blockIdentity:null,fragmentIndex:null,columnIndex:null,blockOffsetTopPx:null,blockOffsetTopRatio:null,blockOffsetLeftPx:null,blockOffsetLeftRatio:null}}function AS(e,t){let r=e.pages.findIndex(o=>o.pageNumber===t);return r<0?null:{pageIndex:r,page:e.pages[r]??null}}function ju(e,t){let r=t.hit?.pageNumber??t.pageNumber,o=AS(e,r);if(!o?.page)return null;let n=Math.max(0,Number(t.frame.page.pageSize.width??t.frame.contentWidth??0)),i=Math.max(0,Number(t.frame.page.pageSize.height??t.frame.contentHeight??0)),s=Number(t.frame.contentTop??0),l=Fu(t.y-s,i),a=RS(o.page,t.x,t.y),c=rt(e,t),u=MS(c,a,t)?t.x:t.pageX,d=Fu(u,n),m=NS(o.page,c,a);return{pageIndex:o.pageIndex,pageNumber:o.page.pageNumber,offsetTopPx:l,offsetTopRatio:Li(l,i),offsetLeftPx:d,offsetLeftRatio:Li(d,n),offsetPx:l,offsetRatio:Li(l,i),...m}}function Hi(e){return e.selectionAnchor?{...e,pageNumber:e.selectionAnchor.pageNumber,x:e.selectionAnchor.x,pageX:e.selectionAnchor.pageX,y:e.selectionAnchor.y,hit:e.selectionAnchor.hit,clickCount:e.selectionAnchor.clickCount??e.clickCount??1,resolvedSelectionPos:e.selectionAnchor.resolvedSelectionPos??null,resolvedSelectionRange:e.selectionAnchor.resolvedSelectionRange??null,resolvedSelectionClickCount:e.selectionAnchor.resolvedSelectionClickCount??null,selectionAnchor:null,target:e.selectionAnchor.target??null,...OS(e.selectionAnchor,e)}:null}function OS(e,t){return e.hit?{clientX:null,clientY:null}:{clientX:e.clientX??t.clientX??null,clientY:e.clientY??t.clientY??null}}function zu(e){return{...e,clickCount:e.clickCount??e.selectionAnchor?.clickCount??1,resolvedSelectionPos:null,resolvedSelectionRange:null,resolvedSelectionClickCount:null,selectionAnchor:null}}function qu(e){return{...e,clickCount:1,shiftKey:!1,resolvedSelectionPos:null,resolvedSelectionRange:null,resolvedSelectionClickCount:null,selectionAnchor:null}}function LS(e,t,r,o){return jl({doc:A(e).view.state.doc,block:t,rawPos:r,clickCount:o})}function DS(e,t){if(t.type==="table"||gr(t)||!Array.isArray(t.path)||t.path.length===0)return null;let r=A(e).view.state.doc,o=VS(r,t.path);return!o||!Ku.isSelectable(o)?null:ku(r,t.path)}function br(e){return Du({editor:e.editor,source:e.previewSource,explicitProjection:e.explicitProjection,boundToEditorDocument:e.boundToEditorDocument}).sourceMatchesEditorDocument}function vr(e,t){return xu(A(e).view.state.doc,t.projection,t)}function ji(e,t){let r=ju(t.projection,t);return r?e.requestPreviewNavigation({anchorPageNumber:r.pageNumber,viewportAnchor:r})!=null:!1}function Fi(e,t){if(t==null)return null;try{let r=Ku.create(A(e).view.state.doc,t);return{from:r.from,to:r.to}}catch{return null}}function Sr(e){let{editor:t,event:r}=e;if(!t||!r.hit||!br(e)||!vr(t,r))return{block:null,nodeSelectionPos:null,nodeSelectionRange:null};let o=ot(r.projection,r);if(!Eu(o,r))return{block:o,nodeSelectionPos:null,nodeSelectionRange:null};let n=Vi(t,o,r);if(n!=null)return{block:o,nodeSelectionPos:n,nodeSelectionRange:Fi(t,n)};let i=o?DS(t,o):null;return{block:o,nodeSelectionPos:i,nodeSelectionRange:Fi(t,i)}}function HS(e,t){let r=it(e,t),o=ze(e,A(e).view.state.selection.anchor);return{from:Math.min(o,r.from),to:Math.max(o,r.to)}}function zi(e,t){let{editor:r}=e;if(!r||!t.hit||!br(e)||!vr(r,t))return null;let o=ot(t.projection,t);if(!o)return null;if(o.type==="table"){let i=Vu({clientX:t.clientX,clientY:t.clientY,block:o,doc:A(r).view.state.doc});if(i!=null)return Yr({doc:A(r).view.state.doc,rawPos:i,clickCount:t.clickCount});let s=ce(r)??{};return Fn({doc:A(r).view.state.doc,block:o,x:t.x,y:t.y,clickCount:t.clickCount,measureText:s.measureText,measurementEpoch:s.measurementEpoch})}if(t.shiftKey){let i=Fi(r,Vi(r,o,t));if(i)return i}if(!gr(o)||!t.hit)return null;let n=Lu({clientX:t.clientX,clientY:t.clientY,block:o,doc:A(r).view.state.doc});return LS(r,o,n??t.hit.pos,t.clickCount)}function _u(e,t){if(t.resolvedSelectionRange)return t.resolvedSelectionRange;let r=Sr({...e,event:t});return r.nodeSelectionRange?r.nodeSelectionRange:zi(e,t)}function Uu(e,t){if(!t.selectionAnchor)return t.selectionAnchor??null;let r=Hi(t);if(!r)return t.selectionAnchor;let o=Br({...e,event:r});return{...t.selectionAnchor,hit:o.hit,clickCount:o.clickCount??t.selectionAnchor.clickCount??1,resolvedSelectionPos:o.resolvedSelectionPos??null,resolvedSelectionRange:o.resolvedSelectionRange??null,resolvedSelectionClickCount:o.resolvedSelectionClickCount??null,pageX:o.pageX,target:o.target??t.selectionAnchor.target??null}}function Wu(e){let{editor:t,event:r}=e;if(!t||!r.hit||!br(e)||!vr(t,r))return r.hit??null;let o=ot(r.projection,r);if(!o||o.type!=="table")return r.hit;let n=ce(t)??{};return jn({doc:A(t).view.state.doc,block:o,x:r.x,y:r.y,hit:r.hit,measureText:n.measureText,measurementEpoch:n.measurementEpoch})??r.hit}function Xu(e){let{editor:t,event:r}=e;if(!t||!r.hit)return r.hit?.pos??null;let o=zi(e,qu(r));return o?it(t,o).from:r.hit.pos}function Mo(e){let{editor:t,event:r}=e;if(!t)return null;let o=Hi(r),n=o?(()=>{let i=_u(e,o),s=_u(e,zu(r));return!i||!s?null:Tu(i,s)})():zi(e,r);return n?r.shiftKey?HS(t,n):n:null}function Gu(e,t){return e<=t.from?t.to:e>=t.to||Math.abs(e-t.from)>Math.abs(e-t.to)?t.from:t.to}function Yu(e){let{editor:t}=e;if(!t)return null;let r=Sr(e);if(r.nodeSelectionPos!=null)return r.nodeSelectionPos;let o=Mo(e);return o?it(t,o).from:null}function Br(e){let{editor:t,event:r}=e;if(!t||!r.hit)return r;let o=rt(r.projection,r);if((o==="header"||o==="footer")&&r.hit.region==="body"&&!wr(r.projection,r))return{...r,resolvedSelectionPos:null,resolvedSelectionRange:null};let n=Wu(e),i=n===r.hit?r:{...r,hit:n},s=Uu(e,i),l=s===i.selectionAnchor?i:{...i,selectionAnchor:s},a=l.hit;if(!a||Ni(l))return l;let c=ot(l.projection,l),u=nt(l.clickCount)<=1&&!l.shiftKey&&l.selectionAnchor==null;if(c&&u){let y=qn({doc:A(t).view.state.doc,block:c,x:l.x,y:l.y});if(y)return{...l,resolvedSelectionPos:y.caretPos,resolvedSelectionRange:null,resolvedSelectionClickCount:1,resolvedTableExitInsertAt:y.insertAt,hit:{...a,pos:y.caretPos}}}let d={...e,event:l},m=nt(l.clickCount),f=Sr(d);if(f.nodeSelectionPos!=null)return{...l,resolvedSelectionPos:f.nodeSelectionPos,resolvedSelectionRange:null,resolvedSelectionClickCount:m,hit:{...a,pos:f.nodeSelectionPos}};let g=Mo(d);if(!g)return l;let p=it(t,g),b=Xu(d)??p.from,w=p.from===p.to;return{...l,resolvedSelectionPos:p.from,resolvedSelectionRange:p,resolvedSelectionClickCount:m,hit:{...a,pos:w?p.from:b}}}function jS(e){return e==="header"||e==="footer"}function $u(e){let{editor:t,previewSource:r,explicitProjection:o,boundToEditorDocument:n,event:i}=e;if(!t||!br(e))return!1;let s={editor:t,previewSource:r,explicitProjection:o,boundToEditorDocument:n},l=Ni(i)?i:Br(e);if(Mi(l.projection,l))return t.setPointerCaretOrigin?.(null),!0;let a=l.selectionAnchor;if(a!=null&&Mi(l.projection,a))return!1;let c=l.resolvedTableExitInsertAt;if(c!=null&&!l.shiftKey&&!Ro(l)){let p=A(t),b=p.view.state;if(c<0||c>b.doc.content.size)return!1;let w=b.schema.nodes.paragraph;if(!w)return!1;let y=b.tr.insert(c,w.create()),x=b.apply(y),E=M(x,c+1);return E?(t.setPointerCaretOrigin?.({pageNumber:l.pageNumber,x:l.x,y:l.y,selectionOffset:c+1}),y.setSelection(E),p.view.dispatch(y),p.focus(),!0):!1}if(l.resolvedTableExitInsertAt===null&&l.resolvedSelectionPos!=null&&!l.shiftKey&&!Ro(l)){let p=A(t),b=ze(t,l.resolvedSelectionPos),w=M(p.view.state,b);return w?(t.setPointerCaretOrigin?.({pageNumber:l.pageNumber,x:l.x,y:l.y,selectionOffset:b}),p.view.dispatch(p.view.state.tr.setSelection(w)),p.focus(),!0):!1}let u=rt(l.projection,l),d=Ro(l);if(!l.hit||jS(u)&&l.hit.region==="body"&&!wr(l.projection,l))return u&&!d?ji(t,l):!1;if(!vr(t,l))return d?!1:ji(t,l);let m=Sr({...s,event:l});if(m.nodeSelectionPos!=null){let p=A(t);return t.setPointerCaretOrigin?.(null),p.view.dispatch(p.view.state.tr.setSelection(FS.create(p.view.state.doc,m.nodeSelectionPos))),p.focus(),!0}let f=l.resolvedSelectionRange?it(t,l.resolvedSelectionRange):Mo({...s,event:l});if(l.shiftKey&&f){t.setPointerCaretOrigin?.(null);let p=A(t),b=ze(t,p.view.state.selection.anchor),w=Gu(b,f),y=M(p.view.state,b,w);return y?(p.view.dispatch(p.view.state.tr.setSelection(y)),p.focus(),!0):!1}if(f){let p=A(t),b=bu(f,l),w=M(p.view.state,b.anchor,b.head);return w?(t.setPointerCaretOrigin?.(f.from===f.to?{pageNumber:l.pageNumber,x:l.x,y:l.y,selectionOffset:f.from}:null),p.view.dispatch(p.view.state.tr.setSelection(w)),p.focus(),!0):!1}let g=l.resolvedSelectionPos??Yu({...s,event:l});if(g!=null){let p=A(t),b=ze(t,g),w=M(p.view.state,b);return w?(t.setPointerCaretOrigin?.({pageNumber:l.pageNumber,x:l.x,y:l.y,selectionOffset:b}),p.view.dispatch(p.view.state.tr.setSelection(w)),p.focus(),!0):!1}return!1}var zS={resolvePositionHitEvent(e){return Br(e)},handlePositionHit(e){return $u(e)}};function qi(){return zS}var _S=qS();function Zu(e){let t=null,r=null,o=null,n=new Set,i=s=>{for(let l of[...n])l(s)};return{readLayoutAdapter(){return _S},readLayoutSource(){let s=e();return s?.view?.state.doc??s?.document??null},readDocumentSize(){return e()?.view?.state.doc.content.size??null},getResolvedProjection(){return t},getPages(){return t?.pages??[]},getSectionMetadata(){return hu(t)},getResolvedProjectionGeometryOptions(){return r},setResolvedProjection(s,l=null){t=s??null,r=l??null,i(t)},subscribeResolvedProjection(s){return n.add(s),()=>{n.delete(s)}},getPointerCaretOrigin(){return o},setPointerCaretOrigin(s){o=s??null},selection:qi()}}function Ju(e){let t=()=>ao(e),o={...Zu(t),getState(){return e.getState()},subscribe(n){return e.subscribe(n)},requestPreviewNavigation(n){return e.requestPreviewNavigation(n)},ackPreviewNavigationRequest(n){e.ackPreviewNavigationRequest(n)},setViewState(n){e.setViewState(n)},setZoomViewportMetrics(n){e.setZoomViewportMetrics(n)}};return Object.defineProperty(o,"surface",{configurable:!1,enumerable:!1,get:t}),o}var Qu=Symbol.for("@datalking/begonia-browser-sdk/browser-editor-v1-runtime"),Ki=new WeakMap,KS=new WeakMap;function US(e,t){Object.defineProperty(e,Qu,{configurable:!0,enumerable:!1,writable:!0,value:t})}function _i(e){return!e||typeof e!="object"?null:e[Qu]??null}function WS(e){return"host"in e}function Ui(e,t){Ki.set(e,t),US(e,t)}function Wi(e){if(!e)return null;if(WS(e))return KS.get(e)??_i(e)??Ki.get(e.host)??_i(e.host)??null;let t=V(e);return t?Ki.get(t)??_i(t)??null:null}function ed(e){return Wi(e)?.controller??null}var SA=Rt({commandIds:Lc});function XS(e){let t=e.getState();return{linkPopover:t.linkPopover,contextMenu:t.contextMenu}}function GS(e){let t=null,r=()=>{let o=XS(e);return(t==null||!yt(t,o))&&(t=o),t};return{getSnapshot:r,subscribe(o){return e.subscribe(()=>{let n=t;n!=null&&r()!==n&&o()})}}}function YS(e,t=It){let r=e.getState(),o=yi(e,t);return Co(r,o)}function $S(e){let t=()=>YS(e);return{doc:e.documentApi,readState:t,subscribe(r){return e.subscribe(()=>{r()})},execute(r,o){return t().commands[r]?.disabled?D("Command is disabled in the current document mode or selection."):uc(e,r,o)??D(`Unsupported browser command: ${String(r)}`)}}}function ZS(e){let t={controller:e,backend:Gc(e),advancedOoxmlActions:e},r=Ju(e),o={session:$S(e),actor:null,documentApi:e.documentApi,readCommandSnapshot(n=It){return Dc(e,n)},...Yc(e),browserViewport:gu(e,r),preview:r,overlayState:GS(e),overlays:{closeLinkPopover:()=>e.closeLinkPopover(),closeContextMenu:()=>e.closeContextMenu()}};return Object.defineProperty(o,"actor",{configurable:!1,enumerable:!0,get(){return e.actor??null}}),Ui(o,t),o}function td(e){let t=ZS(e),r={...t,overlays:t.overlays??{}},o=Wi(t);return o&&Ui(r,o),r}function rd(e){return ed(e)}function JS(e=""){return typeof window>"u"?null:window.prompt("Enter link URL",e)}function QS(e,t){let r=new Map(e.map(o=>[o.id,{...o,items:[...o.items]}]));for(let o of t){let n=r.get(o.id);if(n){n.items.push(...o.items);continue}r.set(o.id,{...o,items:[...o.items]})}return[...r.values()]}function eB(e,t){let r=Math.min(e.selection.from,e.selection.to),o=Math.max(e.selection.from,e.selection.to);return(t.segments?.length?t.segments:[t]).every(i=>r<=i.from&&o>=i.to)}function od(e,t,r){let o=new Set(e.trackedChangeIds),n=t.getState().revisions.filter(i=>o.has(i.id));return n.length===0||n.some(i=>i.relatedKinds.length!==1)?!1:n.some(i=>!eB(r,i))}function tB(e,t,r){if(!t||!e.hasSelection)return r;let o=Math.min(t.selection.from,t.selection.to),n=Math.max(t.selection.from,t.selection.to),i=Math.min(e.selectionStart,e.selectionEnd),s=Math.max(e.selectionStart,e.selectionEnd),l=r?Math.min(r.selection.from,r.selection.to):o,a=r?Math.max(r.selection.from,r.selection.to):n;return(i!==l||s!==a)&&i===o&&s===n?{selection:{...t.selection,from:i,to:s,empty:!1,trackedChangeIds:[...e.trackedChangeIds]}}:r}function nd(e,t,r){let{hasSelection:o,trackedChangeIds:n}=e,i=ie(t);if(n.length===0)return;let s=t.readEffectiveSelection({includeText:!0}),l=e.actionSelectionCapture??e.selectionCapture,a=t.getState().revisions,c=Ko(s,l,a),u=!c&&l?t.readSelectionCapture(l,{includeText:!0}):null,d=tB(e,l,u),m=u?Ko(s,u,a):c;if(n.length===1&&!o){let f=n[0];if(!f)return;if(r==="accept"){t.acceptRevision(f);return}t.rejectRevision(f);return}if(i&&(r==="accept"&&typeof i.acceptSelectionRevisions=="function"||r==="reject"&&typeof i.rejectSelectionRevisions=="function")&&d&&!d.selection.empty&&od(e,t,d)){De(i,d,f=>r==="accept"?f.acceptSelectionRevisions?.()??!1:f.rejectSelectionRevisions?.()??!1,{restoreSelection:!1});return}if(!(d&&!d.selection.empty&&od(e,t,d)&&(r==="accept"?t.documentApi.review.accept([...n],t.actor??void 0):t.documentApi.review.reject([...n],t.actor??void 0)).changed)){if(n.length===1&&!c&&!m){let f=n[0];if(!f)return;if(r==="accept"){t.acceptRevision(f);return}t.rejectRevision(f);return}if(l&&!c&&!m){if(r==="accept"){t.documentApi.review.accept([...n],t.actor??void 0);return}t.documentApi.review.reject([...n],t.actor??void 0);return}if(r==="accept"){t.acceptSelection();return}t.rejectSelection()}}function fe(e,t){let r=Kn(e,t).actionSelection;if(r.stale)return"Captured selection is no longer available after the document changed. Capture a new text selection or caret before applying inline formatting.";let o=ie(t);return o?Tt({editable:e.isEditable},o.state,r.resolvedSelectionCapture):"Live editor surface is unavailable for inline formatting."}function Xi(e){return e.hasAmbiguousPointReviewTarget?"Right-click hit multiple overlapping review targets. Click a specific change or narrow the selection before accepting or rejecting changes.":e.isEditable?null:"Document is read-only in the current document mode."}function id(e){return Xi(e)==null}function rB(e,t){let r=ie(t),{effectiveSelection:o,actionSelection:n}=Kn(e,t),i=o.stale?!1:o.resolvedSelectionCapture?.selection.formatting.link??e.activeMarks.includes("link"),s=o.stale?"":o.resolvedSelectionCapture?.selection.formatting.linkHref??"",l=[{id:"formatting",items:[{id:"bold",label:"Bold",action:()=>{n.stale||Se(t,"bold",n.selectionCapture,{restoreSelection:n.restoreSelection})},enabledWhen:()=>fe(e,t)==null,disabledReason:()=>fe(e,t)},{id:"italic",label:"Italic",action:()=>{n.stale||Se(t,"italic",n.selectionCapture,{restoreSelection:n.restoreSelection})},enabledWhen:()=>fe(e,t)==null,disabledReason:()=>fe(e,t)},{id:"underline",label:"Underline",action:()=>{n.stale||Se(t,"underline",n.selectionCapture,{restoreSelection:n.restoreSelection})},enabledWhen:()=>fe(e,t)==null,disabledReason:()=>fe(e,t)},{id:"strikethrough",label:"Strikethrough",action:()=>{n.stale||Se(t,"strike",n.selectionCapture,{restoreSelection:n.restoreSelection})},enabledWhen:()=>fe(e,t)==null,disabledReason:()=>fe(e,t)}]},{id:"links",items:[{id:"insert-link",label:i?"Edit link":"Insert link",action:()=>{if(n.stale)return;let a=t.captureSelectionHandleFromCapture(n.selectionCapture);if(!a)return;let c=JS(s);try{c&&t.setLinkFromHandle(a,c,null,{restoreSelection:n.restoreSelection})}finally{t.releaseSelectionHandle(a)}},enabledWhen:()=>fe(e,t)==null,disabledReason:()=>fe(e,t)},{id:"clear-link",label:"Clear link",showWhen:()=>i,enabledWhen:()=>fe(e,t)==null,disabledReason:()=>fe(e,t),action:()=>{if(n.stale)return;let a=t.captureSelectionHandleFromCapture(n.selectionCapture);if(a)try{t.clearLinkFromHandle(a,{restoreSelection:n.restoreSelection})}finally{t.releaseSelectionHandle(a)}}}]},{id:"history",items:[{id:"undo",label:"Undo",action:()=>{r?.undo()},enabledWhen:a=>a.isEditable&&(r?.canUndo()??!1)},{id:"redo",label:"Redo",action:()=>{r?.redo()},enabledWhen:a=>a.isEditable&&(r?.canRedo()??!1)}]}];return e.trackedChangeIds.length>0&&l.unshift({id:"track-changes",items:[{id:"accept-change",label:e.trackedChangeIds.length===1?"Accept change":"Accept changes",tone:"success",enabledWhen:id,disabledReason:Xi,action:()=>nd(e,t,"accept")},{id:"reject-change",label:e.trackedChangeIds.length===1?"Reject change":"Reject changes",tone:"danger",enabledWhen:id,disabledReason:Xi,action:()=>nd(e,t,"reject")}]}),l}function oB(e,t,r){return r?null:typeof e.disabledReason=="function"?e.disabledReason(t)??"Action unavailable.":e.disabledReason??"Action unavailable."}function sd(e,t,r){let o=r??rd(e.host)??e.controller??null,n=t?.includeDefaultItems===!1||!o?[]:rB(e,o),i=QS(n,t?.customItems??[]);return(t?.menuProvider?.(e,i)??i).map(l=>{let a=l.items.filter(c=>c.showWhen?.(e)??!0).map(c=>{let u=c.enabledWhen?.(e)??!0;return{...c,enabled:u,disabledReason:oB(c,e,u)}});return{id:l.id,label:l.label,items:a}}).filter(l=>l.items.length>0)}import{NodeSelection as ld}from"prosemirror-state";function nB(e,t){return{left:e+8,top:t+12}}function iB(){return{status:"none",kind:null,trackedChangeIds:[],commentIds:[]}}function sB(e){let{selection:t}=e,{$from:r}=t,o=new Set;R(t)&&o.add(t.node.type.name);for(let n=0;n<=r.depth;n+=1)o.add(r.node(n).type.name);return[...o]}function ad(e,t){return Math.max(1,Math.min(t,e.content.size))}function lB(e,t){return Math.max(0,Math.min(t,e.content.size))}function aB(e,t){let r=Math.min(e.selection.from,e.selection.to),o=Math.max(e.selection.from,e.selection.to);return(t.segments?.length?t.segments:[t]).every(i=>r<=i.from&&o>=i.to)}function cB(e){let t=X(e.effectiveTrackedChangeIds,e.revisions);if(!e.selectionCapture||e.selectionCapture.selection.empty)return t;if(t.length===0)return[];let r=_t({from:e.selectionCapture.selection.from,to:e.selectionCapture.selection.to,trackedChangeIds:[]},e.revisions);if(r.length<=t.length)return t;let o=new Set(t),n=new Map(e.revisions.map(s=>[s.id,s]));return r.filter(s=>!o.has(s)).some(s=>{let l=n.get(s);return l?!aB(e.selectionCapture,l):!1})?r:t}function uB(e,t){let{selection:r}=e;return r.from===t.selection.from&&r.to===t.selection.to&&r.empty===t.selection.empty&&(t.selectionKind!=="node"||R(r)&&(!t.nodeSelectionTarget||ut(Le(e),t.nodeSelectionTarget)))}function dB(e,t){if(t.selectionKind==="node"){let n=no(e,t.nodeSelectionTarget);if(n)return n;let i=lB(e.doc,Math.min(t.selection.from,t.selection.to)),s=e.doc.nodeAt(i);if(s&&ld.isSelectable(s))try{return e.apply(e.tr.setSelection(ld.create(e.doc,i)))}catch{}}let r=ad(e.doc,Math.min(t.selection.from,t.selection.to)),o=ad(e.doc,Math.max(t.selection.from,t.selection.to));try{let n=M(e,r,o);return n?e.apply(e.tr.setSelection(n)):null}catch{return null}}function mB(e,t,r){return t||(!r||uB(e,r)?e:dB(e,r)??e)}function fB(e){return R(e.selection)?e.selection.node.type.name:e.selection.$from.parent.type.name}function pB(e,t){return t?[...t.activeMarks]:Qe(e).activeMarks}function wB(e,t){return t?[...t.activeCommentIds]:Qe(e).activeCommentIds}function gB(e){let t=new Set(Qe(e).activeMarks);if(!e.selection.empty)return[...t];for(let r of e.storedMarks??[])t.add(r.type.name);for(let r of e.selection.$from.marks())t.add(r.type.name);for(let r of e.selection.$from.nodeBefore?.marks??[])t.add(r.type.name);for(let r of e.selection.$from.nodeAfter?.marks??[])t.add(r.type.name);return[...t]}function hB(e){if(!e.pointSelectionCapture)return iB();let t=e.surface.view?.dom;return eu({host:t,clientX:e.clientX,clientY:e.clientY,revisions:e.revisions,comments:e.comments})}function cd(e,t,r){let o=H(e),n=td(e),i=r.selectionCapture??null,s=r.actionSelectionCapture??i,l=r.pointSelectionCapture??null,a=r.pointSelectionState??null,c=e.documentApi?.comments?.list?.()??e.getState?.().comments??[],u=hB({surface:o,pointSelectionCapture:l,clientX:r.clientX,clientY:r.clientY,revisions:r.revisions,comments:c}),d=[...u.trackedChangeIds],m=[...u.commentIds],f=mB(o.state,r.selectionState,i),g=a??f,p=r.selection??f.selection,b=sB(g),w=wB(f,i),y=a?gB(g):pB(f,i),x=r.reviewActionsEnabled,E=(()=>{if(!x)return[];let k=ae(r.selection?.trackedChangeIds??r.selectionTrackedChangeIds);if(r.selection?.trackedChangeIdsExplicit===!0)return cB({effectiveTrackedChangeIds:k,selectionCapture:s??i,revisions:r.revisions});let Y=ae(o.listSelectionRevisionIds?.());return _t({from:p.from,to:p.to,trackedChangeIds:k.length>0?k:Y},r.revisions)})(),O=l&&E.length===0&&u.status==="resolved"&&d.length>0?[...d]:E;return{host:n,trigger:"contextmenu",selectedText:p.empty?"":ge(f.doc,o.schema,p),hasSelection:!p.empty,selectionStart:p.from,selectionEnd:p.to,isInTable:b.some(k=>k==="table"||k==="table_row"||k==="table_cell"),isInList:b.some(k=>k==="bullet_list"||k==="ordered_list"||k==="list_item"),isTrackedChange:O.length>0,trackedChangeIds:[...O],hasAmbiguousPointReviewTarget:l!=null&&u.status==="ambiguous",pointReviewTrackedChangeIds:d,pointReviewCommentIds:m,documentMode:t,currentNodeType:fB(g),activeCommentIds:w,activeMarks:y,selectionCapture:i,actionSelectionCapture:s,pointSelectionCapture:l,isEditable:pc(o),pos:a?a.selection.from:p.from,clientX:r.clientX,clientY:r.clientY,position:nB(r.clientX,r.clientY)}}function bB(e){let t=e.pointSelection?.capture.selection.from??null,r=dt(e.pointSelection?.capture,e.revisions),o=!!(e.effectiveSelectionRange&&typeof t=="number"&&t>=e.effectiveSelectionRange.from&&t<=e.effectiveSelectionRange.to);return!!(e.pointSelection&&(!e.effectiveSelectionRange||!o)&&(r.length>0||e.pointSelection.capture.selectionKind==="node"||e.pointSelection.capture.selection.formatting.link||e.pointSelection.capture.selection.empty))}function ud(e){let t=e.controller.getState(),r=e.actionSelectionCapture&&!e.actionSelectionCapture.selection.empty?{from:Math.min(e.actionSelectionCapture.selection.from,e.actionSelectionCapture.selection.to),to:Math.max(e.actionSelectionCapture.selection.from,e.actionSelectionCapture.selection.to)}:null,o=bB({pointSelection:e.pointSelection,effectiveSelectionRange:r,revisions:t.revisions}),n=o?e.pointSelection?.capture??null:e.effectiveSelection,i=o?e.pointSelection?.capture??null:e.actionSelectionCapture,s=i?.selection??n?.selection??null,l=o?dt(e.pointSelection?.capture,t.revisions):Bo({liveSelection:yo(t.selection)??{from:0,to:0,empty:!0,trackedChangeIds:t.selection.trackedChangeIds},liveSelectionInfo:t.selectionInfo,revisions:t.revisions,effectiveSelection:i??e.effectiveSelection});return cd(e.controller,e.documentMode,{revisions:t.revisions,reviewActionsEnabled:e.reviewActionsEnabled,selection:n?{from:s?.from??n.selection.from,to:s?.to??n.selection.to,empty:s?.empty??n.selection.empty,trackedChangeIds:l,trackedChangeIdsExplicit:!0}:null,selectionCapture:n,actionSelectionCapture:i,pointSelectionCapture:o?e.pointSelection?.capture??null:null,pointSelectionState:o?e.pointSelection?.state??void 0:void 0,selectionTrackedChangeIds:t.selection.trackedChangeIds,clientX:e.clientX,clientY:e.clientY,selectionState:o?e.pointSelection?.state??void 0:void 0})}function vB(e){let{closeContextMenu:t,closeLinkPopover:r,emit:o,getController:n,getDocumentMode:i,getResolvedModules:s,readTrackChangesDisplayState:l,setContextMenu:a}=e;return c=>{if(!c||typeof c.clientX!="number"||typeof c.clientY!="number")return!1;let u=s();if(u.contextMenu?.enabled===!1)return!1;r();let d=n(),m=d.captureEffectiveSelection({includeText:!0}),f=d.captureEffectiveSelection()??m;if(!m&&!f)return t(),!1;let g=ud({controller:d,documentMode:i(),reviewActionsEnabled:l().enabled,effectiveSelection:m,actionSelectionCapture:f,pointSelection:null,clientX:c.clientX,clientY:c.clientY}),p=sd(g,u.contextMenu,d);return p.length===0?(t(),!1):(a({context:g,sections:p}),o(),!0)}}export{Jo as createBrowserEditorCommentsController,yn as createBrowserEditorTrackChangesController,fl as createBrowserEditorUi,vB as createOpenBrowserEditorContextMenuAt,kn as createPaginatedCaretRevealer,ww as createPaginatedEditingSession,Tn as createPaginatedInputBridge,Oo as focusBrowserCommentTarget,eg as installPaginatedColumnKeyboard,Jw as installPaginatedTableBoundaryKeyboard,pp as requestBrowserTrackChangeNavigation,We as resolveBrowserCommentTargetSelection,Lp as resolveBrowserEditorActiveCommentId,Hp as resolveBrowserEditorActiveRevisionId,Pn as resolveBrowserEditorActiveRevisionIds,Cn as resolveBrowserEditorActiveRevisionSelection,xn as resolveBrowserEditorFocusedActiveCommentState,No as resolveBrowserEditorPreviewBinding,og as resolveBrowserHistoryShortcut,Oe as resolveBrowserTrackChangeNavigation,er as resolveBrowserViewIntentPatch,Qt as resolveBrowserViewIntentSnapshot,_p as resolveBrowserViewLayoutMode,Kp as resolveBrowserViewZoomMode,Up as resolveBrowserZoomStep,vl as resolvePaginatedCaretRevealFromRects,xl as resolvePaginatedCompositionTransition,En as resolvePaginatedPreviewKeySelection,_n as resolvePaginatedTableBoundaryArrow,kp as revealBrowserTrackChange,Tp as revealNextBrowserTrackChange,Ip as revealPreviousBrowserTrackChange,Vo as scrollBrowserCommentTargetIntoView,Jt as scrollBrowserTrackChangeIntoView,Pl as shouldFocusPaginatedHostForKey,Cl as shouldFocusPaginatedHostForPointer};
|