@univerjs/docs-ui 0.9.3 → 0.9.4-nightly.202507290757
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/lib/cjs/index.js +2 -2
- package/lib/es/index.js +99 -107
- package/lib/index.js +99 -107
- package/lib/umd/index.js +2 -2
- package/package.json +10 -10
- package/LICENSE +0 -176
package/lib/umd/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(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("@univerjs/drawing"),require("rxjs"),require("rxjs/operators"),require("react/jsx-runtime"),require("react"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs","@univerjs/engine-render","@univerjs/ui","@univerjs/drawing","rxjs","rxjs/operators","react/jsx-runtime","react","@univerjs/design"],a):(y=typeof globalThis<"u"?globalThis:y||self,a(y.UniverDocsUi={},y.UniverCore,y.UniverDocs,y.UniverEngineRender,y.UniverUi,y.UniverDrawing,y.rxjs,y.rxjs.operators,y.React,y.React,y.UniverDesign))})(this,function(y,a,D,_,I,xn,L,dt,P,w,J){"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}}const He={id:"doc.command.tab",type:a.CommandType.COMMAND,async handler(o,t){const n=o.get(y.DocAutoFormatService).onAutoFormat(He.id,t);return(await a.sequenceExecuteAsync(n,o.get(a.ICommandService))).result}},At={id:"doc.command.after-space",type:a.CommandType.COMMAND,async handler(o){const e=o.get(y.DocAutoFormatService).onAutoFormat(At.id);return(await a.sequenceExecuteAsync(e,o.get(a.ICommandService))).result}},Ye={id:"doc.command.enter",type:a.CommandType.COMMAND,async handler(o){const e=o.get(y.DocAutoFormatService).onAutoFormat(Ye.id);return(await a.sequenceExecuteAsync(e,o.get(a.ICommandService))).result}};var ys=Object.getOwnPropertyDescriptor,bs=(o,t,e,n)=>{for(var i=n>1?void 0:n?ys(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Nn=(o,t)=>(e,n)=>t(e,n,o);const Os=11,Rs=9,Qt={ff:"Arial",fs:Os};let ve=class extends a.Disposable{constructor(t,e,n){super();B(this,"_cacheStyle",null);this._textSelectionManagerService=t,this._univerInstanceService=e,this._renderManagerService=n,this._init()}_init(){this._listenDocRangeChange()}_listenDocRangeChange(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(()=>{this._clearStyleCache()}))}getStyleCache(){return this._cacheStyle}getDefaultStyle(){var r;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(t==null)return{...Qt};const e=t==null?void 0:t.getUnitId(),n=(r=this._renderManagerService.getRenderById(e))==null?void 0:r.with(D.DocSkeletonManagerService),i=n==null?void 0:n.getViewModel();return i==null?{...Qt}:i.getEditArea()===_.DocumentEditArea.BODY?{...Qt}:{...Qt,fs:Rs}}setStyleCache(t){this._cacheStyle={...this._cacheStyle,...t}}_clearStyleCache(){this._cacheStyle=null}};ve=bs([Nn(0,a.Inject(D.DocSelectionManagerService)),Nn(1,a.IUniverInstanceService),Nn(2,_.IRenderManagerService)],ve);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")}function Pn(o,t,e){const n=[];for(let i=0,s=o.length;i<s;i++)o[i]===a.DataStreamTreeTokenType.PARAGRAPH&&n.push({startIndex:i});if(t)for(const i of n)t.bullet&&(i.bullet=a.Tools.deepClone(t.bullet)),t.paragraphStyle&&(i.paragraphStyle=a.Tools.deepClone(t.paragraphStyle),delete i.paragraphStyle.borderBottom,t.paragraphStyle.headingId&&(i.paragraphStyle.headingId=a.generateRandomId(6)));if(e)for(const i of n)i.paragraphStyle||(i.paragraphStyle={}),i.paragraphStyle.borderBottom=e;return n}const Ft={id:"doc.command.break-line",type:a.CommandType.COMMAND,handler:(o,t)=>{var Q,X,j,k,W;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=o.get(ve),r=(Q=t==null?void 0:t.textRange)!=null?Q:e.getActiveTextRange(),c=e.getRectRanges();if(r==null)return!1;if(c&&c.length){const{startOffset:G}=r;return e.replaceDocRanges([{startOffset:G,endOffset:G}]),!0}const{horizontalLine:l}=t!=null?t:{},{segmentId:A}=r,d=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A!=null?A:"").getBody();if(d==null||u==null)return!1;const m=d.getUnitId(),{startOffset:h,endOffset:g}=r,f=((X=u.paragraphs)!=null?X:[]).find(G=>G.startIndex>=h);if(!f)return!1;const S=h===f.startIndex,E=f.startIndex,C=s.getDefaultStyle(),T=s.getStyleCache(),R=Lt(u,g,C,T),v={dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Pn(a.DataStreamTreeTokenType.PARAGRAPH,f,l),textRuns:[{st:0,ed:1,ts:{...R.ts}}]};if(d==null)return!1;const O=e.getActiveTextRange();if(u==null)return!1;const{collapsed:M}=r,b=v.dataStream.length,N=[{startOffset:h+b,endOffset:h+b,style:O==null?void 0:O.style,collapsed:M}],x={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:N,debounce:!0}},U=new a.TextX,F=a.JSONX.getInstance();if(M)h>0&&U.push({t:a.TextXActionType.RETAIN,len:h}),U.push({t:a.TextXActionType.INSERT,body:v,len:v.dataStream.length});else{const G=a.BuildTextUtils.selection.delete([r],u,0,v);U.push(...G)}(((j=f.bullet)==null?void 0:j.listType)===a.PresetListType.CHECK_LIST_CHECKED||(k=f.paragraphStyle)!=null&&k.headingId)&&(r.endOffset<E&&U.push({t:a.TextXActionType.RETAIN,len:E-r.endOffset}),U.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...f,paragraphStyle:{...f.paragraphStyle,...S?{headingId:void 0,namedStyleType:void 0}:null},startIndex:0,bullet:(W=f.paragraphStyle)!=null&&W.headingId?void 0:{...f.bullet,listType:a.PresetListType.CHECK_LIST}}]},coverType:a.UpdateDocsAttributeType.REPLACE})),x.params.textRanges=[{startOffset:h+b,endOffset:h+b,collapsed:M}];const V=Z(d,A);return x.params.actions=F.editOp(U.serialize(),V),!!i.syncExecuteCommand(x.id,x.params)}};var Ht=(o=>(o[o.ABOVE=0]="ABOVE",o[o.BELLOW=1]="BELLOW",o))(Ht||{}),wn=(o=>(o[o.LEFT=0]="LEFT",o[o.RIGHT=1]="RIGHT",o))(wn||{});function Ms(o,t){let e=a.DataStreamTreeTokenType.TABLE_START;const n=[],i=[];for(let s=0;s<o;s++){e+=a.DataStreamTreeTokenType.TABLE_ROW_START;for(let r=0;r<t;r++)e+=`${a.DataStreamTreeTokenType.TABLE_CELL_START}\r
|
|
1
|
+
(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("@univerjs/drawing"),require("rxjs"),require("rxjs/operators"),require("react/jsx-runtime"),require("react"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs","@univerjs/engine-render","@univerjs/ui","@univerjs/drawing","rxjs","rxjs/operators","react/jsx-runtime","react","@univerjs/design"],a):(y=typeof globalThis<"u"?globalThis:y||self,a(y.UniverDocsUi={},y.UniverCore,y.UniverDocs,y.UniverEngineRender,y.UniverUi,y.UniverDrawing,y.rxjs,y.rxjs.operators,y.React,y.React,y.UniverDesign))})(this,function(y,a,D,_,I,xn,L,dt,P,w,J){"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.getCurrentUnitOfType(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}}const He={id:"doc.command.tab",type:a.CommandType.COMMAND,async handler(o,t){const n=o.get(y.DocAutoFormatService).onAutoFormat(He.id,t);return(await a.sequenceExecuteAsync(n,o.get(a.ICommandService))).result}},At={id:"doc.command.after-space",type:a.CommandType.COMMAND,async handler(o){const e=o.get(y.DocAutoFormatService).onAutoFormat(At.id);return(await a.sequenceExecuteAsync(e,o.get(a.ICommandService))).result}},Ye={id:"doc.command.enter",type:a.CommandType.COMMAND,async handler(o){const e=o.get(y.DocAutoFormatService).onAutoFormat(Ye.id);return(await a.sequenceExecuteAsync(e,o.get(a.ICommandService))).result}};var ys=Object.getOwnPropertyDescriptor,bs=(o,t,e,n)=>{for(var i=n>1?void 0:n?ys(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},Nn=(o,t)=>(e,n)=>t(e,n,o);const Os=11,Rs=9,Qt={ff:"Arial",fs:Os};let ve=class extends a.Disposable{constructor(t,e,n){super();B(this,"_cacheStyle",null);this._textSelectionManagerService=t,this._univerInstanceService=e,this._renderManagerService=n,this._init()}_init(){this._listenDocRangeChange()}_listenDocRangeChange(){this.disposeWithMe(this._textSelectionManagerService.textSelection$.subscribe(()=>{this._clearStyleCache()}))}getStyleCache(){return this._cacheStyle}getDefaultStyle(){var r;const t=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(t==null)return{...Qt};const e=t==null?void 0:t.getUnitId(),n=(r=this._renderManagerService.getRenderById(e))==null?void 0:r.with(D.DocSkeletonManagerService),i=n==null?void 0:n.getViewModel();return i==null?{...Qt}:i.getEditArea()===_.DocumentEditArea.BODY?{...Qt}:{...Qt,fs:Rs}}setStyleCache(t){this._cacheStyle={...this._cacheStyle,...t}}_clearStyleCache(){this._cacheStyle=null}};ve=bs([Nn(0,a.Inject(D.DocSelectionManagerService)),Nn(1,a.IUniverInstanceService),Nn(2,_.IRenderManagerService)],ve);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")}function Pn(o,t,e){const n=[];for(let i=0,s=o.length;i<s;i++)o[i]===a.DataStreamTreeTokenType.PARAGRAPH&&n.push({startIndex:i});if(t)for(const i of n)t.bullet&&(i.bullet=a.Tools.deepClone(t.bullet)),t.paragraphStyle&&(i.paragraphStyle=a.Tools.deepClone(t.paragraphStyle),delete i.paragraphStyle.borderBottom,t.paragraphStyle.headingId&&(i.paragraphStyle.headingId=a.generateRandomId(6)));if(e)for(const i of n)i.paragraphStyle||(i.paragraphStyle={}),i.paragraphStyle.borderBottom=e;return n}const Ft={id:"doc.command.break-line",type:a.CommandType.COMMAND,handler:(o,t)=>{var Q,X,j,k,W;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=o.get(ve),r=(Q=t==null?void 0:t.textRange)!=null?Q:e.getActiveTextRange(),c=e.getRectRanges();if(r==null)return!1;if(c&&c.length){const{startOffset:G}=r;return e.replaceDocRanges([{startOffset:G,endOffset:G}]),!0}const{horizontalLine:l}=t!=null?t:{},{segmentId:A}=r,d=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),u=d==null?void 0:d.getSelfOrHeaderFooterModel(A!=null?A:"").getBody();if(d==null||u==null)return!1;const m=d.getUnitId(),{startOffset:h,endOffset:g}=r,f=((X=u.paragraphs)!=null?X:[]).find(G=>G.startIndex>=h);if(!f)return!1;const S=h===f.startIndex,E=f.startIndex,C=s.getDefaultStyle(),T=s.getStyleCache(),R=Lt(u,g,C,T),v={dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Pn(a.DataStreamTreeTokenType.PARAGRAPH,f,l),textRuns:[{st:0,ed:1,ts:{...R.ts}}]};if(d==null)return!1;const O=e.getActiveTextRange();if(u==null)return!1;const{collapsed:M}=r,b=v.dataStream.length,N=[{startOffset:h+b,endOffset:h+b,style:O==null?void 0:O.style,collapsed:M}],x={id:D.RichTextEditingMutation.id,params:{unitId:m,actions:[],textRanges:N,debounce:!0}},U=new a.TextX,F=a.JSONX.getInstance();if(M)h>0&&U.push({t:a.TextXActionType.RETAIN,len:h}),U.push({t:a.TextXActionType.INSERT,body:v,len:v.dataStream.length});else{const G=a.BuildTextUtils.selection.delete([r],u,0,v);U.push(...G)}(((j=f.bullet)==null?void 0:j.listType)===a.PresetListType.CHECK_LIST_CHECKED||(k=f.paragraphStyle)!=null&&k.headingId)&&(r.endOffset<E&&U.push({t:a.TextXActionType.RETAIN,len:E-r.endOffset}),U.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...f,paragraphStyle:{...f.paragraphStyle,...S?{headingId:void 0,namedStyleType:void 0}:null},startIndex:0,bullet:(W=f.paragraphStyle)!=null&&W.headingId?void 0:{...f.bullet,listType:a.PresetListType.CHECK_LIST}}]},coverType:a.UpdateDocsAttributeType.REPLACE})),x.params.textRanges=[{startOffset:h+b,endOffset:h+b,collapsed:M}];const V=Z(d,A);return x.params.actions=F.editOp(U.serialize(),V),!!i.syncExecuteCommand(x.id,x.params)}};var Ht=(o=>(o[o.ABOVE=0]="ABOVE",o[o.BELLOW=1]="BELLOW",o))(Ht||{}),wn=(o=>(o[o.LEFT=0]="LEFT",o[o.RIGHT=1]="RIGHT",o))(wn||{});function Ms(o,t){let e=a.DataStreamTreeTokenType.TABLE_START;const n=[],i=[];for(let s=0;s<o;s++){e+=a.DataStreamTreeTokenType.TABLE_ROW_START;for(let r=0;r<t;r++)e+=`${a.DataStreamTreeTokenType.TABLE_CELL_START}\r
|
|
2
2
|
${a.DataStreamTreeTokenType.TABLE_CELL_END}`,n.push({startIndex:e.length-3,paragraphStyle:{spaceAbove:{v:3},lineSpacing:2,spaceBelow:{v:0}}}),i.push({startIndex:e.length-2});e+=a.DataStreamTreeTokenType.TABLE_ROW_END}return e+=a.DataStreamTreeTokenType.TABLE_END,{dataStream:e,paragraphs:n,sectionBreaks:i}}function kt(){return{margin:{start:{v:10},end:{v:10},top:{v:5},bottom:{v:5}}}}function Vt(o){const t=kt();return{tableCells:[...new Array(o).fill(null).map(()=>a.Tools.deepClone(t))],trHeight:{val:{v:30},hRule:a.TableRowHeightRule.AUTO}}}function Wt(o){return{size:{type:a.TableSizeType.SPECIFIED,width:{v:o}}}}function Un(o,t,e){const n=Wt(e/t),i=Vt(t),s=[...new Array(o).fill(null).map(()=>a.Tools.deepClone(i))],r=[...new Array(t).fill(null).map(()=>a.Tools.deepClone(n))],c=a.generateRandomId(6);return{tableRows:s,tableColumns:r,tableId:c,align:a.TableAlignmentType.START,indent:{v:0},textWrap:a.TableTextWrapType.NONE,position:{positionH:{relativeFrom:a.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:a.ObjectRelativeFromV.PAGE,posOffset:0}},dist:{distB:0,distL:0,distR:0,distT:0},cellMargin:{start:{v:10},end:{v:10},top:{v:5},bottom:{v:5}},size:{type:a.TableSizeType.UNSPECIFIED,width:{v:e}}}}function ut(o,t){if(!o&&!t)return null;if(t&&t.length>0){let e=Number.POSITIVE_INFINITY,n=Number.NEGATIVE_INFINITY;const i="";for(const s of t){const{startOffset:r,endOffset:c,segmentId:l}=s;r==null||c==null||l==null||(e=Math.min(e,r),n=Math.max(n,c))}if(Number.isFinite(e)&&Number.isFinite(n))return{startOffset:e,endOffset:n,segmentId:i}}else if(o){const{startOffset:e,endOffset:n,segmentId:i}=o;return e==null||n==null||i==null?null:{startOffset:e,endOffset:n,segmentId:i}}}function xs(o){let t=a.DataStreamTreeTokenType.TABLE_ROW_START;const e=[],n=[];for(let i=0;i<o;i++)t+=`${a.DataStreamTreeTokenType.TABLE_CELL_START}\r
|
|
3
3
|
${a.DataStreamTreeTokenType.TABLE_CELL_END}`,e.push({startIndex:t.length-3,paragraphStyle:{spaceAbove:{v:3},lineSpacing:2,spaceBelow:{v:0}}}),n.push({startIndex:t.length-2});return t+=a.DataStreamTreeTokenType.TABLE_ROW_END,{dataStream:t,paragraphs:e,sectionBreaks:n}}function Ds(){const o=`${a.DataStreamTreeTokenType.TABLE_CELL_START}\r
|
|
4
4
|
${a.DataStreamTreeTokenType.TABLE_CELL_END}`,t=[],e=[];return t.push({startIndex:1,paragraphStyle:{spaceAbove:{v:3},lineSpacing:2,spaceBelow:{v:0}}}),e.push({startIndex:2}),{dataStream:o,paragraphs:t,sectionBreaks:e}}function Bs(o,t,e){var u,m,h;const{startOffset:n,endOffset:i,segmentId:s}=o,r=e.getSelfOrHeaderFooterViewModel(s),c=t===0?n:i;let l=null;const A=(h=(m=(u=e.getBody())==null?void 0:u.tables)==null?void 0:m.find(g=>c>=g.startIndex&&c<=g.endIndex))==null?void 0:h.tableId;let d=0;for(const g of r.getChildren()){for(const p of g.children){const{children:f}=p,S=f[0];if(S){for(const E of S.children)if(E.startIndex<=c&&c<=E.endIndex){d=S.children.indexOf(E),l=E;break}}if(l)break}if(l)break}return l==null||A==null?null:{offset:t===0?l.startIndex:l.endIndex+1,colCount:l.children.length,tableId:A,insertRowIndex:t===0?d:d+1}}function _s(o,t,e){var h,g,p;const{startOffset:n,endOffset:i,segmentId:s}=o,r=e.getSelfOrHeaderFooterViewModel(s),c=t===0?n:i,l=(p=(g=(h=e.getBody())==null?void 0:h.tables)==null?void 0:g.find(f=>c>=f.startIndex&&c<=f.endIndex))==null?void 0:p.tableId,A=[];let d=null,u=-1;for(const f of r.getChildren()){for(const S of f.children){const{children:E}=S,C=E[0];if(C){if(c<C.startIndex||c>C.endIndex)continue;d=C;for(const T of C.children){for(const R of T.children){const v=T.children.indexOf(R);if(c>=R.startIndex&&c<=R.endIndex){u=v;break}}if(u!==-1)break}}if(d)break}if(d)break}if(d==null||l==null||u===-1)return null;let m=0;for(const f of d.children){const S=f.children[u],E=t===0?S.startIndex:S.endIndex+1;A.push(E-m),m=E}return{offsets:A,tableId:l,columnIndex:u,rowCount:d.children.length}}function Ns(o,t,e){const n=[];let i=t[e].size.width.v,s=0;for(let r=0;r<t.length;r++)s+=t[r].size.width.v;s+=i;for(let r=0;r<t.length;r++)n.push(t[r].size.width.v/s*o);return i=i/s*o,{widths:n,newColWidth:i}}function Ai(o,t){var m,h,g;const{startOffset:e,endOffset:n,segmentId:i}=o,s=t.getSelfOrHeaderFooterViewModel(i),r=(g=(h=(m=t.getBody())==null?void 0:m.tables)==null?void 0:h.find(p=>e>=p.startIndex&&n<=p.endIndex))==null?void 0:g.tableId,c=[];let l=-1,A=0,d=-1,u=!1;for(const p of s.getChildren()){for(const f of p.children){const{children:S}=f,E=S[0];if(E){if(e<E.startIndex||n>E.endIndex)continue;d=E.startIndex+3;for(const C of E.children){const T=E.children.indexOf(C),{startIndex:R,endIndex:v}=C;e>=R&&e<=v?(l=R,c.push(T),A+=v-R+1):(R>e&&v<n||n>=R&&n<=v)&&(c.push(T),A+=v-R+1),c.length===E.children.length&&(u=!0)}}if(c.length)break}if(c.length)break}return r==null||c.length===0?null:{tableId:r,rowIndexes:c,offset:l,len:A,cursor:d,selectWholeTable:u}}function Ps(o,t){var g,p,f;const{startOffset:e,endOffset:n,segmentId:i}=o,s=t.getSelfOrHeaderFooterViewModel(i),r=(f=(p=(g=t.getBody())==null?void 0:g.tables)==null?void 0:p.find(S=>e>=S.startIndex&&n<=S.endIndex))==null?void 0:f.tableId,c=[];let l=null;const A=[];let d=-1,u=-1,m=-1;for(const S of s.getChildren()){for(const E of S.children){const{children:C}=E,T=C[0];if(T){if(e<T.startIndex||n>T.endIndex)continue;l=T;for(const R of T.children)for(const v of R.children){const O=R.children.indexOf(v);e>=v.startIndex&&e<=v.endIndex&&(u=O),n>=v.startIndex&&n<=v.endIndex&&(m=O)}}if(l)break}if(l)break}if(l==null||r==null)return null;for(let S=u;S<=m;S++)A.push(S);let h=0;for(const S of l.children){const E=S.children[u],C=S.children[m];c.push({retain:E.startIndex-h,delete:C.endIndex-E.startIndex+1}),h=C.endIndex+1}return d=l.startIndex+3,{offsets:c,tableId:r,columnIndexes:A,cursor:d,selectWholeTable:A.length===l.children[0].children.length,rowCount:l.children.length}}function ui(o,t){var d,u,m;const{startOffset:e,endOffset:n,segmentId:i}=o,s=t.getSelfOrHeaderFooterViewModel(i),r=(m=(u=(d=t.getBody())==null?void 0:d.tables)==null?void 0:u.find(h=>e>=h.startIndex&&n<=h.endIndex))==null?void 0:m.tableId;let c=-1,l=0,A=-1;for(const h of s.getChildren()){for(const g of h.children){const{children:p}=g,f=p[0];if(f){if(e<f.startIndex||n>f.endIndex)continue;c=f.startIndex,l=f.endIndex-f.startIndex+1,A=f.startIndex}if(f)break}if(l>0)break}return r==null?null:{tableId:r,offset:c,len:l,cursor:A}}function ws(o,t){var g,p,f;const{startOffset:e,endOffset:n,segmentId:i}=o,s=t.getSelfOrHeaderFooterViewModel(i),r=(f=(p=(g=t.getBody())==null?void 0:g.tables)==null?void 0:p.find(S=>e>=S.startIndex&&n<=S.endIndex))==null?void 0:f.tableId,c=[];let l=null,A=-1,d=-1,u=-1,m=-1;for(const S of s.getChildren()){for(const E of S.children){const{children:C}=E,T=C[0];if(T){if(e<T.startIndex||n>T.endIndex)continue;l=T;for(const R of T.children){const v=T.children.indexOf(R);for(const O of R.children){const M=R.children.indexOf(O);e>=O.startIndex&&e<=O.endIndex&&(d=v,u=M),n>=O.startIndex&&n<=O.endIndex&&(m=M)}}}if(l)break}if(l)break}if(l==null||r==null||d===-1)return null;const h=l.children[d];for(let S=u;S<=m;S++){const E=h.children[S];c.push({retain:E.startIndex+1,delete:E.endIndex-E.startIndex-3})}return A=l.startIndex+3,{offsets:c,tableId:r,cursor:A,rowCount:l.children.length}}var Ln=(o=>(o[o.NEXT=0]="NEXT",o[o.PREV=1]="PREV",o))(Ln||{});function hi(o,t,e){const{startOffset:n}=t;let i=null;for(const A of o.getChildren()){for(const d of A.children){const u=d.children[0];if(u&&n>u.startIndex&&n<u.endIndex){i=u;break}}if(i)break}if(i==null)return null;let s=-1,r=-1,c=null;for(const A of i.children){for(const d of A.children)if(n>d.startIndex&&n<d.endIndex){s=A.children.indexOf(d),r=i.children.indexOf(A),c=A;break}if(s>-1)break}if(s===-1||r===-1||c==null)return null;let l=null;if(e===0){if(l=c.children[s+1],!l){const A=i.children[r+1];A&&(l=A.children[0])}}else if(l=c.children[s-1],!l){const A=i.children[r-1];A&&(l=A.children[A.children.length-1])}if(l){const{startIndex:A,endIndex:d}=l;return{startOffset:A+1,endOffset:d-2}}}function gi(o,t){const e=[],{customBlocks:n=[]}=o;for(const i of t){const{startOffset:s,endOffset:r}=i;if(!(s==null||r==null))for(const c of n){const{startIndex:l}=c;l>=s&&l<r&&e.push(c.blockId)}}return e}function Us(o){return o.some(t=>{const{startNodePosition:e}=t;return e?(e==null?void 0:e.path.indexOf("cells"))>-1:!1})}const Ls=a.SHEET_EDITOR_UNITS,Qn={id:"doc.command.inner-paste",type:a.CommandType.COMMAND,handler:async(o,t)=>{var b,N,x,U,F,V;const{segmentId:e,textRanges:n,doc:i}=t,s=o.get(a.ICommandService),r=o.get(D.DocSelectionManagerService),c=o.get(a.IUniverInstanceService),l=r.getTextRanges(),A=r.getRectRanges(),{body:d,tableSource:u,drawings:m}=i;if(!Array.isArray(l)||l.length===0||d==null)return!1;const h=c.getCurrentUniverDocInstance(),g=h==null?void 0:h.getSelfOrHeaderFooterModel(e).getBody();if(h==null||g==null)return!1;const p=h.getUnitId(),f={id:D.RichTextEditingMutation.id,params:{unitId:p,actions:[],textRanges:n,segmentId:e}},S=new a.MemoryCursor;S.reset();const E=new a.TextX,C=a.JSONX.getInstance(),T=[],R=!!((b=d.tables)!=null&&b.length),v=!!((N=d.customBlocks)!=null&&N.length);if(R&&e||R&&Us(l)||l.length&&(A!=null&&A.length))return!1;for(let H=0;H<l.length;H++){const Q=l[H],{startOffset:X,endOffset:j,collapsed:k}=Q,W=X-S.cursor,G=a.Tools.deepClone(d);if(R)for(const q of G.tables){const{tableId:z}=q,$=a.generateRandomId(6);q.tableId=$;const ie=a.Tools.deepClone(u[z]);ie.tableId=$;const fe=C.insertOp(["tableSource",$],ie);T.push(fe)}if(v&&m){const q=(U=(x=h.getSnapshot().drawingsOrder)==null?void 0:x.length)!=null?U:0;for(const z of G.customBlocks){const{blockId:$}=z,ie=a.generateRandomId(6);z.blockId=ie;const fe=a.Tools.deepClone(m[$]);fe.drawingId=ie;const Fe=C.insertOp(["drawings",ie],fe),Se=C.insertOp(["drawingsOrder",q],ie);T.push(Fe),T.push(Se)}}const K=Bn((F=g.customRanges)!=null?F:[],j,Ls.includes(p)),Y=_n((V=g.customDecorations)!=null?V:[],j);if(K&&(G.customRanges=[{...K,startIndex:0,endIndex:d.dataStream.length-1}]),Y.length&&(G.customDecorations=Y.map(q=>({...q,startIndex:0,endIndex:d.dataStream.length-1}))),k)E.push({t:a.TextXActionType.RETAIN,len:W}),E.push({t:a.TextXActionType.INSERT,body:G,len:d.dataStream.length});else{const q=a.BuildTextUtils.selection.delete([Q],d,S.cursor,G,l.length===1);E.push(...q)}S.reset(),S.moveCursor(j)}const O=Z(h,e);return T.push(C.editOp(E.serialize(),O)),f.params.actions=T.reduce((H,Q)=>a.JSONX.compose(H,Q),null),!!s.syncExecuteCommand(f.id,f.params)}};function Qs(o,t){const{startOffset:e,endOffset:n}=o,i=t.some(r=>r.startIndex===n),s=Math.max(e,i?n-1:n);return{...o,endOffset:s,collapsed:e===s}}function Fs(o,t,e){var g,p;const n=t.getSelfOrHeaderFooterModel(e).getBody(),i=new a.TextX,s=a.JSONX.getInstance(),r=[];if(n==null)return r;const{tables:c=[]}=n,l=new a.MemoryCursor;l.reset();for(let f=0;f<o.length;f++){const S=Qs(o[f],c),{startOffset:E,endOffset:C,collapsed:T}=S,R=E-l.cursor;T?i.push({t:a.TextXActionType.RETAIN,len:R}):i.push(...a.BuildTextUtils.selection.delete([S],n,l.cursor,null,!1)),l.reset(),l.moveCursor(C)}const A=Z(t,e);r.push(s.editOp(i.serialize(),A));const d=gi(n,o),u=(g=t.getDrawings())!=null?g:{},m=(p=t.getDrawingsOrder())!=null?p:[],h=d.sort((f,S)=>m.indexOf(f)>m.indexOf(S)?-1:m.indexOf(f)<m.indexOf(S)?1:0);if(h.length>0)for(const f of h){const S=u[f],E=m.indexOf(f);if(S==null||E<0)continue;const C=s.removeOp(["drawings",f],S),T=s.removeOp(["drawingsOrder",E],f);r.push(C),r.push(T)}return r.reduce((f,S)=>a.JSONX.compose(f,S),null)}function Hs(o,t,e,n){const i=[];if(t.getSelfOrHeaderFooterModel(n).getBody()==null)return i;const r=new a.TextX,c=a.JSONX.getInstance(),l=new a.MemoryCursor;l.reset();for(const d of o){const{startOffset:u,endOffset:m,spanEntireRow:h,spanEntireTable:g}=d;if(!(u==null||m==null))if(g){const p=ui({startOffset:u,endOffset:m,segmentId:n},e);if(p==null)continue;const{offset:f,len:S,tableId:E}=p;f-l.cursor>0&&r.push({t:a.TextXActionType.RETAIN,len:f-l.cursor}),r.push({t:a.TextXActionType.DELETE,len:S});const C=c.removeOp(["tableSource",E]);i.push(C),l.moveCursorTo(f+S)}else if(h){const p=Ai({startOffset:u,endOffset:m,segmentId:n},e);if(p==null)continue;const{offset:f,rowIndexes:S,len:E,tableId:C}=p;f-l.cursor>0&&r.push({t:a.TextXActionType.RETAIN,len:f-l.cursor}),r.push({t:a.TextXActionType.DELETE,len:E});for(const T of S.reverse()){const R=c.removeOp(["tableSource",C,"tableRows",T]);i.push(R)}l.moveCursorTo(f+E)}else{const p=ws({startOffset:u,endOffset:m,segmentId:n},e);if(p==null)continue;const{offsets:f}=p;for(const S of f){const{retain:E,delete:C}=S;E-l.cursor>0&&r.push({t:a.TextXActionType.RETAIN,len:E-l.cursor}),r.push({t:a.TextXActionType.DELETE,len:C}),l.moveCursorTo(E+C)}}}const A=Z(t,n);return i.push(c.editOp(r.serialize(),A)),i.reduce((d,u)=>a.JSONX.compose(d,u),null)}function mi(o,t,e,n,i){let s=[];if(Array.isArray(o)&&(o==null?void 0:o.length)!==0&&(s=Fs(o,e,i)),Array.isArray(t)&&(t==null?void 0:t.length)!==0){const r=Hs(t,e,n,i);s==null||s.length===0?s=r:s=a.JSONX.compose(s,a.JSONX.transform(r,s,"right"))}return s}const ke={id:"doc.command.inner-cut",type:a.CommandType.COMMAND,handler:(o,t)=>{var p;const e=o.get(D.DocSelectionManagerService),n=o.get(a.ICommandService),i=o.get(a.IUniverInstanceService),{segmentId:s,textRanges:r,selections:c=e.getTextRanges(),rectRanges:l=e.getRectRanges()}=t;if((!Array.isArray(c)||c.length===0)&&(!Array.isArray(l)||l.length===0))return!1;const A=(p=i.getCurrentUniverDocInstance())==null?void 0:p.getUnitId();if(!A)return!1;const d=i.getUniverDocInstance(A);if(d==null)return!1;const u=re(o,A);if(u==null)return!1;const m=u.getViewModel(),h={id:D.RichTextEditingMutation.id,params:{unitId:A,actions:[],textRanges:r}};return h.params.actions=mi(c,l,d,m,s),!!n.syncExecuteCommand(h.id,h.params)}};var oe=(o=>(o[o.LEFT=0]="LEFT",o[o.RIGHT=1]="RIGHT",o))(oe||{});const pi="doc.command.insert-text",Fn={id:pi,type:a.CommandType.COMMAND,handler:async(o,t)=>{var v;const e=o.get(a.ICommandService),{range:n,segmentId:i,body:s,unitId:r,cursorOffset:c}=t,l=o.get(D.DocSelectionManagerService),d=o.get(a.IUniverInstanceService).getUnit(r,a.UniverInstanceType.UNIVER_DOC);if(d==null)return!1;const u=l.getActiveTextRange(),m=d.getSelfOrHeaderFooterModel((v=u==null?void 0:u.segmentId)!=null?v:"").getBody();if(m==null)return!1;const{startOffset:h,collapsed:g}=n,p=c!=null?c:s.dataStream.length,f=[{startOffset:h+p,endOffset:h+p,style:u==null?void 0:u.style,collapsed:g}],S={id:D.RichTextEditingMutation.id,params:{unitId:r,actions:[],textRanges:f,debounce:!0}},E=new a.TextX,C=a.JSONX.getInstance();if(g)h>0&&E.push({t:a.TextXActionType.RETAIN,len:h}),E.push({t:a.TextXActionType.INSERT,body:s,len:s.dataStream.length});else{const O=a.BuildTextUtils.selection.delete([n],m,0,s);E.push(...O)}S.params.textRanges=[{startOffset:h+p,endOffset:h+p,collapsed:g}];const T=Z(d,i);return S.params.actions=C.editOp(E.serialize(),T),!!e.syncExecuteCommand(S.id,S.params)}},qe={id:"doc.command.delete-text",type:a.CommandType.COMMAND,handler:async(o,t)=>{var R;const e=o.get(a.ICommandService),n=o.get(a.IUniverInstanceService),{range:i,segmentId:s,unitId:r,direction:c,len:l=1}=t,A=n.getUnit(r,a.UniverInstanceType.UNIVER_DOC),d=A==null?void 0:A.getSelfOrHeaderFooterModel(s).getBody();if(A==null||d==null)return!1;const{startOffset:u}=i;let m=c===oe.LEFT?u-l:u,h=c===oe.LEFT?u-1:u+l-1;const g=(R=d.customRanges)==null?void 0:R.find(v=>v.startIndex<=m&&v.endIndex>=h);g!=null&&g.wholeEntity&&(m=g.startIndex,h=Math.max(h,g.endIndex));const p={id:D.RichTextEditingMutation.id,params:{unitId:r,actions:[],textRanges:[{startOffset:m,endOffset:m,collapsed:!0}],debounce:!0}},f=new a.TextX,S=a.JSONX.getInstance();f.push({t:a.TextXActionType.RETAIN,len:m-0}),f.push({t:a.TextXActionType.DELETE,len:h-m+1});const C=Z(A,s);return p.params.actions=S.editOp(f.serialize(),C),!!e.syncExecuteCommand(p.id,p.params)}},Hn={id:"doc.command.update-text",type:a.CommandType.COMMAND,handler:async(o,t)=>{const{range:e,segmentId:n,updateBody:i,coverType:s,unitId:r,textRanges:c}=t,l=o.get(a.ICommandService),d=o.get(a.IUniverInstanceService).getCurrentUniverDocInstance();if(d==null)return!1;const u={id:D.RichTextEditingMutation.id,params:{unitId:r,actions:[],textRanges:c}},m=new a.TextX,h=a.JSONX.getInstance(),{startOffset:g,endOffset:p}=e;m.push({t:a.TextXActionType.RETAIN,len:g}),m.push({t:a.TextXActionType.RETAIN,body:i,len:p-g,coverType:s});const f=Z(d,n);return u.params.actions=h.editOp(m.serialize(),f),!!l.syncExecuteCommand(u.id,u.params)}};function ht(o){var r,c,l,A;const t=o.get(a.IUniverInstanceService),n=o.get(D.DocSelectionManagerService).getActiveTextRange(),i=t.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);return!n||!n.collapsed||!i||n.segmentId?!1:a.BuildTextUtils.range.getParagraphsInRange(n,(c=(r=i.getBody())==null?void 0:r.paragraphs)!=null?c:[],(A=(l=i.getBody())==null?void 0:l.dataStream)!=null?A:"")[0]}const Gt={id:"doc.command.delete-custom-block",type:a.CommandType.COMMAND,handler:async(o,t)=>{var x;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=e.getActiveTextRange(),r=n.getCurrentUniverDocInstance();if(s==null||r==null)return!1;const{direction:c,range:l,unitId:A,drawingId:d}=t,{startOffset:u,segmentId:m,style:h}=s,g=c===oe.LEFT?u-1:u,p=[{startOffset:g,endOffset:g,style:h}],f={id:D.RichTextEditingMutation.id,params:{unitId:A,actions:[],textRanges:p,prevTextRanges:[l]}},S=new a.TextX,E=a.JSONX.getInstance(),C=[];u>0&&S.push({t:a.TextXActionType.RETAIN,len:c===oe.LEFT?u-1:u}),S.push({t:a.TextXActionType.DELETE,len:1});const T=Z(r,m);C.push(E.editOp(S.serialize(),T));const R=((x=r.getDrawings())!=null?x:{})[d],O=r.getDrawingsOrder().indexOf(d),M=E.removeOp(["drawings",d],R),b=E.removeOp(["drawingsOrder",O],d);return C.push(M),C.push(b),f.params.actions=C.reduce((U,F)=>a.JSONX.compose(U,F),null),!!i.syncExecuteCommand(f.id,f.params)}},jt={id:"doc.command.merge-two-paragraph",type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),{direction:s,range:r}=t,c=e.getActiveTextRange(),l=e.getTextRanges();if(c==null||l==null)return!1;const{segmentId:A,style:d}=c,u=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),m=u==null?void 0:u.getSelfOrHeaderFooterModel(A).getBody();if(u==null||m==null)return!1;const h=m.dataStream,g=c,p=u.getUnitId(),{startOffset:f,collapsed:S}=g;if(!S)return!1;const E=s===oe.LEFT?f:f+1;let C,T;for(const V of m.paragraphs){if(V.startIndex>=E){T=V;break}C=V}if(C==null||T==null)return!1;const R=s===oe.LEFT?f-1:f,v=[{startOffset:R,endOffset:R,style:d}],O={id:D.RichTextEditingMutation.id,params:{unitId:p,actions:[],textRanges:v,prevTextRanges:[r]}},M=new a.TextX,b=a.JSONX.getInstance();C.startIndex>0&&M.push({t:a.TextXActionType.RETAIN,len:C.startIndex}),M.push({t:a.TextXActionType.DELETE,len:1}),T.startIndex>C.startIndex+1&&M.push({t:a.TextXActionType.RETAIN,len:T.startIndex-C.startIndex-1});const N=Object.values(a.DataStreamTreeTokenType),x=h[C.startIndex-1];(x&&!N.includes(x)||x===" ")&&M.push({t:a.TextXActionType.RETAIN,len:1,coverType:a.UpdateDocsAttributeType.REPLACE,body:{dataStream:"",paragraphs:[{...a.Tools.deepClone(C),startIndex:0}]}});const U=Z(u,A);return O.params.actions=b.editOp(M.serialize(),U),!!i.syncExecuteCommand(O.id,O.params)}},fi={id:"doc.command.remove-horizontal-line",type:a.CommandType.COMMAND,handler:async o=>{var R;const t=o.get(D.DocSelectionManagerService),e=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),i=t.getActiveTextRange(),s=t.getTextRanges();if(i==null||s==null)return!1;const{segmentId:r,style:c}=i,l=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),A=l==null?void 0:l.getSelfOrHeaderFooterModel(r).getBody();if(l==null||A==null)return!1;const d=i,u=l.getUnitId(),{startOffset:m,collapsed:h}=d;if(!h)return!1;const g=(R=A.paragraphs)==null?void 0:R.find(v=>v.startIndex===m-1);if(g==null)return!1;const p=[{startOffset:m,endOffset:m,style:c}],f={id:D.RichTextEditingMutation.id,params:{unitId:u,actions:[],textRanges:p}},S=new a.TextX,E=a.JSONX.getInstance();g.startIndex>0&&S.push({t:a.TextXActionType.RETAIN,len:g.startIndex}),S.push({t:a.TextXActionType.RETAIN,len:1,coverType:a.UpdateDocsAttributeType.REPLACE,body:{dataStream:"",paragraphs:[{...a.Tools.deepClone({...g,paragraphStyle:{...g.paragraphStyle,borderBottom:void 0}}),startIndex:0}]}});const C=Z(l,r);return f.params.actions=E.editOp(S.serialize(),C),!!n.syncExecuteCommand(f.id,f.params)}};function Xt(o,t){let e=0;if(o==null||o.length===0){if(typeof t[0].startOffset=="number"){const n=t[0],{spanEntireRow:i,spanEntireTable:s}=n;s?e=n.startOffset-3:i?n.startRow>0?e=n.startOffset-6:e=n.startOffset:e=t[0].startOffset}}else if(o.length>0&&t.length>0){const n=o[0],i=t[0];if(n.startOffset!=null&&i.startOffset!=null){if(n.startOffset<i.startOffset)e=n.startOffset;else if(n.startOffset>=i.startOffset){const{spanEntireRow:s,spanEntireTable:r}=i;r?e=i.startOffset-3:s&&(e=i.startOffset-6)}}}return e}const gt={id:"doc.command.delete-left",type:a.CommandType.COMMAND,handler:async o=>{var b,N,x,U,F,V;const t=o.get(D.DocSelectionManagerService),e=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService);let i=!0;const s=e.getCurrentUniverDocInstance();if(s==null)return!1;const r=s.getUnitId(),c=re(o,r),l=t.getActiveTextRange(),A=t.getRectRanges(),d=t.getTextRanges(),u=c==null?void 0:c.getSkeleton();if(u==null)return!1;if(A!=null&&A.length){const H=Xt(d,A),Q=A[0].segmentId,X=[{startOffset:H,endOffset:H}];return n.executeCommand(ke.id,{segmentId:Q,textRanges:X})}if(l==null||d==null)return!1;const{segmentId:m,style:h,segmentPage:g}=l,p=s.getSelfOrHeaderFooterModel(m).getBody();if(p==null)return!1;const f=l,{startOffset:S,collapsed:E}=f,C=u.findNodeByCharIndex(S,m,g),T=_.hasListGlyph(C),R=_.isIndentByGlyph(C,p);let v=S;const O=u.findNodeByCharIndex(S-1,m,g);if(_.isFirstGlyph(C)&&O!==C&&(T===!0||R===!0)&&E){const H=_.getParagraphByGlyph(C,p);if(H==null)return!1;const Q=H==null?void 0:H.startIndex,X={startIndex:0},j=H.paragraphStyle;if(T===!0){const W=H.paragraphStyle;if(W){X.paragraphStyle=W;const{hanging:G}=W;G&&(X.paragraphStyle.indentStart=G,X.paragraphStyle.hanging=void 0)}}else if(R===!0){const W=H.bullet;W&&(X.bullet=W),j!=null&&(X.paragraphStyle={...j},delete X.paragraphStyle.hanging,delete X.paragraphStyle.indentStart)}const k=[{startOffset:v,endOffset:v,style:h}];i=await n.executeCommand(Hn.id,{unitId:s.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...X}]},range:{startOffset:Q,endOffset:Q+1},textRanges:k,coverType:a.UpdateDocsAttributeType.REPLACE,segmentId:m})}else if(E===!0){if(O==null)return!0;if(O.content==="\r"){const H=(b=p.paragraphs)==null?void 0:b.find(Q=>Q.startIndex===S-1);(N=H==null?void 0:H.paragraphStyle)!=null&&N.borderBottom?i=await n.executeCommand(fi.id):i=await n.executeCommand(jt.id,{direction:oe.LEFT,range:f})}else if(O.streamType==="\b"){const H=(U=s.getSnapshot().drawings)==null?void 0:U[(x=O.drawingId)!=null?x:""];if(H==null)return!0;const Q=(V=(F=s.getBody())==null?void 0:F.customBlocks)==null?void 0:V.find(j=>j.blockId===O.drawingId);if(H.layoutType===a.PositionedObjectLayoutType.INLINE||(Q==null?void 0:Q.blockType)===a.BlockType.CUSTOM){const j=s.getUnitId();i=await n.executeCommand(Gt.id,{direction:oe.LEFT,range:l,unitId:j,drawingId:O.drawingId})}else{const j=u.findNodeByCharIndex(S-2);if(j==null)return!0;v-=O.count,v-=j.count;const k=[{startOffset:v,endOffset:v,style:h}];i=await n.executeCommand(qe.id,{unitId:s.getUnitId(),range:{...l,startOffset:l.startOffset-1,endOffset:l.endOffset-1},segmentId:m,direction:oe.LEFT,len:j.count,textRanges:k})}}else v-=O.count,i=await n.executeCommand(qe.id,{unitId:s.getUnitId(),range:f,segmentId:m,direction:oe.LEFT,len:O.count})}else{const H=Si(f,[f]);i=await n.executeCommand(ke.id,{segmentId:m,textRanges:H,selections:[f]})}return i}},kn={id:"doc.command.delete-right",type:a.CommandType.COMMAND,handler:async o=>{var C,T;const t=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService).getCurrentUniverDocInstance();if(!n)return!1;const i=re(o,n.getUnitId()),s=o.get(a.ICommandService),r=t.getActiveTextRange(),c=t.getRectRanges(),l=t.getTextRanges(),A=i==null?void 0:i.getSkeleton();if(c!=null&&c.length){const R=Xt(l,c),v=c[0].segmentId,O=[{startOffset:R,endOffset:R}];return s.executeCommand(ke.id,{segmentId:v,textRanges:O})}if(r==null||A==null||l==null)return!1;const{segmentId:d,style:u,segmentPage:m}=r,h=n==null?void 0:n.getSelfOrHeaderFooterModel(d).getBody();if(!n||!h)return!1;const g=r,{startOffset:p,endOffset:f,collapsed:S}=g;if(p===h.dataStream.length-2&&S)return!0;let E=!1;if(S===!0){const R=A.findNodeByCharIndex(p,d,m),v=A.findNodeByCharIndex(p+1);if(R.streamType===a.DataStreamTreeTokenType.PARAGRAPH&&(v==null?void 0:v.streamType)===a.DataStreamTreeTokenType.SECTION_BREAK)return!1;if(R.content==="\r")E=await s.executeCommand(jt.id,{direction:oe.RIGHT,range:r});else if(R.streamType==="\b"){const O=(T=n.getSnapshot().drawings)==null?void 0:T[(C=R.drawingId)!=null?C:""];if(O==null)return!0;if(O.layoutType===a.PositionedObjectLayoutType.INLINE){const b=n.getUnitId();E=await s.executeCommand(Gt.id,{direction:oe.RIGHT,range:r,unitId:b,drawingId:R.drawingId})}else{if(v==null)return!0;const b=[{startOffset:p+1,endOffset:p+1,style:u}];E=await s.executeCommand(qe.id,{unitId:n.getUnitId(),range:{...r,startOffset:p+1,endOffset:f+1},segmentId:d,direction:oe.RIGHT,textRanges:b,len:v.count})}}else{const O=[{startOffset:p,endOffset:p,style:u}];E=await s.executeCommand(qe.id,{unitId:n.getUnitId(),range:g,segmentId:d,direction:oe.RIGHT,textRanges:O,len:R.count})}}else{const R=Si(g,[g]);E=await s.executeCommand(ke.id,{segmentId:d,textRanges:R,selections:[g]})}return E}};function Si(o,t){let e=o.endOffset;for(const i of t){const{startOffset:s,endOffset:r}=i;s==null||r==null||r<=o.endOffset&&(e-=r-s)}return[{startOffset:e,endOffset:e,style:o.style}]}const Vn={id:"doc.command.delete-current-paragraph",type:a.CommandType.COMMAND,handler:async o=>{var A,d;const t=o.get(a.IUniverInstanceService),e=o.get(a.ICommandService),n=t.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!n)return!1;const i=(d=(A=n.getBody())==null?void 0:A.dataStream)!=null?d:"",s=ht(o);if(!s)return!1;const r=a.BuildTextUtils.selection.delete([{startOffset:s.paragraphStart,endOffset:i[s.paragraphEnd+1]===`
|
|
@@ -8,7 +8,7 @@ ${a.DataStreamTreeTokenType.TABLE_CELL_END}`;break}}}_processBeforeLink(t,e){ret
|
|
|
8
8
|
`,e.push({startIndex:i.length-2}),n.push({startIndex:i.length-1}),t.dataStream=i,t.paragraphs=e,t.sectionBreaks=n);const s={html:""},r=_.parseDataStreamToTree(i).sectionList;for(const c of r)Ze(c,o,s);return s.html}function Ze(o,t,e){var n,i;switch(o.nodeType){case a.DataStreamTreeNodeType.SECTION_BREAK:{for(const s of o.children)Ze(s,t,e);break}case a.DataStreamTreeNodeType.PARAGRAPH:{const{children:s,startIndex:r,endIndex:c}=o,l=(i=(n=t.body)==null?void 0:n.paragraphs.find(g=>g.startIndex===c))!=null?i:{},{paragraphStyle:A={}}=l,{spaceAbove:d,spaceBelow:u,lineSpacing:m}=A,h=[];if(d!=null&&(typeof d=="number"?h.push(`margin-top: ${d}px`):h.push(`margin-top: ${d.v}px`)),u!=null&&(typeof u=="number"?h.push(`margin-bottom: ${u}px`):h.push(`margin-bottom: ${u.v}px`)),m!=null&&h.push(`line-height: ${m}`),e.html+=`<p class="UniverNormal" ${h.length?`style="${h.join("; ")};"`:""}>`,s.length)for(const g of s)Ze(g,t,e);e.html+=`${zs(t,r,c)}</p>`;break}case a.DataStreamTreeNodeType.TABLE:{const{children:s}=o;e.html+='<table class="UniverTable" style="width: 100%; border-collapse: collapse;"><tbody>';for(const r of s)Ze(r,t,e);e.html+="</tbody></table>";break}case a.DataStreamTreeNodeType.TABLE_ROW:{const{children:s}=o;e.html+='<tr class="UniverTableRow">';for(const r of s)Ze(r,t,e);e.html+="</tr>";break}case a.DataStreamTreeNodeType.TABLE_CELL:{const{children:s}=o;e.html+='<td class="UniverTableCell">';for(const r of s)Ze(r,t,e);e.html+="</td>";break}default:throw new Error(`Unknown node type: ${o.nodeType}`)}}class Ys{convert(t){if(t.length===0)throw new Error("The bodyList length at least to be 1");let e="";for(const n of a.Tools.deepClone(t))e+=Oi(n);return e}}var qs=Object.getOwnPropertyDescriptor,Js=(o,t,e,n)=>{for(var i=n>1?void 0:n?qs(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},mt=(o,t)=>(e,n)=>t(e,n,o);Je.use(yi),Je.use(Ei),Je.use(Ti);function Ri(o,t,e){var s,r,c;const n=a.getBodySlice(o,t,e+2),i=a.DataStreamTreeTokenType.TABLE_START+a.DataStreamTreeTokenType.TABLE_ROW_START+a.DataStreamTreeTokenType.TABLE_CELL_START+n.dataStream+a.DataStreamTreeTokenType.TABLE_CELL_END+a.DataStreamTreeTokenType.TABLE_ROW_END+a.DataStreamTreeTokenType.TABLE_END;return n.dataStream=i,(s=n.textRuns)==null||s.forEach(l=>{const{st:A,ed:d}=l;l.st=A+3,l.ed=d+3}),(r=n.tables)==null||r.forEach(l=>{const{startIndex:A,endIndex:d}=l;l.startIndex=A+3,l.endIndex=d+3}),(c=n.paragraphs)==null||c.forEach(l=>{const{startIndex:A}=l;l.startIndex=A+3}),n}const Me=a.createIdentifier("doc.clipboard-service");let Xn=class extends a.Disposable{constructor(t,e,n,i,s){super();B(this,"_clipboardHooks",[]);B(this,"_htmlToUDM",new Je);B(this,"_umdToHtml",new Ys);this._univerInstanceService=t,this._logService=e,this._commandService=n,this._clipboardInterfaceService=i,this._docSelectionManagerService=s}async copy(t=a.SliceBodyType.copy,e){var c,l;const{newSnapshotList:n=[],needCache:i=!1,snapshot:s,ranges:r}=(c=this._getDocumentBodyInRanges(t,e))!=null?c:{};if(n.length===0||s==null)return!1;try{const A=!!((l=r==null?void 0:r[0])!=null&&l.segmentId);this._setClipboardData(n,!A&&i)}catch(A){return this._logService.error("[DocClipboardService] copy failed",A),!1}return!0}async cut(t){return this._cut(t)}async paste(t){const e=await this._genDocDataFromClipboardItems(t);return this._paste(e)}async legacyPaste(t){let{html:e,text:n,files:i}=t;const s=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),r=(s==null?void 0:s.getUnitId())||"";if(!e&&!n&&i.length&&(e=await this._createImagePasteHtml(i)),!e&&!n)return this._logService.warn("[DocClipboardController] html and text cannot be both empty!"),!1;const c=this._genDocDataFromHtmlAndText(e,n,r);if(r===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)if(n){const l=a.BuildTextUtils.transform.fromPlainText(n);return this._paste({body:l})}else c.body.textRuns=[];return this._paste(c)}async _cut(t){var c,l,A,d,u;const e=(l=(c=t==null?void 0:t.filter(m=>m.rangeType===a.DOC_RANGE_TYPE.TEXT))!=null?c:this._docSelectionManagerService.getTextRanges())!=null?l:[],n=(d=(A=t==null?void 0:t.filter(m=>m.rangeType===a.DOC_RANGE_TYPE.RECT))!=null?A:this._docSelectionManagerService.getRectRanges())!=null?d:[],{segmentId:i,endOffset:s,style:r}=(u=e[0])!=null?u:{};if(i==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),e.length===0&&n.length===0)return!1;this.copy(a.SliceBodyType.cut,t);try{let m=0;if(n.length>0)m=Xt(e,n);else if(s!=null){m=s;for(const g of e){const{startOffset:p,endOffset:f}=g;p==null||f==null||f<=s&&(m-=f-p)}}const h=[{startOffset:m,endOffset:m,style:r}];return this._commandService.executeCommand(ke.id,{segmentId:i,textRanges:h,rectRanges:n,selections:e})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(t){var d,u,m;const{body:e}=t;if(e==null)return!1;let n=a.normalizeBody(e);if(!((d=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC))==null?void 0:d.getUnitId()))return!1;this._clipboardHooks.forEach(h=>{h.onBeforePaste&&(n=h.onBeforePaste(n))}),n.customRanges=(u=n.customRanges)==null?void 0:u.map(a.BuildTextUtils.customRange.copyCustomRange),(m=n.paragraphs)==null||m.forEach(h=>{var g;(g=h.paragraphStyle)!=null&&g.headingId&&(h.paragraphStyle.headingId=a.generateRandomId(6))});const s=this._docSelectionManagerService.getActiveTextRange(),{segmentId:r,endOffset:c,style:l}=s||{},A=this._docSelectionManagerService.getTextRanges();if(r==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),c==null||A==null)return!1;try{let h=c;for(const p of A){const{startOffset:f,endOffset:S}=p;f==null||S==null||S<=c&&(h+=n.dataStream.length-(S-f))}const g=[{startOffset:h,endOffset:h,style:l}];return this._commandService.executeCommand(Qn.id,{doc:{...t,body:n},segmentId:r,textRanges:g})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(t,e=!0){var r,c,l,A;const n=Ws(),i=(t.length>1?t.map(d=>{var u;return((u=d.body)==null?void 0:u.dataStream)||""}).join(`
|
|
9
9
|
`):((r=t[0].body)==null?void 0:r.dataStream)||"").replaceAll(a.DataStreamTreeTokenType.TABLE_START,"").replaceAll(a.DataStreamTreeTokenType.TABLE_END,"").replaceAll(a.DataStreamTreeTokenType.TABLE_ROW_START,"").replaceAll(a.DataStreamTreeTokenType.TABLE_ROW_END,"").replaceAll(a.DataStreamTreeTokenType.TABLE_CELL_START,"").replaceAll(a.DataStreamTreeTokenType.TABLE_CELL_END,"").replaceAll(`\r
|
|
10
10
|
`," ");let s=this._umdToHtml.convert(t);if(t.length===1&&e){s=s.replace(/(<[a-z]+)/,(m,h)=>`${h} data-copy-id="${n}"`);const d=t[0],u={body:d.body};if((l=(c=d.body)==null?void 0:c.customBlocks)!=null&&l.length){u.drawings={};for(const m of d.body.customBlocks){const{blockId:h}=m,g=(A=d.drawings)==null?void 0:A[h];if(g){const p=a.generateRandomId(6);m.blockId=p,u.drawings[p]={...a.Tools.deepClone(g),drawingId:p}}}}Wn.set(n,u)}return this._clipboardInterfaceService.write(i,s)}addClipboardHook(t){return this._clipboardHooks.push(t),a.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(t,e){var d;const n=this._univerInstanceService.getCurrentUniverDocInstance(),i=e!=null?e:this._docSelectionManagerService.getDocRanges(),s=[];let r=!0;if(n==null||i.length===0)return;const c=i[0].segmentId,l=(d=n==null?void 0:n.getSelfOrHeaderFooterModel(c))==null?void 0:d.getBody(),A=n.getSnapshot();if(l!=null){for(const u of i){const{startOffset:m,endOffset:h,collapsed:g,rangeType:p}=u;if(g||m==null||h==null)continue;if(p===a.DOC_RANGE_TYPE.RECT){r=!1;const{spanEntireRow:E}=u;let C;C=Ri(l,m,h),s.push(C);continue}const f={startOffset:m,endOffset:h},S=n.getSelfOrHeaderFooterModel(c).sliceBody(f.startOffset,f.endOffset,t);S!=null&&s.push(S)}return{newSnapshotList:s.map(u=>({...A,body:u})),needCache:r,snapshot:A,ranges:i}}}async _genDocDataFromClipboardItems(t){try{let e="",n="";const i=[];for(const s of t)for(const r of s.types)switch(r){case I.PLAIN_TEXT_CLIPBOARD_MIME_TYPE:{n=await s.getType(r).then(c=>c&&c.text());break}case I.HTML_CLIPBOARD_MIME_TYPE:{e=await s.getType(r).then(c=>c&&c.text());break}case I.FILE__BMP_CLIPBOARD_MIME_TYPE:case I.FILE__JPEG_CLIPBOARD_MIME_TYPE:case I.FILE__WEBP_CLIPBOARD_MIME_TYPE:case I.FILE_PNG_CLIPBOARD_MIME_TYPE:{const c=await s.getType(r),l=new File([c],`pasted_image.${r.split("/")[1]}`,{type:r});i.push(l);break}}return!e&&!n&&i.length&&(e=await this._createImagePasteHtml(i)),this._genDocDataFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_genDocDataFromHtmlAndText(t,e,n){if(!t){if(e)return{body:a.BuildTextUtils.transform.fromPlainText(e)};throw new Error("[DocClipboardService] html and text cannot be both empty!")}const i=Gs(t);if(i){const r=Wn.get(i);if(r)return r}if(!n){const r=this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);n=(r==null?void 0:r.getUnitId())||""}const s=this._htmlToUDM.convert(t,{unitId:n});return i&&Wn.set(i,s),s}async _createImagePasteHtml(t){var c,l;const e={id:"",documentStyle:{},body:{dataStream:"",customBlocks:[]},drawings:{}},n=async A=>{const d=new FileReader;return new Promise(u=>{d.onloadend=function(){u({source:d.result,imageSourceType:xn.ImageSourceType.BASE64})},d.readAsDataURL(A)})},i=A=>{const d=new Image,u=500;return new Promise(m=>{d.src=typeof A=="string"?A:URL.createObjectURL(A),d.onload=()=>{const h=Math.min(u,d.naturalWidth),g=d.naturalHeight/d.naturalWidth;m({width:h,height:h*g})}})},s=(l=(c=this._clipboardHooks.find(A=>A.onBeforePasteImage))==null?void 0:c.onBeforePasteImage)!=null?l:n;return await Promise.all(t.map(async(A,d)=>{var S;const u=await s(A);if(!u)return Promise.resolve();const{width:m=100,height:h=100}=await i(A),g=`paste_image_id_${d}`,p=e.body,f=e.drawings;p.dataStream+="\b",(S=p.customBlocks)==null||S.push({startIndex:d,blockId:g}),f[g]={drawingId:g,unitId:"",subUnitId:"",imageSourceType:u.imageSourceType,title:"",source:u.source,description:"",layoutType:a.PositionedObjectLayoutType.INLINE,drawingType:a.DrawingTypeEnum.DRAWING_IMAGE,transform:{width:m,height:h,angle:0},docTransform:{angle:0,size:{width:m,height:h},positionH:{relativeFrom:a.ObjectRelativeFromH.CHARACTER,posOffset:0},positionV:{relativeFrom:a.ObjectRelativeFromV.LINE,posOffset:0}}}})),this._umdToHtml.convert([e])}};Xn=Js([mt(0,a.IUniverInstanceService),mt(1,a.ILogService),mt(2,a.ICommandService),mt(3,I.IClipboardInterfaceService),mt(4,a.Inject(D.DocSelectionManagerService))],Xn);function Kt(o){return o.getContextValue(a.FOCUSING_DOC)||o.getContextValue(a.EDITOR_ACTIVATED)}const Kn=999,pt={id:I.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:Kn,preconditions:Kt,handler:async o=>o.get(Me).copy()},zn={id:"doc.command.copy-current-paragraph",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(Me),e=ht(o);return e?t.copy(a.SliceBodyType.copy,[{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1}]):!1}},zt={id:I.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:Kn,preconditions:Kt,handler:async o=>o.get(Me).cut()},Yn={id:"doc.command.cut-current-paragraph",type:a.CommandType.COMMAND,handler:async o=>{const t=o.get(Me),e=ht(o);return e?t.cut([{startOffset:e.paragraphStart,endOffset:e.paragraphEnd+1,collapsed:!1,rangeType:a.DOC_RANGE_TYPE.TEXT}]):!1}},Yt={id:I.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:Kn,preconditions:Kt,handler:async o=>{const t=o.get(Me),n=await o.get(I.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}},ft={id:"doc.command.horizontal-line",type:a.CommandType.COMMAND,handler:(o,t)=>o.get(a.ICommandService).syncExecuteCommand(Ft.id,{horizontalLine:{padding:5,color:{rgb:"#CDD0D8"},width:1,dashStyle:a.DashStyleType.SOLID},textRange:t==null?void 0:t.insertRange})},qn={id:"doc.command.insert-horizontal-line-bellow",type:a.CommandType.COMMAND,handler:o=>{const t=o.get(a.ICommandService),e=ht(o);return e?t.syncExecuteCommand(ft.id,{insertRange:{startOffset:e.startIndex+1,endOffset:e.startIndex+1}}):!1}},Jn={id:"doc.command.select-all",type:a.CommandType.COMMAND,handler:async o=>{var h;const t=o.get(a.IUniverInstanceService),e=o.get(D.DocSelectionManagerService),n=t.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),i=e.getDocRanges(),s=(h=i.find(g=>g.isActive))!=null?h:i[0];if(n==null||s==null)return!1;const{segmentId:r}=s,c=n.getUnitId(),l=n.getSelfOrHeaderFooterModel(r).getSnapshot().body;if(l==null)return!1;const{tables:A=[],dataStream:d}=l;if(d===`\r
|
|
11
|
-
`)return!0;const u=[];let m=0;for(const g of A){const{startIndex:p,endIndex:f}=g;m!==p&&u.push({startOffset:m,endOffset:p-1,rangeType:a.DOC_RANGE_TYPE.TEXT}),u.push({startOffset:p+3,endOffset:f-5,rangeType:a.DOC_RANGE_TYPE.RECT}),m=f}return m!==l.dataStream.length-2&&u.push({startOffset:m,endOffset:l.dataStream.length-2,rangeType:a.DOC_RANGE_TYPE.TEXT}),e.replaceDocRanges(u,{unitId:c,subUnitId:c},!1),!0}};class St extends a.RxDisposable{constructor(e){super();B(this,"_previousActiveRange",null);B(this,"_undoMutationParamsCache",[]);B(this,"_redoMutationParamsCache",[]);this._context=e}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:e=[],redoCache:n=[]}){this._undoMutationParamsCache=e,this._redoMutationParamsCache=n}getActiveRange(){return this._previousActiveRange}setActiveRange(e){this._previousActiveRange=e}pushUndoRedoMutationParams(e,n){this._undoMutationParamsCache.push(e),this._redoMutationParamsCache.push(n)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:e}=this._undoMutationParamsCache[0],n={unitId:e,actions:this._undoMutationParamsCache.reverse().reduce((s,r)=>a.JSONX.compose(s,r.actions),null),textRanges:[]};return{redoMutationParams:{unitId:e,actions:this._redoMutationParamsCache.reduce((s,r)=>a.JSONX.compose(s,r.actions),null),textRanges:[]},undoMutationParams:n,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Zn={id:"doc.command.ime-input",type:a.CommandType.COMMAND,handler:async(o,t)=>{var Q,X,j;const{unitId:e,newText:n,oldTextLen:i,isCompositionEnd:s,isCompositionStart:r}=t,c=o.get(a.ICommandService),l=o.get(_.IRenderManagerService),A=o.get(a.IUniverInstanceService),d=o.get(ve),u=(Q=l.getRenderById(e))==null?void 0:Q.with(St),m=A.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(m==null||u==null)return!1;const h=u.getActiveRange();if(h==null)return!1;const{style:g,segmentId:p}=h,f=m.getSelfOrHeaderFooterModel(p).getBody();if(f==null)return!1;Object.assign(h,h);const{startOffset:E,endOffset:C}=h,T=n.length,R=[{startOffset:E+T,endOffset:E+T,collapsed:!0,style:g}],v={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:R}},O=d.getDefaultStyle(),M=d.getStyleCache(),b=Bn((X=f.customRanges)!=null?X:[],E+i,a.SHEET_EDITOR_UNITS.includes(e)),N=Lt(f,r?C:E+i,O,M,a.SHEET_EDITOR_UNITS.includes(e)),x=_n((j=f.customDecorations)!=null?j:[],E+i),U=new a.TextX,F=a.JSONX.getInstance();if(!h.collapsed&&r){const k=a.BuildTextUtils.selection.delete([h],f,0,null,!1);U.push(...k),v.params.textRanges=[{startOffset:E+T,endOffset:E+T,collapsed:!0}]}else U.push({t:a.TextXActionType.RETAIN,len:E});i>0&&U.push({t:a.TextXActionType.DELETE,len:i}),U.push({t:a.TextXActionType.INSERT,body:{dataStream:n,textRuns:N?[{...N,st:0,ed:n.length}]:[],customRanges:b?[{...b,startIndex:0,endIndex:n.length-1}]:[],customDecorations:x.map(k=>({...k,startIndex:0,endIndex:n.length-1}))},len:n.length});const V=Z(m,p);v.params.actions=F.editOp(U.serialize(),V),v.params.noHistory=!s,v.params.isCompositionEnd=s;const H=c.syncExecuteCommand(v.id,v.params);return u.pushUndoRedoMutationParams(H,v.params),!!H}};function ue(o,t,e){return e.executeCommand(Ce.id,{preCommandId:o,...t!=null?t:{}})}const Mi="doc.command.set-inline-format-bold",xe={id:Mi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Mi,t,e)}},xi="doc.command.set-inline-format-italic",De={id:xi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(xi,t,e)}},Di="doc.command.set-inline-format-underline",Be={id:Di,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Di,t,e)}},Bi="doc.command.set-inline-format-strikethrough",_e={id:Bi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Bi,t,e)}},_i="doc.command.set-inline-format-subscript",Ee={id:_i,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(_i,t,e)}},Ni="doc.command.set-inline-format-superscript",Ne={id:Ni,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ni,t,e)}},Pi="doc.command.set-inline-format-fontsize",ge={id:Pi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Pi,t,e)}},wi="doc.command.set-inline-format-font-family",Ve={id:wi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(wi,t,e)}},Ui="doc.command.set-inline-format-text-color",Pe={id:Ui,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ui,t,e)}},Li="doc.command.set-inline-format-text-background-color",we={id:Li,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Li,t,e)}},Qi="doc.command.reset-inline-format-text-background-color",$e={id:Qi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Qi,t,e)}},$n={[xe.id]:"bl",[De.id]:"it",[Be.id]:"ul",[_e.id]:"st",[ge.id]:"fs",[Ve.id]:"ff",[Pe.id]:"cl",[we.id]:"bg",[$e.id]:"bg",[Ee.id]:"va",[Ne.id]:"va"},Ce={id:"doc.command.set-inline-format",type:a.CommandType.COMMAND,handler:async(o,t)=>{var R;const{value:e,preCommandId:n}=t,i=o.get(a.ICommandService),s=o.get(D.DocSelectionManagerService),r=o.get(a.IUniverInstanceService),c=o.get(ve),l=s.getDocRanges(),A=(R=l.find(v=>v.isActive))!=null?R:l[0];if(l.length===0)return!1;const{segmentId:d}=l[0],u=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(u==null)return!1;const m=u.getSelfOrHeaderFooterModel(d).getBody();if(m==null)return!1;const h=u.getUnitId();let g;switch(n){case xe.id:case De.id:case Be.id:case _e.id:case Ee.id:case Ne.id:{const v=c.getDefaultStyle(),O=Hi(m,A,v);g=$s(O,n);break}case ge.id:case Ve.id:{g=e;break}case Pe.id:case we.id:{g={rgb:e};break}case $e.id:{g={rgb:null};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:l}},f=new a.TextX,S=a.JSONX.getInstance(),E=new a.MemoryCursor;E.reset();for(const v of l){let{startOffset:O,endOffset:M,rangeType:b}=v;if(O==null||M==null)continue;if(b===a.DOC_RANGE_TYPE.RECT&&(O=O-1),O===M){const U=c.getStyleCache(),F=$n[n];c.setStyleCache({[F]:(U==null?void 0:U[F])!==void 0?Fi(U,F,n):g});continue}const N={dataStream:"",textRuns:[{st:0,ed:M-O,ts:{[$n[n]]:g}}]},x=O-E.cursor;x!==0&&f.push({t:a.TextXActionType.RETAIN,len:x}),f.push({t:a.TextXActionType.RETAIN,body:N,len:M-O}),E.reset(),E.moveCursor(M)}const C=Z(u,d);return p.params.actions=S.editOp(f.serialize(),C),!!i.syncExecuteCommand(p.id,p.params)}};function Zs(o){return o!==null&&typeof o=="object"}function Fi(o,t,e){if(/bl|it/.test(t))return(o==null?void 0:o[t])===a.BooleanNumber.TRUE?a.BooleanNumber.FALSE:a.BooleanNumber.TRUE;if(/ul|st/.test(t))return Zs(o==null?void 0:o[t])&&(o==null?void 0:o[t]).s===a.BooleanNumber.TRUE?{s:a.BooleanNumber.FALSE}:{s:a.BooleanNumber.TRUE};if(/va/.test(t))return e===Ee.id?(o==null?void 0:o[t])===a.BaselineOffset.SUBSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUBSCRIPT:(o==null?void 0:o[t])===a.BaselineOffset.SUPERSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUPERSCRIPT}function Hi(o,t,e){var d,u,m,h,g,p,f,S,E,C,T,R,v,O;const{startOffset:n,endOffset:i,collapsed:s}=t;if(s){const M=(d=o.textRuns)!=null?d:[];let b=null;for(let N=M.length-1;N>=0;N--){const x=M[N];if(x.st<n&&n<=x.ed){b=x;break}}return b!=null&&b.ts?{...e,...b.ts}:e}const{textRuns:r=[]}=a.getBodySlice(o,n,i),c=a.Tools.deepClone(e),l=r.map(M=>{var b;return(b=M==null?void 0:M.ts)==null?void 0:b.fs}).filter(Boolean);c.fs=c.fs?Math.max(c.fs,...l):l.length?Math.max(...l):void 0,c.fs=!c.fs||Number.isNaN(c.fs)?void 0:c.fs,c.ff=(h=(m=(u=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.ff)!=null}))==null?void 0:u.ts)==null?void 0:m.ff)!=null?h:c.ff,c.it=r.length&&r.every(M=>{var b;return((b=M.ts)==null?void 0:b.it)===a.BooleanNumber.TRUE})?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE,c.bl=r.length&&r.every(M=>{var b;return((b=M.ts)==null?void 0:b.bl)===a.BooleanNumber.TRUE})?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE,c.ul=r.length&&r.every(M=>{var b,N;return((N=(b=M.ts)==null?void 0:b.ul)==null?void 0:N.s)===a.BooleanNumber.TRUE})?(g=r[0].ts)==null?void 0:g.ul:c.ul,c.st=r.length&&r.every(M=>{var b,N;return((N=(b=M.ts)==null?void 0:b.st)==null?void 0:N.s)===a.BooleanNumber.TRUE})?(p=r[0].ts)==null?void 0:p.st:c.st,c.bg=(E=(S=(f=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.bg)!=null}))==null?void 0:f.ts)==null?void 0:S.bg)!=null?E:c.bg,c.cl=(R=(T=(C=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.cl)!=null}))==null?void 0:C.ts)==null?void 0:T.cl)!=null?R:c.cl;const A=r.filter(M=>{var b;return((b=M==null?void 0:M.ts)==null?void 0:b.va)!=null});if(A.length>0&&A.length===r.length){const M=(v=A[0].ts)==null?void 0:v.va;let b=!0;for(let N=1;N<A.length;N++)if(((O=A[N].ts)==null?void 0:O.va)!==M){b=!1;break}b&&(c.va=M)}return c}function $s(o,t){const e=$n[t];return Fi(o,e,t)}const eo={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)}},ki={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=Wi(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)}},Vi={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=Wi(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 er(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 Wi(o,t,e,n,i){const s={id:D.RichTextEditingMutation.id,params:{unitId:o,actions:[],textRanges:[]}},r=er(t,e,n,i);return s.params.actions=r,s}const to={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)}},Gi={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)}},ji={id:"doc.command.insert-custom-range",type:a.CommandType.COMMAND,handler:(o,t)=>{if(!t)return!1;const e=o.get(a.ICommandService),{unitId:n,rangeId:i=a.generateRandomId(),textRanges:s,properties:r,text:c,wholeEntity:l}=t,A={unitId:n,textRanges:s,body:{dataStream:c,customRanges:[{startIndex:0,endIndex:c.length-1,rangeId:i,rangeType:a.CustomRangeType.CUSTOM,properties:r,wholeEntity:l}]}};return e.syncExecuteCommand(to.id,A)}},et={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(o,t)=>{var T,R,v,O,M,b;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=t.listType,r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=(R=(T=t.docRange)!=null?T:e.getDocRanges())!=null?R:[];if(r==null||c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(O=(v=A.getBody())==null?void 0:v.paragraphs)!=null?O:[],u=(b=(M=A.getBody())==null?void 0:M.dataStream)!=null?b:"";if(!d.length)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}};new a.MemoryCursor().reset();const f=a.BuildTextUtils.paragraph.bullet.switch({paragraphs:m,listType:s,document:r,segmentId:l}),S=a.JSONX.getInstance(),E=Z(r,l);return g.params.actions=S.editOp(f.serialize(),E),!!i.syncExecuteCommand(g.id,g.params)}},It={id:"doc.command.change-list-type",type:a.CommandType.COMMAND,handler:(o,t)=>{var C,T,R,v,O;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),{listType:s}=t,r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=(C=t.docRange)!=null?C:e.getDocRanges();if(r==null||c==null||!c.length)return!1;const{segmentId:l}=c[0],A=r.getSelfOrHeaderFooterModel(l),d=(R=(T=A.getBody())==null?void 0:T.paragraphs)!=null?R:[],u=(O=(v=A.getBody())==null?void 0:v.dataStream)!=null?O:"";if(!d.length)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=a.BuildTextUtils.paragraph.bullet.set({paragraphs:m,listType:s,segmentId:l,document:r});if(!g)return!1;const p=a.JSONX.getInstance(),f={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}},S=Z(r,l);return f.params.actions=p.editOp(g.serialize(),S),!!i.syncExecuteCommand(f.id,f.params)}};var vt=(o=>(o[o.increase=1]="increase",o[o.decrease=-1]="decrease",o))(vt||{});const qt={id:"doc.command.change-list-nesting-level",type:a.CommandType.COMMAND,handler:(o,t)=>{var T,R,v,O,M;if(!t)return!1;const{type:e}=t,n=o.get(D.DocSelectionManagerService),i=o.get(a.IUniverInstanceService),s=o.get(a.ICommandService),r=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null)return!1;const{segmentId:l}=c,A=(T=n.getDocRanges())!=null?T:[],d=r.getSelfOrHeaderFooterModel(l),u=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"";if(!u.length)return!1;const h=a.BuildTextUtils.range.getParagraphsInRange(c,u,m),g=r.getUnitId(),p=a.JSONX.getInstance(),f=a.BuildTextUtils.paragraph.bullet.changeNestLevel({paragraphs:h,type:e,segmentId:l,document:r}),S={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:A,isEditing:!1}},E=Z(r,l);return S.params.actions=p.editOp(f.serialize(),E),!!s.syncExecuteCommand(S.id,S.params)}},tt={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(et.id,{listType:a.PresetListType.BULLET_LIST,docRange:t==null?void 0:t.docRange})}},Et={id:"doc.command.check-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(et.id,{listType:a.PresetListType.CHECK_LIST,docRange:t==null?void 0:t.docRange})}},no={id:"doc.command.toggle-check-list",type:a.CommandType.COMMAND,handler:(o,t)=>{var p;if(!t)return!1;const e=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),{index:i,segmentId:s,textRanges:r}=t,c=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(c==null||((p=c.getSelfOrHeaderFooterModel(s).getBody())==null?void 0:p.paragraphs)==null)return!1;const A=c.getUnitId(),d={id:D.RichTextEditingMutation.id,params:{unitId:A,actions:[],textRanges:r!=null?r:[],segmentId:s,isEditing:!1}},u=a.BuildTextUtils.paragraph.bullet.toggleChecklist({document:c,paragraphIndex:i,segmentId:s});if(!u)return!1;const m=a.JSONX.getInstance(),h=Z(c,s);return d.params.actions=m.editOp(u.serialize(),h),!!n.syncExecuteCommand(d.id,d.params)}},nt={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value}):e.syncExecuteCommand(et.id,{listType:a.PresetListType.ORDER_LIST})}},oo={id:"doc.command.quick-list",type:a.CommandType.COMMAND,handler(o,t){var x,U,F;if(!t)return!1;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),r=e.getActiveTextRange();if(s==null||r==null)return!1;const{segmentId:c,startOffset:l}=r,{listType:A,paragraph:d}=t,{paragraphStart:u,paragraphEnd:m}=d,h=new a.TextX,g=a.JSONX.getInstance(),{paragraphStyle:p={}}=d,S=(a.PRESET_LIST_TYPE[A].nestingLevel[0].paragraphProperties||{}).textStyle;let C=a.generateRandomId(6);const T=(U=(x=s.getBody())==null?void 0:x.paragraphs)!=null?U:[],R=T.findIndex(V=>V.startIndex===d.startIndex),v=T[R-1],O=T[R+1];v&&v.bullet&&v.bullet.listType.indexOf(A)===0?C=v.bullet.listId:O&&O.bullet&&O.bullet.listType.indexOf(A)===0&&(C=O.bullet.listId);const M={id:D.RichTextEditingMutation.id,params:{unitId:s.getUnitId(),actions:[],textRanges:[{startOffset:u,endOffset:u,collapsed:!0}],isEditing:!1}};h.push({t:a.TextXActionType.RETAIN,len:u}),h.push({t:a.TextXActionType.DELETE,len:l-u}),m>l&&h.push({t:a.TextXActionType.RETAIN,len:m-l}),h.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{startIndex:0,paragraphStyle:{...p,textStyle:{...p.textStyle,...S},indentFirstLine:void 0},bullet:{...(F=d.bullet)!=null?F:{nestingLevel:0,textStyle:{fs:20}},listType:A,listId:C}}]}});const b=Z(s,c);return M.params.actions=g.editOp(h.serialize(),b),!!i.syncExecuteCommand(M.id,M.params)}};function io(o,t){var d,u;const e=o.get(a.ICommandService),n=ht(o);if(!n)return!1;const i=o.get(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!i)return!1;const s=a.BuildTextUtils.selection.replace({doc:i,selection:{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0},body:{dataStream:"\r",paragraphs:[{startIndex:0,paragraphStyle:{...n.paragraphStyle},bullet:{listType:t,listId:((d=n.bullet)==null?void 0:d.listType)===t?n.bullet.listId:a.generateRandomId(6),nestingLevel:((u=n.bullet)==null?void 0:u.listType)===t?n.bullet.nestingLevel:0}}]}});if(!s)return!1;const r={id:D.RichTextEditingMutation.id,params:{unitId:i.getUnitId(),actions:[],textRanges:[{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0}],isEditing:!1}},c=a.JSONX.getInstance(),l=Z(i);return r.params.actions=c.editOp(s.serialize(),l),!!e.syncExecuteCommand(r.id,r.params)}const ao={id:"doc.command.insert-bullet-list-bellow",type:a.CommandType.COMMAND,handler:o=>io(o,a.PresetListType.BULLET_LIST)},so={id:"doc.command.insert-order-list-bellow",type:a.CommandType.COMMAND,handler:o=>io(o,a.PresetListType.ORDER_LIST)},ro={id:"doc.command.insert-check-list-bellow",type:a.CommandType.COMMAND,handler:o=>io(o,a.PresetListType.CHECK_LIST)},me={id:"doc.command.align-action",type:a.CommandType.COMMAND,handler:(o,t)=>{var R,v,O,M;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),{alignType:s}=t,r=n.getCurrentUniverDocInstance();if(r==null)return!1;const c=e.getDocRanges();if(c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(v=(R=A.getBody())==null?void 0:R.paragraphs)!=null?v:[],u=(M=(O=A.getBody())==null?void 0:O.dataStream)!=null?M:"";if(d==null)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=m.every(b=>{var N;return((N=b.paragraphStyle)==null?void 0:N.horizontalAlign)===s}),p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c}},f=new a.MemoryCursor;f.reset();const S=new a.TextX,E=a.JSONX.getInstance();for(const b of m){const{startIndex:N}=b;S.push({t:a.TextXActionType.RETAIN,len:N-f.cursor});const x={...b.paragraphStyle,horizontalAlign:g?a.HorizontalAlign.UNSPECIFIED:s};S.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...b,paragraphStyle:x,startIndex:0}]},coverType:a.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(N+1)}const C=Z(r,l);return p.params.actions=E.editOp(S.serialize(),C),!!i.syncExecuteCommand(p.id,p.params)}},Ct={id:"doc.command.align-left",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.LEFT})},Tt={id:"doc.command.align-center",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.CENTER})},yt={id:"doc.command.align-right",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.RIGHT})},bt={id:"doc.command.align-justify",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.JUSTIFIED})},tr=(o,t)=>{const e=o.get(a.IUniverInstanceService).getUniverDocInstance(t.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...a.Tools.deepClone(t),zoomRatio:n}},he={id:"doc.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(o,t)=>{const e=o.get(a.IUniverInstanceService).getUniverDocInstance(t.unitId);if(!e)return!1;const n=e.getSnapshot();return n.settings==null?n.settings={zoomRatio:t.zoomRatio}:n.settings.zoomRatio=t.zoomRatio,!0}},Ot={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,t)=>{var u,m,h;const e=o.get(a.ICommandService),n=o.get(a.IUndoRedoService),i=o.get(a.IUniverInstanceService);let s=(u=i.getCurrentUniverDocInstance())==null?void 0:u.getUnitId();if(!s)return!1;let r=1;if(t&&(s=(m=t.documentId)!=null?m:s,r=(h=t.zoomRatio)!=null?h:r),!i.getUniverDocInstance(s))return!1;const l={zoomRatio:r,unitId:s},A=tr(o,l);return e.syncExecuteCommand(he.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:he.id,params:A}],redoMutations:[{id:he.id,params:l}]}),!0):!1}},ce={id:"doc.command.set-paragraph-named-style",type:a.CommandType.COMMAND,handler(o,t){var g;if(!t)return!1;const n=o.get(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!n)return!1;const i=n.getUnitId(),s=o.get(D.DocSelectionManagerService),r=(g=t.textRanges)!=null?g:s.getTextRanges({unitId:i,subUnitId:i});if(!(r!=null&&r.length))return!1;const c=r[0].segmentId,l=a.BuildTextUtils.paragraph.style.set({document:n.getSelfOrHeaderFooterModel(c),textRanges:r,style:{namedStyleType:t.value,headingId:!t.value||t.value===a.NamedStyleType.NORMAL_TEXT?void 0:a.generateRandomId(6),spaceAbove:void 0,spaceBelow:void 0,lineSpacing:void 0},paragraphTextRun:{}}),A={id:D.RichTextEditingMutation.id,params:{actions:[],textRanges:r,unitId:i,segmentId:c}},d=a.JSONX.getInstance(),u=Z(n,c);return A.params.actions=d.editOp(l.serialize(),u),!!o.get(a.ICommandService).syncExecuteCommand(A.id,A.params)}},Xi={id:"doc.command.quick-heading",type:a.CommandType.COMMAND,handler(o,t){var R,v,O,M;if(!t)return!1;const{value:e}=t,n=o.get(D.DocSelectionManagerService),i=o.get(a.IUniverInstanceService),s=o.get(a.ICommandService),r=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null||!c.collapsed)return!1;const{segmentId:l,startOffset:A}=c,d=r.getSelfOrHeaderFooterModel(l),u=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"",h=a.BuildTextUtils.paragraph.util.getParagraphsInRange(c,u,m)[0];if(!h)return!1;const{paragraphStart:g}=h,p=new a.TextX,f=a.JSONX.getInstance(),{paragraphStyle:S={}}=h,E={id:D.RichTextEditingMutation.id,params:{unitId:r.getUnitId(),actions:[],textRanges:[{startOffset:g,endOffset:g,collapsed:!0}],isEditing:!1}};p.push({t:a.TextXActionType.RETAIN,len:g}),a.BuildTextUtils.paragraph.style.set({textRanges:[c],document:r,style:{...S,headingId:a.generateRandomId(6),namedStyleType:e},cursor:A,deleteLen:A-g,textX:p,paragraphTextRun:{}});const C=Z(r,l);return E.params.actions=f.editOp(p.serialize(),C),!!s.syncExecuteCommand(E.id,E.params)}},co={"#":a.NamedStyleType.HEADING_1,"##":a.NamedStyleType.HEADING_2,"###":a.NamedStyleType.HEADING_3,"####":a.NamedStyleType.HEADING_4,"#####":a.NamedStyleType.HEADING_5},lo={id:"doc.command.h1-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_1})},Ao={id:"doc.command.h2-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_2})},uo={id:"doc.command.h3-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_3})},ho={id:"doc.command.h4-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_4})},go={id:"doc.command.h5-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_5})},Jt={id:"doc.command.normal-text-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.NORMAL_TEXT})},Ki={id:"doc.command.title",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.TITLE})},zi={id:"doc.command.subtitle-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.SUBTITLE})};var Zt=(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))(Zt||{});const ot={page:0,section:1,column:2,line:3,divide:4,glyph:5};function mo(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 po(o,t){return mo(o,t)?{start:o,end:t}:{start:t,end:o}}function fo(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 nr(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 So(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 Te{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(`
|
|
11
|
+
`)return!0;const u=[];let m=0;for(const g of A){const{startIndex:p,endIndex:f}=g;m!==p&&u.push({startOffset:m,endOffset:p-1,rangeType:a.DOC_RANGE_TYPE.TEXT}),u.push({startOffset:p+3,endOffset:f-5,rangeType:a.DOC_RANGE_TYPE.RECT}),m=f}return m!==l.dataStream.length-2&&u.push({startOffset:m,endOffset:l.dataStream.length-2,rangeType:a.DOC_RANGE_TYPE.TEXT}),e.replaceDocRanges(u,{unitId:c,subUnitId:c},!1),!0}};class St extends a.RxDisposable{constructor(e){super();B(this,"_previousActiveRange",null);B(this,"_undoMutationParamsCache",[]);B(this,"_redoMutationParamsCache",[]);this._context=e}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}getUndoRedoMutationParamsCache(){return{undoCache:this._undoMutationParamsCache,redoCache:this._redoMutationParamsCache}}setUndoRedoMutationParamsCache({undoCache:e=[],redoCache:n=[]}){this._undoMutationParamsCache=e,this._redoMutationParamsCache=n}getActiveRange(){return this._previousActiveRange}setActiveRange(e){this._previousActiveRange=e}pushUndoRedoMutationParams(e,n){this._undoMutationParamsCache.push(e),this._redoMutationParamsCache.push(n)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:e}=this._undoMutationParamsCache[0],n={unitId:e,actions:this._undoMutationParamsCache.reverse().reduce((s,r)=>a.JSONX.compose(s,r.actions),null),textRanges:[]};return{redoMutationParams:{unitId:e,actions:this._redoMutationParamsCache.reduce((s,r)=>a.JSONX.compose(s,r.actions),null),textRanges:[]},undoMutationParams:n,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Zn={id:"doc.command.ime-input",type:a.CommandType.COMMAND,handler:async(o,t)=>{var Q,X,j;const{unitId:e,newText:n,oldTextLen:i,isCompositionEnd:s,isCompositionStart:r}=t,c=o.get(a.ICommandService),l=o.get(_.IRenderManagerService),A=o.get(a.IUniverInstanceService),d=o.get(ve),u=(Q=l.getRenderById(e))==null?void 0:Q.with(St),m=A.getUnit(e,a.UniverInstanceType.UNIVER_DOC);if(m==null||u==null)return!1;const h=u.getActiveRange();if(h==null)return!1;const{style:g,segmentId:p}=h,f=m.getSelfOrHeaderFooterModel(p).getBody();if(f==null)return!1;Object.assign(h,h);const{startOffset:E,endOffset:C}=h,T=n.length,R=[{startOffset:E+T,endOffset:E+T,collapsed:!0,style:g}],v={id:D.RichTextEditingMutation.id,params:{unitId:e,actions:[],textRanges:R}},O=d.getDefaultStyle(),M=d.getStyleCache(),b=Bn((X=f.customRanges)!=null?X:[],E+i,a.SHEET_EDITOR_UNITS.includes(e)),N=Lt(f,r?C:E+i,O,M,a.SHEET_EDITOR_UNITS.includes(e)),x=_n((j=f.customDecorations)!=null?j:[],E+i),U=new a.TextX,F=a.JSONX.getInstance();if(!h.collapsed&&r){const k=a.BuildTextUtils.selection.delete([h],f,0,null,!1);U.push(...k),v.params.textRanges=[{startOffset:E+T,endOffset:E+T,collapsed:!0}]}else U.push({t:a.TextXActionType.RETAIN,len:E});i>0&&U.push({t:a.TextXActionType.DELETE,len:i}),U.push({t:a.TextXActionType.INSERT,body:{dataStream:n,textRuns:N?[{...N,st:0,ed:n.length}]:[],customRanges:b?[{...b,startIndex:0,endIndex:n.length-1}]:[],customDecorations:x.map(k=>({...k,startIndex:0,endIndex:n.length-1}))},len:n.length});const V=Z(m,p);v.params.actions=F.editOp(U.serialize(),V),v.params.noHistory=!s,v.params.isCompositionEnd=s;const H=c.syncExecuteCommand(v.id,v.params);return u.pushUndoRedoMutationParams(H,v.params),!!H}};function ue(o,t,e){return e.executeCommand(Ce.id,{preCommandId:o,...t!=null?t:{}})}const Mi="doc.command.set-inline-format-bold",xe={id:Mi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Mi,t,e)}},xi="doc.command.set-inline-format-italic",De={id:xi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(xi,t,e)}},Di="doc.command.set-inline-format-underline",Be={id:Di,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Di,t,e)}},Bi="doc.command.set-inline-format-strikethrough",_e={id:Bi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Bi,t,e)}},_i="doc.command.set-inline-format-subscript",Ee={id:_i,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(_i,t,e)}},Ni="doc.command.set-inline-format-superscript",Ne={id:Ni,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ni,t,e)}},Pi="doc.command.set-inline-format-fontsize",ge={id:Pi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Pi,t,e)}},wi="doc.command.set-inline-format-font-family",Ve={id:wi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(wi,t,e)}},Ui="doc.command.set-inline-format-text-color",Pe={id:Ui,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Ui,t,e)}},Li="doc.command.set-inline-format-text-background-color",we={id:Li,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Li,t,e)}},Qi="doc.command.reset-inline-format-text-background-color",$e={id:Qi,type:a.CommandType.COMMAND,handler:async(o,t)=>{const e=o.get(a.ICommandService);return ue(Qi,t,e)}},$n={[xe.id]:"bl",[De.id]:"it",[Be.id]:"ul",[_e.id]:"st",[ge.id]:"fs",[Ve.id]:"ff",[Pe.id]:"cl",[we.id]:"bg",[$e.id]:"bg",[Ee.id]:"va",[Ne.id]:"va"},Ce={id:"doc.command.set-inline-format",type:a.CommandType.COMMAND,handler:async(o,t)=>{var R;const{value:e,preCommandId:n}=t,i=o.get(a.ICommandService),s=o.get(D.DocSelectionManagerService),r=o.get(a.IUniverInstanceService),c=o.get(ve),l=s.getDocRanges(),A=(R=l.find(v=>v.isActive))!=null?R:l[0];if(l.length===0)return!1;const{segmentId:d}=l[0],u=r.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(u==null)return!1;const m=u.getSelfOrHeaderFooterModel(d).getBody();if(m==null)return!1;const h=u.getUnitId();let g;switch(n){case xe.id:case De.id:case Be.id:case _e.id:case Ee.id:case Ne.id:{const v=c.getDefaultStyle(),O=Hi(m,A,v);g=$s(O,n);break}case ge.id:case Ve.id:{g=e;break}case Pe.id:case we.id:{g={rgb:e};break}case $e.id:{g={rgb:null};break}default:throw new Error(`Unknown command: ${n} in handleInlineFormat`)}const p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:l}},f=new a.TextX,S=a.JSONX.getInstance(),E=new a.MemoryCursor;E.reset();for(const v of l){let{startOffset:O,endOffset:M,rangeType:b}=v;if(O==null||M==null)continue;if(b===a.DOC_RANGE_TYPE.RECT&&(O=O-1),O===M){const U=c.getStyleCache(),F=$n[n];c.setStyleCache({[F]:(U==null?void 0:U[F])!==void 0?Fi(U,F,n):g});continue}const N={dataStream:"",textRuns:[{st:0,ed:M-O,ts:{[$n[n]]:g}}]},x=O-E.cursor;x!==0&&f.push({t:a.TextXActionType.RETAIN,len:x}),f.push({t:a.TextXActionType.RETAIN,body:N,len:M-O}),E.reset(),E.moveCursor(M)}const C=Z(u,d);return p.params.actions=S.editOp(f.serialize(),C),!!i.syncExecuteCommand(p.id,p.params)}};function Zs(o){return o!==null&&typeof o=="object"}function Fi(o,t,e){if(/bl|it/.test(t))return(o==null?void 0:o[t])===a.BooleanNumber.TRUE?a.BooleanNumber.FALSE:a.BooleanNumber.TRUE;if(/ul|st/.test(t))return Zs(o==null?void 0:o[t])&&(o==null?void 0:o[t]).s===a.BooleanNumber.TRUE?{s:a.BooleanNumber.FALSE}:{s:a.BooleanNumber.TRUE};if(/va/.test(t))return e===Ee.id?(o==null?void 0:o[t])===a.BaselineOffset.SUBSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUBSCRIPT:(o==null?void 0:o[t])===a.BaselineOffset.SUPERSCRIPT?a.BaselineOffset.NORMAL:a.BaselineOffset.SUPERSCRIPT}function Hi(o,t,e){var d,u,m,h,g,p,f,S,E,C,T,R,v,O;const{startOffset:n,endOffset:i,collapsed:s}=t;if(s){const M=(d=o.textRuns)!=null?d:[];let b=null;for(let N=M.length-1;N>=0;N--){const x=M[N];if(x.st<n&&n<=x.ed){b=x;break}}return b!=null&&b.ts?{...e,...b.ts}:e}const{textRuns:r=[]}=a.getBodySlice(o,n,i),c=a.Tools.deepClone(e),l=r.map(M=>{var b;return(b=M==null?void 0:M.ts)==null?void 0:b.fs}).filter(Boolean);c.fs=c.fs?Math.max(c.fs,...l):l.length?Math.max(...l):void 0,c.fs=!c.fs||Number.isNaN(c.fs)?void 0:c.fs,c.ff=(h=(m=(u=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.ff)!=null}))==null?void 0:u.ts)==null?void 0:m.ff)!=null?h:c.ff,c.it=r.length&&r.every(M=>{var b;return((b=M.ts)==null?void 0:b.it)===a.BooleanNumber.TRUE})?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE,c.bl=r.length&&r.every(M=>{var b;return((b=M.ts)==null?void 0:b.bl)===a.BooleanNumber.TRUE})?a.BooleanNumber.TRUE:a.BooleanNumber.FALSE,c.ul=r.length&&r.every(M=>{var b,N;return((N=(b=M.ts)==null?void 0:b.ul)==null?void 0:N.s)===a.BooleanNumber.TRUE})?(g=r[0].ts)==null?void 0:g.ul:c.ul,c.st=r.length&&r.every(M=>{var b,N;return((N=(b=M.ts)==null?void 0:b.st)==null?void 0:N.s)===a.BooleanNumber.TRUE})?(p=r[0].ts)==null?void 0:p.st:c.st,c.bg=(E=(S=(f=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.bg)!=null}))==null?void 0:f.ts)==null?void 0:S.bg)!=null?E:c.bg,c.cl=(R=(T=(C=r.find(M=>{var b;return((b=M.ts)==null?void 0:b.cl)!=null}))==null?void 0:C.ts)==null?void 0:T.cl)!=null?R:c.cl;const A=r.filter(M=>{var b;return((b=M==null?void 0:M.ts)==null?void 0:b.va)!=null});if(A.length>0&&A.length===r.length){const M=(v=A[0].ts)==null?void 0:v.va;let b=!0;for(let N=1;N<A.length;N++)if(((O=A[N].ts)==null?void 0:O.va)!==M){b=!1;break}b&&(c.va=M)}return c}function $s(o,t){const e=$n[t];return Fi(o,e,t)}const eo={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)}},ki={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=Wi(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)}},Vi={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=Wi(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 er(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 Wi(o,t,e,n,i){const s={id:D.RichTextEditingMutation.id,params:{unitId:o,actions:[],textRanges:[]}},r=er(t,e,n,i);return s.params.actions=r,s}const to={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)}},Gi={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)}},ji={id:"doc.command.insert-custom-range",type:a.CommandType.COMMAND,handler:(o,t)=>{if(!t)return!1;const e=o.get(a.ICommandService),{unitId:n,rangeId:i=a.generateRandomId(),textRanges:s,properties:r,text:c,wholeEntity:l}=t,A={unitId:n,textRanges:s,body:{dataStream:c,customRanges:[{startIndex:0,endIndex:c.length-1,rangeId:i,rangeType:a.CustomRangeType.CUSTOM,properties:r,wholeEntity:l}]}};return e.syncExecuteCommand(to.id,A)}},et={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(o,t)=>{var T,R,v,O,M,b;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=t.listType,r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=(R=(T=t.docRange)!=null?T:e.getDocRanges())!=null?R:[];if(r==null||c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(O=(v=A.getBody())==null?void 0:v.paragraphs)!=null?O:[],u=(b=(M=A.getBody())==null?void 0:M.dataStream)!=null?b:"";if(!d.length)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}};new a.MemoryCursor().reset();const f=a.BuildTextUtils.paragraph.bullet.switch({paragraphs:m,listType:s,document:r,segmentId:l}),S=a.JSONX.getInstance(),E=Z(r,l);return g.params.actions=S.editOp(f.serialize(),E),!!i.syncExecuteCommand(g.id,g.params)}},It={id:"doc.command.change-list-type",type:a.CommandType.COMMAND,handler:(o,t)=>{var C,T,R,v,O;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),{listType:s}=t,r=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=(C=t.docRange)!=null?C:e.getDocRanges();if(r==null||c==null||!c.length)return!1;const{segmentId:l}=c[0],A=r.getSelfOrHeaderFooterModel(l),d=(R=(T=A.getBody())==null?void 0:T.paragraphs)!=null?R:[],u=(O=(v=A.getBody())==null?void 0:v.dataStream)!=null?O:"";if(!d.length)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=a.BuildTextUtils.paragraph.bullet.set({paragraphs:m,listType:s,segmentId:l,document:r});if(!g)return!1;const p=a.JSONX.getInstance(),f={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c,isEditing:!1}},S=Z(r,l);return f.params.actions=p.editOp(g.serialize(),S),!!i.syncExecuteCommand(f.id,f.params)}};var vt=(o=>(o[o.increase=1]="increase",o[o.decrease=-1]="decrease",o))(vt||{});const qt={id:"doc.command.change-list-nesting-level",type:a.CommandType.COMMAND,handler:(o,t)=>{var T,R,v,O,M;if(!t)return!1;const{type:e}=t,n=o.get(D.DocSelectionManagerService),i=o.get(a.IUniverInstanceService),s=o.get(a.ICommandService),r=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null)return!1;const{segmentId:l}=c,A=(T=n.getDocRanges())!=null?T:[],d=r.getSelfOrHeaderFooterModel(l),u=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"";if(!u.length)return!1;const h=a.BuildTextUtils.range.getParagraphsInRange(c,u,m),g=r.getUnitId(),p=a.JSONX.getInstance(),f=a.BuildTextUtils.paragraph.bullet.changeNestLevel({paragraphs:h,type:e,segmentId:l,document:r}),S={id:D.RichTextEditingMutation.id,params:{unitId:g,actions:[],textRanges:A,isEditing:!1}},E=Z(r,l);return S.params.actions=p.editOp(f.serialize(),E),!!s.syncExecuteCommand(S.id,S.params)}},tt={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(et.id,{listType:a.PresetListType.BULLET_LIST,docRange:t==null?void 0:t.docRange})}},Et={id:"doc.command.check-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value,docRange:t.docRange}):e.syncExecuteCommand(et.id,{listType:a.PresetListType.CHECK_LIST,docRange:t==null?void 0:t.docRange})}},no={id:"doc.command.toggle-check-list",type:a.CommandType.COMMAND,handler:(o,t)=>{var p;if(!t)return!1;const e=o.get(a.IUniverInstanceService),n=o.get(a.ICommandService),{index:i,segmentId:s,textRanges:r}=t,c=e.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC);if(c==null||((p=c.getSelfOrHeaderFooterModel(s).getBody())==null?void 0:p.paragraphs)==null)return!1;const A=c.getUnitId(),d={id:D.RichTextEditingMutation.id,params:{unitId:A,actions:[],textRanges:r!=null?r:[],segmentId:s,isEditing:!1}},u=a.BuildTextUtils.paragraph.bullet.toggleChecklist({document:c,paragraphIndex:i,segmentId:s});if(!u)return!1;const m=a.JSONX.getInstance(),h=Z(c,s);return d.params.actions=m.editOp(u.serialize(),h),!!n.syncExecuteCommand(d.id,d.params)}},nt={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:(o,t)=>{const e=o.get(a.ICommandService);return t!=null&&t.value?e.syncExecuteCommand(It.id,{listType:t.value}):e.syncExecuteCommand(et.id,{listType:a.PresetListType.ORDER_LIST})}},oo={id:"doc.command.quick-list",type:a.CommandType.COMMAND,handler(o,t){var x,U,F;if(!t)return!1;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),s=n.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),r=e.getActiveTextRange();if(s==null||r==null)return!1;const{segmentId:c,startOffset:l}=r,{listType:A,paragraph:d}=t,{paragraphStart:u,paragraphEnd:m}=d,h=new a.TextX,g=a.JSONX.getInstance(),{paragraphStyle:p={}}=d,S=(a.PRESET_LIST_TYPE[A].nestingLevel[0].paragraphProperties||{}).textStyle;let C=a.generateRandomId(6);const T=(U=(x=s.getBody())==null?void 0:x.paragraphs)!=null?U:[],R=T.findIndex(V=>V.startIndex===d.startIndex),v=T[R-1],O=T[R+1];v&&v.bullet&&v.bullet.listType.indexOf(A)===0?C=v.bullet.listId:O&&O.bullet&&O.bullet.listType.indexOf(A)===0&&(C=O.bullet.listId);const M={id:D.RichTextEditingMutation.id,params:{unitId:s.getUnitId(),actions:[],textRanges:[{startOffset:u,endOffset:u,collapsed:!0}],isEditing:!1}};h.push({t:a.TextXActionType.RETAIN,len:u}),h.push({t:a.TextXActionType.DELETE,len:l-u}),m>l&&h.push({t:a.TextXActionType.RETAIN,len:m-l}),h.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{startIndex:0,paragraphStyle:{...p,textStyle:{...p.textStyle,...S},indentFirstLine:void 0},bullet:{...(F=d.bullet)!=null?F:{nestingLevel:0,textStyle:{fs:20}},listType:A,listId:C}}]}});const b=Z(s,c);return M.params.actions=g.editOp(h.serialize(),b),!!i.syncExecuteCommand(M.id,M.params)}};function io(o,t){var d,u;const e=o.get(a.ICommandService),n=ht(o);if(!n)return!1;const i=o.get(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!i)return!1;const s=a.BuildTextUtils.selection.replace({doc:i,selection:{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0},body:{dataStream:"\r",paragraphs:[{startIndex:0,paragraphStyle:{...n.paragraphStyle},bullet:{listType:t,listId:((d=n.bullet)==null?void 0:d.listType)===t?n.bullet.listId:a.generateRandomId(6),nestingLevel:((u=n.bullet)==null?void 0:u.listType)===t?n.bullet.nestingLevel:0}}]}});if(!s)return!1;const r={id:D.RichTextEditingMutation.id,params:{unitId:i.getUnitId(),actions:[],textRanges:[{startOffset:n.startIndex+1,endOffset:n.startIndex+1,collapsed:!0}],isEditing:!1}},c=a.JSONX.getInstance(),l=Z(i);return r.params.actions=c.editOp(s.serialize(),l),!!e.syncExecuteCommand(r.id,r.params)}const ao={id:"doc.command.insert-bullet-list-bellow",type:a.CommandType.COMMAND,handler:o=>io(o,a.PresetListType.BULLET_LIST)},so={id:"doc.command.insert-order-list-bellow",type:a.CommandType.COMMAND,handler:o=>io(o,a.PresetListType.ORDER_LIST)},ro={id:"doc.command.insert-check-list-bellow",type:a.CommandType.COMMAND,handler:o=>io(o,a.PresetListType.CHECK_LIST)},me={id:"doc.command.align-action",type:a.CommandType.COMMAND,handler:(o,t)=>{var R,v,O,M;const e=o.get(D.DocSelectionManagerService),n=o.get(a.IUniverInstanceService),i=o.get(a.ICommandService),{alignType:s}=t,r=n.getCurrentUniverDocInstance();if(r==null)return!1;const c=e.getDocRanges();if(c.length===0)return!1;const l=c[0].segmentId,A=r.getSelfOrHeaderFooterModel(l),d=(v=(R=A.getBody())==null?void 0:R.paragraphs)!=null?v:[],u=(M=(O=A.getBody())==null?void 0:O.dataStream)!=null?M:"";if(d==null)return!1;const m=a.BuildTextUtils.range.getParagraphsInRanges(c,d,u),h=r.getUnitId(),g=m.every(b=>{var N;return((N=b.paragraphStyle)==null?void 0:N.horizontalAlign)===s}),p={id:D.RichTextEditingMutation.id,params:{unitId:h,actions:[],textRanges:c}},f=new a.MemoryCursor;f.reset();const S=new a.TextX,E=a.JSONX.getInstance();for(const b of m){const{startIndex:N}=b;S.push({t:a.TextXActionType.RETAIN,len:N-f.cursor});const x={...b.paragraphStyle,horizontalAlign:g?a.HorizontalAlign.UNSPECIFIED:s};S.push({t:a.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[{...b,paragraphStyle:x,startIndex:0}]},coverType:a.UpdateDocsAttributeType.REPLACE}),f.moveCursorTo(N+1)}const C=Z(r,l);return p.params.actions=E.editOp(S.serialize(),C),!!i.syncExecuteCommand(p.id,p.params)}},Ct={id:"doc.command.align-left",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.LEFT})},Tt={id:"doc.command.align-center",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.CENTER})},yt={id:"doc.command.align-right",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.RIGHT})},bt={id:"doc.command.align-justify",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(me.id,{alignType:a.HorizontalAlign.JUSTIFIED})},tr=(o,t)=>{const n=o.get(a.IUniverInstanceService).getUnit(t.unitId,a.UniverInstanceType.UNIVER_DOC);return n==null||n.setZoomRatio(t.zoomRatio),{...t}},he={id:"doc.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(o,t)=>{const n=o.get(a.IUniverInstanceService).getUnit(t.unitId,a.UniverInstanceType.UNIVER_DOC);return n?(n.setZoomRatio(t.zoomRatio),!0):!1}},Ot={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(o,t)=>{var u,m,h;const e=o.get(a.ICommandService),n=o.get(a.IUndoRedoService),i=o.get(a.IUniverInstanceService);let s=(u=i.getCurrentUniverDocInstance())==null?void 0:u.getUnitId();if(!s)return!1;let r=1;if(t&&(s=(m=t.documentId)!=null?m:s,r=(h=t.zoomRatio)!=null?h:r),!i.getUniverDocInstance(s))return!1;const l={zoomRatio:r,unitId:s},A=tr(o,l);return e.syncExecuteCommand(he.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:he.id,params:A}],redoMutations:[{id:he.id,params:l}]}),!0):!1}},ce={id:"doc.command.set-paragraph-named-style",type:a.CommandType.COMMAND,handler(o,t){var g;if(!t)return!1;const n=o.get(a.IUniverInstanceService).getCurrentUnitOfType(a.UniverInstanceType.UNIVER_DOC);if(!n)return!1;const i=n.getUnitId(),s=o.get(D.DocSelectionManagerService),r=(g=t.textRanges)!=null?g:s.getTextRanges({unitId:i,subUnitId:i});if(!(r!=null&&r.length))return!1;const c=r[0].segmentId,l=a.BuildTextUtils.paragraph.style.set({document:n.getSelfOrHeaderFooterModel(c),textRanges:r,style:{namedStyleType:t.value,headingId:!t.value||t.value===a.NamedStyleType.NORMAL_TEXT?void 0:a.generateRandomId(6),spaceAbove:void 0,spaceBelow:void 0,lineSpacing:void 0},paragraphTextRun:{}}),A={id:D.RichTextEditingMutation.id,params:{actions:[],textRanges:r,unitId:i,segmentId:c}},d=a.JSONX.getInstance(),u=Z(n,c);return A.params.actions=d.editOp(l.serialize(),u),!!o.get(a.ICommandService).syncExecuteCommand(A.id,A.params)}},Xi={id:"doc.command.quick-heading",type:a.CommandType.COMMAND,handler(o,t){var R,v,O,M;if(!t)return!1;const{value:e}=t,n=o.get(D.DocSelectionManagerService),i=o.get(a.IUniverInstanceService),s=o.get(a.ICommandService),r=i.getCurrentUnitForType(a.UniverInstanceType.UNIVER_DOC),c=n.getActiveTextRange();if(r==null||c==null||!c.collapsed)return!1;const{segmentId:l,startOffset:A}=c,d=r.getSelfOrHeaderFooterModel(l),u=(v=(R=d.getBody())==null?void 0:R.paragraphs)!=null?v:[],m=(M=(O=d.getBody())==null?void 0:O.dataStream)!=null?M:"",h=a.BuildTextUtils.paragraph.util.getParagraphsInRange(c,u,m)[0];if(!h)return!1;const{paragraphStart:g}=h,p=new a.TextX,f=a.JSONX.getInstance(),{paragraphStyle:S={}}=h,E={id:D.RichTextEditingMutation.id,params:{unitId:r.getUnitId(),actions:[],textRanges:[{startOffset:g,endOffset:g,collapsed:!0}],isEditing:!1}};p.push({t:a.TextXActionType.RETAIN,len:g}),a.BuildTextUtils.paragraph.style.set({textRanges:[c],document:r,style:{...S,headingId:a.generateRandomId(6),namedStyleType:e},cursor:A,deleteLen:A-g,textX:p,paragraphTextRun:{}});const C=Z(r,l);return E.params.actions=f.editOp(p.serialize(),C),!!s.syncExecuteCommand(E.id,E.params)}},co={"#":a.NamedStyleType.HEADING_1,"##":a.NamedStyleType.HEADING_2,"###":a.NamedStyleType.HEADING_3,"####":a.NamedStyleType.HEADING_4,"#####":a.NamedStyleType.HEADING_5},lo={id:"doc.command.h1-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_1})},Ao={id:"doc.command.h2-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_2})},uo={id:"doc.command.h3-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_3})},ho={id:"doc.command.h4-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_4})},go={id:"doc.command.h5-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.HEADING_5})},Jt={id:"doc.command.normal-text-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.NORMAL_TEXT})},Ki={id:"doc.command.title",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.TITLE})},zi={id:"doc.command.subtitle-heading",type:a.CommandType.COMMAND,handler:o=>o.get(a.ICommandService).syncExecuteCommand(ce.id,{value:a.NamedStyleType.SUBTITLE})};var Zt=(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))(Zt||{});const ot={page:0,section:1,column:2,line:3,divide:4,glyph:5};function mo(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 po(o,t){return mo(o,t)?{start:o,end:t}:{start:t,end:o}}function fo(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 nr(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 So(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 Te{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(`
|
|
12
12
|
Invalid positions in NodePositionConvertToCursor,
|
|
13
13
|
they are not in the same segment page when in header or footer.`);const{start:c,end:l}=po(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}=nr(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(So(M)),i.push(So(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=Zt[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=Zt[t],A=Zt[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(ot.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(ot.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(ot.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(ot.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(ot.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 Yi(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 Io(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 qi(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 vo(o,t){if(Io(o,t))return mo(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 it(o){return o.sections[0].columns[0].lines.length===0}function or(o,t,e){let n=t,i=e,s=o[n],r=o[i];for(;n<i&&(it(s)||it(r));)it(s)?(n++,s=o[n]):it(r)&&(i--,r=o[i]);if(!it(s)&&!it(r))return[s,r]}class Eo{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=or(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(So(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 ir="__TestSelectionRange__",ar="__TestSelectionAnchor__",Ji=6,Co=500,sr=500,$t=3;function Rt(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 en(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 We{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()},Co),this._anchorBlinkTimer=setInterval(()=>{this._anchorShape&&this._anchorShape.visible&&(this.activeStatic(),setTimeout(()=>{this.deactivateStatic()},Co))},sr+Co)}get startOffset(){var i;const{startOffset:t}=(i=fo(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=fo(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}=po(this.anchorNodePosition,this.focusNodePosition);return t}get endNodePosition(){if(this.anchorNodePosition==null)return this.focusNodePosition;if(this.focusNodePosition==null)return null;const{end:t}=po(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:mo(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 Te(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=Rt(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=Rt(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 Te(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(ot);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(ir+a.generateRandomId(Ji),{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,$t)}_createOrUpdateAnchor(t,e,n,i){var p,f,S;const s=Rt(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(-d,0):this._anchorShape.skew(0,0);return}const g=new _.Rect(ar+a.generateRandomId(Ji),{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(-d,0),this._anchorShape=g,this._scene.addObject(g,$t),this.activeStatic()}_setCursorList(t){t.length!==0&&(this._cursorList=t)}}const rr="__DocTableRectRange__",cr=6;function tn(o,t,e,n,i,s=_.NORMAL_TEXT_SELECTION_PLUGIN_STYLE,r="",c=-1){const l=t.getOffsetConfig(),d=new Eo(l,e).getNodePositionGroup(n,i);return(d!=null?d:[]).map(u=>new To(o,t,e,u.anchor,u.focus,s,r,c))}class To{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 vo(t,e)?t:e}get endNodePosition(){const{anchorNodePosition:t,focusNodePosition:e}=this;return vo(t,e)?e:t}get direction(){const{anchorNodePosition:t,focusNodePosition:e}=this;return vo(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 Eo(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(rr+a.generateRandomId(cr),{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,$t)}}function Zi(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 We(e,n,i,d,u,s,r,c)}function lr(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 To(e,n,i,l,A,s,r,c)}function dr(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 yo(l,A,e,n,i,s,r,c)}function yo(o,t,e,n,i,s,r,c){const l=[],A=[],d=[e,n,i,o,t,s,r,c];if(qi(i,o,t)){if(Io(o,t))return l.push(new We(...d)),{textRanges:l,rectRanges:A};{const C=tn(...d);return A.push(...C),{textRanges:l,rectRanges:A}}}if(Yi(o,t)){const C=tn(...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 We(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(...tn(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 We(e,n,i,V,H,s,r,c))}}return{textRanges:l,rectRanges:A}}function $i(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 ea(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 bo(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 Ar(o){const t=bo(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 ur=Object.getOwnPropertyDescriptor,hr=(o,t,e,n)=>{for(var i=n>1?void 0:n?ur(t,e):t,s=o.length-1,r;s>=0;s--)(r=o[s])&&(i=r(i)||i);return i},nn=(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=dr(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=lr(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=Zi(S.isBack?g:g-1,E.isBack?p:p-1,l,d,u,c,s,r,S.isBack,E.isBack):C=Zi(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=ea(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=ea(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 We(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(bo)}_getAllRectRanges(){return this._rectRangeList.map(Ar)}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:bo(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=`
|
|
14
14
|
position:absolute;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs-ui",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.4-nightly.202507290757",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Univer normal ui-plugin-docs",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -65,12 +65,12 @@
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"@univerjs/icons": "^0.4.6",
|
|
68
|
-
"@univerjs/core": "0.9.
|
|
69
|
-
"@univerjs/design": "0.9.
|
|
70
|
-
"@univerjs/
|
|
71
|
-
"@univerjs/
|
|
72
|
-
"@univerjs/
|
|
73
|
-
"@univerjs/
|
|
68
|
+
"@univerjs/core": "0.9.4-nightly.202507290757",
|
|
69
|
+
"@univerjs/design": "0.9.4-nightly.202507290757",
|
|
70
|
+
"@univerjs/engine-render": "0.9.4-nightly.202507290757",
|
|
71
|
+
"@univerjs/docs": "0.9.4-nightly.202507290757",
|
|
72
|
+
"@univerjs/drawing": "0.9.4-nightly.202507290757",
|
|
73
|
+
"@univerjs/ui": "0.9.4-nightly.202507290757"
|
|
74
74
|
},
|
|
75
75
|
"devDependencies": {
|
|
76
76
|
"jest-canvas-mock": "^2.5.2",
|
|
@@ -80,10 +80,10 @@
|
|
|
80
80
|
"rxjs": "^7.8.2",
|
|
81
81
|
"tailwindcss": "3.4.17",
|
|
82
82
|
"typescript": "^5.8.3",
|
|
83
|
-
"vite": "^7.0.
|
|
83
|
+
"vite": "^7.0.6",
|
|
84
84
|
"vitest": "^3.2.4",
|
|
85
|
-
"@univerjs-infra/shared": "0.9.
|
|
86
|
-
"@univerjs/docs-drawing": "0.9.
|
|
85
|
+
"@univerjs-infra/shared": "0.9.4",
|
|
86
|
+
"@univerjs/docs-drawing": "0.9.4-nightly.202507290757"
|
|
87
87
|
},
|
|
88
88
|
"scripts": {
|
|
89
89
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|