@univerjs/docs 0.1.0-beta.4 → 0.1.1

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