@univerjs/preset-docs-core 0.8.0-nightly.202506011606 → 0.8.0-nightly.202506031608

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.
Files changed (2) hide show
  1. package/lib/umd/index.js +1 -1
  2. package/package.json +9 -9
package/lib/umd/index.js CHANGED
@@ -31,7 +31,7 @@ ${i}
31
31
 
32
32
 
33
33
  // @univerjs/docs-ui/index
34
- (function(y,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("react"),require("react/jsx-runtime"),require("@univerjs/design"),require("rxjs"),require("rxjs/operators"),require("@univerjs/drawing")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs","@univerjs/engine-render","@univerjs/ui","react","react/jsx-runtime","@univerjs/design","rxjs","rxjs/operators","@univerjs/drawing"],a):(y=typeof globalThis<"u"?globalThis:y||self,a(y.UniverDocsUi={},y.UniverCore,y.UniverDocs,y.UniverEngineRender,y.UniverUi,y.React,y.React,y.UniverDesign,y.rxjs,y.rxjs.operators,y.UniverDrawing))})(this,function(y,a,D,_,I,w,P,J,L,dt,xn){"use strict";var DA=Object.defineProperty;var BA=(y,a,D)=>a in y?DA(y,a,{enumerable:!0,configurable:!0,writable:!0,value:D}):y[a]=D;var B=(y,a,D)=>BA(y,typeof a!="symbol"?a+"":a,D);var ms=Object.getOwnPropertyDescriptor,ps=(o,t,e,n)=>{for(var i=n>1?void 0:n?ms(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},oi=(o,t)=>(e,n)=>t(e,n,o);y.DocAutoFormatService=class extends a.Disposable{constructor(e,n){super();B(this,"_matches",new Map);this._univerInstanceService=e,this._textSelectionManagerService=n}registerAutoFormat(e){const n=this._matches.get(e.id);return n?(n.push(e),n.sort((i,s)=>{var r,c;return((r=s.priority)!=null?r:0)-((c=i.priority)!=null?c:0)})):this._matches.set(e.id,[e]),a.toDisposable(()=>{const i=this._matches.get(e.id);if(i){const s=i.findIndex(r=>r===e);s>=0&&i.splice(s,1)}})}onAutoFormat(e,n){var l,A,d,u,m,h,g,p,f;const i=(l=this._matches.get(e))!=null?l:[],s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),r=this._textSelectionManagerService.getDocRanges(),c=(A=r.find(S=>S.isActive))!=null?A:r[0];if(s&&c){const S=s.getSelfOrHeaderFooterModel(c.segmentId),E={unit:S,selection:c,isBody:!c.segmentId,paragraphs:a.BuildTextUtils.range.getParagraphsInRange(c,(u=(d=S.getBody())==null?void 0:d.paragraphs)!=null?u:[],(h=(m=S.getBody())==null?void 0:m.dataStream)!=null?h:""),customRanges:a.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(c,(p=(g=S.getBody())==null?void 0:g.customRanges)!=null?p:[]),commandId:e,commandParams:n},C=i.find(T=>T.match(E));return(f=C==null?void 0:C.getMutations(E))!=null?f:[]}return[]}},y.DocAutoFormatService=ps([oi(0,a.IUniverInstanceService),oi(1,a.Inject(D.DocSelectionManagerService))],y.DocAutoFormatService);const ii={undo:!0,redo:!0,font:!0,fontSize:!0,bold:!0,italic:!0,strikethrough:!0,underline:!0,textColor:!0,fillColor:!0,horizontalAlignMode:!0,verticalAlignMode:!0,textWrapMode:!0,textRotateMode:!0},ai={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0},si="DOC_UI_PLUGIN";var Ae=(o=>(o.MAIN="__Document_Render_Main__",o.BACKGROUND="__Document_Render_Background__",o))(Ae||{}),se=(o=>(o.VIEW_MAIN="viewMain",o.VIEW_TOP="viewTop",o.VIEW_LEFT="viewLeft",o.VIEW_LEFT_TOP="viewLeftTop",o))(se||{});const ri=0,Ut=2,ci=4,Dn=10,fs="normalTextSelectionPluginName";function Ie(o){const{mainComponent:t,scene:e,engine:n,components:i}=o,s=t,r=i.get(Ae.BACKGROUND);return{document:s,docBackground:r,scene:e,engine:n}}function li(o,t){const e=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!e)return null;const n=e.getUnitId(),i=t.getRenderById(n);if(i==null)return;const{mainComponent:s,scene:r,engine:c,components:l}=i,A=s,d=l.get(Ae.BACKGROUND);return{document:A,docBackground:d,scene:r,engine:c}}function Ss(o,t){const e=t.getRenderById(o);if(e==null)return;const{mainComponent:n,scene:i,engine:s,components:r}=e,c=n,l=r.get(Ae.BACKGROUND);return{document:c,docBackground:l,scene:i,engine:s}}function di(o){const{unitId:t,ranges:e,id:n,type:i,segmentId:s}=o,r={id:D.RichTextEditingMutation.id,params:{unitId:t,actions:[],textRanges:void 0,segmentId:s}},c=a.JSONX.getInstance(),l=a.BuildTextUtils.customDecoration.add({ranges:e,id:n,type:i});return r.params.actions=c.editOp(l.serialize()),r}function Is(o,t){const{segmentId:e,id:n,type:i,unitId:s}=t,r=o.get(D.DocSelectionManagerService),c=o.get(a.IUniverInstanceService),l=s?c.getUnit(s,a.UniverInstanceType.UNIVER_DOC):c.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!l)return!1;const A=l.getUnitId(),d=r.getTextRanges({unitId:A,subUnitId:A});return!d||!l.getBody()?!1:di({unitId:A,ranges:d,id:n,type:i,segmentId:e})}function vs(o,t){const{unitId:e,id:n,segmentId:i}=t,r=o.get(a.IUniverInstanceService).getUnit(e);if(!r)return!1;const c={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:void 0,segmentId:i}},l=a.BuildTextUtils.customDecoration.delete({id:n,segmentId:i,documentDataModel:r});if(!l)return!1;const A=a.JSONX.getInstance();return c.params.actions=A.editOp(l.serialize()),c}function Es(o,t){return t.some(e=>o.startIndex>e.startIndex&&o.startIndex<e.endIndex)}function Lt(o,t,e,n,i){const{textRuns:s=[],dataStream:r}=o,c=i&&r.startsWith("="),l={st:0,ed:0,ts:{}};if(c)return l;for(let A=s.length-1;A>=0;A--){const d=s[A],{st:u,ed:m}=d;t>u&&t<=m&&(l.st=u,l.ed=m,l.ts={...l.ts,...d.ts})}if(t===0){const A=s==null?void 0:s[0];A&&A.st===0&&(l.ts={...l.ts,...A.ts})}return n&&(l.ts={...l.ts,...n}),l}function Bn(o,t,e){if(e){const i=o.find(s=>t>=s.startIndex&&t<=s.endIndex+1);return i!=null&&i.wholeEntity?null:i}const n=o.find(i=>t>i.startIndex&&t<=i.endIndex);return n!=null&&n.wholeEntity?null:n}function _n(o,t){return o.filter(e=>t>e.startIndex&&t<=e.endIndex)}function Cs(o){return{left:o.positionH.posOffset,top:o.positionV.posOffset,width:o.size.width,height:o.size.height}}function Ts(o,t=0,e=0){return{size:{width:o.width,height:o.height},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:(o.left||0)-t},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:(o.top||0)-e},angle:o.angle||0}}function Ai(o,t,e){const n=I.useDependency(a.ICommandService),i=I.useDependency(I.IShortcutService),s=w.useMemo(()=>a.generateRandomId(4),[]);w.useEffect(()=>{if(!e||!o||!t)return;const c=`sheet.operation.editor-${e.getEditorId()}-keyboard-${s}`,l=new a.DisposableCollection;return l.add(n.registerCommand({id:c,type:a.CommandType.OPERATION,handler(A,d){const{keyCode:u,metaKey:m}=d;t.handler(u,m)}})),t.keyCodes.map(A=>({id:c,binding:A.metaKey?A.keyCode|A.metaKey:A.keyCode,preconditions:()=>!0,priority:901,staticParameters:{eventType:_.DeviceInputEventType.Keyboard,keyCode:A.keyCode,metaKey:A.metaKey}})).forEach(A=>{l.add(i.registerShortcut(A))}),()=>{l.dispose()}},[n,t,e,o,s,i])}const ui=(o,t=!0,e,n)=>{const i=w.useCallback(()=>{if(o){const{scene:r,mainComponent:c}=o.render,l=o.render.with(D.DocSkeletonManagerService),{width:A,height:d}=o.getBoundingClientRect();l.getViewModel().getDataModel().updateDocumentDataPageSize(t?1/0:A,1/0),r.transformByState({width:A,height:d}),c==null||c.resize(A,d)}},[o,t]),s=w.useMemo(()=>a.debounce(()=>{var E,C;if(!e||!o||!e)return;const c=o.render.with(D.DocSkeletonManagerService).getSkeleton(),{scene:l,mainComponent:A}=o.render,d=l.getViewport(se.VIEW_MAIN),{actualWidth:u,actualHeight:m}=c.getActualSize(),{width:h,height:g}=o.getBoundingClientRect();let p=d==null?void 0:d.getScrollBar();const f=Math.max(u,h),S=Math.max(m,g);l.transformByState({width:f,height:S}),A==null||A.resize(f,S),t?u>h?(p==null?d&&new _.ScrollBar(d,{barSize:8,enableVertical:!1,enableHorizontal:!0,minThumbSizeV:8}):d==null||d.resetCanvasSizeAndUpdateScroll(),n&&(d==null||d.scrollToBarPos({x:1/0,y:0}))):(p=null,d==null||d.scrollToBarPos({x:0,y:0}),(C=d==null?void 0:d.getScrollBar())==null||C.dispose()):m>g?(p==null?d&&(p=new _.ScrollBar(d,{enableHorizontal:!1,enableVertical:!0,barSize:8,minThumbSizeV:8})):d==null||d.resetCanvasSizeAndUpdateScroll(),n&&(d==null||d.scrollToBarPos({x:0,y:1/0}))):(p=null,d==null||d.scrollToBarPos({x:0,y:0}),(E=d==null?void 0:d.getScrollBar())==null||E.dispose())},30),[o,e,t,n]);return w.useEffect(()=>{if(e&&o){const r=setTimeout(()=>{i(),s()},500);return()=>{clearTimeout(r)}}},[o,e,i,s]),w.useEffect(()=>{if(e&&o){const r=o.input$.subscribe(()=>{s()});return()=>{r.unsubscribe()}}},[o,e,s]),{resize:i,checkScrollBar:s}};function re(o,t){var n;return(n=o.get(_.IRenderManagerService).getRenderById(t))==null?void 0:n.with(D.DocSkeletonManagerService)}function Z(o,t=""){if(!t)return["body"];const{headers:e,footers:n}=o.getSnapshot();if(e==null&&n==null)throw new Error("Document data model must have headers or footers when update by segment id");if((e==null?void 0:e[t])!=null)return["headers",t,"body"];if((n==null?void 0:n[t])!=null)return["footers",t,"body"];throw new Error("Segment id not found in headers or footers")}const Nn={id:"doc.command-replace-snapshot",type:a.CommandType.COMMAND,handler:(o,t)=>{const{unitId:e,snapshot:n,textRanges:i,segmentId:s="",options:r}=t,c=o.get(a.IUniverInstanceService),l=o.get(a.ICommandService),A=o.get(D.DocSelectionManagerService),d=c.getUnit(e,a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(s).getSnapshot();if(d==null||u==null)return!1;const{body:m,tableSource:h,footers:g,headers:p,lists:f,drawings:S,drawingsOrder:E,documentStyle:C}=a.Tools.deepClone(n),{body:T,tableSource:R,footers:v,headers:O,lists:M,drawings:b,drawingsOrder:N,documentStyle:x}=u;if(m==null||T==null)return!1;if(a.Tools.diffValue(m,T)&&i)return A.replaceDocRanges(i,{unitId:e,subUnitId:e},!1),!0;const U={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:i}};r&&(U.params.options=r);const F=[],V=a.JSONX.getInstance();if(!a.Tools.diffValue(x,C)){const Q=V.replaceOp(["documentStyle"],x,C);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(m,T)){const Q=V.replaceOp(["body"],T,m);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(h,R)){const Q=V.replaceOp(["tableSource"],R,h);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(g,v)){const Q=V.replaceOp(["footers"],v,g);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(p,O)){const Q=V.replaceOp(["headers"],O,p);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(f,M)){const Q=V.replaceOp(["lists"],M,f);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(S,b)){const Q=V.replaceOp(["drawings"],b,S);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(E,N)){const Q=V.replaceOp(["drawingsOrder"],N,E);Q!=null&&F.push(Q)}return U.params.actions=F.reduce((Q,X)=>a.JSONX.compose(Q,X),null),!!l.syncExecuteCommand(U.id,U.params)}},hi={id:"doc.command-replace-content",type:a.CommandType.COMMAND,handler:async(o,t)=>{const{unitId:e,body:n,textRanges:i,segmentId:s="",options:r}=t,c=o.get(a.IUniverInstanceService),l=o.get(a.ICommandService),A=o.get(D.DocSelectionManagerService),d=c.getUnit(e,a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(s).getSnapshot().body;if(d==null||u==null)return!1;const m=mi(e,s,d,u,n);return m.params.textRanges=i,r&&(m.params.options=r),m.params.actions==null&&i?(A.replaceDocRanges(i,{unitId:e,subUnitId:e},!1),!0):!!l.syncExecuteCommand(m.id,m.params)}},gi={id:"doc.command-cover-content",type:a.CommandType.COMMAND,handler:(o,t)=>{const{unitId:e,body:n,segmentId:i="",textRanges:s}=t,r=o.get(a.IUniverInstanceService),c=o.get(a.ICommandService),l=o.get(a.IUndoRedoService),A=r.getUniverDocInstance(e),d=A==null?void 0:A.getSnapshot().body;if(A==null||d==null)return!1;const u=mi(e,i,A,d,n);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,u.params.textRanges=s,c.syncExecuteCommand(u.id,u.params),l.clearUndoRedo(e),!0}};function ys(o,t,e,n){const i=new a.TextX,s=a.JSONX.getInstance(),r=(e==null?void 0:e.dataStream.length)-2;r>0&&i.push({t:a.TextXActionType.DELETE,len:r}),n.dataStream.length>0&&i.push({t:a.TextXActionType.INSERT,body:n,len:n.dataStream.length});const c=Z(t,o);return s.editOp(i.serialize(),c)}function mi(o,t,e,n,i){const s={id:D.RichTextEditingMutation.id,params:{unitId:o,actions:[],textRanges:[]}},r=ys(t,e,n,i);return s.params.actions=r,s}const Pn={id:"doc.command.replace-selection",type:a.CommandType.COMMAND,handler(o,t){var g;if(!t)return!1;const e=o.get(a.ICommandService),{unitId:n,body:i,textRanges:s}=t,c=o.get(a.IUniverInstanceService).getUnit(n),l=o.get(D.DocSelectionManagerService);if(!c)return!1;const A=c.getBody(),d=(g=t.selection)!=null?g:l.getActiveTextRange();if(!d||!A)return!1;const u={id:D.RichTextEditingMutation.id,params:{unitId:n,actions:[],textRanges:s,debounce:!0}},m=new a.TextX,h=a.JSONX.getInstance();return m.push(...a.BuildTextUtils.selection.delete([d],A,0,i)),u.params.actions=h.editOp(m.serialize()),e.syncExecuteCommand(u.id,u.params)}},pi={id:"doc.command.replace-text-runs",type:a.CommandType.COMMAND,handler:(o,t)=>{const{unitId:e,body:n,textRanges:i,segmentId:s="",options:r}=t,c=o.get(a.IUniverInstanceService),l=o.get(a.ICommandService),A=c.getUnit(e,a.UniverInstanceType.UNIVER_DOC),d=A==null?void 0:A.getSelfOrHeaderFooterModel(s).getSnapshot().body;if(A==null||d==null)return!1;const u=a.BuildTextUtils.selection.replaceTextRuns({doc:A,body:n,selection:{startOffset:0,endOffset:d.dataStream.length-2,collapsed:!1}});if(!u)return!1;const m={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:i,noHistory:!0}},h=a.JSONX.getInstance(),g=Z(A,s);return m.params.actions=h.editOp(u.serialize(),g),m.params.textRanges=i,r&&(m.params.options=r),!!l.syncExecuteCommand(m.id,m.params)}};var Qt=(o=>(o[o.page=0]="page",o[o.section=1]="section",o[o.column=2]="column",o[o.line=3]="line",o[o.divide=4]="divide",o[o.glyph=5]="glyph",o))(Qt||{});const Ye={page:0,section:1,column:2,line:3,divide:4,glyph:5};function wn(o,t){return o.page>t.page?!1:o.page<t.page?!0:o.section>t.section?!1:o.section<t.section?!0:o.column>t.column?!1:o.column<t.column?!0:o.line>t.line?!1:o.line<t.line?!0:o.divide>t.divide?!1:o.divide<t.divide?!0:o.glyph>t.glyph?!1:(o.glyph<t.glyph,!0)}function Un(o,t){return wn(o,t)?{start:o,end:t}:{start:t,end:o}}function Ln(o){const t=o.length;if(t===0)return;const e=o[0],n=o[t-1],i=o.length===1&&e.collapsed;return{startOffset:e.startOffset,endOffset:n.endOffset,collapsed:i}}function bs(o,t,e,n){let i=n,s=n;for(let r=0;r<o.length;r++){const l=o[r].count;r<t&&(i+=l),r<e&&(s+=l)}return{startOffset:i,endOffset:s}}function Qn(o){const{startX:t,startY:e,endX:n,endY:i}=o,s=[];return s.push({x:t,y:e}),s.push({x:n,y:e}),s.push({x:n,y:i}),s.push({x:t,y:i}),s.push({x:t,y:e}),s}class ve{constructor(t,e){B(this,"_liquid",new _.Liquid);B(this,"_currentStartState",{page:0,section:0,column:0,line:0,divide:0,glyph:0});B(this,"_currentEndState",{page:0,section:0,column:0,line:0,divide:0,glyph:0});this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const n=[],i=[],s=[];if(t==null||e==null)return{borderBoxPointGroup:n,contentBoxPointGroup:i,cursorList:s};if(!this._isValidPosition(t,e))throw new Error(`
34
+ (function(y,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/docs"),require("@univerjs/engine-render"),require("@univerjs/ui"),require("react"),require("react/jsx-runtime"),require("@univerjs/design"),require("rxjs"),require("rxjs/operators"),require("@univerjs/drawing")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs","@univerjs/engine-render","@univerjs/ui","react","react/jsx-runtime","@univerjs/design","rxjs","rxjs/operators","@univerjs/drawing"],a):(y=typeof globalThis<"u"?globalThis:y||self,a(y.UniverDocsUi={},y.UniverCore,y.UniverDocs,y.UniverEngineRender,y.UniverUi,y.React,y.React,y.UniverDesign,y.rxjs,y.rxjs.operators,y.UniverDrawing))})(this,function(y,a,D,_,I,w,P,J,L,dt,xn){"use strict";var DA=Object.defineProperty;var BA=(y,a,D)=>a in y?DA(y,a,{enumerable:!0,configurable:!0,writable:!0,value:D}):y[a]=D;var B=(y,a,D)=>BA(y,typeof a!="symbol"?a+"":a,D);var ms=Object.getOwnPropertyDescriptor,ps=(o,t,e,n)=>{for(var i=n>1?void 0:n?ms(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},oi=(o,t)=>(e,n)=>t(e,n,o);y.DocAutoFormatService=class extends a.Disposable{constructor(e,n){super();B(this,"_matches",new Map);this._univerInstanceService=e,this._textSelectionManagerService=n}registerAutoFormat(e){const n=this._matches.get(e.id);return n?(n.push(e),n.sort((i,s)=>{var r,c;return((r=s.priority)!=null?r:0)-((c=i.priority)!=null?c:0)})):this._matches.set(e.id,[e]),a.toDisposable(()=>{const i=this._matches.get(e.id);if(i){const s=i.findIndex(r=>r===e);s>=0&&i.splice(s,1)}})}onAutoFormat(e,n){var l,A,d,u,m,h,g,p,f;const i=(l=this._matches.get(e))!=null?l:[],s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),r=this._textSelectionManagerService.getDocRanges(),c=(A=r.find(S=>S.isActive))!=null?A:r[0];if(s&&c){const S=s.getSelfOrHeaderFooterModel(c.segmentId),E={unit:S,selection:c,isBody:!c.segmentId,paragraphs:a.BuildTextUtils.range.getParagraphsInRange(c,(u=(d=S.getBody())==null?void 0:d.paragraphs)!=null?u:[],(h=(m=S.getBody())==null?void 0:m.dataStream)!=null?h:""),customRanges:a.BuildTextUtils.customRange.getCustomRangesInterestsWithSelection(c,(p=(g=S.getBody())==null?void 0:g.customRanges)!=null?p:[]),commandId:e,commandParams:n},C=i.find(T=>T.match(E));return(f=C==null?void 0:C.getMutations(E))!=null?f:[]}return[]}},y.DocAutoFormatService=ps([oi(0,a.IUniverInstanceService),oi(1,a.Inject(D.DocSelectionManagerService))],y.DocAutoFormatService);const ii={undo:!0,redo:!0,font:!0,fontSize:!0,bold:!0,italic:!0,strikethrough:!0,underline:!0,textColor:!0,fillColor:!0,horizontalAlignMode:!0,verticalAlignMode:!0,textWrapMode:!0,textRotateMode:!0},ai={outerLeft:!1,outerRight:!1,header:!0,footer:!0,innerLeft:!1,innerRight:!1,frozenHeaderLT:!1,frozenHeaderRT:!1,frozenHeaderLM:!1,frozenContent:!1,infoBar:!0,toolbar:!0},si="DOC_UI_PLUGIN";var Ae=(o=>(o.MAIN="__Document_Render_Main__",o.BACKGROUND="__Document_Render_Background__",o))(Ae||{}),se=(o=>(o.VIEW_MAIN="viewMain",o.VIEW_TOP="viewTop",o.VIEW_LEFT="viewLeft",o.VIEW_LEFT_TOP="viewLeftTop",o))(se||{});const ri=0,Ut=2,ci=4,Dn=10,fs="normalTextSelectionPluginName";function Ie(o){const{mainComponent:t,scene:e,engine:n,components:i}=o,s=t,r=i.get(Ae.BACKGROUND);return{document:s,docBackground:r,scene:e,engine:n}}function li(o,t){const e=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!e)return null;const n=e.getUnitId(),i=t.getRenderById(n);if(i==null)return;const{mainComponent:s,scene:r,engine:c,components:l}=i,A=s,d=l.get(Ae.BACKGROUND);return{document:A,docBackground:d,scene:r,engine:c}}function Ss(o,t){const e=t.getRenderById(o);if(e==null)return;const{mainComponent:n,scene:i,engine:s,components:r}=e,c=n,l=r.get(Ae.BACKGROUND);return{document:c,docBackground:l,scene:i,engine:s}}function di(o){const{unitId:t,ranges:e,id:n,type:i,segmentId:s}=o,r={id:D.RichTextEditingMutation.id,params:{unitId:t,actions:[],textRanges:void 0,segmentId:s}},c=a.JSONX.getInstance(),l=a.BuildTextUtils.customDecoration.add({ranges:e,id:n,type:i});return r.params.actions=c.editOp(l.serialize()),r}function Is(o,t){const{segmentId:e,id:n,type:i,unitId:s}=t,r=o.get(D.DocSelectionManagerService),c=o.get(a.IUniverInstanceService),l=s?c.getUnit(s,a.UniverInstanceType.UNIVER_DOC):c.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(!l)return!1;const A=l.getUnitId(),d=r.getTextRanges({unitId:A,subUnitId:A});return!d||!l.getBody()?!1:di({unitId:A,ranges:d,id:n,type:i,segmentId:e})}function vs(o,t){const{unitId:e,id:n,segmentId:i}=t,r=o.get(a.IUniverInstanceService).getUnit(e);if(!r)return!1;const c={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:void 0,segmentId:i}},l=a.BuildTextUtils.customDecoration.delete({id:n,segmentId:i,documentDataModel:r});if(!l)return!1;const A=a.JSONX.getInstance();return c.params.actions=A.editOp(l.serialize()),c}function Es(o,t){return t.some(e=>o.startIndex>e.startIndex&&o.startIndex<e.endIndex)}function Lt(o,t,e,n,i){const{textRuns:s=[],dataStream:r}=o,c=i&&r.startsWith("="),l={st:0,ed:0,ts:{}};if(c)return l;for(let A=s.length-1;A>=0;A--){const d=s[A],{st:u,ed:m}=d;t>u&&t<=m&&(l.st=u,l.ed=m,l.ts={...l.ts,...d.ts})}if(t===0){const A=s==null?void 0:s[0];A&&A.st===0&&(l.ts={...l.ts,...A.ts})}return n&&(l.ts={...l.ts,...n}),l}function Bn(o,t,e){if(e){const i=o.find(s=>t>=s.startIndex&&t<=s.endIndex+1);return i!=null&&i.wholeEntity?null:i}const n=o.find(i=>t>i.startIndex&&t<=i.endIndex);return n!=null&&n.wholeEntity?null:n}function _n(o,t){return o.filter(e=>t>e.startIndex&&t<=e.endIndex)}function Cs(o){return{left:o.positionH.posOffset,top:o.positionV.posOffset,width:o.size.width,height:o.size.height}}function Ts(o,t=0,e=0){return{size:{width:o.width,height:o.height},positionH:{relativeFrom:a.ObjectRelativeFromH.MARGIN,posOffset:(o.left||0)-t},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:(o.top||0)-e},angle:o.angle||0}}function Ai(o,t,e){const n=I.useDependency(a.ICommandService),i=I.useDependency(I.IShortcutService),s=w.useMemo(()=>a.generateRandomId(4),[]);w.useEffect(()=>{if(!e||!o||!t)return;const c=`sheet.operation.editor-${e.getEditorId()}-keyboard-${s}`,l=new a.DisposableCollection;return l.add(n.registerCommand({id:c,type:a.CommandType.OPERATION,handler(A,d){const{keyCode:u,metaKey:m}=d;t.handler(u,m)}})),t.keyCodes.map(A=>({id:c,binding:A.metaKey?A.keyCode|A.metaKey:A.keyCode,preconditions:()=>!0,priority:901,staticParameters:{eventType:_.DeviceInputEventType.Keyboard,keyCode:A.keyCode,metaKey:A.metaKey}})).forEach(A=>{l.add(i.registerShortcut(A))}),()=>{l.dispose()}},[n,t,e,o,s,i])}const ui=(o,t=!0,e,n)=>{const i=w.useCallback(()=>{if(o){const{scene:r,mainComponent:c}=o.render,l=o.render.with(D.DocSkeletonManagerService),{width:A,height:d}=o.getBoundingClientRect();l.getViewModel().getDataModel().updateDocumentDataPageSize(t?1/0:A,1/0),r.transformByState({width:A,height:d}),c==null||c.resize(A,d)}},[o,t]),s=w.useMemo(()=>a.debounce(()=>{var E,C;if(!e||!o||!e)return;const c=o.render.with(D.DocSkeletonManagerService).getSkeleton(),{scene:l,mainComponent:A}=o.render,d=l.getViewport(se.VIEW_MAIN),{actualWidth:u,actualHeight:m}=c.getActualSize(),{width:h,height:g}=o.getBoundingClientRect();let p=d==null?void 0:d.getScrollBar();const f=Math.max(u,h),S=Math.max(m,g);l.transformByState({width:f,height:S}),A==null||A.resize(f,S),t?u>h?(p==null?d&&new _.ScrollBar(d,{barSize:8,enableVertical:!1,enableHorizontal:!0,minThumbSizeV:8}):d==null||d.resetCanvasSizeAndUpdateScroll(),n&&(d==null||d.scrollToBarPos({x:1/0,y:0}))):(p=null,d==null||d.scrollToBarPos({x:0,y:0}),(C=d==null?void 0:d.getScrollBar())==null||C.dispose()):m>g?(p==null?d&&(p=new _.ScrollBar(d,{enableHorizontal:!1,enableVertical:!0,barSize:8,minThumbSizeV:8})):d==null||d.resetCanvasSizeAndUpdateScroll(),n&&(d==null||d.scrollToBarPos({x:0,y:1/0}))):(p=null,d==null||d.scrollToBarPos({x:0,y:0}),(E=d==null?void 0:d.getScrollBar())==null||E.dispose())},30),[o,e,t,n]);return w.useEffect(()=>{if(e&&o){const r=setTimeout(()=>{i(),s()},500);return()=>{clearTimeout(r)}}},[o,e,i,s]),w.useEffect(()=>{if(e&&o){const r=o.input$.subscribe(()=>{s()});return()=>{r.unsubscribe()}}},[o,e,s]),{resize:i,checkScrollBar:s}};function re(o,t){var n;return(n=o.get(_.IRenderManagerService).getRenderById(t))==null?void 0:n.with(D.DocSkeletonManagerService)}function Z(o,t=""){if(!t)return["body"];const{headers:e,footers:n}=o.getSnapshot();if(e==null&&n==null)throw new Error("Document data model must have headers or footers when update by segment id");if((e==null?void 0:e[t])!=null)return["headers",t,"body"];if((n==null?void 0:n[t])!=null)return["footers",t,"body"];throw new Error("Segment id not found in headers or footers")}const Nn={id:"doc.command-replace-snapshot",type:a.CommandType.COMMAND,handler:(o,t)=>{const{unitId:e,snapshot:n,textRanges:i,segmentId:s="",options:r}=t,c=o.get(a.IUniverInstanceService),l=o.get(a.ICommandService),A=o.get(D.DocSelectionManagerService),d=c.getUnit(e,a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(s).getSnapshot();if(d==null||u==null)return!1;const{body:m,tableSource:h,footers:g,headers:p,lists:f,drawings:S,drawingsOrder:E,documentStyle:C}=a.Tools.deepClone(n),{body:T,tableSource:R,footers:v,headers:O,lists:M,drawings:b,drawingsOrder:N,documentStyle:x}=u;if(m==null||T==null)return!1;if(a.Tools.diffValue(m,T)&&i)return A.replaceDocRanges(i,{unitId:e,subUnitId:e},!1),!0;const U={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:i}};r&&(U.params.options=r);const F=[],V=a.JSONX.getInstance();if(!a.Tools.diffValue(x,C)){const Q=V.replaceOp(["documentStyle"],x,C);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(m,T)){const Q=V.replaceOp(["body"],T,m);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(h,R)){const Q=V.replaceOp(["tableSource"],R,h);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(g,v)){const Q=V.replaceOp(["footers"],v,g);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(p,O)){const Q=V.replaceOp(["headers"],O,p);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(f,M)){const Q=V.replaceOp(["lists"],M,f);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(S,b)){const Q=V.replaceOp(["drawings"],b,S);Q!=null&&F.push(Q)}if(!a.Tools.diffValue(E,N)){const Q=V.replaceOp(["drawingsOrder"],N,E);Q!=null&&F.push(Q)}return U.params.actions=F.reduce((Q,X)=>a.JSONX.compose(Q,X),null),!!l.syncExecuteCommand(U.id,U.params)}},hi={id:"doc.command-replace-content",type:a.CommandType.COMMAND,handler:async(o,t)=>{const{unitId:e,body:n,textRanges:i,segmentId:s="",options:r}=t,c=o.get(a.IUniverInstanceService),l=o.get(a.ICommandService),A=o.get(D.DocSelectionManagerService),d=c.getUnit(e,a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(s).getSnapshot().body;if(d==null||u==null)return!1;const m=mi(e,s,d,u,n);return m.params.textRanges=i,r&&(m.params.options=r),m.params.actions==null&&i?(A.replaceDocRanges(i,{unitId:e,subUnitId:e},!1),!0):!!l.syncExecuteCommand(m.id,m.params)}},gi={id:"doc.command-cover-content",type:a.CommandType.COMMAND,handler:(o,t)=>{const{unitId:e,body:n,segmentId:i="",textRanges:s}=t,r=o.get(a.IUniverInstanceService),c=o.get(a.ICommandService),l=o.get(a.IUndoRedoService),A=r.getUniverDocInstance(e),d=A==null?void 0:A.getSnapshot().body;if(A==null||d==null)return!1;const u=mi(e,i,A,d,n);return u.params.noNeedSetTextRange=!0,u.params.noHistory=!0,u.params.textRanges=s,c.syncExecuteCommand(u.id,u.params),l.clearUndoRedo(e),!0}};function ys(o,t,e,n){const i=new a.TextX,s=a.JSONX.getInstance(),r=(e==null?void 0:e.dataStream.length)-2;r>0&&i.push({t:a.TextXActionType.DELETE,len:r}),n.dataStream.length>0&&i.push({t:a.TextXActionType.INSERT,body:n,len:n.dataStream.length});const c=Z(t,o);return s.editOp(i.serialize(),c)}function mi(o,t,e,n,i){const s={id:D.RichTextEditingMutation.id,params:{unitId:o,actions:[],textRanges:[]}},r=ys(t,e,n,i);return s.params.actions=r,s}const Pn={id:"doc.command.replace-selection",type:a.CommandType.COMMAND,handler(o,t){var g;if(!t)return!1;const e=o.get(a.ICommandService),{unitId:n,body:i,textRanges:s}=t,c=o.get(a.IUniverInstanceService).getUnit(n),l=o.get(D.DocSelectionManagerService);if(!c)return!1;const A=c.getBody(),d=(g=t.selection)!=null?g:l.getActiveTextRange();if(!d||!A)return!1;const u={id:D.RichTextEditingMutation.id,params:{unitId:n,actions:[],textRanges:s,debounce:!0}},m=new a.TextX,h=a.JSONX.getInstance();return m.push(...a.BuildTextUtils.selection.delete([d],A,0,i)),u.params.actions=h.editOp(m.serialize()),e.syncExecuteCommand(u.id,u.params)}},pi={id:"doc.command.replace-text-runs",type:a.CommandType.COMMAND,handler:(o,t)=>{const{unitId:e,body:n,textRanges:i,segmentId:s="",options:r}=t,c=o.get(a.IUniverInstanceService),l=o.get(a.ICommandService),A=o.get(a.ThemeService),d=c.getUnit(e,a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(s).getSnapshot().body;if(d==null||u==null)return!1;const m=a.BuildTextUtils.selection.replaceTextRuns({doc:d,body:n,selection:{startOffset:0,endOffset:u.dataStream.length-2,collapsed:!1},themeService:A});if(!m)return!1;const h={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:i,noHistory:!0}},g=a.JSONX.getInstance(),p=Z(d,s);return h.params.actions=g.editOp(m.serialize(),p),h.params.textRanges=i,r&&(h.params.options=r),!!l.syncExecuteCommand(h.id,h.params)}};var Qt=(o=>(o[o.page=0]="page",o[o.section=1]="section",o[o.column=2]="column",o[o.line=3]="line",o[o.divide=4]="divide",o[o.glyph=5]="glyph",o))(Qt||{});const Ye={page:0,section:1,column:2,line:3,divide:4,glyph:5};function wn(o,t){return o.page>t.page?!1:o.page<t.page?!0:o.section>t.section?!1:o.section<t.section?!0:o.column>t.column?!1:o.column<t.column?!0:o.line>t.line?!1:o.line<t.line?!0:o.divide>t.divide?!1:o.divide<t.divide?!0:o.glyph>t.glyph?!1:(o.glyph<t.glyph,!0)}function Un(o,t){return wn(o,t)?{start:o,end:t}:{start:t,end:o}}function Ln(o){const t=o.length;if(t===0)return;const e=o[0],n=o[t-1],i=o.length===1&&e.collapsed;return{startOffset:e.startOffset,endOffset:n.endOffset,collapsed:i}}function bs(o,t,e,n){let i=n,s=n;for(let r=0;r<o.length;r++){const l=o[r].count;r<t&&(i+=l),r<e&&(s+=l)}return{startOffset:i,endOffset:s}}function Qn(o){const{startX:t,startY:e,endX:n,endY:i}=o,s=[];return s.push({x:t,y:e}),s.push({x:n,y:e}),s.push({x:n,y:i}),s.push({x:t,y:i}),s.push({x:t,y:e}),s}class ve{constructor(t,e){B(this,"_liquid",new _.Liquid);B(this,"_currentStartState",{page:0,section:0,column:0,line:0,divide:0,glyph:0});B(this,"_currentEndState",{page:0,section:0,column:0,line:0,divide:0,glyph:0});this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const n=[],i=[],s=[];if(t==null||e==null)return{borderBoxPointGroup:n,contentBoxPointGroup:i,cursorList:s};if(!this._isValidPosition(t,e))throw new Error(`
35
35
  Invalid positions in NodePositionConvertToCursor,
36
36
  they are not in the same segment page when in header or footer.`);const{start:c,end:l}=Un(t,e);return this._selectionIterator(c,l,(A,d,u,m,h,g)=>{const{lineHeight:p,asc:f,paddingTop:S,marginTop:E,marginBottom:C}=g,{glyphGroup:T,st:R}=h;if(T.length===0)return;const{x:v,y:O}=this._liquid;let M,b;const N=T[A],x=T[d],U=T[A-1],F=(N==null?void 0:N.left)||0,V=(N==null?void 0:N.width)||0,H=(x==null?void 0:x.left)||0,Q=(x==null?void 0:x.width)||0,X=(N==null?void 0:N.glyphType)===_.GlyphType.LIST,{startOffset:j,endOffset:k}=bs(T,A,d,R),W=c.glyph===A&&u?c.isBack:!0,G=l.glyph===d&&m?l.isBack:!1,K=c===l,Y=W&&U!=null?U:N;if(A===0&&d===T.length-1)M={startX:v+F+(X?V:0),startY:O,endX:v+H+(G?0:Q),endY:O+p-E-C},b={startX:v+F+(X?V:0),startY:O+S+f-Y.bBox.ba,endX:v+H+(G?0:Q),endY:O+S+f+Y.bBox.bd};else{const q=W&&!X;M={startX:v+F+(q?0:V),startY:O,endX:v+H+(G?0:Q),endY:O+p-E-C},b={startX:v+F+(q?0:V),startY:O+S+f-Y.bBox.ba,endX:v+H+(G?0:Q),endY:O+S+f+Y.bBox.bd}}n.push(Qn(M)),i.push(Qn(b)),s.push({startOffset:W?j:j+N.count,endOffset:G?k:k+x.count,collapsed:K})}),{borderBoxPointGroup:n,contentBoxPointGroup:i,cursorList:s}}_isValidPosition(t,e){const{segmentPage:n,pageType:i}=t,{segmentPage:s,pageType:r}=e;return i!==r?!1:i===_.DocumentSkeletonPageType.HEADER||i===_.DocumentSkeletonPageType.FOOTER?n===s:!0}_resetCurrentNodePositionState(){this._currentStartState={page:0,section:0,column:0,line:0,divide:0,glyph:0},this._currentEndState={page:0,section:0,column:0,line:0,divide:0,glyph:0}}_setNodePositionState(t=0,e,n,i){i===e?this._currentStartState[t]=1:this._currentStartState[t]=0,i===n?this._currentEndState[t]=2:this._currentEndState[t]=0}_checkPreviousNodePositionState(t,e=!0){let n=t,i;for(;n>=0;){const s=Qt[n];let r;if(e?r=this._currentStartState[s]:r=this._currentEndState[s],r===void 0)return;if(i===void 0&&(i=r),r!==i)return 0;n--}return i}_getSelectionRuler(t,e,n,i,s){let r=0,c=i;const l=Qt[t],A=Qt[t+1];if(A===null||l===null)return{start_next:r,end_next:c};const d=e[l],u=n[l];this._setNodePositionState(l,d,u,s);const m=this._checkPreviousNodePositionState(t),h=this._checkPreviousNodePositionState(t,!1);return m===1&&(r=e[A]),h===2&&(c=n[A]),{start_next:r,end_next:c}}_selectionIterator(t,e,n){var T,R;const i=this._docSkeleton;if(!i)return[];const{pageType:s,path:r}=t;this._liquid.reset();const c=i.getSkeletonData();if(c==null)return[];const{pages:l,skeHeaders:A,skeFooters:d}=c,{page:u,segmentPage:m}=t,{page:h,segmentPage:g}=e;if(this._resetCurrentNodePositionState(),this._documentOffsetConfig==null)return[];const{pageLayoutType:p,pageMarginLeft:f,pageMarginTop:S}=this._documentOffsetConfig,E=s===_.DocumentSkeletonPageType.BODY||s===_.DocumentSkeletonPageType.CELL?u:m;for(let v=0;v<E;v++){const O=l[v];this._liquid.translatePage(O,p,f,S)}const C=s===_.DocumentSkeletonPageType.BODY||s===_.DocumentSkeletonPageType.CELL?h:g;for(let v=E;v<=C;v++){const O=l[v],{headerId:M,footerId:b,pageWidth:N}=O;let x=O;if(s===_.DocumentSkeletonPageType.HEADER?x=(T=A.get(M))==null?void 0:T.get(N):s===_.DocumentSkeletonPageType.FOOTER?x=(R=d.get(b))==null?void 0:R.get(N):s===_.DocumentSkeletonPageType.CELL&&(x=_.getPageFromPath(c,r)),x==null){this._liquid.translatePage(O,p,f,S);continue}const U=x.sections,{start_next:F,end_next:V}=this._getSelectionRuler(Ye.page,t,e,U.length-1,s===_.DocumentSkeletonPageType.BODY||s===_.DocumentSkeletonPageType.CELL?v:0);switch(this._liquid.translateSave(),s){case _.DocumentSkeletonPageType.HEADER:this._liquid.translatePagePadding({...x,marginLeft:O.marginLeft});break;case _.DocumentSkeletonPageType.FOOTER:{const H=O.pageHeight-x.height-x.marginBottom;this._liquid.translate(O.marginLeft,H);break}case _.DocumentSkeletonPageType.CELL:{this._liquid.translatePagePadding(O);const H=x.parent,Q=H.parent,{left:X}=x,{top:j,left:k}=Q,{top:W}=H;this._liquid.translate(k+X,j+W),this._liquid.translatePagePadding(x);break}default:this._liquid.translatePagePadding(O);break}for(let H=F;H<=V;H++){const Q=U[H],X=Q.columns,{start_next:j,end_next:k}=this._getSelectionRuler(Ye.section,t,e,X.length-1,H);this._liquid.translateSection(Q);for(let W=j;W<=k;W++){const G=X[W],K=G.lines,{start_next:Y,end_next:q}=this._getSelectionRuler(Ye.column,t,e,K.length-1,W);this._liquid.translateColumn(G);for(let z=Y;z<=q;z++){const $=K[z],{divides:ie}=$,{start_next:fe,end_next:Fe}=this._getSelectionRuler(Ye.line,t,e,ie.length-1,z);this._liquid.translateSave(),this._liquid.translateLine($,!0,!1);for(let Se=fe;Se<=Fe;Se++){const ni=ie[Se];this._liquid.translateSave(),this._liquid.translateDivide(ni);const{glyphGroup:RA}=ni,{start_next:MA,end_next:xA}=this._getSelectionRuler(Ye.divide,t,e,RA.length-1,Se);let hs=!1,gs=!1;v===E&&H===F&&W===j&&z===Y&&Se===fe&&(hs=!0),v===C&&H===V&&W===k&&z===q&&Se===Fe&&(gs=!0),n&&n(MA,xA,hs,gs,ni,$,G,Q,x),this._liquid.translateRestore()}this._liquid.translateRestore()}}}this._liquid.translateRestore(),this._liquid.translatePage(O,p,f,S)}}}function fi(o,t){const{path:e}=o,{path:n}=t;if(e.length!==n.length||e.indexOf("cells")===-1)return!1;const i=e.indexOf("skeTables")+1,s=e.indexOf("rows")+1,r=e.indexOf("cells")+1,{tableId:c,sliceIndex:l}=_.getTableIdAndSliceIndex(e[i]),{tableId:A,sliceIndex:d}=_.getTableIdAndSliceIndex(n[i]);if(c!==A)return!1;const u=e[s],m=n[s],h=e[r],g=n[r];return!(u===m&&h===g&&l===d)}function Fn(o,t){const{path:e}=o,{path:n}=t;return e.indexOf("cells")===-1||n.indexOf("cells")===-1||e.length!==n.length?!1:a.Tools.diffValue(e,n)}function Si(o,t,e){var h,g,p,f,S,E,C,T;const{path:n}=t,{path:i}=e;if(n.indexOf("cells")===-1||i.indexOf("cells")===-1)return!1;const s=o.findGlyphByPosition(t),r=o.findGlyphByPosition(e),c=(f=(p=(g=(h=s==null?void 0:s.parent)==null?void 0:h.parent)==null?void 0:g.parent)==null?void 0:p.parent)==null?void 0:f.parent,l=(T=(C=(E=(S=r==null?void 0:r.parent)==null?void 0:S.parent)==null?void 0:E.parent)==null?void 0:C.parent)==null?void 0:T.parent;if(c==null||l==null)return!1;const A=c.parent,d=l.parent,u=A.cells.indexOf(c),m=d.cells.indexOf(l);return u===m&&A.index===d.index}function Hn(o,t){if(Fn(o,t))return wn(o,t);const{path:e}=o,{path:n}=t,i=e[e.length-5],s=n[n.length-5];if(i!==s&&typeof i=="string"&&typeof s=="string"){const d=i.split("#-#")[1],u=s.split("#-#")[1];return+d<+u}const r=e[e.length-3],c=n[n.length-3],l=e[e.length-1],A=n[n.length-1];return r<c?!0:r>c?!1:l<=A}function qe(o){return o.sections[0].columns[0].lines.length===0}function Os(o,t,e){let n=t,i=e,s=o[n],r=o[i];for(;n<i&&(qe(s)||qe(r));)qe(s)?(n++,s=o[n]):qe(r)&&(i--,r=o[i]);if(!qe(s)&&!qe(r))return[s,r]}class kn{constructor(t,e){B(this,"_liquid",new _.Liquid);this._documentOffsetConfig=t,this._docSkeleton=e}getRangePointData(t,e){const n=[],s=this._docSkeleton.getSkeletonData();if(s==null)return;const{pages:r}=s,{segmentPage:c,page:l,pageType:A}=t,d=this._getTableRectRangeInfo(t,e);if(d==null)return;const{tableId:u,startRowIndex:m,startColumnIndex:h,endRowIndex:g,endColumnIndex:p}=d;this._liquid.reset();const{pageLayoutType:f,pageMarginLeft:S,pageMarginTop:E}=this._documentOffsetConfig,C=A===_.DocumentSkeletonPageType.BODY||A===_.DocumentSkeletonPageType.CELL?l:c;for(let T=0;T<C;T++){const R=r[T];this._liquid.translatePage(R,f,S,E)}for(let T=C;T<r.length;T++){const R=r[T];this._liquid.translatePagePadding(R);const{skeTables:v}=R;let O=null;for(const[x,U]of v.entries())x.startsWith(u)&&(O=U);if(O==null){this._liquid.restorePagePadding(R),this._liquid.translatePage(R,f,S,E);continue}this._liquid.translateSave(),this._liquid.translate(0,O.top);const{x:M,y:b}=this._liquid,{left:N}=O;for(const x of O.rows)if(x.index>=m&&x.index<=g){const U=Os(x.cells,h,p);if(U==null)continue;const[F,V]=U,H={startX:M+F.left+N,startY:b+x.top,endX:M+V.left+V.pageWidth+N,endY:b+x.top+x.height};n.push(Qn(H))}this._liquid.translateRestore(),this._liquid.restorePagePadding(R),this._liquid.translatePage(R,f,S,E)}return{pointGroup:n,startRow:m,startColumn:h,endRow:g,endColumn:p,tableId:u}}getNodePositionGroup(t,e){const n=[],i=this._docSkeleton.findCharIndexByPosition(t),s=this._docSkeleton.findCharIndexByPosition(e);if(i==null||s==null)return;const r=i<s,c=this._getTableRectRangeInfo(t,e);if(c==null)return;const{tableId:l,startRowIndex:A,startColumnIndex:d,endRowIndex:u,endColumnIndex:m}=c,h=this._docSkeleton.getViewModel().findTableNodeById(l);if(h==null)return;const g=h.children[0].children.length;if(d===0&&m===g-1){const f=h.children[A].children[d],S=this._docSkeleton.findNodePositionByCharIndex(f.startIndex+1),E=h.children[u].children[m],C=this._docSkeleton.findNodePositionByCharIndex(E.endIndex-2);if(S==null||C==null)return;n.push({anchor:r?S:C,focus:r?C:S})}else for(let f=A;f<=u;f++){const S=h.children[f],E=S.children[d],C=S.children[m],T=this._docSkeleton.findNodePositionByCharIndex(E.startIndex+1),R=this._docSkeleton.findNodePositionByCharIndex(C.endIndex-2);if(T==null||R==null)return;n.push({anchor:r?T:R,focus:r?R:T})}return n}_getTableRectRangeInfo(t,e){const i=this._docSkeleton.getSkeletonData();if(i==null)return;const{pages:s}=i,{path:r}=t,{path:c}=e,l=_.getPageFromPath(i,r),A=_.getPageFromPath(i,c);if(l==null||A==null)return;const d=l.segmentId,u=l.parent.index,m=l.parent.cells.indexOf(l),h=(A==null?void 0:A.parent).index,g=(A==null?void 0:A.parent).cells.indexOf(A),p=Math.min(u,h),f=Math.max(u,h),S=Math.min(m,g),E=Math.max(m,g);return{pages:s,tableId:d,startRowIndex:p,startColumnIndex:S,endRowIndex:f,endColumnIndex:E}}}const Rs="__TestSelectionRange__",Ms="__TestSelectionAnchor__",Ii=6,Vn=500,xs=500,Ft=3;function At(o){const t=o[0],e=t[0],n=t[2],{x:i,y:s}=e,{x:r,y:c}=n;return{left:i,top:s,width:r-i,height:c-s}}function Ht(o){return o.map(t=>{let e=1/0,n=-1/0,i=1/0,s=-1/0;return t.forEach(r=>{e=Math.min(r.x,e),n=Math.max(r.x,n),s=Math.max(r.y,s),i=Math.min(r.y,i)}),{left:e,right:n,top:i,bottom:s}})}class He{constructor(t,e,n,i,s,r=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,c="",l=-1){B(this,"rangeType",a.DOC_RANGE_TYPE.TEXT);B(this,"_current",!1);B(this,"_rangeShape");B(this,"_anchorShape");B(this,"_cursorList",[]);B(this,"_anchorBlinkTimer",null);this._scene=t,this._document=e,this._docSkeleton=n,this.anchorNodePosition=i,this.focusNodePosition=s,this.style=r,this._segmentId=c,this._segmentPage=l,this._anchorBlink(),this.refresh()}_anchorBlink(){setTimeout(()=>{this._anchorShape&&this._anchorShape.visible&&this.deactivateStatic()},Vn),this._anchorBlinkTimer=setInterval(()=>{this._anchorShape&&this._anchorShape.visible&&(this.activeStatic(),setTimeout(()=>{this.deactivateStatic()},Vn))},xs+Vn)}get startOffset(){var i;const{startOffset:t}=(i=Ln(this._cursorList))!=null?i:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const n=e.dataStream.length-2;return Math.min(n,t)}get endOffset(){var i;const{endOffset:t}=(i=Ln(this._cursorList))!=null?i:{},e=this._docSkeleton.getViewModel().getDataModel().getSelfOrHeaderFooterModel(this._segmentId).getBody();if(t==null||e==null)return t;const n=e.dataStream.length-2;return Math.min(t,n)}get collapsed(){const{startOffset:t,endOffset:e}=this;return t!=null&&t===e}get startNodePosition(){if(this.anchorNodePosition==null)return null;if(this.focusNodePosition==null)return this.anchorNodePosition;const{start:t}=Un(this.anchorNodePosition,this.focusNodePosition);return t}get endNodePosition(){if(this.anchorNodePosition==null)return this.focusNodePosition;if(this.focusNodePosition==null)return null;const{end:t}=Un(this.anchorNodePosition,this.focusNodePosition);return t}get direction(){const{collapsed:t,anchorNodePosition:e,focusNodePosition:n}=this;return t||e==null||n==null?a.RANGE_DIRECTION.NONE:wn(e,n)?a.RANGE_DIRECTION.FORWARD:a.RANGE_DIRECTION.BACKWARD}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}getAbsolutePosition(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(this._isEmpty())return;const n=this._document.getOffsetConfig(),{docsLeft:i,docsTop:s}=n,r=new ve(n,this._docSkeleton);if(this._isCollapsed()){const{contentBoxPointGroup:d,cursorList:u}=r.getRangePointData(t,t);if(this._setCursorList(u),d.length===0)return;const m=At(d);return{...m,left:m.left+i,top:m.top+s}}const{borderBoxPointGroup:c,cursorList:l}=r.getRangePointData(t,e);if(this._setCursorList(l),c.length===0)return;const A=At(c);return{...A,left:A.left+i,top:A.top+s}}getAnchor(){return this._anchorShape}activeStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.strokeActive)||_.getColor(a.COLORS.black,1)})}deactivateStatic(){var t,e;(e=this._anchorShape)==null||e.setProps({stroke:((t=this.style)==null?void 0:t.stroke)||_.getColor(a.COLORS.black,0)})}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t,e;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null,(e=this._anchorShape)==null||e.dispose(),this._anchorShape=null,this._anchorBlinkTimer&&(clearInterval(this._anchorBlinkTimer),this._anchorBlinkTimer=null)}isIntersection(t){const{startOffset:e,endOffset:n}=this,{startOffset:i,endOffset:s}=t;return e==null||n==null||i==null||s==null?!1:e<=s&&n>=i}refresh(){var u,m;const{_document:t,_docSkeleton:e}=this,n=this.anchorNodePosition,i=this.focusNodePosition;if((u=this._anchorShape)==null||u.hide(),(m=this._rangeShape)==null||m.hide(),this._isEmpty())return;const s=t.getOffsetConfig(),{docsLeft:r,docsTop:c}=s,l=new ve(s,e);if(this._isCollapsed()){const{contentBoxPointGroup:h,cursorList:g}=l.getRangePointData(n,n);if(this._setCursorList(g),h.length>0){const p=e.findGlyphByPosition(n);this._createOrUpdateAnchor(h,r,c,p)}return}const{borderBoxPointGroup:A,cursorList:d}=l.getRangePointData(n,i);this._setCursorList(d),A.length>0&&this._createOrUpdateRange(A,r,c)}_isEmpty(){return this.anchorNodePosition==null&&this.focusNodePosition==null}_isCollapsed(){const t=this.anchorNodePosition,e=this.focusNodePosition;if(t!=null&&e==null)return!0;if(t==null||e==null)return!1;const n=Object.keys(Ye);for(const i of n){const s=t[i],r=e[i];if(s!==r)return!1}return t.isBack===e.isBack}_createOrUpdateRange(t,e,n){var r;if(this._rangeShape){this._rangeShape.translate(e,n),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const i=.3,s=new _.RegularPolygon(Rs+a.Tools.generateRandomId(Ii),{pointsGroup:t,fill:((r=this.style)==null?void 0:r.fill)||_.getColor(a.COLORS.black,i),left:e,top:n,evented:!1,debounceParentDirty:!1});this._rangeShape=s,this._scene.addObject(s,Ft)}_createOrUpdateAnchor(t,e,n,i){var p,f,S;const s=At(t),{left:r}=s;let{top:c,height:l}=s;const A=14;l<A&&(c-=A-l,l=A);const d=12;let u=r+e;const m=c+n,h=((p=i==null?void 0:i.ts)==null?void 0:p.it)===a.BooleanNumber.TRUE;if(h&&(u+=l*Math.tan(d*Math.PI/180)/2),this._anchorShape){this._anchorShape.transformByState({left:u,top:m,height:l}),this._anchorShape.show(),h?this._anchorShape.skew(-12,0):this._anchorShape.skew(0,0);return}const g=new _.Rect(Ms+a.generateRandomId(Ii),{left:u,top:m,height:l,strokeWidth:((f=this.style)==null?void 0:f.strokeWidth)||1,stroke:((S=this.style)==null?void 0:S.strokeActive)||_.getColor(a.COLORS.black,1),evented:!1});h&&g.skew(-12,0),this._anchorShape=g,this._scene.addObject(g,Ft),this.activeStatic()}_setCursorList(t){t.length!==0&&(this._cursorList=t)}}const Ds="__DocTableRectRange__",Bs=6;function kt(o,t,e,n,i,s=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,r="",c=-1){const l=t.getOffsetConfig(),d=new kn(l,e).getNodePositionGroup(n,i);return(d!=null?d:[]).map(u=>new Wn(o,t,e,u.anchor,u.focus,s,r,c))}class Wn{constructor(t,e,n,i,s,r=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,c="",l=-1){B(this,"rangeType",a.DOC_RANGE_TYPE.RECT);B(this,"_rangeShape");B(this,"_current",!1);B(this,"_startRow");B(this,"_startCol");B(this,"_endRow");B(this,"_endCol");B(this,"_tableId");this._scene=t,this._document=e,this._docSkeleton=n,this.anchorNodePosition=i,this.focusNodePosition=s,this.style=r,this._segmentId=c,this._segmentPage=l,this.refresh()}get startOffset(){const{startNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get endOffset(){const{endNodePosition:t}=this;return this._docSkeleton.findCharIndexByPosition(t)}get collapsed(){return!1}get startRow(){return this._startRow}get startColumn(){return this._startCol}get endRow(){return this._endRow}get endColumn(){return this._endCol}get tableId(){return this._tableId}get segmentId(){return this._segmentId}get segmentPage(){return this._segmentPage}get spanEntireRow(){var r;const e=(r=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:r[this._tableId],{_startCol:n,_endCol:i}=this;if(e==null)throw new Error("Table is not found.");const{tableColumns:s}=e;return n===0&&i===s.length-1}get spanEntireColumn(){var r;const e=(r=this._docSkeleton.getViewModel().getSnapshot().tableSource)==null?void 0:r[this._tableId],{_startRow:n,_endRow:i}=this;if(e==null)throw new Error("Table is not found.");const{tableRows:s}=e;return n===0&&i===s.length-1}get spanEntireTable(){return this.spanEntireRow&&this.spanEntireColumn}get startNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Hn(t,e)?t:e}get endNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Hn(t,e)?e:t}get direction(){const{anchorNodePosition:t,focusNodePosition:e}=this;return Hn(t,e)?a.RANGE_DIRECTION.FORWARD:a.RANGE_DIRECTION.BACKWARD}isActive(){return this._current===!0}activate(){this._current=!0}deactivate(){this._current=!1}dispose(){var t;(t=this._rangeShape)==null||t.dispose(),this._rangeShape=null}isIntersection(t){const{startRow:e,startColumn:n,endRow:i,endColumn:s}=this,{startRow:r,startColumn:c,endRow:l,endColumn:A}=t,d={left:n,top:e,right:s,bottom:i},u={left:c,top:r,right:A,bottom:l};return a.Rectangle.hasIntersectionBetweenTwoRect(d,u)}refresh(){var f;(f=this._rangeShape)==null||f.hide();const{startNodePosition:t,endNodePosition:e,_document:n,_docSkeleton:i}=this,s=n.getOffsetConfig(),{docsLeft:r,docsTop:c}=s,A=new kn(s,i).getRangePointData(t,e);if(A==null)return;const{pointGroup:d=[],startRow:u,endRow:m,startColumn:h,endColumn:g,tableId:p}=A;(d==null?void 0:d.length)>0&&this._createOrUpdateRange(d,r,c),this._updateTableInfo(u,m,h,g,p)}_updateTableInfo(t,e,n,i,s){this._startRow=t,this._endRow=e,this._startCol=n,this._endCol=i,this._tableId=s}_createOrUpdateRange(t,e,n){var r;if(this._rangeShape){this._rangeShape.translate(e,n),this._rangeShape.updatePointGroup(t),this._rangeShape.show();return}const i=.3,s=new _.RegularPolygon(Ds+a.Tools.generateRandomId(Bs),{pointsGroup:t,fill:((r=this.style)==null?void 0:r.fill)||_.getColor(a.COLORS.black,i),left:e,top:n,evented:!1,debounceParentDirty:!1});this._rangeShape=s,this._scene.addObject(s,Ft)}}function vi(o,t,e,n,i,s,r,c,l=!0,A=!0){const d=i.findNodePositionByCharIndex(o,l,r,c),u=i.findNodePositionByCharIndex(t,A,r,c);if(!(d==null||u==null))return new He(e,n,i,d,u,s,r,c)}function _s(o,t,e,n,i,s,r,c){const l=i.findNodePositionByCharIndex(o,!0,r,c),A=i.findNodePositionByCharIndex(t,!0,r,c);if(!(l==null||A==null))return new Wn(e,n,i,l,A,s,r,c)}function Ns(o,t,e,n,i,s,r,c){const l=i.findNodePositionByCharIndex(o,!0,r,c),A=i.findNodePositionByCharIndex(t,!0,r,c);if(!(l==null||A==null))return Gn(l,A,e,n,i,s,r,c)}function Gn(o,t,e,n,i,s,r,c){const l=[],A=[],d=[e,n,i,o,t,s,r,c];if(Si(i,o,t)){if(Fn(o,t))return l.push(new He(...d)),{textRanges:l,rectRanges:A};{const C=kt(...d);return A.push(...C),{textRanges:l,rectRanges:A}}}if(fi(o,t)){const C=kt(...d);return A.push(...C),{textRanges:l,rectRanges:A}}const u=i.getViewModel().getSelfOrHeaderFooterViewModel(r),m=i.findCharIndexByPosition(o),h=i.findCharIndexByPosition(t);if(m==null||h==null)return;const g=m<=h?a.RANGE_DIRECTION.FORWARD:a.RANGE_DIRECTION.BACKWARD,p=Math.min(m,h),f=Math.max(m,h);let S=p,E=f;for(const C of u.getChildren())for(const T of C.children){const{startIndex:R,endIndex:v,children:O}=T,M=C.children.indexOf(T),b=C.children[M+1],N=O[0];let x=!1;if(N){const{startIndex:U,endIndex:F,children:V}=N;let H=null,Q=null;const X=V.find(k=>k.startIndex<=p&&k.endIndex>=p),j=V.find(k=>k.startIndex<=f&&k.endIndex>=f);if(p>U&&p<F)H=i.findNodePositionByCharIndex(X.startIndex+2,!0,r,c),Q=i.findNodePositionByCharIndex(F-4,!0,r,c),S=F+1;else if(f>U&&f<F)H=i.findNodePositionByCharIndex(U+3,!0,r,c),Q=i.findNodePositionByCharIndex(j.endIndex-3,!0,r,c),E=U-1,x=!0;else if(U>p&&F<f){if(H=i.findNodePositionByCharIndex(U+3,!0,r,c),Q=i.findNodePositionByCharIndex(F-4,!0,r,c),S<=U-1){const k=i.findNodePositionByCharIndex(S,!0,r,c),W=i.findNodePositionByCharIndex(U-1,!1,r,c),G=g===a.RANGE_DIRECTION.FORWARD?k:W,K=g===a.RANGE_DIRECTION.FORWARD?W:k;l.push(new He(e,n,i,G,K,s,r,c))}S=F+1}if(H&&Q){const k=g===a.RANGE_DIRECTION.FORWARD?H:Q,W=g===a.RANGE_DIRECTION.FORWARD?Q:H;A.push(...kt(e,n,i,k,W,s,r,c))}}if(E===v+1&&!x&&b&&b.children.length&&(E=v,x=!0),E>=R&&E<=v||x){const U=i.findNodePositionByCharIndex(S,!0,r,c),F=i.findNodePositionByCharIndex(E,!x,r,c),V=g===a.RANGE_DIRECTION.FORWARD?U:F,H=g===a.RANGE_DIRECTION.FORWARD?F:U;if(A.length&&a.Tools.diffValue(V,H))continue;l.push(new He(e,n,i,V,H,s,r,c))}}return{textRanges:l,rectRanges:A}}function Ei(o){const t=o==null?void 0:o.getCanvasElement();if(!t)return{left:0,top:0};const{top:e,left:n}=_.getOffsetRectForDom(t);return{left:n,top:e}}function Ci(o){var l;const t=(l=o.parent)==null?void 0:l.parent,e=t==null?void 0:t.parent;if(t==null||e==null)return;const{paragraphIndex:n}=t,i=e.lines.filter(A=>A.paragraphIndex===n);let s=-1,r="",c=!1;for(const A of i)for(const d of A.divides)for(const u of d.glyphGroup)c||(s+=u.count),u===o&&(c=!0),r+=u.count>0?u.content:"";return{st:i[0].st,ed:n,content:r,nodeIndex:s}}function jn(o){const{startOffset:t,endOffset:e,collapsed:n,rangeType:i,startNodePosition:s,endNodePosition:r,direction:c,segmentId:l,segmentPage:A}=o;return{startOffset:t,endOffset:e,collapsed:n,rangeType:i,startNodePosition:s,endNodePosition:r,direction:c,segmentId:l,segmentPage:A,isActive:o.isActive()}}function Ps(o){const t=jn(o),{startRow:e,startColumn:n,endRow:i,endColumn:s,tableId:r,spanEntireRow:c,spanEntireColumn:l,spanEntireTable:A}=o;return{...t,startRow:e,startColumn:n,endRow:i,endColumn:s,tableId:r,spanEntireRow:c,spanEntireColumn:l,spanEntireTable:A}}var ws=Object.getOwnPropertyDescriptor,Us=(o,t,e,n)=>{for(var i=n>1?void 0:n?ws(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Vt=(o,t)=>(e,n)=>t(e,n,o);y.DocSelectionRenderService=class extends a.RxDisposable{constructor(e,n,i,s,r){super();B(this,"_onInputBefore$",new L.Subject);B(this,"onInputBefore$",this._onInputBefore$.asObservable());B(this,"_onKeydown$",new L.Subject);B(this,"onKeydown$",this._onKeydown$.asObservable());B(this,"_onInput$",new L.Subject);B(this,"onInput$",this._onInput$.asObservable());B(this,"_onCompositionstart$",new L.BehaviorSubject(null));B(this,"onCompositionstart$",this._onCompositionstart$.asObservable());B(this,"_onCompositionupdate$",new L.BehaviorSubject(null));B(this,"onCompositionupdate$",this._onCompositionupdate$.asObservable());B(this,"_onCompositionend$",new L.BehaviorSubject(null));B(this,"onCompositionend$",this._onCompositionend$.asObservable());B(this,"_onSelectionStart$",new L.BehaviorSubject(null));B(this,"onSelectionStart$",this._onSelectionStart$.asObservable());B(this,"onChangeByEvent$",L.merge(this._onInput$,this._onKeydown$.pipe(L.filter(e=>e.event.keyCode===I.KeyCode.BACKSPACE)),this._onCompositionend$));B(this,"_onPaste$",new L.Subject);B(this,"onPaste$",this._onPaste$.asObservable());B(this,"_textSelectionInner$",new L.BehaviorSubject(null));B(this,"textSelectionInner$",this._textSelectionInner$.asObservable());B(this,"_onFocus$",new L.Subject);B(this,"onFocus$",this._onFocus$.asObservable());B(this,"_onBlur$",new L.Subject);B(this,"onBlur$",this._onBlur$.asObservable());B(this,"_onPointerDown$",new L.Subject);B(this,"onPointerDown$",this._onPointerDown$.asObservable());B(this,"_container");B(this,"_inputParent");B(this,"_input");B(this,"_scrollTimers",[]);B(this,"_rangeList",[]);B(this,"_rangeListCache",[]);B(this,"_rectRangeList",[]);B(this,"_rectRangeListCache",[]);B(this,"_anchorNodePosition",null);B(this,"_focusNodePosition",null);B(this,"_currentSegmentId","");B(this,"_currentSegmentPage",-1);B(this,"_selectionStyle",_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE);B(this,"_onPointerEvent",!1);B(this,"_viewPortObserverMap",new Map);B(this,"_isIMEInputApply",!1);B(this,"_scenePointerMoveSubs",[]);B(this,"_scenePointerUpSubs",[]);B(this,"_reserveRanges",!1);this._context=e,this._layoutService=n,this._logService=i,this._univerInstanceService=s,this._docSkeletonManagerService=r,this._initDOM(),this._registerContainer(),this._setSystemHighlightColorToStyle(),this._listenCurrentUnitChange()}get isOnPointerEvent(){return this._onPointerEvent}get isFocusing(){return this._input===document.activeElement}get canFocusing(){return this.isFocusing||document.activeElement===document.body||document.activeElement===null}_listenCurrentUnitChange(){this._univerInstanceService.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC).pipe(L.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;e.getUnitId()!==this._context.unitId&&!this._reserveRanges&&this.removeAllRanges()})}get activeViewPort(){return this._context.scene.getViewports()[0]}setSegment(e){this._currentSegmentId=e}getSegment(){return this._currentSegmentId}setSegmentPage(e){this._currentSegmentPage=e}getSegmentPage(){return this._currentSegmentPage}setReserveRangesStatus(e){this._reserveRanges=e}_setRangeStyle(e=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE){this._selectionStyle=e}addDocRanges(e,n=!0,i){const{_currentSegmentId:s,_currentSegmentPage:r,_selectionStyle:c}=this,{scene:l,mainComponent:A}=this._context,d=A,u=this._docSkeletonManagerService.getSkeleton(),m=(h,g)=>{const p=Ns(h,g,l,d,u,c,s,r);if(p==null)return;const{textRanges:f,rectRanges:S}=p;for(const E of f)this._addTextRange(E);this._addRectRanges(S)};for(const h of e){const{startOffset:g,endOffset:p,rangeType:f,startNodePosition:S,endNodePosition:E}=h;if(f===a.DOC_RANGE_TYPE.RECT){const C=_s(g,p,l,d,u,c,s,r);C&&this._addRectRanges([C])}else if(f===a.DOC_RANGE_TYPE.TEXT)try{let C=null;S&&E?C=vi(S.isBack?g:g-1,E.isBack?p:p-1,l,d,u,c,s,r,S.isBack,E.isBack):C=vi(g,p,l,d,u,c,s,r),C&&this._addTextRange(C)}catch{m(g,p)}else m(g,p)}this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:s,segmentPage:r,style:c,isEditing:n,options:i}),!(!e.length||(i==null?void 0:i.shouldFocus)===!1)&&this._updateInputPosition(i==null?void 0:i.forceFocus)}setCursorManually(e,n){const i=this._findNodeByCoord(e,n,{strict:!0,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),s=this._getNodePosition(i);if(s==null){this._removeAllRanges();return}(i==null?void 0:i.node.streamType)===a.DataStreamTreeTokenType.PARAGRAPH&&(s.isBack=!0),this._createTextRangeByAnchorPosition(s),this._textSelectionInner$.next({textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1})}sync(){this._updateInputPosition()}activate(e,n,i=!1){this._container.style.left=`${e}px`,this._container.style.top=`${n}px`,this._container.style.zIndex="1000",(this.canFocusing||i)&&this.focus()}hasFocus(){return document.activeElement===this._input}focus(){this._input.focus()}blur(){this._input.blur()}deactivate(){this._container.style.left="0px",this._container.style.top="0px"}__handleDblClick(e){const{offsetX:n,offsetY:i}=e,s=this._findNodeByCoord(n,i,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(s==null||s.node==null)return;const r=Ci(s.node);if(r==null)return;const{content:c,st:l,nodeIndex:A}=r;if(A===-1||Intl.Segmenter==null)return;const u=new Intl.Segmenter(void 0,{granularity:"word"}).segment(c);let m=Number.NEGATIVE_INFINITY,h=Number.NEGATIVE_INFINITY;for(const{segment:g,index:p,isWordLike:f}of u)if(p<=A&&A<p+g.length&&f){m=p+l,h=p+l+g.length;break}if(Number.isFinite(m)&&Number.isFinite(h)){this.removeAllRanges();const g=[{startOffset:m,endOffset:h}];this.addDocRanges(g,!1,{forceFocus:!0})}}__handleTripleClick(e){const{offsetX:n,offsetY:i}=e,s=this._findNodeByCoord(n,i,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage});if(s==null||s.node==null)return;const r=Ci(s.node);if(r==null)return;this.removeAllRanges();const{st:c,ed:l}=r,A=[{startOffset:c,endOffset:l}];this.addDocRanges(A,!1,{forceFocus:!0})}__onPointDown(e){var f,S;const{scene:n,mainComponent:i}=this._context,s=this._docSkeletonManagerService.getSkeleton(),{offsetX:r,offsetY:c}=e,l=this._findNodeByCoord(r,c,{strict:!1,segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage}),A=this._getNodePosition(l);if(A==null||l==null){this._removeAllRanges();return}(l==null?void 0:l.node.streamType)===a.DataStreamTreeTokenType.PARAGRAPH&&(A.isBack=!0);const d=this._textSelectionInner$.value;if(l&&e.button===2&&d){const E=s.findCharIndexByPosition(A);if(typeof E=="number"&&d.textRanges.some(C=>C.startOffset<=E&&C.endOffset>E)||typeof E=="number"&&d.rectRanges.some(C=>C.startOffset<=E&&C.endOffset>=E))return}const{segmentId:u,segmentPage:m}=l;u&&this._currentSegmentId&&u!==this._currentSegmentId&&this.setSegment(u),u&&m!==this._currentSegmentPage&&this.setSegmentPage(m),this._anchorNodePosition=A,e.shiftKey&&this._getActiveRangeInstance()?this._updateActiveRangePosition(A):e.ctrlKey?this._removeAllCollapsedTextRanges():this._isEmpty()||this._removeAllRanges(),n.disableObjectsEvent();const h=_.ScrollTimer.create(n);this._scrollTimers.push(h),h.startScroll(r,c),this._onSelectionStart$.next((f=this._getActiveRangeInstance())==null?void 0:f.startNodePosition),(S=n.getTransformer())==null||S.clearSelectedObjects();let g=r,p=c;this._onPointerEvent=!0,this._scenePointerMoveSubs.push(n.onPointerMove$.subscribeEvent(E=>{const{offsetX:C,offsetY:T}=E;n.setCursor(_.CURSOR_TYPE.TEXT),!(Math.sqrt((C-g)**2+(T-p)**2)<3)&&(this._moving(C,T),h.scrolling(C,T,()=>{this._moving(C,T)}),g=C,p=T)})),this._scenePointerUpSubs.push(n.onPointerUp$.subscribeEvent(()=>{if([...this._scenePointerMoveSubs,...this._scenePointerUpSubs].forEach(C=>{C.unsubscribe()}),this._onPointerEvent=!1,n.enableObjectsEvent(),this._anchorNodePosition&&!this._focusNodePosition){if(e.ctrlKey){this._disposeScrollTimers();return}const C=new He(n,i,s,this._anchorNodePosition,void 0,this._selectionStyle,this._currentSegmentId,this._currentSegmentPage);this._addTextRange(C)}else if(this._anchorNodePosition&&this._focusNodePosition){for(const C of this._rangeListCache)e.ctrlKey?C.collapsed?C.dispose():this._addTextRange(C):this._addTextRange(C);this._addRectRanges(this._rectRangeListCache),this._rangeListCache=[],this._rectRangeListCache=[]}this._anchorNodePosition=null,this._focusNodePosition=null;const E={textRanges:this._getAllTextRanges(),rectRanges:this._getAllRectRanges(),segmentId:this._currentSegmentId,segmentPage:this._currentSegmentPage,style:this._selectionStyle,isEditing:!1};this._textSelectionInner$.next(E),this._disposeScrollTimers(),this._updateInputPosition(!0)}))}removeAllRanges(){this._removeAllRanges(),this.deactivate()}getActiveTextRange(){return this._getActiveRangeInstance()}_disposeScrollTimers(){this._scrollTimers.forEach(e=>{e==null||e.dispose()}),this._scrollTimers=[]}_setSystemHighlightColorToStyle(){const{r:e,g:n,b:i,a:s}=_.getSystemHighlightColor(),r={strokeWidth:1,stroke:"rgba(0, 0, 0, 0)",strokeActive:"rgba(0, 0, 0, 1)",fill:`rgba(${e}, ${n}, ${i}, ${s!=null?s:.3})`};this._setRangeStyle(r)}_getAllTextRanges(){return this._rangeList.map(jn)}_getAllRectRanges(){return this._rectRangeList.map(Ps)}getAllTextRanges(){return this._getAllTextRanges()}getAllRectRanges(){return this._getAllRectRanges()}_getActiveRange(){const e=this._rangeList.find(s=>s.isActive());if(e==null)return null;const{startOffset:n,endOffset:i}=e;return n==null||i==null?null:jn(e)}_getActiveRangeInstance(){return this._rangeList.find(e=>e.isActive())}dispose(){super.dispose(),this._detachEvent(),this._removeAllRanges(),this._container.remove()}_initDOM(){const{unitId:e}=this._context,n=document.createElement("div");n.style.position="fixed",n.style.left="0px",n.style.top="0px",n.id=`univer-doc-selection-container-${e}`;const i=document.createElement("div"),s=document.createElement("div");i.appendChild(s),n.appendChild(i),this._container=n,this._inputParent=i,this._input=s,this._initInput(),this._initInputEvents(),document.body.appendChild(n)}_registerContainer(){this.disposeWithMe(this._layoutService.registerContainerElement(this._container))}_initInput(){this._inputParent.style.cssText=`
37
37
  position:absolute;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/preset-docs-core",
3
- "version": "0.8.0-nightly.202506011606",
3
+ "version": "0.8.0-nightly.202506031608",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -57,16 +57,16 @@
57
57
  "rxjs": ">=7.0.0"
58
58
  },
59
59
  "dependencies": {
60
- "@univerjs/design": "0.8.0-nightly.202506011606",
61
- "@univerjs/docs": "0.8.0-nightly.202506011606",
62
- "@univerjs/docs-ui": "0.8.0-nightly.202506011606",
63
- "@univerjs/engine-formula": "0.8.0-nightly.202506011606",
64
- "@univerjs/engine-render": "0.8.0-nightly.202506011606",
65
- "@univerjs/network": "0.8.0-nightly.202506011606",
66
- "@univerjs/ui": "0.8.0-nightly.202506011606"
60
+ "@univerjs/design": "0.8.0-nightly.202506031608",
61
+ "@univerjs/docs": "0.8.0-nightly.202506031608",
62
+ "@univerjs/docs-ui": "0.8.0-nightly.202506031608",
63
+ "@univerjs/engine-formula": "0.8.0-nightly.202506031608",
64
+ "@univerjs/engine-render": "0.8.0-nightly.202506031608",
65
+ "@univerjs/network": "0.8.0-nightly.202506031608",
66
+ "@univerjs/ui": "0.8.0-nightly.202506031608"
67
67
  },
68
68
  "devDependencies": {
69
- "@univerjs/core": "0.8.0-nightly.202506011606",
69
+ "@univerjs/core": "0.8.0-nightly.202506031608",
70
70
  "react": "18.3.1",
71
71
  "react-dom": "18.3.1",
72
72
  "rxjs": "7.8.2",