@univerjs/sheets-drawing-ui 0.15.5 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/cjs/locale/ca-ES.js +1 -1
- package/lib/cjs/locale/en-US.js +1 -1
- package/lib/cjs/locale/es-ES.js +1 -1
- package/lib/cjs/locale/fa-IR.js +1 -1
- package/lib/cjs/locale/fr-FR.js +1 -1
- package/lib/cjs/locale/ja-JP.js +1 -1
- package/lib/cjs/locale/ko-KR.js +1 -1
- package/lib/cjs/locale/ru-RU.js +1 -1
- package/lib/cjs/locale/sk-SK.js +1 -1
- package/lib/cjs/locale/vi-VN.js +1 -1
- package/lib/cjs/locale/zh-CN.js +1 -1
- package/lib/cjs/locale/zh-TW.js +1 -1
- package/lib/es/index.js +1420 -1331
- package/lib/es/locale/ca-ES.js +3 -1
- package/lib/es/locale/en-US.js +3 -1
- package/lib/es/locale/es-ES.js +3 -1
- package/lib/es/locale/fa-IR.js +3 -1
- package/lib/es/locale/fr-FR.js +3 -1
- package/lib/es/locale/ja-JP.js +3 -1
- package/lib/es/locale/ko-KR.js +3 -1
- package/lib/es/locale/ru-RU.js +3 -1
- package/lib/es/locale/sk-SK.js +3 -1
- package/lib/es/locale/vi-VN.js +5 -3
- package/lib/es/locale/zh-CN.js +3 -1
- package/lib/es/locale/zh-TW.js +3 -1
- package/lib/index.js +1420 -1331
- package/lib/locale/ca-ES.js +3 -1
- package/lib/locale/en-US.js +3 -1
- package/lib/locale/es-ES.js +3 -1
- package/lib/locale/fa-IR.js +3 -1
- package/lib/locale/fr-FR.js +3 -1
- package/lib/locale/ja-JP.js +3 -1
- package/lib/locale/ko-KR.js +3 -1
- package/lib/locale/ru-RU.js +3 -1
- package/lib/locale/sk-SK.js +3 -1
- package/lib/locale/vi-VN.js +5 -3
- package/lib/locale/zh-CN.js +3 -1
- package/lib/locale/zh-TW.js +3 -1
- package/lib/types/commands/commands/flip-drawings.command.d.ts +17 -0
- package/lib/types/locale/en-US.d.ts +2 -0
- package/lib/umd/index.js +2 -2
- package/lib/umd/locale/ca-ES.js +1 -1
- package/lib/umd/locale/en-US.js +1 -1
- package/lib/umd/locale/es-ES.js +1 -1
- package/lib/umd/locale/fa-IR.js +1 -1
- package/lib/umd/locale/fr-FR.js +1 -1
- package/lib/umd/locale/ja-JP.js +1 -1
- package/lib/umd/locale/ko-KR.js +1 -1
- package/lib/umd/locale/ru-RU.js +1 -1
- package/lib/umd/locale/sk-SK.js +1 -1
- package/lib/umd/locale/vi-VN.js +1 -1
- package/lib/umd/locale/zh-CN.js +1 -1
- package/lib/umd/locale/zh-TW.js +1 -1
- package/package.json +13 -13
package/lib/cjs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var Zt=Object.defineProperty;var Jt=(i,r,e)=>r in i?Zt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e;var ie=(i,r,e)=>Jt(i,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("@univerjs/engine-render"),A=require("@univerjs/sheets-ui"),l=require("@univerjs/core"),w=require("@univerjs/sheets-drawing"),D=require("@univerjs/sheets"),G=require("@univerjs/design"),et=require("@univerjs/docs-ui"),x=require("@univerjs/drawing"),j=require("@univerjs/ui"),Ft=require("@univerjs/docs-drawing"),me=require("@univerjs/drawing-ui"),N=require("rxjs"),L=require("react/jsx-runtime"),Z=require("react");function Q(i,r,e){const{from:t,to:n,flipY:s=!1,flipX:o=!1,angle:a=0,skewX:c=0,skewY:g=0}=i,u=e.getCurrent();if(u==null)return;const d=A.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:t,to:n},e);let{left:m,top:h,width:p,height:S}=d;const f=e.getCurrentSkeleton(),v=f.rowHeaderWidth+f.columnTotalWidth,I=f.columnHeaderHeight+f.rowTotalHeight;return m+p>v&&(m=v-p),h+S>I&&(h=I-S),{flipY:s,flipX:o,angle:a,skewX:c,skewY:g,left:m,top:h,width:p,height:S}}function $(i,r){const{left:e=0,top:t=0,width:n=0,height:s=0,flipY:o=!1,flipX:a=!1,angle:c=0,skewX:g=0,skewY:u=0}=i,d=r.getCellWithCoordByOffset(e,t);if(d==null)return;const m={column:d.actualColumn,columnOffset:k.precisionTo(e-d.startX,1),row:d.actualRow,rowOffset:k.precisionTo(t-d.startY,1)},h=r.getCellWithCoordByOffset(e+n,t+s);if(h==null)return;const p={column:h.actualColumn,columnOffset:k.precisionTo(e+n-h.startX,1),row:h.actualRow,rowOffset:k.precisionTo(t+s-h.startY,1)};return{flipY:o,flipX:a,angle:c,skewX:g,skewY:u,from:m,to:p}}function Y(i,r){const{left:e=0,top:t=0,width:n=0,height:s=0,angle:o=0}=i,a=(o%360+360)%360;if(!(a>=45&&a<135||a>=225&&a<315))return $(i,r);const g={...i,left:e+n/2-s/2,top:t+s/2-n/2,width:s,height:n};return $(g,r)}const X={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const e=i.get(k.IRenderManagerService);return r.forEach(t=>{var n,s;(s=(n=e.getRenderById(t))==null?void 0:n.scene.getTransformer())==null||s.debounceRefreshControls()}),!0}},Re={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var I,C,E;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(D.SheetInterceptorService),s=i.get(w.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=[];o.forEach(T=>{const{unitId:y}=T;a.push(y)});const c=s.getBatchRemoveOp(o),{unitId:g,subUnitId:u,undo:d,redo:m,objects:h}=c,p=n.onCommandExecute({id:Re.id,params:r}),S={id:w.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:m,objects:h,type:w.DrawingApplyType.REMOVE}},f={id:w.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:d,objects:h,type:w.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],e)?(t.pushUndoRedo({unitID:g,undoMutations:[...(C=p.preUndos)!=null?C:[],f,...p.undos,{id:X.id,params:a}],redoMutations:[...(E=p.preRedos)!=null?E:[],S,...p.redos,{id:X.id,params:a}]}),!0):!1}},It={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),t=i.get(w.ISheetDrawingService).getFocusDrawings();if(t.length===0)return!1;const n=t[0].unitId,s=t.map(o=>{const{unitId:a,subUnitId:c,drawingId:g,drawingType:u}=o;return{unitId:a,subUnitId:c,drawingId:g,drawingType:u}});return r.executeCommand(Re.id,{unitId:n,drawings:s})}};function Qt(i){const r=[];return i.forEach(e=>{const{parent:t,children:n}=e,{unitId:s,subUnitId:o,drawingId:a}=t,c=k.getGroupState(0,0,n.map(d=>d.transform||{})),g=n.map(d=>{const m=d.transform||{left:0,top:0},{unitId:h,subUnitId:p,drawingId:S}=d;return{unitId:h,subUnitId:p,drawingId:S,transform:{...m,left:m.left-c.left,top:m.top-c.top},groupId:a}}),u={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:c};r.push({parent:u,children:g})}),r}function en(i){const r=[];return i.forEach(e=>{const{parent:t,children:n}=e,{unitId:s,subUnitId:o,drawingId:a,transform:c={width:0,height:0}}=t;if(c==null)return;const g=n.map(d=>{const{transform:m}=d,{unitId:h,subUnitId:p,drawingId:S}=d,f=k.transformObjectOutOfGroup(m||{},c,c.width||0,c.height||0);return{unitId:h,subUnitId:p,drawingId:S,transform:f,groupId:void 0}}),u={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const Dt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService);if(!r)return!1;const s=[];r.forEach(({parent:h,children:p})=>{s.push(h.unitId),p.forEach(S=>{s.push(S.unitId)})});const o=n.getGroupDrawingOp(r),{unitId:a,subUnitId:c,undo:g,redo:u,objects:d}=o;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:c,objects:d,type:w.DrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:c,objects:en(d),type:w.DrawingApplyType.UNGROUP}},{id:X.id,params:s}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:d,type:w.DrawingApplyType.GROUP}},{id:X.id,params:s}]}),!0):!1}},je={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var I,C,E;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService),s=i.get(D.SheetInterceptorService);if(!r)return!1;const o=r.drawings,a=o.map(T=>T.unitId),c=n.getBatchAddOp(o),{unitId:g,subUnitId:u,undo:d,redo:m,objects:h}=c,p=s.onCommandExecute({id:je.id,params:r}),S={id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:g,subUnitId:u,objects:h,type:w.DrawingApplyType.INSERT}},f={id:w.SetDrawingApplyMutation.id,params:{op:d,unitId:g,subUnitId:u,objects:h,type:w.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],e)?(t.pushUndoRedo({unitID:g,undoMutations:[...(C=p.preUndos)!=null?C:[],f,...p.undos,{id:X.id,params:a}],redoMutations:[...(E=p.preRedos)!=null?E:[],S,...p.redos,{id:X.id,params:a}]}),!0):!1}},yt={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService);if(!r)return!1;const n=i.get(w.ISheetDrawingService),{unitId:s,subUnitId:o,drawingIds:a,arrangeType:c}=r,g={unitId:s,subUnitId:o,drawingIds:a};let u;if(c===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):c===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):c===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):c===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:d,redo:m,undo:h}=u;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:m,unitId:s,subUnitId:o,objects:d,type:w.DrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:s,subUnitId:o,objects:d,type:w.DrawingApplyType.ARRANGE}}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:o,objects:d,type:w.DrawingApplyType.ARRANGE}}]}),!0):!1}},Me={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var v,I;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService),s=i.get(D.SheetInterceptorService);if(!r)return!1;const{drawings:o}=r,a=n.getBatchUpdateOp(o),{unitId:c,subUnitId:g,undo:u,redo:d,objects:m}=a,h=s.onCommandExecute({id:Me.id,params:r}),p=[...(v=h.preRedos)!=null?v:[],{id:w.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:g,op:d,objects:m,type:w.DrawingApplyType.UPDATE}},...h.redos,{id:X.id,params:[c]}],S=[...(I=h.preUndos)!=null?I:[],{id:w.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:g,op:u,objects:m,type:w.DrawingApplyType.UPDATE}},...h.undos,{id:X.id,params:[c]}];return l.sequenceExecute(p,e)?(t.pushUndoRedo({unitID:c,undoMutations:S,redoMutations:p}),!0):!1}},Ct={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService);if(!r)return!1;const s=[];r.forEach(({parent:h,children:p})=>{s.push(h.unitId),p.forEach(S=>{s.push(S.unitId)})});const o=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:c,undo:g,redo:u,objects:d}=o;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:c,objects:d,type:w.DrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:c,objects:Qt(d),type:w.DrawingApplyType.GROUP}},{id:X.id,params:s}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:d,type:w.DrawingApplyType.UNGROUP}},{id:X.id,params:s}]}),!0):!1}};var tn=Object.getOwnPropertyDescriptor,nn=(i,r,e,t)=>{for(var n=t>1?void 0:t?tn(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},te=(i,r)=>(e,t)=>r(e,t,i);function rn(i,r,e){const t=e*Math.PI/180,n=Math.abs(i*Math.cos(t))+Math.abs(r*Math.sin(t)),s=Math.abs(i*Math.sin(t))+Math.abs(r*Math.cos(t));return{rotatedWidth:n,rotatedHeight:s}}function St(i,r,e,t,n){var I;const{rotatedHeight:s,rotatedWidth:o}=rn(e,t,n),c=i.get(k.IRenderManagerService).getRenderById(r.unitId);if(!c)return!1;const u=(I=c.with(A.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const d=u.getCellByIndex(r.row,r.col),m=d.mergeInfo.endX-d.mergeInfo.startX-2,h=d.mergeInfo.endY-d.mergeInfo.startY-2,p=o/s,f=Math.ceil(Math.min(m,h*p))/o,v=!f||Number.isNaN(f)?.001:f;return{width:e*v,height:t*v}}exports.SheetDrawingUpdateController=class extends l.Disposable{constructor(e,t,n,s,o,a,c,g,u,d,m,h,p,S){super();ie(this,"_workbookSelections");this._context=e,this._skeletonManagerService=t,this._commandService=n,this._selectionRenderService=s,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=c,this._drawingManagerService=g,this._contextService=u,this._messageService=d,this._localeService=m,this._injector=p,this._urlImageService=S,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const e=await this._fileOpenerService.openFile({multiple:!0,accept:x.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),t=e.length;return t>x.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:G.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(x.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t===0?!1:(e.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const t=(await this._fileOpenerService.openFile({multiple:!1,accept:x.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return t?(await this._insertCellImage(t),!0):!1}insertCellImageByFile(e,t){return this._insertCellImage(e,t)}async insertFloatImageByFile(e){var E;let t;try{t=await this._imageIoService.saveImage(e)}catch(T){const y=T.message;y===x.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:G.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(x.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===x.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:G.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===x.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:G.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const n=this._getUnitInfo(),{unitId:s,subUnitId:o}=n,{imageId:a,imageSourceType:c,source:g,base64Cache:u}=t,{width:d,height:m,image:h}=await x.getImageSize(u||""),{width:p,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(g,c,h);let f=1;if(d>x.DRAWING_IMAGE_WIDTH_LIMIT||m>x.DRAWING_IMAGE_HEIGHT_LIMIT){const T=x.DRAWING_IMAGE_WIDTH_LIMIT/d,y=x.DRAWING_IMAGE_HEIGHT_LIMIT/m;f=Math.max(T,y)}const v=this._getImagePosition(d*f,m*f,p,S);if(v==null)return;const I=Q(v,this._selectionRenderService,this._skeletonManagerService),C={unitId:s,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:g,transform:I,sheetTransform:v,axisAlignSheetTransform:(E=Y(I,this._selectionRenderService))!=null?E:v};return this._commandService.executeCommand(je.id,{unitId:s,drawings:[C]})}async _insertCellImage(e,t){var E,T;let n;try{n=await this._imageIoService.saveImage(e)}catch(y){const R=y.message;R===x.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:G.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(x.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):R===x.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:G.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===x.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:G.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:s,imageSourceType:o,source:a,base64Cache:c}=n,{width:g,height:u,image:d}=await x.getImageSize(c||"");this._imageIoService.addImageSourceCache(a,o,d);const m=this._workbookSelections.getCurrentLastSelection();if(!m)return!1;let h=m.primary.actualRow,p=m.primary.actualColumn;m.primary.isMerged&&(h=m.primary.startRow,p=m.primary.startColumn);const S=l.createDocumentModelWithStyle("",{}),f=St(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:h,col:p},g,u,0);if(!f)return!1;const v={size:{width:f.width,height:f.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},I={unitId:S.getUnitId(),subUnitId:S.getUnitId(),drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:o,source:a,transform:et.docDrawingPositionToTransform(v),docTransform:v,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:S,drawings:[I],selection:{collapsed:!0,startOffset:0,endOffset:0}});return C?(S.apply(C),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(E=t==null?void 0:t.row)!=null?E:h]:{[(T=t==null?void 0:t.col)!=null?T:p]:{p:S.getSnapshot(),t:1}}},unitId:t==null?void 0:t.unitId,subUnitId:t==null?void 0:t.subUnitId})):!1}async insertCellImageByUrl(e,t){var p,S;let n=e;try{n=await this._urlImageService.getImage(e)}catch(f){console.error(`Failed to get image from URLImageService: ${e}`,f)}const{width:s,height:o,image:a}=await x.getImageSize(n||"");this._imageIoService.addImageSourceCache(e,l.ImageSourceType.URL,a);const c=this._workbookSelections.getCurrentLastSelection();if(!c)return!1;const g=l.createDocumentModelWithStyle("",{}),u=St(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:c.primary.actualRow,col:c.primary.actualColumn},s,o,0);if(!u)return!1;const d={size:{width:u.width,height:u.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},m={unitId:g.getUnitId(),subUnitId:g.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:e,transform:et.docDrawingPositionToTransform(d),docTransform:d,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},h=l.BuildTextUtils.drawing.add({documentDataModel:g,drawings:[m],selection:{collapsed:!0,startOffset:0,endOffset:0}});return h?(g.apply(h),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(p=t==null?void 0:t.row)!=null?p:c.primary.actualRow]:{[(S=t==null?void 0:t.col)!=null?S:c.primary.actualColumn]:{p:g.getSnapshot(),t:1}}},unitId:t==null?void 0:t.unitId,subUnitId:t==null?void 0:t.subUnitId})):!1}_getUnitInfo(){const e=this._context.unit,t=e.getActiveSheet(),n=e.getUnitId(),s=t.getSheetId();return{unitId:n,subUnitId:s}}_getImagePosition(e,t,n,s){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 c=A.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(c==null)return;let{startColumn:g,startRow:u,startX:d,startY:m}=c,h=!1;if(d+e>n&&(d=n-e,d<0&&(d=0,e=n),h=!0),m+t>s&&(m=s-t,m<0&&(m=0,t=s),h=!0),h){const v=this._selectionRenderService.getCellWithCoordByOffset(d,m);if(v==null)return;d=v.startX,m=v.startY,g=v.actualColumn,u=v.actualRow}const p={column:g,columnOffset:0,row:u,rowOffset:0},S=this._selectionRenderService.getCellWithCoordByOffset(d+e,m+t);if(S==null)return;const f={column:S.actualColumn,columnOffset:d+e-S.startX,row:S.actualRow,rowOffset:m+t-S.startY};return{from:p,to:f}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:t,subUnitId:n,drawingIds:s,arrangeType:o}=e;this._commandService.executeCommand(yt.id,{unitId:t,subUnitId:n,drawingIds:s,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{const t=[];e.length!==0&&(e.forEach(n=>{const{unitId:s,subUnitId:o,drawingId:a,drawingType:c,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:s,subUnitId:o,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const d=$({...u.transform,...g},this._selectionRenderService),m=Y({...u.transform,...g},this._selectionRenderService);if(d==null||m==null)return;const h={...n,transform:{...u.transform,...g,...Q(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d},axisAlignSheetTransform:{...m}};t.push(h)}),t.length>0&&this._commandService.executeCommand(Me.id,{unitId:e[0].unitId,drawings:t}))}))}_getSheetTransformByParam(e){const{unitId:t,subUnitId:n,drawingId:s,transform:o}=e;if(o==null)return null;const a=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:s});if(a==null||a.unitId!==this._context.unitId)return null;const c=$({...a.transform,...o},this._selectionRenderService),g=Y({...a.transform,...o},this._selectionRenderService);return c==null||g==null?null:{sheetTransform:c,axisAlignSheetTransform:g}}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{const t=[];for(const n of e){const s=this._getSheetTransformByParam(n.parent),o=[];for(const c of n.children){const g=this._getSheetTransformByParam(c);g!=null&&o.push({...c,sheetTransform:g.sheetTransform,axisAlignSheetTransform:g.axisAlignSheetTransform})}const a={parent:{...n.parent,sheetTransform:s},children:o};t.push(a)}if(t.length>0){this._commandService.executeCommand(Dt.id,t);const{unitId:n,subUnitId:s,drawingId:o}=e[0].parent;this._commandService.syncExecuteCommand(x.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:s,drawingId:o}])}})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{const t=[];for(const n of e){const{children:s}=n,o=[];for(const a of s){const c=this._getSheetTransformByParam(a);c!=null&&o.push({...a,sheetTransform:c})}t.push({...n,children:o})}this._commandService.executeCommand(Ct.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};exports.SheetDrawingUpdateController=nn([te(1,l.Inject(A.SheetSkeletonManagerService)),te(2,l.ICommandService),te(3,A.ISheetSelectionRenderService),te(4,x.IImageIoService),te(5,j.ILocalFileService),te(6,w.ISheetDrawingService),te(7,x.IDrawingManagerService),te(8,l.IContextService),te(9,j.IMessageService),te(10,l.Inject(l.LocaleService)),te(11,l.Inject(D.SheetsSelectionsService)),te(12,l.Inject(l.Injector)),te(13,l.IURLImageService)],exports.SheetDrawingUpdateController);const ke={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var o,a;const e=i.get(l.IUniverInstanceService),t=i.get(k.IRenderManagerService),n=(o=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,e,t))==null?void 0:o.with(exports.SheetDrawingUpdateController);if(!n)return!1;const s=r==null?void 0:r.files;if(s){const c=s.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(c)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},Tt={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var t,n;const r=i.get(l.IUniverInstanceService),e=i.get(k.IRenderManagerService);return(n=(t=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,r,e))==null?void 0:t.with(exports.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}},be={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(w.ISheetDrawingService),n=i.get(A.ISheetSelectionRenderService),{direction:s}=r,o=t.getFocusDrawings();if(o.length===0)return!1;const a=o[0].unitId,c=o.map(u=>{const{transform:d}=u;if(d==null)return null;const m={...d},{left:h=0,top:p=0}=d;return s===l.Direction.UP?m.top=p-1:s===l.Direction.DOWN?m.top=p+1:s===l.Direction.LEFT?m.left=h-1:s===l.Direction.RIGHT&&(m.left=h+1),{...u,transform:m,sheetTransform:$(m,n),axisAlignSheetTransform:Y(m,n)}}).filter(u=>u!=null);return e.syncExecuteCommand(Me.id,{unitId:a,drawings:c})?(e.syncExecuteCommand(X.id,[a]),!0):!1}};var sn=Object.getOwnPropertyDescriptor,on=(i,r,e,t)=>{for(var n=t>1?void 0:t?sn(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ze=(i,r)=>(e,t)=>r(e,t,i),he=(i=>(i.CELL_ADDRESS="cellAddress",i.COLUMN_VALUE="columnValue",i))(he||{});const lt=l.createIdentifier("sheets-drawing-ui.batch-save-images.service");function ft(i){let r="",e=i;for(;e>=0;)r=String.fromCharCode(e%26+65)+r,e=Math.floor(e/26)-1;return r}function tt(i,r){return`${ft(r)}${i+1}`}function an(i){const r=tt(i.startRow,i.startColumn),e=tt(i.endRow,i.endColumn);return r===e?r:`${r}:${e}`}function Nt(i){var r,e,t,n;return!!((e=(r=i==null?void 0:i.p)==null?void 0:r.drawingsOrder)!=null&&e.length&&((n=(t=i==null?void 0:i.p)==null?void 0:t.drawingsOrder)==null?void 0:n.length)>0)}function xt(i){var t,n,s;if(!((n=(t=i.p)==null?void 0:t.drawingsOrder)!=null&&n.length)||!((s=i.p)!=null&&s.drawings))return null;const r=i.p.drawingsOrder[0],e=i.p.drawings[r];return!e||!("source"in e)||!("imageSourceType"in e)?null:e}function ht(i,r){if(r===l.ImageSourceType.BASE64){const e=i.match(/^data:image\/(\w+);/);if(e)return e[1]==="jpeg"?"jpg":e[1]}if(r===l.ImageSourceType.URL){const e=i.match(/\.(\w+)(?:\?|$)/);if(e)return e[1].toLowerCase()}return"png"}async function jt(i,r){if(r===l.ImageSourceType.BASE64)return(await fetch(i)).blob();if(r===l.ImageSourceType.URL)return(await fetch(i)).blob();throw new Error("UUID image type requires additional handling")}exports.BatchSaveImagesService=class extends l.Disposable{constructor(r,e,t,n){super(),this._univerInstanceService=r,this._selectionService=e,this._imageIoService=t,this._urlImageService=n}registerURLImageDownloader(r){return this._urlImageService.registerURLImageDownloader(r)}getCellImagesInSelection(){const r=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!r)return[];const e=r.getActiveSheet();if(!e)return[];const t=this._selectionService.getCurrentSelections();if(!t||t.length===0)return[];const n=e.getCellMatrix(),s=[];for(const o of t){const{startRow:a,endRow:c,startColumn:g,endColumn:u}=o.range;for(let d=a;d<=c;d++)for(let m=g;m<=u;m++){const h=n.getValue(d,m);if(Nt(h)){const p=xt(h);p&&s.push({row:d,col:m,cellAddress:tt(d,m),source:p.source,imageSourceType:p.imageSourceType,imageId:p.drawingId})}}}return s}getCellImagesFromRanges(r,e,t){const n=this._univerInstanceService.getUnit(r,l.UniverInstanceType.UNIVER_SHEET);if(!n)return[];const s=n.getSheetBySheetId(e);if(!s)return[];const o=s.getCellMatrix(),a=[];for(const c of t){const{startRow:g,endRow:u,startColumn:d,endColumn:m}=c;for(let h=g;h<=u;h++)for(let p=d;p<=m;p++){const S=o.getValue(h,p);if(Nt(S)){const f=xt(S);f&&a.push({row:h,col:p,cellAddress:tt(h,p),source:f.source,imageSourceType:f.imageSourceType,imageId:f.drawingId})}}}return a}getDataColumns(){var m,h,p,S;const r=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!r)return[];const e=r.getActiveSheet();if(!e)return[];const t=this._selectionService.getCurrentSelections();if(!t||t.length===0)return[];const n=e.getCellMatrix(),s=n.getDataRange();let o=1/0,a=-1/0;const c=new Set;for(const f of t){o=Math.min(o,f.range.startRow),a=Math.max(a,f.range.endRow);for(let v=f.range.startColumn;v<=f.range.endColumn;v++)c.add(v)}const g=new Set;for(let f=s.startColumn;f<=s.endColumn;f++)if(!c.has(f))for(let v=o;v<=a;v++){const I=n.getValue(v,f);if(I&&(((m=I.v)==null?void 0:m.toString())||((S=(p=(h=I.p)==null?void 0:h.body)==null?void 0:p.dataStream)==null?void 0:S.trim())||"")){g.add(f);break}}const u=[],d=Array.from(g).sort((f,v)=>f-v);for(const f of d)u.push({index:f,label:ft(f)});return u}getDataColumnsForRanges(r,e,t){var p,S,f,v;const n=this._univerInstanceService.getUnit(r,l.UniverInstanceType.UNIVER_SHEET);if(!n)return[];const s=n.getSheetBySheetId(e);if(!s)return[];const o=s.getCellMatrix(),a=o.getDataRange();let c=1/0,g=-1/0;const u=new Set;for(const I of t){c=Math.min(c,I.startRow),g=Math.max(g,I.endRow);for(let C=I.startColumn;C<=I.endColumn;C++)u.add(C)}const d=new Set;for(let I=a.startColumn;I<=a.endColumn;I++)if(!u.has(I))for(let C=c;C<=g;C++){const E=o.getValue(C,I);if(E&&(((p=E.v)==null?void 0:p.toString())||((v=(f=(S=E.p)==null?void 0:S.body)==null?void 0:f.dataStream)==null?void 0:v.trim())||"")){d.add(I);break}}const m=[],h=Array.from(d).sort((I,C)=>I-C);for(const I of h)m.push({index:I,label:ft(I)});return m}getSelectionRangeNotation(){const r=this._selectionService.getCurrentSelections();return!r||r.length===0?"":r.map(e=>an(e.range)).join(", ")}getSelectionRowRange(){const r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return null;let e=1/0,t=-1/0;for(const n of r)e=Math.min(e,n.range.startRow),t=Math.max(t,n.range.endRow);return{startRow:e,endRow:t}}getSelectionColumnIndices(){const r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return new Set;const e=new Set;for(const t of r)for(let n=t.range.startColumn;n<=t.range.endColumn;n++)e.add(n);return e}generateFileName(r,e){var o,a,c,g;const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),n=ht(r.source,r.imageSourceType),s=[];for(const u of e.fileNameParts)if(u==="cellAddress")s.push(r.cellAddress);else if(u==="columnValue"&&e.columnIndex!==void 0){const d=t==null?void 0:t.getActiveSheet();if(d){const h=d.getCellMatrix().getValue(r.row,e.columnIndex);if(h){const p=((o=h.v)==null?void 0:o.toString())||((g=(c=(a=h.p)==null?void 0:a.body)==null?void 0:c.dataStream)==null?void 0:g.trim())||"";if(p){const S=p.replace(/[<>:"/\\|?*]/g,"_").trim();S&&s.push(S)}}}}return s.length===0?`${r.cellAddress}.${n}`:`${s.join("_")}.${n}`}generateFileNameWithContext(r,e,t,n){var c,g,u,d;const s=this._univerInstanceService.getUnit(t,l.UniverInstanceType.UNIVER_SHEET),o=ht(r.source,r.imageSourceType),a=[];for(const m of e.fileNameParts)if(m==="cellAddress")a.push(r.cellAddress);else if(m==="columnValue"&&e.columnIndex!==void 0){const h=s==null?void 0:s.getSheetBySheetId(n);if(h){const S=h.getCellMatrix().getValue(r.row,e.columnIndex);if(S){const f=((c=S.v)==null?void 0:c.toString())||((d=(u=(g=S.p)==null?void 0:g.body)==null?void 0:u.dataStream)==null?void 0:d.trim())||"";if(f){const v=f.replace(/[<>:"/\\|?*]/g,"_").trim();v&&a.push(v)}}}}return a.length===0?`${r.cellAddress}.${o}`:`${a.join("_")}.${o}`}async saveImages(r,e){var s;const t=await window.showDirectoryPicker({mode:"readwrite"}),n=new Map;for(const o of r){let a=this.generateFileName(o,e);const c=a.replace(/\.\w+$/,""),g=((s=a.match(/\.\w+$/))==null?void 0:s[0])||".png",u=n.get(c)||0;u>0&&(a=`${c}_${u}${g}`),n.set(c,u+1);try{const d=await this._getImageBlob(o),h=await(await t.getFileHandle(a,{create:!0})).createWritable();await h.write(d),await h.close()}catch(d){throw console.error(`Failed to save image ${a}:`,d),d}}}async saveImagesWithContext(r,e,t,n){var a;const s=await window.showDirectoryPicker({mode:"readwrite"}),o=new Map;for(const c of r){let g=this.generateFileNameWithContext(c,e,t,n);const u=g.replace(/\.\w+$/,""),d=((a=g.match(/\.\w+$/))==null?void 0:a[0])||".png",m=o.get(u)||0;m>0&&(g=`${u}_${m}${d}`),o.set(u,m+1);try{const h=await this._getImageBlob(c),S=await(await s.getFileHandle(g,{create:!0})).createWritable();await S.write(h),await S.close()}catch(h){throw console.error(`Failed to save image ${g}:`,h),h}}}async downloadSingleImage(r){const e=ht(r.source,r.imageSourceType),t=`${r.cellAddress}.${e}`;try{const n=await this._getImageBlob(r),s=URL.createObjectURL(n),o=document.createElement("a");o.href=s,o.download=t,document.body.appendChild(o),o.click(),document.body.removeChild(o),URL.revokeObjectURL(s)}catch(n){throw console.error(`Failed to download image ${t}:`,n),n}}async _getImageBlob(r){if(r.imageSourceType===l.ImageSourceType.UUID){const e=await this._imageIoService.getImage(r.source);return jt(e,l.ImageSourceType.URL)}return r.imageSourceType===l.ImageSourceType.URL?this._urlImageService.downloadImage(r.source):jt(r.source,r.imageSourceType)}};exports.BatchSaveImagesService=on([ze(0,l.IUniverInstanceService),ze(1,l.Inject(D.SheetsSelectionsService)),ze(2,l.IImageIoService),ze(3,l.IURLImageService)],exports.BatchSaveImagesService);const Ce="sheet.dialog.batch-save-images",Te={id:"sheet.command.save-cell-images",type:l.CommandType.COMMAND,handler:async i=>{const r=i.get(j.IDialogService),e=i.get(lt),t=e.getCellImagesInSelection();if(t.length===1)try{return await e.downloadSingleImage(t[0]),!0}catch(a){return console.error("Failed to download image:",a),!1}const n=i.get(l.LocaleService),s=e.getSelectionRangeNotation(),o=`${n.t("sheetImage.save.title")} (${s})`;return r.open({id:Ce,draggable:!0,width:360,title:{title:o},children:{label:Ce},destroyOnClose:!0,preservePositionOnDestroy:!0,onClose:()=>r.close(Ce)}),!0}},Lt="COMPONENT_SHEET_DRAWING_PANEL",Rt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const e=i.get(j.ISidebarService),t=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),s=i.get(l.ICommandService);return D.getSheetCommandTarget(n)?(r.value==="open"?e.open({header:{title:t.t("sheetImage.panel.title")},children:{label:Lt},onClose:()=>{s.syncExecuteCommand(x.SetDrawingSelectedOperation.id,[])},width:360}):e.close(),!0):!1}},Mt={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const e=i.get(l.ICommandService);return r==null?!1:(e.syncExecuteCommand(x.SetDrawingSelectedOperation.id,[r]),e.executeCommand(Rt.id,{value:"open"}),!0)}},cn="sheets-drawing-ui.config",kt={};var dn=Object.getOwnPropertyDescriptor,ln=(i,r,e,t)=>{for(var n=t>1?void 0:t?dn(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},oe=(i,r)=>(e,t)=>r(e,t,i);let nt=class extends l.RxDisposable{constructor(r,e,t,n,s,o,a,c,g,u){super();ie(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=e,this._drawingManagerService=t,this._canvasPopManagerService=n,this._renderManagerService=s,this._univerInstanceService=o,this._messageService=a,this._contextService=c,this._ioService=g,this._commandService=u,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).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 e;this.disposeWithMe(this._ioService.change$.subscribe(t=>{t>0&&!e?e=this._messageService.show({id:r,type:G.MessageType.Loading,content:`${this._localeService.t("uploadLoading.loading")}: ${t}`,duration:0}):t===0&&(e==null||e.dispose(),e=void 0)}))}_dispose(r){super.dispose();const e=r.getUnitId();this._renderManagerService.removeRender(e),this._initImagePopupMenu.delete(e)}_create(r){if(!r)return;const e=r.getUnitId();this._renderManagerService.has(e)&&!this._initImagePopupMenu.has(e)&&(this._popupMenuListener(e),this._initImagePopupMenu.add(e))}_hasCropObject(r){const e=r.getAllObjectsByOrder();for(const t of e)if(t instanceof me.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var s;const e=(s=this._renderManagerService.getRenderById(r))==null?void 0:s.scene;if(!e)return;const t=e.getTransformerByCreate();if(!t)return;let n;this.disposeWithMe(t.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(e))return;const o=t.getSelectedObjectMap();if(o.size>1){n==null||n.dispose();return}const a=o.values().next().value;if(!a)return;const c=a.oKey,g=this._drawingManagerService.getDrawingOKey(c);if(!g)return;const{unitId:u,subUnitId:d,drawingId:m,drawingType:h}=g,p=g.data;if(p&&p.disablePopup)return;n==null||n.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,d,m,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:me.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,d,m,h)}}))})),this.disposeWithMe(t.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(x.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(o=>{o[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(t.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,e,t,n){return[{label:"image-popup.edit",index:0,commandId:Mt.id,commandParams:{unitId:r,subUnitId:e,drawingId:t},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Re.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:e,drawingId:t}]},disable:!1},{label:"image-popup.crop",index:2,commandId:me.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:e,drawingId:t},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:me.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:e,drawingId:t}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};nt=ln([oe(0,l.Inject(l.Injector)),oe(1,l.Inject(l.LocaleService)),oe(2,x.IDrawingManagerService),oe(3,l.Inject(A.SheetCanvasPopManagerService)),oe(4,k.IRenderManagerService),oe(5,l.IUniverInstanceService),oe(6,j.IMessageService),oe(7,l.IContextService),oe(8,l.IImageIoService),oe(9,l.ICommandService)],nt);var un=Object.getOwnPropertyDescriptor,gn=(i,r,e,t)=>{for(var n=t>1?void 0:t?un(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},qe=(i,r)=>(e,t)=>r(e,t,i);let wt=class extends l.Disposable{constructor(r,e,t,n,s){super();ie(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=e,this._selectionsService=t,this._drawingRenderService=n,this._sheetSkeletonManagerService=s,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(N.throttleTime(33)).subscribe(r=>{var t,n;let e=[];r!==null&&(e=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),e.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&e.length===1&&((t=e[0].primary)==null?void 0:t.actualRow)===r.row&&((n=e[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 e;if(r!=null&&r.drawing&&this._isSetCursor){const t=r.drawing.drawing.drawingOrigin,n=(e=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:e.imageCacheMap.getImage(t.imageSourceType,t.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};wt=gn([qe(1,l.Inject(A.HoverManagerService)),qe(2,l.Inject(D.SheetsSelectionsService)),qe(3,l.Inject(me.DrawingRenderService)),qe(4,l.Inject(A.SheetSkeletonManagerService))],wt);var hn=Object.getOwnPropertyDescriptor,mn=(i,r,e,t)=>{for(var n=t>1?void 0:t?hn(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Ze=(i,r)=>(e,t)=>r(e,t,i);let vt=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=e,this._sheetSelectionRenderService=t,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const e=i[r];for(const t in e.data){const n=e.data[t];n.sheetTransform&&(n.transform=Q(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService))}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};vt=mn([Ze(1,w.ISheetDrawingService),Ze(2,x.IDrawingManagerService),Ze(3,l.Inject(A.ISheetSelectionRenderService)),Ze(4,l.Inject(A.SheetSkeletonManagerService))],vt);var pn=Object.getOwnPropertyDescriptor,Sn=(i,r,e,t)=>{for(var n=t>1?void 0:t?pn(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},De=(i,r)=>(e,t)=>r(e,t,i);function $t(i,r,e){var t,n,s,o;if(((n=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:n.dataStream.length)===3&&((o=(s=e.p)==null?void 0:s.drawingsOrder)==null?void 0:o.length)===1){const a=e.p.drawings[e.p.drawingsOrder[0]],c=St(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(c)return a.transform.width=c.width,a.transform.height=c.height,a.docTransform.size.width=c.width,a.docTransform.size.height=c.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,e.p.documentStyle.pageSize.width=1/0,e.p.documentStyle.pageSize.height=1/0,!0}return!1}let rt=class extends l.Disposable{constructor(i,r,e,t,n,s){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=e,this._drawingManagerService=t,this._docDrawingController=n,this._editorBridgeService=s,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.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(i=>{i.id===et.ReplaceSnapshotCommand.id&&i.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:(i,r,e)=>{var t;return i!=null&&i.p&&((t=i.p.drawingsOrder)!=null&&t.length)&&(i===r.rawData&&(i={...r.rawData}),i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},$t(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),e(i)}}))}};rt=Sn([De(0,l.ICommandService),De(1,l.Inject(D.SheetInterceptorService)),De(2,l.Inject(l.Injector)),De(3,x.IDrawingManagerService),De(4,l.Inject(Ft.DocDrawingController)),De(5,l.Inject(A.IEditorBridgeService))],rt);var fn=Object.getOwnPropertyDescriptor,wn=(i,r,e,t)=>{for(var n=t>1?void 0:t?fn(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Wt=(i,r)=>(e,t)=>r(e,t,i);let it=class extends l.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,e,t)=>{new l.ObjectMatrix(t).forValue((n,s,o)=>{$t(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:s},o)})}}))}};it=wn([Wt(0,l.Inject(D.IAutoFillService)),Wt(1,l.Inject(l.Injector))],it);var vn=Object.getOwnPropertyDescriptor,_n=(i,r,e,t)=>{for(var n=t>1?void 0:t?vn(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Ue=(i,r)=>(e,t)=>r(e,t,i);const In=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let st=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._commandService=i,this._univerInstanceService=r,this._dialogService=e,this._renderManagerService=t,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(i){var n;const r=l.createDocumentModelWithStyle("",{}),e=(n=k.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(A.EditingRenderController),t=l.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[i],selection:{collapsed:!0,startOffset:0,endOffset:0}});t&&(r.apply(t),e&&e.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,e;if(i.id===et.InnerPasteCommand.id){const t=i.params,{doc:n}=t,s=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_DOC);if(s==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const o=s.getUnitId();if(In.includes(o)){if(o!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(A.SetCellEditVisibleOperation.id,{visible:!1})};((e=s.getBody())==null?void 0:e.dataStream)===`\r
|
|
2
|
-
`?(this._commandService.syncExecuteCommand(A.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")}}}))}};st=_n([Ue(0,l.ICommandService),Ue(1,l.IUniverInstanceService),Ue(2,j.IDialogService),Ue(3,k.IRenderManagerService),Ue(4,l.Inject(l.LocaleService))],st);var Dn=Object.getOwnPropertyDescriptor,yn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Dn(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Pe=(i,r)=>(e,t)=>r(e,t,i);const Yt="image/png";function Cn(i){const r=i.split(","),e=atob(r[1]),t=e.length,n=new Uint8Array(t);for(let s=0;s<t;s++)n[s]=e.charCodeAt(s);return new Blob([n],{type:Yt})}function Tn(i){const r=new ClipboardItem({[Yt]:Cn(i)});navigator.clipboard.write([r]).catch(e=>{console.error("Could not copy image using clipboard API: ",e)})}function Rn(){function i(){const t=document.createElement("input");return t.style.position="absolute",t.style.height="1px",t.style.width="1px",t.style.opacity="0",t}const r=document.activeElement,e=i();return document.body.appendChild(e),e.focus(),()=>{e.blur(),document.body.removeChild(e),r instanceof HTMLElement&&r.focus()}}const Bt=[A.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,A.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,A.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,A.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA];let ot=class extends l.Disposable{constructor(r,e,t,n,s){super();ie(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=e,this._drawingService=t,this._clipboardInterfaceService=n,this._commandService=s,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,e,t,n)=>{this._copyInfo=null;const s=this._focusedDrawings;if(s.length>0){const[o]=s;if(o.drawingType!==l.DrawingTypeEnum.DRAWING_IMAGE)return;if(n===A.COPY_TYPE.CUT){const c={unitId:r,drawings:[o]};this._commandService.executeCommand(Re.id,c)}setTimeout(()=>{const c=Rn();o.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&o.imageSourceType===x.ImageSourceType.BASE64?Tn(o.source):this._clipboardInterfaceService.writeText(""),c()},200);const a={unitId:o.unitId,subUnitId:o.subUnitId,drawings:[o]};this._copyInfo=a}else{const o=this._createDrawingsCopyInfoByRange(r,e,t);this._copyInfo=o}},onPasteCells:(r,e,t,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:s=A.COPY_TYPE.COPY,pasteType:o}=n,{range:a}=r||{},{range:c,unitId:g,subUnitId:u}=e;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:o,unitId:g,subUnitId:u,pasteRange:c},{copyRange:a,copyType:s}):this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:o},A.COPY_TYPE.COPY)},onPastePlainText:(r,e)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:A.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},A.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,e)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:A.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},A.COPY_TYPE.COPY);{const t=e.filter(n=>n.type.includes("image"));if(t.length)return{undos:[],redos:[{id:ke.id,params:{files:t}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,e,t){var m;const n=(m=this._renderManagerService.getRenderById(r))==null?void 0:m.with(A.SheetSkeletonManagerService);if(!n)return;const s=n.attachRangeWithCoord(t);if(!s)return;const{startX:o,endX:a,startY:c,endY:g}=s,u=this._drawingService.getDrawingData(r,e),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const p=u[h];if(p.drawingType!==l.DrawingTypeEnum.DRAWING_IMAGE)return;const{transform:S}=p;if(p.anchorType!==w.SheetDrawingAnchorType.Both||!S)return;const{left:f=0,top:v=0,width:I=0,height:C=0}=S,{drawingStartX:E,drawingEndX:T,drawingStartY:y,drawingEndY:R}={drawingStartX:f,drawingEndX:f+I,drawingStartY:v,drawingEndY:v+C};o<=E&&T<=a&&c<=y&&R<=g&&d.push(p)}),d.length)return{copyRange:t,drawings:d,unitId:r,subUnitId:e}}_generateSingleDrawingPasteMutations(r,e){const{pasteType:t,pasteTo:n}=r;if(Bt.includes(t))return{redos:[],undos:[]};const{unitId:s,subUnitId:o,range:a}=n,c=this._renderManagerService.getRenderById(s),g=c==null?void 0:c.with(A.SheetSkeletonManagerService),u=c==null?void 0:c.with(A.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:m}=d,h=D.discreteRangeToRange(a);return this._generateMutations(m,{unitId:s,subUnitId:o,isCut:e===A.COPY_TYPE.CUT,getTransform:(p,S)=>{var I,C;const f=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),v={...p,left:f==null?void 0:f.startX,top:f==null?void 0:f.startY};return{transform:v,sheetTransform:(I=$(v,u))!=null?I:S,axisAlignSheetTransform:(C=Y(v,u))!=null?C:S}}})}_generateMutations(r,e){const{unitId:t,subUnitId:n,getTransform:s,isCut:o}=e,a=[],c=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:d,sheetTransform:m}=u;if(!d)return;const h=s(d,m),p={...u,unitId:t,subUnitId:n,drawingId:o?u.drawingId:l.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform,axisAlignSheetTransform:h.axisAlignSheetTransform};if(o){const{undo:S,redo:f,objects:v}=g.getBatchUpdateOp([p]);a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:w.DrawingApplyType.UPDATE,op:f,objects:v}}),c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:w.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:f,objects:v}=g.getBatchAddOp([p]);a.push({id:w.SetDrawingApplyMutation.id,params:{op:f,unitId:t,subUnitId:n,objects:v,type:w.DrawingApplyType.INSERT}}),c.push({id:w.SetDrawingApplyMutation.id,params:{op:S,unitId:t,subUnitId:n,objects:v,type:w.DrawingApplyType.REMOVE}})}}),{redos:a,undos:c}}_generateRangeDrawingsPasteMutations(r,e){var M;const{unitId:t,subUnitId:n,pasteType:s,pasteRange:o}=r,{copyRange:a,copyType:c}=e;if(Bt.includes(s))return{redos:[],undos:[]};const g=(M=this._renderManagerService.getRenderById(t))==null?void 0:M.with(A.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:t,subUnitId:n,range:D.discreteRangeToRange(o)},pasteType:s},c);const{ranges:[d,m],mapFunc:h}=A.virtualizeDiscreteRanges([a,o]),{row:p,col:S}=h(d.startRow,d.startColumn),{row:f,col:v}=h(m.startRow,m.startColumn),I=g.attachRangeWithCoord({startRow:p,endRow:p,startColumn:S,endColumn:S}),C=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:v,endColumn:v});if(!I||!C||!this._copyInfo)return{redos:[],undos:[]};const E=C.startX-I.startX,T=C.startY-I.startY,y=f-p,R=v-S;return this._generateMutations(u,{unitId:t,subUnitId:n,getTransform:(P,O)=>{var W,B,J;const U={...P,left:((W=P==null?void 0:P.left)!=null?W:0)+E,top:((B=P==null?void 0:P.top)!=null?B:0)+T},_=this._renderManagerService.getRenderById(t),b=_==null?void 0:_.with(A.ISheetSelectionRenderService);return b?{transform:U,sheetTransform:{...O,to:{...O.to,row:O.to.row+y,column:O.to.column+R},from:{...O.from,row:O.from.row+y,column:O.from.column+R}},axisAlignSheetTransform:(J=Y(U,b))!=null?J:O}:{transform:U,sheetTransform:{...O,to:{...O.to,row:O.to.row+y,column:O.to.column+R},from:{...O.from,row:O.from.row+y,column:O.from.column+R}},axisAlignSheetTransform:{...O,to:{...O.to,row:O.to.row+y,column:O.to.column+R},from:{...O.from,row:O.from.row+y,column:O.from.column+R}}}},isCut:c===A.COPY_TYPE.CUT})}};ot=yn([Pe(0,A.ISheetClipboardService),Pe(1,k.IRenderManagerService),Pe(2,x.IDrawingManagerService),Pe(3,j.IClipboardInterfaceService),Pe(4,l.ICommandService)],ot);var Mn=Object.getOwnPropertyDescriptor,bn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Mn(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Ne=(i,r)=>(e,t)=>r(e,t,i);let at=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=e,this._univerInstanceService=t,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,e=N.combineLatest([i,r]);this.disposeWithMe(e.pipe(N.switchMap(([t,n])=>t?t.activeSheet$.pipe(N.tap(s=>{if(!s){this._drawingManagerService.setDrawingVisible(!1);return}const o=t.getUnitId(),a=s.getSheetId();this._permissionService.composePermission([new D.WorkbookViewPermission(o).id,new D.WorksheetViewPermission(o,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(t,s)})):(this._drawingManagerService.setDrawingVisible(!1),N.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const e=i.getUnitId(),t=r.getSheetId(),n=this._drawingManagerService.getDrawingData(e,t),s=Object.values(n),o=this._renderManagerService.getRenderById(e),a=o==null?void 0:o.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&s.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,e=N.combineLatest([i,r]);this.disposeWithMe(e.pipe(N.switchMap(([t,n])=>t?t.activeSheet$.pipe(N.tap(s=>{if(!s){this._drawingManagerService.setDrawingEditable(!1);return}const o=t.getUnitId(),a=s.getSheetId();this._permissionService.composePermission([new D.WorkbookEditablePermission(o).id,new D.WorksheetEditPermission(o,a).id]).every(g=>g.value)?this._drawingManagerService.setDrawingEditable(!0):this._handleDrawingEditableFalse(t,s)})):(this._drawingManagerService.setDrawingEditable(!1),N.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const e=i.getUnitId(),t=r.getSheetId(),n=this._drawingManagerService.getDrawingData(e,t),s=Object.values(n),o=this._renderManagerService.getRenderById(e),a=o==null?void 0:o.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===k.RENDER_CLASS_TYPE.IMAGE&&s.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([e,t])=>e?e.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const s=e.getUnitId(),o=n.getSheetId(),a=this._renderManagerService.getRenderById(s),c=a==null?void 0:a.scene;if(!c)return N.EMPTY;const g=c.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookViewPermission(s).id,new D.WorksheetViewPermission(s,o).id]).pipe(N.map(d=>d.every(m=>m.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:c,transformer:g,unitId:s,subUnitId:o})))})):N.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:s,subUnitId:o})=>{this._drawingManagerService.setDrawingVisible(e);const a=t.getAllObjectsByOrder(),c=this._drawingManagerService.getDrawingData(s,o),g=Object.values(c);e?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&t.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),t=e==null?void 0:e.getActiveSheet(),n=e==null?void 0:e.getUnitId(),s=t==null?void 0:t.getSheetId();if(!n||!s)return;const o=this._drawingManagerService.getDrawingData(n,s),a=Object.values(o);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([e,t])=>e?e.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const s=e.getUnitId(),o=n.getSheetId(),a=this._renderManagerService.getRenderById(s),c=a==null?void 0:a.scene;if(!c)return N.EMPTY;const g=c.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookEditablePermission(s).id,new D.WorksheetEditPermission(s,o).id]).pipe(N.map(d=>d.every(m=>m.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:c,transformer:g,unitId:s,subUnitId:o})))})):N.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:s,subUnitId:o})=>{this._drawingManagerService.setDrawingEditable(e);const a=t.getAllObjectsByOrder(),c=this._drawingManagerService.getDrawingData(s,o),g=Object.values(c);e?(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&t.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&t.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),n=e.getActiveSheet();if(!n)return;const s=n.getSheetId(),o=this._renderManagerService.getRenderById(t),a=o==null?void 0:o.scene;if(!a)return;const c=this._drawingManagerService.getDrawingData(t,s),g=Object.values(c);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(d=>{d.classType===k.RENDER_CLASS_TYPE.IMAGE&&g.some(m=>d.oKey.includes(m.drawingId))&&a.detachTransformerFrom(d)})}}))}};at=bn([Ne(0,x.IDrawingManagerService),Ne(1,k.IRenderManagerService),Ne(2,l.IPermissionService),Ne(3,l.IUniverInstanceService),Ne(4,l.Inject(l.UserManagerService))],at);var En=Object.getOwnPropertyDescriptor,On=(i,r,e,t)=>{for(var n=t>1?void 0:t?En(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},pe=(i,r)=>(e,t)=>r(e,t,i);const Gt="univer-sheet-float-dom-";function Ht(i,r,e,t,n,s=!1){const{scaleX:o,scaleY:a}=r.getAncestorScale(),c=r.getViewport(k.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=t.getFreeze(),{startColumn:u,startRow:d,xSplit:m,ySplit:h}=g,p={left:!0,top:!0};if(!c)return{...i,absolute:p};const{left:S,right:f,top:v,bottom:I}=i;let{top:C,left:E,viewportScrollX:T,viewportScrollY:y}=c;const{boundsOfViewArea:R,scrollDirectionResponse:M}=n||{},{rowHeaderWidth:P,columnHeaderHeight:O}=e,U={top:s?0:O,left:s?0:P};R&&(l.Tools.isDefine(U.top)&&(U.top=R.top),l.Tools.isDefine(U.left)&&(U.left=R.left)),M==="HORIZONTAL"&&(y=0),M==="VERTICAL"&&(T=0);let _=0,b=0;const W=e.rowStartY(d-h)+O,B=e.colStartX(u-m)+P,J=e.rowStartY(d)+O,ne=e.colStartX(u)+P;if(m===0)p.left=!1,_=(S-T)*o,b=(f-T)*o;else{const z=S-(B-P),ee=f-(B-P);f<ne?(_=z*o,b=ee*o):S<=ne&&f>=ne?(_=z*o,b=Math.max(E,(f-T)*o)):S>ne&&(p.left=!1,_=Math.max((S-T)*o,E),b=Math.max((f-T)*o,E))}let K=0,q=0;if(h===0)p.top=!1,K=(v-y)*a,q=(I-y)*a;else{const z=v-(W-O),ee=I-(W-O);I<J?(K=z*a,q=ee*a):v<=J&&I>=J?(K=z*a,q=Math.max(C,(I-y)*a)):v>J&&(p.top=!1,K=Math.max((v-y)*a,C),q=Math.max((I-y)*a,C))}return _=Math.max(_,U.left),K=Math.max(K,U.top),b=Math.max(b,U.left),q=Math.max(q,U.top),{left:_,right:b,top:K,bottom:q,absolute:p}}const ae=(i,r,e,t,n)=>{const{left:s,top:o,width:a,height:c,angle:g}=i,u={left:s,right:s+a,top:o,bottom:o+c},d=Ht(u,r,e,t,n),{scaleX:m,scaleY:h}=r.getAncestorScale();return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:g,width:a*m,height:c*h,absolute:d.absolute}};exports.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(e,t,n,s,o,a,c){super();ie(this,"_domLayerInfoMap",new Map);ie(this,"_transformChange$",new N.Subject);ie(this,"transformChange$",this._transformChange$.asObservable());ie(this,"_add$",new N.Subject);ie(this,"add$",this._add$.asObservable());ie(this,"_remove$",new N.Subject);ie(this,"remove$",this._remove$.asObservable());this._renderManagerService=e,this._univerInstanceService=t,this._commandService=n,this._drawingManagerService=s,this._canvasFloatDomService=o,this._sheetDrawingService=a,this._lifecycleService=c,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(N.filter(e=>e===l.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(e){return this._domLayerInfoMap.get(e)}getFloatDomsBySubUnitId(e,t){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===t&&n.unitId===e)}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;const t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;if(t==null||n==null)return null;const s=n.getTransformerByCreate(),o=t.engine.getCanvasElement();return{scene:n,transformer:s,renderUnit:t,canvas:o}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(t=>{var ee;const{unitId:n,subUnitId:s,drawingId:o}=t,a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:s}),c=this._drawingManagerService.getDrawingByParam(t),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!c||!a)return;const d=(ee=this._renderManagerService.getRenderById(n))==null?void 0:ee.with(A.SheetSkeletonManagerService).getSkeletonParam(s);if(!d)return;const{transform:m,drawingType:h,data:p}=c;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(n);if(S==null)return;const{scene:f,canvas:v}=S;if(m==null)return!0;if(u!==s)return;const{left:I,top:C,width:E,height:T,angle:y,flipX:R,flipY:M,skewX:P,skewY:O}=m,U=x.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:s,drawingId:o}),_=f.getObject(U);if(_!=null){_.transformByState({left:I,top:C,width:E,height:T,angle:y,flipX:R,flipY:M,skewX:P,skewY:O});return}const b={left:I,top:C,width:E,height:T,zIndex:this._drawingManagerService.getDrawingOrder(n,s).length-1},W=h===l.DrawingTypeEnum.DRAWING_CHART;if(b.rotateEnabled=!1,W){const H=p?p.backgroundColor:"white";b.fill=H,p&&p.border&&(b.stroke=p.border),b.paintFirst="stroke",b.strokeWidth=1,b.borderEnabled=!1,b.radius=8}const B=new k.Rect(U,b);W&&B.setObjectType(k.ObjectType.CHART),f.addObject(B,k.DRAWING_OBJECT_LAYER_INDEX),c.allowTransform!==!1&&f.attachTransformerTo(B);const J=new l.DisposableCollection,ne=ae(B,S.renderUnit.scene,d.skeleton,a.worksheet),K=new N.BehaviorSubject(ne),q=`${Gt}${l.generateRandomId(6)}`,se={dispose:J,rect:B,position$:K,unitId:n,subUnitId:s,id:o,domId:q};this._canvasFloatDomService.addFloatDom({position$:K,id:o,domId:q,componentKey:c.componentKey,onPointerDown:H=>{v.dispatchEvent(new PointerEvent(H.type,H))},onPointerMove:H=>{v.dispatchEvent(new PointerEvent(H.type,H))},onPointerUp:H=>{v.dispatchEvent(new PointerEvent(H.type,H))},onWheel:H=>{v.dispatchEvent(new WheelEvent(H.type,H))},data:p,unitId:n});const z=B.onTransformChange$.subscribeEvent(()=>{const H=ae(B,S.renderUnit.scene,d.skeleton,a.worksheet);K.next(H)});J.add(()=>{this._canvasFloatDomService.removeFloatDom(o)}),z&&J.add(z),this._domLayerInfoMap.set(o,se)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{var m;const{unitId:n,subUnitId:s,drawingId:o}=t,a=x.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:s,drawingId:o}),c=this._getSceneAndTransformerByDrawingSearch(n);if(c==null)return;const{transformer:g,scene:u}=c,d=u.getObject(a);d!=null&&d.oKey&&(g.clearControlByIds([d==null?void 0:d.oKey]),(m=u.getTransformer())==null||m.clearSelectedObjects())})}))}_scrollUpdateListener(){const e=(t,n)=>{var g;const s=this._getSceneAndTransformerByDrawingSearch(t),o=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===t).map(u=>u.id),a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:n}),c=(g=this._renderManagerService.getRenderById(t))==null?void 0:g.with(A.SheetSkeletonManagerService).getSkeletonParam(n);!s||!a||!c||o.forEach(u=>{const d=this._domLayerInfoMap.get(u);if(d){const m=ae(d.rect,s.renderUnit.scene,c.skeleton,a.worksheet,d);d.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(t=>t?t.activeSheet$:N.of(null)),N.map(t=>{if(!t)return null;const n=t.getUnitId(),s=this._renderManagerService.getRenderById(n);return s?{render:s,unitId:n,subUnitId:t.getSheetId()}:null}),N.switchMap(t=>t?l.fromEventSubject(t.render.scene.getViewport(k.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(N.map(()=>({unitId:t.unitId,subUnitId:t.subUnitId}))):N.of(null))).subscribe(t=>{if(!t)return;const{unitId:n,subUnitId:s}=t;e(n,s)})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===A.SetZoomRatioOperation.id){const n=t.params,{unitId:s}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===s).map(a=>a.subUnitId).forEach(a=>{e(s,a)})}else if(t.id===D.SetFrozenMutation.id){const{unitId:n,subUnitId:s}=t.params;e(n,s)}else if(t.id===D.SetSelectionsOperation.id){const{unitId:n,subUnitId:s}=t.params;e(n,s)}}))}updateFloatDomProps(e,t,n,s){const o=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(e);if(o&&a){const{scene:c}=a,g=x.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:t,drawingId:n}),u=c.getObject(g);u&&u instanceof k.Rect&&u.setProps(s)}}_getPosition(e,t){var h;const{startX:n,endX:s,startY:o,endY:a}=e,c=(h=this._renderManagerService.getRenderById(t))==null?void 0:h.with(A.ISheetSelectionRenderService);if(c==null)return;const g=c.getCellWithCoordByOffset(n,o);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:o-g.startY},d=c.getCellWithCoordByOffset(s,a);if(d==null)return;const m={column:d.actualColumn,columnOffset:s-d.startX,row:d.actualRow,rowOffset:a-d.startY};return{from:u,to:m}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(t=>{const n=this._drawingManagerService.getDrawingByParam(t);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const s={...n.transform};this._transformChange$.next({id:t.drawingId,value:s}),this._canvasFloatDomService.updateFloatDom(t.drawingId,{...n});const o=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(o&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART){const{scene:a}=o,c=this._domLayerInfoMap.get(t.drawingId);c!=null&&c.rect&&(n.allowTransform===!1?a.detachTransformerFrom(c.rect):a.attachTransformerTo(c.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{this._removeDom(t.drawingId)})}))}addFloatDomToPosition(e,t){const n=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:s,subUnitId:o}=n,{initPosition:a,componentKey:c,data:g,allowTransform:u=!0}=e,d=t!=null?t:l.generateRandomId(),m=this._getPosition(a,s);if(m==null)return;const h={unitId:s,subUnitId:o,drawingId:d,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:c,sheetTransform:m,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},axisAlignSheetTransform:m,data:g,allowTransform:u};return this._commandService.executeCommand(je.id,{unitId:s,drawings:[h]}),this._add$.next({unitId:s,subUnitId:o,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(e,t=!1){const n=this._domLayerInfoMap.get(e);if(!n)return;const{unitId:s,subUnitId:o}=n;this._domLayerInfoMap.delete(e),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(s);if(a&&a.scene.removeObject(n.rect),t){const c=this._drawingManagerService.getDrawingByParam({unitId:s,subUnitId:o,drawingId:e});if(!c)return;const g=this._sheetDrawingService.getBatchRemoveOp([c]),{redo:u,objects:d}=g;this._commandService.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:s,subUnitId:o,op:u,objects:d,type:w.DrawingApplyType.REMOVE})}}addFloatDomToRange(e,t,n,s){var R,M,P;const o=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:c}=o,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(R=this._renderManagerService.getRenderById(a))==null?void 0:R.with(A.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:m,data:h,allowTransform:p=!0}=t,S=s!=null?s:l.generateRandomId(),{position:f,position$:v}=this._createRangePositionObserver(e,u,d.skeleton);if(this._getPosition(f,a)==null)return;const C=g.scene,{scaleX:E}=C.getAncestorScale(),T=Je(f,n,E),y={unitId:a,subUnitId:c,drawingId:S,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:T.startX,top:T.startY,width:T.width,height:T.height},data:h,allowTransform:p};{const{unitId:O,subUnitId:U,drawingId:_}=y,b=D.getSheetCommandTarget(this._univerInstanceService,{unitId:O,subUnitId:U}),W=y,B=this._univerInstanceService.getUnit(O,l.UniverInstanceType.UNIVER_SHEET);if(!B)return;const J=B.getActiveSheet().getSheetId();if(!W||!b)return;const ne=(M=this._renderManagerService.getRenderById(O))==null?void 0:M.with(A.SheetSkeletonManagerService);if(!ne)return;const K=ne.getWorksheetSkeleton(U);if(!K)return;const{transform:q,drawingType:se,data:z}=W;if(se!==l.DrawingTypeEnum.DRAWING_DOM&&se!==l.DrawingTypeEnum.DRAWING_CHART)return;const ee=this._getSceneAndTransformerByDrawingSearch(O);if(ee==null)return;const{scene:H,canvas:fe}=ee;if(q==null||J!==U)return;const{left:Be,top:Fe,width:Le,height:$e,angle:ut,flipX:gt,flipY:Ye,skewX:Ge,skewY:we}=q,He=x.getDrawingShapeKeyByDrawingSearch({unitId:O,subUnitId:U,drawingId:_}),ce=H.getObject(He);if(ce!=null){ce.transformByState({left:Be,top:Fe,width:Le,height:$e,angle:ut,flipX:gt,flipY:Ye,skewX:Ge,skewY:we});return}const re={left:Be,top:Fe,width:Le,height:$e,zIndex:this._drawingManagerService.getDrawingOrder(O,U).length-1},ve=se===l.DrawingTypeEnum.DRAWING_CHART;if(ve){const F=z?z.backgroundColor:"white";re.fill=F,re.rotateEnabled=!1,z&&z.border&&(re.stroke=z.border),re.paintFirst="stroke",re.strokeWidth=1,re.borderEnabled=!1,re.radius=8}const de=new k.Rect(He,re);ve&&de.setObjectType(k.ObjectType.CHART),H.addObject(de,k.DRAWING_OBJECT_LAYER_INDEX),W.allowTransform!==!1&&H.attachTransformerTo(de);const le=new l.DisposableCollection,Ve=H.getMainViewport(),{rowHeaderWidth:_e,columnHeaderHeight:Ee}=K.skeleton,Xe={top:Ee,left:_e,bottom:Ve.bottom,right:Ve.right},ue={dispose:le,rect:de,boundsOfViewArea:Xe,domAnchor:n,unitId:O,subUnitId:U},V=ae(de,ee.renderUnit.scene,K.skeleton,b.worksheet,ue),Ie=new N.BehaviorSubject(V);ue.position$=Ie;let Oe={position$:Ie,id:_,componentKey:W.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:F=>{fe.dispatchEvent(new WheelEvent(F.type,F))},data:z,unitId:O};t.eventPassThrough&&(Oe={...Oe,onPointerDown:F=>{fe.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{fe.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{fe.dispatchEvent(new PointerEvent(F.type,F))}}),this._canvasFloatDomService.addFloatDom(Oe),this.disposeWithMe(v.subscribe(F=>{var Ot,At,Ut,Pt;const Et=Je({startX:F.startX,startY:F.startY,endX:F.endX,endY:F.endY,width:(Ot=n.width)!=null?Ot:F.width,height:(At=n.height)!=null?At:F.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),Kt=x.getDrawingShapeKeyByDrawingSearch({unitId:O,subUnitId:U,drawingId:_}),zt=new k.Rect(Kt,{left:Et.startX,top:Et.startY,width:(Ut=n.width)!=null?Ut:F.width,height:(Pt=n.height)!=null?Pt:F.height,zIndex:this._drawingManagerService.getDrawingOrder(O,U).length-1}),qt=ae(zt,ee.renderUnit.scene,K.skeleton,b.worksheet,ue);Ie.next(qt)}));const Ae=(P=this._renderManagerService.getRenderById(O))==null?void 0:P.with(A.SheetSkeletonManagerService);Ae==null||Ae.currentSkeleton$.subscribe(F=>{F&&K.sheetId!==F.sheetId&&this._removeDom(S,!0)});const Ke=de.onTransformChange$.subscribeEvent(()=>{const F=ae(de,ee.renderUnit.scene,K.skeleton,b.worksheet,ue);Ie.next(F)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(_)}),Ke&&le.add(Ke),this._domLayerInfoMap.set(_,ue)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(e,t,n,s){var T,y,R;const o=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!o)throw new Error("cannot find current target!");const{unitId:a,subUnitId:c}=o;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(T=this._renderManagerService.getRenderById(a))==null?void 0:T.with(A.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:m,data:h,allowTransform:p=!0}=t,S=s!=null?s:l.generateRandomId(),{position:f,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:e,endColumn:e},u,d.skeleton),I=f;if(I.startY=0,this._getPosition(f,a)==null)return;const E={unitId:a,subUnitId:c,drawingId:S,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:p};{const{unitId:M,subUnitId:P,drawingId:O}=E,U=D.getSheetCommandTarget(this._univerInstanceService,{unitId:M,subUnitId:P}),_=E,b=this._univerInstanceService.getUnit(M,l.UniverInstanceType.UNIVER_SHEET);if(!b)return;const W=b.getActiveSheet().getSheetId();if(!_||!U)return;const B=(y=this._renderManagerService.getRenderById(M))==null?void 0:y.with(A.SheetSkeletonManagerService);if(!B)return;const J=B.getWorksheetSkeleton(P);if(!J)return;const{transform:ne,data:K}=_,q=this._getSceneAndTransformerByDrawingSearch(M);if(q==null)return;const{scene:se,canvas:z}=q;if(ne==null||W!==P)return;const{left:ee,top:H,width:fe,height:Be,angle:Fe,flipX:Le,flipY:$e,skewX:ut,skewY:gt}=ne,Ye=x.getDrawingShapeKeyByDrawingSearch({unitId:M,subUnitId:P,drawingId:O}),Ge=se.getObject(Ye);if(Ge!=null){Ge.transformByState({left:ee,top:H,width:fe,height:Be,angle:Fe,flipX:Le,flipY:$e,skewX:ut,skewY:gt});return}const we=Je({startX:I.startX,startY:0,endX:f.endX,endY:f.endY,width:n.width,height:n.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),He={left:we.startX,top:we.startY,width:we.width,height:we.height,zIndex:this._drawingManagerService.getDrawingOrder(M,P).length-1},ce=new k.Rect(Ye,He);se.addObject(ce,k.DRAWING_OBJECT_LAYER_INDEX),_.allowTransform!==!1&&se.attachTransformerTo(ce);const re=new l.DisposableCollection,ve=se.getMainViewport(),de={top:0,left:ve.left,bottom:ve.bottom,right:ve.right},le={dispose:re,rect:ce,unitId:M,subUnitId:P,boundsOfViewArea:de,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},Ve=ae(ce,q.renderUnit.scene,J.skeleton,U.worksheet,le),_e=new N.BehaviorSubject(Ve);le.position$=_e;let Ee={position$:_e,id:O,componentKey:_.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:V=>{z.dispatchEvent(new WheelEvent(V.type,V))},data:K,unitId:M};t.eventPassThrough&&(Ee={...Ee,onPointerDown:V=>{z.dispatchEvent(new PointerEvent(V.type,V))},onPointerMove:V=>{z.dispatchEvent(new PointerEvent(V.type,V))},onPointerUp:V=>{z.dispatchEvent(new PointerEvent(V.type,V))}}),this._canvasFloatDomService.addFloatDom(Ee);const Xe=ce.onTransformChange$.subscribeEvent(()=>{const V=ae(ce,q.renderUnit.scene,J.skeleton,U.worksheet,le);_e.next(V)});this.disposeWithMe(v.subscribe(V=>{const Ie=Je({startX:V.startX,startY:0,endX:V.endX,endY:V.endY,width:n.width,height:n.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),Oe=x.getDrawingShapeKeyByDrawingSearch({unitId:M,subUnitId:P,drawingId:O}),Ae=new k.Rect(Oe,{left:Ie.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(M,P).length-1}),Ke=ae(Ae,q.renderUnit.scene,J.skeleton,U.worksheet,le);_e.next(Ke)}));const ue=(R=this._renderManagerService.getRenderById(M))==null?void 0:R.with(A.SheetSkeletonManagerService);ue==null||ue.currentSkeleton$.subscribe(V=>{V&&d.sheetId!==V.sheetId&&this._removeDom(S,!0)}),re.add(()=>{this._canvasFloatDomService.removeFloatDom(O)}),Xe&&re.add(Xe),this._domLayerInfoMap.set(O,le)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(e,t,n){let{startRow:s,startColumn:o}=e;const a=xe(s,o,n),c=new N.BehaviorSubject(a),g=xe(e.endRow,e.endColumn,n),u=new N.BehaviorSubject(g),d=()=>{const v=xe(s,o,n),I=xe(e.endRow,e.endColumn,n);c.next(v),u.next(I)},m=new l.DisposableCollection;m.add(t.engine.clientRect$.subscribe(()=>d())),m.add(this._commandService.onCommandExecuted(v=>{if(v.id===D.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(C=>C.row===s)>-1){d();return}(D.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===A.SetScrollOperation.id||v.id===A.SetZoomRatioOperation.id)&&d()}));const h=(v,I)=>{s=v,o=I,d()},p=()=>({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}),S=c.pipe(N.map(v=>{const I=xe(e.endRow,e.endColumn,n);return{rotate:0,width:I.right-v.left,height:I.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:I.right,endY:I.bottom}})),f=p();return{position$:S,position:f,updateRowCol:h,topLeftPos$:c,rightBottomPos$:u,disposable:m}}};exports.SheetCanvasFloatDomManagerService=On([pe(0,l.Inject(k.IRenderManagerService)),pe(1,l.IUniverInstanceService),pe(2,l.Inject(l.ICommandService)),pe(3,x.IDrawingManagerService),pe(4,l.Inject(j.CanvasFloatDomService)),pe(5,w.ISheetDrawingService),pe(6,l.Inject(l.LifecycleService))],exports.SheetCanvasFloatDomManagerService);function xe(i,r,e){const t=e.getCellWithCoordByIndex(i,r),n=t.isMergedMainCell?t.mergeInfo:t;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Je(i,r,e){var g,u;e=e!=null?e:1;const t=i.endX-i.startX,n=i.endY-i.startY,s=(g=r==null?void 0:r.width)!=null?g:t,o=(u=r==null?void 0:r.height)!=null?u:n;let a=0,c=0;if(r){if(r.horizonOffsetAlign==="right"){const d=Qe(r.marginX,t*e);a=i.endX-d-s}else a=i.startX+Qe(r.marginX,t);if(r.verticalOffsetAlign==="bottom"){const d=Qe(r.marginY,n*e);c=i.endY-d-o}else c=i.startY+Qe(r.marginY,n)}return{rotate:0,startX:a,startY:c,endX:i.endX,endY:i.endY,width:s,height:o,absolute:{left:i.absolute.left,top:i.absolute.top}}}function Qe(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const e=Number.parseFloat(i);return r*e/100}const An=i=>{const{floatDomInfos:r,scene:e,skeleton:t,worksheet:n}=i,s=Z.useMemo(()=>r.map(o=>{const{width:a,height:c,angle:g,left:u,top:d}=o.transform,m=Ht({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:d!=null?d:0,bottom:(d!=null?d:0)+(c!=null?c:0)},e,t,n,void 0,!0),{scaleX:h,scaleY:p}=e.getAncestorScale(),S={startX:m.left,endX:m.right,startY:m.top,endY:m.bottom,rotate:g,width:a*h,height:c*p,absolute:m.absolute},f={position$:new N.BehaviorSubject(S),position:S,id:o.drawingId,componentKey:o.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:o.unitId,data:o.data};return[o.drawingId,f]}),[r,e,t,n]);return L.jsx("div",{style:{position:"absolute",top:0,left:0},children:s.map(([o,a])=>L.jsx(j.PrintFloatDomSingle,{layer:a,id:o,position:a.position},o))})};var Un=Object.getOwnPropertyDescriptor,Pn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Un(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},Se=(i,r)=>(e,t)=>r(e,t,i);let ct=class extends l.Disposable{constructor(i,r,e,t,n,s,o){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=e,this._renderManagerService=t,this._canvasFloatDomManagerService=n,this._componetManager=s,this._injector=o,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,e)=>{const{unitId:t,scene:n,subUnitId:s}=r,o=this._drawingManagerService.getDrawingDataForUnit(t),a=o==null?void 0:o[s];return a&&a.order.forEach(c=>{const g=a.data[c];g.drawingType!==l.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),e()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,e)=>{const{unitId:t,subUnitId:n}=r,s=this._renderManagerService.getRenderById(t);if(!s)return e(i);const o=s.with(A.SheetSkeletonManagerService).getSkeletonParam(n);if(!o)return e(i);const a=this._drawingManagerService.getDrawingDataForUnit(t),c=a==null?void 0:a[r.subUnitId];if(!c)return e(i);const{scaleX:g,scaleY:u}=s.scene,d=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=c.order.map(h=>c.data[h]);return m.length?(m.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 p=o.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),S=o.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});p.column<d.startColumn&&(d.startColumn=p.column),p.row<d.startRow&&(d.startRow=p.row),d.endRow<S.row&&(d.endRow=S.row),d.endColumn<S.column&&(d.endColumn=S.column)}}),e(d)):e(i)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(i,r,e)=>{const{unitId:t,subUnitId:n}=r,s=this._drawingManagerService.getDrawingDataForUnit(t),o=s==null?void 0:s[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 d=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(d||u.componentKey)}}return null}).filter(Boolean),c=j.connectInjector(An,this._injector);return G.render(L.jsx(c,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{G.unmount(r.root)}),e(i)}}}))}};ct=Pn([Se(0,l.Inject(A.SheetPrintInterceptorService)),Se(1,l.Inject(me.DrawingRenderService)),Se(2,x.IDrawingManagerService),Se(3,k.IRenderManagerService),Se(4,l.Inject(exports.SheetCanvasFloatDomManagerService)),Se(5,l.Inject(j.ComponentManager)),Se(6,l.Inject(l.Injector))],ct);var Nn=Object.getOwnPropertyDescriptor,xn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Nn(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ge=(i,r)=>(e,t)=>r(e,t,i);const jn=[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],kn=[D.SetRowVisibleMutation.id,D.SetRowHiddenMutation.id,D.SetColVisibleMutation.id,D.SetColHiddenMutation.id,D.SetWorksheetRowHeightMutation.id,D.SetWorksheetRowAutoHeightMutation.id,D.SetWorksheetRowIsAutoHeightMutation.id,D.SetWorksheetColWidthMutation.id];let _t=class extends l.Disposable{constructor(i,r,e,t,n,s,o,a,c){super(),this._context=i,this._renderManagerService=r,this._commandService=e,this._selectionRenderService=t,this._skeletonManagerService=n,this._sheetInterceptorService=s,this._sheetDrawingService=o,this._drawingManagerService=a,this._univerInstanceService=c,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({getMutations:i=>{if(!jn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===D.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===D.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===D.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===D.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===D.DeleteRangeMoveLeftCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,0)}else if(r===D.DeleteRangeMoveUpCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,1)}else if(r===D.InsertRangeMoveDownCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,2)}else if(r===D.InsertRangeMoveRightCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,3)}else if(r===D.SetRowHiddenCommand.id||r===D.SetSpecificRowsVisibleCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:s}=e;return this._getDrawingUndoForRowVisible(t,n,s)}else if(r===D.SetSpecificColsVisibleCommand.id||r===D.SetColHiddenCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:s}=e;return this._getDrawingUndoForColVisible(t,n,s)}else if(r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id||r===D.DeltaColumnWidthCommand.id||r===D.SetColWidthCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:s}=e,o=r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(t,n,s,o)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const e=D.getSheetCommandTarget(this._univerInstanceService);if(e==null)return{redos:[],undos:[]};const t=e.unitId,n=e.subUnitId,s=[],o=[],a=this._sheetDrawingService.getDrawingData(t,n),c=[],g=[];if(Object.keys(a).forEach(u=>{const d=a[u],{updateDrawings:m,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,d);c.push(...m),g.push(...h)}),c.length===0&&g.length===0)return{redos:[],undos:[]};if(c.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(c),{undo:d,redo:m,objects:h}=u;s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:m,objects:h,type:w.DrawingApplyType.UPDATE}}),o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:h,type:w.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),d=u.undo,m=u.redo,h=u.objects;s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:m,objects:h,type:w.DrawingApplyType.REMOVE}}),o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:h,type:w.DrawingApplyType.INSERT}})}return s.push({id:X.id,params:[t]}),o.push({id:X.id,params:[t]}),{redos:s,undos:o}}_getUpdateOrDeleteDrawings(i,r,e){var M,P,O,U;const t=[],n=[],{sheetTransform:s,anchorType:o=w.SheetDrawingAnchorType.Position,transform:a,unitId:c,subUnitId:g,drawingId:u}=e,{from:d,to:m}=s,{row:h,column:p}=d,{row:S,column:f}=m;if(s==null||a==null)return{updateDrawings:t,deleteDrawings:n};const{startRow:v,endRow:I,startColumn:C,endColumn:E}=i;let T=null,y=null,R;if(r===0&&h>=v&&S<=I)if(p>=C&&f<=E)n.push({unitId:c,subUnitId:g,drawingId:u});else{const _=this._shrinkCol(s,a,C,E,o);T=_==null?void 0:_.newSheetTransform,y=_==null?void 0:_.newTransform,R=(M=_==null?void 0:_.axisAlignSheetTransform)!=null?M:void 0}else if(r===1&&p>=C&&f<=E)if(h>=v&&S<=I)n.push({unitId:c,subUnitId:g,drawingId:u});else{const _=this._shrinkRow(s,a,v,I,o);T=_==null?void 0:_.newSheetTransform,y=_==null?void 0:_.newTransform,R=(P=_==null?void 0:_.axisAlignSheetTransform)!=null?P:void 0}else if(r===2){const _=this._expandRow(s,a,v,I,o);T=_==null?void 0:_.newSheetTransform,y=_==null?void 0:_.newTransform,R=(O=_==null?void 0:_.axisAlignSheetTransform)!=null?O:void 0}else if(r===3){const _=this._expandCol(s,a,C,E,o);T=_==null?void 0:_.newSheetTransform,y=_==null?void 0:_.newTransform,R=(U=_==null?void 0:_.axisAlignSheetTransform)!=null?U:void 0}if(T!=null&&y!=null){const _=Q(T,this._selectionRenderService,this._skeletonManagerService);t.push({...e,sheetTransform:T,transform:_,axisAlignSheetTransform:R})}return{updateDrawings:t,deleteDrawings:n}}_remainDrawingSize(i,r,e){const t=$({...i},this._selectionRenderService);if(t!=null){const n=Y({...i},this._selectionRenderService);r.push({...e,sheetTransform:t,axisAlignSheetTransform:n})}}_getDrawingUndoForColVisible(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[],s=[];if(Object.keys(t).forEach(u=>{const d=t[u],{sheetTransform:m,transform:h,anchorType:p=w.SheetDrawingAnchorType.Position}=d;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:f}=m,{row:v,column:I}=S,{row:C,column:E}=f;for(let T=0;T<e.length;T++){const y=e[T],{startRow:R,endRow:M,startColumn:P,endColumn:O}=y;if(E<P)continue;if(p===w.SheetDrawingAnchorType.Position){let b=null,W=null;if(I>=P&&I<=O){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:O,startRow:S.row,endRow:f.row});if(B==null)return;W={...h,left:B.startX}}if(W!=null){b=$(W,this._selectionRenderService);const B=Y(W,this._selectionRenderService);if(b!=null&&W!=null){n.push({...d,sheetTransform:b,transform:W,axisAlignSheetTransform:B});break}}this._remainDrawingSize(h,n,d);continue}if(I>=P&&E<=O)continue;let U=null,_=null;if(I>=P&&I<=O){const b=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:O,startRow:S.row,endRow:f.row});if(b==null)return;_={...h,left:(b==null?void 0:b.startX)||0,width:((h==null?void 0:h.width)||0)-b.endX+b.startX}}else if(E>=P&&E<=O){const b=this._skeletonManagerService.attachRangeWithCoord({startColumn:P,endColumn:E,startRow:S.row,endRow:f.row});if(b==null)return;_={...h,left:b.startX-((h==null?void 0:h.width)||0)}}else{const b=this._skeletonManagerService.attachRangeWithCoord({startColumn:P,endColumn:O,startRow:S.row,endRow:f.row});if(b==null)return;if(_={...h,width:((h==null?void 0:h.width)||0)-b.endX+b.startX},U=$(_,this._selectionRenderService),U!=null&&_!=null){const W=Y(_,this._selectionRenderService);s.push({...d,sheetTransform:U,transform:_,axisAlignSheetTransform:W});break}}if(_!=null&&(U=$(_,this._selectionRenderService)),_!=null&&U!=null){const b=Y(_,this._selectionRenderService);n.push({...d,sheetTransform:U,transform:_,axisAlignSheetTransform:b});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&s.length===0)return{redos:[],undos:[]};const{redos:o,undos:a}=this._createUndoAndRedoMutation(i,r,n),c=[],g=[];if(s.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,s);c.push(...u),g.push(...d)}return{redos:o,undos:a,preRedos:c,preUndos:g}}_createUndoAndRedoMutation(i,r,e){const t=this._sheetDrawingService.getBatchUpdateOp(e),{undo:n,redo:s,objects:o}=t,a=[{id:w.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:s,objects:o,type:w.DrawingApplyType.UPDATE}},{id:X.id,params:[i]}],c=[{id:w.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:o,type:w.DrawingApplyType.UPDATE}},{id:X.id,params:[i]}];return{redos:a,undos:c}}_getDrawingUndoForRowVisible(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[],s=[];if(Object.keys(t).forEach(u=>{const d=t[u],{sheetTransform:m,transform:h,anchorType:p=w.SheetDrawingAnchorType.Position}=d;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:f}=m,{row:v,column:I}=S,{row:C,column:E}=f;for(let T=0;T<e.length;T++){const y=e[T],{startRow:R,endRow:M,startColumn:P,endColumn:O}=y;if(C<R)continue;if(p===w.SheetDrawingAnchorType.Position){let b=null,W=null;if(v>=R&&v<=M){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:v,endRow:M});if(B==null)return;W={...h,top:B.startY}}if(W!=null){b=$(W,this._selectionRenderService);const B=Y(W,this._selectionRenderService);if(b!=null&&W!=null){n.push({...d,sheetTransform:b,transform:W,axisAlignSheetTransform:B});break}}this._remainDrawingSize(h,n,d);continue}if(v>=R&&C<=M)continue;let U=null,_=null;if(v>=R&&v<=M){const b=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:v,endRow:M});if(b==null)return;_={...h,top:(b==null?void 0:b.startY)||0,height:((h==null?void 0:h.height)||0)-b.endY+b.startY}}else if(C>=R&&C<=M){const b=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:R,endRow:C});if(b==null)return;_={...h,top:b.startY-((h==null?void 0:h.height)||0)}}else{const b=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:R,endRow:M});if(b==null)return;if(_={...h,height:((h==null?void 0:h.height)||0)-b.endY+b.startY},U=$(_,this._selectionRenderService),U!=null&&_!=null){const W=Y(_,this._selectionRenderService);s.push({...d,sheetTransform:U,transform:_,axisAlignSheetTransform:W});break}}if(_!=null&&(U=$(_,this._selectionRenderService)),_!=null&&U!=null){const b=Y(_,this._selectionRenderService);n.push({...d,sheetTransform:U,transform:_,axisAlignSheetTransform:b});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&s.length===0)return{redos:[],undos:[]};const{redos:o,undos:a}=this._createUndoAndRedoMutation(i,r,n),c=[],g=[];if(s.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,s);c.push(...u),g.push(...d)}return{redos:o,undos:a,preRedos:c,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,e,t){const n=this._drawingManagerService.getDrawingData(i,r),s=[];return Object.keys(n).forEach(o=>{const a=n[o],{sheetTransform:c,transform:g,anchorType:u=w.SheetDrawingAnchorType.Position}=a;if(u===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,s,a);else{const{from:d,to:m}=c,{row:h,column:p}=d,{row:S,column:f}=m;for(let v=0;v<e.length;v++){const I=e[v],{startRow:C,endRow:E,startColumn:T,endColumn:y}=I;if(S<C||f<T)continue;if(u===w.SheetDrawingAnchorType.Position&&(h<=C&&S>=E||p<=T&&f>=y)){this._remainDrawingSize(g,s,a);continue}const R=Q({...c},this._selectionRenderService,this._skeletonManagerService);if(R!=null){s.push({...a,transform:R});break}}}}),s.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,s)}_getUnitIdAndSubUnitId(i,r){let e,t;if(r==="insert")e=i.unitId,t=i.subUnitId;else{const n=D.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;e=n.unitId,t=n.subUnitId}return{unitId:e,subUnitId:t}}_moveRangeInterceptor(i){var C,E;const{toRange:r,fromRange:e}=i,t=D.getSheetCommandTarget(this._univerInstanceService);if(!t)return{redos:[],undos:[]};const{unitId:n,subUnitId:s}=t,o=(E=(C=this._renderManagerService.getRenderById(n))==null?void 0:C.with(A.SheetSkeletonManagerService))==null?void 0:E.getCurrentSkeleton();if(!o)return{redos:[],undos:[]};const a=A.attachRangeWithCoord(o,e);if(!a)return{redos:[],undos:[]};const{startX:c,endX:g,startY:u,endY:d}=a,m=this._sheetDrawingService.getDrawingData(n,s),h=[];Object.keys(m).forEach(T=>{const y=m[T];if(y.anchorType!==w.SheetDrawingAnchorType.Both)return;const{transform:R}=y;if(!R)return;const{left:M=0,top:P=0,width:O=0,height:U=0}=R,{drawingStartX:_,drawingEndX:b,drawingStartY:W,drawingEndY:B}={drawingStartX:M,drawingEndX:M+O,drawingStartY:P,drawingEndY:P+U};c<=_&&b<=g&&u<=W&&B<=d&&h.push(y)});const p=[],S=[],f=r.startRow-e.startRow,v=r.startColumn-e.startColumn,I=h.map(T=>{const y=T.sheetTransform,R={to:{...y.to,row:y.to.row+f,column:y.to.column+v},from:{...y.from,row:y.from.row+f,column:y.from.column+v}},M=Q(R,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:s,drawingId:T.drawingId,transform:M,sheetTransform:R}});if(I.length){const T=this._sheetDrawingService.getBatchUpdateOp(I),{undo:y,redo:R,objects:M}=T;p.push({id:w.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:s,op:R,objects:M,type:w.DrawingApplyType.UPDATE}}),S.push({id:w.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:s,op:y,objects:M,type:w.DrawingApplyType.UPDATE}})}return{redos:p,undos:S}}_moveRowInterceptor(i,r){const e=this._getUnitIdAndSubUnitId(i,r);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=e,{range:s}=i,o=s.startRow,a=s.endRow,c=[],g=[],u=this._sheetDrawingService.getDrawingData(t,n),d=[],m=[];if(Object.keys(u).forEach(h=>{var y,R;const p=u[h],{sheetTransform:S,transform:f,anchorType:v=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,C,E;if(r==="insert"){const M=this._expandRow(S,f,o,a,v);I=M==null?void 0:M.newSheetTransform,C=M==null?void 0:M.newTransform,E=(y=M==null?void 0:M.axisAlignSheetTransform)!=null?y:void 0}else{const{from:M,to:P}=S,{row:O}=M,{row:U}=P;if(v===w.SheetDrawingAnchorType.Both&&O>=o&&U<=a)m.push({unitId:t,subUnitId:n,drawingId:h});else{const _=this._shrinkRow(S,f,o,a,v);I=_==null?void 0:_.newSheetTransform,C=_==null?void 0:_.newTransform,E=(R=_==null?void 0:_.axisAlignSheetTransform)!=null?R:void 0}}if(!I||!C)return;const T={unitId:t,subUnitId:n,drawingId:h,transform:C,sheetTransform:I,axisAlignSheetTransform:E};d.push(T)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:S,objects:f}=h;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),p=h.undo,S=h.redo,f=h.objects;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return c.push({id:X.id,params:[t]}),g.push({id:X.id,params:[t]}),{redos:c,undos:g}}_moveColInterceptor(i,r){const e=this._getUnitIdAndSubUnitId(i,r);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=e,{range:s}=i,o=s.startColumn,a=s.endColumn,c=[],g=[],u=this._sheetDrawingService.getDrawingData(t,n),d=[],m=[];if(Object.keys(u).forEach(h=>{var y,R;const p=u[h],{sheetTransform:S,transform:f,anchorType:v=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,C,E;if(r==="insert"){const M=this._expandCol(S,f,o,a,v);I=M==null?void 0:M.newSheetTransform,C=M==null?void 0:M.newTransform,E=(y=M==null?void 0:M.axisAlignSheetTransform)!=null?y:void 0}else{const{from:M,to:P}=S,{column:O}=M,{column:U}=P;if(v===w.SheetDrawingAnchorType.Both&&O>=o&&U<=a)m.push({unitId:t,subUnitId:n,drawingId:h});else{const _=this._shrinkCol(S,f,o,a,v);I=_==null?void 0:_.newSheetTransform,C=_==null?void 0:_.newTransform,E=(R=_==null?void 0:_.axisAlignSheetTransform)!=null?R:void 0}}if(!I||!C)return;const T={unitId:t,subUnitId:n,drawingId:h,transform:C,sheetTransform:I,axisAlignSheetTransform:E};d.push(T)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:S,objects:f}=h;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),p=h.undo,S=h.redo,f=h.objects;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return c.push({id:X.id,params:[t]}),g.push({id:X.id,params:[t]}),{redos:c,undos:g}}_expandCol(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const s=t-e+1,{from:o,to:a}=i,{column:c}=o,{column:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};let u=null,d=null,m=null;if(c>=e){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:t,startRow:o.row,endRow:a.row});if(h==null)return;d={...r,left:(r.left||0)+h.endX-h.startX},u=$(d,this._selectionRenderService),m=Y(d,this._selectionRenderService)}else if(g>=t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,column:g+s}},d=Q(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d,axisAlignSheetTransform:m}:null}_shrinkCol(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const s=t-e+1,{from:o,to:a}=i,{column:c}=o,{column:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};let u=null,d=null,m=null;if(c>t)u={from:{...o,column:c-s},to:{...a,column:g-s}},d=Q(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=e&&g<=t)return null;if(c<e&&g>t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,column:g-s}},d=Q(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};else if(c>=e&&c<=t){if(c===e)d={...r,left:(r.left||0)-i.from.columnOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:c-1,startRow:o.row,endRow:a.row});if(h==null)return;d={...r,left:(r.left||0)-h.endX+h.startX-i.from.columnOffset}}u=$(d,this._selectionRenderService),m=Y(d,this._selectionRenderService)}else if(g>=e&&g<=t&&n===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:e-1,endColumn:e-1,startRow:o.row,endRow:a.row});if(h==null)return;u={from:{...o},to:{...a,column:e-1,columnOffset:h.endX-h.startX}},d=Q(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d,axisAlignSheetTransform:m}:null}_expandRow(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const s=t-e+1,{from:o,to:a}=i,{row:c}=o,{row:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};let u=null,d=null,m=null;if(c>=e){const h=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:t,startColumn:o.column,endColumn:a.column});if(h==null)return;d={...r,top:(r.top||0)+h.endY-h.startY},u=$(d,this._selectionRenderService),m=Y(d,this._selectionRenderService)}else if(g>=t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,row:g+s}},d=Q(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d,axisAlignSheetTransform:m}:null}_shrinkRow(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const s=t-e+1,{from:o,to:a}=i,{row:c}=o,{row:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};let u=null,d=null,m=null;if(c>t)u={from:{...o,row:c-s},to:{...a,row:g-s}},d=Q(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=e&&g<=t)return null;if(c<e&&g>t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...o},to:{...a,row:g-s}},d=Q(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};else if(c>=e&&c<=t){if(c===e)d={...r,top:(r.top||0)-i.from.rowOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:c-1,startColumn:o.column,endColumn:a.column});if(h==null)return;d={...r,top:(r.top||0)-h.endY+h.startY-i.from.rowOffset}}u=$(d,this._selectionRenderService),m=Y(d,this._selectionRenderService)}else if(g>=e&&g<=t&&n===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:o.column,endColumn:o.column,startRow:e-1,endRow:e-1});if(h==null)return;u={from:{...o},to:{...a,row:e-1,rowOffset:h.endY-h.startY}},d=Q(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d,axisAlignSheetTransform:m}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===D.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:e}=i.params;this._updateDrawings(r,e)}})),this.disposeWithMe(this._context.activated$.subscribe(i=>{const{unit:r,unitId:e}=this._context;if(i){const t=r.getActiveSheet().getSheetId();this._updateDrawings(e,t)}else this._clearDrawings(e)}))}_clearDrawings(i){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,e=[];Object.keys(r).forEach(t=>{const n=r[t];n!=null&&Object.keys(n).forEach(s=>{const o=n[s].data;o!=null&&Object.keys(o).forEach(a=>{t===i&&e.push(o[a])})})}),this._sheetDrawingService.removeNotification(e),this._drawingManagerService.removeNotification(e)})}_updateDrawings(i,r){setTimeout(()=>{const e=this._drawingManagerService.drawingManagerData,t=[],n=[];Object.keys(e).forEach(s=>{const o=e[s];o!=null&&Object.keys(o).forEach(a=>{const c=o[a].data;c!=null&&Object.keys(c).forEach(g=>{if(s===i&&a===r){const u=c[g];u.transform=Q(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),t.push(c[g])}else n.push(c[g])})})}),this._sheetDrawingService.removeNotification(n),this._sheetDrawingService.addNotification(t),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(t)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{kn.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,e=D.getSheetCommandTarget(this._univerInstanceService,r);if(!e)return;const{unitId:t,subUnitId:n,worksheet:s}=e;let o=[];"ranges"in r?o=r.ranges:"rowsAutoHeightInfo"in r&&(o=r.rowsAutoHeightInfo.map(a=>({startRow:a.row,endRow:a.row,startColumn:0,endColumn:s.getColumnCount()-1}))),this._refreshDrawingTransform(t,n,o)})}))}_refreshDrawingTransform(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(t).forEach(s=>{const o=t[s],{sheetTransform:a,transform:c,anchorType:g=w.SheetDrawingAnchorType.Position}=o;if(g===w.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=a,{row:m,column:h}=u,{row:p,column:S}=d;for(let f=0;f<e.length;f++){const v=e[f],{startRow:I,endRow:C,startColumn:E,endColumn:T}=v;if(l.Rectangle.intersects({startRow:I,endRow:C,startColumn:E,endColumn:T},{startRow:m,endRow:p,startColumn:h,endColumn:S})||m>C||h>T){const y=g===w.SheetDrawingAnchorType.Position,R=Q(a,this._selectionRenderService,this._skeletonManagerService);n.push({...o,transform:{...R,width:y?c==null?void 0:c.width:R==null?void 0:R.width,height:y?c==null?void 0:c.height:R==null?void 0:R.height}});break}}}),n.length!==0&&(this._sheetDrawingService.refreshTransform(n),this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(X.id,[i]))}};_t=xn([ge(1,k.IRenderManagerService),ge(2,l.ICommandService),ge(3,A.ISheetSelectionRenderService),ge(4,l.Inject(A.SheetSkeletonManagerService)),ge(5,l.Inject(D.SheetInterceptorService)),ge(6,w.ISheetDrawingService),ge(7,x.IDrawingManagerService),ge(8,l.IUniverInstanceService)],_t);function Wn(){const i=j.useDependency(l.LocaleService),r=j.useDependency(j.IDialogService),e=j.useDependency(lt),[t,n]=Z.useState([he.CELL_ADDRESS]),[s,o]=Z.useState(!1),[a,c]=Z.useState(null),g=Z.useMemo(()=>e.getCellImagesInSelection(),[e]),u=Z.useMemo(()=>e.getDataColumns(),[e]),d=Z.useMemo(()=>e.getSelectionRowRange(),[e]),m=u.length>0,h=Z.useMemo(()=>u.map(y=>({label:y.label,value:String(y.index)})),[u]),[p,S]=Z.useState(()=>h.length>0?h[0].value:"0"),f=Z.useMemo(()=>{if(!t.includes(he.COLUMN_VALUE)||!d)return[];const R=Number(p);return[{startRow:d.startRow,endRow:d.endRow,startColumn:R,endColumn:R}]},[t,p,d]);A.useHighlightRange(f);const v=Z.useCallback(y=>{y.length!==0&&n(y)},[]),I=Z.useCallback(y=>{S(String(y))},[]),C=Z.useCallback(()=>{r.close(Ce)},[r]),E=Z.useCallback(async()=>{if(g.length!==0){o(!0),c(null);try{await e.saveImages(g,{fileNameParts:t,columnIndex:t.includes(he.COLUMN_VALUE)?Number(p):void 0}),r.close(Ce)}catch(y){console.error("Failed to save images:",y),c(i.t("sheetImage.save.error"))}finally{o(!1)}}},[e,g,t,p,r,i]),T=t.includes(he.COLUMN_VALUE);return L.jsxs("div",{className:"univer-flex univer-flex-col",children:[L.jsx(G.FormLayout,{label:i.t("sheetImage.save.imageCount"),children:L.jsx("div",{className:"univer-text-sm univer-text-gray-600",children:g.length})}),L.jsx(G.FormLayout,{label:i.t("sheetImage.save.fileNameConfig"),children:L.jsxs(G.CheckboxGroup,{value:t,onChange:v,direction:"vertical",children:[L.jsx(G.Checkbox,{value:he.CELL_ADDRESS,disabled:!m,children:i.t("sheetImage.save.useRowCol")}),m&&L.jsx(G.Checkbox,{value:he.COLUMN_VALUE,children:i.t("sheetImage.save.useColumnValue")})]})}),T&&L.jsx(G.FormLayout,{label:i.t("sheetImage.save.selectColumn"),children:L.jsx(G.Select,{value:p,options:h,onChange:I})}),a&&L.jsx("div",{className:"univer-text-xs univer-text-red-500",children:a}),L.jsxs("div",{className:"univer-flex univer-justify-end univer-gap-2 univer-border-t univer-border-gray-200 univer-pt-3",children:[L.jsx(G.Button,{onClick:C,disabled:s,children:i.t("sheetImage.save.cancel")}),L.jsx(G.Button,{variant:"primary",onClick:E,disabled:s||g.length===0,children:s?i.t("sheetImage.save.saving"):i.t("sheetImage.save.confirm")})]})]})}const Vt=i=>{var I;const r=j.useDependency(l.ICommandService),e=j.useDependency(l.LocaleService),t=j.useDependency(x.IDrawingManagerService),n=j.useDependency(k.IRenderManagerService),{drawings:s}=i,o=s[0];if(o==null)return;const{unitId:a}=o,c=n.getRenderById(a),g=c==null?void 0:c.scene;if(g==null)return;const u=g.getTransformerByCreate(),[d,m]=Z.useState(!0),h=(I=o.anchorType)!=null?I:w.SheetDrawingAnchorType.Position,[p,S]=Z.useState(h);function f(C,E){const T=[];return C.forEach(y=>{const{oKey:R}=y,M=E.getDrawingOKey(R);if(M==null)return T.push(null),!0;const{unitId:P,subUnitId:O,drawingId:U,drawingType:_,anchorType:b,sheetTransform:W,axisAlignSheetTransform:B}=M;T.push({unitId:P,subUnitId:O,drawingId:U,anchorType:b,sheetTransform:W,drawingType:_,axisAlignSheetTransform:B})}),T}Z.useEffect(()=>{const C=u.clearControl$.subscribe(T=>{T===!0&&m(!1)}),E=u.changeStart$.subscribe(T=>{var M;const{objects:y}=T,R=f(y,t);if(R.length===0)m(!1);else if(R.length>=1){m(!0);const P=((M=R[0])==null?void 0:M.anchorType)||w.SheetDrawingAnchorType.Position;S(P)}});return()=>{E.unsubscribe(),C.unsubscribe()}},[]);function v(C){S(C);const E=t.getFocusDrawings();if(E.length===0)return;const T=E.map(y=>({unitId:y.unitId,subUnitId:y.subUnitId,drawingId:y.drawingId,anchorType:C}));r.executeCommand(Me.id,{unitId:E[0].unitId,drawings:T})}return L.jsxs("div",{className:G.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!d}),children:[L.jsx("header",{className:"univer-text-gray-600 dark:!univer-text-gray-200",children:L.jsx("div",{children:e.t("drawing-anchor.title")})}),L.jsx("div",{children:L.jsxs(G.RadioGroup,{value:p,onChange:v,direction:"vertical",children:[L.jsx(G.Radio,{value:w.SheetDrawingAnchorType.Both,children:e.t("drawing-anchor.both")}),L.jsx(G.Radio,{value:w.SheetDrawingAnchorType.Position,children:e.t("drawing-anchor.position")}),L.jsx(G.Radio,{value:w.SheetDrawingAnchorType.None,children:e.t("drawing-anchor.none")})]})})]})},Bn=()=>{const i=j.useDependency(x.IDrawingManagerService),r=i.getFocusDrawings(),[e,t]=Z.useState(r);return Z.useEffect(()=>{const n=i.focus$.subscribe(s=>{t(s)});return()=>{n.unsubscribe()}},[]),!!(e!=null&&e.length)&&L.jsxs("div",{className:"univer-text-sm",children:[L.jsx(me.DrawingCommonPanel,{drawings:e}),L.jsx(Vt,{drawings:e})]})},bt="sheet.menu.image";function Fn(i){return{id:bt,type:j.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:A.getCurrentRangeDisable$(i,{workbookTypes:[D.WorkbookEditablePermission],worksheetTypes:[D.WorksheetEditPermission],rangeTypes:[D.RangeProtectionPermissionEditPoint]})}}function Ln(i){return{id:ke.id,title:"sheetImage.upload.float",type:j.MenuItemType.BUTTON,hidden$:j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function $n(i){return{id:Tt.id,title:"sheetImage.upload.cell",type:j.MenuItemType.BUTTON,hidden$:j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function Yn(i){var r,e,t,n;return!!((e=(r=i==null?void 0:i.p)==null?void 0:r.drawingsOrder)!=null&&e.length&&((n=(t=i==null?void 0:i.p)==null?void 0:t.drawingsOrder)==null?void 0:n.length)>0)}function Gn(i,r){const e=i.getActiveSheet();if(!e)return!1;const t=e.getCellMatrix(),{startRow:n,endRow:s,startColumn:o,endColumn:a}=r;for(let c=n;c<=s;c++)for(let g=o;g<=a;g++){const u=t.getValue(c,g);if(Yn(u))return!0}return!1}function Hn(){return"showDirectoryPicker"in window}function mt(i){const r=i.get(l.IUniverInstanceService),e=i.get(D.SheetsSelectionsService),t=N.combineLatest([j.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),r.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>n?e.selectionMoveEnd$.pipe(N.map(()=>{if(!Hn())return!0;const s=e.getCurrentSelections();if(!s||s.length===0)return!0;for(const o of s)if(Gn(n,o.range))return!1;return!0})):N.of(!0)))]).pipe(N.map(([n,s])=>n||s));return{id:Te.id,type:j.MenuItemType.BUTTON,icon:"DownloadImageIcon",title:"sheetImage.save.menuLabel",hidden$:t}}const Vn={[j.RibbonInsertGroup.MEDIA]:{[bt]:{order:0,menuItemFactory:Fn,[ke.id]:{order:0,menuItemFactory:Ln},[Tt.id]:{order:1,menuItemFactory:$n}}},[j.ContextMenuPosition.MAIN_AREA]:{[j.ContextMenuGroup.OTHERS]:{[Te.id]:{order:10,menuItemFactory:mt}}},[j.ContextMenuPosition.COL_HEADER]:{[j.ContextMenuGroup.OTHERS]:{[Te.id]:{order:10,menuItemFactory:mt}}},[j.ContextMenuPosition.ROW_HEADER]:{[j.ContextMenuGroup.OTHERS]:{[Te.id]:{order:10,menuItemFactory:mt}}}};function We(i){return i.getContextValue(l.FOCUSING_SHEET)&&!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)&&!i.getContextValue(l.FOCUSING_SHAPE_TEXT_EDITOR)}const Xn={id:be.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:j.KeyCode.ARROW_DOWN,priority:100,preconditions:We,staticParameters:{direction:l.Direction.DOWN}},Kn={id:be.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:j.KeyCode.ARROW_UP,priority:100,preconditions:We,staticParameters:{direction:l.Direction.UP}},zn={id:be.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:j.KeyCode.ARROW_LEFT,priority:100,preconditions:We,staticParameters:{direction:l.Direction.LEFT}},qn={id:be.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:j.KeyCode.ARROW_RIGHT,priority:100,preconditions:We,staticParameters:{direction:l.Direction.RIGHT}},Zn={id:It.id,description:"shortcut.drawing-delete",group:"4_drawing-view",priority:100,preconditions:We,binding:j.KeyCode.DELETE,mac:j.KeyCode.BACKSPACE};var Jn=Object.getOwnPropertyDescriptor,Qn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Jn(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},ye=(i,r)=>(e,t)=>r(e,t,i);let dt=class extends l.Disposable{constructor(i,r,e,t,n,s){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=e,this._shortcutService=t,this._drawingManagerService=n,this._sheetsSelectionsService=s,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Lt,Bn)),this.disposeWithMe(i.register(Ce,Wn))}_initMenus(){this._menuManagerService.mergeMenu(Vn)}_initCommands(){[ke,Tt,je,Re,Me,Rt,X,Mt,Dt,Ct,be,It,yt,Te].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[Xn,Kn,zn,qn,Zn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};dt=Qn([ye(0,l.Inject(j.ComponentManager)),ye(1,j.IMenuManagerService),ye(2,l.ICommandService),ye(3,j.IShortcutService),ye(4,x.IDrawingManagerService),ye(5,l.Inject(D.SheetsSelectionsService))],dt);var er=Object.defineProperty,tr=Object.getOwnPropertyDescriptor,nr=(i,r,e)=>r in i?er(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e,rr=(i,r,e,t)=>{for(var n=t>1?void 0:t?tr(r,e):r,s=i.length-1,o;s>=0;s--)(o=i[s])&&(n=o(n)||n);return n},pt=(i,r)=>(e,t)=>r(e,t,i),Xt=(i,r,e)=>nr(i,typeof r!="symbol"?r+"":r,e);const ir="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=kt,e,t,n){super(),this._config=r,this._injector=e,this._renderManagerService=t,this._configService=n;const{menu:s,...o}=l.merge({},kt,this._config);s&&this._configService.setConfig("menu",s,{merge:!0}),this._configService.setConfig(cn,o)}onStarting(){l.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[dt],[nt],[ct],[at],[ot],[rt],[it],[st],[lt,{useClass:exports.BatchSaveImagesService}]]),l.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[ot],[st]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[at],[ct],[dt],[rt],[it]])}onSteady(){this._injector.get(nt)}_registerRenderModules(){[[exports.SheetDrawingUpdateController],[_t],[vt],[wt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}};Xt(exports.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);Xt(exports.UniverSheetsDrawingUIPlugin,"pluginName",ir);exports.UniverSheetsDrawingUIPlugin=rr([l.DependentOn(x.UniverDrawingPlugin,Ft.UniverDocsDrawingPlugin,me.UniverDrawingUIPlugin,w.UniverSheetsDrawingPlugin),pt(1,l.Inject(l.Injector)),pt(2,k.IRenderManagerService),pt(3,l.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=X;exports.DeleteDrawingsCommand=It;exports.EditSheetDrawingOperation=Mt;exports.FileNamePart=he;exports.GroupSheetDrawingCommand=Dt;exports.IBatchSaveImagesService=lt;exports.InsertFloatImageCommand=ke;exports.InsertSheetDrawingCommand=je;exports.MoveDrawingsCommand=be;exports.RemoveSheetDrawingCommand=Re;exports.SHEETS_IMAGE_MENU_ID=bt;exports.SHEET_FLOAT_DOM_PREFIX=Gt;exports.SaveCellImagesCommand=Te;exports.SetDrawingArrangeCommand=yt;exports.SetSheetDrawingCommand=Me;exports.SheetDrawingAnchor=Vt;exports.SidebarSheetDrawingOperation=Rt;exports.UngroupSheetDrawingCommand=Ct;exports.calcSheetFloatDomPosition=ae;exports.drawingPositionToTransform=Q;exports.transformToAxisAlignPosition=Y;exports.transformToDrawingPosition=$;
|
|
1
|
+
"use strict";var Jt=Object.defineProperty;var Qt=(i,r,e)=>r in i?Jt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e;var oe=(i,r,e)=>Qt(i,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const j=require("@univerjs/engine-render"),P=require("@univerjs/sheets-ui"),l=require("@univerjs/core"),w=require("@univerjs/sheets-drawing"),D=require("@univerjs/sheets"),V=require("@univerjs/design"),et=require("@univerjs/docs-ui"),x=require("@univerjs/drawing"),k=require("@univerjs/ui"),Lt=require("@univerjs/docs-drawing"),ve=require("@univerjs/drawing-ui"),N=require("rxjs"),G=require("react/jsx-runtime"),Q=require("react");function ee(i,r,e){const{from:t,to:n,flipY:o=!1,flipX:s=!1,angle:a=0,skewX:c=0,skewY:g=0}=i,u=e.getCurrent();if(u==null)return;const d=P.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:t,to:n},e);let{left:m,top:h,width:p,height:S}=d;const f=e.getCurrentSkeleton(),v=f.rowHeaderWidth+f.columnTotalWidth,I=f.columnHeaderHeight+f.rowTotalHeight;return m+p>v&&(m=v-p),h+S>I&&(h=I-S),{flipY:o,flipX:s,angle:a,skewX:c,skewY:g,left:m,top:h,width:p,height:S}}function $(i,r){const{left:e=0,top:t=0,width:n=0,height:o=0,flipY:s=!1,flipX:a=!1,angle:c=0,skewX:g=0,skewY:u=0}=i,d=r.getCellWithCoordByOffset(e,t);if(d==null)return;const m={column:d.actualColumn,columnOffset:j.precisionTo(e-d.startX,1),row:d.actualRow,rowOffset:j.precisionTo(t-d.startY,1)},h=r.getCellWithCoordByOffset(e+n,t+o);if(h==null)return;const p={column:h.actualColumn,columnOffset:j.precisionTo(e+n-h.startX,1),row:h.actualRow,rowOffset:j.precisionTo(t+o-h.startY,1)};return{flipY:s,flipX:a,angle:c,skewX:g,skewY:u,from:m,to:p}}function Y(i,r){const{left:e=0,top:t=0,width:n=0,height:o=0,angle:s=0}=i,a=(s%360+360)%360;if(!(a>=45&&a<135||a>=225&&a<315))return $(i,r);const g={...i,left:e+n/2-o/2,top:t+o/2-n/2,width:o,height:n};return $(g,r)}const X={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(i,r)=>{const e=i.get(j.IRenderManagerService);return r.forEach(t=>{var n,o;(o=(n=e.getRenderById(t))==null?void 0:n.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Oe={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var I,T,O;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(D.SheetInterceptorService),o=i.get(w.ISheetDrawingService);if(!r)return!1;const{drawings:s}=r,a=[];s.forEach(C=>{const{unitId:y}=C;a.push(y)});const c=o.getBatchRemoveOp(s),{unitId:g,subUnitId:u,undo:d,redo:m,objects:h}=c,p=n.onCommandExecute({id:Oe.id,params:r}),S={id:w.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:m,objects:h,type:w.DrawingApplyType.REMOVE}},f={id:w.SetDrawingApplyMutation.id,params:{unitId:g,subUnitId:u,op:d,objects:h,type:w.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],e)?(t.pushUndoRedo({unitID:g,undoMutations:[...(T=p.preUndos)!=null?T:[],f,...p.undos,{id:X.id,params:a}],redoMutations:[...(O=p.preRedos)!=null?O:[],S,...p.redos,{id:X.id,params:a}]}),!0):!1}},Dt={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:i=>{const r=i.get(l.ICommandService),t=i.get(w.ISheetDrawingService).getFocusDrawings();if(t.length===0)return!1;const n=t[0].unitId,o=t.map(s=>{const{unitId:a,subUnitId:c,drawingId:g,drawingType:u}=s;return{unitId:a,subUnitId:c,drawingId:g,drawingType:u}});return r.executeCommand(Oe.id,{unitId:n,drawings:o})}};function en(i){const r=[];return i.forEach(e=>{const{parent:t,children:n}=e,{unitId:o,subUnitId:s,drawingId:a}=t,c=j.getGroupState(0,0,n.map(d=>d.transform||{})),g=n.map(d=>{const m=d.transform||{left:0,top:0},{unitId:h,subUnitId:p,drawingId:S}=d;return{unitId:h,subUnitId:p,drawingId:S,transform:{...m,left:m.left-c.left,top:m.top-c.top},groupId:a}}),u={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:c};r.push({parent:u,children:g})}),r}function tn(i){const r=[];return i.forEach(e=>{const{parent:t,children:n}=e,{unitId:o,subUnitId:s,drawingId:a,transform:c={width:0,height:0}}=t;if(c==null)return;const g=n.map(d=>{const{transform:m}=d,{unitId:h,subUnitId:p,drawingId:S}=d,f=j.transformObjectOutOfGroup(m||{},c,c.width||0,c.height||0);return{unitId:h,subUnitId:p,drawingId:S,transform:f,groupId:void 0}}),u={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:g})}),r}const yt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:p})=>{o.push(h.unitId),p.forEach(S=>{o.push(S.unitId)})});const s=n.getGroupDrawingOp(r),{unitId:a,subUnitId:c,undo:g,redo:u,objects:d}=s;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:c,objects:d,type:w.DrawingApplyType.GROUP})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:c,objects:tn(d),type:w.DrawingApplyType.UNGROUP}},{id:X.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:d,type:w.DrawingApplyType.GROUP}},{id:X.id,params:o}]}),!0):!1}},Fe={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var I,T,O;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService),o=i.get(D.SheetInterceptorService);if(!r)return!1;const s=r.drawings,a=s.map(C=>C.unitId),c=n.getBatchAddOp(s),{unitId:g,subUnitId:u,undo:d,redo:m,objects:h}=c,p=o.onCommandExecute({id:Fe.id,params:r}),S={id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:g,subUnitId:u,objects:h,type:w.DrawingApplyType.INSERT}},f={id:w.SetDrawingApplyMutation.id,params:{op:d,unitId:g,subUnitId:u,objects:h,type:w.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],e)?(t.pushUndoRedo({unitID:g,undoMutations:[...(T=p.preUndos)!=null?T:[],f,...p.undos,{id:X.id,params:a}],redoMutations:[...(O=p.preRedos)!=null?O:[],S,...p.redos,{id:X.id,params:a}]}),!0):!1}},Ct={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService);if(!r)return!1;const n=i.get(w.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:a,arrangeType:c}=r,g={unitId:o,subUnitId:s,drawingIds:a};let u;if(c===l.ArrangeTypeEnum.forward?u=n.getForwardDrawingsOp(g):c===l.ArrangeTypeEnum.backward?u=n.getBackwardDrawingOp(g):c===l.ArrangeTypeEnum.front?u=n.getFrontDrawingsOp(g):c===l.ArrangeTypeEnum.back&&(u=n.getBackDrawingsOp(g)),u==null)return!1;const{objects:d,redo:m,undo:h}=u;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:m,unitId:o,subUnitId:s,objects:d,type:w.DrawingApplyType.ARRANGE})?(t.pushUndoRedo({unitID:o,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:s,objects:d,type:w.DrawingApplyType.ARRANGE}}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:s,objects:d,type:w.DrawingApplyType.ARRANGE}}]}),!0):!1}},Ae={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{var v,I;const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService),o=i.get(D.SheetInterceptorService);if(!r)return!1;const{drawings:s}=r,a=n.getBatchUpdateOp(s),{unitId:c,subUnitId:g,undo:u,redo:d,objects:m}=a,h=o.onCommandExecute({id:Ae.id,params:r}),p=[...(v=h.preRedos)!=null?v:[],{id:w.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:g,op:d,objects:m,type:w.DrawingApplyType.UPDATE}},...h.redos,{id:X.id,params:[c]}],S=[...(I=h.preUndos)!=null?I:[],{id:w.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:g,op:u,objects:m,type:w.DrawingApplyType.UPDATE}},...h.undos,{id:X.id,params:[c]}];return l.sequenceExecute(p,e)?(t.pushUndoRedo({unitID:c,undoMutations:S,redoMutations:p}),!0):!1}},Tt={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:h,children:p})=>{o.push(h.unitId),p.forEach(S=>{o.push(S.unitId)})});const s=n.getUngroupDrawingOp(r),{unitId:a,subUnitId:c,undo:g,redo:u,objects:d}=s;return e.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:a,subUnitId:c,objects:d,type:w.DrawingApplyType.UNGROUP})?(t.pushUndoRedo({unitID:a,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:a,subUnitId:c,objects:en(d),type:w.DrawingApplyType.GROUP}},{id:X.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:a,subUnitId:c,objects:d,type:w.DrawingApplyType.UNGROUP}},{id:X.id,params:o}]}),!0):!1}};var nn=Object.getOwnPropertyDescriptor,rn=(i,r,e,t)=>{for(var n=t>1?void 0:t?nn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},re=(i,r)=>(e,t)=>r(e,t,i);function on(i,r,e){const t=e*Math.PI/180,n=Math.abs(i*Math.cos(t))+Math.abs(r*Math.sin(t)),o=Math.abs(i*Math.sin(t))+Math.abs(r*Math.cos(t));return{rotatedWidth:n,rotatedHeight:o}}function St(i,r,e,t,n){var I;const{rotatedHeight:o,rotatedWidth:s}=on(e,t,n),c=i.get(j.IRenderManagerService).getRenderById(r.unitId);if(!c)return!1;const u=(I=c.with(P.SheetSkeletonManagerService).getSkeletonParam(r.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const d=u.getCellByIndex(r.row,r.col),m=d.mergeInfo.endX-d.mergeInfo.startX-2,h=d.mergeInfo.endY-d.mergeInfo.startY-2,p=s/o,f=Math.ceil(Math.min(m,h*p))/s,v=!f||Number.isNaN(f)?.001:f;return{width:e*v,height:t*v}}exports.SheetDrawingUpdateController=class extends l.Disposable{constructor(e,t,n,o,s,a,c,g,u,d,m,h,p,S){super();oe(this,"_workbookSelections");this._context=e,this._skeletonManagerService=t,this._commandService=n,this._selectionRenderService=o,this._imageIoService=s,this._fileOpenerService=a,this._sheetDrawingService=c,this._drawingManagerService=g,this._contextService=u,this._messageService=d,this._localeService=m,this._injector=p,this._urlImageService=S,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const e=await this._fileOpenerService.openFile({multiple:!0,accept:x.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),t=e.length;return t>x.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(x.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t===0?!1:(e.forEach(async n=>await this.insertFloatImageByFile(n)),!0)}async insertCellImage(){const t=(await this._fileOpenerService.openFile({multiple:!1,accept:x.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}))[0];return t?(await this._insertCellImage(t),!0):!1}insertCellImageByFile(e,t){return this._insertCellImage(e,t)}async insertFloatImageByFile(e){var O;let t;try{t=await this._imageIoService.saveImage(e)}catch(C){const y=C.message;y===x.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(x.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):y===x.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):y===x.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(t==null)return;const n=this._getUnitInfo(),{unitId:o,subUnitId:s}=n,{imageId:a,imageSourceType:c,source:g,base64Cache:u}=t,{width:d,height:m,image:h}=await x.getImageSize(u||""),{width:p,height:S}=this._context.scene;this._imageIoService.addImageSourceCache(g,c,h);let f=1;if(d>x.DRAWING_IMAGE_WIDTH_LIMIT||m>x.DRAWING_IMAGE_HEIGHT_LIMIT){const C=x.DRAWING_IMAGE_WIDTH_LIMIT/d,y=x.DRAWING_IMAGE_HEIGHT_LIMIT/m;f=Math.max(C,y)}const v=this._getImagePosition(d*f,m*f,p,S);if(v==null)return;const I=ee(v,this._selectionRenderService,this._skeletonManagerService),T={unitId:o,subUnitId:s,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:g,transform:I,sheetTransform:v,axisAlignSheetTransform:(O=Y(I,this._selectionRenderService))!=null?O:v};return this._commandService.executeCommand(Fe.id,{unitId:o,drawings:[T]})}async _insertCellImage(e,t){var O,C;let n;try{n=await this._imageIoService.saveImage(e)}catch(y){const R=y.message;R===x.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(x.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):R===x.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):R===x.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:V.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return!1;const{imageId:o,imageSourceType:s,source:a,base64Cache:c}=n,{width:g,height:u,image:d}=await x.getImageSize(c||"");this._imageIoService.addImageSourceCache(a,s,d);const m=this._workbookSelections.getCurrentLastSelection();if(!m)return!1;let h=m.primary.actualRow,p=m.primary.actualColumn;m.primary.isMerged&&(h=m.primary.startRow,p=m.primary.startColumn);const S=l.createDocumentModelWithStyle("",{}),f=St(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:h,col:p},g,u,0);if(!f)return!1;const v={size:{width:f.width,height:f.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},I={unitId:S.getUnitId(),subUnitId:S.getUnitId(),drawingId:o,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:a,transform:et.docDrawingPositionToTransform(v),docTransform:v,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},T=l.BuildTextUtils.drawing.add({documentDataModel:S,drawings:[I],selection:{collapsed:!0,startOffset:0,endOffset:0}});return T?(S.apply(T),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(O=t==null?void 0:t.row)!=null?O:h]:{[(C=t==null?void 0:t.col)!=null?C:p]:{p:S.getSnapshot(),t:1}}},unitId:t==null?void 0:t.unitId,subUnitId:t==null?void 0:t.subUnitId})):!1}async insertCellImageByUrl(e,t){var p,S;let n=e;try{n=await this._urlImageService.getImage(e)}catch(f){console.error(`Failed to get image from URLImageService: ${e}`,f)}const{width:o,height:s,image:a}=await x.getImageSize(n||"");this._imageIoService.addImageSourceCache(e,l.ImageSourceType.URL,a);const c=this._workbookSelections.getCurrentLastSelection();if(!c)return!1;const g=l.createDocumentModelWithStyle("",{}),u=St(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:c.primary.actualRow,col:c.primary.actualColumn},o,s,0);if(!u)return!1;const d={size:{width:u.width,height:u.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},m={unitId:g.getUnitId(),subUnitId:g.getUnitId(),drawingId:l.generateRandomId(),drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l.ImageSourceType.URL,source:e,transform:et.docDrawingPositionToTransform(d),docTransform:d,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},h=l.BuildTextUtils.drawing.add({documentDataModel:g,drawings:[m],selection:{collapsed:!0,startOffset:0,endOffset:0}});return h?(g.apply(h),this._commandService.syncExecuteCommand(D.SetRangeValuesCommand.id,{value:{[(p=t==null?void 0:t.row)!=null?p:c.primary.actualRow]:{[(S=t==null?void 0:t.col)!=null?S:c.primary.actualColumn]:{p:g.getSnapshot(),t:1}}},unitId:t==null?void 0:t.unitId,subUnitId:t==null?void 0:t.subUnitId})):!1}_getUnitInfo(){const e=this._context.unit,t=e.getActiveSheet(),n=e.getUnitId(),o=t.getSheetId();return{unitId:n,subUnitId:o}}_getImagePosition(e,t,n,o){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 c=P.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(c==null)return;let{startColumn:g,startRow:u,startX:d,startY:m}=c,h=!1;if(d+e>n&&(d=n-e,d<0&&(d=0,e=n),h=!0),m+t>o&&(m=o-t,m<0&&(m=0,t=o),h=!0),h){const v=this._selectionRenderService.getCellWithCoordByOffset(d,m);if(v==null)return;d=v.startX,m=v.startY,g=v.actualColumn,u=v.actualRow}const p={column:g,columnOffset:0,row:u,rowOffset:0},S=this._selectionRenderService.getCellWithCoordByOffset(d+e,m+t);if(S==null)return;const f={column:S.actualColumn,columnOffset:d+e-S.startX,row:S.actualRow,rowOffset:m+t-S.startY};return{from:p,to:f}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{const{unitId:t,subUnitId:n,drawingIds:o,arrangeType:s}=e;this._commandService.executeCommand(Ct.id,{unitId:t,subUnitId:n,drawingIds:o,arrangeType:s})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{const t=[];e.length!==0&&(e.forEach(n=>{const{unitId:o,subUnitId:s,drawingId:a,drawingType:c,transform:g}=n;if(g==null)return;const u=this._sheetDrawingService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:a});if(u==null||u.unitId!==this._context.unitId)return;const d=$({...u.transform,...g},this._selectionRenderService),m=Y({...u.transform,...g},this._selectionRenderService);if(d==null||m==null)return;const h={...n,transform:{...u.transform,...g,...ee(d,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...d},axisAlignSheetTransform:{...m}};t.push(h)}),t.length>0&&this._commandService.executeCommand(Ae.id,{unitId:e[0].unitId,drawings:t}))}))}_getSheetTransformByParam(e){const{unitId:t,subUnitId:n,drawingId:o,transform:s}=e;if(s==null)return null;const a=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:o});if(a==null||a.unitId!==this._context.unitId)return null;const c=$({...a.transform,...s},this._selectionRenderService),g=Y({...a.transform,...s},this._selectionRenderService);return c==null||g==null?null:{sheetTransform:c,axisAlignSheetTransform:g}}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{const t=[];for(const n of e){const o=this._getSheetTransformByParam(n.parent),s=[];for(const c of n.children){const g=this._getSheetTransformByParam(c);g!=null&&s.push({...c,sheetTransform:g.sheetTransform,axisAlignSheetTransform:g.axisAlignSheetTransform})}const a={parent:{...n.parent,sheetTransform:o},children:s};t.push(a)}if(t.length>0){this._commandService.executeCommand(yt.id,t);const{unitId:n,subUnitId:o,drawingId:s}=e[0].parent;this._commandService.syncExecuteCommand(x.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:o,drawingId:s}])}})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{const t=[];for(const n of e){const{children:o}=n,s=[];for(const a of o){const c=this._getSheetTransformByParam(a);c!=null&&s.push({...a,sheetTransform:c})}t.push({...n,children:s})}this._commandService.executeCommand(Tt.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};exports.SheetDrawingUpdateController=rn([re(1,l.Inject(P.SheetSkeletonManagerService)),re(2,l.ICommandService),re(3,P.ISheetSelectionRenderService),re(4,x.IImageIoService),re(5,k.ILocalFileService),re(6,w.ISheetDrawingService),re(7,x.IDrawingManagerService),re(8,l.IContextService),re(9,k.IMessageService),re(10,l.Inject(l.LocaleService)),re(11,l.Inject(D.SheetsSelectionsService)),re(12,l.Inject(l.Injector)),re(13,l.IURLImageService)],exports.SheetDrawingUpdateController);const Le={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{var s,a;const e=i.get(l.IUniverInstanceService),t=i.get(j.IRenderManagerService),n=(s=j.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,e,t))==null?void 0:s.with(exports.SheetDrawingUpdateController);if(!n)return!1;const o=r==null?void 0:r.files;if(o){const c=o.map(g=>n.insertFloatImageByFile(g));return(await Promise.all(c)).every(g=>g)}else return(a=n.insertFloatImage())!=null?a:!1}},Rt={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:i=>{var t,n;const r=i.get(l.IUniverInstanceService),e=i.get(j.IRenderManagerService);return(n=(t=j.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,r,e))==null?void 0:t.with(exports.SheetDrawingUpdateController).insertCellImage())!=null?n:!1}},Ue={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(w.ISheetDrawingService),n=i.get(P.ISheetSelectionRenderService),{direction:o}=r,s=t.getFocusDrawings();if(s.length===0)return!1;const a=s[0].unitId,c=s.map(u=>{const{transform:d}=u;if(d==null)return null;const m={...d},{left:h=0,top:p=0}=d;return o===l.Direction.UP?m.top=p-1:o===l.Direction.DOWN?m.top=p+1:o===l.Direction.LEFT?m.left=h-1:o===l.Direction.RIGHT&&(m.left=h+1),{...u,transform:m,sheetTransform:$(m,n),axisAlignSheetTransform:Y(m,n)}}).filter(u=>u!=null);return e.syncExecuteCommand(Ae.id,{unitId:a,drawings:c})?(e.syncExecuteCommand(X.id,[a]),!0):!1}};var sn=Object.getOwnPropertyDescriptor,an=(i,r,e,t)=>{for(var n=t>1?void 0:t?sn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},ze=(i,r)=>(e,t)=>r(e,t,i),we=(i=>(i.CELL_ADDRESS="cellAddress",i.COLUMN_VALUE="columnValue",i))(we||{});const lt=l.createIdentifier("sheets-drawing-ui.batch-save-images.service");function ft(i){let r="",e=i;for(;e>=0;)r=String.fromCharCode(e%26+65)+r,e=Math.floor(e/26)-1;return r}function tt(i,r){return`${ft(r)}${i+1}`}function cn(i){const r=tt(i.startRow,i.startColumn),e=tt(i.endRow,i.endColumn);return r===e?r:`${r}:${e}`}function xt(i){var r,e,t,n;return!!((e=(r=i==null?void 0:i.p)==null?void 0:r.drawingsOrder)!=null&&e.length&&((n=(t=i==null?void 0:i.p)==null?void 0:t.drawingsOrder)==null?void 0:n.length)>0)}function jt(i){var t,n,o;if(!((n=(t=i.p)==null?void 0:t.drawingsOrder)!=null&&n.length)||!((o=i.p)!=null&&o.drawings))return null;const r=i.p.drawingsOrder[0],e=i.p.drawings[r];return!e||!("source"in e)||!("imageSourceType"in e)?null:e}function ht(i,r){if(r===l.ImageSourceType.BASE64){const e=i.match(/^data:image\/(\w+);/);if(e)return e[1]==="jpeg"?"jpg":e[1]}if(r===l.ImageSourceType.URL){const e=i.match(/\.(\w+)(?:\?|$)/);if(e)return e[1].toLowerCase()}return"png"}async function kt(i,r){if(r===l.ImageSourceType.BASE64)return(await fetch(i)).blob();if(r===l.ImageSourceType.URL)return(await fetch(i)).blob();throw new Error("UUID image type requires additional handling")}exports.BatchSaveImagesService=class extends l.Disposable{constructor(r,e,t,n){super(),this._univerInstanceService=r,this._selectionService=e,this._imageIoService=t,this._urlImageService=n}registerURLImageDownloader(r){return this._urlImageService.registerURLImageDownloader(r)}getCellImagesInSelection(){const r=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!r)return[];const e=r.getActiveSheet();if(!e)return[];const t=this._selectionService.getCurrentSelections();if(!t||t.length===0)return[];const n=e.getCellMatrix(),o=[];for(const s of t){const{startRow:a,endRow:c,startColumn:g,endColumn:u}=s.range;for(let d=a;d<=c;d++)for(let m=g;m<=u;m++){const h=n.getValue(d,m);if(xt(h)){const p=jt(h);p&&o.push({row:d,col:m,cellAddress:tt(d,m),source:p.source,imageSourceType:p.imageSourceType,imageId:p.drawingId})}}}return o}getCellImagesFromRanges(r,e,t){const n=this._univerInstanceService.getUnit(r,l.UniverInstanceType.UNIVER_SHEET);if(!n)return[];const o=n.getSheetBySheetId(e);if(!o)return[];const s=o.getCellMatrix(),a=[];for(const c of t){const{startRow:g,endRow:u,startColumn:d,endColumn:m}=c;for(let h=g;h<=u;h++)for(let p=d;p<=m;p++){const S=s.getValue(h,p);if(xt(S)){const f=jt(S);f&&a.push({row:h,col:p,cellAddress:tt(h,p),source:f.source,imageSourceType:f.imageSourceType,imageId:f.drawingId})}}}return a}getDataColumns(){var m,h,p,S;const r=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!r)return[];const e=r.getActiveSheet();if(!e)return[];const t=this._selectionService.getCurrentSelections();if(!t||t.length===0)return[];const n=e.getCellMatrix(),o=n.getDataRange();let s=1/0,a=-1/0;const c=new Set;for(const f of t){s=Math.min(s,f.range.startRow),a=Math.max(a,f.range.endRow);for(let v=f.range.startColumn;v<=f.range.endColumn;v++)c.add(v)}const g=new Set;for(let f=o.startColumn;f<=o.endColumn;f++)if(!c.has(f))for(let v=s;v<=a;v++){const I=n.getValue(v,f);if(I&&(((m=I.v)==null?void 0:m.toString())||((S=(p=(h=I.p)==null?void 0:h.body)==null?void 0:p.dataStream)==null?void 0:S.trim())||"")){g.add(f);break}}const u=[],d=Array.from(g).sort((f,v)=>f-v);for(const f of d)u.push({index:f,label:ft(f)});return u}getDataColumnsForRanges(r,e,t){var p,S,f,v;const n=this._univerInstanceService.getUnit(r,l.UniverInstanceType.UNIVER_SHEET);if(!n)return[];const o=n.getSheetBySheetId(e);if(!o)return[];const s=o.getCellMatrix(),a=s.getDataRange();let c=1/0,g=-1/0;const u=new Set;for(const I of t){c=Math.min(c,I.startRow),g=Math.max(g,I.endRow);for(let T=I.startColumn;T<=I.endColumn;T++)u.add(T)}const d=new Set;for(let I=a.startColumn;I<=a.endColumn;I++)if(!u.has(I))for(let T=c;T<=g;T++){const O=s.getValue(T,I);if(O&&(((p=O.v)==null?void 0:p.toString())||((v=(f=(S=O.p)==null?void 0:S.body)==null?void 0:f.dataStream)==null?void 0:v.trim())||"")){d.add(I);break}}const m=[],h=Array.from(d).sort((I,T)=>I-T);for(const I of h)m.push({index:I,label:ft(I)});return m}getSelectionRangeNotation(){const r=this._selectionService.getCurrentSelections();return!r||r.length===0?"":r.map(e=>cn(e.range)).join(", ")}getSelectionRowRange(){const r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return null;let e=1/0,t=-1/0;for(const n of r)e=Math.min(e,n.range.startRow),t=Math.max(t,n.range.endRow);return{startRow:e,endRow:t}}getSelectionColumnIndices(){const r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return new Set;const e=new Set;for(const t of r)for(let n=t.range.startColumn;n<=t.range.endColumn;n++)e.add(n);return e}generateFileName(r,e){var s,a,c,g;const t=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),n=ht(r.source,r.imageSourceType),o=[];for(const u of e.fileNameParts)if(u==="cellAddress")o.push(r.cellAddress);else if(u==="columnValue"&&e.columnIndex!==void 0){const d=t==null?void 0:t.getActiveSheet();if(d){const h=d.getCellMatrix().getValue(r.row,e.columnIndex);if(h){const p=((s=h.v)==null?void 0:s.toString())||((g=(c=(a=h.p)==null?void 0:a.body)==null?void 0:c.dataStream)==null?void 0:g.trim())||"";if(p){const S=p.replace(/[<>:"/\\|?*]/g,"_").trim();S&&o.push(S)}}}}return o.length===0?`${r.cellAddress}.${n}`:`${o.join("_")}.${n}`}generateFileNameWithContext(r,e,t,n){var c,g,u,d;const o=this._univerInstanceService.getUnit(t,l.UniverInstanceType.UNIVER_SHEET),s=ht(r.source,r.imageSourceType),a=[];for(const m of e.fileNameParts)if(m==="cellAddress")a.push(r.cellAddress);else if(m==="columnValue"&&e.columnIndex!==void 0){const h=o==null?void 0:o.getSheetBySheetId(n);if(h){const S=h.getCellMatrix().getValue(r.row,e.columnIndex);if(S){const f=((c=S.v)==null?void 0:c.toString())||((d=(u=(g=S.p)==null?void 0:g.body)==null?void 0:u.dataStream)==null?void 0:d.trim())||"";if(f){const v=f.replace(/[<>:"/\\|?*]/g,"_").trim();v&&a.push(v)}}}}return a.length===0?`${r.cellAddress}.${s}`:`${a.join("_")}.${s}`}async saveImages(r,e){var o;const t=await window.showDirectoryPicker({mode:"readwrite"}),n=new Map;for(const s of r){let a=this.generateFileName(s,e);const c=a.replace(/\.\w+$/,""),g=((o=a.match(/\.\w+$/))==null?void 0:o[0])||".png",u=n.get(c)||0;u>0&&(a=`${c}_${u}${g}`),n.set(c,u+1);try{const d=await this._getImageBlob(s),h=await(await t.getFileHandle(a,{create:!0})).createWritable();await h.write(d),await h.close()}catch(d){throw console.error(`Failed to save image ${a}:`,d),d}}}async saveImagesWithContext(r,e,t,n){var a;const o=await window.showDirectoryPicker({mode:"readwrite"}),s=new Map;for(const c of r){let g=this.generateFileNameWithContext(c,e,t,n);const u=g.replace(/\.\w+$/,""),d=((a=g.match(/\.\w+$/))==null?void 0:a[0])||".png",m=s.get(u)||0;m>0&&(g=`${u}_${m}${d}`),s.set(u,m+1);try{const h=await this._getImageBlob(c),S=await(await o.getFileHandle(g,{create:!0})).createWritable();await S.write(h),await S.close()}catch(h){throw console.error(`Failed to save image ${g}:`,h),h}}}async downloadSingleImage(r){const e=ht(r.source,r.imageSourceType),t=`${r.cellAddress}.${e}`;try{const n=await this._getImageBlob(r),o=URL.createObjectURL(n),s=document.createElement("a");s.href=o,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(o)}catch(n){throw console.error(`Failed to download image ${t}:`,n),n}}async _getImageBlob(r){if(r.imageSourceType===l.ImageSourceType.UUID){const e=await this._imageIoService.getImage(r.source);return kt(e,l.ImageSourceType.URL)}return r.imageSourceType===l.ImageSourceType.URL?this._urlImageService.downloadImage(r.source):kt(r.source,r.imageSourceType)}};exports.BatchSaveImagesService=an([ze(0,l.IUniverInstanceService),ze(1,l.Inject(D.SheetsSelectionsService)),ze(2,l.IImageIoService),ze(3,l.IURLImageService)],exports.BatchSaveImagesService);const be="sheet.dialog.batch-save-images",Ee={id:"sheet.command.save-cell-images",type:l.CommandType.COMMAND,handler:async i=>{const r=i.get(k.IDialogService),e=i.get(lt),t=e.getCellImagesInSelection();if(t.length===1)try{return await e.downloadSingleImage(t[0]),!0}catch(a){return console.error("Failed to download image:",a),!1}const n=i.get(l.LocaleService),o=e.getSelectionRangeNotation(),s=`${n.t("sheetImage.save.title")} (${o})`;return r.open({id:be,draggable:!0,width:360,title:{title:s},children:{label:be},destroyOnClose:!0,preservePositionOnDestroy:!0,onClose:()=>r.close(be)}),!0}},$t="COMPONENT_SHEET_DRAWING_PANEL",Mt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(i,r)=>{const e=i.get(k.ISidebarService),t=i.get(l.LocaleService),n=i.get(l.IUniverInstanceService),o=i.get(l.ICommandService);return D.getSheetCommandTarget(n)?(r.value==="open"?e.open({header:{title:t.t("sheetImage.panel.title")},children:{label:$t},onClose:()=>{o.syncExecuteCommand(x.SetDrawingSelectedOperation.id,[])},width:360}):e.close(),!0):!1}},bt={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(i,r)=>{const e=i.get(l.ICommandService);return r==null?!1:(e.syncExecuteCommand(x.SetDrawingSelectedOperation.id,[r]),e.executeCommand(Mt.id,{value:"open"}),!0)}},dn="sheets-drawing-ui.config",Wt={},wt={id:"sheet.command.toggle-flip-drawings",type:l.CommandType.COMMAND,handler:(i,r)=>{const e=i.get(l.ICommandService),t=i.get(l.IUndoRedoService),n=i.get(w.ISheetDrawingService),o=i.get(j.IRenderManagerService);if(!r)return!1;const{drawings:s}=r,a=r.flipH,c=r.flipV,g=[],u=[];for(const O of s){const{unitId:C,subUnitId:y,drawingId:R}=O;g.push(C);const M=n.getDrawingData(C,y),U=M==null?void 0:M[R];if(!U)continue;const b={...U.transform};a&&(b.flipX=!b.flipX),c&&(b.flipY=!b.flipY);const A=o.getRenderById(C),_=A==null?void 0:A.with(P.ISheetSelectionRenderService);if(!_)continue;const E=$(b,_),W=Y(b,_),B={unitId:C,subUnitId:y,drawingType:U.drawingType,drawingId:R,transform:b,sheetTransform:E,axisAlignSheetTransform:W};if(U.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE){const te=ln(i,C);if(te){const K=x.getDrawingShapeKeyByDrawingSearch({unitId:C,subUnitId:y,drawingId:R}),z=te.getObject(K);if(z){const ne=z.srcRect;if(ne){let H;const{left:Z=0,top:F=0,right:se=0,bottom:le=0}=ne;if(a){const ae=Z+(se-Z)/2,pe=ae-(se-Z)/2,Se=ae+(se-Z)/2;H={left:pe,top:F,right:Se,bottom:le}}if(c){const ae=F+(le-F)/2,pe=ae-(le-F)/2,Se=ae+(le-F)/2;H={left:Z,top:pe,right:se,bottom:Se}}H&&(B.srcRect=H)}}}}u.push(B)}if(u.length===0)return!1;const d=n.getBatchUpdateOp(u),{unitId:m,subUnitId:h,undo:p,redo:S,objects:f}=d,v={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:h,op:S,objects:f,type:w.DrawingApplyType.UPDATE}},I={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:h,op:p,objects:f,type:w.DrawingApplyType.UPDATE}};return l.sequenceExecute([v],e)?(t.pushUndoRedo({unitID:m,undoMutations:[I,{id:X.id,params:g}],redoMutations:[v,{id:X.id,params:g}]}),!0):!1}};function ln(i,r){const t=i.get(j.IRenderManagerService).getRenderById(r);return t?t.scene:null}var un=Object.getOwnPropertyDescriptor,gn=(i,r,e,t)=>{for(var n=t>1?void 0:t?un(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},ce=(i,r)=>(e,t)=>r(e,t,i);let nt=class extends l.RxDisposable{constructor(r,e,t,n,o,s,a,c,g,u){super();oe(this,"_initImagePopupMenu",new Set);this._injector=r,this._localeService=e,this._drawingManagerService=t,this._canvasPopManagerService=n,this._renderManagerService=o,this._univerInstanceService=s,this._messageService=a,this._contextService=c,this._ioService=g,this._commandService=u,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).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 e;this.disposeWithMe(this._ioService.change$.subscribe(t=>{t>0&&!e?e=this._messageService.show({id:r,type:V.MessageType.Loading,content:`${this._localeService.t("uploadLoading.loading")}: ${t}`,duration:0}):t===0&&(e==null||e.dispose(),e=void 0)}))}_dispose(r){super.dispose();const e=r.getUnitId();this._renderManagerService.removeRender(e),this._initImagePopupMenu.delete(e)}_create(r){if(!r)return;const e=r.getUnitId();this._renderManagerService.has(e)&&!this._initImagePopupMenu.has(e)&&(this._popupMenuListener(e),this._initImagePopupMenu.add(e))}_hasCropObject(r){const e=r.getAllObjectsByOrder();for(const t of e)if(t instanceof ve.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const e=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!e)return;const t=e.getTransformerByCreate();if(!t)return;let n;this.disposeWithMe(t.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(e))return;const s=t.getSelectedObjectMap();if(s.size>1){n==null||n.dispose();return}const a=s.values().next().value;if(!a)return;const c=a.oKey,g=this._drawingManagerService.getDrawingOKey(c);if(!g)return;const{unitId:u,subUnitId:d,drawingId:m,drawingType:h}=g,p=g.data;if(p&&p.disablePopup)return;n==null||n.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,d,m,h);n=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(a,{componentKey:ve.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,d,m,h)}}))})),this.disposeWithMe(t.clearControl$.subscribe(()=>{n==null||n.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(x.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(s=>{s[l.FOCUSING_COMMON_DRAWINGS]===!1&&(n==null||n.dispose())})),this.disposeWithMe(t.changing$.subscribe(()=>{n==null||n.dispose()}))}_getImageMenuItems(r,e,t,n){return[{label:"image-popup.edit",index:0,commandId:bt.id,commandParams:{unitId:r,subUnitId:e,drawingId:t},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Oe.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:e,drawingId:t}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ve.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:e,drawingId:t},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.flipH",index:2,commandId:wt.id,commandParams:{unitId:r,flipH:!0,drawings:[{unitId:r,subUnitId:e,drawingId:t}]},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.flipV",index:2,commandId:wt.id,commandParams:{unitId:r,flipV:!0,drawings:[{unitId:r,subUnitId:e,drawingId:t}]},disable:n===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ve.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:e,drawingId:t}],disable:n===l.DrawingTypeEnum.DRAWING_DOM}]}};nt=gn([ce(0,l.Inject(l.Injector)),ce(1,l.Inject(l.LocaleService)),ce(2,x.IDrawingManagerService),ce(3,l.Inject(P.SheetCanvasPopManagerService)),ce(4,j.IRenderManagerService),ce(5,l.IUniverInstanceService),ce(6,k.IMessageService),ce(7,l.IContextService),ce(8,l.IImageIoService),ce(9,l.ICommandService)],nt);var hn=Object.getOwnPropertyDescriptor,mn=(i,r,e,t)=>{for(var n=t>1?void 0:t?hn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},qe=(i,r)=>(e,t)=>r(e,t,i);let vt=class extends l.Disposable{constructor(r,e,t,n,o){super();oe(this,"_isSetCursor",!1);this._context=r,this._hoverManagerService=e,this._selectionsService=t,this._drawingRenderService=n,this._sheetSkeletonManagerService=o,this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe(N.throttleTime(33)).subscribe(r=>{var t,n;let e=[];r!==null&&(e=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),e.length>0&&(r==null?void 0:r.unitId)===this._context.unitId&&(r!=null&&r.drawing)&&e.length===1&&((t=e[0].primary)==null?void 0:t.actualRow)===r.row&&((n=e[0].primary)==null?void 0:n.actualColumn)===r.col?(this._isSetCursor=!0,this._context.scene.setCursor(j.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(r=>{var e;if(r!=null&&r.drawing&&this._isSetCursor){const t=r.drawing.drawing.drawingOrigin,n=(e=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:e.imageCacheMap.getImage(t.imageSourceType,t.source);if(!n)return;this._drawingRenderService.previewImage("preview-cell-image",n.src,n.width,n.height),this._context.scene.resetCursor(),this._isSetCursor=!1}}))}};vt=mn([qe(1,l.Inject(P.HoverManagerService)),qe(2,l.Inject(D.SheetsSelectionsService)),qe(3,l.Inject(ve.DrawingRenderService)),qe(4,l.Inject(P.SheetSkeletonManagerService))],vt);var pn=Object.getOwnPropertyDescriptor,Sn=(i,r,e,t)=>{for(var n=t>1?void 0:t?pn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ze=(i,r)=>(e,t)=>r(e,t,i);let _t=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=e,this._sheetSelectionRenderService=t,this._sheetSkeletonManagerService=n,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const e=i[r];for(const t in e.data){const n=e.data[t];n.sheetTransform&&(n.transform=ee(n.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService))}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};_t=Sn([Ze(1,w.ISheetDrawingService),Ze(2,x.IDrawingManagerService),Ze(3,l.Inject(P.ISheetSelectionRenderService)),Ze(4,l.Inject(P.SheetSkeletonManagerService))],_t);var fn=Object.getOwnPropertyDescriptor,wn=(i,r,e,t)=>{for(var n=t>1?void 0:t?fn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Re=(i,r)=>(e,t)=>r(e,t,i);function Yt(i,r,e){var t,n,o,s;if(((n=(t=e==null?void 0:e.p)==null?void 0:t.body)==null?void 0:n.dataStream.length)===3&&((s=(o=e.p)==null?void 0:o.drawingsOrder)==null?void 0:s.length)===1){const a=e.p.drawings[e.p.drawingsOrder[0]],c=St(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},a.docTransform.size.width,a.docTransform.size.height,a.docTransform.angle);if(c)return a.transform.width=c.width,a.transform.height=c.height,a.docTransform.size.width=c.width,a.docTransform.size.height=c.height,a.transform.left=0,a.transform.top=0,a.docTransform.positionH.posOffset=0,a.docTransform.positionV.posOffset=0,e.p.documentStyle.pageSize.width=1/0,e.p.documentStyle.pageSize.height=1/0,!0}return!1}let rt=class extends l.Disposable{constructor(i,r,e,t,n,o){super(),this._commandService=i,this._sheetInterceptorService=r,this._injector=e,this._drawingManagerService=t,this._docDrawingController=n,this._editorBridgeService=o,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.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(i=>{i.id===et.ReplaceSnapshotCommand.id&&i.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:(i,r,e)=>{var t;return i!=null&&i.p&&((t=i.p.drawingsOrder)!=null&&t.length)&&(i===r.rawData&&(i={...r.rawData}),i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0},Yt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i)),e(i)}}))}};rt=wn([Re(0,l.ICommandService),Re(1,l.Inject(D.SheetInterceptorService)),Re(2,l.Inject(l.Injector)),Re(3,x.IDrawingManagerService),Re(4,l.Inject(Lt.DocDrawingController)),Re(5,l.Inject(P.IEditorBridgeService))],rt);var vn=Object.getOwnPropertyDescriptor,_n=(i,r,e,t)=>{for(var n=t>1?void 0:t?vn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Bt=(i,r)=>(e,t)=>r(e,t,i);let it=class extends l.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,e,t)=>{new l.ObjectMatrix(t).forValue((n,o,s)=>{Yt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:n,col:o},s)})}}))}};it=_n([Bt(0,l.Inject(D.IAutoFillService)),Bt(1,l.Inject(l.Injector))],it);var In=Object.getOwnPropertyDescriptor,Dn=(i,r,e,t)=>{for(var n=t>1?void 0:t?In(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},je=(i,r)=>(e,t)=>r(e,t,i);const yn=[l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,l.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,l.DOCS_ZEN_EDITOR_UNIT_ID_KEY];let ot=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._commandService=i,this._univerInstanceService=r,this._dialogService=e,this._renderManagerService=t,this._localeService=n,this._initDocImageCopyPasteHooks()}_setCellImage(i){var n;const r=l.createDocumentModelWithStyle("",{}),e=(n=j.getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(P.EditingRenderController),t=l.BuildTextUtils.drawing.add({documentDataModel:r,drawings:[i],selection:{collapsed:!0,startOffset:0,endOffset:0}});t&&(r.apply(t),e&&e.submitCellData(r))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(i=>{var r,e;if(i.id===et.InnerPasteCommand.id){const t=i.params,{doc:n}=t,o=this._univerInstanceService.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_DOC);if(o==null||!Object.keys((r=n.drawings)!=null?r:{}).length)return;const s=o.getUnitId();if(yn.includes(s)){if(s!==l.DOCS_ZEN_EDITOR_UNIT_ID_KEY){const a=()=>{this._dialogService.close("sheet-cell-image-copy-paste"),this._commandService.syncExecuteCommand(P.SetCellEditVisibleOperation.id,{visible:!1})};((e=o.getBody())==null?void 0:e.dataStream)===`\r
|
|
2
|
+
`?(this._commandService.syncExecuteCommand(P.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")}}}))}};ot=Dn([je(0,l.ICommandService),je(1,l.IUniverInstanceService),je(2,k.IDialogService),je(3,j.IRenderManagerService),je(4,l.Inject(l.LocaleService))],ot);var Cn=Object.getOwnPropertyDescriptor,Tn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Cn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},ke=(i,r)=>(e,t)=>r(e,t,i);const Gt="image/png";function Rn(i){const r=i.split(","),e=atob(r[1]),t=e.length,n=new Uint8Array(t);for(let o=0;o<t;o++)n[o]=e.charCodeAt(o);return new Blob([n],{type:Gt})}function Mn(i){const r=new ClipboardItem({[Gt]:Rn(i)});navigator.clipboard.write([r]).catch(e=>{console.error("Could not copy image using clipboard API: ",e)})}function bn(){function i(){const t=document.createElement("input");return t.style.position="absolute",t.style.height="1px",t.style.width="1px",t.style.opacity="0",t}const r=document.activeElement,e=i();return document.body.appendChild(e),e.focus(),()=>{e.blur(),document.body.removeChild(e),r instanceof HTMLElement&&r.focus()}}const Ft=[P.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,P.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,P.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,P.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA];let st=class extends l.Disposable{constructor(r,e,t,n,o){super();oe(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=e,this._drawingService=t,this._clipboardInterfaceService=n,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,e,t,n)=>{this._copyInfo=null;const o=this._focusedDrawings;if(o.length>0){const[s]=o;if(s.drawingType!==l.DrawingTypeEnum.DRAWING_IMAGE)return;if(n===P.COPY_TYPE.CUT){const c={unitId:r,drawings:[s]};this._commandService.executeCommand(Oe.id,c)}setTimeout(()=>{const c=bn();s.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&s.imageSourceType===x.ImageSourceType.BASE64?Mn(s.source):this._clipboardInterfaceService.writeText(""),c()},200);const a={unitId:s.unitId,subUnitId:s.subUnitId,drawings:[s]};this._copyInfo=a}else{const s=this._createDrawingsCopyInfoByRange(r,e,t);this._copyInfo=s}},onPasteCells:(r,e,t,n)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=P.COPY_TYPE.COPY,pasteType:s}=n,{range:a}=r||{},{range:c,unitId:g,subUnitId:u}=e;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:s,unitId:g,subUnitId:u,pasteRange:c},{copyRange:a,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:s},P.COPY_TYPE.COPY)},onPastePlainText:(r,e)=>({undos:[],redos:[]}),onPasteUnrecognized:r=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:P.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},P.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(r,e)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:r,pasteType:P.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},P.COPY_TYPE.COPY);{const t=e.filter(n=>n.type.includes("image"));if(t.length)return{undos:[],redos:[{id:Le.id,params:{files:t}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(r,e,t){var m;const n=(m=this._renderManagerService.getRenderById(r))==null?void 0:m.with(P.SheetSkeletonManagerService);if(!n)return;const o=n.attachRangeWithCoord(t);if(!o)return;const{startX:s,endX:a,startY:c,endY:g}=o,u=this._drawingService.getDrawingData(r,e),d=this._focusedDrawings.slice();if(Object.keys(u).forEach(h=>{const p=u[h];if(p.drawingType!==l.DrawingTypeEnum.DRAWING_IMAGE)return;const{transform:S}=p;if(p.anchorType!==w.SheetDrawingAnchorType.Both||!S)return;const{left:f=0,top:v=0,width:I=0,height:T=0}=S,{drawingStartX:O,drawingEndX:C,drawingStartY:y,drawingEndY:R}={drawingStartX:f,drawingEndX:f+I,drawingStartY:v,drawingEndY:v+T};s<=O&&C<=a&&c<=y&&R<=g&&d.push(p)}),d.length)return{copyRange:t,drawings:d,unitId:r,subUnitId:e}}_generateSingleDrawingPasteMutations(r,e){const{pasteType:t,pasteTo:n}=r;if(Ft.includes(t))return{redos:[],undos:[]};const{unitId:o,subUnitId:s,range:a}=n,c=this._renderManagerService.getRenderById(o),g=c==null?void 0:c.with(P.SheetSkeletonManagerService),u=c==null?void 0:c.with(P.ISheetSelectionRenderService),d=this._copyInfo;if(!g||!u)return{redos:[],undos:[]};const{drawings:m}=d,h=D.discreteRangeToRange(a);return this._generateMutations(m,{unitId:o,subUnitId:s,isCut:e===P.COPY_TYPE.CUT,getTransform:(p,S)=>{var I,T;const f=g.attachRangeWithCoord({startRow:h.startRow,endRow:h.endRow,startColumn:h.startColumn,endColumn:h.endColumn}),v={...p,left:f==null?void 0:f.startX,top:f==null?void 0:f.startY};return{transform:v,sheetTransform:(I=$(v,u))!=null?I:S,axisAlignSheetTransform:(T=Y(v,u))!=null?T:S}}})}_generateMutations(r,e){const{unitId:t,subUnitId:n,getTransform:o,isCut:s}=e,a=[],c=[],{_drawingService:g}=this;return r.forEach(u=>{const{transform:d,sheetTransform:m}=u;if(!d)return;const h=o(d,m),p={...u,unitId:t,subUnitId:n,drawingId:s?u.drawingId:l.generateRandomId(),transform:h.transform,sheetTransform:h.sheetTransform,axisAlignSheetTransform:h.axisAlignSheetTransform};if(s){const{undo:S,redo:f,objects:v}=g.getBatchUpdateOp([p]);a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:w.DrawingApplyType.UPDATE,op:f,objects:v}}),c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,type:w.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:f,objects:v}=g.getBatchAddOp([p]);a.push({id:w.SetDrawingApplyMutation.id,params:{op:f,unitId:t,subUnitId:n,objects:v,type:w.DrawingApplyType.INSERT}}),c.push({id:w.SetDrawingApplyMutation.id,params:{op:S,unitId:t,subUnitId:n,objects:v,type:w.DrawingApplyType.REMOVE}})}}),{redos:a,undos:c}}_generateRangeDrawingsPasteMutations(r,e){var M;const{unitId:t,subUnitId:n,pasteType:o,pasteRange:s}=r,{copyRange:a,copyType:c}=e;if(Ft.includes(o))return{redos:[],undos:[]};const g=(M=this._renderManagerService.getRenderById(t))==null?void 0:M.with(P.SheetSkeletonManagerService);if(!g||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!a)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:t,subUnitId:n,range:D.discreteRangeToRange(s)},pasteType:o},c);const{ranges:[d,m],mapFunc:h}=P.virtualizeDiscreteRanges([a,s]),{row:p,col:S}=h(d.startRow,d.startColumn),{row:f,col:v}=h(m.startRow,m.startColumn),I=g.attachRangeWithCoord({startRow:p,endRow:p,startColumn:S,endColumn:S}),T=g.attachRangeWithCoord({startRow:f,endRow:f,startColumn:v,endColumn:v});if(!I||!T||!this._copyInfo)return{redos:[],undos:[]};const O=T.startX-I.startX,C=T.startY-I.startY,y=f-p,R=v-S;return this._generateMutations(u,{unitId:t,subUnitId:n,getTransform:(U,b)=>{var W,B,J;const A={...U,left:((W=U==null?void 0:U.left)!=null?W:0)+O,top:((B=U==null?void 0:U.top)!=null?B:0)+C},_=this._renderManagerService.getRenderById(t),E=_==null?void 0:_.with(P.ISheetSelectionRenderService);return E?{transform:A,sheetTransform:{...b,to:{...b.to,row:b.to.row+y,column:b.to.column+R},from:{...b.from,row:b.from.row+y,column:b.from.column+R}},axisAlignSheetTransform:(J=Y(A,E))!=null?J:b}:{transform:A,sheetTransform:{...b,to:{...b.to,row:b.to.row+y,column:b.to.column+R},from:{...b.from,row:b.from.row+y,column:b.from.column+R}},axisAlignSheetTransform:{...b,to:{...b.to,row:b.to.row+y,column:b.to.column+R},from:{...b.from,row:b.from.row+y,column:b.from.column+R}}}},isCut:c===P.COPY_TYPE.CUT})}};st=Tn([ke(0,P.ISheetClipboardService),ke(1,j.IRenderManagerService),ke(2,x.IDrawingManagerService),ke(3,k.IClipboardInterfaceService),ke(4,l.ICommandService)],st);var En=Object.getOwnPropertyDescriptor,On=(i,r,e,t)=>{for(var n=t>1?void 0:t?En(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},We=(i,r)=>(e,t)=>r(e,t,i);let at=class extends l.Disposable{constructor(i,r,e,t,n){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=e,this._univerInstanceService=t,this._userManagerService=n,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,e=N.combineLatest([i,r]);this.disposeWithMe(e.pipe(N.switchMap(([t,n])=>t?t.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingVisible(!1);return}const s=t.getUnitId(),a=o.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(t,o)})):(this._drawingManagerService.setDrawingVisible(!1),N.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(i,r){this._drawingManagerService.setDrawingVisible(!1);const e=i.getUnitId(),t=r.getSheetId(),n=this._drawingManagerService.getDrawingData(e,t),o=Object.values(n),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===j.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&a.removeObject(g)})}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$,e=N.combineLatest([i,r]);this.disposeWithMe(e.pipe(N.switchMap(([t,n])=>t?t.activeSheet$.pipe(N.tap(o=>{if(!o){this._drawingManagerService.setDrawingEditable(!1);return}const s=t.getUnitId(),a=o.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(t,o)})):(this._drawingManagerService.setDrawingEditable(!1),N.EMPTY))).subscribe())}_handleDrawingEditableFalse(i,r){this._drawingManagerService.setDrawingEditable(!1);const e=i.getUnitId(),t=r.getSheetId(),n=this._drawingManagerService.getDrawingData(e,t),o=Object.values(n),s=this._renderManagerService.getRenderById(e),a=s==null?void 0:s.scene;if(!a)return;a.getAllObjectsByOrder().forEach(g=>{g.classType===j.RENDER_CLASS_TYPE.IMAGE&&o.some(u=>g.oKey.includes(u.drawingId))&&a.detachTransformerFrom(g)})}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([e,t])=>e?e.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=e.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),c=a==null?void 0:a.scene;if(!c)return N.EMPTY;const g=c.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookViewPermission(o).id,new D.WorksheetViewPermission(o,s).id]).pipe(N.map(d=>d.every(m=>m.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:c,transformer:g,unitId:o,subUnitId:s})))})):N.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:o,subUnitId:s})=>{this._drawingManagerService.setDrawingVisible(e);const a=t.getAllObjectsByOrder(),c=this._drawingManagerService.getDrawingData(o,s),g=Object.values(c);e?this._drawingManagerService.addNotification(g):(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&t.removeObject(u)}),n.clearSelectedObjects())},complete:()=>{this._drawingManagerService.setDrawingVisible(!0);const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),t=e==null?void 0:e.getActiveSheet(),n=e==null?void 0:e.getUnitId(),o=t==null?void 0:t.getSheetId();if(!n||!o)return;const s=this._drawingManagerService.getDrawingData(n,o),a=Object.values(s);this._drawingManagerService.addNotification(a)}}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),r=this._userManagerService.currentUser$;this.disposeWithMe(N.combineLatest([i,r]).pipe(N.switchMap(([e,t])=>e?e.activeSheet$.pipe(N.switchMap(n=>{if(!n)return N.EMPTY;const o=e.getUnitId(),s=n.getSheetId(),a=this._renderManagerService.getRenderById(o),c=a==null?void 0:a.scene;if(!c)return N.EMPTY;const g=c.getTransformerByCreate();return this._permissionService.composePermission$([new D.WorkbookEditablePermission(o).id,new D.WorksheetEditPermission(o,s).id]).pipe(N.map(d=>d.every(m=>m.value)),N.distinctUntilChanged()).pipe(N.map(d=>({permission:d,scene:c,transformer:g,unitId:o,subUnitId:s})))})):N.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:o,subUnitId:s})=>{this._drawingManagerService.setDrawingEditable(e);const a=t.getAllObjectsByOrder(),c=this._drawingManagerService.getDrawingData(o,s),g=Object.values(c);e?(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&t.attachTransformerTo(u)}),this._drawingManagerService.addNotification(g)):(a.forEach(u=>{u.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(d=>u.oKey.includes(d.drawingId))&&t.detachTransformerFrom(u)}),n.clearSelectedObjects())},complete:()=>{const e=this._univerInstanceService.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET);if(!e)return;const t=e.getUnitId(),n=e.getActiveSheet();if(!n)return;const o=n.getSheetId(),s=this._renderManagerService.getRenderById(t),a=s==null?void 0:s.scene;if(!a)return;const c=this._drawingManagerService.getDrawingData(t,o),g=Object.values(c);this._drawingManagerService.setDrawingEditable(!0),a.getAllObjectsByOrder().forEach(d=>{d.classType===j.RENDER_CLASS_TYPE.IMAGE&&g.some(m=>d.oKey.includes(m.drawingId))&&a.detachTransformerFrom(d)})}}))}};at=On([We(0,x.IDrawingManagerService),We(1,j.IRenderManagerService),We(2,l.IPermissionService),We(3,l.IUniverInstanceService),We(4,l.Inject(l.UserManagerService))],at);var An=Object.getOwnPropertyDescriptor,Un=(i,r,e,t)=>{for(var n=t>1?void 0:t?An(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},_e=(i,r)=>(e,t)=>r(e,t,i);const Ht="univer-sheet-float-dom-";function Vt(i,r,e,t,n,o=!1){const{scaleX:s,scaleY:a}=r.getAncestorScale(),c=r.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN),g=t.getFreeze(),{startColumn:u,startRow:d,xSplit:m,ySplit:h}=g,p={left:!0,top:!0};if(!c)return{...i,absolute:p};const{left:S,right:f,top:v,bottom:I}=i;let{top:T,left:O,viewportScrollX:C,viewportScrollY:y}=c;const{boundsOfViewArea:R,scrollDirectionResponse:M}=n||{},{rowHeaderWidth:U,columnHeaderHeight:b}=e,A={top:o?0:b,left:o?0:U};R&&(l.Tools.isDefine(A.top)&&(A.top=R.top),l.Tools.isDefine(A.left)&&(A.left=R.left)),M==="HORIZONTAL"&&(y=0),M==="VERTICAL"&&(C=0);let _=0,E=0;const W=e.rowStartY(d-h)+b,B=e.colStartX(u-m)+U,J=e.rowStartY(d)+b,te=e.colStartX(u)+U;if(m===0)p.left=!1,_=(S-C)*s,E=(f-C)*s;else{const H=S-(B-U),Z=f-(B-U);f<te?(_=H*s,E=Z*s):S<=te&&f>=te?(_=H*s,E=Math.max(O,(f-C)*s)):S>te&&(p.left=!1,_=Math.max((S-C)*s,O),E=Math.max((f-C)*s,O))}let K=0,z=0;if(h===0)p.top=!1,K=(v-y)*a,z=(I-y)*a;else{const H=v-(W-b),Z=I-(W-b);I<J?(K=H*a,z=Z*a):v<=J&&I>=J?(K=H*a,z=Math.max(T,(I-y)*a)):v>J&&(p.top=!1,K=Math.max((v-y)*a,T),z=Math.max((I-y)*a,T))}return _=Math.max(_,A.left),K=Math.max(K,A.top),E=Math.max(E,A.left),z=Math.max(z,A.top),{left:_,right:E,top:K,bottom:z,absolute:p}}const de=(i,r,e,t,n)=>{const{left:o,top:s,width:a,height:c,angle:g}=i,u={left:o,right:o+a,top:s,bottom:s+c},d=Vt(u,r,e,t,n),{scaleX:m,scaleY:h}=r.getAncestorScale();return{startX:d.left,endX:d.right,startY:d.top,endY:d.bottom,rotate:g,width:a*m,height:c*h,absolute:d.absolute}};exports.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(e,t,n,o,s,a,c){super();oe(this,"_domLayerInfoMap",new Map);oe(this,"_transformChange$",new N.Subject);oe(this,"transformChange$",this._transformChange$.asObservable());oe(this,"_add$",new N.Subject);oe(this,"add$",this._add$.asObservable());oe(this,"_remove$",new N.Subject);oe(this,"remove$",this._remove$.asObservable());this._renderManagerService=e,this._univerInstanceService=t,this._commandService=n,this._drawingManagerService=o,this._canvasFloatDomService=s,this._sheetDrawingService=a,this._lifecycleService=c,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(N.filter(e=>e===l.LifecycleStages.Rendered),N.take(1)).subscribe(()=>{this._scrollUpdateListener()})}getFloatDomInfo(e){return this._domLayerInfoMap.get(e)}getFloatDomsBySubUnitId(e,t){return Array.from(this._domLayerInfoMap.values()).filter(n=>n.subUnitId===t&&n.unitId===e)}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;const t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;if(t==null||n==null)return null;const o=n.getTransformerByCreate(),s=t.engine.getCanvasElement();return{scene:n,transformer:o,renderUnit:t,canvas:s}}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(t=>{var Z;const{unitId:n,subUnitId:o,drawingId:s}=t,a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:n,subUnitId:o}),c=this._drawingManagerService.getDrawingByParam(t),g=this._univerInstanceService.getUnit(n,l.UniverInstanceType.UNIVER_SHEET);if(!g)return;const u=g.getActiveSheet().getSheetId();if(!c||!a)return;const d=(Z=this._renderManagerService.getRenderById(n))==null?void 0:Z.with(P.SheetSkeletonManagerService).getSkeletonParam(o);if(!d)return;const{transform:m,drawingType:h,data:p}=c;if(h!==l.DrawingTypeEnum.DRAWING_DOM&&h!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(n);if(S==null)return;const{scene:f,canvas:v}=S;if(m==null)return!0;if(u!==o)return;const{left:I,top:T,width:O,height:C,angle:y,flipX:R,flipY:M,skewX:U,skewY:b}=m,A=x.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),_=f.getObject(A);if(_!=null){_.transformByState({left:I,top:T,width:O,height:C,angle:y,flipX:R,flipY:M,skewX:U,skewY:b});return}const E={left:I,top:T,width:O,height:C,zIndex:this._drawingManagerService.getDrawingOrder(n,o).length-1},W=h===l.DrawingTypeEnum.DRAWING_CHART;if(E.rotateEnabled=!1,W){const F=p?p.backgroundColor:"white";E.fill=F,p&&p.border&&(E.stroke=p.border),E.paintFirst="stroke",E.strokeWidth=1,E.borderEnabled=!1,E.radius=8}const B=new j.Rect(A,E);W&&B.setObjectType(j.ObjectType.CHART),f.addObject(B,j.DRAWING_OBJECT_LAYER_INDEX),c.allowTransform!==!1&&f.attachTransformerTo(B);const J=new l.DisposableCollection,te=de(B,S.renderUnit.scene,d.skeleton,a.worksheet),K=new N.BehaviorSubject(te),z=`${Ht}${l.generateRandomId(6)}`,ne={dispose:J,rect:B,position$:K,unitId:n,subUnitId:o,id:s,domId:z};this._canvasFloatDomService.addFloatDom({position$:K,id:s,domId:z,componentKey:c.componentKey,onPointerDown:F=>{v.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{v.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{v.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{v.dispatchEvent(new WheelEvent(F.type,F))},data:p,unitId:n});const H=B.onTransformChange$.subscribeEvent(()=>{const F=de(B,S.renderUnit.scene,d.skeleton,a.worksheet);K.next(F)});J.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),H&&J.add(H),this._domLayerInfoMap.set(s,ne)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{var m;const{unitId:n,subUnitId:o,drawingId:s}=t,a=x.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:o,drawingId:s}),c=this._getSceneAndTransformerByDrawingSearch(n);if(c==null)return;const{transformer:g,scene:u}=c,d=u.getObject(a);d!=null&&d.oKey&&(g.clearControlByIds([d==null?void 0:d.oKey]),(m=u.getTransformer())==null||m.clearSelectedObjects())})}))}_scrollUpdateListener(){const e=(t,n)=>{var g;const o=this._getSceneAndTransformerByDrawingSearch(t),s=Array.from(this._domLayerInfoMap.keys()).map(u=>({id:u,...this._domLayerInfoMap.get(u)})).filter(u=>u.subUnitId===n&&u.unitId===t).map(u=>u.id),a=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:n}),c=(g=this._renderManagerService.getRenderById(t))==null?void 0:g.with(P.SheetSkeletonManagerService).getSkeletonParam(n);!o||!a||!c||s.forEach(u=>{const d=this._domLayerInfoMap.get(u);if(d){const m=de(d.rect,o.renderUnit.scene,c.skeleton,a.worksheet,d);d.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(t=>t?t.activeSheet$:N.of(null)),N.map(t=>{if(!t)return null;const n=t.getUnitId(),o=this._renderManagerService.getRenderById(n);return o?{render:o,unitId:n,subUnitId:t.getSheetId()}:null}),N.switchMap(t=>t?l.fromEventSubject(t.render.scene.getViewport(j.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(N.map(()=>({unitId:t.unitId,subUnitId:t.subUnitId}))):N.of(null))).subscribe(t=>{if(!t)return;const{unitId:n,subUnitId:o}=t;e(n,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===P.SetZoomRatioOperation.id){const n=t.params,{unitId:o}=n;Array.from(this._domLayerInfoMap.values()).filter(a=>a.unitId===o).map(a=>a.subUnitId).forEach(a=>{e(o,a)})}else if(t.id===D.SetFrozenMutation.id){const{unitId:n,subUnitId:o}=t.params;e(n,o)}else if(t.id===D.SetSelectionsOperation.id){const{unitId:n,subUnitId:o}=t.params;e(n,o)}}))}updateFloatDomProps(e,t,n,o){const s=this._domLayerInfoMap.get(n),a=this._getSceneAndTransformerByDrawingSearch(e);if(s&&a){const{scene:c}=a,g=x.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:t,drawingId:n}),u=c.getObject(g);u&&u instanceof j.Rect&&u.setProps(o)}}_getPosition(e,t){var h;const{startX:n,endX:o,startY:s,endY:a}=e,c=(h=this._renderManagerService.getRenderById(t))==null?void 0:h.with(P.ISheetSelectionRenderService);if(c==null)return;const g=c.getCellWithCoordByOffset(n,s);if(g==null)return;const u={column:g.actualColumn,columnOffset:n-g.startX,row:g.actualRow,rowOffset:s-g.startY},d=c.getCellWithCoordByOffset(o,a);if(d==null)return;const m={column:d.actualColumn,columnOffset:o-d.startX,row:d.actualRow,rowOffset:a-d.startY};return{from:u,to:m}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(t=>{const n=this._drawingManagerService.getDrawingByParam(t);if(!n||n.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...n.transform};this._transformChange$.next({id:t.drawingId,value:o}),this._canvasFloatDomService.updateFloatDom(t.drawingId,{...n});const s=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(s&&n.drawingType!==l.DrawingTypeEnum.DRAWING_CHART){const{scene:a}=s,c=this._domLayerInfoMap.get(t.drawingId);c!=null&&c.rect&&(n.allowTransform===!1?a.detachTransformerFrom(c.rect):a.attachTransformerTo(c.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(t=>{this._removeDom(t.drawingId)})}))}addFloatDomToPosition(e,t){const n=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!n)throw new Error("cannot find current target!");const{unitId:o,subUnitId:s}=n,{initPosition:a,componentKey:c,data:g,allowTransform:u=!0}=e,d=t!=null?t:l.generateRandomId(),m=this._getPosition(a,o);if(m==null)return;const h={unitId:o,subUnitId:s,drawingId:d,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:c,sheetTransform:m,transform:{left:a.startX,top:a.startY,width:a.endX-a.startX,height:a.endY-a.startY},axisAlignSheetTransform:m,data:g,allowTransform:u};return this._commandService.executeCommand(Fe.id,{unitId:o,drawings:[h]}),this._add$.next({unitId:o,subUnitId:s,id:d}),{id:d,dispose:()=>{this._removeDom(d,!0)}}}_removeDom(e,t=!1){const n=this._domLayerInfoMap.get(e);if(!n)return;const{unitId:o,subUnitId:s}=n;this._domLayerInfoMap.delete(e),n.dispose.dispose();const a=this._getSceneAndTransformerByDrawingSearch(o);if(a&&a.scene.removeObject(n.rect),t){const c=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:e});if(!c)return;const g=this._sheetDrawingService.getBatchRemoveOp([c]),{redo:u,objects:d}=g;this._commandService.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:u,objects:d,type:w.DrawingApplyType.REMOVE})}}addFloatDomToRange(e,t,n,o){var R,M,U;const s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:c}=s,g=this._getSceneAndTransformerByDrawingSearch(a);if(!g)return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(R=this._renderManagerService.getRenderById(a))==null?void 0:R.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:m,data:h,allowTransform:p=!0}=t,S=o!=null?o:l.generateRandomId(),{position:f,position$:v}=this._createRangePositionObserver(e,u,d.skeleton);if(this._getPosition(f,a)==null)return;const T=g.scene,{scaleX:O}=T.getAncestorScale(),C=Je(f,n,O),y={unitId:a,subUnitId:c,drawingId:S,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:C.startX,top:C.startY,width:C.width,height:C.height},data:h,allowTransform:p};{const{unitId:b,subUnitId:A,drawingId:_}=y,E=D.getSheetCommandTarget(this._univerInstanceService,{unitId:b,subUnitId:A}),W=y,B=this._univerInstanceService.getUnit(b,l.UniverInstanceType.UNIVER_SHEET);if(!B)return;const J=B.getActiveSheet().getSheetId();if(!W||!E)return;const te=(M=this._renderManagerService.getRenderById(b))==null?void 0:M.with(P.SheetSkeletonManagerService);if(!te)return;const K=te.getWorksheetSkeleton(A);if(!K)return;const{transform:z,drawingType:ne,data:H}=W;if(ne!==l.DrawingTypeEnum.DRAWING_DOM&&ne!==l.DrawingTypeEnum.DRAWING_CHART)return;const Z=this._getSceneAndTransformerByDrawingSearch(b);if(Z==null)return;const{scene:F,canvas:se}=Z;if(z==null||J!==A)return;const{left:le,top:ae,width:pe,height:Se,angle:ut,flipX:gt,flipY:Ye,skewX:Ge,skewY:De}=z,He=x.getDrawingShapeKeyByDrawingSearch({unitId:b,subUnitId:A,drawingId:_}),ue=F.getObject(He);if(ue!=null){ue.transformByState({left:le,top:ae,width:pe,height:Se,angle:ut,flipX:gt,flipY:Ye,skewX:Ge,skewY:De});return}const ie={left:le,top:ae,width:pe,height:Se,zIndex:this._drawingManagerService.getDrawingOrder(b,A).length-1},ye=ne===l.DrawingTypeEnum.DRAWING_CHART;if(ye){const L=H?H.backgroundColor:"white";ie.fill=L,ie.rotateEnabled=!1,H&&H.border&&(ie.stroke=H.border),ie.paintFirst="stroke",ie.strokeWidth=1,ie.borderEnabled=!1,ie.radius=8}const ge=new j.Rect(He,ie);ye&&ge.setObjectType(j.ObjectType.CHART),F.addObject(ge,j.DRAWING_OBJECT_LAYER_INDEX),W.allowTransform!==!1&&F.attachTransformerTo(ge);const he=new l.DisposableCollection,Ve=F.getMainViewport(),{rowHeaderWidth:Ce,columnHeaderHeight:Pe}=K.skeleton,Xe={top:Pe,left:Ce,bottom:Ve.bottom,right:Ve.right},me={dispose:he,rect:ge,boundsOfViewArea:Xe,domAnchor:n,unitId:b,subUnitId:A},q=de(ge,Z.renderUnit.scene,K.skeleton,E.worksheet,me),Te=new N.BehaviorSubject(q);me.position$=Te;let Ne={position$:Te,id:_,componentKey:W.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:L=>{se.dispatchEvent(new WheelEvent(L.type,L))},data:H,unitId:b};t.eventPassThrough&&(Ne={...Ne,onPointerDown:L=>{se.dispatchEvent(new PointerEvent(L.type,L))},onPointerMove:L=>{se.dispatchEvent(new PointerEvent(L.type,L))},onPointerUp:L=>{se.dispatchEvent(new PointerEvent(L.type,L))}}),this._canvasFloatDomService.addFloatDom(Ne),this.disposeWithMe(v.subscribe(L=>{var At,Ut,Pt,Nt;const Ot=Je({startX:L.startX,startY:L.startY,endX:L.endX,endY:L.endY,width:(At=n.width)!=null?At:L.width,height:(Ut=n.height)!=null?Ut:L.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),zt=x.getDrawingShapeKeyByDrawingSearch({unitId:b,subUnitId:A,drawingId:_}),qt=new j.Rect(zt,{left:Ot.startX,top:Ot.startY,width:(Pt=n.width)!=null?Pt:L.width,height:(Nt=n.height)!=null?Nt:L.height,zIndex:this._drawingManagerService.getDrawingOrder(b,A).length-1}),Zt=de(qt,Z.renderUnit.scene,K.skeleton,E.worksheet,me);Te.next(Zt)}));const xe=(U=this._renderManagerService.getRenderById(b))==null?void 0:U.with(P.SheetSkeletonManagerService);xe==null||xe.currentSkeleton$.subscribe(L=>{L&&K.sheetId!==L.sheetId&&this._removeDom(S,!0)});const Ke=ge.onTransformChange$.subscribeEvent(()=>{const L=de(ge,Z.renderUnit.scene,K.skeleton,E.worksheet,me);Te.next(L)});he.add(()=>{this._canvasFloatDomService.removeFloatDom(_)}),Ke&&he.add(Ke),this._domLayerInfoMap.set(_,me)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(e,t,n,o){var C,y,R;const s=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t.unitId,subUnitId:t.subUnitId});if(!s)throw new Error("cannot find current target!");const{unitId:a,subUnitId:c}=s;if(!this._getSceneAndTransformerByDrawingSearch(a))return;const u=this._renderManagerService.getRenderById(a);if(!u)return;const d=(C=this._renderManagerService.getRenderById(a))==null?void 0:C.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(c);if(!d)return;const{componentKey:m,data:h,allowTransform:p=!0}=t,S=o!=null?o:l.generateRandomId(),{position:f,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:e,endColumn:e},u,d.skeleton),I=f;if(I.startY=0,this._getPosition(f,a)==null)return;const O={unitId:a,subUnitId:c,drawingId:S,drawingType:t.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:m,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:h,allowTransform:p};{const{unitId:M,subUnitId:U,drawingId:b}=O,A=D.getSheetCommandTarget(this._univerInstanceService,{unitId:M,subUnitId:U}),_=O,E=this._univerInstanceService.getUnit(M,l.UniverInstanceType.UNIVER_SHEET);if(!E)return;const W=E.getActiveSheet().getSheetId();if(!_||!A)return;const B=(y=this._renderManagerService.getRenderById(M))==null?void 0:y.with(P.SheetSkeletonManagerService);if(!B)return;const J=B.getWorksheetSkeleton(U);if(!J)return;const{transform:te,data:K}=_,z=this._getSceneAndTransformerByDrawingSearch(M);if(z==null)return;const{scene:ne,canvas:H}=z;if(te==null||W!==U)return;const{left:Z,top:F,width:se,height:le,angle:ae,flipX:pe,flipY:Se,skewX:ut,skewY:gt}=te,Ye=x.getDrawingShapeKeyByDrawingSearch({unitId:M,subUnitId:U,drawingId:b}),Ge=ne.getObject(Ye);if(Ge!=null){Ge.transformByState({left:Z,top:F,width:se,height:le,angle:ae,flipX:pe,flipY:Se,skewX:ut,skewY:gt});return}const De=Je({startX:I.startX,startY:0,endX:f.endX,endY:f.endY,width:n.width,height:n.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),He={left:De.startX,top:De.startY,width:De.width,height:De.height,zIndex:this._drawingManagerService.getDrawingOrder(M,U).length-1},ue=new j.Rect(Ye,He);ne.addObject(ue,j.DRAWING_OBJECT_LAYER_INDEX),_.allowTransform!==!1&&ne.attachTransformerTo(ue);const ie=new l.DisposableCollection,ye=ne.getMainViewport(),ge={top:0,left:ye.left,bottom:ye.bottom,right:ye.right},he={dispose:ie,rect:ue,unitId:M,subUnitId:U,boundsOfViewArea:ge,domAnchor:n,scrollDirectionResponse:"HORIZONTAL"},Ve=de(ue,z.renderUnit.scene,J.skeleton,A.worksheet,he),Ce=new N.BehaviorSubject(Ve);he.position$=Ce;let Pe={position$:Ce,id:b,componentKey:_.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:q=>{H.dispatchEvent(new WheelEvent(q.type,q))},data:K,unitId:M};t.eventPassThrough&&(Pe={...Pe,onPointerDown:q=>{H.dispatchEvent(new PointerEvent(q.type,q))},onPointerMove:q=>{H.dispatchEvent(new PointerEvent(q.type,q))},onPointerUp:q=>{H.dispatchEvent(new PointerEvent(q.type,q))}}),this._canvasFloatDomService.addFloatDom(Pe);const Xe=ue.onTransformChange$.subscribeEvent(()=>{const q=de(ue,z.renderUnit.scene,J.skeleton,A.worksheet,he);Ce.next(q)});this.disposeWithMe(v.subscribe(q=>{const Te=Je({startX:q.startX,startY:0,endX:q.endX,endY:q.endY,width:n.width,height:n.height,absolute:{left:f.absolute.left,top:f.absolute.top}},n),Ne=x.getDrawingShapeKeyByDrawingSearch({unitId:M,subUnitId:U,drawingId:b}),xe=new j.Rect(Ne,{left:Te.startX,top:0,width:n.width,height:n.height,zIndex:this._drawingManagerService.getDrawingOrder(M,U).length-1}),Ke=de(xe,z.renderUnit.scene,J.skeleton,A.worksheet,he);Ce.next(Ke)}));const me=(R=this._renderManagerService.getRenderById(M))==null?void 0:R.with(P.SheetSkeletonManagerService);me==null||me.currentSkeleton$.subscribe(q=>{q&&d.sheetId!==q.sheetId&&this._removeDom(S,!0)}),ie.add(()=>{this._canvasFloatDomService.removeFloatDom(b)}),Xe&&ie.add(Xe),this._domLayerInfoMap.set(b,he)}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(e,t,n){let{startRow:o,startColumn:s}=e;const a=Be(o,s,n),c=new N.BehaviorSubject(a),g=Be(e.endRow,e.endColumn,n),u=new N.BehaviorSubject(g),d=()=>{const v=Be(o,s,n),I=Be(e.endRow,e.endColumn,n);c.next(v),u.next(I)},m=new l.DisposableCollection;m.add(t.engine.clientRect$.subscribe(()=>d())),m.add(this._commandService.onCommandExecuted(v=>{if(v.id===D.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(T=>T.row===o)>-1){d();return}(D.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===P.SetScrollOperation.id||v.id===P.SetZoomRatioOperation.id)&&d()}));const h=(v,I)=>{o=v,s=I,d()},p=()=>({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}),S=c.pipe(N.map(v=>{const I=Be(e.endRow,e.endColumn,n);return{rotate:0,width:I.right-v.left,height:I.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:I.right,endY:I.bottom}})),f=p();return{position$:S,position:f,updateRowCol:h,topLeftPos$:c,rightBottomPos$:u,disposable:m}}};exports.SheetCanvasFloatDomManagerService=Un([_e(0,l.Inject(j.IRenderManagerService)),_e(1,l.IUniverInstanceService),_e(2,l.Inject(l.ICommandService)),_e(3,x.IDrawingManagerService),_e(4,l.Inject(k.CanvasFloatDomService)),_e(5,w.ISheetDrawingService),_e(6,l.Inject(l.LifecycleService))],exports.SheetCanvasFloatDomManagerService);function Be(i,r,e){const t=e.getCellWithCoordByIndex(i,r),n=t.isMergedMainCell?t.mergeInfo:t;return{left:n.startX,right:n.endX,top:n.startY,bottom:n.endY}}function Je(i,r,e){var g,u;e=e!=null?e:1;const t=i.endX-i.startX,n=i.endY-i.startY,o=(g=r==null?void 0:r.width)!=null?g:t,s=(u=r==null?void 0:r.height)!=null?u:n;let a=0,c=0;if(r){if(r.horizonOffsetAlign==="right"){const d=Qe(r.marginX,t*e);a=i.endX-d-o}else a=i.startX+Qe(r.marginX,t);if(r.verticalOffsetAlign==="bottom"){const d=Qe(r.marginY,n*e);c=i.endY-d-s}else c=i.startY+Qe(r.marginY,n)}return{rotate:0,startX:a,startY:c,endX:i.endX,endY:i.endY,width:o,height:s,absolute:{left:i.absolute.left,top:i.absolute.top}}}function Qe(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const e=Number.parseFloat(i);return r*e/100}const Pn=i=>{const{floatDomInfos:r,scene:e,skeleton:t,worksheet:n}=i,o=Q.useMemo(()=>r.map(s=>{const{width:a,height:c,angle:g,left:u,top:d}=s.transform,m=Vt({left:u!=null?u:0,right:(u!=null?u:0)+(a!=null?a:0),top:d!=null?d:0,bottom:(d!=null?d:0)+(c!=null?c:0)},e,t,n,void 0,!0),{scaleX:h,scaleY:p}=e.getAncestorScale(),S={startX:m.left,endX:m.right,startY:m.top,endY:m.bottom,rotate:g,width:a*h,height:c*p,absolute:m.absolute},f={position$:new N.BehaviorSubject(S),position:S,id:s.drawingId,componentKey:s.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:s.unitId,data:s.data};return[s.drawingId,f]}),[r,e,t,n]);return G.jsx("div",{style:{position:"absolute",top:0,left:0},children:o.map(([s,a])=>G.jsx(k.PrintFloatDomSingle,{layer:a,id:s,position:a.position},s))})};var Nn=Object.getOwnPropertyDescriptor,xn=(i,r,e,t)=>{for(var n=t>1?void 0:t?Nn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Ie=(i,r)=>(e,t)=>r(e,t,i);let ct=class extends l.Disposable{constructor(i,r,e,t,n,o,s){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=e,this._renderManagerService=t,this._canvasFloatDomManagerService=n,this._componetManager=o,this._injector=s,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,e)=>{const{unitId:t,scene:n,subUnitId:o}=r,s=this._drawingManagerService.getDrawingDataForUnit(t),a=s==null?void 0:s[o];return a&&a.order.forEach(c=>{const g=a.data[c];g.drawingType!==l.DrawingTypeEnum.DRAWING_CHART&&g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&this._drawingRenderService.renderDrawing(g,n)}),e()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,e)=>{const{unitId:t,subUnitId:n}=r,o=this._renderManagerService.getRenderById(t);if(!o)return e(i);const s=o.with(P.SheetSkeletonManagerService).getSkeletonParam(n);if(!s)return e(i);const a=this._drawingManagerService.getDrawingDataForUnit(t),c=a==null?void 0:a[r.subUnitId];if(!c)return e(i);const{scaleX:g,scaleY:u}=o.scene,d=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=c.order.map(h=>c.data[h]);return m.length?(m.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 p=s.skeleton.getCellIndexByOffset(h.transform.left,h.transform.top,g,u,{x:0,y:0}),S=s.skeleton.getCellIndexByOffset(h.transform.left+h.transform.width,h.transform.top+h.transform.height,g,u,{x:0,y:0});p.column<d.startColumn&&(d.startColumn=p.column),p.row<d.startRow&&(d.startRow=p.row),d.endRow<S.row&&(d.endRow=S.row),d.endColumn<S.column&&(d.endColumn=S.column)}}),e(d)):e(i)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(i,r,e)=>{const{unitId:t,subUnitId:n}=r,o=this._drawingManagerService.getDrawingDataForUnit(t),s=o==null?void 0:o[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 d=this._sheetPrintInterceptorService.getPrintComponent(u.componentKey);return{...u,componentKey:this._componetManager.get(d||u.componentKey)}}return null}).filter(Boolean),c=k.connectInjector(Pn,this._injector);return V.render(G.jsx(c,{floatDomInfos:a,scene:r.scene,skeleton:r.skeleton,worksheet:r.worksheet}),r.root),i==null||i.add(()=>{V.unmount(r.root)}),e(i)}}}))}};ct=xn([Ie(0,l.Inject(P.SheetPrintInterceptorService)),Ie(1,l.Inject(ve.DrawingRenderService)),Ie(2,x.IDrawingManagerService),Ie(3,j.IRenderManagerService),Ie(4,l.Inject(exports.SheetCanvasFloatDomManagerService)),Ie(5,l.Inject(k.ComponentManager)),Ie(6,l.Inject(l.Injector))],ct);var jn=Object.getOwnPropertyDescriptor,kn=(i,r,e,t)=>{for(var n=t>1?void 0:t?jn(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},fe=(i,r)=>(e,t)=>r(e,t,i);const Wn=[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],Bn=[D.SetRowVisibleMutation.id,D.SetRowHiddenMutation.id,D.SetColVisibleMutation.id,D.SetColHiddenMutation.id,D.SetWorksheetRowHeightMutation.id,D.SetWorksheetRowAutoHeightMutation.id,D.SetWorksheetRowIsAutoHeightMutation.id,D.SetWorksheetColWidthMutation.id];let It=class extends l.Disposable{constructor(i,r,e,t,n,o,s,a,c){super(),this._context=i,this._renderManagerService=r,this._commandService=e,this._selectionRenderService=t,this._skeletonManagerService=n,this._sheetInterceptorService=o,this._sheetDrawingService=s,this._drawingManagerService=a,this._univerInstanceService=c,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptAfterCommand({getMutations:i=>{if(!Wn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===D.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===D.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===D.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===D.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===D.DeleteRangeMoveLeftCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,0)}else if(r===D.DeleteRangeMoveUpCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,1)}else if(r===D.InsertRangeMoveDownCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,2)}else if(r===D.InsertRangeMoveRightCommand.id){const{range:e}=i.params;return this._getRangeMoveUndo(e,3)}else if(r===D.SetRowHiddenCommand.id||r===D.SetSpecificRowsVisibleCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:o}=e;return this._getDrawingUndoForRowVisible(t,n,o)}else if(r===D.SetSpecificColsVisibleCommand.id||r===D.SetColHiddenCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:o}=e;return this._getDrawingUndoForColVisible(t,n,o)}else if(r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id||r===D.DeltaColumnWidthCommand.id||r===D.SetColWidthCommand.id){const e=i.params,{unitId:t,subUnitId:n,ranges:o}=e,s=r===D.DeltaRowHeightCommand.id||r===D.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(t,n,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const e=D.getSheetCommandTarget(this._univerInstanceService);if(e==null)return{redos:[],undos:[]};const t=e.unitId,n=e.subUnitId,o=[],s=[],a=this._sheetDrawingService.getDrawingData(t,n),c=[],g=[];if(Object.keys(a).forEach(u=>{const d=a[u],{updateDrawings:m,deleteDrawings:h}=this._getUpdateOrDeleteDrawings(i,r,d);c.push(...m),g.push(...h)}),c.length===0&&g.length===0)return{redos:[],undos:[]};if(c.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(c),{undo:d,redo:m,objects:h}=u;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:m,objects:h,type:w.DrawingApplyType.UPDATE}}),s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:h,type:w.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),d=u.undo,m=u.redo,h=u.objects;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:m,objects:h,type:w.DrawingApplyType.REMOVE}}),s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:d,objects:h,type:w.DrawingApplyType.INSERT}})}return o.push({id:X.id,params:[t]}),s.push({id:X.id,params:[t]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,r,e){var M,U,b,A;const t=[],n=[],{sheetTransform:o,anchorType:s=w.SheetDrawingAnchorType.Position,transform:a,unitId:c,subUnitId:g,drawingId:u}=e,{from:d,to:m}=o,{row:h,column:p}=d,{row:S,column:f}=m;if(o==null||a==null)return{updateDrawings:t,deleteDrawings:n};const{startRow:v,endRow:I,startColumn:T,endColumn:O}=i;let C=null,y=null,R;if(r===0&&h>=v&&S<=I)if(p>=T&&f<=O)n.push({unitId:c,subUnitId:g,drawingId:u});else{const _=this._shrinkCol(o,a,T,O,s);C=_==null?void 0:_.newSheetTransform,y=_==null?void 0:_.newTransform,R=(M=_==null?void 0:_.axisAlignSheetTransform)!=null?M:void 0}else if(r===1&&p>=T&&f<=O)if(h>=v&&S<=I)n.push({unitId:c,subUnitId:g,drawingId:u});else{const _=this._shrinkRow(o,a,v,I,s);C=_==null?void 0:_.newSheetTransform,y=_==null?void 0:_.newTransform,R=(U=_==null?void 0:_.axisAlignSheetTransform)!=null?U:void 0}else if(r===2){const _=this._expandRow(o,a,v,I,s);C=_==null?void 0:_.newSheetTransform,y=_==null?void 0:_.newTransform,R=(b=_==null?void 0:_.axisAlignSheetTransform)!=null?b:void 0}else if(r===3){const _=this._expandCol(o,a,T,O,s);C=_==null?void 0:_.newSheetTransform,y=_==null?void 0:_.newTransform,R=(A=_==null?void 0:_.axisAlignSheetTransform)!=null?A:void 0}if(C!=null&&y!=null){const _=ee(C,this._selectionRenderService,this._skeletonManagerService);t.push({...e,sheetTransform:C,transform:_,axisAlignSheetTransform:R})}return{updateDrawings:t,deleteDrawings:n}}_remainDrawingSize(i,r,e){const t=$({...i},this._selectionRenderService);if(t!=null){const n=Y({...i},this._selectionRenderService);r.push({...e,sheetTransform:t,axisAlignSheetTransform:n})}}_getDrawingUndoForColVisible(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(t).forEach(u=>{const d=t[u],{sheetTransform:m,transform:h,anchorType:p=w.SheetDrawingAnchorType.Position}=d;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:f}=m,{row:v,column:I}=S,{row:T,column:O}=f;for(let C=0;C<e.length;C++){const y=e[C],{startRow:R,endRow:M,startColumn:U,endColumn:b}=y;if(O<U)continue;if(p===w.SheetDrawingAnchorType.Position){let E=null,W=null;if(I>=U&&I<=b){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:b,startRow:S.row,endRow:f.row});if(B==null)return;W={...h,left:B.startX}}if(W!=null){E=$(W,this._selectionRenderService);const B=Y(W,this._selectionRenderService);if(E!=null&&W!=null){n.push({...d,sheetTransform:E,transform:W,axisAlignSheetTransform:B});break}}this._remainDrawingSize(h,n,d);continue}if(I>=U&&O<=b)continue;let A=null,_=null;if(I>=U&&I<=b){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:b,startRow:S.row,endRow:f.row});if(E==null)return;_={...h,left:(E==null?void 0:E.startX)||0,width:((h==null?void 0:h.width)||0)-E.endX+E.startX}}else if(O>=U&&O<=b){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:U,endColumn:O,startRow:S.row,endRow:f.row});if(E==null)return;_={...h,left:E.startX-((h==null?void 0:h.width)||0)}}else{const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:U,endColumn:b,startRow:S.row,endRow:f.row});if(E==null)return;if(_={...h,width:((h==null?void 0:h.width)||0)-E.endX+E.startX},A=$(_,this._selectionRenderService),A!=null&&_!=null){const W=Y(_,this._selectionRenderService);o.push({...d,sheetTransform:A,transform:_,axisAlignSheetTransform:W});break}}if(_!=null&&(A=$(_,this._selectionRenderService)),_!=null&&A!=null){const E=Y(_,this._selectionRenderService);n.push({...d,sheetTransform:A,transform:_,axisAlignSheetTransform:E});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,n),c=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);c.push(...u),g.push(...d)}return{redos:s,undos:a,preRedos:c,preUndos:g}}_createUndoAndRedoMutation(i,r,e){const t=this._sheetDrawingService.getBatchUpdateOp(e),{undo:n,redo:o,objects:s}=t,a=[{id:w.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:s,type:w.DrawingApplyType.UPDATE}},{id:X.id,params:[i]}],c=[{id:w.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:n,objects:s,type:w.DrawingApplyType.UPDATE}},{id:X.id,params:[i]}];return{redos:a,undos:c}}_getDrawingUndoForRowVisible(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[],o=[];if(Object.keys(t).forEach(u=>{const d=t[u],{sheetTransform:m,transform:h,anchorType:p=w.SheetDrawingAnchorType.Position}=d;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(h,n,d);else{const{from:S,to:f}=m,{row:v,column:I}=S,{row:T,column:O}=f;for(let C=0;C<e.length;C++){const y=e[C],{startRow:R,endRow:M,startColumn:U,endColumn:b}=y;if(T<R)continue;if(p===w.SheetDrawingAnchorType.Position){let E=null,W=null;if(v>=R&&v<=M){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:v,endRow:M});if(B==null)return;W={...h,top:B.startY}}if(W!=null){E=$(W,this._selectionRenderService);const B=Y(W,this._selectionRenderService);if(E!=null&&W!=null){n.push({...d,sheetTransform:E,transform:W,axisAlignSheetTransform:B});break}}this._remainDrawingSize(h,n,d);continue}if(v>=R&&T<=M)continue;let A=null,_=null;if(v>=R&&v<=M){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:v,endRow:M});if(E==null)return;_={...h,top:(E==null?void 0:E.startY)||0,height:((h==null?void 0:h.height)||0)-E.endY+E.startY}}else if(T>=R&&T<=M){const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:R,endRow:T});if(E==null)return;_={...h,top:E.startY-((h==null?void 0:h.height)||0)}}else{const E=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:R,endRow:M});if(E==null)return;if(_={...h,height:((h==null?void 0:h.height)||0)-E.endY+E.startY},A=$(_,this._selectionRenderService),A!=null&&_!=null){const W=Y(_,this._selectionRenderService);o.push({...d,sheetTransform:A,transform:_,axisAlignSheetTransform:W});break}}if(_!=null&&(A=$(_,this._selectionRenderService)),_!=null&&A!=null){const E=Y(_,this._selectionRenderService);n.push({...d,sheetTransform:A,transform:_,axisAlignSheetTransform:E});break}else this._remainDrawingSize(h,n,d)}}}),n.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:a}=this._createUndoAndRedoMutation(i,r,n),c=[],g=[];if(o.length>0){const{redos:u,undos:d}=this._createUndoAndRedoMutation(i,r,o);c.push(...u),g.push(...d)}return{redos:s,undos:a,preRedos:c,preUndos:g}}_getDrawingUndoForRowAndColSize(i,r,e,t){const n=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(n).forEach(s=>{const a=n[s],{sheetTransform:c,transform:g,anchorType:u=w.SheetDrawingAnchorType.Position}=a;if(u===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,o,a);else{const{from:d,to:m}=c,{row:h,column:p}=d,{row:S,column:f}=m;for(let v=0;v<e.length;v++){const I=e[v],{startRow:T,endRow:O,startColumn:C,endColumn:y}=I;if(S<T||f<C)continue;if(u===w.SheetDrawingAnchorType.Position&&(h<=T&&S>=O||p<=C&&f>=y)){this._remainDrawingSize(g,o,a);continue}const R=ee({...c},this._selectionRenderService,this._skeletonManagerService);if(R!=null){o.push({...a,transform:R});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let e,t;if(r==="insert")e=i.unitId,t=i.subUnitId;else{const n=D.getSheetCommandTarget(this._univerInstanceService);if(n==null)return;e=n.unitId,t=n.subUnitId}return{unitId:e,subUnitId:t}}_moveRangeInterceptor(i){var T,O;const{toRange:r,fromRange:e}=i,t=D.getSheetCommandTarget(this._univerInstanceService);if(!t)return{redos:[],undos:[]};const{unitId:n,subUnitId:o}=t,s=(O=(T=this._renderManagerService.getRenderById(n))==null?void 0:T.with(P.SheetSkeletonManagerService))==null?void 0:O.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const a=P.attachRangeWithCoord(s,e);if(!a)return{redos:[],undos:[]};const{startX:c,endX:g,startY:u,endY:d}=a,m=this._sheetDrawingService.getDrawingData(n,o),h=[];Object.keys(m).forEach(C=>{const y=m[C];if(y.anchorType!==w.SheetDrawingAnchorType.Both)return;const{transform:R}=y;if(!R)return;const{left:M=0,top:U=0,width:b=0,height:A=0}=R,{drawingStartX:_,drawingEndX:E,drawingStartY:W,drawingEndY:B}={drawingStartX:M,drawingEndX:M+b,drawingStartY:U,drawingEndY:U+A};c<=_&&E<=g&&u<=W&&B<=d&&h.push(y)});const p=[],S=[],f=r.startRow-e.startRow,v=r.startColumn-e.startColumn,I=h.map(C=>{const y=C.sheetTransform,R={to:{...y.to,row:y.to.row+f,column:y.to.column+v},from:{...y.from,row:y.from.row+f,column:y.from.column+v}},M=ee(R,this._selectionRenderService,this._skeletonManagerService);return{unitId:n,subUnitId:o,drawingId:C.drawingId,transform:M,sheetTransform:R}});if(I.length){const C=this._sheetDrawingService.getBatchUpdateOp(I),{undo:y,redo:R,objects:M}=C;p.push({id:w.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:R,objects:M,type:w.DrawingApplyType.UPDATE}}),S.push({id:w.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:o,op:y,objects:M,type:w.DrawingApplyType.UPDATE}})}return{redos:p,undos:S}}_moveRowInterceptor(i,r){const e=this._getUnitIdAndSubUnitId(i,r);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=e,{range:o}=i,s=o.startRow,a=o.endRow,c=[],g=[],u=this._sheetDrawingService.getDrawingData(t,n),d=[],m=[];if(Object.keys(u).forEach(h=>{var y,R;const p=u[h],{sheetTransform:S,transform:f,anchorType:v=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,T,O;if(r==="insert"){const M=this._expandRow(S,f,s,a,v);I=M==null?void 0:M.newSheetTransform,T=M==null?void 0:M.newTransform,O=(y=M==null?void 0:M.axisAlignSheetTransform)!=null?y:void 0}else{const{from:M,to:U}=S,{row:b}=M,{row:A}=U;if(v===w.SheetDrawingAnchorType.Both&&b>=s&&A<=a)m.push({unitId:t,subUnitId:n,drawingId:h});else{const _=this._shrinkRow(S,f,s,a,v);I=_==null?void 0:_.newSheetTransform,T=_==null?void 0:_.newTransform,O=(R=_==null?void 0:_.axisAlignSheetTransform)!=null?R:void 0}}if(!I||!T)return;const C={unitId:t,subUnitId:n,drawingId:h,transform:T,sheetTransform:I,axisAlignSheetTransform:O};d.push(C)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:S,objects:f}=h;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),p=h.undo,S=h.redo,f=h.objects;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return c.push({id:X.id,params:[t]}),g.push({id:X.id,params:[t]}),{redos:c,undos:g}}_moveColInterceptor(i,r){const e=this._getUnitIdAndSubUnitId(i,r);if(e==null)return{redos:[],undos:[]};const{unitId:t,subUnitId:n}=e,{range:o}=i,s=o.startColumn,a=o.endColumn,c=[],g=[],u=this._sheetDrawingService.getDrawingData(t,n),d=[],m=[];if(Object.keys(u).forEach(h=>{var y,R;const p=u[h],{sheetTransform:S,transform:f,anchorType:v=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,T,O;if(r==="insert"){const M=this._expandCol(S,f,s,a,v);I=M==null?void 0:M.newSheetTransform,T=M==null?void 0:M.newTransform,O=(y=M==null?void 0:M.axisAlignSheetTransform)!=null?y:void 0}else{const{from:M,to:U}=S,{column:b}=M,{column:A}=U;if(v===w.SheetDrawingAnchorType.Both&&b>=s&&A<=a)m.push({unitId:t,subUnitId:n,drawingId:h});else{const _=this._shrinkCol(S,f,s,a,v);I=_==null?void 0:_.newSheetTransform,T=_==null?void 0:_.newTransform,O=(R=_==null?void 0:_.axisAlignSheetTransform)!=null?R:void 0}}if(!I||!T)return;const C={unitId:t,subUnitId:n,drawingId:h,transform:T,sheetTransform:I,axisAlignSheetTransform:O};d.push(C)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const h=this._sheetDrawingService.getBatchUpdateOp(d),{undo:p,redo:S,objects:f}=h;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const h=this._sheetDrawingService.getBatchRemoveOp(m),p=h.undo,S=h.redo,f=h.objects;c.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),g.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:n,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return c.push({id:X.id,params:[t]}),g.push({id:X.id,params:[t]}),{redos:c,undos:g}}_expandCol(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{column:c}=s,{column:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};let u=null,d=null,m=null;if(c>=e){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:t,startRow:s.row,endRow:a.row});if(h==null)return;d={...r,left:(r.left||0)+h.endX-h.startX},u=$(d,this._selectionRenderService),m=Y(d,this._selectionRenderService)}else if(g>=t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g+o}},d=ee(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d,axisAlignSheetTransform:m}:null}_shrinkCol(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{column:c}=s,{column:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};let u=null,d=null,m=null;if(c>t)u={from:{...s,column:c-o},to:{...a,column:g-o}},d=ee(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=e&&g<=t)return null;if(c<e&&g>t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,column:g-o}},d=ee(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};else if(c>=e&&c<=t){if(c===e)d={...r,left:(r.left||0)-i.from.columnOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:e,endColumn:c-1,startRow:s.row,endRow:a.row});if(h==null)return;d={...r,left:(r.left||0)-h.endX+h.startX-i.from.columnOffset}}u=$(d,this._selectionRenderService),m=Y(d,this._selectionRenderService)}else if(g>=e&&g<=t&&n===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:e-1,endColumn:e-1,startRow:s.row,endRow:a.row});if(h==null)return;u={from:{...s},to:{...a,column:e-1,columnOffset:h.endX-h.startX}},d=ee(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d,axisAlignSheetTransform:m}:null}_expandRow(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{row:c}=s,{row:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};let u=null,d=null,m=null;if(c>=e){const h=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:t,startColumn:s.column,endColumn:a.column});if(h==null)return;d={...r,top:(r.top||0)+h.endY-h.startY},u=$(d,this._selectionRenderService),m=Y(d,this._selectionRenderService)}else if(g>=t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g+o}},d=ee(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};return u!=null&&d!=null?{newSheetTransform:u,newTransform:d,axisAlignSheetTransform:m}:null}_shrinkRow(i,r,e,t,n=w.SheetDrawingAnchorType.Position){const o=t-e+1,{from:s,to:a}=i,{row:c}=s,{row:g}=a;if(n===w.SheetDrawingAnchorType.None)return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};let u=null,d=null,m=null;if(c>t)u={from:{...s,row:c-o},to:{...a,row:g-o}},d=ee(u,this._selectionRenderService,this._skeletonManagerService);else{if(c>=e&&g<=t)return null;if(c<e&&g>t)if(n===w.SheetDrawingAnchorType.Both)u={from:{...s},to:{...a,row:g-o}},d=ee(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...r},this._selectionRenderService),newTransform:r,axisAlignSheetTransform:Y({...r},this._selectionRenderService)};else if(c>=e&&c<=t){if(c===e)d={...r,top:(r.top||0)-i.from.rowOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startRow:e,endRow:c-1,startColumn:s.column,endColumn:a.column});if(h==null)return;d={...r,top:(r.top||0)-h.endY+h.startY-i.from.rowOffset}}u=$(d,this._selectionRenderService),m=Y(d,this._selectionRenderService)}else if(g>=e&&g<=t&&n===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:e-1,endRow:e-1});if(h==null)return;u={from:{...s},to:{...a,row:e-1,rowOffset:h.endY-h.startY}},d=ee(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&d!=null?{newSheetTransform:u,newTransform:d,axisAlignSheetTransform:m}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{if(i.id===D.SetWorksheetActiveOperation.id){const{unitId:r,subUnitId:e}=i.params;this._updateDrawings(r,e)}})),this.disposeWithMe(this._context.activated$.subscribe(i=>{const{unit:r,unitId:e}=this._context;if(i){const t=r.getActiveSheet().getSheetId();this._updateDrawings(e,t)}else this._clearDrawings(e)}))}_clearDrawings(i){setTimeout(()=>{const r=this._drawingManagerService.drawingManagerData,e=[];Object.keys(r).forEach(t=>{const n=r[t];n!=null&&Object.keys(n).forEach(o=>{const s=n[o].data;s!=null&&Object.keys(s).forEach(a=>{t===i&&e.push(s[a])})})}),this._sheetDrawingService.removeNotification(e),this._drawingManagerService.removeNotification(e)})}_updateDrawings(i,r){setTimeout(()=>{const e=this._drawingManagerService.drawingManagerData,t=[],n=[];Object.keys(e).forEach(o=>{const s=e[o];s!=null&&Object.keys(s).forEach(a=>{const c=s[a].data;c!=null&&Object.keys(c).forEach(g=>{if(o===i&&a===r){const u=c[g];u.transform=ee(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),t.push(c[g])}else n.push(c[g])})})}),this._sheetDrawingService.removeNotification(n),this._sheetDrawingService.addNotification(t),this._drawingManagerService.removeNotification(n),this._drawingManagerService.addNotification(t)},0)}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Bn.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,e=D.getSheetCommandTarget(this._univerInstanceService,r);if(!e)return;const{unitId:t,subUnitId:n,worksheet:o}=e;let s=[];"ranges"in r?s=r.ranges:"rowsAutoHeightInfo"in r&&(s=r.rowsAutoHeightInfo.map(a=>({startRow:a.row,endRow:a.row,startColumn:0,endColumn:o.getColumnCount()-1}))),this._refreshDrawingTransform(t,n,s)})}))}_refreshDrawingTransform(i,r,e){const t=this._drawingManagerService.getDrawingData(i,r),n=[];Object.keys(t).forEach(o=>{const s=t[o],{sheetTransform:a,transform:c,anchorType:g=w.SheetDrawingAnchorType.Position}=s;if(g===w.SheetDrawingAnchorType.None)return!0;const{from:u,to:d}=a,{row:m,column:h}=u,{row:p,column:S}=d;for(let f=0;f<e.length;f++){const v=e[f],{startRow:I,endRow:T,startColumn:O,endColumn:C}=v;if(l.Rectangle.intersects({startRow:I,endRow:T,startColumn:O,endColumn:C},{startRow:m,endRow:p,startColumn:h,endColumn:S})||m>T||h>C){const y=g===w.SheetDrawingAnchorType.Position,R=ee(a,this._selectionRenderService,this._skeletonManagerService);n.push({...s,transform:{...R,width:y?c==null?void 0:c.width:R==null?void 0:R.width,height:y?c==null?void 0:c.height:R==null?void 0:R.height}});break}}}),n.length!==0&&(this._sheetDrawingService.refreshTransform(n),this._drawingManagerService.refreshTransform(n),this._commandService.syncExecuteCommand(X.id,[i]))}};It=kn([fe(1,j.IRenderManagerService),fe(2,l.ICommandService),fe(3,P.ISheetSelectionRenderService),fe(4,l.Inject(P.SheetSkeletonManagerService)),fe(5,l.Inject(D.SheetInterceptorService)),fe(6,w.ISheetDrawingService),fe(7,x.IDrawingManagerService),fe(8,l.IUniverInstanceService)],It);function Fn(){const i=k.useDependency(l.LocaleService),r=k.useDependency(k.IDialogService),e=k.useDependency(lt),[t,n]=Q.useState([we.CELL_ADDRESS]),[o,s]=Q.useState(!1),[a,c]=Q.useState(null),g=Q.useMemo(()=>e.getCellImagesInSelection(),[e]),u=Q.useMemo(()=>e.getDataColumns(),[e]),d=Q.useMemo(()=>e.getSelectionRowRange(),[e]),m=u.length>0,h=Q.useMemo(()=>u.map(y=>({label:y.label,value:String(y.index)})),[u]),[p,S]=Q.useState(()=>h.length>0?h[0].value:"0"),f=Q.useMemo(()=>{if(!t.includes(we.COLUMN_VALUE)||!d)return[];const R=Number(p);return[{startRow:d.startRow,endRow:d.endRow,startColumn:R,endColumn:R}]},[t,p,d]);P.useHighlightRange(f);const v=Q.useCallback(y=>{y.length!==0&&n(y)},[]),I=Q.useCallback(y=>{S(String(y))},[]),T=Q.useCallback(()=>{r.close(be)},[r]),O=Q.useCallback(async()=>{if(g.length!==0){s(!0),c(null);try{await e.saveImages(g,{fileNameParts:t,columnIndex:t.includes(we.COLUMN_VALUE)?Number(p):void 0}),r.close(be)}catch(y){console.error("Failed to save images:",y),c(i.t("sheetImage.save.error"))}finally{s(!1)}}},[e,g,t,p,r,i]),C=t.includes(we.COLUMN_VALUE);return G.jsxs("div",{className:"univer-flex univer-flex-col",children:[G.jsx(V.FormLayout,{label:i.t("sheetImage.save.imageCount"),children:G.jsx("div",{className:"univer-text-sm univer-text-gray-600",children:g.length})}),G.jsx(V.FormLayout,{label:i.t("sheetImage.save.fileNameConfig"),children:G.jsxs(V.CheckboxGroup,{value:t,onChange:v,direction:"vertical",children:[G.jsx(V.Checkbox,{value:we.CELL_ADDRESS,disabled:!m,children:i.t("sheetImage.save.useRowCol")}),m&&G.jsx(V.Checkbox,{value:we.COLUMN_VALUE,children:i.t("sheetImage.save.useColumnValue")})]})}),C&&G.jsx(V.FormLayout,{label:i.t("sheetImage.save.selectColumn"),children:G.jsx(V.Select,{value:p,options:h,onChange:I})}),a&&G.jsx("div",{className:"univer-text-xs univer-text-red-500",children:a}),G.jsxs("div",{className:"univer-flex univer-justify-end univer-gap-2 univer-border-t univer-border-gray-200 univer-pt-3",children:[G.jsx(V.Button,{onClick:T,disabled:o,children:i.t("sheetImage.save.cancel")}),G.jsx(V.Button,{variant:"primary",onClick:O,disabled:o||g.length===0,children:o?i.t("sheetImage.save.saving"):i.t("sheetImage.save.confirm")})]})]})}const Xt=i=>{var I;const r=k.useDependency(l.ICommandService),e=k.useDependency(l.LocaleService),t=k.useDependency(x.IDrawingManagerService),n=k.useDependency(j.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:a}=s,c=n.getRenderById(a),g=c==null?void 0:c.scene;if(g==null)return;const u=g.getTransformerByCreate(),[d,m]=Q.useState(!0),h=(I=s.anchorType)!=null?I:w.SheetDrawingAnchorType.Position,[p,S]=Q.useState(h);function f(T,O){const C=[];return T.forEach(y=>{const{oKey:R}=y,M=O.getDrawingOKey(R);if(M==null)return C.push(null),!0;const{unitId:U,subUnitId:b,drawingId:A,drawingType:_,anchorType:E,sheetTransform:W,axisAlignSheetTransform:B}=M;C.push({unitId:U,subUnitId:b,drawingId:A,anchorType:E,sheetTransform:W,drawingType:_,axisAlignSheetTransform:B})}),C}Q.useEffect(()=>{const T=u.clearControl$.subscribe(C=>{C===!0&&m(!1)}),O=u.changeStart$.subscribe(C=>{var M;const{objects:y}=C,R=f(y,t);if(R.length===0)m(!1);else if(R.length>=1){m(!0);const U=((M=R[0])==null?void 0:M.anchorType)||w.SheetDrawingAnchorType.Position;S(U)}});return()=>{O.unsubscribe(),T.unsubscribe()}},[]);function v(T){S(T);const O=t.getFocusDrawings();if(O.length===0)return;const C=O.map(y=>({unitId:y.unitId,subUnitId:y.subUnitId,drawingId:y.drawingId,anchorType:T}));r.executeCommand(Ae.id,{unitId:O[0].unitId,drawings:C})}return G.jsxs("div",{className:V.clsx("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400",{"univer-hidden":!d}),children:[G.jsx("header",{className:"univer-text-gray-600 dark:!univer-text-gray-200",children:G.jsx("div",{children:e.t("drawing-anchor.title")})}),G.jsx("div",{children:G.jsxs(V.RadioGroup,{value:p,onChange:v,direction:"vertical",children:[G.jsx(V.Radio,{value:w.SheetDrawingAnchorType.Both,children:e.t("drawing-anchor.both")}),G.jsx(V.Radio,{value:w.SheetDrawingAnchorType.Position,children:e.t("drawing-anchor.position")}),G.jsx(V.Radio,{value:w.SheetDrawingAnchorType.None,children:e.t("drawing-anchor.none")})]})})]})},Ln=()=>{const i=k.useDependency(x.IDrawingManagerService),r=i.getFocusDrawings(),[e,t]=Q.useState(r);return Q.useEffect(()=>{const n=i.focus$.subscribe(o=>{t(o)});return()=>{n.unsubscribe()}},[]),!!(e!=null&&e.length)&&G.jsxs("div",{className:"univer-text-sm",children:[G.jsx(ve.DrawingCommonPanel,{drawings:e}),G.jsx(Xt,{drawings:e})]})},Et="sheet.menu.image";function $n(i){return{id:Et,type:k.MenuItemType.SUBITEMS,icon:"AddImageIcon",tooltip:"sheetImage.title",hidden$:k.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(i,{workbookTypes:[D.WorkbookEditablePermission],worksheetTypes:[D.WorksheetEditPermission],rangeTypes:[D.RangeProtectionPermissionEditPoint]})}}function Yn(i){return{id:Le.id,title:"sheetImage.upload.float",type:k.MenuItemType.BUTTON,hidden$:k.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function Gn(i){return{id:Rt.id,title:"sheetImage.upload.cell",type:k.MenuItemType.BUTTON,hidden$:k.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET)}}function Hn(i){var r,e,t,n;return!!((e=(r=i==null?void 0:i.p)==null?void 0:r.drawingsOrder)!=null&&e.length&&((n=(t=i==null?void 0:i.p)==null?void 0:t.drawingsOrder)==null?void 0:n.length)>0)}function Vn(i,r){const e=i.getActiveSheet();if(!e)return!1;const t=e.getCellMatrix(),{startRow:n,endRow:o,startColumn:s,endColumn:a}=r;for(let c=n;c<=o;c++)for(let g=s;g<=a;g++){const u=t.getValue(c,g);if(Hn(u))return!0}return!1}function Xn(){return"showDirectoryPicker"in window}function mt(i){const r=i.get(l.IUniverInstanceService),e=i.get(D.SheetsSelectionsService),t=N.combineLatest([k.getMenuHiddenObservable(i,l.UniverInstanceType.UNIVER_SHEET),r.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(N.switchMap(n=>n?e.selectionMoveEnd$.pipe(N.map(()=>{if(!Xn())return!0;const o=e.getCurrentSelections();if(!o||o.length===0)return!0;for(const s of o)if(Vn(n,s.range))return!1;return!0})):N.of(!0)))]).pipe(N.map(([n,o])=>n||o));return{id:Ee.id,type:k.MenuItemType.BUTTON,icon:"DownloadImageIcon",title:"sheetImage.save.menuLabel",hidden$:t}}const Kn={[k.RibbonInsertGroup.MEDIA]:{[Et]:{order:0,menuItemFactory:$n,[Le.id]:{order:0,menuItemFactory:Yn},[Rt.id]:{order:1,menuItemFactory:Gn}}},[k.ContextMenuPosition.MAIN_AREA]:{[k.ContextMenuGroup.OTHERS]:{[Ee.id]:{order:10,menuItemFactory:mt}}},[k.ContextMenuPosition.COL_HEADER]:{[k.ContextMenuGroup.OTHERS]:{[Ee.id]:{order:10,menuItemFactory:mt}}},[k.ContextMenuPosition.ROW_HEADER]:{[k.ContextMenuGroup.OTHERS]:{[Ee.id]:{order:10,menuItemFactory:mt}}}};function $e(i){return i.getContextValue(l.FOCUSING_SHEET)&&!i.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(l.FOCUSING_PANEL_EDITOR)&&i.getContextValue(l.FOCUSING_COMMON_DRAWINGS)&&!i.getContextValue(l.FOCUSING_SHAPE_TEXT_EDITOR)}const zn={id:Ue.id,description:"shortcut.drawing-move-down",group:"4_drawing-view",binding:k.KeyCode.ARROW_DOWN,priority:100,preconditions:$e,staticParameters:{direction:l.Direction.DOWN}},qn={id:Ue.id,description:"shortcut.drawing-move-up",group:"4_drawing-view",binding:k.KeyCode.ARROW_UP,priority:100,preconditions:$e,staticParameters:{direction:l.Direction.UP}},Zn={id:Ue.id,description:"shortcut.drawing-move-left",group:"4_drawing-view",binding:k.KeyCode.ARROW_LEFT,priority:100,preconditions:$e,staticParameters:{direction:l.Direction.LEFT}},Jn={id:Ue.id,description:"shortcut.drawing-move-right",group:"4_drawing-view",binding:k.KeyCode.ARROW_RIGHT,priority:100,preconditions:$e,staticParameters:{direction:l.Direction.RIGHT}},Qn={id:Dt.id,description:"shortcut.drawing-delete",group:"4_drawing-view",priority:100,preconditions:$e,binding:k.KeyCode.DELETE,mac:k.KeyCode.BACKSPACE};var er=Object.getOwnPropertyDescriptor,tr=(i,r,e,t)=>{for(var n=t>1?void 0:t?er(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},Me=(i,r)=>(e,t)=>r(e,t,i);let dt=class extends l.Disposable{constructor(i,r,e,t,n,o){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=e,this._shortcutService=t,this._drawingManagerService=n,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register($t,Ln)),this.disposeWithMe(i.register(be,Fn))}_initMenus(){this._menuManagerService.mergeMenu(Kn)}_initCommands(){[Le,Rt,Fe,Oe,Ae,Mt,X,bt,yt,Tt,Ue,Dt,Ct,Ee,wt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[zn,qn,Zn,Jn,Qn].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};dt=tr([Me(0,l.Inject(k.ComponentManager)),Me(1,k.IMenuManagerService),Me(2,l.ICommandService),Me(3,k.IShortcutService),Me(4,x.IDrawingManagerService),Me(5,l.Inject(D.SheetsSelectionsService))],dt);var nr=Object.defineProperty,rr=Object.getOwnPropertyDescriptor,ir=(i,r,e)=>r in i?nr(i,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[r]=e,or=(i,r,e,t)=>{for(var n=t>1?void 0:t?rr(r,e):r,o=i.length-1,s;o>=0;o--)(s=i[o])&&(n=s(n)||n);return n},pt=(i,r)=>(e,t)=>r(e,t,i),Kt=(i,r,e)=>ir(i,typeof r!="symbol"?r+"":r,e);const sr="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(r=Wt,e,t,n){super(),this._config=r,this._injector=e,this._renderManagerService=t,this._configService=n;const{menu:o,...s}=l.merge({},Wt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(dn,s)}onStarting(){l.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[dt],[nt],[ct],[at],[st],[rt],[it],[ot],[lt,{useClass:exports.BatchSaveImagesService}]]),l.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[st],[ot]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[at],[ct],[dt],[rt],[it]])}onSteady(){this._injector.get(nt)}_registerRenderModules(){[[exports.SheetDrawingUpdateController],[It],[_t],[vt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,r))})}};Kt(exports.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);Kt(exports.UniverSheetsDrawingUIPlugin,"pluginName",sr);exports.UniverSheetsDrawingUIPlugin=or([l.DependentOn(x.UniverDrawingPlugin,Lt.UniverDocsDrawingPlugin,ve.UniverDrawingUIPlugin,w.UniverSheetsDrawingPlugin),pt(1,l.Inject(l.Injector)),pt(2,j.IRenderManagerService),pt(3,l.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=X;exports.DeleteDrawingsCommand=Dt;exports.EditSheetDrawingOperation=bt;exports.FileNamePart=we;exports.GroupSheetDrawingCommand=yt;exports.IBatchSaveImagesService=lt;exports.InsertFloatImageCommand=Le;exports.InsertSheetDrawingCommand=Fe;exports.MoveDrawingsCommand=Ue;exports.RemoveSheetDrawingCommand=Oe;exports.SHEETS_IMAGE_MENU_ID=Et;exports.SHEET_FLOAT_DOM_PREFIX=Ht;exports.SaveCellImagesCommand=Ee;exports.SetDrawingArrangeCommand=Ct;exports.SetSheetDrawingCommand=Ae;exports.SheetDrawingAnchor=Xt;exports.SidebarSheetDrawingOperation=Mt;exports.UngroupSheetDrawingCommand=Tt;exports.calcSheetFloatDomPosition=de;exports.drawingPositionToTransform=ee;exports.transformToAxisAlignPosition=Y;exports.transformToDrawingPosition=$;
|
package/lib/cjs/locale/ca-ES.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e={sheetImage:{title:"Imatge",upload:{float:"Imatge flotant",cell:"Imatge de cel·la"},panel:{title:"Edita la imatge"},save:{title:"Desa les imatges de cel·la",menuLabel:"Desa les imatges de cel·la",imageCount:"Nombre d'imatges",fileNameConfig:"Nom del fitxer",useRowCol:"Utilitza l'adreça de la cel·la (A1, B2...)",useColumnValue:"Utilitza el valor de la columna",selectColumn:"Selecciona la columna",cancel:"Cancel·la",confirm:"Desa",saving:"Desant...",error:"No s'han pogut desar les imatges de cel·la"}},"image-popup":{replace:"Reemplaça",delete:"Elimina",edit:"Edita",crop:"Retalla",reset:"Restableix la mida"},"drawing-anchor":{title:"Propietats d’ancoratge",both:"Mou i canvia la mida amb les cel·les",position:"Mou però no canviïs la mida amb les cel·les",none:"No moguis ni canviïs la mida amb les cel·les"},"update-status":{exceedMaxSize:"La mida de la imatge supera el límit, el límit és {0}M",invalidImageType:"Tipus d’imatge no vàlid",exceedMaxCount:"Només es poden pujar {0} imatges alhora",invalidImage:"Imatge no vàlida"},"cell-image":{pasteTitle:"Enganxa com a imatge de cel·la",pasteContent:"Enganxar una imatge de cel·la sobreescriurà el contingut existent de la cel·la, continuar enganxant",pasteError:"La còpia i enganxat d’imatges de cel·la de full no està suportada en aquesta unitat"}};module.exports=e;
|
|
1
|
+
"use strict";const e={sheetImage:{title:"Imatge",upload:{float:"Imatge flotant",cell:"Imatge de cel·la"},panel:{title:"Edita la imatge"},save:{title:"Desa les imatges de cel·la",menuLabel:"Desa les imatges de cel·la",imageCount:"Nombre d'imatges",fileNameConfig:"Nom del fitxer",useRowCol:"Utilitza l'adreça de la cel·la (A1, B2...)",useColumnValue:"Utilitza el valor de la columna",selectColumn:"Selecciona la columna",cancel:"Cancel·la",confirm:"Desa",saving:"Desant...",error:"No s'han pogut desar les imatges de cel·la"}},"image-popup":{replace:"Reemplaça",delete:"Elimina",edit:"Edita",crop:"Retalla",reset:"Restableix la mida",flipH:"Gira horizontalmente",flipV:"Gira verticalmente"},"drawing-anchor":{title:"Propietats d’ancoratge",both:"Mou i canvia la mida amb les cel·les",position:"Mou però no canviïs la mida amb les cel·les",none:"No moguis ni canviïs la mida amb les cel·les"},"update-status":{exceedMaxSize:"La mida de la imatge supera el límit, el límit és {0}M",invalidImageType:"Tipus d’imatge no vàlid",exceedMaxCount:"Només es poden pujar {0} imatges alhora",invalidImage:"Imatge no vàlida"},"cell-image":{pasteTitle:"Enganxa com a imatge de cel·la",pasteContent:"Enganxar una imatge de cel·la sobreescriurà el contingut existent de la cel·la, continuar enganxant",pasteError:"La còpia i enganxat d’imatges de cel·la de full no està suportada en aquesta unitat"}};module.exports=e;
|