@univerjs/docs 0.1.0-alpha.2 → 0.1.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/README.md +1 -1
  2. package/lib/cjs/index.js +2 -2
  3. package/lib/es/index.js +1840 -1763
  4. package/lib/types/commands/commands/__tests__/mock-text-selection-render-manager.d.ts +24 -0
  5. package/lib/types/{basics/demo-data.d.ts → commands/commands/break-line.command.d.ts} +2 -2
  6. package/lib/types/commands/commands/core-editing.command.d.ts +2 -5
  7. package/lib/types/commands/commands/delete.command.d.ts +26 -0
  8. package/lib/types/commands/commands/inline-format.command.d.ts +2 -0
  9. package/lib/types/commands/commands/list.command.d.ts +28 -0
  10. package/lib/types/commands/operations/text-selection.operation.d.ts +4 -2
  11. package/lib/types/controllers/clipboard.controller.d.ts +3 -3
  12. package/lib/types/controllers/doc-render.controller.d.ts +2 -2
  13. package/lib/types/controllers/ime-input.controller.d.ts +1 -3
  14. package/lib/types/controllers/inline-format.controller.d.ts +2 -5
  15. package/lib/types/controllers/move-cursor.controller.d.ts +2 -3
  16. package/lib/types/controllers/normal-input.controller.d.ts +1 -3
  17. package/lib/types/controllers/page-render.controller.d.ts +3 -2
  18. package/lib/types/controllers/text-selection.controller.d.ts +5 -5
  19. package/lib/types/index.d.ts +7 -2
  20. package/lib/types/services/clipboard/html-to-udm/converter.d.ts +5 -5
  21. package/lib/types/services/text-selection-manager.service.d.ts +33 -31
  22. package/lib/types/views/doc-canvas-view.d.ts +5 -2
  23. package/lib/umd/index.js +2 -2
  24. package/package.json +12 -14
  25. package/lib/types/controllers/delete.controller.d.ts +0 -30
  26. 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,a){typeof exports=="object"&&typeof module<"u"?a(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"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.UniverDocs={},h.UniverCore,h.UniverEngineRender,h.rxjs,h.UniverUi,h["@wendellhu/redi"]))})(this,function(h,a,M,j,T,b){"use strict";var Wn=Object.defineProperty;var Hn=(h,a,M)=>a in h?Wn(h,a,{enumerable:!0,configurable:!0,writable:!0,value:M}):h[a]=M;var C=(h,a,M)=>(Hn(h,typeof a!="symbol"?a+"":a,M),M);var ke;function X(r,e){const n=r.getCurrentUniverDocInstance().getUnitId(),i=e.getRenderById(n);if(i==null)return;const{mainComponent:s,scene:o,engine:c}=i;return{document:s,scene:o,engine:c}}function mt(r,e){const t=e.getRenderById(r);if(t==null)return;const{mainComponent:n,scene:i,engine:s}=t;return{document:n,scene:i,engine:s}}var se=(r=>(r.MAIN="__Document_Render_Main__",r))(se||{}),ae=(r=>(r.VIEW_MAIN="viewMain",r.VIEW_TOP="viewTop",r.VIEW_LEFT="viewLeft",r.VIEW_LEFT_TOP="viewLeftTop",r))(ae||{});const Te=0,ze=2,Ge=10,gt="normalTextSelectionPluginName",be={id:"doc.operation.set-selections",type:a.CommandType.OPERATION,handler:(r,e)=>!0};var ft=Object.defineProperty,ht=Object.getOwnPropertyDescriptor,pt=(r,e,t,n)=>{for(var i=n>1?void 0:n?ht(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&ft(e,t,i),i},We=(r,e)=>(t,n)=>e(t,n,r);function He(r){const{startOffset:e,endOffset:t,collapsed:n}=r;return{startOffset:e,endOffset:t,collapsed:n}}h.TextSelectionManagerService=class extends a.RxDisposable{constructor(t,n){super();C(this,"_currentSelection",null);C(this,"_textSelectionInfo",new Map);C(this,"_textSelection$",new j.BehaviorSubject(null));C(this,"textSelection$",this._textSelection$.asObservable());this._textSelectionRenderManager=t,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(t){this._currentSelection=t,this._refresh(t)}setCurrentSelectionNotRefresh(t){this._currentSelection=t}getSelections(){var t;return(t=this._getTextRanges(this._currentSelection))==null?void 0:t.textRanges}getActiveRange(){const t=this._getTextRanges(this._currentSelection);if(t==null)return;const{textRanges:n,segmentId:i,style:s}=t,o=n.find(m=>m.isActive());if(o==null)return null;const{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:g,direction:f}=o;return c==null||l==null?null:{startOffset:c,endOffset:l,collapsed:u,startNodePosition:d,endNodePosition:g,direction:f,segmentId:i,style:s}}add(t){this._currentSelection!=null&&this._addByParam({...this._currentSelection,textRanges:t,segmentId:"",style:M.NORMAL_TEXT_SELECTION_PLUGIN_STYLE})}replaceTextRanges(t){this._currentSelection!=null&&(this._textSelectionRenderManager.removeAllTextRanges(),this._textSelectionRenderManager.addTextRanges(t))}_syncSelectionFromRenderService(){this._textSelectionRenderManager.textSelectionInner$.pipe(j.takeUntil(this.dispose$)).subscribe(t=>{t!=null&&this._replaceTextRangesWithNoRefresh(t)})}_replaceTextRangesWithNoRefresh(t){if(this._currentSelection==null)return;const n={...this._currentSelection,...t};this._replaceByParam(n),this._textSelection$.next(n);const{unitId:i,subUnitId:s,segmentId:o,style:c,textRanges:l}=n;this._commandService.executeCommand(be.id,{unitId:i,subUnitId:s,segmentId:o,style:c,ranges:l.map(He)})}_getTextRanges(t){var s;if(t==null)return;const{unitId:n,subUnitId:i=""}=t;return(s=this._textSelectionInfo.get(n))==null?void 0:s.get(i)}_refresh(t){const n=this._getTextRanges(t);this._textSelectionRenderManager.removeAllTextRanges(),n&&Array.isArray(n.textRanges)&&n.textRanges.length&&this._textSelectionRenderManager.addTextRanges(n.textRanges.map(He))}_replaceByParam(t){const{unitId:n,subUnitId:i,style:s,segmentId:o,textRanges:c}=t;this._textSelectionInfo.has(n)||this._textSelectionInfo.set(n,new Map),this._textSelectionInfo.get(n).set(i,{textRanges:c,style:s,segmentId:o})}_addByParam(t){const{unitId:n,subUnitId:i,textRanges:s,style:o,segmentId:c}=t;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:o,segmentId:c})}},h.TextSelectionManagerService=pt([We(0,M.ITextSelectionRenderManager),We(1,a.ICommandService)],h.TextSelectionManagerService);function oe(r,e="",t=0){const{startOffset:n,endOffset:i}=r,s=[],o=n-t,c=i-t;return o>0&&s.push({t:"r",len:o,segmentId:e}),s.push({t:"d",len:c-o,line:0,segmentId:e}),s}var St=Object.defineProperty,_t=Object.getOwnPropertyDescriptor,vt=(r,e,t,n)=>{for(var i=n>1?void 0:n?_t(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&St(e,t,i),i},Ct=(r,e)=>(t,n)=>e(t,n,r);h.DocViewModelManagerService=class{constructor(e){C(this,"_currentViewModelUnitId","");C(this,"_docViewModelMap",new Map);C(this,"_currentDocViewModel$",new j.BehaviorSubject(null));C(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 i=this._buildDocViewModel(t);this._docViewModelMap.set(e,{unitId:e,docViewModel:i})}if(e===a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY){const i=(n=this._docViewModelMap.get(e))==null?void 0:n.docViewModel;if(i==null)return;i.reset(t)}this._currentViewModelUnitId=e,this._currentDocViewModel$.next(this.getCurrent())}}_buildDocViewModel(e){return new M.DocumentViewModel(e)}},h.DocViewModelManagerService=vt([Ct(0,a.IUniverInstanceService)],h.DocViewModelManagerService);const v={id:"doc.mutation.rich-text-editing",type:a.CommandType.MUTATION,handler:(r,e)=>{const{unitId:t,mutations:n}=e,s=r.get(a.IUniverInstanceService).getUniverDocInstance(t),c=r.get(h.DocViewModelManagerService).getViewModel(t);if(s==null||c==null)throw new Error(`DocumentDataModel or documentViewModel not found for unitId: ${t}`);const l=s.apply(n),u=n[0].segmentId,d=s.getSelfOrHeaderFooterModel(u);return c.getSelfOrHeaderFooterViewModel(u).reset(d),{unitId:t,mutations:l}}},ce={id:"doc.command.insert-text",type:a.CommandType.COMMAND,handler:async(r,e)=>{const t=r.get(a.IUndoRedoService),n=r.get(a.ICommandService),i=r.get(h.TextSelectionManagerService),{range:s,segmentId:o,body:c,unitId:l,textRanges:u}=e,{startOffset:d,collapsed:g}=s,f={id:v.id,params:{unitId:l,mutations:[]}};g?d>0&&f.params.mutations.push({t:"r",len:d,segmentId:o}):f.params.mutations.push(...oe(s,o)),f.params.mutations.push({t:"i",body:c,len:c.dataStream.length,line:0,segmentId:o});const m=n.syncExecuteCommand(f.id,f.params);return i.replaceTextRanges(u),m?(t.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 le={id:"doc.command.delete-text",type:a.CommandType.COMMAND,handler:async(r,e)=>{const t=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(h.TextSelectionManagerService),{range:s,segmentId:o,unitId:c,direction:l,textRanges:u,len:d=1}=e,{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:o}),f.params.mutations.push({t:"d",len:d,line:0,segmentId:o});const m=t.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 t.syncExecuteCommand(v.id,m),i.replaceTextRanges([s]),!0},redo(){return t.syncExecuteCommand(v.id,f.params),i.replaceTextRanges(u),!0}}),!1}},xe={id:"doc.command.update-text",type:a.CommandType.COMMAND,handler:async(r,e)=>{const{range:t,segmentId:n,updateBody:i,coverType:s,unitId:o,textRanges:c}=e,l=r.get(a.ICommandService),u=r.get(a.IUndoRedoService),d=r.get(h.TextSelectionManagerService),g={id:v.id,params:{unitId:o,mutations:[]}},{startOffset:f,endOffset:m}=t;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:o,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,e){const t=[];for(let n=0,i=r.length;n<i;n++)r[n]===a.DataStreamTreeTokenType.PARAGRAPH&&t.push({startIndex:n});if(e)for(const n of t)e.bullet&&(n.bullet=a.Tools.deepClone(e.bullet)),e.paragraphStyle&&(n.paragraphStyle=a.Tools.deepClone(e.paragraphStyle));return t}const Ue={id:"doc.command.break-line",type:a.CommandType.COMMAND,handler:async r=>{var p;const e=r.get(h.TextSelectionManagerService),t=r.get(a.IUniverInstanceService),n=r.get(a.ICommandService),i=e.getActiveRange();if(i==null)return!1;const s=t.getCurrentUniverDocInstance(),o=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(ce.id,{unitId:o,body:{dataStream:a.DataStreamTreeTokenType.PARAGRAPH,paragraphs:It(a.DataStreamTreeTokenType.PARAGRAPH,f)},range:i,textRanges:d,segmentId:l})}},de={id:T.CopyCommand.id,name:"doc.command.copy",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.FOCUSING_EDITOR),handler:async()=>!0},ue={id:T.CutCommand.id,name:"doc.command.cut",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.FOCUSING_EDITOR),handler:async()=>!0},me={id:T.PasteCommand.id,name:"doc.command.paste",type:a.CommandType.COMMAND,multi:!0,priority:999,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.FOCUSING_EDITOR),handler:async()=>!0};var Mt=Object.defineProperty,Ot=Object.getOwnPropertyDescriptor,Rt=(r,e,t,n)=>{for(var i=n>1?void 0:n?Ot(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Mt(e,t,i),i},Ke=(r,e)=>(t,n)=>e(t,n,r);h.DocSkeletonManagerService=class{constructor(e,t){C(this,"_currentSkeletonUnitId","");C(this,"_docSkeletonMap",new Map);C(this,"_currentSkeleton$",new j.BehaviorSubject(null));C(this,"currentSkeleton$",this._currentSkeleton$.asObservable());C(this,"_currentSkeletonBefore$",new j.BehaviorSubject(null));C(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 M.DocumentSkeleton.create(e,this._localeService)}},h.DocSkeletonManagerService=Rt([Ke(0,b.Inject(a.LocaleService)),Ke(1,b.Inject(h.DocViewModelManagerService))],h.DocSkeletonManagerService);const Ye={id:"doc.command.inner-paste",type:a.CommandType.COMMAND,handler:async(r,e)=>{const{segmentId:t,body:n,textRanges:i}=e,s=r.get(a.IUndoRedoService),o=r.get(a.ICommandService),c=r.get(h.TextSelectionManagerService),l=r.get(a.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 a.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:t}):f.params.mutations.push(...oe(S,t,m.cursor)),f.params.mutations.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:t}),m.reset(),m.moveCursor(I)}const p=o.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 o.syncExecuteCommand(v.id,p),c.replaceTextRanges(u),!0},redo(){return o.syncExecuteCommand(v.id,f.params),c.replaceTextRanges(i),!0}}),!0):!1}},ge={id:"doc.command.inner-cut",type:a.CommandType.COMMAND,handler:async(r,e)=>{const{segmentId:t,textRanges:n}=e,i=r.get(a.IUndoRedoService),s=r.get(a.ICommandService),o=r.get(h.TextSelectionManagerService),c=r.get(a.IUniverInstanceService),l=o.getSelections();if(!Array.isArray(l)||l.length===0)return!1;const u=c.getCurrentUniverDocInstance().getUnitId(),d=c.getUniverDocInstance(u),g=a.getDocsUpdateBody(d.snapshot,t);if(g==null)return!1;const f={id:v.id,params:{unitId:u,mutations:[]}},m=new a.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:t}):f.params.mutations.push(...yt(S,g,t,m.cursor)),m.reset(),m.moveCursor(I)}const p=s.syncExecuteCommand(f.id,f.params);return o.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),o.replaceTextRanges(l),!0},redo(){return s.syncExecuteCommand(v.id,f.params),o.replaceTextRanges(n),!0}}),!0):!1}};function yt(r,e,t="",n=0){const{startOffset:i,endOffset:s}=r,o=[],{paragraphs:c=[]}=e,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&&o.push({t:"r",len:l,segmentId:t}),d&&d.startIndex-n>l){const g=d.startIndex-n;o.push({t:"d",len:g-l,line:0,segmentId:t}),o.push({t:"r",len:1,segmentId:t}),u>g+1&&o.push({t:"d",len:u-g-1,line:0,segmentId:t})}else o.push({t:"d",len:u-l,line:0,segmentId:t});return o}const Ee={id:"doc.command.delete-left",type:a.CommandType.COMMAND,handler:async r=>{var D;const e=r.get(h.TextSelectionManagerService),t=r.get(h.DocSkeletonManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=e.getActiveRange(),o=e.getSelections(),c=(D=t.getCurrent())==null?void 0:D.skeleton;let l;if(s==null||c==null||o==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:a.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(le.id,{unitId:u.getUnitId(),range:s,segmentId:f,direction:L.LEFT,len:O.count,textRanges:R})}else{const R=Xe(s,o);l=await i.executeCommand(ge.id,{segmentId:f,textRanges:R})}return l}},Pe={id:"doc.command.delete-right",type:a.CommandType.COMMAND,handler:async r=>{var p;const e=r.get(h.TextSelectionManagerService),t=r.get(h.DocSkeletonManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=e.getActiveRange(),o=e.getSelections(),c=(p=t.getCurrent())==null?void 0:p.skeleton;let l;if(s==null||c==null||o==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(le.id,{unitId:u.getUnitId(),range:s,segmentId:f,direction:L.RIGHT,textRanges:_,len:S.count})}}else{const S=Xe(s,o);l=await i.executeCommand(ge.id,{segmentId:f,textRanges:S})}return l}},we={id:"doc.command.merge-two-paragraph",type:a.CommandType.COMMAND,handler:async(r,e)=>{var E,P,w;const t=r.get(h.TextSelectionManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=r.get(a.IUndoRedoService),{direction:o,range:c}=e,l=t.getActiveRange(),u=t.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=o===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=o===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:o===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 t.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),t.replaceTextRanges([c]),!0},redo(){return i.syncExecuteCommand(v.id,R.params),t.replaceTextRanges(D),!0}}),!0):!1}};function Dt(r,e,t){const{textRuns:n}=r,i=r.dataStream.substring(e,t);if(n==null)return{dataStream:i};const s=[];for(const o of n){const{st:c,ed:l}=o;l<=e||c>=t||(c<e?s.push({...o,st:0,ed:l-e}):l>t?s.push({...o,st:c-e,ed:t-e}):s.push({...o,st:c-e,ed:l-e}))}return{dataStream:i,textRuns:s}}function Xe(r,e){let t=r.endOffset;for(const i of e){const{startOffset:s,endOffset:o}=i;s==null||o==null||o<=r.endOffset&&(t-=o-s)}return[{startOffset:t,endOffset:t,style:r.style}]}class Ne{constructor(){C(this,"_previousActiveRange",null);C(this,"_undoMutationParamsCache",[]);C(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:i,collapsed:s}=this._previousActiveRange,o={unitId:t,mutations:[]},c={unitId:t,mutations:[]};return s?(o.mutations.push({t:"r",len:i,segmentId:n}),c.mutations.push({t:"r",len:i,segmentId:n})):(i>0&&o.mutations.push({t:"r",len:i,segmentId:n}),o.mutations.push(this._undoMutationParamsCache[0].mutations.find(l=>l.t==="i")),c.mutations.push(...oe(this._previousActiveRange,n))),e.length&&(o.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:o,previousActiveRange:this._previousActiveRange}}dispose(){this._undoMutationParamsCache=[],this._redoMutationParamsCache=[],this._previousActiveRange=null}}const Le={id:"doc.command.ime-input",type:a.CommandType.COMMAND,handler:async(r,e)=>{const{unitId:t,newText:n,oldTextLen:i,range:s,segmentId:o,textRanges:c,isCompositionEnd:l}=e,u=r.get(a.ICommandService),d=r.get(a.IUndoRedoService),g=r.get(h.TextSelectionManagerService),f=r.get(Ne),m={id:v.id,params:{unitId:t,mutations:[]}};s.collapsed?m.params.mutations.push({t:"r",len:s.startOffset,segmentId:o}):m.params.mutations.push(...oe(s,o)),i>0&&m.params.mutations.push({t:"d",len:i,line:0,segmentId:o}),m.params.mutations.push({t:"i",body:{dataStream:n},len:n.length,line:0,segmentId:o});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:t,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:a.CommandType.COMMAND,handler:async()=>!0},q={id:"doc.command.set-inline-format-italic",type:a.CommandType.COMMAND,handler:async()=>!0},Z={id:"doc.command.set-inline-format-underline",type:a.CommandType.COMMAND,handler:async()=>!0},J={id:"doc.command.set-inline-format-strikethrough",type:a.CommandType.COMMAND,handler:async()=>!0},A={id:"doc.command.set-inline-format-subscript",type:a.CommandType.COMMAND,handler:async()=>!0},V={id:"doc.command.set-inline-format-superscript",type:a.CommandType.COMMAND,handler:async()=>!0},W={id:"doc.command.set-inline-format-fontsize",type:a.CommandType.COMMAND,handler:async()=>!0},H={id:"doc.command.set-inline-format-font-family",type:a.CommandType.COMMAND,handler:async()=>!0},Q={id:"doc.command.set-inline-format-text-color",type:a.CommandType.COMMAND,handler:async()=>!0},qe={[G.id]:"bl",[q.id]:"it",[Z.id]:"ul",[J.id]:"st",[W.id]:"fs",[H.id]:"ff",[Q.id]:"cl",[A.id]:"va",[V.id]:"va"},Ae={id:"doc.command.set-inline-format",type:a.CommandType.COMMAND,handler:async(r,e)=>{const{segmentId:t,value:n,preCommandId:i}=e,s=r.get(a.IUndoRedoService),o=r.get(a.ICommandService),c=r.get(h.TextSelectionManagerService),l=r.get(a.IUniverInstanceService),u=c.getSelections();if(!Array.isArray(u)||u.length===0)return!1;let d=l.getCurrentUniverDocInstance(),g=d.getUnitId();g===a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&(d=l.getUniverDocInstance(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),g=d.getUnitId());let f;switch(i){case G.id:case q.id:case Z.id:case J.id:case A.id:case V.id:{f=bt(d.getBody().textRuns,i,u);break}case W.id:case H.id:{f=n;break}case Q.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 a.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:t}),m.params.mutations.push({t:"r",body:D,len:x-O,segmentId:t}),p.reset(),p.moveCursor(x)}const S=o.syncExecuteCommand(m.id,m.params),_=[G.id,W.id,H.id,A.id,V.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 o.syncExecuteCommand(v.id,S),_.includes(i)&&c.refreshSelection(),!0},redo(){return o.syncExecuteCommand(v.id,m.params),_.includes(i)&&c.refreshSelection(),!0}}),!0):!1}};function Tt(r){return r!==null&&typeof r=="object"}function bt(r,e,t){let n=0,i=0;const s=qe[e];for(;n!==r.length&&i!==t.length;){const{startOffset:o,endOffset:c}=t[i],{st:l,ed:u,ts:d}=r[n];if(c<=l)i++;else if(u<=o)n++;else{if((d==null?void 0:d[s])==null){if(/bl|it/.test(s))return a.BooleanNumber.TRUE;if(/ul|st/.test(s))return{s:a.BooleanNumber.TRUE};if(/va/.test(s))return e===A.id?a.BaselineOffset.SUBSCRIPT:a.BaselineOffset.SUPERSCRIPT}if(Tt(d==null?void 0:d[s])&&d[s].s===a.BooleanNumber.FALSE)return{s:a.BooleanNumber.TRUE};if(e===A.id&&(d==null?void 0:d[s])!==a.BaselineOffset.SUBSCRIPT)return a.BaselineOffset.SUBSCRIPT;if(e===V.id&&(d==null?void 0:d[s])!==a.BaselineOffset.SUPERSCRIPT)return a.BaselineOffset.SUPERSCRIPT;if((d==null?void 0:d[s])===a.BooleanNumber.FALSE)return a.BooleanNumber.TRUE;n++}}return/bl|it/.test(s)?a.BooleanNumber.FALSE:/ul|st/.test(s)?{s:a.BooleanNumber.FALSE}:a.BaselineOffset.NORMAL}const Ze={id:"doc.command.bullet-list",type:a.CommandType.COMMAND,handler:r=>r.get(a.ICommandService).syncExecuteCommand(Be.id,{listType:a.PresetListType.BULLET_LIST})},Je={id:"doc.command.order-list",type:a.CommandType.COMMAND,handler:r=>r.get(a.ICommandService).syncExecuteCommand(Be.id,{listType:a.PresetListType.ORDER_LIST})},Be={id:"doc.command.list-operation",type:a.CommandType.COMMAND,handler:(r,e)=>{var x;const t=r.get(h.TextSelectionManagerService),n=r.get(a.IUniverInstanceService),i=r.get(a.ICommandService),s=r.get(a.IUndoRedoService),{listType:o}=e,c=n.getCurrentUniverDocInstance(),l=t.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)===o}),p=6;let S=a.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===o?S=R.bullet.listId:U&&U.bullet&&U.bullet.listType===o&&(S=U.bullet.listId)}const _={id:v.id,params:{unitId:f,mutations:[]}},I=new a.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:o,listId:S}}]},segmentId:g,coverType:a.UpdateDocsAttributeType.REPLACE}),I.moveCursorTo(R+1)}const O=i.syncExecuteCommand(_.id,_.params);return t.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),t.refreshSelection(),!0},redo(){return i.syncExecuteCommand(v.id,_.params),t.refreshSelection(),!0}}),!0}};function xt(r,e){const{startOffset:t,endOffset:n}=r,i=[];let s=0;for(const o of e){const{startIndex:c}=o;(t>s&&t<=c||n>s&&n<=c||c>=t&&c<=n)&&i.push(o),s=c}return i}const Qe={id:"doc.command-replace-content",type:a.CommandType.COMMAND,handler:async(r,e)=>{var p;const{unitId:t,body:n,textRanges:i,segmentId:s=""}=e,o=r.get(a.IUniverInstanceService),c=r.get(a.ICommandService),l=r.get(h.TextSelectionManagerService),u=r.get(a.IUndoRedoService),d=(p=o.getUniverDocInstance(t))==null?void 0:p.getSnapshot().body,g=l.getSelections();if(d==null||!Array.isArray(g)||g.length===0)return!1;const f=tt(t,s,d,n),m=c.syncExecuteCommand(f.id,f.params);return l.replaceTextRanges(i),m?(u.pushUndoRedo({unitID:t,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:a.CommandType.COMMAND,handler:async(r,e)=>{var d;const{unitId:t,body:n,segmentId:i=""}=e,s=r.get(a.IUniverInstanceService),o=r.get(a.ICommandService),c=r.get(a.IUndoRedoService),l=(d=s.getUniverDocInstance(t))==null?void 0:d.getSnapshot().body;if(l==null)return!1;const u=tt(t,i,l,n);return o.syncExecuteCommand(u.id,u.params),c.clearUndoRedo(t),!0}};function tt(r,e,t,n){const i={id:v.id,params:{unitId:r,mutations:[]}},s=(t==null?void 0:t.dataStream.length)-2;return s>0&&i.params.mutations.push({t:"d",len:s,line:0,segmentId:e}),n.dataStream.length>0&&i.params.mutations.push({t:"i",body:n,len:n.dataStream.length,line:0,segmentId:e}),i}const B={id:"doc.operation.move-cursor",type:a.CommandType.OPERATION,handler:(r,e)=>!!e},$={id:"doc.operation.move-selection",type:a.CommandType.OPERATION,handler:(r,e)=>!!e},Ut=(r,e)=>{const t=r.get(a.IUniverInstanceService).getUniverDocInstance(e.unitId),n=(t==null?void 0:t.zoomRatio)||1;return{...a.Tools.deepClone(e),zoomRatio:n}},k={id:"doc.operation.set-zoom-ratio",type:a.CommandType.OPERATION,handler:(r,e)=>{const t=r.get(a.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}},nt={type:a.CommandType.COMMAND,id:"doc.command.set-zoom-ratio",handler:async(r,e)=>{const t=r.get(a.ICommandService),n=r.get(a.IUndoRedoService),i=r.get(a.IUniverInstanceService);let s=i.getCurrentUniverDocInstance().getUnitId(),o=1;if(e&&(s=e.documentId??s,o=e.zoomRatio??o),!i.getUniverDocInstance(s))return!1;const l={zoomRatio:o,unitId:s},u=Ut(r,l);return t.syncExecuteCommand(k.id,l)?(n.pushUndoRedo({unitID:s,undoMutations:[{id:k.id,params:u}],redoMutations:[{id:k.id,params:l}]}),!0):!1}},it={id:"doc.operation.select-all",type:a.CommandType.COMMAND,handler:async r=>{const e=r.get(a.IUniverInstanceService),t=r.get(h.TextSelectionManagerService),n=e.getCurrentUniverDocInstance().getSnapshot().body;if(n==null)return!1;const i=[{startOffset:0,endOffset:n.dataStream.length-2}];return t.replaceTextRanges(i),!0}},Et=10,Pt=6;function wt(){return a.Tools.generateRandomId(Pt)}function Nt(r){const e=r.match(/data-copy-id="([^\s]+)"/);return e&&e[1]?e[1]:null}class Lt{constructor(){C(this,"_cache",new a.LRUMap(Et))}set(e,t){this._cache.set(e,t)}get(e){return this._cache.get(e)}clear(){this._cache.clear()}}const rt=new Lt;function At(r){const e=r.style,t={};for(let n=0;n<e.length;n++){const i=e[n],s=e.getPropertyValue(i);switch(i){case"margin-top":{const o=parseInt(s);t.spaceAbove=/pt/.test(s)?$e(o):o;break}case"margin-bottom":{const o=parseInt(s);t.spaceBelow=/pt/.test(s)?$e(o):o;break}}}return Object.getOwnPropertyNames(t).length?t:null}function $e(r){return r/.75}function Fe(r){const e=r.style,t={},n=r.tagName.toLowerCase();switch(n){case"b":case"em":case"strong":{t.bl=a.BooleanNumber.TRUE;break}case"s":{t.st={s:a.BooleanNumber.TRUE};break}case"u":{t.ul={s:a.BooleanNumber.TRUE};break}case"i":{t.it=a.BooleanNumber.TRUE;break}case"sub":case"sup":{t.va=n==="sup"?a.BaselineOffset.SUPERSCRIPT:a.BaselineOffset.SUBSCRIPT;break}}for(let i=0;i<e.length;i++){const s=e[i],o=e.getPropertyValue(s);switch(s){case"font-family":{t.ff=o;break}case"font-size":{const c=parseInt(o);Number.isNaN(c)||(t.fs=/pt$/.test(o)?$e(c):c);break}case"font-style":{o==="italic"&&(t.it=a.BooleanNumber.TRUE);break}case"font-weight":{Number(o)>400&&(t.bl=a.BooleanNumber.TRUE);break}case"text-decoration":{/underline/.test(o)?t.ul={s:a.BooleanNumber.TRUE}:/overline/.test(o)?t.ol={s:a.BooleanNumber.TRUE}:/line-through/.test(o)&&(t.st={s:a.BooleanNumber.TRUE});break}case"color":{const c=new a.ColorKit(o);c.isValid&&(t.cl={rgb:c.toRgbString()});break}case"background-color":{const c=new a.ColorKit(o);c.isValid&&(t.bg={rgb:c.toRgbString()});break}}}return t}function Bt(r){const e=new DOMParser,t=`<x-univer id="univer-root">${r}</x-univer>`;return e.parseFromString(t,"text/html").querySelector("#univer-root")}function st(r,e){const t=r.tagName.toLowerCase();return typeof e=="string"?t===e:Array.isArray(e)?e.some(n=>n===t):e(r)}const De=class De{constructor(){C(this,"_styleCache",new Map);C(this,"_styleRules",[]);C(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=De._pluginList.find(s=>s.checkPasteType(e)),n=Bt(e),i={dataStream:"",textRuns:[]};return t&&(this._styleRules=[...t.stylesRules],this._afterProcessRules=[...t.afterProcessRules]),this._styleCache.clear(),this._process(null,n==null?void 0:n.childNodes,i),this._styleCache.clear(),this._styleRules=[],this._afterProcessRules=[],i}_process(e,t,n){var i;for(const s of t)if(s.nodeType===Node.TEXT_NODE){const o=(i=s.nodeValue)==null?void 0:i.replace(/[\r\n]/g,"");let c;e&&this._styleCache.has(e)&&(c=this._styleCache.get(e)),n.dataStream+=o,c&&Object.getOwnPropertyNames(c).length&&n.textRuns.push({st:n.dataStream.length-o.length,ed:n.dataStream.length,ts:c})}else if(s.nodeType===Node.ELEMENT_NODE){const o=e?this._styleCache.get(e):{},c=this._styleRules.find(({filter:g})=>st(s,g)),l=c?c.getStyle(s):Fe(s);this._styleCache.set(s,{...o,...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(De,"_pluginList",[]);let ee=De;const $t={name:"univer-doc-paste-plugin-lark",checkPasteType(r){return/lark-record-clipboard/i.test(r)},stylesRules:[{filter:["s"],getStyle(r){const e=Fe(r);return{st:{s:a.BooleanNumber.TRUE},...e}}}],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 e=Fe(r);return{bl:a.BooleanNumber.TRUE,...e}}}],afterProcessRules:[{filter(r){return r.tagName==="P"&&/mso/i.test(r.className)},handler(r,e){r.paragraphs==null&&(r.paragraphs=[]);const t={startIndex:r.dataStream.length},n=At(e);n&&(t.paragraphStyle=n),r.paragraphs.push(t),r.dataStream+="\r"}}]};function jt(r,e){const{st:t,ed:n,ts:i={}}=e,{ff:s,fs:o,it:c,bl:l,ul:u,st:d,ol:g,bg:f,cl:m,va:p}=i;let S=r.slice(t,n);const _=[];return c===a.BooleanNumber.TRUE&&(S=`<i>${S}</i>`),p===a.BaselineOffset.SUPERSCRIPT?S=`<sup>${S}</sup>`:p===a.BaselineOffset.SUBSCRIPT&&(S=`<sub>${S}</sub>`),(u==null?void 0:u.s)===a.BooleanNumber.TRUE&&(S=`<u>${S}</u>`),(d==null?void 0:d.s)===a.BooleanNumber.TRUE&&(S=`<s>${S}</s>`),l===a.BooleanNumber.TRUE&&(S=`<strong>${S}</strong>`),s&&_.push(`font-family: ${s}`),m&&_.push(`color: ${m.rgb}`),o&&_.push(`font-size: ${o}px`),g&&_.push("text-decoration: overline"),f&&_.push(`background: ${f.rgb}`),_.length?`<span style="${_.join(";")}">${S}</span>`:S}function at(r,e=!0){const{dataStream:t,textRuns:n=[],paragraphs:i=[]}=r;let s=0;const o=[],c=[];for(const l of n){const{st:u,ed:d}=l;if(u!==s&&o.push(t.slice(s,u)),o.push(jt(t,l)),s=d,e)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(";")}"`:""}>${o.join("")}</p>`),o.length=0}}}return c.join("")+o.join("")}class Vt{convert(e){if(e.length===0)throw new Error("The bodyList length at least to be 1");if(e.length===1)return at(e[0]);let t="";for(const n of e)t+='<p className="UniverNormal">',t+=at(n,!1),t+="</p>";return t}}var kt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Gt=(r,e,t,n)=>{for(var i=n>1?void 0:n?zt(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&kt(e,t,i),i},ot=(r,e)=>(t,n)=>e(t,n,r);ee.use(Ft),ee.use($t);function Wt(r){const e=r.replace(/\n/g,"\r"),t=[];for(let n=0;n<e.length;n++)e[n]==="\r"&&t.push({startIndex:n});return{dataStream:e,paragraphs:t}}const ct=b.createIdentifier("doc.clipboard-service");let je=class extends a.Disposable{constructor(e,t){super();C(this,"_clipboardHooks",[]);C(this,"_htmlToUDM",new ee);C(this,"_umdToHtml",new Vt);this._currentUniverService=e,this._clipboardInterfaceService=t}async queryClipboardData(){const e=await this._clipboardInterfaceService.read();if(e.length===0)return Promise.reject();try{let t="",n="";for(const s of e)for(const o of s.types)o===T.PLAIN_TEXT_CLIPBOARD_MIME_TYPE?n=await s.getType(o).then(c=>c&&c.text()):o===T.HTML_CLIPBOARD_MIME_TYPE&&(t=await s.getType(o).then(c=>c&&c.text()));if(!t)return Wt(n);const i=Nt(t);if(i){const s=rt.get(i);if(s)return s}return this._htmlToUDM.convert(t)}catch(t){return Promise.reject(t)}}async setClipboardData(e){const t=wt(),n=e.length>1?e.map(s=>s.dataStream).join(`
2
+ `):e[0].dataStream;let i=this._umdToHtml.convert(e);return e.length===1&&(i=i.replace(/(<[a-z]+)/,(s,o)=>`${o} data-copy-id="${t}"`),rt.set(t,e[0])),this._clipboardInterfaceService.write(n,i)}addClipboardHook(e){return this._clipboardHooks.push(e),a.toDisposable(()=>{const t=this._clipboardHooks.indexOf(e);t>-1&&this._clipboardHooks.splice(t,1)})}};je=Gt([ot(0,a.IUniverInstanceService),ot(1,T.IClipboardInterfaceService)],je);var Ht=Object.defineProperty,Kt=Object.getOwnPropertyDescriptor,Yt=(r,e,t,n)=>{for(var i=n>1?void 0:n?Kt(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Ht(e,t,i),i},K=(r,e)=>(t,n)=>e(t,n,r);let fe=class extends a.Disposable{constructor(r,e,t,n,i,s){super(),this._logService=r,this._commandService=e,this._currentUniverService=t,this._docClipboardService=n,this._textSelectionManagerService=i,this._contextService=s,this._commandExecutedListener(),this.initialize()}initialize(){[de,ue,me].forEach(r=>this.disposeWithMe(this._commandService.registerAsMultipleCommand(r))),[Ye,ge].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_commandExecutedListener(){const r=[ue.id,de.id,me.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(r.includes(e.id)&&!(!this._contextService.getContextValue(a.FOCUSING_DOC)&&!this._contextService.getContextValue(a.FOCUSING_EDITOR)))switch(e.id){case me.id:{this._handlePaste();break}case de.id:{this._handleCopy();break}case ue.id:{this._handleCut();break}default:throw new Error(`Unhandled command ${e.id}`)}}))}async _handlePaste(){const{_docClipboardService:r}=this,{segmentId:e,endOffset:t,style:n}=this._textSelectionManagerService.getActiveRange()??{},i=this._textSelectionManagerService.getSelections();if(e==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),!(t==null||i==null))try{const s=await r.queryClipboardData();let o=t;for(const l of i){const{startOffset:u,endOffset:d}=l;u==null||d==null||d<=t&&(o+=s.dataStream.length-(d-u))}const c=[{startOffset:o,endOffset:o,style:n}];this._commandService.executeCommand(Ye.id,{body:s,segmentId:e,textRanges:c})}catch{this._logService.error("[DocClipboardController] clipboard is empty")}}_getDocumentBodyInRanges(){const r=this._textSelectionManagerService.getSelections(),e=this._currentUniverService.getCurrentUniverDocInstance(),{dataStream:t,textRuns:n=[],paragraphs:i=[]}=e.getBody(),s=[];if(r==null)return s;for(const o of r){const{startOffset:c,endOffset:l,collapsed:u}=o;if(u||c==null||l==null)continue;const d={dataStream:t.slice(c,l)},g=[];for(const m of n){const p=a.Tools.deepClone(m),{st:S,ed:_}=p;a.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(a.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,e=this._getDocumentBodyInRanges();try{r.setClipboardData(e)}catch{this._logService.error("[DocClipboardController] set clipboard failed")}}async _handleCut(){const{segmentId:r,endOffset:e,style:t}=this._textSelectionManagerService.getActiveRange()??{},n=this._textSelectionManagerService.getSelections();if(r==null&&this._logService.error("[DocClipboardController] segmentId is not existed"),!(e==null||n==null)){this._handleCopy();try{let i=e;for(const o of n){const{startOffset:c,endOffset:l}=o;c==null||l==null||l<=e&&(i-=l-c)}const s=[{startOffset:i,endOffset:i,style:t}];this._commandService.executeCommand(ge.id,{segmentId:r,textRanges:s})}catch{this._logService.error("[DocClipboardController] cut content failed")}}}};fe=Yt([a.OnLifecycle(a.LifecycleStages.Rendered,fe),K(0,a.ILogService),K(1,a.ICommandService),K(2,a.IUniverInstanceService),K(3,ct),K(4,b.Inject(h.TextSelectionManagerService)),K(5,a.IContextService)],fe);var Xt=Object.defineProperty,qt=Object.getOwnPropertyDescriptor,Zt=(r,e,t,n)=>{for(var i=n>1?void 0:n?qt(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Xt(e,t,i),i},Ve=(r,e)=>(t,n)=>e(t,n,r);let he=class extends a.RxDisposable{constructor(r,e,t){super(),this._docSkeletonManagerService=r,this._renderManagerService=e,this._commandService=t,this._initialRenderRefresh(),this._commandExecutedListener()}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeletonBefore$.pipe(j.takeUntil(this.dispose$)).subscribe(r=>{if(r==null)return;const{skeleton:e,unitId:t}=r,n=this._renderManagerService.getRenderById(t);if(n==null)return;const{mainComponent:i}=n;i.changeSkeleton(e),this._recalculateSizeBySkeleton(n,e)})}_recalculateSizeBySkeleton(r,e){var u;const{mainComponent:t,scene:n}=r,i=t,s=(u=e.getSkeletonData())==null?void 0:u.pages;if(s==null)return;let o=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),o=Math.max(o,m)):i.pageLayoutType===M.PageLayoutType.HORIZONTAL&&(o+=m,d!==g-1&&(o+=i.pageMarginLeft),c=Math.max(c,p))}i.resize(o,c),[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(r.unitId)||n.resize(o,c)}_commandExecutedListener(){const r=[v.id],e=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(r.includes(t.id)){const i=t.params,{unitId:s}=i,o=this._docSkeletonManagerService.getSkeletonByUnitId(s);if(o==null)return;const{skeleton:c}=o,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)}}))}};he=Zt([a.OnLifecycle(a.LifecycleStages.Rendered,he),Ve(0,b.Inject(h.DocSkeletonManagerService)),Ve(1,M.IRenderManagerService),Ve(2,a.ICommandService)],he);var Jt=Object.defineProperty,Qt=Object.getOwnPropertyDescriptor,en=(r,e,t,n)=>{for(var i=n>1?void 0:n?Qt(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Jt(e,t,i),i},te=(r,e)=>(t,n)=>e(t,n,r);let pe=class extends a.Disposable{constructor(e,t,n,i,s){super();C(this,"_liquid",new M.Liquid);C(this,"_pageMarginCache",new Map);this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._commandService=i,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:i}=t,s=this._renderManagerService.getRenderById(n);if(s==null)return;const{mainComponent:o,components:c,scene:l}=s,u=o,{left:d,top:g}=u;e.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(),o==null||o.makeDirty()})}_initialRenderRefresh(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{skeleton:t,unitId:n}=e,i=this._renderManagerService.getRenderById(n);if(i==null)return;const{mainComponent:s}=i;s.changeSkeleton(t),this._refreshFloatingObject(n,t,i)})}_commandExecutedListener(){const e=[v.id,k.id],t=[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY];this.disposeWithMe(this._commandService.onCommandExecuted(n=>{var i;if(e.includes(n.id)){const s=n.params,{unitId:o}=s,c=this._docSkeletonManagerService.getCurrent();if(c==null)return;const{unitId:l,skeleton:u}=c;if(o!==l)return;const d=this._renderManagerService.getRenderById(l);if(d==null)return;if(t.includes(l)){(i=d.mainComponent)==null||i.makeDirty();return}this._refreshFloatingObject(l,u,d)}}))}_refreshFloatingObject(e,t,n){const i=t==null?void 0:t.getSkeletonData(),{mainComponent:s,scene:o}=n,c=s;if(!i)return;const{left:l,top:u,pageLayoutType:d,pageMarginLeft:g,pageMarginTop:f}=c,{pages:m}=i,p=[];o.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:e,subComponentId:a.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)}};pe=en([a.OnLifecycle(a.LifecycleStages.Steady,pe),te(0,b.Inject(h.DocSkeletonManagerService)),te(1,a.IUniverInstanceService),te(2,M.IRenderManagerService),te(3,a.ICommandService),te(4,a.IFloatingObjectManagerService)],pe);var tn=Object.defineProperty,nn=Object.getOwnPropertyDescriptor,rn=(r,e,t,n)=>{for(var i=n>1?void 0:n?nn(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&tn(e,t,i),i},Y=(r,e)=>(t,n)=>e(t,n,r);let Se=class extends a.Disposable{constructor(e,t,n,i,s,o){super();C(this,"_previousIMEContent","");C(this,"_previousIMERange");C(this,"_onStartSubscription");C(this,"_onUpdateSubscription");C(this,"_onEndSubscription");this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._textSelectionRenderManager=i,this._imeInputManagerService=s,this._commandService=o,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(a.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 p;const n=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(this._previousIMERange==null||e==null||n==null)return;const i=this._currentUniverService.getCurrentUniverDocInstance(),{event:s,activeRange:o}=e,{startOffset:c,segmentId:l,style:u}=this._previousIMERange;if(n==null||o==null)return;const g=s.data;if(g===this._previousIMEContent&&t)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:!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 X(this._currentUniverService,this._renderManagerService)}};Se=rn([a.OnLifecycle(a.LifecycleStages.Rendered,Se),Y(0,b.Inject(h.DocSkeletonManagerService)),Y(1,a.IUniverInstanceService),Y(2,M.IRenderManagerService),Y(3,M.ITextSelectionRenderManager),Y(4,b.Inject(Ne)),Y(5,a.ICommandService)],Se);var sn=Object.defineProperty,an=Object.getOwnPropertyDescriptor,on=(r,e,t,n)=>{for(var i=n>1?void 0:n?an(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&sn(e,t,i),i},lt=(r,e)=>(t,n)=>e(t,n,r);let _e=class extends a.Disposable{constructor(r,e){super(),this._textSelectionManagerService=r,this._commandService=e,this._commandExecutedListener()}_commandExecutedListener(){const r=[G.id,q.id,Z.id,J.id,A.id,V.id,W.id,H.id,Q.id];this.disposeWithMe(this._commandService.onCommandExecuted(e=>{r.includes(e.id)&&this._handleInlineFormat(e)}))}_handleInlineFormat(r){const{segmentId:e}=this._textSelectionManagerService.getActiveRange()??{};e!=null&&this._commandService.executeCommand(Ae.id,{segmentId:e,preCommandId:r.id,...r.params??{}})}};_e=on([a.OnLifecycle(a.LifecycleStages.Rendered,_e),lt(0,b.Inject(h.TextSelectionManagerService)),lt(1,a.ICommandService)],_e);var cn=Object.defineProperty,ln=Object.getOwnPropertyDescriptor,dn=(r,e,t,n)=>{for(var i=n>1?void 0:n?ln(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&cn(e,t,i),i},ne=(r,e)=>(t,n)=>e(t,n,r);let ve=class extends a.Disposable{constructor(e,t,n,i,s){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._textSelectionManagerService=i,this._commandService=s,this._initialize(),this._commandExecutedListener()}dispose(){var e;(e=this._onInputSubscription)==null||e.unsubscribe()}_initialize(){}_commandExecutedListener(){const e=[B.id,$.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(!e.includes(t.id))return;const n=t.params;switch(t.id){case B.id:return this._handleMoveCursor(n.direction);case $.id:return this._handleShiftMoveSelection(n.direction);default:throw new Error("Unknown command")}}))}_handleShiftMoveSelection(e){var S;const t=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),i=this._currentUniverService.getCurrentUniverDocInstance(),s=(S=this._docSkeletonManagerService.getCurrent())==null?void 0:S.skeleton,o=this._getDocObject();if(t==null||s==null||o==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d,direction:g}=t;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:e===a.Direction.LEFT||e===a.Direction.UP?I:_,endOffset:e===a.Direction.LEFT||e===a.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(e===a.Direction.LEFT||e===a.Direction.RIGHT){const _=s.findNodeByCharIndex(m-1),I=s.findNodeByCharIndex(m);m=e===a.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=o.document.getOffsetConfig(),O=this._getTopOrBottomPosition(s,_,e===a.Direction.DOWN);if(O==null){const D=e===a.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(e){var f;const t=this._textSelectionManagerService.getActiveRange(),n=this._textSelectionManagerService.getSelections(),i=this._currentUniverService.getCurrentUniverDocInstance(),s=(f=this._docSkeletonManagerService.getCurrent())==null?void 0:f.skeleton,o=this._getDocObject();if(t==null||s==null||o==null||n==null)return;const{startOffset:c,endOffset:l,style:u,collapsed:d}=t,g=i.getBody().dataStream.length??1/0;if(e===a.Direction.LEFT||e===a.Direction.RIGHT){let m;if(!t.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=e===a.Direction.LEFT?p:S}else{const p=s.findNodeByCharIndex(c-1),S=s.findNodeByCharIndex(c);e===a.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=o.document.getOffsetConfig(),_=this._getTopOrBottomPosition(s,e===a.Direction.UP?m:p,e===a.Direction.DOWN);if(_==null){let O;d?O=e===a.Direction.UP?0:g-2:O=e===a.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(e,t,n){if(t==null)return;const i=this._getSpanLeftOffsetInLine(t),s=this._getNextOrPrevLine(t,n);if(s==null)return;const o=this._matchPositionByLeftOffset(e,s,i);if(o!=null)return{...o,isBack:!0}}_getSpanLeftOffsetInLine(e){const t=e.parent;if(t==null)return-1/0;const n=t.left,{left:i}=e;return n+i}_matchPositionByLeftOffset(e,t,n){const i={distance:1/0};for(const s of t.divides){const o=s.left;for(const c of s.spanGroup){const{left:l}=c,u=o+l,d=Math.abs(n-u);d<i.distance&&(i.span=c,i.distance=d)}}if(i.span!=null)return e.findPositionBySpan(i.span)}_getNextOrPrevLine(e,t){var p,S,_,I,O,x,D,R,U,E,P,w;const n=e.parent;if(n==null)return;const i=n.parent;if(i==null)return;const s=i.parent;if(s==null)return;const o=s.lines.indexOf(i);if(o===-1)return;let c;if(t===!0?c=s.lines[o+1]:c=s.lines[o-1],c!=null)return c;const l=s.parent;if(l==null)return;const u=l.columns.indexOf(s);if(u===-1)return;if(t===!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(t===!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(t===!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 X(this._currentUniverService,this._renderManagerService)}};ve=dn([a.OnLifecycle(a.LifecycleStages.Rendered,ve),ne(0,b.Inject(h.DocSkeletonManagerService)),ne(1,a.IUniverInstanceService),ne(2,M.IRenderManagerService),ne(3,b.Inject(h.TextSelectionManagerService)),ne(4,a.ICommandService)],ve);var un=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,gn=(r,e,t,n)=>{for(var i=n>1?void 0:n?mn(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&un(e,t,i),i},ie=(r,e)=>(t,n)=>e(t,n,r);let Ce=class extends a.Disposable{constructor(e,t,n,i,s){super();C(this,"_onInputSubscription");this._docSkeletonManagerService=e,this._currentUniverService=t,this._renderManagerService=n,this._textSelectionRenderManager=i,this._commandService=s,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 p;if(e==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().getUnitId(),{event:i,content:s="",activeRange:o}=e,c=i,l=(p=this._docSkeletonManagerService.getCurrent())==null?void 0:p.skeleton;if(c.data==null||l==null||!l||!o)return;const{startOffset:u,segmentId:d,style:g}=o,f=s.length,m=[{startOffset:u+f,endOffset:u+f,style:g}];await this._commandService.executeCommand(ce.id,{unitId:n,body:{dataStream:s},range:o,textRanges:m,segmentId:d})})}_commandExecutedListener(){}_getDocObject(){return X(this._currentUniverService,this._renderManagerService)}};Ce=gn([a.OnLifecycle(a.LifecycleStages.Rendered,Ce),ie(0,b.Inject(h.DocSkeletonManagerService)),ie(1,a.IUniverInstanceService),ie(2,M.IRenderManagerService),ie(3,M.ITextSelectionRenderManager),ie(4,a.ICommandService)],Ce);var fn=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,pn=(r,e,t,n)=>{for(var i=n>1?void 0:n?hn(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&fn(e,t,i),i},dt=(r,e)=>(t,n)=>e(t,n,r);const Sn="rgba(198, 198, 198, 1)",_n="rgba(255, 255, 255, 1)";let Ie=class extends a.Disposable{constructor(r,e){super(),this._renderManagerService=r,this._currentUniverService=e,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 e=this._renderManagerService.getRenderById(r);if(e==null)return;const{mainComponent:t}=e,n=t,i=(s=n.getSkeleton())==null?void 0:s.getPageSize();n.onPageRenderObservable.add(o=>{if([a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(r))return;const{page:c,pageLeft:l,pageTop:u,ctx:d}=o,{width:g,pageWidth:f,height:m,pageHeight:p}=c;d.save(),d.translate(l-.5,u-.5),M.Rect.drawWith(d,{width:(i==null?void 0:i.width)??f??g,height:(i==null?void 0:i.height)??p??m,strokeWidth:1,stroke:Sn,fill:_n,zIndex:3}),d.restore()})})}_commandExecutedListener(){}};Ie=pn([a.OnLifecycle(a.LifecycleStages.Rendered,Ie),dt(0,M.IRenderManagerService),dt(1,b.Inject(a.IUniverInstanceService))],Ie);var vn=Object.defineProperty,Cn=Object.getOwnPropertyDescriptor,In=(r,e,t,n)=>{for(var i=n>1?void 0:n?Cn(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&vn(e,t,i),i},z=(r,e)=>(t,n)=>e(t,n,r);let Me=class extends a.Disposable{constructor(e,t,n,i,s,o,c){super();C(this,"_moveInObserver");C(this,"_moveOutObserver");C(this,"_downObserver");C(this,"_dblClickObserver");C(this,"_tripleClickObserver");C(this,"_loadedMap",new Set);this._docSkeletonManagerService=e,this._currentUniverService=t,this._commandService=n,this._renderManagerService=i,this._textSelectionRenderManager=s,this._textSelectionManagerService=o,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(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))})}_initialMain(e){const t=this._getDocObjectById(e);if(t==null)return;const{document:n,scene:i}=t;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((s,o)=>{this._currentUniverService.getCurrentUniverDocInstance().getUnitId()!==e&&this._currentUniverService.setCurrentUniverDocInstance(e),this._textSelectionRenderManager.eventTrigger(s),s.button!==2&&o.stopPropagation()}),this._dblClickObserver=n==null?void 0:n.onDblclickObserver.add(s=>{this._textSelectionRenderManager.handleDblClick(s)}),this._tripleClickObserver=n==null?void 0:n.onTripleClickObserver.add(s=>{this._textSelectionRenderManager.handleTripleClick(s)})}_commandExecutedListener(){const e=[k.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{var n;if(e.includes(t.id)){const i=t.params,{unitId:s}=i,o=(n=this._textSelectionManagerService.getCurrentSelection())==null?void 0:n.unitId;if(s!==o)return;this._textSelectionManagerService.refreshSelection()}}))}_skeletonListener(){this._docSkeletonManagerService.currentSkeleton$.subscribe(e=>{if(e==null)return;const{unitId:t,skeleton:n}=e,i=this._renderManagerService.getRenderById(t);if(i==null)return;const{scene:s,mainComponent:o}=i;this._textSelectionRenderManager.changeRuntime(n,s,o),this._textSelectionManagerService.setCurrentSelectionNotRefresh({unitId:t,subUnitId:""})})}_getDocObjectById(e){return mt(e,this._renderManagerService)}};Me=In([a.OnLifecycle(a.LifecycleStages.Rendered,Me),z(0,b.Inject(h.DocSkeletonManagerService)),z(1,a.IUniverInstanceService),z(2,a.ICommandService),z(3,M.IRenderManagerService),z(4,M.ITextSelectionRenderManager),z(5,b.Inject(h.TextSelectionManagerService)),z(6,b.Optional(T.LayoutService))],Me);var Mn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,Rn=(r,e,t,n)=>{for(var i=n>1?void 0:n?On(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Mn(e,t,i),i},re=(r,e)=>(t,n)=>e(t,n,r);let Oe=class extends a.Disposable{constructor(e,t,n,i,s){super();C(this,"_initializedRender",new Set);this._docSkeletonManagerService=e,this._currentUniverService=t,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(e=>{if(e==null)return;const{unitId:t}=e,n=this._renderManagerService.getRenderById(t);if(n==null||this._initializedRender.has(t)||[a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY].includes(t))return;this._initializedRender.add(t);const{scene:i}=n;this.disposeWithMe(a.toDisposable(i.onMouseWheelObserver.add(s=>{if(!s.ctrlKey)return;const o=Math.abs(s.deltaX);let c=o<40?.2:o<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(a.toDisposable(this._docSkeletonManagerService.currentSkeletonBefore$.subscribe(e=>{if(e==null)return;const n=this._currentUniverService.getCurrentUniverDocInstance().zoomRatio||1;this._updateViewZoom(n,!1)})))}_commandExecutedListener(){const e=[k.id];this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(e.includes(t.id)){const n=this._currentUniverService.getCurrentUniverDocInstance(),i=t.params,{unitId:s}=i;if(s!==n.getUnitId())return;const o=n.zoomRatio||1;this._updateViewZoom(o)}}))}_updateViewZoom(e,t=!0){var i;const n=this._getDocObject();n!=null&&(n.scene.scale(e,e),this._calculatePagePosition(n,e),t&&this._textSelectionManagerService.refreshSelection(),(i=n.scene.getTransformer())==null||i.hideControl())}_calculatePagePosition(e,t){const{document:n,scene:i}=e,s=i==null?void 0:i.getParent(),{width:o,height:c,pageMarginLeft:l,pageMarginTop:u}=n;if(s==null||o===1/0||c===1/0)return;const{width:d,height:g}=s;let f=0,m=0,p=0,S=0,_=1/0;d>(o+l*2)*t?(f=d/2-o*t/2,f/=t,p=(d-l*2)/t,_=0):(f=l,p=o+l*2,_=(p-d/t)/2),g>c?(m=g/2-c/2,S=(g-u*2)/t):(m=u,S=c+u*2),i.resize(p,S+200),n.translate(f,m);const I=i.getViewport(ae.VIEW_MAIN);if(_!==1/0&&I!=null){const O=I.getBarScroll(_,0).x;I.scrollTo({x:O})}return this}_getDocObject(){return X(this._currentUniverService,this._renderManagerService)}};Oe=Rn([a.OnLifecycle(a.LifecycleStages.Rendered,Oe),re(0,b.Inject(h.DocSkeletonManagerService)),re(1,a.IUniverInstanceService),re(2,a.ICommandService),re(3,M.IRenderManagerService),re(4,b.Inject(h.TextSelectionManagerService))],Oe);const yn={id:Ue.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:T.KeyCode.ENTER},Dn={id:Ee.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:T.KeyCode.BACKSPACE},Tn={id:Pe.id,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),binding:T.KeyCode.DELETE},bn={id:B.id,binding:T.KeyCode.ARROW_UP,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},xn={id:B.id,binding:T.KeyCode.ARROW_DOWN,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},Un={id:B.id,binding:T.KeyCode.ARROW_LEFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},En={id:B.id,binding:T.KeyCode.ARROW_RIGHT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},Pn={id:$.id,binding:T.KeyCode.ARROW_UP|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.UP}},wn={id:$.id,binding:T.KeyCode.ARROW_DOWN|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.DOWN}},Nn={id:$.id,binding:T.KeyCode.ARROW_LEFT|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.LEFT}},Ln={id:$.id,binding:T.KeyCode.ARROW_RIGHT|T.MetaKeys.SHIFT,preconditions:r=>r.getContextValue(a.FOCUSING_DOC),staticParameters:{direction:a.Direction.RIGHT}},An={id:it.id,binding:T.KeyCode.A|T.MetaKeys.CTRL_COMMAND,preconditions:r=>r.getContextValue(a.FOCUSING_DOC)||r.getContextValue(a.FOCUSING_EDITOR)};var Bn=Object.defineProperty,$n=Object.getOwnPropertyDescriptor,Fn=(r,e,t,n)=>{for(var i=n>1?void 0:n?$n(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&Bn(e,t,i),i},Re=(r,e)=>(t,n)=>e(t,n,r);h.DocCanvasView=class extends a.RxDisposable{constructor(t,n,i,s){super();C(this,"_scene");C(this,"_currentDocumentModel");C(this,"_loadedMap",new Set);C(this,"_fps$",new j.BehaviorSubject(""));C(this,"fps$",this._fps$.asObservable());this._renderManagerService=t,this._configService=n,this._currentUniverService=i,this._docViewModelManagerService=s,this._initialize()}_initialize(){this._currentUniverService.currentDoc$.subscribe(t=>{if(t==null)return;this._currentDocumentModel=t;const n=t.getUnitId();this._docViewModelManagerService.setCurrent(n),this._loadedMap.has(n)||(this._addNewRender(),this._loadedMap.add(n))})}dispose(){this._fps$.complete()}_addNewRender(){const t=this._currentDocumentModel,n=t.getUnitId(),i=t.getContainer(),s=t.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 o=this._renderManagerService.getRenderById(n);if(o==null)return;const{scene:c,engine:l}=o;c.openTransformer(),this._scene=c;const u=new M.Viewport(ae.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!==a.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY&&new M.ScrollBar(u),c.addLayer(new M.Layer(c,[],Te),new M.Layer(c,[],ze)),this._addComponent(o),this._currentDocumentModel.getShouldRenderLoopImmediately()&&l.runRenderLoop(()=>{c.render(),this._fps$.next(Math.round(l.getFps()).toString())}),this._renderManagerService.setCurrent(n)}_addComponent(t){const n=this._scene,i=this._currentDocumentModel,s=new M.Documents(se.MAIN,void 0,{pageMarginLeft:i.documentStyle.marginLeft||0,pageMarginTop:i.documentStyle.marginTop||0});s.zIndex=Ge,t.mainComponent=s,t.components.set(se.MAIN,s),n.addObjects([s],Te)}},h.DocCanvasView=Fn([a.OnLifecycle(a.LifecycleStages.Ready,h.DocCanvasView),Re(0,M.IRenderManagerService),Re(1,a.IConfigService),Re(2,a.IUniverInstanceService),Re(3,b.Inject(h.DocViewModelManagerService))],h.DocCanvasView);var jn=Object.defineProperty,Vn=Object.getOwnPropertyDescriptor,kn=(r,e,t,n)=>{for(var i=n>1?void 0:n?Vn(e,t):e,s=r.length-1,o;s>=0;s--)(o=r[s])&&(i=(n?o(e,t,i):o(i))||i);return n&&i&&jn(e,t,i),i},ye=(r,e)=>(t,n)=>e(t,n,r);const zn={hasScroll:!0},Gn="docs";h.UniverDocsPlugin=(ke=class extends a.Plugin{constructor(t={},n,i,s,o){super(Gn);C(this,"_config");this._injector=n,this._localeService=i,this._configService=s,this._currentUniverService=o,this._config=Object.assign(zn,t),this._initializeDependencies(n),this._initializeCommands()}initialize(){}_initializeCommands(){[B,$,Ee,Pe,G,q,Z,J,A,V,W,H,Q,Ae,Ue,ce,le,xe,Le,we,v,Qe,et,nt,k,be,it,Je,Ze,Be].forEach(t=>{this._injector.get(a.ICommandService).registerCommand(t)}),[bn,xn,En,Un,Pn,wn,Nn,Ln,An,Dn,Tn,yn].forEach(t=>{this._injector.get(T.IShortcutService).registerShortcut(t)})}onReady(){this.initialize()}_initializeDependencies(t){[[h.DocCanvasView],[h.DocSkeletonManagerService],[h.DocViewModelManagerService],[Ne],[ct,{useClass:je}],[M.ITextSelectionRenderManager,{useClass:M.TextSelectionRenderManager}],[h.TextSelectionManagerService],[he],[Ie],[Me],[Ce],[Se],[_e],[fe],[ve],[Oe],[pe]].forEach(n=>t.add(n))}},C(ke,"type",a.PluginType.Doc),ke),h.UniverDocsPlugin=kn([ye(1,b.Inject(b.Injector)),ye(2,b.Inject(a.LocaleService)),ye(3,a.IConfigService),ye(4,a.IUniverInstanceService)],h.UniverDocsPlugin),h.BreakLineCommand=Ue,h.BulletListCommand=Ze,h.CoverContentCommand=et,h.DOCS_COMPONENT_DEFAULT_Z_INDEX=Ge,h.DOCS_COMPONENT_HEADER_LAYER_INDEX=ze,h.DOCS_COMPONENT_MAIN_LAYER_INDEX=Te,h.DOCS_VIEW_KEY=se,h.DeleteCommand=le,h.DeleteLeftCommand=Ee,h.DeleteRightCommand=Pe,h.DocCopyCommand=de,h.DocCutCommand=ue,h.DocPasteCommand=me,h.IMEInputCommand=Le,h.InsertCommand=ce,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=H,h.SetInlineFormatFontSizeCommand=W,h.SetInlineFormatItalicCommand=q,h.SetInlineFormatStrikethroughCommand=J,h.SetInlineFormatSubscriptCommand=A,h.SetInlineFormatSuperscriptCommand=V,h.SetInlineFormatTextColorCommand=Q,h.SetInlineFormatUnderlineCommand=Z,h.SetTextSelectionsOperation=be,h.UpdateCommand=xe,h.VIEWPORT_KEY=ae,h.getDocObject=X,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.2",
3
+ "version": "0.1.0-beta.0",
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
- "@ctrl/tinycolor": "^4.0.2",
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.7",
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.2",
45
- "@univerjs/engine-render": "0.1.0-alpha.2",
46
- "@univerjs/core": "0.1.0-alpha.2",
47
- "@univerjs/sheets": "0.1.0-alpha.2",
48
- "@univerjs/ui": "0.1.0-alpha.2"
43
+ "vitest": "^1.0.4",
44
+ "@univerjs/engine-render": "0.1.0-beta.0",
45
+ "@univerjs/core": "0.1.0-beta.0",
46
+ "@univerjs/sheets": "0.1.0-beta.0",
47
+ "@univerjs/ui": "0.1.0-beta.0"
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/core": "0.1.0-alpha.2",
55
- "@univerjs/engine-render": "0.1.0-alpha.2",
56
- "@univerjs/sheets": "0.1.0-alpha.2",
57
- "@univerjs/ui": "0.1.0-alpha.2"
52
+ "@univerjs/core": "0.1.0-beta.0",
53
+ "@univerjs/engine-render": "0.1.0-beta.0",
54
+ "@univerjs/ui": "0.1.0-beta.0",
55
+ "@univerjs/sheets": "0.1.0-beta.0"
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
- }