@univerjs/sheets-drawing-ui 0.10.7 → 0.10.8-nightly.202509200616
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -1
- package/lib/es/index.js +2 -1
- package/lib/index.js +2 -1
- package/lib/umd/index.js +1 -1
- package/package.json +13 -13
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"use strict";var kt=Object.defineProperty;var Wt=(s,r,t)=>r in s?kt(s,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[r]=t;var te=(s,r,t)=>Wt(s,typeof r!="symbol"?r+"":r,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("@univerjs/engine-render"),E=require("@univerjs/sheets-ui"),l=require("@univerjs/core"),m=require("@univerjs/sheets-drawing"),y=require("@univerjs/sheets"),q=require("@univerjs/design"),ze=require("@univerjs/docs-ui"),j=require("@univerjs/drawing"),W=require("@univerjs/ui"),Rt=require("@univerjs/docs-drawing"),le=require("@univerjs/drawing-ui"),A=require("rxjs"),Z=require("react/jsx-runtime"),Ie=require("react");function K(s,r,t){const{from:e,to:n,flipY:i=!1,flipX:o=!1,angle:a=0,skewX:d=0,skewY:g=0}=s,u=t.getCurrent();if(u==null)return;const c=E.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:f,height:w}=c;const S=t.getCurrentSkeleton(),_=S.rowHeaderWidth+S.columnTotalWidth,I=S.columnHeaderHeight+S.rowTotalHeight;return p+f>_&&(p=_-f),h+w>I&&(h=I-w),{flipY:i,flipX:o,angle:a,skewX:d,skewY:g,left:p,top:h,width:f,height:w}}function x(s,r){const{left:t=0,top:e=0,width:n=0,height:i=0,flipY:o=!1,flipX:a=!1,angle:d=0,skewX:g=0,skewY:u=0}=s,c=r.getCellWithCoordByOffset(t,e);if(c==null)return;const p={column:c.actualColumn,columnOffset:k.precisionTo(t-c.startX,1),row:c.actualRow,rowOffset:k.precisionTo(e-c.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+i);if(h==null)return;const f={column:h.actualColumn,columnOffset:k.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:k.precisionTo(e+i-h.startY,1)};return{flipY:o,flipX:a,angle:d,skewX:g,skewY:u,from:p,to:f}}const G={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(s,r)=>{const t=s.get(k.IRenderManagerService);return r.forEach(e=>{var n,i;(i=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||i.debounceRefreshControls()}),!0}},De={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(s,r)=>{var I,C,R;const t=s.get(l.ICommandService),e=s.get(l.IUndoRedoService),n=s.get(y.SheetInterceptorService),i=s.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=[];o.forEach(D=>{const{unitId:M}=D;a.push(M)});const d=i.getBatchRemoveOp(o),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=n.onCommandExecute({id:De.id,params:r}),w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},S={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:c,objects:h,type:m.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=f.preRedos)!=null?I:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=f.preUndos)!=null?C:[],S,...f.undos,{id:G.id,params:a}],redoMutations:[...(R=f.preRedos)!=null?R:[],w,...f.redos,{id:G.id,params:a}]}),!0):!1}},ut={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:s=>{const r=s.get(l.ICommandService),e=s.get(m.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,i=e.map(o=>{const{unitId:a,subUnitId:d,drawingId:g,drawingType:u}=o;return{unitId:a,subUnitId:d,drawingId:g,drawingType:u}});return r.executeCommand(De.id,{unitId:n,drawings:i})}};function Bt(s){const r=[];return s.forEach(t=>{const{parent:e,children:n}=t,{unitId:i,subUnitId:o,drawingId:a}=e,d=k.getGroupState(0,0,n.map(c=>c.transform||{})),g=n.map(c=>{const p=c.transform||{left:0,top:0},{unitId:h,subUnitId:f,drawingId:w}=c;return{unitId:h,subUnitId:f,drawingId:w,transform:{...p,left:p.left-d.left,top:p.top-d.top},groupId:a}}),u={unitId:i,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:u,children:g})}),r}function Yt(s){const r=[];return s.forEach(t=>{const{parent:e,children:n}=t,{unitId:i,subUnitId:o,drawingId:a,transform:d={width:0,height:0}}=e;if(d==null)return;const g=n.map(c=>{const{transform:p}=c,{unitId:h,subUnitId:f,drawingId:w}=c,S=k.transformObjectOutOfGroup(p||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:f,drawingId:w,transform:S,groupId:void 0}}),u={unitId:i,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const gt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(s,r)=>{const t=s.get(l.ICommandService),e=s.get(l.IUndoRedoService),n=s.get(m.ISheetDrawingService);if(!r)return!1;const i=[];r.forEach(({parent:h,children:f})=>{i.push(h.unitId),f.forEach(w=>{i.push(w.unitId)})});const o=n.getGroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:Yt(c),type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:i}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP}},{id:G.id,params:i}]}),!0):!1}},Ue={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(s,r)=>{var I,C,R;const t=s.get(l.ICommandService),e=s.get(l.IUndoRedoService),n=s.get(m.ISheetDrawingService),i=s.get(y.SheetInterceptorService);if(!r)return!1;const o=r.drawings,a=o.map(D=>D.unitId),d=n.getBatchAddOp(o),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,f=i.onCommandExecute({id:Ue.id,params:r}),w={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},S={id:m.SetDrawingApplyMutation.id,params:{op:c,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=f.preRedos)!=null?I:[],w,...f.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=f.preUndos)!=null?C:[],S,...f.undos,{id:G.id,params:a}],redoMutations:[...(R=f.preRedos)!=null?R:[],w,...f.redos,{id:G.id,params:a}]}),!0):!1}},ht={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(s,r)=>{const t=s.get(l.ICommandService),e=s.get(l.IUndoRedoService);if(!r)return!1;const n=s.get(m.ISheetDrawingService),{unitId:i,subUnitId:o,drawingIds:a,arrangeType:d}=r,g={unitId:i,subUnitId:o,drawingIds:a};let u;if(d===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):d===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):d===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):d===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:c,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:i,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:i,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:i,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:i,subUnitId:o,objects:c,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},Ae={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(s,r)=>{const t=s.get(l.ICommandService),e=s.get(l.IUndoRedoService),n=s.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:i}=r,o=n.getBatchUpdateOp(i),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:g,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[a]}]}),!0):!1}},pt={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(s,r)=>{const t=s.get(l.ICommandService),e=s.get(l.IUndoRedoService),n=s.get(m.ISheetDrawingService);if(!r)return!1;const i=[];r.forEach(({parent:h,children:f})=>{i.push(h.unitId),f.forEach(w=>{i.push(w.unitId)})});const o=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=o;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:Bt(c),type:m.DrawingApplyType.GROUP}},{id:G.id,params:i}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP}},{id:G.id,params:i}]}),!0):!1}};var Ft=Object.getOwnPropertyDescriptor,$t=(s,r,t,e)=>{for(var n=e>1?void 0:e?Ft(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},ne=(s,r)=>(t,e)=>r(t,e,s);function xt(s,r,t){const e=t*Math.PI/180,n=Math.abs(s*Math.cos(e))+Math.abs(r*Math.sin(e)),i=Math.abs(s*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:i}}function at(s,r,t,e,n){var I;const{rotatedHeight:i,rotatedWidth:o}=xt(t,e,n),d=s.get(k.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(I=d.with(E.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),p=c.mergeInfo.endX-c.mergeInfo.startX-2,h=c.mergeInfo.endY-c.mergeInfo.startY-2,f=o/i,S=Math.ceil(Math.min(p,h*f))/o,_=!S||Number.isNaN(S)?.001:S;return{width:t*_,height:e*_}}exports.SheetDrawingUpdateController=class extends l.Disposable{constructor(t,e,n,i,o,a,d,g,u,c,p,h,f){super();te(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=i,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=d,this._drawingManagerService=g,this._contextService=u,this._messageService=c,this._localeService=p,this._injector=f,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:j.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>j.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(j.DRAWING_IMAGE_COUNT_LIMIT))}),!1):e===0?!1:(t.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const e=(await this._fileOpenerService.openFile({multiple:!1,accept:j.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(C){const R=C.message;R===j.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(j.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):R===j.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:i,subUnitId:o}=n,{imageId:a,imageSourceType:d,source:g,base64Cache:u}=e,{width:c,height:p,image:h}=await j.getImageSize(u||""),{width:f,height:w}=this._context.scene;this._imageIoService.addImageSourceCache(g,d,h);let S=1;if(c>j.DRAWING_IMAGE_WIDTH_LIMIT||p>j.DRAWING_IMAGE_HEIGHT_LIMIT){const C=j.DRAWING_IMAGE_WIDTH_LIMIT/c,R=j.DRAWING_IMAGE_HEIGHT_LIMIT/p;S=Math.max(C,R)}const _=this._getImagePosition(c*S,p*S,f,w);if(_==null)return;const I={unitId:i,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:d,source:g,transform:K(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(Ue.id,{unitId:i,drawings:[I]})}async _insertCellImage(t,e){var R,D;let n;try{n=await this._imageIoService.saveImage(t)}catch(M){const v=M.message;v===j.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(j.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):v===j.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):v===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:i,imageSourceType:o,source:a,base64Cache:d}=n,{width:g,height:u,image:c}=await j.getImageSize(d||"");this._imageIoService.addImageSourceCache(a,o,c);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;let h=p.primary.actualRow,f=p.primary.actualColumn;p.primary.isMerged&&(h=p.primary.startRow,f=p.primary.startColumn);const w=l.createDocumentModelWithStyle("",{}),S=at(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:h,col:f},g,u,0);if(!S)return!1;const _={size:{width:S.width,height:S.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},I={unitId:w.getUnitId(),subUnitId:w.getUnitId(),drawingId:i,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:o,source:a,transform:ze.docDrawingPositionToTransform(_),docTransform:_,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},C=l.BuildTextUtils.drawing.add({documentDataModel:w,drawings:[I],selection:{collapsed:!0,startOffset:0,endOffset:0}});return C?(w.apply(C),this._commandService.syncExecuteCommand(y.SetRangeValuesCommand.id,{value:{[(R=e==null?void 0:e.row)!=null?R:h]:{[(D=e==null?void 0:e.col)!=null?D:f]:{p:w.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,f;const{width:n,height:i,image:o}=await j.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,l.ImageSourceType.URL,o);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const d=l.createDocumentModelWithStyle("",{}),g=at(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,i,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},c={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:t,transform:ze.docDrawingPositionToTransform(u),docTransform:u,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[c],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(d.apply(p),this._commandService.syncExecuteCommand(y.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:a.primary.actualRow]:{[(f=e==null?void 0:e.col)!=null?f:a.primary.actualColumn]:{p:d.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),i=e.getSheetId();return{unitId:n,subUnitId:i}}_getImagePosition(t,e,n,i){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const d=E.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(d==null)return;let{startColumn:g,startRow:u,startX:c,startY:p}=d,h=!1;if(c+t>n&&(c=n-t,c<0&&(c=0,t=n),h=!0),p+e>i&&(p=i-e,p<0&&(p=0,e=i),h=!0),h){const _=this._selectionRenderService.getCellWithCoordByOffset(c,p);if(_==null)return;c=_.startX,p=_.startY,g=_.actualColumn,u=_.actualRow}const f={column:g,columnOffset:0,row:u,rowOffset:0},w=this._selectionRenderService.getCellWithCoordByOffset(c+t,p+e);if(w==null)return;const S={column:w.actualColumn,columnOffset:c+t-w.startX,row:w.actualRow,rowOffset:p+e-w.startY};return{from:f,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:i,arrangeType:o}=t;this._commandService.executeCommand(ht.id,{unitId:e,subUnitId:n,drawingIds:i,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:i,subUnitId:o,drawingId:a,drawingType:d,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:i,subUnitId:o,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const c=x({...u.transform,...g},this._selectionRenderService);if(c==null)return;const p={...n,transform:{...u.transform,...g,...K(c,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...c}};e.push(p)}),e.length>0&&this._commandService.executeCommand(Ae.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(gt.id,t);const{unitId:e,subUnitId:n,drawingId:i}=t[0].parent;this._commandService.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:i}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(pt.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}};exports.SheetDrawingUpdateController=$t([ne(1,l.Inject(E.SheetSkeletonManagerService)),ne(2,l.ICommandService),ne(3,E.ISheetSelectionRenderService),ne(4,j.IImageIoService),ne(5,W.ILocalFileService),ne(6,m.ISheetDrawingService),ne(7,j.IDrawingManagerService),ne(8,l.IContextService),ne(9,W.IMessageService),ne(10,l.Inject(l.LocaleService)),ne(11,l.Inject(y.SheetsSelectionsService)),ne(12,l.Inject(l.Injector))],exports.SheetDrawingUpdateController);const Pe={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(s,r)=>{var o,a;const t=s.get(l.IUniverInstanceService),e=s.get(k.IRenderManagerService),n=(o=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:o.with(exports.SheetDrawingUpdateController);if(!n)return!1;const i=r==null?void 0:r.files;if(i){const d=i.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},mt={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:s=>{var e,n;const r=s.get(l.IUniverInstanceService),t=s.get(k.IRenderManagerService);return(n=(e=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(exports.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}},ye={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(s,r)=>{const t=s.get(l.ICommandService),e=s.get(m.ISheetDrawingService),n=s.get(E.ISheetSelectionRenderService),{direction:i}=r,o=e.getFocusDrawings();if(o.length===0)return!1;const a=o[0].unitId,d=o.map(u=>{const{transform:c}=u;if(c==null)return null;const p={...c},{left:h=0,top:f=0}=c;return i===l.Direction.UP?p.top=f-1:i===l.Direction.DOWN?p.top=f+1:i===l.Direction.LEFT?p.left=h-1:i===l.Direction.RIGHT&&(p.left=h+1),{...u,transform:p,sheetTransform:x(p,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Ae.id,{unitId:a,drawings:d})?(t.syncExecuteCommand(G.id,[a]),!0):!1}},bt="COMPONENT_SHEET_DRAWING_PANEL",wt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(s,r)=>{const t=s.get(W.ISidebarService),e=s.get(l.LocaleService),n=s.get(l.IUniverInstanceService),i=s.get(l.ICommandService);if(!y.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:bt},onClose:()=>{i.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},ft={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(s,r)=>{const t=s.get(l.ICommandService);return r==null?!1:(t.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[r]),t.executeCommand(wt.id,{value:"open"}),!0)}},Lt="sheets-drawing-ui.config",Ct={};var Gt=Object.getOwnPropertyDescriptor,Ht=(s,r,t,e)=>{for(var n=e>1?void 0:e?Gt(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},re=(s,r)=>(t,e)=>r(t,e,s);let qe=class extends l.RxDisposable{constructor(r,t,e,n,i,o,a,d,g,u){super();te(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=t,this._drawingManagerService=e,this._canvasPopManagerService=n,this._renderManagerService=i,this._univerInstanceService=o,this._messageService=a,this._contextService=d,this._ioService=g,this._commandService=u,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(A.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(A.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._setupLoadingStatus()}_setupLoadingStatus(){const r="image-upload-loading";let t;this.disposeWithMe(this._ioService.change$.subscribe(e=>{e>0&&!t?t=this._messageService.show({id:r,type:q.MessageType.Loading,content:`${this._localeService.t("uploadLoading.loading")}: ${e}`,duration:0}):e===0&&(t==null||t.dispose(),t=void 0)}))}_dispose(r){super.dispose();const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof le.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var i;const t=(i=this._renderManagerService.getRenderById(r))==null?void 0:i.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const o=e.getSelectedObjectMap();if(o.size>1){n==null||n.dispose();return}const a=o.values().next().value;if(!a)return;const d=a.oKey,g=this._drawingManagerService.getDrawingOKey(d);if(!g)return;const{unitId:u,subUnitId:c,drawingId:p,drawingType:h}=g,f=g.data;if(f&&f.disablePopup)return;n==null||n.dispose();const w=this._canvasPopManagerService.getFeatureMenu(u,c,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:le.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:w||this._getImageMenuItems(u,c,p,h)}}))})),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(o=>{o[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:ft.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:De.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:le.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:le.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};qe=Ht([re(0,l.Inject(l.Injector)),re(1,l.Inject(l.LocaleService)),re(2,j.IDrawingManagerService),re(3,l.Inject(E.SheetCanvasPopManagerService)),re(4,k.IRenderManagerService),re(5,l.IUniverInstanceService),re(6,W.IMessageService),re(7,l.IContextService),re(8,l.IImageIoService),re(9,l.ICommandService)],qe);var Xt=Object.getOwnPropertyDescriptor,Vt=(s,r,t,e)=>{for(var n=e>1?void 0:e?Xt(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},He=(s,r)=>(t,e)=>r(t,e,s);let ct=class extends l.Disposable{constructor(r,t,e,n,i){super();te(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=i,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(A.throttleTime(33)).subscribe(r=>{var e,n;let t=[];r!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),t.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&t.length===1&&((e=t[0].primary)==null?void 0:e.actualRow)===r.row&&((n=t[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(k.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var t;if(r!=null&&r.drawing&&this._isSetCursor){const e=r.drawing.drawing.drawingOrigin,n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(e.imageSourceType,e.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};ct=Vt([He(1,l.Inject(E.HoverManagerService)),He(2,l.Inject(y.SheetsSelectionsService)),He(3,l.Inject(le.DrawingRenderService)),He(4,l.Inject(E.SheetSkeletonManagerService))],ct);var Kt=Object.getOwnPropertyDescriptor,zt=(s,r,t,e)=>{for(var n=e>1?void 0:e?Kt(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},Xe=(s,r)=>(t,e)=>r(t,e,s);let dt=class extends l.Disposable{constructor(s,r,t,e,n){super(),this._context=s,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const s=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in s){const t=s[r];for(const e in t.data){const n=t.data[e];n.sheetTransform&&(n.transform=K(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService))}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};dt=zt([Xe(1,m.ISheetDrawingService),Xe(2,j.IDrawingManagerService),Xe(3,l.Inject(E.ISheetSelectionRenderService)),Xe(4,l.Inject(E.SheetSkeletonManagerService))],dt);var qt=Object.getOwnPropertyDescriptor,Zt=(s,r,t,e)=>{for(var n=e>1?void 0:e?qt(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},_e=(s,r)=>(t,e)=>r(t,e,s);function Et(s,r,t){var e,n,i,o;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((o=(i=t.p)==null?void 0:i.drawingsOrder)==null?void 0:o.length)===1){const a=t.p.drawings[t.p.drawingsOrder[0]],d=at(s,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(d)return a.transform.width=d.width,a.transform.height=d.height,a.docTransform.size.width=d.width,a.docTransform.size.height=d.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let Ze=class extends l.Disposable{constructor(s,r,t,e,n,i){super(),this._commandService=s,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=i,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(s=>{s.visible?s.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(s=>{s.id===ze.ReplaceSnapshotCommand.id&&s.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(y.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:y.InterceptCellContentPriority.CELL_IMAGE,handler:(s,r,t)=>{var e;return s!=null&&s.p&&((e=s.p.drawingsOrder)!=null&&e.length)&&(s===r.rawData&&(s={...r.rawData}),s.interceptorStyle||(s.interceptorStyle={}),s.interceptorStyle.tr={a:0},Et(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},s)),t(s)}}))}};Ze=Zt([_e(0,l.ICommandService),_e(1,l.Inject(y.SheetInterceptorService)),_e(2,l.Inject(l.Injector)),_e(3,j.IDrawingManagerService),_e(4,l.Inject(Rt.DocDrawingController)),_e(5,l.Inject(E.IEditorBridgeService))],Ze);var Jt=Object.getOwnPropertyDescriptor,Qt=(s,r,t,e)=>{for(var n=e>1?void 0:e?Jt(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},Tt=(s,r)=>(t,e)=>r(t,e,s);let Je=class extends l.Disposable{constructor(s,r){super(),this._autoFillService=s,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(s,r,t,e)=>{new l.ObjectMatrix(e).forValue((n,i,o)=>{Et(this._injector,{unitId:s.unitId,subUnitId:s.subUnitId,row:n,col:i},o)})}}))}};Je=Qt([Tt(0,l.Inject(E.IAutoFillService)),Tt(1,l.Inject(l.Injector))],Je);var en=Object.getOwnPropertyDescriptor,tn=(s,r,t,e)=>{for(var n=e>1?void 0:e?en(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},Re=(s,r)=>(t,e)=>r(t,e,s);const nn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let Qe=class extends l.Disposable{constructor(s,r,t,e,n){super(),this._commandService=s,this._univerInstanceService=r,this._dialogService=t,this._renderManagerService=e,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(s){var n;const r=l.createDocumentModelWithStyle("",{}),t=(n=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(E.EditingRenderController),e=l.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[s],selection:{collapsed:!0,startOffset:0,endOffset:0}});e&&(r.apply(e),t&&t.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(s=>{var r,t;if(s.id===ze.InnerPasteCommand.id){const e=s.params,{doc:n}=e,i=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_DOC);if(i==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const o=i.getUnitId();if(nn.includes(o)){if(o!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(E.SetCellEditVisibleOperation.id,{visible:!1})};((t=i.getBody())==null?void 0:t.dataStream)===`\r
|
|
2
|
-
`?(this._commandService.syncExecuteCommand(E.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(n.drawings)[0])):this._dialogService.open({id:"sheet-cell-image-copy-paste",title:{label:this._localeService.t("cell-image.pasteTitle")},children:{label:this._localeService.t("cell-image.pasteContent")},width:320,destroyOnClose:!0,onClose:a,showOk:!0,showCancel:!0,onOk:()=>{a(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:a})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};Qe=tn([Re(0,l.ICommandService),Re(1,l.IUniverInstanceService),Re(2,W.IDialogService),Re(3,k.IRenderManagerService),Re(4,l.Inject(l.LocaleService))],Qe);var rn=Object.getOwnPropertyDescriptor,sn=(s,r,t,e)=>{for(var n=e>1?void 0:e?rn(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},be=(s,r)=>(t,e)=>r(t,e,s);const Ot="image/png";function on(s){const r=s.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let i=0;i<e;i++)n[i]=t.charCodeAt(i);return new Blob([n],{type:Ot})}function an(s){const r=new ClipboardItem({[Ot]:on(s)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function cn(){function s(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const r=document.activeElement,t=s();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const Mt=[E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let et=class extends l.Disposable{constructor(r,t,e,n,i){super();te(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=i,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const i=this._focusedDrawings;if(i.length>0){const[o]=i;if(n===E.COPY_TYPE.CUT){const d={unitId:r,drawings:[o]};this._commandService.executeCommand(De.id,d)}setTimeout(()=>{const d=cn();o.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&o.imageSourceType===j.ImageSourceType.BASE64?an(o.source):this._clipboardInterfaceService.writeText(""),d()},200);const a={unitId:o.unitId,subUnitId:o.subUnitId,drawings:[o]};this._copyInfo=a}else{const o=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=o}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:i=E.COPY_TYPE.COPY,pasteType:o}=n,{range:a}=r||{},{range:d,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:o,unitId:g,subUnitId:u,pasteRange:d},{copyRange:a,copyType:i}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:o},E.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Pe.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var p;const n=(p=this._renderManagerService.getRenderById(r))==null?void 0:p.with(E.SheetSkeletonManagerService);if(!n)return;const i=n.attachRangeWithCoord(e);if(!i)return;const{startX:o,endX:a,startY:d,endY:g}=i,u=this._drawingService.getDrawingData(r,t),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const f=u[h],{transform:w}=f;if(f.anchorType!==m.SheetDrawingAnchorType.Both||!w)return;const{left:S=0,top:_=0,width:I=0,height:C=0}=w,{drawingStartX:R,drawingEndX:D,drawingStartY:M,drawingEndY:v}={drawingStartX:S,drawingEndX:S+I,drawingStartY:_,drawingEndY:_+C};o<=R&&D<=a&&d<=M&&v<=g&&c.push(f)}),c.length)return{copyRange:e,drawings:c,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Mt.includes(e))return{redos:[],undos:[]};const{unitId:i,subUnitId:o,range:a}=n,d=this._renderManagerService.getRenderById(i),g=d==null?void 0:d.with(E.SheetSkeletonManagerService),u=d==null?void 0:d.with(E.ISheetSelectionRenderService),c=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=c,h=E.discreteRangeToRange(a);return this._generateMutations(p,{unitId:i,subUnitId:o,isCut:t===E.COPY_TYPE.CUT,getTransform:(f,w)=>{var I;const S=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...f,left:S==null?void 0:S.startX,top:S==null?void 0:S.startY};return{transform:_,sheetTransform:(I=x(_,u))!=null?I:w}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:i,isCut:o}=t,a=[],d=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:c,sheetTransform:p}=u;if(!c)return;const h=i(c,p),f={...u,unitId:e,subUnitId:n,drawingId:o?u.drawingId:l.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(o){const{undo:w,redo:S,objects:_}=g.getBatchUpdateOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:S,objects:_}}),d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:_}})}else{const{undo:w,redo:S,objects:_}=g.getBatchAddOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.INSERT}}),d.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.REMOVE}})}}),{redos:a,undos:d}}_generateRangeDrawingsPasteMutations(r,t){var U;const{unitId:e,subUnitId:n,pasteType:i,pasteRange:o}=r,{copyRange:a,copyType:d}=t;if(Mt.includes(i))return{redos:[],undos:[]};const g=(U=this._renderManagerService.getRenderById(e))==null?void 0:U.with(E.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:E.discreteRangeToRange(o)},pasteType:i},d);const{ranges:[c,p],mapFunc:h}=E.virtualizeDiscreteRanges([a,o]),{row:f,col:w}=h(c.startRow,c.startColumn),{row:S,col:_}=h(p.startRow,p.startColumn),I=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:w,endColumn:w}),C=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:_,endColumn:_});if(!I||!C||!this._copyInfo)return{redos:[],undos:[]};const R=C.startX-I.startX,D=C.startY-I.startY,M=S-f,v=_-w;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(b,P)=>{var N,O;return{transform:{...b,left:((N=b==null?void 0:b.left)!=null?N:0)+R,top:((O=b==null?void 0:b.top)!=null?O:0)+D},sheetTransform:{...P,to:{...P.to,row:P.to.row+M,column:P.to.column+v},from:{...P.from,row:P.from.row+M,column:P.from.column+v}}}},isCut:d===E.COPY_TYPE.CUT})}};et=sn([be(0,E.ISheetClipboardService),be(1,k.IRenderManagerService),be(2,j.IDrawingManagerService),be(3,W.IClipboardInterfaceService),be(4,l.ICommandService)],et);var dn=Object.getOwnPropertyDescriptor,ln=(s,r,t,e)=>{for(var n=e>1?void 0:e?dn(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},Ee=(s,r)=>(t,e)=>r(t,e,s);let tt=class extends l.Disposable{constructor(s,r,t,e,n){super(),this._drawingManagerService=s,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const s=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=A.combineLatest([s,r]);this.disposeWithMe(t.pipe(A.switchMap(([e,n])=>e?e.activeSheet$.pipe(A.tap(i=>{if(!i){this._drawingManagerService.setDrawingVisible(!1);return}const o=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new y.WorkbookViewPermission(o).id,new y.WorksheetViewPermission(o,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,i)})):(this._drawingManagerService.setDrawingVisible(!1),A.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(s,r){this._drawingManagerService.setDrawingVisible(!1);const t=s.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),o=this._renderManagerService.getRenderById(t),a=o==null?void 0:o.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const s=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=A.combineLatest([s,r]);this.disposeWithMe(t.pipe(A.switchMap(([e,n])=>e?e.activeSheet$.pipe(A.tap(i=>{if(!i){this._drawingManagerService.setDrawingEditable(!1);return}const o=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new y.WorkbookEditablePermission(o).id,new y.WorksheetEditPermission(o,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,i)})):(this._drawingManagerService.setDrawingEditable(!1),A.EMPTY))).subscribe())}_handleDrawingEditableFalse(s,r){this._drawingManagerService.setDrawingEditable(!1);const t=s.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),o=this._renderManagerService.getRenderById(t),a=o==null?void 0:o.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const s=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(A.combineLatest([s,r]).pipe(A.switchMap(([t,e])=>t?t.activeSheet$.pipe(A.switchMap(n=>{if(!n)return A.EMPTY;const i=t.getUnitId(),o=n.getSheetId(),a=this._renderManagerService.getRenderById(i),d=a==null?void 0:a.scene;if(!d)return A.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookViewPermission(i).id,new y.WorksheetViewPermission(i,o).id]).pipe(A.map(c=>c.every(p=>p.value)),A.distinctUntilChanged()).pipe(A.map(c=>({permission:c,scene:d,transformer:g,unitId:i,subUnitId:o})))})):A.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:o})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(i,o),g=Object.values(d);t?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),i=e==null?void 0:e.getSheetId();if(!n||!i)return;const o=this._drawingManagerService.getDrawingData(n,i),a=Object.values(o);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const s=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(A.combineLatest([s,r]).pipe(A.switchMap(([t,e])=>t?t.activeSheet$.pipe(A.switchMap(n=>{if(!n)return A.EMPTY;const i=t.getUnitId(),o=n.getSheetId(),a=this._renderManagerService.getRenderById(i),d=a==null?void 0:a.scene;if(!d)return A.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookEditablePermission(i).id,new y.WorksheetEditPermission(i,o).id]).pipe(A.map(c=>c.every(p=>p.value)),A.distinctUntilChanged()).pipe(A.map(c=>({permission:c,scene:d,transformer:g,unitId:i,subUnitId:o})))})):A.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:o})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(i,o),g=Object.values(d);t?(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const i=n.getSheetId(),o=this._renderManagerService.getRenderById(e),a=o==null?void 0:o.scene;if(!a)return;const d=this._drawingManagerService.getDrawingData(e,i),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(c=>{c.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>c.oKey.includes(p.drawingId))&&a.detachTransformerFrom(c)})}}))}};tt=ln([Ee(0,j.IDrawingManagerService),Ee(1,k.IRenderManagerService),Ee(2,l.IPermissionService),Ee(3,l.IUniverInstanceService),Ee(4,l.Inject(l.UserManagerService))],tt);var un=Object.getOwnPropertyDescriptor,gn=(s,r,t,e)=>{for(var n=e>1?void 0:e?un(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},ue=(s,r)=>(t,e)=>r(t,e,s);function Ut(s,r,t,e,n,i=!1){const{scaleX:o,scaleY:a}=r.getAncestorScale(),d=r.getViewport(k.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:c,xSplit:p,ySplit:h}=g,f={left:!0,top:!0};if(!d)return{...s,absolute:f};const{left:w,right:S,top:_,bottom:I}=s;let{top:C,left:R,viewportScrollX:D,viewportScrollY:M}=d;const{boundsOfViewArea:v,scrollDirectionResponse:U}=n||{},{rowHeaderWidth:b,columnHeaderHeight:P}=t,N={top:i?0:P,left:i?0:b};v&&(l.Tools.isDefine(N.top)&&(N.top=v.top),l.Tools.isDefine(N.left)&&(N.left=v.left)),U==="HORIZONTAL"&&(M=0),U==="VERTICAL"&&(D=0);let O=0,T=0;const B=t.rowStartY(c-h)+P,$=t.colStartX(u-p)+b,z=t.rowStartY(c)+P,J=t.colStartX(u)+b;if(p===0)f.left=!1,O=(w-D)*o,T=(S-D)*o;else{const X=w-($-b),Y=S-($-b);S<J?(O=X*o,T=Y*o):w<=J&&S>=J?(O=X*o,T=Math.max(R,(S-D)*o)):w>J&&(f.left=!1,O=Math.max((w-D)*o,R),T=Math.max((S-D)*o,R))}let H=0,V=0;if(h===0)f.top=!1,H=(_-M)*a,V=(I-M)*a;else{const X=_-(B-P),Y=I-(B-P);I<z?(H=X*a,V=Y*a):_<=z&&I>=z?(H=X*a,V=Math.max(C,(I-M)*a)):_>z&&(f.top=!1,H=Math.max((_-M)*a,C),V=Math.max((I-M)*a,C))}return O=Math.max(O,N.left),H=Math.max(H,N.top),T=Math.max(T,N.left),V=Math.max(V,N.top),{left:O,right:T,top:H,bottom:V,absolute:f}}const ie=(s,r,t,e,n)=>{const{left:i,top:o,width:a,height:d,angle:g}=s,u={left:i,right:i+a,top:o,bottom:o+d},c=Ut(u,r,t,e,n),{scaleX:p,scaleY:h}=r.getAncestorScale();return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:g,width:a*p,height:d*h,absolute:c.absolute}};exports.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(t,e,n,i,o,a,d){super();te(this,"_domLayerInfoMap",new Map);te(this,"_transformChange$",new A.Subject);te(this,"transformChange$",this._transformChange$.asObservable());te(this,"_add$",new A.Subject);te(this,"add$",this._add$.asObservable());te(this,"_remove$",new A.Subject);te(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=i,this._canvasFloatDomService=o,this._sheetDrawingService=a,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(A.filter(t=>t===l.LifecycleStages.Rendered),A.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}getFloatDomsBySubUnitId(t,e){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===e&&n.unitId===t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const i=n.getTransformerByCreate(),o=e.engine.getCanvasElement();return{scene:n,transformer:i,renderUnit:e,canvas:o}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var X;const{unitId:n,subUnitId:i,drawingId:o}=e,a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),d=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!d||!a)return;const c=(X=this._renderManagerService.getRenderById(n))==null?void 0:X.with(E.SheetSkeletonManagerService).getSkeletonParam(i);if(!c)return;const{transform:p,drawingType:h,data:f}=d;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const w=this._getSceneAndTransformerByDrawingSearch(n);if(w==null)return;const{scene:S,canvas:_}=w;if(p==null)return!0;if(u!==i)return;const{left:I,top:C,width:R,height:D,angle:M,flipX:v,flipY:U,skewX:b,skewY:P}=p,N=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:o}),O=S.getObject(N);if(O!=null){O.transformByState({left:I,top:C,width:R,height:D,angle:M,flipX:v,flipY:U,skewX:b,skewY:P});return}const T={left:I,top:C,width:R,height:D,zIndex:this._drawingManagerService.getDrawingOrder(n,i).length-1},B=h===l.DrawingTypeEnum.DRAWING_CHART;if(T.rotateEnabled=!1,B){const Y=f?f.backgroundColor:"white";T.fill=Y,f&&f.border&&(T.stroke=f.border),T.paintFirst="stroke",T.strokeWidth=1,T.borderEnabled=!1,T.radius=8}const $=new k.Rect(N,T);B&&$.setObjectType(k.ObjectType.CHART),S.addObject($,k.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo($);const z=new l.DisposableCollection,J=ie($,w.renderUnit.scene,c.skeleton,a.worksheet),H=new A.BehaviorSubject(J),V={dispose:z,rect:$,position$:H,unitId:n,subUnitId:i,id:o};this._canvasFloatDomService.addFloatDom({position$:H,id:o,componentKey:d.componentKey,onPointerDown:Y=>{_.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{_.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{_.dispatchEvent(new PointerEvent(Y.type,Y))},onWheel:Y=>{_.dispatchEvent(new WheelEvent(Y.type,Y))},data:f,unitId:n});const Q=$.onTransformChange$.subscribeEvent(()=>{const Y=ie($,w.renderUnit.scene,c.skeleton,a.worksheet);H.next(Y)});z.add(()=>{this._canvasFloatDomService.removeFloatDom(o)}),Q&&z.add(Q),this._domLayerInfoMap.set(o,V)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{var p;const{unitId:n,subUnitId:i,drawingId:o}=e,a=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:o}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:g,scene:u}=d,c=u.getObject(a);c!=null&&c.oKey&&(g.clearControlByIds([c==null?void 0:c.oKey]),(p=u.getTransformer())==null||p.clearSelectedObjects())})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const i=this._getSceneAndTransformerByDrawingSearch(e),o=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===e).map(u=>u.id),a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(E.SheetSkeletonManagerService).getSkeletonParam(n);!i||!a||!d||o.forEach(u=>{const c=this._domLayerInfoMap.get(u);if(c){const p=ie(c.rect,i.renderUnit.scene,d.skeleton,a.worksheet,c);c.position$.next(p)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(A.switchMap(e=>e?e.activeSheet$:A.of(null)),A.map(e=>{if(!e)return null;const n=e.getUnitId(),i=this._renderManagerService.getRenderById(n);return i?{render:i,unitId:n,subUnitId:e.getSheetId()}:null}),A.switchMap(e=>e?l.fromEventSubject(e.render.scene.getViewport(k.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(A.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):A.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:i}=e;t(n,i)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===E.SetZoomRatioOperation.id){const n=e.params,{unitId:i}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===i).map(a=>a.subUnitId).forEach(a=>{t(i,a)})}else if(e.id===y.SetFrozenMutation.id){const{unitId:n,subUnitId:i}=e.params;t(n,i)}}))}updateFloatDomProps(t,e,n,i){const o=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(o&&a){const{scene:d}=a,g=j.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=d.getObject(g);u&&u instanceof k.Rect&&u.setProps(i)}}_getPosition(t,e){var h;const{startX:n,endX:i,startY:o,endY:a}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(E.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(n,o);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:o-g.startY},c=d.getCellWithCoordByOffset(i,a);if(c==null)return;const p={column:c.actualColumn,columnOffset:i-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const i={...n.transform};this._transformChange$.next({id:e.drawingId,value:i}),this._canvasFloatDomService.updateFloatDom(e.drawingId,{...n});const o=this._getSceneAndTransformerByDrawingSearch(e.unitId);if(o&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART){const{scene:a}=o,d=this._domLayerInfoMap.get(e.drawingId);d!=null&&d.rect&&(n.allowTransform===!1?a.detachTransformerFrom(d.rect):a.attachTransformerTo(d.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(t,e){const n=y.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:i,subUnitId:o}=n,{initPosition:a,componentKey:d,data:g,allowTransform:u=!0}=t,c=e!=null?e:l.generateRandomId(),p=this._getPosition(a,i);if(p==null)return;const h={unitId:i,subUnitId:o,drawingId:c,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:p,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Ue.id,{unitId:i,drawings:[h]}),this._add$.next({unitId:i,subUnitId:o,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:i,subUnitId:o}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(i);if(a&&a.scene.removeObject(n.rect),e){const d=this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:o,drawingId:t});if(!d)return;const g=this._sheetDrawingService.getBatchRemoveOp([d]),{redo:u,objects:c}=g;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:i,subUnitId:o,op:u,objects:c,type:m.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,i){var v,U,b;const o=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=o,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(v=this._renderManagerService.getRenderById(a))==null?void 0:v.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,w=i!=null?i:l.generateRandomId(),{position:S,position$:_}=this._createRangePositionObserver(t,u,c.skeleton);if(this._getPosition(S,a)==null)return;const C=g.scene,{scaleX:R}=C.getAncestorScale(),D=Ve(S,n,R),M={unitId:a,subUnitId:d,drawingId:w,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:D.startX,top:D.startY,width:D.width,height:D.height},data:h,allowTransform:f};{const{unitId:P,subUnitId:N,drawingId:O}=M,T=y.getSheetCommandTarget(this._univerInstanceService,{unitId:P,subUnitId:N}),B=M,$=this._univerInstanceService.getUnit(P,l.UniverInstanceType.UNIVER_SHEET);if(!$)return;const z=$.getActiveSheet().getSheetId();if(!B||!T)return;const J=(U=this._renderManagerService.getRenderById(P))==null?void 0:U.with(E.SheetSkeletonManagerService);if(!J)return;const H=J.getWorksheetSkeleton(N);if(!H)return;const{transform:V,drawingType:Q,data:X}=B;if(Q!==l.DrawingTypeEnum.DRAWING_DOM&&Q!==l.DrawingTypeEnum.DRAWING_CHART)return;const Y=this._getSceneAndTransformerByDrawingSearch(P);if(Y==null)return;const{scene:he,canvas:pe}=Y;if(V==null||z!==N)return;const{left:je,top:ke,width:We,height:Be,angle:it,flipX:st,flipY:Ye,skewX:Fe,skewY:me}=V,$e=j.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:N,drawingId:O}),se=he.getObject($e);if(se!=null){se.transformByState({left:je,top:ke,width:We,height:Be,angle:it,flipX:st,flipY:Ye,skewX:Fe,skewY:me});return}const ee={left:je,top:ke,width:We,height:Be,zIndex:this._drawingManagerService.getDrawingOrder(P,N).length-1},we=Q===l.DrawingTypeEnum.DRAWING_CHART;if(we){const F=X?X.backgroundColor:"white";ee.fill=F,ee.rotateEnabled=!1,X&&X.border&&(ee.stroke=X.border),ee.paintFirst="stroke",ee.strokeWidth=1,ee.borderEnabled=!1,ee.radius=8}const oe=new k.Rect($e,ee);we&&oe.setObjectType(k.ObjectType.CHART),he.addObject(oe,k.DRAWING_OBJECT_LAYER_INDEX),B.allowTransform!==!1&&he.attachTransformerTo(oe);const ae=new l.DisposableCollection,xe=he.getMainViewport(),{rowHeaderWidth:fe,columnHeaderHeight:Ce}=H.skeleton,Le={top:Ce,left:fe,bottom:xe.bottom,right:xe.right},ce={dispose:ae,rect:oe,boundsOfViewArea:Le,domAnchor:n,unitId:P,subUnitId:N},L=ie(oe,Y.renderUnit.scene,H.skeleton,T.worksheet,ce),Se=new A.BehaviorSubject(L);ce.position$=Se;let Te={position$:Se,id:O,componentKey:B.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:F=>{pe.dispatchEvent(new WheelEvent(F.type,F))},data:X,unitId:P};e.eventPassThrough&&(Te={...Te,onPointerDown:F=>{pe.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{pe.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{pe.dispatchEvent(new PointerEvent(F.type,F))}}),this._canvasFloatDomService.addFloatDom(Te),this.disposeWithMe(_.subscribe(F=>{var vt,It,Dt,yt;const _t=Ve({startX:F.startX,startY:F.startY,endX:F.endX,endY:F.endY,width:(vt=n.width)!=null?vt:F.width,height:(It=n.height)!=null?It:F.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Pt=j.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:N,drawingId:O}),Nt=new k.Rect(Pt,{left:_t.startX,top:_t.startY,width:(Dt=n.width)!=null?Dt:F.width,height:(yt=n.height)!=null?yt:F.height,zIndex:this._drawingManagerService.getDrawingOrder(P,N).length-1}),jt=ie(Nt,Y.renderUnit.scene,H.skeleton,T.worksheet,ce);Se.next(jt)}));const Me=(b=this._renderManagerService.getRenderById(P))==null?void 0:b.with(E.SheetSkeletonManagerService);Me==null||Me.currentSkeleton$.subscribe(F=>{F&&H.sheetId!==F.sheetId&&this._removeDom(w,!0)});const Ge=oe.onTransformChange$.subscribeEvent(()=>{const F=ie(oe,Y.renderUnit.scene,H.skeleton,T.worksheet,ce);Se.next(F)});ae.add(()=>{this._canvasFloatDomService.removeFloatDom(O)}),Ge&&ae.add(Ge),this._domLayerInfoMap.set(O,ce)}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}addFloatDomToColumnHeader(t,e,n,i){var D,M,v;const o=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=o;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(D=this._renderManagerService.getRenderById(a))==null?void 0:D.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,w=i!=null?i:l.generateRandomId(),{position:S,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,c.skeleton),I=S;if(I.startY=0,this._getPosition(S,a)==null)return;const R={unitId:a,subUnitId:d,drawingId:w,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:f};{const{unitId:U,subUnitId:b,drawingId:P}=R,N=y.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:b}),O=R,T=this._univerInstanceService.getUnit(U,l.UniverInstanceType.UNIVER_SHEET);if(!T)return;const B=T.getActiveSheet().getSheetId();if(!O||!N)return;const $=(M=this._renderManagerService.getRenderById(U))==null?void 0:M.with(E.SheetSkeletonManagerService);if(!$)return;const z=$.getWorksheetSkeleton(b);if(!z)return;const{transform:J,data:H}=O,V=this._getSceneAndTransformerByDrawingSearch(U);if(V==null)return;const{scene:Q,canvas:X}=V;if(J==null||B!==b)return;const{left:Y,top:he,width:pe,height:je,angle:ke,flipX:We,flipY:Be,skewX:it,skewY:st}=J,Ye=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:P}),Fe=Q.getObject(Ye);if(Fe!=null){Fe.transformByState({left:Y,top:he,width:pe,height:je,angle:ke,flipX:We,flipY:Be,skewX:it,skewY:st});return}const me=Ve({startX:I.startX,startY:0,endX:S.endX,endY:S.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),$e={left:me.startX,top:me.startY,width:me.width,height:me.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1},se=new k.Rect(Ye,$e);Q.addObject(se,k.DRAWING_OBJECT_LAYER_INDEX),O.allowTransform!==!1&&Q.attachTransformerTo(se);const ee=new l.DisposableCollection,we=Q.getMainViewport(),oe={top:0,left:we.left,bottom:we.bottom,right:we.right},ae={dispose:ee,rect:se,unitId:U,subUnitId:b,boundsOfViewArea:oe,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},xe=ie(se,V.renderUnit.scene,z.skeleton,N.worksheet,ae),fe=new A.BehaviorSubject(xe);ae.position$=fe;let Ce={position$:fe,id:P,componentKey:O.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:L=>{X.dispatchEvent(new WheelEvent(L.type,L))},data:H,unitId:U};e.eventPassThrough&&(Ce={...Ce,onPointerDown:L=>{X.dispatchEvent(new PointerEvent(L.type,L))},onPointerMove:L=>{X.dispatchEvent(new PointerEvent(L.type,L))},onPointerUp:L=>{X.dispatchEvent(new PointerEvent(L.type,L))}}),this._canvasFloatDomService.addFloatDom(Ce);const Le=se.onTransformChange$.subscribeEvent(()=>{const L=ie(se,V.renderUnit.scene,z.skeleton,N.worksheet,ae);fe.next(L)});this.disposeWithMe(_.subscribe(L=>{const Se=Ve({startX:L.startX,startY:0,endX:L.endX,endY:L.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Te=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:P}),Me=new k.Rect(Te,{left:Se.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1}),Ge=ie(Me,V.renderUnit.scene,z.skeleton,N.worksheet,ae);fe.next(Ge)}));const ce=(v=this._renderManagerService.getRenderById(U))==null?void 0:v.with(E.SheetSkeletonManagerService);ce==null||ce.currentSkeleton$.subscribe(L=>{L&&c.sheetId!==L.sheetId&&this._removeDom(w,!0)}),ee.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),Le&&ee.add(Le),this._domLayerInfoMap.set(P,ae)}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:i,startColumn:o}=t;const a=Oe(i,o,n),d=new A.BehaviorSubject(a),g=Oe(t.endRow,t.endColumn,n),u=new A.BehaviorSubject(g),c=()=>{const _=Oe(i,o,n),I=Oe(t.endRow,t.endColumn,n);d.next(_),u.next(I)},p=new l.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>c())),p.add(this._commandService.onCommandExecuted(_=>{if(_.id===y.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(C=>C.row===i)>-1){c();return}(y.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===E.SetScrollOperation.id||_.id===E.SetZoomRatioOperation.id)&&c()}));const h=(_,I)=>{i=_,o=I,c()},f=()=>({rotate:0,width:g.right-a.left,height:g.bottom-a.top,absolute:{left:!0,top:!0},startX:a.left,startY:a.top,endX:g.right,endY:g.bottom}),w=d.pipe(A.map(_=>{const I=Oe(t.endRow,t.endColumn,n);return{rotate:0,width:I.right-_.left,height:I.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:I.right,endY:I.bottom}})),S=f();return{position$:w,position:S,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:p}}};exports.SheetCanvasFloatDomManagerService=gn([ue(0,l.Inject(k.IRenderManagerService)),ue(1,l.IUniverInstanceService),ue(2,l.Inject(l.ICommandService)),ue(3,j.IDrawingManagerService),ue(4,l.Inject(W.CanvasFloatDomService)),ue(5,m.ISheetDrawingService),ue(6,l.Inject(l.LifecycleService))],exports.SheetCanvasFloatDomManagerService);function Oe(s,r,t){const e=t.getCellWithCoordByIndex(s,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Ve(s,r,t){var g,u;t=t!=null?t:1;const e=s.endX-s.startX,n=s.endY-s.startY,i=(g=r==null?void 0:r.width)!=null?g:e,o=(u=r==null?void 0:r.height)!=null?u:n;let a=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=Ke(r.marginX,e*t);a=s.endX-c-i}else a=s.startX+Ke(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const c=Ke(r.marginY,n*t);d=s.endY-c-o}else d=s.startY+Ke(r.marginY,n)}return{rotate:0,startX:a,startY:d,endX:s.endX,endY:s.endY,width:i,height:o,absolute:{left:s.absolute.left,top:s.absolute.top}}}function Ke(s,r){if(s===void 0)return 0;if(typeof s=="number")return s;const t=Number.parseFloat(s);return r*t/100}const hn=s=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=s,i=Ie.useMemo(()=>r.map(o=>{const{width:a,height:d,angle:g,left:u,top:c}=o.transform,p=Ut({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:c!=null?c:0,bottom:(c!=null?c:0)+(d!=null?d:0)},t,e,n,void 0,!0),{scaleX:h,scaleY:f}=t.getAncestorScale(),w={startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:g,width:a*h,height:d*f,absolute:p.absolute},S={position$:new A.BehaviorSubject(w),position:w,id:o.drawingId,componentKey:o.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:o.unitId,data:o.data};return[o.drawingId,S]}),[r,t,e,n]);return Z.jsx("div",{style:{position:"absolute",top:0,left:0},children:i.map(([o,a])=>Z.jsx(W.PrintFloatDomSingle,{layer:a,id:o,position:a.position},o))})};var pn=Object.getOwnPropertyDescriptor,mn=(s,r,t,e)=>{for(var n=e>1?void 0:e?pn(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},ge=(s,r)=>(t,e)=>r(t,e,s);let nt=class extends l.Disposable{constructor(s,r,t,e,n,i,o){super(),this._sheetPrintInterceptorService=s,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=i,this._injector=o,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(s,r,t)=>{const{unitId:e,scene:n,subUnitId:i}=r,o=this._drawingManagerService.getDrawingDataForUnit(e),a=o==null?void 0:o[i];return a&&a.order.forEach(d=>{const g=a.data[d];g.drawingType!==l.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(s,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._renderManagerService.getRenderById(e);if(!i)return t(s);const o=i.with(E.SheetSkeletonManagerService).getSkeletonParam(n);if(!o)return t(s);const a=this._drawingManagerService.getDrawingDataForUnit(e),d=a==null?void 0:a[r.subUnitId];if(!d)return t(s);const{scaleX:g,scaleY:u}=i.scene,c=s?{...s}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=d.order.map(h=>d.data[h]);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const f=o.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),w=o.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});f.column<c.startColumn&&(c.startColumn=f.column),f.row<c.startRow&&(c.startRow=f.row),c.endRow<w.row&&(c.endRow=w.row),c.endColumn<w.column&&(c.endColumn=w.column)}}),t(c)):t(s)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(s,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._drawingManagerService.getDrawingDataForUnit(e),o=i==null?void 0:i[n];if(o){const a=o.order.map(g=>{const u=o.data[g];if(u.drawingType===l.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(l.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===l.DrawingTypeEnum.DRAWING_DOM){const c=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(c||u.componentKey)}}return null}).filter(Boolean),d=W.connectInjector(hn,this._injector);return q.render(Z.jsx(d,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),s==null||s.add(()=>{q.unmount(r.root)}),t(s)}}}))}};nt=mn([ge(0,l.Inject(E.SheetPrintInterceptorService)),ge(1,l.Inject(le.DrawingRenderService)),ge(2,j.IDrawingManagerService),ge(3,k.IRenderManagerService),ge(4,l.Inject(exports.SheetCanvasFloatDomManagerService)),ge(5,l.Inject(W.ComponentManager)),ge(6,l.Inject(l.Injector))],nt);var wn=Object.getOwnPropertyDescriptor,fn=(s,r,t,e)=>{for(var n=e>1?void 0:e?wn(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},de=(s,r)=>(t,e)=>r(t,e,s);const Sn=[y.InsertRowCommand.id,y.InsertColCommand.id,y.RemoveRowCommand.id,y.RemoveColCommand.id,y.DeleteRangeMoveLeftCommand.id,y.DeleteRangeMoveUpCommand.id,y.InsertRangeMoveDownCommand.id,y.InsertRangeMoveRightCommand.id,y.DeltaRowHeightCommand.id,y.SetRowHeightCommand.id,y.DeltaColumnWidthCommand.id,y.SetColWidthCommand.id,y.SetRowHiddenCommand.id,y.SetSpecificRowsVisibleCommand.id,y.SetSpecificColsVisibleCommand.id,y.SetColHiddenCommand.id,y.MoveColsCommand.id,y.MoveRowsCommand.id,y.MoveRangeCommand.id],_n=[y.SetRowVisibleMutation.id,y.SetRowHiddenMutation.id,y.SetColVisibleMutation.id,y.SetColHiddenMutation.id,y.SetWorksheetRowHeightMutation.id,y.SetWorksheetColWidthMutation.id];let lt=class extends l.Disposable{constructor(s,r,t,e,n,i,o,a,d){super(),this._context=s,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=i,this._sheetDrawingService=o,this._drawingManagerService=a,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:s=>{if(!Sn.includes(s.id))return{redos:[],undos:[]};if(s.params==null)return{redos:[],undos:[]};const r=s.id;if(r===y.InsertRowCommand.id)return this._moveRowInterceptor(s.params,"insert");if([y.MoveColsCommand.id,y.MoveRowsCommand.id,y.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(s.params);if(r===y.InsertColCommand.id)return this._moveColInterceptor(s.params,"insert");if(r===y.RemoveRowCommand.id)return this._moveRowInterceptor(s.params,"remove");if(r===y.RemoveColCommand.id)return this._moveColInterceptor(s.params,"remove");if(r===y.DeleteRangeMoveLeftCommand.id){const{range:t}=s.params;return this._getRangeMoveUndo(t,0)}else if(r===y.DeleteRangeMoveUpCommand.id){const{range:t}=s.params;return this._getRangeMoveUndo(t,1)}else if(r===y.InsertRangeMoveDownCommand.id){const{range:t}=s.params;return this._getRangeMoveUndo(t,2)}else if(r===y.InsertRangeMoveRightCommand.id){const{range:t}=s.params;return this._getRangeMoveUndo(t,3)}else if(r===y.SetRowHiddenCommand.id||r===y.SetSpecificRowsVisibleCommand.id){const t=s.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForRowVisible(e,n,i)}else if(r===y.SetSpecificColsVisibleCommand.id||r===y.SetColHiddenCommand.id){const t=s.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForColVisible(e,n,i)}else if(r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id||r===y.DeltaColumnWidthCommand.id||r===y.SetColWidthCommand.id){const t=s.params,{unitId:e,subUnitId:n,ranges:i}=t,o=r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,i,o)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(s,r){const t=y.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,i=[],o=[],a=this._sheetDrawingService.getDrawingData(e,n),d=[],g=[];if(Object.keys(a).forEach(u=>{const c=a[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(s,r,c);d.push(...p),g.push(...h)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:p,objects:h}=u;i.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),c=u.undo,p=u.redo,h=u.objects;i.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.INSERT}})}return i.push({id:G.id,params:[e]}),o.push({id:G.id,params:[e]}),{redos:i,undos:o}}_getUpdateOrDeleteDrawings(s,r,t){const e=[],n=[],{sheetTransform:i,anchorType:o=m.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:g,drawingId:u}=t,{from:c,to:p}=i,{row:h,column:f}=c,{row:w,column:S}=p;if(i==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:_,endRow:I,startColumn:C,endColumn:R}=s;let D=null,M=null;if(r===0&&h>=_&&w<=I)if(f>=C&&S<=R)n.push({unitId:d,subUnitId:g,drawingId:u});else{const v=this._shrinkCol(i,a,C,R,o);D=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(r===1&&f>=C&&S<=R)if(h>=_&&w<=I)n.push({unitId:d,subUnitId:g,drawingId:u});else{const v=this._shrinkRow(i,a,_,I,o);D=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(r===2){const v=this._expandRow(i,a,_,I,o);D=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(r===3){const v=this._expandCol(i,a,C,R,o);D=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}if(D!=null&&M!=null){const v=K(D,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:D,transform:v})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(s,r,t){const e=x({...s},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(s,r,t){const e=this._drawingManagerService.getDrawingData(s,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=p,{row:_,column:I}=w,{row:C,column:R}=S;for(let D=0;D<t.length;D++){const M=t[D],{startRow:v,endRow:U,startColumn:b,endColumn:P}=M;if(R<b)continue;if(f===m.SheetDrawingAnchorType.Position){let T=null,B=null;if(I>=b&&I<=P){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:P,startRow:w.row,endRow:S.row});if($==null)return;B={...h,left:$.startX}}if(B!=null&&(T=x(B,this._selectionRenderService),T!=null&&B!=null)){n.push({...c,sheetTransform:T,transform:B});break}this._remainDrawingSize(h,n,c);continue}if(I>=b&&R<=P)continue;let N=null,O=null;if(I>=b&&I<=P){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:P,startRow:w.row,endRow:S.row});if(T==null)return;O={...h,left:(T==null?void 0:T.startX)||0,width:((h==null?void 0:h.width)||0)-T.endX+T.startX}}else if(R>=b&&R<=P){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:R,startRow:w.row,endRow:S.row});if(T==null)return;O={...h,left:T.startX-((h==null?void 0:h.width)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:P,startRow:w.row,endRow:S.row});if(T==null)return;if(O={...h,width:((h==null?void 0:h.width)||0)-T.endX+T.startX},N=x(O,this._selectionRenderService),N!=null&&O!=null){i.push({...c,sheetTransform:N,transform:O});break}}if(O!=null&&(N=x(O,this._selectionRenderService)),O!=null&&N!=null){n.push({...c,sheetTransform:N,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&i.length===0)return{redos:[],undos:[]};const{redos:o,undos:a}=this._createUndoAndRedoMutation(s,r,n),d=[],g=[];if(i.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(s,r,i);d.push(...u),g.push(...c)}return{redos:o,undos:a,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(s,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:i,objects:o}=e,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:r,op:i,objects:o,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}],d=[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:r,op:n,objects:o,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(s,r,t){const e=this._drawingManagerService.getDrawingData(s,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=p,{row:_,column:I}=w,{row:C,column:R}=S;for(let D=0;D<t.length;D++){const M=t[D],{startRow:v,endRow:U,startColumn:b,endColumn:P}=M;if(C<v)continue;if(f===m.SheetDrawingAnchorType.Position){let T=null,B=null;if(_>=v&&_<=U){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:_,endRow:U});if($==null)return;B={...h,top:$.startY}}if(B!=null&&(T=x(B,this._selectionRenderService),T!=null&&B!=null)){n.push({...c,sheetTransform:T,transform:B});break}this._remainDrawingSize(h,n,c);continue}if(_>=v&&C<=U)continue;let N=null,O=null;if(_>=v&&_<=U){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:_,endRow:U});if(T==null)return;O={...h,top:(T==null?void 0:T.startY)||0,height:((h==null?void 0:h.height)||0)-T.endY+T.startY}}else if(C>=v&&C<=U){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:C});if(T==null)return;O={...h,top:T.startY-((h==null?void 0:h.height)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:U});if(T==null)return;if(O={...h,height:((h==null?void 0:h.height)||0)-T.endY+T.startY},N=x(O,this._selectionRenderService),N!=null&&O!=null){i.push({...c,sheetTransform:N,transform:O});break}}if(O!=null&&(N=x(O,this._selectionRenderService)),O!=null&&N!=null){n.push({...c,sheetTransform:N,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&i.length===0)return{redos:[],undos:[]};const{redos:o,undos:a}=this._createUndoAndRedoMutation(s,r,n),d=[],g=[];if(i.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(s,r,i);d.push(...u),g.push(...c)}return{redos:o,undos:a,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(s,r,t,e){const n=this._drawingManagerService.getDrawingData(s,r),i=[];return Object.keys(n).forEach(o=>{const a=n[o],{sheetTransform:d,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=a;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,i,a);else{const{from:c,to:p}=d,{row:h,column:f}=c,{row:w,column:S}=p;for(let _=0;_<t.length;_++){const I=t[_],{startRow:C,endRow:R,startColumn:D,endColumn:M}=I;if(w<C||S<D)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=C&&w>=R||f<=D&&S>=M)){this._remainDrawingSize(g,i,a);continue}const v=K({...d},this._selectionRenderService,this._skeletonManagerService);if(v!=null){i.push({...a,transform:v});break}}}}),i.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(s,r,i)}_getUnitIdAndSubUnitId(s,r){let t,e;if(r==="insert")t=s.unitId,e=s.subUnitId;else{const n=y.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(s){var C,R;const{toRange:r,fromRange:t}=s,e=y.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:i}=e,o=(R=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.with(E.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!o)return{redos:[],undos:[]};const a=E.attachRangeWithCoord(o,t);if(!a)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=a,p=this._sheetDrawingService.getDrawingData(n,i),h=[];Object.keys(p).forEach(D=>{const M=p[D];if(M.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:v}=M;if(!v)return;const{left:U=0,top:b=0,width:P=0,height:N=0}=v,{drawingStartX:O,drawingEndX:T,drawingStartY:B,drawingEndY:$}={drawingStartX:U,drawingEndX:U+P,drawingStartY:b,drawingEndY:b+N};d<=O&&T<=g&&u<=B&&$<=c&&h.push(M)});const f=[],w=[],S=r.startRow-t.startRow,_=r.startColumn-t.startColumn,I=h.map(D=>{const M=D.sheetTransform,v={to:{...M.to,row:M.to.row+S,column:M.to.column+_},from:{...M.from,row:M.from.row+S,column:M.from.column+_}},U=K(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:i,drawingId:D.drawingId,transform:U,sheetTransform:v}});if(I.length){const D=this._sheetDrawingService.getBatchUpdateOp(I),{undo:M,redo:v,objects:U}=D;f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:v,objects:U,type:m.DrawingApplyType.UPDATE}}),w.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:M,objects:U,type:m.DrawingApplyType.UPDATE}})}return{redos:f,undos:w}}_moveRowInterceptor(s,r){const t=this._getUnitIdAndSubUnitId(s,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=s,o=i.startRow,a=i.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=m.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let I,C;if(r==="insert"){const D=this._expandRow(w,S,o,a,_);I=D==null?void 0:D.newSheetTransform,C=D==null?void 0:D.newTransform}else{const{from:D,to:M}=w,{row:v}=D,{row:U}=M;if(_===m.SheetDrawingAnchorType.Both&&v>=o&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkRow(w,S,o,a,_);I=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!I||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};c.push(R)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:w,objects:S}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,w=h.redo,S=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_moveColInterceptor(s,r){const t=this._getUnitIdAndSubUnitId(s,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=s,o=i.startColumn,a=i.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=m.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let I,C;if(r==="insert"){const D=this._expandCol(w,S,o,a,_);I=D==null?void 0:D.newSheetTransform,C=D==null?void 0:D.newTransform}else{const{from:D,to:M}=w,{column:v}=D,{column:U}=M;if(_===m.SheetDrawingAnchorType.Both&&v>=o&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkCol(w,S,o,a,_);I=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!I||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};c.push(R)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:w,objects:S}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,w=h.redo,S=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_expandCol(s,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:o,to:a}=s,{column:d}=o,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:o.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)+p.endX-p.startX},u=x(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,column:g+i}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(s,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:o,to:a}=s,{column:d}=o,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...o,column:d-i},to:{...a,column:g-i}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,column:g-i}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,left:(r.left||0)-s.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:o.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)-p.endX+p.startX-s.from.columnOffset}}u=x(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:o.row,endRow:a.row});if(p==null)return;u={from:{...o},to:{...a,column:t-1,columnOffset:p.endX-p.startX}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(s,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:o,to:a}=s,{row:d}=o,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:o.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)+p.endY-p.startY},u=x(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,row:g+i}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(s,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:o,to:a}=s,{row:d}=o,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...o,row:d-i},to:{...a,row:g-i}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,row:g-i}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,top:(r.top||0)-s.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:o.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)-p.endY+p.startY-s.from.rowOffset}}u=x(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:o.column,endColumn:o.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...o},to:{...a,row:t-1,rowOffset:p.endY-p.startY}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(s=>{if(s.id===y.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=s.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(s=>{const{unit:r,unitId:t}=this._context;if(s){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(s){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(i=>{const o=n[i].data;o!=null&&Object.keys(o).forEach(a=>{e===s&&t.push(o[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(s,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(i=>{const o=t[i];o!=null&&Object.keys(o).forEach(a=>{const d=o[a].data;d!=null&&Object.keys(d).forEach(g=>{if(i===s&&a===r){const u=d[g];u.transform=K(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(d[g])}else n.push(d[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(s=>{_n.includes(s.id)&&requestIdleCallback(()=>{const r=s.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(s,r,t){const e=this._drawingManagerService.getDrawingData(s,r),n=[];Object.keys(e).forEach(i=>{const o=e[i],{sheetTransform:a,transform:d,anchorType:g=m.SheetDrawingAnchorType.Position}=o;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=a,{row:p,column:h}=u,{row:f,column:w}=c;for(let S=0;S<t.length;S++){const _=t[S],{startRow:I,endRow:C,startColumn:R,endColumn:D}=_;if(l.Rectangle.intersects({startRow:I,endRow:C,startColumn:R,endColumn:D},{startRow:p,endRow:f,startColumn:h,endColumn:w})||p>C||h>D){const M=g===m.SheetDrawingAnchorType.Position,v=K(a,this._selectionRenderService,this._skeletonManagerService);n.push({...o,transform:{...v,width:M?d==null?void 0:d.width:v==null?void 0:v.width,height:M?d==null?void 0:d.height:v==null?void 0:v.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[s]))}};lt=fn([de(1,k.IRenderManagerService),de(2,l.ICommandService),de(3,E.ISheetSelectionRenderService),de(4,l.Inject(E.SheetSkeletonManagerService)),de(5,l.Inject(y.SheetInterceptorService)),de(6,m.ISheetDrawingService),de(7,j.IDrawingManagerService),de(8,l.IUniverInstanceService)],lt);const vn=s=>{var I;const r=W.useDependency(l.ICommandService),t=W.useDependency(l.LocaleService),e=W.useDependency(j.IDrawingManagerService),n=W.useDependency(k.IRenderManagerService),{drawings:i}=s,o=i[0];if(o==null)return;const{unitId:a}=o,d=n.getRenderById(a),g=d==null?void 0:d.scene;if(g==null)return;const u=g.getTransformerByCreate(),[c,p]=Ie.useState(!0),h=(I=o.anchorType)!=null?I:m.SheetDrawingAnchorType.Position,[f,w]=Ie.useState(h);function S(C,R){const D=[];return C.forEach(M=>{const{oKey:v}=M,U=R.getDrawingOKey(v);if(U==null)return D.push(null),!0;const{unitId:b,subUnitId:P,drawingId:N,drawingType:O,anchorType:T,sheetTransform:B}=U;D.push({unitId:b,subUnitId:P,drawingId:N,anchorType:T,sheetTransform:B,drawingType:O})}),D}Ie.useEffect(()=>{const C=u.clearControl$.subscribe(D=>{D===!0&&p(!1)}),R=u.changeStart$.subscribe(D=>{var U;const{objects:M}=D,v=S(M,e);if(v.length===0)p(!1);else if(v.length>=1){p(!0);const b=((U=v[0])==null?void 0:U.anchorType)||m.SheetDrawingAnchorType.Position;w(b)}});return()=>{R.unsubscribe(),C.unsubscribe()}},[]);function _(C){w(C);const R=e.getFocusDrawings();if(R.length===0)return;const D=R.map(M=>({unitId:M.unitId,subUnitId:M.subUnitId,drawingId:M.drawingId,anchorType:C}));r.executeCommand(Ae.id,{unitId:R[0].unitId,drawings:D})}return Z.jsxs("div",{className:q.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!c}),children:[Z.jsx("header",{className:"univer-text-gray-600 dark:!univer-text-gray-200",children:Z.jsx("div",{children:t.t("drawing-anchor.title")})}),Z.jsx("div",{children:Z.jsxs(q.RadioGroup,{value:f,onChange:_,direction:"vertical",children:[Z.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),Z.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),Z.jsx(q.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})]})},In=()=>{const s=W.useDependency(j.IDrawingManagerService),r=s.getFocusDrawings(),[t,e]=Ie.useState(r);return Ie.useEffect(()=>{const n=s.focus$.subscribe(i=>{e(i)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&Z.jsxs("div",{className:"univer-text-sm",children:[Z.jsx(le.DrawingCommonPanel,{drawings:t}),Z.jsx(vn,{drawings:t})]})},St="sheet.menu.image";function Dn(s){return{id:St,type:W.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:W.getMenuHiddenObservable(s,l.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(s,{workbookTypes:[y.WorkbookEditablePermission],worksheetTypes:[y.WorksheetEditPermission],rangeTypes:[y.RangeProtectionPermissionEditPoint]})}}function yn(s){return{id:Pe.id,title:"sheetImage.upload.float",type:W.MenuItemType.BUTTON,hidden$:W.getMenuHiddenObservable(s,l.UniverInstanceType.UNIVER_SHEET)}}function Cn(s){return{id:mt.id,title:"sheetImage.upload.cell",type:W.MenuItemType.BUTTON,hidden$:W.getMenuHiddenObservable(s,l.UniverInstanceType.UNIVER_SHEET)}}const Tn={[W.RibbonInsertGroup.MEDIA]:{[St]:{order:0,menuItemFactory:Dn,[Pe.id]:{order:0,menuItemFactory:yn},[mt.id]:{order:1,menuItemFactory:Cn}}}};function Ne(s){return!s.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!s.getContextValue(l.EDITOR_ACTIVATED)&&!s.getContextValue(l.FOCUSING_PANEL_EDITOR)&&s.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const Mn={id:ye.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:W.KeyCode.ARROW_DOWN,priority:100,preconditions:Ne,staticParameters:{direction:l.Direction.DOWN}},Rn={id:ye.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:W.KeyCode.ARROW_UP,priority:100,preconditions:Ne,staticParameters:{direction:l.Direction.UP}},bn={id:ye.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:W.KeyCode.ARROW_LEFT,priority:100,preconditions:Ne,staticParameters:{direction:l.Direction.LEFT}},En={id:ye.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:W.KeyCode.ARROW_RIGHT,priority:100,preconditions:Ne,staticParameters:{direction:l.Direction.RIGHT}},On={id:ut.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:Ne,binding:W.KeyCode.DELETE,mac:W.KeyCode.BACKSPACE};var Un=Object.getOwnPropertyDescriptor,An=(s,r,t,e)=>{for(var n=e>1?void 0:e?Un(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},ve=(s,r)=>(t,e)=>r(t,e,s);let rt=class extends l.Disposable{constructor(s,r,t,e,n,i){super(),this._componentManager=s,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=i,this._init()}_initCustomComponents(){const s=this._componentManager;this.disposeWithMe(s.register(bt,In))}_initMenus(){this._menuManagerService.mergeMenu(Tn)}_initCommands(){[Pe,mt,Ue,De,Ae,wt,G,ft,gt,pt,ye,ut,ht].forEach(s=>this.disposeWithMe(this._commandService.registerCommand(s)))}_initShortcuts(){[Mn,Rn,bn,En,On].forEach(s=>{this.disposeWithMe(this._shortcutService.registerShortcut(s))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};rt=An([ve(0,l.Inject(W.ComponentManager)),ve(1,W.IMenuManagerService),ve(2,l.ICommandService),ve(3,W.IShortcutService),ve(4,j.IDrawingManagerService),ve(5,l.Inject(y.SheetsSelectionsService))],rt);var Pn=Object.defineProperty,Nn=Object.getOwnPropertyDescriptor,jn=(s,r,t)=>r in s?Pn(s,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[r]=t,kn=(s,r,t,e)=>{for(var n=e>1?void 0:e?Nn(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},ot=(s,r)=>(t,e)=>r(t,e,s),At=(s,r,t)=>jn(s,typeof r!="symbol"?r+"":r,t);const Wn="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Ct,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:i,...o}=l.merge({},Ct,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Lt,o)}onStarting(){l.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[rt],[qe],[nt],[tt],[et],[Ze],[Je],[Qe]]),l.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[et],[Qe]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[tt],[nt],[rt],[Ze],[Je]])}onSteady(){this._injector.get(qe)}_registerRenderModules(){[[exports.SheetDrawingUpdateController],[lt],[dt],[ct]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}};At(exports.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);At(exports.UniverSheetsDrawingUIPlugin,"pluginName",Wn);exports.UniverSheetsDrawingUIPlugin=kn([l.DependentOn(j.UniverDrawingPlugin,Rt.UniverDocsDrawingPlugin,le.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),ot(1,l.Inject(l.Injector)),ot(2,k.IRenderManagerService),ot(3,l.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=G;exports.DeleteDrawingsCommand=ut;exports.EditSheetDrawingOperation=ft;exports.GroupSheetDrawingCommand=gt;exports.InsertFloatImageCommand=Pe;exports.InsertSheetDrawingCommand=Ue;exports.MoveDrawingsCommand=ye;exports.RemoveSheetDrawingCommand=De;exports.SHEETS_IMAGE_MENU_ID=St;exports.SetDrawingArrangeCommand=ht;exports.SetSheetDrawingCommand=Ae;exports.SidebarSheetDrawingOperation=wt;exports.UngroupSheetDrawingCommand=pt;exports.calcSheetFloatDomPosition=ie;exports.drawingPositionToTransform=K;exports.transformToDrawingPosition=x;
|
|
2
|
+
`?(this._commandService.syncExecuteCommand(E.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(n.drawings)[0])):this._dialogService.open({id:"sheet-cell-image-copy-paste",title:{label:this._localeService.t("cell-image.pasteTitle")},children:{label:this._localeService.t("cell-image.pasteContent")},width:320,destroyOnClose:!0,onClose:a,showOk:!0,showCancel:!0,onOk:()=>{a(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:a})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};Qe=tn([Re(0,l.ICommandService),Re(1,l.IUniverInstanceService),Re(2,W.IDialogService),Re(3,k.IRenderManagerService),Re(4,l.Inject(l.LocaleService))],Qe);var rn=Object.getOwnPropertyDescriptor,sn=(s,r,t,e)=>{for(var n=e>1?void 0:e?rn(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},be=(s,r)=>(t,e)=>r(t,e,s);const Ot="image/png";function on(s){const r=s.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let i=0;i<e;i++)n[i]=t.charCodeAt(i);return new Blob([n],{type:Ot})}function an(s){const r=new ClipboardItem({[Ot]:on(s)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function cn(){function s(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const r=document.activeElement,t=s();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const Mt=[E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,E.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let et=class extends l.Disposable{constructor(r,t,e,n,i){super();te(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=i,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const i=this._focusedDrawings;if(i.length>0){const[o]=i;if(n===E.COPY_TYPE.CUT){const d={unitId:r,drawings:[o]};this._commandService.executeCommand(De.id,d)}setTimeout(()=>{const d=cn();o.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&o.imageSourceType===j.ImageSourceType.BASE64?an(o.source):this._clipboardInterfaceService.writeText(""),d()},200);const a={unitId:o.unitId,subUnitId:o.subUnitId,drawings:[o]};this._copyInfo=a}else{const o=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=o}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:i=E.COPY_TYPE.COPY,pasteType:o}=n,{range:a}=r||{},{range:d,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:o,unitId:g,subUnitId:u,pasteRange:d},{copyRange:a,copyType:i}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:o},E.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:E.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},E.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Pe.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var p;const n=(p=this._renderManagerService.getRenderById(r))==null?void 0:p.with(E.SheetSkeletonManagerService);if(!n)return;const i=n.attachRangeWithCoord(e);if(!i)return;const{startX:o,endX:a,startY:d,endY:g}=i,u=this._drawingService.getDrawingData(r,t),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const f=u[h],{transform:w}=f;if(f.anchorType!==m.SheetDrawingAnchorType.Both||!w)return;const{left:S=0,top:_=0,width:I=0,height:C=0}=w,{drawingStartX:R,drawingEndX:D,drawingStartY:M,drawingEndY:v}={drawingStartX:S,drawingEndX:S+I,drawingStartY:_,drawingEndY:_+C};o<=R&&D<=a&&d<=M&&v<=g&&c.push(f)}),c.length)return{copyRange:e,drawings:c,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Mt.includes(e))return{redos:[],undos:[]};const{unitId:i,subUnitId:o,range:a}=n,d=this._renderManagerService.getRenderById(i),g=d==null?void 0:d.with(E.SheetSkeletonManagerService),u=d==null?void 0:d.with(E.ISheetSelectionRenderService),c=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=c,h=E.discreteRangeToRange(a);return this._generateMutations(p,{unitId:i,subUnitId:o,isCut:t===E.COPY_TYPE.CUT,getTransform:(f,w)=>{var I;const S=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...f,left:S==null?void 0:S.startX,top:S==null?void 0:S.startY};return{transform:_,sheetTransform:(I=x(_,u))!=null?I:w}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:i,isCut:o}=t,a=[],d=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:c,sheetTransform:p}=u;if(!c)return;const h=i(c,p),f={...u,unitId:e,subUnitId:n,drawingId:o?u.drawingId:l.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(o){const{undo:w,redo:S,objects:_}=g.getBatchUpdateOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:S,objects:_}}),d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:_}})}else{const{undo:w,redo:S,objects:_}=g.getBatchAddOp([f]);a.push({id:m.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.INSERT}}),d.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.REMOVE}})}}),{redos:a,undos:d}}_generateRangeDrawingsPasteMutations(r,t){var U;const{unitId:e,subUnitId:n,pasteType:i,pasteRange:o}=r,{copyRange:a,copyType:d}=t;if(Mt.includes(i))return{redos:[],undos:[]};const g=(U=this._renderManagerService.getRenderById(e))==null?void 0:U.with(E.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:E.discreteRangeToRange(o)},pasteType:i},d);const{ranges:[c,p],mapFunc:h}=E.virtualizeDiscreteRanges([a,o]),{row:f,col:w}=h(c.startRow,c.startColumn),{row:S,col:_}=h(p.startRow,p.startColumn),I=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:w,endColumn:w}),C=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:_,endColumn:_});if(!I||!C||!this._copyInfo)return{redos:[],undos:[]};const R=C.startX-I.startX,D=C.startY-I.startY,M=S-f,v=_-w;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(b,P)=>{var N,O;return{transform:{...b,left:((N=b==null?void 0:b.left)!=null?N:0)+R,top:((O=b==null?void 0:b.top)!=null?O:0)+D},sheetTransform:{...P,to:{...P.to,row:P.to.row+M,column:P.to.column+v},from:{...P.from,row:P.from.row+M,column:P.from.column+v}}}},isCut:d===E.COPY_TYPE.CUT})}};et=sn([be(0,E.ISheetClipboardService),be(1,k.IRenderManagerService),be(2,j.IDrawingManagerService),be(3,W.IClipboardInterfaceService),be(4,l.ICommandService)],et);var dn=Object.getOwnPropertyDescriptor,ln=(s,r,t,e)=>{for(var n=e>1?void 0:e?dn(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},Ee=(s,r)=>(t,e)=>r(t,e,s);let tt=class extends l.Disposable{constructor(s,r,t,e,n){super(),this._drawingManagerService=s,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const s=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=A.combineLatest([s,r]);this.disposeWithMe(t.pipe(A.switchMap(([e,n])=>e?e.activeSheet$.pipe(A.tap(i=>{if(!i){this._drawingManagerService.setDrawingVisible(!1);return}const o=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new y.WorkbookViewPermission(o).id,new y.WorksheetViewPermission(o,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,i)})):(this._drawingManagerService.setDrawingVisible(!1),A.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(s,r){this._drawingManagerService.setDrawingVisible(!1);const t=s.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),o=this._renderManagerService.getRenderById(t),a=o==null?void 0:o.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const s=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=A.combineLatest([s,r]);this.disposeWithMe(t.pipe(A.switchMap(([e,n])=>e?e.activeSheet$.pipe(A.tap(i=>{if(!i){this._drawingManagerService.setDrawingEditable(!1);return}const o=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new y.WorkbookEditablePermission(o).id,new y.WorksheetEditPermission(o,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,i)})):(this._drawingManagerService.setDrawingEditable(!1),A.EMPTY))).subscribe())}_handleDrawingEditableFalse(s,r){this._drawingManagerService.setDrawingEditable(!1);const t=s.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),o=this._renderManagerService.getRenderById(t),a=o==null?void 0:o.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const s=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(A.combineLatest([s,r]).pipe(A.switchMap(([t,e])=>t?t.activeSheet$.pipe(A.switchMap(n=>{if(!n)return A.EMPTY;const i=t.getUnitId(),o=n.getSheetId(),a=this._renderManagerService.getRenderById(i),d=a==null?void 0:a.scene;if(!d)return A.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookViewPermission(i).id,new y.WorksheetViewPermission(i,o).id]).pipe(A.map(c=>c.every(p=>p.value)),A.distinctUntilChanged()).pipe(A.map(c=>({permission:c,scene:d,transformer:g,unitId:i,subUnitId:o})))})):A.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:o})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(i,o),g=Object.values(d);t?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),i=e==null?void 0:e.getSheetId();if(!n||!i)return;const o=this._drawingManagerService.getDrawingData(n,i),a=Object.values(o);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const s=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(A.combineLatest([s,r]).pipe(A.switchMap(([t,e])=>t?t.activeSheet$.pipe(A.switchMap(n=>{if(!n)return A.EMPTY;const i=t.getUnitId(),o=n.getSheetId(),a=this._renderManagerService.getRenderById(i),d=a==null?void 0:a.scene;if(!d)return A.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new y.WorkbookEditablePermission(i).id,new y.WorksheetEditPermission(i,o).id]).pipe(A.map(c=>c.every(p=>p.value)),A.distinctUntilChanged()).pipe(A.map(c=>({permission:c,scene:d,transformer:g,unitId:i,subUnitId:o})))})):A.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:o})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(i,o),g=Object.values(d);t?(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const i=n.getSheetId(),o=this._renderManagerService.getRenderById(e),a=o==null?void 0:o.scene;if(!a)return;const d=this._drawingManagerService.getDrawingData(e,i),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(c=>{c.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>c.oKey.includes(p.drawingId))&&a.detachTransformerFrom(c)})}}))}};tt=ln([Ee(0,j.IDrawingManagerService),Ee(1,k.IRenderManagerService),Ee(2,l.IPermissionService),Ee(3,l.IUniverInstanceService),Ee(4,l.Inject(l.UserManagerService))],tt);var un=Object.getOwnPropertyDescriptor,gn=(s,r,t,e)=>{for(var n=e>1?void 0:e?un(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},ue=(s,r)=>(t,e)=>r(t,e,s);function Ut(s,r,t,e,n,i=!1){const{scaleX:o,scaleY:a}=r.getAncestorScale(),d=r.getViewport(k.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:c,xSplit:p,ySplit:h}=g,f={left:!0,top:!0};if(!d)return{...s,absolute:f};const{left:w,right:S,top:_,bottom:I}=s;let{top:C,left:R,viewportScrollX:D,viewportScrollY:M}=d;const{boundsOfViewArea:v,scrollDirectionResponse:U}=n||{},{rowHeaderWidth:b,columnHeaderHeight:P}=t,N={top:i?0:P,left:i?0:b};v&&(l.Tools.isDefine(N.top)&&(N.top=v.top),l.Tools.isDefine(N.left)&&(N.left=v.left)),U==="HORIZONTAL"&&(M=0),U==="VERTICAL"&&(D=0);let O=0,T=0;const B=t.rowStartY(c-h)+P,$=t.colStartX(u-p)+b,z=t.rowStartY(c)+P,J=t.colStartX(u)+b;if(p===0)f.left=!1,O=(w-D)*o,T=(S-D)*o;else{const X=w-($-b),Y=S-($-b);S<J?(O=X*o,T=Y*o):w<=J&&S>=J?(O=X*o,T=Math.max(R,(S-D)*o)):w>J&&(f.left=!1,O=Math.max((w-D)*o,R),T=Math.max((S-D)*o,R))}let H=0,V=0;if(h===0)f.top=!1,H=(_-M)*a,V=(I-M)*a;else{const X=_-(B-P),Y=I-(B-P);I<z?(H=X*a,V=Y*a):_<=z&&I>=z?(H=X*a,V=Math.max(C,(I-M)*a)):_>z&&(f.top=!1,H=Math.max((_-M)*a,C),V=Math.max((I-M)*a,C))}return O=Math.max(O,N.left),H=Math.max(H,N.top),T=Math.max(T,N.left),V=Math.max(V,N.top),{left:O,right:T,top:H,bottom:V,absolute:f}}const ie=(s,r,t,e,n)=>{const{left:i,top:o,width:a,height:d,angle:g}=s,u={left:i,right:i+a,top:o,bottom:o+d},c=Ut(u,r,t,e,n),{scaleX:p,scaleY:h}=r.getAncestorScale();return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:g,width:a*p,height:d*h,absolute:c.absolute}};exports.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(t,e,n,i,o,a,d){super();te(this,"_domLayerInfoMap",new Map);te(this,"_transformChange$",new A.Subject);te(this,"transformChange$",this._transformChange$.asObservable());te(this,"_add$",new A.Subject);te(this,"add$",this._add$.asObservable());te(this,"_remove$",new A.Subject);te(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=i,this._canvasFloatDomService=o,this._sheetDrawingService=a,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(A.filter(t=>t===l.LifecycleStages.Rendered),A.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}getFloatDomsBySubUnitId(t,e){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===e&&n.unitId===t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const i=n.getTransformerByCreate(),o=e.engine.getCanvasElement();return{scene:n,transformer:i,renderUnit:e,canvas:o}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var X;const{unitId:n,subUnitId:i,drawingId:o}=e,a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),d=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!d||!a)return;const c=(X=this._renderManagerService.getRenderById(n))==null?void 0:X.with(E.SheetSkeletonManagerService).getSkeletonParam(i);if(!c)return;const{transform:p,drawingType:h,data:f}=d;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const w=this._getSceneAndTransformerByDrawingSearch(n);if(w==null)return;const{scene:S,canvas:_}=w;if(p==null)return!0;if(u!==i)return;const{left:I,top:C,width:R,height:D,angle:M,flipX:v,flipY:U,skewX:b,skewY:P}=p,N=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:o}),O=S.getObject(N);if(O!=null){O.transformByState({left:I,top:C,width:R,height:D,angle:M,flipX:v,flipY:U,skewX:b,skewY:P});return}const T={left:I,top:C,width:R,height:D,zIndex:this._drawingManagerService.getDrawingOrder(n,i).length-1},B=h===l.DrawingTypeEnum.DRAWING_CHART;if(T.rotateEnabled=!1,B){const Y=f?f.backgroundColor:"white";T.fill=Y,f&&f.border&&(T.stroke=f.border),T.paintFirst="stroke",T.strokeWidth=1,T.borderEnabled=!1,T.radius=8}const $=new k.Rect(N,T);B&&$.setObjectType(k.ObjectType.CHART),S.addObject($,k.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo($);const z=new l.DisposableCollection,J=ie($,w.renderUnit.scene,c.skeleton,a.worksheet),H=new A.BehaviorSubject(J),V={dispose:z,rect:$,position$:H,unitId:n,subUnitId:i,id:o};this._canvasFloatDomService.addFloatDom({position$:H,id:o,componentKey:d.componentKey,onPointerDown:Y=>{_.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{_.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{_.dispatchEvent(new PointerEvent(Y.type,Y))},onWheel:Y=>{_.dispatchEvent(new WheelEvent(Y.type,Y))},data:f,unitId:n});const Q=$.onTransformChange$.subscribeEvent(()=>{const Y=ie($,w.renderUnit.scene,c.skeleton,a.worksheet);H.next(Y)});z.add(()=>{this._canvasFloatDomService.removeFloatDom(o)}),Q&&z.add(Q),this._domLayerInfoMap.set(o,V)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{var p;const{unitId:n,subUnitId:i,drawingId:o}=e,a=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:o}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:g,scene:u}=d,c=u.getObject(a);c!=null&&c.oKey&&(g.clearControlByIds([c==null?void 0:c.oKey]),(p=u.getTransformer())==null||p.clearSelectedObjects())})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const i=this._getSceneAndTransformerByDrawingSearch(e),o=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===e).map(u=>u.id),a=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(E.SheetSkeletonManagerService).getSkeletonParam(n);!i||!a||!d||o.forEach(u=>{const c=this._domLayerInfoMap.get(u);if(c){const p=ie(c.rect,i.renderUnit.scene,d.skeleton,a.worksheet,c);c.position$.next(p)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(A.switchMap(e=>e?e.activeSheet$:A.of(null)),A.map(e=>{if(!e)return null;const n=e.getUnitId(),i=this._renderManagerService.getRenderById(n);return i?{render:i,unitId:n,subUnitId:e.getSheetId()}:null}),A.switchMap(e=>e?l.fromEventSubject(e.render.scene.getViewport(k.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(A.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):A.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:i}=e;t(n,i)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===E.SetZoomRatioOperation.id){const n=e.params,{unitId:i}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===i).map(a=>a.subUnitId).forEach(a=>{t(i,a)})}else if(e.id===y.SetFrozenMutation.id){const{unitId:n,subUnitId:i}=e.params;t(n,i)}}))}updateFloatDomProps(t,e,n,i){const o=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(o&&a){const{scene:d}=a,g=j.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=d.getObject(g);u&&u instanceof k.Rect&&u.setProps(i)}}_getPosition(t,e){var h;const{startX:n,endX:i,startY:o,endY:a}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(E.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(n,o);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:o-g.startY},c=d.getCellWithCoordByOffset(i,a);if(c==null)return;const p={column:c.actualColumn,columnOffset:i-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const i={...n.transform};this._transformChange$.next({id:e.drawingId,value:i}),this._canvasFloatDomService.updateFloatDom(e.drawingId,{...n});const o=this._getSceneAndTransformerByDrawingSearch(e.unitId);if(o&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART){const{scene:a}=o,d=this._domLayerInfoMap.get(e.drawingId);d!=null&&d.rect&&(n.allowTransform===!1?a.detachTransformerFrom(d.rect):a.attachTransformerTo(d.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(t,e){const n=y.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:i,subUnitId:o}=n,{initPosition:a,componentKey:d,data:g,allowTransform:u=!0}=t,c=e!=null?e:l.generateRandomId(),p=this._getPosition(a,i);if(p==null)return;const h={unitId:i,subUnitId:o,drawingId:c,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:p,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Ue.id,{unitId:i,drawings:[h]}),this._add$.next({unitId:i,subUnitId:o,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:i,subUnitId:o}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(i);if(a&&a.scene.removeObject(n.rect),e){const d=this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:o,drawingId:t});if(!d)return;const g=this._sheetDrawingService.getBatchRemoveOp([d]),{redo:u,objects:c}=g;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:i,subUnitId:o,op:u,objects:c,type:m.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,i){var v,U,b;const o=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=o,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(v=this._renderManagerService.getRenderById(a))==null?void 0:v.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,w=i!=null?i:l.generateRandomId(),{position:S,position$:_}=this._createRangePositionObserver(t,u,c.skeleton);if(this._getPosition(S,a)==null)return;const C=g.scene,{scaleX:R}=C.getAncestorScale(),D=Ve(S,n,R),M={unitId:a,subUnitId:d,drawingId:w,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:D.startX,top:D.startY,width:D.width,height:D.height},data:h,allowTransform:f};{const{unitId:P,subUnitId:N,drawingId:O}=M,T=y.getSheetCommandTarget(this._univerInstanceService,{unitId:P,subUnitId:N}),B=M,$=this._univerInstanceService.getUnit(P,l.UniverInstanceType.UNIVER_SHEET);if(!$)return;const z=$.getActiveSheet().getSheetId();if(!B||!T)return;const J=(U=this._renderManagerService.getRenderById(P))==null?void 0:U.with(E.SheetSkeletonManagerService);if(!J)return;const H=J.getWorksheetSkeleton(N);if(!H)return;const{transform:V,drawingType:Q,data:X}=B;if(Q!==l.DrawingTypeEnum.DRAWING_DOM&&Q!==l.DrawingTypeEnum.DRAWING_CHART)return;const Y=this._getSceneAndTransformerByDrawingSearch(P);if(Y==null)return;const{scene:he,canvas:pe}=Y;if(V==null||z!==N)return;const{left:je,top:ke,width:We,height:Be,angle:it,flipX:st,flipY:Ye,skewX:Fe,skewY:me}=V,$e=j.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:N,drawingId:O}),se=he.getObject($e);if(se!=null){se.transformByState({left:je,top:ke,width:We,height:Be,angle:it,flipX:st,flipY:Ye,skewX:Fe,skewY:me});return}const ee={left:je,top:ke,width:We,height:Be,zIndex:this._drawingManagerService.getDrawingOrder(P,N).length-1},we=Q===l.DrawingTypeEnum.DRAWING_CHART;if(we){const F=X?X.backgroundColor:"white";ee.fill=F,ee.rotateEnabled=!1,X&&X.border&&(ee.stroke=X.border),ee.paintFirst="stroke",ee.strokeWidth=1,ee.borderEnabled=!1,ee.radius=8}const oe=new k.Rect($e,ee);we&&oe.setObjectType(k.ObjectType.CHART),he.addObject(oe,k.DRAWING_OBJECT_LAYER_INDEX),B.allowTransform!==!1&&he.attachTransformerTo(oe);const ae=new l.DisposableCollection,xe=he.getMainViewport(),{rowHeaderWidth:fe,columnHeaderHeight:Ce}=H.skeleton,Le={top:Ce,left:fe,bottom:xe.bottom,right:xe.right},ce={dispose:ae,rect:oe,boundsOfViewArea:Le,domAnchor:n,unitId:P,subUnitId:N},L=ie(oe,Y.renderUnit.scene,H.skeleton,T.worksheet,ce),Se=new A.BehaviorSubject(L);ce.position$=Se;let Te={position$:Se,id:O,componentKey:B.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:F=>{pe.dispatchEvent(new WheelEvent(F.type,F))},data:X,unitId:P};e.eventPassThrough&&(Te={...Te,onPointerDown:F=>{pe.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{pe.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{pe.dispatchEvent(new PointerEvent(F.type,F))}}),this._canvasFloatDomService.addFloatDom(Te),this.disposeWithMe(_.subscribe(F=>{var vt,It,Dt,yt;const _t=Ve({startX:F.startX,startY:F.startY,endX:F.endX,endY:F.endY,width:(vt=n.width)!=null?vt:F.width,height:(It=n.height)!=null?It:F.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Pt=j.getDrawingShapeKeyByDrawingSearch({unitId:P,subUnitId:N,drawingId:O}),Nt=new k.Rect(Pt,{left:_t.startX,top:_t.startY,width:(Dt=n.width)!=null?Dt:F.width,height:(yt=n.height)!=null?yt:F.height,zIndex:this._drawingManagerService.getDrawingOrder(P,N).length-1}),jt=ie(Nt,Y.renderUnit.scene,H.skeleton,T.worksheet,ce);Se.next(jt)}));const Me=(b=this._renderManagerService.getRenderById(P))==null?void 0:b.with(E.SheetSkeletonManagerService);Me==null||Me.currentSkeleton$.subscribe(F=>{F&&H.sheetId!==F.sheetId&&this._removeDom(w,!0)});const Ge=oe.onTransformChange$.subscribeEvent(()=>{const F=ie(oe,Y.renderUnit.scene,H.skeleton,T.worksheet,ce);Se.next(F)});ae.add(()=>{this._canvasFloatDomService.removeFloatDom(O)}),Ge&&ae.add(Ge),this._domLayerInfoMap.set(O,ce)}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}addFloatDomToColumnHeader(t,e,n,i){var D,M,v;const o=y.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=o;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(D=this._renderManagerService.getRenderById(a))==null?void 0:D.with(E.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:f=!0}=e,w=i!=null?i:l.generateRandomId(),{position:S,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,c.skeleton),I=S;if(I.startY=0,this._getPosition(S,a)==null)return;const R={unitId:a,subUnitId:d,drawingId:w,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:f};{const{unitId:U,subUnitId:b,drawingId:P}=R,N=y.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:b}),O=R,T=this._univerInstanceService.getUnit(U,l.UniverInstanceType.UNIVER_SHEET);if(!T)return;const B=T.getActiveSheet().getSheetId();if(!O||!N)return;const $=(M=this._renderManagerService.getRenderById(U))==null?void 0:M.with(E.SheetSkeletonManagerService);if(!$)return;const z=$.getWorksheetSkeleton(b);if(!z)return;const{transform:J,data:H}=O,V=this._getSceneAndTransformerByDrawingSearch(U);if(V==null)return;const{scene:Q,canvas:X}=V;if(J==null||B!==b)return;const{left:Y,top:he,width:pe,height:je,angle:ke,flipX:We,flipY:Be,skewX:it,skewY:st}=J,Ye=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:P}),Fe=Q.getObject(Ye);if(Fe!=null){Fe.transformByState({left:Y,top:he,width:pe,height:je,angle:ke,flipX:We,flipY:Be,skewX:it,skewY:st});return}const me=Ve({startX:I.startX,startY:0,endX:S.endX,endY:S.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),$e={left:me.startX,top:me.startY,width:me.width,height:me.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1},se=new k.Rect(Ye,$e);Q.addObject(se,k.DRAWING_OBJECT_LAYER_INDEX),O.allowTransform!==!1&&Q.attachTransformerTo(se);const ee=new l.DisposableCollection,we=Q.getMainViewport(),oe={top:0,left:we.left,bottom:we.bottom,right:we.right},ae={dispose:ee,rect:se,unitId:U,subUnitId:b,boundsOfViewArea:oe,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},xe=ie(se,V.renderUnit.scene,z.skeleton,N.worksheet,ae),fe=new A.BehaviorSubject(xe);ae.position$=fe;let Ce={position$:fe,id:P,componentKey:O.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:L=>{X.dispatchEvent(new WheelEvent(L.type,L))},data:H,unitId:U};e.eventPassThrough&&(Ce={...Ce,onPointerDown:L=>{X.dispatchEvent(new PointerEvent(L.type,L))},onPointerMove:L=>{X.dispatchEvent(new PointerEvent(L.type,L))},onPointerUp:L=>{X.dispatchEvent(new PointerEvent(L.type,L))}}),this._canvasFloatDomService.addFloatDom(Ce);const Le=se.onTransformChange$.subscribeEvent(()=>{const L=ie(se,V.renderUnit.scene,z.skeleton,N.worksheet,ae);fe.next(L)});this.disposeWithMe(_.subscribe(L=>{const Se=Ve({startX:L.startX,startY:0,endX:L.endX,endY:L.endY,width:n.width,height:n.height,absolute:{left:S.absolute.left,top:S.absolute.top}},n),Te=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:b,drawingId:P}),Me=new k.Rect(Te,{left:Se.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(U,b).length-1}),Ge=ie(Me,V.renderUnit.scene,z.skeleton,N.worksheet,ae);fe.next(Ge)}));const ce=(v=this._renderManagerService.getRenderById(U))==null?void 0:v.with(E.SheetSkeletonManagerService);ce==null||ce.currentSkeleton$.subscribe(L=>{L&&c.sheetId!==L.sheetId&&this._removeDom(w,!0)}),ee.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),Le&&ee.add(Le),this._domLayerInfoMap.set(P,ae)}return{id:w,dispose:()=>{this._removeDom(w,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:i,startColumn:o}=t;const a=Oe(i,o,n),d=new A.BehaviorSubject(a),g=Oe(t.endRow,t.endColumn,n),u=new A.BehaviorSubject(g),c=()=>{const _=Oe(i,o,n),I=Oe(t.endRow,t.endColumn,n);d.next(_),u.next(I)},p=new l.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>c())),p.add(this._commandService.onCommandExecuted(_=>{if(_.id===y.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(C=>C.row===i)>-1){c();return}(y.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===E.SetScrollOperation.id||_.id===E.SetZoomRatioOperation.id)&&c()}));const h=(_,I)=>{i=_,o=I,c()},f=()=>({rotate:0,width:g.right-a.left,height:g.bottom-a.top,absolute:{left:!0,top:!0},startX:a.left,startY:a.top,endX:g.right,endY:g.bottom}),w=d.pipe(A.map(_=>{const I=Oe(t.endRow,t.endColumn,n);return{rotate:0,width:I.right-_.left,height:I.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:I.right,endY:I.bottom}})),S=f();return{position$:w,position:S,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:p}}};exports.SheetCanvasFloatDomManagerService=gn([ue(0,l.Inject(k.IRenderManagerService)),ue(1,l.IUniverInstanceService),ue(2,l.Inject(l.ICommandService)),ue(3,j.IDrawingManagerService),ue(4,l.Inject(W.CanvasFloatDomService)),ue(5,m.ISheetDrawingService),ue(6,l.Inject(l.LifecycleService))],exports.SheetCanvasFloatDomManagerService);function Oe(s,r,t){const e=t.getCellWithCoordByIndex(s,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Ve(s,r,t){var g,u;t=t!=null?t:1;const e=s.endX-s.startX,n=s.endY-s.startY,i=(g=r==null?void 0:r.width)!=null?g:e,o=(u=r==null?void 0:r.height)!=null?u:n;let a=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=Ke(r.marginX,e*t);a=s.endX-c-i}else a=s.startX+Ke(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const c=Ke(r.marginY,n*t);d=s.endY-c-o}else d=s.startY+Ke(r.marginY,n)}return{rotate:0,startX:a,startY:d,endX:s.endX,endY:s.endY,width:i,height:o,absolute:{left:s.absolute.left,top:s.absolute.top}}}function Ke(s,r){if(s===void 0)return 0;if(typeof s=="number")return s;const t=Number.parseFloat(s);return r*t/100}const hn=s=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=s,i=Ie.useMemo(()=>r.map(o=>{const{width:a,height:d,angle:g,left:u,top:c}=o.transform,p=Ut({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:c!=null?c:0,bottom:(c!=null?c:0)+(d!=null?d:0)},t,e,n,void 0,!0),{scaleX:h,scaleY:f}=t.getAncestorScale(),w={startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:g,width:a*h,height:d*f,absolute:p.absolute},S={position$:new A.BehaviorSubject(w),position:w,id:o.drawingId,componentKey:o.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:o.unitId,data:o.data};return[o.drawingId,S]}),[r,t,e,n]);return Z.jsx("div",{style:{position:"absolute",top:0,left:0},children:i.map(([o,a])=>Z.jsx(W.PrintFloatDomSingle,{layer:a,id:o,position:a.position},o))})};var pn=Object.getOwnPropertyDescriptor,mn=(s,r,t,e)=>{for(var n=e>1?void 0:e?pn(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},ge=(s,r)=>(t,e)=>r(t,e,s);let nt=class extends l.Disposable{constructor(s,r,t,e,n,i,o){super(),this._sheetPrintInterceptorService=s,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=i,this._injector=o,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(s,r,t)=>{const{unitId:e,scene:n,subUnitId:i}=r,o=this._drawingManagerService.getDrawingDataForUnit(e),a=o==null?void 0:o[i];return a&&a.order.forEach(d=>{const g=a.data[d];g.drawingType!==l.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(s,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._renderManagerService.getRenderById(e);if(!i)return t(s);const o=i.with(E.SheetSkeletonManagerService).getSkeletonParam(n);if(!o)return t(s);const a=this._drawingManagerService.getDrawingDataForUnit(e),d=a==null?void 0:a[r.subUnitId];if(!d)return t(s);const{scaleX:g,scaleY:u}=i.scene,c=s?{...s}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=d.order.map(h=>d.data[h]);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const f=o.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),w=o.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});f.column<c.startColumn&&(c.startColumn=f.column),f.row<c.startRow&&(c.startRow=f.row),c.endRow<w.row&&(c.endRow=w.row),c.endColumn<w.column&&(c.endColumn=w.column)}}),t(c)):t(s)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(s,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._drawingManagerService.getDrawingDataForUnit(e),o=i==null?void 0:i[n];if(o){const a=o.order.map(g=>{const u=o.data[g];if(u.drawingType===l.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(l.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===l.DrawingTypeEnum.DRAWING_DOM){const c=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(c||u.componentKey)}}return null}).filter(Boolean),d=W.connectInjector(hn,this._injector);return q.render(Z.jsx(d,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),s==null||s.add(()=>{q.unmount(r.root)}),t(s)}}}))}};nt=mn([ge(0,l.Inject(E.SheetPrintInterceptorService)),ge(1,l.Inject(le.DrawingRenderService)),ge(2,j.IDrawingManagerService),ge(3,k.IRenderManagerService),ge(4,l.Inject(exports.SheetCanvasFloatDomManagerService)),ge(5,l.Inject(W.ComponentManager)),ge(6,l.Inject(l.Injector))],nt);var wn=Object.getOwnPropertyDescriptor,fn=(s,r,t,e)=>{for(var n=e>1?void 0:e?wn(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},de=(s,r)=>(t,e)=>r(t,e,s);const Sn=[y.InsertRowCommand.id,y.InsertColCommand.id,y.RemoveRowCommand.id,y.RemoveColCommand.id,y.DeleteRangeMoveLeftCommand.id,y.DeleteRangeMoveUpCommand.id,y.InsertRangeMoveDownCommand.id,y.InsertRangeMoveRightCommand.id,y.DeltaRowHeightCommand.id,y.SetRowHeightCommand.id,y.DeltaColumnWidthCommand.id,y.SetColWidthCommand.id,y.SetRowHiddenCommand.id,y.SetSpecificRowsVisibleCommand.id,y.SetSpecificColsVisibleCommand.id,y.SetColHiddenCommand.id,y.MoveColsCommand.id,y.MoveRowsCommand.id,y.MoveRangeCommand.id],_n=[y.SetRowVisibleMutation.id,y.SetRowHiddenMutation.id,y.SetColVisibleMutation.id,y.SetColHiddenMutation.id,y.SetWorksheetRowHeightMutation.id,y.SetWorksheetColWidthMutation.id];let lt=class extends l.Disposable{constructor(s,r,t,e,n,i,o,a,d){super(),this._context=s,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=i,this._sheetDrawingService=o,this._drawingManagerService=a,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({getMutations:s=>{if(!Sn.includes(s.id))return{redos:[],undos:[]};if(s.params==null)return{redos:[],undos:[]};const r=s.id;if(r===y.InsertRowCommand.id)return this._moveRowInterceptor(s.params,"insert");if([y.MoveColsCommand.id,y.MoveRowsCommand.id,y.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(s.params);if(r===y.InsertColCommand.id)return this._moveColInterceptor(s.params,"insert");if(r===y.RemoveRowCommand.id)return this._moveRowInterceptor(s.params,"remove");if(r===y.RemoveColCommand.id)return this._moveColInterceptor(s.params,"remove");if(r===y.DeleteRangeMoveLeftCommand.id){const{range:t}=s.params;return this._getRangeMoveUndo(t,0)}else if(r===y.DeleteRangeMoveUpCommand.id){const{range:t}=s.params;return this._getRangeMoveUndo(t,1)}else if(r===y.InsertRangeMoveDownCommand.id){const{range:t}=s.params;return this._getRangeMoveUndo(t,2)}else if(r===y.InsertRangeMoveRightCommand.id){const{range:t}=s.params;return this._getRangeMoveUndo(t,3)}else if(r===y.SetRowHiddenCommand.id||r===y.SetSpecificRowsVisibleCommand.id){const t=s.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForRowVisible(e,n,i)}else if(r===y.SetSpecificColsVisibleCommand.id||r===y.SetColHiddenCommand.id){const t=s.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForColVisible(e,n,i)}else if(r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id||r===y.DeltaColumnWidthCommand.id||r===y.SetColWidthCommand.id){const t=s.params,{unitId:e,subUnitId:n,ranges:i}=t,o=r===y.DeltaRowHeightCommand.id||r===y.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,i,o)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(s,r){const t=y.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,i=[],o=[],a=this._sheetDrawingService.getDrawingData(e,n),d=[],g=[];if(Object.keys(a).forEach(u=>{const c=a[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(s,r,c);d.push(...p),g.push(...h)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:p,objects:h}=u;i.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),c=u.undo,p=u.redo,h=u.objects;i.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),o.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.INSERT}})}return i.push({id:G.id,params:[e]}),o.push({id:G.id,params:[e]}),{redos:i,undos:o}}_getUpdateOrDeleteDrawings(s,r,t){const e=[],n=[],{sheetTransform:i,anchorType:o=m.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:g,drawingId:u}=t,{from:c,to:p}=i,{row:h,column:f}=c,{row:w,column:S}=p;if(i==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:_,endRow:I,startColumn:C,endColumn:R}=s;let D=null,M=null;if(r===0&&h>=_&&w<=I)if(f>=C&&S<=R)n.push({unitId:d,subUnitId:g,drawingId:u});else{const v=this._shrinkCol(i,a,C,R,o);D=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(r===1&&f>=C&&S<=R)if(h>=_&&w<=I)n.push({unitId:d,subUnitId:g,drawingId:u});else{const v=this._shrinkRow(i,a,_,I,o);D=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(r===2){const v=this._expandRow(i,a,_,I,o);D=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(r===3){const v=this._expandCol(i,a,C,R,o);D=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}if(D!=null&&M!=null){const v=K(D,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:D,transform:v})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(s,r,t){const e=x({...s},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(s,r,t){const e=this._drawingManagerService.getDrawingData(s,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=p,{row:_,column:I}=w,{row:C,column:R}=S;for(let D=0;D<t.length;D++){const M=t[D],{startRow:v,endRow:U,startColumn:b,endColumn:P}=M;if(R<b)continue;if(f===m.SheetDrawingAnchorType.Position){let T=null,B=null;if(I>=b&&I<=P){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:P,startRow:w.row,endRow:S.row});if($==null)return;B={...h,left:$.startX}}if(B!=null&&(T=x(B,this._selectionRenderService),T!=null&&B!=null)){n.push({...c,sheetTransform:T,transform:B});break}this._remainDrawingSize(h,n,c);continue}if(I>=b&&R<=P)continue;let N=null,O=null;if(I>=b&&I<=P){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:P,startRow:w.row,endRow:S.row});if(T==null)return;O={...h,left:(T==null?void 0:T.startX)||0,width:((h==null?void 0:h.width)||0)-T.endX+T.startX}}else if(R>=b&&R<=P){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:R,startRow:w.row,endRow:S.row});if(T==null)return;O={...h,left:T.startX-((h==null?void 0:h.width)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:P,startRow:w.row,endRow:S.row});if(T==null)return;if(O={...h,width:((h==null?void 0:h.width)||0)-T.endX+T.startX},N=x(O,this._selectionRenderService),N!=null&&O!=null){i.push({...c,sheetTransform:N,transform:O});break}}if(O!=null&&(N=x(O,this._selectionRenderService)),O!=null&&N!=null){n.push({...c,sheetTransform:N,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&i.length===0)return{redos:[],undos:[]};const{redos:o,undos:a}=this._createUndoAndRedoMutation(s,r,n),d=[],g=[];if(i.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(s,r,i);d.push(...u),g.push(...c)}return{redos:o,undos:a,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(s,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:i,objects:o}=e,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:r,op:i,objects:o,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}],d=[{id:m.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:r,op:n,objects:o,type:m.DrawingApplyType.UPDATE}},{id:G.id,params:[s]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(s,r,t){const e=this._drawingManagerService.getDrawingData(s,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:f=m.SheetDrawingAnchorType.Position}=c;if(f===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:w,to:S}=p,{row:_,column:I}=w,{row:C,column:R}=S;for(let D=0;D<t.length;D++){const M=t[D],{startRow:v,endRow:U,startColumn:b,endColumn:P}=M;if(C<v)continue;if(f===m.SheetDrawingAnchorType.Position){let T=null,B=null;if(_>=v&&_<=U){const $=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:_,endRow:U});if($==null)return;B={...h,top:$.startY}}if(B!=null&&(T=x(B,this._selectionRenderService),T!=null&&B!=null)){n.push({...c,sheetTransform:T,transform:B});break}this._remainDrawingSize(h,n,c);continue}if(_>=v&&C<=U)continue;let N=null,O=null;if(_>=v&&_<=U){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:_,endRow:U});if(T==null)return;O={...h,top:(T==null?void 0:T.startY)||0,height:((h==null?void 0:h.height)||0)-T.endY+T.startY}}else if(C>=v&&C<=U){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:C});if(T==null)return;O={...h,top:T.startY-((h==null?void 0:h.height)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:U});if(T==null)return;if(O={...h,height:((h==null?void 0:h.height)||0)-T.endY+T.startY},N=x(O,this._selectionRenderService),N!=null&&O!=null){i.push({...c,sheetTransform:N,transform:O});break}}if(O!=null&&(N=x(O,this._selectionRenderService)),O!=null&&N!=null){n.push({...c,sheetTransform:N,transform:O});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&i.length===0)return{redos:[],undos:[]};const{redos:o,undos:a}=this._createUndoAndRedoMutation(s,r,n),d=[],g=[];if(i.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(s,r,i);d.push(...u),g.push(...c)}return{redos:o,undos:a,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(s,r,t,e){const n=this._drawingManagerService.getDrawingData(s,r),i=[];return Object.keys(n).forEach(o=>{const a=n[o],{sheetTransform:d,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=a;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,i,a);else{const{from:c,to:p}=d,{row:h,column:f}=c,{row:w,column:S}=p;for(let _=0;_<t.length;_++){const I=t[_],{startRow:C,endRow:R,startColumn:D,endColumn:M}=I;if(w<C||S<D)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=C&&w>=R||f<=D&&S>=M)){this._remainDrawingSize(g,i,a);continue}const v=K({...d},this._selectionRenderService,this._skeletonManagerService);if(v!=null){i.push({...a,transform:v});break}}}}),i.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(s,r,i)}_getUnitIdAndSubUnitId(s,r){let t,e;if(r==="insert")t=s.unitId,e=s.subUnitId;else{const n=y.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(s){var C,R;const{toRange:r,fromRange:t}=s,e=y.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:i}=e,o=(R=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.with(E.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!o)return{redos:[],undos:[]};const a=E.attachRangeWithCoord(o,t);if(!a)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=a,p=this._sheetDrawingService.getDrawingData(n,i),h=[];Object.keys(p).forEach(D=>{const M=p[D];if(M.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:v}=M;if(!v)return;const{left:U=0,top:b=0,width:P=0,height:N=0}=v,{drawingStartX:O,drawingEndX:T,drawingStartY:B,drawingEndY:$}={drawingStartX:U,drawingEndX:U+P,drawingStartY:b,drawingEndY:b+N};d<=O&&T<=g&&u<=B&&$<=c&&h.push(M)});const f=[],w=[],S=r.startRow-t.startRow,_=r.startColumn-t.startColumn,I=h.map(D=>{const M=D.sheetTransform,v={to:{...M.to,row:M.to.row+S,column:M.to.column+_},from:{...M.from,row:M.from.row+S,column:M.from.column+_}},U=K(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:i,drawingId:D.drawingId,transform:U,sheetTransform:v}});if(I.length){const D=this._sheetDrawingService.getBatchUpdateOp(I),{undo:M,redo:v,objects:U}=D;f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:v,objects:U,type:m.DrawingApplyType.UPDATE}}),w.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:M,objects:U,type:m.DrawingApplyType.UPDATE}})}return{redos:f,undos:w}}_moveRowInterceptor(s,r){const t=this._getUnitIdAndSubUnitId(s,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=s,o=i.startRow,a=i.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=m.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let I,C;if(r==="insert"){const D=this._expandRow(w,S,o,a,_);I=D==null?void 0:D.newSheetTransform,C=D==null?void 0:D.newTransform}else{const{from:D,to:M}=w,{row:v}=D,{row:U}=M;if(_===m.SheetDrawingAnchorType.Both&&v>=o&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkRow(w,S,o,a,_);I=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!I||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};c.push(R)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:w,objects:S}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,w=h.redo,S=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_moveColInterceptor(s,r){const t=this._getUnitIdAndSubUnitId(s,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=s,o=i.startColumn,a=i.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const f=u[h],{sheetTransform:w,transform:S,anchorType:_=m.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let I,C;if(r==="insert"){const D=this._expandCol(w,S,o,a,_);I=D==null?void 0:D.newSheetTransform,C=D==null?void 0:D.newTransform}else{const{from:D,to:M}=w,{column:v}=D,{column:U}=M;if(_===m.SheetDrawingAnchorType.Both&&v>=o&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const b=this._shrinkCol(w,S,o,a,_);I=b==null?void 0:b.newSheetTransform,C=b==null?void 0:b.newTransform}}if(!I||!C)return;const R={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};c.push(R)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:f,redo:w,objects:S}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),f=h.undo,w=h.redo,S=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:w,objects:S,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:S,type:m.DrawingApplyType.INSERT}})}return d.push({id:G.id,params:[e]}),g.push({id:G.id,params:[e]}),{redos:d,undos:g}}_expandCol(s,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:o,to:a}=s,{column:d}=o,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:o.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)+p.endX-p.startX},u=x(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,column:g+i}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(s,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:o,to:a}=s,{column:d}=o,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...o,column:d-i},to:{...a,column:g-i}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,column:g-i}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,left:(r.left||0)-s.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:o.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)-p.endX+p.startX-s.from.columnOffset}}u=x(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:o.row,endRow:a.row});if(p==null)return;u={from:{...o},to:{...a,column:t-1,columnOffset:p.endX-p.startX}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(s,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:o,to:a}=s,{row:d}=o,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:o.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)+p.endY-p.startY},u=x(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,row:g+i}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(s,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:o,to:a}=s,{row:d}=o,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...o,row:d-i},to:{...a,row:g-i}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,row:g-i}},c=K(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:x({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,top:(r.top||0)-s.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:o.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)-p.endY+p.startY-s.from.rowOffset}}u=x(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:o.column,endColumn:o.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...o},to:{...a,row:t-1,rowOffset:p.endY-p.startY}},c=K(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(s=>{if(s.id===y.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=s.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(s=>{const{unit:r,unitId:t}=this._context;if(s){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(s){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(i=>{const o=n[i].data;o!=null&&Object.keys(o).forEach(a=>{e===s&&t.push(o[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(s,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(i=>{const o=t[i];o!=null&&Object.keys(o).forEach(a=>{const d=o[a].data;d!=null&&Object.keys(d).forEach(g=>{if(i===s&&a===r){const u=d[g];u.transform=K(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(d[g])}else n.push(d[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(s=>{_n.includes(s.id)&&requestIdleCallback(()=>{const r=s.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(s,r,t){const e=this._drawingManagerService.getDrawingData(s,r),n=[];Object.keys(e).forEach(i=>{const o=e[i],{sheetTransform:a,transform:d,anchorType:g=m.SheetDrawingAnchorType.Position}=o;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=a,{row:p,column:h}=u,{row:f,column:w}=c;for(let S=0;S<t.length;S++){const _=t[S],{startRow:I,endRow:C,startColumn:R,endColumn:D}=_;if(l.Rectangle.intersects({startRow:I,endRow:C,startColumn:R,endColumn:D},{startRow:p,endRow:f,startColumn:h,endColumn:w})||p>C||h>D){const M=g===m.SheetDrawingAnchorType.Position,v=K(a,this._selectionRenderService,this._skeletonManagerService);n.push({...o,transform:{...v,width:M?d==null?void 0:d.width:v==null?void 0:v.width,height:M?d==null?void 0:d.height:v==null?void 0:v.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(G.id,[s]))}};lt=fn([de(1,k.IRenderManagerService),de(2,l.ICommandService),de(3,E.ISheetSelectionRenderService),de(4,l.Inject(E.SheetSkeletonManagerService)),de(5,l.Inject(y.SheetInterceptorService)),de(6,m.ISheetDrawingService),de(7,j.IDrawingManagerService),de(8,l.IUniverInstanceService)],lt);const vn=s=>{var I;const r=W.useDependency(l.ICommandService),t=W.useDependency(l.LocaleService),e=W.useDependency(j.IDrawingManagerService),n=W.useDependency(k.IRenderManagerService),{drawings:i}=s,o=i[0];if(o==null)return;const{unitId:a}=o,d=n.getRenderById(a),g=d==null?void 0:d.scene;if(g==null)return;const u=g.getTransformerByCreate(),[c,p]=Ie.useState(!0),h=(I=o.anchorType)!=null?I:m.SheetDrawingAnchorType.Position,[f,w]=Ie.useState(h);function S(C,R){const D=[];return C.forEach(M=>{const{oKey:v}=M,U=R.getDrawingOKey(v);if(U==null)return D.push(null),!0;const{unitId:b,subUnitId:P,drawingId:N,drawingType:O,anchorType:T,sheetTransform:B}=U;D.push({unitId:b,subUnitId:P,drawingId:N,anchorType:T,sheetTransform:B,drawingType:O})}),D}Ie.useEffect(()=>{const C=u.clearControl$.subscribe(D=>{D===!0&&p(!1)}),R=u.changeStart$.subscribe(D=>{var U;const{objects:M}=D,v=S(M,e);if(v.length===0)p(!1);else if(v.length>=1){p(!0);const b=((U=v[0])==null?void 0:U.anchorType)||m.SheetDrawingAnchorType.Position;w(b)}});return()=>{R.unsubscribe(),C.unsubscribe()}},[]);function _(C){w(C);const R=e.getFocusDrawings();if(R.length===0)return;const D=R.map(M=>({unitId:M.unitId,subUnitId:M.subUnitId,drawingId:M.drawingId,anchorType:C}));r.executeCommand(Ae.id,{unitId:R[0].unitId,drawings:D})}return Z.jsxs("div",{className:q.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!c}),children:[Z.jsx("header",{className:"univer-text-gray-600 dark:!univer-text-gray-200",children:Z.jsx("div",{children:t.t("drawing-anchor.title")})}),Z.jsx("div",{children:Z.jsxs(q.RadioGroup,{value:f,onChange:_,direction:"vertical",children:[Z.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),Z.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),Z.jsx(q.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})]})},In=()=>{const s=W.useDependency(j.IDrawingManagerService),r=s.getFocusDrawings(),[t,e]=Ie.useState(r);return Ie.useEffect(()=>{const n=s.focus$.subscribe(i=>{e(i)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&Z.jsxs("div",{className:"univer-text-sm",children:[Z.jsx(le.DrawingCommonPanel,{drawings:t}),Z.jsx(vn,{drawings:t})]})},St="sheet.menu.image";function Dn(s){return{id:St,type:W.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:W.getMenuHiddenObservable(s,l.UniverInstanceType.UNIVER_SHEET),disabled$:E.getCurrentRangeDisable$(s,{workbookTypes:[y.WorkbookEditablePermission],worksheetTypes:[y.WorksheetEditPermission],rangeTypes:[y.RangeProtectionPermissionEditPoint]})}}function yn(s){return{id:Pe.id,title:"sheetImage.upload.float",type:W.MenuItemType.BUTTON,hidden$:W.getMenuHiddenObservable(s,l.UniverInstanceType.UNIVER_SHEET)}}function Cn(s){return{id:mt.id,title:"sheetImage.upload.cell",type:W.MenuItemType.BUTTON,hidden$:W.getMenuHiddenObservable(s,l.UniverInstanceType.UNIVER_SHEET)}}const Tn={[W.RibbonInsertGroup.MEDIA]:{[St]:{order:0,menuItemFactory:Dn,[Pe.id]:{order:0,menuItemFactory:yn},[mt.id]:{order:1,menuItemFactory:Cn}}}};function Ne(s){return!s.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!s.getContextValue(l.EDITOR_ACTIVATED)&&!s.getContextValue(l.FOCUSING_PANEL_EDITOR)&&s.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const Mn={id:ye.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:W.KeyCode.ARROW_DOWN,priority:100,preconditions:Ne,staticParameters:{direction:l.Direction.DOWN}},Rn={id:ye.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:W.KeyCode.ARROW_UP,priority:100,preconditions:Ne,staticParameters:{direction:l.Direction.UP}},bn={id:ye.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:W.KeyCode.ARROW_LEFT,priority:100,preconditions:Ne,staticParameters:{direction:l.Direction.LEFT}},En={id:ye.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:W.KeyCode.ARROW_RIGHT,priority:100,preconditions:Ne,staticParameters:{direction:l.Direction.RIGHT}},On={id:ut.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:Ne,binding:W.KeyCode.DELETE,mac:W.KeyCode.BACKSPACE};var Un=Object.getOwnPropertyDescriptor,An=(s,r,t,e)=>{for(var n=e>1?void 0:e?Un(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},ve=(s,r)=>(t,e)=>r(t,e,s);let rt=class extends l.Disposable{constructor(s,r,t,e,n,i){super(),this._componentManager=s,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=i,this._init()}_initCustomComponents(){const s=this._componentManager;this.disposeWithMe(s.register(bt,In))}_initMenus(){this._menuManagerService.mergeMenu(Tn)}_initCommands(){[Pe,mt,Ue,De,Ae,wt,G,ft,gt,pt,ye,ut,ht].forEach(s=>this.disposeWithMe(this._commandService.registerCommand(s)))}_initShortcuts(){[Mn,Rn,bn,En,On].forEach(s=>{this.disposeWithMe(this._shortcutService.registerShortcut(s))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};rt=An([ve(0,l.Inject(W.ComponentManager)),ve(1,W.IMenuManagerService),ve(2,l.ICommandService),ve(3,W.IShortcutService),ve(4,j.IDrawingManagerService),ve(5,l.Inject(y.SheetsSelectionsService))],rt);var Pn=Object.defineProperty,Nn=Object.getOwnPropertyDescriptor,jn=(s,r,t)=>r in s?Pn(s,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[r]=t,kn=(s,r,t,e)=>{for(var n=e>1?void 0:e?Nn(r,t):r,i=s.length-1,o;i>=0;i--)(o=s[i])&&(n=o(n)||n);return n},ot=(s,r)=>(t,e)=>r(t,e,s),At=(s,r,t)=>jn(s,typeof r!="symbol"?r+"":r,t);const Wn="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Ct,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:i,...o}=l.merge({},Ct,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Lt,o)}onStarting(){l.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[rt],[qe],[nt],[tt],[et],[Ze],[Je],[Qe]]),l.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[et],[Qe]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[tt],[nt],[rt],[Ze],[Je]])}onSteady(){this._injector.get(qe)}_registerRenderModules(){[[exports.SheetDrawingUpdateController],[lt],[dt],[ct]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}};At(exports.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);At(exports.UniverSheetsDrawingUIPlugin,"pluginName",Wn);exports.UniverSheetsDrawingUIPlugin=kn([l.DependentOn(j.UniverDrawingPlugin,Rt.UniverDocsDrawingPlugin,le.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),ot(1,l.Inject(l.Injector)),ot(2,k.IRenderManagerService),ot(3,l.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=G;exports.DeleteDrawingsCommand=ut;exports.EditSheetDrawingOperation=ft;exports.GroupSheetDrawingCommand=gt;exports.InsertFloatImageCommand=Pe;exports.InsertSheetDrawingCommand=Ue;exports.MoveDrawingsCommand=ye;exports.RemoveSheetDrawingCommand=De;exports.SHEETS_IMAGE_MENU_ID=St;exports.SetDrawingArrangeCommand=ht;exports.SetSheetDrawingCommand=Ae;exports.SidebarSheetDrawingOperation=wt;exports.UngroupSheetDrawingCommand=pt;exports.calcSheetFloatDomPosition=ie;exports.drawingPositionToTransform=K;exports.transformToDrawingPosition=x;
|
package/lib/es/index.js
CHANGED
|
@@ -2575,7 +2575,8 @@ let rn = class extends ne {
|
|
|
2575
2575
|
}
|
|
2576
2576
|
_sheetInterceptorListener() {
|
|
2577
2577
|
this.disposeWithMe(
|
|
2578
|
-
this._sheetInterceptorService.
|
|
2578
|
+
this._sheetInterceptorService.interceptAfterCommand({
|
|
2579
|
+
/* eslint-disable-next-line complexity */
|
|
2579
2580
|
getMutations: (i) => {
|
|
2580
2581
|
if (!As.includes(i.id))
|
|
2581
2582
|
return { redos: [], undos: [] };
|
package/lib/index.js
CHANGED
|
@@ -2575,7 +2575,8 @@ let rn = class extends ne {
|
|
|
2575
2575
|
}
|
|
2576
2576
|
_sheetInterceptorListener() {
|
|
2577
2577
|
this.disposeWithMe(
|
|
2578
|
-
this._sheetInterceptorService.
|
|
2578
|
+
this._sheetInterceptorService.interceptAfterCommand({
|
|
2579
|
+
/* eslint-disable-next-line complexity */
|
|
2579
2580
|
getMutations: (i) => {
|
|
2580
2581
|
if (!As.includes(i.id))
|
|
2581
2582
|
return { redos: [], undos: [] };
|
package/lib/umd/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
(function(b,A){typeof exports=="object"&&typeof module<"u"?A(exports,require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("@univerjs/core"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets"),require("@univerjs/design"),require("@univerjs/docs-ui"),require("@univerjs/drawing"),require("@univerjs/ui"),require("@univerjs/docs-drawing"),require("@univerjs/drawing-ui"),require("rxjs"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","@univerjs/engine-render","@univerjs/sheets-ui","@univerjs/core","@univerjs/sheets-drawing","@univerjs/sheets","@univerjs/design","@univerjs/docs-ui","@univerjs/drawing","@univerjs/ui","@univerjs/docs-drawing","@univerjs/drawing-ui","rxjs","react/jsx-runtime","react"],A):(b=typeof globalThis<"u"?globalThis:b||self,A(b.UniverSheetsDrawingUi={},b.UniverEngineRender,b.UniverSheetsUi,b.UniverCore,b.UniverSheetsDrawing,b.UniverSheets,b.UniverDesign,b.UniverDocsUi,b.UniverDrawing,b.UniverUi,b.UniverDocsDrawing,b.UniverDrawingUi,b.rxjs,b.React,b.React))})(this,(function(b,A,R,l,m,D,q,We,j,B,vt,le,N,J,pe){"use strict";var jn=Object.defineProperty;var Bn=(b,A,R)=>A in b?jn(b,A,{enumerable:!0,configurable:!0,writable:!0,value:R}):b[A]=R;var re=(b,A,R)=>Bn(b,typeof A!="symbol"?A+"":A,R);function x(o,r,t){const{from:e,to:n,flipY:i=!1,flipX:s=!1,angle:a=0,skewX:d=0,skewY:g=0}=o,u=t.getCurrent();if(u==null)return;const c=R.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:n},t);let{left:p,top:h,width:S,height:f}=c;const w=t.getCurrentSkeleton(),_=w.rowHeaderWidth+w.columnTotalWidth,I=w.columnHeaderHeight+w.rowTotalHeight;return p+S>_&&(p=_-S),h+f>I&&(h=I-f),{flipY:i,flipX:s,angle:a,skewX:d,skewY:g,left:p,top:h,width:S,height:f}}function G(o,r){const{left:t=0,top:e=0,width:n=0,height:i=0,flipY:s=!1,flipX:a=!1,angle:d=0,skewX:g=0,skewY:u=0}=o,c=r.getCellWithCoordByOffset(t,e);if(c==null)return;const p={column:c.actualColumn,columnOffset:A.precisionTo(t-c.startX,1),row:c.actualRow,rowOffset:A.precisionTo(e-c.startY,1)},h=r.getCellWithCoordByOffset(t+n,e+i);if(h==null)return;const S={column:h.actualColumn,columnOffset:A.precisionTo(t+n-h.startX,1),row:h.actualRow,rowOffset:A.precisionTo(e+i-h.startY,1)};return{flipY:s,flipX:a,angle:d,skewX:g,skewY:u,from:p,to:S}}const H={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(o,r)=>{const t=o.get(A.IRenderManagerService);return r.forEach(e=>{var n,i;(i=(n=t.getRenderById(e))==null?void 0:n.scene.getTransformer())==null||i.debounceRefreshControls()}),!0}},me={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(o,r)=>{var I,C,E;const t=o.get(l.ICommandService),e=o.get(l.IUndoRedoService),n=o.get(D.SheetInterceptorService),i=o.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,a=[];s.forEach(y=>{const{unitId:M}=y;a.push(M)});const d=i.getBatchRemoveOp(s),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,S=n.onCommandExecute({id:me.id,params:r}),f={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:p,objects:h,type:m.DrawingApplyType.REMOVE}},w={id:m.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:c,objects:h,type:m.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=S.preRedos)!=null?I:[],f,...S.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=S.preUndos)!=null?C:[],w,...S.undos,{id:H.id,params:a}],redoMutations:[...(E=S.preRedos)!=null?E:[],f,...S.redos,{id:H.id,params:a}]}),!0):!1}},ot={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:o=>{const r=o.get(l.ICommandService),e=o.get(m.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const n=e[0].unitId,i=e.map(s=>{const{unitId:a,subUnitId:d,drawingId:g,drawingType:u}=s;return{unitId:a,subUnitId:d,drawingId:g,drawingType:u}});return r.executeCommand(me.id,{unitId:n,drawings:i})}};function Nt(o){const r=[];return o.forEach(t=>{const{parent:e,children:n}=t,{unitId:i,subUnitId:s,drawingId:a}=e,d=A.getGroupState(0,0,n.map(c=>c.transform||{})),g=n.map(c=>{const p=c.transform||{left:0,top:0},{unitId:h,subUnitId:S,drawingId:f}=c;return{unitId:h,subUnitId:S,drawingId:f,transform:{...p,left:p.left-d.left,top:p.top-d.top},groupId:a}}),u={unitId:i,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};r.push({parent:u,children:g})}),r}function kt(o){const r=[];return o.forEach(t=>{const{parent:e,children:n}=t,{unitId:i,subUnitId:s,drawingId:a,transform:d={width:0,height:0}}=e;if(d==null)return;const g=n.map(c=>{const{transform:p}=c,{unitId:h,subUnitId:S,drawingId:f}=c,w=A.transformObjectOutOfGroup(p||{},d,d.width||0,d.height||0);return{unitId:h,subUnitId:S,drawingId:f,transform:w,groupId:void 0}}),u={unitId:i,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const st={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(l.ICommandService),e=o.get(l.IUndoRedoService),n=o.get(m.ISheetDrawingService);if(!r)return!1;const i=[];r.forEach(({parent:h,children:S})=>{i.push(h.unitId),S.forEach(f=>{i.push(f.unitId)})});const s=n.getGroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=s;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:kt(c),type:m.DrawingApplyType.UNGROUP}},{id:H.id,params:i}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.GROUP}},{id:H.id,params:i}]}),!0):!1}},Te={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(o,r)=>{var I,C,E;const t=o.get(l.ICommandService),e=o.get(l.IUndoRedoService),n=o.get(m.ISheetDrawingService),i=o.get(D.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(y=>y.unitId),d=n.getBatchAddOp(s),{unitId:g,subUnitId:u,undo:c,redo:p,objects:h}=d,S=i.onCommandExecute({id:Te.id,params:r}),f={id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.INSERT}},w={id:m.SetDrawingApplyMutation.id,params:{op:c,unitId:g,subUnitId:u,objects:h,type:m.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=S.preRedos)!=null?I:[],f,...S.redos],t)?(e.pushUndoRedo({unitID:g,undoMutations:[...(C=S.preUndos)!=null?C:[],w,...S.undos,{id:H.id,params:a}],redoMutations:[...(E=S.preRedos)!=null?E:[],f,...S.redos,{id:H.id,params:a}]}),!0):!1}},at={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(l.ICommandService),e=o.get(l.IUndoRedoService);if(!r)return!1;const n=o.get(m.ISheetDrawingService),{unitId:i,subUnitId:s,drawingIds:a,arrangeType:d}=r,g={unitId:i,subUnitId:s,drawingIds:a};let u;if(d===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):d===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):d===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):d===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:c,redo:p,undo:h}=u;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:p,unitId:i,subUnitId:s,objects:c,type:m.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:i,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:h,unitId:i,subUnitId:s,objects:c,type:m.DrawingApplyType.ARRANGE}}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:p,unitId:i,subUnitId:s,objects:c,type:m.DrawingApplyType.ARRANGE}}]}),!0):!1}},Me={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(l.ICommandService),e=o.get(l.IUndoRedoService),n=o.get(m.ISheetDrawingService);if(!r)return!1;const{drawings:i}=r,s=n.getBatchUpdateOp(i),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=s;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:a,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:g,objects:c,type:m.DrawingApplyType.UPDATE}},{id:H.id,params:[a]}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:d,op:u,objects:c,type:m.DrawingApplyType.UPDATE}},{id:H.id,params:[a]}]}),!0):!1}},ct={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(l.ICommandService),e=o.get(l.IUndoRedoService),n=o.get(m.ISheetDrawingService);if(!r)return!1;const i=[];r.forEach(({parent:h,children:S})=>{i.push(h.unitId),S.forEach(f=>{i.push(f.unitId)})});const s=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:d,undo:g,redo:u,objects:c}=s;return t.syncExecuteCommand(m.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:a,undoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:d,objects:Nt(c),type:m.DrawingApplyType.GROUP}},{id:H.id,params:i}],redoMutations:[{id:m.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:d,objects:c,type:m.DrawingApplyType.UNGROUP}},{id:H.id,params:i}]}),!0):!1}};var Wt=Object.getOwnPropertyDescriptor,jt=(o,r,t,e)=>{for(var n=e>1?void 0:e?Wt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Q=(o,r)=>(t,e)=>r(t,e,o);function Bt(o,r,t){const e=t*Math.PI/180,n=Math.abs(o*Math.cos(e))+Math.abs(r*Math.sin(e)),i=Math.abs(o*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:n,rotatedHeight:i}}function dt(o,r,t,e,n){var I;const{rotatedHeight:i,rotatedWidth:s}=Bt(t,e,n),d=o.get(A.IRenderManagerService).getRenderById(r.unitId);if(!d)return!1;const u=(I=d.with(R.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),p=c.mergeInfo.endX-c.mergeInfo.startX-2,h=c.mergeInfo.endY-c.mergeInfo.startY-2,S=s/i,w=Math.ceil(Math.min(p,h*S))/s,_=!w||Number.isNaN(w)?.001:w;return{width:t*_,height:e*_}}b.SheetDrawingUpdateController=class extends l.Disposable{constructor(t,e,n,i,s,a,d,g,u,c,p,h,S){super();re(this,"_workbookSelections");this._context=t,this._skeletonManagerService=e,this._commandService=n,this._selectionRenderService=i,this._imageIoService=s,this._fileOpenerService=a,this._sheetDrawingService=d,this._drawingManagerService=g,this._contextService=u,this._messageService=c,this._localeService=p,this._injector=S,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:j.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),e=t.length;return e>j.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(j.DRAWING_IMAGE_COUNT_LIMIT))}),!1):e===0?!1:(t.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const e=(await this._fileOpenerService.openFile({multiple:!1,accept:j.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return e?(await this._insertCellImage(e),!0):!1}insertCellImageByFile(t,e){return this._insertCellImage(t,e)}async insertFloatImageByFile(t){let e;try{e=await this._imageIoService.saveImage(t)}catch(C){const E=C.message;E===j.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(j.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):E===j.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):E===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(e==null)return;const n=this._getUnitInfo(),{unitId:i,subUnitId:s}=n,{imageId:a,imageSourceType:d,source:g,base64Cache:u}=e,{width:c,height:p,image:h}=await j.getImageSize(u||""),{width:S,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(g,d,h);let w=1;if(c>j.DRAWING_IMAGE_WIDTH_LIMIT||p>j.DRAWING_IMAGE_HEIGHT_LIMIT){const C=j.DRAWING_IMAGE_WIDTH_LIMIT/c,E=j.DRAWING_IMAGE_HEIGHT_LIMIT/p;w=Math.max(C,E)}const _=this._getImagePosition(c*w,p*w,S,f);if(_==null)return;const I={unitId:i,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:d,source:g,transform:x(_,this._selectionRenderService,this._skeletonManagerService),sheetTransform:_};return this._commandService.executeCommand(Te.id,{unitId:i,drawings:[I]})}async _insertCellImage(t,e){var E,y;let n;try{n=await this._imageIoService.saveImage(t)}catch(M){const v=M.message;v===j.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(j.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):v===j.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):v===j.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:q.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:i,imageSourceType:s,source:a,base64Cache:d}=n,{width:g,height:u,image:c}=await j.getImageSize(d||"");this._imageIoService.addImageSourceCache(a,s,c);const p=this._workbookSelections.getCurrentLastSelection();if(!p)return!1;let h=p.primary.actualRow,S=p.primary.actualColumn;p.primary.isMerged&&(h=p.primary.startRow,S=p.primary.startColumn);const f=l.createDocumentModelWithStyle("",{}),w=dt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:h,col:S},g,u,0);if(!w)return!1;const _={size:{width:w.width,height:w.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},I={unitId:f.getUnitId(),subUnitId:f.getUnitId(),drawingId:i,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:We.docDrawingPositionToTransform(_),docTransform:_,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},C=l.BuildTextUtils.drawing.add({documentDataModel:f,drawings:[I],selection:{collapsed:!0,startOffset:0,endOffset:0}});return C?(f.apply(C),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(E=e==null?void 0:e.row)!=null?E:h]:{[(y=e==null?void 0:e.col)!=null?y:S]:{p:f.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}async insertCellImageByUrl(t,e){var h,S;const{width:n,height:i,image:s}=await j.getImageSize(t||"");this._imageIoService.addImageSourceCache(t,l.ImageSourceType.URL,s);const a=this._workbookSelections.getCurrentLastSelection();if(!a)return!1;const d=l.createDocumentModelWithStyle("",{}),g=dt(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:a.primary.actualRow,col:a.primary.actualColumn},n,i,0);if(!g)return!1;const u={size:{width:g.width,height:g.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},c={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:t,transform:We.docDrawingPositionToTransform(u),docTransform:u,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},p=l.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[c],selection:{collapsed:!0,startOffset:0,endOffset:0}});return p?(d.apply(p),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(h=e==null?void 0:e.row)!=null?h:a.primary.actualRow]:{[(S=e==null?void 0:e.col)!=null?S:a.primary.actualColumn]:{p:d.getSnapshot(),t:1}}},unitId:e==null?void 0:e.unitId,subUnitId:e==null?void 0:e.subUnitId})):!1}_getUnitInfo(){const t=this._context.unit,e=t.getActiveSheet(),n=t.getUnitId(),i=e.getSheetId();return{unitId:n,subUnitId:i}}_getImagePosition(t,e,n,i){const s=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};s&&s.length>0&&(a=s[s.length-1].range);const d=R.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(d==null)return;let{startColumn:g,startRow:u,startX:c,startY:p}=d,h=!1;if(c+t>n&&(c=n-t,c<0&&(c=0,t=n),h=!0),p+e>i&&(p=i-e,p<0&&(p=0,e=i),h=!0),h){const _=this._selectionRenderService.getCellWithCoordByOffset(c,p);if(_==null)return;c=_.startX,p=_.startY,g=_.actualColumn,u=_.actualRow}const S={column:g,columnOffset:0,row:u,rowOffset:0},f=this._selectionRenderService.getCellWithCoordByOffset(c+t,p+e);if(f==null)return;const w={column:f.actualColumn,columnOffset:c+t-f.startX,row:f.actualRow,rowOffset:p+e-f.startY};return{from:S,to:w}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:e,subUnitId:n,drawingIds:i,arrangeType:s}=t;this._commandService.executeCommand(at.id,{unitId:e,subUnitId:n,drawingIds:i,arrangeType:s})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const e=[];t.length!==0&&(t.forEach(n=>{const{unitId:i,subUnitId:s,drawingId:a,drawingType:d,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:i,subUnitId:s,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const c=G({...u.transform,...g},this._selectionRenderService);if(c==null)return;const p={...n,transform:{...u.transform,...g,...x(c,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...c}};e.push(p)}),e.length>0&&this._commandService.executeCommand(Me.id,{unitId:t[0].unitId,drawings:e}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(st.id,t);const{unitId:e,subUnitId:n,drawingId:i}=t[0].parent;this._commandService.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:n,drawingId:i}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(ct.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}},b.SheetDrawingUpdateController=jt([Q(1,l.Inject(R.SheetSkeletonManagerService)),Q(2,l.ICommandService),Q(3,R.ISheetSelectionRenderService),Q(4,j.IImageIoService),Q(5,B.ILocalFileService),Q(6,m.ISheetDrawingService),Q(7,j.IDrawingManagerService),Q(8,l.IContextService),Q(9,B.IMessageService),Q(10,l.Inject(l.LocaleService)),Q(11,l.Inject(D.SheetsSelectionsService)),Q(12,l.Inject(l.Injector))],b.SheetDrawingUpdateController);const Re={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(o,r)=>{var s,a;const t=o.get(l.IUniverInstanceService),e=o.get(A.IRenderManagerService),n=(s=A.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,t,e))==null?void 0:s.with(b.SheetDrawingUpdateController);if(!n)return!1;const i=r==null?void 0:r.files;if(i){const d=i.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(d)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},lt={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:o=>{var e,n;const r=o.get(l.IUniverInstanceService),t=o.get(A.IRenderManagerService);return(n=(e=A.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,r,t))==null?void 0:e.with(b.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}},fe={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(o,r)=>{const t=o.get(l.ICommandService),e=o.get(m.ISheetDrawingService),n=o.get(R.ISheetSelectionRenderService),{direction:i}=r,s=e.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,d=s.map(u=>{const{transform:c}=u;if(c==null)return null;const p={...c},{left:h=0,top:S=0}=c;return i===l.Direction.UP?p.top=S-1:i===l.Direction.DOWN?p.top=S+1:i===l.Direction.LEFT?p.left=h-1:i===l.Direction.RIGHT&&(p.left=h+1),{...u,transform:p,sheetTransform:G(p,n)}}).filter(u=>u!=null);return t.syncExecuteCommand(Me.id,{unitId:a,drawings:d})?(t.syncExecuteCommand(H.id,[a]),!0):!1}},It="COMPONENT_SHEET_DRAWING_PANEL",ut={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(o,r)=>{const t=o.get(B.ISidebarService),e=o.get(l.LocaleService),n=o.get(l.IUniverInstanceService),i=o.get(l.ICommandService);if(!D.getSheetCommandTarget(n))return!1;switch(r.value){case"open":t.open({header:{title:e.t("sheetImage.panel.title")},children:{label:It},onClose:()=>{i.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:t.close();break}return!0}},gt={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(o,r)=>{const t=o.get(l.ICommandService);return r==null?!1:(t.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[r]),t.executeCommand(ut.id,{value:"open"}),!0)}},Yt="sheets-drawing-ui.config",yt={};var Ft=Object.getOwnPropertyDescriptor,$t=(o,r,t,e)=>{for(var n=e>1?void 0:e?Ft(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},ie=(o,r)=>(t,e)=>r(t,e,o);let je=class extends l.RxDisposable{constructor(r,t,e,n,i,s,a,d,g,u){super();re(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=t,this._drawingManagerService=e,this._canvasPopManagerService=n,this._renderManagerService=i,this._univerInstanceService=s,this._messageService=a,this._contextService=d,this._ioService=g,this._commandService=u,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._setupLoadingStatus()}_setupLoadingStatus(){const r="image-upload-loading";let t;this.disposeWithMe(this._ioService.change$.subscribe(e=>{e>0&&!t?t=this._messageService.show({id:r,type:q.MessageType.Loading,content:`${this._localeService.t("uploadLoading.loading")}: ${e}`,duration:0}):e===0&&(t==null||t.dispose(),t=void 0)}))}_dispose(r){super.dispose();const t=r.getUnitId();this._renderManagerService.removeRender(t)}_create(r){if(!r)return;const t=r.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(r){const t=r.getAllObjectsByOrder();for(const e of t)if(e instanceof le.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var i;const t=(i=this._renderManagerService.getRenderById(r))==null?void 0:i.scene;if(!t)return;const e=t.getTransformerByCreate();if(!e)return;let n;this.disposeWithMe(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(t))return;const s=e.getSelectedObjectMap();if(s.size>1){n==null||n.dispose();return}const a=s.values().next().value;if(!a)return;const d=a.oKey,g=this._drawingManagerService.getDrawingOKey(d);if(!g)return;const{unitId:u,subUnitId:c,drawingId:p,drawingType:h}=g,S=g.data;if(S&&S.disablePopup)return;n==null||n.dispose();const f=this._canvasPopManagerService.getFeatureMenu(u,c,p,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:le.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:f||this._getImageMenuItems(u,c,p,h)}}))})),this.disposeWithMe(e.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(j.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(s=>{s[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,t,e,n){return[{label:"image-popup.edit",index:0,commandId:gt.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:me.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:t,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:le.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:t,drawingId:e},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:le.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:t,drawingId:e}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};je=$t([ie(0,l.Inject(l.Injector)),ie(1,l.Inject(l.LocaleService)),ie(2,j.IDrawingManagerService),ie(3,l.Inject(R.SheetCanvasPopManagerService)),ie(4,A.IRenderManagerService),ie(5,l.IUniverInstanceService),ie(6,B.IMessageService),ie(7,l.IContextService),ie(8,l.IImageIoService),ie(9,l.ICommandService)],je);var Lt=Object.getOwnPropertyDescriptor,Gt=(o,r,t,e)=>{for(var n=e>1?void 0:e?Lt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Be=(o,r)=>(t,e)=>r(t,e,o);let ht=class extends l.Disposable{constructor(r,t,e,n,i){super();re(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=t,this._selectionsService=e,this._drawingRenderService=n,this._sheetSkeletonManagerService=i,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(N.throttleTime(33)).subscribe(r=>{var e,n;let t=[];r!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),t.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&t.length===1&&((e=t[0].primary)==null?void 0:e.actualRow)===r.row&&((n=t[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(A.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var t;if(r!=null&&r.drawing&&this._isSetCursor){const e=r.drawing.drawing.drawingOrigin,n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap.getImage(e.imageSourceType,e.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};ht=Gt([Be(1,l.Inject(R.HoverManagerService)),Be(2,l.Inject(D.SheetsSelectionsService)),Be(3,l.Inject(le.DrawingRenderService)),Be(4,l.Inject(R.SheetSkeletonManagerService))],ht);var Ht=Object.getOwnPropertyDescriptor,Xt=(o,r,t,e)=>{for(var n=e>1?void 0:e?Ht(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ye=(o,r)=>(t,e)=>r(t,e,o);let pt=class extends l.Disposable{constructor(o,r,t,e,n){super(),this._context=o,this._sheetDrawingService=r,this._drawingManagerService=t,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const o=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in o){const t=o[r];for(const e in t.data){const n=t.data[e];n.sheetTransform&&(n.transform=x(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService))}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};pt=Xt([Ye(1,m.ISheetDrawingService),Ye(2,j.IDrawingManagerService),Ye(3,l.Inject(R.ISheetSelectionRenderService)),Ye(4,l.Inject(R.SheetSkeletonManagerService))],pt);var Vt=Object.getOwnPropertyDescriptor,Kt=(o,r,t,e)=>{for(var n=e>1?void 0:e?Vt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Se=(o,r)=>(t,e)=>r(t,e,o);function Dt(o,r,t){var e,n,i,s;if(((n=(e=t==null?void 0:t.p)==null?void 0:e.body)==null?void 0:n.dataStream.length)===3&&((s=(i=t.p)==null?void 0:i.drawingsOrder)==null?void 0:s.length)===1){const a=t.p.drawings[t.p.drawingsOrder[0]],d=dt(o,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(d)return a.transform.width=d.width,a.transform.height=d.height,a.docTransform.size.width=d.width,a.docTransform.size.height=d.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,t.p.documentStyle.pageSize.width=1/0,t.p.documentStyle.pageSize.height=1/0,!0}return!1}let Fe=class extends l.Disposable{constructor(o,r,t,e,n,i){super(),this._commandService=o,this._sheetInterceptorService=r,this._injector=t,this._drawingManagerService=e,this._docDrawingController=n,this._editorBridgeService=i,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(o=>{o.visible?o.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(o=>{o.id===We.ReplaceSnapshotCommand.id&&o.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(D.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:D.InterceptCellContentPriority.CELL_IMAGE,handler:(o,r,t)=>{var e;return o!=null&&o.p&&((e=o.p.drawingsOrder)!=null&&e.length)&&(o===r.rawData&&(o={...r.rawData}),o.interceptorStyle||(o.interceptorStyle={}),o.interceptorStyle.tr={a:0},Dt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},o)),t(o)}}))}};Fe=Kt([Se(0,l.ICommandService),Se(1,l.Inject(D.SheetInterceptorService)),Se(2,l.Inject(l.Injector)),Se(3,j.IDrawingManagerService),Se(4,l.Inject(vt.DocDrawingController)),Se(5,l.Inject(R.IEditorBridgeService))],Fe);var zt=Object.getOwnPropertyDescriptor,xt=(o,r,t,e)=>{for(var n=e>1?void 0:e?zt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ct=(o,r)=>(t,e)=>r(t,e,o);let $e=class extends l.Disposable{constructor(o,r){super(),this._autoFillService=o,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(o,r,t,e)=>{new l.ObjectMatrix(e).forValue((n,i,s)=>{Dt(this._injector,{unitId:o.unitId,subUnitId:o.subUnitId,row:n,col:i},s)})}}))}};$e=xt([Ct(0,l.Inject(R.IAutoFillService)),Ct(1,l.Inject(l.Injector))],$e);var qt=Object.getOwnPropertyDescriptor,Zt=(o,r,t,e)=>{for(var n=e>1?void 0:e?qt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Ee=(o,r)=>(t,e)=>r(t,e,o);const Jt=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let Le=class extends l.Disposable{constructor(o,r,t,e,n){super(),this._commandService=o,this._univerInstanceService=r,this._dialogService=t,this._renderManagerService=e,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(o){var n;const r=l.createDocumentModelWithStyle("",{}),t=(n=A.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(R.EditingRenderController),e=l.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[o],selection:{collapsed:!0,startOffset:0,endOffset:0}});e&&(r.apply(e),t&&t.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(o=>{var r,t;if(o.id===We.InnerPasteCommand.id){const e=o.params,{doc:n}=e,i=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_DOC);if(i==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const s=i.getUnitId();if(Jt.includes(s)){if(s!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(R.SetCellEditVisibleOperation.id,{visible:!1})};((t=i.getBody())==null?void 0:t.dataStream)===`\r
|
|
2
|
-
`?(this._commandService.syncExecuteCommand(R.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(n.drawings)[0])):this._dialogService.open({id:"sheet-cell-image-copy-paste",title:{label:this._localeService.t("cell-image.pasteTitle")},children:{label:this._localeService.t("cell-image.pasteContent")},width:320,destroyOnClose:!0,onClose:a,showOk:!0,showCancel:!0,onOk:()=>{a(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:a})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};Le=Zt([Ee(0,l.ICommandService),Ee(1,l.IUniverInstanceService),Ee(2,B.IDialogService),Ee(3,A.IRenderManagerService),Ee(4,l.Inject(l.LocaleService))],Le);var Qt=Object.getOwnPropertyDescriptor,en=(o,r,t,e)=>{for(var n=e>1?void 0:e?Qt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},be=(o,r)=>(t,e)=>r(t,e,o);const Tt="image/png";function tn(o){const r=o.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let i=0;i<e;i++)n[i]=t.charCodeAt(i);return new Blob([n],{type:Tt})}function nn(o){const r=new ClipboardItem({[Tt]:tn(o)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function rn(){function o(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const r=document.activeElement,t=o();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const Mt=[R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let Ge=class extends l.Disposable{constructor(r,t,e,n,i){super();re(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=i,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const i=this._focusedDrawings;if(i.length>0){const[s]=i;if(n===R.COPY_TYPE.CUT){const d={unitId:r,drawings:[s]};this._commandService.executeCommand(me.id,d)}setTimeout(()=>{const d=rn();s.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===j.ImageSourceType.BASE64?nn(s.source):this._clipboardInterfaceService.writeText(""),d()},200);const a={unitId:s.unitId,subUnitId:s.subUnitId,drawings:[s]};this._copyInfo=a}else{const s=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=s}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:i=R.COPY_TYPE.COPY,pasteType:s}=n,{range:a}=r||{},{range:d,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:s,unitId:g,subUnitId:u,pasteRange:d},{copyRange:a,copyType:i}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:s},R.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:R.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},R.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:R.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},R.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Re.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var p;const n=(p=this._renderManagerService.getRenderById(r))==null?void 0:p.with(R.SheetSkeletonManagerService);if(!n)return;const i=n.attachRangeWithCoord(e);if(!i)return;const{startX:s,endX:a,startY:d,endY:g}=i,u=this._drawingService.getDrawingData(r,t),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const S=u[h],{transform:f}=S;if(S.anchorType!==m.SheetDrawingAnchorType.Both||!f)return;const{left:w=0,top:_=0,width:I=0,height:C=0}=f,{drawingStartX:E,drawingEndX:y,drawingStartY:M,drawingEndY:v}={drawingStartX:w,drawingEndX:w+I,drawingStartY:_,drawingEndY:_+C};s<=E&&y<=a&&d<=M&&v<=g&&c.push(S)}),c.length)return{copyRange:e,drawings:c,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Mt.includes(e))return{redos:[],undos:[]};const{unitId:i,subUnitId:s,range:a}=n,d=this._renderManagerService.getRenderById(i),g=d==null?void 0:d.with(R.SheetSkeletonManagerService),u=d==null?void 0:d.with(R.ISheetSelectionRenderService),c=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=c,h=R.discreteRangeToRange(a);return this._generateMutations(p,{unitId:i,subUnitId:s,isCut:t===R.COPY_TYPE.CUT,getTransform:(S,f)=>{var I;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...S,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:_,sheetTransform:(I=G(_,u))!=null?I:f}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:i,isCut:s}=t,a=[],d=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:c,sheetTransform:p}=u;if(!c)return;const h=i(c,p),S={...u,unitId:e,subUnitId:n,drawingId:s?u.drawingId:l.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(s){const{undo:f,redo:w,objects:_}=g.getBatchUpdateOp([S]);a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:_}}),d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:f,objects:_}})}else{const{undo:f,redo:w,objects:_}=g.getBatchAddOp([S]);a.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.INSERT}}),d.push({id:m.SetDrawingApplyMutation.id,params:{op:f,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.REMOVE}})}}),{redos:a,undos:d}}_generateRangeDrawingsPasteMutations(r,t){var U;const{unitId:e,subUnitId:n,pasteType:i,pasteRange:s}=r,{copyRange:a,copyType:d}=t;if(Mt.includes(i))return{redos:[],undos:[]};const g=(U=this._renderManagerService.getRenderById(e))==null?void 0:U.with(R.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:R.discreteRangeToRange(s)},pasteType:i},d);const{ranges:[c,p],mapFunc:h}=R.virtualizeDiscreteRanges([a,s]),{row:S,col:f}=h(c.startRow,c.startColumn),{row:w,col:_}=h(p.startRow,p.startColumn),I=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:f,endColumn:f}),C=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:_,endColumn:_});if(!I||!C||!this._copyInfo)return{redos:[],undos:[]};const E=C.startX-I.startX,y=C.startY-I.startY,M=w-S,v=_-f;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(O,k)=>{var W,P;return{transform:{...O,left:((W=O==null?void 0:O.left)!=null?W:0)+E,top:((P=O==null?void 0:O.top)!=null?P:0)+y},sheetTransform:{...k,to:{...k.to,row:k.to.row+M,column:k.to.column+v},from:{...k.from,row:k.from.row+M,column:k.from.column+v}}}},isCut:d===R.COPY_TYPE.CUT})}};Ge=en([be(0,R.ISheetClipboardService),be(1,A.IRenderManagerService),be(2,j.IDrawingManagerService),be(3,B.IClipboardInterfaceService),be(4,l.ICommandService)],Ge);var on=Object.getOwnPropertyDescriptor,sn=(o,r,t,e)=>{for(var n=e>1?void 0:e?on(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Oe=(o,r)=>(t,e)=>r(t,e,o);let He=class extends l.Disposable{constructor(o,r,t,e,n){super(),this._drawingManagerService=o,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([o,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(i=>{if(!i){this._drawingManagerService.setDrawingVisible(!1);return}const s=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new D.WorkbookViewPermission(s).id,new D.WorksheetViewPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,i)})):(this._drawingManagerService.setDrawingVisible(!1),N.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(o,r){this._drawingManagerService.setDrawingVisible(!1);const t=o.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===A.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([o,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(i=>{if(!i){this._drawingManagerService.setDrawingEditable(!1);return}const s=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new D.WorkbookEditablePermission(s).id,new D.WorksheetEditPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,i)})):(this._drawingManagerService.setDrawingEditable(!1),N.EMPTY))).subscribe())}_handleDrawingEditableFalse(o,r){this._drawingManagerService.setDrawingEditable(!1);const t=o.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===A.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([o,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const i=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(i),d=a==null?void 0:a.scene;if(!d)return N.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookViewPermission(i).id,new D.WorksheetViewPermission(i,s).id]).pipe(N.map(c=>c.every(p=>p.value)),N.distinctUntilChanged()).pipe(N.map(c=>({permission:c,scene:d,transformer:g,unitId:i,subUnitId:s})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:s})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(i,s),g=Object.values(d);t?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),i=e==null?void 0:e.getSheetId();if(!n||!i)return;const s=this._drawingManagerService.getDrawingData(n,i),a=Object.values(s);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([o,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const i=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(i),d=a==null?void 0:a.scene;if(!d)return N.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookEditablePermission(i).id,new D.WorksheetEditPermission(i,s).id]).pipe(N.map(c=>c.every(p=>p.value)),N.distinctUntilChanged()).pipe(N.map(c=>({permission:c,scene:d,transformer:g,unitId:i,subUnitId:s})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:s})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(i,s),g=Object.values(d);t?(a.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const i=n.getSheetId(),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;const d=this._drawingManagerService.getDrawingData(e,i),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(c=>{c.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>c.oKey.includes(p.drawingId))&&a.detachTransformerFrom(c)})}}))}};He=sn([Oe(0,j.IDrawingManagerService),Oe(1,A.IRenderManagerService),Oe(2,l.IPermissionService),Oe(3,l.IUniverInstanceService),Oe(4,l.Inject(l.UserManagerService))],He);var an=Object.getOwnPropertyDescriptor,cn=(o,r,t,e)=>{for(var n=e>1?void 0:e?an(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},ge=(o,r)=>(t,e)=>r(t,e,o);function Rt(o,r,t,e,n,i=!1){const{scaleX:s,scaleY:a}=r.getAncestorScale(),d=r.getViewport(A.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:c,xSplit:p,ySplit:h}=g,S={left:!0,top:!0};if(!d)return{...o,absolute:S};const{left:f,right:w,top:_,bottom:I}=o;let{top:C,left:E,viewportScrollX:y,viewportScrollY:M}=d;const{boundsOfViewArea:v,scrollDirectionResponse:U}=n||{},{rowHeaderWidth:O,columnHeaderHeight:k}=t,W={top:i?0:k,left:i?0:O};v&&(l.Tools.isDefine(W.top)&&(W.top=v.top),l.Tools.isDefine(W.left)&&(W.left=v.left)),U==="HORIZONTAL"&&(M=0),U==="VERTICAL"&&(y=0);let P=0,T=0;const Y=t.rowStartY(c-h)+k,L=t.colStartX(u-p)+O,Z=t.rowStartY(c)+k,ee=t.colStartX(u)+O;if(p===0)S.left=!1,P=(f-y)*s,T=(w-y)*s;else{const K=f-(L-O),F=w-(L-O);w<ee?(P=K*s,T=F*s):f<=ee&&w>=ee?(P=K*s,T=Math.max(E,(w-y)*s)):f>ee&&(S.left=!1,P=Math.max((f-y)*s,E),T=Math.max((w-y)*s,E))}let V=0,z=0;if(h===0)S.top=!1,V=(_-M)*a,z=(I-M)*a;else{const K=_-(Y-k),F=I-(Y-k);I<Z?(V=K*a,z=F*a):_<=Z&&I>=Z?(V=K*a,z=Math.max(C,(I-M)*a)):_>Z&&(S.top=!1,V=Math.max((_-M)*a,C),z=Math.max((I-M)*a,C))}return P=Math.max(P,W.left),V=Math.max(V,W.top),T=Math.max(T,W.left),z=Math.max(z,W.top),{left:P,right:T,top:V,bottom:z,absolute:S}}const oe=(o,r,t,e,n)=>{const{left:i,top:s,width:a,height:d,angle:g}=o,u={left:i,right:i+a,top:s,bottom:s+d},c=Rt(u,r,t,e,n),{scaleX:p,scaleY:h}=r.getAncestorScale();return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:g,width:a*p,height:d*h,absolute:c.absolute}};b.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(t,e,n,i,s,a,d){super();re(this,"_domLayerInfoMap",new Map);re(this,"_transformChange$",new N.Subject);re(this,"transformChange$",this._transformChange$.asObservable());re(this,"_add$",new N.Subject);re(this,"add$",this._add$.asObservable());re(this,"_remove$",new N.Subject);re(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=i,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(N.filter(t=>t===l.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}getFloatDomsBySubUnitId(t,e){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===e&&n.unitId===t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const i=n.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:n,transformer:i,renderUnit:e,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var K;const{unitId:n,subUnitId:i,drawingId:s}=e,a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),d=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!d||!a)return;const c=(K=this._renderManagerService.getRenderById(n))==null?void 0:K.with(R.SheetSkeletonManagerService).getSkeletonParam(i);if(!c)return;const{transform:p,drawingType:h,data:S}=d;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const f=this._getSceneAndTransformerByDrawingSearch(n);if(f==null)return;const{scene:w,canvas:_}=f;if(p==null)return!0;if(u!==i)return;const{left:I,top:C,width:E,height:y,angle:M,flipX:v,flipY:U,skewX:O,skewY:k}=p,W=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:s}),P=w.getObject(W);if(P!=null){P.transformByState({left:I,top:C,width:E,height:y,angle:M,flipX:v,flipY:U,skewX:O,skewY:k});return}const T={left:I,top:C,width:E,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,i).length-1},Y=h===l.DrawingTypeEnum.DRAWING_CHART;if(T.rotateEnabled=!1,Y){const F=S?S.backgroundColor:"white";T.fill=F,S&&S.border&&(T.stroke=S.border),T.paintFirst="stroke",T.strokeWidth=1,T.borderEnabled=!1,T.radius=8}const L=new A.Rect(W,T);Y&&L.setObjectType(A.ObjectType.CHART),w.addObject(L,A.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&w.attachTransformerTo(L);const Z=new l.DisposableCollection,ee=oe(L,f.renderUnit.scene,c.skeleton,a.worksheet),V=new N.BehaviorSubject(ee),z={dispose:Z,rect:L,position$:V,unitId:n,subUnitId:i,id:s};this._canvasFloatDomService.addFloatDom({position$:V,id:s,componentKey:d.componentKey,onPointerDown:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{_.dispatchEvent(new WheelEvent(F.type,F))},data:S,unitId:n});const te=L.onTransformChange$.subscribeEvent(()=>{const F=oe(L,f.renderUnit.scene,c.skeleton,a.worksheet);V.next(F)});Z.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),te&&Z.add(te),this._domLayerInfoMap.set(s,z)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{var p;const{unitId:n,subUnitId:i,drawingId:s}=e,a=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:s}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:g,scene:u}=d,c=u.getObject(a);c!=null&&c.oKey&&(g.clearControlByIds([c==null?void 0:c.oKey]),(p=u.getTransformer())==null||p.clearSelectedObjects())})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const i=this._getSceneAndTransformerByDrawingSearch(e),s=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===e).map(u=>u.id),a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(R.SheetSkeletonManagerService).getSkeletonParam(n);!i||!a||!d||s.forEach(u=>{const c=this._domLayerInfoMap.get(u);if(c){const p=oe(c.rect,i.renderUnit.scene,d.skeleton,a.worksheet,c);c.position$.next(p)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(e=>e?e.activeSheet$:N.of(null)),N.map(e=>{if(!e)return null;const n=e.getUnitId(),i=this._renderManagerService.getRenderById(n);return i?{render:i,unitId:n,subUnitId:e.getSheetId()}:null}),N.switchMap(e=>e?l.fromEventSubject(e.render.scene.getViewport(A.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(N.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):N.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:i}=e;t(n,i)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===R.SetZoomRatioOperation.id){const n=e.params,{unitId:i}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===i).map(a=>a.subUnitId).forEach(a=>{t(i,a)})}else if(e.id===D.SetFrozenMutation.id){const{unitId:n,subUnitId:i}=e.params;t(n,i)}}))}updateFloatDomProps(t,e,n,i){const s=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(s&&a){const{scene:d}=a,g=j.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=d.getObject(g);u&&u instanceof A.Rect&&u.setProps(i)}}_getPosition(t,e){var h;const{startX:n,endX:i,startY:s,endY:a}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(R.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(n,s);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:s-g.startY},c=d.getCellWithCoordByOffset(i,a);if(c==null)return;const p={column:c.actualColumn,columnOffset:i-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const i={...n.transform};this._transformChange$.next({id:e.drawingId,value:i}),this._canvasFloatDomService.updateFloatDom(e.drawingId,{...n});const s=this._getSceneAndTransformerByDrawingSearch(e.unitId);if(s&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART){const{scene:a}=s,d=this._domLayerInfoMap.get(e.drawingId);d!=null&&d.rect&&(n.allowTransform===!1?a.detachTransformerFrom(d.rect):a.attachTransformerTo(d.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(t,e){const n=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:i,subUnitId:s}=n,{initPosition:a,componentKey:d,data:g,allowTransform:u=!0}=t,c=e!=null?e:l.generateRandomId(),p=this._getPosition(a,i);if(p==null)return;const h={unitId:i,subUnitId:s,drawingId:c,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:p,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Te.id,{unitId:i,drawings:[h]}),this._add$.next({unitId:i,subUnitId:s,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:i,subUnitId:s}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(i);if(a&&a.scene.removeObject(n.rect),e){const d=this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:s,drawingId:t});if(!d)return;const g=this._sheetDrawingService.getBatchRemoveOp([d]),{redo:u,objects:c}=g;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:i,subUnitId:s,op:u,objects:c,type:m.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,i){var v,U,O;const s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=s,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(v=this._renderManagerService.getRenderById(a))==null?void 0:v.with(R.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:S=!0}=e,f=i!=null?i:l.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver(t,u,c.skeleton);if(this._getPosition(w,a)==null)return;const C=g.scene,{scaleX:E}=C.getAncestorScale(),y=Xe(w,n,E),M={unitId:a,subUnitId:d,drawingId:f,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:y.startX,top:y.startY,width:y.width,height:y.height},data:h,allowTransform:S};{const{unitId:k,subUnitId:W,drawingId:P}=M,T=D.getSheetCommandTarget(this._univerInstanceService,{unitId:k,subUnitId:W}),Y=M,L=this._univerInstanceService.getUnit(k,l.UniverInstanceType.UNIVER_SHEET);if(!L)return;const Z=L.getActiveSheet().getSheetId();if(!Y||!T)return;const ee=(U=this._renderManagerService.getRenderById(k))==null?void 0:U.with(R.SheetSkeletonManagerService);if(!ee)return;const V=ee.getWorksheetSkeleton(W);if(!V)return;const{transform:z,drawingType:te,data:K}=Y;if(te!==l.DrawingTypeEnum.DRAWING_DOM&&te!==l.DrawingTypeEnum.DRAWING_CHART)return;const F=this._getSceneAndTransformerByDrawingSearch(k);if(F==null)return;const{scene:_e,canvas:ve}=F;if(z==null||Z!==W)return;const{left:xe,top:qe,width:Ze,height:Je,angle:wt,flipX:_t,flipY:Qe,skewX:et,skewY:Ie}=z,tt=j.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),se=_e.getObject(tt);if(se!=null){se.transformByState({left:xe,top:qe,width:Ze,height:Je,angle:wt,flipX:_t,flipY:Qe,skewX:et,skewY:Ie});return}const ne={left:xe,top:qe,width:Ze,height:Je,zIndex:this._drawingManagerService.getDrawingOrder(k,W).length-1},ye=te===l.DrawingTypeEnum.DRAWING_CHART;if(ye){const $=K?K.backgroundColor:"white";ne.fill=$,ne.rotateEnabled=!1,K&&K.border&&(ne.stroke=K.border),ne.paintFirst="stroke",ne.strokeWidth=1,ne.borderEnabled=!1,ne.radius=8}const ae=new A.Rect(tt,ne);ye&&ae.setObjectType(A.ObjectType.CHART),_e.addObject(ae,A.DRAWING_OBJECT_LAYER_INDEX),Y.allowTransform!==!1&&_e.attachTransformerTo(ae);const ce=new l.DisposableCollection,nt=_e.getMainViewport(),{rowHeaderWidth:De,columnHeaderHeight:Ue}=V.skeleton,rt={top:Ue,left:De,bottom:nt.bottom,right:nt.right},de={dispose:ce,rect:ae,boundsOfViewArea:rt,domAnchor:n,unitId:k,subUnitId:W},X=oe(ae,F.renderUnit.scene,V.skeleton,T.worksheet,de),Ce=new N.BehaviorSubject(X);de.position$=Ce;let Ne={position$:Ce,id:P,componentKey:Y.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{ve.dispatchEvent(new WheelEvent($.type,$))},data:K,unitId:k};e.eventPassThrough&&(Ne={...Ne,onPointerDown:$=>{ve.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{ve.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{ve.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(Ne),this.disposeWithMe(_.subscribe($=>{var Ot,At,Pt,Ut;const bt=Xe({startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(Ot=n.width)!=null?Ot:$.width,height:(At=n.height)!=null?At:$.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Nn=j.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),kn=new A.Rect(Nn,{left:bt.startX,top:bt.startY,width:(Pt=n.width)!=null?Pt:$.width,height:(Ut=n.height)!=null?Ut:$.height,zIndex:this._drawingManagerService.getDrawingOrder(k,W).length-1}),Wn=oe(kn,F.renderUnit.scene,V.skeleton,T.worksheet,de);Ce.next(Wn)}));const ke=(O=this._renderManagerService.getRenderById(k))==null?void 0:O.with(R.SheetSkeletonManagerService);ke==null||ke.currentSkeleton$.subscribe($=>{$&&V.sheetId!==$.sheetId&&this._removeDom(f,!0)});const it=ae.onTransformChange$.subscribeEvent(()=>{const $=oe(ae,F.renderUnit.scene,V.skeleton,T.worksheet,de);Ce.next($)});ce.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),it&&ce.add(it),this._domLayerInfoMap.set(P,de)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}addFloatDomToColumnHeader(t,e,n,i){var y,M,v;const s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(y=this._renderManagerService.getRenderById(a))==null?void 0:y.with(R.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:S=!0}=e,f=i!=null?i:l.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,c.skeleton),I=w;if(I.startY=0,this._getPosition(w,a)==null)return;const E={unitId:a,subUnitId:d,drawingId:f,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:S};{const{unitId:U,subUnitId:O,drawingId:k}=E,W=D.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:O}),P=E,T=this._univerInstanceService.getUnit(U,l.UniverInstanceType.UNIVER_SHEET);if(!T)return;const Y=T.getActiveSheet().getSheetId();if(!P||!W)return;const L=(M=this._renderManagerService.getRenderById(U))==null?void 0:M.with(R.SheetSkeletonManagerService);if(!L)return;const Z=L.getWorksheetSkeleton(O);if(!Z)return;const{transform:ee,data:V}=P,z=this._getSceneAndTransformerByDrawingSearch(U);if(z==null)return;const{scene:te,canvas:K}=z;if(ee==null||Y!==O)return;const{left:F,top:_e,width:ve,height:xe,angle:qe,flipX:Ze,flipY:Je,skewX:wt,skewY:_t}=ee,Qe=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:O,drawingId:k}),et=te.getObject(Qe);if(et!=null){et.transformByState({left:F,top:_e,width:ve,height:xe,angle:qe,flipX:Ze,flipY:Je,skewX:wt,skewY:_t});return}const Ie=Xe({startX:I.startX,startY:0,endX:w.endX,endY:w.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),tt={left:Ie.startX,top:Ie.startY,width:Ie.width,height:Ie.height,zIndex:this._drawingManagerService.getDrawingOrder(U,O).length-1},se=new A.Rect(Qe,tt);te.addObject(se,A.DRAWING_OBJECT_LAYER_INDEX),P.allowTransform!==!1&&te.attachTransformerTo(se);const ne=new l.DisposableCollection,ye=te.getMainViewport(),ae={top:0,left:ye.left,bottom:ye.bottom,right:ye.right},ce={dispose:ne,rect:se,unitId:U,subUnitId:O,boundsOfViewArea:ae,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},nt=oe(se,z.renderUnit.scene,Z.skeleton,W.worksheet,ce),De=new N.BehaviorSubject(nt);ce.position$=De;let Ue={position$:De,id:k,componentKey:P.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:X=>{K.dispatchEvent(new WheelEvent(X.type,X))},data:V,unitId:U};e.eventPassThrough&&(Ue={...Ue,onPointerDown:X=>{K.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{K.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{K.dispatchEvent(new PointerEvent(X.type,X))}}),this._canvasFloatDomService.addFloatDom(Ue);const rt=se.onTransformChange$.subscribeEvent(()=>{const X=oe(se,z.renderUnit.scene,Z.skeleton,W.worksheet,ce);De.next(X)});this.disposeWithMe(_.subscribe(X=>{const Ce=Xe({startX:X.startX,startY:0,endX:X.endX,endY:X.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Ne=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:O,drawingId:k}),ke=new A.Rect(Ne,{left:Ce.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(U,O).length-1}),it=oe(ke,z.renderUnit.scene,Z.skeleton,W.worksheet,ce);De.next(it)}));const de=(v=this._renderManagerService.getRenderById(U))==null?void 0:v.with(R.SheetSkeletonManagerService);de==null||de.currentSkeleton$.subscribe(X=>{X&&c.sheetId!==X.sheetId&&this._removeDom(f,!0)}),ne.add(()=>{this._canvasFloatDomService.removeFloatDom(k)}),rt&&ne.add(rt),this._domLayerInfoMap.set(k,ce)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:i,startColumn:s}=t;const a=Ae(i,s,n),d=new N.BehaviorSubject(a),g=Ae(t.endRow,t.endColumn,n),u=new N.BehaviorSubject(g),c=()=>{const _=Ae(i,s,n),I=Ae(t.endRow,t.endColumn,n);d.next(_),u.next(I)},p=new l.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>c())),p.add(this._commandService.onCommandExecuted(_=>{if(_.id===D.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(C=>C.row===i)>-1){c();return}(D.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===R.SetScrollOperation.id||_.id===R.SetZoomRatioOperation.id)&&c()}));const h=(_,I)=>{i=_,s=I,c()},S=()=>({rotate:0,width:g.right-a.left,height:g.bottom-a.top,absolute:{left:!0,top:!0},startX:a.left,startY:a.top,endX:g.right,endY:g.bottom}),f=d.pipe(N.map(_=>{const I=Ae(t.endRow,t.endColumn,n);return{rotate:0,width:I.right-_.left,height:I.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:I.right,endY:I.bottom}})),w=S();return{position$:f,position:w,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:p}}},b.SheetCanvasFloatDomManagerService=cn([ge(0,l.Inject(A.IRenderManagerService)),ge(1,l.IUniverInstanceService),ge(2,l.Inject(l.ICommandService)),ge(3,j.IDrawingManagerService),ge(4,l.Inject(B.CanvasFloatDomService)),ge(5,m.ISheetDrawingService),ge(6,l.Inject(l.LifecycleService))],b.SheetCanvasFloatDomManagerService);function Ae(o,r,t){const e=t.getCellWithCoordByIndex(o,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Xe(o,r,t){var g,u;t=t!=null?t:1;const e=o.endX-o.startX,n=o.endY-o.startY,i=(g=r==null?void 0:r.width)!=null?g:e,s=(u=r==null?void 0:r.height)!=null?u:n;let a=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=Ve(r.marginX,e*t);a=o.endX-c-i}else a=o.startX+Ve(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const c=Ve(r.marginY,n*t);d=o.endY-c-s}else d=o.startY+Ve(r.marginY,n)}return{rotate:0,startX:a,startY:d,endX:o.endX,endY:o.endY,width:i,height:s,absolute:{left:o.absolute.left,top:o.absolute.top}}}function Ve(o,r){if(o===void 0)return 0;if(typeof o=="number")return o;const t=Number.parseFloat(o);return r*t/100}const dn=o=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=o,i=pe.useMemo(()=>r.map(s=>{const{width:a,height:d,angle:g,left:u,top:c}=s.transform,p=Rt({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:c!=null?c:0,bottom:(c!=null?c:0)+(d!=null?d:0)},t,e,n,void 0,!0),{scaleX:h,scaleY:S}=t.getAncestorScale(),f={startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:g,width:a*h,height:d*S,absolute:p.absolute},w={position$:new N.BehaviorSubject(f),position:f,id:s.drawingId,componentKey:s.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:s.unitId,data:s.data};return[s.drawingId,w]}),[r,t,e,n]);return J.jsx("div",{style:{position:"absolute",top:0,left:0},children:i.map(([s,a])=>J.jsx(B.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};var ln=Object.getOwnPropertyDescriptor,un=(o,r,t,e)=>{for(var n=e>1?void 0:e?ln(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},he=(o,r)=>(t,e)=>r(t,e,o);let Ke=class extends l.Disposable{constructor(o,r,t,e,n,i,s){super(),this._sheetPrintInterceptorService=o,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=i,this._injector=s,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(o,r,t)=>{const{unitId:e,scene:n,subUnitId:i}=r,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[i];return a&&a.order.forEach(d=>{const g=a.data[d];g.drawingType!==l.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(o,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._renderManagerService.getRenderById(e);if(!i)return t(o);const s=i.with(R.SheetSkeletonManagerService).getSkeletonParam(n);if(!s)return t(o);const a=this._drawingManagerService.getDrawingDataForUnit(e),d=a==null?void 0:a[r.subUnitId];if(!d)return t(o);const{scaleX:g,scaleY:u}=i.scene,c=o?{...o}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=d.order.map(h=>d.data[h]);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const S=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),f=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});S.column<c.startColumn&&(c.startColumn=S.column),S.row<c.startRow&&(c.startRow=S.row),c.endRow<f.row&&(c.endRow=f.row),c.endColumn<f.column&&(c.endColumn=f.column)}}),t(c)):t(o)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(o,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._drawingManagerService.getDrawingDataForUnit(e),s=i==null?void 0:i[n];if(s){const a=s.order.map(g=>{const u=s.data[g];if(u.drawingType===l.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(l.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===l.DrawingTypeEnum.DRAWING_DOM){const c=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(c||u.componentKey)}}return null}).filter(Boolean),d=B.connectInjector(dn,this._injector);return q.render(J.jsx(d,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),o==null||o.add(()=>{q.unmount(r.root)}),t(o)}}}))}};Ke=un([he(0,l.Inject(R.SheetPrintInterceptorService)),he(1,l.Inject(le.DrawingRenderService)),he(2,j.IDrawingManagerService),he(3,A.IRenderManagerService),he(4,l.Inject(b.SheetCanvasFloatDomManagerService)),he(5,l.Inject(B.ComponentManager)),he(6,l.Inject(l.Injector))],Ke);var gn=Object.getOwnPropertyDescriptor,hn=(o,r,t,e)=>{for(var n=e>1?void 0:e?gn(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},ue=(o,r)=>(t,e)=>r(t,e,o);const pn=[D.InsertRowCommand.id,D.InsertColCommand.id,D.RemoveRowCommand.id,D.RemoveColCommand.id,D.DeleteRangeMoveLeftCommand.id,D.DeleteRangeMoveUpCommand.id,D.InsertRangeMoveDownCommand.id,D.InsertRangeMoveRightCommand.id,D.DeltaRowHeightCommand.id,D.SetRowHeightCommand.id,D.DeltaColumnWidthCommand.id,D.SetColWidthCommand.id,D.SetRowHiddenCommand.id,D.SetSpecificRowsVisibleCommand.id,D.SetSpecificColsVisibleCommand.id,D.SetColHiddenCommand.id,D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id],mn=[D.SetRowVisibleMutation.id,D.SetRowHiddenMutation.id,D.SetColVisibleMutation.id,D.SetColHiddenMutation.id,D.SetWorksheetRowHeightMutation.id,D.SetWorksheetColWidthMutation.id];let mt=class extends l.Disposable{constructor(o,r,t,e,n,i,s,a,d){super(),this._context=o,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=i,this._sheetDrawingService=s,this._drawingManagerService=a,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:o=>{if(!pn.includes(o.id))return{redos:[],undos:[]};if(o.params==null)return{redos:[],undos:[]};const r=o.id;if(r===D.InsertRowCommand.id)return this._moveRowInterceptor(o.params,"insert");if([D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(o.params);if(r===D.InsertColCommand.id)return this._moveColInterceptor(o.params,"insert");if(r===D.RemoveRowCommand.id)return this._moveRowInterceptor(o.params,"remove");if(r===D.RemoveColCommand.id)return this._moveColInterceptor(o.params,"remove");if(r===D.DeleteRangeMoveLeftCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,0)}else if(r===D.DeleteRangeMoveUpCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,1)}else if(r===D.InsertRangeMoveDownCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,2)}else if(r===D.InsertRangeMoveRightCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,3)}else if(r===D.SetRowHiddenCommand.id||r===D.SetSpecificRowsVisibleCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForRowVisible(e,n,i)}else if(r===D.SetSpecificColsVisibleCommand.id||r===D.SetColHiddenCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForColVisible(e,n,i)}else if(r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id||r===D.DeltaColumnWidthCommand.id||r===D.SetColWidthCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t,s=r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,i,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(o,r){const t=D.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,i=[],s=[],a=this._sheetDrawingService.getDrawingData(e,n),d=[],g=[];if(Object.keys(a).forEach(u=>{const c=a[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(o,r,c);d.push(...p),g.push(...h)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:p,objects:h}=u;i.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),c=u.undo,p=u.redo,h=u.objects;i.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.INSERT}})}return i.push({id:H.id,params:[e]}),s.push({id:H.id,params:[e]}),{redos:i,undos:s}}_getUpdateOrDeleteDrawings(o,r,t){const e=[],n=[],{sheetTransform:i,anchorType:s=m.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:g,drawingId:u}=t,{from:c,to:p}=i,{row:h,column:S}=c,{row:f,column:w}=p;if(i==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:_,endRow:I,startColumn:C,endColumn:E}=o;let y=null,M=null;if(r===0&&h>=_&&f<=I)if(S>=C&&w<=E)n.push({unitId:d,subUnitId:g,drawingId:u});else{const v=this._shrinkCol(i,a,C,E,s);y=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(r===1&&S>=C&&w<=E)if(h>=_&&f<=I)n.push({unitId:d,subUnitId:g,drawingId:u});else{const v=this._shrinkRow(i,a,_,I,s);y=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(r===2){const v=this._expandRow(i,a,_,I,s);y=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(r===3){const v=this._expandCol(i,a,C,E,s);y=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}if(y!=null&&M!=null){const v=x(y,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:y,transform:v})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(o,r,t){const e=G({...o},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:S=m.SheetDrawingAnchorType.Position}=c;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:f,to:w}=p,{row:_,column:I}=f,{row:C,column:E}=w;for(let y=0;y<t.length;y++){const M=t[y],{startRow:v,endRow:U,startColumn:O,endColumn:k}=M;if(E<O)continue;if(S===m.SheetDrawingAnchorType.Position){let T=null,Y=null;if(I>=O&&I<=k){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:k,startRow:f.row,endRow:w.row});if(L==null)return;Y={...h,left:L.startX}}if(Y!=null&&(T=G(Y,this._selectionRenderService),T!=null&&Y!=null)){n.push({...c,sheetTransform:T,transform:Y});break}this._remainDrawingSize(h,n,c);continue}if(I>=O&&E<=k)continue;let W=null,P=null;if(I>=O&&I<=k){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:k,startRow:f.row,endRow:w.row});if(T==null)return;P={...h,left:(T==null?void 0:T.startX)||0,width:((h==null?void 0:h.width)||0)-T.endX+T.startX}}else if(E>=O&&E<=k){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:E,startRow:f.row,endRow:w.row});if(T==null)return;P={...h,left:T.startX-((h==null?void 0:h.width)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:k,startRow:f.row,endRow:w.row});if(T==null)return;if(P={...h,width:((h==null?void 0:h.width)||0)-T.endX+T.startX},W=G(P,this._selectionRenderService),W!=null&&P!=null){i.push({...c,sheetTransform:W,transform:P});break}}if(P!=null&&(W=G(P,this._selectionRenderService)),P!=null&&W!=null){n.push({...c,sheetTransform:W,transform:P});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&i.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(o,r,n),d=[],g=[];if(i.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(o,r,i);d.push(...u),g.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(o,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:i,objects:s}=e,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:r,op:i,objects:s,type:m.DrawingApplyType.UPDATE}},{id:H.id,params:[o]}],d=[{id:m.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:r,op:n,objects:s,type:m.DrawingApplyType.UPDATE}},{id:H.id,params:[o]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:S=m.SheetDrawingAnchorType.Position}=c;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:f,to:w}=p,{row:_,column:I}=f,{row:C,column:E}=w;for(let y=0;y<t.length;y++){const M=t[y],{startRow:v,endRow:U,startColumn:O,endColumn:k}=M;if(C<v)continue;if(S===m.SheetDrawingAnchorType.Position){let T=null,Y=null;if(_>=v&&_<=U){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:U});if(L==null)return;Y={...h,top:L.startY}}if(Y!=null&&(T=G(Y,this._selectionRenderService),T!=null&&Y!=null)){n.push({...c,sheetTransform:T,transform:Y});break}this._remainDrawingSize(h,n,c);continue}if(_>=v&&C<=U)continue;let W=null,P=null;if(_>=v&&_<=U){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:U});if(T==null)return;P={...h,top:(T==null?void 0:T.startY)||0,height:((h==null?void 0:h.height)||0)-T.endY+T.startY}}else if(C>=v&&C<=U){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:v,endRow:C});if(T==null)return;P={...h,top:T.startY-((h==null?void 0:h.height)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:v,endRow:U});if(T==null)return;if(P={...h,height:((h==null?void 0:h.height)||0)-T.endY+T.startY},W=G(P,this._selectionRenderService),W!=null&&P!=null){i.push({...c,sheetTransform:W,transform:P});break}}if(P!=null&&(W=G(P,this._selectionRenderService)),P!=null&&W!=null){n.push({...c,sheetTransform:W,transform:P});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&i.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(o,r,n),d=[],g=[];if(i.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(o,r,i);d.push(...u),g.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(o,r,t,e){const n=this._drawingManagerService.getDrawingData(o,r),i=[];return Object.keys(n).forEach(s=>{const a=n[s],{sheetTransform:d,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=a;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,i,a);else{const{from:c,to:p}=d,{row:h,column:S}=c,{row:f,column:w}=p;for(let _=0;_<t.length;_++){const I=t[_],{startRow:C,endRow:E,startColumn:y,endColumn:M}=I;if(f<C||w<y)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=C&&f>=E||S<=y&&w>=M)){this._remainDrawingSize(g,i,a);continue}const v=x({...d},this._selectionRenderService,this._skeletonManagerService);if(v!=null){i.push({...a,transform:v});break}}}}),i.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(o,r,i)}_getUnitIdAndSubUnitId(o,r){let t,e;if(r==="insert")t=o.unitId,e=o.subUnitId;else{const n=D.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(o){var C,E;const{toRange:r,fromRange:t}=o,e=D.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:i}=e,s=(E=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.with(R.SheetSkeletonManagerService))==null?void 0:E.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=R.attachRangeWithCoord(s,t);if(!a)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=a,p=this._sheetDrawingService.getDrawingData(n,i),h=[];Object.keys(p).forEach(y=>{const M=p[y];if(M.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:v}=M;if(!v)return;const{left:U=0,top:O=0,width:k=0,height:W=0}=v,{drawingStartX:P,drawingEndX:T,drawingStartY:Y,drawingEndY:L}={drawingStartX:U,drawingEndX:U+k,drawingStartY:O,drawingEndY:O+W};d<=P&&T<=g&&u<=Y&&L<=c&&h.push(M)});const S=[],f=[],w=r.startRow-t.startRow,_=r.startColumn-t.startColumn,I=h.map(y=>{const M=y.sheetTransform,v={to:{...M.to,row:M.to.row+w,column:M.to.column+_},from:{...M.from,row:M.from.row+w,column:M.from.column+_}},U=x(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:i,drawingId:y.drawingId,transform:U,sheetTransform:v}});if(I.length){const y=this._sheetDrawingService.getBatchUpdateOp(I),{undo:M,redo:v,objects:U}=y;S.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:v,objects:U,type:m.DrawingApplyType.UPDATE}}),f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:M,objects:U,type:m.DrawingApplyType.UPDATE}})}return{redos:S,undos:f}}_moveRowInterceptor(o,r){const t=this._getUnitIdAndSubUnitId(o,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=o,s=i.startRow,a=i.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const S=u[h],{sheetTransform:f,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let I,C;if(r==="insert"){const y=this._expandRow(f,w,s,a,_);I=y==null?void 0:y.newSheetTransform,C=y==null?void 0:y.newTransform}else{const{from:y,to:M}=f,{row:v}=y,{row:U}=M;if(_===m.SheetDrawingAnchorType.Both&&v>=s&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const O=this._shrinkRow(f,w,s,a,_);I=O==null?void 0:O.newSheetTransform,C=O==null?void 0:O.newTransform}}if(!I||!C)return;const E={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};c.push(E)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:S,redo:f,objects:w}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),S=h.undo,f=h.redo,w=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.INSERT}})}return d.push({id:H.id,params:[e]}),g.push({id:H.id,params:[e]}),{redos:d,undos:g}}_moveColInterceptor(o,r){const t=this._getUnitIdAndSubUnitId(o,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=o,s=i.startColumn,a=i.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const S=u[h],{sheetTransform:f,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let I,C;if(r==="insert"){const y=this._expandCol(f,w,s,a,_);I=y==null?void 0:y.newSheetTransform,C=y==null?void 0:y.newTransform}else{const{from:y,to:M}=f,{column:v}=y,{column:U}=M;if(_===m.SheetDrawingAnchorType.Both&&v>=s&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const O=this._shrinkCol(f,w,s,a,_);I=O==null?void 0:O.newSheetTransform,C=O==null?void 0:O.newTransform}}if(!I||!C)return;const E={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};c.push(E)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:S,redo:f,objects:w}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),S=h.undo,f=h.redo,w=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.INSERT}})}return d.push({id:H.id,params:[e]}),g.push({id:H.id,params:[e]}),{redos:d,undos:g}}_expandCol(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{column:d}=s,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:s.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)+p.endX-p.startX},u=G(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g+i}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{column:d}=s,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...s,column:d-i},to:{...a,column:g-i}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g-i}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,left:(r.left||0)-o.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:s.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)-p.endX+p.startX-o.from.columnOffset}}u=G(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:s.row,endRow:a.row});if(p==null)return;u={from:{...s},to:{...a,column:t-1,columnOffset:p.endX-p.startX}},c=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{row:d}=s,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:s.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)+p.endY-p.startY},u=G(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g+i}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{row:d}=s,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...s,row:d-i},to:{...a,row:g-i}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g-i}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,top:(r.top||0)-o.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:s.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)-p.endY+p.startY-o.from.rowOffset}}u=G(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...s},to:{...a,row:t-1,rowOffset:p.endY-p.startY}},c=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{if(o.id===D.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=o.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(o=>{const{unit:r,unitId:t}=this._context;if(o){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(o){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(i=>{const s=n[i].data;s!=null&&Object.keys(s).forEach(a=>{e===o&&t.push(s[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(o,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(i=>{const s=t[i];s!=null&&Object.keys(s).forEach(a=>{const d=s[a].data;d!=null&&Object.keys(d).forEach(g=>{if(i===o&&a===r){const u=d[g];u.transform=x(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(d[g])}else n.push(d[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{mn.includes(o.id)&&requestIdleCallback(()=>{const r=o.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[];Object.keys(e).forEach(i=>{const s=e[i],{sheetTransform:a,transform:d,anchorType:g=m.SheetDrawingAnchorType.Position}=s;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=a,{row:p,column:h}=u,{row:S,column:f}=c;for(let w=0;w<t.length;w++){const _=t[w],{startRow:I,endRow:C,startColumn:E,endColumn:y}=_;if(l.Rectangle.intersects({startRow:I,endRow:C,startColumn:E,endColumn:y},{startRow:p,endRow:S,startColumn:h,endColumn:f})||p>C||h>y){const M=g===m.SheetDrawingAnchorType.Position,v=x(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...v,width:M?d==null?void 0:d.width:v==null?void 0:v.width,height:M?d==null?void 0:d.height:v==null?void 0:v.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(H.id,[o]))}};mt=hn([ue(1,A.IRenderManagerService),ue(2,l.ICommandService),ue(3,R.ISheetSelectionRenderService),ue(4,l.Inject(R.SheetSkeletonManagerService)),ue(5,l.Inject(D.SheetInterceptorService)),ue(6,m.ISheetDrawingService),ue(7,j.IDrawingManagerService),ue(8,l.IUniverInstanceService)],mt);const fn=o=>{var I;const r=B.useDependency(l.ICommandService),t=B.useDependency(l.LocaleService),e=B.useDependency(j.IDrawingManagerService),n=B.useDependency(A.IRenderManagerService),{drawings:i}=o,s=i[0];if(s==null)return;const{unitId:a}=s,d=n.getRenderById(a),g=d==null?void 0:d.scene;if(g==null)return;const u=g.getTransformerByCreate(),[c,p]=pe.useState(!0),h=(I=s.anchorType)!=null?I:m.SheetDrawingAnchorType.Position,[S,f]=pe.useState(h);function w(C,E){const y=[];return C.forEach(M=>{const{oKey:v}=M,U=E.getDrawingOKey(v);if(U==null)return y.push(null),!0;const{unitId:O,subUnitId:k,drawingId:W,drawingType:P,anchorType:T,sheetTransform:Y}=U;y.push({unitId:O,subUnitId:k,drawingId:W,anchorType:T,sheetTransform:Y,drawingType:P})}),y}pe.useEffect(()=>{const C=u.clearControl$.subscribe(y=>{y===!0&&p(!1)}),E=u.changeStart$.subscribe(y=>{var U;const{objects:M}=y,v=w(M,e);if(v.length===0)p(!1);else if(v.length>=1){p(!0);const O=((U=v[0])==null?void 0:U.anchorType)||m.SheetDrawingAnchorType.Position;f(O)}});return()=>{E.unsubscribe(),C.unsubscribe()}},[]);function _(C){f(C);const E=e.getFocusDrawings();if(E.length===0)return;const y=E.map(M=>({unitId:M.unitId,subUnitId:M.subUnitId,drawingId:M.drawingId,anchorType:C}));r.executeCommand(Me.id,{unitId:E[0].unitId,drawings:y})}return J.jsxs("div",{className:q.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!c}),children:[J.jsx("header",{className:"univer-text-gray-600 dark:!univer-text-gray-200",children:J.jsx("div",{children:t.t("drawing-anchor.title")})}),J.jsx("div",{children:J.jsxs(q.RadioGroup,{value:S,onChange:_,direction:"vertical",children:[J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})]})},Sn=()=>{const o=B.useDependency(j.IDrawingManagerService),r=o.getFocusDrawings(),[t,e]=pe.useState(r);return pe.useEffect(()=>{const n=o.focus$.subscribe(i=>{e(i)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&J.jsxs("div",{className:"univer-text-sm",children:[J.jsx(le.DrawingCommonPanel,{drawings:t}),J.jsx(fn,{drawings:t})]})},ft="sheet.menu.image";function wn(o){return{id:ft,type:B.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:B.getMenuHiddenObservable(o,l.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(o,{workbookTypes:[D.WorkbookEditablePermission],worksheetTypes:[D.WorksheetEditPermission],rangeTypes:[D.RangeProtectionPermissionEditPoint]})}}function _n(o){return{id:Re.id,title:"sheetImage.upload.float",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(o,l.UniverInstanceType.UNIVER_SHEET)}}function vn(o){return{id:lt.id,title:"sheetImage.upload.cell",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(o,l.UniverInstanceType.UNIVER_SHEET)}}const In={[B.RibbonInsertGroup.MEDIA]:{[ft]:{order:0,menuItemFactory:wn,[Re.id]:{order:0,menuItemFactory:_n},[lt.id]:{order:1,menuItemFactory:vn}}}};function Pe(o){return!o.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!o.getContextValue(l.EDITOR_ACTIVATED)&&!o.getContextValue(l.FOCUSING_PANEL_EDITOR)&&o.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const yn={id:fe.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:B.KeyCode.ARROW_DOWN,priority:100,preconditions:Pe,staticParameters:{direction:l.Direction.DOWN}},Dn={id:fe.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:B.KeyCode.ARROW_UP,priority:100,preconditions:Pe,staticParameters:{direction:l.Direction.UP}},Cn={id:fe.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:B.KeyCode.ARROW_LEFT,priority:100,preconditions:Pe,staticParameters:{direction:l.Direction.LEFT}},Tn={id:fe.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:B.KeyCode.ARROW_RIGHT,priority:100,preconditions:Pe,staticParameters:{direction:l.Direction.RIGHT}},Mn={id:ot.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:Pe,binding:B.KeyCode.DELETE,mac:B.KeyCode.BACKSPACE};var Rn=Object.getOwnPropertyDescriptor,En=(o,r,t,e)=>{for(var n=e>1?void 0:e?Rn(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},we=(o,r)=>(t,e)=>r(t,e,o);let ze=class extends l.Disposable{constructor(o,r,t,e,n,i){super(),this._componentManager=o,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=i,this._init()}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(It,Sn))}_initMenus(){this._menuManagerService.mergeMenu(In)}_initCommands(){[Re,lt,Te,me,Me,ut,H,gt,st,ct,fe,ot,at].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o)))}_initShortcuts(){[yn,Dn,Cn,Tn,Mn].forEach(o=>{this.disposeWithMe(this._shortcutService.registerShortcut(o))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};ze=En([we(0,l.Inject(B.ComponentManager)),we(1,B.IMenuManagerService),we(2,l.ICommandService),we(3,B.IShortcutService),we(4,j.IDrawingManagerService),we(5,l.Inject(D.SheetsSelectionsService))],ze);var bn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,An=(o,r,t)=>r in o?bn(o,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[r]=t,Pn=(o,r,t,e)=>{for(var n=e>1?void 0:e?On(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},St=(o,r)=>(t,e)=>r(t,e,o),Et=(o,r,t)=>An(o,typeof r!="symbol"?r+"":r,t);const Un="SHEET_IMAGE_UI_PLUGIN";b.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=yt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:i,...s}=l.merge({},yt,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Yt,s)}onStarting(){l.registerDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService],[ze],[je],[Ke],[He],[Ge],[Fe],[$e],[Le]]),l.touchDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[Ge],[Le]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[He],[Ke],[ze],[Fe],[$e]])}onSteady(){this._injector.get(je)}_registerRenderModules(){[[b.SheetDrawingUpdateController],[mt],[pt],[ht]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}},Et(b.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),Et(b.UniverSheetsDrawingUIPlugin,"pluginName",Un),b.UniverSheetsDrawingUIPlugin=Pn([l.DependentOn(j.UniverDrawingPlugin,vt.UniverDocsDrawingPlugin,le.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),St(1,l.Inject(l.Injector)),St(2,A.IRenderManagerService),St(3,l.IConfigService)],b.UniverSheetsDrawingUIPlugin),b.ClearSheetDrawingTransformerOperation=H,b.DeleteDrawingsCommand=ot,b.EditSheetDrawingOperation=gt,b.GroupSheetDrawingCommand=st,b.InsertFloatImageCommand=Re,b.InsertSheetDrawingCommand=Te,b.MoveDrawingsCommand=fe,b.RemoveSheetDrawingCommand=me,b.SHEETS_IMAGE_MENU_ID=ft,b.SetDrawingArrangeCommand=at,b.SetSheetDrawingCommand=Me,b.SidebarSheetDrawingOperation=ut,b.UngroupSheetDrawingCommand=ct,b.calcSheetFloatDomPosition=oe,b.drawingPositionToTransform=x,b.transformToDrawingPosition=G,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
|
2
|
+
`?(this._commandService.syncExecuteCommand(R.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(n.drawings)[0])):this._dialogService.open({id:"sheet-cell-image-copy-paste",title:{label:this._localeService.t("cell-image.pasteTitle")},children:{label:this._localeService.t("cell-image.pasteContent")},width:320,destroyOnClose:!0,onClose:a,showOk:!0,showCancel:!0,onOk:()=>{a(),this._setCellImage(Object.values(n.drawings)[0])},onCancel:a})}throw new Error("Sheet cell image copy paste is not supported in this unit")}}}))}};Le=Zt([Ee(0,l.ICommandService),Ee(1,l.IUniverInstanceService),Ee(2,B.IDialogService),Ee(3,A.IRenderManagerService),Ee(4,l.Inject(l.LocaleService))],Le);var Qt=Object.getOwnPropertyDescriptor,en=(o,r,t,e)=>{for(var n=e>1?void 0:e?Qt(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},be=(o,r)=>(t,e)=>r(t,e,o);const Tt="image/png";function tn(o){const r=o.split(","),t=atob(r[1]),e=t.length,n=new Uint8Array(e);for(let i=0;i<e;i++)n[i]=t.charCodeAt(i);return new Blob([n],{type:Tt})}function nn(o){const r=new ClipboardItem({[Tt]:tn(o)});navigator.clipboard.write([r]).catch(t=>{console.error("Could not copy image using clipboard API: ",t)})}function rn(){function o(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const r=document.activeElement,t=o();return document.body.appendChild(t),t.focus(),()=>{t.blur(),document.body.removeChild(t),r instanceof HTMLElement&&r.focus()}}const Mt=[R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let Ge=class extends l.Disposable{constructor(r,t,e,n,i){super();re(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=t,this._drawingService=e,this._clipboardInterfaceService=n,this._commandService=i,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,t,e,n)=>{const i=this._focusedDrawings;if(i.length>0){const[s]=i;if(n===R.COPY_TYPE.CUT){const d={unitId:r,drawings:[s]};this._commandService.executeCommand(me.id,d)}setTimeout(()=>{const d=rn();s.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===j.ImageSourceType.BASE64?nn(s.source):this._clipboardInterfaceService.writeText(""),d()},200);const a={unitId:s.unitId,subUnitId:s.subUnitId,drawings:[s]};this._copyInfo=a}else{const s=this._createDrawingsCopyInfoByRange(r,t,e);this._copyInfo=s}},onPasteCells:(r,t,e,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:i=R.COPY_TYPE.COPY,pasteType:s}=n,{range:a}=r||{},{range:d,unitId:g,subUnitId:u}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:s,unitId:g,subUnitId:u,pasteRange:d},{copyRange:a,copyType:i}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:s},R.COPY_TYPE.COPY)},onPastePlainText:(r,t)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:R.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},R.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,t)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:R.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},R.COPY_TYPE.COPY);{const e=t.filter(n=>n.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Re.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,t,e){var p;const n=(p=this._renderManagerService.getRenderById(r))==null?void 0:p.with(R.SheetSkeletonManagerService);if(!n)return;const i=n.attachRangeWithCoord(e);if(!i)return;const{startX:s,endX:a,startY:d,endY:g}=i,u=this._drawingService.getDrawingData(r,t),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const S=u[h],{transform:f}=S;if(S.anchorType!==m.SheetDrawingAnchorType.Both||!f)return;const{left:w=0,top:_=0,width:I=0,height:C=0}=f,{drawingStartX:E,drawingEndX:y,drawingStartY:M,drawingEndY:v}={drawingStartX:w,drawingEndX:w+I,drawingStartY:_,drawingEndY:_+C};s<=E&&y<=a&&d<=M&&v<=g&&c.push(S)}),c.length)return{copyRange:e,drawings:c,unitId:r,subUnitId:t}}_generateSingleDrawingPasteMutations(r,t){const{pasteType:e,pasteTo:n}=r;if(Mt.includes(e))return{redos:[],undos:[]};const{unitId:i,subUnitId:s,range:a}=n,d=this._renderManagerService.getRenderById(i),g=d==null?void 0:d.with(R.SheetSkeletonManagerService),u=d==null?void 0:d.with(R.ISheetSelectionRenderService),c=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:p}=c,h=R.discreteRangeToRange(a);return this._generateMutations(p,{unitId:i,subUnitId:s,isCut:t===R.COPY_TYPE.CUT,getTransform:(S,f)=>{var I;const w=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),_={...S,left:w==null?void 0:w.startX,top:w==null?void 0:w.startY};return{transform:_,sheetTransform:(I=G(_,u))!=null?I:f}}})}_generateMutations(r,t){const{unitId:e,subUnitId:n,getTransform:i,isCut:s}=t,a=[],d=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:c,sheetTransform:p}=u;if(!c)return;const h=i(c,p),S={...u,unitId:e,subUnitId:n,drawingId:s?u.drawingId:l.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform};if(s){const{undo:f,redo:w,objects:_}=g.getBatchUpdateOp([S]);a.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:w,objects:_}}),d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,type:m.DrawingApplyType.UPDATE,op:f,objects:_}})}else{const{undo:f,redo:w,objects:_}=g.getBatchAddOp([S]);a.push({id:m.SetDrawingApplyMutation.id,params:{op:w,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.INSERT}}),d.push({id:m.SetDrawingApplyMutation.id,params:{op:f,unitId:e,subUnitId:n,objects:_,type:m.DrawingApplyType.REMOVE}})}}),{redos:a,undos:d}}_generateRangeDrawingsPasteMutations(r,t){var U;const{unitId:e,subUnitId:n,pasteType:i,pasteRange:s}=r,{copyRange:a,copyType:d}=t;if(Mt.includes(i))return{redos:[],undos:[]};const g=(U=this._renderManagerService.getRenderById(e))==null?void 0:U.with(R.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:n,range:R.discreteRangeToRange(s)},pasteType:i},d);const{ranges:[c,p],mapFunc:h}=R.virtualizeDiscreteRanges([a,s]),{row:S,col:f}=h(c.startRow,c.startColumn),{row:w,col:_}=h(p.startRow,p.startColumn),I=g.attachRangeWithCoord({startRow:S,endRow:S,startColumn:f,endColumn:f}),C=g.attachRangeWithCoord({startRow:w,endRow:w,startColumn:_,endColumn:_});if(!I||!C||!this._copyInfo)return{redos:[],undos:[]};const E=C.startX-I.startX,y=C.startY-I.startY,M=w-S,v=_-f;return this._generateMutations(u,{unitId:e,subUnitId:n,getTransform:(O,k)=>{var W,P;return{transform:{...O,left:((W=O==null?void 0:O.left)!=null?W:0)+E,top:((P=O==null?void 0:O.top)!=null?P:0)+y},sheetTransform:{...k,to:{...k.to,row:k.to.row+M,column:k.to.column+v},from:{...k.from,row:k.from.row+M,column:k.from.column+v}}}},isCut:d===R.COPY_TYPE.CUT})}};Ge=en([be(0,R.ISheetClipboardService),be(1,A.IRenderManagerService),be(2,j.IDrawingManagerService),be(3,B.IClipboardInterfaceService),be(4,l.ICommandService)],Ge);var on=Object.getOwnPropertyDescriptor,sn=(o,r,t,e)=>{for(var n=e>1?void 0:e?on(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},Oe=(o,r)=>(t,e)=>r(t,e,o);let He=class extends l.Disposable{constructor(o,r,t,e,n){super(),this._drawingManagerService=o,this._renderManagerService=r,this._permissionService=t,this._univerInstanceService=e,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([o,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(i=>{if(!i){this._drawingManagerService.setDrawingVisible(!1);return}const s=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new D.WorkbookViewPermission(s).id,new D.WorksheetViewPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,i)})):(this._drawingManagerService.setDrawingVisible(!1),N.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(o,r){this._drawingManagerService.setDrawingVisible(!1);const t=o.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===A.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,t=N.combineLatest([o,r]);this.disposeWithMe(t.pipe(N.switchMap(([e,n])=>e?e.activeSheet$.pipe(N.tap(i=>{if(!i){this._drawingManagerService.setDrawingEditable(!1);return}const s=e.getUnitId(),a=i.getSheetId();this._permissionService.composePermission([new D.WorkbookEditablePermission(s).id,new D.WorksheetEditPermission(s,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,i)})):(this._drawingManagerService.setDrawingEditable(!1),N.EMPTY))).subscribe())}_handleDrawingEditableFalse(o,r){this._drawingManagerService.setDrawingEditable(!1);const t=o.getUnitId(),e=r.getSheetId(),n=this._drawingManagerService.getDrawingData(t,e),i=Object.values(n),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===A.RENDER_CLASS_TYPE.IMAGE&&i.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([o,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const i=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(i),d=a==null?void 0:a.scene;if(!d)return N.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookViewPermission(i).id,new D.WorksheetViewPermission(i,s).id]).pipe(N.map(c=>c.every(p=>p.value)),N.distinctUntilChanged()).pipe(N.map(c=>({permission:c,scene:d,transformer:g,unitId:i,subUnitId:s})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:s})=>{this._drawingManagerService.setDrawingVisible(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(i,s),g=Object.values(d);t?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),e=t==null?void 0:t.getActiveSheet(),n=t==null?void 0:t.getUnitId(),i=e==null?void 0:e.getSheetId();if(!n||!i)return;const s=this._drawingManagerService.getDrawingData(n,i),a=Object.values(s);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const o=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([o,r]).pipe(N.switchMap(([t,e])=>t?t.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const i=t.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(i),d=a==null?void 0:a.scene;if(!d)return N.EMPTY;const g=d.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookEditablePermission(i).id,new D.WorksheetEditPermission(i,s).id]).pipe(N.map(c=>c.every(p=>p.value)),N.distinctUntilChanged()).pipe(N.map(c=>({permission:c,scene:d,transformer:g,unitId:i,subUnitId:s})))})):N.EMPTY)).subscribe({next:({permission:t,scene:e,transformer:n,unitId:i,subUnitId:s})=>{this._drawingManagerService.setDrawingEditable(t);const a=e.getAllObjectsByOrder(),d=this._drawingManagerService.getDrawingData(i,s),g=Object.values(d);t?(a.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(c=>u.oKey.includes(c.drawingId))&&e.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!t)return;const e=t.getUnitId(),n=t.getActiveSheet();if(!n)return;const i=n.getSheetId(),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;const d=this._drawingManagerService.getDrawingData(e,i),g=Object.values(d);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(c=>{c.classType===A.RENDER_CLASS_TYPE.IMAGE&&g.some(p=>c.oKey.includes(p.drawingId))&&a.detachTransformerFrom(c)})}}))}};He=sn([Oe(0,j.IDrawingManagerService),Oe(1,A.IRenderManagerService),Oe(2,l.IPermissionService),Oe(3,l.IUniverInstanceService),Oe(4,l.Inject(l.UserManagerService))],He);var an=Object.getOwnPropertyDescriptor,cn=(o,r,t,e)=>{for(var n=e>1?void 0:e?an(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},ge=(o,r)=>(t,e)=>r(t,e,o);function Rt(o,r,t,e,n,i=!1){const{scaleX:s,scaleY:a}=r.getAncestorScale(),d=r.getViewport(A.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=e.getFreeze(),{startColumn:u,startRow:c,xSplit:p,ySplit:h}=g,S={left:!0,top:!0};if(!d)return{...o,absolute:S};const{left:f,right:w,top:_,bottom:I}=o;let{top:C,left:E,viewportScrollX:y,viewportScrollY:M}=d;const{boundsOfViewArea:v,scrollDirectionResponse:U}=n||{},{rowHeaderWidth:O,columnHeaderHeight:k}=t,W={top:i?0:k,left:i?0:O};v&&(l.Tools.isDefine(W.top)&&(W.top=v.top),l.Tools.isDefine(W.left)&&(W.left=v.left)),U==="HORIZONTAL"&&(M=0),U==="VERTICAL"&&(y=0);let P=0,T=0;const Y=t.rowStartY(c-h)+k,L=t.colStartX(u-p)+O,Z=t.rowStartY(c)+k,ee=t.colStartX(u)+O;if(p===0)S.left=!1,P=(f-y)*s,T=(w-y)*s;else{const K=f-(L-O),F=w-(L-O);w<ee?(P=K*s,T=F*s):f<=ee&&w>=ee?(P=K*s,T=Math.max(E,(w-y)*s)):f>ee&&(S.left=!1,P=Math.max((f-y)*s,E),T=Math.max((w-y)*s,E))}let V=0,z=0;if(h===0)S.top=!1,V=(_-M)*a,z=(I-M)*a;else{const K=_-(Y-k),F=I-(Y-k);I<Z?(V=K*a,z=F*a):_<=Z&&I>=Z?(V=K*a,z=Math.max(C,(I-M)*a)):_>Z&&(S.top=!1,V=Math.max((_-M)*a,C),z=Math.max((I-M)*a,C))}return P=Math.max(P,W.left),V=Math.max(V,W.top),T=Math.max(T,W.left),z=Math.max(z,W.top),{left:P,right:T,top:V,bottom:z,absolute:S}}const oe=(o,r,t,e,n)=>{const{left:i,top:s,width:a,height:d,angle:g}=o,u={left:i,right:i+a,top:s,bottom:s+d},c=Rt(u,r,t,e,n),{scaleX:p,scaleY:h}=r.getAncestorScale();return{startX:c.left,endX:c.right,startY:c.top,endY:c.bottom,rotate:g,width:a*p,height:d*h,absolute:c.absolute}};b.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(t,e,n,i,s,a,d){super();re(this,"_domLayerInfoMap",new Map);re(this,"_transformChange$",new N.Subject);re(this,"transformChange$",this._transformChange$.asObservable());re(this,"_add$",new N.Subject);re(this,"add$",this._add$.asObservable());re(this,"_remove$",new N.Subject);re(this,"remove$",this._remove$.asObservable());this._renderManagerService=t,this._univerInstanceService=e,this._commandService=n,this._drawingManagerService=i,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(N.filter(t=>t===l.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(t){return this._domLayerInfoMap.get(t)}getFloatDomsBySubUnitId(t,e){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===e&&n.unitId===t)}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const e=this._renderManagerService.getRenderById(t),n=e==null?void 0:e.scene;if(e==null||n==null)return null;const i=n.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:n,transformer:i,renderUnit:e,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{t.forEach(e=>{var K;const{unitId:n,subUnitId:i,drawingId:s}=e,a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:i}),d=this._drawingManagerService.getDrawingByParam(e),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!d||!a)return;const c=(K=this._renderManagerService.getRenderById(n))==null?void 0:K.with(R.SheetSkeletonManagerService).getSkeletonParam(i);if(!c)return;const{transform:p,drawingType:h,data:S}=d;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const f=this._getSceneAndTransformerByDrawingSearch(n);if(f==null)return;const{scene:w,canvas:_}=f;if(p==null)return!0;if(u!==i)return;const{left:I,top:C,width:E,height:y,angle:M,flipX:v,flipY:U,skewX:O,skewY:k}=p,W=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:s}),P=w.getObject(W);if(P!=null){P.transformByState({left:I,top:C,width:E,height:y,angle:M,flipX:v,flipY:U,skewX:O,skewY:k});return}const T={left:I,top:C,width:E,height:y,zIndex:this._drawingManagerService.getDrawingOrder(n,i).length-1},Y=h===l.DrawingTypeEnum.DRAWING_CHART;if(T.rotateEnabled=!1,Y){const F=S?S.backgroundColor:"white";T.fill=F,S&&S.border&&(T.stroke=S.border),T.paintFirst="stroke",T.strokeWidth=1,T.borderEnabled=!1,T.radius=8}const L=new A.Rect(W,T);Y&&L.setObjectType(A.ObjectType.CHART),w.addObject(L,A.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&w.attachTransformerTo(L);const Z=new l.DisposableCollection,ee=oe(L,f.renderUnit.scene,c.skeleton,a.worksheet),V=new N.BehaviorSubject(ee),z={dispose:Z,rect:L,position$:V,unitId:n,subUnitId:i,id:s};this._canvasFloatDomService.addFloatDom({position$:V,id:s,componentKey:d.componentKey,onPointerDown:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{_.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{_.dispatchEvent(new WheelEvent(F.type,F))},data:S,unitId:n});const te=L.onTransformChange$.subscribeEvent(()=>{const F=oe(L,f.renderUnit.scene,c.skeleton,a.worksheet);V.next(F)});Z.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),te&&Z.add(te),this._domLayerInfoMap.set(s,z)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{var p;const{unitId:n,subUnitId:i,drawingId:s}=e,a=j.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:i,drawingId:s}),d=this._getSceneAndTransformerByDrawingSearch(n);if(d==null)return;const{transformer:g,scene:u}=d,c=u.getObject(a);c!=null&&c.oKey&&(g.clearControlByIds([c==null?void 0:c.oKey]),(p=u.getTransformer())==null||p.clearSelectedObjects())})}))}_scrollUpdateListener(){const t=(e,n)=>{var g;const i=this._getSceneAndTransformerByDrawingSearch(e),s=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===e).map(u=>u.id),a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:n}),d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(R.SheetSkeletonManagerService).getSkeletonParam(n);!i||!a||!d||s.forEach(u=>{const c=this._domLayerInfoMap.get(u);if(c){const p=oe(c.rect,i.renderUnit.scene,d.skeleton,a.worksheet,c);c.position$.next(p)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(e=>e?e.activeSheet$:N.of(null)),N.map(e=>{if(!e)return null;const n=e.getUnitId(),i=this._renderManagerService.getRenderById(n);return i?{render:i,unitId:n,subUnitId:e.getSheetId()}:null}),N.switchMap(e=>e?l.fromEventSubject(e.render.scene.getViewport(A.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(N.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))):N.of(null))).subscribe(e=>{if(!e)return;const{unitId:n,subUnitId:i}=e;t(n,i)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===R.SetZoomRatioOperation.id){const n=e.params,{unitId:i}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===i).map(a=>a.subUnitId).forEach(a=>{t(i,a)})}else if(e.id===D.SetFrozenMutation.id){const{unitId:n,subUnitId:i}=e.params;t(n,i)}}))}updateFloatDomProps(t,e,n,i){const s=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(t);if(s&&a){const{scene:d}=a,g=j.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:e,drawingId:n}),u=d.getObject(g);u&&u instanceof A.Rect&&u.setProps(i)}}_getPosition(t,e){var h;const{startX:n,endX:i,startY:s,endY:a}=t,d=(h=this._renderManagerService.getRenderById(e))==null?void 0:h.with(R.ISheetSelectionRenderService);if(d==null)return;const g=d.getCellWithCoordByOffset(n,s);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:s-g.startY},c=d.getCellWithCoordByOffset(i,a);if(c==null)return;const p={column:c.actualColumn,columnOffset:i-c.startX,row:c.actualRow,rowOffset:a-c.startY};return{from:u,to:p}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(e=>{const n=this._drawingManagerService.getDrawingByParam(e);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const i={...n.transform};this._transformChange$.next({id:e.drawingId,value:i}),this._canvasFloatDomService.updateFloatDom(e.drawingId,{...n});const s=this._getSceneAndTransformerByDrawingSearch(e.unitId);if(s&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART){const{scene:a}=s,d=this._domLayerInfoMap.get(e.drawingId);d!=null&&d.rect&&(n.allowTransform===!1?a.detachTransformerFrom(d.rect):a.attachTransformerTo(d.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(t,e){const n=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:i,subUnitId:s}=n,{initPosition:a,componentKey:d,data:g,allowTransform:u=!0}=t,c=e!=null?e:l.generateRandomId(),p=this._getPosition(a,i);if(p==null)return;const h={unitId:i,subUnitId:s,drawingId:c,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:p,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},data:g,allowTransform:u};return this._commandService.executeCommand(Te.id,{unitId:i,drawings:[h]}),this._add$.next({unitId:i,subUnitId:s,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(t,e=!1){const n=this._domLayerInfoMap.get(t);if(!n)return;const{unitId:i,subUnitId:s}=n;this._domLayerInfoMap.delete(t),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(i);if(a&&a.scene.removeObject(n.rect),e){const d=this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:s,drawingId:t});if(!d)return;const g=this._sheetDrawingService.getBatchRemoveOp([d]),{redo:u,objects:c}=g;this._commandService.syncExecuteCommand(m.SetDrawingApplyMutation.id,{unitId:i,subUnitId:s,op:u,objects:c,type:m.DrawingApplyType.REMOVE})}}addFloatDomToRange(t,e,n,i){var v,U,O;const s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=s,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(v=this._renderManagerService.getRenderById(a))==null?void 0:v.with(R.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:S=!0}=e,f=i!=null?i:l.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver(t,u,c.skeleton);if(this._getPosition(w,a)==null)return;const C=g.scene,{scaleX:E}=C.getAncestorScale(),y=Xe(w,n,E),M={unitId:a,subUnitId:d,drawingId:f,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:y.startX,top:y.startY,width:y.width,height:y.height},data:h,allowTransform:S};{const{unitId:k,subUnitId:W,drawingId:P}=M,T=D.getSheetCommandTarget(this._univerInstanceService,{unitId:k,subUnitId:W}),Y=M,L=this._univerInstanceService.getUnit(k,l.UniverInstanceType.UNIVER_SHEET);if(!L)return;const Z=L.getActiveSheet().getSheetId();if(!Y||!T)return;const ee=(U=this._renderManagerService.getRenderById(k))==null?void 0:U.with(R.SheetSkeletonManagerService);if(!ee)return;const V=ee.getWorksheetSkeleton(W);if(!V)return;const{transform:z,drawingType:te,data:K}=Y;if(te!==l.DrawingTypeEnum.DRAWING_DOM&&te!==l.DrawingTypeEnum.DRAWING_CHART)return;const F=this._getSceneAndTransformerByDrawingSearch(k);if(F==null)return;const{scene:_e,canvas:ve}=F;if(z==null||Z!==W)return;const{left:xe,top:qe,width:Ze,height:Je,angle:wt,flipX:_t,flipY:Qe,skewX:et,skewY:Ie}=z,tt=j.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),se=_e.getObject(tt);if(se!=null){se.transformByState({left:xe,top:qe,width:Ze,height:Je,angle:wt,flipX:_t,flipY:Qe,skewX:et,skewY:Ie});return}const ne={left:xe,top:qe,width:Ze,height:Je,zIndex:this._drawingManagerService.getDrawingOrder(k,W).length-1},ye=te===l.DrawingTypeEnum.DRAWING_CHART;if(ye){const $=K?K.backgroundColor:"white";ne.fill=$,ne.rotateEnabled=!1,K&&K.border&&(ne.stroke=K.border),ne.paintFirst="stroke",ne.strokeWidth=1,ne.borderEnabled=!1,ne.radius=8}const ae=new A.Rect(tt,ne);ye&&ae.setObjectType(A.ObjectType.CHART),_e.addObject(ae,A.DRAWING_OBJECT_LAYER_INDEX),Y.allowTransform!==!1&&_e.attachTransformerTo(ae);const ce=new l.DisposableCollection,nt=_e.getMainViewport(),{rowHeaderWidth:De,columnHeaderHeight:Ue}=V.skeleton,rt={top:Ue,left:De,bottom:nt.bottom,right:nt.right},de={dispose:ce,rect:ae,boundsOfViewArea:rt,domAnchor:n,unitId:k,subUnitId:W},X=oe(ae,F.renderUnit.scene,V.skeleton,T.worksheet,de),Ce=new N.BehaviorSubject(X);de.position$=Ce;let Ne={position$:Ce,id:P,componentKey:Y.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{ve.dispatchEvent(new WheelEvent($.type,$))},data:K,unitId:k};e.eventPassThrough&&(Ne={...Ne,onPointerDown:$=>{ve.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{ve.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{ve.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(Ne),this.disposeWithMe(_.subscribe($=>{var Ot,At,Pt,Ut;const bt=Xe({startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:(Ot=n.width)!=null?Ot:$.width,height:(At=n.height)!=null?At:$.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Nn=j.getDrawingShapeKeyByDrawingSearch({unitId:k,subUnitId:W,drawingId:P}),kn=new A.Rect(Nn,{left:bt.startX,top:bt.startY,width:(Pt=n.width)!=null?Pt:$.width,height:(Ut=n.height)!=null?Ut:$.height,zIndex:this._drawingManagerService.getDrawingOrder(k,W).length-1}),Wn=oe(kn,F.renderUnit.scene,V.skeleton,T.worksheet,de);Ce.next(Wn)}));const ke=(O=this._renderManagerService.getRenderById(k))==null?void 0:O.with(R.SheetSkeletonManagerService);ke==null||ke.currentSkeleton$.subscribe($=>{$&&V.sheetId!==$.sheetId&&this._removeDom(f,!0)});const it=ae.onTransformChange$.subscribeEvent(()=>{const $=oe(ae,F.renderUnit.scene,V.skeleton,T.worksheet,de);Ce.next($)});ce.add(()=>{this._canvasFloatDomService.removeFloatDom(P)}),it&&ce.add(it),this._domLayerInfoMap.set(P,de)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}addFloatDomToColumnHeader(t,e,n,i){var y,M,v;const s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:d}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const c=(y=this._renderManagerService.getRenderById(a))==null?void 0:y.with(R.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:p,data:h,allowTransform:S=!0}=e,f=i!=null?i:l.generateRandomId(),{position:w,position$:_}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:t,endColumn:t},u,c.skeleton),I=w;if(I.startY=0,this._getPosition(w,a)==null)return;const E={unitId:a,subUnitId:d,drawingId:f,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:p,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:S};{const{unitId:U,subUnitId:O,drawingId:k}=E,W=D.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:O}),P=E,T=this._univerInstanceService.getUnit(U,l.UniverInstanceType.UNIVER_SHEET);if(!T)return;const Y=T.getActiveSheet().getSheetId();if(!P||!W)return;const L=(M=this._renderManagerService.getRenderById(U))==null?void 0:M.with(R.SheetSkeletonManagerService);if(!L)return;const Z=L.getWorksheetSkeleton(O);if(!Z)return;const{transform:ee,data:V}=P,z=this._getSceneAndTransformerByDrawingSearch(U);if(z==null)return;const{scene:te,canvas:K}=z;if(ee==null||Y!==O)return;const{left:F,top:_e,width:ve,height:xe,angle:qe,flipX:Ze,flipY:Je,skewX:wt,skewY:_t}=ee,Qe=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:O,drawingId:k}),et=te.getObject(Qe);if(et!=null){et.transformByState({left:F,top:_e,width:ve,height:xe,angle:qe,flipX:Ze,flipY:Je,skewX:wt,skewY:_t});return}const Ie=Xe({startX:I.startX,startY:0,endX:w.endX,endY:w.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),tt={left:Ie.startX,top:Ie.startY,width:Ie.width,height:Ie.height,zIndex:this._drawingManagerService.getDrawingOrder(U,O).length-1},se=new A.Rect(Qe,tt);te.addObject(se,A.DRAWING_OBJECT_LAYER_INDEX),P.allowTransform!==!1&&te.attachTransformerTo(se);const ne=new l.DisposableCollection,ye=te.getMainViewport(),ae={top:0,left:ye.left,bottom:ye.bottom,right:ye.right},ce={dispose:ne,rect:se,unitId:U,subUnitId:O,boundsOfViewArea:ae,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},nt=oe(se,z.renderUnit.scene,Z.skeleton,W.worksheet,ce),De=new N.BehaviorSubject(nt);ce.position$=De;let Ue={position$:De,id:k,componentKey:P.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:X=>{K.dispatchEvent(new WheelEvent(X.type,X))},data:V,unitId:U};e.eventPassThrough&&(Ue={...Ue,onPointerDown:X=>{K.dispatchEvent(new PointerEvent(X.type,X))},onPointerMove:X=>{K.dispatchEvent(new PointerEvent(X.type,X))},onPointerUp:X=>{K.dispatchEvent(new PointerEvent(X.type,X))}}),this._canvasFloatDomService.addFloatDom(Ue);const rt=se.onTransformChange$.subscribeEvent(()=>{const X=oe(se,z.renderUnit.scene,Z.skeleton,W.worksheet,ce);De.next(X)});this.disposeWithMe(_.subscribe(X=>{const Ce=Xe({startX:X.startX,startY:0,endX:X.endX,endY:X.endY,width:n.width,height:n.height,absolute:{left:w.absolute.left,top:w.absolute.top}},n),Ne=j.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:O,drawingId:k}),ke=new A.Rect(Ne,{left:Ce.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(U,O).length-1}),it=oe(ke,z.renderUnit.scene,Z.skeleton,W.worksheet,ce);De.next(it)}));const de=(v=this._renderManagerService.getRenderById(U))==null?void 0:v.with(R.SheetSkeletonManagerService);de==null||de.currentSkeleton$.subscribe(X=>{X&&c.sheetId!==X.sheetId&&this._removeDom(f,!0)}),ne.add(()=>{this._canvasFloatDomService.removeFloatDom(k)}),rt&&ne.add(rt),this._domLayerInfoMap.set(k,ce)}return{id:f,dispose:()=>{this._removeDom(f,!0)}}}_createRangePositionObserver(t,e,n){let{startRow:i,startColumn:s}=t;const a=Ae(i,s,n),d=new N.BehaviorSubject(a),g=Ae(t.endRow,t.endColumn,n),u=new N.BehaviorSubject(g),c=()=>{const _=Ae(i,s,n),I=Ae(t.endRow,t.endColumn,n);d.next(_),u.next(I)},p=new l.DisposableCollection;p.add(e.engine.clientRect$.subscribe(()=>c())),p.add(this._commandService.onCommandExecuted(_=>{if(_.id===D.SetWorksheetRowAutoHeightMutation.id&&_.params.rowsAutoHeightInfo.findIndex(C=>C.row===i)>-1){c();return}(D.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(_.id)>-1||_.id===R.SetScrollOperation.id||_.id===R.SetZoomRatioOperation.id)&&c()}));const h=(_,I)=>{i=_,s=I,c()},S=()=>({rotate:0,width:g.right-a.left,height:g.bottom-a.top,absolute:{left:!0,top:!0},startX:a.left,startY:a.top,endX:g.right,endY:g.bottom}),f=d.pipe(N.map(_=>{const I=Ae(t.endRow,t.endColumn,n);return{rotate:0,width:I.right-_.left,height:I.bottom-_.top,absolute:{left:!0,top:!0},startX:_.left,startY:_.top,endX:I.right,endY:I.bottom}})),w=S();return{position$:f,position:w,updateRowCol:h,topLeftPos$:d,rightBottomPos$:u,disposable:p}}},b.SheetCanvasFloatDomManagerService=cn([ge(0,l.Inject(A.IRenderManagerService)),ge(1,l.IUniverInstanceService),ge(2,l.Inject(l.ICommandService)),ge(3,j.IDrawingManagerService),ge(4,l.Inject(B.CanvasFloatDomService)),ge(5,m.ISheetDrawingService),ge(6,l.Inject(l.LifecycleService))],b.SheetCanvasFloatDomManagerService);function Ae(o,r,t){const e=t.getCellWithCoordByIndex(o,r),n=e.isMergedMainCell?e.mergeInfo:e;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Xe(o,r,t){var g,u;t=t!=null?t:1;const e=o.endX-o.startX,n=o.endY-o.startY,i=(g=r==null?void 0:r.width)!=null?g:e,s=(u=r==null?void 0:r.height)!=null?u:n;let a=0,d=0;if(r){if(r.horizonOffsetAlign==="right"){const c=Ve(r.marginX,e*t);a=o.endX-c-i}else a=o.startX+Ve(r.marginX,e);if(r.verticalOffsetAlign==="bottom"){const c=Ve(r.marginY,n*t);d=o.endY-c-s}else d=o.startY+Ve(r.marginY,n)}return{rotate:0,startX:a,startY:d,endX:o.endX,endY:o.endY,width:i,height:s,absolute:{left:o.absolute.left,top:o.absolute.top}}}function Ve(o,r){if(o===void 0)return 0;if(typeof o=="number")return o;const t=Number.parseFloat(o);return r*t/100}const dn=o=>{const{floatDomInfos:r,scene:t,skeleton:e,worksheet:n}=o,i=pe.useMemo(()=>r.map(s=>{const{width:a,height:d,angle:g,left:u,top:c}=s.transform,p=Rt({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:c!=null?c:0,bottom:(c!=null?c:0)+(d!=null?d:0)},t,e,n,void 0,!0),{scaleX:h,scaleY:S}=t.getAncestorScale(),f={startX:p.left,endX:p.right,startY:p.top,endY:p.bottom,rotate:g,width:a*h,height:d*S,absolute:p.absolute},w={position$:new N.BehaviorSubject(f),position:f,id:s.drawingId,componentKey:s.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:s.unitId,data:s.data};return[s.drawingId,w]}),[r,t,e,n]);return J.jsx("div",{style:{position:"absolute",top:0,left:0},children:i.map(([s,a])=>J.jsx(B.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};var ln=Object.getOwnPropertyDescriptor,un=(o,r,t,e)=>{for(var n=e>1?void 0:e?ln(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},he=(o,r)=>(t,e)=>r(t,e,o);let Ke=class extends l.Disposable{constructor(o,r,t,e,n,i,s){super(),this._sheetPrintInterceptorService=o,this._drawingRenderService=r,this._drawingManagerService=t,this._renderManagerService=e,this._canvasFloatDomManagerService=n,this._componetManager=i,this._injector=s,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(o,r,t)=>{const{unitId:e,scene:n,subUnitId:i}=r,s=this._drawingManagerService.getDrawingDataForUnit(e),a=s==null?void 0:s[i];return a&&a.order.forEach(d=>{const g=a.data[d];g.drawingType!==l.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),t()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(o,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._renderManagerService.getRenderById(e);if(!i)return t(o);const s=i.with(R.SheetSkeletonManagerService).getSkeletonParam(n);if(!s)return t(o);const a=this._drawingManagerService.getDrawingDataForUnit(e),d=a==null?void 0:a[r.subUnitId];if(!d)return t(o);const{scaleX:g,scaleY:u}=i.scene,c=o?{...o}:{startColumn:0,endColumn:0,endRow:0,startRow:0},p=d.order.map(h=>d.data[h]);return p.length?(p.forEach(h=>{if(!h.groupId&&h.transform&&l.Tools.isDefine(h.transform.left)&&l.Tools.isDefine(h.transform.top)&&l.Tools.isDefine(h.transform.width)&&l.Tools.isDefine(h.transform.height)){const S=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),f=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});S.column<c.startColumn&&(c.startColumn=S.column),S.row<c.startRow&&(c.startRow=S.row),c.endRow<f.row&&(c.endRow=f.row),c.endColumn<f.column&&(c.endColumn=f.column)}}),t(c)):t(o)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(o,r,t)=>{const{unitId:e,subUnitId:n}=r,i=this._drawingManagerService.getDrawingDataForUnit(e),s=i==null?void 0:i[n];if(s){const a=s.order.map(g=>{const u=s.data[g];if(u.drawingType===l.DrawingTypeEnum.DRAWING_CHART)return{...u,componentKey:this._componetManager.get(l.PRINT_CHART_COMPONENT_KEY)};if(u.drawingType===l.DrawingTypeEnum.DRAWING_DOM){const c=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(c||u.componentKey)}}return null}).filter(Boolean),d=B.connectInjector(dn,this._injector);return q.render(J.jsx(d,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),o==null||o.add(()=>{q.unmount(r.root)}),t(o)}}}))}};Ke=un([he(0,l.Inject(R.SheetPrintInterceptorService)),he(1,l.Inject(le.DrawingRenderService)),he(2,j.IDrawingManagerService),he(3,A.IRenderManagerService),he(4,l.Inject(b.SheetCanvasFloatDomManagerService)),he(5,l.Inject(B.ComponentManager)),he(6,l.Inject(l.Injector))],Ke);var gn=Object.getOwnPropertyDescriptor,hn=(o,r,t,e)=>{for(var n=e>1?void 0:e?gn(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},ue=(o,r)=>(t,e)=>r(t,e,o);const pn=[D.InsertRowCommand.id,D.InsertColCommand.id,D.RemoveRowCommand.id,D.RemoveColCommand.id,D.DeleteRangeMoveLeftCommand.id,D.DeleteRangeMoveUpCommand.id,D.InsertRangeMoveDownCommand.id,D.InsertRangeMoveRightCommand.id,D.DeltaRowHeightCommand.id,D.SetRowHeightCommand.id,D.DeltaColumnWidthCommand.id,D.SetColWidthCommand.id,D.SetRowHiddenCommand.id,D.SetSpecificRowsVisibleCommand.id,D.SetSpecificColsVisibleCommand.id,D.SetColHiddenCommand.id,D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id],mn=[D.SetRowVisibleMutation.id,D.SetRowHiddenMutation.id,D.SetColVisibleMutation.id,D.SetColHiddenMutation.id,D.SetWorksheetRowHeightMutation.id,D.SetWorksheetColWidthMutation.id];let mt=class extends l.Disposable{constructor(o,r,t,e,n,i,s,a,d){super(),this._context=o,this._renderManagerService=r,this._commandService=t,this._selectionRenderService=e,this._skeletonManagerService=n,this._sheetInterceptorService=i,this._sheetDrawingService=s,this._drawingManagerService=a,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({getMutations:o=>{if(!pn.includes(o.id))return{redos:[],undos:[]};if(o.params==null)return{redos:[],undos:[]};const r=o.id;if(r===D.InsertRowCommand.id)return this._moveRowInterceptor(o.params,"insert");if([D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(o.params);if(r===D.InsertColCommand.id)return this._moveColInterceptor(o.params,"insert");if(r===D.RemoveRowCommand.id)return this._moveRowInterceptor(o.params,"remove");if(r===D.RemoveColCommand.id)return this._moveColInterceptor(o.params,"remove");if(r===D.DeleteRangeMoveLeftCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,0)}else if(r===D.DeleteRangeMoveUpCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,1)}else if(r===D.InsertRangeMoveDownCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,2)}else if(r===D.InsertRangeMoveRightCommand.id){const{range:t}=o.params;return this._getRangeMoveUndo(t,3)}else if(r===D.SetRowHiddenCommand.id||r===D.SetSpecificRowsVisibleCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForRowVisible(e,n,i)}else if(r===D.SetSpecificColsVisibleCommand.id||r===D.SetColHiddenCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t;return this._getDrawingUndoForColVisible(e,n,i)}else if(r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id||r===D.DeltaColumnWidthCommand.id||r===D.SetColWidthCommand.id){const t=o.params,{unitId:e,subUnitId:n,ranges:i}=t,s=r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,n,i,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(o,r){const t=D.getSheetCommandTarget(this._univerInstanceService);if(t==null)return{redos:[],undos:[]};const e=t.unitId,n=t.subUnitId,i=[],s=[],a=this._sheetDrawingService.getDrawingData(e,n),d=[],g=[];if(Object.keys(a).forEach(u=>{const c=a[u],{updateDrawings:p,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(o,r,c);d.push(...p),g.push(...h)}),d.length===0&&g.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:p,objects:h}=u;i.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.UPDATE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),c=u.undo,p=u.redo,h=u.objects;i.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:p,objects:h,type:m.DrawingApplyType.REMOVE}}),s.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:c,objects:h,type:m.DrawingApplyType.INSERT}})}return i.push({id:H.id,params:[e]}),s.push({id:H.id,params:[e]}),{redos:i,undos:s}}_getUpdateOrDeleteDrawings(o,r,t){const e=[],n=[],{sheetTransform:i,anchorType:s=m.SheetDrawingAnchorType.Position,transform:a,unitId:d,subUnitId:g,drawingId:u}=t,{from:c,to:p}=i,{row:h,column:S}=c,{row:f,column:w}=p;if(i==null||a==null)return{updateDrawings:e,deleteDrawings:n};const{startRow:_,endRow:I,startColumn:C,endColumn:E}=o;let y=null,M=null;if(r===0&&h>=_&&f<=I)if(S>=C&&w<=E)n.push({unitId:d,subUnitId:g,drawingId:u});else{const v=this._shrinkCol(i,a,C,E,s);y=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(r===1&&S>=C&&w<=E)if(h>=_&&f<=I)n.push({unitId:d,subUnitId:g,drawingId:u});else{const v=this._shrinkRow(i,a,_,I,s);y=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(r===2){const v=this._expandRow(i,a,_,I,s);y=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(r===3){const v=this._expandCol(i,a,C,E,s);y=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}if(y!=null&&M!=null){const v=x(y,this._selectionRenderService,this._skeletonManagerService);e.push({...t,sheetTransform:y,transform:v})}return{updateDrawings:e,deleteDrawings:n}}_remainDrawingSize(o,r,t){const e=G({...o},this._selectionRenderService);e!=null&&r.push({...t,sheetTransform:e})}_getDrawingUndoForColVisible(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:S=m.SheetDrawingAnchorType.Position}=c;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:f,to:w}=p,{row:_,column:I}=f,{row:C,column:E}=w;for(let y=0;y<t.length;y++){const M=t[y],{startRow:v,endRow:U,startColumn:O,endColumn:k}=M;if(E<O)continue;if(S===m.SheetDrawingAnchorType.Position){let T=null,Y=null;if(I>=O&&I<=k){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:k,startRow:f.row,endRow:w.row});if(L==null)return;Y={...h,left:L.startX}}if(Y!=null&&(T=G(Y,this._selectionRenderService),T!=null&&Y!=null)){n.push({...c,sheetTransform:T,transform:Y});break}this._remainDrawingSize(h,n,c);continue}if(I>=O&&E<=k)continue;let W=null,P=null;if(I>=O&&I<=k){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:k,startRow:f.row,endRow:w.row});if(T==null)return;P={...h,left:(T==null?void 0:T.startX)||0,width:((h==null?void 0:h.width)||0)-T.endX+T.startX}}else if(E>=O&&E<=k){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:E,startRow:f.row,endRow:w.row});if(T==null)return;P={...h,left:T.startX-((h==null?void 0:h.width)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:k,startRow:f.row,endRow:w.row});if(T==null)return;if(P={...h,width:((h==null?void 0:h.width)||0)-T.endX+T.startX},W=G(P,this._selectionRenderService),W!=null&&P!=null){i.push({...c,sheetTransform:W,transform:P});break}}if(P!=null&&(W=G(P,this._selectionRenderService)),P!=null&&W!=null){n.push({...c,sheetTransform:W,transform:P});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&i.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(o,r,n),d=[],g=[];if(i.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(o,r,i);d.push(...u),g.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:g}}_createUndoAndRedoMutation(o,r,t){const e=this._sheetDrawingService.getBatchUpdateOp(t),{undo:n,redo:i,objects:s}=e,a=[{id:m.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:r,op:i,objects:s,type:m.DrawingApplyType.UPDATE}},{id:H.id,params:[o]}],d=[{id:m.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:r,op:n,objects:s,type:m.DrawingApplyType.UPDATE}},{id:H.id,params:[o]}];return{redos:a,undos:d}}_getDrawingUndoForRowVisible(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[],i=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:p,transform:h,anchorType:S=m.SheetDrawingAnchorType.Position}=c;if(S===m.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,c);else{const{from:f,to:w}=p,{row:_,column:I}=f,{row:C,column:E}=w;for(let y=0;y<t.length;y++){const M=t[y],{startRow:v,endRow:U,startColumn:O,endColumn:k}=M;if(C<v)continue;if(S===m.SheetDrawingAnchorType.Position){let T=null,Y=null;if(_>=v&&_<=U){const L=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:U});if(L==null)return;Y={...h,top:L.startY}}if(Y!=null&&(T=G(Y,this._selectionRenderService),T!=null&&Y!=null)){n.push({...c,sheetTransform:T,transform:Y});break}this._remainDrawingSize(h,n,c);continue}if(_>=v&&C<=U)continue;let W=null,P=null;if(_>=v&&_<=U){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:_,endRow:U});if(T==null)return;P={...h,top:(T==null?void 0:T.startY)||0,height:((h==null?void 0:h.height)||0)-T.endY+T.startY}}else if(C>=v&&C<=U){const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:v,endRow:C});if(T==null)return;P={...h,top:T.startY-((h==null?void 0:h.height)||0)}}else{const T=this._skeletonManagerService.attachRangeWithCoord({startColumn:f.column,endColumn:w.column,startRow:v,endRow:U});if(T==null)return;if(P={...h,height:((h==null?void 0:h.height)||0)-T.endY+T.startY},W=G(P,this._selectionRenderService),W!=null&&P!=null){i.push({...c,sheetTransform:W,transform:P});break}}if(P!=null&&(W=G(P,this._selectionRenderService)),P!=null&&W!=null){n.push({...c,sheetTransform:W,transform:P});break}else this._remainDrawingSize(h,n,c)}}}),n.length===0&&i.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(o,r,n),d=[],g=[];if(i.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(o,r,i);d.push(...u),g.push(...c)}return{redos:s,undos:a,preRedos:d,preUndos:g}}_getDrawingUndoForRowAndColSize(o,r,t,e){const n=this._drawingManagerService.getDrawingData(o,r),i=[];return Object.keys(n).forEach(s=>{const a=n[s],{sheetTransform:d,transform:g,anchorType:u=m.SheetDrawingAnchorType.Position}=a;if(u===m.SheetDrawingAnchorType.None)this._remainDrawingSize(g,i,a);else{const{from:c,to:p}=d,{row:h,column:S}=c,{row:f,column:w}=p;for(let _=0;_<t.length;_++){const I=t[_],{startRow:C,endRow:E,startColumn:y,endColumn:M}=I;if(f<C||w<y)continue;if(u===m.SheetDrawingAnchorType.Position&&(h<=C&&f>=E||S<=y&&w>=M)){this._remainDrawingSize(g,i,a);continue}const v=x({...d},this._selectionRenderService,this._skeletonManagerService);if(v!=null){i.push({...a,transform:v});break}}}}),i.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(o,r,i)}_getUnitIdAndSubUnitId(o,r){let t,e;if(r==="insert")t=o.unitId,e=o.subUnitId;else{const n=D.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;t=n.unitId,e=n.subUnitId}return{unitId:t,subUnitId:e}}_moveRangeInterceptor(o){var C,E;const{toRange:r,fromRange:t}=o,e=D.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:n,subUnitId:i}=e,s=(E=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.with(R.SheetSkeletonManagerService))==null?void 0:E.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=R.attachRangeWithCoord(s,t);if(!a)return{redos:[],undos:[]};const{startX:d,endX:g,startY:u,endY:c}=a,p=this._sheetDrawingService.getDrawingData(n,i),h=[];Object.keys(p).forEach(y=>{const M=p[y];if(M.anchorType!==m.SheetDrawingAnchorType.Both)return;const{transform:v}=M;if(!v)return;const{left:U=0,top:O=0,width:k=0,height:W=0}=v,{drawingStartX:P,drawingEndX:T,drawingStartY:Y,drawingEndY:L}={drawingStartX:U,drawingEndX:U+k,drawingStartY:O,drawingEndY:O+W};d<=P&&T<=g&&u<=Y&&L<=c&&h.push(M)});const S=[],f=[],w=r.startRow-t.startRow,_=r.startColumn-t.startColumn,I=h.map(y=>{const M=y.sheetTransform,v={to:{...M.to,row:M.to.row+w,column:M.to.column+_},from:{...M.from,row:M.from.row+w,column:M.from.column+_}},U=x(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:i,drawingId:y.drawingId,transform:U,sheetTransform:v}});if(I.length){const y=this._sheetDrawingService.getBatchUpdateOp(I),{undo:M,redo:v,objects:U}=y;S.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:v,objects:U,type:m.DrawingApplyType.UPDATE}}),f.push({id:m.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:i,op:M,objects:U,type:m.DrawingApplyType.UPDATE}})}return{redos:S,undos:f}}_moveRowInterceptor(o,r){const t=this._getUnitIdAndSubUnitId(o,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=o,s=i.startRow,a=i.endRow,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const S=u[h],{sheetTransform:f,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let I,C;if(r==="insert"){const y=this._expandRow(f,w,s,a,_);I=y==null?void 0:y.newSheetTransform,C=y==null?void 0:y.newTransform}else{const{from:y,to:M}=f,{row:v}=y,{row:U}=M;if(_===m.SheetDrawingAnchorType.Both&&v>=s&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const O=this._shrinkRow(f,w,s,a,_);I=O==null?void 0:O.newSheetTransform,C=O==null?void 0:O.newTransform}}if(!I||!C)return;const E={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};c.push(E)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:S,redo:f,objects:w}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),S=h.undo,f=h.redo,w=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.INSERT}})}return d.push({id:H.id,params:[e]}),g.push({id:H.id,params:[e]}),{redos:d,undos:g}}_moveColInterceptor(o,r){const t=this._getUnitIdAndSubUnitId(o,r);if(t==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:n}=t,{range:i}=o,s=i.startColumn,a=i.endColumn,d=[],g=[],u=this._sheetDrawingService.getDrawingData(e,n),c=[],p=[];if(Object.keys(u).forEach(h=>{const S=u[h],{sheetTransform:f,transform:w,anchorType:_=m.SheetDrawingAnchorType.Position}=S;if(f==null||w==null)return;let I,C;if(r==="insert"){const y=this._expandCol(f,w,s,a,_);I=y==null?void 0:y.newSheetTransform,C=y==null?void 0:y.newTransform}else{const{from:y,to:M}=f,{column:v}=y,{column:U}=M;if(_===m.SheetDrawingAnchorType.Both&&v>=s&&U<=a)p.push({unitId:e,subUnitId:n,drawingId:h});else{const O=this._shrinkCol(f,w,s,a,_);I=O==null?void 0:O.newSheetTransform,C=O==null?void 0:O.newTransform}}if(!I||!C)return;const E={unitId:e,subUnitId:n,drawingId:h,transform:C,sheetTransform:I};c.push(E)}),c.length===0&&p.length===0)return{redos:[],undos:[]};if(c.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(c),{undo:S,redo:f,objects:w}=h;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.UPDATE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.UPDATE}})}if(p.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(p),S=h.undo,f=h.redo,w=h.objects;d.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:f,objects:w,type:m.DrawingApplyType.REMOVE}}),g.push({id:m.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:n,op:S,objects:w,type:m.DrawingApplyType.INSERT}})}return d.push({id:H.id,params:[e]}),g.push({id:H.id,params:[e]}),{redos:d,undos:g}}_expandCol(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{column:d}=s,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:e,startRow:s.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)+p.endX-p.startX},u=G(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g+i}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{column:d}=s,{column:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...s,column:d-i},to:{...a,column:g-i}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g-i}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,left:(r.left||0)-o.from.columnOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t,endColumn:d-1,startRow:s.row,endRow:a.row});if(p==null)return;c={...r,left:(r.left||0)-p.endX+p.startX-o.from.columnOffset}}u=G(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:t-1,endColumn:t-1,startRow:s.row,endRow:a.row});if(p==null)return;u={from:{...s},to:{...a,column:t-1,columnOffset:p.endX-p.startX}},c=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{row:d}=s,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>=t){const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:e,startColumn:s.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)+p.endY-p.startY},u=G(c,this._selectionRenderService)}else if(g>=e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g+i}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(o,r,t,e,n=m.SheetDrawingAnchorType.Position){const i=e-t+1,{from:s,to:a}=o,{row:d}=s,{row:g}=a;if(n===m.SheetDrawingAnchorType.None)return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(d>e)u={from:{...s,row:d-i},to:{...a,row:g-i}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=t&&g<=e)return null;if(d<t&&g>e)if(n===m.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g-i}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:G({...r},this._selectionRenderService),newTransform:r};else if(d>=t&&d<=e){if(d===t)c={...r,top:(r.top||0)-o.from.rowOffset};else{const p=this._skeletonManagerService.attachRangeWithCoord({startRow:t,endRow:d-1,startColumn:s.column,endColumn:a.column});if(p==null)return;c={...r,top:(r.top||0)-p.endY+p.startY-o.from.rowOffset}}u=G(c,this._selectionRenderService)}else if(g>=t&&g<=e&&n===m.SheetDrawingAnchorType.Both){const p=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:t-1,endRow:t-1});if(p==null)return;u={from:{...s},to:{...a,row:t-1,rowOffset:p.endY-p.startY}},c=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{if(o.id===D.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:t}=o.params;this._updateDrawings(r,t)}})),this.disposeWithMe(this._context.activated$.subscribe(o=>{const{unit:r,unitId:t}=this._context;if(o){const e=r.getActiveSheet().getSheetId();this._updateDrawings(t,e)}else this._clearDrawings(t)}))}_clearDrawings(o){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,t=[];Object.keys(r).forEach(e=>{const n=r[e];n!=null&&Object.keys(n).forEach(i=>{const s=n[i].data;s!=null&&Object.keys(s).forEach(a=>{e===o&&t.push(s[a])})})}),this._drawingManagerService.removeNotification(t)})}_updateDrawings(o,r){setTimeout(()=>{const t=this._drawingManagerService.drawingManagerData,e=[],n=[];Object.keys(t).forEach(i=>{const s=t[i];s!=null&&Object.keys(s).forEach(a=>{const d=s[a].data;d!=null&&Object.keys(d).forEach(g=>{if(i===o&&a===r){const u=d[g];u.transform=x(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),e.push(d[g])}else n.push(d[g])})})}),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(e)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(o=>{mn.includes(o.id)&&requestIdleCallback(()=>{const r=o.params,{unitId:t,subUnitId:e,ranges:n}=r;this._refreshDrawingTransform(t,e,n)})}))}_refreshDrawingTransform(o,r,t){const e=this._drawingManagerService.getDrawingData(o,r),n=[];Object.keys(e).forEach(i=>{const s=e[i],{sheetTransform:a,transform:d,anchorType:g=m.SheetDrawingAnchorType.Position}=s;if(g===m.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=a,{row:p,column:h}=u,{row:S,column:f}=c;for(let w=0;w<t.length;w++){const _=t[w],{startRow:I,endRow:C,startColumn:E,endColumn:y}=_;if(l.Rectangle.intersects({startRow:I,endRow:C,startColumn:E,endColumn:y},{startRow:p,endRow:S,startColumn:h,endColumn:f})||p>C||h>y){const M=g===m.SheetDrawingAnchorType.Position,v=x(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...v,width:M?d==null?void 0:d.width:v==null?void 0:v.width,height:M?d==null?void 0:d.height:v==null?void 0:v.height}});break}}}),n.length!==0&&(this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(H.id,[o]))}};mt=hn([ue(1,A.IRenderManagerService),ue(2,l.ICommandService),ue(3,R.ISheetSelectionRenderService),ue(4,l.Inject(R.SheetSkeletonManagerService)),ue(5,l.Inject(D.SheetInterceptorService)),ue(6,m.ISheetDrawingService),ue(7,j.IDrawingManagerService),ue(8,l.IUniverInstanceService)],mt);const fn=o=>{var I;const r=B.useDependency(l.ICommandService),t=B.useDependency(l.LocaleService),e=B.useDependency(j.IDrawingManagerService),n=B.useDependency(A.IRenderManagerService),{drawings:i}=o,s=i[0];if(s==null)return;const{unitId:a}=s,d=n.getRenderById(a),g=d==null?void 0:d.scene;if(g==null)return;const u=g.getTransformerByCreate(),[c,p]=pe.useState(!0),h=(I=s.anchorType)!=null?I:m.SheetDrawingAnchorType.Position,[S,f]=pe.useState(h);function w(C,E){const y=[];return C.forEach(M=>{const{oKey:v}=M,U=E.getDrawingOKey(v);if(U==null)return y.push(null),!0;const{unitId:O,subUnitId:k,drawingId:W,drawingType:P,anchorType:T,sheetTransform:Y}=U;y.push({unitId:O,subUnitId:k,drawingId:W,anchorType:T,sheetTransform:Y,drawingType:P})}),y}pe.useEffect(()=>{const C=u.clearControl$.subscribe(y=>{y===!0&&p(!1)}),E=u.changeStart$.subscribe(y=>{var U;const{objects:M}=y,v=w(M,e);if(v.length===0)p(!1);else if(v.length>=1){p(!0);const O=((U=v[0])==null?void 0:U.anchorType)||m.SheetDrawingAnchorType.Position;f(O)}});return()=>{E.unsubscribe(),C.unsubscribe()}},[]);function _(C){f(C);const E=e.getFocusDrawings();if(E.length===0)return;const y=E.map(M=>({unitId:M.unitId,subUnitId:M.subUnitId,drawingId:M.drawingId,anchorType:C}));r.executeCommand(Me.id,{unitId:E[0].unitId,drawings:y})}return J.jsxs("div",{className:q.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!c}),children:[J.jsx("header",{className:"univer-text-gray-600 dark:!univer-text-gray-200",children:J.jsx("div",{children:t.t("drawing-anchor.title")})}),J.jsx("div",{children:J.jsxs(q.RadioGroup,{value:S,onChange:_,direction:"vertical",children:[J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Both,children:t.t("drawing-anchor.both")}),J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.Position,children:t.t("drawing-anchor.position")}),J.jsx(q.Radio,{value:m.SheetDrawingAnchorType.None,children:t.t("drawing-anchor.none")})]})})]})},Sn=()=>{const o=B.useDependency(j.IDrawingManagerService),r=o.getFocusDrawings(),[t,e]=pe.useState(r);return pe.useEffect(()=>{const n=o.focus$.subscribe(i=>{e(i)});return()=>{n.unsubscribe()}},[]),!!(t!=null&&t.length)&&J.jsxs("div",{className:"univer-text-sm",children:[J.jsx(le.DrawingCommonPanel,{drawings:t}),J.jsx(fn,{drawings:t})]})},ft="sheet.menu.image";function wn(o){return{id:ft,type:B.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:B.getMenuHiddenObservable(o,l.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(o,{workbookTypes:[D.WorkbookEditablePermission],worksheetTypes:[D.WorksheetEditPermission],rangeTypes:[D.RangeProtectionPermissionEditPoint]})}}function _n(o){return{id:Re.id,title:"sheetImage.upload.float",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(o,l.UniverInstanceType.UNIVER_SHEET)}}function vn(o){return{id:lt.id,title:"sheetImage.upload.cell",type:B.MenuItemType.BUTTON,hidden$:B.getMenuHiddenObservable(o,l.UniverInstanceType.UNIVER_SHEET)}}const In={[B.RibbonInsertGroup.MEDIA]:{[ft]:{order:0,menuItemFactory:wn,[Re.id]:{order:0,menuItemFactory:_n},[lt.id]:{order:1,menuItemFactory:vn}}}};function Pe(o){return!o.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!o.getContextValue(l.EDITOR_ACTIVATED)&&!o.getContextValue(l.FOCUSING_PANEL_EDITOR)&&o.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const yn={id:fe.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:B.KeyCode.ARROW_DOWN,priority:100,preconditions:Pe,staticParameters:{direction:l.Direction.DOWN}},Dn={id:fe.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:B.KeyCode.ARROW_UP,priority:100,preconditions:Pe,staticParameters:{direction:l.Direction.UP}},Cn={id:fe.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:B.KeyCode.ARROW_LEFT,priority:100,preconditions:Pe,staticParameters:{direction:l.Direction.LEFT}},Tn={id:fe.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:B.KeyCode.ARROW_RIGHT,priority:100,preconditions:Pe,staticParameters:{direction:l.Direction.RIGHT}},Mn={id:ot.id,description:"shortcut.drawing-delete",group:"4_drawing-view",preconditions:Pe,binding:B.KeyCode.DELETE,mac:B.KeyCode.BACKSPACE};var Rn=Object.getOwnPropertyDescriptor,En=(o,r,t,e)=>{for(var n=e>1?void 0:e?Rn(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},we=(o,r)=>(t,e)=>r(t,e,o);let ze=class extends l.Disposable{constructor(o,r,t,e,n,i){super(),this._componentManager=o,this._menuManagerService=r,this._commandService=t,this._shortcutService=e,this._drawingManagerService=n,this._sheetsSelectionsService=i,this._init()}_initCustomComponents(){const o=this._componentManager;this.disposeWithMe(o.register(It,Sn))}_initMenus(){this._menuManagerService.mergeMenu(In)}_initCommands(){[Re,lt,Te,me,Me,ut,H,gt,st,ct,fe,ot,at].forEach(o=>this.disposeWithMe(this._commandService.registerCommand(o)))}_initShortcuts(){[yn,Dn,Cn,Tn,Mn].forEach(o=>{this.disposeWithMe(this._shortcutService.registerShortcut(o))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};ze=En([we(0,l.Inject(B.ComponentManager)),we(1,B.IMenuManagerService),we(2,l.ICommandService),we(3,B.IShortcutService),we(4,j.IDrawingManagerService),we(5,l.Inject(D.SheetsSelectionsService))],ze);var bn=Object.defineProperty,On=Object.getOwnPropertyDescriptor,An=(o,r,t)=>r in o?bn(o,r,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[r]=t,Pn=(o,r,t,e)=>{for(var n=e>1?void 0:e?On(r,t):r,i=o.length-1,s;i>=0;i--)(s=o[i])&&(n=s(n)||n);return n},St=(o,r)=>(t,e)=>r(t,e,o),Et=(o,r,t)=>An(o,typeof r!="symbol"?r+"":r,t);const Un="SHEET_IMAGE_UI_PLUGIN";b.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=yt,t,e,n){super(),this._config=r,this._injector=t,this._renderManagerService=e,this._configService=n;const{menu:i,...s}=l.merge({},yt,this._config);i&&this._configService.setConfig("menu",i,{merge:!0}),this._configService.setConfig(Yt,s)}onStarting(){l.registerDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService],[ze],[je],[Ke],[He],[Ge],[Fe],[$e],[Le]]),l.touchDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[Ge],[Le]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[He],[Ke],[ze],[Fe],[$e]])}onSteady(){this._injector.get(je)}_registerRenderModules(){[[b.SheetDrawingUpdateController],[mt],[pt],[ht]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}},Et(b.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),Et(b.UniverSheetsDrawingUIPlugin,"pluginName",Un),b.UniverSheetsDrawingUIPlugin=Pn([l.DependentOn(j.UniverDrawingPlugin,vt.UniverDocsDrawingPlugin,le.UniverDrawingUIPlugin,m.UniverSheetsDrawingPlugin),St(1,l.Inject(l.Injector)),St(2,A.IRenderManagerService),St(3,l.IConfigService)],b.UniverSheetsDrawingUIPlugin),b.ClearSheetDrawingTransformerOperation=H,b.DeleteDrawingsCommand=ot,b.EditSheetDrawingOperation=gt,b.GroupSheetDrawingCommand=st,b.InsertFloatImageCommand=Re,b.InsertSheetDrawingCommand=Te,b.MoveDrawingsCommand=fe,b.RemoveSheetDrawingCommand=me,b.SHEETS_IMAGE_MENU_ID=ft,b.SetDrawingArrangeCommand=at,b.SetSheetDrawingCommand=Me,b.SidebarSheetDrawingOperation=ut,b.UngroupSheetDrawingCommand=ct,b.calcSheetFloatDomPosition=oe,b.drawingPositionToTransform=x,b.transformToDrawingPosition=G,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-drawing-ui",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.8-nightly.202509200616",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -62,17 +62,17 @@
|
|
|
62
62
|
"rxjs": ">=7.0.0"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@univerjs/core": "0.10.
|
|
66
|
-
"@univerjs/design": "0.10.
|
|
67
|
-
"@univerjs/drawing": "0.10.
|
|
68
|
-
"@univerjs/docs-
|
|
69
|
-
"@univerjs/drawing
|
|
70
|
-
"@univerjs/
|
|
71
|
-
"@univerjs/
|
|
72
|
-
"@univerjs/
|
|
73
|
-
"@univerjs/sheets-
|
|
74
|
-
"@univerjs/ui": "0.10.
|
|
75
|
-
"@univerjs/
|
|
65
|
+
"@univerjs/core": "0.10.8-nightly.202509200616",
|
|
66
|
+
"@univerjs/design": "0.10.8-nightly.202509200616",
|
|
67
|
+
"@univerjs/docs-drawing": "0.10.8-nightly.202509200616",
|
|
68
|
+
"@univerjs/docs-ui": "0.10.8-nightly.202509200616",
|
|
69
|
+
"@univerjs/drawing": "0.10.8-nightly.202509200616",
|
|
70
|
+
"@univerjs/drawing-ui": "0.10.8-nightly.202509200616",
|
|
71
|
+
"@univerjs/sheets": "0.10.8-nightly.202509200616",
|
|
72
|
+
"@univerjs/engine-render": "0.10.8-nightly.202509200616",
|
|
73
|
+
"@univerjs/sheets-drawing": "0.10.8-nightly.202509200616",
|
|
74
|
+
"@univerjs/sheets-ui": "0.10.8-nightly.202509200616",
|
|
75
|
+
"@univerjs/ui": "0.10.8-nightly.202509200616"
|
|
76
76
|
},
|
|
77
77
|
"devDependencies": {
|
|
78
78
|
"postcss": "^8.5.6",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"typescript": "^5.9.2",
|
|
83
83
|
"vite": "^7.1.4",
|
|
84
84
|
"vitest": "^3.2.4",
|
|
85
|
-
"@univerjs-infra/shared": "0.10.
|
|
85
|
+
"@univerjs-infra/shared": "0.10.8"
|
|
86
86
|
},
|
|
87
87
|
"scripts": {
|
|
88
88
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|