@univerjs/sheets-drawing-ui 1.0.1 → 1.0.3

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 CHANGED
@@ -3718,7 +3718,7 @@ const menuSchema = {
3718
3718
  //#endregion
3719
3719
  //#region package.json
3720
3720
  var name = "@univerjs/sheets-drawing-ui";
3721
- var version = "1.0.1";
3721
+ var version = "1.0.3";
3722
3722
 
3723
3723
  //#endregion
3724
3724
  //#region src/config/config.ts
package/lib/es/index.js CHANGED
@@ -3717,7 +3717,7 @@ const menuSchema = {
3717
3717
  //#endregion
3718
3718
  //#region package.json
3719
3719
  var name = "@univerjs/sheets-drawing-ui";
3720
- var version = "1.0.1";
3720
+ var version = "1.0.3";
3721
3721
 
3722
3722
  //#endregion
3723
3723
  //#region src/config/config.ts
package/lib/index.js CHANGED
@@ -3717,7 +3717,7 @@ const menuSchema = {
3717
3717
  //#endregion
3718
3718
  //#region package.json
3719
3719
  var name = "@univerjs/sheets-drawing-ui";
3720
- var version = "1.0.1";
3720
+ var version = "1.0.3";
3721
3721
 
3722
3722
  //#endregion
3723
3723
  //#region src/config/config.ts
package/lib/umd/index.js CHANGED
@@ -1,2 +1,2 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets-drawing"),require("@univerjs/engine-render"),require("@univerjs/design"),require("@univerjs/docs"),require("@univerjs/drawing"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/drawing-ui"),require("rxjs"),require("@univerjs/docs-drawing"),require("react"),require("react/jsx-runtime"),require("@univerjs/docs-ui")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-drawing`,`@univerjs/engine-render`,`@univerjs/design`,`@univerjs/docs`,`@univerjs/drawing`,`@univerjs/sheets`,`@univerjs/sheets-ui`,`@univerjs/ui`,`@univerjs/drawing-ui`,`rxjs`,`@univerjs/docs-drawing`,`react`,`react/jsx-runtime`,`@univerjs/docs-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDrawingUi={},e.UniverCore,e.UniverSheetsDrawing,e.UniverEngineRender,e.UniverDesign,e.UniverDocs,e.UniverDrawing,e.UniverSheets,e.UniverSheetsUi,e.UniverUi,e.UniverDrawingUi,e.rxjs,e.UniverDocsDrawing,e.React,e.React,e.UniverDocsUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let g={id:`sheet.command.delete-drawing`,type:t.CommandType.COMMAND,handler:e=>{let r=e.get(t.ICommandService),i=e.get(n.ISheetDrawingService).getFocusDrawings();if(i.length===0)return!1;let a=i[0].unitId,o=i.map(e=>{let{unitId:t,subUnitId:n,drawingId:r,drawingType:i}=e;return{unitId:t,subUnitId:n,drawingId:r,drawingType:i}});return r.executeCommand(n.RemoveSheetDrawingCommand.id,{unitId:a,drawings:o})}};function _(e){let n=[];return e.forEach(e=>{let{parent:i,children:a}=e,{unitId:o,subUnitId:s,drawingId:c}=i,l=(0,r.getGroupState)(0,0,a.map(e=>e.transform||{})),u=a.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t,left:t.left,top:t.top},groupId:c}}),d={unitId:o,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,groupBaseBound:{...i.groupBaseBound},transform:l};n.push({parent:d,children:u})}),n}function v(e){let n=[];return e.forEach(e=>{let{parent:i,children:a}=e,{unitId:o,subUnitId:s,drawingId:c,transform:l={width:0,height:0}}=i;if(l==null)return;let u=a.map(e=>{let{transform:t}=e,{unitId:n,subUnitId:a,drawingId:o}=e;return{unitId:n,subUnitId:a,drawingId:o,transform:(0,r.transformObjectOutOfGroup)(t||{},l,l.width||0,l.height||0,i.groupBaseBound),groupId:void 0}}),d={unitId:o,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:d,children:u})}),n}function y(e){var n;let r=new Map;(n=e.flatChildren)==null||n.forEach(e=>r.set(e.drawingId,(0,t.generateRandomId)(10))),e.groups.forEach(e=>r.set(e.drawingId,(0,t.generateRandomId)(10)));let i={};for(let[t,n]of Object.entries(e.nestedIdRecord)){var a;let e=r.get(t)??t;i[e]={drawingId:e,children:(a=n.children)==null?void 0:a.map(e=>r.get(e)??e)}}let o=[],s=[];for(let t of e.groups){let e=r.get(t.drawingId)??t.drawingId,n=t.groupId?r.get(t.groupId)??t.groupId:void 0;s.push(b(t,e,n))}for(let t of e.flatChildren||[]){let e=r.get(t.drawingId)??t.drawingId,n=t.groupId?r.get(t.groupId)??t.groupId:void 0;o.push(b(t,e,n))}return{cloned:{nestedIdRecord:i,flatChildren:o,groups:s},idMap:r}}function b(e,t,n){let r={...e};return t&&(r.drawingId=t),n?r.groupId=n:delete r.groupId,JSON.parse(JSON.stringify(r))}let x={id:`sheet.command.group-sheet-image`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(n.ISheetDrawingService);if(!r)return!1;let s=[];r.forEach(({parent:e,children:t})=>{s.push(e.unitId),t.forEach(e=>{s.push(e.unitId)})});let{unitId:c,subUnitId:l,undo:u,redo:d,objects:f}=o.getGroupDrawingOp(r);return i.syncExecuteCommand(n.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.GROUP})?(a.pushUndoRedo({unitID:c,undoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:v(f),type:n.DrawingApplyType.UNGROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}],redoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.GROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}]}),!0):!1}},S={id:`sheet.command.ungroup-sheet-image`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(n.ISheetDrawingService);if(!r)return!1;let s=[];r.forEach(({parent:e,children:t})=>{s.push(e.unitId),t.forEach(e=>{s.push(e.unitId)})});let{unitId:c,subUnitId:l,undo:u,redo:d,objects:f}=o.getUngroupDrawingOp(r);return i.syncExecuteCommand(n.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.UNGROUP})?(a.pushUndoRedo({unitID:c,undoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:_(f),type:n.DrawingApplyType.GROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}],redoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.UNGROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}]}),!0):!1}},C=.0254;function w(e){let t=T(e);if(!t)return;let n=E(t);if(!n)return;let r=96/(n.x*C),i=96/(n.y*C);if(Number.isFinite(r)&&Number.isFinite(i)&&!(Math.abs(r-1)<=.001&&Math.abs(i-1)<=.001))return{scaleX:r,scaleY:i}}function T(e){let t=e.indexOf(`,`);if(!(t<0||!e.slice(0,t).toLowerCase().includes(`;base64`)))try{let n=globalThis.atob(e.slice(t+1)),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}catch{return}}function E(e){return D(e)??O(e)}function D(e){if(!k(e,0,[137,80,78,71,13,10,26,10]))return;let t=8;for(;t+12<=e.length;){let n=j(e,t),r=t+4,i=t+8,a=i+n,o=a+4;if(o>e.length)return;if(k(e,r,[112,72,89,115])){if(n!==9||e[a-1]!==1)return;let t=j(e,i),r=j(e,i+4);return t>0&&r>0?{x:t,y:r}:void 0}t=o}}function O(e){if(!k(e,0,[255,216]))return;let t=2;for(;t+4<=e.length;){if(e[t]!==255){t++;continue}for(;t<e.length&&e[t]===255;)t++;let n=e[t++];if(n==null)return;if(n===216||n===217||n===1||n>=208&&n<=215)continue;let r=A(e,t);if(r<2)return;let i=t+2,a=t+r;if(a>e.length)return;if(n===224&&r>=14&&k(e,i,[74,70,73,70,0])){let t=e[i+7],n=A(e,i+8),r=A(e,i+10);return!n||!r?void 0:t===1?{x:Math.round(n/C),y:Math.round(r/C)}:t===2?{x:n*100,y:r*100}:void 0}t=a}}function k(e,t,n){return n.every((n,r)=>e[t+r]===n)}function A(e,t){return(e[t]??0)<<8|(e[t+1]??0)}function j(e,t){return((e[t]??0)<<24>>>0|(e[t+1]??0)<<16|(e[t+2]??0)<<8|(e[t+3]??0))>>>0}function M(e){"@babel/helpers - typeof";return M=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},M(e)}function N(e,t){if(M(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(M(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function P(e){var t=N(e,`string`);return M(t)==`symbol`?t:t+``}function F(e,t,n){return(t=P(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function I(e,t){return function(n,r){t(n,r,e)}}function L(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function ee(e,t,n){let r=n*Math.PI/180;return{rotatedWidth:Math.abs(e*Math.cos(r))+Math.abs(t*Math.sin(r)),rotatedHeight:Math.abs(e*Math.sin(r))+Math.abs(t*Math.cos(r))}}function R(e,t,n,i,a){var o;let{rotatedHeight:s,rotatedWidth:l}=ee(n,i,a),u=e.get(r.IRenderManagerService).getRenderUnitById(t.unitId);if(!u)return!1;let d=(o=u.with(c.SheetSkeletonManagerService).getSkeletonParam(t.subUnitId))==null?void 0:o.skeleton;if(d==null)return!1;let f=d.getCellWithCoordByIndex(t.row,t.col),p=f.mergeInfo.endX-f.mergeInfo.startX-2,m=f.mergeInfo.endY-f.mergeInfo.startY-2,h=l/s,g=Math.ceil(Math.min(p,m*h))/l,_=!g||Number.isNaN(g)?.001:g;return{width:n*_,height:i*_}}let z=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){super(),this._context=e,this._commandService=t,this._sheetInterceptorService=n,this._selectionRenderService=r,this._imageIoService=i,this._fileOpenerService=a,this._sheetDrawingService=o,this._drawingManagerService=s,this._contextService=c,this._messageService=l,this._localeService=u,this._sheetSkeletonService=f,this._injector=p,this._urlImageService=m,F(this,`_workbookSelections`,void 0),this._workbookSelections=d.getWorkbookSelections(this._context.unitId),this._updateDrawingListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){let e=await this._fileOpenerService.openFile({multiple:!0,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}),t=e.length;return t>o.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxCount`,String(o.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t!==0&&(e.forEach(async e=>await this.insertFloatImageByFile(e)),!0)}async insertCellImage(){let e=(await this._fileOpenerService.openFile({multiple:!1,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}))[0];return e?(await this._insertCellImage(e),!0):!1}async setWorksheetBackgroundImage(e){let r=(e??await this._fileOpenerService.openFile({multiple:!1,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}))[0];if(!r)return!1;let a;try{a=await this._imageIoService.saveImage(r)}catch(e){let n=e.message;return n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/1048576))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)}),!1}if(!a)return!1;let{unitId:s,subUnitId:c}=this._getUnitInfo(),l=w(a.base64Cache||a.source);return this._commandService.executeCommand(n.SetWorksheetBackgroundImageCommand.id,{unitId:s,subUnitId:c,backgroundImage:{source:a.source,imageSourceType:a.imageSourceType,...l}})}insertCellImageByFile(e,t){return this._insertCellImage(e,t)}async insertFloatImageByFile(e){let r;try{r=await this._imageIoService.saveImage(e)}catch(e){let n=e.message;n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/1048576))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)})}if(r==null)return;let{unitId:a,subUnitId:s}=this._getUnitInfo(),{imageId:c,imageSourceType:l,source:u,base64Cache:d}=r,{width:f,height:p,image:m}=await(0,o.getImageSize)(d||``),{width:h,height:g}=this._context.scene;this._imageIoService.addImageSourceCache(u,l,m);let _=1;if(f>o.DRAWING_IMAGE_WIDTH_LIMIT||p>o.DRAWING_IMAGE_HEIGHT_LIMIT){let e=o.DRAWING_IMAGE_WIDTH_LIMIT/f,t=o.DRAWING_IMAGE_HEIGHT_LIMIT/p;_=Math.max(e,t)}let v=this._sheetSkeletonService.getSkeletonParam(a,s);if(!v)return;let{skeleton:y}=v,b=this._getImagePosition(f*_,p*_,h,g,y);if(!b)return;let x=(0,n.drawingPositionToTransform)(b,v);if(!x)return;let S={unitId:a,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:u,transform:x,sheetTransform:b,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(x,y)??b};return this._commandService.executeCommand(n.InsertSheetDrawingCommand.id,{unitId:a,drawings:[S]})}async _insertCellImage(e,n){let r;try{r=await this._imageIoService.saveImage(e)}catch(e){let n=e.message;n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/1048576))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)})}if(r==null)return!1;let{imageId:c,imageSourceType:l,source:u,base64Cache:d}=r,{width:f,height:p,image:m}=await(0,o.getImageSize)(d||``);this._imageIoService.addImageSourceCache(u,l,m);let h=this._workbookSelections.getCurrentLastSelection();if(!h)return!1;let g=h.primary.actualRow,_=h.primary.actualColumn;h.primary.isMerged&&(g=h.primary.startRow,_=h.primary.startColumn);let v=(0,t.createDocumentModelWithStyle)(``,{}),y=R(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:g,col:_},f,p,0);if(!y)return!1;let b=(0,a.buildDocTransform)(y.width,y.height),x={unitId:v.getUnitId(),subUnitId:v.getUnitId(),drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:u,transform:(0,a.docDrawingPositionToTransform)(b),docTransform:b,behindDoc:t.BooleanNumber.FALSE,title:``,description:``,layoutType:t.PositionedObjectLayoutType.INLINE,wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=t.BuildTextUtils.drawing.add({documentDataModel:v,drawings:[x],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(v.apply(S),this._commandService.syncExecuteCommand(s.SetRangeValuesCommand.id,{value:{[(n==null?void 0:n.row)??g]:{[(n==null?void 0:n.col)??_]:{p:v.getSnapshot(),t:1}}},unitId:n==null?void 0:n.unitId,subUnitId:n==null?void 0:n.subUnitId})):!1}async insertCellImageByUrl(e,n){let r=e;try{r=await this._urlImageService.getImage(e)}catch(t){console.error(`Failed to get image from URLImageService: ${e}`,t)}let{width:i,height:c,image:l}=await(0,o.getImageSize)(r||``);this._imageIoService.addImageSourceCache(e,t.ImageSourceType.URL,l);let u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;let d=(0,t.createDocumentModelWithStyle)(``,{}),f=R(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},i,c,0);if(!f)return!1;let p=(0,a.buildDocTransform)(f.width,f.height),m={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:(0,t.generateRandomId)(),drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t.ImageSourceType.URL,source:e,transform:(0,a.docDrawingPositionToTransform)(p),docTransform:p,behindDoc:t.BooleanNumber.FALSE,title:``,description:``,layoutType:t.PositionedObjectLayoutType.INLINE,wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},h=t.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[m],selection:{collapsed:!0,startOffset:0,endOffset:0}});return h?(d.apply(h),this._commandService.syncExecuteCommand(s.SetRangeValuesCommand.id,{value:{[(n==null?void 0:n.row)??u.primary.actualRow]:{[(n==null?void 0:n.col)??u.primary.actualColumn]:{p:d.getSnapshot(),t:1}}},unitId:n==null?void 0:n.unitId,subUnitId:n==null?void 0:n.subUnitId})):!1}_getUnitInfo(){let e=this._context.unit,t=e.getActiveSheet();return{unitId:e.getUnitId(),subUnitId:t.getSheetId()}}_getImagePosition(e,t,n,r,i){let a=this._workbookSelections.getCurrentSelections(),o={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(o=a[a.length-1].range);let c=(0,s.attachRangeWithCoord)(i,o);if(c==null)return;let{startColumn:l,startRow:u,startX:d,startY:f}=c,p=!1;if(d+e>n&&(d=n-e,d<0&&(d=0,e=n),p=!0),f+t>r&&(f=r-t,f<0&&(f=0,t=r),p=!0),p){let e=this._selectionRenderService.getCellWithCoordByOffset(d,f);if(e==null)return;d=e.startX,f=e.startY,l=e.actualColumn,u=e.actualRow}let m={column:l,columnOffset:0,row:u,rowOffset:0},h=this._selectionRenderService.getCellWithCoordByOffset(d+e,f+t);if(h!=null)return{from:m,to:{column:h.actualColumn,columnOffset:d+e-h.startX,row:h.actualRow,rowOffset:f+t-h.startY}}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{let{unitId:t,subUnitId:r,drawingIds:i,arrangeType:a}=e;this._commandService.executeCommand(n.SetDrawingArrangeCommand.id,{unitId:t,subUnitId:r,drawingIds:i,arrangeType:a})}))}_updateDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{let t=[];e.length!==0&&(e.forEach(e=>{let{unitId:r,subUnitId:i,drawingId:a,transform:o}=e,s=this._sheetSkeletonService.getSkeletonParam(r,i);if(!o||!s)return;let{skeleton:c}=s,l=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:a});if(l==null||l.unitId!==this._context.unitId)return;let u=(0,n.transformToDrawingPosition)({...l.transform,...o},c),d=(0,n.transformToAxisAlignPosition)({...l.transform,...o},c);if(u==null||d==null)return;let f={...e,transform:{...l.transform,...o,...(0,n.drawingPositionToTransform)(u,s)},sheetTransform:{...u},axisAlignSheetTransform:{...d}};t.push(f)}),t.length>0&&this._commandService.executeCommand(n.SetSheetDrawingCommand.id,{unitId:e[0].unitId,drawings:t}))}))}_getSheetTransformByParam(e,t){let{unitId:r,subUnitId:i,drawingId:a,transform:o}=e,s=this._sheetSkeletonService.getSkeleton(r,i);if(!o||!s)return null;let c=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:a}),l=c==null?void 0:c.transform;if(t&&(l={}),!t&&(!c||c.unitId!==this._context.unitId))return null;let u=(0,n.transformToDrawingPosition)({...l,...o},s),d=(0,n.transformToAxisAlignPosition)({...l,...o},s);return!u||!d?null:{sheetTransform:u,axisAlignSheetTransform:d}}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{let t=[];for(let n of e){let e=n.parent,r=this._getSheetTransformByParam(e,!0),i=[];for(let e of n.children){let t=this._getSheetTransformByParam(e,!1);t!=null&&i.push({...e,sheetTransform:t.sheetTransform,axisAlignSheetTransform:t.axisAlignSheetTransform})}let a={parent:{...e,sheetTransform:r==null?void 0:r.sheetTransform,axisAlignSheetTransform:r==null?void 0:r.axisAlignSheetTransform},children:i};t.push(a)}if(t.length>0){this._commandService.executeCommand(x.id,t);let{unitId:n,subUnitId:r,drawingId:i}=e[0].parent;this._commandService.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:r,drawingId:i}])}})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{let t=[];for(let n of e){let{children:e}=n,r=[];for(let t of e){let e=this._getSheetTransformByParam(t,!1);e!=null&&r.push({...t,sheetTransform:e.sheetTransform,axisAlignSheetTransform:e.axisAlignSheetTransform})}t.push({...n,children:r})}this._commandService.executeCommand(S.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};z=L([I(1,t.ICommandService),I(2,(0,t.Inject)(s.SheetInterceptorService)),I(3,c.ISheetSelectionRenderService),I(4,t.IImageIoService),I(5,l.ILocalFileService),I(6,n.ISheetDrawingService),I(7,o.IDrawingManagerService),I(8,t.IContextService),I(9,l.IMessageService),I(10,(0,t.Inject)(t.LocaleService)),I(11,(0,t.Inject)(s.SheetsSelectionsService)),I(12,(0,t.Inject)(s.SheetSkeletonService)),I(13,(0,t.Inject)(t.Injector)),I(14,t.IURLImageService)],z);let B={id:`sheet.command.insert-float-image`,type:t.CommandType.COMMAND,handler:async(e,n)=>{var i;let a=e.get(t.IUniverInstanceService),o=e.get(r.IRenderManagerService),s=(i=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,a,o))==null?void 0:i.with(z);if(!s)return!1;let c=n==null?void 0:n.files;if(c){let e=c.map(e=>s.insertFloatImageByFile(e));return(await Promise.all(e)).every(e=>e)}return s.insertFloatImage()??!1}},V={id:`sheet.command.insert-cell-image`,type:t.CommandType.COMMAND,handler:e=>{var n;let i=e.get(t.IUniverInstanceService),a=e.get(r.IRenderManagerService);return((n=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,i,a))==null?void 0:n.with(z).insertCellImage())??!1}},H={id:`sheet.command.move-drawing`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(n.ISheetDrawingService),o=e.get(s.SheetSkeletonService),c=e.get(l.UndoRedoGroupService),{direction:u}=r,d=a.getFocusDrawings();if(d.length===0)return!1;let f=d[0].unitId,p=d.map(e=>{let{transform:r,unitId:i,subUnitId:a}=e,s=o.getSkeleton(i,a);if(!r||!s)return null;let c={...r},{left:l=0,top:d=0}=r;return u===t.Direction.UP?c.top=d-1:u===t.Direction.DOWN?c.top=d+1:u===t.Direction.LEFT?c.left=l-1:u===t.Direction.RIGHT&&(c.left=l+1),{...e,transform:c,sheetTransform:(0,n.transformToDrawingPosition)(c,s),axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(c,s)}}).filter(e=>e!=null);return c.runTimed(f,`sheet-drawing:nudge:${d[0].subUnitId}:${d.map(e=>e.drawingId).sort().join(`,`)}`,()=>i.syncExecuteCommand(n.SetSheetDrawingCommand.id,{unitId:f,drawings:p}))?(i.syncExecuteCommand(n.ClearSheetDrawingTransformerOperation.id,[f]),!0):!1}},U=function(e){return e.CELL_ADDRESS=`cellAddress`,e.COLUMN_VALUE=`columnValue`,e}({}),W=(0,t.createIdentifier)(`sheets-drawing-ui.batch-save-images.service`);function G(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function K(e,t){return`${G(t)}${e+1}`}function q(e){let t=K(e.startRow,e.startColumn),n=K(e.endRow,e.endColumn);return t===n?t:`${t}:${n}`}function J(e){var t;let n=e.p,r=n==null||(t=n.drawingsOrder)==null?void 0:t[0];if(!(0,s.isCellImage)(n)||!r||!(n!=null&&n.drawings))return null;let i=n.drawings[r];return!i||!(`source`in i)||!(`imageSourceType`in i)?null:i}function Y(e,n){if(n===t.ImageSourceType.BASE64){let t=e.match(/^data:image\/(\w+);/);if(t)return t[1]===`jpeg`?`jpg`:t[1]}if(n===t.ImageSourceType.URL){let t=e.match(/\.(\w+)(?:\?|$)/);if(t)return t[1].toLowerCase()}return`png`}async function te(e,n){if(n===t.ImageSourceType.BASE64||n===t.ImageSourceType.URL)return(await fetch(e)).blob();throw Error(`UUID image type requires additional handling`)}let X=class extends t.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._selectionService=t,this._imageIoService=n,this._urlImageService=r}getCellImagesInSelection(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return[];let n=e.getActiveSheet();if(!n)return[];let r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return[];let i=n.getCellMatrix(),a=[];for(let e of r){let{startRow:t,endRow:n,startColumn:r,endColumn:o}=e.range;for(let e=t;e<=n;e++)for(let t=r;t<=o;t++){let n=i.getValue(e,t);if((0,s.isCellImage)(n==null?void 0:n.p)){let r=J(n);r&&a.push({row:e,col:t,cellAddress:K(e,t),source:r.source,imageSourceType:r.imageSourceType,imageId:r.drawingId})}}}return a}getCellImagesFromRanges(e,n,r){let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)return[];let a=i.getSheetBySheetId(n);if(!a)return[];let o=a.getCellMatrix(),c=[];for(let e of r){let{startRow:t,endRow:n,startColumn:r,endColumn:i}=e;for(let e=t;e<=n;e++)for(let t=r;t<=i;t++){let n=o.getValue(e,t);if((0,s.isCellImage)(n==null?void 0:n.p)){let r=J(n);r&&c.push({row:e,col:t,cellAddress:K(e,t),source:r.source,imageSourceType:r.imageSourceType,imageId:r.drawingId})}}}return c}getDataColumns(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return[];let n=e.getActiveSheet();if(!n)return[];let r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return[];let i=n.getCellMatrix(),a=i.getDataRange(),o=1/0,s=-1/0,c=new Set;for(let e of r){o=Math.min(o,e.range.startRow),s=Math.max(s,e.range.endRow);for(let t=e.range.startColumn;t<=e.range.endColumn;t++)c.add(t)}let l=new Set;for(let e=a.startColumn;e<=a.endColumn;e++)if(!c.has(e))for(let t=o;t<=s;t++){let n=i.getValue(t,e);if(n){var u,d;if((u=n.v)!=null&&u.toString()||(d=n.p)!=null&&(d=d.body)!=null&&(d=d.dataStream)!=null&&d.trim()){l.add(e);break}}}let f=[],p=Array.from(l).sort((e,t)=>e-t);for(let e of p)f.push({index:e,label:G(e)});return f}getDataColumnsForRanges(e,n,r){let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)return[];let a=i.getSheetBySheetId(n);if(!a)return[];let o=a.getCellMatrix(),s=o.getDataRange(),c=1/0,l=-1/0,u=new Set;for(let e of r){c=Math.min(c,e.startRow),l=Math.max(l,e.endRow);for(let t=e.startColumn;t<=e.endColumn;t++)u.add(t)}let d=new Set;for(let e=s.startColumn;e<=s.endColumn;e++)if(!u.has(e))for(let t=c;t<=l;t++){let n=o.getValue(t,e);if(n){var f,p;if((f=n.v)!=null&&f.toString()||(p=n.p)!=null&&(p=p.body)!=null&&(p=p.dataStream)!=null&&p.trim()){d.add(e);break}}}let m=[],h=Array.from(d).sort((e,t)=>e-t);for(let e of h)m.push({index:e,label:G(e)});return m}getSelectionRangeNotation(){let e=this._selectionService.getCurrentSelections();return!e||e.length===0?``:e.map(e=>q(e.range)).join(`, `)}getSelectionRowRange(){let e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return null;let t=1/0,n=-1/0;for(let r of e)t=Math.min(t,r.range.startRow),n=Math.max(n,r.range.endRow);return{startRow:t,endRow:n}}getSelectionColumnIndices(){let e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return new Set;let t=new Set;for(let n of e)for(let e=n.range.startColumn;e<=n.range.endColumn;e++)t.add(e);return t}generateFileName(e,n){let r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),i=Y(e.source,e.imageSourceType),a=[];for(let t of n.fileNameParts)if(t===`cellAddress`)a.push(e.cellAddress);else if(t===`columnValue`&&n.columnIndex!==void 0){let t=r==null?void 0:r.getActiveSheet();if(t){let r=t.getCellMatrix().getValue(e.row,n.columnIndex);if(r){var o,s;let e=((o=r.v)==null?void 0:o.toString())||((s=r.p)==null||(s=s.body)==null||(s=s.dataStream)==null?void 0:s.trim())||``;if(e){let t=e.replace(/[<>:"/\\|?*]/g,`_`).trim();t&&a.push(t)}}}}return a.length===0?`${e.cellAddress}.${i}`:`${a.join(`_`)}.${i}`}generateFileNameWithContext(e,n,r,i){let a=this._univerInstanceService.getUnit(r,t.UniverInstanceType.UNIVER_SHEET),o=Y(e.source,e.imageSourceType),s=[];for(let t of n.fileNameParts)if(t===`cellAddress`)s.push(e.cellAddress);else if(t===`columnValue`&&n.columnIndex!==void 0){let t=a==null?void 0:a.getSheetBySheetId(i);if(t){let r=t.getCellMatrix().getValue(e.row,n.columnIndex);if(r){var c,l;let e=((c=r.v)==null?void 0:c.toString())||((l=r.p)==null||(l=l.body)==null||(l=l.dataStream)==null?void 0:l.trim())||``;if(e){let t=e.replace(/[<>:"/\\|?*]/g,`_`).trim();t&&s.push(t)}}}}return s.length===0?`${e.cellAddress}.${o}`:`${s.join(`_`)}.${o}`}async saveImages(e,t){let n=await window.showDirectoryPicker({mode:`readwrite`}),r=new Map;for(let a of e){var i;let e=this.generateFileName(a,t),o=e.replace(/\.\w+$/,``),s=((i=e.match(/\.\w+$/))==null?void 0:i[0])||`.png`,c=r.get(o)||0;c>0&&(e=`${o}_${c}${s}`),r.set(o,c+1);try{let t=await this._getImageBlob(a),r=await(await n.getFileHandle(e,{create:!0})).createWritable();await r.write(t),await r.close()}catch(t){throw console.error(`Failed to save image ${e}:`,t),t}}}async saveImagesWithContext(e,t,n,r){let i=await window.showDirectoryPicker({mode:`readwrite`}),a=new Map;for(let s of e){var o;let e=this.generateFileNameWithContext(s,t,n,r),c=e.replace(/\.\w+$/,``),l=((o=e.match(/\.\w+$/))==null?void 0:o[0])||`.png`,u=a.get(c)||0;u>0&&(e=`${c}_${u}${l}`),a.set(c,u+1);try{let t=await this._getImageBlob(s),n=await(await i.getFileHandle(e,{create:!0})).createWritable();await n.write(t),await n.close()}catch(t){throw console.error(`Failed to save image ${e}:`,t),t}}}async downloadSingleImage(e){let t=Y(e.source,e.imageSourceType),n=`${e.cellAddress}.${t}`;try{let t=await this._getImageBlob(e),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}catch(e){throw console.error(`Failed to download image ${n}:`,e),e}}async _getImageBlob(e){return e.imageSourceType===t.ImageSourceType.UUID?te(await this._imageIoService.getImage(e.source),t.ImageSourceType.URL):e.imageSourceType===t.ImageSourceType.URL?this._urlImageService.downloadImage(e.source):te(e.source,e.imageSourceType)}};X=L([I(0,t.IUniverInstanceService),I(1,(0,t.Inject)(s.SheetsSelectionsService)),I(2,t.IImageIoService),I(3,t.IURLImageService)],X);let Z=`sheet.dialog.batch-save-images`,Q={id:`sheet.command.save-cell-images`,type:t.CommandType.COMMAND,handler:async e=>{let n=e.get(l.IDialogService),r=e.get(W),i=r.getCellImagesInSelection();if(i.length===1)try{return await r.downloadSingleImage(i[0]),!0}catch(e){return console.error(`Failed to download image:`,e),!1}let a=e.get(t.LocaleService),o=r.getSelectionRangeNotation(),s=`${a.t(`sheets-drawing-ui.save.title`)} (${o})`;return n.open({id:Z,draggable:!0,width:360,title:{title:s},children:{label:Z},preservePositionOnDestroy:!0,onClose:()=>n.close(Z)}),!0}},ne={id:`sheet.command.add-worksheet-background-image`,type:t.CommandType.COMMAND,handler:(e,n)=>{var i;let a=e.get(t.IUniverInstanceService),o=e.get(r.IRenderManagerService);return((i=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,a,o))==null?void 0:i.with(z).setWorksheetBackgroundImage(n==null?void 0:n.files))??!1}},re={id:`sheet.command.delete-worksheet-background-image`,type:t.CommandType.COMMAND,handler:e=>e.get(t.ICommandService).executeCommand(n.SetWorksheetBackgroundImageCommand.id,{backgroundImage:null})},ie=`COMPONENT_SHEET_DRAWING_PANEL`,ae={id:`sidebar.operation.sheet-image`,type:t.CommandType.COMMAND,handler:async(e,n)=>{let r=e.get(l.ISidebarService),i=e.get(t.LocaleService),a=e.get(t.IUniverInstanceService),c=e.get(o.IDrawingManagerService),u=e.get(t.ICommandService);if(!(0,s.getSheetCommandTarget)(a))return!1;switch(n.value){case`open`:r.open({id:ie,header:{title:i.t(`sheets-drawing-ui.panel.title`)},children:{label:ie},onClose:()=>{let e=c.getFocusDrawings();e.length===1&&e[0].drawingType===t.DrawingTypeEnum.DRAWING_IMAGE&&u.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[])},width:360});break;default:r.close(ie)}return!0}},oe={id:`sheet.operation.edit-sheet-image`,type:t.CommandType.OPERATION,handler:(e,n)=>{let r=e.get(t.ICommandService);return n!=null&&(r.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[n]),r.executeCommand(ae.id,{value:`open`}),!0)}},se=[c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA],ce=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetClipboardService=e,this._renderManagerService=t,this._sheetSkeletonService=n,this._sheetDrawingService=r,this._drawingManagerService=i,F(this,`_featurePasteHooks`,[]),F(this,`_copyInfo`,void 0),this._initCopyPaste()}get _focusedDrawings(){return this._sheetDrawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:`SHEET_DRAWING_GROUP`,onBeforeCopyFocusedObject:(e,n)=>{this._copyInfo=null;let r=this._focusedDrawings;if(r.length===0)return!1;let i=r.find(e=>e.drawingType===t.DrawingTypeEnum.DRAWING_GROUP);if(!i)return!1;let a=this._drawingManagerService.getDrawingsByGroupNested({unitId:i.unitId,subUnitId:i.subUnitId,drawingId:i.drawingId});return a?(this._copyInfo={unitId:i.unitId,subUnitId:i.subUnitId,groupNestedParam:a},!0):!1},onPasteCells:(e,t,n,r)=>{if(!r.copyId||!e||!this._copyInfo)return{redos:[],undos:[]};let{pasteType:i}=r;return se.includes(i)?{redos:[],undos:[]}:this._generateGroupPasteMutations(t)}})}registerFeaturePasteHook(e,n){let r={hook:e,beforeDrawing:(n==null?void 0:n.beforeDrawing)===!0};return this._featurePasteHooks.push(r),(0,t.toDisposable)(()=>{let e=this._featurePasteHooks.indexOf(r);e>=0&&this._featurePasteHooks.splice(e,1)})}_getGroupFeaturePasteMutations(e,t){let n=[],r=[],i=!1;for(let a of this._featurePasteHooks){if(a.beforeDrawing!==t)continue;let o=a.hook(e);n.push(...o.redos),r.push(...o.undos),i||=o.cancel===!0}return{redos:n,undos:r,cancel:i}}_generateGroupPasteMutations(e){if(!this._copyInfo)return{redos:[],undos:[]};let{unitId:t,subUnitId:r,range:i}=e,a=this._sheetSkeletonService.getSkeleton(t,r);if(!a)return{redos:[],undos:[]};let{groupNestedParam:o}=this._copyInfo,c=o.groups[o.groups.length-1],{cloned:l,idMap:u}=y(o),d=l.groups[l.groups.length-1].drawingId,f={fromUnitId:this._copyInfo.unitId,fromSubUnitId:this._copyInfo.subUnitId,toUnitId:t,toSubUnitId:r,idMap:u,cloned:l},p=this._getGroupFeaturePasteMutations(f,!0);if(p.cancel)return{redos:[],undos:[]};let m=(0,s.discreteRangeToRange)(i),h=(0,s.attachRangeWithCoord)(a,{startRow:m.startRow,endRow:m.endRow,startColumn:m.startColumn,endColumn:m.endColumn});if(!h)return{redos:[],undos:[]};let g={...c.transform,left:h.startX,top:h.startY},_=[...(l.flatChildren??[]).map(e=>({...e,unitId:t,subUnitId:r})),...l.groups.map(e=>e.drawingId===d?{...e,unitId:t,subUnitId:r,transform:g,sheetTransform:(0,n.transformToDrawingPosition)(g,a)??c.sheetTransform,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(g,a)??c.sheetTransform}:{...e,unitId:t,subUnitId:r})],{undo:v,redo:b,objects:x}=this._sheetDrawingService.getBatchAddOp(_),S=this._getGroupFeaturePasteMutations(f,!1);if(S.cancel)return{redos:[],undos:[]};let C={id:n.SetDrawingApplyMutation.id,params:{op:b,unitId:t,subUnitId:r,objects:x,type:n.DrawingApplyType.INSERT}},w={id:n.SetDrawingApplyMutation.id,params:{op:v,unitId:t,subUnitId:r,objects:x,type:n.DrawingApplyType.REMOVE}};return{redos:[...p.redos,C,...S.redos],undos:[w,...p.undos,...S.undos]}}dispose(){this._copyInfo=null,this._featurePasteHooks.length=0,super.dispose()}};ce=L([I(0,c.ISheetClipboardService),I(1,r.IRenderManagerService),I(2,(0,t.Inject)(s.SheetSkeletonService)),I(3,n.ISheetDrawingService),I(4,o.IDrawingManagerService)],ce);let le=Object.freeze({borderEnabled:!1,paintFirst:`stroke`,radius:8,rotateEnabled:!1,strokeWidth:1});var ue;let de=`univer-sheet-float-dom-`;function fe(e,t,n){let r=new WeakRef(e),i=!1;return{id:t,dispose(){if(i)return;i=!0;let e=r.deref();e&&n(e,t)}}}let pe={...r.DEFAULT_TRANSFORMER_CONFIG,rotateEnabled:!1,moveBoundaryEnabled:!1},me={...r.DEFAULT_TRANSFORMER_CONFIG,rotateEnabled:!1,keepRatio:!1,moveBoundaryEnabled:!1},he=-100,ge=`univer:embed-float-drag-handle:pointerdown`;function _e(e,t){return t.hostAnchorId===e.id&&(t.hostUnitId==null||t.hostUnitId===e.unitId)&&(t.button==null||t.button===0)&&typeof t.clientX==`number`&&typeof t.clientY==`number`}function ve(e,t){if(typeof t.clientX==`number`&&typeof t.clientY==`number`)return{pointerId:t.pointerId,startClientX:t.clientX,startClientY:t.clientY,startLeft:Number(e.rect.left??0),startTop:Number(e.rect.top??0)}}function ye(e,t,n){let{scaleX:r,scaleY:i}=n.getAncestorScale();return{left:e.startLeft+(t.clientX-e.startClientX)/(r||1),top:e.startTop+(t.clientY-e.startClientY)/(i||1)}}function be(e,t){let n=t.data;if(!n||typeof n!=`object`)return;let r=n;r.version===1&&typeof r.embedId==`string`&&(e.transformerConfig={...pe,keepRatio:r.resizeBehavior===`aspect-ratio`})}function xe(e){e.transformerConfig={...e.transformerConfig,...me}}function Se(e){if(!Ce(e))return!1;let n=e.data;return n.hostType===t.UniverInstanceType.UNIVER_SHEET&&n.childType===t.UniverInstanceType.UNIVER_SHEET&&n.runtimeMountMode===`stage2`}function Ce(e){let t=e.data;if(!t||typeof t!=`object`)return!1;let n=t;return n.version===1&&typeof n.embedId==`string`}function we(e){if(!Ce(e))return!1;let n=e.data;return n.hostType===t.UniverInstanceType.UNIVER_SHEET&&n.childType!=null}function Te(e,t=`inactive`){return{autoMountRuntime:!Se(e),passThroughRuntimeEvents:!(we(e)&&t===`stage2`),preserveOnFocusChange:Ce(e),usePreviewObject:Se(e)}}function Ee(e){return Te(e).autoMountRuntime}function De(e){return Te(e).preserveOnFocusChange}function Oe(e){return Te(e).usePreviewObject}function ke(e,t=`inactive`){return Te(e,t).passThroughRuntimeEvents}function Ae(e){return Ce(e)&&!Ee(e)}function je(e,t){var n,r;if(!we(e))return!0;let i=t.target,a=i==null||(n=i.closest)==null?void 0:n.call(i,`[data-embed-float-dom="true"]`);return(a==null||(r=a.dataset)==null?void 0:r.embedFloatStage)!==`stage2`}function Me(e){return e!==`stage2`}function Ne(e,t,n){if(t){if(e===`stage1`){var r,i;(r=(i=t.scene).attachTransformerTo)==null||r.call(i,n);return}if(e===`stage2`&&n.oKey){var a,o,s;t.transformer.clearControlByIds([n.oKey]),(a=(o=t.scene).getTransformer)==null||(a=a.call(o))==null||(s=a.clearSelectedObjects)==null||s.call(a)}}}function Pe(e,t){return e.domLayers.some(([e])=>e===t)}function Fe(e){return e===t.DrawingTypeEnum.DRAWING_DOM||e===t.DrawingTypeEnum.DRAWING_BLOCK||e===t.DrawingTypeEnum.DRAWING_CHART}function Ie(e,t){if(e.runtimeMounted||e.runtimeStage!==`stage1`)return!1;let{offsetX:n,offsetY:r}=t;if(typeof n!=`number`||typeof r!=`number`)return!1;let i=e.position$.getValue();if(n>=Math.min(i.startX,i.endX)&&n<=Math.max(i.startX,i.endX)&&r>=Math.min(i.startY,i.endY)&&r<=Math.max(i.startY,i.endY))return!0;let a=e.rect;if(typeof a.isHit==`function`)try{return a.isHit({x:n,y:r})}catch{}return n>=a.left&&n<=a.left+a.width&&r>=a.top&&r<=a.top+a.height}function Le(e,t){if(t.type===`pointerdown`&&Ie(e,t))return{pointerId:t.pointerId,startOffsetX:t.offsetX,startOffsetY:t.offsetY,startedAt:Date.now()}}function Re(e,t,n){return!t||n.type!==`pointerup`||t.pointerId!=null&&n.pointerId!=null&&t.pointerId!==n.pointerId||!Ie(e,n)?!1:Math.hypot(n.offsetX-t.startOffsetX,n.offsetY-t.startOffsetY)<=4}function ze(e,n,i,a,o,s=!1){let{scaleX:c,scaleY:l}=n.getAncestorScale(),u=n.getViewport(r.SHEET_VIEWPORT_KEY.VIEW_MAIN),{startColumn:d,startRow:f,xSplit:p,ySplit:m}=a.getFreeze(),h={left:!0,top:!0};if(!u)return{...e,absolute:h};let{left:g,right:_,top:v,bottom:y}=e,{top:b,left:x,viewportScrollX:S,viewportScrollY:C}=u,{boundsOfViewArea:w,scrollDirectionResponse:T}=o||{},{rowHeaderWidth:E,columnHeaderHeight:D}=i,O={top:s?0:D,left:s?0:E};w&&(t.Tools.isDefine(O.top)&&(O.top=w.top),t.Tools.isDefine(O.left)&&(O.left=w.left)),T===`HORIZONTAL`&&(C=0),T===`VERTICAL`&&(S=0);let k=0,A=0,j=i.rowStartY(f-m)+D,M=i.colStartX(d-p)+E,N=i.rowStartY(f)+D,P=i.colStartX(d)+E;if(p===0)h.left=!1,k=(g-S)*c,A=(_-S)*c;else{let e=g-(M-E),t=_-(M-E);_<P?(k=e*c,A=t*c):g<=P&&_>=P?(k=e*c,A=Math.max(x,(_-S)*c)):g>P&&(h.left=!1,k=Math.max((g-S)*c,x),A=Math.max((_-S)*c,x))}let F=0,I=0;if(m===0)h.top=!1,F=(v-C)*l,I=(y-C)*l;else{let e=v-(j-D),t=y-(j-D);y<N?(F=e*l,I=t*l):v<=N&&y>=N?(F=e*l,I=Math.max(b,(y-C)*l)):v>N&&(h.top=!1,F=Math.max((v-C)*l,b),I=Math.max((y-C)*l,b))}return k=Math.max(k,O.left),F=Math.max(F,O.top),A=Math.max(A,O.left),I=Math.max(I,O.top),{left:k,right:A,top:F,bottom:I,absolute:h}}let $=(e,t,n,r,i)=>{let{left:a,top:o,width:s,height:c,angle:l}=e,u=ze({left:a,right:a+s,top:o,bottom:o+c},t,n,r,i),{scaleX:d,scaleY:f}=t.getAncestorScale();return{startX:u.left,endX:u.right,startY:u.top,endY:u.bottom,rotate:l,width:s*d,height:c*f,absolute:u.absolute}},Be=ue=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._renderManagerService=e,this._univerInstanceService=t,this._commandService=n,this._drawingManagerService=r,this._canvasFloatDomService=i,this._sheetDrawingService=a,this._lifecycleService=o,this._canvasFloatDomPreviewService=s,F(this,`_domLayerInfoMap`,new Map),F(this,`_transformChange$`,new d.Subject),F(this,`transformChange$`,this._transformChange$.asObservable()),F(this,`_add$`,new d.Subject),F(this,`add$`,this._add$.asObservable()),F(this,`_remove$`,new d.Subject),F(this,`remove$`,this._remove$.asObservable()),F(this,`_renderObjectFactories`,new Map),this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent(),this._bindEmbedFloatDragHandleEvent()}registerRenderObjectFactory(e,t){let n=this._renderObjectFactories.get(e)??[];return n.push(t),this._renderObjectFactories.set(e,n),{dispose:()=>{let n=this._renderObjectFactories.get(e);if(!n)return;let r=n.indexOf(t);r>=0&&n.splice(r,1),n.length===0&&this._renderObjectFactories.delete(e)}}}_createRenderObject(e){let t=this._renderObjectFactories.get(e.drawingType),n=t==null?void 0:t[t.length-1];return(n==null?void 0:n(e))??new r.Rect(e.key,e.config)}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe((0,d.filter)(e=>e===t.LifecycleStages.Rendered),(0,d.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)}static _disposeExternalFloatDom(e,t){e._removeDom(t,!0)}_createFloatDomDisposable(e){return fe(this,e,ue._disposeExternalFloatDom)}_bindEmbedFloatDragHandleEvent(){if(typeof document>`u`)return;let e=e=>this._handleEmbedFloatDragHandlePointerDown(e);document.addEventListener(ge,e),this.disposeWithMe(()=>document.removeEventListener(ge,e))}_handleEmbedFloatDragHandlePointerDown(e){let t=e.detail;if(!(t!=null&&t.hostAnchorId))return;let n=this._domLayerInfoMap.get(t.hostAnchorId);if(!n||!_e(n,t))return;let r=ve(n,t),i=this._getSceneAndTransformerByDrawingSearch(n.unitId);if(!r||!i)return;let{scene:a,transformer:o}=i;if(n.rect.oKey){var s;o.clearControlByIds([n.rect.oKey]),(s=a.getTransformer())==null||s.clearSelectedObjects()}let c=e=>{if(r.pointerId!=null&&e.pointerId!==r.pointerId)return;e.preventDefault();let t=ye(r,e,a);n.rect.transformByState(t)},l=e=>{if((r.pointerId==null||e.pointerId===r.pointerId)&&(window.removeEventListener(`pointermove`,c,!0),window.removeEventListener(`pointerup`,l,!0),window.removeEventListener(`pointercancel`,u,!0),e.preventDefault(),(n.rect.left!==r.startLeft||n.rect.top!==r.startTop)&&this._commitFloatDomMove(n),n.runtimeStage===`stage1`)){var t;(t=a.attachTransformerTo)==null||t.call(a,n.rect)}},u=e=>{if((r.pointerId==null||e.pointerId===r.pointerId)&&(window.removeEventListener(`pointermove`,c,!0),window.removeEventListener(`pointerup`,l,!0),window.removeEventListener(`pointercancel`,u,!0),n.rect.transformByState({left:r.startLeft,top:r.startTop}),n.runtimeStage===`stage1`)){var t;(t=a.attachTransformerTo)==null||t.call(a,n.rect)}};window.addEventListener(`pointermove`,c,!0),window.addEventListener(`pointerup`,l,!0),window.addEventListener(`pointercancel`,u,!0)}_commitFloatDomMove(e){var t;let r=(t=this._renderManagerService.getRenderUnitById(e.unitId))==null?void 0:t.with(c.SheetSkeletonManagerService).getSkeletonParam(e.subUnitId),i=this._sheetDrawingService.getDrawingByParam({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.id});if(!r||!(i!=null&&i.transform))return;let a={...i.transform,left:e.rect.left,top:e.rect.top,width:e.rect.width,height:e.rect.height,angle:e.rect.angle,flipX:e.rect.flipX,flipY:e.rect.flipY,skewX:e.rect.skewX,skewY:e.rect.skewY},o=(0,n.transformToDrawingPosition)(a,r.skeleton),s=(0,n.transformToAxisAlignPosition)(a,r.skeleton);o&&s&&this._commandService.syncExecuteCommand(n.SetSheetDrawingCommand.id,{unitId:e.unitId,drawings:[{...i,transform:a,sheetTransform:o,axisAlignSheetTransform:s}]})}isFloatDomRuntimeMounted(e){var t;return((t=this._domLayerInfoMap.get(e))==null?void 0:t.runtimeMounted)===!0}_getFloatDomPreviewObjectKey(e){return`${e}__preview`}_syncPreviewObjectTransform(e,t){e==null||e.transformByState({left:t.left,top:t.top,width:t.width,height:t.height,angle:t.angle,flipX:t.flipX,flipY:t.flipY,skewX:t.skewX,skewY:t.skewY})}_requestFloatDomPreview(e,t,n){this._canvasFloatDomPreviewService&&this._canvasFloatDomPreviewService.requestPreview({id:e,width:t.width,height:t.height,data:n})}_upsertFloatDomPreviewObject(e,t,n,i,a){var o;let s=(o=this._canvasFloatDomPreviewService)==null?void 0:o.getPreview(i);if(!(s!=null&&s.image)){this._requestFloatDomPreview(i,t,a);return}let c=this._getFloatDomPreviewObjectKey(n),l=e.getObject(c);if(l instanceof r.Image)return l.changeSource(s.image),this._syncPreviewObjectTransform(l,t),l;let u=new r.Image(c,{left:t.left,top:t.top,width:t.width,height:t.height,angle:t.angle,flipX:t.flipX,flipY:t.flipY,skewX:t.skewX,skewY:t.skewY,url:s.image,evented:!1,rotateEnabled:!1,resizeEnabled:!1});return e.addObject(u,r.DRAWING_OBJECT_LAYER_INDEX),u}mountFloatDomRuntime(e){let t=this._domLayerInfoMap.get(e);return t!=null&&t.floatDomConfig?t.runtimeMounted?!0:(Pe(this._canvasFloatDomService,e)?this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:!1,props:{...t.floatDomConfig.props,initialStage:`stage2`,onRuntimeStageExit:()=>this.unmountFloatDomRuntime(e)}}):this._canvasFloatDomService.addFloatDom({...t.floatDomConfig,eventPassThrough:!1,props:{...t.floatDomConfig.props,initialStage:`stage2`,onRuntimeStageExit:()=>this.unmountFloatDomRuntime(e)}}),t.runtimeMounted=!0,t.runtimeStage=`stage2`,!0):!1}unmountFloatDomRuntime(e){let t=this._domLayerInfoMap.get(e);t!=null&&t.runtimeMounted&&(t.floatDomConfig&&!Ee(t.floatDomConfig)?this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:ke(t.floatDomConfig,`inactive`),props:t.floatDomConfig.props}):this._canvasFloatDomService.removeFloatDom(e),t.runtimeMounted=!1,t.runtimeStage=`inactive`)}_syncFloatDomVisibilityForActiveSheet(e,t){Array.from(this._domLayerInfoMap.values()).filter(t=>t.unitId===e&&t.floatDomConfig).forEach(e=>{let n=e.subUnitId===t,r=Pe(this._canvasFloatDomService,e.id);if(!n){r&&this._canvasFloatDomService.removeFloatDom(e.id),e.runtimeMounted=!1,e.runtimeStage=`inactive`;return}if(r||!e.floatDomConfig)return;this._canvasFloatDomService.addFloatDom(e.floatDomConfig);let i=Ee(e.floatDomConfig);e.runtimeMounted=i,e.runtimeStage=Ce(e.floatDomConfig)?`inactive`:i?`stage2`:`inactive`})}promoteFloatDomRuntimeStage(e){let t=this._domLayerInfoMap.get(e);if(!(t!=null&&t.floatDomConfig))return;let n=we(t.floatDomConfig);return t.runtimeMounted&&!n?(t.runtimeStage=`stage2`,`stage2`):t.runtimeStage===`stage1`?t.runtimeMounted?(t.runtimeStage=`stage2`,Ae(t.floatDomConfig)&&this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:ke(t.floatDomConfig,`stage2`)}),`stage2`):(this.mountFloatDomRuntime(e),`stage2`):(t.runtimeStage=`stage1`,Ae(t.floatDomConfig)&&this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:ke(t.floatDomConfig,`stage1`)}),`stage1`)}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderUnitById(e),n=t==null?void 0:t.scene;return t==null||n==null?null:{scene:n,transformer:n.getTransformerByCreate(),renderUnit:t,canvas:t.engine.getCanvasElement()}}_getDrawingZIndex(e,t,n){let r=this._drawingManagerService.getDrawingOrder(e,t),i=r.indexOf(n);return i<0?r.length-1:i}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(e=>{var n;let{unitId:i,subUnitId:a,drawingId:l}=e,f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:i,subUnitId:a}),p=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(i,t.UniverInstanceType.UNIVER_SHEET);if(!m)return;let h=m.getActiveSheet().getSheetId();if(!p||!f)return;let g=(n=this._renderManagerService.getRenderUnitById(i))==null?void 0:n.with(c.SheetSkeletonManagerService).getSkeletonParam(a);if(!g)return;let{transform:_,drawingType:v,data:y,hidden:b,groupId:x}=p;if(!Fe(v))return;let S=this._getSceneAndTransformerByDrawingSearch(i);if(S==null||b)return;let{scene:C,canvas:w}=S;if(_==null)return!0;if(h!==a)return;let{left:T,top:E,width:D,height:O,angle:k,flipX:A,flipY:j,skewX:M,skewY:N}=_,P=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:l}),F=x?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:x}):void 0,I=this._getObjectIncludingGroup(C,P,F);if(I!=null&&(this._removeTopLevelDuplicateIfGrouped(C,P,I),be(I,p),v===t.DrawingTypeEnum.DRAWING_CHART&&xe(I),I.transformByState({left:T,top:E,width:D,height:O,angle:k,flipX:A,flipY:j,skewX:M,skewY:N}),this._syncFloatDomRect(l,I),Oe(p)&&(this._syncPreviewObjectTransform(C.getObject(this._getFloatDomPreviewObjectKey(P)),I),this._requestFloatDomPreview(l,I,y)),this._domLayerInfoMap.has(l)))return;let L={left:T,top:E,width:D,height:O,zIndex:this._getDrawingZIndex(i,a,l)},ee=v===t.DrawingTypeEnum.DRAWING_CHART;if(ee){let e=this._getChartDataBackground(y);e!==void 0&&(L.fill=e),y&&y.border&&(L.stroke=y.border),Object.assign(L,le)}else L.rotateEnabled=!1;let R=I??this._createRenderObject({key:P,config:L,unitId:i,subUnitId:a,drawingId:l,drawingType:v,data:y});be(R,p),ee&&xe(R),ee?R.objectType=r.ObjectType.CHART:(v===t.DrawingTypeEnum.DRAWING_DOM||v===t.DrawingTypeEnum.DRAWING_BLOCK)&&(R.objectType=r.ObjectType.DRAWING_DOM),I||C.addObject(R,r.DRAWING_OBJECT_LAYER_INDEX),!I&&p.allowTransform!==!1&&C.attachTransformerTo(R),!I&&ee&&x&&(0,u.insertGroupObject)({drawingId:x,unitId:i,subUnitId:a},R,C,this._drawingManagerService);let z=new t.DisposableCollection,B=Oe(p),V=B?this._getFloatDomPreviewObjectKey(P):void 0;if(B){var H;this._upsertFloatDomPreviewObject(C,R,P,l,y);let e=(H=this._canvasFloatDomPreviewService)==null?void 0:H.previewUpdated$.subscribe(e=>{e.id===l&&this._upsertFloatDomPreviewObject(C,R,P,l,y)});e&&z.add(e)}let U=$(R,S.renderUnit.scene,g.skeleton,f.worksheet),W=new d.BehaviorSubject(U),G=`${de}${(0,t.generateRandomId)(6)}`,K=Ee(p),q=Ce(p),J,Y={position$:W,id:l,domId:G,componentKey:p.componentKey,eventPassThrough:ke(p,`inactive`),preserveOnFocusChange:De(p),onPointerDown:e=>{je(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{je(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{je(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onWheel:e=>{je(p,e)&&w.dispatchEvent(new WheelEvent(e.type,e))},data:y,props:q?{onRuntimeStageEnter:e=>{J&&(J.runtimeStage=e,J.runtimeMounted=K||e===`stage2`,Ae(p)&&this._canvasFloatDomService.updateFloatDom(l,{eventPassThrough:ke(p,e)})),Ne(e,this._getSceneAndTransformerByDrawingSearch(i),R)}}:void 0,unitId:i};if(J={dispose:z,rect:R,position$:W,unitId:i,subUnitId:a,id:l,domId:G,floatDomConfig:Y,runtimeMounted:K,runtimeStage:q?`inactive`:K?`stage2`:`inactive`,previewObjectKey:V},this._canvasFloatDomService.addFloatDom(Y),!K){let e,t=t=>{if(e&&(e.pointerId==null||t.pointerId==null||e.pointerId===t.pointerId)){if(typeof t.offsetX!=`number`||typeof t.offsetY!=`number`){e=void 0;return}Math.hypot(t.offsetX-e.startOffsetX,t.offsetY-e.startOffsetY)>4&&(e=void 0)}},n=R.onPointerDown$.subscribeEvent({priority:he,next:([t,n])=>{if((J==null?void 0:J.runtimeStage)===`stage1`){e=Le(J,t);return}let r=this.promoteFloatDomRuntimeStage(l);r===`stage2`&&(Ne(r,S,R),n.skipNextObservers=!0),Me(r)||n.stopPropagation()}}),r=C.onPointerDown$.subscribeEvent({priority:he,next:([t])=>{J&&(e=Le(J,t))}}),i=C.onPointerMove$.subscribeEvent({priority:he,next:([e])=>{t(e)}}),a=C.onPointerUp$.subscribeEvent({priority:he,next:([t,n])=>{let r=J&&Re(J,e,t);if(e=void 0,!r)return;let i=this.promoteFloatDomRuntimeStage(l);i===`stage2`&&(Ne(i,S,R),n.stopPropagation(),n.skipNextObservers=!0)}});z.add(n),z.add(r),z.add(i),z.add(a)}let te=R.onTransformChange$.subscribeEvent(()=>{let e=$(R,S.renderUnit.scene,g.skeleton,f.worksheet);W.next(e),V&&this._syncPreviewObjectTransform(C.getObject(V),R)});z.add(()=>{this._canvasFloatDomService.removeFloatDom(l),V&&C.removeObject(V)}),te&&z.add(te),this._bindFloatDomScroll(z,J,S.renderUnit.scene,g.skeleton,f.worksheet),this._domLayerInfoMap.set(l,J)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:n,drawingId:r}),a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{transformer:s,scene:c}=a,l=this._getObjectIncludingGroup(c,i);if(l!=null&&l.oKey){var u;s.clearControlByIds([l==null?void 0:l.oKey]),(u=c.getTransformer())==null||u.clearSelectedObjects()}})}))}_scrollUpdateListener(){let e=(e,t)=>{var n;let r=this._getSceneAndTransformerByDrawingSearch(e),i=Array.from(this._domLayerInfoMap.keys()).map(e=>({id:e,...this._domLayerInfoMap.get(e)})).filter(n=>n.subUnitId===t&&n.unitId===e).map(e=>e.id),a=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:t}),o=(n=this._renderManagerService.getRenderUnitById(e))==null?void 0:n.with(c.SheetSkeletonManagerService).getSkeletonParam(t);r&&a&&o&&i.forEach(e=>{let t=this._domLayerInfoMap.get(e);if(t){let e=$(t.rect,r.renderUnit.scene,o.skeleton,a.worksheet,t);t.position$.next(e)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?e.activeSheet$:(0,d.of)(null))).subscribe(t=>{if(!t)return;let n=t.getUnitId(),r=t.getSheetId();this._syncFloatDomVisibilityForActiveSheet(n,r),e(n,r)})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===c.SetZoomRatioOperation.id){let{unitId:n}=t.params;new Set(Array.from(this._domLayerInfoMap.values()).filter(e=>e.unitId===n).map(e=>e.subUnitId)).forEach(t=>{e(n,t)})}else if(t.id===s.SetFrozenMutation.id){let{unitId:n,subUnitId:r}=t.params;e(n,r)}else if(t.id===s.SetSelectionsOperation.id){let{unitId:n,subUnitId:r}=t.params;e(n,r)}}))}_bindFloatDomScroll(e,n,i,a,o){let s=i.getViewport(r.SHEET_VIEWPORT_KEY.VIEW_MAIN);s&&e.add((0,t.fromEventSubject)(s.onScrollAfter$).subscribe(()=>{n.position$.next($(n.rect,i,a,o,n))}))}updateFloatDomProps(e,t,n,i){let a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(e);if(a&&s){let{scene:a}=s,c=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),l=this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),u=l!=null&&l.groupId?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:l.groupId}):void 0,d=this._getObjectIncludingGroup(a,c,u);d&&d instanceof r.Rect&&(this._removeTopLevelDuplicateIfGrouped(a,c,d),d.setProps(i),this._syncFloatDomRect(n,d))}}_getObjectIncludingGroup(e,t,n){var r;return this._getChildObjectFromGroup(e,t,n)??((r=e.getObjectIncludeInGroup)==null?void 0:r.call(e,t))??e.getObject(t)??null}_getChildObjectFromGroup(e,t,n){var r;if(!n)return null;let i=((r=e.getObjectIncludeInGroup)==null?void 0:r.call(e,n))??e.getObject(n);return this._findChildObject(i,t)}_findChildObject(e,t){if(!e)return null;let n=e.getObjects();for(let e of n){if(e.oKey===t)return e;let n=this._findChildObject(e,t);if(n)return n}return null}_removeTopLevelDuplicateIfGrouped(e,t,n){if(!n.isInGroup)return;let r=e.getObject(t);r&&r!==n&&e.removeObject(r)}_syncFloatDomRect(e,t){if(!(t instanceof r.Rect))return;let n=this._domLayerInfoMap.get(e);n&&(n.rect=t)}_getChartDataBackground(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e,n=t.backgroundColor??t.background;return typeof n==`string`?n:void 0}_getPosition(e,t){var n;let{startX:r,endX:i,startY:a,endY:o}=e,s=(n=this._renderManagerService.getRenderUnitById(t))==null?void 0:n.with(c.ISheetSelectionRenderService);if(s==null)return;let l=s.getCellWithCoordByOffset(r,a);if(l==null)return;let u={column:l.actualColumn,columnOffset:r-l.startX,row:l.actualRow,rowOffset:a-l.startY},d=s.getCellWithCoordByOffset(i,o);if(d!=null)return{from:u,to:{column:d.actualColumn,columnOffset:i-d.startX,row:d.actualRow,rowOffset:o-d.startY}}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let n=this._drawingManagerService.getDrawingByParam(e);if(!n||!Fe(n.drawingType))return;if(n.hidden){this._removeDom(e.drawingId);return}if(!this._domLayerInfoMap.has(e.drawingId)){this._drawingManagerService.addNotification([e]);return}let r={...n.transform};this._transformChange$.next({id:e.drawingId,value:r}),this._canvasFloatDomService.updateFloatDom(e.drawingId,{...n});let i=this._getSceneAndTransformerByDrawingSearch(e.unitId);if(i&&n.drawingType!==t.DrawingTypeEnum.DRAWING_CHART){let{scene:t}=i,r=this._domLayerInfoMap.get(e.drawingId);r!=null&&r.rect&&(n.allowTransform===!1?t.detachTransformerFrom(r.rect):t.attachTransformerTo(r.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(e,r){let i=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!i)throw Error(`cannot find current target!`);let{unitId:a,subUnitId:o}=i,{initPosition:c,componentKey:l,data:u,allowTransform:d=!0}=e,f=r??(0,t.generateRandomId)(),p=this._getPosition(c,a);if(p==null)return;let m={unitId:a,subUnitId:o,drawingId:f,drawingType:e.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:p,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},axisAlignSheetTransform:p,data:u,allowTransform:d};return this._commandService.executeCommand(n.InsertSheetDrawingCommand.id,{unitId:a,drawings:[m]}),this._add$.next({unitId:a,subUnitId:o,id:f}),this._createFloatDomDisposable(f)}_removeDom(e,t=!1){let r=this._domLayerInfoMap.get(e);if(!r)return;let{unitId:i,subUnitId:a}=r;this._domLayerInfoMap.delete(e),r.dispose.dispose();let o=this._getSceneAndTransformerByDrawingSearch(i);if(o){let{scene:t,transformer:n}=o;if((0,u.disposeDrawingRenderObject)(t,{unitId:i,subUnitId:a,drawingId:e})){var s;n.clearControlByIds([r.rect.oKey]),(s=t.getTransformer())==null||s.clearSelectedObjects()}}if(t){let t=this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:a,drawingId:e});if(!t)return;let{redo:r,objects:o}=this._sheetDrawingService.getBatchRemoveOp([t]);this._commandService.syncExecuteCommand(n.SetDrawingApplyMutation.id,{unitId:i,subUnitId:a,op:r,objects:o,type:n.DrawingApplyType.REMOVE})}}removeFloatDom(e,t=!0){this._removeDom(e,t)}addFloatDomToRange(e,n,i,a){var l;let f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!f)throw Error(`cannot find current target!`);let{unitId:p,subUnitId:m}=f,h=this._getSceneAndTransformerByDrawingSearch(p);if(!h)return;let g=this._renderManagerService.getRenderUnitById(p);if(!g)return;let _=(l=this._renderManagerService.getRenderUnitById(p))==null?void 0:l.with(c.SheetSkeletonManagerService).getSkeletonParam(m);if(!_)return;let{componentKey:v,data:y,allowTransform:b=!0}=n,x=a??(0,t.generateRandomId)(),{position:S,position$:C}=this._createRangePositionObserver(e,g,_.skeleton),w=this._getPosition(S,p);if(w==null)return;let{scaleX:T}=h.scene.getAncestorScale(),E=He(S,i,T),D={unitId:p,subUnitId:m,drawingId:x,drawingType:n.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:v,sheetTransform:w,axisAlignSheetTransform:w,transform:{left:E.startX,top:E.startY,width:E.width,height:E.height},data:y,allowTransform:b};{var O,k;let{unitId:e,subUnitId:a,drawingId:l}=D,f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:a}),p=D,m=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!m)return;let h=m.getActiveSheet().getSheetId();if(!p||!f)return;let g=(O=this._renderManagerService.getRenderUnitById(e))==null?void 0:O.with(c.SheetSkeletonManagerService);if(!g)return;let _=g.getSkeletonParam(a);if(!_)return;let{transform:v,drawingType:y,data:b,groupId:w}=p;if(!Fe(y))return;let T=this._getSceneAndTransformerByDrawingSearch(e);if(T==null)return;let{scene:E,canvas:A}=T;if(v==null||h!==a)return;let{left:j,top:M,width:N,height:P,angle:F,flipX:I,flipY:L,skewX:ee,skewY:R}=v,z=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),B=w?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:w}):void 0,V=this._getObjectIncludingGroup(E,z,B);if(V!=null){this._removeTopLevelDuplicateIfGrouped(E,z,V),y===t.DrawingTypeEnum.DRAWING_CHART&&xe(V),V.transformByState({left:j,top:M,width:N,height:P,angle:F,flipX:I,flipY:L,skewX:ee,skewY:R}),this._syncFloatDomRect(l,V);return}let H={left:j,top:M,width:N,height:P,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1},U=y===t.DrawingTypeEnum.DRAWING_CHART;if(U){let e=this._getChartDataBackground(b);e!==void 0&&(H.fill=e),H.rotateEnabled=!1,b&&b.border&&(H.stroke=b.border),H.paintFirst=`stroke`,H.strokeWidth=1,H.radius=8}let W=this._createRenderObject({key:z,config:H,unitId:e,subUnitId:a,drawingId:l,drawingType:y,data:b});U&&(W.setObjectType(r.ObjectType.CHART),xe(W)),E.addObject(W,r.DRAWING_OBJECT_LAYER_INDEX),p.allowTransform!==!1&&E.attachTransformerTo(W),U&&w&&(0,u.insertGroupObject)({drawingId:w,unitId:e,subUnitId:a},W,E,this._drawingManagerService);let G=new t.DisposableCollection,K=E.getMainViewport(),{rowHeaderWidth:q,columnHeaderHeight:J}=_.skeleton,Y={dispose:G,rect:W,boundsOfViewArea:{top:J,left:q,bottom:K.bottom,right:K.right},domAnchor:i,unitId:e,subUnitId:a,id:l},te=$(W,T.renderUnit.scene,_.skeleton,f.worksheet,Y),X=new d.BehaviorSubject(te);Y.position$=X;let Z={position$:X,id:l,componentKey:p.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:e=>{A.dispatchEvent(new WheelEvent(e.type,e))},data:b,unitId:e};n.eventPassThrough&&(Z={...Z,onPointerDown:e=>{A.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{A.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{A.dispatchEvent(new PointerEvent(e.type,e))}}),this._canvasFloatDomService.addFloatDom(Z),this.disposeWithMe(C.subscribe(t=>{let n=He({rotate:0,startX:t.startX,startY:t.startY,endX:t.endX,endY:t.endY,width:i.width??t.width,height:i.height??t.height,absolute:{left:S.absolute.left,top:S.absolute.top}},i),s=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),c=new r.Rect(s,{left:n.startX,top:n.startY,width:i.width??t.width,height:i.height??t.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1}),u=$(c,T.renderUnit.scene,_.skeleton,f.worksheet,Y);X.next(u)}));let Q=(k=this._renderManagerService.getRenderUnitById(e))==null?void 0:k.with(c.SheetSkeletonManagerService),ne=Q==null?void 0:Q.currentSkeleton$.subscribe(e=>{e&&_.sheetId!==e.sheetId&&this._removeDom(x,!0)});ne&&G.add(ne);let re=W.onTransformChange$.subscribeEvent(()=>{let e=$(W,T.renderUnit.scene,_.skeleton,f.worksheet,Y);X.next(e)});G.add(()=>{this._canvasFloatDomService.removeFloatDom(l)}),re&&G.add(re),this._bindFloatDomScroll(G,Y,T.renderUnit.scene,_.skeleton,f.worksheet),this._domLayerInfoMap.set(l,Y)}return this._createFloatDomDisposable(x)}addFloatDomToColumnHeader(e,n,i,a){var l;let u=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!u)throw Error(`cannot find current target!`);let{unitId:f,subUnitId:p}=u;if(!this._getSceneAndTransformerByDrawingSearch(f))return;let m=this._renderManagerService.getRenderUnitById(f);if(!m)return;let h=(l=this._renderManagerService.getRenderUnitById(f))==null?void 0:l.with(c.SheetSkeletonManagerService).getSkeletonParam(p);if(!h)return;let{componentKey:g,data:_,allowTransform:v=!0}=n,y=a??(0,t.generateRandomId)(),{position:b,position$:x}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:e,endColumn:e},m,h.skeleton),S=b;S.startY=0;let C=this._getPosition(b,f);if(C==null)return;let w={unitId:f,subUnitId:p,drawingId:y,drawingType:n.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:g,sheetTransform:C,axisAlignSheetTransform:C,transform:{left:S.startX,top:S.startY,width:S.width,height:S.height},data:_,allowTransform:v};{var T,E;let{unitId:e,subUnitId:a,drawingId:l}=w,u=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:a}),f=w,p=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!p)return;let m=p.getActiveSheet().getSheetId();if(!f||!u)return;let g=(T=this._renderManagerService.getRenderUnitById(e))==null?void 0:T.with(c.SheetSkeletonManagerService);if(!g)return;let _=g.getSkeletonParam(a);if(!_)return;let{transform:v,data:C}=f,D=this._getSceneAndTransformerByDrawingSearch(e);if(D==null)return;let{scene:O,canvas:k}=D;if(v==null||m!==a)return;let{left:A,top:j,width:M,height:N,angle:P,flipX:F,flipY:I,skewX:L,skewY:ee}=v,R=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),z=this._getObjectIncludingGroup(O,R);if(z!=null){this._removeTopLevelDuplicateIfGrouped(O,R,z),z.transformByState({left:A,top:j,width:M,height:N,angle:P,flipX:F,flipY:I,skewX:L,skewY:ee}),this._syncFloatDomRect(l,z);return}let B=He({rotate:0,startX:S.startX,startY:0,endX:b.endX,endY:b.endY,width:i.width,height:i.height,absolute:{left:b.absolute.left,top:b.absolute.top}},i),V={left:B.startX,top:B.startY,width:B.width,height:B.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1},H=new r.Rect(R,V);O.addObject(H,r.DRAWING_OBJECT_LAYER_INDEX),f.allowTransform!==!1&&O.attachTransformerTo(H);let U=new t.DisposableCollection,W=O.getMainViewport(),G={dispose:U,rect:H,unitId:e,subUnitId:a,id:l,boundsOfViewArea:{top:0,left:W.left,bottom:W.bottom,right:W.right},domAnchor:i,scrollDirectionResponse:`HORIZONTAL`},K=$(H,D.renderUnit.scene,_.skeleton,u.worksheet,G),q=new d.BehaviorSubject(K);G.position$=q;let J={position$:q,id:l,componentKey:f.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:e=>{k.dispatchEvent(new WheelEvent(e.type,e))},data:C,unitId:e};n.eventPassThrough&&(J={...J,onPointerDown:e=>{k.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{k.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{k.dispatchEvent(new PointerEvent(e.type,e))}}),this._canvasFloatDomService.addFloatDom(J);let Y=H.onTransformChange$.subscribeEvent(()=>{let e=$(H,D.renderUnit.scene,_.skeleton,u.worksheet,G);q.next(e)});this.disposeWithMe(x.subscribe(t=>{let n=He({rotate:0,startX:t.startX,startY:0,endX:t.endX,endY:t.endY,width:i.width,height:i.height,absolute:{left:b.absolute.left,top:b.absolute.top}},i),s=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),c=new r.Rect(s,{left:n.startX,top:0,width:i.width,height:i.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1}),d=$(c,D.renderUnit.scene,_.skeleton,u.worksheet,G);q.next(d)}));let te=(E=this._renderManagerService.getRenderUnitById(e))==null?void 0:E.with(c.SheetSkeletonManagerService);te==null||te.currentSkeleton$.subscribe(e=>{e&&h.sheetId!==e.sheetId&&this._removeDom(y,!0)}),U.add(()=>{this._canvasFloatDomService.removeFloatDom(l)}),Y&&U.add(Y),this._bindFloatDomScroll(U,G,D.renderUnit.scene,_.skeleton,u.worksheet),this._domLayerInfoMap.set(l,G)}return this._createFloatDomDisposable(y)}_createRangePositionObserver(e,n,r){let{startRow:i,startColumn:a}=e,o=Ve(i,a,r),l=new d.BehaviorSubject(o),u=Ve(e.endRow,e.endColumn,r),f=new d.BehaviorSubject(u),p=()=>{let t=Ve(i,a,r),n=Ve(e.endRow,e.endColumn,r);l.next(t),f.next(n)},m=new t.DisposableCollection;return m.add(n.engine.clientRect$.subscribe({next:()=>p(),error:()=>{}})),m.add(this._commandService.onCommandExecuted(e=>{if(e.id===s.SetWorksheetRowAutoHeightMutation.id&&e.params.rowsAutoHeightInfo.findIndex(e=>e.row===i)>-1){p();return}(s.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(e.id)>-1||e.id===c.SetScrollOperation.id||e.id===c.SetZoomRatioOperation.id)&&p()})),{position$:l.pipe((0,d.map)(t=>{let n=Ve(e.endRow,e.endColumn,r);return{rotate:0,width:n.right-t.left,height:n.bottom-t.top,absolute:{left:!0,top:!0},startX:t.left,startY:t.top,endX:n.right,endY:n.bottom}})),position:{rotate:0,width:u.right-o.left,height:u.bottom-o.top,absolute:{left:!0,top:!0},startX:o.left,startY:o.top,endX:u.right,endY:u.bottom},updateRowCol:(e,t)=>{i=e,a=t,p()},topLeftPos$:l,rightBottomPos$:f,disposable:m}}};Be=ue=L([I(0,(0,t.Inject)(r.IRenderManagerService)),I(1,t.IUniverInstanceService),I(2,(0,t.Inject)(t.ICommandService)),I(3,o.IDrawingManagerService),I(4,(0,t.Inject)(l.CanvasFloatDomService)),I(5,n.ISheetDrawingService),I(6,(0,t.Inject)(t.LifecycleService)),I(7,(0,t.Optional)(l.CanvasFloatDomPreviewService))],Be);function Ve(e,t,n){let r=n.getCellWithCoordByIndex(e,t),i=r.isMergedMainCell?r.mergeInfo:r;return{left:i.startX,right:i.endX,top:i.startY,bottom:i.endY}}function He(e,t,n){n??=1;let r=e.endX-e.startX,i=e.endY-e.startY,a=(t==null?void 0:t.width)??r,o=(t==null?void 0:t.height)??i,s=0,c=0;if(t){if(t.horizonOffsetAlign===`right`){let i=Ue(t.marginX,r*n);s=e.endX-i-a}else s=e.startX+Ue(t.marginX,r);if(t.verticalOffsetAlign===`bottom`){let r=Ue(t.marginY,i*n);c=e.endY-r-o}else c=e.startY+Ue(t.marginY,i)}return{rotate:0,startX:s,startY:c,endX:e.endX,endY:e.endY,width:a,height:o,absolute:{left:e.absolute.left,top:e.absolute.top}}}function Ue(e,t){return e===void 0?0:typeof e==`number`?e:t*Number.parseFloat(e)/100}let We=[[Be]];function Ge(e){e.has(Be)||(0,t.registerDependencies)(e,We),qe(e)}function Ke(e){(0,t.touchDependencies)(e,[[Be]])}function qe(e){if(!e.has(t.LifecycleService)){Ke(e);return}let n=e.get(t.LifecycleService);if(n.stage>=t.LifecycleStages.Ready){Ke(e);return}n.onStage(t.LifecycleStages.Ready).then(()=>{Ke(e)})}let Je=`sheet.menu.image`;function Ye(e){return{id:Je,type:l.MenuItemType.SUBITEMS,icon:`AddImageIcon`,tooltip:`sheets-drawing-ui.title`,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission],rangeTypes:[s.RangeProtectionPermissionEditPoint]})}}function Xe(e){return{id:B.id,title:`sheets-drawing-ui.upload.float`,type:l.MenuItemType.BUTTON,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}function Ze(e){return{id:V.id,title:`sheets-drawing-ui.upload.cell`,type:l.MenuItemType.BUTTON,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}function Qe(e,t){let n=e.getActiveSheet();if(!n)return!1;let r=n.getCellMatrix(),{startRow:i,endRow:a,startColumn:o,endColumn:c}=t;for(let e=i;e<=a;e++)for(let t=o;t<=c;t++){let n=r.getValue(e,t);if((0,s.isCellImage)(n==null?void 0:n.p))return!0}return!1}function $e(){return`showDirectoryPicker`in window}function et(e){let n=e.get(t.IUniverInstanceService),r=e.get(s.SheetsSelectionsService),i=(0,d.combineLatest)([(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),n.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?r.selectionMoveEnd$.pipe((0,d.map)(()=>{if(!$e())return!0;let t=r.getCurrentSelections();if(!t||t.length===0)return!0;for(let n of t)if(Qe(e,n.range))return!1;return!0})):(0,d.of)(!0)))]).pipe((0,d.map)(([e,t])=>e||t));return{id:Q.id,type:l.MenuItemType.BUTTON,icon:`DownloadImageIcon`,title:`sheets-drawing-ui.save.menuLabel`,hidden$:i}}let tt=`sheet.menu.worksheet-background-image`;function nt(e){let r=e.get(t.ICommandService),i=e.get(t.IUniverInstanceService);return new d.Observable(e=>{let a=()=>{let e=i.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);return!!(e!=null&&e.getActiveSheet().getConfig().backgroundImage)},o=new t.DisposableCollection;return o.add(r.onCommandExecuted(t=>{(t.id===n.SetWorksheetBackgroundImageMutation.id||t.id===s.SetWorksheetActiveOperation.id)&&e.next(a())})),o.add(i.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{e.next(a())})),e.next(a()),()=>o.dispose()})}function rt(e){return(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission]})}function it(e){return{id:tt,type:l.MenuItemType.SUBITEMS,icon:`AddImageIcon`,tooltip:`sheets-drawing-ui.backgroundImage.title`,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:rt(e)}}function at(e){return{id:ne.id,type:l.MenuItemType.BUTTON,title:`sheets-drawing-ui.backgroundImage.add`,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:rt(e)}}function ot(e){let n=rt(e);return{id:re.id,type:l.MenuItemType.BUTTON,title:`sheets-drawing-ui.backgroundImage.delete`,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,d.combineLatest)([n,nt(e)]).pipe((0,d.map)(([e,t])=>e||!t))}}let st={[l.RibbonInsertGroup.MEDIA]:{[Je]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,showLabel:!0},menuItemFactory:Ye,[B.id]:{order:0,menuItemFactory:Xe},[V.id]:{order:1,menuItemFactory:Ze}}},[l.RibbonPosition.VIEW]:{[l.RibbonViewGroup.DISPLAY]:{[tt]:{order:.5,gridLayout:{row:1,column:2,rowSpan:2,showLabel:!0},menuItemFactory:it,[ne.id]:{order:0,menuItemFactory:at},[re.id]:{order:1,menuItemFactory:ot}}}},[l.ContextMenuPosition.MAIN_AREA]:{[l.ContextMenuGroup.OTHERS]:{[Q.id]:{order:10,menuItemFactory:et}}},[l.ContextMenuPosition.COL_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[Q.id]:{order:10,menuItemFactory:et}}},[l.ContextMenuPosition.ROW_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[Q.id]:{order:10,menuItemFactory:et}}}};var ct=`@univerjs/sheets-drawing-ui`,lt=`1.0.1`;let ut=`sheets-drawing-ui.config`,dt={},ft=(0,t.createIdentifier)(`sheets-drawing-ui.drawing-context-menu.service`);var pt=class extends t.Disposable{constructor(...e){super(...e),F(this,`_providers`,new Map)}registerProvider(e,n){return this._providers.set(e,n),(0,t.toDisposable)(()=>{this._providers.get(e)===n&&this._providers.delete(e)})}getContextMenuPosition(e){var t;return(t=this._providers.get(e.drawingType))==null?void 0:t.getContextMenuPosition(e)}};let mt=class extends t.RxDisposable{constructor(e,t,n,r,i){super(),this._drawingManagerService=e,this._contextMenuService=t,this._renderManagerService=n,this._univerInstanceService=r,this._drawingContextMenuService=i,this._init()}_init(){this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._contextMenuListener(e))}_contextMenuListener(e){var t;if(!e)return;let n=(t=this._renderManagerService.getRenderUnitById(e.getUnitId()))==null?void 0:t.scene;if(!n)return;let r=n.getTransformerByCreate();r&&this.disposeWithMe(r.changeEnd$.subscribe(e=>{let{event:t}=e;if(t.button!==2)return;let n=r.getSelectedObjectMap();if(n.size===0)return;let i=[];for(let e of n.values()){let t=e.oKey,n=this._drawingManagerService.getDrawingOKey(t);if(!n)return;i.push(n)}this._contextMenuService.triggerContextMenu(t,this._getContextMenuPosition(i))}))}_getContextMenuPosition(e){if(e.length!==1)return l.ContextMenuPosition.DRAWING;let[t]=e;return this._drawingContextMenuService.getContextMenuPosition({unitId:t.unitId,subUnitId:t.subUnitId,drawingId:t.drawingId,drawingType:t.drawingType,drawing:t})??l.ContextMenuPosition.DRAWING}};mt=L([I(0,o.IDrawingManagerService),I(1,l.IContextMenuService),I(2,r.IRenderManagerService),I(3,t.IUniverInstanceService),I(4,ft)],mt);function ht({SelectComponent:e=i.Select}={}){let n=(0,l.useDependency)(t.LocaleService),r=(0,l.useDependency)(l.IDialogService),a=(0,l.useDependency)(W),[o,s]=(0,p.useState)([`cellAddress`]),[u,d]=(0,p.useState)(!1),[f,h]=(0,p.useState)(null),g=(0,p.useMemo)(()=>a.getCellImagesInSelection(),[a]),_=(0,p.useMemo)(()=>a.getDataColumns(),[a]),v=(0,p.useMemo)(()=>a.getSelectionRowRange(),[a]),y=_.length>0,b=(0,p.useMemo)(()=>_.map(e=>({label:e.label,value:String(e.index)})),[_]),[x,S]=(0,p.useState)(()=>b.length>0?b[0].value:`0`),C=(0,p.useMemo)(()=>{if(!o.includes(`columnValue`)||!v)return[];let e=Number(x);return[{startRow:v.startRow,endRow:v.endRow,startColumn:e,endColumn:e}]},[o,x,v]);(0,c.useHighlightRange)(C);let w=(0,p.useCallback)(e=>{e.length!==0&&s(e)},[]),T=(0,p.useCallback)(e=>{S(String(e))},[]),E=(0,p.useCallback)(()=>{r.close(Z)},[r]),D=(0,p.useCallback)(async()=>{if(g.length!==0){d(!0),h(null);try{await a.saveImages(g,{fileNameParts:o,columnIndex:o.includes(`columnValue`)?Number(x):void 0}),r.close(Z)}catch(e){console.error(`Failed to save images:`,e),h(n.t(`sheets-drawing-ui.save.error`))}finally{d(!1)}}},[a,g,o,x,r,n]),O=o.includes(`columnValue`);return(0,m.jsxs)(`div`,{className:`univer-flex univer-flex-col`,children:[(0,m.jsx)(i.FormLayout,{label:n.t(`sheets-drawing-ui.save.imageCount`),children:(0,m.jsx)(`div`,{className:`univer-text-sm univer-text-gray-600`,children:g.length})}),(0,m.jsx)(i.FormLayout,{label:n.t(`sheets-drawing-ui.save.fileNameConfig`),children:(0,m.jsxs)(i.CheckboxGroup,{value:o,onChange:w,direction:`vertical`,children:[(0,m.jsx)(i.Checkbox,{value:`cellAddress`,disabled:!y,children:n.t(`sheets-drawing-ui.save.useRowCol`)}),y&&(0,m.jsx)(i.Checkbox,{value:`columnValue`,children:n.t(`sheets-drawing-ui.save.useColumnValue`)})]})}),O&&(0,m.jsx)(i.FormLayout,{label:n.t(`sheets-drawing-ui.save.selectColumn`),children:(0,m.jsx)(e,{value:x,options:b,onChange:T})}),f&&(0,m.jsx)(`div`,{className:`univer-text-xs univer-text-red-500`,children:f}),(0,m.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-2 univer-border-t univer-border-gray-200 univer-pt-3`,children:[(0,m.jsx)(i.Button,{onClick:E,disabled:u,children:n.t(`sheets-drawing-ui.save.cancel`)}),(0,m.jsx)(i.Button,{variant:`primary`,onClick:D,disabled:u||g.length===0,children:u?n.t(`sheets-drawing-ui.save.saving`):n.t(`sheets-drawing-ui.save.confirm`)})]})]})}function gt(){return(0,m.jsx)(ht,{SelectComponent:i.MobileSelect})}let _t=e=>{let a=(0,l.useDependency)(t.ICommandService),s=(0,l.useDependency)(t.LocaleService),c=(0,l.useDependency)(o.IDrawingManagerService),u=(0,l.useDependency)(r.IRenderManagerService),{drawings:d}=e,f=vt(d[0])?d[0]:void 0,h=f?u.getRenderUnitById(f.unitId):void 0,g=h==null?void 0:h.scene,_=g==null?void 0:g.getTransformerByCreate(),[v,y]=(0,p.useState)(!0),b=f?(0,n.getSheetDrawingPlacement)(f).kind:n.SheetDrawingAnchorType.Position,[x,S]=(0,p.useState)(b);function C(e,t){let n=[];return e.forEach(e=>{let{oKey:r}=e,i=t.getDrawingOKey(r);if(i==null||!vt(i))return n.push(null),!0;let{unitId:a,subUnitId:o,drawingId:s,drawingType:c,anchorType:l,sheetTransform:u,axisAlignSheetTransform:d}=i;n.push({unitId:a,subUnitId:o,drawingId:s,anchorType:l,sheetTransform:u,drawingType:c,axisAlignSheetTransform:d})}),n}if((0,p.useEffect)(()=>{if(!_)return;let e=_.clearControl$.subscribe(e=>{e===!0&&y(!1)}),t=_.changeStart$.subscribe(e=>{let{objects:t}=e,r=C(t,c);if(r.length===0)y(!1);else if(r.length>=1){y(!0);let e=r[0];S(e?(0,n.getSheetDrawingPlacement)(e).kind:n.SheetDrawingAnchorType.Position)}});return()=>{t.unsubscribe(),e.unsubscribe()}},[c,_]),!f||!_)return null;function w(e){let t=yt(e);if(!t)return;let r=c.getFocusDrawings();if(!r.length||!r.every(vt))return;let{unitId:i,subUnitId:o}=r[0],s=[];for(let e of r){let{transform:n}=e,{left:r,top:i,width:a,height:o}=n??{};if(typeof r!=`number`||typeof i!=`number`||typeof a!=`number`||typeof o!=`number`||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(a)||!Number.isFinite(o))return;s.push({drawingId:e.drawingId,placement:{kind:t,bounds:{left:r,top:i,width:a,height:o}}})}a.syncExecuteCommand(n.SetSheetDrawingPlacementCommand.id,{unitId:i,subUnitId:o,drawings:s})&&S(t)}return(0,m.jsxs)(`div`,{className:(0,i.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!v}),children:[(0,m.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,m.jsx)(`div`,{children:s.t(`sheets-drawing-ui.drawing-anchor.title`)})}),(0,m.jsx)(`div`,{children:(0,m.jsxs)(i.RadioGroup,{value:x,onChange:w,direction:`vertical`,children:[(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.Both,children:s.t(`sheets-drawing-ui.drawing-anchor.both`)}),(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.Position,children:s.t(`sheets-drawing-ui.drawing-anchor.position`)}),(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.None,children:s.t(`sheets-drawing-ui.drawing-anchor.none`)})]})})]})};function vt(e){return!!(e&&`sheetTransform`in e&&`axisAlignSheetTransform`in e)}function yt(e){return e===n.SheetDrawingAnchorType.Position||e===n.SheetDrawingAnchorType.Both||e===n.SheetDrawingAnchorType.None?e:null}let bt=()=>{let e=(0,l.useDependency)(o.IDrawingManagerService),t=(0,l.useObservable)(()=>e.focus$,e.getFocusDrawings(),!1,[e]);return!!(t!=null&&t.length)&&(0,m.jsxs)(`div`,{className:`univer-text-sm`,children:[(0,m.jsx)(u.DrawingCommonPanel,{drawings:t}),(0,m.jsx)(_t,{drawings:t})]})},xt=class extends t.Disposable{constructor(e){super(),this.disposeWithMe(e.register(ie,bt)),this.disposeWithMe(e.register(Z,gt))}};xt=L([I(0,(0,t.Inject)(l.ComponentManager))],xt);let St=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._context=e,this._hoverManagerService=t,this._selectionsService=n,this._drawingRenderService=r,this._sheetSkeletonManagerService=i,F(this,`_isSetCursor`,!1),this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe((0,d.throttleTime)(33)).subscribe(e=>{let t=[];if(e!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),(e==null?void 0:e.unitId)===this._context.unitId&&e!=null&&e.drawing&&t.length===1&&t[0].primary){let{row:n,col:i}=e,{actualRow:a,actualColumn:o,startRow:s,startColumn:c,endRow:l,endColumn:u,isMerged:d,isMergedMainCell:f}=t[0].primary;(d||f)&&n>=s&&n<=l&&i>=c&&i<=u||n===a&&i===o?(this._isSetCursor=!0,this._context.scene.setCursor(r.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}else this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(e=>{if(e!=null&&e.drawing&&this._isSetCursor){let t=e.drawing.drawing.drawingOrigin;this._previewImage(t)}}));let e=this._hoverManagerService.currentDbClickedCell$;e&&this.disposeWithMe(e.subscribe(({location:e})=>{var t,n,r;if(e.unitId!==this._context.unitId)return;let i=this._context.unit.getSheetBySheetId(e.subUnitId),a=i==null||(t=i.getCellRaw(e.row,e.col))==null?void 0:t.p,o=a==null||(n=a.drawingsOrder)==null?void 0:n[0],c=(0,s.isCellImage)(a)&&o?(r=a.drawings)==null?void 0:r[o]:void 0;c&&this._previewImage(c)}))}_previewImage(e){var t;if(this._disposed)return;let n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap,r=n==null?void 0:n.getImage(e.imageSourceType,e.source,()=>this._previewImage(e));r&&(this._drawingRenderService.previewImage(`preview-cell-image`,r.src,r.width,r.height),this._context.scene.resetCursor(),this._isSetCursor=!1)}};St=L([I(1,(0,t.Inject)(c.HoverManagerService)),I(2,(0,t.Inject)(s.SheetsSelectionsService)),I(3,(0,t.Inject)(u.DrawingRenderService)),I(4,(0,t.Inject)(c.SheetSkeletonManagerService))],St);let Ct=class extends t.Disposable{constructor(e,t,n,r){super(),this._context=e,this._sheetDrawingService=t,this._drawingManagerService=n,this._sheetSkeletonService=r,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);let e=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(let r in e){let i=e[r];for(let e in i.data){let r=i.data[e],{unitId:a,subUnitId:o}=r,s=this._sheetSkeletonService.getSkeletonParam(a,o);if(s&&r.sheetTransform&&!r.groupId&&r.anchorType!==n.SheetDrawingAnchorType.None){let e=(0,n.drawingPositionToTransform)(r.sheetTransform,s);r.transform=e&&r.drawingType===t.DrawingTypeEnum.DRAWING_GROUP?{...e,left:(e.left??0)-s.skeleton.rowHeaderWidthAndMarginLeft,top:(e.top??0)-s.skeleton.columnHeaderHeightAndMarginTop}:e}}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Ct=L([I(1,n.ISheetDrawingService),I(2,o.IDrawingManagerService),I(3,(0,t.Inject)(s.SheetSkeletonService))],Ct);var wt=class extends r.SheetExtension{constructor(e,n){super(),this._requestRender=n,F(this,`uKey`,`WorksheetBackgroundImageExtension`),F(this,`type`,r.SHEET_EXTENSION_TYPE.BACKGROUND),F(this,`_imageCache`,void 0),this._imageCache=new t.ImageCacheMap(e)}draw(e,t,n,r,i){let a=n.worksheet.getConfig().backgroundImage;if(!a)return;let o=this._imageCache.getImage(a.imageSourceType,a.source,this._requestRender,this._requestRender);if(!o||!o.complete||o.naturalWidth===0||o.getAttribute(`data-error`))return;let s=e.createPattern(o,`repeat`);if(!s)return;let c=a.scaleX??1,l=a.scaleY??1;(c!==1||l!==1)&&s.setTransform({a:c,d:l});let u=r.length>0?r:i.viewRanges,{columnWidthAccumulation:d,rowHeightAccumulation:f}=n;d&&f&&(e.save(),e.fillStyle=s,u.forEach(t=>{let n=t.startColumn>0?d[t.startColumn-1]:0,r=t.startRow>0?f[t.startRow-1]:0,i=d[t.endColumn],a=f[t.endRow];i!=null&&a!=null&&e.fillRect(n,r,i-n,a-r)}),e.restore())}};let Tt=class extends t.Disposable{constructor(e,t,r){super(),this._context=e;let i=this._context.mainComponent,a=new wt(r,()=>{i.makeForceDirty(!0),this._context.scene.makeDirty()});this.disposeWithMe(i.register(a)),this.disposeWithMe(t.onCommandExecuted(e=>{let t=e.params;e.id===n.SetWorksheetBackgroundImageMutation.id&&(t==null?void 0:t.unitId)===this._context.unitId&&(i.makeForceDirty(!0),this._context.scene.makeDirty())}))}};Tt=L([I(1,t.ICommandService),I(2,(0,t.Inject)(t.Injector))],Tt);function Et(e,t,n){var r,i;let a=n==null?void 0:n.p,o=(0,s.isCellImage)(a)&&(a==null||(r=a.drawingsOrder)==null?void 0:r.length)===1?a.drawingsOrder[0]:void 0,c=o?a==null||(i=a.drawings)==null?void 0:i[o]:void 0;if(c&&a){let n=R(e,{unitId:t.unitId,subUnitId:t.subUnitId,row:t.row,col:t.col},c.docTransform.size.width,c.docTransform.size.height,c.docTransform.angle);if(n)return c.transform.width=n.width,c.transform.height=n.height,c.docTransform.size.width=n.width,c.docTransform.size.height=n.height,c.transform.left=0,c.transform.top=0,c.docTransform.positionH.posOffset=0,c.docTransform.positionV.posOffset=0,a.documentStyle.pageSize.width=1/0,a.documentStyle.pageSize.height=1/0,!0}return!1}let Dt=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._injector=t,this._drawingManagerService=n,this._docDrawingController=r,this._editorBridgeService=i,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible?e.visible&&(this._drawingManagerService.removeDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(s.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,priority:s.InterceptCellContentPriority.CELL_IMAGE,handler:(e,t,n)=>(e&&(0,s.isCellImage)(e.p)&&(e===t.rawData&&(e={...t.rawData}),e.interceptorStyle||(e.interceptorStyle={}),e.interceptorStyle.tr={a:0},Et(this._injector,{unitId:t.unitId,subUnitId:t.subUnitId,row:t.row,col:t.col},e)),n(e))}))}};Dt=L([I(0,(0,t.Inject)(s.SheetInterceptorService)),I(1,(0,t.Inject)(t.Injector)),I(2,o.IDrawingManagerService),I(3,(0,t.Inject)(f.DocDrawingController)),I(4,(0,t.Inject)(c.IEditorBridgeService))],Dt);let Ot=class extends t.Disposable{constructor(e,t){super(),this._autoFillService=e,this._injector=t,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:`sheet-cell-image-autofill`,onBeforeSubmit:(e,n,r,i)=>{new t.ObjectMatrix(i).forValue((t,n,r)=>{Et(this._injector,{unitId:e.unitId,subUnitId:e.subUnitId,row:t,col:n},r)})}}))}};Ot=L([I(0,(0,t.Inject)(s.IAutoFillService)),I(1,(0,t.Inject)(t.Injector))],Ot);let kt=[t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],At=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._commandService=e,this._univerInstanceService=t,this._dialogService=n,this._renderManagerService=r,this._localeService=i,this._initDocImageCopyPasteHooks()}_setCellImage(e){var n;let i=(0,t.createDocumentModelWithStyle)(``,{}),a=(n=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(c.EditingRenderController),o=t.BuildTextUtils.drawing.add({documentDataModel:i,drawings:[e],selection:{collapsed:!0,startOffset:0,endOffset:0}});o&&(i.apply(o),a&&a.submitCellData(i))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===h.InnerPasteCommand.id){let{doc:r}=e.params,i=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(i==null||!Object.keys(r.drawings??{}).length)return;let a=i.getUnitId();if(kt.includes(a)){var n;let e=()=>{this._dialogService.close(`sheet-cell-image-copy-paste`),this._commandService.syncExecuteCommand(c.SetCellEditVisibleOperation.id,{visible:!1})};((n=i.getBody())==null?void 0:n.dataStream)===`\r
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require("@univerjs/core"),require("@univerjs/sheets-drawing"),require("@univerjs/engine-render"),require("@univerjs/design"),require("@univerjs/docs"),require("@univerjs/drawing"),require("@univerjs/sheets"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("@univerjs/drawing-ui"),require("rxjs"),require("@univerjs/docs-drawing"),require("react"),require("react/jsx-runtime"),require("@univerjs/docs-ui")):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/sheets-drawing`,`@univerjs/engine-render`,`@univerjs/design`,`@univerjs/docs`,`@univerjs/drawing`,`@univerjs/sheets`,`@univerjs/sheets-ui`,`@univerjs/ui`,`@univerjs/drawing-ui`,`rxjs`,`@univerjs/docs-drawing`,`react`,`react/jsx-runtime`,`@univerjs/docs-ui`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverSheetsDrawingUi={},e.UniverCore,e.UniverSheetsDrawing,e.UniverEngineRender,e.UniverDesign,e.UniverDocs,e.UniverDrawing,e.UniverSheets,e.UniverSheetsUi,e.UniverUi,e.UniverDrawingUi,e.rxjs,e.UniverDocsDrawing,e.React,e.React,e.UniverDocsUi))})(this,function(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let g={id:`sheet.command.delete-drawing`,type:t.CommandType.COMMAND,handler:e=>{let r=e.get(t.ICommandService),i=e.get(n.ISheetDrawingService).getFocusDrawings();if(i.length===0)return!1;let a=i[0].unitId,o=i.map(e=>{let{unitId:t,subUnitId:n,drawingId:r,drawingType:i}=e;return{unitId:t,subUnitId:n,drawingId:r,drawingType:i}});return r.executeCommand(n.RemoveSheetDrawingCommand.id,{unitId:a,drawings:o})}};function _(e){let n=[];return e.forEach(e=>{let{parent:i,children:a}=e,{unitId:o,subUnitId:s,drawingId:c}=i,l=(0,r.getGroupState)(0,0,a.map(e=>e.transform||{})),u=a.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t,left:t.left,top:t.top},groupId:c}}),d={unitId:o,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,groupBaseBound:{...i.groupBaseBound},transform:l};n.push({parent:d,children:u})}),n}function v(e){let n=[];return e.forEach(e=>{let{parent:i,children:a}=e,{unitId:o,subUnitId:s,drawingId:c,transform:l={width:0,height:0}}=i;if(l==null)return;let u=a.map(e=>{let{transform:t}=e,{unitId:n,subUnitId:a,drawingId:o}=e;return{unitId:n,subUnitId:a,drawingId:o,transform:(0,r.transformObjectOutOfGroup)(t||{},l,l.width||0,l.height||0,i.groupBaseBound),groupId:void 0}}),d={unitId:o,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:d,children:u})}),n}function y(e){var n;let r=new Map;(n=e.flatChildren)==null||n.forEach(e=>r.set(e.drawingId,(0,t.generateRandomId)(10))),e.groups.forEach(e=>r.set(e.drawingId,(0,t.generateRandomId)(10)));let i={};for(let[t,n]of Object.entries(e.nestedIdRecord)){var a;let e=r.get(t)??t;i[e]={drawingId:e,children:(a=n.children)==null?void 0:a.map(e=>r.get(e)??e)}}let o=[],s=[];for(let t of e.groups){let e=r.get(t.drawingId)??t.drawingId,n=t.groupId?r.get(t.groupId)??t.groupId:void 0;s.push(b(t,e,n))}for(let t of e.flatChildren||[]){let e=r.get(t.drawingId)??t.drawingId,n=t.groupId?r.get(t.groupId)??t.groupId:void 0;o.push(b(t,e,n))}return{cloned:{nestedIdRecord:i,flatChildren:o,groups:s},idMap:r}}function b(e,t,n){let r={...e};return t&&(r.drawingId=t),n?r.groupId=n:delete r.groupId,JSON.parse(JSON.stringify(r))}let x={id:`sheet.command.group-sheet-image`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(n.ISheetDrawingService);if(!r)return!1;let s=[];r.forEach(({parent:e,children:t})=>{s.push(e.unitId),t.forEach(e=>{s.push(e.unitId)})});let{unitId:c,subUnitId:l,undo:u,redo:d,objects:f}=o.getGroupDrawingOp(r);return i.syncExecuteCommand(n.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.GROUP})?(a.pushUndoRedo({unitID:c,undoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:v(f),type:n.DrawingApplyType.UNGROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}],redoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.GROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}]}),!0):!1}},S={id:`sheet.command.ungroup-sheet-image`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),o=e.get(n.ISheetDrawingService);if(!r)return!1;let s=[];r.forEach(({parent:e,children:t})=>{s.push(e.unitId),t.forEach(e=>{s.push(e.unitId)})});let{unitId:c,subUnitId:l,undo:u,redo:d,objects:f}=o.getUngroupDrawingOp(r);return i.syncExecuteCommand(n.SetDrawingApplyMutation.id,{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.UNGROUP})?(a.pushUndoRedo({unitID:c,undoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:u,unitId:c,subUnitId:l,objects:_(f),type:n.DrawingApplyType.GROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}],redoMutations:[{id:n.SetDrawingApplyMutation.id,params:{op:d,unitId:c,subUnitId:l,objects:f,type:n.DrawingApplyType.UNGROUP}},{id:n.ClearSheetDrawingTransformerOperation.id,params:s}]}),!0):!1}},C=.0254;function w(e){let t=T(e);if(!t)return;let n=E(t);if(!n)return;let r=96/(n.x*C),i=96/(n.y*C);if(Number.isFinite(r)&&Number.isFinite(i)&&!(Math.abs(r-1)<=.001&&Math.abs(i-1)<=.001))return{scaleX:r,scaleY:i}}function T(e){let t=e.indexOf(`,`);if(!(t<0||!e.slice(0,t).toLowerCase().includes(`;base64`)))try{let n=globalThis.atob(e.slice(t+1)),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return r}catch{return}}function E(e){return D(e)??O(e)}function D(e){if(!k(e,0,[137,80,78,71,13,10,26,10]))return;let t=8;for(;t+12<=e.length;){let n=j(e,t),r=t+4,i=t+8,a=i+n,o=a+4;if(o>e.length)return;if(k(e,r,[112,72,89,115])){if(n!==9||e[a-1]!==1)return;let t=j(e,i),r=j(e,i+4);return t>0&&r>0?{x:t,y:r}:void 0}t=o}}function O(e){if(!k(e,0,[255,216]))return;let t=2;for(;t+4<=e.length;){if(e[t]!==255){t++;continue}for(;t<e.length&&e[t]===255;)t++;let n=e[t++];if(n==null)return;if(n===216||n===217||n===1||n>=208&&n<=215)continue;let r=A(e,t);if(r<2)return;let i=t+2,a=t+r;if(a>e.length)return;if(n===224&&r>=14&&k(e,i,[74,70,73,70,0])){let t=e[i+7],n=A(e,i+8),r=A(e,i+10);return!n||!r?void 0:t===1?{x:Math.round(n/C),y:Math.round(r/C)}:t===2?{x:n*100,y:r*100}:void 0}t=a}}function k(e,t,n){return n.every((n,r)=>e[t+r]===n)}function A(e,t){return(e[t]??0)<<8|(e[t+1]??0)}function j(e,t){return((e[t]??0)<<24>>>0|(e[t+1]??0)<<16|(e[t+2]??0)<<8|(e[t+3]??0))>>>0}function M(e){"@babel/helpers - typeof";return M=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},M(e)}function N(e,t){if(M(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(M(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function P(e){var t=N(e,`string`);return M(t)==`symbol`?t:t+``}function F(e,t,n){return(t=P(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function I(e,t){return function(n,r){t(n,r,e)}}function L(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function ee(e,t,n){let r=n*Math.PI/180;return{rotatedWidth:Math.abs(e*Math.cos(r))+Math.abs(t*Math.sin(r)),rotatedHeight:Math.abs(e*Math.sin(r))+Math.abs(t*Math.cos(r))}}function R(e,t,n,i,a){var o;let{rotatedHeight:s,rotatedWidth:l}=ee(n,i,a),u=e.get(r.IRenderManagerService).getRenderUnitById(t.unitId);if(!u)return!1;let d=(o=u.with(c.SheetSkeletonManagerService).getSkeletonParam(t.subUnitId))==null?void 0:o.skeleton;if(d==null)return!1;let f=d.getCellWithCoordByIndex(t.row,t.col),p=f.mergeInfo.endX-f.mergeInfo.startX-2,m=f.mergeInfo.endY-f.mergeInfo.startY-2,h=l/s,g=Math.ceil(Math.min(p,m*h))/l,_=!g||Number.isNaN(g)?.001:g;return{width:n*_,height:i*_}}let z=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m){super(),this._context=e,this._commandService=t,this._sheetInterceptorService=n,this._selectionRenderService=r,this._imageIoService=i,this._fileOpenerService=a,this._sheetDrawingService=o,this._drawingManagerService=s,this._contextService=c,this._messageService=l,this._localeService=u,this._sheetSkeletonService=f,this._injector=p,this._urlImageService=m,F(this,`_workbookSelections`,void 0),this._workbookSelections=d.getWorkbookSelections(this._context.unitId),this._updateDrawingListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){let e=await this._fileOpenerService.openFile({multiple:!0,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}),t=e.length;return t>o.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxCount`,String(o.DRAWING_IMAGE_COUNT_LIMIT))}),!1):t!==0&&(e.forEach(async e=>await this.insertFloatImageByFile(e)),!0)}async insertCellImage(){let e=(await this._fileOpenerService.openFile({multiple:!1,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}))[0];return e?(await this._insertCellImage(e),!0):!1}async setWorksheetBackgroundImage(e){let r=(e??await this._fileOpenerService.openFile({multiple:!1,accept:o.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace(`image/`,``)}`).join(`,`)}))[0];if(!r)return!1;let a;try{a=await this._imageIoService.saveImage(r)}catch(e){let n=e.message;return n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/1048576))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)}),!1}if(!a)return!1;let{unitId:s,subUnitId:c}=this._getUnitInfo(),l=w(a.base64Cache||a.source);return this._commandService.executeCommand(n.SetWorksheetBackgroundImageCommand.id,{unitId:s,subUnitId:c,backgroundImage:{source:a.source,imageSourceType:a.imageSourceType,...l}})}insertCellImageByFile(e,t){return this._insertCellImage(e,t)}async insertFloatImageByFile(e){let r;try{r=await this._imageIoService.saveImage(e)}catch(e){let n=e.message;n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/1048576))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)})}if(r==null)return;let{unitId:a,subUnitId:s}=this._getUnitInfo(),{imageId:c,imageSourceType:l,source:u,base64Cache:d}=r,{width:f,height:p,image:m}=await(0,o.getImageSize)(d||``),{width:h,height:g}=this._context.scene;this._imageIoService.addImageSourceCache(u,l,m);let _=1;if(f>o.DRAWING_IMAGE_WIDTH_LIMIT||p>o.DRAWING_IMAGE_HEIGHT_LIMIT){let e=o.DRAWING_IMAGE_WIDTH_LIMIT/f,t=o.DRAWING_IMAGE_HEIGHT_LIMIT/p;_=Math.max(e,t)}let v=this._sheetSkeletonService.getSkeletonParam(a,s);if(!v)return;let{skeleton:y}=v,b=this._getImagePosition(f*_,p*_,h,g,y);if(!b)return;let x=(0,n.drawingPositionToTransform)(b,v);if(!x)return;let S={unitId:a,subUnitId:s,drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:u,transform:x,sheetTransform:b,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(x,y)??b};return this._commandService.executeCommand(n.InsertSheetDrawingCommand.id,{unitId:a,drawings:[S]})}async _insertCellImage(e,n){let r;try{r=await this._imageIoService.saveImage(e)}catch(e){let n=e.message;n===t.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.exceedMaxSize`,String((0,o.getDrawingImageAllowSize)()/1048576))}):n===t.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImageType`)}):n===t.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:i.MessageType.Error,content:this._localeService.t(`sheets-drawing-ui.update-status.invalidImage`)})}if(r==null)return!1;let{imageId:c,imageSourceType:l,source:u,base64Cache:d}=r,{width:f,height:p,image:m}=await(0,o.getImageSize)(d||``);this._imageIoService.addImageSourceCache(u,l,m);let h=this._workbookSelections.getCurrentLastSelection();if(!h)return!1;let g=h.primary.actualRow,_=h.primary.actualColumn;h.primary.isMerged&&(g=h.primary.startRow,_=h.primary.startColumn);let v=(0,t.createDocumentModelWithStyle)(``,{}),y=R(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:g,col:_},f,p,0);if(!y)return!1;let b=(0,a.buildDocTransform)(y.width,y.height),x={unitId:v.getUnitId(),subUnitId:v.getUnitId(),drawingId:c,drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:l,source:u,transform:(0,a.docDrawingPositionToTransform)(b),docTransform:b,behindDoc:t.BooleanNumber.FALSE,title:``,description:``,layoutType:t.PositionedObjectLayoutType.INLINE,wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=t.BuildTextUtils.drawing.add({documentDataModel:v,drawings:[x],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(v.apply(S),this._commandService.syncExecuteCommand(s.SetRangeValuesCommand.id,{value:{[(n==null?void 0:n.row)??g]:{[(n==null?void 0:n.col)??_]:{p:v.getSnapshot(),t:1}}},unitId:n==null?void 0:n.unitId,subUnitId:n==null?void 0:n.subUnitId})):!1}async insertCellImageByUrl(e,n){let r=e;try{r=await this._urlImageService.getImage(e)}catch(t){console.error(`Failed to get image from URLImageService: ${e}`,t)}let{width:i,height:c,image:l}=await(0,o.getImageSize)(r||``);this._imageIoService.addImageSourceCache(e,t.ImageSourceType.URL,l);let u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;let d=(0,t.createDocumentModelWithStyle)(``,{}),f=R(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},i,c,0);if(!f)return!1;let p=(0,a.buildDocTransform)(f.width,f.height),m={unitId:d.getUnitId(),subUnitId:d.getUnitId(),drawingId:(0,t.generateRandomId)(),drawingType:t.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t.ImageSourceType.URL,source:e,transform:(0,a.docDrawingPositionToTransform)(p),docTransform:p,behindDoc:t.BooleanNumber.FALSE,title:``,description:``,layoutType:t.PositionedObjectLayoutType.INLINE,wrapText:t.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},h=t.BuildTextUtils.drawing.add({documentDataModel:d,drawings:[m],selection:{collapsed:!0,startOffset:0,endOffset:0}});return h?(d.apply(h),this._commandService.syncExecuteCommand(s.SetRangeValuesCommand.id,{value:{[(n==null?void 0:n.row)??u.primary.actualRow]:{[(n==null?void 0:n.col)??u.primary.actualColumn]:{p:d.getSnapshot(),t:1}}},unitId:n==null?void 0:n.unitId,subUnitId:n==null?void 0:n.subUnitId})):!1}_getUnitInfo(){let e=this._context.unit,t=e.getActiveSheet();return{unitId:e.getUnitId(),subUnitId:t.getSheetId()}}_getImagePosition(e,t,n,r,i){let a=this._workbookSelections.getCurrentSelections(),o={startRow:0,endRow:0,startColumn:0,endColumn:0};a&&a.length>0&&(o=a[a.length-1].range);let c=(0,s.attachRangeWithCoord)(i,o);if(c==null)return;let{startColumn:l,startRow:u,startX:d,startY:f}=c,p=!1;if(d+e>n&&(d=n-e,d<0&&(d=0,e=n),p=!0),f+t>r&&(f=r-t,f<0&&(f=0,t=r),p=!0),p){let e=this._selectionRenderService.getCellWithCoordByOffset(d,f);if(e==null)return;d=e.startX,f=e.startY,l=e.actualColumn,u=e.actualRow}let m={column:l,columnOffset:0,row:u,rowOffset:0},h=this._selectionRenderService.getCellWithCoordByOffset(d+e,f+t);if(h!=null)return{from:m,to:{column:h.actualColumn,columnOffset:d+e-h.startX,row:h.actualRow,rowOffset:f+t-h.startY}}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(e=>{let{unitId:t,subUnitId:r,drawingIds:i,arrangeType:a}=e;this._commandService.executeCommand(n.SetDrawingArrangeCommand.id,{unitId:t,subUnitId:r,drawingIds:i,arrangeType:a})}))}_updateDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(e=>{let t=[];e.length!==0&&(e.forEach(e=>{let{unitId:r,subUnitId:i,drawingId:a,transform:o}=e,s=this._sheetSkeletonService.getSkeletonParam(r,i);if(!o||!s)return;let{skeleton:c}=s,l=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:a});if(l==null||l.unitId!==this._context.unitId)return;let u=(0,n.transformToDrawingPosition)({...l.transform,...o},c),d=(0,n.transformToAxisAlignPosition)({...l.transform,...o},c);if(u==null||d==null)return;let f={...e,transform:{...l.transform,...o,...(0,n.drawingPositionToTransform)(u,s)},sheetTransform:{...u},axisAlignSheetTransform:{...d}};t.push(f)}),t.length>0&&this._commandService.executeCommand(n.SetSheetDrawingCommand.id,{unitId:e[0].unitId,drawings:t}))}))}_getSheetTransformByParam(e,t){let{unitId:r,subUnitId:i,drawingId:a,transform:o}=e,s=this._sheetSkeletonService.getSkeleton(r,i);if(!o||!s)return null;let c=this._sheetDrawingService.getDrawingByParam({unitId:r,subUnitId:i,drawingId:a}),l=c==null?void 0:c.transform;if(t&&(l={}),!t&&(!c||c.unitId!==this._context.unitId))return null;let u=(0,n.transformToDrawingPosition)({...l,...o},s),d=(0,n.transformToAxisAlignPosition)({...l,...o},s);return!u||!d?null:{sheetTransform:u,axisAlignSheetTransform:d}}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(e=>{let t=[];for(let n of e){let e=n.parent,r=this._getSheetTransformByParam(e,!0),i=[];for(let e of n.children){let t=this._getSheetTransformByParam(e,!1);t!=null&&i.push({...e,sheetTransform:t.sheetTransform,axisAlignSheetTransform:t.axisAlignSheetTransform})}let a={parent:{...e,sheetTransform:r==null?void 0:r.sheetTransform,axisAlignSheetTransform:r==null?void 0:r.axisAlignSheetTransform},children:i};t.push(a)}if(t.length>0){this._commandService.executeCommand(x.id,t);let{unitId:n,subUnitId:r,drawingId:i}=e[0].parent;this._commandService.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:r,drawingId:i}])}})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(e=>{let t=[];for(let n of e){let{children:e}=n,r=[];for(let t of e){let e=this._getSheetTransformByParam(t,!1);e!=null&&r.push({...t,sheetTransform:e.sheetTransform,axisAlignSheetTransform:e.axisAlignSheetTransform})}t.push({...n,children:r})}this._commandService.executeCommand(S.id,t)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{e==null||e.length===0?(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(e))}))}};z=L([I(1,t.ICommandService),I(2,(0,t.Inject)(s.SheetInterceptorService)),I(3,c.ISheetSelectionRenderService),I(4,t.IImageIoService),I(5,l.ILocalFileService),I(6,n.ISheetDrawingService),I(7,o.IDrawingManagerService),I(8,t.IContextService),I(9,l.IMessageService),I(10,(0,t.Inject)(t.LocaleService)),I(11,(0,t.Inject)(s.SheetsSelectionsService)),I(12,(0,t.Inject)(s.SheetSkeletonService)),I(13,(0,t.Inject)(t.Injector)),I(14,t.IURLImageService)],z);let B={id:`sheet.command.insert-float-image`,type:t.CommandType.COMMAND,handler:async(e,n)=>{var i;let a=e.get(t.IUniverInstanceService),o=e.get(r.IRenderManagerService),s=(i=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,a,o))==null?void 0:i.with(z);if(!s)return!1;let c=n==null?void 0:n.files;if(c){let e=c.map(e=>s.insertFloatImageByFile(e));return(await Promise.all(e)).every(e=>e)}return s.insertFloatImage()??!1}},V={id:`sheet.command.insert-cell-image`,type:t.CommandType.COMMAND,handler:e=>{var n;let i=e.get(t.IUniverInstanceService),a=e.get(r.IRenderManagerService);return((n=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,i,a))==null?void 0:n.with(z).insertCellImage())??!1}},H={id:`sheet.command.move-drawing`,type:t.CommandType.COMMAND,handler:(e,r)=>{let i=e.get(t.ICommandService),a=e.get(n.ISheetDrawingService),o=e.get(s.SheetSkeletonService),c=e.get(l.UndoRedoGroupService),{direction:u}=r,d=a.getFocusDrawings();if(d.length===0)return!1;let f=d[0].unitId,p=d.map(e=>{let{transform:r,unitId:i,subUnitId:a}=e,s=o.getSkeleton(i,a);if(!r||!s)return null;let c={...r},{left:l=0,top:d=0}=r;return u===t.Direction.UP?c.top=d-1:u===t.Direction.DOWN?c.top=d+1:u===t.Direction.LEFT?c.left=l-1:u===t.Direction.RIGHT&&(c.left=l+1),{...e,transform:c,sheetTransform:(0,n.transformToDrawingPosition)(c,s),axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(c,s)}}).filter(e=>e!=null);return c.runTimed(f,`sheet-drawing:nudge:${d[0].subUnitId}:${d.map(e=>e.drawingId).sort().join(`,`)}`,()=>i.syncExecuteCommand(n.SetSheetDrawingCommand.id,{unitId:f,drawings:p}))?(i.syncExecuteCommand(n.ClearSheetDrawingTransformerOperation.id,[f]),!0):!1}},U=function(e){return e.CELL_ADDRESS=`cellAddress`,e.COLUMN_VALUE=`columnValue`,e}({}),W=(0,t.createIdentifier)(`sheets-drawing-ui.batch-save-images.service`);function G(e){let t=``,n=e;for(;n>=0;)t=String.fromCharCode(n%26+65)+t,n=Math.floor(n/26)-1;return t}function K(e,t){return`${G(t)}${e+1}`}function q(e){let t=K(e.startRow,e.startColumn),n=K(e.endRow,e.endColumn);return t===n?t:`${t}:${n}`}function J(e){var t;let n=e.p,r=n==null||(t=n.drawingsOrder)==null?void 0:t[0];if(!(0,s.isCellImage)(n)||!r||!(n!=null&&n.drawings))return null;let i=n.drawings[r];return!i||!(`source`in i)||!(`imageSourceType`in i)?null:i}function Y(e,n){if(n===t.ImageSourceType.BASE64){let t=e.match(/^data:image\/(\w+);/);if(t)return t[1]===`jpeg`?`jpg`:t[1]}if(n===t.ImageSourceType.URL){let t=e.match(/\.(\w+)(?:\?|$)/);if(t)return t[1].toLowerCase()}return`png`}async function te(e,n){if(n===t.ImageSourceType.BASE64||n===t.ImageSourceType.URL)return(await fetch(e)).blob();throw Error(`UUID image type requires additional handling`)}let X=class extends t.Disposable{constructor(e,t,n,r){super(),this._univerInstanceService=e,this._selectionService=t,this._imageIoService=n,this._urlImageService=r}getCellImagesInSelection(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return[];let n=e.getActiveSheet();if(!n)return[];let r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return[];let i=n.getCellMatrix(),a=[];for(let e of r){let{startRow:t,endRow:n,startColumn:r,endColumn:o}=e.range;for(let e=t;e<=n;e++)for(let t=r;t<=o;t++){let n=i.getValue(e,t);if((0,s.isCellImage)(n==null?void 0:n.p)){let r=J(n);r&&a.push({row:e,col:t,cellAddress:K(e,t),source:r.source,imageSourceType:r.imageSourceType,imageId:r.drawingId})}}}return a}getCellImagesFromRanges(e,n,r){let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)return[];let a=i.getSheetBySheetId(n);if(!a)return[];let o=a.getCellMatrix(),c=[];for(let e of r){let{startRow:t,endRow:n,startColumn:r,endColumn:i}=e;for(let e=t;e<=n;e++)for(let t=r;t<=i;t++){let n=o.getValue(e,t);if((0,s.isCellImage)(n==null?void 0:n.p)){let r=J(n);r&&c.push({row:e,col:t,cellAddress:K(e,t),source:r.source,imageSourceType:r.imageSourceType,imageId:r.drawingId})}}}return c}getDataColumns(){let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return[];let n=e.getActiveSheet();if(!n)return[];let r=this._selectionService.getCurrentSelections();if(!r||r.length===0)return[];let i=n.getCellMatrix(),a=i.getDataRange(),o=1/0,s=-1/0,c=new Set;for(let e of r){o=Math.min(o,e.range.startRow),s=Math.max(s,e.range.endRow);for(let t=e.range.startColumn;t<=e.range.endColumn;t++)c.add(t)}let l=new Set;for(let e=a.startColumn;e<=a.endColumn;e++)if(!c.has(e))for(let t=o;t<=s;t++){let n=i.getValue(t,e);if(n){var u,d;if((u=n.v)!=null&&u.toString()||(d=n.p)!=null&&(d=d.body)!=null&&(d=d.dataStream)!=null&&d.trim()){l.add(e);break}}}let f=[],p=Array.from(l).sort((e,t)=>e-t);for(let e of p)f.push({index:e,label:G(e)});return f}getDataColumnsForRanges(e,n,r){let i=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!i)return[];let a=i.getSheetBySheetId(n);if(!a)return[];let o=a.getCellMatrix(),s=o.getDataRange(),c=1/0,l=-1/0,u=new Set;for(let e of r){c=Math.min(c,e.startRow),l=Math.max(l,e.endRow);for(let t=e.startColumn;t<=e.endColumn;t++)u.add(t)}let d=new Set;for(let e=s.startColumn;e<=s.endColumn;e++)if(!u.has(e))for(let t=c;t<=l;t++){let n=o.getValue(t,e);if(n){var f,p;if((f=n.v)!=null&&f.toString()||(p=n.p)!=null&&(p=p.body)!=null&&(p=p.dataStream)!=null&&p.trim()){d.add(e);break}}}let m=[],h=Array.from(d).sort((e,t)=>e-t);for(let e of h)m.push({index:e,label:G(e)});return m}getSelectionRangeNotation(){let e=this._selectionService.getCurrentSelections();return!e||e.length===0?``:e.map(e=>q(e.range)).join(`, `)}getSelectionRowRange(){let e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return null;let t=1/0,n=-1/0;for(let r of e)t=Math.min(t,r.range.startRow),n=Math.max(n,r.range.endRow);return{startRow:t,endRow:n}}getSelectionColumnIndices(){let e=this._selectionService.getCurrentSelections();if(!e||e.length===0)return new Set;let t=new Set;for(let n of e)for(let e=n.range.startColumn;e<=n.range.endColumn;e++)t.add(e);return t}generateFileName(e,n){let r=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),i=Y(e.source,e.imageSourceType),a=[];for(let t of n.fileNameParts)if(t===`cellAddress`)a.push(e.cellAddress);else if(t===`columnValue`&&n.columnIndex!==void 0){let t=r==null?void 0:r.getActiveSheet();if(t){let r=t.getCellMatrix().getValue(e.row,n.columnIndex);if(r){var o,s;let e=((o=r.v)==null?void 0:o.toString())||((s=r.p)==null||(s=s.body)==null||(s=s.dataStream)==null?void 0:s.trim())||``;if(e){let t=e.replace(/[<>:"/\\|?*]/g,`_`).trim();t&&a.push(t)}}}}return a.length===0?`${e.cellAddress}.${i}`:`${a.join(`_`)}.${i}`}generateFileNameWithContext(e,n,r,i){let a=this._univerInstanceService.getUnit(r,t.UniverInstanceType.UNIVER_SHEET),o=Y(e.source,e.imageSourceType),s=[];for(let t of n.fileNameParts)if(t===`cellAddress`)s.push(e.cellAddress);else if(t===`columnValue`&&n.columnIndex!==void 0){let t=a==null?void 0:a.getSheetBySheetId(i);if(t){let r=t.getCellMatrix().getValue(e.row,n.columnIndex);if(r){var c,l;let e=((c=r.v)==null?void 0:c.toString())||((l=r.p)==null||(l=l.body)==null||(l=l.dataStream)==null?void 0:l.trim())||``;if(e){let t=e.replace(/[<>:"/\\|?*]/g,`_`).trim();t&&s.push(t)}}}}return s.length===0?`${e.cellAddress}.${o}`:`${s.join(`_`)}.${o}`}async saveImages(e,t){let n=await window.showDirectoryPicker({mode:`readwrite`}),r=new Map;for(let a of e){var i;let e=this.generateFileName(a,t),o=e.replace(/\.\w+$/,``),s=((i=e.match(/\.\w+$/))==null?void 0:i[0])||`.png`,c=r.get(o)||0;c>0&&(e=`${o}_${c}${s}`),r.set(o,c+1);try{let t=await this._getImageBlob(a),r=await(await n.getFileHandle(e,{create:!0})).createWritable();await r.write(t),await r.close()}catch(t){throw console.error(`Failed to save image ${e}:`,t),t}}}async saveImagesWithContext(e,t,n,r){let i=await window.showDirectoryPicker({mode:`readwrite`}),a=new Map;for(let s of e){var o;let e=this.generateFileNameWithContext(s,t,n,r),c=e.replace(/\.\w+$/,``),l=((o=e.match(/\.\w+$/))==null?void 0:o[0])||`.png`,u=a.get(c)||0;u>0&&(e=`${c}_${u}${l}`),a.set(c,u+1);try{let t=await this._getImageBlob(s),n=await(await i.getFileHandle(e,{create:!0})).createWritable();await n.write(t),await n.close()}catch(t){throw console.error(`Failed to save image ${e}:`,t),t}}}async downloadSingleImage(e){let t=Y(e.source,e.imageSourceType),n=`${e.cellAddress}.${t}`;try{let t=await this._getImageBlob(e),r=URL.createObjectURL(t),i=document.createElement(`a`);i.href=r,i.download=n,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}catch(e){throw console.error(`Failed to download image ${n}:`,e),e}}async _getImageBlob(e){return e.imageSourceType===t.ImageSourceType.UUID?te(await this._imageIoService.getImage(e.source),t.ImageSourceType.URL):e.imageSourceType===t.ImageSourceType.URL?this._urlImageService.downloadImage(e.source):te(e.source,e.imageSourceType)}};X=L([I(0,t.IUniverInstanceService),I(1,(0,t.Inject)(s.SheetsSelectionsService)),I(2,t.IImageIoService),I(3,t.IURLImageService)],X);let Z=`sheet.dialog.batch-save-images`,Q={id:`sheet.command.save-cell-images`,type:t.CommandType.COMMAND,handler:async e=>{let n=e.get(l.IDialogService),r=e.get(W),i=r.getCellImagesInSelection();if(i.length===1)try{return await r.downloadSingleImage(i[0]),!0}catch(e){return console.error(`Failed to download image:`,e),!1}let a=e.get(t.LocaleService),o=r.getSelectionRangeNotation(),s=`${a.t(`sheets-drawing-ui.save.title`)} (${o})`;return n.open({id:Z,draggable:!0,width:360,title:{title:s},children:{label:Z},preservePositionOnDestroy:!0,onClose:()=>n.close(Z)}),!0}},ne={id:`sheet.command.add-worksheet-background-image`,type:t.CommandType.COMMAND,handler:(e,n)=>{var i;let a=e.get(t.IUniverInstanceService),o=e.get(r.IRenderManagerService);return((i=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,a,o))==null?void 0:i.with(z).setWorksheetBackgroundImage(n==null?void 0:n.files))??!1}},re={id:`sheet.command.delete-worksheet-background-image`,type:t.CommandType.COMMAND,handler:e=>e.get(t.ICommandService).executeCommand(n.SetWorksheetBackgroundImageCommand.id,{backgroundImage:null})},ie=`COMPONENT_SHEET_DRAWING_PANEL`,ae={id:`sidebar.operation.sheet-image`,type:t.CommandType.COMMAND,handler:async(e,n)=>{let r=e.get(l.ISidebarService),i=e.get(t.LocaleService),a=e.get(t.IUniverInstanceService),c=e.get(o.IDrawingManagerService),u=e.get(t.ICommandService);if(!(0,s.getSheetCommandTarget)(a))return!1;switch(n.value){case`open`:r.open({id:ie,header:{title:i.t(`sheets-drawing-ui.panel.title`)},children:{label:ie},onClose:()=>{let e=c.getFocusDrawings();e.length===1&&e[0].drawingType===t.DrawingTypeEnum.DRAWING_IMAGE&&u.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[])},width:360});break;default:r.close(ie)}return!0}},oe={id:`sheet.operation.edit-sheet-image`,type:t.CommandType.OPERATION,handler:(e,n)=>{let r=e.get(t.ICommandService);return n!=null&&(r.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[n]),r.executeCommand(ae.id,{value:`open`}),!0)}},se=[c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA],ce=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetClipboardService=e,this._renderManagerService=t,this._sheetSkeletonService=n,this._sheetDrawingService=r,this._drawingManagerService=i,F(this,`_featurePasteHooks`,[]),F(this,`_copyInfo`,void 0),this._initCopyPaste()}get _focusedDrawings(){return this._sheetDrawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:`SHEET_DRAWING_GROUP`,onBeforeCopyFocusedObject:(e,n)=>{this._copyInfo=null;let r=this._focusedDrawings;if(r.length===0)return!1;let i=r.find(e=>e.drawingType===t.DrawingTypeEnum.DRAWING_GROUP);if(!i)return!1;let a=this._drawingManagerService.getDrawingsByGroupNested({unitId:i.unitId,subUnitId:i.subUnitId,drawingId:i.drawingId});return a?(this._copyInfo={unitId:i.unitId,subUnitId:i.subUnitId,groupNestedParam:a},!0):!1},onPasteCells:(e,t,n,r)=>{if(!r.copyId||!e||!this._copyInfo)return{redos:[],undos:[]};let{pasteType:i}=r;return se.includes(i)?{redos:[],undos:[]}:this._generateGroupPasteMutations(t)}})}registerFeaturePasteHook(e,n){let r={hook:e,beforeDrawing:(n==null?void 0:n.beforeDrawing)===!0};return this._featurePasteHooks.push(r),(0,t.toDisposable)(()=>{let e=this._featurePasteHooks.indexOf(r);e>=0&&this._featurePasteHooks.splice(e,1)})}_getGroupFeaturePasteMutations(e,t){let n=[],r=[],i=!1;for(let a of this._featurePasteHooks){if(a.beforeDrawing!==t)continue;let o=a.hook(e);n.push(...o.redos),r.push(...o.undos),i||=o.cancel===!0}return{redos:n,undos:r,cancel:i}}_generateGroupPasteMutations(e){if(!this._copyInfo)return{redos:[],undos:[]};let{unitId:t,subUnitId:r,range:i}=e,a=this._sheetSkeletonService.getSkeleton(t,r);if(!a)return{redos:[],undos:[]};let{groupNestedParam:o}=this._copyInfo,c=o.groups[o.groups.length-1],{cloned:l,idMap:u}=y(o),d=l.groups[l.groups.length-1].drawingId,f={fromUnitId:this._copyInfo.unitId,fromSubUnitId:this._copyInfo.subUnitId,toUnitId:t,toSubUnitId:r,idMap:u,cloned:l},p=this._getGroupFeaturePasteMutations(f,!0);if(p.cancel)return{redos:[],undos:[]};let m=(0,s.discreteRangeToRange)(i),h=(0,s.attachRangeWithCoord)(a,{startRow:m.startRow,endRow:m.endRow,startColumn:m.startColumn,endColumn:m.endColumn});if(!h)return{redos:[],undos:[]};let g={...c.transform,left:h.startX,top:h.startY},_=[...(l.flatChildren??[]).map(e=>({...e,unitId:t,subUnitId:r})),...l.groups.map(e=>e.drawingId===d?{...e,unitId:t,subUnitId:r,transform:g,sheetTransform:(0,n.transformToDrawingPosition)(g,a)??c.sheetTransform,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(g,a)??c.sheetTransform}:{...e,unitId:t,subUnitId:r})],{undo:v,redo:b,objects:x}=this._sheetDrawingService.getBatchAddOp(_),S=this._getGroupFeaturePasteMutations(f,!1);if(S.cancel)return{redos:[],undos:[]};let C={id:n.SetDrawingApplyMutation.id,params:{op:b,unitId:t,subUnitId:r,objects:x,type:n.DrawingApplyType.INSERT}},w={id:n.SetDrawingApplyMutation.id,params:{op:v,unitId:t,subUnitId:r,objects:x,type:n.DrawingApplyType.REMOVE}};return{redos:[...p.redos,C,...S.redos],undos:[w,...p.undos,...S.undos]}}dispose(){this._copyInfo=null,this._featurePasteHooks.length=0,super.dispose()}};ce=L([I(0,c.ISheetClipboardService),I(1,r.IRenderManagerService),I(2,(0,t.Inject)(s.SheetSkeletonService)),I(3,n.ISheetDrawingService),I(4,o.IDrawingManagerService)],ce);let le=Object.freeze({borderEnabled:!1,paintFirst:`stroke`,radius:8,rotateEnabled:!1,strokeWidth:1});var ue;let de=`univer-sheet-float-dom-`;function fe(e,t,n){let r=new WeakRef(e),i=!1;return{id:t,dispose(){if(i)return;i=!0;let e=r.deref();e&&n(e,t)}}}let pe={...r.DEFAULT_TRANSFORMER_CONFIG,rotateEnabled:!1,moveBoundaryEnabled:!1},me={...r.DEFAULT_TRANSFORMER_CONFIG,rotateEnabled:!1,keepRatio:!1,moveBoundaryEnabled:!1},he=-100,ge=`univer:embed-float-drag-handle:pointerdown`;function _e(e,t){return t.hostAnchorId===e.id&&(t.hostUnitId==null||t.hostUnitId===e.unitId)&&(t.button==null||t.button===0)&&typeof t.clientX==`number`&&typeof t.clientY==`number`}function ve(e,t){if(typeof t.clientX==`number`&&typeof t.clientY==`number`)return{pointerId:t.pointerId,startClientX:t.clientX,startClientY:t.clientY,startLeft:Number(e.rect.left??0),startTop:Number(e.rect.top??0)}}function ye(e,t,n){let{scaleX:r,scaleY:i}=n.getAncestorScale();return{left:e.startLeft+(t.clientX-e.startClientX)/(r||1),top:e.startTop+(t.clientY-e.startClientY)/(i||1)}}function be(e,t){let n=t.data;if(!n||typeof n!=`object`)return;let r=n;r.version===1&&typeof r.embedId==`string`&&(e.transformerConfig={...pe,keepRatio:r.resizeBehavior===`aspect-ratio`})}function xe(e){e.transformerConfig={...e.transformerConfig,...me}}function Se(e){if(!Ce(e))return!1;let n=e.data;return n.hostType===t.UniverInstanceType.UNIVER_SHEET&&n.childType===t.UniverInstanceType.UNIVER_SHEET&&n.runtimeMountMode===`stage2`}function Ce(e){let t=e.data;if(!t||typeof t!=`object`)return!1;let n=t;return n.version===1&&typeof n.embedId==`string`}function we(e){if(!Ce(e))return!1;let n=e.data;return n.hostType===t.UniverInstanceType.UNIVER_SHEET&&n.childType!=null}function Te(e,t=`inactive`){return{autoMountRuntime:!Se(e),passThroughRuntimeEvents:!(we(e)&&t===`stage2`),preserveOnFocusChange:Ce(e),usePreviewObject:Se(e)}}function Ee(e){return Te(e).autoMountRuntime}function De(e){return Te(e).preserveOnFocusChange}function Oe(e){return Te(e).usePreviewObject}function ke(e,t=`inactive`){return Te(e,t).passThroughRuntimeEvents}function Ae(e){return Ce(e)&&!Ee(e)}function je(e,t){var n,r;if(!we(e))return!0;let i=t.target,a=i==null||(n=i.closest)==null?void 0:n.call(i,`[data-embed-float-dom="true"]`);return(a==null||(r=a.dataset)==null?void 0:r.embedFloatStage)!==`stage2`}function Me(e){return e!==`stage2`}function Ne(e,t,n){if(t){if(e===`stage1`){var r,i;(r=(i=t.scene).attachTransformerTo)==null||r.call(i,n);return}if(e===`stage2`&&n.oKey){var a,o,s;t.transformer.clearControlByIds([n.oKey]),(a=(o=t.scene).getTransformer)==null||(a=a.call(o))==null||(s=a.clearSelectedObjects)==null||s.call(a)}}}function Pe(e,t){return e.domLayers.some(([e])=>e===t)}function Fe(e){return e===t.DrawingTypeEnum.DRAWING_DOM||e===t.DrawingTypeEnum.DRAWING_BLOCK||e===t.DrawingTypeEnum.DRAWING_CHART}function Ie(e,t){if(e.runtimeMounted||e.runtimeStage!==`stage1`)return!1;let{offsetX:n,offsetY:r}=t;if(typeof n!=`number`||typeof r!=`number`)return!1;let i=e.position$.getValue();if(n>=Math.min(i.startX,i.endX)&&n<=Math.max(i.startX,i.endX)&&r>=Math.min(i.startY,i.endY)&&r<=Math.max(i.startY,i.endY))return!0;let a=e.rect;if(typeof a.isHit==`function`)try{return a.isHit({x:n,y:r})}catch{}return n>=a.left&&n<=a.left+a.width&&r>=a.top&&r<=a.top+a.height}function Le(e,t){if(t.type===`pointerdown`&&Ie(e,t))return{pointerId:t.pointerId,startOffsetX:t.offsetX,startOffsetY:t.offsetY,startedAt:Date.now()}}function Re(e,t,n){return!t||n.type!==`pointerup`||t.pointerId!=null&&n.pointerId!=null&&t.pointerId!==n.pointerId||!Ie(e,n)?!1:Math.hypot(n.offsetX-t.startOffsetX,n.offsetY-t.startOffsetY)<=4}function ze(e,n,i,a,o,s=!1){let{scaleX:c,scaleY:l}=n.getAncestorScale(),u=n.getViewport(r.SHEET_VIEWPORT_KEY.VIEW_MAIN),{startColumn:d,startRow:f,xSplit:p,ySplit:m}=a.getFreeze(),h={left:!0,top:!0};if(!u)return{...e,absolute:h};let{left:g,right:_,top:v,bottom:y}=e,{top:b,left:x,viewportScrollX:S,viewportScrollY:C}=u,{boundsOfViewArea:w,scrollDirectionResponse:T}=o||{},{rowHeaderWidth:E,columnHeaderHeight:D}=i,O={top:s?0:D,left:s?0:E};w&&(t.Tools.isDefine(O.top)&&(O.top=w.top),t.Tools.isDefine(O.left)&&(O.left=w.left)),T===`HORIZONTAL`&&(C=0),T===`VERTICAL`&&(S=0);let k=0,A=0,j=i.rowStartY(f-m)+D,M=i.colStartX(d-p)+E,N=i.rowStartY(f)+D,P=i.colStartX(d)+E;if(p===0)h.left=!1,k=(g-S)*c,A=(_-S)*c;else{let e=g-(M-E),t=_-(M-E);_<P?(k=e*c,A=t*c):g<=P&&_>=P?(k=e*c,A=Math.max(x,(_-S)*c)):g>P&&(h.left=!1,k=Math.max((g-S)*c,x),A=Math.max((_-S)*c,x))}let F=0,I=0;if(m===0)h.top=!1,F=(v-C)*l,I=(y-C)*l;else{let e=v-(j-D),t=y-(j-D);y<N?(F=e*l,I=t*l):v<=N&&y>=N?(F=e*l,I=Math.max(b,(y-C)*l)):v>N&&(h.top=!1,F=Math.max((v-C)*l,b),I=Math.max((y-C)*l,b))}return k=Math.max(k,O.left),F=Math.max(F,O.top),A=Math.max(A,O.left),I=Math.max(I,O.top),{left:k,right:A,top:F,bottom:I,absolute:h}}let $=(e,t,n,r,i)=>{let{left:a,top:o,width:s,height:c,angle:l}=e,u=ze({left:a,right:a+s,top:o,bottom:o+c},t,n,r,i),{scaleX:d,scaleY:f}=t.getAncestorScale();return{startX:u.left,endX:u.right,startY:u.top,endY:u.bottom,rotate:l,width:s*d,height:c*f,absolute:u.absolute}},Be=ue=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._renderManagerService=e,this._univerInstanceService=t,this._commandService=n,this._drawingManagerService=r,this._canvasFloatDomService=i,this._sheetDrawingService=a,this._lifecycleService=o,this._canvasFloatDomPreviewService=s,F(this,`_domLayerInfoMap`,new Map),F(this,`_transformChange$`,new d.Subject),F(this,`transformChange$`,this._transformChange$.asObservable()),F(this,`_add$`,new d.Subject),F(this,`add$`,this._add$.asObservable()),F(this,`_remove$`,new d.Subject),F(this,`remove$`,this._remove$.asObservable()),F(this,`_renderObjectFactories`,new Map),this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent(),this._bindEmbedFloatDragHandleEvent()}registerRenderObjectFactory(e,t){let n=this._renderObjectFactories.get(e)??[];return n.push(t),this._renderObjectFactories.set(e,n),{dispose:()=>{let n=this._renderObjectFactories.get(e);if(!n)return;let r=n.indexOf(t);r>=0&&n.splice(r,1),n.length===0&&this._renderObjectFactories.delete(e)}}}_createRenderObject(e){let t=this._renderObjectFactories.get(e.drawingType),n=t==null?void 0:t[t.length-1];return(n==null?void 0:n(e))??new r.Rect(e.key,e.config)}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe((0,d.filter)(e=>e===t.LifecycleStages.Rendered),(0,d.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)}static _disposeExternalFloatDom(e,t){e._removeDom(t,!0)}_createFloatDomDisposable(e){return fe(this,e,ue._disposeExternalFloatDom)}_bindEmbedFloatDragHandleEvent(){if(typeof document>`u`)return;let e=e=>this._handleEmbedFloatDragHandlePointerDown(e);document.addEventListener(ge,e),this.disposeWithMe(()=>document.removeEventListener(ge,e))}_handleEmbedFloatDragHandlePointerDown(e){let t=e.detail;if(!(t!=null&&t.hostAnchorId))return;let n=this._domLayerInfoMap.get(t.hostAnchorId);if(!n||!_e(n,t))return;let r=ve(n,t),i=this._getSceneAndTransformerByDrawingSearch(n.unitId);if(!r||!i)return;let{scene:a,transformer:o}=i;if(n.rect.oKey){var s;o.clearControlByIds([n.rect.oKey]),(s=a.getTransformer())==null||s.clearSelectedObjects()}let c=e=>{if(r.pointerId!=null&&e.pointerId!==r.pointerId)return;e.preventDefault();let t=ye(r,e,a);n.rect.transformByState(t)},l=e=>{if((r.pointerId==null||e.pointerId===r.pointerId)&&(window.removeEventListener(`pointermove`,c,!0),window.removeEventListener(`pointerup`,l,!0),window.removeEventListener(`pointercancel`,u,!0),e.preventDefault(),(n.rect.left!==r.startLeft||n.rect.top!==r.startTop)&&this._commitFloatDomMove(n),n.runtimeStage===`stage1`)){var t;(t=a.attachTransformerTo)==null||t.call(a,n.rect)}},u=e=>{if((r.pointerId==null||e.pointerId===r.pointerId)&&(window.removeEventListener(`pointermove`,c,!0),window.removeEventListener(`pointerup`,l,!0),window.removeEventListener(`pointercancel`,u,!0),n.rect.transformByState({left:r.startLeft,top:r.startTop}),n.runtimeStage===`stage1`)){var t;(t=a.attachTransformerTo)==null||t.call(a,n.rect)}};window.addEventListener(`pointermove`,c,!0),window.addEventListener(`pointerup`,l,!0),window.addEventListener(`pointercancel`,u,!0)}_commitFloatDomMove(e){var t;let r=(t=this._renderManagerService.getRenderUnitById(e.unitId))==null?void 0:t.with(c.SheetSkeletonManagerService).getSkeletonParam(e.subUnitId),i=this._sheetDrawingService.getDrawingByParam({unitId:e.unitId,subUnitId:e.subUnitId,drawingId:e.id});if(!r||!(i!=null&&i.transform))return;let a={...i.transform,left:e.rect.left,top:e.rect.top,width:e.rect.width,height:e.rect.height,angle:e.rect.angle,flipX:e.rect.flipX,flipY:e.rect.flipY,skewX:e.rect.skewX,skewY:e.rect.skewY},o=(0,n.transformToDrawingPosition)(a,r.skeleton),s=(0,n.transformToAxisAlignPosition)(a,r.skeleton);o&&s&&this._commandService.syncExecuteCommand(n.SetSheetDrawingCommand.id,{unitId:e.unitId,drawings:[{...i,transform:a,sheetTransform:o,axisAlignSheetTransform:s}]})}isFloatDomRuntimeMounted(e){var t;return((t=this._domLayerInfoMap.get(e))==null?void 0:t.runtimeMounted)===!0}_getFloatDomPreviewObjectKey(e){return`${e}__preview`}_syncPreviewObjectTransform(e,t){e==null||e.transformByState({left:t.left,top:t.top,width:t.width,height:t.height,angle:t.angle,flipX:t.flipX,flipY:t.flipY,skewX:t.skewX,skewY:t.skewY})}_requestFloatDomPreview(e,t,n){this._canvasFloatDomPreviewService&&this._canvasFloatDomPreviewService.requestPreview({id:e,width:t.width,height:t.height,data:n})}_upsertFloatDomPreviewObject(e,t,n,i,a){var o;let s=(o=this._canvasFloatDomPreviewService)==null?void 0:o.getPreview(i);if(!(s!=null&&s.image)){this._requestFloatDomPreview(i,t,a);return}let c=this._getFloatDomPreviewObjectKey(n),l=e.getObject(c);if(l instanceof r.Image)return l.changeSource(s.image),this._syncPreviewObjectTransform(l,t),l;let u=new r.Image(c,{left:t.left,top:t.top,width:t.width,height:t.height,angle:t.angle,flipX:t.flipX,flipY:t.flipY,skewX:t.skewX,skewY:t.skewY,url:s.image,evented:!1,rotateEnabled:!1,resizeEnabled:!1});return e.addObject(u,r.DRAWING_OBJECT_LAYER_INDEX),u}mountFloatDomRuntime(e){let t=this._domLayerInfoMap.get(e);return t!=null&&t.floatDomConfig?t.runtimeMounted?!0:(Pe(this._canvasFloatDomService,e)?this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:!1,props:{...t.floatDomConfig.props,initialStage:`stage2`,onRuntimeStageExit:()=>this.unmountFloatDomRuntime(e)}}):this._canvasFloatDomService.addFloatDom({...t.floatDomConfig,eventPassThrough:!1,props:{...t.floatDomConfig.props,initialStage:`stage2`,onRuntimeStageExit:()=>this.unmountFloatDomRuntime(e)}}),t.runtimeMounted=!0,t.runtimeStage=`stage2`,!0):!1}unmountFloatDomRuntime(e){let t=this._domLayerInfoMap.get(e);t!=null&&t.runtimeMounted&&(t.floatDomConfig&&!Ee(t.floatDomConfig)?this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:ke(t.floatDomConfig,`inactive`),props:t.floatDomConfig.props}):this._canvasFloatDomService.removeFloatDom(e),t.runtimeMounted=!1,t.runtimeStage=`inactive`)}_syncFloatDomVisibilityForActiveSheet(e,t){Array.from(this._domLayerInfoMap.values()).filter(t=>t.unitId===e&&t.floatDomConfig).forEach(e=>{let n=e.subUnitId===t,r=Pe(this._canvasFloatDomService,e.id);if(!n){r&&this._canvasFloatDomService.removeFloatDom(e.id),e.runtimeMounted=!1,e.runtimeStage=`inactive`;return}if(r||!e.floatDomConfig)return;this._canvasFloatDomService.addFloatDom(e.floatDomConfig);let i=Ee(e.floatDomConfig);e.runtimeMounted=i,e.runtimeStage=Ce(e.floatDomConfig)?`inactive`:i?`stage2`:`inactive`})}promoteFloatDomRuntimeStage(e){let t=this._domLayerInfoMap.get(e);if(!(t!=null&&t.floatDomConfig))return;let n=we(t.floatDomConfig);return t.runtimeMounted&&!n?(t.runtimeStage=`stage2`,`stage2`):t.runtimeStage===`stage1`?t.runtimeMounted?(t.runtimeStage=`stage2`,Ae(t.floatDomConfig)&&this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:ke(t.floatDomConfig,`stage2`)}),`stage2`):(this.mountFloatDomRuntime(e),`stage2`):(t.runtimeStage=`stage1`,Ae(t.floatDomConfig)&&this._canvasFloatDomService.updateFloatDom(e,{eventPassThrough:ke(t.floatDomConfig,`stage1`)}),`stage1`)}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderUnitById(e),n=t==null?void 0:t.scene;return t==null||n==null?null:{scene:n,transformer:n.getTransformerByCreate(),renderUnit:t,canvas:t.engine.getCanvasElement()}}_getDrawingZIndex(e,t,n){let r=this._drawingManagerService.getDrawingOrder(e,t),i=r.indexOf(n);return i<0?r.length-1:i}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{e.forEach(e=>{var n;let{unitId:i,subUnitId:a,drawingId:l}=e,f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:i,subUnitId:a}),p=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(i,t.UniverInstanceType.UNIVER_SHEET);if(!m)return;let h=m.getActiveSheet().getSheetId();if(!p||!f)return;let g=(n=this._renderManagerService.getRenderUnitById(i))==null?void 0:n.with(c.SheetSkeletonManagerService).getSkeletonParam(a);if(!g)return;let{transform:_,drawingType:v,data:y,hidden:b,groupId:x}=p;if(!Fe(v))return;let S=this._getSceneAndTransformerByDrawingSearch(i);if(S==null||b)return;let{scene:C,canvas:w}=S;if(_==null)return!0;if(h!==a)return;let{left:T,top:E,width:D,height:O,angle:k,flipX:A,flipY:j,skewX:M,skewY:N}=_,P=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:l}),F=x?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:x}):void 0,I=this._getObjectIncludingGroup(C,P,F);if(I!=null&&(this._removeTopLevelDuplicateIfGrouped(C,P,I),be(I,p),v===t.DrawingTypeEnum.DRAWING_CHART&&xe(I),I.transformByState({left:T,top:E,width:D,height:O,angle:k,flipX:A,flipY:j,skewX:M,skewY:N}),this._syncFloatDomRect(l,I),Oe(p)&&(this._syncPreviewObjectTransform(C.getObject(this._getFloatDomPreviewObjectKey(P)),I),this._requestFloatDomPreview(l,I,y)),this._domLayerInfoMap.has(l)))return;let L={left:T,top:E,width:D,height:O,zIndex:this._getDrawingZIndex(i,a,l)},ee=v===t.DrawingTypeEnum.DRAWING_CHART;if(ee){let e=this._getChartDataBackground(y);e!==void 0&&(L.fill=e),y&&y.border&&(L.stroke=y.border),Object.assign(L,le)}else L.rotateEnabled=!1;let R=I??this._createRenderObject({key:P,config:L,unitId:i,subUnitId:a,drawingId:l,drawingType:v,data:y});be(R,p),ee&&xe(R),ee?R.objectType=r.ObjectType.CHART:(v===t.DrawingTypeEnum.DRAWING_DOM||v===t.DrawingTypeEnum.DRAWING_BLOCK)&&(R.objectType=r.ObjectType.DRAWING_DOM),I||C.addObject(R,r.DRAWING_OBJECT_LAYER_INDEX),!I&&p.allowTransform!==!1&&C.attachTransformerTo(R),!I&&ee&&x&&(0,u.insertGroupObject)({drawingId:x,unitId:i,subUnitId:a},R,C,this._drawingManagerService);let z=new t.DisposableCollection,B=Oe(p),V=B?this._getFloatDomPreviewObjectKey(P):void 0;if(B){var H;this._upsertFloatDomPreviewObject(C,R,P,l,y);let e=(H=this._canvasFloatDomPreviewService)==null?void 0:H.previewUpdated$.subscribe(e=>{e.id===l&&this._upsertFloatDomPreviewObject(C,R,P,l,y)});e&&z.add(e)}let U=$(R,S.renderUnit.scene,g.skeleton,f.worksheet),W=new d.BehaviorSubject(U),G=`${de}${(0,t.generateRandomId)(6)}`,K=Ee(p),q=Ce(p),J,Y={position$:W,id:l,domId:G,componentKey:p.componentKey,eventPassThrough:ke(p,`inactive`),preserveOnFocusChange:De(p),onPointerDown:e=>{je(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{je(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{je(p,e)&&w.dispatchEvent(new PointerEvent(e.type,e))},onWheel:e=>{je(p,e)&&w.dispatchEvent(new WheelEvent(e.type,e))},data:y,props:q?{onRuntimeStageEnter:e=>{J&&(J.runtimeStage=e,J.runtimeMounted=K||e===`stage2`,Ae(p)&&this._canvasFloatDomService.updateFloatDom(l,{eventPassThrough:ke(p,e)})),Ne(e,this._getSceneAndTransformerByDrawingSearch(i),R)}}:void 0,unitId:i};if(J={dispose:z,rect:R,position$:W,unitId:i,subUnitId:a,id:l,domId:G,floatDomConfig:Y,runtimeMounted:K,runtimeStage:q?`inactive`:K?`stage2`:`inactive`,previewObjectKey:V},this._canvasFloatDomService.addFloatDom(Y),!K){let e,t=t=>{if(e&&(e.pointerId==null||t.pointerId==null||e.pointerId===t.pointerId)){if(typeof t.offsetX!=`number`||typeof t.offsetY!=`number`){e=void 0;return}Math.hypot(t.offsetX-e.startOffsetX,t.offsetY-e.startOffsetY)>4&&(e=void 0)}},n=R.onPointerDown$.subscribeEvent({priority:he,next:([t,n])=>{if((J==null?void 0:J.runtimeStage)===`stage1`){e=Le(J,t);return}let r=this.promoteFloatDomRuntimeStage(l);r===`stage2`&&(Ne(r,S,R),n.skipNextObservers=!0),Me(r)||n.stopPropagation()}}),r=C.onPointerDown$.subscribeEvent({priority:he,next:([t])=>{J&&(e=Le(J,t))}}),i=C.onPointerMove$.subscribeEvent({priority:he,next:([e])=>{t(e)}}),a=C.onPointerUp$.subscribeEvent({priority:he,next:([t,n])=>{let r=J&&Re(J,e,t);if(e=void 0,!r)return;let i=this.promoteFloatDomRuntimeStage(l);i===`stage2`&&(Ne(i,S,R),n.stopPropagation(),n.skipNextObservers=!0)}});z.add(n),z.add(r),z.add(i),z.add(a)}let te=R.onTransformChange$.subscribeEvent(()=>{let e=$(R,S.renderUnit.scene,g.skeleton,f.worksheet);W.next(e),V&&this._syncPreviewObjectTransform(C.getObject(V),R)});z.add(()=>{this._canvasFloatDomService.removeFloatDom(l),V&&C.removeObject(V)}),te&&z.add(te),this._bindFloatDomScroll(z,J,S.renderUnit.scene,g.skeleton,f.worksheet),this._domLayerInfoMap.set(l,J)})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:n,drawingId:r}),a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{transformer:s,scene:c}=a,l=this._getObjectIncludingGroup(c,i);if(l!=null&&l.oKey){var u;s.clearControlByIds([l==null?void 0:l.oKey]),(u=c.getTransformer())==null||u.clearSelectedObjects()}})}))}_scrollUpdateListener(){let e=(e,t)=>{var n;let r=this._getSceneAndTransformerByDrawingSearch(e),i=Array.from(this._domLayerInfoMap.keys()).map(e=>({id:e,...this._domLayerInfoMap.get(e)})).filter(n=>n.subUnitId===t&&n.unitId===e).map(e=>e.id),a=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:t}),o=(n=this._renderManagerService.getRenderUnitById(e))==null?void 0:n.with(c.SheetSkeletonManagerService).getSkeletonParam(t);r&&a&&o&&i.forEach(e=>{let t=this._domLayerInfoMap.get(e);if(t){let e=$(t.rect,r.renderUnit.scene,o.skeleton,a.worksheet,t);t.position$.next(e)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?e.activeSheet$:(0,d.of)(null))).subscribe(t=>{if(!t)return;let n=t.getUnitId(),r=t.getSheetId();this._syncFloatDomVisibilityForActiveSheet(n,r),e(n,r)})),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===c.SetZoomRatioOperation.id){let{unitId:n}=t.params;new Set(Array.from(this._domLayerInfoMap.values()).filter(e=>e.unitId===n).map(e=>e.subUnitId)).forEach(t=>{e(n,t)})}else if(t.id===s.SetFrozenMutation.id){let{unitId:n,subUnitId:r}=t.params;e(n,r)}else if(t.id===s.SetSelectionsOperation.id){let{unitId:n,subUnitId:r}=t.params;e(n,r)}}))}_bindFloatDomScroll(e,n,i,a,o){let s=i.getViewport(r.SHEET_VIEWPORT_KEY.VIEW_MAIN);s&&e.add((0,t.fromEventSubject)(s.onScrollAfter$).subscribe(()=>{n.position$.next($(n.rect,i,a,o,n))}))}updateFloatDomProps(e,t,n,i){let a=this._domLayerInfoMap.get(n),s=this._getSceneAndTransformerByDrawingSearch(e);if(a&&s){let{scene:a}=s,c=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:n}),l=this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:t,drawingId:n}),u=l!=null&&l.groupId?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:t,drawingId:l.groupId}):void 0,d=this._getObjectIncludingGroup(a,c,u);d&&d instanceof r.Rect&&(this._removeTopLevelDuplicateIfGrouped(a,c,d),d.setProps(i),this._syncFloatDomRect(n,d))}}_getObjectIncludingGroup(e,t,n){var r;return this._getChildObjectFromGroup(e,t,n)??((r=e.getObjectIncludeInGroup)==null?void 0:r.call(e,t))??e.getObject(t)??null}_getChildObjectFromGroup(e,t,n){var r;if(!n)return null;let i=((r=e.getObjectIncludeInGroup)==null?void 0:r.call(e,n))??e.getObject(n);return this._findChildObject(i,t)}_findChildObject(e,t){if(!e)return null;let n=e.getObjects();for(let e of n){if(e.oKey===t)return e;let n=this._findChildObject(e,t);if(n)return n}return null}_removeTopLevelDuplicateIfGrouped(e,t,n){if(!n.isInGroup)return;let r=e.getObject(t);r&&r!==n&&e.removeObject(r)}_syncFloatDomRect(e,t){if(!(t instanceof r.Rect))return;let n=this._domLayerInfoMap.get(e);n&&(n.rect=t)}_getChartDataBackground(e){if(!e||typeof e!=`object`||Array.isArray(e))return;let t=e,n=t.backgroundColor??t.background;return typeof n==`string`?n:void 0}_getPosition(e,t){var n;let{startX:r,endX:i,startY:a,endY:o}=e,s=(n=this._renderManagerService.getRenderUnitById(t))==null?void 0:n.with(c.ISheetSelectionRenderService);if(s==null)return;let l=s.getCellWithCoordByOffset(r,a);if(l==null)return;let u={column:l.actualColumn,columnOffset:r-l.startX,row:l.actualRow,rowOffset:a-l.startY},d=s.getCellWithCoordByOffset(i,o);if(d!=null)return{from:u,to:{column:d.actualColumn,columnOffset:i-d.startX,row:d.actualRow,rowOffset:o-d.startY}}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let n=this._drawingManagerService.getDrawingByParam(e);if(!n||!Fe(n.drawingType))return;if(n.hidden){this._removeDom(e.drawingId);return}if(!this._domLayerInfoMap.has(e.drawingId)){this._drawingManagerService.addNotification([e]);return}let r={...n.transform};this._transformChange$.next({id:e.drawingId,value:r}),this._canvasFloatDomService.updateFloatDom(e.drawingId,{...n});let i=this._getSceneAndTransformerByDrawingSearch(e.unitId);if(i&&n.drawingType!==t.DrawingTypeEnum.DRAWING_CHART){let{scene:t}=i,r=this._domLayerInfoMap.get(e.drawingId);r!=null&&r.rect&&(n.allowTransform===!1?t.detachTransformerFrom(r.rect):t.attachTransformerTo(r.rect))}})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{this._removeDom(e.drawingId)})}))}addFloatDomToPosition(e,r){let i=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!i)throw Error(`cannot find current target!`);let{unitId:a,subUnitId:o}=i,{initPosition:c,componentKey:l,data:u,allowTransform:d=!0}=e,f=r??(0,t.generateRandomId)(),p=this._getPosition(c,a);if(p==null)return;let m={unitId:a,subUnitId:o,drawingId:f,drawingType:e.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:p,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},axisAlignSheetTransform:p,data:u,allowTransform:d};return this._commandService.executeCommand(n.InsertSheetDrawingCommand.id,{unitId:a,drawings:[m]}),this._add$.next({unitId:a,subUnitId:o,id:f}),this._createFloatDomDisposable(f)}_removeDom(e,t=!1){let r=this._domLayerInfoMap.get(e);if(!r)return;let{unitId:i,subUnitId:a}=r;this._domLayerInfoMap.delete(e),r.dispose.dispose();let o=this._getSceneAndTransformerByDrawingSearch(i);if(o){let{scene:t,transformer:n}=o;if((0,u.disposeDrawingRenderObject)(t,{unitId:i,subUnitId:a,drawingId:e})){var s;n.clearControlByIds([r.rect.oKey]),(s=t.getTransformer())==null||s.clearSelectedObjects()}}if(t){let t=this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:a,drawingId:e});if(!t)return;let{redo:r,objects:o}=this._sheetDrawingService.getBatchRemoveOp([t]);this._commandService.syncExecuteCommand(n.SetDrawingApplyMutation.id,{unitId:i,subUnitId:a,op:r,objects:o,type:n.DrawingApplyType.REMOVE})}}removeFloatDom(e,t=!0){this._removeDom(e,t)}addFloatDomToRange(e,n,i,a){var l;let f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!f)throw Error(`cannot find current target!`);let{unitId:p,subUnitId:m}=f,h=this._getSceneAndTransformerByDrawingSearch(p);if(!h)return;let g=this._renderManagerService.getRenderUnitById(p);if(!g)return;let _=(l=this._renderManagerService.getRenderUnitById(p))==null?void 0:l.with(c.SheetSkeletonManagerService).getSkeletonParam(m);if(!_)return;let{componentKey:v,data:y,allowTransform:b=!0}=n,x=a??(0,t.generateRandomId)(),{position:S,position$:C}=this._createRangePositionObserver(e,g,_.skeleton),w=this._getPosition(S,p);if(w==null)return;let{scaleX:T}=h.scene.getAncestorScale(),E=He(S,i,T),D={unitId:p,subUnitId:m,drawingId:x,drawingType:n.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:v,sheetTransform:w,axisAlignSheetTransform:w,transform:{left:E.startX,top:E.startY,width:E.width,height:E.height},data:y,allowTransform:b};{var O,k;let{unitId:e,subUnitId:a,drawingId:l}=D,f=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:a}),p=D,m=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!m)return;let h=m.getActiveSheet().getSheetId();if(!p||!f)return;let g=(O=this._renderManagerService.getRenderUnitById(e))==null?void 0:O.with(c.SheetSkeletonManagerService);if(!g)return;let _=g.getSkeletonParam(a);if(!_)return;let{transform:v,drawingType:y,data:b,groupId:w}=p;if(!Fe(y))return;let T=this._getSceneAndTransformerByDrawingSearch(e);if(T==null)return;let{scene:E,canvas:A}=T;if(v==null||h!==a)return;let{left:j,top:M,width:N,height:P,angle:F,flipX:I,flipY:L,skewX:ee,skewY:R}=v,z=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),B=w?(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:w}):void 0,V=this._getObjectIncludingGroup(E,z,B);if(V!=null){this._removeTopLevelDuplicateIfGrouped(E,z,V),y===t.DrawingTypeEnum.DRAWING_CHART&&xe(V),V.transformByState({left:j,top:M,width:N,height:P,angle:F,flipX:I,flipY:L,skewX:ee,skewY:R}),this._syncFloatDomRect(l,V);return}let H={left:j,top:M,width:N,height:P,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1},U=y===t.DrawingTypeEnum.DRAWING_CHART;if(U){let e=this._getChartDataBackground(b);e!==void 0&&(H.fill=e),H.rotateEnabled=!1,b&&b.border&&(H.stroke=b.border),H.paintFirst=`stroke`,H.strokeWidth=1,H.radius=8}let W=this._createRenderObject({key:z,config:H,unitId:e,subUnitId:a,drawingId:l,drawingType:y,data:b});U&&(W.setObjectType(r.ObjectType.CHART),xe(W)),E.addObject(W,r.DRAWING_OBJECT_LAYER_INDEX),p.allowTransform!==!1&&E.attachTransformerTo(W),U&&w&&(0,u.insertGroupObject)({drawingId:w,unitId:e,subUnitId:a},W,E,this._drawingManagerService);let G=new t.DisposableCollection,K=E.getMainViewport(),{rowHeaderWidth:q,columnHeaderHeight:J}=_.skeleton,Y={dispose:G,rect:W,boundsOfViewArea:{top:J,left:q,bottom:K.bottom,right:K.right},domAnchor:i,unitId:e,subUnitId:a,id:l},te=$(W,T.renderUnit.scene,_.skeleton,f.worksheet,Y),X=new d.BehaviorSubject(te);Y.position$=X;let Z={position$:X,id:l,componentKey:p.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:e=>{A.dispatchEvent(new WheelEvent(e.type,e))},data:b,unitId:e};n.eventPassThrough&&(Z={...Z,onPointerDown:e=>{A.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{A.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{A.dispatchEvent(new PointerEvent(e.type,e))}}),this._canvasFloatDomService.addFloatDom(Z),this.disposeWithMe(C.subscribe(t=>{let n=He({rotate:0,startX:t.startX,startY:t.startY,endX:t.endX,endY:t.endY,width:i.width??t.width,height:i.height??t.height,absolute:{left:S.absolute.left,top:S.absolute.top}},i),s=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),c=new r.Rect(s,{left:n.startX,top:n.startY,width:i.width??t.width,height:i.height??t.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1}),u=$(c,T.renderUnit.scene,_.skeleton,f.worksheet,Y);X.next(u)}));let Q=(k=this._renderManagerService.getRenderUnitById(e))==null?void 0:k.with(c.SheetSkeletonManagerService),ne=Q==null?void 0:Q.currentSkeleton$.subscribe(e=>{e&&_.sheetId!==e.sheetId&&this._removeDom(x,!0)});ne&&G.add(ne);let re=W.onTransformChange$.subscribeEvent(()=>{let e=$(W,T.renderUnit.scene,_.skeleton,f.worksheet,Y);X.next(e)});G.add(()=>{this._canvasFloatDomService.removeFloatDom(l)}),re&&G.add(re),this._bindFloatDomScroll(G,Y,T.renderUnit.scene,_.skeleton,f.worksheet),this._domLayerInfoMap.set(l,Y)}return this._createFloatDomDisposable(x)}addFloatDomToColumnHeader(e,n,i,a){var l;let u=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!u)throw Error(`cannot find current target!`);let{unitId:f,subUnitId:p}=u;if(!this._getSceneAndTransformerByDrawingSearch(f))return;let m=this._renderManagerService.getRenderUnitById(f);if(!m)return;let h=(l=this._renderManagerService.getRenderUnitById(f))==null?void 0:l.with(c.SheetSkeletonManagerService).getSkeletonParam(p);if(!h)return;let{componentKey:g,data:_,allowTransform:v=!0}=n,y=a??(0,t.generateRandomId)(),{position:b,position$:x}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:e,endColumn:e},m,h.skeleton),S=b;S.startY=0;let C=this._getPosition(b,f);if(C==null)return;let w={unitId:f,subUnitId:p,drawingId:y,drawingType:n.type||t.DrawingTypeEnum.DRAWING_DOM,componentKey:g,sheetTransform:C,axisAlignSheetTransform:C,transform:{left:S.startX,top:S.startY,width:S.width,height:S.height},data:_,allowTransform:v};{var T,E;let{unitId:e,subUnitId:a,drawingId:l}=w,u=(0,s.getSheetCommandTarget)(this._univerInstanceService,{unitId:e,subUnitId:a}),f=w,p=this._univerInstanceService.getUnit(e,t.UniverInstanceType.UNIVER_SHEET);if(!p)return;let m=p.getActiveSheet().getSheetId();if(!f||!u)return;let g=(T=this._renderManagerService.getRenderUnitById(e))==null?void 0:T.with(c.SheetSkeletonManagerService);if(!g)return;let _=g.getSkeletonParam(a);if(!_)return;let{transform:v,data:C}=f,D=this._getSceneAndTransformerByDrawingSearch(e);if(D==null)return;let{scene:O,canvas:k}=D;if(v==null||m!==a)return;let{left:A,top:j,width:M,height:N,angle:P,flipX:F,flipY:I,skewX:L,skewY:ee}=v,R=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),z=this._getObjectIncludingGroup(O,R);if(z!=null){this._removeTopLevelDuplicateIfGrouped(O,R,z),z.transformByState({left:A,top:j,width:M,height:N,angle:P,flipX:F,flipY:I,skewX:L,skewY:ee}),this._syncFloatDomRect(l,z);return}let B=He({rotate:0,startX:S.startX,startY:0,endX:b.endX,endY:b.endY,width:i.width,height:i.height,absolute:{left:b.absolute.left,top:b.absolute.top}},i),V={left:B.startX,top:B.startY,width:B.width,height:B.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1},H=new r.Rect(R,V);O.addObject(H,r.DRAWING_OBJECT_LAYER_INDEX),f.allowTransform!==!1&&O.attachTransformerTo(H);let U=new t.DisposableCollection,W=O.getMainViewport(),G={dispose:U,rect:H,unitId:e,subUnitId:a,id:l,boundsOfViewArea:{top:0,left:W.left,bottom:W.bottom,right:W.right},domAnchor:i,scrollDirectionResponse:`HORIZONTAL`},K=$(H,D.renderUnit.scene,_.skeleton,u.worksheet,G),q=new d.BehaviorSubject(K);G.position$=q;let J={position$:q,id:l,componentKey:f.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:e=>{k.dispatchEvent(new WheelEvent(e.type,e))},data:C,unitId:e};n.eventPassThrough&&(J={...J,onPointerDown:e=>{k.dispatchEvent(new PointerEvent(e.type,e))},onPointerMove:e=>{k.dispatchEvent(new PointerEvent(e.type,e))},onPointerUp:e=>{k.dispatchEvent(new PointerEvent(e.type,e))}}),this._canvasFloatDomService.addFloatDom(J);let Y=H.onTransformChange$.subscribeEvent(()=>{let e=$(H,D.renderUnit.scene,_.skeleton,u.worksheet,G);q.next(e)});this.disposeWithMe(x.subscribe(t=>{let n=He({rotate:0,startX:t.startX,startY:0,endX:t.endX,endY:t.endY,width:i.width,height:i.height,absolute:{left:b.absolute.left,top:b.absolute.top}},i),s=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:e,subUnitId:a,drawingId:l}),c=new r.Rect(s,{left:n.startX,top:0,width:i.width,height:i.height,zIndex:this._drawingManagerService.getDrawingOrder(e,a).length-1}),d=$(c,D.renderUnit.scene,_.skeleton,u.worksheet,G);q.next(d)}));let te=(E=this._renderManagerService.getRenderUnitById(e))==null?void 0:E.with(c.SheetSkeletonManagerService);te==null||te.currentSkeleton$.subscribe(e=>{e&&h.sheetId!==e.sheetId&&this._removeDom(y,!0)}),U.add(()=>{this._canvasFloatDomService.removeFloatDom(l)}),Y&&U.add(Y),this._bindFloatDomScroll(U,G,D.renderUnit.scene,_.skeleton,u.worksheet),this._domLayerInfoMap.set(l,G)}return this._createFloatDomDisposable(y)}_createRangePositionObserver(e,n,r){let{startRow:i,startColumn:a}=e,o=Ve(i,a,r),l=new d.BehaviorSubject(o),u=Ve(e.endRow,e.endColumn,r),f=new d.BehaviorSubject(u),p=()=>{let t=Ve(i,a,r),n=Ve(e.endRow,e.endColumn,r);l.next(t),f.next(n)},m=new t.DisposableCollection;return m.add(n.engine.clientRect$.subscribe({next:()=>p(),error:()=>{}})),m.add(this._commandService.onCommandExecuted(e=>{if(e.id===s.SetWorksheetRowAutoHeightMutation.id&&e.params.rowsAutoHeightInfo.findIndex(e=>e.row===i)>-1){p();return}(s.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(e.id)>-1||e.id===c.SetScrollOperation.id||e.id===c.SetZoomRatioOperation.id)&&p()})),{position$:l.pipe((0,d.map)(t=>{let n=Ve(e.endRow,e.endColumn,r);return{rotate:0,width:n.right-t.left,height:n.bottom-t.top,absolute:{left:!0,top:!0},startX:t.left,startY:t.top,endX:n.right,endY:n.bottom}})),position:{rotate:0,width:u.right-o.left,height:u.bottom-o.top,absolute:{left:!0,top:!0},startX:o.left,startY:o.top,endX:u.right,endY:u.bottom},updateRowCol:(e,t)=>{i=e,a=t,p()},topLeftPos$:l,rightBottomPos$:f,disposable:m}}};Be=ue=L([I(0,(0,t.Inject)(r.IRenderManagerService)),I(1,t.IUniverInstanceService),I(2,(0,t.Inject)(t.ICommandService)),I(3,o.IDrawingManagerService),I(4,(0,t.Inject)(l.CanvasFloatDomService)),I(5,n.ISheetDrawingService),I(6,(0,t.Inject)(t.LifecycleService)),I(7,(0,t.Optional)(l.CanvasFloatDomPreviewService))],Be);function Ve(e,t,n){let r=n.getCellWithCoordByIndex(e,t),i=r.isMergedMainCell?r.mergeInfo:r;return{left:i.startX,right:i.endX,top:i.startY,bottom:i.endY}}function He(e,t,n){n??=1;let r=e.endX-e.startX,i=e.endY-e.startY,a=(t==null?void 0:t.width)??r,o=(t==null?void 0:t.height)??i,s=0,c=0;if(t){if(t.horizonOffsetAlign===`right`){let i=Ue(t.marginX,r*n);s=e.endX-i-a}else s=e.startX+Ue(t.marginX,r);if(t.verticalOffsetAlign===`bottom`){let r=Ue(t.marginY,i*n);c=e.endY-r-o}else c=e.startY+Ue(t.marginY,i)}return{rotate:0,startX:s,startY:c,endX:e.endX,endY:e.endY,width:a,height:o,absolute:{left:e.absolute.left,top:e.absolute.top}}}function Ue(e,t){return e===void 0?0:typeof e==`number`?e:t*Number.parseFloat(e)/100}let We=[[Be]];function Ge(e){e.has(Be)||(0,t.registerDependencies)(e,We),qe(e)}function Ke(e){(0,t.touchDependencies)(e,[[Be]])}function qe(e){if(!e.has(t.LifecycleService)){Ke(e);return}let n=e.get(t.LifecycleService);if(n.stage>=t.LifecycleStages.Ready){Ke(e);return}n.onStage(t.LifecycleStages.Ready).then(()=>{Ke(e)})}let Je=`sheet.menu.image`;function Ye(e){return{id:Je,type:l.MenuItemType.SUBITEMS,icon:`AddImageIcon`,tooltip:`sheets-drawing-ui.title`,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission],rangeTypes:[s.RangeProtectionPermissionEditPoint]})}}function Xe(e){return{id:B.id,title:`sheets-drawing-ui.upload.float`,type:l.MenuItemType.BUTTON,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}function Ze(e){return{id:V.id,title:`sheets-drawing-ui.upload.cell`,type:l.MenuItemType.BUTTON,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET)}}function Qe(e,t){let n=e.getActiveSheet();if(!n)return!1;let r=n.getCellMatrix(),{startRow:i,endRow:a,startColumn:o,endColumn:c}=t;for(let e=i;e<=a;e++)for(let t=o;t<=c;t++){let n=r.getValue(e,t);if((0,s.isCellImage)(n==null?void 0:n.p))return!0}return!1}function $e(){return`showDirectoryPicker`in window}function et(e){let n=e.get(t.IUniverInstanceService),r=e.get(s.SheetsSelectionsService),i=(0,d.combineLatest)([(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),n.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,d.switchMap)(e=>e?r.selectionMoveEnd$.pipe((0,d.map)(()=>{if(!$e())return!0;let t=r.getCurrentSelections();if(!t||t.length===0)return!0;for(let n of t)if(Qe(e,n.range))return!1;return!0})):(0,d.of)(!0)))]).pipe((0,d.map)(([e,t])=>e||t));return{id:Q.id,type:l.MenuItemType.BUTTON,icon:`DownloadImageIcon`,title:`sheets-drawing-ui.save.menuLabel`,hidden$:i}}let tt=`sheet.menu.worksheet-background-image`;function nt(e){let r=e.get(t.ICommandService),i=e.get(t.IUniverInstanceService);return new d.Observable(e=>{let a=()=>{let e=i.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);return!!(e!=null&&e.getActiveSheet().getConfig().backgroundImage)},o=new t.DisposableCollection;return o.add(r.onCommandExecuted(t=>{(t.id===n.SetWorksheetBackgroundImageMutation.id||t.id===s.SetWorksheetActiveOperation.id)&&e.next(a())})),o.add(i.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{e.next(a())})),e.next(a()),()=>o.dispose()})}function rt(e){return(0,c.getCurrentRangeDisable$)(e,{workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission]})}function it(e){return{id:tt,type:l.MenuItemType.SUBITEMS,icon:`AddImageIcon`,tooltip:`sheets-drawing-ui.backgroundImage.title`,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:rt(e)}}function at(e){return{id:ne.id,type:l.MenuItemType.BUTTON,title:`sheets-drawing-ui.backgroundImage.add`,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:rt(e)}}function ot(e){let n=rt(e);return{id:re.id,type:l.MenuItemType.BUTTON,title:`sheets-drawing-ui.backgroundImage.delete`,hidden$:(0,l.getMenuHiddenObservable)(e,t.UniverInstanceType.UNIVER_SHEET),disabled$:(0,d.combineLatest)([n,nt(e)]).pipe((0,d.map)(([e,t])=>e||!t))}}let st={[l.RibbonInsertGroup.MEDIA]:{[Je]:{order:0,gridLayout:{row:1,column:1,rowSpan:2,showLabel:!0},menuItemFactory:Ye,[B.id]:{order:0,menuItemFactory:Xe},[V.id]:{order:1,menuItemFactory:Ze}}},[l.RibbonPosition.VIEW]:{[l.RibbonViewGroup.DISPLAY]:{[tt]:{order:.5,gridLayout:{row:1,column:2,rowSpan:2,showLabel:!0},menuItemFactory:it,[ne.id]:{order:0,menuItemFactory:at},[re.id]:{order:1,menuItemFactory:ot}}}},[l.ContextMenuPosition.MAIN_AREA]:{[l.ContextMenuGroup.OTHERS]:{[Q.id]:{order:10,menuItemFactory:et}}},[l.ContextMenuPosition.COL_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[Q.id]:{order:10,menuItemFactory:et}}},[l.ContextMenuPosition.ROW_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[Q.id]:{order:10,menuItemFactory:et}}}};var ct=`@univerjs/sheets-drawing-ui`,lt=`1.0.3`;let ut=`sheets-drawing-ui.config`,dt={},ft=(0,t.createIdentifier)(`sheets-drawing-ui.drawing-context-menu.service`);var pt=class extends t.Disposable{constructor(...e){super(...e),F(this,`_providers`,new Map)}registerProvider(e,n){return this._providers.set(e,n),(0,t.toDisposable)(()=>{this._providers.get(e)===n&&this._providers.delete(e)})}getContextMenuPosition(e){var t;return(t=this._providers.get(e.drawingType))==null?void 0:t.getContextMenuPosition(e)}};let mt=class extends t.RxDisposable{constructor(e,t,n,r,i){super(),this._drawingManagerService=e,this._contextMenuService=t,this._renderManagerService=n,this._univerInstanceService=r,this._drawingContextMenuService=i,this._init()}_init(){this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._contextMenuListener(e))}_contextMenuListener(e){var t;if(!e)return;let n=(t=this._renderManagerService.getRenderUnitById(e.getUnitId()))==null?void 0:t.scene;if(!n)return;let r=n.getTransformerByCreate();r&&this.disposeWithMe(r.changeEnd$.subscribe(e=>{let{event:t}=e;if(t.button!==2)return;let n=r.getSelectedObjectMap();if(n.size===0)return;let i=[];for(let e of n.values()){let t=e.oKey,n=this._drawingManagerService.getDrawingOKey(t);if(!n)return;i.push(n)}this._contextMenuService.triggerContextMenu(t,this._getContextMenuPosition(i))}))}_getContextMenuPosition(e){if(e.length!==1)return l.ContextMenuPosition.DRAWING;let[t]=e;return this._drawingContextMenuService.getContextMenuPosition({unitId:t.unitId,subUnitId:t.subUnitId,drawingId:t.drawingId,drawingType:t.drawingType,drawing:t})??l.ContextMenuPosition.DRAWING}};mt=L([I(0,o.IDrawingManagerService),I(1,l.IContextMenuService),I(2,r.IRenderManagerService),I(3,t.IUniverInstanceService),I(4,ft)],mt);function ht({SelectComponent:e=i.Select}={}){let n=(0,l.useDependency)(t.LocaleService),r=(0,l.useDependency)(l.IDialogService),a=(0,l.useDependency)(W),[o,s]=(0,p.useState)([`cellAddress`]),[u,d]=(0,p.useState)(!1),[f,h]=(0,p.useState)(null),g=(0,p.useMemo)(()=>a.getCellImagesInSelection(),[a]),_=(0,p.useMemo)(()=>a.getDataColumns(),[a]),v=(0,p.useMemo)(()=>a.getSelectionRowRange(),[a]),y=_.length>0,b=(0,p.useMemo)(()=>_.map(e=>({label:e.label,value:String(e.index)})),[_]),[x,S]=(0,p.useState)(()=>b.length>0?b[0].value:`0`),C=(0,p.useMemo)(()=>{if(!o.includes(`columnValue`)||!v)return[];let e=Number(x);return[{startRow:v.startRow,endRow:v.endRow,startColumn:e,endColumn:e}]},[o,x,v]);(0,c.useHighlightRange)(C);let w=(0,p.useCallback)(e=>{e.length!==0&&s(e)},[]),T=(0,p.useCallback)(e=>{S(String(e))},[]),E=(0,p.useCallback)(()=>{r.close(Z)},[r]),D=(0,p.useCallback)(async()=>{if(g.length!==0){d(!0),h(null);try{await a.saveImages(g,{fileNameParts:o,columnIndex:o.includes(`columnValue`)?Number(x):void 0}),r.close(Z)}catch(e){console.error(`Failed to save images:`,e),h(n.t(`sheets-drawing-ui.save.error`))}finally{d(!1)}}},[a,g,o,x,r,n]),O=o.includes(`columnValue`);return(0,m.jsxs)(`div`,{className:`univer-flex univer-flex-col`,children:[(0,m.jsx)(i.FormLayout,{label:n.t(`sheets-drawing-ui.save.imageCount`),children:(0,m.jsx)(`div`,{className:`univer-text-sm univer-text-gray-600`,children:g.length})}),(0,m.jsx)(i.FormLayout,{label:n.t(`sheets-drawing-ui.save.fileNameConfig`),children:(0,m.jsxs)(i.CheckboxGroup,{value:o,onChange:w,direction:`vertical`,children:[(0,m.jsx)(i.Checkbox,{value:`cellAddress`,disabled:!y,children:n.t(`sheets-drawing-ui.save.useRowCol`)}),y&&(0,m.jsx)(i.Checkbox,{value:`columnValue`,children:n.t(`sheets-drawing-ui.save.useColumnValue`)})]})}),O&&(0,m.jsx)(i.FormLayout,{label:n.t(`sheets-drawing-ui.save.selectColumn`),children:(0,m.jsx)(e,{value:x,options:b,onChange:T})}),f&&(0,m.jsx)(`div`,{className:`univer-text-xs univer-text-red-500`,children:f}),(0,m.jsxs)(`div`,{className:`univer-flex univer-justify-end univer-gap-2 univer-border-t univer-border-gray-200 univer-pt-3`,children:[(0,m.jsx)(i.Button,{onClick:E,disabled:u,children:n.t(`sheets-drawing-ui.save.cancel`)}),(0,m.jsx)(i.Button,{variant:`primary`,onClick:D,disabled:u||g.length===0,children:u?n.t(`sheets-drawing-ui.save.saving`):n.t(`sheets-drawing-ui.save.confirm`)})]})]})}function gt(){return(0,m.jsx)(ht,{SelectComponent:i.MobileSelect})}let _t=e=>{let a=(0,l.useDependency)(t.ICommandService),s=(0,l.useDependency)(t.LocaleService),c=(0,l.useDependency)(o.IDrawingManagerService),u=(0,l.useDependency)(r.IRenderManagerService),{drawings:d}=e,f=vt(d[0])?d[0]:void 0,h=f?u.getRenderUnitById(f.unitId):void 0,g=h==null?void 0:h.scene,_=g==null?void 0:g.getTransformerByCreate(),[v,y]=(0,p.useState)(!0),b=f?(0,n.getSheetDrawingPlacement)(f).kind:n.SheetDrawingAnchorType.Position,[x,S]=(0,p.useState)(b);function C(e,t){let n=[];return e.forEach(e=>{let{oKey:r}=e,i=t.getDrawingOKey(r);if(i==null||!vt(i))return n.push(null),!0;let{unitId:a,subUnitId:o,drawingId:s,drawingType:c,anchorType:l,sheetTransform:u,axisAlignSheetTransform:d}=i;n.push({unitId:a,subUnitId:o,drawingId:s,anchorType:l,sheetTransform:u,drawingType:c,axisAlignSheetTransform:d})}),n}if((0,p.useEffect)(()=>{if(!_)return;let e=_.clearControl$.subscribe(e=>{e===!0&&y(!1)}),t=_.changeStart$.subscribe(e=>{let{objects:t}=e,r=C(t,c);if(r.length===0)y(!1);else if(r.length>=1){y(!0);let e=r[0];S(e?(0,n.getSheetDrawingPlacement)(e).kind:n.SheetDrawingAnchorType.Position)}});return()=>{t.unsubscribe(),e.unsubscribe()}},[c,_]),!f||!_)return null;function w(e){let t=yt(e);if(!t)return;let r=c.getFocusDrawings();if(!r.length||!r.every(vt))return;let{unitId:i,subUnitId:o}=r[0],s=[];for(let e of r){let{transform:n}=e,{left:r,top:i,width:a,height:o}=n??{};if(typeof r!=`number`||typeof i!=`number`||typeof a!=`number`||typeof o!=`number`||!Number.isFinite(r)||!Number.isFinite(i)||!Number.isFinite(a)||!Number.isFinite(o))return;s.push({drawingId:e.drawingId,placement:{kind:t,bounds:{left:r,top:i,width:a,height:o}}})}a.syncExecuteCommand(n.SetSheetDrawingPlacementCommand.id,{unitId:i,subUnitId:o,drawings:s})&&S(t)}return(0,m.jsxs)(`div`,{className:(0,i.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!v}),children:[(0,m.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,m.jsx)(`div`,{children:s.t(`sheets-drawing-ui.drawing-anchor.title`)})}),(0,m.jsx)(`div`,{children:(0,m.jsxs)(i.RadioGroup,{value:x,onChange:w,direction:`vertical`,children:[(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.Both,children:s.t(`sheets-drawing-ui.drawing-anchor.both`)}),(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.Position,children:s.t(`sheets-drawing-ui.drawing-anchor.position`)}),(0,m.jsx)(i.Radio,{value:n.SheetDrawingAnchorType.None,children:s.t(`sheets-drawing-ui.drawing-anchor.none`)})]})})]})};function vt(e){return!!(e&&`sheetTransform`in e&&`axisAlignSheetTransform`in e)}function yt(e){return e===n.SheetDrawingAnchorType.Position||e===n.SheetDrawingAnchorType.Both||e===n.SheetDrawingAnchorType.None?e:null}let bt=()=>{let e=(0,l.useDependency)(o.IDrawingManagerService),t=(0,l.useObservable)(()=>e.focus$,e.getFocusDrawings(),!1,[e]);return!!(t!=null&&t.length)&&(0,m.jsxs)(`div`,{className:`univer-text-sm`,children:[(0,m.jsx)(u.DrawingCommonPanel,{drawings:t}),(0,m.jsx)(_t,{drawings:t})]})},xt=class extends t.Disposable{constructor(e){super(),this.disposeWithMe(e.register(ie,bt)),this.disposeWithMe(e.register(Z,gt))}};xt=L([I(0,(0,t.Inject)(l.ComponentManager))],xt);let St=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._context=e,this._hoverManagerService=t,this._selectionsService=n,this._drawingRenderService=r,this._sheetSkeletonManagerService=i,F(this,`_isSetCursor`,!1),this._initHover(),this._initImageClick()}_initHover(){this.disposeWithMe(this._hoverManagerService.currentRichTextNoDistinct$.pipe((0,d.throttleTime)(33)).subscribe(e=>{let t=[];if(e!==null&&(t=this._selectionsService.getWorkbookSelections(this._context.unitId).getCurrentSelections()),(e==null?void 0:e.unitId)===this._context.unitId&&e!=null&&e.drawing&&t.length===1&&t[0].primary){let{row:n,col:i}=e,{actualRow:a,actualColumn:o,startRow:s,startColumn:c,endRow:l,endColumn:u,isMerged:d,isMergedMainCell:f}=t[0].primary;(d||f)&&n>=s&&n<=l&&i>=c&&i<=u||n===a&&i===o?(this._isSetCursor=!0,this._context.scene.setCursor(r.CURSOR_TYPE.ZOOM_IN)):this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}else this._isSetCursor&&(this._isSetCursor=!1,this._context.scene.resetCursor())}))}_initImageClick(){this.disposeWithMe(this._hoverManagerService.currentClickedCell$.subscribe(e=>{if(e!=null&&e.drawing&&this._isSetCursor){let t=e.drawing.drawing.drawingOrigin;this._previewImage(t)}}));let e=this._hoverManagerService.currentDbClickedCell$;e&&this.disposeWithMe(e.subscribe(({location:e})=>{var t,n,r;if(e.unitId!==this._context.unitId)return;let i=this._context.unit.getSheetBySheetId(e.subUnitId),a=i==null||(t=i.getCellRaw(e.row,e.col))==null?void 0:t.p,o=a==null||(n=a.drawingsOrder)==null?void 0:n[0],c=(0,s.isCellImage)(a)&&o?(r=a.drawings)==null?void 0:r[o]:void 0;c&&this._previewImage(c)}))}_previewImage(e){var t;if(this._disposed)return;let n=(t=this._sheetSkeletonManagerService.getCurrentSkeleton())==null?void 0:t.imageCacheMap,r=n==null?void 0:n.getImage(e.imageSourceType,e.source,()=>this._previewImage(e));r&&(this._drawingRenderService.previewImage(`preview-cell-image`,r.src,r.width,r.height),this._context.scene.resetCursor(),this._isSetCursor=!1)}};St=L([I(1,(0,t.Inject)(c.HoverManagerService)),I(2,(0,t.Inject)(s.SheetsSelectionsService)),I(3,(0,t.Inject)(u.DrawingRenderService)),I(4,(0,t.Inject)(c.SheetSkeletonManagerService))],St);let Ct=class extends t.Disposable{constructor(e,t,n,r){super(),this._context=e,this._sheetDrawingService=t,this._drawingManagerService=n,this._sheetSkeletonService=r,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);let e=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(let r in e){let i=e[r];for(let e in i.data){let r=i.data[e],{unitId:a,subUnitId:o}=r,s=this._sheetSkeletonService.getSkeletonParam(a,o);if(s&&r.sheetTransform&&!r.groupId&&r.anchorType!==n.SheetDrawingAnchorType.None){let e=(0,n.drawingPositionToTransform)(r.sheetTransform,s);r.transform=e&&r.drawingType===t.DrawingTypeEnum.DRAWING_GROUP?{...e,left:(e.left??0)-s.skeleton.rowHeaderWidthAndMarginLeft,top:(e.top??0)-s.skeleton.columnHeaderHeightAndMarginTop}:e}}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Ct=L([I(1,n.ISheetDrawingService),I(2,o.IDrawingManagerService),I(3,(0,t.Inject)(s.SheetSkeletonService))],Ct);var wt=class extends r.SheetExtension{constructor(e,n){super(),this._requestRender=n,F(this,`uKey`,`WorksheetBackgroundImageExtension`),F(this,`type`,r.SHEET_EXTENSION_TYPE.BACKGROUND),F(this,`_imageCache`,void 0),this._imageCache=new t.ImageCacheMap(e)}draw(e,t,n,r,i){let a=n.worksheet.getConfig().backgroundImage;if(!a)return;let o=this._imageCache.getImage(a.imageSourceType,a.source,this._requestRender,this._requestRender);if(!o||!o.complete||o.naturalWidth===0||o.getAttribute(`data-error`))return;let s=e.createPattern(o,`repeat`);if(!s)return;let c=a.scaleX??1,l=a.scaleY??1;(c!==1||l!==1)&&s.setTransform({a:c,d:l});let u=r.length>0?r:i.viewRanges,{columnWidthAccumulation:d,rowHeightAccumulation:f}=n;d&&f&&(e.save(),e.fillStyle=s,u.forEach(t=>{let n=t.startColumn>0?d[t.startColumn-1]:0,r=t.startRow>0?f[t.startRow-1]:0,i=d[t.endColumn],a=f[t.endRow];i!=null&&a!=null&&e.fillRect(n,r,i-n,a-r)}),e.restore())}};let Tt=class extends t.Disposable{constructor(e,t,r){super(),this._context=e;let i=this._context.mainComponent,a=new wt(r,()=>{i.makeForceDirty(!0),this._context.scene.makeDirty()});this.disposeWithMe(i.register(a)),this.disposeWithMe(t.onCommandExecuted(e=>{let t=e.params;e.id===n.SetWorksheetBackgroundImageMutation.id&&(t==null?void 0:t.unitId)===this._context.unitId&&(i.makeForceDirty(!0),this._context.scene.makeDirty())}))}};Tt=L([I(1,t.ICommandService),I(2,(0,t.Inject)(t.Injector))],Tt);function Et(e,t,n){var r,i;let a=n==null?void 0:n.p,o=(0,s.isCellImage)(a)&&(a==null||(r=a.drawingsOrder)==null?void 0:r.length)===1?a.drawingsOrder[0]:void 0,c=o?a==null||(i=a.drawings)==null?void 0:i[o]:void 0;if(c&&a){let n=R(e,{unitId:t.unitId,subUnitId:t.subUnitId,row:t.row,col:t.col},c.docTransform.size.width,c.docTransform.size.height,c.docTransform.angle);if(n)return c.transform.width=n.width,c.transform.height=n.height,c.docTransform.size.width=n.width,c.docTransform.size.height=n.height,c.transform.left=0,c.transform.top=0,c.docTransform.positionH.posOffset=0,c.docTransform.positionV.posOffset=0,a.documentStyle.pageSize.width=1/0,a.documentStyle.pageSize.height=1/0,!0}return!1}let Dt=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._sheetInterceptorService=e,this._injector=t,this._drawingManagerService=n,this._docDrawingController=r,this._editorBridgeService=i,this._handleInitEditor(),this._initCellContentInterceptor()}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(e=>{e.visible?e.visible&&(this._drawingManagerService.removeDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(s.INTERCEPTOR_POINT.CELL_CONTENT,{effect:t.InterceptorEffectEnum.Style,priority:s.InterceptCellContentPriority.CELL_IMAGE,handler:(e,t,n)=>(e&&(0,s.isCellImage)(e.p)&&(e===t.rawData&&(e={...t.rawData}),e.interceptorStyle||(e.interceptorStyle={}),e.interceptorStyle.tr={a:0},Et(this._injector,{unitId:t.unitId,subUnitId:t.subUnitId,row:t.row,col:t.col},e)),n(e))}))}};Dt=L([I(0,(0,t.Inject)(s.SheetInterceptorService)),I(1,(0,t.Inject)(t.Injector)),I(2,o.IDrawingManagerService),I(3,(0,t.Inject)(f.DocDrawingController)),I(4,(0,t.Inject)(c.IEditorBridgeService))],Dt);let Ot=class extends t.Disposable{constructor(e,t){super(),this._autoFillService=e,this._injector=t,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:`sheet-cell-image-autofill`,onBeforeSubmit:(e,n,r,i)=>{new t.ObjectMatrix(i).forValue((t,n,r)=>{Et(this._injector,{unitId:e.unitId,subUnitId:e.subUnitId,row:t,col:n},r)})}}))}};Ot=L([I(0,(0,t.Inject)(s.IAutoFillService)),I(1,(0,t.Inject)(t.Injector))],Ot);let kt=[t.DOCS_NORMAL_EDITOR_UNIT_ID_KEY,t.DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY],At=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._commandService=e,this._univerInstanceService=t,this._dialogService=n,this._renderManagerService=r,this._localeService=i,this._initDocImageCopyPasteHooks()}_setCellImage(e){var n;let i=(0,t.createDocumentModelWithStyle)(``,{}),a=(n=(0,r.getCurrentTypeOfRenderer)(t.UniverInstanceType.UNIVER_SHEET,this._univerInstanceService,this._renderManagerService))==null?void 0:n.with(c.EditingRenderController),o=t.BuildTextUtils.drawing.add({documentDataModel:i,drawings:[e],selection:{collapsed:!0,startOffset:0,endOffset:0}});o&&(i.apply(o),a&&a.submitCellData(i))}_initDocImageCopyPasteHooks(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{if(e.id===h.InnerPasteCommand.id){let{doc:r}=e.params,i=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_DOC);if(i==null||!Object.keys(r.drawings??{}).length)return;let a=i.getUnitId();if(kt.includes(a)){var n;let e=()=>{this._dialogService.close(`sheet-cell-image-copy-paste`),this._commandService.syncExecuteCommand(c.SetCellEditVisibleOperation.id,{visible:!1})};((n=i.getBody())==null?void 0:n.dataStream)===`\r
2
2
  `?(this._commandService.syncExecuteCommand(c.SetCellEditVisibleOperation.id,{visible:!1}),this._setCellImage(Object.values(r.drawings)[0])):this._dialogService.open({id:`sheet-cell-image-copy-paste`,title:{label:this._localeService.t(`sheets-drawing-ui.cell-image.pasteTitle`)},children:{label:this._localeService.t(`sheets-drawing-ui.cell-image.pasteContent`)},width:320,onClose:e,showOk:!0,showCancel:!0,onOk:()=>{e(),this._setCellImage(Object.values(r.drawings)[0])},onCancel:e})}}}))}};At=L([I(0,t.ICommandService),I(1,t.IUniverInstanceService),I(2,l.IDialogService),I(3,r.IRenderManagerService),I(4,(0,t.Inject)(t.LocaleService))],At);let jt=class extends t.Disposable{constructor(e,t,n,r,i){super(),this._context=e,this._commandService=t,this._sheetSkeletonService=n,this._sheetDrawingService=r,this._drawingManagerService=i,this._commandListener()}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===s.SetWorksheetActiveOperation.id){let{unitId:t,subUnitId:n}=e.params;this._updateDrawings(t,n)}})),this.disposeWithMe(this._context.activated$.subscribe(e=>{let{unit:t,unitId:n}=this._context;e?this._updateDrawings(n,t.getActiveSheet().getSheetId()):this._clearDrawings(n)}))}_clearDrawings(e){setTimeout(()=>{let t=this._drawingManagerService.drawingManagerData,n=[];Object.keys(t??{}).forEach(r=>{let i=t[r]??{};Object.keys(i).forEach(t=>{var a;let o=((a=i[t])==null?void 0:a.data)??{};Object.keys(o).forEach(t=>{r===e&&n.push(o[t])})})}),this._sheetDrawingService.removeNotification(n),this._drawingManagerService.removeNotification(n)})}_updateDrawings(e,t){setTimeout(()=>{let r=this._sheetSkeletonService.getSkeletonParam(e,t),i=this._drawingManagerService.drawingManagerData,a=[],o=[];Object.keys(i??{}).forEach(s=>{if(s!==e)return;let c=i[s]??{};Object.keys(c).forEach(i=>{var l;let u=((l=c[i])==null?void 0:l.data)??{};Object.keys(u).forEach(c=>{if(s===e&&i===t){let e=u[c];e.sheetTransform&&e.anchorType!==n.SheetDrawingAnchorType.None&&(e.transform=(0,n.drawingPositionToTransform)(e.sheetTransform,r)),a.push(u[c])}else o.push(u[c])})})}),this._sheetDrawingService.removeNotification(o),this._sheetDrawingService.addNotification(a),this._drawingManagerService.removeNotification(o),this._drawingManagerService.addNotification(a)},0)}};jt=L([I(1,t.ICommandService),I(2,(0,t.Inject)(s.SheetSkeletonService)),I(3,n.ISheetDrawingService),I(4,o.IDrawingManagerService)],jt);let Mt=`image/png`;function Nt(e){let t=e.split(`,`),n=atob(t[1]),r=n.length,i=new Uint8Array(r);for(let e=0;e<r;e++)i[e]=n.charCodeAt(e);return new Blob([i],{type:Mt})}function Pt(e){let t=new ClipboardItem({[Mt]:Nt(e)});navigator.clipboard.write([t]).catch(e=>{console.error(`Could not copy image using clipboard API: `,e)})}function Ft(){function e(){let e=document.createElement(`input`);return e.style.position=`absolute`,e.style.height=`1px`,e.style.width=`1px`,e.style.opacity=`0`,e}let t=document.activeElement,n=e();return document.body.appendChild(n),n.focus(),()=>{n.blur(),document.body.removeChild(n),t instanceof HTMLElement&&t.focus()}}let It=[c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_COL_WIDTH,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_VALUE,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMAT,c.PREDEFINED_HOOK_NAME_PASTE.SPECIAL_PASTE_FORMULA],Lt=class extends t.RxDisposable{constructor(e,t,n,r,i,a){super(),this._sheetClipboardService=e,this._renderManagerService=t,this._sheetSkeletonService=n,this._drawingService=r,this._clipboardInterfaceService=i,this._commandService=a,F(this,`_copyInfo`,void 0),this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this.disposeWithMe(this._sheetClipboardService.addClipboardHook({id:`SHEET_IMAGE_UI_PLUGIN`,onBeforeCopyFocusedObject:(e,r,i)=>{this._copyInfo=null;let a=this._focusedDrawings.filter(e=>e.drawingType===t.DrawingTypeEnum.DRAWING_IMAGE);if(a.length===0)return!1;let[o]=a;if(i===c.COPY_TYPE.CUT){let t={unitId:e,drawings:a};this._commandService.executeCommand(n.RemoveSheetDrawingCommand.id,t)}return(0,d.timer)(200).pipe((0,d.takeUntil)(this.dispose$)).subscribe(()=>{let e=Ft();o.drawingType===t.DrawingTypeEnum.DRAWING_IMAGE&&o.imageSourceType===t.ImageSourceType.BASE64?Pt(o.source):this._clipboardInterfaceService.writeText(``),e()}),this._copyInfo={unitId:o.unitId,subUnitId:o.subUnitId,drawings:a},!0},onBeforeCopy:(e,t,n)=>{this._copyInfo=this._createDrawingsCopyInfoByRange(e,t,n)},onPasteCells:(e,t,n,r)=>{if(!r.copyId)return this._copyInfo=null,{redos:[],undos:[]};if(!e||!this._copyInfo)return{redos:[],undos:[]};let{copyType:i=c.COPY_TYPE.COPY,pasteType:a}=r,{range:o,unitId:s,subUnitId:l}=e,{range:u,unitId:d,subUnitId:f}=t;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({unitId:d,subUnitId:f,pasteRange:u,pasteType:a},{unitId:s,subUnitId:l,copyType:i,copyRange:o}):this._generateSingleDrawingPasteMutations({pasteTo:t,pasteType:a},c.COPY_TYPE.COPY)},onPastePlainText:(e,t)=>(this._copyInfo=null,{undos:[],redos:[]}),onPasteUnrecognized:e=>{if(!this._copyInfo||this._copyInfo.copyRange)return{undos:[],redos:[]};let t=this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:c.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},c.COPY_TYPE.COPY);return this._copyInfo=null,t},onPasteFiles:(e,t)=>{if(this._copyInfo&&!this._copyInfo.copyRange){let t=this._generateSingleDrawingPasteMutations({pasteTo:e,pasteType:c.PREDEFINED_HOOK_NAME_PASTE.DEFAULT_PASTE},c.COPY_TYPE.COPY);return this._copyInfo=null,t}let n=t.filter(e=>e.type.includes(`image`));return n.length?(this._copyInfo=null,{undos:[],redos:[{id:B.id,params:{files:n}}]}):{undos:[],redos:[]}}}))}_createDrawingsCopyInfoByRange(e,r,i){let a=this._sheetSkeletonService.getSkeleton(e,r);if(!a)return;let o=(0,s.attachRangeWithCoord)(a,i);if(!o)return;let{startX:c,endX:l,startY:u,endY:d}=o,f=this._drawingService.getDrawingData(e,r),p=[];if(Object.keys(f).forEach(e=>{let r=f[e];if(r.drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE||(r.anchorType??n.SheetDrawingAnchorType.Position)===n.SheetDrawingAnchorType.None)return;let{transform:i}=r;if(!i)return;let{left:a=0,top:o=0,width:s=0,height:m=0}=i,{drawingStartX:h,drawingEndX:g,drawingStartY:_,drawingEndY:v}={drawingStartX:a,drawingEndX:a+s,drawingStartY:o,drawingEndY:o+m};c<=h&&g<=l&&u<=_&&v<=d&&p.push(r)}),p.length)return{copyRange:i,drawings:p,unitId:e,subUnitId:r}}_generateSingleDrawingPasteMutations(e,t){let{pasteType:r,pasteTo:i}=e;if(It.includes(r))return{redos:[],undos:[]};let{unitId:a,subUnitId:o,range:l}=i,u=this._sheetSkeletonService.getSkeleton(a,o);if(!u)return{redos:[],undos:[]};let{drawings:d}=this._copyInfo,f=(0,s.discreteRangeToRange)(l),p;if(d.length>1){let e=1/0,t=1/0;for(let n of d){let{left:r=0,top:i=0}=n.transform??{};e=Math.min(e,r),t=Math.min(t,i)}p={left:e,top:t}}return this._generateMutations(d,{unitId:a,subUnitId:o,isCut:t===c.COPY_TYPE.CUT,getTransform:(e,t)=>{let r=(0,s.attachRangeWithCoord)(u,{startRow:f.startRow,endRow:f.endRow,startColumn:f.startColumn,endColumn:f.endColumn}),i={...e,left:p&&r?r.startX+((e==null?void 0:e.left)??0)-p.left:r==null?void 0:r.startX,top:p&&r?r.startY+((e==null?void 0:e.top)??0)-p.top:r==null?void 0:r.startY};return{transform:i,sheetTransform:(0,n.transformToDrawingPosition)(i,u)??t,axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(i,u)??t}}})}_generateMutations(e,r){let{unitId:i,subUnitId:a,getTransform:o,isCut:s}=r,c=[],l=[],{_drawingService:u}=this;return e.forEach(e=>{let{transform:r,sheetTransform:d}=e;if(!r)return;let f=o(r,d),p={...e,unitId:i,subUnitId:a,drawingId:s?e.drawingId:(0,t.generateRandomId)(),transform:f.transform,sheetTransform:f.sheetTransform,axisAlignSheetTransform:f.axisAlignSheetTransform};if(s){let{undo:e,redo:t,objects:r}=u.getBatchUpdateOp([p]);c.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,type:n.DrawingApplyType.UPDATE,op:t,objects:r}}),l.push({id:n.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:a,type:n.DrawingApplyType.UPDATE,op:e,objects:r}})}else{let{undo:e,redo:t,objects:r}=u.getBatchAddOp([p]);c.push({id:n.SetDrawingApplyMutation.id,params:{op:t,unitId:i,subUnitId:a,objects:r,type:n.DrawingApplyType.INSERT}}),l.push({id:n.SetDrawingApplyMutation.id,params:{op:e,unitId:i,subUnitId:a,objects:r,type:n.DrawingApplyType.REMOVE}})}}),{redos:c,undos:l}}_generateRangeDrawingsPasteMutations(e,t){if(!this._copyInfo)return{redos:[],undos:[]};let{unitId:r,subUnitId:i,pasteRange:a,pasteType:o}=e,{unitId:l,subUnitId:u,copyRange:d,copyType:f}=t;if(It.includes(o))return{redos:[],undos:[]};let p=this._sheetSkeletonService.getSkeleton(r,i);if(!p)return{redos:[],undos:[]};let{drawings:m}=this._copyInfo;if(!d)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:r,subUnitId:i,range:(0,s.discreteRangeToRange)(a)},pasteType:o},f);let h=this._sheetSkeletonService.getSkeleton(l,u);if(!h)return{redos:[],undos:[]};let{ranges:[g,_],mapFunc:v}=(0,c.virtualizeDiscreteRanges)([d,a]),{row:y,col:b}=v(g.startRow,g.startColumn),{row:x,col:S}=v(_.startRow,_.startColumn),C=(0,s.attachRangeWithCoord)(h,{startRow:y,endRow:y,startColumn:b,endColumn:b}),w=(0,s.attachRangeWithCoord)(p,{startRow:x,endRow:x,startColumn:S,endColumn:S});if(!C||!w)return{redos:[],undos:[]};let T=w.startX-C.startX,E=w.startY-C.startY,D=x-y,O=S-b;return this._generateMutations(m,{unitId:r,subUnitId:i,getTransform:(e,t)=>{let r={...e,left:((e==null?void 0:e.left)??0)+T,top:((e==null?void 0:e.top)??0)+E};return{transform:r,sheetTransform:{...t,to:{...t.to,row:t.to.row+D,column:t.to.column+O},from:{...t.from,row:t.from.row+D,column:t.from.column+O}},axisAlignSheetTransform:(0,n.transformToAxisAlignPosition)(r,p)??t}},isCut:f===c.COPY_TYPE.CUT})}};Lt=L([I(0,c.ISheetClipboardService),I(1,r.IRenderManagerService),I(2,(0,t.Inject)(s.SheetSkeletonService)),I(3,o.IDrawingManagerService),I(4,l.IClipboardInterfaceService),I(5,t.ICommandService)],Lt);let Rt=[r.ObjectType.IMAGE,r.ObjectType.SHAPE,r.ObjectType.CHART,r.ObjectType.DRAWING_DOM],zt=class extends t.Disposable{constructor(e,t,n,r,i,a,o,s){super(),this._commandService=e,this._localeService=t,this._renderManagerService=n,this._permissionService=r,this._univerInstanceService=i,this._userManagerService=a,this._sheetPermissionCheckController=o,this._sheetDrawingService=s,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange(),this._initCommandPermissionCheck()}_initDrawingVisible(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$,r=(0,d.combineLatest)([e,n]);this.disposeWithMe(r.pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.tap)(t=>{if(!t){this._sheetDrawingService.setDrawingVisible(!1);return}let n=e.getUnitId(),r=t.getSheetId();this._permissionService.composePermission([new s.WorkbookViewPermission(n).id,new s.WorksheetViewPermission(n,r).id]).every(e=>e.value)?this._sheetDrawingService.setDrawingVisible(!0):this._handleDrawingVisibilityFalse(e,t)})):(this._sheetDrawingService.setDrawingVisible(!1),d.EMPTY))).subscribe())}_handleDrawingVisibilityFalse(e,t){this._sheetDrawingService.setDrawingVisible(!1);let n=e.getUnitId(),r=t.getSheetId(),i=this._sheetDrawingService.getDrawingData(n,r),a=Object.values(i),o=this._renderManagerService.getRenderUnitById(n),s=o==null?void 0:o.scene;s&&s.getAllObjectsByOrder().forEach(e=>{Rt.includes(e.objectType)&&a.some(t=>e.oKey.includes(t.drawingId))&&s.removeObject(e)})}_initDrawingEditable(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$,r=(0,d.combineLatest)([e,n]);this.disposeWithMe(r.pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.tap)(t=>{if(!t){this._sheetDrawingService.setDrawingEditable(!1);return}let n=e.getUnitId(),r=t.getSheetId();this._permissionService.composePermission([new s.WorkbookEditablePermission(n).id,new s.WorksheetEditPermission(n,r).id]).every(e=>e.value)?this._sheetDrawingService.setDrawingEditable(!0):this._handleDrawingEditableFalse(e,t)})):(this._sheetDrawingService.setDrawingEditable(!1),d.EMPTY))).subscribe())}_handleDrawingEditableFalse(e,t){this._sheetDrawingService.setDrawingEditable(!1);let n=e.getUnitId(),r=t.getSheetId(),i=this._sheetDrawingService.getDrawingData(n,r),a=Object.values(i),o=this._renderManagerService.getRenderUnitById(n),s=o==null?void 0:o.scene;s&&s.getAllObjectsByOrder().forEach(e=>{Rt.includes(e.objectType)&&a.some(t=>e.oKey.includes(t.drawingId))&&s.detachTransformerFrom(e)})}_initViewPermissionChange(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$;this.disposeWithMe((0,d.combineLatest)([e,n]).pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=t.getSheetId(),i=this._renderManagerService.getRenderUnitById(n),a=i==null?void 0:i.scene;if(!a)return d.EMPTY;let o=a.getTransformerByCreate();return this._permissionService.composePermission$([new s.WorkbookViewPermission(n).id,new s.WorksheetViewPermission(n,r).id]).pipe((0,d.map)(e=>e.every(e=>e.value)),(0,d.distinctUntilChanged)()).pipe((0,d.map)(e=>({permission:e,scene:a,transformer:o,unitId:n,subUnitId:r})))})):d.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:r,subUnitId:i})=>{this._sheetDrawingService.setDrawingVisible(e);let a=t.getAllObjectsByOrder(),o=this._sheetDrawingService.getDrawingData(r,i),s=Object.values(o);e?this._sheetDrawingService.addNotification(s):(a.forEach(e=>{Rt.includes(e.objectType)&&s.some(t=>e.oKey.includes(t.drawingId))&&t.removeObject(e)}),n.clearSelectedObjects())},complete:()=>{this._sheetDrawingService.setDrawingVisible(!0);let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),n=e==null?void 0:e.getActiveSheet(),r=e==null?void 0:e.getUnitId(),i=n==null?void 0:n.getSheetId();if(!r||!i)return;let a=this._sheetDrawingService.getDrawingData(r,i),o=Object.values(a);this._sheetDrawingService.addNotification(o)}}))}_initEditPermissionChange(){let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET),n=this._userManagerService.currentUser$;this.disposeWithMe((0,d.combineLatest)([e,n]).pipe((0,d.switchMap)(([e,t])=>e?e.activeSheet$.pipe((0,d.switchMap)(t=>{if(!t)return d.EMPTY;let n=e.getUnitId(),r=t.getSheetId(),i=this._renderManagerService.getRenderUnitById(n),a=i==null?void 0:i.scene;if(!a)return d.EMPTY;let o=a.getTransformerByCreate();return this._permissionService.composePermission$([new s.WorkbookEditablePermission(n).id,new s.WorksheetEditPermission(n,r).id]).pipe((0,d.map)(e=>e.every(e=>e.value)),(0,d.distinctUntilChanged)()).pipe((0,d.map)(e=>({permission:e,scene:a,transformer:o,unitId:n,subUnitId:r})))})):d.EMPTY)).subscribe({next:({permission:e,scene:t,transformer:n,unitId:r,subUnitId:i})=>{this._sheetDrawingService.setDrawingEditable(e);let a=t.getAllObjectsByOrder(),o=this._sheetDrawingService.getDrawingData(r,i),s=Object.values(o);e?(a.forEach(e=>{Rt.includes(e.objectType)&&s.some(t=>e.oKey.includes(t.drawingId))&&t.attachTransformerTo(e)}),this._sheetDrawingService.addNotification(s)):(a.forEach(e=>{Rt.includes(e.objectType)&&s.some(t=>e.oKey.includes(t.drawingId))&&t.detachTransformerFrom(e)}),n.clearSelectedObjects())},complete:()=>{let e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET);if(!e)return;let n=e.getUnitId(),r=e.getActiveSheet();if(!r)return;let i=r.getSheetId(),a=this._renderManagerService.getRenderUnitById(n),o=a==null?void 0:a.scene;if(!o)return;let s=this._sheetDrawingService.getDrawingData(n,i),c=Object.values(s);this._sheetDrawingService.setDrawingEditable(!0),o.getAllObjectsByOrder().forEach(e=>{Rt.includes(e.objectType)&&c.some(t=>e.oKey.includes(t.drawingId))&&o.detachTransformerFrom(e)})}}))}_initCommandPermissionCheck(){this.disposeWithMe(this._commandService.beforeCommandExecuted(e=>{let t,r;if(e.id===n.InsertSheetDrawingCommand.id||e.id===n.RemoveSheetDrawingCommand.id||e.id===n.SetSheetDrawingCommand.id){var i,a;let{drawings:n}=e.params;t=n==null||(i=n[0])==null?void 0:i.unitId,r=n==null||(a=n[0])==null?void 0:a.subUnitId}else if(e.id===n.SetSheetDrawingPlacementCommand.id){let n=Bt(e.params);t=n.unitId,r=n.subUnitId}else if(e.id===n.SetDrawingArrangeCommand.id){let n=e.params;t=n.unitId,r=n.subUnitId}t&&r&&(this._sheetPermissionCheckController.permissionCheckWithoutRange({workbookTypes:[s.WorkbookEditablePermission],worksheetTypes:[s.WorksheetEditPermission]},t,r)||this._sheetPermissionCheckController.blockExecuteWithoutPermission(this._localeService.t(`sheets-drawing-ui.permission.dialog.editErr`)))}))}};zt=L([I(0,(0,t.Inject)(t.ICommandService)),I(1,(0,t.Inject)(t.LocaleService)),I(2,r.IRenderManagerService),I(3,t.IPermissionService),I(4,t.IUniverInstanceService),I(5,(0,t.Inject)(t.UserManagerService)),I(6,(0,t.Inject)(s.SheetPermissionCheckController)),I(7,(0,t.Inject)(n.ISheetDrawingService))],zt);function Bt(e){return e?{unitId:`unitId`in e&&typeof e.unitId==`string`?e.unitId:void 0,subUnitId:`subUnitId`in e&&typeof e.subUnitId==`string`?e.subUnitId:void 0}:{}}function Vt(e,t,n,r){let{width:i,height:a,angle:o,left:s,top:c}=e.transform,l=ze({left:s??0,right:(s??0)+(i??0),top:c??0,bottom:(c??0)+(a??0)},t,n,r,void 0,!0),{scaleX:u,scaleY:f}=t.getAncestorScale(),p={startX:l.left,endX:l.right,startY:l.top,endY:l.bottom,rotate:o,width:i*u,height:a*f,absolute:l.absolute},m={position$:new d.BehaviorSubject(p),position:p,id:e.drawingId,componentKey:e.componentKey,onPointerMove:()=>{},onPointerDown:()=>{},onPointerUp:()=>{},onWheel:()=>{},unitId:e.unitId,data:e.data,props:e.props};return[e.drawingId,m]}let Ht=e=>{let{floatDomInfos:t,scene:n,skeleton:r,worksheet:i}=e,a=(0,p.useMemo)(()=>t.map(e=>Vt(e,n,r,i)),[t,n,r,i]);return(0,m.jsx)(`div`,{style:{position:`absolute`,top:0,left:0},children:a.map(([e,t])=>(0,m.jsx)(l.PrintFloatDomSingle,{layer:t,id:e,position:t.position},e))})};function Ut(e,t,n){let r=(0,l.connectInjector)(Ht,n);return(0,i.render)((0,m.jsx)(r,{...e}),t),()=>(0,i.unmount)(t)}let Wt=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._sheetPrintInterceptorService=e,this._drawingRenderService=t,this._drawingManagerService=n,this._renderManagerService=r,this._componetManager=i,this._injector=a,this._initPrinting(),this._initPrintingDom()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(e,n,r)=>{let{unitId:i,scene:a,subUnitId:o,resourceCollector:s}=n,c=this._drawingManagerService.getDrawingDataForUnit(i),l=c==null?void 0:c[o];return l&&l.order.forEach(e=>{let n=l.data[e];if(!n.hidden&&n.drawingType!==t.DrawingTypeEnum.DRAWING_CHART&&n.drawingType!==t.DrawingTypeEnum.DRAWING_DOM&&n.drawingType!==t.DrawingTypeEnum.DRAWING_BLOCK){let e=this._drawingRenderService.renderDrawing(n,a,{allowInactiveSheet:!0});e&&s.add(Promise.resolve(e))}}),r()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(e,n,r)=>{let{unitId:i,subUnitId:a}=n,o=this._renderManagerService.getRenderUnitById(i);if(!o)return r(e);let s=o.with(c.SheetSkeletonManagerService).getSkeletonParam(a);if(!s)return r(e);let l=this._drawingManagerService.getDrawingDataForUnit(i),u=l==null?void 0:l[n.subUnitId];if(!u)return r(e);let{scaleX:d,scaleY:f}=o.scene,p=e?{...e}:{startColumn:0,endColumn:0,endRow:0,startRow:0},m=u.order.map(e=>u.data[e]);return m.length?(m.forEach(e=>{if(!e.hidden&&!e.groupId&&e.transform&&t.Tools.isDefine(e.transform.left)&&t.Tools.isDefine(e.transform.top)&&t.Tools.isDefine(e.transform.width)&&t.Tools.isDefine(e.transform.height)){let t=s.skeleton.getCellIndexByOffset(e.transform.left,e.transform.top,d,f,{x:0,y:0}),n=s.skeleton.getCellIndexByOffset(e.transform.left+e.transform.width,e.transform.top+e.transform.height,d,f,{x:0,y:0});t.column<p.startColumn&&(p.startColumn=t.column),t.row<p.startRow&&(p.startRow=t.row),p.endRow<n.row&&(p.endRow=n.row),p.endColumn<n.column&&(p.endColumn=n.column)}}),r(p)):r(e)}}))}_initPrintingDom(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_DOM_COLLECT,{handler:(e,n,r)=>{let{unitId:i,subUnitId:a}=n,o=this._drawingManagerService.getDrawingDataForUnit(i),s=o==null?void 0:o[a];if(s){let i=s.order.map(e=>{let n=s.data[e];if(n.hidden)return null;if(n.drawingType===t.DrawingTypeEnum.DRAWING_DOM||n.drawingType===t.DrawingTypeEnum.DRAWING_BLOCK){let e=this._sheetPrintInterceptorService.getPrintComponent(n.componentKey);return{...n,componentKey:this._componetManager.get(e||n.componentKey)}}return null}).filter(Boolean),a=document.createElement(`div`);a.style.position=`absolute`,a.style.inset=`0`,n.root.appendChild(a);let o=Ut({floatDomInfos:i,scene:n.scene,skeleton:n.skeleton,worksheet:n.worksheet},a,this._injector);return e==null||e.add(()=>{a.remove(),queueMicrotask(o)}),r(e)}return r(e)}}))}};Wt=L([I(0,(0,t.Inject)(c.SheetPrintInterceptorService)),I(1,(0,t.Inject)(u.DrawingRenderService)),I(2,o.IDrawingManagerService),I(3,r.IRenderManagerService),I(4,(0,t.Inject)(l.ComponentManager)),I(5,(0,t.Inject)(t.Injector))],Wt);let Gt={id:`sheet.command.toggle-flip-drawings`,type:t.CommandType.COMMAND,handler:(e,r)=>{if(!r)return!1;let i=e.get(t.ICommandService),a=e.get(t.IUndoRedoService),c=e.get(n.ISheetDrawingService),l=e.get(s.SheetSkeletonService),{drawings:u}=r,d=r.flipH,f=r.flipV,p=[],m=[];for(let r of u){let{unitId:i,subUnitId:a,drawingId:s}=r;p.push(i);let u=c.getDrawingData(i,a),h=u==null?void 0:u[s];if(!h)continue;let g=l.getSkeleton(i,a);if(!g)continue;let _={...h.transform};d&&(_.flipX=!_.flipX),f&&(_.flipY=!_.flipY);let v=(0,n.transformToDrawingPosition)(_,g),y=(0,n.transformToAxisAlignPosition)(_,g),b={unitId:i,subUnitId:a,drawingType:h.drawingType,drawingId:s,transform:_,sheetTransform:v,axisAlignSheetTransform:y};if(h.drawingType===t.DrawingTypeEnum.DRAWING_IMAGE){let t=Kt(e,i);if(t){let e=(0,o.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:s}),n=t.getObject(e);if(n){let e=n.srcRect;if(e){let t,{left:n=0,top:r=0,right:i=0,bottom:a=0}=e;if(d){let e=n+(i-n)/2;t={left:e-(i-n)/2,top:r,right:e+(i-n)/2,bottom:a}}if(f){let e=r+(a-r)/2;t={left:n,top:e-(a-r)/2,right:i,bottom:e+(a-r)/2}}t&&(b.srcRect=t)}}}}m.push(b)}if(m.length===0)return!1;let{unitId:h,subUnitId:g,undo:_,redo:v,objects:y}=c.getBatchUpdateOp(m),b={id:n.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:g,op:v,objects:y,type:n.DrawingApplyType.UPDATE}},x={id:n.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:g,op:_,objects:y,type:n.DrawingApplyType.UPDATE}};return(0,t.sequenceExecute)([b],i).result?(a.pushUndoRedo({unitID:h,undoMutations:[x,{id:n.ClearSheetDrawingTransformerOperation.id,params:p}],redoMutations:[b,{id:n.ClearSheetDrawingTransformerOperation.id,params:p}]}),!0):!1}};function Kt(e,t){let n=e.get(r.IRenderManagerService).getRenderUnitById(t);return n?n.scene:null}function qt(e){return e.getContextValue(t.FOCUSING_SHEET)&&!e.getContextValue(t.FOCUSING_FX_BAR_EDITOR)&&!e.getContextValue(t.FOCUSING_PANEL_EDITOR)&&e.getContextValue(t.FOCUSING_COMMON_DRAWINGS)&&!e.getContextValue(t.FOCUSING_SHAPE_TEXT_EDITOR)}let Jt={id:H.id,description:`sheets-drawing-ui.shortcut.drawing-move-down`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_DOWN,priority:100,preconditions:qt,staticParameters:{direction:t.Direction.DOWN}},Yt={id:H.id,description:`sheets-drawing-ui.shortcut.drawing-move-up`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_UP,priority:100,preconditions:qt,staticParameters:{direction:t.Direction.UP}},Xt={id:H.id,description:`sheets-drawing-ui.shortcut.drawing-move-left`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_LEFT,priority:100,preconditions:qt,staticParameters:{direction:t.Direction.LEFT}},Zt={id:H.id,description:`sheets-drawing-ui.shortcut.drawing-move-right`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,binding:l.KeyCode.ARROW_RIGHT,priority:100,preconditions:qt,staticParameters:{direction:t.Direction.RIGHT}},Qt={id:g.id,description:`sheets-drawing-ui.shortcut.drawing-delete`,group:`4_drawing-view`,groupTitle:`sheets-drawing-ui.shortcut.drawing-view`,priority:100,preconditions:qt,binding:l.KeyCode.DELETE,mac:l.KeyCode.BACKSPACE},$t=class extends t.Disposable{constructor(e,t,n,r){super(),this._commandService=e,this._shortcutService=t,this._drawingManagerService=n,this._sidebarService=r,this._init()}_initCustomComponents(){}_initCommands(){[B,V,ne,re,ae,oe,x,S,H,g,Q,Gt].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initShortcuts(){[Jt,Yt,Xt,Zt,Qt].forEach(e=>{this.disposeWithMe(this._shortcutService.registerShortcut(e))})}_initImagePanel(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(e=>{this._sidebarService.visible&&this._sidebarService.options.id===`COMPONENT_SHEET_DRAWING_PANEL`&&(e.length!==1||e[0].drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE)&&this._sidebarService.close(ie)}))}_init(){this._initCommands(),this._initCustomComponents(),this._initShortcuts(),this._initImagePanel()}};$t=L([I(0,t.ICommandService),I(1,l.IShortcutService),I(2,o.IDrawingManagerService),I(3,(0,t.Inject)(l.ISidebarService))],$t);let en=`sheet-mobile-image-actions`,tn=class extends t.RxDisposable{constructor(e,t,n,r,i,a,o,s,c,l,u,d){super(),this._localeService=e,this._drawingManagerService=t,this._canvasPopManagerService=n,this._renderManagerService=r,this._univerInstanceService=i,this._messageService=a,this._menuManagerService=o,this._contextService=s,this._ioService=c,this._commandService=l,this._dialogService=u,this._layoutService=d,F(this,`_initImagePopupMenu`,new Set),this._init()}_init(){this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(e=>this._create(e))),this.disposeWithMe(this._univerInstanceService.getTypeOfUnitDisposed$(t.UniverInstanceType.UNIVER_SHEET).subscribe(e=>this._dispose(e))),this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._create(e)),this._setupLoadingStatus()}_setupLoadingStatus(){let e;this.disposeWithMe(this._ioService.change$.subscribe(t=>{t>0&&!e?e=this._messageService.show({id:`image-upload-loading`,type:i.MessageType.Loading,content:`${this._localeService.t(`sheets-drawing-ui.uploadLoading.loading`)}: ${t}`,duration:0}):t===0&&(e==null||e.dispose(),e=void 0)}))}_dispose(e){super.dispose();let t=e.getUnitId();this._renderManagerService.removeRender(t),this._initImagePopupMenu.delete(t)}_create(e){if(!e)return;let t=e.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(e){for(let t of e.getAllObjectsByOrder())if(t instanceof u.ImageCropperObject)return!0;return!1}_openDrawingPopup(e,n,r){if(this._hasCropObject(e))return null;let i=this._drawingManagerService.getDrawingOKey(n.oKey);if(!i)return null;let{unitId:a,subUnitId:o,drawingId:s,drawingType:c}=i,l=i.data;if(l&&(l.disablePopup||l.version===1&&typeof l.embedId==`string`))return null;let d=[...this._canvasPopManagerService.getFeatureMenu(a,o,s,c)||this._getImageMenuItems(a,o,s,c),...this._getFloatingObjectMenuItems()],f=this._canvasPopManagerService.getFeatureMenuTitle(c)??(c===t.DrawingTypeEnum.DRAWING_IMAGE?`sheets-drawing-ui.title`:`sheets-drawing-ui.image-popup.edit`);return r(),this._dialogService.open({id:en,title:{title:this._localeService.t(f)},children:{label:{name:u.COMPONENT_MOBILE_IMAGE_POPUP_MENU,props:{popup:{extraProps:{menuItems:d,dialogId:en}}}}}}),(0,t.toDisposable)(()=>this._dialogService.close(en))}_trackActivePointer(e){let n=this._layoutService.getContentElement(),r,i=e=>{e.isPrimary&&e.button===0&&(r=e.pointerId)},a=t=>{t.pointerId===r&&(r=void 0,e())};return n==null||n.addEventListener(`pointerdown`,i,!0),n==null||n.addEventListener(`pointerup`,a,!0),n==null||n.addEventListener(`pointercancel`,a,!0),{getActivePointerId:()=>r,disposable:(0,t.toDisposable)(()=>{n==null||n.removeEventListener(`pointerdown`,i,!0),n==null||n.removeEventListener(`pointerup`,a,!0),n==null||n.removeEventListener(`pointercancel`,a,!0)})}}_getSelectedDrawingObject(e,t){let n=e.getSelectedObjectMap();if(n.size!==1)return null;let r=n.values().next().value,i=r?this._drawingManagerService.getDrawingOKey(r.oKey):null;return r&&(i==null?void 0:i.unitId)===t.unitId&&i.subUnitId===t.subUnitId&&i.drawingId===t.drawingId?r:null}_popupMenuListener(e){var n;let r=(n=this._renderManagerService.getRenderUnitById(e))==null?void 0:n.scene;if(!r)return;let i=r.getTransformerByCreate();if(!i)return;let a,s,c=()=>{s!==void 0&&(clearTimeout(s),s=void 0)},l=this._trackActivePointer(c);this.disposeWithMe(l.disposable),this.disposeWithMe((0,t.toDisposable)(()=>{c(),a==null||a.dispose()})),this.disposeWithMe(i.createControl$.subscribe(()=>{c(),this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!0)})),this.disposeWithMe(i.changeStart$.subscribe(({target:e,objects:t})=>{if(c(),a==null||a.dispose(),l.getActivePointerId()===void 0||!e||t.size!==1||this._hasCropObject(r))return;let n=this._drawingManagerService.getDrawingOKey(e.oKey);n&&(s=setTimeout(()=>{s=void 0;let e=this._getSelectedDrawingObject(i,n);if(!e)return;let t=this._openDrawingPopup(r,e,()=>a==null?void 0:a.dispose());t&&(a=t)},500))})),this.disposeWithMe(i.clearControl$.subscribe(()=>{c(),a==null||a.dispose(),this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(e=>{e[t.FOCUSING_COMMON_DRAWINGS]===!1&&(a==null||a.dispose())})),this.disposeWithMe(i.changing$.subscribe(()=>{c(),a==null||a.dispose()})),this.disposeWithMe(i.changeEnd$.subscribe(()=>{c()}))}_getImageMenuItems(e,r,i,a){return[{label:`sheets-drawing-ui.image-popup.edit`,index:0,commandId:oe.id,commandParams:{unitId:e,subUnitId:r,drawingId:i},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.delete`,index:1,commandId:n.RemoveSheetDrawingCommand.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:!1},{label:`sheets-drawing-ui.image-popup.crop`,index:2,commandId:u.OpenImageCropOperation.id,commandParams:{unitId:e,subUnitId:r,drawingId:i},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.flipH`,index:2,commandId:Gt.id,commandParams:{unitId:e,flipH:!0,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.flipV`,index:2,commandId:Gt.id,commandParams:{unitId:e,flipV:!0,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.reset`,index:3,commandId:u.ImageResetSizeOperation.id,commandParams:[{unitId:e,subUnitId:r,drawingId:i}],disable:a===t.DrawingTypeEnum.DRAWING_DOM}]}_getFloatingObjectMenuItems(){return this._menuManagerService.getFlatMenuByPositionKey(l.FloatingObjectToolbarPosition.SHEET).flatMap(({item:e},t)=>!e||e.type!==l.MenuItemType.BUTTON||!e.title?[]:[{label:e.title,index:100+t,commandId:e.commandId??e.id,commandParams:typeof e.params==`function`?e.params():e.params,disable:!1}])}};tn=L([I(0,(0,t.Inject)(t.LocaleService)),I(1,o.IDrawingManagerService),I(2,(0,t.Inject)(c.SheetCanvasPopManagerService)),I(3,r.IRenderManagerService),I(4,t.IUniverInstanceService),I(5,l.IMessageService),I(6,l.IMenuManagerService),I(7,t.IContextService),I(8,t.IImageIoService),I(9,t.ICommandService),I(10,l.IDialogService),I(11,l.ILayoutService)],tn);let nn={[l.RibbonInsertGroup.MEDIA]:{[Je]:{order:0,menuItemFactory:Ye,[B.id]:{order:0,menuItemFactory:Xe},[V.id]:{order:1,menuItemFactory:Ze}}},[l.RibbonDataGroup.ORGANIZATION]:{[tt]:{order:22,menuItemFactory:it,[ne.id]:{order:0,menuItemFactory:at},[re.id]:{order:1,menuItemFactory:ot}}},[l.ContextMenuPosition.MAIN_AREA]:{[l.ContextMenuGroup.OTHERS]:{[Q.id]:{order:10,menuItemFactory:et}}},[l.ContextMenuPosition.COL_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[Q.id]:{order:10,menuItemFactory:et}}},[l.ContextMenuPosition.ROW_HEADER]:{[l.ContextMenuGroup.OTHERS]:{[Q.id]:{order:10,menuItemFactory:et}}}},rn=class extends t.Disposable{constructor(e){super(),e.mergeMenu(nn)}};rn=L([I(0,l.IMenuManagerService)],rn);let an=class extends t.Disposable{constructor(e,t,n){super(),this._drawingManagerService=e,this._univerInstanceService=t,this._renderManagerService=n,F(this,`_onDoubleClick$`,new d.Subject),F(this,`onDoubleClick$`,this._onDoubleClick$.asObservable()),F(this,`_doubleClickDisposable`,null),F(this,`_boundRender`,null),F(this,`_boundScene`,null),this._init()}dispose(){this._disposeDoubleClickListener(),this._onDoubleClick$.complete(),super.dispose()}hitTestCurrentSheet(e,t){let n=this._getActiveSheetContext();return n?this.hitTest(n.unitId,n.subUnitId,e,t):null}hitTest(e,t,n,r){var i;let a=(i=this._renderManagerService.getRenderUnitById(e))==null?void 0:i.scene;return a?this._hitTestScene(a,e,t,n,r):null}_init(){this.disposeWithMe((0,t.toDisposable)(this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(()=>{this._bindDoubleClickListener()}))),this.disposeWithMe((0,t.toDisposable)(this._renderManagerService.created$.subscribe(e=>{let t=this._getActiveSheetContext();e.unitId===(t==null?void 0:t.unitId)&&this._bindDoubleClickListener()}))),this.disposeWithMe((0,t.toDisposable)(this._renderManagerService.disposed$.subscribe(e=>{var t;e===((t=this._boundRender)==null?void 0:t.unitId)&&this._disposeDoubleClickListener()}))),this._bindDoubleClickListener()}_bindDoubleClickListener(){let e=this._getActiveSheetContext();if(!e){this._disposeDoubleClickListener();return}let t=this._renderManagerService.getRenderUnitById(e.unitId),n=t==null?void 0:t.scene;if(!t||!n){this._disposeDoubleClickListener();return}if(this._boundRender===t&&this._boundScene===n&&this._doubleClickDisposable)return;this._disposeDoubleClickListener();let r=n.onDblclick$.subscribeEvent(t=>{let r=this._getActiveSheetContext();if(!r||r.unitId!==e.unitId)return;let i=this._hitTestScene(n,r.unitId,r.subUnitId,t.offsetX,t.offsetY);i&&this._onDoubleClick$.next({...i,nativeEvent:t})});this._doubleClickDisposable={dispose:()=>r.unsubscribe()},this._boundRender=t,this._boundScene=n}_disposeDoubleClickListener(){var e;(e=this._doubleClickDisposable)==null||e.dispose(),this._doubleClickDisposable=null,this._boundRender=null,this._boundScene=null}_hitTestScene(e,t,n,i,a){let o=e.pick(r.Vector2.FromArray([i,a])),s=typeof(o==null?void 0:o.oKey)==`string`?o.oKey:null;if(!s)return null;let c=this._drawingManagerService.getDrawingOKey(s);return!c||c.unitId!==t||c.subUnitId!==n?null:{drawing:c,oKey:s,offsetX:i,offsetY:a}}_getActiveSheetContext(){var e;let n=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET),r=n==null?void 0:n.getUnitId(),i=n==null||(e=n.getActiveSheet())==null?void 0:e.getSheetId();return!r||!i?null:{unitId:r,subUnitId:i}}};an=L([I(0,o.IDrawingManagerService),I(1,t.IUniverInstanceService),I(2,r.IRenderManagerService)],an);let on=class extends t.Plugin{constructor(e=dt,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerService=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},dt,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(ut,o)}onStarting(){let e=[[xt],[Be],[an],[$t],[rn],[tn],[Wt],[zt],[Lt],[ce],[Dt],[Ot],[At],[W,{useClass:X}],[ft,{useClass:pt}],[mt]];(0,t.registerDependencies)(this._injector,(0,t.mergeOverrideWithDependencies)(e,this._config.overrides)),qe(this._injector),this._injector.get(xt)}onReady(){(0,t.touchDependencies)(this._injector,[[Lt],[At],[ce]])}onRendered(){this._registerRenderModules(),(0,t.touchDependencies)(this._injector,[[zt],[Wt],[$t],[rn],[Dt],[Ot]])}onSteady(){this._injector.get(tn),this._injector.get(mt)}_registerRenderModules(){[[z],[jt],[Ct],[St],[Tt]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,e))})}};F(on,`type`,t.UniverInstanceType.UNIVER_SHEET),F(on,`pluginName`,`SHEET_IMAGE_UI_PLUGIN`),F(on,`packageName`,ct),F(on,`version`,lt),on=L([(0,t.DependentOn)(o.UniverDrawingPlugin,r.UniverRenderEnginePlugin,f.UniverDocsDrawingPlugin,s.UniverSheetsPlugin,n.UniverSheetsDrawingPlugin,u.UniverDrawingMobileUIPlugin,c.UniverSheetsMobileUIPlugin,l.UniverMobileUIPlugin),I(1,(0,t.Inject)(t.Injector)),I(2,r.IRenderManagerService),I(3,t.IConfigService)],on);let sn=class extends t.Disposable{constructor(e){super(),this._componentManager=e,this._registerComponents()}_registerComponents(){this.disposeWithMe(this._componentManager.register(ie,bt)),this.disposeWithMe(this._componentManager.register(Z,ht))}};sn=L([I(0,(0,t.Inject)(l.ComponentManager))],sn);let cn=class extends t.RxDisposable{constructor(e,t,n,r,i,a,o,s,c,l){super(),this._localeService=e,this._drawingManagerService=t,this._canvasPopManagerService=n,this._renderManagerService=r,this._univerInstanceService=i,this._messageService=a,this._menuManagerService=o,this._contextService=s,this._ioService=c,this._commandService=l,F(this,`_initImagePopupMenu`,new Set),this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).subscribe(e=>this._create(e)),this._univerInstanceService.getTypeOfUnitDisposed$(t.UniverInstanceType.UNIVER_SHEET).subscribe(e=>this._dispose(e)),this._univerInstanceService.getAllUnitsForType(t.UniverInstanceType.UNIVER_SHEET).forEach(e=>this._create(e)),this._setupLoadingStatus()}_setupLoadingStatus(){let e;this.disposeWithMe(this._ioService.change$.subscribe(t=>{t>0&&!e?e=this._messageService.show({id:`image-upload-loading`,type:i.MessageType.Loading,content:`${this._localeService.t(`sheets-drawing-ui.uploadLoading.loading`)}: ${t}`,duration:0}):t===0&&(e==null||e.dispose(),e=void 0)}))}_dispose(e){super.dispose();let t=e.getUnitId();this._renderManagerService.removeRender(t),this._initImagePopupMenu.delete(t)}_create(e){if(!e)return;let t=e.getUnitId();this._renderManagerService.has(t)&&!this._initImagePopupMenu.has(t)&&(this._popupMenuListener(t),this._initImagePopupMenu.add(t))}_hasCropObject(e){let t=e.getAllObjectsByOrder();for(let e of t)if(e instanceof u.ImageCropperObject)return!0;return!1}_popupMenuListener(e){var n;let r=(n=this._renderManagerService.getRenderUnitById(e))==null?void 0:n.scene;if(!r)return;let i=r.getTransformerByCreate();if(!i)return;let a;this.disposeWithMe(i.createControl$.subscribe(()=>{a==null||a.dispose(),a=this._createPopup(r,i)})),this.disposeWithMe(i.clearControl$.subscribe(()=>{a==null||a.dispose(),this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(o.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(e=>{e[t.FOCUSING_COMMON_DRAWINGS]===!1&&(a==null||a.dispose())})),this.disposeWithMe(i.changing$.subscribe(()=>{a==null||a.dispose()}))}_createPopup(e,n){if(this._contextService.setContextValue(t.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(e))return;let r=n.getSelectedObjectMap();if(r.size>1)return;let i=r.values().next().value;if(!i)return;let a=this._drawingManagerService.getDrawingOKey(i.oKey);if(!a||a.drawingType===t.DrawingTypeEnum.DRAWING_SHAPE)return;let{unitId:o,subUnitId:s,drawingId:c,drawingType:l}=a,d=a.data;if(d&&(d.disablePopup||d.version===1&&typeof d.embedId==`string`))return;let f=[...this._canvasPopManagerService.getFeatureMenu(o,s,c,l)||this._getImageMenuItems(o,s,c,l),...this._getFloatingObjectMenuItems()];return this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(i,{componentKey:u.COMPONENT_IMAGE_POPUP_MENU,constrainToCanvas:!0,direction:this._localeService.getDirection()===`rtl`?`left`:`horizontal`,offset:[2,0],extraProps:{menuItems:f}}))}_getImageMenuItems(e,r,i,a){return[{label:`sheets-drawing-ui.image-popup.edit`,index:0,commandId:oe.id,commandParams:{unitId:e,subUnitId:r,drawingId:i},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.delete`,index:1,commandId:n.RemoveSheetDrawingCommand.id,commandParams:{unitId:e,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:!1},{label:`sheets-drawing-ui.image-popup.crop`,index:2,commandId:u.OpenImageCropOperation.id,commandParams:{unitId:e,subUnitId:r,drawingId:i},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.flipH`,index:2,commandId:Gt.id,commandParams:{unitId:e,flipH:!0,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.flipV`,index:2,commandId:Gt.id,commandParams:{unitId:e,flipV:!0,drawings:[{unitId:e,subUnitId:r,drawingId:i}]},disable:a===t.DrawingTypeEnum.DRAWING_DOM},{label:`sheets-drawing-ui.image-popup.reset`,index:3,commandId:u.ImageResetSizeOperation.id,commandParams:[{unitId:e,subUnitId:r,drawingId:i}],disable:a===t.DrawingTypeEnum.DRAWING_DOM}]}_getFloatingObjectMenuItems(){return this._menuManagerService.getFlatMenuByPositionKey(l.FloatingObjectToolbarPosition.SHEET).flatMap(({item:e},t)=>!e||e.type!==l.MenuItemType.BUTTON||!e.title?[]:[{label:e.title,index:100+t,commandId:e.commandId??e.id,commandParams:typeof e.params==`function`?e.params():e.params,disable:!1}])}};cn=L([I(0,(0,t.Inject)(t.LocaleService)),I(1,o.IDrawingManagerService),I(2,(0,t.Inject)(c.SheetCanvasPopManagerService)),I(3,r.IRenderManagerService),I(4,t.IUniverInstanceService),I(5,l.IMessageService),I(6,l.IMenuManagerService),I(7,t.IContextService),I(8,t.IImageIoService),I(9,t.ICommandService)],cn);let ln=class extends t.Disposable{constructor(e){super(),e.mergeMenu(st)}};ln=L([I(0,l.IMenuManagerService)],ln);let un=class extends t.Plugin{constructor(e=dt,n,r,i){super(),this._config=e,this._injector=n,this._renderManagerService=r,this._configService=i;let{menu:a,...o}=(0,t.merge)({},dt,this._config);a&&this._configService.setConfig(`menu`,a,{merge:!0}),this._configService.setConfig(ut,o)}onStarting(){(0,t.registerDependencies)(this._injector,[[sn],[Be],[an],[$t],[ln],[cn],[Wt],[zt],[Lt],[ce],[Dt],[Ot],[At],[W,{useClass:X}],[ft,{useClass:pt}],[mt]]),qe(this._injector),this._injector.get(sn)}onReady(){(0,t.touchDependencies)(this._injector,[[Lt],[At],[ce]])}onRendered(){this._registerRenderModules(),(0,t.touchDependencies)(this._injector,[[zt],[Wt],[$t],[ln],[Dt],[Ot]])}onSteady(){this._injector.get(cn),this._injector.get(mt)}_registerRenderModules(){[[z],[jt],[Ct],[St],[Tt]].forEach(e=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(t.UniverInstanceType.UNIVER_SHEET,e))})}};F(un,`type`,t.UniverInstanceType.UNIVER_SHEET),F(un,`pluginName`,`SHEET_IMAGE_UI_PLUGIN`),F(un,`packageName`,ct),F(un,`version`,lt),un=L([(0,t.DependentOn)(o.UniverDrawingPlugin,r.UniverRenderEnginePlugin,f.UniverDocsDrawingPlugin,s.UniverSheetsPlugin,n.UniverSheetsDrawingPlugin,u.UniverDrawingUIPlugin,c.UniverSheetsUIPlugin),I(1,(0,t.Inject)(t.Injector)),I(2,r.IRenderManagerService),I(3,t.IConfigService)],un),e.AddWorksheetBackgroundImageCommand=ne,Object.defineProperty(e,"BatchSaveImagesService",{enumerable:!0,get:function(){return X}}),e.DeleteDrawingsCommand=g,e.DeleteWorksheetBackgroundImageCommand=re,e.DrawingContextMenuService=pt,e.EditSheetDrawingOperation=oe,e.FileNamePart=U,e.GroupSheetDrawingCommand=x,e.IBatchSaveImagesService=W,e.IDrawingContextMenuService=ft,e.InsertFloatImageCommand=B,e.MoveDrawingsCommand=H,e.SHEETS_DRAWING_FLOATING_HOST_DEPENDENCIES=We,e.SHEETS_IMAGE_MENU_ID=Je,e.SHEET_CHART_RENDER_OBJECT_CONFIG=le,e.SHEET_FLOAT_DOM_PREFIX=de,e.SaveCellImagesCommand=Q,Object.defineProperty(e,"SheetCanvasFloatDomManagerService",{enumerable:!0,get:function(){return Be}}),e.SheetDrawingAnchor=_t,Object.defineProperty(e,"SheetDrawingHitTestService",{enumerable:!0,get:function(){return an}}),Object.defineProperty(e,"SheetDrawingUpdateController",{enumerable:!0,get:function(){return z}}),Object.defineProperty(e,"SheetsDrawingGroupCopyPasteController",{enumerable:!0,get:function(){return ce}}),e.SheetsDrawingUIMenuSchema=st,e.SidebarSheetDrawingOperation=ae,e.UngroupSheetDrawingCommand=S,Object.defineProperty(e,"UniverSheetsDrawingMobileUIPlugin",{enumerable:!0,get:function(){return on}}),Object.defineProperty(e,"UniverSheetsDrawingUIPlugin",{enumerable:!0,get:function(){return un}}),e.calcSheetFloatDomPosition=$,e.registerSheetsDrawingFloatingHostCapability=Ge});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/sheets-drawing-ui",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "private": false,
5
5
  "description": "Drawing UI integration for Univer Sheets.",
6
6
  "author": "DreamNum Co., Ltd. <developer@univer.ai>",
@@ -68,21 +68,21 @@
68
68
  "rxjs": ">=7.0.0"
69
69
  },
70
70
  "dependencies": {
71
- "@univerjs/core": "1.0.1",
72
- "@univerjs/design": "1.0.1",
73
- "@univerjs/docs": "1.0.1",
74
- "@univerjs/docs-drawing": "1.0.1",
75
- "@univerjs/docs-ui": "1.0.1",
76
- "@univerjs/drawing": "1.0.1",
77
- "@univerjs/drawing-ui": "1.0.1",
78
- "@univerjs/engine-render": "1.0.1",
79
- "@univerjs/sheets": "1.0.1",
80
- "@univerjs/sheets-drawing": "1.0.1",
81
- "@univerjs/sheets-ui": "1.0.1",
82
- "@univerjs/ui": "1.0.1"
71
+ "@univerjs/core": "1.0.3",
72
+ "@univerjs/design": "1.0.3",
73
+ "@univerjs/docs": "1.0.3",
74
+ "@univerjs/docs-drawing": "1.0.3",
75
+ "@univerjs/docs-ui": "1.0.3",
76
+ "@univerjs/drawing": "1.0.3",
77
+ "@univerjs/drawing-ui": "1.0.3",
78
+ "@univerjs/engine-render": "1.0.3",
79
+ "@univerjs/sheets": "1.0.3",
80
+ "@univerjs/sheets-drawing": "1.0.3",
81
+ "@univerjs/sheets-ui": "1.0.3",
82
+ "@univerjs/ui": "1.0.3"
83
83
  },
84
84
  "devDependencies": {
85
- "@univerjs-infra/shared": "1.0.1",
85
+ "@univerjs-infra/shared": "1.0.3",
86
86
  "postcss": "^8.5.28",
87
87
  "react": "18.3.1",
88
88
  "rxjs": "^7.8.2",