@univerjs/docs 0.1.0-alpha.2 → 0.1.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +1820 -1712
- package/lib/types/commands/commands/__tests__/mock-text-selection-render-manager.d.ts +24 -0
- package/lib/types/{basics/demo-data.d.ts → commands/commands/break-line.command.d.ts} +2 -2
- package/lib/types/commands/commands/core-editing.command.d.ts +2 -5
- package/lib/types/commands/commands/delete.command.d.ts +26 -0
- package/lib/types/commands/commands/inline-format.command.d.ts +2 -0
- package/lib/types/commands/commands/list.command.d.ts +28 -0
- package/lib/types/commands/operations/text-selection.operation.d.ts +4 -2
- package/lib/types/controllers/clipboard.controller.d.ts +3 -3
- package/lib/types/controllers/ime-input.controller.d.ts +1 -3
- package/lib/types/controllers/inline-format.controller.d.ts +2 -5
- package/lib/types/controllers/move-cursor.controller.d.ts +2 -3
- package/lib/types/controllers/normal-input.controller.d.ts +1 -3
- package/lib/types/controllers/page-render.controller.d.ts +3 -2
- package/lib/types/controllers/text-selection.controller.d.ts +5 -5
- package/lib/types/index.d.ts +6 -2
- package/lib/types/services/text-selection-manager.service.d.ts +33 -31
- package/lib/types/views/doc-canvas-view.d.ts +5 -2
- package/lib/umd/index.js +2 -2
- package/package.json +12 -14
- package/lib/types/controllers/delete.controller.d.ts +0 -30
- package/lib/types/controllers/line-break-input.controller.d.ts +0 -34
package/lib/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(p,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/engine-render"),require("@wendellhu/redi"),require("@ctrl/tinycolor")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/ui","rxjs","@univerjs/engine-render","@wendellhu/redi","@ctrl/tinycolor"],o):(p=typeof globalThis<"u"?globalThis:p||self,o(p.UniverDocs={},p.UniverCore,p.UniverUi,p.rxjs,p.UniverEngineRender,p["@wendellhu/redi"],p.tinycolor))})(this,function(p,o,O,oe,I,y,Ke){"use strict";var Vn=Object.defineProperty;var zn=(p,o,O)=>o in p?Vn(p,o,{enumerable:!0,configurable:!0,writable:!0,value:O}):p[o]=O;var v=(p,o,O)=>(zn(p,typeof o!="symbol"?o+"":o,O),O);var He;function B(i,e){const n=i.getCurrentUniverDocInstance().getUnitId(),r=e.getRenderById(n);if(r==null)return;const{mainComponent:s,scene:a,engine:c}=r;return{document:s,scene:a,engine:c}}function lt(i,e){const t=e.getRenderById(i);if(t==null)return;const{components:n,mainComponent:r,scene:s,engine:a}=t;return{document:r,scene:s,engine:a}}var ce=(i=>(i.MAIN="__Document_Render_Main__",i))(ce||{}),j=(i=>(i.VIEW_MAIN="viewMain",i.VIEW_TOP="viewTop",i.VIEW_LEFT="viewLeft",i.VIEW_LEFT_TOP="viewLeftTop",i))(j||{});const Le=0,Ye=2,Xe=10,Y="normalTextSelectionPluginName",le={id:O.CopyCommand.id,name:"doc.command.copy",type:o.CommandType.COMMAND,multi:!0,priority:999,preconditions:i=>i.getContextValue(o.FOCUSING_DOC)||i.getContextValue(o.FOCUSING_EDITOR),handler:async()=>!0},de={id:O.CutCommand.id,name:"doc.command.cut",type:o.CommandType.COMMAND,multi:!0,priority:999,preconditions:i=>i.getContextValue(o.FOCUSING_DOC)||i.getContextValue(o.FOCUSING_EDITOR),handler:async()=>!0},ue={id:O.PasteCommand.id,name:"doc.command.paste",type:o.CommandType.COMMAND,multi:!0,priority:999,preconditions:i=>i.getContextValue(o.FOCUSING_DOC)||i.getContextValue(o.FOCUSING_EDITOR),handler:async()=>!0};function X(i,e="",t=0){const{startOffset:n,endOffset:r}=i,s=[],a=n-t,c=r-t;return a>0&&s.push({t:"r",len:a,segmentId:e}),s.push({t:"d",len:c-a,line:0,segmentId:e}),s}class x{constructor(){v(this,"_textSelectionInfo",new Map);v(this,"_currentSelection",null);v(this,"_textSelectionInfo$",new oe.BehaviorSubject(null));v(this,"textSelectionInfo$",this._textSelectionInfo$.asObservable())}getCurrentSelection(){return this._currentSelection}dispose(){this._textSelectionInfo$.complete()}refreshSelection(){this._currentSelection!=null&&this._refresh(this._currentSelection)}setCurrentSelection(e){this._currentSelection=e,this._refresh(e)}setCurrentSelectionNotRefresh(e){this._currentSelection=e}getTextSelectionInfo(){return this._textSelectionInfo}getTextRangesByParam(e){return this._getTextRanges(e)}getSelections(){return this._getTextRanges(this._currentSelection)}getFirst(){return this._getFirstByParam(this._currentSelection)}getLast(){return this._getLastByParam(this._currentSelection)}add(e){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:e})}replaceTextRanges(e){this._currentSelection!=null&&this._textSelectionInfo$.next(e)}replaceTextRangesWithNoRefresh(e){this._currentSelection!=null&&this._replaceByParam({...this._currentSelection,textRanges:e})}_addByParam(e){const{pluginName:t,unitId:n,textRanges:r}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map);const s=this._textSelectionInfo.get(t);s.has(n)?s.get(n).push(...r):s.set(n,[...r]),this._refresh({pluginName:t,unitId:n})}_clear(){this._currentSelection!=null&&this._clearByParam(this._currentSelection)}_remove(e){this._currentSelection!=null&&this._removeByParam(e,this._currentSelection)}_reset(){var e;this._currentSelection!=null&&(this._currentSelection={pluginName:Y,unitId:(e=this._currentSelection)==null?void 0:e.unitId},this._textSelectionInfo.clear(),this._refresh(this._currentSelection))}_resetPlugin(){this._currentSelection!=null&&(this._currentSelection.pluginName=Y,this._refresh(this._currentSelection))}_getTextRanges(e){var r;if(e==null)return;const{pluginName:t,unitId:n}=e;return(r=this._textSelectionInfo.get(t))==null?void 0:r.get(n)}_refresh(e){const t=this._getTextRanges(e)??[];this._textSelectionInfo$.next(t.map(n=>{const r=n.startOffset,s=n.endOffset,a=n.collapsed,c=n.style;return{startOffset:r,endOffset:s,collapsed:a,style:c}}))}_getFirstByParam(e){const t=this._getTextRanges(e);return t==null?void 0:t[0]}_getLastByParam(e){const t=this._getTextRanges(e);return t==null?void 0:t[t.length-1]}_replaceByParam(e){const{pluginName:t,unitId:n,textRanges:r}=e;this._textSelectionInfo.has(t)||this._textSelectionInfo.set(t,new Map),this._textSelectionInfo.get(t).set(n,r)}_clearByParam(e){const t=this._getTextRanges(e);t==null||t.splice(0),this._refresh(e)}_removeByParam(e,t){const n=this._getTextRanges(t);n==null||n.splice(e,1),this._refresh(t)}}var dt=Object.defineProperty,ut=Object.getOwnPropertyDescriptor,mt=(i,e,t,n)=>{for(var r=n>1?void 0:n?ut(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&dt(e,t,r),r},ht=(i,e)=>(t,n)=>e(t,n,i);p.DocViewModelManagerService=class{constructor(e){v(this,"_currentViewModelUnitId","");v(this,"_docViewModelMap",new Map);v(this,"_currentDocViewModel$",new oe.BehaviorSubject(null));v(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=e}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap=new Map}getCurrent(){return this._docViewModelMap.get(this._currentViewModelUnitId)}getViewModel(e){var t;return(t=this._docViewModelMap.get(e))==null?void 0:t.docViewModel}setCurrent(e){var n;const t=this._currentUniverService.getUniverDocInstance(e);if(t==null)throw new Error(`Document data model with id ${e} not found when build view model.`);if(t.getBody()!=null){if(!this._docViewModelMap.has(e)){const r=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:r})}if(e===o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const r=(n=this._docViewModelMap.get(e))==null?void 0:n.docViewModel;if(r==null)return;r.reset(t)}this._currentViewModelUnitId=e,this._currentDocViewModel$.next(this.getCurrent())}}_buildDocViewModel(e){return new I.DocumentViewModel(e)}},p.DocViewModelManagerService=mt([ht(0,o.IUniverInstanceService)],p.DocViewModelManagerService);const C={id:"doc.mutation.rich-text-editing",type:o.CommandType.MUTATION,handler:(i,e)=>{const{unitId:t,mutations:n}=e,s=i.get(o.IUniverInstanceService).getUniverDocInstance(t),c=i.get(p.DocViewModelManagerService).getViewModel(t);if(!s)throw new Error(`DocumentDataModel not found for unitId: ${t}`);const l=new o.MemoryCursor;l.reset(),n.forEach(u=>{const{segmentId:g,len:h}=u,m=c==null?void 0:c.getSelfOrHeaderFooterViewModel(g);if(u.t==="r"){const{len:f}=u;l.moveCursor(f)}else if(u.t==="i"){const{body:f}=u;if(f.dataStream.length>1&&/\r/.test(f.dataStream)){const _=s.getSelfOrHeaderFooterModel(g);m.reset(_)}else m.insert(f,l.cursor);l.moveCursor(h)}else if(u.t==="d")m.delete(l.cursor,h);else throw new Error(`Unknown mutation type for mutation: ${u}.`)});const d=s.apply(n);return{unitId:t,mutations:d}}},q={id:"doc.command.delete-left",type:o.CommandType.COMMAND,handler:async()=>!0},me={id:"doc.command.delete-right",type:o.CommandType.COMMAND,handler:async()=>!0},he={id:"doc.command.break-line",type:o.CommandType.COMMAND,handler:async()=>!0},fe={id:"doc.command.insert-text",type:o.CommandType.COMMAND,handler:async(i,e)=>{const t=i.get(o.IUndoRedoService),n=i.get(o.ICommandService),r=i.get(x),{range:s,segmentId:a,body:c,unitId:l,textRanges:d}=e,{startOffset:u,collapsed:g}=s,h={id:C.id,params:{unitId:l,mutations:[]}};g?h.params.mutations.push({t:"r",len:u,segmentId:a}):h.params.mutations.push(...X(s,a)),h.params.mutations.push({t:"i",body:c,len:c.dataStream.length,line:0,segmentId:a});const m=n.syncExecuteCommand(h.id,h.params);return r.replaceTextRanges(d),m?(t.pushUndoRedo({unitID:l,undoMutations:[{id:C.id,params:m}],redoMutations:[{id:C.id,params:h.params}],undo(){return n.syncExecuteCommand(C.id,m),r.replaceTextRanges([s]),!0},redo(){return n.syncExecuteCommand(C.id,h.params),r.replaceTextRanges(d),!0}}),!0):!1}};var Ae=(i=>(i[i.LEFT=0]="LEFT",i[i.RIGHT=1]="RIGHT",i))(Ae||{});const ge={id:"doc.command.delete-text",type:o.CommandType.COMMAND,handler:async(i,e)=>{const t=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(x),{range:s,segmentId:a,unitId:c,direction:l,textRanges:d,len:u=1}=e,{collapsed:g,startOffset:h}=s,m={id:C.id,params:{unitId:c,mutations:[]}};g?(h>0&&m.params.mutations.push({t:"r",len:l===0?h-u:h,segmentId:a}),m.params.mutations.push({t:"d",len:u,line:0,segmentId:a})):m.params.mutations.push(...X(s,a));const f=t.syncExecuteCommand(m.id,m.params);return r.replaceTextRanges(d),f&&n.pushUndoRedo({unitID:c,undoMutations:[{id:C.id,params:f}],redoMutations:[{id:C.id,params:m.params}],undo(){return t.syncExecuteCommand(C.id,f),r.replaceTextRanges([s]),!0},redo(){return t.syncExecuteCommand(C.id,m.params),r.replaceTextRanges(d),!0}}),!1}},$e={id:"doc.command.update-text",type:o.CommandType.COMMAND,handler:async(i,e)=>{const{range:t,segmentId:n,updateBody:r,coverType:s,unitId:a,textRanges:c}=e,l=i.get(o.ICommandService),d=i.get(o.IUndoRedoService),u=i.get(x),g={id:C.id,params:{unitId:a,mutations:[]}},{startOffset:h,endOffset:m}=t;g.params.mutations.push({t:"r",len:h,segmentId:n}),g.params.mutations.push({t:"r",body:r,len:m-h,segmentId:n,coverType:s});const f=l.syncExecuteCommand(g.id,g.params);return u.replaceTextRanges(c),f?(d.pushUndoRedo({unitID:a,undoMutations:[{id:C.id,params:f}],redoMutations:[{id:C.id,params:g.params}],undo(){return l.syncExecuteCommand(C.id,f),u.replaceTextRanges(c),!0},redo(){return l.syncExecuteCommand(C.id,g.params),u.replaceTextRanges(c),!0}}),!0):!1}};class Be{constructor(){v(this,"_previousActiveRange",null);v(this,"_undoMutationParamsCache",[]);v(this,"_redoMutationParamsCache",[])}clearUndoRedoMutationParamsCache(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[]}setActiveRange(e){this._previousActiveRange=e}pushUndoRedoMutationParams(e,t){this._undoMutationParamsCache.push(e),this._redoMutationParamsCache.push(t)}fetchComposedUndoRedoMutationParams(e){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null)return null;const{unitId:t}=this._undoMutationParamsCache[0],{segmentId:n,startOffset:r,collapsed:s}=this._previousActiveRange,a={unitId:t,mutations:[]},c={unitId:t,mutations:[]};return s?(a.mutations.push({t:"r",len:r,segmentId:n}),c.mutations.push({t:"r",len:r,segmentId:n})):(r>0&&a.mutations.push({t:"r",len:r,segmentId:n}),a.mutations.push(this._undoMutationParamsCache[0].mutations.find(l=>l.t==="i")),c.mutations.push(...X(this._previousActiveRange,n))),e.length&&(a.mutations.push({t:"d",len:e.length,line:0,segmentId:n}),c.mutations.push({t:"i",body:{dataStream:e},len:e.length,line:0,segmentId:n})),{redoMutationParams:c,undoMutationParams:a,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const je={id:"doc.command.ime-input",type:o.CommandType.COMMAND,handler:async(i,e)=>{const{unitId:t,newText:n,oldTextLen:r,range:s,segmentId:a,textRanges:c,isCompositionEnd:l}=e,d=i.get(o.ICommandService),u=i.get(o.IUndoRedoService),g=i.get(x),h=i.get(Be),m={id:C.id,params:{unitId:t,mutations:[]}};s.collapsed?m.params.mutations.push({t:"r",len:s.startOffset,segmentId:a}):m.params.mutations.push(...X(s,a)),r>0&&m.params.mutations.push({t:"d",len:r,line:0,segmentId:a}),m.params.mutations.push({t:"i",body:{dataStream:n},len:n.length,line:0,segmentId:a});const f=d.syncExecuteCommand(m.id,m.params);if(h.pushUndoRedoMutationParams(f,m.params),g.replaceTextRanges(c),l){if(f){const _=h.fetchComposedUndoRedoMutationParams(n);if(_==null)return!1;const{undoMutationParams:S,redoMutationParams:M,previousActiveRange:R}=_;return u.pushUndoRedo({unitID:t,undoMutations:[{id:C.id,params:S}],redoMutations:[{id:C.id,params:M}],undo(){return d.syncExecuteCommand(C.id,S),g.replaceTextRanges([R]),!0},redo(){return d.syncExecuteCommand(C.id,M),g.replaceTextRanges(c),!0}}),!0}}else return!!f;return!1}},F={id:"doc.command.set-inline-format-bold",type:o.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-italic",type:o.CommandType.COMMAND,handler:async()=>!0},J={id:"doc.command.set-inline-format-underline",type:o.CommandType.COMMAND,handler:async()=>!0},Q={id:"doc.command.set-inline-format-strikethrough",type:o.CommandType.COMMAND,handler:async()=>!0},k={id:"doc.command.set-inline-format-fontsize",type:o.CommandType.COMMAND,handler:async()=>!0},V={id:"doc.command.set-inline-format-font-family",type:o.CommandType.COMMAND,handler:async()=>!0},ee={id:"doc.command.set-inline-format-text-color",type:o.CommandType.COMMAND,handler:async()=>!0},Fe={id:"doc.command.set-inline-format",type:o.CommandType.COMMAND,handler:async(i,e)=>{const{segmentId:t,value:n,preCommandId:r}=e,s=i.get(o.IUndoRedoService),a=i.get(o.ICommandService),c=i.get(x),l=i.get(o.IUniverInstanceService),d=c.getSelections();if(!Array.isArray(d)||d.length===0)return!1;let u=l.getCurrentUniverDocInstance(),g=u.getUnitId();g===o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(u=l.getUniverDocInstance(o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),g=u.getUnitId());let h;const m={[F.id]:"bl",[Z.id]:"it",[J.id]:"ul",[Q.id]:"st",[k.id]:"fs",[V.id]:"ff",[ee.id]:"cl"};switch(r){case F.id:case Z.id:case J.id:case Q.id:{h=gt(u.body.textRuns,m[r],d);break}case k.id:case V.id:{h=n;break}case ee.id:{h={rgb:n};break}default:throw new Error(`Unknown command: ${r} in handleInlineFormat`)}const f={id:C.id,params:{unitId:g,mutations:[]}},_=new o.MemoryCursor;_.reset();for(const R of d){const{startOffset:b,endOffset:T}=R,$={dataStream:"",textRuns:[{st:0,ed:T-b,ts:{[m[r]]:h}}]},N=b-_.cursor;N!==0&&f.params.mutations.push({t:"r",len:N,segmentId:t}),f.params.mutations.push({t:"r",body:$,len:T-b,segmentId:t}),_.reset(),_.moveCursor(T)}const S=a.syncExecuteCommand(f.id,f.params),M=[F.id,k.id,V.id];return M.includes(r)&&c.refreshSelection(),S?(s.pushUndoRedo({unitID:g,undoMutations:[{id:C.id,params:S}],redoMutations:[{id:C.id,params:f.params}],undo(){return a.syncExecuteCommand(C.id,S),M.includes(r)&&c.refreshSelection(),!0},redo(){return a.syncExecuteCommand(C.id,f.params),M.includes(r)&&c.refreshSelection(),!0}}),!0):!1}};function ft(i){return i!==null&&typeof i=="object"}function gt(i,e,t){let n=0,r=0;for(;n!==i.length&&r!==t.length;){const{startOffset:s,endOffset:a}=t[r],{st:c,ed:l,ts:d}=i[n];if(a<=c)r++;else if(l<=s)n++;else{if((d==null?void 0:d[e])==null)return/bl|it/.test(e)?o.BooleanNumber.TRUE:{s:o.BooleanNumber.TRUE};if(d[e]===o.BooleanNumber.FALSE)return o.BooleanNumber.TRUE;if(ft(d[e])&&d[e].s===o.BooleanNumber.FALSE)return{s:o.BooleanNumber.TRUE};n++}}return/bl|it/.test(e)?o.BooleanNumber.FALSE:{s:o.BooleanNumber.FALSE}}const qe={id:"doc.command-replace-content",type:o.CommandType.COMMAND,handler:async(i,e)=>{var f;const{unitId:t,body:n,textRanges:r,segmentId:s=""}=e,a=i.get(o.IUniverInstanceService),c=i.get(o.ICommandService),l=i.get(x),d=i.get(o.IUndoRedoService),u=(f=a.getUniverDocInstance(t))==null?void 0:f.getSnapshot().body,g=l.getSelections();if(u==null||!Array.isArray(g)||g.length===0)return!1;const h=Je(t,s,u,n),m=c.syncExecuteCommand(h.id,h.params);return l.replaceTextRanges(r),m?(d.pushUndoRedo({unitID:t,undoMutations:[{id:C.id,params:m}],redoMutations:[{id:C.id,params:h.params}],undo(){return c.syncExecuteCommand(C.id,m),l.replaceTextRanges(g),!0},redo(){return c.syncExecuteCommand(C.id,h.params),l.replaceTextRanges(r),!0}}),!0):!1}},Ze={id:"doc.command-cover-content",type:o.CommandType.COMMAND,handler:async(i,e)=>{var u;const{unitId:t,body:n,segmentId:r=""}=e,s=i.get(o.IUniverInstanceService),a=i.get(o.ICommandService),c=i.get(o.IUndoRedoService),l=(u=s.getUniverDocInstance(t))==null?void 0:u.getSnapshot().body;if(l==null)return!1;const d=Je(t,r,l,n);return a.syncExecuteCommand(d.id,d.params),c.clearUndoRedo(t),!0}};function Je(i,e,t,n){const r={id:C.id,params:{unitId:i,mutations:[]}},s=(t==null?void 0:t.dataStream.length)-2;return s>0&&r.params.mutations.push({t:"d",len:s,line:0,segmentId:e}),n.dataStream.length>0&&r.params.mutations.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:e}),r}const U={id:"doc.operation.move-cursor",type:o.CommandType.OPERATION,handler:(i,e)=>!!e},E={id:"doc.operation.move-selection",type:o.CommandType.OPERATION,handler:(i,e)=>!!e},ke={id:"doc.operation.set-selections",type:o.CommandType.OPERATION,handler:(i,e)=>(i.get(x).replaceTextRangesWithNoRefresh(e.ranges),!0)},_t=(i,e)=>{const t=i.get(o.IUniverInstanceService).getUniverDocInstance(e.unitId),n=(t==null?void 0:t.zoomRatio)||1;return{...o.Tools.deepClone(e),zoomRatio:n}},L={id:"doc.operation.set-zoom-ratio",type:o.CommandType.OPERATION,handler:(i,e)=>{const t=i.get(o.IUniverInstanceService).getUniverDocInstance(e.unitId);if(!t)return!1;const n=t.getSnapshot();return n.settings==null?n.settings={zoomRatio:e.zoomRatio}:n.settings.zoomRatio=e.zoomRatio,!0}},Qe={type:o.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(i,e)=>{const t=i.get(o.ICommandService),n=i.get(o.IUndoRedoService),r=i.get(o.IUniverInstanceService);let s=r.getCurrentUniverDocInstance().getUnitId(),a=1;if(e&&(s=e.documentId??s,a=e.zoomRatio??a),!r.getUniverDocInstance(s))return!1;const l={zoomRatio:a,unitId:s},d=_t(i,l);return t.syncExecuteCommand(L.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:L.id,params:d}],redoMutations:[{id:L.id,params:l}]}),!0):!1}},et={id:"doc.operation.select-all",type:o.CommandType.COMMAND,handler:async i=>{const e=i.get(o.IUniverInstanceService),t=i.get(x),n=e.getCurrentUniverDocInstance().getSnapshot().body;if(n==null)return!1;const r=[{startOffset:0,endOffset:n.dataStream.length-2,collapsed:!1}];return t.replaceTextRanges(r),!0}},tt={id:"doc.command.inner-paste",type:o.CommandType.COMMAND,handler:async(i,e)=>{const{segmentId:t,body:n,textRanges:r}=e,s=i.get(o.IUndoRedoService),a=i.get(o.ICommandService),c=i.get(x),l=i.get(o.IUniverInstanceService),d=c.getSelections();if(!Array.isArray(d)||d.length===0)return!1;const g=l.getCurrentUniverDocInstance().getUnitId(),h={id:C.id,params:{unitId:g,mutations:[]}},m=new o.MemoryCursor;m.reset();for(const _ of d){const{startOffset:S,endOffset:M,collapsed:R}=_,b=S-m.cursor;R?h.params.mutations.push({t:"r",len:b,segmentId:t}):h.params.mutations.push(...X(_,t,m.cursor)),h.params.mutations.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:t}),m.reset(),m.moveCursor(M)}const f=a.syncExecuteCommand(h.id,h.params);return c.replaceTextRanges(r),f?(s.pushUndoRedo({unitID:g,undoMutations:[{id:C.id,params:f}],redoMutations:[{id:C.id,params:h.params}],undo(){return a.syncExecuteCommand(C.id,f),c.replaceTextRanges(d),!0},redo(){return a.syncExecuteCommand(C.id,h.params),c.replaceTextRanges(r),!0}}),!0):!1}},_e={id:"doc.command.inner-cut",type:o.CommandType.COMMAND,handler:async(i,e)=>{const{segmentId:t,textRanges:n}=e,r=i.get(o.IUndoRedoService),s=i.get(o.ICommandService),a=i.get(x),c=i.get(o.IUniverInstanceService),l=a.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const d=c.getCurrentUniverDocInstance().getUnitId(),u=c.getUniverDocInstance(d),g=o.getDocsUpdateBody(u.snapshot,t);if(g==null)return!1;const h={id:C.id,params:{unitId:d,mutations:[]}},m=new o.MemoryCursor;m.reset();for(const _ of l){const{startOffset:S,endOffset:M,collapsed:R}=_,b=S-m.cursor;R?h.params.mutations.push({t:"r",len:b,segmentId:t}):h.params.mutations.push(...pt(_,g,t,m.cursor)),m.reset(),m.moveCursor(M)}const f=s.syncExecuteCommand(h.id,h.params);return a.replaceTextRanges(n),f?(r.pushUndoRedo({unitID:d,undoMutations:[{id:C.id,params:f}],redoMutations:[{id:C.id,params:h.params}],undo(){return s.syncExecuteCommand(C.id,f),a.replaceTextRanges(l),!0},redo(){return s.syncExecuteCommand(C.id,h.params),a.replaceTextRanges(n),!0}}),!0):!1}};function pt(i,e,t="",n=0){const{startOffset:r,endOffset:s}=i,a=[],{paragraphs:c=[]}=e,l=r-n,d=s-n,u=c==null?void 0:c.find(g=>g.startIndex-n>=l&&g.startIndex-n<=d);if(l>0&&a.push({t:"r",len:l,segmentId:t}),u&&u.startIndex-n>l){const g=u.startIndex-n;a.push({t:"d",len:g-l,line:0,segmentId:t}),a.push({t:"r",len:1,segmentId:t}),d>g+1&&a.push({t:"d",len:d-g-1,line:0,segmentId:t})}else a.push({t:"d",len:d-l,line:0,segmentId:t});return a}const St=10,vt=6;function It(){return o.Tools.generateRandomId(vt)}function Ct(i){const e=i.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class Mt{constructor(){v(this,"_cache",new o.LRUMap(St))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const nt=new Mt;function Ot(i){const e=i.style,t={};for(let n=0;n<e.length;n++){const r=e[n],s=e.getPropertyValue(r);switch(r){case"margin-top":{const a=parseInt(s);t.spaceAbove=/pt/.test(s)?Ve(a):a;break}case"margin-bottom":{const a=parseInt(s);t.spaceBelow=/pt/.test(s)?Ve(a):a;break}}}return Object.getOwnPropertyNames(t).length?t:null}function Ve(i){return i/.75}function ze(i){const e=i.style,t={},n=i.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{t.bl=o.BooleanNumber.TRUE;break}case"s":{t.st={s:o.BooleanNumber.TRUE};break}case"u":{t.ul={s:o.BooleanNumber.TRUE};break}case"i":{t.it=o.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=n==="sup"?o.BaselineOffset.SUPERSCRIPT:o.BaselineOffset.SUBSCRIPT;break}}for(let r=0;r<e.length;r++){const s=e[r],a=e.getPropertyValue(s);switch(s){case"font-family":{t.ff=a;break}case"font-size":{const c=parseInt(a);Number.isNaN(c)||(t.fs=/pt$/.test(a)?Ve(c):c);break}case"font-style":{a==="italic"&&(t.it=o.BooleanNumber.TRUE);break}case"font-weight":{Number(a)>400&&(t.bl=o.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(a)?t.ul={s:o.BooleanNumber.TRUE}:/overline/.test(a)?t.ol={s:o.BooleanNumber.TRUE}:/line-through/.test(a)&&(t.st={s:o.BooleanNumber.TRUE});break}case"color":{const c=new Ke.TinyColor(a);c.isValid&&(t.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new Ke.TinyColor(a);c.isValid&&(t.bg={rgb:c.toRgbString()});break}}}return t}function Rt(i){const e=new DOMParser,t=`<x-univer id="univer-root">${i}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function rt(i,e){const t=i.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(i)}const we=class we{constructor(){v(this,"styleCache",new Map);v(this,"styleRules",[]);v(this,"afterProcessRules",[])}static use(e){if(this.pluginList.includes(e))throw new Error(`Univer paste plugin ${e.name} already added`);this.pluginList.push(e)}convert(e){const t=we.pluginList.find(s=>s.checkPasteType(e)),n=Rt(e),r={dataStream:"",textRuns:[]};return t&&(this.styleRules=[...t.stylesRules],this.afterProcessRules=[...t.afterProcessRules]),this.styleCache.clear(),this.process(null,n==null?void 0:n.childNodes,r),this.styleCache.clear(),this.styleRules=[],this.afterProcessRules=[],r}process(e,t,n){var r;for(const s of t)if(s.nodeType===Node.TEXT_NODE){const a=(r=s.nodeValue)==null?void 0:r.replace(/[\r\n]/g,"");let c;e&&this.styleCache.has(e)&&(c=this.styleCache.get(e)),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(s.nodeType===Node.ELEMENT_NODE){const a=e?this.styleCache.get(e):{},c=this.styleRules.find(({filter:g})=>rt(s,g)),l=c?c.getStyle(s):ze(s);this.styleCache.set(s,{...a,...l});const{childNodes:d}=s;this.process(s,d,n);const u=this.afterProcessRules.find(({filter:g})=>rt(s,g));u&&u.handler(n,s)}}};v(we,"pluginList",[]);let te=we;const yt={name:"univer-doc-paste-plugin-lark",checkPasteType(i){return/lark-record-clipboard/i.test(i)},stylesRules:[{filter:["s"],getStyle(i){const e=ze(i);return{st:{s:o.BooleanNumber.TRUE},...e}}}],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"}}]},Dt={name:"univer-doc-paste-plugin-word",checkPasteType(i){return/word|mso/i.test(i)},stylesRules:[{filter:["b"],getStyle(i){const e=ze(i);return{bl:o.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(i){return i.tagName==="P"&&/mso/i.test(i.className)},handler(i,e){i.paragraphs==null&&(i.paragraphs=[]);const t={startIndex:i.dataStream.length},n=Ot(e);n&&(t.paragraphStyle=n),i.paragraphs.push(t),i.dataStream+="\r"}}]};function bt(i,e){const{st:t,ed:n,ts:r={}}=e,{ff:s,fs:a,it:c,bl:l,ul:d,st:u,ol:g,bg:h,cl:m,va:f}=r;let _=i.slice(t,n);const S=[];return c===o.BooleanNumber.TRUE&&(_=`<i>${_}</i>`),f===o.BaselineOffset.SUPERSCRIPT?_=`<sup>${_}</sup>`:f===o.BaselineOffset.SUBSCRIPT&&(_=`<sub>${_}</sub>`),(d==null?void 0:d.s)===o.BooleanNumber.TRUE&&(_=`<u>${_}</u>`),(u==null?void 0:u.s)===o.BooleanNumber.TRUE&&(_=`<s>${_}</s>`),l===o.BooleanNumber.TRUE&&(_=`<strong>${_}</strong>`),s&&S.push(`font-family: ${s}`),m&&S.push(`color: ${m.rgb}`),a&&S.push(`font-size: ${a}px`),g&&S.push("text-decoration: overline"),h&&S.push(`background: ${h.rgb}`),S.length?`<span style="${S.join(";")}">${_}</span>`:_}function it(i,e=!0){const{dataStream:t,textRuns:n=[],paragraphs:r=[]}=i;let s=0;const a=[],c=[];for(const l of n){const{st:d,ed:u}=l;if(d!==s&&a.push(t.slice(s,d)),a.push(bt(t,l)),s=u,e)for(const g of r){const{startIndex:h,paragraphStyle:m={}}=g;if(h>=d&&h<=u){const{spaceAbove:f,spaceBelow:_}=m,S=[];f!=null&&(typeof f=="number"?S.push(`margin-top: ${f}px`):S.push(`margin-top: ${f.v}px`)),_!=null&&(typeof _=="number"?S.push(`margin-bottom: ${_}px`):S.push(`margin-bottom: ${_.v}px`)),c.push(`<p className="UniverNormal" ${S.length?`style="${S.join(";")}"`:""}>${a.join("")}</p>`),a.length=0}}}return c.join("")+a.join("")}class xt{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return it(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=it(n,!1),t+="</p>";return t}}var Tt=Object.defineProperty,Pt=Object.getOwnPropertyDescriptor,Ut=(i,e,t,n)=>{for(var r=n>1?void 0:n?Pt(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&Tt(e,t,r),r},st=(i,e)=>(t,n)=>e(t,n,i);te.use(Dt),te.use(yt);const at=y.createIdentifier("doc.clipboard-service");let We=class extends o.Disposable{constructor(e,t){super();v(this,"_clipboardHooks",[]);v(this,"_htmlToUDM",new te);v(this,"_umdToHtml",new xt);this._currentUniverService=e,this._clipboardInterfaceService=t}async queryClipboardData(){const e=await this._clipboardInterfaceService.read();if(e.length===0)return Promise.reject();const t=e[0],n=await t.getType(O.PLAIN_TEXT_CLIPBOARD_MIME_TYPE).then(a=>a&&a.text()),r=await t.getType(O.HTML_CLIPBOARD_MIME_TYPE).then(a=>a&&a.text());if(!r)return{dataStream:n};const s=Ct(r);if(s){const a=nt.get(s);if(a)return a}return this._htmlToUDM.convert(r)}async setClipboardData(e){const t=It(),n=e.length>1?e.map(s=>s.dataStream).join(`
|
|
2
|
-
`):e[0].dataStream;let r=this._umdToHtml.convert(e);return e.length===1&&(r=r.replace(/(<[a-z]+)/,(s,a)=>`${a} data-copy-id="${t}"`),nt.set(t,e[0])),this._clipboardInterfaceService.write(n,r)}addClipboardHook(e){return this._clipboardHooks.push(e),o.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}};We=Ut([st(0,o.IUniverInstanceService),st(1,O.IClipboardInterfaceService)],We);var Et=Object.defineProperty,Nt=Object.getOwnPropertyDescriptor,wt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Nt(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&Et(e,t,r),r},z=(i,e)=>(t,n)=>e(t,n,i);let pe=class extends o.Disposable{constructor(i,e,t,n,r,s){super(),this._logService=i,this._commandService=e,this._currentUniverService=t,this._docClipboardService=n,this._textSelectionRenderManager=r,this._contextService=s,this._commandExecutedListener(),this.initialize()}initialize(){[le,de,ue].forEach(i=>this.disposeWithMe(this._commandService.registerAsMultipleCommand(i))),[tt,_e].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_commandExecutedListener(){const i=[de.id,le.id,ue.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id)&&!(!this._contextService.getContextValue(o.FOCUSING_DOC)&&!this._contextService.getContextValue(o.FOCUSING_EDITOR)))switch(e.id){case ue.id:{this._handlePaste();break}case le.id:{this._handleCopy();break}case de.id:{this._handleCut();break}default:throw new Error(`Unhandled command ${e.id}`)}}))}async _handlePaste(){const{_docClipboardService:i}=this,{segmentId:e,endOffset:t,style:n}=this._textSelectionRenderManager.getActiveRange()??{},r=this._textSelectionRenderManager.getAllTextRanges();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),t!=null)try{const s=await i.queryClipboardData();let a=t;for(const l of r){const{startOffset:d,endOffset:u}=l;d==null||u==null||u<=t&&(a+=s.dataStream.length-(u-d))}const c=[{startOffset:a,endOffset:a,collapsed:!0,style:n}];this._commandService.executeCommand(tt.id,{body:s,segmentId:e,textRanges:c})}catch{this._logService.error("[DocClipboardController] clipboard is empty")}}_getDocumentBodyInRanges(){const i=this._textSelectionRenderManager.getAllTextRanges(),e=this._currentUniverService.getCurrentUniverDocInstance(),{dataStream:t,textRuns:n=[],paragraphs:r=[]}=e.getBody(),s=[];for(const a of i){const{startOffset:c,endOffset:l,collapsed:d}=a;if(d||c==null||l==null)continue;const u={dataStream:t.slice(c,l)},g=[];for(const m of n){const f=o.Tools.deepClone(m),{st:_,ed:S}=f;o.Tools.hasIntersectionBetweenTwoRanges(_,S,c,l)&&(c>=_&&c<=S?g.push({...f,st:c,ed:Math.min(l,S)}):l>=_&&l<=S?g.push({...f,st:Math.max(c,_),ed:l}):g.push(f))}g.length&&(u.textRuns=g.map(m=>{const{st:f,ed:_}=m;return{...m,st:f-c,ed:_-c}}));const h=[];for(const m of r){const{startIndex:f}=m;f>=c&&f<=l&&h.push(o.Tools.deepClone(m))}h.length&&(u.paragraphs=h.map(m=>({...m,startIndex:m.startIndex-c}))),s.push(u)}return s}async _handleCopy(){const{_docClipboardService:i}=this,e=this._getDocumentBodyInRanges();try{i.setClipboardData(e)}catch{this._logService.error("[DocClipboardController] set clipboard failed")}}async _handleCut(){const{segmentId:i,endOffset:e,style:t}=this._textSelectionRenderManager.getActiveRange()??{},n=this._textSelectionRenderManager.getAllTextRanges();if(i==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),e!=null){this._handleCopy();try{let r=e;for(const a of n){const{startOffset:c,endOffset:l}=a;c==null||l==null||l<=e&&(r-=l-c)}const s=[{startOffset:r,endOffset:r,collapsed:!0,style:t}];this._commandService.executeCommand(_e.id,{segmentId:i,textRanges:s})}catch{this._logService.error("[DocClipboardController] cut content failed")}}}};pe=wt([o.OnLifecycle(o.LifecycleStages.Rendered,pe),z(0,o.ILogService),z(1,o.ICommandService),z(2,o.IUniverInstanceService),z(3,at),z(4,I.ITextSelectionRenderManager),z(5,o.IContextService)],pe);var Lt=Object.defineProperty,At=Object.getOwnPropertyDescriptor,$t=(i,e,t,n)=>{for(var r=n>1?void 0:n?At(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&Lt(e,t,r),r},ot=(i,e)=>(t,n)=>e(t,n,i);p.DocSkeletonManagerService=class{constructor(e,t){v(this,"_currentSkeletonUnitId","");v(this,"_docSkeletonMap",new Map);v(this,"_currentSkeleton$",new oe.BehaviorSubject(null));v(this,"currentSkeleton$",this._currentSkeleton$.asObservable());v(this,"_currentSkeletonBefore$",new oe.BehaviorSubject(null));v(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=e,this._docViewModelManagerService=t,this.initialize()}initialize(){this._docViewModelManagerService.currentDocViewModel$.subscribe(e=>{e!=null&&this._setCurrent(e)})}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap=new Map}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}makeDirtyCurrent(e=!0){this.makeDirty(this._currentSkeletonUnitId,e)}makeDirty(e,t=!0){const n=this.getSkeletonByUnitId(e);n!=null&&(n.dirty=t)}_setCurrent(e){const{unitId:t}=e;if(this._docSkeletonMap.has(t)){const n=this.getSkeletonByUnitId(t);n.skeleton.calculate(),n.dirty=!0}else{const n=this._buildSkeleton(e.docViewModel);n.calculate(),this._docSkeletonMap.set(t,{unitId:t,skeleton:n,dirty:!1})}return this._currentSkeletonUnitId=t,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}getSkeletonByUnitId(e){return this._docSkeletonMap.get(e)}_buildSkeleton(e){return I.DocumentSkeleton.create(e,this._localeService)}},p.DocSkeletonManagerService=$t([ot(0,y.Inject(o.LocaleService)),ot(1,y.Inject(p.DocViewModelManagerService))],p.DocSkeletonManagerService);var Bt=Object.defineProperty,jt=Object.getOwnPropertyDescriptor,Ft=(i,e,t,n)=>{for(var r=n>1?void 0:n?jt(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&Bt(e,t,r),r},Se=(i,e)=>(t,n)=>e(t,n,i);let ve=class extends o.Disposable{constructor(i,e,t,n){super(),this._docSkeletonManagerService=i,this._currentUniverService=e,this._textSelectionRenderManager=t,this._commandService=n,this._initialize(),this._commandExecutedListener()}_initialize(){}_commandExecutedListener(){const i=[q.id,me.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(i.includes(e.id))switch(e.id){case q.id:this._handleDeleteLeft();break;case me.id:this._handleDeleteRight();break;default:throw new Error("Unknown command")}}))}_handleDeleteLeft(){var m;const i=this._textSelectionRenderManager.getActiveRange(),e=(m=this._docSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(i==null||e==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance(),{startOffset:n,collapsed:r,segmentId:s,style:a}=i;if(n===0&&r)return;const c=e.findNodeByCharIndex(n),l=I.hasListSpan(c),d=I.isIndentBySpan(c,t.body);let u=n;const g=e.findNodeByCharIndex(n-1);if(I.isFirstSpan(c)&&g!==c&&(l===!0||d===!0)){const f=I.getParagraphBySpan(c,t.body);if(f==null)return;const _=f==null?void 0:f.startIndex,S={startIndex:0},M=f.paragraphStyle;if(l===!0){const b=f.paragraphStyle;b&&(S.paragraphStyle=b)}else if(d===!0){const b=f.bullet;b&&(S.bullet=b),M!=null&&(S.paragraphStyle={...M},delete S.paragraphStyle.hanging,delete S.paragraphStyle.indentStart)}const R=[{startOffset:u,endOffset:u,collapsed:!0,style:a}];this._commandService.executeCommand($e.id,{unitId:t.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...S}]},range:{startOffset:_,endOffset:_+1,collapsed:!1},textRanges:R,coverType:o.UpdateDocsAttributeType.REPLACE,segmentId:s})}else{const{endNodePosition:f}=i;if(f!=null){const _=e.findSpanByPosition(f);I.hasListSpan(_)&&!I.isSameLine(c,_)&&(i.endOffset-=1)}if(r===!0){u-=g.count;const _=[{startOffset:u,endOffset:u,collapsed:!0,style:a}];this._commandService.executeCommand(ge.id,{unitId:t.getUnitId(),range:i,segmentId:s,direction:Ae.LEFT,len:g.count,textRanges:_})}else{const _=this._getTextRangesWhenDelete();this._commandService.executeCommand(_e.id,{segmentId:s,textRanges:_})}}e==null||e.calculate()}_handleDeleteRight(){var c;const i=this._textSelectionRenderManager.getActiveRange(),e=(c=this._docSkeletonManagerService.getCurrent())==null?void 0:c.skeleton;if(i==null||e==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance(),{startOffset:n,collapsed:r,segmentId:s,style:a}=i;if(!(n===t.getBody().dataStream.length-2&&r)){if(r===!0){const l=[{startOffset:n,endOffset:n,collapsed:!0,style:a}],d=e.findNodeByCharIndex(n);this._commandService.executeCommand(ge.id,{unitId:t.getUnitId(),range:i,segmentId:s,direction:Ae.RIGHT,textRanges:l,len:d.count})}else{const l=this._getTextRangesWhenDelete();this._commandService.executeCommand(_e.id,{segmentId:s,textRanges:l})}e==null||e.calculate()}}_getTextRangesWhenDelete(){const i=this._textSelectionRenderManager.getActiveRange(),e=this._textSelectionRenderManager.getAllTextRanges();let t=i.endOffset;for(const r of e){const{startOffset:s,endOffset:a}=r;s==null||a==null||a<=i.endOffset&&(t-=a-s)}return[{startOffset:t,endOffset:t,collapsed:!0,style:i.style}]}};ve=Ft([o.OnLifecycle(o.LifecycleStages.Rendered,ve),Se(0,y.Inject(p.DocSkeletonManagerService)),Se(1,o.IUniverInstanceService),Se(2,I.ITextSelectionRenderManager),Se(3,o.ICommandService)],ve);var kt=Object.defineProperty,Vt=Object.getOwnPropertyDescriptor,zt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Vt(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&kt(e,t,r),r},Ge=(i,e)=>(t,n)=>e(t,n,i);let Ie=class extends o.Disposable{constructor(i,e,t){super(),this._docSkeletonManagerService=i,this._renderManagerService=e,this._commandService=t,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.subscribe(i=>{if(i==null)return;const{skeleton:e,unitId:t}=i,n=this._renderManagerService.getRenderById(t);if(n==null)return;const{mainComponent:r}=n;r.changeSkeleton(e),this._recalculateSizeBySkeleton(n,e)})}_recalculateSizeBySkeleton(i,e){var c;const{mainComponent:t}=i,n=t,r=(c=e.getSkeletonData())==null?void 0:c.pages;if(r==null)return;let s=0,a=0;for(let l=0,d=r.length;l<d;l++){const u=r[l],{pageWidth:g,pageHeight:h}=u;n.pageLayoutType===I.PageLayoutType.VERTICAL?(a+=h,l!==d-1&&(a+=n.pageMarginTop),s=Math.max(s,g)):n.pageLayoutType===I.PageLayoutType.HORIZONTAL&&(s+=g,l!==d-1&&(s+=n.pageMarginLeft),a=Math.max(a,h))}n.resize(s,a)}_commandExecutedListener(){const i=[C.id],e=[o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(i.includes(t.id)){const r=t.params,{unitId:s}=r,a=this._docSkeletonManagerService.getSkeletonByUnitId(s);if(a==null)return;const{skeleton:c}=a,l=this._renderManagerService.getRenderById(s);if(l==null)return;if(c.calculate(),e.includes(s)){(n=l.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(l,c)}}))}};Ie=zt([o.OnLifecycle(o.LifecycleStages.Rendered,Ie),Ge(0,y.Inject(p.DocSkeletonManagerService)),Ge(1,I.IRenderManagerService),Ge(2,o.ICommandService)],Ie);var Wt=Object.defineProperty,Gt=Object.getOwnPropertyDescriptor,Ht=(i,e,t,n)=>{for(var r=n>1?void 0:n?Gt(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&Wt(e,t,r),r},ne=(i,e)=>(t,n)=>e(t,n,i);let Ce=class extends o.Disposable{constructor(e,t,n,r,s){super();v(this,"_liquid",new I.Liquid);v(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._commandService=r,this._floatingObjectManagerService=s,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh(),this._updateOnPluginChange()}_updateOnPluginChange(){this._floatingObjectManagerService.pluginUpdate$.subscribe(e=>{const t=this._docSkeletonManagerService.getCurrent();if(t==null)return;const{unitId:n,skeleton:r}=t,s=this._renderManagerService.getRenderById(n);if(s==null)return;const{mainComponent:a,components:c,scene:l}=s,d=a,{left:u,top:g}=d;e.forEach(h=>{const{unitId:m,subComponentId:f,floatingObjectId:_,floatingObject:S}=h,{left:M=0,top:R=0,width:b=0,height:T=0,angle:$,flipX:N,flipY:ie,skewX:se,skewY:ae}=S,D=this._pageMarginCache.get(_),w=(D==null?void 0:D.marginLeft)||0,P=(D==null?void 0:D.marginTop)||0;r==null||r.getViewModel().getDataModel().updateDrawing(_,{left:M-u-w,top:R-g-P,height:T,width:b})}),r==null||r.calculate(),a==null||a.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:n}=e,r=this._renderManagerService.getRenderById(n);if(r==null)return;const{mainComponent:s}=r;s.changeSkeleton(t),this._refreshFloatingObject(n,t,r)})}_commandExecutedListener(){const e=[C.id,L.id],t=[o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var r;if(e.includes(n.id)){const s=n.params,{unitId:a}=s,c=this._docSkeletonManagerService.getCurrent();if(c==null)return;const{unitId:l,skeleton:d}=c;if(a!==l)return;const u=this._renderManagerService.getRenderById(l);if(u==null)return;if(t.includes(l)){(r=u.mainComponent)==null||r.makeDirty();return}this._refreshFloatingObject(l,d,u)}}))}_refreshFloatingObject(e,t,n){const r=t==null?void 0:t.getSkeletonData(),{mainComponent:s,scene:a}=n,c=s;if(!r)return;const{left:l,top:d,pageLayoutType:u,pageMarginLeft:g,pageMarginTop:h}=c,{pages:m}=r,f=[];a.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let _=0,S=m.length;_<S;_++){const M=m[_],{skeDrawings:R,marginLeft:b,marginTop:T}=M;this._liquid.translatePagePadding(M),R.forEach($=>{const{aLeft:N,aTop:ie,height:se,width:ae,objectId:D}=$;f.push({unitId:e,subComponentId:o.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:D,floatingObject:{left:N+l+this._liquid.x,top:ie+d+this._liquid.y,width:ae,height:se}}),this._pageMarginCache.set(D,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(M,u,g,h)}this._floatingObjectManagerService.BatchAddOrUpdate(f)}};Ce=Ht([o.OnLifecycle(o.LifecycleStages.Steady,Ce),ne(0,y.Inject(p.DocSkeletonManagerService)),ne(1,o.IUniverInstanceService),ne(2,I.IRenderManagerService),ne(3,o.ICommandService),ne(4,o.IFloatingObjectManagerService)],Ce);var Kt=Object.defineProperty,Yt=Object.getOwnPropertyDescriptor,Xt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Yt(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&Kt(e,t,r),r},A=(i,e)=>(t,n)=>e(t,n,i);let Me=class extends o.Disposable{constructor(e,t,n,r,s,a,c){super();v(this,"_previousIMEContent","");v(this,"_previousIMERange");v(this,"_onStartSubscription");v(this,"_onUpdateSubscription");v(this,"_onEndSubscription");this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._textSelectionRenderManager=r,this._textSelectionManagerService=s,this._imeInputManagerService=a,this._commandService=c,this._initialize()}dispose(){var e,t,n;(e=this._onStartSubscription)==null||e.unsubscribe(),(t=this._onUpdateSubscription)==null||t.unsubscribe(),(n=this._onEndSubscription)==null||n.unsubscribe()}_initialize(){this._initialOnCompositionstart(),this._initialOnCompositionUpdate(),this._initialOnCompositionend()}_initialOnCompositionstart(){this._onStartSubscription=this._textSelectionRenderManager.onCompositionstart$.subscribe(e=>{if(e==null)return;const{activeRange:t}=e;t!=null&&(this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(o.Tools.deepClone(t)),this._previousIMERange=t)})}_initialOnCompositionUpdate(){this._onUpdateSubscription=this._textSelectionRenderManager.onCompositionupdate$.subscribe(async e=>{this._updateContent(e,!0)})}_initialOnCompositionend(){this._onEndSubscription=this._textSelectionRenderManager.onCompositionend$.subscribe(e=>{this._updateContent(e,!1)})}async _updateContent(e,t){var f;const n=(f=this._docSkeletonManagerService.getCurrent())==null?void 0:f.skeleton;if(this._previousIMERange==null||e==null||n==null)return;const r=this._currentUniverService.getCurrentUniverDocInstance(),{event:s,activeRange:a}=e,{startOffset:c,segmentId:l,style:d}=this._previousIMERange;if(n==null||a==null)return;const g=s.data;if(g===this._previousIMEContent&&t)return;const h=g.length,m=[{startOffset:c+h,endOffset:c+h,collapsed:!0,style:d}];await this._commandService.executeCommand(je.id,{unitId:r.getUnitId(),newText:g,oldTextLen:this._previousIMEContent.length,range:this._previousIMERange,textRanges:m,isCompositionEnd:!t,segmentId:l}),n.calculate(),t?(this._previousIMERange.collapsed||(this._previousIMERange.collapsed=!0),this._previousIMEContent=g):this._resetIME()}_resetIME(){this._previousIMEContent="",this._previousIMERange=null,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}_getDocObject(){return B(this._currentUniverService,this._renderManagerService)}};Me=Xt([o.OnLifecycle(o.LifecycleStages.Rendered,Me),A(0,y.Inject(p.DocSkeletonManagerService)),A(1,o.IUniverInstanceService),A(2,I.IRenderManagerService),A(3,I.ITextSelectionRenderManager),A(4,y.Inject(x)),A(5,y.Inject(Be)),A(6,o.ICommandService)],Me);var qt=Object.defineProperty,Zt=Object.getOwnPropertyDescriptor,Jt=(i,e,t,n)=>{for(var r=n>1?void 0:n?Zt(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&qt(e,t,r),r},Oe=(i,e)=>(t,n)=>e(t,n,i);let Re=class extends o.Disposable{constructor(i,e,t,n){super(),this._currentUniverService=i,this._textSelectionRenderManager=e,this._textSelectionManagerService=t,this._commandService=n,this._commandExecutedListener()}_commandExecutedListener(){const i=[F.id,Z.id,J.id,Q.id,k.id,V.id,ee.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{i.includes(e.id)&&this._handleInlineFormat(e)}))}_handleInlineFormat(i){const{segmentId:e}=this._textSelectionRenderManager.getActiveRange()??{};e!=null&&this._commandService.executeCommand(Fe.id,{segmentId:e,preCommandId:i.id,...i.params??{}})}};Re=Jt([o.OnLifecycle(o.LifecycleStages.Rendered,Re),Oe(0,o.IUniverInstanceService),Oe(1,I.ITextSelectionRenderManager),Oe(2,y.Inject(x)),Oe(3,o.ICommandService)],Re);var Qt=Object.defineProperty,en=Object.getOwnPropertyDescriptor,tn=(i,e,t,n)=>{for(var r=n>1?void 0:n?en(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&Qt(e,t,r),r},W=(i,e)=>(t,n)=>e(t,n,i);function nn(i){const e=[];for(let t=0,n=i.length;t<n;t++)i[t]===o.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:t});return e}let ye=class extends o.Disposable{constructor(e,t,n,r,s,a){super();v(this,"_onInputSubscription");this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._textSelectionRenderManager=r,this._textSelectionManagerService=s,this._commandService=a,this._initialize(),this._commandExecutedListener()}dispose(){var e;(e=this._onInputSubscription)==null||e.unsubscribe()}_initialize(){}_commandExecutedListener(){const e=[he.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{e.includes(t.id)&&this._handleBreakLine()}))}_handleBreakLine(){var d;const e=(d=this._docSkeletonManagerService.getCurrent())==null?void 0:d.skeleton,t=this._textSelectionRenderManager.getActiveRange();if(t==null||e==null)return;const r=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{startOffset:s,segmentId:a,style:c}=t,l=[{startOffset:s+1,endOffset:s+1,collapsed:!0,style:c}];this._commandService.executeCommand(fe.id,{unitId:r,body:{dataStream:o.DataStreamTreeTokenType.PARAGRAPH,paragraphs:nn(o.DataStreamTreeTokenType.PARAGRAPH)},range:t,textRanges:l,segmentId:a}),e==null||e.calculate()}_getDocObject(){return B(this._currentUniverService,this._renderManagerService)}};ye=tn([o.OnLifecycle(o.LifecycleStages.Rendered,ye),W(0,y.Inject(p.DocSkeletonManagerService)),W(1,o.IUniverInstanceService),W(2,I.IRenderManagerService),W(3,I.ITextSelectionRenderManager),W(4,y.Inject(x)),W(5,o.ICommandService)],ye);var rn=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,an=(i,e,t,n)=>{for(var r=n>1?void 0:n?sn(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&rn(e,t,r),r},G=(i,e)=>(t,n)=>e(t,n,i);let De=class extends o.Disposable{constructor(e,t,n,r,s,a){super();v(this,"_onInputSubscription");this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._textSelectionRenderManager=r,this._textSelectionManagerService=s,this._commandService=a,this._initialize(),this._commandExecutedListener()}dispose(){var e;(e=this._onInputSubscription)==null||e.unsubscribe()}_initialize(){}_commandExecutedListener(){const e=[U.id,E.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(!e.includes(t.id))return;const n=t.params;switch(t.id){case U.id:return this._handleMoveCursor(n.direction);case E.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(e){var _;const t=this._textSelectionRenderManager.getActiveRange(),n=this._textSelectionRenderManager.getAllTextRanges(),r=this._currentUniverService.getCurrentUniverDocInstance(),s=(_=this._docSkeletonManagerService.getCurrent())==null?void 0:_.skeleton,a=this._getDocObject();if(t==null||s==null||a==null)return;const{startOffset:c,endOffset:l,style:d,collapsed:u,direction:g}=t;if(n.length>1){let S=1/0,M=-1/0;for(const R of n)S=Math.min(S,R.startOffset),M=Math.max(M,R.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:e===o.Direction.LEFT||e===o.Direction.UP?M:S,endOffset:e===o.Direction.LEFT||e===o.Direction.UP?S:M,collapsed:!1,style:d}]);return}const h=u||g===I.RANGE_DIRECTION.FORWARD?c:l;let m=u||g===I.RANGE_DIRECTION.FORWARD?l:c;const f=r.getBody().dataStream.length??1/0;if(e===o.Direction.LEFT||e===o.Direction.RIGHT){const S=s.findNodeByCharIndex(m-1),M=s.findNodeByCharIndex(m);m=e===o.Direction.RIGHT?m+M.count:m-S.count,m=Math.min(f-2,Math.max(0,m)),this._textSelectionManagerService.replaceTextRanges([{startOffset:h,endOffset:m,collapsed:h===m,style:d}])}else{const S=s.findNodeByCharIndex(m),M=a.document.getOffsetConfig(),R=this._getTopOrBottomPosition(s,S,e===o.Direction.DOWN);if(R==null){const T=e===o.Direction.UP?0:f-2;if(T===m)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:h,endOffset:T,collapsed:h===T,style:d}]);return}const b=new I.NodePositionConvertToCursor(M,s).getRangePointData(R,R).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:h,endOffset:b.endOffset,collapsed:h===b.endOffset,style:d}])}}_handleMoveCursor(e){var h;const t=this._textSelectionRenderManager.getActiveRange(),n=this._textSelectionRenderManager.getAllTextRanges(),r=this._currentUniverService.getCurrentUniverDocInstance(),s=(h=this._docSkeletonManagerService.getCurrent())==null?void 0:h.skeleton,a=this._getDocObject();if(t==null||s==null||a==null)return;const{startOffset:c,endOffset:l,style:d,collapsed:u}=t,g=r.getBody().dataStream.length??1/0;if(e===o.Direction.LEFT||e===o.Direction.RIGHT){let m;if(!t.collapsed||n.length>1){let f=1/0,_=-1/0;for(const S of n)f=Math.min(f,S.startOffset),_=Math.max(_,S.endOffset);m=e===o.Direction.LEFT?f:_}else{const f=s.findNodeByCharIndex(c-1),_=s.findNodeByCharIndex(c);e===o.Direction.LEFT?m=Math.max(0,c-f.count):m=Math.min(g-2,l+_.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:m,endOffset:m,collapsed:!0,style:d}])}else{const m=s.findNodeByCharIndex(c),f=s.findNodeByCharIndex(l),_=a.document.getOffsetConfig(),S=this._getTopOrBottomPosition(s,e===o.Direction.UP?m:f,e===o.Direction.DOWN);if(S==null){let R;u?R=e===o.Direction.UP?0:g-2:R=e===o.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:R,endOffset:R,collapsed:!0,style:d}]);return}const M=new I.NodePositionConvertToCursor(_,s).getRangePointData(S,S).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...M,style:d}])}}_getTopOrBottomPosition(e,t,n){if(t==null)return;const r=this._getSpanLeftOffsetInLine(t),s=this._getNextOrPrevLine(t,n);if(s==null)return;const a=this._matchPositionByLeftOffset(e,s,r);if(a!=null)return{...a,isBack:!0}}_getSpanLeftOffsetInLine(e){const t=e.parent;if(t==null)return-1/0;const n=t.left,{left:r}=e;return n+r}_matchPositionByLeftOffset(e,t,n){const r={distance:1/0};for(const s of t.divides){const a=s.left;for(const c of s.spanGroup){const{left:l}=c,d=a+l,u=Math.abs(n-d);u<r.distance&&(r.span=c,r.distance=u)}}if(r.span!=null)return e.findPositionBySpan(r.span)}_getNextOrPrevLine(e,t){var f,_,S,M,R,b,T,$,N,ie,se,ae;const n=e.parent;if(n==null)return;const r=n.parent;if(r==null)return;const s=r.parent;if(s==null)return;const a=s.lines.indexOf(r);if(a===-1)return;let c;if(t===!0?c=s.lines[a+1]:c=s.lines[a-1],c!=null)return c;const l=s.parent;if(l==null)return;const d=l.columns.indexOf(s);if(d===-1)return;if(t===!0)c=(f=l.columns[d+1])==null?void 0:f.lines[0];else{const D=(S=(_=l.columns)==null?void 0:_[d-1])==null?void 0:S.lines;c=D==null?void 0:D[D.length-1]}if(c!=null)return c;const u=l.parent;if(u==null)return;const g=u.sections.indexOf(l);if(g===-1)return;if(t===!0)c=(R=(M=u.sections[g-1])==null?void 0:M.columns[0])==null?void 0:R.lines[0];else{const D=(T=(b=u.sections)==null?void 0:b[g-1])==null?void 0:T.columns,w=D==null?void 0:D[D.length-1],P=w==null?void 0:w.lines;c=P==null?void 0:P[P.length-1]}if(c!=null)return c;const h=u.parent;if(h==null)return;const m=h.pages.indexOf(u);if(m!==-1){if(t===!0)c=(ie=(N=($=h.pages[m+1])==null?void 0:$.sections[0])==null?void 0:N.columns[0])==null?void 0:ie.lines[0];else{const D=(se=h.pages[m-1])==null?void 0:se.sections;if(D==null)return;const w=(ae=D[D.length-1])==null?void 0:ae.columns,P=w[w.length-1],ct=P==null?void 0:P.lines;c=ct[ct.length-1]}if(c!=null)return c}}_getDocObject(){return B(this._currentUniverService,this._renderManagerService)}};De=an([o.OnLifecycle(o.LifecycleStages.Rendered,De),G(0,y.Inject(p.DocSkeletonManagerService)),G(1,o.IUniverInstanceService),G(2,I.IRenderManagerService),G(3,I.ITextSelectionRenderManager),G(4,y.Inject(x)),G(5,o.ICommandService)],De);var on=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,ln=(i,e,t,n)=>{for(var r=n>1?void 0:n?cn(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&on(e,t,r),r},H=(i,e)=>(t,n)=>e(t,n,i);let be=class extends o.Disposable{constructor(e,t,n,r,s,a){super();v(this,"_onInputSubscription");this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._textSelectionRenderManager=r,this._textSelectionManagerService=s,this._commandService=a,this._initialize(),this._commandExecutedListener()}dispose(){var e;(e=this._onInputSubscription)==null||e.unsubscribe()}_initialize(){this._initialNormalInput()}_initialNormalInput(){this._onInputSubscription=this._textSelectionRenderManager.onInput$.subscribe(async e=>{var m;if(e==null)return;const t=this._currentUniverService.getCurrentUniverDocInstance(),{event:n,content:r="",activeRange:s}=e,a=n,c=(m=this._docSkeletonManagerService.getCurrent())==null?void 0:m.skeleton;if(a.data==null||c==null||!c||!s)return;const{startOffset:l,segmentId:d,style:u}=s,g=r.length,h=[{startOffset:l+g,endOffset:l+g,collapsed:!0,style:u}];await this._commandService.executeCommand(fe.id,{unitId:t.getUnitId(),body:{dataStream:r},range:s,textRanges:h,segmentId:d}),c.calculate()})}_commandExecutedListener(){}_getDocObject(){return B(this._currentUniverService,this._renderManagerService)}};be=ln([o.OnLifecycle(o.LifecycleStages.Rendered,be),H(0,y.Inject(p.DocSkeletonManagerService)),H(1,o.IUniverInstanceService),H(2,I.IRenderManagerService),H(3,I.ITextSelectionRenderManager),H(4,y.Inject(x)),H(5,o.ICommandService)],be);var dn=Object.defineProperty,un=Object.getOwnPropertyDescriptor,mn=(i,e,t,n)=>{for(var r=n>1?void 0:n?un(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&dn(e,t,r),r},hn=(i,e)=>(t,n)=>e(t,n,i);const fn="rgba(198,198,198, 1)",gn="rgba(255,255,255, 1)";let xe=class extends o.Disposable{constructor(i){super(),this._renderManagerService=i,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this._renderManagerService.currentRender$.subscribe(i=>{var s;if(i==null)return;const e=this._renderManagerService.getRenderById(i);if(e==null)return;const{mainComponent:t}=e,n=t,r=(s=n.getSkeleton())==null?void 0:s.getPageSize();n.onPageRenderObservable.add(a=>{if([o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(i))return;const{page:c,pageLeft:l,pageTop:d,ctx:u}=a,{width:g,height:h}=c;u.save(),u.translate(l-.5,d-.5),I.Rect.drawWith(u,{width:(r==null?void 0:r.width)||g,height:(r==null?void 0:r.height)||h,strokeWidth:1,stroke:fn,fill:gn,zIndex:3}),u.restore()})})}_commandExecutedListener(){}};xe=mn([o.OnLifecycle(o.LifecycleStages.Rendered,xe),hn(0,I.IRenderManagerService)],xe);var _n=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,Sn=(i,e,t,n)=>{for(var r=n>1?void 0:n?pn(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&_n(e,t,r),r},K=(i,e)=>(t,n)=>e(t,n,i);let Te=class extends o.Disposable{constructor(e,t,n,r,s,a){super();v(this,"_moveInObserver");v(this,"_moveOutObserver");v(this,"_downObserver");v(this,"_dblClickObserver");v(this,"_tripleClickObserver");v(this,"_loadedMap",new Set);this._docSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionRenderManager=s,this._textSelectionManagerService=a,this._renderManagerService.currentRender$.subscribe(c=>{c!=null&&this._currentUniverService.getUniverDocInstance(c)!=null&&(this._loadedMap.has(c)||(this._initialMain(c),this._loadedMap.add(c)))}),this._initialize()}dispose(){this._renderManagerService.getRenderAll().forEach(e=>{const{mainComponent:t}=e;t!=null&&(t.onPointerEnterObserver.remove(this._moveInObserver),t.onPointerLeaveObserver.remove(this._moveOutObserver),t.onPointerDownObserver.remove(this._downObserver),t.onDblclickObserver.remove(this._dblClickObserver),t.onTripleClickObserver.remove(this._tripleClickObserver))})}_initialize(){this._onChangeListener(),this._skeletonListener(),this._userActionSyncListener(),this._commandExecutedListener()}_initialMain(e){const t=this._getDocObjectById(e);if(t==null)return;const{document:n,scene:r}=t,s=r.getViewport(j.VIEW_MAIN);this._moveInObserver=n.onPointerEnterObserver.add(()=>{n.cursor=I.CURSOR_TYPE.TEXT}),this._moveOutObserver=n.onPointerLeaveObserver.add(()=>{n.cursor=I.CURSOR_TYPE.DEFAULT,r.resetCursor()}),this._downObserver=n==null?void 0:n.onPointerDownObserver.add((a,c)=>{this._currentUniverService.getCurrentUniverDocInstance().getUnitId()!==e&&this._currentUniverService.setCurrentUniverDocInstance(e),this._textSelectionRenderManager.eventTrigger(a,n.getOffsetConfig(),s),a.button!==2&&c.stopPropagation()}),this._dblClickObserver=n==null?void 0:n.onDblclickObserver.add(a=>{this._textSelectionRenderManager.handleDblClick(a,n.getOffsetConfig(),s)}),this._tripleClickObserver=n==null?void 0:n.onTripleClickObserver.add(a=>{this._textSelectionRenderManager.handleTripleClick(a,n.getOffsetConfig(),s)})}_onChangeListener(){this._textSelectionManagerService.textSelectionInfo$.subscribe(e=>{var c,l;const t=(c=this._textSelectionManagerService.getCurrentSelection())==null?void 0:c.unitId;if(this._textSelectionRenderManager.removeAllTextRanges(),e==null||t==null)return;const n=(l=this._docSkeletonManagerService.getCurrent())==null?void 0:l.skeleton,r=this._getDocObjectById(t);if(r==null||n==null)return;const{scene:s,document:a}=r;this._textSelectionRenderManager.addTextRanges(e,{scene:s,skeleton:n,documentOffsetConfig:a.getOffsetConfig()})})}_userActionSyncListener(){this._textSelectionRenderManager.textSelection$.subscribe(e=>{const t=this._docSkeletonManagerService.getCurrent();if(t==null)return;const{unitId:n}=t;this._commandService.executeCommand(ke.id,{unitId:n,pluginName:Y,ranges:e})})}_getDocObjectById(e){return lt(e,this._renderManagerService)}_commandExecutedListener(){const e=[L.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const r=t.params,{unitId:s}=r,a=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(s!==a)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t,skeleton:n}=e,r=this._renderManagerService.getRenderById(t);if(r==null)return;const{scene:s,mainComponent:a}=r,c=s.getViewport(j.VIEW_MAIN);this._textSelectionRenderManager.changeRuntime(n,s,c,a.getOffsetConfig()),this._textSelectionManagerService.setCurrentSelectionNotRefresh({pluginName:Y,unitId:t})})}};Te=Sn([o.OnLifecycle(o.LifecycleStages.Rendered,Te),K(0,y.Inject(p.DocSkeletonManagerService)),K(1,o.IUniverInstanceService),K(2,o.ICommandService),K(3,I.IRenderManagerService),K(4,I.ITextSelectionRenderManager),K(5,y.Inject(x))],Te);var vn=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Cn=(i,e,t,n)=>{for(var r=n>1?void 0:n?In(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&vn(e,t,r),r},re=(i,e)=>(t,n)=>e(t,n,i);let Pe=class extends o.Disposable{constructor(e,t,n,r,s){super();v(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=r,this._textSelectionManagerService=s,this._initialize()}dispose(){super.dispose()}_initialize(){this._skeletonListener(),this._commandExecutedListener(),this._initialRenderRefresh()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t}=e,n=this._renderManagerService.getRenderById(t);if(n==null||this._initializedRender.has(t)||[o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(t))return;this._initializedRender.add(t);const{scene:r}=n;this.disposeWithMe(o.toDisposable(r.onMouseWheelObserver.add(s=>{if(!s.ctrlKey)return;const a=Math.abs(s.deltaX);let c=a<40?.2:a<80?.4:.2;c*=s.deltaY>0?-1:1,r.scaleX<1&&(c/=2);const l=this._currentUniverService.getCurrentUniverDocInstance(),d=l.zoomRatio;let u=+parseFloat(`${d+c}`).toFixed(1);u=u>=4?4:u<=.1?.1:u,this._commandService.executeCommand(Qe.id,{zoomRatio:u,workbookId:l.getUnitId()}),s.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(o.toDisposable(this._docSkeletonManagerService.currentSkeletonBefore$.subscribe(e=>{if(e==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const e=[L.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._currentUniverService.getCurrentUniverDocInstance(),r=t.params,{unitId:s}=r;if(s!==n.getUnitId())return;const a=n.zoomRatio||1;this._updateViewZoom(a)}}))}_updateViewZoom(e,t=!0){var r;const n=this._getDocObject();n!=null&&(n.scene.scale(e,e),this._calculatePagePosition(n,e),t&&this._textSelectionManagerService.refreshSelection(),(r=n.scene.getTransformer())==null||r.hideControl())}_calculatePagePosition(e,t){const{document:n,scene:r}=e,s=r==null?void 0:r.getParent(),{width:a,height:c,pageMarginLeft:l,pageMarginTop:d}=n;if(s==null||a===1/0||c===1/0)return;const{width:u,height:g}=s;let h=0,m=0,f=0,_=0,S=1/0;u>(a+l*2)*t?(h=u/2-a*t/2,h/=t,f=(u-l*2)/t,S=0):(h=l,f=a+l*2,S=(f-u/t)/2),g>c?(m=g/2-c/2,_=(g-d*2)/t):(m=d,_=c+d*2),r.resize(f,_+200),n.translate(h,m);const M=r.getViewport(j.VIEW_MAIN);if(S!==1/0&&M!=null){const R=M.getBarScroll(S,0).x;M.scrollTo({x:R})}return this}_getDocObject(){return B(this._currentUniverService,this._renderManagerService)}};Pe=Cn([o.OnLifecycle(o.LifecycleStages.Rendered,Pe),re(0,y.Inject(p.DocSkeletonManagerService)),re(1,o.IUniverInstanceService),re(2,o.ICommandService),re(3,I.IRenderManagerService),re(4,y.Inject(x))],Pe);const Mn={id:he.id,preconditions:i=>i.getContextValue(o.FOCUSING_DOC),binding:O.KeyCode.ENTER},On={id:q.id,preconditions:i=>i.getContextValue(o.FOCUSING_DOC),binding:O.KeyCode.BACKSPACE},Rn={id:me.id,preconditions:i=>i.getContextValue(o.FOCUSING_DOC),binding:O.KeyCode.DELETE},yn={id:U.id,binding:O.KeyCode.ARROW_UP,preconditions:i=>i.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.UP}},Dn={id:U.id,binding:O.KeyCode.ARROW_DOWN,preconditions:i=>i.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.DOWN}},bn={id:U.id,binding:O.KeyCode.ARROW_LEFT,preconditions:i=>i.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.LEFT}},xn={id:U.id,binding:O.KeyCode.ARROW_RIGHT,preconditions:i=>i.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.RIGHT}},Tn={id:E.id,binding:O.KeyCode.ARROW_UP|O.MetaKeys.SHIFT,preconditions:i=>i.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.UP}},Pn={id:E.id,binding:O.KeyCode.ARROW_DOWN|O.MetaKeys.SHIFT,preconditions:i=>i.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.DOWN}},Un={id:E.id,binding:O.KeyCode.ARROW_LEFT|O.MetaKeys.SHIFT,preconditions:i=>i.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.LEFT}},En={id:E.id,binding:O.KeyCode.ARROW_RIGHT|O.MetaKeys.SHIFT,preconditions:i=>i.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.RIGHT}},Nn={id:et.id,binding:O.KeyCode.A|O.MetaKeys.CTRL_COMMAND,preconditions:i=>i.getContextValue(o.FOCUSING_DOC)||i.getContextValue(o.FOCUSING_EDITOR)};var wn=Object.defineProperty,Ln=Object.getOwnPropertyDescriptor,An=(i,e,t,n)=>{for(var r=n>1?void 0:n?Ln(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&wn(e,t,r),r},Ue=(i,e)=>(t,n)=>e(t,n,i);let Ee=class{constructor(i,e,t,n){v(this,"_scene");v(this,"_currentDocumentModel");v(this,"_loadedMap",new Set);this._renderManagerService=i,this._configService=e,this._currentUniverService=t,this._docViewModelManagerService=n,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.subscribe(i=>{if(i==null)return;this._currentDocumentModel=i;const e=i.getUnitId();this._docViewModelManagerService.setCurrent(e),this._loadedMap.has(e)||(this._addNewRender(),this._loadedMap.add(e))})}_addNewRender(){const i=this._currentDocumentModel,e=i.getUnitId(),t=i.getContainer(),n=i.getParentRenderUnitId();if(t!=null&&n!=null)throw new Error("container or parentRenderUnitId can only exist one");t==null&&n!=null?this._renderManagerService.createRenderWithParent(e,n):this._renderManagerService.createRender(e);const r=this._renderManagerService.getRenderById(e);if(r==null)return;const{scene:s,engine:a}=r;s.openTransformer(),this._scene=s;const c=new I.Viewport(j.VIEW_MAIN,s,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});s.addViewport(c).attachControl(),s.on(I.EVENT_TYPE.wheel,(u,g)=>{const h=u;if(h.ctrlKey){const m=Math.abs(h.deltaX);let f=m<40?.2:m<80?.4:.2;f*=h.deltaY>0?-1:1,s.scaleX<1&&(f/=2),s.scaleX+f>4?s.scale(4,4):s.scaleX+f<.1?s.scale(.1,.1):h.preventDefault()}else c.onMouseWheel(h,g)}),this._configService.getConfig("hasScroll")!==!1&&e!==o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&new I.ScrollBar(c),s.addLayer(I.Layer.create(s,[],Le),I.Layer.create(s,[],Ye)),this._addComponent(r),this._currentDocumentModel.getShouldRenderLoopImmediately()&&a.runRenderLoop(()=>{s.render()}),this._renderManagerService.setCurrent(e)}_addComponent(i){const e=this._scene,t=this._currentDocumentModel,n=new I.Documents(ce.MAIN,void 0,{pageMarginLeft:t.documentStyle.marginLeft||0,pageMarginTop:t.documentStyle.marginTop||0});n.zIndex=Xe,i.mainComponent=n,i.components.set(ce.MAIN,n),e.addObjects([n],Le)}};Ee=An([o.OnLifecycle(o.LifecycleStages.Ready,Ee),Ue(0,I.IRenderManagerService),Ue(1,o.IConfigService),Ue(2,o.IUniverInstanceService),Ue(3,y.Inject(p.DocViewModelManagerService))],Ee);var $n=Object.defineProperty,Bn=Object.getOwnPropertyDescriptor,jn=(i,e,t,n)=>{for(var r=n>1?void 0:n?Bn(e,t):e,s=i.length-1,a;s>=0;s--)(a=i[s])&&(r=(n?a(e,t,r):a(r))||r);return n&&r&&$n(e,t,r),r},Ne=(i,e)=>(t,n)=>e(t,n,i);const Fn={hasScroll:!0},kn="docs";p.UniverDocsPlugin=(He=class extends o.Plugin{constructor(t={},n,r,s,a){super(kn);v(this,"_config");this._injector=n,this._localeService=r,this._configService=s,this._currentUniverService=a,this._config=Object.assign(Fn,t),this._initializeDependencies(n),this._initializeCommands()}initialize(){}_initializeCommands(){[U,E,q,me,F,Z,J,Q,k,V,ee,Fe,he,fe,ge,$e,je,C,qe,Ze,Qe,L,ke,et].forEach(t=>{this._injector.get(o.ICommandService).registerCommand(t)}),[yn,Dn,xn,bn,Tn,Pn,Un,En,Nn,On,Rn,Mn].forEach(t=>{this._injector.get(O.IShortcutService).registerShortcut(t)})}onReady(){this.initialize()}_initializeDependencies(t){[[Ee],[p.DocSkeletonManagerService],[p.DocViewModelManagerService],[Be],[at,{useClass:We}],[I.ITextSelectionRenderManager,{useClass:I.TextSelectionRenderManager}],[x],[Ie],[xe],[Te],[be],[Me],[ve],[Re],[pe],[ye],[De],[Pe],[Ce]].forEach(n=>t.add(n))}},v(He,"type",o.PluginType.Doc),He),p.UniverDocsPlugin=jn([Ne(1,y.Inject(y.Injector)),Ne(2,y.Inject(o.LocaleService)),Ne(3,o.IConfigService),Ne(4,o.IUniverInstanceService)],p.UniverDocsPlugin),p.BreakLineCommand=he,p.CoverContentCommand=Ze,p.DOCS_COMPONENT_DEFAULT_Z_INDEX=Xe,p.DOCS_COMPONENT_HEADER_LAYER_INDEX=Ye,p.DOCS_COMPONENT_MAIN_LAYER_INDEX=Le,p.DOCS_VIEW_KEY=ce,p.DeleteCommand=ge,p.DeleteLeftCommand=q,p.DocCopyCommand=le,p.DocCutCommand=de,p.DocPasteCommand=ue,p.IMEInputCommand=je,p.InsertCommand=fe,p.MoveCursorOperation=U,p.MoveSelectionOperation=E,p.NORMAL_TEXT_SELECTION_PLUGIN_NAME=Y,p.ReplaceContentCommand=qe,p.RichTextEditingMutation=C,p.SetInlineFormatBoldCommand=F,p.SetInlineFormatCommand=Fe,p.SetInlineFormatFontFamilyCommand=V,p.SetInlineFormatFontSizeCommand=k,p.SetInlineFormatItalicCommand=Z,p.SetInlineFormatStrikethroughCommand=Q,p.SetInlineFormatTextColorCommand=ee,p.SetInlineFormatUnderlineCommand=J,p.SetTextSelectionsOperation=ke,p.TextSelectionManagerService=x,p.UpdateCommand=$e,p.VIEWPORT_KEY=j,p.getDocObject=B,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(h,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("@univerjs/core"),require("@univerjs/engine-render"),require("rxjs"),require("@univerjs/ui"),require("@wendellhu/redi")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/engine-render","rxjs","@univerjs/ui","@wendellhu/redi"],o):(h=typeof globalThis<"u"?globalThis:h||self,o(h.UniverDocs={},h.UniverCore,h.UniverEngineRender,h.rxjs,h.UniverUi,h["@wendellhu/redi"]))})(this,function(h,o,M,z,T,b){"use strict";var Wn=Object.defineProperty;var Gn=(h,o,M)=>o in h?Wn(h,o,{enumerable:!0,configurable:!0,writable:!0,value:M}):h[o]=M;var C=(h,o,M)=>(Gn(h,typeof o!="symbol"?o+"":o,M),M);var ke;function q(r,t){const n=r.getCurrentUniverDocInstance().getUnitId(),i=t.getRenderById(n);if(i==null)return;const{mainComponent:s,scene:a,engine:c}=i;return{document:s,scene:a,engine:c}}function mt(r,t){const e=t.getRenderById(r);if(e==null)return;const{components:n,mainComponent:i,scene:s,engine:a}=e;return{document:i,scene:s,engine:a}}var ae=(r=>(r.MAIN="__Document_Render_Main__",r))(ae||{}),W=(r=>(r.VIEW_MAIN="viewMain",r.VIEW_TOP="viewTop",r.VIEW_LEFT="viewLeft",r.VIEW_LEFT_TOP="viewLeftTop",r))(W||{});const oe=0,ze=2,We=10,gt="normalTextSelectionPluginName",be={id:"doc.operation.set-selections",type:o.CommandType.OPERATION,handler:(r,t)=>!0};var ft=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,pt=(r,t,e,n)=>{for(var i=n>1?void 0:n?ht(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&ft(t,e,i),i},Ge=(r,t)=>(e,n)=>t(e,n,r);function He(r){const{startOffset:t,endOffset:e,collapsed:n}=r;return{startOffset:t,endOffset:e,collapsed:n}}h.TextSelectionManagerService=class extends o.RxDisposable{constructor(e,n){super();C(this,"_currentSelection",null);C(this,"_textSelectionInfo",new Map);C(this,"_textSelection$",new z.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:i,style:s}=e,a=n.find(m=>m.isActive());if(a==null)return null;const{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:g,direction:f}=a;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:g,direction:f,segmentId:i,style:s}}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(z.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:i,subUnitId:s,segmentId:a,style:c,textRanges:l}=n;this._commandService.executeCommand(be.id,{unitId:i,subUnitId:s,segmentId:a,style:c,ranges:l.map(He)})}_getTextRanges(e){var s;if(e==null)return;const{unitId:n,subUnitId:i=""}=e;return(s=this._textSelectionInfo.get(n))==null?void 0:s.get(i)}_refresh(e){const n=this._getTextRanges(e);this._textSelectionRenderManager.removeAllTextRanges(),n&&Array.isArray(n.textRanges)&&n.textRanges.length&&this._textSelectionRenderManager.addTextRanges(n.textRanges.map(He))}_replaceByParam(e){const{unitId:n,subUnitId:i,style:s,segmentId:a,textRanges:c}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map),this._textSelectionInfo.get(n).set(i,{textRanges:c,style:s,segmentId:a})}_addByParam(e){const{unitId:n,subUnitId:i,textRanges:s,style:a,segmentId:c}=e;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map);const l=this._textSelectionInfo.get(n);l.has(i)?l.get(i).textRanges.push(...s):l.set(i,{textRanges:s,style:a,segmentId:c})}},h.TextSelectionManagerService=pt([Ge(0,M.ITextSelectionRenderManager),Ge(1,o.ICommandService)],h.TextSelectionManagerService);function ce(r,t="",e=0){const{startOffset:n,endOffset:i}=r,s=[],a=n-e,c=i-e;return a>0&&s.push({t:"r",len:a,segmentId:t}),s.push({t:"d",len:c-a,line:0,segmentId:t}),s}var St=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,vt=(r,t,e,n)=>{for(var i=n>1?void 0:n?_t(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&St(t,e,i),i},Ct=(r,t)=>(e,n)=>t(e,n,r);h.DocViewModelManagerService=class{constructor(t){C(this,"_currentViewModelUnitId","");C(this,"_docViewModelMap",new Map);C(this,"_currentDocViewModel$",new z.BehaviorSubject(null));C(this,"currentDocViewModel$",this._currentDocViewModel$.asObservable());this._currentUniverService=t}dispose(){this._currentDocViewModel$.complete(),this._docViewModelMap=new Map}getCurrent(){return this._docViewModelMap.get(this._currentViewModelUnitId)}getViewModel(t){var e;return(e=this._docViewModelMap.get(t))==null?void 0:e.docViewModel}setCurrent(t){var n;const e=this._currentUniverService.getUniverDocInstance(t);if(e==null)throw new Error(`Document data model with id ${t} not found when build view model.`);if(e.getBody()!=null){if(!this._docViewModelMap.has(t)){const i=this._buildDocViewModel(e);this._docViewModelMap.set(t,{unitId:t,docViewModel:i})}if(t===o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const i=(n=this._docViewModelMap.get(t))==null?void 0:n.docViewModel;if(i==null)return;i.reset(e)}this._currentViewModelUnitId=t,this._currentDocViewModel$.next(this.getCurrent())}}_buildDocViewModel(t){return new M.DocumentViewModel(t)}},h.DocViewModelManagerService=vt([Ct(0,o.IUniverInstanceService)],h.DocViewModelManagerService);const v={id:"doc.mutation.rich-text-editing",type:o.CommandType.MUTATION,handler:(r,t)=>{const{unitId:e,mutations:n}=t,s=r.get(o.IUniverInstanceService).getUniverDocInstance(e),c=r.get(h.DocViewModelManagerService).getViewModel(e);if(s==null||c==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${e}`);const l=s.apply(n),u=n[0].segmentId,d=s.getSelfOrHeaderFooterModel(u);return c.getSelfOrHeaderFooterViewModel(u).reset(d),{unitId:e,mutations:l}}},le={id:"doc.command.insert-text",type:o.CommandType.COMMAND,handler:async(r,t)=>{const e=r.get(o.IUndoRedoService),n=r.get(o.ICommandService),i=r.get(h.TextSelectionManagerService),{range:s,segmentId:a,body:c,unitId:l,textRanges:u}=t,{startOffset:d,collapsed:g}=s,f={id:v.id,params:{unitId:l,mutations:[]}};g?f.params.mutations.push({t:"r",len:d,segmentId:a}):f.params.mutations.push(...ce(s,a)),f.params.mutations.push({t:"i",body:c,len:c.dataStream.length,line:0,segmentId:a});const m=n.syncExecuteCommand(f.id,f.params);return i.replaceTextRanges(u),m?(e.pushUndoRedo({unitID:l,undoMutations:[{id:v.id,params:m}],redoMutations:[{id:v.id,params:f.params}],undo(){return n.syncExecuteCommand(v.id,m),i.replaceTextRanges([s]),!0},redo(){return n.syncExecuteCommand(v.id,f.params),i.replaceTextRanges(u),!0}}),!0):!1}};var L=(r=>(r[r.LEFT=0]="LEFT",r[r.RIGHT=1]="RIGHT",r))(L||{});const de={id:"doc.command.delete-text",type:o.CommandType.COMMAND,handler:async(r,t)=>{const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(h.TextSelectionManagerService),{range:s,segmentId:a,unitId:c,direction:l,textRanges:u,len:d=1}=t,{startOffset:g}=s,f={id:v.id,params:{unitId:c,mutations:[]}};g>0&&f.params.mutations.push({t:"r",len:l===0?g-d:g,segmentId:a}),f.params.mutations.push({t:"d",len:d,line:0,segmentId:a});const m=e.syncExecuteCommand(f.id,f.params);return i.replaceTextRanges(u),m&&n.pushUndoRedo({unitID:c,undoMutations:[{id:v.id,params:m}],redoMutations:[{id:v.id,params:f.params}],undo(){return e.syncExecuteCommand(v.id,m),i.replaceTextRanges([s]),!0},redo(){return e.syncExecuteCommand(v.id,f.params),i.replaceTextRanges(u),!0}}),!1}},xe={id:"doc.command.update-text",type:o.CommandType.COMMAND,handler:async(r,t)=>{const{range:e,segmentId:n,updateBody:i,coverType:s,unitId:a,textRanges:c}=t,l=r.get(o.ICommandService),u=r.get(o.IUndoRedoService),d=r.get(h.TextSelectionManagerService),g={id:v.id,params:{unitId:a,mutations:[]}},{startOffset:f,endOffset:m}=e;g.params.mutations.push({t:"r",len:f,segmentId:n}),g.params.mutations.push({t:"r",body:i,len:m-f,segmentId:n,coverType:s});const p=l.syncExecuteCommand(g.id,g.params);return d.replaceTextRanges(c),p?(u.pushUndoRedo({unitID:a,undoMutations:[{id:v.id,params:p}],redoMutations:[{id:v.id,params:g.params}],undo(){return l.syncExecuteCommand(v.id,p),d.replaceTextRanges(c),!0},redo(){return l.syncExecuteCommand(v.id,g.params),d.replaceTextRanges(c),!0}}),!0):!1}};function It(r,t){const e=[];for(let n=0,i=r.length;n<i;n++)r[n]===o.DataStreamTreeTokenType.PARAGRAPH&&e.push({startIndex:n});if(t)for(const n of e)t.bullet&&(n.bullet=o.Tools.deepClone(t.bullet)),t.paragraphStyle&&(n.paragraphStyle=o.Tools.deepClone(t.paragraphStyle));return e}const Ue={id:"doc.command.break-line",type:o.CommandType.COMMAND,handler:async r=>{var p;const t=r.get(h.TextSelectionManagerService),e=r.get(o.IUniverInstanceService),n=r.get(o.ICommandService),i=t.getActiveRange();if(i==null)return!1;const s=e.getCurrentUniverDocInstance(),a=s.getUnitId(),{startOffset:c,segmentId:l,style:u}=i,d=[{startOffset:c+1,endOffset:c+1,style:u}],f=(((p=s.getBody())==null?void 0:p.paragraphs)??[]).find(S=>S.startIndex>=c);return await n.executeCommand(le.id,{unitId:a,body:{dataStream:o.DataStreamTreeTokenType.PARAGRAPH,paragraphs:It(o.DataStreamTreeTokenType.PARAGRAPH,f)},range:i,textRanges:d,segmentId:l})}},ue={id:T.CopyCommand.id,name:"doc.command.copy",type:o.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(o.FOCUSING_DOC)||r.getContextValue(o.FOCUSING_EDITOR),handler:async()=>!0},me={id:T.CutCommand.id,name:"doc.command.cut",type:o.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(o.FOCUSING_DOC)||r.getContextValue(o.FOCUSING_EDITOR),handler:async()=>!0},ge={id:T.PasteCommand.id,name:"doc.command.paste",type:o.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(o.FOCUSING_DOC)||r.getContextValue(o.FOCUSING_EDITOR),handler:async()=>!0};var Mt=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,Rt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ot(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Mt(t,e,i),i},Ke=(r,t)=>(e,n)=>t(e,n,r);h.DocSkeletonManagerService=class{constructor(t,e){C(this,"_currentSkeletonUnitId","");C(this,"_docSkeletonMap",new Map);C(this,"_currentSkeleton$",new z.BehaviorSubject(null));C(this,"currentSkeleton$",this._currentSkeleton$.asObservable());C(this,"_currentSkeletonBefore$",new z.BehaviorSubject(null));C(this,"currentSkeletonBefore$",this._currentSkeletonBefore$.asObservable());this._localeService=t,this._docViewModelManagerService=e,this.initialize()}initialize(){this._docViewModelManagerService.currentDocViewModel$.subscribe(t=>{t!=null&&this._setCurrent(t)})}dispose(){this._currentSkeletonBefore$.complete(),this._currentSkeleton$.complete(),this._docSkeletonMap=new Map}getCurrent(){return this.getSkeletonByUnitId(this._currentSkeletonUnitId)}makeDirtyCurrent(t=!0){this.makeDirty(this._currentSkeletonUnitId,t)}makeDirty(t,e=!0){const n=this.getSkeletonByUnitId(t);n!=null&&(n.dirty=e)}_setCurrent(t){const{unitId:e}=t;if(this._docSkeletonMap.has(e)){const n=this.getSkeletonByUnitId(e);n.skeleton.calculate(),n.dirty=!0}else{const n=this._buildSkeleton(t.docViewModel);n.calculate(),this._docSkeletonMap.set(e,{unitId:e,skeleton:n,dirty:!1})}return this._currentSkeletonUnitId=e,this._currentSkeletonBefore$.next(this.getCurrent()),this._currentSkeleton$.next(this.getCurrent()),this.getCurrent()}getSkeletonByUnitId(t){return this._docSkeletonMap.get(t)}_buildSkeleton(t){return M.DocumentSkeleton.create(t,this._localeService)}},h.DocSkeletonManagerService=Rt([Ke(0,b.Inject(o.LocaleService)),Ke(1,b.Inject(h.DocViewModelManagerService))],h.DocSkeletonManagerService);const Ye={id:"doc.command.inner-paste",type:o.CommandType.COMMAND,handler:async(r,t)=>{const{segmentId:e,body:n,textRanges:i}=t,s=r.get(o.IUndoRedoService),a=r.get(o.ICommandService),c=r.get(h.TextSelectionManagerService),l=r.get(o.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;const g=l.getCurrentUniverDocInstance().getUnitId(),f={id:v.id,params:{unitId:g,mutations:[]}},m=new o.MemoryCursor;m.reset();for(const S of u){const{startOffset:_,endOffset:I,collapsed:O}=S,x=_-m.cursor;O?f.params.mutations.push({t:"r",len:x,segmentId:e}):f.params.mutations.push(...ce(S,e,m.cursor)),f.params.mutations.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:e}),m.reset(),m.moveCursor(I)}const p=a.syncExecuteCommand(f.id,f.params);return c.replaceTextRanges(i),p?(s.pushUndoRedo({unitID:g,undoMutations:[{id:v.id,params:p}],redoMutations:[{id:v.id,params:f.params}],undo(){return a.syncExecuteCommand(v.id,p),c.replaceTextRanges(u),!0},redo(){return a.syncExecuteCommand(v.id,f.params),c.replaceTextRanges(i),!0}}),!0):!1}},fe={id:"doc.command.inner-cut",type:o.CommandType.COMMAND,handler:async(r,t)=>{const{segmentId:e,textRanges:n}=t,i=r.get(o.IUndoRedoService),s=r.get(o.ICommandService),a=r.get(h.TextSelectionManagerService),c=r.get(o.IUniverInstanceService),l=a.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const u=c.getCurrentUniverDocInstance().getUnitId(),d=c.getUniverDocInstance(u),g=o.getDocsUpdateBody(d.snapshot,e);if(g==null)return!1;const f={id:v.id,params:{unitId:u,mutations:[]}},m=new o.MemoryCursor;m.reset();for(const S of l){const{startOffset:_,endOffset:I,collapsed:O}=S,x=_-m.cursor;O?f.params.mutations.push({t:"r",len:x,segmentId:e}):f.params.mutations.push(...yt(S,g,e,m.cursor)),m.reset(),m.moveCursor(I)}const p=s.syncExecuteCommand(f.id,f.params);return a.replaceTextRanges(n),p?(i.pushUndoRedo({unitID:u,undoMutations:[{id:v.id,params:p}],redoMutations:[{id:v.id,params:f.params}],undo(){return s.syncExecuteCommand(v.id,p),a.replaceTextRanges(l),!0},redo(){return s.syncExecuteCommand(v.id,f.params),a.replaceTextRanges(n),!0}}),!0):!1}};function yt(r,t,e="",n=0){const{startOffset:i,endOffset:s}=r,a=[],{paragraphs:c=[]}=t,l=i-n,u=s-n,d=c==null?void 0:c.find(g=>g.startIndex-n>=l&&g.startIndex-n<=u);if(l>0&&a.push({t:"r",len:l,segmentId:e}),d&&d.startIndex-n>l){const g=d.startIndex-n;a.push({t:"d",len:g-l,line:0,segmentId:e}),a.push({t:"r",len:1,segmentId:e}),u>g+1&&a.push({t:"d",len:u-g-1,line:0,segmentId:e})}else a.push({t:"d",len:u-l,line:0,segmentId:e});return a}const Ee={id:"doc.command.delete-left",type:o.CommandType.COMMAND,handler:async r=>{var D;const t=r.get(h.TextSelectionManagerService),e=r.get(h.DocSkeletonManagerService),n=r.get(o.IUniverInstanceService),i=r.get(o.ICommandService),s=t.getActiveRange(),a=t.getSelections(),c=(D=e.getCurrent())==null?void 0:D.skeleton;let l;if(s==null||c==null||a==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:g,segmentId:f,style:m}=s;if(d===0&&g)return!0;const p=c.findNodeByCharIndex(d),S=M.hasListSpan(p),_=M.isIndentBySpan(p,u.body);let I=d;const O=c.findNodeByCharIndex(d-1);if(M.isFirstSpan(p)&&O!==p&&(S===!0||_===!0)){const R=M.getParagraphBySpan(p,u.body);if(R==null)return!1;const U=R==null?void 0:R.startIndex,E={startIndex:0},P=R.paragraphStyle;if(S===!0){const y=R.paragraphStyle;y&&(E.paragraphStyle=y)}else if(_===!0){const y=R.bullet;y&&(E.bullet=y),P!=null&&(E.paragraphStyle={...P},delete E.paragraphStyle.hanging,delete E.paragraphStyle.indentStart)}const w=[{startOffset:I,endOffset:I,style:m}];l=await i.executeCommand(xe.id,{unitId:u.getUnitId(),updateBody:{dataStream:"",paragraphs:[{...E}]},range:{startOffset:U,endOffset:U+1},textRanges:w,coverType:o.UpdateDocsAttributeType.REPLACE,segmentId:f})}else if(g===!0)if(O.content==="\r")l=await i.executeCommand(we.id,{direction:L.LEFT,range:s});else{I-=O.count;const R=[{startOffset:I,endOffset:I,style:m}];l=await i.executeCommand(de.id,{unitId:u.getUnitId(),range:s,segmentId:f,direction:L.LEFT,len:O.count,textRanges:R})}else{const R=Xe(s,a);l=await i.executeCommand(fe.id,{segmentId:f,textRanges:R})}return l}},Pe={id:"doc.command.delete-right",type:o.CommandType.COMMAND,handler:async r=>{var p;const t=r.get(h.TextSelectionManagerService),e=r.get(h.DocSkeletonManagerService),n=r.get(o.IUniverInstanceService),i=r.get(o.ICommandService),s=t.getActiveRange(),a=t.getSelections(),c=(p=e.getCurrent())==null?void 0:p.skeleton;let l;if(s==null||c==null||a==null)return!1;const u=n.getCurrentUniverDocInstance(),{startOffset:d,collapsed:g,segmentId:f,style:m}=s;if(d===u.getBody().dataStream.length-2&&g)return!0;if(g===!0){const S=c.findNodeByCharIndex(d);if(S.content==="\r")l=await i.executeCommand(we.id,{direction:L.RIGHT,range:s});else{const _=[{startOffset:d,endOffset:d,style:m}];l=await i.executeCommand(de.id,{unitId:u.getUnitId(),range:s,segmentId:f,direction:L.RIGHT,textRanges:_,len:S.count})}}else{const S=Xe(s,a);l=await i.executeCommand(fe.id,{segmentId:f,textRanges:S})}return l}},we={id:"doc.command.merge-two-paragraph",type:o.CommandType.COMMAND,handler:async(r,t)=>{var E,P,w;const e=r.get(h.TextSelectionManagerService),n=r.get(o.IUniverInstanceService),i=r.get(o.ICommandService),s=r.get(o.IUndoRedoService),{direction:a,range:c}=t,l=e.getActiveRange(),u=e.getSelections();if(l==null||u==null)return!1;const d=n.getCurrentUniverDocInstance(),{startOffset:g,collapsed:f,segmentId:m,style:p}=l;if(!f)return!1;const S=a===L.LEFT?g:g+1,_=(w=(P=(E=d.getBody())==null?void 0:E.paragraphs)==null?void 0:P.find(y=>y.startIndex>=S))==null?void 0:w.startIndex,I=Dt(d.getBody(),S,_),O=a===L.LEFT?g-1:g,x=d.getUnitId(),D=[{startOffset:O,endOffset:O,style:p}],R={id:v.id,params:{unitId:x,mutations:[]}};R.params.mutations.push({t:"r",len:a===L.LEFT?g-1:g,segmentId:m}),I.dataStream.length&&R.params.mutations.push({t:"i",body:I,len:I.dataStream.length,line:0,segmentId:m}),R.params.mutations.push({t:"r",len:1,segmentId:m}),R.params.mutations.push({t:"d",len:_+1-S,line:0,segmentId:m});const U=i.syncExecuteCommand(R.id,R.params);return e.replaceTextRanges(D),U?(s.pushUndoRedo({unitID:x,undoMutations:[{id:v.id,params:U}],redoMutations:[{id:v.id,params:R.params}],undo(){return i.syncExecuteCommand(v.id,U),e.replaceTextRanges([c]),!0},redo(){return i.syncExecuteCommand(v.id,R.params),e.replaceTextRanges(D),!0}}),!0):!1}};function Dt(r,t,e){const{textRuns:n}=r,i=r.dataStream.substring(t,e);if(n==null)return{dataStream:i};const s=[];for(const a of n){const{st:c,ed:l}=a;l<=t||c>=e||(c<t?s.push({...a,st:0,ed:l-t}):l>e?s.push({...a,st:c-t,ed:e-t}):s.push({...a,st:c-t,ed:l-t}))}return{dataStream:i,textRuns:s}}function Xe(r,t){let e=r.endOffset;for(const i of t){const{startOffset:s,endOffset:a}=i;s==null||a==null||a<=r.endOffset&&(e-=a-s)}return[{startOffset:e,endOffset:e,style:r.style}]}class Ne{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(t){if(this._undoMutationParamsCache.length===0||this._previousActiveRange==null)return null;const{unitId:e}=this._undoMutationParamsCache[0],{segmentId:n,startOffset:i,collapsed:s}=this._previousActiveRange,a={unitId:e,mutations:[]},c={unitId:e,mutations:[]};return s?(a.mutations.push({t:"r",len:i,segmentId:n}),c.mutations.push({t:"r",len:i,segmentId:n})):(i>0&&a.mutations.push({t:"r",len:i,segmentId:n}),a.mutations.push(this._undoMutationParamsCache[0].mutations.find(l=>l.t==="i")),c.mutations.push(...ce(this._previousActiveRange,n))),t.length&&(a.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:a,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Le={id:"doc.command.ime-input",type:o.CommandType.COMMAND,handler:async(r,t)=>{const{unitId:e,newText:n,oldTextLen:i,range:s,segmentId:a,textRanges:c,isCompositionEnd:l}=t,u=r.get(o.ICommandService),d=r.get(o.IUndoRedoService),g=r.get(h.TextSelectionManagerService),f=r.get(Ne),m={id:v.id,params:{unitId:e,mutations:[]}};s.collapsed?m.params.mutations.push({t:"r",len:s.startOffset,segmentId:a}):m.params.mutations.push(...ce(s,a)),i>0&&m.params.mutations.push({t:"d",len:i,line:0,segmentId:a}),m.params.mutations.push({t:"i",body:{dataStream:n},len:n.length,line:0,segmentId:a});const p=u.syncExecuteCommand(m.id,m.params);if(f.pushUndoRedoMutationParams(p,m.params),g.replaceTextRanges(c),l){if(p){const S=f.fetchComposedUndoRedoMutationParams(n);if(S==null)return!1;const{undoMutationParams:_,redoMutationParams:I,previousActiveRange:O}=S;return d.pushUndoRedo({unitID:e,undoMutations:[{id:v.id,params:_}],redoMutations:[{id:v.id,params:I}],undo(){return u.syncExecuteCommand(v.id,_),g.replaceTextRanges([O]),!0},redo(){return u.syncExecuteCommand(v.id,I),g.replaceTextRanges(c),!0}}),!0}}else return!!p;return!1}},G={id:"doc.command.set-inline-format-bold",type:o.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-italic",type:o.CommandType.COMMAND,handler:async()=>!0},J={id:"doc.command.set-inline-format-underline",type:o.CommandType.COMMAND,handler:async()=>!0},Q={id:"doc.command.set-inline-format-strikethrough",type:o.CommandType.COMMAND,handler:async()=>!0},A={id:"doc.command.set-inline-format-subscript",type:o.CommandType.COMMAND,handler:async()=>!0},j={id:"doc.command.set-inline-format-superscript",type:o.CommandType.COMMAND,handler:async()=>!0},H={id:"doc.command.set-inline-format-fontsize",type:o.CommandType.COMMAND,handler:async()=>!0},K={id:"doc.command.set-inline-format-font-family",type:o.CommandType.COMMAND,handler:async()=>!0},ee={id:"doc.command.set-inline-format-text-color",type:o.CommandType.COMMAND,handler:async()=>!0},qe={[G.id]:"bl",[Z.id]:"it",[J.id]:"ul",[Q.id]:"st",[H.id]:"fs",[K.id]:"ff",[ee.id]:"cl",[A.id]:"va",[j.id]:"va"},Ae={id:"doc.command.set-inline-format",type:o.CommandType.COMMAND,handler:async(r,t)=>{const{segmentId:e,value:n,preCommandId:i}=t,s=r.get(o.IUndoRedoService),a=r.get(o.ICommandService),c=r.get(h.TextSelectionManagerService),l=r.get(o.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;let d=l.getCurrentUniverDocInstance(),g=d.getUnitId();g===o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(d=l.getUniverDocInstance(o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),g=d.getUnitId());let f;switch(i){case G.id:case Z.id:case J.id:case Q.id:case A.id:case j.id:{f=bt(d.getBody().textRuns,i,u);break}case H.id:case K.id:{f=n;break}case ee.id:{f={rgb:n};break}default:throw new Error(`Unknown command: ${i} in handleInlineFormat`)}const m={id:v.id,params:{unitId:g,mutations:[]}},p=new o.MemoryCursor;p.reset();for(const I of u){const{startOffset:O,endOffset:x}=I,D={dataStream:"",textRuns:[{st:0,ed:x-O,ts:{[qe[i]]:f}}]},R=O-p.cursor;R!==0&&m.params.mutations.push({t:"r",len:R,segmentId:e}),m.params.mutations.push({t:"r",body:D,len:x-O,segmentId:e}),p.reset(),p.moveCursor(x)}const S=a.syncExecuteCommand(m.id,m.params),_=[G.id,H.id,K.id,A.id,j.id];return _.includes(i)&&c.refreshSelection(),S?(s.pushUndoRedo({unitID:g,undoMutations:[{id:v.id,params:S}],redoMutations:[{id:v.id,params:m.params}],undo(){return a.syncExecuteCommand(v.id,S),_.includes(i)&&c.refreshSelection(),!0},redo(){return a.syncExecuteCommand(v.id,m.params),_.includes(i)&&c.refreshSelection(),!0}}),!0):!1}};function Tt(r){return r!==null&&typeof r=="object"}function bt(r,t,e){let n=0,i=0;const s=qe[t];for(;n!==r.length&&i!==e.length;){const{startOffset:a,endOffset:c}=e[i],{st:l,ed:u,ts:d}=r[n];if(c<=l)i++;else if(u<=a)n++;else{if((d==null?void 0:d[s])==null){if(/bl|it/.test(s))return o.BooleanNumber.TRUE;if(/ul|st/.test(s))return{s:o.BooleanNumber.TRUE};if(/va/.test(s))return t===A.id?o.BaselineOffset.SUBSCRIPT:o.BaselineOffset.SUPERSCRIPT}if(Tt(d==null?void 0:d[s])&&d[s].s===o.BooleanNumber.FALSE)return{s:o.BooleanNumber.TRUE};if(t===A.id&&(d==null?void 0:d[s])!==o.BaselineOffset.SUBSCRIPT)return o.BaselineOffset.SUBSCRIPT;if(t===j.id&&(d==null?void 0:d[s])!==o.BaselineOffset.SUPERSCRIPT)return o.BaselineOffset.SUPERSCRIPT;if((d==null?void 0:d[s])===o.BooleanNumber.FALSE)return o.BooleanNumber.TRUE;n++}}return/bl|it/.test(s)?o.BooleanNumber.FALSE:/ul|st/.test(s)?{s:o.BooleanNumber.FALSE}:o.BaselineOffset.NORMAL}const Ze={id:"doc.command.bullet-list",type:o.CommandType.COMMAND,handler:r=>r.get(o.ICommandService).syncExecuteCommand(Be.id,{listType:o.PresetListType.BULLET_LIST})},Je={id:"doc.command.order-list",type:o.CommandType.COMMAND,handler:r=>r.get(o.ICommandService).syncExecuteCommand(Be.id,{listType:o.PresetListType.ORDER_LIST})},Be={id:"doc.command.list-operation",type:o.CommandType.COMMAND,handler:(r,t)=>{var x;const e=r.get(h.TextSelectionManagerService),n=r.get(o.IUniverInstanceService),i=r.get(o.ICommandService),s=r.get(o.IUndoRedoService),{listType:a}=t,c=n.getCurrentUniverDocInstance(),l=e.getActiveRange(),u=(x=c.getBody())==null?void 0:x.paragraphs;if(l==null||u==null)return!1;const d=xt(l,u),{segmentId:g}=l,f=c.getUnitId(),m=d.every(D=>{var R;return((R=D.bullet)==null?void 0:R.listType)===a}),p=6;let S=o.Tools.generateRandomId(p);if(d.length===1){const D=u.indexOf(d[0]),R=u[D-1],U=u[D+1];R&&R.bullet&&R.bullet.listType===a?S=R.bullet.listId:U&&U.bullet&&U.bullet.listType===a&&(S=U.bullet.listId)}const _={id:v.id,params:{unitId:f,mutations:[]}},I=new o.MemoryCursor;I.reset();for(const D of d){const{startIndex:R}=D;_.params.mutations.push({t:"r",len:R-I.cursor,segmentId:g});const U={...D.paragraphStyle,hanging:void 0,indentStart:void 0};_.params.mutations.push({t:"r",len:1,body:{dataStream:"",paragraphs:[m?{paragraphStyle:U,startIndex:0}:{...D,startIndex:0,bullet:{...D.bullet??{nestingLevel:0,textStyle:{fs:20}},listType:a,listId:S}}]},segmentId:g,coverType:o.UpdateDocsAttributeType.REPLACE}),I.moveCursorTo(R+1)}const O=i.syncExecuteCommand(_.id,_.params);return e.refreshSelection(),O&&s.pushUndoRedo({unitID:f,undoMutations:[{id:v.id,params:O}],redoMutations:[{id:v.id,params:_.params}],undo(){return i.syncExecuteCommand(v.id,O),e.refreshSelection(),!0},redo(){return i.syncExecuteCommand(v.id,_.params),e.refreshSelection(),!0}}),!0}};function xt(r,t){const{startOffset:e,endOffset:n}=r,i=[];let s=0;for(const a of t){const{startIndex:c}=a;(e>s&&e<=c||n>s&&n<=c||c>=e&&c<=n)&&i.push(a),s=c}return i}const Qe={id:"doc.command-replace-content",type:o.CommandType.COMMAND,handler:async(r,t)=>{var p;const{unitId:e,body:n,textRanges:i,segmentId:s=""}=t,a=r.get(o.IUniverInstanceService),c=r.get(o.ICommandService),l=r.get(h.TextSelectionManagerService),u=r.get(o.IUndoRedoService),d=(p=a.getUniverDocInstance(e))==null?void 0:p.getSnapshot().body,g=l.getSelections();if(d==null||!Array.isArray(g)||g.length===0)return!1;const f=tt(e,s,d,n),m=c.syncExecuteCommand(f.id,f.params);return l.replaceTextRanges(i),m?(u.pushUndoRedo({unitID:e,undoMutations:[{id:v.id,params:m}],redoMutations:[{id:v.id,params:f.params}],undo(){return c.syncExecuteCommand(v.id,m),l.replaceTextRanges(g),!0},redo(){return c.syncExecuteCommand(v.id,f.params),l.replaceTextRanges(i),!0}}),!0):!1}},et={id:"doc.command-cover-content",type:o.CommandType.COMMAND,handler:async(r,t)=>{var d;const{unitId:e,body:n,segmentId:i=""}=t,s=r.get(o.IUniverInstanceService),a=r.get(o.ICommandService),c=r.get(o.IUndoRedoService),l=(d=s.getUniverDocInstance(e))==null?void 0:d.getSnapshot().body;if(l==null)return!1;const u=tt(e,i,l,n);return a.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(e),!0}};function tt(r,t,e,n){const i={id:v.id,params:{unitId:r,mutations:[]}},s=(e==null?void 0:e.dataStream.length)-2;return s>0&&i.params.mutations.push({t:"d",len:s,line:0,segmentId:t}),n.dataStream.length>0&&i.params.mutations.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:t}),i}const B={id:"doc.operation.move-cursor",type:o.CommandType.OPERATION,handler:(r,t)=>!!t},$={id:"doc.operation.move-selection",type:o.CommandType.OPERATION,handler:(r,t)=>!!t},Ut=(r,t)=>{const e=r.get(o.IUniverInstanceService).getUniverDocInstance(t.unitId),n=(e==null?void 0:e.zoomRatio)||1;return{...o.Tools.deepClone(t),zoomRatio:n}},V={id:"doc.operation.set-zoom-ratio",type:o.CommandType.OPERATION,handler:(r,t)=>{const e=r.get(o.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}},nt={type:o.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(r,t)=>{const e=r.get(o.ICommandService),n=r.get(o.IUndoRedoService),i=r.get(o.IUniverInstanceService);let s=i.getCurrentUniverDocInstance().getUnitId(),a=1;if(t&&(s=t.documentId??s,a=t.zoomRatio??a),!i.getUniverDocInstance(s))return!1;const l={zoomRatio:a,unitId:s},u=Ut(r,l);return e.syncExecuteCommand(V.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:V.id,params:u}],redoMutations:[{id:V.id,params:l}]}),!0):!1}},it={id:"doc.operation.select-all",type:o.CommandType.COMMAND,handler:async r=>{const t=r.get(o.IUniverInstanceService),e=r.get(h.TextSelectionManagerService),n=t.getCurrentUniverDocInstance().getSnapshot().body;if(n==null)return!1;const i=[{startOffset:0,endOffset:n.dataStream.length-2}];return e.replaceTextRanges(i),!0}},Et=10,Pt=6;function wt(){return o.Tools.generateRandomId(Pt)}function Nt(r){const t=r.match(/data-copy-id="([^\s]+)"/);return t&&t[1]?t[1]:null}class Lt{constructor(){C(this,"_cache",new o.LRUMap(Et))}set(t,e){this._cache.set(t,e)}get(t){return this._cache.get(t)}clear(){this._cache.clear()}}const rt=new Lt;function At(r){const t=r.style,e={};for(let n=0;n<t.length;n++){const i=t[n],s=t.getPropertyValue(i);switch(i){case"margin-top":{const a=parseInt(s);e.spaceAbove=/pt/.test(s)?$e(a):a;break}case"margin-bottom":{const a=parseInt(s);e.spaceBelow=/pt/.test(s)?$e(a):a;break}}}return Object.getOwnPropertyNames(e).length?e:null}function $e(r){return r/.75}function Fe(r){const t=r.style,e={},n=r.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{e.bl=o.BooleanNumber.TRUE;break}case"s":{e.st={s:o.BooleanNumber.TRUE};break}case"u":{e.ul={s:o.BooleanNumber.TRUE};break}case"i":{e.it=o.BooleanNumber.TRUE;break}case"sub":case"sup":{e.va=n==="sup"?o.BaselineOffset.SUPERSCRIPT:o.BaselineOffset.SUBSCRIPT;break}}for(let i=0;i<t.length;i++){const s=t[i],a=t.getPropertyValue(s);switch(s){case"font-family":{e.ff=a;break}case"font-size":{const c=parseInt(a);Number.isNaN(c)||(e.fs=/pt$/.test(a)?$e(c):c);break}case"font-style":{a==="italic"&&(e.it=o.BooleanNumber.TRUE);break}case"font-weight":{Number(a)>400&&(e.bl=o.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(a)?e.ul={s:o.BooleanNumber.TRUE}:/overline/.test(a)?e.ol={s:o.BooleanNumber.TRUE}:/line-through/.test(a)&&(e.st={s:o.BooleanNumber.TRUE});break}case"color":{const c=new o.ColorKit(a);c.isValid&&(e.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new o.ColorKit(a);c.isValid&&(e.bg={rgb:c.toRgbString()});break}}}return e}function Bt(r){const t=new DOMParser,e=`<x-univer id="univer-root">${r}</x-univer>`;return t.parseFromString(e,"text/html").querySelector("#univer-root")}function st(r,t){const e=r.tagName.toLowerCase();return typeof t=="string"?e===t:Array.isArray(t)?t.some(n=>n===e):t(r)}const Te=class Te{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=Te.pluginList.find(s=>s.checkPasteType(t)),n=Bt(t),i={dataStream:"",textRuns:[]};return e&&(this.styleRules=[...e.stylesRules],this.afterProcessRules=[...e.afterProcessRules]),this.styleCache.clear(),this.process(null,n==null?void 0:n.childNodes,i),this.styleCache.clear(),this.styleRules=[],this.afterProcessRules=[],i}process(t,e,n){var i;for(const s of e)if(s.nodeType===Node.TEXT_NODE){const a=(i=s.nodeValue)==null?void 0:i.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(s.nodeType===Node.ELEMENT_NODE){const a=t?this.styleCache.get(t):{},c=this.styleRules.find(({filter:g})=>st(s,g)),l=c?c.getStyle(s):Fe(s);this.styleCache.set(s,{...a,...l});const{childNodes:u}=s;this.process(s,u,n);const d=this.afterProcessRules.find(({filter:g})=>st(s,g));d&&d.handler(n,s)}}};C(Te,"pluginList",[]);let te=Te;const $t={name:"univer-doc-paste-plugin-lark",checkPasteType(r){return/lark-record-clipboard/i.test(r)},stylesRules:[{filter:["s"],getStyle(r){const t=Fe(r);return{st:{s:o.BooleanNumber.TRUE},...t}}}],afterProcessRules:[{filter(r){return r.tagName==="DIV"&&/ace-line/i.test(r.className)},handler(r){r.paragraphs==null&&(r.paragraphs=[]),r.paragraphs.push({startIndex:r.dataStream.length}),r.dataStream+="\r"}}]},Ft={name:"univer-doc-paste-plugin-word",checkPasteType(r){return/word|mso/i.test(r)},stylesRules:[{filter:["b"],getStyle(r){const t=Fe(r);return{bl:o.BooleanNumber.TRUE,...t}}}],afterProcessRules:[{filter(r){return r.tagName==="P"&&/mso/i.test(r.className)},handler(r,t){r.paragraphs==null&&(r.paragraphs=[]);const e={startIndex:r.dataStream.length},n=At(t);n&&(e.paragraphStyle=n),r.paragraphs.push(e),r.dataStream+="\r"}}]};function jt(r,t){const{st:e,ed:n,ts:i={}}=t,{ff:s,fs:a,it:c,bl:l,ul:u,st:d,ol:g,bg:f,cl:m,va:p}=i;let S=r.slice(e,n);const _=[];return c===o.BooleanNumber.TRUE&&(S=`<i>${S}</i>`),p===o.BaselineOffset.SUPERSCRIPT?S=`<sup>${S}</sup>`:p===o.BaselineOffset.SUBSCRIPT&&(S=`<sub>${S}</sub>`),(u==null?void 0:u.s)===o.BooleanNumber.TRUE&&(S=`<u>${S}</u>`),(d==null?void 0:d.s)===o.BooleanNumber.TRUE&&(S=`<s>${S}</s>`),l===o.BooleanNumber.TRUE&&(S=`<strong>${S}</strong>`),s&&_.push(`font-family: ${s}`),m&&_.push(`color: ${m.rgb}`),a&&_.push(`font-size: ${a}px`),g&&_.push("text-decoration: overline"),f&&_.push(`background: ${f.rgb}`),_.length?`<span style="${_.join(";")}">${S}</span>`:S}function at(r,t=!0){const{dataStream:e,textRuns:n=[],paragraphs:i=[]}=r;let s=0;const a=[],c=[];for(const l of n){const{st:u,ed:d}=l;if(u!==s&&a.push(e.slice(s,u)),a.push(jt(e,l)),s=d,t)for(const g of i){const{startIndex:f,paragraphStyle:m={}}=g;if(f>=u&&f<=d){const{spaceAbove:p,spaceBelow:S}=m,_=[];p!=null&&(typeof p=="number"?_.push(`margin-top: ${p}px`):_.push(`margin-top: ${p.v}px`)),S!=null&&(typeof S=="number"?_.push(`margin-bottom: ${S}px`):_.push(`margin-bottom: ${S.v}px`)),c.push(`<p className="UniverNormal" ${_.length?`style="${_.join(";")}"`:""}>${a.join("")}</p>`),a.length=0}}}return c.join("")+a.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 at(t[0]);let e="";for(const n of t)e+='<p className="UniverNormal">',e+=at(n,!1),e+="</p>";return e}}var kt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Wt=(r,t,e,n)=>{for(var i=n>1?void 0:n?zt(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&kt(t,e,i),i},ot=(r,t)=>(e,n)=>t(e,n,r);te.use(Ft),te.use($t);const ct=b.createIdentifier("doc.clipboard-service");let je=class extends o.Disposable{constructor(t,e){super();C(this,"_clipboardHooks",[]);C(this,"_htmlToUDM",new te);C(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 s of t)for(const a of s.types)a===T.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await s.getType(a).then(c=>c&&c.text()):a===T.HTML_CLIPBOARD_MIME_TYPE&&(e=await s.getType(a).then(c=>c&&c.text()));if(!e)return{dataStream:n};const i=Nt(e);if(i){const s=rt.get(i);if(s)return s}return this._htmlToUDM.convert(e)}catch(e){return Promise.reject(e)}}async setClipboardData(t){const e=wt(),n=t.length>1?t.map(s=>s.dataStream).join(`
|
|
2
|
+
`):t[0].dataStream;let i=this._umdToHtml.convert(t);return t.length===1&&(i=i.replace(/(<[a-z]+)/,(s,a)=>`${a} data-copy-id="${e}"`),rt.set(e,t[0])),this._clipboardInterfaceService.write(n,i)}addClipboardHook(t){return this._clipboardHooks.push(t),o.toDisposable(()=>{const e=this._clipboardHooks.indexOf(t);e>-1&&this._clipboardHooks.splice(e,1)})}};je=Wt([ot(0,o.IUniverInstanceService),ot(1,T.IClipboardInterfaceService)],je);var Gt=Object.defineProperty,Ht=Object.getOwnPropertyDescriptor,Kt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Ht(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Gt(t,e,i),i},Y=(r,t)=>(e,n)=>t(e,n,r);let he=class extends o.Disposable{constructor(r,t,e,n,i,s){super(),this._logService=r,this._commandService=t,this._currentUniverService=e,this._docClipboardService=n,this._textSelectionManagerService=i,this._contextService=s,this._commandExecutedListener(),this.initialize()}initialize(){[ue,me,ge].forEach(r=>this.disposeWithMe(this._commandService.registerAsMultipleCommand(r))),[Ye,fe].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_commandExecutedListener(){const r=[me.id,ue.id,ge.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(r.includes(t.id)&&!(!this._contextService.getContextValue(o.FOCUSING_DOC)&&!this._contextService.getContextValue(o.FOCUSING_EDITOR)))switch(t.id){case ge.id:{this._handlePaste();break}case ue.id:{this._handleCopy();break}case me.id:{this._handleCut();break}default:throw new Error(`Unhandled command ${t.id}`)}}))}async _handlePaste(){const{_docClipboardService:r}=this,{segmentId:t,endOffset:e,style:n}=this._textSelectionManagerService.getActiveRange()??{},i=this._textSelectionManagerService.getSelections();if(t==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),!(e==null||i==null))try{const s=await r.queryClipboardData();let a=e;for(const l of i){const{startOffset:u,endOffset:d}=l;u==null||d==null||d<=e&&(a+=s.dataStream.length-(d-u))}const c=[{startOffset:a,endOffset:a,style:n}];this._commandService.executeCommand(Ye.id,{body:s,segmentId:t,textRanges:c})}catch{this._logService.error("[DocClipboardController] clipboard is empty")}}_getDocumentBodyInRanges(){const r=this._textSelectionManagerService.getSelections(),t=this._currentUniverService.getCurrentUniverDocInstance(),{dataStream:e,textRuns:n=[],paragraphs:i=[]}=t.getBody(),s=[];if(r==null)return s;for(const a of r){const{startOffset:c,endOffset:l,collapsed:u}=a;if(u||c==null||l==null)continue;const d={dataStream:e.slice(c,l)},g=[];for(const m of n){const p=o.Tools.deepClone(m),{st:S,ed:_}=p;o.Tools.hasIntersectionBetweenTwoRanges(S,_,c,l)&&(c>=S&&c<=_?g.push({...p,st:c,ed:Math.min(l,_)}):l>=S&&l<=_?g.push({...p,st:Math.max(c,S),ed:l}):g.push(p))}g.length&&(d.textRuns=g.map(m=>{const{st:p,ed:S}=m;return{...m,st:p-c,ed:S-c}}));const f=[];for(const m of i){const{startIndex:p}=m;p>=c&&p<=l&&f.push(o.Tools.deepClone(m))}f.length&&(d.paragraphs=f.map(m=>({...m,startIndex:m.startIndex-c}))),s.push(d)}return s}async _handleCopy(){const{_docClipboardService:r}=this,t=this._getDocumentBodyInRanges();try{r.setClipboardData(t)}catch{this._logService.error("[DocClipboardController] set clipboard failed")}}async _handleCut(){const{segmentId:r,endOffset:t,style:e}=this._textSelectionManagerService.getActiveRange()??{},n=this._textSelectionManagerService.getSelections();if(r==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),!(t==null||n==null)){this._handleCopy();try{let i=t;for(const a of n){const{startOffset:c,endOffset:l}=a;c==null||l==null||l<=t&&(i-=l-c)}const s=[{startOffset:i,endOffset:i,style:e}];this._commandService.executeCommand(fe.id,{segmentId:r,textRanges:s})}catch{this._logService.error("[DocClipboardController] cut content failed")}}}};he=Kt([o.OnLifecycle(o.LifecycleStages.Rendered,he),Y(0,o.ILogService),Y(1,o.ICommandService),Y(2,o.IUniverInstanceService),Y(3,ct),Y(4,b.Inject(h.TextSelectionManagerService)),Y(5,o.IContextService)],he);var Yt=Object.defineProperty,Xt=Object.getOwnPropertyDescriptor,qt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Xt(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Yt(t,e,i),i},Ve=(r,t)=>(e,n)=>t(e,n,r);let pe=class extends o.Disposable{constructor(r,t,e){super(),this._docSkeletonManagerService=r,this._renderManagerService=t,this._commandService=e,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.subscribe(r=>{if(r==null)return;const{skeleton:t,unitId:e}=r,n=this._renderManagerService.getRenderById(e);if(n==null)return;const{mainComponent:i}=n;i.changeSkeleton(t),this._recalculateSizeBySkeleton(n,t)})}_recalculateSizeBySkeleton(r,t){var u;const{mainComponent:e,scene:n}=r,i=e,s=(u=t.getSkeletonData())==null?void 0:u.pages;if(s==null)return;let a=0,c=0;for(let d=0,g=s.length;d<g;d++){const f=s[d],{pageWidth:m,pageHeight:p}=f;i.pageLayoutType===M.PageLayoutType.VERTICAL?(c+=p,c+=i.pageMarginTop,d===g-1&&(c+=i.pageMarginTop),a=Math.max(a,m)):i.pageLayoutType===M.PageLayoutType.HORIZONTAL&&(a+=m,d!==g-1&&(a+=i.pageMarginLeft),c=Math.max(c,p))}i.resize(a,c),[o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(r.unitId)||n.resize(a,c)}_commandExecutedListener(){const r=[v.id],t=[o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(r.includes(e.id)){const i=e.params,{unitId:s}=i,a=this._docSkeletonManagerService.getSkeletonByUnitId(s);if(a==null)return;const{skeleton:c}=a,l=this._renderManagerService.getRenderById(s);if(l==null)return;if(c.calculate(),t.includes(s)){(n=l.mainComponent)==null||n.makeDirty();return}this._recalculateSizeBySkeleton(l,c)}}))}};pe=qt([o.OnLifecycle(o.LifecycleStages.Rendered,pe),Ve(0,b.Inject(h.DocSkeletonManagerService)),Ve(1,M.IRenderManagerService),Ve(2,o.ICommandService)],pe);var Zt=Object.defineProperty,Jt=Object.getOwnPropertyDescriptor,Qt=(r,t,e,n)=>{for(var i=n>1?void 0:n?Jt(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Zt(t,e,i),i},ne=(r,t)=>(e,n)=>t(e,n,r);let Se=class extends o.Disposable{constructor(t,e,n,i,s){super();C(this,"_liquid",new M.Liquid);C(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._commandService=i,this._floatingObjectManagerService=s,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:i}=e,s=this._renderManagerService.getRenderById(n);if(s==null)return;const{mainComponent:a,components:c,scene:l}=s,u=a,{left:d,top:g}=u;t.forEach(f=>{const{unitId:m,subComponentId:p,floatingObjectId:S,floatingObject:_}=f,{left:I=0,top:O=0,width:x=0,height:D=0,angle:R,flipX:U,flipY:E,skewX:P,skewY:w}=_,y=this._pageMarginCache.get(S),F=(y==null?void 0:y.marginLeft)||0,N=(y==null?void 0:y.marginTop)||0;i==null||i.getViewModel().getDataModel().updateDrawing(S,{left:I-d-F,top:O-g-N,height:D,width:x})}),i==null||i.calculate(),a==null||a.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{skeleton:e,unitId:n}=t,i=this._renderManagerService.getRenderById(n);if(i==null)return;const{mainComponent:s}=i;s.changeSkeleton(e),this._refreshFloatingObject(n,e,i)})}_commandExecutedListener(){const t=[v.id,V.id],e=[o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var i;if(t.includes(n.id)){const s=n.params,{unitId:a}=s,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)){(i=d.mainComponent)==null||i.makeDirty();return}this._refreshFloatingObject(l,u,d)}}))}_refreshFloatingObject(t,e,n){const i=e==null?void 0:e.getSkeletonData(),{mainComponent:s,scene:a}=n,c=s;if(!i)return;const{left:l,top:u,pageLayoutType:d,pageMarginLeft:g,pageMarginTop:f}=c,{pages:m}=i,p=[];a.getAncestorScale(),this._liquid.reset(),this._pageMarginCache.clear();for(let S=0,_=m.length;S<_;S++){const I=m[S],{skeDrawings:O,marginLeft:x,marginTop:D}=I;this._liquid.translatePagePadding(I),O.forEach(R=>{const{aLeft:U,aTop:E,height:P,width:w,objectId:y}=R;p.push({unitId:t,subComponentId:o.DEFAULT_DOCUMENT_SUB_COMPONENT_ID,floatingObjectId:y,floatingObject:{left:U+l+this._liquid.x,top:E+u+this._liquid.y,width:w,height:P}}),this._pageMarginCache.set(y,{marginLeft:this._liquid.x,marginTop:this._liquid.y})}),this._liquid.translatePage(I,d,g,f)}this._floatingObjectManagerService.BatchAddOrUpdate(p)}};Se=Qt([o.OnLifecycle(o.LifecycleStages.Steady,Se),ne(0,b.Inject(h.DocSkeletonManagerService)),ne(1,o.IUniverInstanceService),ne(2,M.IRenderManagerService),ne(3,o.ICommandService),ne(4,o.IFloatingObjectManagerService)],Se);var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(r,t,e,n)=>{for(var i=n>1?void 0:n?tn(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&en(t,e,i),i},X=(r,t)=>(e,n)=>t(e,n,r);let _e=class extends o.Disposable{constructor(t,e,n,i,s,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=i,this._imeInputManagerService=s,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(o.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 p;const n=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(this._previousIMERange==null||t==null||n==null)return;const i=this._currentUniverService.getCurrentUniverDocInstance(),{event:s,activeRange:a}=t,{startOffset:c,segmentId:l,style:u}=this._previousIMERange;if(n==null||a==null)return;const g=s.data;if(g===this._previousIMEContent&&e)return;const f=g.length,m=[{startOffset:c+f,endOffset:c+f,style:u}];await this._commandService.executeCommand(Le.id,{unitId:i.getUnitId(),newText:g,oldTextLen:this._previousIMEContent.length,range:this._previousIMERange,textRanges:m,isCompositionEnd:!e,segmentId:l}),n.calculate(),e?(this._previousIMERange.collapsed||(this._previousIMERange.collapsed=!0),this._previousIMEContent=g):this._resetIME()}_resetIME(){this._previousIMEContent="",this._previousIMERange=null,this._imeInputManagerService.clearUndoRedoMutationParamsCache(),this._imeInputManagerService.setActiveRange(null)}_getDocObject(){return q(this._currentUniverService,this._renderManagerService)}};_e=nn([o.OnLifecycle(o.LifecycleStages.Rendered,_e),X(0,b.Inject(h.DocSkeletonManagerService)),X(1,o.IUniverInstanceService),X(2,M.IRenderManagerService),X(3,M.ITextSelectionRenderManager),X(4,b.Inject(Ne)),X(5,o.ICommandService)],_e);var rn=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,an=(r,t,e,n)=>{for(var i=n>1?void 0:n?sn(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&rn(t,e,i),i},lt=(r,t)=>(e,n)=>t(e,n,r);let ve=class extends o.Disposable{constructor(r,t){super(),this._textSelectionManagerService=r,this._commandService=t,this._commandExecutedListener()}_commandExecutedListener(){const r=[G.id,Z.id,J.id,Q.id,A.id,j.id,H.id,K.id,ee.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{r.includes(t.id)&&this._handleInlineFormat(t)}))}_handleInlineFormat(r){const{segmentId:t}=this._textSelectionManagerService.getActiveRange()??{};t!=null&&this._commandService.executeCommand(Ae.id,{segmentId:t,preCommandId:r.id,...r.params??{}})}};ve=an([o.OnLifecycle(o.LifecycleStages.Rendered,ve),lt(0,b.Inject(h.TextSelectionManagerService)),lt(1,o.ICommandService)],ve);var on=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,ln=(r,t,e,n)=>{for(var i=n>1?void 0:n?cn(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&on(t,e,i),i},ie=(r,t)=>(e,n)=>t(e,n,r);let Ce=class extends o.Disposable{constructor(t,e,n,i,s){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._textSelectionManagerService=i,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var t;(t=this._onInputSubscription)==null||t.unsubscribe()}_initialize(){}_commandExecutedListener(){const t=[B.id,$.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(!t.includes(e.id))return;const n=e.params;switch(e.id){case B.id:return this._handleMoveCursor(n.direction);case $.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(t){var S;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),i=this._currentUniverService.getCurrentUniverDocInstance(),s=(S=this._docSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,a=this._getDocObject();if(e==null||s==null||a==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d,direction:g}=e;if(n.length>1){let _=1/0,I=-1/0;for(const O of n)_=Math.min(_,O.startOffset),I=Math.max(I,O.endOffset);this._textSelectionManagerService.replaceTextRanges([{startOffset:t===o.Direction.LEFT||t===o.Direction.UP?I:_,endOffset:t===o.Direction.LEFT||t===o.Direction.UP?_:I,style:u}]);return}const f=d||g===M.RANGE_DIRECTION.FORWARD?c:l;let m=d||g===M.RANGE_DIRECTION.FORWARD?l:c;const p=i.getBody().dataStream.length??1/0;if(t===o.Direction.LEFT||t===o.Direction.RIGHT){const _=s.findNodeByCharIndex(m-1),I=s.findNodeByCharIndex(m);m=t===o.Direction.RIGHT?m+I.count:m-((_==null?void 0:_.count)??0),m=Math.min(p-2,Math.max(0,m)),this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:m,style:u}])}else{const _=s.findNodeByCharIndex(m),I=a.document.getOffsetConfig(),O=this._getTopOrBottomPosition(s,_,t===o.Direction.DOWN);if(O==null){const D=t===o.Direction.UP?0:p-2;if(D===m)return;this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:D,style:u}]);return}const x=new M.NodePositionConvertToCursor(I,s).getRangePointData(O,O).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{startOffset:f,endOffset:x.endOffset,style:u}])}}_handleMoveCursor(t){var f;const e=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),i=this._currentUniverService.getCurrentUniverDocInstance(),s=(f=this._docSkeletonManagerService.getCurrent())==null?void 0:f.skeleton,a=this._getDocObject();if(e==null||s==null||a==null||n==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d}=e,g=i.getBody().dataStream.length??1/0;if(t===o.Direction.LEFT||t===o.Direction.RIGHT){let m;if(!e.collapsed||n.length>1){let p=1/0,S=-1/0;for(const _ of n)p=Math.min(p,_.startOffset),S=Math.max(S,_.endOffset);m=t===o.Direction.LEFT?p:S}else{const p=s.findNodeByCharIndex(c-1),S=s.findNodeByCharIndex(c);t===o.Direction.LEFT?m=Math.max(0,c-((p==null?void 0:p.count)??0)):m=Math.min(g-2,l+S.count)}this._textSelectionManagerService.replaceTextRanges([{startOffset:m,endOffset:m,style:u}])}else{const m=s.findNodeByCharIndex(c),p=s.findNodeByCharIndex(l),S=a.document.getOffsetConfig(),_=this._getTopOrBottomPosition(s,t===o.Direction.UP?m:p,t===o.Direction.DOWN);if(_==null){let O;d?O=t===o.Direction.UP?0:g-2:O=t===o.Direction.UP?c:l,this._textSelectionManagerService.replaceTextRanges([{startOffset:O,endOffset:O,style:u}]);return}const I=new M.NodePositionConvertToCursor(S,s).getRangePointData(_,_).cursorList[0];this._textSelectionManagerService.replaceTextRanges([{...I,style:u}])}}_getTopOrBottomPosition(t,e,n){if(e==null)return;const i=this._getSpanLeftOffsetInLine(e),s=this._getNextOrPrevLine(e,n);if(s==null)return;const a=this._matchPositionByLeftOffset(t,s,i);if(a!=null)return{...a,isBack:!0}}_getSpanLeftOffsetInLine(t){const e=t.parent;if(e==null)return-1/0;const n=e.left,{left:i}=t;return n+i}_matchPositionByLeftOffset(t,e,n){const i={distance:1/0};for(const s of e.divides){const a=s.left;for(const c of s.spanGroup){const{left:l}=c,u=a+l,d=Math.abs(n-u);d<i.distance&&(i.span=c,i.distance=d)}}if(i.span!=null)return t.findPositionBySpan(i.span)}_getNextOrPrevLine(t,e){var p,S,_,I,O,x,D,R,U,E,P,w;const n=t.parent;if(n==null)return;const i=n.parent;if(i==null)return;const s=i.parent;if(s==null)return;const a=s.lines.indexOf(i);if(a===-1)return;let c;if(e===!0?c=s.lines[a+1]:c=s.lines[a-1],c!=null)return c;const l=s.parent;if(l==null)return;const u=l.columns.indexOf(s);if(u===-1)return;if(e===!0)c=(p=l.columns[u+1])==null?void 0:p.lines[0];else{const y=(_=(S=l.columns)==null?void 0:S[u-1])==null?void 0:_.lines;c=y==null?void 0:y[y.length-1]}if(c!=null)return c;const d=l.parent;if(d==null)return;const g=d.sections.indexOf(l);if(g===-1)return;if(e===!0)c=(O=(I=d.sections[g-1])==null?void 0:I.columns[0])==null?void 0:O.lines[0];else{const y=(D=(x=d.sections)==null?void 0:x[g-1])==null?void 0:D.columns,F=y==null?void 0:y[y.length-1],N=F==null?void 0:F.lines;c=N==null?void 0:N[N.length-1]}if(c!=null)return c;const f=d.parent;if(f==null)return;const m=f.pages.indexOf(d);if(m!==-1){if(e===!0)c=(E=(U=(R=f.pages[m+1])==null?void 0:R.sections[0])==null?void 0:U.columns[0])==null?void 0:E.lines[0];else{const y=(P=f.pages[m-1])==null?void 0:P.sections;if(y==null)return;const F=(w=y[y.length-1])==null?void 0:w.columns,N=F[F.length-1],ut=N==null?void 0:N.lines;c=ut[ut.length-1]}if(c!=null)return c}}_getDocObject(){return q(this._currentUniverService,this._renderManagerService)}};Ce=ln([o.OnLifecycle(o.LifecycleStages.Rendered,Ce),ie(0,b.Inject(h.DocSkeletonManagerService)),ie(1,o.IUniverInstanceService),ie(2,M.IRenderManagerService),ie(3,b.Inject(h.TextSelectionManagerService)),ie(4,o.ICommandService)],Ce);var dn=Object.defineProperty,un=Object.getOwnPropertyDescriptor,mn=(r,t,e,n)=>{for(var i=n>1?void 0:n?un(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&dn(t,e,i),i},re=(r,t)=>(e,n)=>t(e,n,r);let Ie=class extends o.Disposable{constructor(t,e,n,i,s){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=t,this._currentUniverService=e,this._renderManagerService=n,this._textSelectionRenderManager=i,this._commandService=s,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 p;if(t==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:i,content:s="",activeRange:a}=t,c=i,l=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(c.data==null||l==null||!l||!a)return;const{startOffset:u,segmentId:d,style:g}=a,f=s.length,m=[{startOffset:u+f,endOffset:u+f,style:g}];await this._commandService.executeCommand(le.id,{unitId:n,body:{dataStream:s},range:a,textRanges:m,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return q(this._currentUniverService,this._renderManagerService)}};Ie=mn([o.OnLifecycle(o.LifecycleStages.Rendered,Ie),re(0,b.Inject(h.DocSkeletonManagerService)),re(1,o.IUniverInstanceService),re(2,M.IRenderManagerService),re(3,M.ITextSelectionRenderManager),re(4,o.ICommandService)],Ie);var gn=Object.defineProperty,fn=Object.getOwnPropertyDescriptor,hn=(r,t,e,n)=>{for(var i=n>1?void 0:n?fn(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&gn(t,e,i),i},dt=(r,t)=>(e,n)=>t(e,n,r);const pn="rgba(198, 198, 198, 1)",Sn="rgba(255, 255, 255, 1)";let Me=class extends o.Disposable{constructor(r,t){super(),this._renderManagerService=r,this._currentUniverService=t,this._initialize(),this._commandExecutedListener()}_initialize(){this._initialRenderRefresh()}_initialRenderRefresh(){this._renderManagerService.currentRender$.subscribe(r=>{var s;if(r==null||this._currentUniverService.getUniverDocInstance(r)==null)return;const t=this._renderManagerService.getRenderById(r);if(t==null)return;const{mainComponent:e}=t,n=e,i=(s=n.getSkeleton())==null?void 0:s.getPageSize();n.onPageRenderObservable.add(a=>{if([o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(r))return;const{page:c,pageLeft:l,pageTop:u,ctx:d}=a,{width:g,height:f}=c;d.save(),d.translate(l-.5,u-.5),M.Rect.drawWith(d,{width:(i==null?void 0:i.width)||g,height:(i==null?void 0:i.height)||f,strokeWidth:1,stroke:pn,fill:Sn,zIndex:3}),d.restore()})})}_commandExecutedListener(){}};Me=hn([o.OnLifecycle(o.LifecycleStages.Rendered,Me),dt(0,M.IRenderManagerService),dt(1,b.Inject(o.IUniverInstanceService))],Me);var _n=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,Cn=(r,t,e,n)=>{for(var i=n>1?void 0:n?vn(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&_n(t,e,i),i},k=(r,t)=>(e,n)=>t(e,n,r);let Oe=class extends o.Disposable{constructor(t,e,n,i,s,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=i,this._textSelectionRenderManager=s,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:i}=e,s=i.getViewport(W.VIEW_MAIN);this._moveInObserver=n.onPointerEnterObserver.add(()=>{n.cursor=M.CURSOR_TYPE.TEXT}),this._moveOutObserver=n.onPointerLeaveObserver.add(()=>{n.cursor=M.CURSOR_TYPE.DEFAULT,i.resetCursor()}),this._downObserver=n==null?void 0:n.onPointerDownObserver.add((a,c)=>{this._currentUniverService.getCurrentUniverDocInstance().getUnitId()!==t&&this._currentUniverService.setCurrentUniverDocInstance(t),this._textSelectionRenderManager.eventTrigger(a,n.getOffsetConfig(),s),a.button!==2&&c.stopPropagation()}),this._dblClickObserver=n==null?void 0:n.onDblclickObserver.add(a=>{this._textSelectionRenderManager.handleDblClick(a,n.getOffsetConfig(),s)}),this._tripleClickObserver=n==null?void 0:n.onTripleClickObserver.add(a=>{this._textSelectionRenderManager.handleTripleClick(a,n.getOffsetConfig(),s)})}_commandExecutedListener(){const t=[V.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var n;if(t.includes(e.id)){const i=e.params,{unitId:s}=i,a=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(s!==a)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this._docSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{unitId:e,skeleton:n}=t,i=this._renderManagerService.getRenderById(e);if(i==null)return;const{scene:s,mainComponent:a}=i,c=s.getViewport(W.VIEW_MAIN);this._textSelectionRenderManager.changeRuntime(n,s,c,a.getOffsetConfig()),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:e,subUnitId:""})})}_getDocObjectById(t){return mt(t,this._renderManagerService)}};Oe=Cn([o.OnLifecycle(o.LifecycleStages.Rendered,Oe),k(0,b.Inject(h.DocSkeletonManagerService)),k(1,o.IUniverInstanceService),k(2,o.ICommandService),k(3,M.IRenderManagerService),k(4,M.ITextSelectionRenderManager),k(5,b.Inject(h.TextSelectionManagerService)),k(6,b.Optional(T.LayoutService))],Oe);var In=Object.defineProperty,Mn=Object.getOwnPropertyDescriptor,On=(r,t,e,n)=>{for(var i=n>1?void 0:n?Mn(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&In(t,e,i),i},se=(r,t)=>(e,n)=>t(e,n,r);let Re=class extends o.Disposable{constructor(t,e,n,i,s){super();C(this,"_initializedRender",new Set);this._docSkeletonManagerService=t,this._currentUniverService=e,this._commandService=n,this._renderManagerService=i,this._textSelectionManagerService=s,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)||[o.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(e))return;this._initializedRender.add(e);const{scene:i}=n;this.disposeWithMe(o.toDisposable(i.onMouseWheelObserver.add(s=>{if(!s.ctrlKey)return;const a=Math.abs(s.deltaX);let c=a<40?.2:a<80?.4:.2;c*=s.deltaY>0?-1:1,i.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(nt.id,{zoomRatio:d,unitId:l.getUnitId()}),s.preventDefault()})))})}_skeletonListener(){this.disposeWithMe(o.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(),i=e.params,{unitId:s}=i;if(s!==n.getUnitId())return;const a=n.zoomRatio||1;this._updateViewZoom(a)}}))}_updateViewZoom(t,e=!0){var i;const n=this._getDocObject();n!=null&&(n.scene.scale(t,t),this._calculatePagePosition(n,t),e&&this._textSelectionManagerService.refreshSelection(),(i=n.scene.getTransformer())==null||i.hideControl())}_calculatePagePosition(t,e){const{document:n,scene:i}=t,s=i==null?void 0:i.getParent(),{width:a,height:c,pageMarginLeft:l,pageMarginTop:u}=n;if(s==null||a===1/0||c===1/0)return;const{width:d,height:g}=s;let f=0,m=0,p=0,S=0,_=1/0;d>(a+l*2)*e?(f=d/2-a*e/2,f/=e,p=(d-l*2)/e,_=0):(f=l,p=a+l*2,_=(p-d/e)/2),g>c?(m=g/2-c/2,S=(g-u*2)/e):(m=u,S=c+u*2),i.resize(p,S+200),n.translate(f,m);const I=i.getViewport(W.VIEW_MAIN);if(_!==1/0&&I!=null){const O=I.getBarScroll(_,0).x;I.scrollTo({x:O})}return this}_getDocObject(){return q(this._currentUniverService,this._renderManagerService)}};Re=On([o.OnLifecycle(o.LifecycleStages.Rendered,Re),se(0,b.Inject(h.DocSkeletonManagerService)),se(1,o.IUniverInstanceService),se(2,o.ICommandService),se(3,M.IRenderManagerService),se(4,b.Inject(h.TextSelectionManagerService))],Re);const Rn={id:Ue.id,preconditions:r=>r.getContextValue(o.FOCUSING_DOC),binding:T.KeyCode.ENTER},yn={id:Ee.id,preconditions:r=>r.getContextValue(o.FOCUSING_DOC),binding:T.KeyCode.BACKSPACE},Dn={id:Pe.id,preconditions:r=>r.getContextValue(o.FOCUSING_DOC),binding:T.KeyCode.DELETE},Tn={id:B.id,binding:T.KeyCode.ARROW_UP,preconditions:r=>r.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.UP}},bn={id:B.id,binding:T.KeyCode.ARROW_DOWN,preconditions:r=>r.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.DOWN}},xn={id:B.id,binding:T.KeyCode.ARROW_LEFT,preconditions:r=>r.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.LEFT}},Un={id:B.id,binding:T.KeyCode.ARROW_RIGHT,preconditions:r=>r.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.RIGHT}},En={id:$.id,binding:T.KeyCode.ARROW_UP|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.UP}},Pn={id:$.id,binding:T.KeyCode.ARROW_DOWN|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.DOWN}},wn={id:$.id,binding:T.KeyCode.ARROW_LEFT|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.LEFT}},Nn={id:$.id,binding:T.KeyCode.ARROW_RIGHT|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(o.FOCUSING_DOC),staticParameters:{direction:o.Direction.RIGHT}},Ln={id:it.id,binding:T.KeyCode.A|T.MetaKeys.CTRL_COMMAND,preconditions:r=>r.getContextValue(o.FOCUSING_DOC)||r.getContextValue(o.FOCUSING_EDITOR)};var An=Object.defineProperty,Bn=Object.getOwnPropertyDescriptor,$n=(r,t,e,n)=>{for(var i=n>1?void 0:n?Bn(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&An(t,e,i),i},ye=(r,t)=>(e,n)=>t(e,n,r);h.DocCanvasView=class extends o.RxDisposable{constructor(e,n,i,s){super();C(this,"_scene");C(this,"_currentDocumentModel");C(this,"_loadedMap",new Set);C(this,"_fps$",new z.BehaviorSubject(""));C(this,"fps$",this._fps$.asObservable());this._renderManagerService=e,this._configService=n,this._currentUniverService=i,this._docViewModelManagerService=s,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.subscribe(e=>{if(e==null)return;this._currentDocumentModel=e;const n=e.getUnitId();this._docViewModelManagerService.setCurrent(n),this._loadedMap.has(n)||(this._addNewRender(),this._loadedMap.add(n))})}dispose(){this._fps$.complete()}_addNewRender(){const e=this._currentDocumentModel,n=e.getUnitId(),i=e.getContainer(),s=e.getParentRenderUnitId();if(i!=null&&s!=null)throw new Error("container or parentRenderUnitId can only exist one");i==null&&s!=null?this._renderManagerService.createRenderWithParent(n,s):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(W.VIEW_MAIN,c,{left:0,top:0,bottom:0,right:0,isWheelPreventDefaultX:!0});c.addViewport(u).attachControl(),c.on(M.EVENT_TYPE.wheel,(f,m)=>{const p=f;if(p.ctrlKey){const S=Math.abs(p.deltaX);let _=S<40?.2:S<80?.4:.2;_*=p.deltaY>0?-1:1,c.scaleX<1&&(_/=2),c.scaleX+_>4?c.scale(4,4):c.scaleX+_<.1?c.scale(.1,.1):p.preventDefault()}else u.onMouseWheel(p,m)}),this._configService.getConfig("hasScroll")!==!1&&n!==o.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&new M.ScrollBar(u),c.addLayer(new M.Layer(c,[],oe),new M.Layer(c,[],ze)),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,i=this._currentDocumentModel,s=new M.Documents(ae.MAIN,void 0,{pageMarginLeft:i.documentStyle.marginLeft||0,pageMarginTop:i.documentStyle.marginTop||0});s.zIndex=We,e.mainComponent=s,e.components.set(ae.MAIN,s),n.addObjects([s],oe),n.enableLayerCache(oe)}},h.DocCanvasView=$n([o.OnLifecycle(o.LifecycleStages.Ready,h.DocCanvasView),ye(0,M.IRenderManagerService),ye(1,o.IConfigService),ye(2,o.IUniverInstanceService),ye(3,b.Inject(h.DocViewModelManagerService))],h.DocCanvasView);var Fn=Object.defineProperty,jn=Object.getOwnPropertyDescriptor,Vn=(r,t,e,n)=>{for(var i=n>1?void 0:n?jn(t,e):t,s=r.length-1,a;s>=0;s--)(a=r[s])&&(i=(n?a(t,e,i):a(i))||i);return n&&i&&Fn(t,e,i),i},De=(r,t)=>(e,n)=>t(e,n,r);const kn={hasScroll:!0},zn="docs";h.UniverDocsPlugin=(ke=class extends o.Plugin{constructor(e={},n,i,s,a){super(zn);C(this,"_config");this._injector=n,this._localeService=i,this._configService=s,this._currentUniverService=a,this._config=Object.assign(kn,e),this._initializeDependencies(n),this._initializeCommands()}initialize(){}_initializeCommands(){[B,$,Ee,Pe,G,Z,J,Q,A,j,H,K,ee,Ae,Ue,le,de,xe,Le,we,v,Qe,et,nt,V,be,it,Je,Ze,Be].forEach(e=>{this._injector.get(o.ICommandService).registerCommand(e)}),[Tn,bn,Un,xn,En,Pn,wn,Nn,Ln,yn,Dn,Rn].forEach(e=>{this._injector.get(T.IShortcutService).registerShortcut(e)})}onReady(){this.initialize()}_initializeDependencies(e){[[h.DocCanvasView],[h.DocSkeletonManagerService],[h.DocViewModelManagerService],[Ne],[ct,{useClass:je}],[M.ITextSelectionRenderManager,{useClass:M.TextSelectionRenderManager}],[h.TextSelectionManagerService],[pe],[Me],[Oe],[Ie],[_e],[ve],[he],[Ce],[Re],[Se]].forEach(n=>e.add(n))}},C(ke,"type",o.PluginType.Doc),ke),h.UniverDocsPlugin=Vn([De(1,b.Inject(b.Injector)),De(2,b.Inject(o.LocaleService)),De(3,o.IConfigService),De(4,o.IUniverInstanceService)],h.UniverDocsPlugin),h.BreakLineCommand=Ue,h.BulletListCommand=Ze,h.CoverContentCommand=et,h.DOCS_COMPONENT_DEFAULT_Z_INDEX=We,h.DOCS_COMPONENT_HEADER_LAYER_INDEX=ze,h.DOCS_COMPONENT_MAIN_LAYER_INDEX=oe,h.DOCS_VIEW_KEY=ae,h.DeleteCommand=de,h.DeleteLeftCommand=Ee,h.DeleteRightCommand=Pe,h.DocCopyCommand=ue,h.DocCutCommand=me,h.DocPasteCommand=ge,h.IMEInputCommand=Le,h.InsertCommand=le,h.MoveCursorOperation=B,h.MoveSelectionOperation=$,h.NORMAL_TEXT_SELECTION_PLUGIN_NAME=gt,h.OrderListCommand=Je,h.ReplaceContentCommand=Qe,h.RichTextEditingMutation=v,h.SetInlineFormatBoldCommand=G,h.SetInlineFormatCommand=Ae,h.SetInlineFormatFontFamilyCommand=K,h.SetInlineFormatFontSizeCommand=H,h.SetInlineFormatItalicCommand=Z,h.SetInlineFormatStrikethroughCommand=Q,h.SetInlineFormatSubscriptCommand=A,h.SetInlineFormatSuperscriptCommand=j,h.SetInlineFormatTextColorCommand=ee,h.SetInlineFormatUnderlineCommand=J,h.SetTextSelectionsOperation=be,h.UpdateCommand=xe,h.VIEWPORT_KEY=W,h.getDocObject=q,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/docs",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.3",
|
|
4
4
|
"description": "UniverSheet normal base-docs",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -31,30 +31,28 @@
|
|
|
31
31
|
],
|
|
32
32
|
"private": false,
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@vitest/coverage-istanbul": "^1.0.2",
|
|
34
|
+
"@vitest/coverage-istanbul": "^1.0.4",
|
|
36
35
|
"@wendellhu/redi": "^0.12.12",
|
|
37
36
|
"happy-dom": "^12.10.3",
|
|
38
37
|
"less": "^4.2.0",
|
|
39
38
|
"rxjs": "^7.8.1",
|
|
40
39
|
"typescript": "^5.3.3",
|
|
41
|
-
"vite": "^5.0.
|
|
40
|
+
"vite": "^5.0.8",
|
|
42
41
|
"vite-plugin-dts": "^3.6.4",
|
|
43
42
|
"vite-plugin-externals": "^0.6.2",
|
|
44
|
-
"vitest": "^1.0.
|
|
45
|
-
"@univerjs/
|
|
46
|
-
"@univerjs/
|
|
47
|
-
"@univerjs/sheets": "0.1.0-alpha.
|
|
48
|
-
"@univerjs/ui": "0.1.0-alpha.
|
|
43
|
+
"vitest": "^1.0.4",
|
|
44
|
+
"@univerjs/core": "0.1.0-alpha.3",
|
|
45
|
+
"@univerjs/engine-render": "0.1.0-alpha.3",
|
|
46
|
+
"@univerjs/sheets": "0.1.0-alpha.3",
|
|
47
|
+
"@univerjs/ui": "0.1.0-alpha.3"
|
|
49
48
|
},
|
|
50
49
|
"peerDependencies": {
|
|
51
|
-
"@ctrl/tinycolor": ">=4.0.0",
|
|
52
50
|
"@wendellhu/redi": ">=0.12.12",
|
|
53
51
|
"rxjs": ">=7.0.0",
|
|
54
|
-
"@univerjs/
|
|
55
|
-
"@univerjs/
|
|
56
|
-
"@univerjs/sheets": "0.1.0-alpha.
|
|
57
|
-
"@univerjs/ui": "0.1.0-alpha.
|
|
52
|
+
"@univerjs/engine-render": "0.1.0-alpha.3",
|
|
53
|
+
"@univerjs/core": "0.1.0-alpha.3",
|
|
54
|
+
"@univerjs/sheets": "0.1.0-alpha.3",
|
|
55
|
+
"@univerjs/ui": "0.1.0-alpha.3"
|
|
58
56
|
},
|
|
59
57
|
"scripts": {
|
|
60
58
|
"test": "vitest run",
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2023-present DreamNum Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
17
|
-
import { ITextSelectionRenderManager } from '@univerjs/engine-render';
|
|
18
|
-
import { DocSkeletonManagerService } from '../services/doc-skeleton-manager.service';
|
|
19
|
-
export declare class DeleteController extends Disposable {
|
|
20
|
-
private readonly _docSkeletonManagerService;
|
|
21
|
-
private readonly _currentUniverService;
|
|
22
|
-
private readonly _textSelectionRenderManager;
|
|
23
|
-
private readonly _commandService;
|
|
24
|
-
constructor(_docSkeletonManagerService: DocSkeletonManagerService, _currentUniverService: IUniverInstanceService, _textSelectionRenderManager: ITextSelectionRenderManager, _commandService: ICommandService);
|
|
25
|
-
private _initialize;
|
|
26
|
-
private _commandExecutedListener;
|
|
27
|
-
private _handleDeleteLeft;
|
|
28
|
-
private _handleDeleteRight;
|
|
29
|
-
private _getTextRangesWhenDelete;
|
|
30
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Copyright 2023-present DreamNum Inc.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { Disposable, ICommandService, IUniverInstanceService } from '@univerjs/core';
|
|
17
|
-
import { IRenderManagerService, ITextSelectionRenderManager } from '@univerjs/engine-render';
|
|
18
|
-
import { DocSkeletonManagerService } from '../services/doc-skeleton-manager.service';
|
|
19
|
-
import { TextSelectionManagerService } from '../services/text-selection-manager.service';
|
|
20
|
-
export declare class LineBreakInputController extends Disposable {
|
|
21
|
-
private readonly _docSkeletonManagerService;
|
|
22
|
-
private readonly _currentUniverService;
|
|
23
|
-
private readonly _renderManagerService;
|
|
24
|
-
private readonly _textSelectionRenderManager;
|
|
25
|
-
private readonly _textSelectionManagerService;
|
|
26
|
-
private readonly _commandService;
|
|
27
|
-
private _onInputSubscription;
|
|
28
|
-
constructor(_docSkeletonManagerService: DocSkeletonManagerService, _currentUniverService: IUniverInstanceService, _renderManagerService: IRenderManagerService, _textSelectionRenderManager: ITextSelectionRenderManager, _textSelectionManagerService: TextSelectionManagerService, _commandService: ICommandService);
|
|
29
|
-
dispose(): void;
|
|
30
|
-
private _initialize;
|
|
31
|
-
private _commandExecutedListener;
|
|
32
|
-
private _handleBreakLine;
|
|
33
|
-
private _getDocObject;
|
|
34
|
-
}
|