(function(t,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("@univerjs/core"),require("@univerjs/docs-ui"),require("@univerjs/engine-render")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-ui","@univerjs/engine-render"],e):(t=typeof globalThis<"u"?globalThis:t||self,e(t.UniverDocsUiFacade={},t.UniverCore,t.UniverDocsUi,t.UniverEngineRender))})(this,function(t,e,a,m){"use strict";var f=Object.defineProperty;var D=(t,e,a)=>e in t?f(t,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[e]=a;var v=(t,e,a)=>D(t,typeof e!="symbol"?e+"":e,a);var h=Object.defineProperty,_=Object.getOwnPropertyDescriptor,I=(u,n,i,r)=>{for(var s=r>1?void 0:r?_(n,i):n,c=u.length-1,o;c>=0;c--)(o=u[c])&&(s=(r?o(n,i,s):o(s))||s);return r&&s&&h(n,i,s),s},d=(u,n)=>(i,r)=>n(i,r,u);t.FDocument=class{constructor(n,i,r,s,c,o){v(this,"id");this._documentDataModel=n,this._injector=i,this._univerInstanceService=r,this._commandService=s,this._resourceManagerService=c,this._renderManagerService=o,this.id=this._documentDataModel.getUnitId()}getId(){return this._documentDataModel.getUnitId()}getName(){return this.getSnapshot().title||""}getSnapshot(){const n=this._resourceManagerService.getResourcesByType(this.id,e.UniverInstanceType.UNIVER_DOC),i=this._documentDataModel.getSnapshot();return i.resources=n,i}undo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(e.UndoCommand.id)}redo(){return this._univerInstanceService.focusUnit(this.id),this._commandService.executeCommand(e.RedoCommand.id)}appendText(n){const i=this.id,{body:r}=this.getSnapshot();if(!r)throw new Error("The document body is empty");const s=r.dataStream.length-2,c={startOffset:s,endOffset:s,collapsed:!0,segmentId:""},{segmentId:o}=c;return this._commandService.executeCommand(a.InsertCommand.id,{unitId:i,body:{dataStream:n},range:c,segmentId:o})}setSelection(n,i){var s;const r=(s=this._renderManagerService.getRenderById(this.getId()))==null?void 0:s.with(a.DocSelectionRenderService);r==null||r.removeAllRanges(),r==null||r.addDocRanges([{startOffset:n,endOffset:i,rangeType:e.DOC_RANGE_TYPE.TEXT}],!0)}},t.FDocument=I([d(1,e.Inject(e.Injector)),d(2,e.IUniverInstanceService),d(3,e.ICommandService),d(4,e.IResourceManagerService),d(5,m.IRenderManagerService)],t.FDocument);class g extends e.FUniver{createUniverDoc(n){const i=this._univerInstanceService.createUnit(e.UniverInstanceType.UNIVER_DOC,n);return this._injector.createInstance(t.FDocument,i)}getActiveDocument(){const n=this._univerInstanceService.getCurrentUnitForType(e.UniverInstanceType.UNIVER_DOC);return n?this._injector.createInstance(t.FDocument,n):null}getUniverDoc(n){const i=this._univerInstanceService.getUniverDocInstance(n);return i?this._injector.createInstance(t.FDocument,i):null}}e.FUniver.extend(g),Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});