@univerjs/docs 0.1.0-beta.2 → 0.1.0-beta.4
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/{LICENSE.txt → LICENSE} +0 -2
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +1829 -1843
- package/lib/types/basics/retain-delete-params.d.ts +2 -2
- package/lib/types/commands/commands/clipboard.command.d.ts +2 -1
- package/lib/types/commands/mutations/core-editing.mutation.d.ts +2 -2
- package/lib/types/controllers/clipboard.controller.d.ts +9 -13
- package/lib/types/services/clipboard/clipboard.service.d.ts +20 -7
- package/lib/types/services/ime-input-manager.service.d.ts +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +31 -30
package/{LICENSE.txt → LICENSE}
RENAMED
package/lib/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var ut=Object.defineProperty;var mt=(i,t,e)=>t in i?ut(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var v=(i,t,e)=>(mt(i,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("@univerjs/core"),O=require("@univerjs/engine-render"),w=require("rxjs"),x=require("@univerjs/ui"),T=require("@wendellhu/redi");function Q(i,t){const n=i.getCurrentUniverDocInstance().getUnitId(),r=t.getRenderById(n);if(r==null)return;const{mainComponent:o,scene:s,engine:c}=r;return{document:o,scene:s,engine:c}}function gt(i,t){const e=t.getRenderById(i);if(e==null)return;const{mainComponent:n,scene:r,engine:o}=e;return{document:n,scene:r,engine:o}}var ve=(i=>(i.MAIN="__Document_Render_Main__",i))(ve||{}),Me=(i=>(i.VIEW_MAIN="viewMain",i.VIEW_TOP="viewTop",i.VIEW_LEFT="viewLeft",i.VIEW_LEFT_TOP="viewLeftTop",i))(Me||{});const Te=0,Qe=2,et=10,pt="normalTextSelectionPluginName",Ee={id:"doc.operation.set-selections",type:a.CommandType.OPERATION,handler:(i,t)=>!0};var ht=Object.defineProperty,ft=Object.getOwnPropertyDescriptor,St=(i,t,e,n)=>{for(var r=n>1?void 0:n?ft(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&ht(t,e,r),r},ze=(i,t)=>(e,n)=>t(e,n,i);function Ge(i){const{startOffset:t,endOffset:e,collapsed:n}=i;return{startOffset:t,endOffset:e,collapsed:n}}exports.TextSelectionManagerService=class extends a.RxDisposable{constructor(e,n){super();v(this,"_currentSelection",null);v(this,"_textSelectionInfo",new Map);v(this,"_textSelection$",new w.BehaviorSubject(null));v(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=n,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:n,segmentId:r,style:o}=e,s=n.find(m=>m.isActive());if(s==null)return null;const{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:p,direction:g}=s;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:p,direction:g,segmentId:r,style:o}}add(e){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",style:O.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(w.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const n={...this._currentSelection,...e};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:r,subUnitId:o,segmentId:s,style:c,textRanges:l}=n;this._commandService.executeCommand(Ee.id,{unitId:r,subUnitId:o,segmentId:s,style:c,ranges:l.map(Ge)})}_getTextRanges(e){var o;if(e==null)return;const{unitId:n,subUnitId:r=""}=e;return(o=this._textSelectionInfo.get(n))==null?void 0:o.get(r)}_refresh(e){const n=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),n&&Array.isArray(n.textRanges)&&n.textRanges.length&&this._textSelectionRenderManager.addTextRanges(n.textRanges.map(Ge))}_replaceByParam(e){const{unitId:n,subUnitId:r,style:o,segmentId:s,textRanges:c}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map),this._textSelectionInfo.get(n).set(r,{textRanges:c,style:o,segmentId:s})}_addByParam(e){const{unitId:n,subUnitId:r,textRanges:o,style:s,segmentId:c}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map);const l=this._textSelectionInfo.get(n);l.has(r)?l.get(r).textRanges.push(...o):l.set(r,{textRanges:o,style:s,segmentId:c})}};exports.TextSelectionManagerService=St([ze(0,O.ITextSelectionRenderManager),ze(1,a.ICommandService)],exports.TextSelectionManagerService);function Oe(i,t="",e=0){const{startOffset:n,endOffset:r}=i,o=[],s=n-e,c=r-e;return s>0&&o.push({t:"r",len:s,segmentId:t}),o.push({t:"d",len:c-s,line:0,segmentId:t}),o}var _t=Object.defineProperty,vt=Object.getOwnPropertyDescriptor,Ct=(i,t,e,n)=>{for(var r=n>1?void 0:n?vt(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&_t(t,e,r),r},It=(i,t)=>(e,n)=>t(e,n,i);exports.DocViewModelManagerService=class extends a.RxDisposable{constructor(e){super();v(this,"_currentViewModelUnitId","");v(this,"_docViewModelMap",new Map);v(this,"_currentDocViewModel$",new w.BehaviorSubject(null));v(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.pipe(w.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const n=e.getUnitId();this._setCurrent(n)})}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}getCurrent(){return this._docViewModelMap.get(this._currentViewModelUnitId)}getViewModel(e){var n;return(n=this._docViewModelMap.get(e))==null?void 0:n.docViewModel}_setCurrent(e){var r;const n=this._currentUniverService.getUniverDocInstance(e);if(n==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(n.getBody()!=null){if(!this._docViewModelMap.has(e)){const o=this._buildDocViewModel(n);this._docViewModelMap.set(e,{unitId:e,docViewModel:o})}if(e===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const o=(r=this._docViewModelMap.get(e))==null?void 0:r.docViewModel;if(o==null)return;o.reset(n)}this._currentViewModelUnitId=e,this._currentDocViewModel$.next(this.getCurrent())}}_buildDocViewModel(e){return new O.DocumentViewModel(e)}};exports.DocViewModelManagerService=Ct([It(0,a.IUniverInstanceService)],exports.DocViewModelManagerService);const _={id:"doc.mutation.rich-text-editing",type:a.CommandType.MUTATION,handler:(i,t)=>{const{unitId:e,mutations:n}=t,o=i.get(a.IUniverInstanceService).getUniverDocInstance(e),c=i.get(exports.DocViewModelManagerService).getViewModel(e);if(o==null||c==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);if(n.length===0)throw new Error("Mutation's length should great than 0 when call RichTextEditingMutation");const l=o.apply(n),{segmentId:u}=n[0],d=o.getSelfOrHeaderFooterModel(u);return c.getSelfOrHeaderFooterViewModel(u).reset(d),{unitId:e,mutations:l}}},Re={id:"doc.command.insert-text",type:a.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(a.IUndoRedoService),n=i.get(a.ICommandService),r=i.get(exports.TextSelectionManagerService),{range:o,segmentId:s,body:c,unitId:l,textRanges:u}=t,{startOffset:d,collapsed:p}=o,g={id:_.id,params:{unitId:l,mutations:[]}};p?d>0&&g.params.mutations.push({t:"r",len:d,segmentId:s}):g.params.mutations.push(...Oe(o,s)),g.params.mutations.push({t:"i",body:c,len:c.dataStream.length,line:0,segmentId:s});const m=n.syncExecuteCommand(g.id,g.params);return r.replaceTextRanges(u),m?(e.pushUndoRedo({unitID:l,undoMutations:[{id:_.id,params:m}],redoMutations:[{id:_.id,params:g.params}],undo(){return n.syncExecuteCommand(_.id,m),r.replaceTextRanges([o]),!0},redo(){return n.syncExecuteCommand(_.id,g.params),r.replaceTextRanges(u),!0}}),!0):!1}};var A=(i=>(i[i.LEFT=0]="LEFT",i[i.RIGHT=1]="RIGHT",i))(A||{});const ye={id:"doc.command.delete-text",type:a.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(a.ICommandService),n=i.get(a.IUndoRedoService),r=i.get(exports.TextSelectionManagerService),{range:o,segmentId:s,unitId:c,direction:l,textRanges:u,len:d=1}=t,{startOffset:p}=o,g={id:_.id,params:{unitId:c,mutations:[]}};p>0&&g.params.mutations.push({t:"r",len:l===0?p-d:p,segmentId:s}),g.params.mutations.push({t:"d",len:d,line:0,segmentId:s});const m=e.syncExecuteCommand(g.id,g.params);return r.replaceTextRanges(u),m&&n.pushUndoRedo({unitID:c,undoMutations:[{id:_.id,params:m}],redoMutations:[{id:_.id,params:g.params}],undo(){return e.syncExecuteCommand(_.id,m),r.replaceTextRanges([o]),!0},redo(){return e.syncExecuteCommand(_.id,g.params),r.replaceTextRanges(u),!0}}),!1}},Pe={id:"doc.command.update-text",type:a.CommandType.COMMAND,handler:async(i,t)=>{const{range:e,segmentId:n,updateBody:r,coverType:o,unitId:s,textRanges:c}=t,l=i.get(a.ICommandService),u=i.get(a.IUndoRedoService),d=i.get(exports.TextSelectionManagerService),p={id:_.id,params:{unitId:s,mutations:[]}},{startOffset:g,endOffset:m}=e;p.params.mutations.push({t:"r",len:g,segmentId:n}),p.params.mutations.push({t:"r",body:r,len:m-g,segmentId:n,coverType:o});const h=l.syncExecuteCommand(p.id,p.params);return d.replaceTextRanges(c),h?(u.pushUndoRedo({unitID:s,undoMutations:[{id:_.id,params:h}],redoMutations:[{id:_.id,params:p.params}],undo(){return l.syncExecuteCommand(_.id,h),d.replaceTextRanges(c),!0},redo(){return l.syncExecuteCommand(_.id,p.params),d.replaceTextRanges(c),!0}}),!0):!1}};function Mt(i,t){const e=[];for(let n=0,r=i.length;n<r;n++)i[n]===a.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:n});if(t)for(const n of e)t.bullet&&(n.bullet=a.Tools.deepClone(t.bullet)),t.paragraphStyle&&(n.paragraphStyle=a.Tools.deepClone(t.paragraphStyle));return e}const Ne={id:"doc.command.break-line",type:a.CommandType.COMMAND,handler:async i=>{var h;const t=i.get(exports.TextSelectionManagerService),e=i.get(a.IUniverInstanceService),n=i.get(a.ICommandService),r=t.getActiveRange();if(r==null)return!1;const o=e.getCurrentUniverDocInstance(),s=o.getUnitId(),{startOffset:c,segmentId:l,style:u}=r,d=[{startOffset:c+1,endOffset:c+1,style:u}],g=(((h=o.getBody())==null?void 0:h.paragraphs)??[]).find(f=>f.startIndex>=c);return await n.executeCommand(Re.id,{unitId:s,body:{dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Mt(a.DataStreamTreeTokenType.PARAGRAPH,g)},range:r,textRanges:d,segmentId:l})}},se={id:x.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:i=>i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.FOCUSING_EDITOR),handler:async()=>!0},ae={id:x.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:i=>i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.FOCUSING_EDITOR),handler:async()=>!0},ce={id:x.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:i=>i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.FOCUSING_EDITOR),handler:async()=>!0};var Ot=Object.defineProperty,Rt=Object.getOwnPropertyDescriptor,yt=(i,t,e,n)=>{for(var r=n>1?void 0:n?Rt(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Ot(t,e,r),r},We=(i,t)=>(e,n)=>t(e,n,i);exports.DocSkeletonManagerService=class extends a.RxDisposable{constructor(e,n){super();v(this,"_currentSkeletonUnitId","");v(this,"_docSkeletonMap",new Map);v(this,"_currentSkeleton$",new w.BehaviorSubject(null));v(this,"currentSkeleton$",this._currentSkeleton$.asObservable());v(this,"_currentSkeletonBefore$",new w.BehaviorSubject(null));v(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=n,this._initialize()}_initialize(){this._docViewModelManagerService.currentDocViewModel$.pipe(w.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)})}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,n=!0){const r=this.getSkeletonByUnitId(e);r!=null&&(r.dirty=n)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:n}=e;if(this._docSkeletonMap.has(n)){const r=this.getSkeletonByUnitId(n);r.skeleton.calculate(),r.dirty=!0}else{const r=this._buildSkeleton(e.docViewModel);r.calculate(),this._docSkeletonMap.set(n,{unitId:n,skeleton:r,dirty:!1})}return this._currentSkeletonUnitId=n,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return O.DocumentSkeleton.create(e,this._localeService)}};exports.DocSkeletonManagerService=yt([We(0,T.Inject(a.LocaleService)),We(1,T.Inject(exports.DocViewModelManagerService))],exports.DocSkeletonManagerService);const He={id:"doc.command.inner-paste",type:a.CommandType.COMMAND,handler:async(i,t)=>{const{segmentId:e,body:n,textRanges:r}=t,o=i.get(a.IUndoRedoService),s=i.get(a.ICommandService),c=i.get(exports.TextSelectionManagerService),l=i.get(a.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;const p=l.getCurrentUniverDocInstance().getUnitId(),g={id:_.id,params:{unitId:p,mutations:[]}},m=new a.MemoryCursor;m.reset();for(const f of u){const{startOffset:S,endOffset:C,collapsed:I}=f,D=S-m.cursor;I?g.params.mutations.push({t:"r",len:D,segmentId:e}):g.params.mutations.push(...Oe(f,e,m.cursor)),g.params.mutations.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:e}),m.reset(),m.moveCursor(C)}const h=s.syncExecuteCommand(g.id,g.params);return c.replaceTextRanges(r),h?(o.pushUndoRedo({unitID:p,undoMutations:[{id:_.id,params:h}],redoMutations:[{id:_.id,params:g.params}],undo(){return s.syncExecuteCommand(_.id,h),c.replaceTextRanges(u),!0},redo(){return s.syncExecuteCommand(_.id,g.params),c.replaceTextRanges(r),!0}}),!0):!1}},Ce={id:"doc.command.inner-cut",type:a.CommandType.COMMAND,handler:async(i,t)=>{const{segmentId:e,textRanges:n}=t,r=i.get(a.IUndoRedoService),o=i.get(a.ICommandService),s=i.get(exports.TextSelectionManagerService),c=i.get(a.IUniverInstanceService),l=s.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const u=c.getCurrentUniverDocInstance().getUnitId(),d=c.getUniverDocInstance(u),p=a.getDocsUpdateBody(d.snapshot,e);if(p==null)return!1;const g={id:_.id,params:{unitId:u,mutations:[]}},m=new a.MemoryCursor;m.reset();for(const f of l){const{startOffset:S,endOffset:C,collapsed:I}=f,D=S-m.cursor;I?g.params.mutations.push({t:"r",len:D,segmentId:e}):g.params.mutations.push(...xt(f,p,e,m.cursor)),m.reset(),m.moveCursor(C)}const h=o.syncExecuteCommand(g.id,g.params);return s.replaceTextRanges(n),h?(r.pushUndoRedo({unitID:u,undoMutations:[{id:_.id,params:h}],redoMutations:[{id:_.id,params:g.params}],undo(){return o.syncExecuteCommand(_.id,h),s.replaceTextRanges(l),!0},redo(){return o.syncExecuteCommand(_.id,g.params),s.replaceTextRanges(n),!0}}),!0):!1}};function xt(i,t,e="",n=0){const{startOffset:r,endOffset:o}=i,s=[],{paragraphs:c=[]}=t,l=r-n,u=o-n,d=c==null?void 0:c.find(p=>p.startIndex-n>=l&&p.startIndex-n<=u);if(l>0&&s.push({t:"r",len:l,segmentId:e}),d&&d.startIndex-n>l){const p=d.startIndex-n;s.push({t:"d",len:p-l,line:0,segmentId:e}),s.push({t:"r",len:1,segmentId:e}),u>p+1&&s.push({t:"d",len:u-p-1,line:0,segmentId:e})}else s.push({t:"d",len:u-l,line:0,segmentId:e});return s}const we={id:"doc.command.delete-left",type:a.CommandType.COMMAND,handler:async i=>{var y;const t=i.get(exports.TextSelectionManagerService),e=i.get(exports.DocSkeletonManagerService),n=i.get(a.IUniverInstanceService),r=i.get(a.ICommandService),o=t.getActiveRange(),s=t.getSelections(),c=(y=e.getCurrent())==null?void 0:y.skeleton;let l;if(o==null||c==null||s==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:p,segmentId:g,style:m}=o;if(d===0&&p)return!0;const h=c.findNodeByCharIndex(d),f=O.hasListSpan(h),S=O.isIndentBySpan(h,u.body);let C=d;const I=c.findNodeByCharIndex(d-1);if(O.isFirstSpan(h)&&I!==h&&(f===!0||S===!0)){const M=O.getParagraphBySpan(h,u.body);if(M==null)return!1;const b=M==null?void 0:M.startIndex,U={startIndex:0},E=M.paragraphStyle;if(f===!0){const R=M.paragraphStyle;R&&(U.paragraphStyle=R)}else if(S===!0){const R=M.bullet;R&&(U.bullet=R),E!=null&&(U.paragraphStyle={...E},delete U.paragraphStyle.hanging,delete U.paragraphStyle.indentStart)}const P=[{startOffset:C,endOffset:C,style:m}];l=await r.executeCommand(Pe.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...U}]},range:{startOffset:b,endOffset:b+1},textRanges:P,coverType:a.UpdateDocsAttributeType.REPLACE,segmentId:g})}else if(p===!0)if(I.content==="\r")l=await r.executeCommand(Ae.id,{direction:A.LEFT,range:o});else{C-=I.count;const M=[{startOffset:C,endOffset:C,style:m}];l=await r.executeCommand(ye.id,{unitId:u.getUnitId(),range:o,segmentId:g,direction:A.LEFT,len:I.count,textRanges:M})}else{const M=tt(o,s);l=await r.executeCommand(Ce.id,{segmentId:g,textRanges:M})}return l}},Le={id:"doc.command.delete-right",type:a.CommandType.COMMAND,handler:async i=>{var h;const t=i.get(exports.TextSelectionManagerService),e=i.get(exports.DocSkeletonManagerService),n=i.get(a.IUniverInstanceService),r=i.get(a.ICommandService),o=t.getActiveRange(),s=t.getSelections(),c=(h=e.getCurrent())==null?void 0:h.skeleton;let l;if(o==null||c==null||s==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:p,segmentId:g,style:m}=o;if(d===u.getBody().dataStream.length-2&&p)return!0;if(p===!0){const f=c.findNodeByCharIndex(d);if(f.content==="\r")l=await r.executeCommand(Ae.id,{direction:A.RIGHT,range:o});else{const S=[{startOffset:d,endOffset:d,style:m}];l=await r.executeCommand(ye.id,{unitId:u.getUnitId(),range:o,segmentId:g,direction:A.RIGHT,textRanges:S,len:f.count})}}else{const f=tt(o,s);l=await r.executeCommand(Ce.id,{segmentId:g,textRanges:f})}return l}},Ae={id:"doc.command.merge-two-paragraph",type:a.CommandType.COMMAND,handler:async(i,t)=>{var U,E,P;const e=i.get(exports.TextSelectionManagerService),n=i.get(a.IUniverInstanceService),r=i.get(a.ICommandService),o=i.get(a.IUndoRedoService),{direction:s,range:c}=t,l=e.getActiveRange(),u=e.getSelections();if(l==null||u==null)return!1;const d=n.getCurrentUniverDocInstance(),{startOffset:p,collapsed:g,segmentId:m,style:h}=l;if(!g)return!1;const f=s===A.LEFT?p:p+1,S=(P=(E=(U=d.getBody())==null?void 0:U.paragraphs)==null?void 0:E.find(R=>R.startIndex>=f))==null?void 0:P.startIndex,C=Dt(d.getBody(),f,S),I=s===A.LEFT?p-1:p,D=d.getUnitId(),y=[{startOffset:I,endOffset:I,style:h}],M={id:_.id,params:{unitId:D,mutations:[]}};M.params.mutations.push({t:"r",len:s===A.LEFT?p-1:p,segmentId:m}),C.dataStream.length&&M.params.mutations.push({t:"i",body:C,len:C.dataStream.length,line:0,segmentId:m}),M.params.mutations.push({t:"r",len:1,segmentId:m}),M.params.mutations.push({t:"d",len:S+1-f,line:0,segmentId:m});const b=r.syncExecuteCommand(M.id,M.params);return e.replaceTextRanges(y),b?(o.pushUndoRedo({unitID:D,undoMutations:[{id:_.id,params:b}],redoMutations:[{id:_.id,params:M.params}],undo(){return r.syncExecuteCommand(_.id,b),e.replaceTextRanges([c]),!0},redo(){return r.syncExecuteCommand(_.id,M.params),e.replaceTextRanges(y),!0}}),!0):!1}};function Dt(i,t,e){const{textRuns:n}=i,r=i.dataStream.substring(t,e);if(n==null)return{dataStream:r};const o=[];for(const s of n){const{st:c,ed:l}=s;l<=t||c>=e||(c<t?o.push({...s,st:0,ed:l-t}):l>e?o.push({...s,st:c-t,ed:e-t}):o.push({...s,st:c-t,ed:l-t}))}return{dataStream:r,textRuns:o}}function tt(i,t){let e=i.endOffset;for(const r of t){const{startOffset:o,endOffset:s}=r;o==null||s==null||s<=i.endOffset&&(e-=s-o)}return[{startOffset:e,endOffset:e,style:i.style}]}class Be{constructor(){v(this,"_previousActiveRange",null);v(this,"_undoMutationParamsCache",[]);v(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}setActiveRange(t){this._previousActiveRange=t}pushUndoRedoMutationParams(t,e){this._undoMutationParamsCache.push(t),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(t){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null)return null;const{unitId:e}=this._undoMutationParamsCache[0],{segmentId:n,startOffset:r,collapsed:o}=this._previousActiveRange,s={unitId:e,mutations:[]},c={unitId:e,mutations:[]};return o?(s.mutations.push({t:"r",len:r,segmentId:n}),c.mutations.push({t:"r",len:r,segmentId:n})):(r>0&&s.mutations.push({t:"r",len:r,segmentId:n}),s.mutations.push(this._undoMutationParamsCache[0].mutations.find(l=>l.t==="i")),c.mutations.push(...Oe(this._previousActiveRange,n))),t.length&&(s.mutations.push({t:"d",len:t.length,line:0,segmentId:n}),c.mutations.push({t:"i",body:{dataStream:t},len:t.length,line:0,segmentId:n})),{redoMutationParams:c,undoMutationParams:s,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const $e={id:"doc.command.ime-input",type:a.CommandType.COMMAND,handler:async(i,t)=>{const{unitId:e,newText:n,oldTextLen:r,range:o,segmentId:s,textRanges:c,isCompositionEnd:l}=t,u=i.get(a.ICommandService),d=i.get(a.IUndoRedoService),p=i.get(exports.TextSelectionManagerService),g=i.get(Be),m={id:_.id,params:{unitId:e,mutations:[]}};o.collapsed?m.params.mutations.push({t:"r",len:o.startOffset,segmentId:s}):m.params.mutations.push(...Oe(o,s)),r>0&&m.params.mutations.push({t:"d",len:r,line:0,segmentId:s}),m.params.mutations.push({t:"i",body:{dataStream:n},len:n.length,line:0,segmentId:s});const h=u.syncExecuteCommand(m.id,m.params);if(g.pushUndoRedoMutationParams(h,m.params),p.replaceTextRanges(c),l){if(h){const f=g.fetchComposedUndoRedoMutationParams(n);if(f==null)return!1;const{undoMutationParams:S,redoMutationParams:C,previousActiveRange:I}=f;return d.pushUndoRedo({unitID:e,undoMutations:[{id:_.id,params:S}],redoMutations:[{id:_.id,params:C}],undo(){return u.syncExecuteCommand(_.id,S),p.replaceTextRanges([I]),!0},redo(){return u.syncExecuteCommand(_.id,C),p.replaceTextRanges(c),!0}}),!0}}else return!!h;return!1}},W={id:"doc.command.set-inline-format-bold",type:a.CommandType.COMMAND,handler:async()=>!0},ee={id:"doc.command.set-inline-format-italic",type:a.CommandType.COMMAND,handler:async()=>!0},te={id:"doc.command.set-inline-format-underline",type:a.CommandType.COMMAND,handler:async()=>!0},ne={id:"doc.command.set-inline-format-strikethrough",type:a.CommandType.COMMAND,handler:async()=>!0},B={id:"doc.command.set-inline-format-subscript",type:a.CommandType.COMMAND,handler:async()=>!0},V={id:"doc.command.set-inline-format-superscript",type:a.CommandType.COMMAND,handler:async()=>!0},H={id:"doc.command.set-inline-format-fontsize",type:a.CommandType.COMMAND,handler:async()=>!0},K={id:"doc.command.set-inline-format-font-family",type:a.CommandType.COMMAND,handler:async()=>!0},re={id:"doc.command.set-inline-format-text-color",type:a.CommandType.COMMAND,handler:async()=>!0},nt={[W.id]:"bl",[ee.id]:"it",[te.id]:"ul",[ne.id]:"st",[H.id]:"fs",[K.id]:"ff",[re.id]:"cl",[B.id]:"va",[V.id]:"va"},Fe={id:"doc.command.set-inline-format",type:a.CommandType.COMMAND,handler:async(i,t)=>{const{segmentId:e,value:n,preCommandId:r}=t,o=i.get(a.IUndoRedoService),s=i.get(a.ICommandService),c=i.get(exports.TextSelectionManagerService),l=i.get(a.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;let d=l.getCurrentUniverDocInstance(),p=d.getUnitId();p===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(d=l.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),p=d.getUnitId());let g;switch(r){case W.id:case ee.id:case te.id:case ne.id:case B.id:case V.id:{g=bt(d.getBody().textRuns,r,u);break}case H.id:case K.id:{g=n;break}case re.id:{g={rgb:n};break}default:throw new Error(`Unknown command: ${r} in handleInlineFormat`)}const m={id:_.id,params:{unitId:p,mutations:[]}},h=new a.MemoryCursor;h.reset();for(const C of u){const{startOffset:I,endOffset:D}=C,y={dataStream:"",textRuns:[{st:0,ed:D-I,ts:{[nt[r]]:g}}]},M=I-h.cursor;M!==0&&m.params.mutations.push({t:"r",len:M,segmentId:e}),m.params.mutations.push({t:"r",body:y,len:D-I,segmentId:e}),h.reset(),h.moveCursor(D)}const f=s.syncExecuteCommand(m.id,m.params),S=[W.id,H.id,K.id,B.id,V.id];return S.includes(r)&&c.refreshSelection(),f?(o.pushUndoRedo({unitID:p,undoMutations:[{id:_.id,params:f}],redoMutations:[{id:_.id,params:m.params}],undo(){return s.syncExecuteCommand(_.id,f),S.includes(r)&&c.refreshSelection(),!0},redo(){return s.syncExecuteCommand(_.id,m.params),S.includes(r)&&c.refreshSelection(),!0}}),!0):!1}};function Tt(i){return i!==null&&typeof i=="object"}function bt(i,t,e){let n=0,r=0;const o=nt[t];for(;n!==i.length&&r!==e.length;){const{startOffset:s,endOffset:c}=e[r],{st:l,ed:u,ts:d}=i[n];if(c<=l)r++;else if(u<=s)n++;else{if((d==null?void 0:d[o])==null){if(/bl|it/.test(o))return a.BooleanNumber.TRUE;if(/ul|st/.test(o))return{s:a.BooleanNumber.TRUE};if(/va/.test(o))return t===B.id?a.BaselineOffset.SUBSCRIPT:a.BaselineOffset.SUPERSCRIPT}if(Tt(d==null?void 0:d[o])&&d[o].s===a.BooleanNumber.FALSE)return{s:a.BooleanNumber.TRUE};if(t===B.id&&(d==null?void 0:d[o])!==a.BaselineOffset.SUBSCRIPT)return a.BaselineOffset.SUBSCRIPT;if(t===V.id&&(d==null?void 0:d[o])!==a.BaselineOffset.SUPERSCRIPT)return a.BaselineOffset.SUPERSCRIPT;if((d==null?void 0:d[o])===a.BooleanNumber.FALSE)return a.BooleanNumber.TRUE;n++}}return/bl|it/.test(o)?a.BooleanNumber.FALSE:/ul|st/.test(o)?{s:a.BooleanNumber.FALSE}:a.BaselineOffset.NORMAL}const rt={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:i=>i.get(a.ICommandService).syncExecuteCommand(je.id,{listType:a.PresetListType.BULLET_LIST})},it={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:i=>i.get(a.ICommandService).syncExecuteCommand(je.id,{listType:a.PresetListType.ORDER_LIST})},je={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(i,t)=>{var D;const e=i.get(exports.TextSelectionManagerService),n=i.get(a.IUniverInstanceService),r=i.get(a.ICommandService),o=i.get(a.IUndoRedoService),{listType:s}=t,c=n.getCurrentUniverDocInstance(),l=e.getActiveRange(),u=(D=c.getBody())==null?void 0:D.paragraphs;if(l==null||u==null)return!1;const d=Ut(l,u),{segmentId:p}=l,g=c.getUnitId(),m=d.every(y=>{var M;return((M=y.bullet)==null?void 0:M.listType)===s}),h=6;let f=a.Tools.generateRandomId(h);if(d.length===1){const y=u.indexOf(d[0]),M=u[y-1],b=u[y+1];M&&M.bullet&&M.bullet.listType===s?f=M.bullet.listId:b&&b.bullet&&b.bullet.listType===s&&(f=b.bullet.listId)}const S={id:_.id,params:{unitId:g,mutations:[]}},C=new a.MemoryCursor;C.reset();for(const y of d){const{startIndex:M}=y;S.params.mutations.push({t:"r",len:M-C.cursor,segmentId:p});const b={...y.paragraphStyle,hanging:void 0,indentStart:void 0};S.params.mutations.push({t:"r",len:1,body:{dataStream:"",paragraphs:[m?{paragraphStyle:b,startIndex:0}:{...y,startIndex:0,bullet:{...y.bullet??{nestingLevel:0,textStyle:{fs:20}},listType:s,listId:f}}]},segmentId:p,coverType:a.UpdateDocsAttributeType.REPLACE}),C.moveCursorTo(M+1)}const I=r.syncExecuteCommand(S.id,S.params);return e.refreshSelection(),I&&o.pushUndoRedo({unitID:g,undoMutations:[{id:_.id,params:I}],redoMutations:[{id:_.id,params:S.params}],undo(){return r.syncExecuteCommand(_.id,I),e.refreshSelection(),!0},redo(){return r.syncExecuteCommand(_.id,S.params),e.refreshSelection(),!0}}),!0}};function Ut(i,t){const{startOffset:e,endOffset:n}=i,r=[];let o=-1;for(const s of t){const{startIndex:c}=s;(e>o&&e<=c||n>o&&n<=c||c>=e&&c<=n)&&r.push(s),o=c}return r}const ot={id:"doc.command-replace-content",type:a.CommandType.COMMAND,handler:async(i,t)=>{var h;const{unitId:e,body:n,textRanges:r,segmentId:o=""}=t,s=i.get(a.IUniverInstanceService),c=i.get(a.ICommandService),l=i.get(exports.TextSelectionManagerService),u=i.get(a.IUndoRedoService),d=(h=s.getUniverDocInstance(e))==null?void 0:h.getSnapshot().body,p=l.getSelections();if(d==null||!Array.isArray(p)||p.length===0)return!1;const g=at(e,o,d,n),m=c.syncExecuteCommand(g.id,g.params);return l.replaceTextRanges(r),m?(u.pushUndoRedo({unitID:e,undoMutations:[{id:_.id,params:m}],redoMutations:[{id:_.id,params:g.params}],undo(){return c.syncExecuteCommand(_.id,m),l.replaceTextRanges(p),!0},redo(){return c.syncExecuteCommand(_.id,g.params),l.replaceTextRanges(r),!0}}),!0):!1}},st={id:"doc.command-cover-content",type:a.CommandType.COMMAND,handler:async(i,t)=>{var d;const{unitId:e,body:n,segmentId:r=""}=t,o=i.get(a.IUniverInstanceService),s=i.get(a.ICommandService),c=i.get(a.IUndoRedoService),l=(d=o.getUniverDocInstance(e))==null?void 0:d.getSnapshot().body;if(l==null)return!1;const u=at(e,r,l,n);return s.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(e),!0}};function at(i,t,e,n){const r={id:_.id,params:{unitId:i,mutations:[]}},o=(e==null?void 0:e.dataStream.length)-2;return o>0&&r.params.mutations.push({t:"d",len:o,line:0,segmentId:t}),n.dataStream.length>0&&r.params.mutations.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:t}),r}const $={id:"doc.operation.move-cursor",type:a.CommandType.OPERATION,handler:(i,t)=>!!t},F={id:"doc.operation.move-selection",type:a.CommandType.OPERATION,handler:(i,t)=>!!t},Et=(i,t)=>{const e=i.get(a.IUniverInstanceService).getUniverDocInstance(t.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...a.Tools.deepClone(t),zoomRatio:n}},k={id:"doc.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(i,t)=>{const e=i.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}},ct={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(i,t)=>{const e=i.get(a.ICommandService),n=i.get(a.IUndoRedoService),r=i.get(a.IUniverInstanceService);let o=r.getCurrentUniverDocInstance().getUnitId(),s=1;if(t&&(o=t.documentId??o,s=t.zoomRatio??s),!r.getUniverDocInstance(o))return!1;const l={zoomRatio:s,unitId:o},u=Et(i,l);return e.syncExecuteCommand(k.id,l)?(n.pushUndoRedo({unitID:o,undoMutations:[{id:k.id,params:u}],redoMutations:[{id:k.id,params:l}]}),!0):!1}},lt={id:"doc.operation.select-all",type:a.CommandType.COMMAND,handler:async i=>{const t=i.get(a.IUniverInstanceService),e=i.get(exports.TextSelectionManagerService),n=t.getCurrentUniverDocInstance().getSnapshot().body;if(n==null)return!1;const r=[{startOffset:0,endOffset:n.dataStream.length-2}];return e.replaceTextRanges(r),!0}},Pt=10,Nt=6;function wt(){return a.Tools.generateRandomId(Nt)}function Lt(i){const t=i.match(/data-copy-id="([^\s]+)"/);return t&&t[1]?t[1]:null}class At{constructor(){v(this,"_cache",new a.LRUMap(Pt))}set(t,e){this._cache.set(t,e)}get(t){return this._cache.get(t)}clear(){this._cache.clear()}}const Ke=new At;function Bt(i){const t=i.style,e={};for(let n=0;n<t.length;n++){const r=t[n],o=t.getPropertyValue(r);switch(r){case"margin-top":{const s=parseInt(o);e.spaceAbove=/pt/.test(o)?be(s):s;break}case"margin-bottom":{const s=parseInt(o);e.spaceBelow=/pt/.test(o)?be(s):s;break}}}return Object.getOwnPropertyNames(e).length?e:null}function be(i){return i/.75}function ke(i){const t=i.style,e={},n=i.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{e.bl=a.BooleanNumber.TRUE;break}case"s":{e.st={s:a.BooleanNumber.TRUE};break}case"u":{e.ul={s:a.BooleanNumber.TRUE};break}case"i":{e.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{e.va=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let r=0;r<t.length;r++){const o=t[r],s=t.getPropertyValue(o);switch(o){case"font-family":{e.ff=s;break}case"font-size":{const c=parseInt(s);Number.isNaN(c)||(e.fs=/pt$/.test(s)?be(c):c);break}case"font-style":{s==="italic"&&(e.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(s)>400&&(e.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(s)?e.ul={s:a.BooleanNumber.TRUE}:/overline/.test(s)?e.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(s)&&(e.st={s:a.BooleanNumber.TRUE});break}case"color":{const c=new a.ColorKit(s);c.isValid&&(e.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new a.ColorKit(s);c.isValid&&(e.bg={rgb:c.toRgbString()});break}}}return e}function $t(i){const t=new DOMParser,e=`<x-univer id="univer-root">${i}</x-univer>`;return t.parseFromString(e,"text/html").querySelector("#univer-root")}function Ye(i,t){const e=i.tagName.toLowerCase();return typeof t=="string"?e===t:Array.isArray(t)?t.some(n=>n===e):t(i)}const Ie=class Ie{constructor(){v(this,"_styleCache",new Map);v(this,"_styleRules",[]);v(this,"_afterProcessRules",[])}static use(t){if(this._pluginList.includes(t))throw new Error(`Univer paste plugin ${t.name} already added`);this._pluginList.push(t)}convert(t){const e=Ie._pluginList.find(o=>o.checkPasteType(t)),n=$t(t),r={dataStream:"",textRuns:[]};return e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,r),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],r}_process(t,e,n){var r;for(const o of e)if(o.nodeType===Node.TEXT_NODE){const s=(r=o.nodeValue)==null?void 0:r.replace(/[\r\n]/g,"");let c;t&&this._styleCache.has(t)&&(c=this._styleCache.get(t)),n.dataStream+=s,c&&Object.getOwnPropertyNames(c).length&&n.textRuns.push({st:n.dataStream.length-s.length,ed:n.dataStream.length,ts:c})}else if(o.nodeType===Node.ELEMENT_NODE){const s=t?this._styleCache.get(t):{},c=this._styleRules.find(({filter:p})=>Ye(o,p)),l=c?c.getStyle(o):ke(o);this._styleCache.set(o,{...s,...l});const{childNodes:u}=o;this._process(o,u,n);const d=this._afterProcessRules.find(({filter:p})=>Ye(o,p));d&&d.handler(n,o)}}};v(Ie,"_pluginList",[]);let J=Ie;const Ft={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const t=ke(i);return{st:{s:a.BooleanNumber.TRUE},...t}}}],afterProcessRules:[{filter(i){return i.tagName==="DIV"&&/ace-line/i.test(i.className)},handler(i){i.paragraphs==null&&(i.paragraphs=[]),i.paragraphs.push({startIndex:i.dataStream.length}),i.dataStream+="\r"}}]},jt={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const t=ke(i);return{bl:a.BooleanNumber.TRUE,...t}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,t){i.paragraphs==null&&(i.paragraphs=[]);const e={startIndex:i.dataStream.length},n=Bt(t);n&&(e.paragraphStyle=n),i.paragraphs.push(e),i.dataStream+="\r"}}]};function kt(i,t){const{st:e,ed:n,ts:r={}}=t,{ff:o,fs:s,it:c,bl:l,ul:u,st:d,ol:p,bg:g,cl:m,va:h}=r;let f=i.slice(e,n);const S=[];return c===a.BooleanNumber.TRUE&&(f=`<i>${f}</i>`),h===a.BaselineOffset.SUPERSCRIPT?f=`<sup>${f}</sup>`:h===a.BaselineOffset.SUBSCRIPT&&(f=`<sub>${f}</sub>`),(u==null?void 0:u.s)===a.BooleanNumber.TRUE&&(f=`<u>${f}</u>`),(d==null?void 0:d.s)===a.BooleanNumber.TRUE&&(f=`<s>${f}</s>`),l===a.BooleanNumber.TRUE&&(f=`<strong>${f}</strong>`),o&&S.push(`font-family: ${o}`),m&&S.push(`color: ${m.rgb}`),s&&S.push(`font-size: ${s}px`),p&&S.push("text-decoration: overline"),g&&S.push(`background: ${g.rgb}`),S.length?`<span style="${S.join(";")}">${f}</span>`:f}function Xe(i,t=!0){const{dataStream:e,textRuns:n=[],paragraphs:r=[]}=i;let o=0;const s=[],c=[];for(const l of n){const{st:u,ed:d}=l;if(u!==o&&s.push(e.slice(o,u)),s.push(kt(e,l)),o=d,t)for(const p of r){const{startIndex:g,paragraphStyle:m={}}=p;if(g>=u&&g<=d){const{spaceAbove:h,spaceBelow:f}=m,S=[];h!=null&&(typeof h=="number"?S.push(`margin-top: ${h}px`):S.push(`margin-top: ${h.v}px`)),f!=null&&(typeof f=="number"?S.push(`margin-bottom: ${f}px`):S.push(`margin-bottom: ${f.v}px`)),c.push(`<p className="UniverNormal" ${S.length?`style="${S.join(";")}"`:""}>${s.join("")}</p>`),s.length=0}}}return c.join("")+s.join("")}class Vt{convert(t){if(t.length===0)throw new Error("The bodyList length at least to be 1");if(t.length===1)return Xe(t[0]);let e="";for(const n of t)e+='<p className="UniverNormal">',e+=Xe(n,!1),e+="</p>";return e}}var zt=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,Wt=(i,t,e,n)=>{for(var r=n>1?void 0:n?Gt(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&zt(t,e,r),r},qe=(i,t)=>(e,n)=>t(e,n,i);J.use(jt);J.use(Ft);function Ht(i){const t=i.replace(/\n/g,"\r"),e=[];for(let n=0;n<t.length;n++)t[n]==="\r"&&e.push({startIndex:n});return{dataStream:t,paragraphs:e}}const dt=T.createIdentifier("doc.clipboard-service");let Ue=class extends a.Disposable{constructor(t,e){super();v(this,"_clipboardHooks",[]);v(this,"_htmlToUDM",new J);v(this,"_umdToHtml",new Vt);this._currentUniverService=t,this._clipboardInterfaceService=e}async queryClipboardData(){const t=await this._clipboardInterfaceService.read();if(t.length===0)return Promise.reject();try{let e="",n="";for(const o of t)for(const s of o.types)s===x.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await o.getType(s).then(c=>c&&c.text()):s===x.HTML_CLIPBOARD_MIME_TYPE&&(e=await o.getType(s).then(c=>c&&c.text()));if(!e)return Ht(n);const r=Lt(e);if(r){const o=Ke.get(r);if(o)return o}return this._htmlToUDM.convert(e)}catch(e){return Promise.reject(e)}}async setClipboardData(t){const e=wt(),n=t.length>1?t.map(o=>o.dataStream).join(`
|
|
2
|
-
`):t[0].dataStream;let r=this._umdToHtml.convert(t);return t.length===1&&(r=r.replace(/(<[a-z]+)/,(o,s)=>`${s} data-copy-id="${e}"`),Ke.set(e,t[0])),this._clipboardInterfaceService.write(n,r)}addClipboardHook(t){return this._clipboardHooks.push(t),a.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}};Ue=Wt([qe(0,a.IUniverInstanceService),qe(1,x.IClipboardInterfaceService)],Ue);var Kt=Object.defineProperty,Yt=Object.getOwnPropertyDescriptor,Xt=(i,t,e,n)=>{for(var r=n>1?void 0:n?Yt(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Kt(t,e,r),r},z=(i,t)=>(e,n)=>t(e,n,i);let le=class extends a.Disposable{constructor(i,t,e,n,r,o){super(),this._logService=i,this._commandService=t,this._currentUniverService=e,this._docClipboardService=n,this._textSelectionManagerService=r,this._contextService=o,this._commandExecutedListener(),this.initialize()}initialize(){[se,ae,ce].forEach(i=>this.disposeWithMe(this._commandService.registerMultipleCommand(i))),[He,Ce].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_commandExecutedListener(){const i=[ae.id,se.id,ce.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(i.includes(t.id)&&!(!this._contextService.getContextValue(a.FOCUSING_DOC)&&!this._contextService.getContextValue(a.FOCUSING_EDITOR)))switch(t.id){case ce.id:{this._handlePaste();break}case se.id:{this._handleCopy();break}case ae.id:{this._handleCut();break}default:throw new Error(`Unhandled command ${t.id}`)}}))}async _handlePaste(){const{_docClipboardService:i}=this,{segmentId:t,endOffset:e,style:n}=this._textSelectionManagerService.getActiveRange()??{},r=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),!(e==null||r==null))try{const o=await i.queryClipboardData();let s=e;for(const l of r){const{startOffset:u,endOffset:d}=l;u==null||d==null||d<=e&&(s+=o.dataStream.length-(d-u))}const c=[{startOffset:s,endOffset:s,style:n}];this._commandService.executeCommand(He.id,{body:o,segmentId:t,textRanges:c})}catch{this._logService.error("[DocClipboardController] clipboard is empty")}}_getDocumentBodyInRanges(){const i=this._textSelectionManagerService.getSelections(),t=this._currentUniverService.getCurrentUniverDocInstance(),e=[];if(i==null)return e;for(const n of i){const{startOffset:r,endOffset:o,collapsed:s}=n;if(s||r==null||o==null)continue;const c=t.sliceBody(r,o);c!=null&&e.push(c)}return e}async _handleCopy(){const{_docClipboardService:i}=this,t=this._getDocumentBodyInRanges();try{i.setClipboardData(t)}catch{this._logService.error("[DocClipboardController] set clipboard failed")}}async _handleCut(){const{segmentId:i,endOffset:t,style:e}=this._textSelectionManagerService.getActiveRange()??{},n=this._textSelectionManagerService.getSelections();if(i==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),!(t==null||n==null)){this._handleCopy();try{let r=t;for(const s of n){const{startOffset:c,endOffset:l}=s;c==null||l==null||l<=t&&(r-=l-c)}const o=[{startOffset:r,endOffset:r,style:e}];this._commandService.executeCommand(Ce.id,{segmentId:i,textRanges:o})}catch{this._logService.error("[DocClipboardController] cut content failed")}}}};le=Xt([a.OnLifecycle(a.LifecycleStages.Rendered,le),z(0,a.ILogService),z(1,a.ICommandService),z(2,a.IUniverInstanceService),z(3,dt),z(4,T.Inject(exports.TextSelectionManagerService)),z(5,a.IContextService)],le);var qt=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,Jt=(i,t,e,n)=>{for(var r=n>1?void 0:n?Zt(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&qt(t,e,r),r},xe=(i,t)=>(e,n)=>t(e,n,i);let de=class extends a.RxDisposable{constructor(i,t,e){super(),this._docSkeletonManagerService=i,this._renderManagerService=t,this._commandService=e,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(w.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;const{skeleton:t,unitId:e}=i,n=this._renderManagerService.getRenderById(e);if(n==null)return;const{mainComponent:r}=n;r.changeSkeleton(t),this._recalculateSizeBySkeleton(n,t)})}_recalculateSizeBySkeleton(i,t){var u;const{mainComponent:e,scene:n}=i,r=e,o=(u=t.getSkeletonData())==null?void 0:u.pages;if(o==null)return;let s=0,c=0;for(let d=0,p=o.length;d<p;d++){const g=o[d],{pageWidth:m,pageHeight:h}=g;r.pageLayoutType===O.PageLayoutType.VERTICAL?(c+=h,c+=r.pageMarginTop,d===p-1&&(c+=r.pageMarginTop),s=Math.max(s,m)):r.pageLayoutType===O.PageLayoutType.HORIZONTAL&&(s+=m,d!==p-1&&(s+=r.pageMarginLeft),c=Math.max(c,h))}r.resize(s,c),[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(i.unitId)||n.resize(s,c)}_commandExecutedListener(){const i=[_.id],t=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(i.includes(e.id)){const r=e.params,{unitId:o}=r,s=this._docSkeletonManagerService.getSkeletonByUnitId(o);if(s==null)return;const{skeleton:c}=s,l=this._renderManagerService.getRenderById(o);if(l==null)return;if(c.calculate(),t.includes(o)){(n=l.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(l,c)}}))}};de=Jt([a.OnLifecycle(a.LifecycleStages.Rendered,de),xe(0,T.Inject(exports.DocSkeletonManagerService)),xe(1,O.IRenderManagerService),xe(2,a.ICommandService)],de);var Qt=Object.defineProperty,en=Object.getOwnPropertyDescriptor,tn=(i,t,e,n)=>{for(var r=n>1?void 0:n?en(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Qt(t,e,r),r},Y=(i,t)=>(e,n)=>t(e,n,i);let ue=class extends a.Disposable{constructor(t,e,n,r,o){super();v(this,"_liquid",new O.Liquid);v(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._commandService=r,this._floatingObjectManagerService=o,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){this._floatingObjectManagerService.pluginUpdate$.subscribe(t=>{const e=this._docSkeletonManagerService.getCurrent();if(e==null)return;const{unitId:n,skeleton:r}=e,o=this._renderManagerService.getRenderById(n);if(o==null)return;const{mainComponent:s,components:c,scene:l}=o,u=s,{left:d,top:p}=u;t.forEach(g=>{const{unitId:m,subUnitId:h,floatingObjectId:f,floatingObject:S}=g,{left:C=0,top:I=0,width:D=0,height:y=0,angle:M,flipX:b,flipY:U,skewX:E,skewY:P}=S,R=this._pageMarginCache.get(f),L=(R==null?void 0:R.marginLeft)||0,N=(R==null?void 0:R.marginTop)||0;r==null||r.getViewModel().getDataModel().updateDrawing(f,{left:C-d-L,top:I-p-N,height:y,width:D})}),r==null||r.calculate(),s==null||s.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{skeleton:e,unitId:n}=t,r=this._renderManagerService.getRenderById(n);if(r==null)return;const{mainComponent:o}=r;o.changeSkeleton(e),this._refreshFloatingObject(n,e,r)})}_commandExecutedListener(){const t=[_.id,k.id],e=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var r;if(t.includes(n.id)){const o=n.params,{unitId:s}=o,c=this._docSkeletonManagerService.getCurrent();if(c==null)return;const{unitId:l,skeleton:u}=c;if(s!==l)return;const d=this._renderManagerService.getRenderById(l);if(d==null)return;if(e.includes(l)){(r=d.mainComponent)==null||r.makeDirty();return}this._refreshFloatingObject(l,u,d)}}))}_refreshFloatingObject(t,e,n){const r=e==null?void 0:e.getSkeletonData(),{mainComponent:o,scene:s}=n,c=o;if(!r)return;const{left:l,top:u,pageLayoutType:d,pageMarginLeft:p,pageMarginTop:g}=c,{pages:m}=r,h=[];s.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let f=0,S=m.length;f<S;f++){const C=m[f],{skeDrawings:I,marginLeft:D,marginTop:y}=C;this._liquid.translatePagePadding(C),I.forEach(M=>{const{aLeft:b,aTop:U,height:E,width:P,objectId:R}=M;h.push({unitId:t,subUnitId:a.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:R,floatingObject:{left:b+l+this._liquid.x,top:U+u+this._liquid.y,width:P,height:E}}),this._pageMarginCache.set(R,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(C,d,p,g)}this._floatingObjectManagerService.BatchAddOrUpdate(h)}};ue=tn([a.OnLifecycle(a.LifecycleStages.Steady,ue),Y(0,T.Inject(exports.DocSkeletonManagerService)),Y(1,a.IUniverInstanceService),Y(2,O.IRenderManagerService),Y(3,a.ICommandService),Y(4,a.IFloatingObjectManagerService)],ue);var nn=Object.defineProperty,rn=Object.getOwnPropertyDescriptor,on=(i,t,e,n)=>{for(var r=n>1?void 0:n?rn(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&nn(t,e,r),r},G=(i,t)=>(e,n)=>t(e,n,i);let me=class extends a.Disposable{constructor(t,e,n,r,o,s){super();v(this,"_previousIMEContent","");v(this,"_previousIMERange");v(this,"_onStartSubscription");v(this,"_onUpdateSubscription");v(this,"_onEndSubscription");this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._textSelectionRenderManager=r,this._imeInputManagerService=o,this._commandService=s,this._initialize()}dispose(){var t,e,n;(t=this._onStartSubscription)==null||t.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(n=this._onEndSubscription)==null||n.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(t=>{if(t==null)return;const{activeRange:e}=t;e!=null&&(this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(a.Tools.deepClone(e)),this._previousIMERange=e)})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async t=>{this._updateContent(t,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(t=>{this._updateContent(t,!1)})}async _updateContent(t,e){var h;const n=(h=this._docSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(this._previousIMERange==null||t==null||n==null)return;const r=this._currentUniverService.getCurrentUniverDocInstance(),{event:o,activeRange:s}=t,{startOffset:c,segmentId:l,style:u}=this._previousIMERange;if(n==null||s==null)return;const p=o.data;if(p===this._previousIMEContent&&e)return;const g=p.length,m=[{startOffset:c+g,endOffset:c+g,style:u}];await this._commandService.executeCommand($e.id,{unitId:r.getUnitId(),newText:p,oldTextLen:this._previousIMEContent.length,range:this._previousIMERange,textRanges:m,isCompositionEnd:!e,segmentId:l}),e?(this._previousIMERange.collapsed||(this._previousIMERange.collapsed=!0),this._previousIMEContent=p):this._resetIME()}_resetIME(){this._previousIMEContent="",this._previousIMERange=null,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}_getDocObject(){return Q(this._currentUniverService,this._renderManagerService)}};me=on([a.OnLifecycle(a.LifecycleStages.Rendered,me),G(0,T.Inject(exports.DocSkeletonManagerService)),G(1,a.IUniverInstanceService),G(2,O.IRenderManagerService),G(3,O.ITextSelectionRenderManager),G(4,T.Inject(Be)),G(5,a.ICommandService)],me);var sn=Object.defineProperty,an=Object.getOwnPropertyDescriptor,cn=(i,t,e,n)=>{for(var r=n>1?void 0:n?an(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&sn(t,e,r),r},Ze=(i,t)=>(e,n)=>t(e,n,i);let ge=class extends a.Disposable{constructor(i,t){super(),this._textSelectionManagerService=i,this._commandService=t,this._commandExecutedListener()}_commandExecutedListener(){const i=[W.id,ee.id,te.id,ne.id,B.id,V.id,H.id,K.id,re.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{i.includes(t.id)&&this._handleInlineFormat(t)}))}_handleInlineFormat(i){const{segmentId:t}=this._textSelectionManagerService.getActiveRange()??{};t!=null&&this._commandService.executeCommand(Fe.id,{segmentId:t,preCommandId:i.id,...i.params??{}})}};ge=cn([a.OnLifecycle(a.LifecycleStages.Rendered,ge),Ze(0,T.Inject(exports.TextSelectionManagerService)),Ze(1,a.ICommandService)],ge);var ln=Object.defineProperty,dn=Object.getOwnPropertyDescriptor,un=(i,t,e,n)=>{for(var r=n>1?void 0:n?dn(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&ln(t,e,r),r},X=(i,t)=>(e,n)=>t(e,n,i);let pe=class extends a.Disposable{constructor(t,e,n,r,o){super();v(this,"_onInputSubscription");this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._textSelectionManagerService=r,this._commandService=o,this._initialize(),this._commandExecutedListener()}dispose(){var t;(t=this._onInputSubscription)==null||t.unsubscribe()}_initialize(){}_commandExecutedListener(){const t=[$.id,F.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!t.includes(e.id))return;const n=e.params;switch(e.id){case $.id:return this._handleMoveCursor(n.direction);case F.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(t){var f;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),r=this._currentUniverService.getCurrentUniverDocInstance(),o=(f=this._docSkeletonManagerService.getCurrent())==null?void 0:f.skeleton,s=this._getDocObject();if(e==null||o==null||s==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d,direction:p}=e;if(n.length>1){let S=1/0,C=-1/0;for(const I of n)S=Math.min(S,I.startOffset),C=Math.max(C,I.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:t===a.Direction.LEFT||t===a.Direction.UP?C:S,endOffset:t===a.Direction.LEFT||t===a.Direction.UP?S:C,style:u}]);return}const g=d||p===O.RANGE_DIRECTION.FORWARD?c:l;let m=d||p===O.RANGE_DIRECTION.FORWARD?l:c;const h=r.getBody().dataStream.length??1/0;if(t===a.Direction.LEFT||t===a.Direction.RIGHT){const S=o.findNodeByCharIndex(m-1),C=o.findNodeByCharIndex(m);m=t===a.Direction.RIGHT?m+C.count:m-((S==null?void 0:S.count)??0),m=Math.min(h-2,Math.max(0,m)),this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:m,style:u}])}else{const S=o.findNodeByCharIndex(m),C=s.document.getOffsetConfig(),I=this._getTopOrBottomPosition(o,S,t===a.Direction.DOWN);if(I==null){const y=t===a.Direction.UP?0:h-2;if(y===m)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:y,style:u}]);return}const D=new O.NodePositionConvertToCursor(C,o).getRangePointData(I,I).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:g,endOffset:D.endOffset,style:u}])}}_handleMoveCursor(t){var g;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),r=this._currentUniverService.getCurrentUniverDocInstance(),o=(g=this._docSkeletonManagerService.getCurrent())==null?void 0:g.skeleton,s=this._getDocObject();if(e==null||o==null||s==null||n==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d}=e,p=r.getBody().dataStream.length??1/0;if(t===a.Direction.LEFT||t===a.Direction.RIGHT){let m;if(!e.collapsed||n.length>1){let h=1/0,f=-1/0;for(const S of n)h=Math.min(h,S.startOffset),f=Math.max(f,S.endOffset);m=t===a.Direction.LEFT?h:f}else{const h=o.findNodeByCharIndex(c-1),f=o.findNodeByCharIndex(c);t===a.Direction.LEFT?m=Math.max(0,c-((h==null?void 0:h.count)??0)):m=Math.min(p-2,l+f.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:m,endOffset:m,style:u}])}else{const m=o.findNodeByCharIndex(c),h=o.findNodeByCharIndex(l),f=s.document.getOffsetConfig(),S=this._getTopOrBottomPosition(o,t===a.Direction.UP?m:h,t===a.Direction.DOWN);if(S==null){let I;d?I=t===a.Direction.UP?0:p-2:I=t===a.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:I,endOffset:I,style:u}]);return}const C=new O.NodePositionConvertToCursor(f,o).getRangePointData(S,S).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...C,style:u}])}}_getTopOrBottomPosition(t,e,n){if(e==null)return;const r=this._getSpanLeftOffsetInLine(e),o=this._getNextOrPrevLine(e,n);if(o==null)return;const s=this._matchPositionByLeftOffset(t,o,r);if(s!=null)return{...s,isBack:!0}}_getSpanLeftOffsetInLine(t){const e=t.parent;if(e==null)return-1/0;const n=e.left,{left:r}=t;return n+r}_matchPositionByLeftOffset(t,e,n){const r={distance:1/0};for(const o of e.divides){const s=o.left;for(const c of o.spanGroup){const{left:l}=c,u=s+l,d=Math.abs(n-u);d<r.distance&&(r.span=c,r.distance=d)}}if(r.span!=null)return t.findPositionBySpan(r.span)}_getNextOrPrevLine(t,e){var h,f,S,C,I,D,y,M,b,U,E,P;const n=t.parent;if(n==null)return;const r=n.parent;if(r==null)return;const o=r.parent;if(o==null)return;const s=o.lines.indexOf(r);if(s===-1)return;let c;if(e===!0?c=o.lines[s+1]:c=o.lines[s-1],c!=null)return c;const l=o.parent;if(l==null)return;const u=l.columns.indexOf(o);if(u===-1)return;if(e===!0)c=(h=l.columns[u+1])==null?void 0:h.lines[0];else{const R=(S=(f=l.columns)==null?void 0:f[u-1])==null?void 0:S.lines;c=R==null?void 0:R[R.length-1]}if(c!=null)return c;const d=l.parent;if(d==null)return;const p=d.sections.indexOf(l);if(p===-1)return;if(e===!0)c=(I=(C=d.sections[p-1])==null?void 0:C.columns[0])==null?void 0:I.lines[0];else{const R=(y=(D=d.sections)==null?void 0:D[p-1])==null?void 0:y.columns,L=R==null?void 0:R[R.length-1],N=L==null?void 0:L.lines;c=N==null?void 0:N[N.length-1]}if(c!=null)return c;const g=d.parent;if(g==null)return;const m=g.pages.indexOf(d);if(m!==-1){if(e===!0)c=(U=(b=(M=g.pages[m+1])==null?void 0:M.sections[0])==null?void 0:b.columns[0])==null?void 0:U.lines[0];else{const R=(E=g.pages[m-1])==null?void 0:E.sections;if(R==null)return;const L=(P=R[R.length-1])==null?void 0:P.columns,N=L[L.length-1],Ve=N==null?void 0:N.lines;c=Ve[Ve.length-1]}if(c!=null)return c}}_getDocObject(){return Q(this._currentUniverService,this._renderManagerService)}};pe=un([a.OnLifecycle(a.LifecycleStages.Rendered,pe),X(0,T.Inject(exports.DocSkeletonManagerService)),X(1,a.IUniverInstanceService),X(2,O.IRenderManagerService),X(3,T.Inject(exports.TextSelectionManagerService)),X(4,a.ICommandService)],pe);var mn=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,pn=(i,t,e,n)=>{for(var r=n>1?void 0:n?gn(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&mn(t,e,r),r},q=(i,t)=>(e,n)=>t(e,n,i);let he=class extends a.Disposable{constructor(t,e,n,r,o){super();v(this,"_onInputSubscription");this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._textSelectionRenderManager=r,this._commandService=o,this._initialize(),this._commandExecutedListener()}dispose(){var t;(t=this._onInputSubscription)==null||t.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async t=>{var h;if(t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:r,content:o="",activeRange:s}=t,c=r,l=(h=this._docSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(c.data==null||l==null||!l||!s)return;const{startOffset:u,segmentId:d,style:p}=s,g=o.length,m=[{startOffset:u+g,endOffset:u+g,style:p}];await this._commandService.executeCommand(Re.id,{unitId:n,body:{dataStream:o},range:s,textRanges:m,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return Q(this._currentUniverService,this._renderManagerService)}};he=pn([a.OnLifecycle(a.LifecycleStages.Rendered,he),q(0,T.Inject(exports.DocSkeletonManagerService)),q(1,a.IUniverInstanceService),q(2,O.IRenderManagerService),q(3,O.ITextSelectionRenderManager),q(4,a.ICommandService)],he);var hn=Object.defineProperty,fn=Object.getOwnPropertyDescriptor,Sn=(i,t,e,n)=>{for(var r=n>1?void 0:n?fn(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&hn(t,e,r),r},Je=(i,t)=>(e,n)=>t(e,n,i);const _n="rgba(198, 198, 198, 1)",vn="rgba(255, 255, 255, 1)";let fe=class extends a.Disposable{constructor(i,t){super(),this._renderManagerService=i,this._currentUniverService=t,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this._renderManagerService.currentRender$.subscribe(i=>{var o;if(i==null||this._currentUniverService.getUniverDocInstance(i)==null)return;const t=this._renderManagerService.getRenderById(i);if(t==null)return;const{mainComponent:e}=t,n=e,r=(o=n.getSkeleton())==null?void 0:o.getPageSize();n.onPageRenderObservable.add(s=>{if([a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(i))return;const{page:c,pageLeft:l,pageTop:u,ctx:d}=s,{width:p,pageWidth:g,height:m,pageHeight:h}=c;d.save(),d.translate(l-.5,u-.5),O.Rect.drawWith(d,{width:(r==null?void 0:r.width)??g??p,height:(r==null?void 0:r.height)??h??m,strokeWidth:1,stroke:_n,fill:vn,zIndex:3}),d.restore()})})}_commandExecutedListener(){}};fe=Sn([a.OnLifecycle(a.LifecycleStages.Rendered,fe),Je(0,O.IRenderManagerService),Je(1,T.Inject(a.IUniverInstanceService))],fe);var Cn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Mn=(i,t,e,n)=>{for(var r=n>1?void 0:n?In(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&Cn(t,e,r),r},j=(i,t)=>(e,n)=>t(e,n,i);let Se=class extends a.Disposable{constructor(t,e,n,r,o,s,c){super();v(this,"_moveInObserver");v(this,"_moveOutObserver");v(this,"_downObserver");v(this,"_dblClickObserver");v(this,"_tripleClickObserver");v(this,"_loadedMap",new Set);this._docSkeletonManagerService=t,this._currentUniverService=e,this._commandService=n,this._renderManagerService=r,this._textSelectionRenderManager=o,this._textSelectionManagerService=s,this._layoutService=c,this._renderManagerService.currentRender$.subscribe(l=>{l!=null&&this._currentUniverService.getUniverDocInstance(l)!=null&&(this._loadedMap.has(l)||(this._initialMain(l),this._loadedMap.add(l)))}),this._initialize()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._layoutService&&this.disposeWithMe(this._layoutService.registerContainer(this._textSelectionRenderManager.__getEditorContainer()))}dispose(){this._renderManagerService.getRenderAll().forEach(t=>{const{mainComponent:e}=t;e!=null&&(e.onPointerEnterObserver.remove(this._moveInObserver),e.onPointerLeaveObserver.remove(this._moveOutObserver),e.onPointerDownObserver.remove(this._downObserver),e.onDblclickObserver.remove(this._dblClickObserver),e.onTripleClickObserver.remove(this._tripleClickObserver))})}_initialMain(t){const e=this._getDocObjectById(t);if(e==null)return;const{document:n,scene:r}=e;this._moveInObserver=n.onPointerEnterObserver.add(()=>{n.cursor=O.CURSOR_TYPE.TEXT}),this._moveOutObserver=n.onPointerLeaveObserver.add(()=>{n.cursor=O.CURSOR_TYPE.DEFAULT,r.resetCursor()}),this._downObserver=n==null?void 0:n.onPointerDownObserver.add((o,s)=>{this._currentUniverService.getCurrentUniverDocInstance().getUnitId()!==t&&this._currentUniverService.setCurrentUniverDocInstance(t),this._textSelectionRenderManager.eventTrigger(o),o.button!==2&&s.stopPropagation()}),this._dblClickObserver=n==null?void 0:n.onDblclickObserver.add(o=>{this._textSelectionRenderManager.handleDblClick(o)}),this._tripleClickObserver=n==null?void 0:n.onTripleClickObserver.add(o=>{this._textSelectionRenderManager.handleTripleClick(o)})}_commandExecutedListener(){const t=[k.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(t.includes(e.id)){const r=e.params,{unitId:o}=r,s=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(o!==s)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{unitId:e,skeleton:n}=t,r=this._renderManagerService.getRenderById(e);if(r==null)return;const{scene:o,mainComponent:s}=r;this._textSelectionRenderManager.changeRuntime(n,o,s),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:e,subUnitId:""})})}_getDocObjectById(t){return gt(t,this._renderManagerService)}};Se=Mn([a.OnLifecycle(a.LifecycleStages.Rendered,Se),j(0,T.Inject(exports.DocSkeletonManagerService)),j(1,a.IUniverInstanceService),j(2,a.ICommandService),j(3,O.IRenderManagerService),j(4,O.ITextSelectionRenderManager),j(5,T.Inject(exports.TextSelectionManagerService)),j(6,T.Optional(x.LayoutService))],Se);var On=Object.defineProperty,Rn=Object.getOwnPropertyDescriptor,yn=(i,t,e,n)=>{for(var r=n>1?void 0:n?Rn(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&On(t,e,r),r},Z=(i,t)=>(e,n)=>t(e,n,i);let _e=class extends a.Disposable{constructor(t,e,n,r,o){super();v(this,"_initializedRender",new Set);this._docSkeletonManagerService=t,this._currentUniverService=e,this._commandService=n,this._renderManagerService=r,this._textSelectionManagerService=o,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{unitId:e}=t,n=this._renderManagerService.getRenderById(e);if(n==null||this._initializedRender.has(e)||[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(e))return;this._initializedRender.add(e);const{scene:r}=n;this.disposeWithMe(a.toDisposable(r.onMouseWheelObserver.add(o=>{if(!o.ctrlKey)return;const s=Math.abs(o.deltaX);let c=s<40?.2:s<80?.4:.2;c*=o.deltaY>0?-1:1,r.scaleX<1&&(c/=2);const l=this._currentUniverService.getCurrentUniverDocInstance(),u=l.zoomRatio;let d=+parseFloat(`${u+c}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(ct.id,{zoomRatio:d,unitId:l.getUnitId()}),o.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(a.toDisposable(this._docSkeletonManagerService.currentSkeletonBefore$.subscribe(t=>{if(t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const t=[k.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=this._currentUniverService.getCurrentUniverDocInstance(),r=e.params,{unitId:o}=r;if(o!==n.getUnitId())return;const s=n.zoomRatio||1;this._updateViewZoom(s)}}))}_updateViewZoom(t,e=!0){var r;const n=this._getDocObject();n!=null&&(n.scene.scale(t,t),this._calculatePagePosition(n,t),e&&this._textSelectionManagerService.refreshSelection(),(r=n.scene.getTransformer())==null||r.hideControl())}_calculatePagePosition(t,e){const{document:n,scene:r}=t,o=r==null?void 0:r.getParent(),{width:s,height:c,pageMarginLeft:l,pageMarginTop:u}=n;if(o==null||s===1/0||c===1/0)return;const{width:d,height:p}=o;let g=0,m=0,h=0,f=0,S=1/0;d>(s+l*2)*e?(g=d/2-s*e/2,g/=e,h=(d-l*2)/e,S=0):(g=l,h=s+l*2,S=(h-d/e)/2),p>c?(m=p/2-c/2,f=(p-u*2)/e):(m=u,f=c+u*2),r.resize(h,f+200),n.translate(g,m);const C=r.getViewport(Me.VIEW_MAIN);if(S!==1/0&&C!=null){const I=C.getBarScroll(S,0).x;C.scrollTo({x:I})}return this}_getDocObject(){return Q(this._currentUniverService,this._renderManagerService)}};_e=yn([a.OnLifecycle(a.LifecycleStages.Rendered,_e),Z(0,T.Inject(exports.DocSkeletonManagerService)),Z(1,a.IUniverInstanceService),Z(2,a.ICommandService),Z(3,O.IRenderManagerService),Z(4,T.Inject(exports.TextSelectionManagerService))],_e);const xn={id:Ne.id,preconditions:i=>i.getContextValue(a.FOCUSING_DOC),binding:x.KeyCode.ENTER},Dn={id:we.id,preconditions:i=>i.getContextValue(a.FOCUSING_DOC),binding:x.KeyCode.BACKSPACE},Tn={id:Le.id,preconditions:i=>i.getContextValue(a.FOCUSING_DOC),binding:x.KeyCode.DELETE},bn={id:$.id,binding:x.KeyCode.ARROW_UP,preconditions:i=>i.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},Un={id:$.id,binding:x.KeyCode.ARROW_DOWN,preconditions:i=>i.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},En={id:$.id,binding:x.KeyCode.ARROW_LEFT,preconditions:i=>i.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},Pn={id:$.id,binding:x.KeyCode.ARROW_RIGHT,preconditions:i=>i.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},Nn={id:F.id,binding:x.KeyCode.ARROW_UP|x.MetaKeys.SHIFT,preconditions:i=>i.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},wn={id:F.id,binding:x.KeyCode.ARROW_DOWN|x.MetaKeys.SHIFT,preconditions:i=>i.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},Ln={id:F.id,binding:x.KeyCode.ARROW_LEFT|x.MetaKeys.SHIFT,preconditions:i=>i.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},An={id:F.id,binding:x.KeyCode.ARROW_RIGHT|x.MetaKeys.SHIFT,preconditions:i=>i.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},Bn={id:lt.id,binding:x.KeyCode.A|x.MetaKeys.CTRL_COMMAND,preconditions:i=>i.getContextValue(a.FOCUSING_DOC)||i.getContextValue(a.FOCUSING_EDITOR)};var $n=Object.defineProperty,Fn=Object.getOwnPropertyDescriptor,jn=(i,t,e,n)=>{for(var r=n>1?void 0:n?Fn(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&$n(t,e,r),r},ie=(i,t)=>(e,n)=>t(e,n,i);exports.DocCanvasView=class extends a.RxDisposable{constructor(e,n,r,o){super();v(this,"_scene");v(this,"_currentDocumentModel");v(this,"_loadedMap",new Set);v(this,"_fps$",new w.BehaviorSubject(""));v(this,"fps$",this._fps$.asObservable());this._renderManagerService=e,this._configService=n,this._currentUniverService=r,this._docViewModelManagerService=o,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.pipe(w.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;this._currentDocumentModel=e;const n=e.getUnitId();this._loadedMap.has(n)||(this._addNewRender(),this._loadedMap.add(n))})}dispose(){this._fps$.complete()}_addNewRender(){const e=this._currentDocumentModel,n=e.getUnitId(),r=e.getContainer(),o=e.getParentRenderUnitId();if(r!=null&&o!=null)throw new Error("container or parentRenderUnitId can only exist one");r==null&&o!=null?this._renderManagerService.createRenderWithParent(n,o):this._renderManagerService.createRender(n);const s=this._renderManagerService.getRenderById(n);if(s==null)return;const{scene:c,engine:l}=s;c.openTransformer(),this._scene=c;const u=new O.Viewport(Me.VIEW_MAIN,c,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});c.attachControl(),c.on(O.EVENT_TYPE.wheel,(g,m)=>{const h=g;if(h.ctrlKey){const f=Math.abs(h.deltaX);let S=f<40?.2:f<80?.4:.2;S*=h.deltaY>0?-1:1,c.scaleX<1&&(S/=2),c.scaleX+S>4?c.scale(4,4):c.scaleX+S<.1?c.scale(.1,.1):h.preventDefault()}else u.onMouseWheel(h,m)}),this._configService.getConfig("hasScroll")!==!1&&n!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&new O.ScrollBar(u),c.addLayer(new O.Layer(c,[],Te),new O.Layer(c,[],Qe)),this._addComponent(s),this._currentDocumentModel.getShouldRenderLoopImmediately()&&l.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(l.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(e){const n=this._scene,r=this._currentDocumentModel,o=new O.Documents(ve.MAIN,void 0,{pageMarginLeft:r.documentStyle.marginLeft||0,pageMarginTop:r.documentStyle.marginTop||0});o.zIndex=et,e.mainComponent=o,e.components.set(ve.MAIN,o),n.addObjects([o],Te)}};exports.DocCanvasView=jn([a.OnLifecycle(a.LifecycleStages.Ready,exports.DocCanvasView),ie(0,O.IRenderManagerService),ie(1,a.IConfigService),ie(2,a.IUniverInstanceService),ie(3,T.Inject(exports.DocViewModelManagerService))],exports.DocCanvasView);var kn=Object.defineProperty,Vn=Object.getOwnPropertyDescriptor,zn=(i,t,e,n)=>{for(var r=n>1?void 0:n?Vn(t,e):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(r=(n?s(t,e,r):s(r))||r);return n&&r&&kn(t,e,r),r},oe=(i,t)=>(e,n)=>t(e,n,i);const Gn={hasScroll:!0},Wn="docs";var De;exports.UniverDocsPlugin=(De=class extends a.Plugin{constructor(e={},n,r,o,s){super(Wn);v(this,"_config");this._injector=n,this._localeService=r,this._configService=o,this._currentUniverService=s,this._config=Object.assign(Gn,e),this._initializeDependencies(n),this._initializeCommands()}initialize(){}_initializeCommands(){[$,F,we,Le,W,ee,te,ne,B,V,H,K,re,Fe,Ne,Re,ye,Pe,$e,Ae,_,ot,st,ct,k,Ee,lt,it,rt,je].forEach(e=>{this._injector.get(a.ICommandService).registerCommand(e)}),[bn,Un,Pn,En,Nn,wn,Ln,An,Bn,Dn,Tn,xn].forEach(e=>{this._injector.get(x.IShortcutService).registerShortcut(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[exports.DocCanvasView],[exports.DocSkeletonManagerService],[exports.DocViewModelManagerService],[Be],[dt,{useClass:Ue}],[O.ITextSelectionRenderManager,{useClass:O.TextSelectionRenderManager}],[exports.TextSelectionManagerService],[de],[fe],[Se],[he],[me],[ge],[le],[pe],[_e],[ue]].forEach(n=>e.add(n))}},v(De,"type",a.PluginType.Doc),De);exports.UniverDocsPlugin=zn([oe(1,T.Inject(T.Injector)),oe(2,T.Inject(a.LocaleService)),oe(3,a.IConfigService),oe(4,a.IUniverInstanceService)],exports.UniverDocsPlugin);exports.BreakLineCommand=Ne;exports.BulletListCommand=rt;exports.CoverContentCommand=st;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=et;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=Qe;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=Te;exports.DOCS_VIEW_KEY=ve;exports.DeleteCommand=ye;exports.DeleteLeftCommand=we;exports.DeleteRightCommand=Le;exports.DocCopyCommand=se;exports.DocCutCommand=ae;exports.DocPasteCommand=ce;exports.IMEInputCommand=$e;exports.InsertCommand=Re;exports.MoveCursorOperation=$;exports.MoveSelectionOperation=F;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=pt;exports.OrderListCommand=it;exports.ReplaceContentCommand=ot;exports.RichTextEditingMutation=_;exports.SetInlineFormatBoldCommand=W;exports.SetInlineFormatCommand=Fe;exports.SetInlineFormatFontFamilyCommand=K;exports.SetInlineFormatFontSizeCommand=H;exports.SetInlineFormatItalicCommand=ee;exports.SetInlineFormatStrikethroughCommand=ne;exports.SetInlineFormatSubscriptCommand=B;exports.SetInlineFormatSuperscriptCommand=V;exports.SetInlineFormatTextColorCommand=re;exports.SetInlineFormatUnderlineCommand=te;exports.SetTextSelectionsOperation=Ee;exports.UpdateCommand=Pe;exports.VIEWPORT_KEY=Me;exports.getDocObject=Q;
|
|
1
|
+
"use strict";var pt=Object.defineProperty;var gt=(i,t,e)=>t in i?pt(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var C=(i,t,e)=>(gt(i,typeof t!="symbol"?t+"":t,e),e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("@univerjs/core"),M=require("@univerjs/engine-render"),P=require("rxjs"),b=require("@univerjs/ui"),E=require("@wendellhu/redi");function ee(i,t){const n=i.getCurrentUniverDocInstance().getUnitId(),r=t.getRenderById(n);if(r==null)return;const{mainComponent:o,scene:a,engine:c}=r;return{document:o,scene:a,engine:c}}function ht(i,t){const e=t.getRenderById(i);if(e==null)return;const{mainComponent:n,scene:r,engine:o}=e;return{document:n,scene:r,engine:o}}var _e=(i=>(i.MAIN="__Document_Render_Main__",i))(_e||{}),Ie=(i=>(i.VIEW_MAIN="viewMain",i.VIEW_TOP="viewTop",i.VIEW_LEFT="viewLeft",i.VIEW_LEFT_TOP="viewLeftTop",i))(Ie||{});const xe=0,Je=2,Qe=10,ft="normalTextSelectionPluginName",Ee={id:"doc.operation.set-selections",type:s.CommandType.OPERATION,handler:(i,t)=>!0};var St=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,vt=(i,t,e,n)=>{for(var r=n>1?void 0:n?_t(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&St(t,e,r),r},ze=(i,t)=>(e,n)=>t(e,n,i);function We(i){const{startOffset:t,endOffset:e,collapsed:n}=i;return{startOffset:t,endOffset:e,collapsed:n}}exports.TextSelectionManagerService=class extends s.RxDisposable{constructor(e,n){super();C(this,"_currentSelection",null);C(this,"_textSelectionInfo",new Map);C(this,"_textSelection$",new P.BehaviorSubject(null));C(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=e,this._commandService=n,this._syncSelectionFromRenderService()}getCurrentSelection(){return this._currentSelection}getCurrentSelectionInfo(){return this._getTextRanges(this._currentSelection)}dispose(){this._textSelection$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getSelections(){var e;return(e=this._getTextRanges(this._currentSelection))==null?void 0:e.textRanges}getActiveRange(){const e=this._getTextRanges(this._currentSelection);if(e==null)return;const{textRanges:n,segmentId:r,style:o}=e,a=n.find(g=>g.isActive());if(a==null)return null;const{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:m,direction:p}=a;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:m,direction:p,segmentId:r,style:o}}add(e){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e,segmentId:"",style:M.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(e){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(e))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._replaceTextRangesWithNoRefresh(e)})}_replaceTextRangesWithNoRefresh(e){if(this._currentSelection==null)return;const n={...this._currentSelection,...e};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:r,subUnitId:o,segmentId:a,style:c,textRanges:l}=n;this._commandService.executeCommand(Ee.id,{unitId:r,subUnitId:o,segmentId:a,style:c,ranges:l.map(We)})}_getTextRanges(e){var o;if(e==null)return;const{unitId:n,subUnitId:r=""}=e;return(o=this._textSelectionInfo.get(n))==null?void 0:o.get(r)}_refresh(e){const n=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),n&&Array.isArray(n.textRanges)&&n.textRanges.length&&this._textSelectionRenderManager.addTextRanges(n.textRanges.map(We))}_replaceByParam(e){const{unitId:n,subUnitId:r,style:o,segmentId:a,textRanges:c}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map),this._textSelectionInfo.get(n).set(r,{textRanges:c,style:o,segmentId:a})}_addByParam(e){const{unitId:n,subUnitId:r,textRanges:o,style:a,segmentId:c}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map);const l=this._textSelectionInfo.get(n);l.has(r)?l.get(r).textRanges.push(...o):l.set(r,{textRanges:o,style:a,segmentId:c})}};exports.TextSelectionManagerService=vt([ze(0,M.ITextSelectionRenderManager),ze(1,s.ICommandService)],exports.TextSelectionManagerService);function Ue(i,t="",e=0){const{startOffset:n,endOffset:r}=i,o=[],a=n-e,c=r-e;return a>0&&o.push({t:s.TextXActionType.RETAIN,len:a,segmentId:t}),o.push({t:s.TextXActionType.DELETE,len:c-a,line:0,segmentId:t}),o}var It=Object.defineProperty,Ct=Object.getOwnPropertyDescriptor,Mt=(i,t,e,n)=>{for(var r=n>1?void 0:n?Ct(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&It(t,e,r),r},Rt=(i,t)=>(e,n)=>t(e,n,i);exports.DocViewModelManagerService=class extends s.RxDisposable{constructor(e){super();C(this,"_currentViewModelUnitId","");C(this,"_docViewModelMap",new Map);C(this,"_currentDocViewModel$",new P.BehaviorSubject(null));C(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;const n=e.getUnitId();this._setCurrent(n)})}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap.clear()}getCurrent(){return this._docViewModelMap.get(this._currentViewModelUnitId)}getViewModel(e){var n;return(n=this._docViewModelMap.get(e))==null?void 0:n.docViewModel}_setCurrent(e){var r;const n=this._currentUniverService.getUniverDocInstance(e);if(n==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(n.getBody()!=null){if(!this._docViewModelMap.has(e)){const o=this._buildDocViewModel(n);this._docViewModelMap.set(e,{unitId:e,docViewModel:o})}if(e===s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const o=(r=this._docViewModelMap.get(e))==null?void 0:r.docViewModel;if(o==null)return;o.reset(n)}this._currentViewModelUnitId=e,this._currentDocViewModel$.next(this.getCurrent())}}_buildDocViewModel(e){return new M.DocumentViewModel(e)}};exports.DocViewModelManagerService=Mt([Rt(0,s.IUniverInstanceService)],exports.DocViewModelManagerService);const _={id:"doc.mutation.rich-text-editing",type:s.CommandType.MUTATION,handler:(i,t)=>{const{unitId:e,mutations:n}=t,o=i.get(s.IUniverInstanceService).getUniverDocInstance(e),c=i.get(exports.DocViewModelManagerService).getViewModel(e);if(o==null||c==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);if(n.length===0)throw new Error("Mutation's length should great than 0 when call RichTextEditingMutation");const l=o.apply(n),{segmentId:u}=n[0],d=o.getSelfOrHeaderFooterModel(u);return c.getSelfOrHeaderFooterViewModel(u).reset(d),{unitId:e,mutations:l}}},Ce={id:"doc.command.insert-text",type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.IUndoRedoService),n=i.get(s.ICommandService),r=i.get(exports.TextSelectionManagerService),{range:o,segmentId:a,body:c,unitId:l,textRanges:u}=t,{startOffset:d,collapsed:m}=o,p={id:_.id,params:{unitId:l,mutations:[]}},g=new s.TextX;m?d>0&&g.push({t:s.TextXActionType.RETAIN,len:d,segmentId:a}):g.push(...Ue(o,a)),g.push({t:s.TextXActionType.INSERT,body:c,len:c.dataStream.length,line:0,segmentId:a}),p.params.mutations=g.serialize();const h=n.syncExecuteCommand(p.id,p.params);return r.replaceTextRanges(u),h?(e.pushUndoRedo({unitID:l,undoMutations:[{id:_.id,params:h}],redoMutations:[{id:_.id,params:p.params}],undo(){return n.syncExecuteCommand(_.id,h),r.replaceTextRanges([o]),!0},redo(){return n.syncExecuteCommand(_.id,p.params),r.replaceTextRanges(u),!0}}),!0):!1}};var L=(i=>(i[i.LEFT=0]="LEFT",i[i.RIGHT=1]="RIGHT",i))(L||{});const Me={id:"doc.command.delete-text",type:s.CommandType.COMMAND,handler:async(i,t)=>{const e=i.get(s.ICommandService),n=i.get(s.IUndoRedoService),r=i.get(exports.TextSelectionManagerService),{range:o,segmentId:a,unitId:c,direction:l,textRanges:u,len:d=1}=t,{startOffset:m}=o,p={id:_.id,params:{unitId:c,mutations:[]}},g=new s.TextX;m>0&&g.push({t:s.TextXActionType.RETAIN,len:l===0?m-d:m,segmentId:a}),g.push({t:s.TextXActionType.DELETE,len:d,line:0,segmentId:a}),p.params.mutations=g.serialize();const h=e.syncExecuteCommand(p.id,p.params);return r.replaceTextRanges(u),h&&n.pushUndoRedo({unitID:c,undoMutations:[{id:_.id,params:h}],redoMutations:[{id:_.id,params:p.params}],undo(){return e.syncExecuteCommand(_.id,h),r.replaceTextRanges([o]),!0},redo(){return e.syncExecuteCommand(_.id,p.params),r.replaceTextRanges(u),!0}}),!1}},Pe={id:"doc.command.update-text",type:s.CommandType.COMMAND,handler:async(i,t)=>{const{range:e,segmentId:n,updateBody:r,coverType:o,unitId:a,textRanges:c}=t,l=i.get(s.ICommandService),u=i.get(s.IUndoRedoService),d=i.get(exports.TextSelectionManagerService),m={id:_.id,params:{unitId:a,mutations:[]}},p=new s.TextX,{startOffset:g,endOffset:h}=e;p.push({t:s.TextXActionType.RETAIN,len:g,segmentId:n}),p.push({t:s.TextXActionType.RETAIN,body:r,len:h-g,segmentId:n,coverType:o}),m.params.mutations=p.serialize();const f=l.syncExecuteCommand(m.id,m.params);return d.replaceTextRanges(c),f?(u.pushUndoRedo({unitID:a,undoMutations:[{id:_.id,params:f}],redoMutations:[{id:_.id,params:m.params}],undo(){return l.syncExecuteCommand(_.id,f),d.replaceTextRanges(c),!0},redo(){return l.syncExecuteCommand(_.id,m.params),d.replaceTextRanges(c),!0}}),!0):!1}};function Tt(i,t){const e=[];for(let n=0,r=i.length;n<r;n++)i[n]===s.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:n});if(t)for(const n of e)t.bullet&&(n.bullet=s.Tools.deepClone(t.bullet)),t.paragraphStyle&&(n.paragraphStyle=s.Tools.deepClone(t.paragraphStyle));return e}const Ne={id:"doc.command.break-line",type:s.CommandType.COMMAND,handler:async i=>{var h,f;const t=i.get(exports.TextSelectionManagerService),e=i.get(s.IUniverInstanceService),n=i.get(s.ICommandService),r=t.getActiveRange();if(r==null)return!1;const o=e.getCurrentUniverDocInstance(),a=o.getUnitId(),{startOffset:c,segmentId:l,style:u}=r,d=[{startOffset:c+1,endOffset:c+1,style:u}],p=((f=(h=o.getBody())==null?void 0:h.paragraphs)!=null?f:[]).find(S=>S.startIndex>=c);return await n.executeCommand(Ce.id,{unitId:a,body:{dataStream:s.DataStreamTreeTokenType.PARAGRAPH,paragraphs:Tt(s.DataStreamTreeTokenType.PARAGRAPH,p)},range:r,textRanges:d,segmentId:l})}},et={id:"doc.command.inner-paste",type:s.CommandType.COMMAND,handler:async(i,t)=>{const{segmentId:e,body:n,textRanges:r}=t,o=i.get(s.IUndoRedoService),a=i.get(s.ICommandService),c=i.get(exports.TextSelectionManagerService),l=i.get(s.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;const m=l.getCurrentUniverDocInstance().getUnitId(),p={id:_.id,params:{unitId:m,mutations:[]}},g=new s.MemoryCursor;g.reset();const h=new s.TextX;for(const S of u){const{startOffset:v,endOffset:I,collapsed:R}=S,T=v-g.cursor;R?h.push({t:s.TextXActionType.RETAIN,len:T,segmentId:e}):h.push(...Ue(S,e,g.cursor)),h.push({t:s.TextXActionType.INSERT,body:n,len:n.dataStream.length,line:0,segmentId:e}),g.reset(),g.moveCursor(I)}p.params.mutations=h.serialize();const f=a.syncExecuteCommand(p.id,p.params);return c.replaceTextRanges(r),f?(o.pushUndoRedo({unitID:m,undoMutations:[{id:_.id,params:f}],redoMutations:[{id:_.id,params:p.params}],undo(){return a.syncExecuteCommand(_.id,f),c.replaceTextRanges(u),!0},redo(){return a.syncExecuteCommand(_.id,p.params),c.replaceTextRanges(r),!0}}),!0):!1}},Re={id:"doc.command.inner-cut",type:s.CommandType.COMMAND,handler:async(i,t)=>{const{segmentId:e,textRanges:n}=t,r=i.get(s.IUndoRedoService),o=i.get(s.ICommandService),a=i.get(exports.TextSelectionManagerService),c=i.get(s.IUniverInstanceService),l=a.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const u=c.getCurrentUniverDocInstance().getUnitId(),d=c.getUniverDocInstance(u),m=s.getDocsUpdateBody(d.snapshot,e);if(m==null)return!1;const p={id:_.id,params:{unitId:u,mutations:[]}},g=new s.MemoryCursor;g.reset();const h=new s.TextX;for(const S of l){const{startOffset:v,endOffset:I,collapsed:R}=S,T=v-g.cursor;R?h.push({t:s.TextXActionType.RETAIN,len:T,segmentId:e}):h.push(...yt(S,m,e,g.cursor)),g.reset(),g.moveCursor(I)}p.params.mutations=h.serialize();const f=o.syncExecuteCommand(p.id,p.params);return a.replaceTextRanges(n),f?(r.pushUndoRedo({unitID:u,undoMutations:[{id:_.id,params:f}],redoMutations:[{id:_.id,params:p.params}],undo(){return o.syncExecuteCommand(_.id,f),a.replaceTextRanges(l),!0},redo(){return o.syncExecuteCommand(_.id,p.params),a.replaceTextRanges(n),!0}}),!0):!1}};function yt(i,t,e="",n=0){const{startOffset:r,endOffset:o}=i,a=[],{paragraphs:c=[]}=t,l=r-n,u=o-n,d=c==null?void 0:c.find(m=>m.startIndex-n>=l&&m.startIndex-n<=u);if(l>0&&a.push({t:s.TextXActionType.RETAIN,len:l,segmentId:e}),d&&d.startIndex-n>l){const m=d.startIndex-n;a.push({t:s.TextXActionType.DELETE,len:m-l,line:0,segmentId:e}),a.push({t:s.TextXActionType.RETAIN,len:1,segmentId:e}),u>m+1&&a.push({t:s.TextXActionType.DELETE,len:u-m-1,line:0,segmentId:e})}else a.push({t:s.TextXActionType.DELETE,len:u-l,line:0,segmentId:e});return a}const Ot=10,xt=6;function Dt(){return s.Tools.generateRandomId(xt)}function bt(i){const t=i.match(/data-copy-id="([^\s]+)"/);return t&&t[1]?t[1]:null}class Et{constructor(){C(this,"_cache",new s.LRUMap(Ot))}set(t,e){this._cache.set(t,e)}get(t){return this._cache.get(t)}clear(){this._cache.clear()}}const He=new Et;function Ut(i){const t=i.style,e={};for(let n=0;n<t.length;n++){const r=t[n],o=t.getPropertyValue(r);switch(r){case"margin-top":{const a=parseInt(o);e.spaceAbove=/pt/.test(o)?De(a):a;break}case"margin-bottom":{const a=parseInt(o);e.spaceBelow=/pt/.test(o)?De(a):a;break}}}return Object.getOwnPropertyNames(e).length?e:null}function De(i){return i/.75}function Ae(i){const t=i.style,e={},n=i.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{e.bl=s.BooleanNumber.TRUE;break}case"s":{e.st={s:s.BooleanNumber.TRUE};break}case"u":{e.ul={s:s.BooleanNumber.TRUE};break}case"i":{e.it=s.BooleanNumber.TRUE;break}case"sub":case"sup":{e.va=n==="sup"?s.BaselineOffset.SUPERSCRIPT:s.BaselineOffset.SUBSCRIPT;break}}for(let r=0;r<t.length;r++){const o=t[r],a=t.getPropertyValue(o);switch(o){case"font-family":{e.ff=a;break}case"font-size":{const c=parseInt(a);Number.isNaN(c)||(e.fs=/pt$/.test(a)?De(c):c);break}case"font-style":{a==="italic"&&(e.it=s.BooleanNumber.TRUE);break}case"font-weight":{Number(a)>400&&(e.bl=s.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(a)?e.ul={s:s.BooleanNumber.TRUE}:/overline/.test(a)?e.ol={s:s.BooleanNumber.TRUE}:/line-through/.test(a)&&(e.st={s:s.BooleanNumber.TRUE});break}case"color":{const c=new s.ColorKit(a);c.isValid&&(e.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new s.ColorKit(a);c.isValid&&(e.bg={rgb:c.toRgbString()});break}}}return e}function Pt(i){const t=new DOMParser,e=`<x-univer id="univer-root">${i}</x-univer>`;return t.parseFromString(e,"text/html").querySelector("#univer-root")}function Ge(i,t){const e=i.tagName.toLowerCase();return typeof t=="string"?e===t:Array.isArray(t)?t.some(n=>n===e):t(i)}const ve=class ve{constructor(){C(this,"_styleCache",new Map);C(this,"_styleRules",[]);C(this,"_afterProcessRules",[])}static use(t){if(this._pluginList.includes(t))throw new Error(`Univer paste plugin ${t.name} already added`);this._pluginList.push(t)}convert(t){const e=ve._pluginList.find(o=>o.checkPasteType(t)),n=Pt(t),r={dataStream:"",textRuns:[]};return e&&(this._styleRules=[...e.stylesRules],this._afterProcessRules=[...e.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,r),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],r}_process(t,e,n){var r;for(const o of e)if(o.nodeType===Node.TEXT_NODE){const a=(r=o.nodeValue)==null?void 0:r.replace(/[\r\n]/g,"");let c;t&&this._styleCache.has(t)&&(c=this._styleCache.get(t)),n.dataStream+=a,c&&Object.getOwnPropertyNames(c).length&&n.textRuns.push({st:n.dataStream.length-a.length,ed:n.dataStream.length,ts:c})}else if(o.nodeType===Node.ELEMENT_NODE){const a=t?this._styleCache.get(t):{},c=this._styleRules.find(({filter:m})=>Ge(o,m)),l=c?c.getStyle(o):Ae(o);this._styleCache.set(o,{...a,...l});const{childNodes:u}=o;this._process(o,u,n);const d=this._afterProcessRules.find(({filter:m})=>Ge(o,m));d&&d.handler(n,o)}}};C(ve,"_pluginList",[]);let Q=ve;const Nt={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const t=Ae(i);return{st:{s:s.BooleanNumber.TRUE},...t}}}],afterProcessRules:[{filter(i){return i.tagName==="DIV"&&/ace-line/i.test(i.className)},handler(i){i.paragraphs==null&&(i.paragraphs=[]),i.paragraphs.push({startIndex:i.dataStream.length}),i.dataStream+="\r"}}]},At={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const t=Ae(i);return{bl:s.BooleanNumber.TRUE,...t}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,t){i.paragraphs==null&&(i.paragraphs=[]);const e={startIndex:i.dataStream.length},n=Ut(t);n&&(e.paragraphStyle=n),i.paragraphs.push(e),i.dataStream+="\r"}}]};function wt(i,t){const{st:e,ed:n,ts:r={}}=t,{ff:o,fs:a,it:c,bl:l,ul:u,st:d,ol:m,bg:p,cl:g,va:h}=r;let f=i.slice(e,n);const S=[];return c===s.BooleanNumber.TRUE&&(f=`<i>${f}</i>`),h===s.BaselineOffset.SUPERSCRIPT?f=`<sup>${f}</sup>`:h===s.BaselineOffset.SUBSCRIPT&&(f=`<sub>${f}</sub>`),(u==null?void 0:u.s)===s.BooleanNumber.TRUE&&(f=`<u>${f}</u>`),(d==null?void 0:d.s)===s.BooleanNumber.TRUE&&(f=`<s>${f}</s>`),l===s.BooleanNumber.TRUE&&(f=`<strong>${f}</strong>`),o&&S.push(`font-family: ${o}`),g&&S.push(`color: ${g.rgb}`),a&&S.push(`font-size: ${a}px`),m&&S.push("text-decoration: overline"),p&&S.push(`background: ${p.rgb}`),S.length?`<span style="${S.join(";")}">${f}</span>`:f}function Ye(i,t=!0){const{dataStream:e,textRuns:n=[],paragraphs:r=[]}=i;let o=0;const a=[],c=[];for(const l of n){const{st:u,ed:d}=l;if(u!==o&&a.push(e.slice(o,u)),a.push(wt(e,l)),o=d,t)for(const m of r){const{startIndex:p,paragraphStyle:g={}}=m;if(p>=u&&p<=d){const{spaceAbove:h,spaceBelow:f}=g,S=[];h!=null&&(typeof h=="number"?S.push(`margin-top: ${h}px`):S.push(`margin-top: ${h.v}px`)),f!=null&&(typeof f=="number"?S.push(`margin-bottom: ${f}px`):S.push(`margin-bottom: ${f.v}px`)),c.push(`<p className="UniverNormal" ${S.length?`style="${S.join(";")}"`:""}>${a.join("")}</p>`),a.length=0}}}return c.join("")+a.join("")}class Lt{convert(t){if(t.length===0)throw new Error("The bodyList length at least to be 1");if(t.length===1)return Ye(t[0]);let e="";for(const n of t)e+='<p className="UniverNormal">',e+=Ye(n,!1),e+="</p>";return e}}var Bt=Object.defineProperty,$t=Object.getOwnPropertyDescriptor,Ft=(i,t,e,n)=>{for(var r=n>1?void 0:n?$t(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Bt(t,e,r),r},G=(i,t)=>(e,n)=>t(e,n,i);Q.use(At);Q.use(Nt);function jt(i){const t=i.replace(/\n/g,"\r"),e=[];for(let n=0;n<t.length;n++)t[n]==="\r"&&e.push({startIndex:n});return{dataStream:t,paragraphs:e}}const te=E.createIdentifier("doc.clipboard-service");let be=class extends s.Disposable{constructor(t,e,n,r,o){super();C(this,"_clipboardHooks",[]);C(this,"_htmlToUDM",new Q);C(this,"_umdToHtml",new Lt);this._currentUniverService=t,this._logService=e,this._commandService=n,this._clipboardInterfaceService=r,this._textSelectionManagerService=o}async copy(){const t=this._getDocumentBodyInRanges();try{this._setClipboardData(t)}catch(e){return this._logService.error("[DocClipboardService] copy failed",e),!1}return!0}async cut(){return this._cut()}async paste(t){const e=await this._generateBodyFromClipboardItems(t);return this._paste(e)}async legacyPaste(t,e){const n=this._generateBodyFromHtmlAndText(t,e);return this._paste(n)}async _cut(){var o;const{segmentId:t,endOffset:e,style:n}=(o=this._textSelectionManagerService.getActiveRange())!=null?o:{},r=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),e==null||r==null)return!1;this.copy();try{let a=e;for(const l of r){const{startOffset:u,endOffset:d}=l;u==null||d==null||d<=e&&(a-=d-u)}const c=[{startOffset:a,endOffset:a,style:n}];return this._commandService.executeCommand(Re.id,{segmentId:t,textRanges:c})}catch{return this._logService.error("[DocClipboardController] cut content failed"),!1}}async _paste(t){var a;const{segmentId:e,endOffset:n,style:r}=(a=this._textSelectionManagerService.getActiveRange())!=null?a:{},o=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId does not exist!"),n==null||o==null)return!1;try{let c=n;for(const u of o){const{startOffset:d,endOffset:m}=u;d==null||m==null||m<=n&&(c+=t.dataStream.length-(m-d))}const l=[{startOffset:c,endOffset:c,style:r}];return this._commandService.executeCommand(et.id,{body:t,segmentId:e,textRanges:l})}catch{return this._logService.error("[DocClipboardController]","clipboard is empty."),!1}}async _setClipboardData(t){const e=Dt(),n=t.length>1?t.map(o=>o.dataStream).join(`
|
|
2
|
+
`):t[0].dataStream;let r=this._umdToHtml.convert(t);return t.length===1&&(r=r.replace(/(<[a-z]+)/,(o,a)=>`${a} data-copy-id="${e}"`),He.set(e,t[0])),this._clipboardInterfaceService.write(n,r)}addClipboardHook(t){return this._clipboardHooks.push(t),s.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}_getDocumentBodyInRanges(){const t=this._textSelectionManagerService.getSelections(),e=this._currentUniverService.getCurrentUniverDocInstance(),n=[];if(t==null)return n;for(const r of t){const{startOffset:o,endOffset:a,collapsed:c}=r;if(c||o==null||a==null)continue;const l=e.sliceBody(o,a);l!=null&&n.push(l)}return n}async _generateBodyFromClipboardItems(t){try{let e="",n="";for(const r of t)for(const o of r.types)o===b.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await r.getType(o).then(a=>a&&a.text()):o===b.HTML_CLIPBOARD_MIME_TYPE&&(e=await r.getType(o).then(a=>a&&a.text()));return this._generateBodyFromHtmlAndText(e,n)}catch(e){return Promise.reject(e)}}_generateBodyFromHtmlAndText(t,e){if(!t){if(e)return jt(e);throw new Error("[DocClipboardService] html and text cannot be both empty!")}const n=bt(t);if(n){const r=He.get(n);if(r)return r}return this._htmlToUDM.convert(t)}};be=Ft([G(0,s.IUniverInstanceService),G(1,s.ILogService),G(2,s.ICommandService),G(3,b.IClipboardInterfaceService),G(4,E.Inject(exports.TextSelectionManagerService))],be);function Te(i){return i.getContextValue(s.FOCUSING_DOC)||i.getContextValue(s.EDITOR_ACTIVATED)}const we=999,tt={id:b.CopyCommand.id,name:"doc.command.copy",type:s.CommandType.COMMAND,multi:!0,priority:we,preconditions:Te,handler:async i=>i.get(te).copy()},nt={id:b.CutCommand.id,name:"doc.command.cut",type:s.CommandType.COMMAND,multi:!0,priority:we,preconditions:Te,handler:async i=>i.get(te).cut()},rt={id:b.PasteCommand.id,name:"doc.command.paste",type:s.CommandType.COMMAND,multi:!0,priority:we,preconditions:Te,handler:async i=>{const t=i.get(te),n=await i.get(b.IClipboardInterfaceService).read();return n.length===0?!1:t.paste(n)}};var Vt=Object.defineProperty,kt=Object.getOwnPropertyDescriptor,Xt=(i,t,e,n)=>{for(var r=n>1?void 0:n?kt(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Vt(t,e,r),r},Ke=(i,t)=>(e,n)=>t(e,n,i);exports.DocSkeletonManagerService=class extends s.RxDisposable{constructor(e,n){super();C(this,"_currentSkeletonUnitId","");C(this,"_docSkeletonMap",new Map);C(this,"_currentSkeleton$",new P.BehaviorSubject(null));C(this,"currentSkeleton$",this._currentSkeleton$.asObservable());C(this,"_currentSkeletonBefore$",new P.BehaviorSubject(null));C(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=n,this._initialize()}_initialize(){this._docViewModelManagerService.currentDocViewModel$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{e!=null&&this._setCurrent(e)})}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap.clear()}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,n=!0){const r=this.getSkeletonByUnitId(e);r!=null&&(r.dirty=n)}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_setCurrent(e){const{unitId:n}=e;if(this._docSkeletonMap.has(n)){const r=this.getSkeletonByUnitId(n);r.skeleton.calculate(),r.dirty=!0}else{const r=this._buildSkeleton(e.docViewModel);r.calculate(),this._docSkeletonMap.set(n,{unitId:n,skeleton:r,dirty:!1})}return this._currentSkeletonUnitId=n,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}_buildSkeleton(e){return M.DocumentSkeleton.create(e,this._localeService)}};exports.DocSkeletonManagerService=Xt([Ke(0,E.Inject(s.LocaleService)),Ke(1,E.Inject(exports.DocViewModelManagerService))],exports.DocSkeletonManagerService);const Le={id:"doc.command.delete-left",type:s.CommandType.COMMAND,handler:async i=>{var T;const t=i.get(exports.TextSelectionManagerService),e=i.get(exports.DocSkeletonManagerService),n=i.get(s.IUniverInstanceService),r=i.get(s.ICommandService),o=t.getActiveRange(),a=t.getSelections(),c=(T=e.getCurrent())==null?void 0:T.skeleton;let l=!0;if(o==null||c==null||a==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:p,style:g}=o,h=c.findNodeByCharIndex(d),f=M.hasListSpan(h),S=M.isIndentBySpan(h,u.getBody());let v=d;const I=c.findNodeByCharIndex(d-1);if(M.isFirstSpan(h)&&I!==h&&(f===!0||S===!0)){const O=M.getParagraphBySpan(h,u.getBody());if(O==null)return!1;const x=O==null?void 0:O.startIndex,D={startIndex:0},U=O.paragraphStyle;if(f===!0){const y=O.paragraphStyle;y&&(D.paragraphStyle=y)}else if(S===!0){const y=O.bullet;y&&(D.bullet=y),U!=null&&(D.paragraphStyle={...U},delete D.paragraphStyle.hanging,delete D.paragraphStyle.indentStart)}const N=[{startOffset:v,endOffset:v,style:g}];l=await r.executeCommand(Pe.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...D}]},range:{startOffset:x,endOffset:x+1},textRanges:N,coverType:s.UpdateDocsAttributeType.REPLACE,segmentId:p})}else if(m===!0){if(I==null)return!0;if(I.content==="\r")l=await r.executeCommand($e.id,{direction:L.LEFT,range:o});else{v-=I.count;const O=[{startOffset:v,endOffset:v,style:g}];l=await r.executeCommand(Me.id,{unitId:u.getUnitId(),range:o,segmentId:p,direction:L.LEFT,len:I.count,textRanges:O})}}else{const O=it(o,a);l=await r.executeCommand(Re.id,{segmentId:p,textRanges:O})}return l}},Be={id:"doc.command.delete-right",type:s.CommandType.COMMAND,handler:async i=>{var h;const t=i.get(exports.TextSelectionManagerService),e=i.get(exports.DocSkeletonManagerService),n=i.get(s.IUniverInstanceService),r=i.get(s.ICommandService),o=t.getActiveRange(),a=t.getSelections(),c=(h=e.getCurrent())==null?void 0:h.skeleton;let l;if(o==null||c==null||a==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:m,segmentId:p,style:g}=o;if(d===u.getBody().dataStream.length-2&&m)return!0;if(m===!0){const f=c.findNodeByCharIndex(d);if(f.content==="\r")l=await r.executeCommand($e.id,{direction:L.RIGHT,range:o});else{const S=[{startOffset:d,endOffset:d,style:g}];l=await r.executeCommand(Me.id,{unitId:u.getUnitId(),range:o,segmentId:p,direction:L.RIGHT,textRanges:S,len:f.count})}}else{const f=it(o,a);l=await r.executeCommand(Re.id,{segmentId:p,textRanges:f})}return l}},$e={id:"doc.command.merge-two-paragraph",type:s.CommandType.COMMAND,handler:async(i,t)=>{var U,N,y;const e=i.get(exports.TextSelectionManagerService),n=i.get(s.IUniverInstanceService),r=i.get(s.ICommandService),o=i.get(s.IUndoRedoService),{direction:a,range:c}=t,l=e.getActiveRange(),u=e.getSelections();if(l==null||u==null)return!1;const d=n.getCurrentUniverDocInstance(),{startOffset:m,collapsed:p,segmentId:g,style:h}=l;if(!p)return!1;const f=a===L.LEFT?m:m+1,S=(y=(N=(U=d.getBody())==null?void 0:U.paragraphs)==null?void 0:N.find(A=>A.startIndex>=f))==null?void 0:y.startIndex,v=zt(d.getBody(),f,S),I=a===L.LEFT?m-1:m,R=d.getUnitId(),T=[{startOffset:I,endOffset:I,style:h}],O={id:_.id,params:{unitId:R,mutations:[]}},x=new s.TextX;x.push({t:s.TextXActionType.RETAIN,len:a===L.LEFT?m-1:m,segmentId:g}),v.dataStream.length&&x.push({t:s.TextXActionType.INSERT,body:v,len:v.dataStream.length,line:0,segmentId:g}),x.push({t:s.TextXActionType.RETAIN,len:1,segmentId:g}),x.push({t:s.TextXActionType.DELETE,len:S+1-f,line:0,segmentId:g}),O.params.mutations=x.serialize();const D=r.syncExecuteCommand(O.id,O.params);return e.replaceTextRanges(T),D?(o.pushUndoRedo({unitID:R,undoMutations:[{id:_.id,params:D}],redoMutations:[{id:_.id,params:O.params}],undo(){return r.syncExecuteCommand(_.id,D),e.replaceTextRanges([c]),!0},redo(){return r.syncExecuteCommand(_.id,O.params),e.replaceTextRanges(T),!0}}),!0):!1}};function zt(i,t,e){const{textRuns:n}=i,r=i.dataStream.substring(t,e);if(n==null)return{dataStream:r};const o=[];for(const a of n){const{st:c,ed:l}=a;l<=t||c>=e||(c<t?o.push({...a,st:0,ed:l-t}):l>e?o.push({...a,st:c-t,ed:e-t}):o.push({...a,st:c-t,ed:l-t}))}return{dataStream:r,textRuns:o}}function it(i,t){let e=i.endOffset;for(const r of t){const{startOffset:o,endOffset:a}=r;o==null||a==null||a<=i.endOffset&&(e-=a-o)}return[{startOffset:e,endOffset:e,style:i.style}]}class Fe{constructor(){C(this,"_previousActiveRange",null);C(this,"_undoMutationParamsCache",[]);C(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}setActiveRange(t){this._previousActiveRange=t}pushUndoRedoMutationParams(t,e){this._undoMutationParamsCache.push(t),this._redoMutationParamsCache.push(e)}fetchComposedUndoRedoMutationParams(){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null||this._redoMutationParamsCache.length===0)return null;const{unitId:t}=this._undoMutationParamsCache[0],e={unitId:t,mutations:this._undoMutationParamsCache.reverse().reduce((r,o)=>s.TextX.compose(r,o.mutations),[])};return{redoMutationParams:{unitId:t,mutations:this._redoMutationParamsCache.reduce((r,o)=>s.TextX.compose(r,o.mutations),[])},undoMutationParams:e,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const je={id:"doc.command.ime-input",type:s.CommandType.COMMAND,handler:async(i,t)=>{const{unitId:e,newText:n,oldTextLen:r,range:o,segmentId:a,textRanges:c,isCompositionEnd:l}=t,u=i.get(s.ICommandService),d=i.get(s.IUndoRedoService),m=i.get(exports.TextSelectionManagerService),p=i.get(Fe),g={id:_.id,params:{unitId:e,mutations:[]}},h=new s.TextX;o.collapsed?h.push({t:s.TextXActionType.RETAIN,len:o.startOffset,segmentId:a}):h.push(...Ue(o,a)),r>0&&h.push({t:s.TextXActionType.DELETE,len:r,line:0,segmentId:a}),h.push({t:s.TextXActionType.INSERT,body:{dataStream:n},len:n.length,line:0,segmentId:a}),g.params.mutations=h.serialize();const f=u.syncExecuteCommand(g.id,g.params);if(p.pushUndoRedoMutationParams(f,g.params),m.replaceTextRanges(c),l){if(f){const S=p.fetchComposedUndoRedoMutationParams();if(S==null)return!1;const{undoMutationParams:v,redoMutationParams:I,previousActiveRange:R}=S;return d.pushUndoRedo({unitID:e,undoMutations:[{id:_.id,params:v}],redoMutations:[{id:_.id,params:I}],undo(){return u.syncExecuteCommand(_.id,v),m.replaceTextRanges([R]),!0},redo(){return u.syncExecuteCommand(_.id,I),m.replaceTextRanges(c),!0}}),!0}}else return!!f;return!1}},z={id:"doc.command.set-inline-format-bold",type:s.CommandType.COMMAND,handler:async()=>!0},ne={id:"doc.command.set-inline-format-italic",type:s.CommandType.COMMAND,handler:async()=>!0},re={id:"doc.command.set-inline-format-underline",type:s.CommandType.COMMAND,handler:async()=>!0},ie={id:"doc.command.set-inline-format-strikethrough",type:s.CommandType.COMMAND,handler:async()=>!0},B={id:"doc.command.set-inline-format-subscript",type:s.CommandType.COMMAND,handler:async()=>!0},k={id:"doc.command.set-inline-format-superscript",type:s.CommandType.COMMAND,handler:async()=>!0},W={id:"doc.command.set-inline-format-fontsize",type:s.CommandType.COMMAND,handler:async()=>!0},H={id:"doc.command.set-inline-format-font-family",type:s.CommandType.COMMAND,handler:async()=>!0},oe={id:"doc.command.set-inline-format-text-color",type:s.CommandType.COMMAND,handler:async()=>!0},ot={[z.id]:"bl",[ne.id]:"it",[re.id]:"ul",[ie.id]:"st",[W.id]:"fs",[H.id]:"ff",[oe.id]:"cl",[B.id]:"va",[k.id]:"va"},Ve={id:"doc.command.set-inline-format",type:s.CommandType.COMMAND,handler:async(i,t)=>{const{segmentId:e,value:n,preCommandId:r}=t,o=i.get(s.IUndoRedoService),a=i.get(s.ICommandService),c=i.get(exports.TextSelectionManagerService),l=i.get(s.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;let d=l.getCurrentUniverDocInstance(),m=d.getUnitId();m===s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(d=l.getUniverDocInstance(s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),m=d.getUnitId());let p;switch(r){case z.id:case ne.id:case re.id:case ie.id:case B.id:case k.id:{p=Ht(d.getBody().textRuns,r,u);break}case W.id:case H.id:{p=n;break}case oe.id:{p={rgb:n};break}default:throw new Error(`Unknown command: ${r} in handleInlineFormat`)}const g={id:_.id,params:{unitId:m,mutations:[]}},h=new s.TextX,f=new s.MemoryCursor;f.reset();for(const I of u){const{startOffset:R,endOffset:T}=I,O={dataStream:"",textRuns:[{st:0,ed:T-R,ts:{[ot[r]]:p}}]},x=R-f.cursor;x!==0&&h.push({t:s.TextXActionType.RETAIN,len:x,segmentId:e}),h.push({t:s.TextXActionType.RETAIN,body:O,len:T-R,segmentId:e}),f.reset(),f.moveCursor(T)}g.params.mutations=h.serialize();const S=a.syncExecuteCommand(g.id,g.params),v=[z.id,W.id,H.id,B.id,k.id];return v.includes(r)&&c.refreshSelection(),S?(o.pushUndoRedo({unitID:m,undoMutations:[{id:_.id,params:S}],redoMutations:[{id:_.id,params:g.params}],undo(){return a.syncExecuteCommand(_.id,S),v.includes(r)&&c.refreshSelection(),!0},redo(){return a.syncExecuteCommand(_.id,g.params),v.includes(r)&&c.refreshSelection(),!0}}),!0):!1}};function Wt(i){return i!==null&&typeof i=="object"}function Ht(i,t,e){let n=0,r=0;const o=ot[t];for(;n!==i.length&&r!==e.length;){const{startOffset:a,endOffset:c}=e[r],{st:l,ed:u,ts:d}=i[n];if(c<=l)r++;else if(u<=a)n++;else{if((d==null?void 0:d[o])==null){if(/bl|it/.test(o))return s.BooleanNumber.TRUE;if(/ul|st/.test(o))return{s:s.BooleanNumber.TRUE};if(/va/.test(o))return t===B.id?s.BaselineOffset.SUBSCRIPT:s.BaselineOffset.SUPERSCRIPT}if(Wt(d==null?void 0:d[o])&&d[o].s===s.BooleanNumber.FALSE)return{s:s.BooleanNumber.TRUE};if(t===B.id&&(d==null?void 0:d[o])!==s.BaselineOffset.SUBSCRIPT)return s.BaselineOffset.SUBSCRIPT;if(t===k.id&&(d==null?void 0:d[o])!==s.BaselineOffset.SUPERSCRIPT)return s.BaselineOffset.SUPERSCRIPT;if((d==null?void 0:d[o])===s.BooleanNumber.FALSE)return s.BooleanNumber.TRUE;n++}}return/bl|it/.test(o)?s.BooleanNumber.FALSE:/ul|st/.test(o)?{s:s.BooleanNumber.FALSE}:s.BaselineOffset.NORMAL}const st={id:"doc.command.bullet-list",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(ke.id,{listType:s.PresetListType.BULLET_LIST})},at={id:"doc.command.order-list",type:s.CommandType.COMMAND,handler:i=>i.get(s.ICommandService).syncExecuteCommand(ke.id,{listType:s.PresetListType.ORDER_LIST})},ke={id:"doc.command.list-operation",type:s.CommandType.COMMAND,handler:(i,t)=>{var T,O;const e=i.get(exports.TextSelectionManagerService),n=i.get(s.IUniverInstanceService),r=i.get(s.ICommandService),o=i.get(s.IUndoRedoService),{listType:a}=t,c=n.getCurrentUniverDocInstance(),l=e.getActiveRange(),u=(T=c.getBody())==null?void 0:T.paragraphs;if(l==null||u==null)return!1;const d=Gt(l,u),{segmentId:m}=l,p=c.getUnitId(),g=d.every(x=>{var D;return((D=x.bullet)==null?void 0:D.listType)===a}),h=6;let f=s.Tools.generateRandomId(h);if(d.length===1){const x=u.indexOf(d[0]),D=u[x-1],U=u[x+1];D&&D.bullet&&D.bullet.listType===a?f=D.bullet.listId:U&&U.bullet&&U.bullet.listType===a&&(f=U.bullet.listId)}const S={id:_.id,params:{unitId:p,mutations:[]}},v=new s.MemoryCursor;v.reset();const I=new s.TextX;for(const x of d){const{startIndex:D}=x;I.push({t:s.TextXActionType.RETAIN,len:D-v.cursor,segmentId:m});const U={...x.paragraphStyle,hanging:void 0,indentStart:void 0};I.push({t:s.TextXActionType.RETAIN,len:1,body:{dataStream:"",paragraphs:[g?{paragraphStyle:U,startIndex:0}:{...x,startIndex:0,bullet:{...(O=x.bullet)!=null?O:{nestingLevel:0,textStyle:{fs:20}},listType:a,listId:f}}]},segmentId:m,coverType:s.UpdateDocsAttributeType.REPLACE}),v.moveCursorTo(D+1)}S.params.mutations=I.serialize();const R=r.syncExecuteCommand(S.id,S.params);return e.refreshSelection(),R&&o.pushUndoRedo({unitID:p,undoMutations:[{id:_.id,params:R}],redoMutations:[{id:_.id,params:S.params}],undo(){return r.syncExecuteCommand(_.id,R),e.refreshSelection(),!0},redo(){return r.syncExecuteCommand(_.id,S.params),e.refreshSelection(),!0}}),!0}};function Gt(i,t){const{startOffset:e,endOffset:n}=i,r=[];let o=-1;for(const a of t){const{startIndex:c}=a;(e>o&&e<=c||n>o&&n<=c||c>=e&&c<=n)&&r.push(a),o=c}return r}const ct={id:"doc.command-replace-content",type:s.CommandType.COMMAND,handler:async(i,t)=>{var h;const{unitId:e,body:n,textRanges:r,segmentId:o=""}=t,a=i.get(s.IUniverInstanceService),c=i.get(s.ICommandService),l=i.get(exports.TextSelectionManagerService),u=i.get(s.IUndoRedoService),d=(h=a.getUniverDocInstance(e))==null?void 0:h.getSnapshot().body,m=l.getSelections();if(d==null||!Array.isArray(m)||m.length===0)return!1;const p=dt(e,o,d,n),g=c.syncExecuteCommand(p.id,p.params);return l.replaceTextRanges(r),g?(u.pushUndoRedo({unitID:e,undoMutations:[{id:_.id,params:g}],redoMutations:[{id:_.id,params:p.params}],undo(){return c.syncExecuteCommand(_.id,g),l.replaceTextRanges(m),!0},redo(){return c.syncExecuteCommand(_.id,p.params),l.replaceTextRanges(r),!0}}),!0):!1}},lt={id:"doc.command-cover-content",type:s.CommandType.COMMAND,handler:async(i,t)=>{var d;const{unitId:e,body:n,segmentId:r=""}=t,o=i.get(s.IUniverInstanceService),a=i.get(s.ICommandService),c=i.get(s.IUndoRedoService),l=(d=o.getUniverDocInstance(e))==null?void 0:d.getSnapshot().body;if(l==null)return!1;const u=dt(e,r,l,n);return a.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(e),!0}};function dt(i,t,e,n){const r={id:_.id,params:{unitId:i,mutations:[]}},o=new s.TextX,a=(e==null?void 0:e.dataStream.length)-2;return a>0&&o.push({t:s.TextXActionType.DELETE,len:a,line:0,segmentId:t}),n.dataStream.length>0&&o.push({t:s.TextXActionType.INSERT,body:n,len:n.dataStream.length,line:0,segmentId:t}),r.params.mutations=o.serialize(),r}const $={id:"doc.operation.move-cursor",type:s.CommandType.OPERATION,handler:(i,t)=>!!t},F={id:"doc.operation.move-selection",type:s.CommandType.OPERATION,handler:(i,t)=>!!t},Yt=(i,t)=>{const e=i.get(s.IUniverInstanceService).getUniverDocInstance(t.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...s.Tools.deepClone(t),zoomRatio:n}},V={id:"doc.operation.set-zoom-ratio",type:s.CommandType.OPERATION,handler:(i,t)=>{const e=i.get(s.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}},ut={type:s.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(i,t)=>{var m,p;const e=i.get(s.ICommandService),n=i.get(s.IUndoRedoService),r=i.get(s.IUniverInstanceService);let o=r.getCurrentUniverDocInstance().getUnitId(),a=1;if(t&&(o=(m=t.documentId)!=null?m:o,a=(p=t.zoomRatio)!=null?p:a),!r.getUniverDocInstance(o))return!1;const l={zoomRatio:a,unitId:o},u=Yt(i,l);return e.syncExecuteCommand(V.id,l)?(n.pushUndoRedo({unitID:o,undoMutations:[{id:V.id,params:u}],redoMutations:[{id:V.id,params:l}]}),!0):!1}},mt={id:"doc.operation.select-all",type:s.CommandType.COMMAND,handler:async i=>{const t=i.get(s.IUniverInstanceService),e=i.get(exports.TextSelectionManagerService),n=t.getCurrentUniverDocInstance().getSnapshot().body;if(n==null)return!1;const r=[{startOffset:0,endOffset:n.dataStream.length-2}];return e.replaceTextRanges(r),!0}};var Kt=Object.defineProperty,qt=Object.getOwnPropertyDescriptor,Zt=(i,t,e,n)=>{for(var r=n>1?void 0:n?qt(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Kt(t,e,r),r},Y=(i,t)=>(e,n)=>t(e,n,i);let ce=class extends s.RxDisposable{constructor(i,t,e,n,r){super(),this._commandService=i,this._clipboardInterfaceService=t,this._docClipboardService=e,this._textSelectionRenderManager=n,this._contextService=r,this._init()}_init(){[tt,nt,rt].forEach(i=>this.disposeWithMe(this._commandService.registerMultipleCommand(i))),[et,Re].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i))),this._initLegacyPasteCommand()}_initLegacyPasteCommand(){var i;this._clipboardInterfaceService.supportClipboard||(i=this._textSelectionRenderManager)==null||i.onPaste$.pipe(P.takeUntil(this.dispose$)).subscribe(t=>{var o,a;if(!Te(this._contextService))return;t.event.preventDefault();const e=t.event,n=(o=e.clipboardData)==null?void 0:o.getData("text/html"),r=(a=e.clipboardData)==null?void 0:a.getData("text/plain");this._docClipboardService.legacyPaste(n,r)})}};ce=Zt([s.OnLifecycle(s.LifecycleStages.Steady,ce),Y(0,s.ICommandService),Y(1,b.IClipboardInterfaceService),Y(2,te),Y(3,M.ITextSelectionRenderManager),Y(4,s.IContextService)],ce);var Jt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,en=(i,t,e,n)=>{for(var r=n>1?void 0:n?Qt(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Jt(t,e,r),r},ye=(i,t)=>(e,n)=>t(e,n,i);let le=class extends s.RxDisposable{constructor(i,t,e){super(),this._docSkeletonManagerService=i,this._renderManagerService=t,this._commandService=e,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(P.takeUntil(this.dispose$)).subscribe(i=>{if(i==null)return;const{skeleton:t,unitId:e}=i,n=this._renderManagerService.getRenderById(e);if(n==null)return;const{mainComponent:r}=n;r.changeSkeleton(t),this._recalculateSizeBySkeleton(n,t)})}_recalculateSizeBySkeleton(i,t){var u;const{mainComponent:e,scene:n}=i,r=e,o=(u=t.getSkeletonData())==null?void 0:u.pages;if(o==null)return;let a=0,c=0;for(let d=0,m=o.length;d<m;d++){const p=o[d],{pageWidth:g,pageHeight:h}=p;r.pageLayoutType===M.PageLayoutType.VERTICAL?(c+=h,c+=r.pageMarginTop,d===m-1&&(c+=r.pageMarginTop),a=Math.max(a,g)):r.pageLayoutType===M.PageLayoutType.HORIZONTAL&&(a+=g,d!==m-1&&(a+=r.pageMarginLeft),c=Math.max(c,h))}r.resize(a,c),[s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(i.unitId)||n.resize(a,c)}_commandExecutedListener(){const i=[_.id],t=[s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(i.includes(e.id)){const r=e.params,{unitId:o}=r,a=this._docSkeletonManagerService.getSkeletonByUnitId(o);if(a==null)return;const{skeleton:c}=a,l=this._renderManagerService.getRenderById(o);if(l==null)return;if(c.calculate(),t.includes(o)){(n=l.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(l,c)}}))}};le=en([s.OnLifecycle(s.LifecycleStages.Rendered,le),ye(0,E.Inject(exports.DocSkeletonManagerService)),ye(1,M.IRenderManagerService),ye(2,s.ICommandService)],le);var tn=Object.defineProperty,nn=Object.getOwnPropertyDescriptor,rn=(i,t,e,n)=>{for(var r=n>1?void 0:n?nn(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&tn(t,e,r),r},K=(i,t)=>(e,n)=>t(e,n,i);let de=class extends s.Disposable{constructor(t,e,n,r,o){super();C(this,"_liquid",new M.Liquid);C(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._commandService=r,this._floatingObjectManagerService=o,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){this._floatingObjectManagerService.pluginUpdate$.subscribe(t=>{const e=this._docSkeletonManagerService.getCurrent();if(e==null)return;const{unitId:n,skeleton:r}=e,o=this._renderManagerService.getRenderById(n);if(o==null)return;const{mainComponent:a,components:c,scene:l}=o,u=a,{left:d,top:m}=u;t.forEach(p=>{const{unitId:g,subUnitId:h,floatingObjectId:f,floatingObject:S}=p,{left:v=0,top:I=0,width:R=0,height:T=0,angle:O,flipX:x,flipY:D,skewX:U,skewY:N}=S,y=this._pageMarginCache.get(f),A=(y==null?void 0:y.marginLeft)||0,w=(y==null?void 0:y.marginTop)||0;r==null||r.getViewModel().getDataModel().updateDrawing(f,{left:v-d-A,top:I-m-w,height:T,width:R})}),r==null||r.calculate(),a==null||a.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{skeleton:e,unitId:n}=t,r=this._renderManagerService.getRenderById(n);if(r==null)return;const{mainComponent:o}=r;o.changeSkeleton(e),this._refreshFloatingObject(n,e,r)})}_commandExecutedListener(){const t=[_.id,V.id],e=[s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var r;if(t.includes(n.id)){const o=n.params,{unitId:a}=o,c=this._docSkeletonManagerService.getCurrent();if(c==null)return;const{unitId:l,skeleton:u}=c;if(a!==l)return;const d=this._renderManagerService.getRenderById(l);if(d==null)return;if(e.includes(l)){(r=d.mainComponent)==null||r.makeDirty();return}this._refreshFloatingObject(l,u,d)}}))}_refreshFloatingObject(t,e,n){const r=e==null?void 0:e.getSkeletonData(),{mainComponent:o,scene:a}=n,c=o;if(!r)return;const{left:l,top:u,pageLayoutType:d,pageMarginLeft:m,pageMarginTop:p}=c,{pages:g}=r,h=[];a.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let f=0,S=g.length;f<S;f++){const v=g[f],{skeDrawings:I,marginLeft:R,marginTop:T}=v;this._liquid.translatePagePadding(v),I.forEach(O=>{const{aLeft:x,aTop:D,height:U,width:N,objectId:y}=O;h.push({unitId:t,subUnitId:s.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:y,floatingObject:{left:x+l+this._liquid.x,top:D+u+this._liquid.y,width:N,height:U}}),this._pageMarginCache.set(y,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(v,d,m,p)}this._floatingObjectManagerService.BatchAddOrUpdate(h)}};de=rn([s.OnLifecycle(s.LifecycleStages.Steady,de),K(0,E.Inject(exports.DocSkeletonManagerService)),K(1,s.IUniverInstanceService),K(2,M.IRenderManagerService),K(3,s.ICommandService),K(4,s.IFloatingObjectManagerService)],de);var on=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,an=(i,t,e,n)=>{for(var r=n>1?void 0:n?sn(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&on(t,e,r),r},X=(i,t)=>(e,n)=>t(e,n,i);let ue=class extends s.Disposable{constructor(t,e,n,r,o,a){super();C(this,"_previousIMEContent","");C(this,"_previousIMERange");C(this,"_onStartSubscription");C(this,"_onUpdateSubscription");C(this,"_onEndSubscription");this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._textSelectionRenderManager=r,this._imeInputManagerService=o,this._commandService=a,this._initialize()}dispose(){var t,e,n;(t=this._onStartSubscription)==null||t.unsubscribe(),(e=this._onUpdateSubscription)==null||e.unsubscribe(),(n=this._onEndSubscription)==null||n.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(t=>{if(t==null)return;const{activeRange:e}=t;e!=null&&(this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(s.Tools.deepClone(e)),this._previousIMERange=e)})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async t=>{this._updateContent(t,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(t=>{this._updateContent(t,!1)})}async _updateContent(t,e){var h;const n=(h=this._docSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(this._previousIMERange==null||t==null||n==null)return;const r=this._currentUniverService.getCurrentUniverDocInstance(),{event:o,activeRange:a}=t,{startOffset:c,segmentId:l,style:u}=this._previousIMERange;if(n==null||a==null)return;const m=o.data;if(m===this._previousIMEContent&&e)return;const p=m.length,g=[{startOffset:c+p,endOffset:c+p,style:u}];await this._commandService.executeCommand(je.id,{unitId:r.getUnitId(),newText:m,oldTextLen:this._previousIMEContent.length,range:this._previousIMERange,textRanges:g,isCompositionEnd:!e,segmentId:l}),e?(this._previousIMERange.collapsed||(this._previousIMERange.collapsed=!0),this._previousIMEContent=m):this._resetIME()}_resetIME(){this._previousIMEContent="",this._previousIMERange=null,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}_getDocObject(){return ee(this._currentUniverService,this._renderManagerService)}};ue=an([s.OnLifecycle(s.LifecycleStages.Rendered,ue),X(0,E.Inject(exports.DocSkeletonManagerService)),X(1,s.IUniverInstanceService),X(2,M.IRenderManagerService),X(3,M.ITextSelectionRenderManager),X(4,E.Inject(Fe)),X(5,s.ICommandService)],ue);var cn=Object.defineProperty,ln=Object.getOwnPropertyDescriptor,dn=(i,t,e,n)=>{for(var r=n>1?void 0:n?ln(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&cn(t,e,r),r},qe=(i,t)=>(e,n)=>t(e,n,i);let me=class extends s.Disposable{constructor(i,t){super(),this._textSelectionManagerService=i,this._commandService=t,this._commandExecutedListener()}_commandExecutedListener(){const i=[z.id,ne.id,re.id,ie.id,B.id,k.id,W.id,H.id,oe.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{i.includes(t.id)&&this._handleInlineFormat(t)}))}_handleInlineFormat(i){var e,n;const{segmentId:t}=(e=this._textSelectionManagerService.getActiveRange())!=null?e:{};t!=null&&this._commandService.executeCommand(Ve.id,{segmentId:t,preCommandId:i.id,...(n=i.params)!=null?n:{}})}};me=dn([s.OnLifecycle(s.LifecycleStages.Rendered,me),qe(0,E.Inject(exports.TextSelectionManagerService)),qe(1,s.ICommandService)],me);var un=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,pn=(i,t,e,n)=>{for(var r=n>1?void 0:n?mn(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&un(t,e,r),r},q=(i,t)=>(e,n)=>t(e,n,i);let pe=class extends s.Disposable{constructor(t,e,n,r,o){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._textSelectionManagerService=r,this._commandService=o,this._initialize(),this._commandExecutedListener()}dispose(){var t;(t=this._onInputSubscription)==null||t.unsubscribe()}_initialize(){}_commandExecutedListener(){const t=[$.id,F.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!t.includes(e.id))return;const n=e.params;switch(e.id){case $.id:return this._handleMoveCursor(n.direction);case F.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(t){var f,S,v;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),r=this._currentUniverService.getCurrentUniverDocInstance(),o=(f=this._docSkeletonManagerService.getCurrent())==null?void 0:f.skeleton,a=this._getDocObject();if(e==null||o==null||a==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d,direction:m}=e;if(n.length>1){let I=Number.POSITIVE_INFINITY,R=Number.NEGATIVE_INFINITY;for(const T of n)I=Math.min(I,T.startOffset),R=Math.max(R,T.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:t===s.Direction.LEFT||t===s.Direction.UP?R:I,endOffset:t===s.Direction.LEFT||t===s.Direction.UP?I:R,style:u}]);return}const p=d||m===M.RANGE_DIRECTION.FORWARD?c:l;let g=d||m===M.RANGE_DIRECTION.FORWARD?l:c;const h=(S=r.getBody().dataStream.length)!=null?S:Number.POSITIVE_INFINITY;if(t===s.Direction.LEFT||t===s.Direction.RIGHT){const I=o.findNodeByCharIndex(g-1),R=o.findNodeByCharIndex(g);g=t===s.Direction.RIGHT?g+R.count:g-((v=I==null?void 0:I.count)!=null?v:0),g=Math.min(h-2,Math.max(0,g)),this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:g,style:u}])}else{const I=o.findNodeByCharIndex(g),R=a.document.getOffsetConfig(),T=this._getTopOrBottomPosition(o,I,t===s.Direction.DOWN);if(T==null){const x=t===s.Direction.UP?0:h-2;if(x===g)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:x,style:u}]);return}const O=new M.NodePositionConvertToCursor(R,o).getRangePointData(T,T).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:p,endOffset:O.endOffset,style:u}])}}_handleMoveCursor(t){var p,g,h;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),r=this._currentUniverService.getCurrentUniverDocInstance(),o=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton,a=this._getDocObject();if(e==null||o==null||a==null||n==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d}=e,m=(g=r.getBody().dataStream.length)!=null?g:Number.POSITIVE_INFINITY;if(t===s.Direction.LEFT||t===s.Direction.RIGHT){let f;if(!e.collapsed||n.length>1){let S=Number.POSITIVE_INFINITY,v=Number.NEGATIVE_INFINITY;for(const I of n)S=Math.min(S,I.startOffset),v=Math.max(v,I.endOffset);f=t===s.Direction.LEFT?S:v}else{const S=o.findNodeByCharIndex(c-1),v=o.findNodeByCharIndex(c);t===s.Direction.LEFT?f=Math.max(0,c-((h=S==null?void 0:S.count)!=null?h:0)):f=Math.min(m-2,l+v.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:f,style:u}])}else{const f=o.findNodeByCharIndex(c),S=o.findNodeByCharIndex(l),v=a.document.getOffsetConfig(),I=this._getTopOrBottomPosition(o,t===s.Direction.UP?f:S,t===s.Direction.DOWN);if(I==null){let T;d?T=t===s.Direction.UP?0:m-2:T=t===s.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:T,endOffset:T,style:u}]);return}const R=new M.NodePositionConvertToCursor(v,o).getRangePointData(I,I).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...R,style:u}])}}_getTopOrBottomPosition(t,e,n){if(e==null)return;const r=this._getSpanLeftOffsetInLine(e),o=this._getNextOrPrevLine(e,n);if(o==null)return;const a=this._matchPositionByLeftOffset(t,o,r);if(a!=null)return{...a,isBack:!0}}_getSpanLeftOffsetInLine(t){const e=t.parent;if(e==null)return Number.NEGATIVE_INFINITY;const n=e.left,{left:r}=t;return n+r}_matchPositionByLeftOffset(t,e,n){const r={distance:Number.POSITIVE_INFINITY};for(const o of e.divides){const a=o.left;for(const c of o.spanGroup){const{left:l}=c,u=a+l,d=Math.abs(n-u);d<r.distance&&(r.span=c,r.distance=d)}}if(r.span!=null)return t.findPositionBySpan(r.span)}_getNextOrPrevLine(t,e){var h,f,S,v,I,R,T,O,x,D,U,N;const n=t.parent;if(n==null)return;const r=n.parent;if(r==null)return;const o=r.parent;if(o==null)return;const a=o.lines.indexOf(r);if(a===-1)return;let c;if(e===!0?c=o.lines[a+1]:c=o.lines[a-1],c!=null)return c;const l=o.parent;if(l==null)return;const u=l.columns.indexOf(o);if(u===-1)return;if(e===!0)c=(h=l.columns[u+1])==null?void 0:h.lines[0];else{const y=(S=(f=l.columns)==null?void 0:f[u-1])==null?void 0:S.lines;c=y==null?void 0:y[y.length-1]}if(c!=null)return c;const d=l.parent;if(d==null)return;const m=d.sections.indexOf(l);if(m===-1)return;if(e===!0)c=(I=(v=d.sections[m-1])==null?void 0:v.columns[0])==null?void 0:I.lines[0];else{const y=(T=(R=d.sections)==null?void 0:R[m-1])==null?void 0:T.columns,A=y==null?void 0:y[y.length-1],w=A==null?void 0:A.lines;c=w==null?void 0:w[w.length-1]}if(c!=null)return c;const p=d.parent;if(p==null)return;const g=p.pages.indexOf(d);if(g!==-1){if(e===!0)c=(D=(x=(O=p.pages[g+1])==null?void 0:O.sections[0])==null?void 0:x.columns[0])==null?void 0:D.lines[0];else{const y=(U=p.pages[g-1])==null?void 0:U.sections;if(y==null)return;const A=(N=y[y.length-1])==null?void 0:N.columns,w=A[A.length-1],Xe=w==null?void 0:w.lines;c=Xe[Xe.length-1]}if(c!=null)return c}}_getDocObject(){return ee(this._currentUniverService,this._renderManagerService)}};pe=pn([s.OnLifecycle(s.LifecycleStages.Rendered,pe),q(0,E.Inject(exports.DocSkeletonManagerService)),q(1,s.IUniverInstanceService),q(2,M.IRenderManagerService),q(3,E.Inject(exports.TextSelectionManagerService)),q(4,s.ICommandService)],pe);var gn=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,fn=(i,t,e,n)=>{for(var r=n>1?void 0:n?hn(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&gn(t,e,r),r},Z=(i,t)=>(e,n)=>t(e,n,i);let ge=class extends s.Disposable{constructor(t,e,n,r,o){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._textSelectionRenderManager=r,this._commandService=o,this._initialize(),this._commandExecutedListener()}dispose(){var t;(t=this._onInputSubscription)==null||t.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async t=>{var h;if(t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:r,content:o="",activeRange:a}=t,c=r,l=(h=this._docSkeletonManagerService.getCurrent())==null?void 0:h.skeleton;if(c.data==null||l==null||!l||!a)return;const{startOffset:u,segmentId:d,style:m}=a,p=o.length,g=[{startOffset:u+p,endOffset:u+p,style:m}];await this._commandService.executeCommand(Ce.id,{unitId:n,body:{dataStream:o},range:a,textRanges:g,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return ee(this._currentUniverService,this._renderManagerService)}};ge=fn([s.OnLifecycle(s.LifecycleStages.Rendered,ge),Z(0,E.Inject(exports.DocSkeletonManagerService)),Z(1,s.IUniverInstanceService),Z(2,M.IRenderManagerService),Z(3,M.ITextSelectionRenderManager),Z(4,s.ICommandService)],ge);var Sn=Object.defineProperty,_n=Object.getOwnPropertyDescriptor,vn=(i,t,e,n)=>{for(var r=n>1?void 0:n?_n(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Sn(t,e,r),r},Ze=(i,t)=>(e,n)=>t(e,n,i);const In="rgba(198, 198, 198, 1)",Cn="rgba(255, 255, 255, 1)";let he=class extends s.Disposable{constructor(i,t){super(),this._renderManagerService=i,this._currentUniverService=t,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this._renderManagerService.currentRender$.subscribe(i=>{var o;if(i==null||this._currentUniverService.getUniverDocInstance(i)==null)return;const t=this._renderManagerService.getRenderById(i);if(t==null)return;const{mainComponent:e}=t,n=e,r=(o=n.getSkeleton())==null?void 0:o.getPageSize();n.onPageRenderObservable.add(a=>{var f,S,v,I;if([s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(i))return;const{page:c,pageLeft:l,pageTop:u,ctx:d}=a,{width:m,pageWidth:p,height:g,pageHeight:h}=c;d.save(),d.translate(l-.5,u-.5),M.Rect.drawWith(d,{width:(S=(f=r==null?void 0:r.width)!=null?f:p)!=null?S:m,height:(I=(v=r==null?void 0:r.height)!=null?v:h)!=null?I:g,strokeWidth:1,stroke:In,fill:Cn,zIndex:3}),d.restore()})})}_commandExecutedListener(){}};he=vn([s.OnLifecycle(s.LifecycleStages.Rendered,he),Ze(0,M.IRenderManagerService),Ze(1,E.Inject(s.IUniverInstanceService))],he);var Mn=Object.defineProperty,Rn=Object.getOwnPropertyDescriptor,Tn=(i,t,e,n)=>{for(var r=n>1?void 0:n?Rn(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Mn(t,e,r),r},j=(i,t)=>(e,n)=>t(e,n,i);let fe=class extends s.Disposable{constructor(t,e,n,r,o,a,c){super();C(this,"_moveInObserver");C(this,"_moveOutObserver");C(this,"_downObserver");C(this,"_dblClickObserver");C(this,"_tripleClickObserver");C(this,"_loadedMap",new Set);this._docSkeletonManagerService=t,this._currentUniverService=e,this._commandService=n,this._renderManagerService=r,this._textSelectionRenderManager=o,this._textSelectionManagerService=a,this._layoutService=c,this._renderManagerService.currentRender$.subscribe(l=>{l!=null&&this._currentUniverService.getUniverDocInstance(l)!=null&&(this._loadedMap.has(l)||(this._initialMain(l),this._loadedMap.add(l)))}),this._initialize()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._layoutService&&this.disposeWithMe(this._layoutService.registerContainer(this._textSelectionRenderManager.__getEditorContainer()))}dispose(){this._renderManagerService.getRenderAll().forEach(t=>{const{mainComponent:e}=t;e!=null&&(e.onPointerEnterObserver.remove(this._moveInObserver),e.onPointerLeaveObserver.remove(this._moveOutObserver),e.onPointerDownObserver.remove(this._downObserver),e.onDblclickObserver.remove(this._dblClickObserver),e.onTripleClickObserver.remove(this._tripleClickObserver))})}_initialMain(t){const e=this._getDocObjectById(t);if(e==null)return;const{document:n,scene:r}=e;this._moveInObserver=n.onPointerEnterObserver.add(()=>{n.cursor=M.CURSOR_TYPE.TEXT}),this._moveOutObserver=n.onPointerLeaveObserver.add(()=>{n.cursor=M.CURSOR_TYPE.DEFAULT,r.resetCursor()}),this._downObserver=n==null?void 0:n.onPointerDownObserver.add((o,a)=>{this._currentUniverService.getCurrentUniverDocInstance().getUnitId()!==t&&this._currentUniverService.setCurrentUniverDocInstance(t),this._textSelectionRenderManager.eventTrigger(o),o.button!==2&&a.stopPropagation()}),this._dblClickObserver=n==null?void 0:n.onDblclickObserver.add(o=>{this._textSelectionRenderManager.handleDblClick(o)}),this._tripleClickObserver=n==null?void 0:n.onTripleClickObserver.add(o=>{this._textSelectionRenderManager.handleTripleClick(o)})}_commandExecutedListener(){const t=[V.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(t.includes(e.id)){const r=e.params,{unitId:o}=r,a=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(o!==a)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{unitId:e,skeleton:n}=t,r=this._renderManagerService.getRenderById(e);if(r==null)return;const{scene:o,mainComponent:a}=r;this._textSelectionRenderManager.changeRuntime(n,o,a),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:e,subUnitId:""})})}_getDocObjectById(t){return ht(t,this._renderManagerService)}};fe=Tn([s.OnLifecycle(s.LifecycleStages.Rendered,fe),j(0,E.Inject(exports.DocSkeletonManagerService)),j(1,s.IUniverInstanceService),j(2,s.ICommandService),j(3,M.IRenderManagerService),j(4,M.ITextSelectionRenderManager),j(5,E.Inject(exports.TextSelectionManagerService)),j(6,E.Optional(b.LayoutService))],fe);var yn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,xn=(i,t,e,n)=>{for(var r=n>1?void 0:n?On(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&yn(t,e,r),r},J=(i,t)=>(e,n)=>t(e,n,i);let Se=class extends s.Disposable{constructor(t,e,n,r,o){super();C(this,"_initializedRender",new Set);this._docSkeletonManagerService=t,this._currentUniverService=e,this._commandService=n,this._renderManagerService=r,this._textSelectionManagerService=o,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{unitId:e}=t,n=this._renderManagerService.getRenderById(e);if(n==null||this._initializedRender.has(e)||[s.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(e))return;this._initializedRender.add(e);const{scene:r}=n;this.disposeWithMe(s.toDisposable(r.onMouseWheelObserver.add(o=>{if(!o.ctrlKey)return;const a=Math.abs(o.deltaX);let c=a<40?.2:a<80?.4:.2;c*=o.deltaY>0?-1:1,r.scaleX<1&&(c/=2);const l=this._currentUniverService.getCurrentUniverDocInstance(),u=l.zoomRatio;let d=+parseFloat(`${u+c}`).toFixed(1);d=d>=4?4:d<=.1?.1:d,this._commandService.executeCommand(ut.id,{zoomRatio:d,unitId:l.getUnitId()}),o.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(s.toDisposable(this._docSkeletonManagerService.currentSkeletonBefore$.subscribe(t=>{if(t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const t=[V.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(t.includes(e.id)){const n=this._currentUniverService.getCurrentUniverDocInstance(),r=e.params,{unitId:o}=r;if(o!==n.getUnitId())return;const a=n.zoomRatio||1;this._updateViewZoom(a)}}))}_updateViewZoom(t,e=!0){var r;const n=this._getDocObject();n!=null&&(n.scene.scale(t,t),this._calculatePagePosition(n,t),e&&this._textSelectionManagerService.refreshSelection(),(r=n.scene.getTransformer())==null||r.hideControl())}_calculatePagePosition(t,e){const{document:n,scene:r}=t,o=r==null?void 0:r.getParent(),{width:a,height:c,pageMarginLeft:l,pageMarginTop:u}=n;if(o==null||a===1/0||c===1/0)return;const{width:d,height:m}=o;let p=0,g=0,h=0,f=0,S=1/0;d>(a+l*2)*e?(p=d/2-a*e/2,p/=e,h=(d-l*2)/e,S=0):(p=l,h=a+l*2,S=(h-d/e)/2),m>c?(g=m/2-c/2,f=(m-u*2)/e):(g=u,f=c+u*2),r.resize(h,f+200),n.translate(p,g);const v=r.getViewport(Ie.VIEW_MAIN);if(S!==1/0&&v!=null){const I=v.getBarScroll(S,0).x;v.scrollTo({x:I})}return this}_getDocObject(){return ee(this._currentUniverService,this._renderManagerService)}};Se=xn([s.OnLifecycle(s.LifecycleStages.Rendered,Se),J(0,E.Inject(exports.DocSkeletonManagerService)),J(1,s.IUniverInstanceService),J(2,s.ICommandService),J(3,M.IRenderManagerService),J(4,E.Inject(exports.TextSelectionManagerService))],Se);const Dn={id:Ne.id,preconditions:i=>i.getContextValue(s.FOCUSING_DOC),binding:b.KeyCode.ENTER},bn={id:Le.id,preconditions:i=>i.getContextValue(s.FOCUSING_DOC),binding:b.KeyCode.BACKSPACE},En={id:Be.id,preconditions:i=>i.getContextValue(s.FOCUSING_DOC),binding:b.KeyCode.DELETE},Un={id:$.id,binding:b.KeyCode.ARROW_UP,preconditions:i=>i.getContextValue(s.FOCUSING_DOC),staticParameters:{direction:s.Direction.UP}},Pn={id:$.id,binding:b.KeyCode.ARROW_DOWN,preconditions:i=>i.getContextValue(s.FOCUSING_DOC),staticParameters:{direction:s.Direction.DOWN}},Nn={id:$.id,binding:b.KeyCode.ARROW_LEFT,preconditions:i=>i.getContextValue(s.FOCUSING_DOC),staticParameters:{direction:s.Direction.LEFT}},An={id:$.id,binding:b.KeyCode.ARROW_RIGHT,preconditions:i=>i.getContextValue(s.FOCUSING_DOC),staticParameters:{direction:s.Direction.RIGHT}},wn={id:F.id,binding:b.KeyCode.ARROW_UP|b.MetaKeys.SHIFT,preconditions:i=>i.getContextValue(s.FOCUSING_DOC),staticParameters:{direction:s.Direction.UP}},Ln={id:F.id,binding:b.KeyCode.ARROW_DOWN|b.MetaKeys.SHIFT,preconditions:i=>i.getContextValue(s.FOCUSING_DOC),staticParameters:{direction:s.Direction.DOWN}},Bn={id:F.id,binding:b.KeyCode.ARROW_LEFT|b.MetaKeys.SHIFT,preconditions:i=>i.getContextValue(s.FOCUSING_DOC),staticParameters:{direction:s.Direction.LEFT}},$n={id:F.id,binding:b.KeyCode.ARROW_RIGHT|b.MetaKeys.SHIFT,preconditions:i=>i.getContextValue(s.FOCUSING_DOC),staticParameters:{direction:s.Direction.RIGHT}},Fn={id:mt.id,binding:b.KeyCode.A|b.MetaKeys.CTRL_COMMAND,preconditions:i=>i.getContextValue(s.FOCUSING_DOC)||i.getContextValue(s.EDITOR_ACTIVATED)};var jn=Object.defineProperty,Vn=Object.getOwnPropertyDescriptor,kn=(i,t,e,n)=>{for(var r=n>1?void 0:n?Vn(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&jn(t,e,r),r},se=(i,t)=>(e,n)=>t(e,n,i);exports.DocCanvasView=class extends s.RxDisposable{constructor(e,n,r,o){super();C(this,"_scene");C(this,"_currentDocumentModel");C(this,"_loadedMap",new Set);C(this,"_fps$",new P.BehaviorSubject(""));C(this,"fps$",this._fps$.asObservable());this._renderManagerService=e,this._configService=n,this._currentUniverService=r,this._docViewModelManagerService=o,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.pipe(P.takeUntil(this.dispose$)).subscribe(e=>{if(e==null)return;this._currentDocumentModel=e;const n=e.getUnitId();this._loadedMap.has(n)||(this._addNewRender(),this._loadedMap.add(n))})}dispose(){this._fps$.complete()}_addNewRender(){const e=this._currentDocumentModel,n=e.getUnitId(),r=e.getContainer(),o=e.getParentRenderUnitId();if(r!=null&&o!=null)throw new Error("container or parentRenderUnitId can only exist one");r==null&&o!=null?this._renderManagerService.createRenderWithParent(n,o):this._renderManagerService.createRender(n);const a=this._renderManagerService.getRenderById(n);if(a==null)return;const{scene:c,engine:l}=a;c.openTransformer(),this._scene=c;const u=new M.Viewport(Ie.VIEW_MAIN,c,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});c.attachControl(),c.on(M.EVENT_TYPE.wheel,(p,g)=>{const h=p;if(h.ctrlKey){const f=Math.abs(h.deltaX);let S=f<40?.2:f<80?.4:.2;S*=h.deltaY>0?-1:1,c.scaleX<1&&(S/=2),c.scaleX+S>4?c.scale(4,4):c.scaleX+S<.1?c.scale(.1,.1):h.preventDefault()}else u.onMouseWheel(h,g)}),this._configService.getConfig("hasScroll")!==!1&&n!==s.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&new M.ScrollBar(u),c.addLayer(new M.Layer(c,[],xe),new M.Layer(c,[],Je)),this._addComponent(a),this._currentDocumentModel.getShouldRenderLoopImmediately()&&l.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(l.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(e){const n=this._scene,r=this._currentDocumentModel,o=new M.Documents(_e.MAIN,void 0,{pageMarginLeft:r.documentStyle.marginLeft||0,pageMarginTop:r.documentStyle.marginTop||0});o.zIndex=Qe,e.mainComponent=o,e.components.set(_e.MAIN,o),n.addObjects([o],xe)}};exports.DocCanvasView=kn([s.OnLifecycle(s.LifecycleStages.Ready,exports.DocCanvasView),se(0,M.IRenderManagerService),se(1,s.IConfigService),se(2,s.IUniverInstanceService),se(3,E.Inject(exports.DocViewModelManagerService))],exports.DocCanvasView);var Xn=Object.defineProperty,zn=Object.getOwnPropertyDescriptor,Wn=(i,t,e,n)=>{for(var r=n>1?void 0:n?zn(t,e):t,o=i.length-1,a;o>=0;o--)(a=i[o])&&(r=(n?a(t,e,r):a(r))||r);return n&&r&&Xn(t,e,r),r},ae=(i,t)=>(e,n)=>t(e,n,i);const Hn={hasScroll:!0},Gn="docs";var Oe;exports.UniverDocsPlugin=(Oe=class extends s.Plugin{constructor(e={},n,r,o,a){super(Gn);C(this,"_config");this._injector=n,this._localeService=r,this._configService=o,this._currentUniverService=a,this._config=Object.assign(Hn,e),this._initializeDependencies(n),this._initializeCommands()}initialize(){}_initializeCommands(){[$,F,Le,Be,z,ne,re,ie,B,k,W,H,oe,Ve,Ne,Ce,Me,Pe,je,$e,_,ct,lt,ut,V,Ee,mt,at,st,ke].forEach(e=>{this._injector.get(s.ICommandService).registerCommand(e)}),[Un,Pn,An,Nn,wn,Ln,Bn,$n,Fn,bn,En,Dn].forEach(e=>{this._injector.get(b.IShortcutService).registerShortcut(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[exports.DocCanvasView],[exports.DocSkeletonManagerService],[exports.DocViewModelManagerService],[Fe],[te,{useClass:be}],[M.ITextSelectionRenderManager,{useClass:M.TextSelectionRenderManager}],[exports.TextSelectionManagerService],[le],[he],[fe],[ge],[ue],[me],[ce],[pe],[Se],[de]].forEach(n=>e.add(n))}},C(Oe,"type",s.PluginType.Doc),Oe);exports.UniverDocsPlugin=Wn([ae(1,E.Inject(E.Injector)),ae(2,E.Inject(s.LocaleService)),ae(3,s.IConfigService),ae(4,s.IUniverInstanceService)],exports.UniverDocsPlugin);exports.BreakLineCommand=Ne;exports.BulletListCommand=st;exports.CoverContentCommand=lt;exports.DOCS_COMPONENT_DEFAULT_Z_INDEX=Qe;exports.DOCS_COMPONENT_HEADER_LAYER_INDEX=Je;exports.DOCS_COMPONENT_MAIN_LAYER_INDEX=xe;exports.DOCS_VIEW_KEY=_e;exports.DeleteCommand=Me;exports.DeleteLeftCommand=Le;exports.DeleteRightCommand=Be;exports.DocCopyCommand=tt;exports.DocCutCommand=nt;exports.DocPasteCommand=rt;exports.IMEInputCommand=je;exports.InsertCommand=Ce;exports.MoveCursorOperation=$;exports.MoveSelectionOperation=F;exports.NORMAL_TEXT_SELECTION_PLUGIN_NAME=ft;exports.OrderListCommand=at;exports.ReplaceContentCommand=ct;exports.RichTextEditingMutation=_;exports.SetInlineFormatBoldCommand=z;exports.SetInlineFormatCommand=Ve;exports.SetInlineFormatFontFamilyCommand=H;exports.SetInlineFormatFontSizeCommand=W;exports.SetInlineFormatItalicCommand=ne;exports.SetInlineFormatStrikethroughCommand=ie;exports.SetInlineFormatSubscriptCommand=B;exports.SetInlineFormatSuperscriptCommand=k;exports.SetInlineFormatTextColorCommand=oe;exports.SetInlineFormatUnderlineCommand=re;exports.SetTextSelectionsOperation=Ee;exports.UpdateCommand=Pe;exports.VIEWPORT_KEY=Ie;exports.getDocObject=ee;
|