@univerjs/sheets-drawing-ui 0.5.5 → 0.6.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -9
- package/lib/es/facade.js +3 -0
- package/lib/es/index.js +1605 -1383
- package/lib/types/controllers/sheet-drawing-copy-paste.controller.d.ts +11 -5
- package/lib/types/controllers/sheet-drawing-update.controller.d.ts +2 -2
- package/lib/types/controllers/sheet-drawing.controller.d.ts +5 -1
- package/lib/types/facade/f-enum.d.ts +3 -0
- package/lib/types/facade/f-event.d.ts +6 -0
- package/lib/types/facade/f-over-grid-image.d.ts +6 -0
- package/lib/types/facade/f-univer.d.ts +6 -0
- package/lib/types/facade/f-worksheet.d.ts +5 -5
- package/lib/types/index.d.ts +1 -1
- package/lib/types/services/canvas-float-dom-manager.service.d.ts +13 -4
- package/lib/types/views/sheet-image-panel/SheetDrawingAnchor.d.ts +1 -2
- package/lib/types/views/sheet-image-panel/SheetDrawingPanel.d.ts +16 -2
- package/lib/types/views/upload-loading/UploadLoading.d.ts +16 -2
- package/lib/umd/index.js +1 -9
- package/package.json +16 -16
package/lib/umd/index.js
CHANGED
|
@@ -1,9 +1 @@
|
|
|
1
|
-
(function(b,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react"),require("@univerjs/docs-ui"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react","@univerjs/docs-ui","@univerjs/design"],d):(b=typeof globalThis<"u"?globalThis:b||self,d(b.UniverSheetsDrawingUi={},b.UniverCore,b.UniverDocsDrawing,b.UniverDrawing,b.UniverDrawingUi,b.UniverEngineRender,b.UniverSheetsDrawing,b.UniverSheetsUi,b.UniverUi,b.rxjs,b.UniverSheets,b.React,b.UniverDocsUi,b.UniverDesign))})(this,function(b,d,Se,O,ue,N,f,P,Y,j,w,Q,Rt,ne){"use strict";var er=Object.defineProperty;var tr=(b,d,Se)=>d in b?er(b,d,{enumerable:!0,configurable:!0,writable:!0,value:Se}):b[d]=Se;var q=(b,d,Se)=>tr(b,typeof d!="symbol"?d+"":d,Se);const Ft="sheets-drawing-ui.config",bt={},$={id:"sheet.operation.clear-drawing-transformer",type:d.CommandType.MUTATION,handler:(i,r)=>{const n=i.get(N.IRenderManagerService);return r.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Oe={id:"sheet.command.remove-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{var C,D,R;const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(w.SheetInterceptorService),o=i.get(f.ISheetDrawingService);if(!r)return!1;const{drawings:a}=r,s=[];a.forEach(y=>{const{unitId:T}=y;s.push(T)});const l=o.getBatchRemoveOp(a),{unitId:h,subUnitId:u,undo:c,redo:g,objects:m}=l,p=t.onCommandExecute({id:Oe.id,params:r}),_={id:f.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:u,op:g,objects:m,type:f.DrawingApplyType.REMOVE}},S={id:f.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:u,op:c,objects:m,type:f.DrawingApplyType.INSERT}};return d.sequenceExecute([...(C=p.preRedos)!=null?C:[],_,...p.redos],n)?(e.pushUndoRedo({unitID:h,undoMutations:[...(D=p.preUndos)!=null?D:[],S,...p.undos,{id:$.id,params:s}],redoMutations:[...(R=p.preRedos)!=null?R:[],_,...p.redos,{id:$.id,params:s}]}),!0):!1}},Et="COMPONENT_SHEET_DRAWING_PANEL",st={id:"sidebar.operation.sheet-image",type:d.CommandType.COMMAND,handler:async(i,r)=>{const n=i.get(Y.ISidebarService),e=i.get(d.LocaleService),t=i.get(d.IUniverInstanceService),o=i.get(d.ICommandService);if(!w.getSheetCommandTarget(t))return!1;switch(r.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Et},onClose:()=>{o.syncExecuteCommand(O.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:n.close();break}return!0}},ct={id:"sheet.operation.edit-sheet-image",type:d.CommandType.OPERATION,handler:(i,r)=>{const n=i.get(d.ICommandService);return r==null?!1:(n.syncExecuteCommand(O.SetDrawingSelectedOperation.id,[r]),n.executeCommand(st.id,{value:"open"}),!0)}};var dt={exports:{}},Pe={};/**
|
|
2
|
-
* @license React
|
|
3
|
-
* react-jsx-runtime.production.min.js
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the MIT license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var Ot;function $t(){if(Ot)return Pe;Ot=1;var i=Q,r=Symbol.for("react.element"),n=Symbol.for("react.fragment"),e=Object.prototype.hasOwnProperty,t=i.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function a(s,l,h){var u,c={},g=null,m=null;h!==void 0&&(g=""+h),l.key!==void 0&&(g=""+l.key),l.ref!==void 0&&(m=l.ref);for(u in l)e.call(l,u)&&!o.hasOwnProperty(u)&&(c[u]=l[u]);if(s&&s.defaultProps)for(u in l=s.defaultProps,l)c[u]===void 0&&(c[u]=l[u]);return{$$typeof:r,type:s,key:g,ref:m,props:c,_owner:t.current}}return Pe.Fragment=n,Pe.jsx=a,Pe.jsxs=a,Pe}var Pt;function Ht(){return Pt||(Pt=1,dt.exports=$t()),dt.exports}var K=Ht();const He={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Yt=()=>{const i=d.useDependency(O.IImageIoService),r=d.useDependency(d.LocaleService),[n,e]=Q.useState(0);return Q.useEffect(()=>{const t=i.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[i]),K.jsx("div",{style:{display:n>0?"block":"none"},className:He.uploadLoading,children:K.jsxs("div",{className:He.uploadLoadingBody,children:[K.jsx("div",{className:He.uploadLoadingBodyAnimation}),K.jsx("div",{className:He.uploadLoadingBodyText,children:`${r.t("uploadLoading.loading")}: ${n}`})]})})};var Vt=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,Xt=(i,r,n,e)=>{for(var t=e>1?void 0:e?xt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Vt(r,n,t),t},me=(i,r)=>(n,e)=>r(n,e,i);let Ye=class extends d.RxDisposable{constructor(r,n,e,t,o,a,s,l){super();q(this,"_initImagePopupMenu",new Set);this._injector=r,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=l,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(j.takeUntil(this.dispose$)).subscribe(r=>this._create(r)),this._univerInstanceService.getTypeOfUnitDisposed$(d.UniverInstanceType.UNIVER_SHEET).pipe(j.takeUntil(this.dispose$)).subscribe(r=>this._dispose(r)),this._univerInstanceService.getAllUnitsForType(d.UniverInstanceType.UNIVER_SHEET).forEach(r=>this._create(r)),this._uiPartsService.registerComponent(Y.BuiltInUIPart.CONTENT,()=>d.connectInjector(Yt,this._injector))}_dispose(r){const n=r.getUnitId();this._renderManagerService.removeRender(n)}_create(r){if(!r)return;const n=r.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(r){const n=r.getAllObjectsByOrder();for(const e of n)if(e instanceof ue.ImageCropperObject)return!0;return!1}_popupMenuListener(r){var o;const n=(o=this._renderManagerService.getRenderById(r))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(d.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const s=a.values().next().value;if(!s)return;const l=s.oKey,h=this._drawingManagerService.getDrawingOKey(l);if(!h)return;const{unitId:u,subUnitId:c,drawingId:g,drawingType:m}=h,p=h.data;if(p&&p.disablePopup)return;t==null||t.dispose();const _=this._canvasPopManagerService.getFeatureMenu(u,c,g,m);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:ue.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:_||this._getImageMenuItems(u,c,g,m)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(O.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[d.FOCUSING_COMMON_DRAWINGS]===!1&&(t==null||t.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(r,n,e,t){return[{label:"image-popup.edit",index:0,commandId:ct.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===d.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Oe.id,commandParams:{unitId:r,drawings:[{unitId:r,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ue.OpenImageCropOperation.id,commandParams:{unitId:r,subUnitId:n,drawingId:e},disable:t===d.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ue.ImageResetSizeOperation.id,commandParams:[{unitId:r,subUnitId:n,drawingId:e}],disable:t===d.DrawingTypeEnum.DRAWING_DOM}]}};Ye=Xt([me(0,d.Inject(d.Injector)),me(1,O.IDrawingManagerService),me(2,d.Inject(P.SheetCanvasPopManagerService)),me(3,N.IRenderManagerService),me(4,d.IUniverInstanceService),me(5,d.IContextService),me(6,d.Inject(Y.IUIPartsService)),me(7,d.ICommandService)],Ye);function z(i,r,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:l=0,skewY:h=0}=i,u=n.getCurrent();if(u==null)return;const c=P.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:t},n);let{left:g,top:m,width:p,height:_}=c;const S=n.getCurrentSkeleton(),v=S.rowHeaderWidth+S.columnTotalWidth,C=S.columnHeaderHeight+S.rowTotalHeight;return g+p>v&&(g=v-p),m+_>C&&(m=C-_),{flipY:o,flipX:a,angle:s,skewX:l,skewY:h,left:g,top:m,width:p,height:_}}function V(i,r){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:l=0,skewX:h=0,skewY:u=0}=i,c=r.getCellWithCoordByOffset(n,e);if(c==null)return;const g={column:c.actualColumn,columnOffset:N.precisionTo(n-c.startX,1),row:c.actualRow,rowOffset:N.precisionTo(e-c.startY,1)},m=r.getCellWithCoordByOffset(n+t,e+o);if(m==null)return;const p={column:m.actualColumn,columnOffset:N.precisionTo(n+t-m.startX,1),row:m.actualRow,rowOffset:N.precisionTo(e+o-m.startY,1)};return{flipY:a,flipX:s,angle:l,skewX:h,skewY:u,from:g,to:p}}var Kt=Object.defineProperty,zt=Object.getOwnPropertyDescriptor,Jt=(i,r,n,e)=>{for(var t=e>1?void 0:e?zt(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Kt(r,n,t),t},Ve=(i,r)=>(n,e)=>r(n,e,i);let lt=class extends d.Disposable{constructor(i,r,n,e,t){super(),this._context=i,this._sheetDrawingService=r,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const r in i){const n=i[r];for(const e in n.data){const t=n.data[e];t.transform=z(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};lt=Jt([Ve(1,f.ISheetDrawingService),Ve(2,O.IDrawingManagerService),Ve(3,d.Inject(P.ISheetSelectionRenderService)),Ve(4,d.Inject(P.SheetSkeletonManagerService))],lt);function Zt(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s}=e,l=N.getGroupState(0,0,t.map(c=>c.transform||{})),h=t.map(c=>{const g=c.transform||{left:0,top:0},{unitId:m,subUnitId:p,drawingId:_}=c;return{unitId:m,subUnitId:p,drawingId:_,transform:{...g,left:g.left-l.left,top:g.top-l.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:d.DrawingTypeEnum.DRAWING_GROUP,transform:l};r.push({parent:u,children:h})}),r}function qt(i){const r=[];return i.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s,transform:l={width:0,height:0}}=e;if(l==null)return;const h=t.map(c=>{const{transform:g}=c,{unitId:m,subUnitId:p,drawingId:_}=c,S=N.transformObjectOutOfGroup(g||{},l,l.width||0,l.height||0);return{unitId:m,subUnitId:p,drawingId:_,transform:S,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:d.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};r.push({parent:u,children:h})}),r}const ut={id:"sheet.command.group-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(f.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:m,children:p})=>{o.push(m.unitId),p.forEach(_=>{o.push(_.unitId)})});const a=t.getGroupDrawingOp(r),{unitId:s,subUnitId:l,undo:h,redo:u,objects:c}=a;return n.syncExecuteCommand(f.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:c,type:f.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:h,unitId:s,subUnitId:l,objects:qt(c),type:f.DrawingApplyType.UNGROUP}},{id:$.id,params:o}],redoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:c,type:f.DrawingApplyType.GROUP}},{id:$.id,params:o}]}),!0):!1}},Ae={id:"sheet.command.insert-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{var C,D,R;const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(f.ISheetDrawingService),o=i.get(w.SheetInterceptorService);if(!r)return!1;const a=r.drawings,s=a.map(y=>y.unitId),l=t.getBatchAddOp(a),{unitId:h,subUnitId:u,undo:c,redo:g,objects:m}=l,p=o.onCommandExecute({id:Ae.id,params:r}),_={id:f.SetDrawingApplyMutation.id,params:{op:g,unitId:h,subUnitId:u,objects:m,type:f.DrawingApplyType.INSERT}},S={id:f.SetDrawingApplyMutation.id,params:{op:c,unitId:h,subUnitId:u,objects:m,type:f.DrawingApplyType.REMOVE}};return d.sequenceExecute([...(C=p.preRedos)!=null?C:[],_,...p.redos],n)?(e.pushUndoRedo({unitID:h,undoMutations:[...(D=p.preUndos)!=null?D:[],S,...p.undos,{id:$.id,params:s}],redoMutations:[...(R=p.preRedos)!=null?R:[],_,...p.redos,{id:$.id,params:s}]}),!0):!1}},mt={id:"sheet.command.set-drawing-arrange",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService);if(!r)return!1;const t=i.get(f.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:l}=r,h={unitId:o,subUnitId:a,drawingIds:s};let u;if(l===d.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(h):l===d.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(h):l===d.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(h):l===d.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(h)),u==null)return!1;const{objects:c,redo:g,undo:m}=u;return n.syncExecuteCommand(f.SetDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:a,objects:c,type:f.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:m,unitId:o,subUnitId:a,objects:c,type:f.DrawingApplyType.ARRANGE}}],redoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:c,type:f.DrawingApplyType.ARRANGE}}]}),!0):!1}},Ue={id:"sheet.command.set-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(f.ISheetDrawingService);if(!r)return!1;const{drawings:o}=r,a=t.getBatchUpdateOp(o),{unitId:s,subUnitId:l,undo:h,redo:u,objects:c}=a;return n.syncExecuteCommand(f.SetDrawingApplyMutation.id,{unitId:s,subUnitId:l,op:u,objects:c,type:f.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:f.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:h,objects:c,type:f.DrawingApplyType.UPDATE}},{id:$.id,params:[s]}],redoMutations:[{id:f.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:l,op:u,objects:c,type:f.DrawingApplyType.UPDATE}},{id:$.id,params:[s]}]}),!0):!1}},gt={id:"sheet.command.ungroup-sheet-image",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(d.IUndoRedoService),t=i.get(f.ISheetDrawingService);if(!r)return!1;const o=[];r.forEach(({parent:m,children:p})=>{o.push(m.unitId),p.forEach(_=>{o.push(_.unitId)})});const a=t.getUngroupDrawingOp(r),{unitId:s,subUnitId:l,undo:h,redo:u,objects:c}=a;return n.syncExecuteCommand(f.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:l,objects:c,type:f.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:h,unitId:s,subUnitId:l,objects:Zt(c),type:f.DrawingApplyType.GROUP}},{id:$.id,params:o}],redoMutations:[{id:f.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:l,objects:c,type:f.DrawingApplyType.UNGROUP}},{id:$.id,params:o}]}),!0):!1}};var Qt=Object.defineProperty,en=Object.getOwnPropertyDescriptor,tn=(i,r,n,e)=>{for(var t=e>1?void 0:e?en(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Qt(r,n,t),t},ee=(i,r)=>(n,e)=>r(n,e,i);function nn(i,r,n){const e=n*Math.PI/180,t=Math.abs(i*Math.cos(e))+Math.abs(r*Math.sin(e)),o=Math.abs(i*Math.sin(e))+Math.abs(r*Math.cos(e));return{rotatedWidth:t,rotatedHeight:o}}function At(i,r,n,e,t){var C;const{rotatedHeight:o,rotatedWidth:a}=nn(n,e,t),l=i.get(N.IRenderManagerService).getRenderById(r.unitId);if(!l)return!1;const u=(C=l.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(r.subUnitId))==null?void 0:C.skeleton;if(u==null)return!1;const c=u.getCellByIndex(r.row,r.col),g=c.mergeInfo.endX-c.mergeInfo.startX-2,m=c.mergeInfo.endY-c.mergeInfo.startY-2,p=a/o,S=Math.ceil(Math.min(g,m*p))/a,v=!S||Number.isNaN(S)?.001:S;return{width:n*v,height:e*v}}let Ne=class extends d.Disposable{constructor(r,n,e,t,o,a,s,l,h,u,c,g,m){super();q(this,"_workbookSelections");this._context=r,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=s,this._drawingManagerService=l,this._contextService=h,this._messageService=u,this._localeService=c,this._injector=m,this._workbookSelections=g.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const r=await this._fileOpenerService.openFile({multiple:!0,accept:O.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),n=r.length;return n>O.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(O.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(r.forEach(async e=>await this._insertFloatImage(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:O.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return n?(await this._insertCellImage(n),!0):!1}async _insertFloatImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(C){const D=C.message;D===O.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(O.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):D===O.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):D===O.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:s,source:l,base64Cache:h}=n,{width:u,height:c,image:g}=await O.getImageSize(h||""),{width:m,height:p}=this._context.scene;this._imageIoService.addImageSourceCache(l,s,g);let _=1;if(u>O.DRAWING_IMAGE_WIDTH_LIMIT||c>O.DRAWING_IMAGE_HEIGHT_LIMIT){const C=O.DRAWING_IMAGE_WIDTH_LIMIT/u,D=O.DRAWING_IMAGE_HEIGHT_LIMIT/c;_=Math.max(C,D)}const S=this._getImagePosition(u*_,c*_,m,p);if(S==null)return;const v={unitId:t,subUnitId:o,drawingId:a,drawingType:d.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:l,transform:z(S,this._selectionRenderService,this._skeletonManagerService),sheetTransform:S};this._commandService.executeCommand(Ae.id,{unitId:t,drawings:[v]})}async _insertCellImage(r){let n;try{n=await this._imageIoService.saveImage(r)}catch(S){const v=S.message;v===O.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(O.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):v===O.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):v===O.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ne.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{imageId:e,imageSourceType:t,source:o,base64Cache:a}=n,{width:s,height:l,image:h}=await O.getImageSize(a||"");this._imageIoService.addImageSourceCache(o,t,h);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const c=d.createDocumentModelWithStyle("",{}),g=At(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},s,l,0);if(!g)return!1;const m={size:{width:g.width,height:g.height},positionH:{relativeFrom:d.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:d.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},p={unitId:c.getUnitId(),subUnitId:c.getUnitId(),drawingId:e,drawingType:d.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:Rt.docDrawingPositionToTransform(m),docTransform:m,behindDoc:d.BooleanNumber.FALSE,title:"",description:"",layoutType:d.PositionedObjectLayoutType.INLINE,wrapText:d.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},_=d.BuildTextUtils.drawing.add({documentDataModel:c,drawings:[p],selection:{collapsed:!0,startOffset:0,endOffset:0}});return _?(c.apply(_),this._commandService.syncExecuteCommand(w.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:c.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const r=this._context.unit,n=r.getActiveSheet(),e=r.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(r,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const s=P.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(s==null)return;let{startColumn:l,startRow:h,startX:u,startY:c}=s,g=!1;if(u+r>e&&(u=e-r,u<0&&(u=0,r=e),g=!0),c+n>t&&(c=t-n,c<0&&(c=0,n=t),g=!0),g){const S=this._selectionRenderService.getCellWithCoordByOffset(u,c);if(S==null)return;u=S.startX,c=S.startY,l=S.actualColumn,h=S.actualRow}const m={column:l,columnOffset:0,row:h,rowOffset:0},p=this._selectionRenderService.getCellWithCoordByOffset(u+r,c+n);if(p==null)return;const _={column:p.actualColumn,columnOffset:u+r-p.startX,row:p.actualRow,rowOffset:c+n-p.startY};return{from:m,to:_}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(r=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=r;this._commandService.executeCommand(mt.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(r=>{const n=[];r.length!==0&&(r.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:s,transform:l}=e;if(l==null)return;const h=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(h==null||h.unitId!==this._context.unitId)return;const u=V({...h.transform,...l},this._selectionRenderService);if(u==null)return;const c={...e,transform:{...h.transform,...l,...z(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(c)}),n.length>0&&this._commandService.executeCommand(Ue.id,{unitId:r[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(r=>{this._commandService.executeCommand(ut.id,r);const{unitId:n,subUnitId:e,drawingId:t}=r[0].parent;this._commandService.syncExecuteCommand(O.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(r=>{this._commandService.executeCommand(gt.id,r)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(r=>{r==null||r.length===0?(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(d.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(r))}))}};Ne=tn([ee(1,d.Inject(P.SheetSkeletonManagerService)),ee(2,d.ICommandService),ee(3,P.ISheetSelectionRenderService),ee(4,O.IImageIoService),ee(5,Y.ILocalFileService),ee(6,f.ISheetDrawingService),ee(7,O.IDrawingManagerService),ee(8,d.IContextService),ee(9,Y.IMessageService),ee(10,d.Inject(d.LocaleService)),ee(11,d.Inject(w.SheetsSelectionsService)),ee(12,d.Inject(d.Injector))],Ne);var rn=Object.defineProperty,on=Object.getOwnPropertyDescriptor,an=(i,r,n,e)=>{for(var t=e>1?void 0:e?on(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&rn(r,n,t),t},_e=(i,r)=>(n,e)=>r(n,e,i);function ht(i,r,n){var e,t,o,a;if(((t=(e=n==null?void 0:n.p)==null?void 0:e.body)==null?void 0:t.dataStream.length)===3&&((a=(o=n.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=n.p.drawings[n.p.drawingsOrder[0]],l=At(i,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(l)return s.transform.width=l.width,s.transform.height=l.height,s.docTransform.size.width=l.width,s.docTransform.size.height=l.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let xe=class extends d.Disposable{constructor(i,r,n,e,t,o,a){super(),this._commandService=i,this._sheetInterceptorService=r,this._univerInstanceService=n,this._injector=e,this._drawingManagerService=t,this._docDrawingController=o,this._editorBridgeService=a,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{let r,n=[];if(i.id===w.SetWorksheetRowHeightMutation.id){const e=i.params;n=e.ranges,r=w.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===w.SetWorksheetColWidthMutation.id){const e=i.params;n=e.ranges,r=w.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===w.SetWorksheetRowIsAutoHeightMutation.id){const e=i.params;n=e.ranges,r=w.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===w.SetWorksheetRowAutoHeightMutation.id){const e=i.params;r=w.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),n=e.rowsAutoHeightInfo.map(t=>({startRow:t.row,endRow:t.row,startColumn:0,endColumn:9999}))}else if(i.id===w.AddWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=w.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(i.id===w.RemoveWorksheetMergeMutation.id){const e=i.params;n=e.ranges,r=w.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}r&&n.length&&n.forEach(e=>{const t=d.Range.transformRange(e,r.worksheet);for(let o=t.startRow;o<=t.endRow;o++)for(let a=t.startColumn;a<=t.endColumn;a++)ht(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:o,col:a},r.worksheet.getCellRaw(o,a))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(i=>{i.visible?i.visible&&(this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===Rt.ReplaceSnapshotCommand.id&&i.params.unitId===d.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(d.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(w.AFTER_CELL_EDIT,{priority:9999,handler:(i,r,n)=>(ht(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:r.row,col:r.col},i),n(i))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(w.INTERCEPTOR_POINT.CELL_CONTENT,{effect:d.InterceptorEffectEnum.Style,priority:w.InterceptCellContentPriority.CELL_IMAGE,handler:(i,r,n)=>{var e;return i!=null&&i.p&&((e=i.p.drawingsOrder)!=null&&e.length)&&(i.interceptorStyle||(i.interceptorStyle={}),i.interceptorStyle.tr={a:0}),n(i)}}))}};xe=an([_e(0,d.ICommandService),_e(1,d.Inject(w.SheetInterceptorService)),_e(2,d.IUniverInstanceService),_e(3,d.Inject(d.Injector)),_e(4,O.IDrawingManagerService),_e(5,d.Inject(Se.DocDrawingController)),_e(6,d.Inject(P.IEditorBridgeService))],xe);var sn=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,dn=(i,r,n,e)=>{for(var t=e>1?void 0:e?cn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&sn(r,n,t),t},Ut=(i,r)=>(n,e)=>r(n,e,i);let Xe=class extends d.Disposable{constructor(i,r){super(),this._autoFillService=i,this._injector=r,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(i,r,n,e)=>{new d.ObjectMatrix(e).forValue((t,o,a)=>{ht(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:t,col:o},a)})}}))}};Xe=dn([Ut(0,d.Inject(P.IAutoFillService)),Ut(1,d.Inject(d.Injector))],Xe);var ln=Object.defineProperty,un=Object.getOwnPropertyDescriptor,mn=(i,r,n,e)=>{for(var t=e>1?void 0:e?un(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&ln(r,n,t),t},Ke=(i,r)=>(n,e)=>r(n,e,i);let ze=class extends d.Disposable{constructor(r,n,e,t){super();q(this,"_isSetCursor",!1);this._hoverManagerService=r,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};ze=mn([Ke(0,d.Inject(P.HoverManagerService)),Ke(1,d.Inject(N.IRenderManagerService)),Ke(2,d.Inject(w.SheetsSelectionsService)),Ke(3,d.Inject(ue.DrawingRenderService))],ze);var gn=Object.defineProperty,hn=Object.getOwnPropertyDescriptor,pn=(i,r,n,e)=>{for(var t=e>1?void 0:e?hn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&gn(r,n,t),t},pt=(i,r)=>(n,e)=>r(n,e,i);let Je=class extends d.Disposable{constructor(r,n,e){super();q(this,"_copyInfo");this._sheetClipboardService=r,this._renderManagerService=n,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(r,n,e)=>this._collect(r,n,e),onPasteCells:(r,n,e,t)=>{const{copyType:o=P.COPY_TYPE.COPY,pasteType:a}=t,{range:s}=r||{},{range:l,unitId:h,subUnitId:u}=n;return this._generateMutations(l,{copyType:o,pasteType:a,copyRange:s,unitId:h,subUnitId:u})},onPastePlainText:(r,n)=>({undos:[],redos:[]})})}_collect(r,n,e){var g;const t=(g=this._renderManagerService.getRenderById(r))==null?void 0:g.with(P.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:l,endY:h}=o,u=this._sheetDrawingService.getDrawingData(r,n),c=[];Object.keys(u).forEach(m=>{const p=u[m],{transform:_}=p;if(p.anchorType!==f.SheetDrawingAnchorType.Both||!_)return;const{left:S=0,top:v=0,width:C=0,height:D=0}=_,{drawingStartX:R,drawingEndX:y,drawingStartY:T,drawingEndY:I}={drawingStartX:S,drawingEndX:S+C,drawingStartY:v,drawingEndY:v+D};a<=R&&y<=s&&l<=T&&I<=h&&c.push(p)}),c.length&&(this._copyInfo={drawings:c,unitId:r,subUnitId:n})}_generateMutations(r,n){var F;if(!this._copyInfo)return{redos:[],undos:[]};if([P.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,P.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,P.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,P.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(n.pasteType))return{redos:[],undos:[]};const{copyRange:t}=n;if(!t)return{redos:[],undos:[]};const{drawings:o,unitId:a,subUnitId:s}=this._copyInfo,{ranges:[l,h],mapFunc:u}=P.virtualizeDiscreteRanges([t,r]),{row:c,col:g}=u(l.startRow,l.startColumn),{row:m,col:p}=u(h.startRow,h.startColumn),_=(F=this._renderManagerService.getRenderById(a))==null?void 0:F.with(P.SheetSkeletonManagerService);if(!_)return{redos:[],undos:[]};const S=_.attachRangeWithCoord({startRow:c,endRow:c,startColumn:g,endColumn:g}),v=_.attachRangeWithCoord({startRow:m,endRow:m,startColumn:p,endColumn:p});if(!S||!v)return{redos:[],undos:[]};const C=[],D=[],R=v.startX-S.startX,y=v.startY-S.startY,T=m-c,I=p-g,U=n.copyType===P.COPY_TYPE.CUT,{_sheetDrawingService:E}=this;return o.forEach(B=>{const{transform:A,sheetTransform:M}=B;if(!A)return;const L={...B,unitId:a,subUnitId:s,drawingId:U?B.drawingId:d.Tools.generateRandomId(),transform:{...A,left:A.left+R,top:A.top+y},sheetTransform:{to:{...M.to,row:M.to.row+T,column:M.to.column+I},from:{...M.from,row:M.from.row+T,column:M.from.column+I}}};if(U){const{undo:G,redo:x,objects:W}=E.getBatchUpdateOp([L]);C.push({id:f.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:s,type:f.DrawingApplyType.UPDATE,op:x,objects:W}}),D.push({id:f.SetDrawingApplyMutation.id,params:{unitId:a,subUnitId:s,type:f.DrawingApplyType.UPDATE,op:G,objects:W}})}else{const{undo:G,redo:x,objects:W}=E.getBatchAddOp([L]);C.push({id:f.SetDrawingApplyMutation.id,params:{op:x,unitId:a,subUnitId:s,objects:W,type:f.DrawingApplyType.INSERT}}),D.push({id:f.SetDrawingApplyMutation.id,params:{op:G,unitId:a,subUnitId:s,objects:W,type:f.DrawingApplyType.REMOVE}})}}),{redos:C,undos:D}}};Je=pn([pt(0,P.ISheetClipboardService),pt(1,N.IRenderManagerService),pt(2,f.ISheetDrawingService)],Je);var fn=Object.defineProperty,Sn=Object.getOwnPropertyDescriptor,_n=(i,r,n,e)=>{for(var t=e>1?void 0:e?Sn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&fn(r,n,t),t},je=(i,r)=>(n,e)=>r(n,e,i);let Ze=class extends d.Disposable{constructor(i,r,n,e,t){super(),this._drawingManagerService=i,this._renderManagerService=r,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingVisible(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new w.WorkbookViewPermission(t).id,new w.WorksheetViewPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const s=r.getUnitId(),l=e.getSheetId(),h=this._drawingManagerService.getDrawingData(s,l),u=Object.values(h),c=this._renderManagerService.getRenderById(s),g=c==null?void 0:c.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(p=>{p.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(_=>p.oKey.includes(_.drawingId))&&g.removeObject(p)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{if(!r){this._drawingManagerService.setDrawingEditable(!1);return}r.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=r.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new w.WorkbookEditablePermission(t).id,new w.WorksheetEditPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const s=r.getUnitId(),l=e.getSheetId(),h=this._drawingManagerService.getDrawingData(s,l),u=Object.values(h),c=this._renderManagerService.getRenderById(s),g=c==null?void 0:c.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(p=>{p.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(_=>p.oKey.includes(_.drawingId))&&g.detachTransformerFrom(p)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var c;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),l=s==null?void 0:s.scene;if(l==null)return;const h=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new w.WorkbookViewPermission(t).id,new w.WorksheetViewPermission(t,o).id]).pipe(j.map(g=>g.every(m=>m.value)));u==null||u.pipe(j.filter(g=>g!==a),j.distinctUntilChanged()).subscribe({next:g=>{a=g,this._drawingManagerService.setDrawingVisible(g);const m=l.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),_=Object.values(p);g?this._drawingManagerService.addNotification(_):(m.forEach(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&_.some(v=>S.oKey.includes(v.drawingId))&&l.removeObject(S)}),h.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new w.WorksheetViewPermission(t,o).id))==null||c.pipe(j.filter(g=>g.value!==a),j.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const g=this._drawingManagerService.getDrawingData(t,o),m=Object.values(g);this._drawingManagerService.addNotification(m)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(j.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([r,n])=>{r&&r.activeSheet$.subscribe(e=>{var c;if(!e)return;const t=r.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),l=s==null?void 0:s.scene;if(l==null)return;const h=l.getTransformerByCreate(),u=this._permissionService.composePermission$([new w.WorkbookEditablePermission(t).id,new w.WorksheetEditPermission(t,o).id]).pipe(j.map(g=>g.every(m=>m.value)));u==null||u.pipe(j.filter(g=>g!==a),j.distinctUntilChanged()).subscribe({next:g=>{a=g,this._drawingManagerService.setDrawingEditable(g);const m=l.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),_=Object.values(p);g?(m.forEach(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&_.some(v=>S.oKey.includes(v.drawingId))&&l.attachTransformerTo(S)}),this._drawingManagerService.addNotification(_)):(m.forEach(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&_.some(v=>S.oKey.includes(v.drawingId))&&l.detachTransformerFrom(S)}),h.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new w.WorksheetEditPermission(t,o).id))==null||c.pipe(j.filter(g=>g.value!==a),j.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const g=r.getUnitId(),m=e.getSheetId(),p=this._drawingManagerService.getDrawingData(g,m),_=Object.values(p),S=this._renderManagerService.getRenderById(g),v=S==null?void 0:S.scene;if(v==null)return;this._drawingManagerService.setDrawingEditable(!0),v.getAllObjectsByOrder().forEach(D=>{D.classType===N.RENDER_CLASS_TYPE.IMAGE&&_.some(R=>D.oKey.includes(R.drawingId))&&v.detachTransformerFrom(D)})}})})}))}};Ze=_n([je(0,O.IDrawingManagerService),je(1,N.IRenderManagerService),je(2,d.IPermissionService),je(3,d.IUniverInstanceService),je(4,d.Inject(d.UserManagerService))],Ze);var vn=Object.defineProperty,wn=Object.getOwnPropertyDescriptor,In=(i,r,n,e)=>{for(var t=e>1?void 0:e?wn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&vn(r,n,t),t},qe=(i,r)=>(n,e)=>r(n,e,i);let Qe=class extends d.Disposable{constructor(i,r,n,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=r,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,r,n)=>{const{unitId:e,scene:t,subUnitId:o}=r,a=this._drawingManagerService.getDrawingDataForUnit(e),s=a==null?void 0:a[o];return s&&s.order.forEach(l=>{this._drawingRenderService.renderDrawing(s.data[l],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,r,n)=>{const{unitId:e,subUnitId:t}=r,o=this._renderManagerService.getRenderById(e);if(!o)return n(i);const a=o.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return n(i);const s=this._drawingManagerService.getDrawingDataForUnit(e),l=s==null?void 0:s[r.subUnitId];if(!l)return n(i);const{scaleX:h,scaleY:u}=o.scene,c=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},g=l.order.map(m=>l.data[m]).filter(m=>m.drawingType!==d.DrawingTypeEnum.DRAWING_DOM);return g.length?(g.forEach(m=>{if(!m.groupId&&m.transform&&d.Tools.isDefine(m.transform.left)&&d.Tools.isDefine(m.transform.top)&&d.Tools.isDefine(m.transform.width)&&d.Tools.isDefine(m.transform.height)){const p=a.skeleton.getCellIndexByOffset(m.transform.left,m.transform.top,h,u,{x:0,y:0}),_=a.skeleton.getCellIndexByOffset(m.transform.left+m.transform.width,m.transform.top+m.transform.height,h,u,{x:0,y:0});p.column<c.startColumn&&(c.startColumn=p.column),p.row<c.startRow&&(c.startRow=p.row),c.endRow<_.row&&(c.endRow=_.row),c.endColumn<_.column&&(c.endColumn=_.column)}}),n(c)):n(i)}}))}};Qe=In([qe(0,d.Inject(P.SheetPrintInterceptorService)),qe(1,d.Inject(ue.DrawingRenderService)),qe(2,O.IDrawingManagerService),qe(3,N.IRenderManagerService)],Qe);var Cn=Object.defineProperty,yn=Object.getOwnPropertyDescriptor,Dn=(i,r,n,e)=>{for(var t=e>1?void 0:e?yn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Cn(r,n,t),t},ge=(i,r)=>(n,e)=>r(n,e,i);const Mn=[w.InsertRowCommand.id,w.InsertColCommand.id,w.RemoveRowCommand.id,w.RemoveColCommand.id,w.DeleteRangeMoveLeftCommand.id,w.DeleteRangeMoveUpCommand.id,w.InsertRangeMoveDownCommand.id,w.InsertRangeMoveRightCommand.id,w.DeltaRowHeightCommand.id,w.SetRowHeightCommand.id,w.DeltaColumnWidthCommand.id,w.SetColWidthCommand.id,w.SetRowHiddenCommand.id,w.SetSpecificRowsVisibleCommand.id,w.SetSpecificColsVisibleCommand.id,w.SetColHiddenCommand.id,w.MoveColsCommand.id,w.MoveRowsCommand.id,w.MoveRangeCommand.id],Tn=[w.SetRowVisibleMutation.id,w.SetRowHiddenMutation.id,w.SetColVisibleMutation.id,w.SetColHiddenMutation.id,w.SetWorksheetRowHeightMutation.id,w.SetWorksheetColWidthMutation.id];let ft=class extends d.Disposable{constructor(i,r,n,e,t,o,a,s,l){super(),this._context=i,this._renderManagerService=r,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=l,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!Mn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const r=i.id;if(r===w.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([w.MoveColsCommand.id,w.MoveRowsCommand.id,w.MoveRangeCommand.id].includes(r))return this._moveRangeInterceptor(i.params);if(r===w.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(r===w.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(r===w.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(r===w.DeleteRangeMoveLeftCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,0)}else if(r===w.DeleteRangeMoveUpCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,1)}else if(r===w.InsertRangeMoveDownCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,2)}else if(r===w.InsertRangeMoveRightCommand.id){const{range:n}=i.params;return this._getRangeMoveUndo(n,3)}else if(r===w.SetRowHiddenCommand.id||r===w.SetSpecificRowsVisibleCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(r===w.SetSpecificColsVisibleCommand.id||r===w.SetColHiddenCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(r===w.DeltaRowHeightCommand.id||r===w.SetRowHeightCommand.id||r===w.DeltaColumnWidthCommand.id||r===w.SetColWidthCommand.id){const n=i.params,{unitId:e,subUnitId:t,ranges:o}=n,a=r===w.DeltaRowHeightCommand.id||r===w.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,r){const n=w.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,t),l=[],h=[];if(Object.keys(s).forEach(u=>{const c=s[u],{updateDrawings:g,deleteDrawings:m}=this._getUpdateOrDeleteDrawings(i,r,c);l.push(...g),h.push(...m)}),l.length===0&&h.length===0)return{redos:[],undos:[]};if(l.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(l),{undo:c,redo:g,objects:m}=u;o.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:g,objects:m,type:f.DrawingApplyType.UPDATE}}),a.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:c,objects:m,type:f.DrawingApplyType.UPDATE}})}if(h.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(h),c=u.undo,g=u.redo,m=u.objects;o.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:g,objects:m,type:f.DrawingApplyType.REMOVE}}),a.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:c,objects:m,type:f.DrawingApplyType.INSERT}})}return o.push({id:$.id,params:[e]}),a.push({id:$.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(i,r,n){const e=[],t=[],{sheetTransform:o,anchorType:a=f.SheetDrawingAnchorType.Position,transform:s,unitId:l,subUnitId:h,drawingId:u}=n,{from:c,to:g}=o,{row:m,column:p}=c,{row:_,column:S}=g;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:v,endRow:C,startColumn:D,endColumn:R}=i;let y=null,T=null;if(r===0&&m>=v&&_<=C)if(p>=D&&S<=R)t.push({unitId:l,subUnitId:h,drawingId:u});else{const I=this._shrinkCol(o,s,D,R,a);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===1&&p>=D&&S<=R)if(m>=v&&_<=C)t.push({unitId:l,subUnitId:h,drawingId:u});else{const I=this._shrinkRow(o,s,v,C,a);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===2){const I=this._expandRow(o,s,v,C,a);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}else if(r===3){const I=this._expandCol(o,s,D,R,a);y=I==null?void 0:I.newSheetTransform,T=I==null?void 0:I.newTransform}if(y!=null&&T!=null){const I=z(y,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:y,transform:I})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(i,r,n){const e=V({...i},this._selectionRenderService);e!=null&&r.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:g,transform:m,anchorType:p=f.SheetDrawingAnchorType.Position}=c;if(p===f.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,c);else{const{from:_,to:S}=g,{row:v,column:C}=_,{row:D,column:R}=S;for(let y=0;y<n.length;y++){const T=n[y],{startRow:I,endRow:U,startColumn:E,endColumn:F}=T;if(R<E)continue;if(p===f.SheetDrawingAnchorType.Position){let M=null,L=null;if(C>=E&&C<=F){const G=this._skeletonManagerService.attachRangeWithCoord({startColumn:C,endColumn:F,startRow:_.row,endRow:S.row});if(G==null)return;L={...m,left:G.startX}}if(L!=null&&(M=V(L,this._selectionRenderService),M!=null&&L!=null)){t.push({...c,sheetTransform:M,transform:L});break}this._remainDrawingSize(m,t,c);continue}if(C>=E&&R<=F)continue;let B=null,A=null;if(C>=E&&C<=F){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:C,endColumn:F,startRow:_.row,endRow:S.row});if(M==null)return;A={...m,left:(M==null?void 0:M.startX)||0,width:((m==null?void 0:m.width)||0)-M.endX+M.startX}}else if(R>=E&&R<=F){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:R,startRow:_.row,endRow:S.row});if(M==null)return;A={...m,left:M.startX-((m==null?void 0:m.width)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:E,endColumn:F,startRow:_.row,endRow:S.row});if(M==null)return;if(A={...m,width:((m==null?void 0:m.width)||0)-M.endX+M.startX},B=V(A,this._selectionRenderService),B!=null&&A!=null){o.push({...c,sheetTransform:B,transform:A});break}}if(A!=null&&(B=V(A,this._selectionRenderService)),A!=null&&B!=null){t.push({...c,sheetTransform:B,transform:A});break}else this._remainDrawingSize(m,t,c)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,t),l=[],h=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),h.push(...c)}return{redos:a,undos:s,preRedos:l,preUndos:h}}_createUndoAndRedoMutation(i,r,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,s=[{id:f.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:o,objects:a,type:f.DrawingApplyType.UPDATE}},{id:$.id,params:[i]}],l=[{id:f.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:r,op:t,objects:a,type:f.DrawingApplyType.UPDATE}},{id:$.id,params:[i]}];return{redos:s,undos:l}}_getDrawingUndoForRowVisible(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:g,transform:m,anchorType:p=f.SheetDrawingAnchorType.Position}=c;if(p===f.SheetDrawingAnchorType.None)this._remainDrawingSize(m,t,c);else{const{from:_,to:S}=g,{row:v,column:C}=_,{row:D,column:R}=S;for(let y=0;y<n.length;y++){const T=n[y],{startRow:I,endRow:U,startColumn:E,endColumn:F}=T;if(D<I)continue;if(p===f.SheetDrawingAnchorType.Position){let M=null,L=null;if(v>=I&&v<=U){const G=this._skeletonManagerService.attachRangeWithCoord({startColumn:_.column,endColumn:S.column,startRow:v,endRow:U});if(G==null)return;L={...m,top:G.startY}}if(L!=null&&(M=V(L,this._selectionRenderService),M!=null&&L!=null)){t.push({...c,sheetTransform:M,transform:L});break}this._remainDrawingSize(m,t,c);continue}if(v>=I&&D<=U)continue;let B=null,A=null;if(v>=I&&v<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:_.column,endColumn:S.column,startRow:v,endRow:U});if(M==null)return;A={...m,top:(M==null?void 0:M.startY)||0,height:((m==null?void 0:m.height)||0)-M.endY+M.startY}}else if(D>=I&&D<=U){const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:_.column,endColumn:S.column,startRow:I,endRow:D});if(M==null)return;A={...m,top:M.startY-((m==null?void 0:m.height)||0)}}else{const M=this._skeletonManagerService.attachRangeWithCoord({startColumn:_.column,endColumn:S.column,startRow:I,endRow:U});if(M==null)return;if(A={...m,height:((m==null?void 0:m.height)||0)-M.endY+M.startY},B=V(A,this._selectionRenderService),B!=null&&A!=null){o.push({...c,sheetTransform:B,transform:A});break}}if(A!=null&&(B=V(A,this._selectionRenderService)),A!=null&&B!=null){t.push({...c,sheetTransform:B,transform:A});break}else this._remainDrawingSize(m,t,c)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(i,r,t),l=[],h=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(i,r,o);l.push(...u),h.push(...c)}return{redos:a,undos:s,preRedos:l,preUndos:h}}_getDrawingUndoForRowAndColSize(i,r,n,e){const t=this._drawingManagerService.getDrawingData(i,r),o=[];return Object.keys(t).forEach(a=>{const s=t[a],{sheetTransform:l,transform:h,anchorType:u=f.SheetDrawingAnchorType.Position}=s;if(u===f.SheetDrawingAnchorType.None)this._remainDrawingSize(h,o,s);else{const{from:c,to:g}=l,{row:m,column:p}=c,{row:_,column:S}=g;for(let v=0;v<n.length;v++){const C=n[v],{startRow:D,endRow:R,startColumn:y,endColumn:T}=C;if(_<D||S<y)continue;if(u===f.SheetDrawingAnchorType.Position&&(m<=D&&_>=R||p<=y&&S>=T)){this._remainDrawingSize(h,o,s);continue}const I=z({...l},this._selectionRenderService,this._skeletonManagerService);if(I!=null){o.push({...s,transform:I});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,r,o)}_getUnitIdAndSubUnitId(i,r){let n,e;if(r==="insert")n=i.unitId,e=i.subUnitId;else{const t=w.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(i){var D,R;const{toRange:r,fromRange:n}=i,e=w.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(R=(D=this._renderManagerService.getRenderById(t))==null?void 0:D.with(P.SheetSkeletonManagerService))==null?void 0:R.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=P.attachRangeWithCoord(a,n);if(!s)return{redos:[],undos:[]};const{startX:l,endX:h,startY:u,endY:c}=s,g=this._sheetDrawingService.getDrawingData(t,o),m=[];Object.keys(g).forEach(y=>{const T=g[y];if(T.anchorType!==f.SheetDrawingAnchorType.Both)return;const{transform:I}=T;if(!I)return;const{left:U=0,top:E=0,width:F=0,height:B=0}=I,{drawingStartX:A,drawingEndX:M,drawingStartY:L,drawingEndY:G}={drawingStartX:U,drawingEndX:U+F,drawingStartY:E,drawingEndY:E+B};l<=A&&M<=h&&u<=L&&G<=c&&m.push(T)});const p=[],_=[],S=r.startRow-n.startRow,v=r.startColumn-n.startColumn,C=m.map(y=>{const T=y.sheetTransform,I={to:{...T.to,row:T.to.row+S,column:T.to.column+v},from:{...T.from,row:T.from.row+S,column:T.from.column+v}},U=z(I,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:y.drawingId,transform:U,sheetTransform:I}});if(C.length){const y=this._sheetDrawingService.getBatchUpdateOp(C),{undo:T,redo:I,objects:U}=y;p.push({id:f.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:I,objects:U,type:f.DrawingApplyType.UPDATE}}),_.push({id:f.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:T,objects:U,type:f.DrawingApplyType.UPDATE}})}return{redos:p,undos:_}}_moveRowInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startRow,s=o.endRow,l=[],h=[],u=this._sheetDrawingService.getDrawingData(e,t),c=[],g=[];if(Object.keys(u).forEach(m=>{const p=u[m],{sheetTransform:_,transform:S,anchorType:v=f.SheetDrawingAnchorType.Position}=p;if(_==null||S==null)return;let C,D;if(r==="insert"){const y=this._expandRow(_,S,a,s,v);C=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:T}=_,{row:I}=y,{row:U}=T;if(v===f.SheetDrawingAnchorType.Both&&I>=a&&U<=s)g.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkRow(_,S,a,s,v);C=E==null?void 0:E.newSheetTransform,D=E==null?void 0:E.newTransform}}if(!C||!D)return;const R={unitId:e,subUnitId:t,drawingId:m,transform:D,sheetTransform:C};c.push(R)}),c.length===0&&g.length===0)return{redos:[],undos:[]};if(c.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(c),{undo:p,redo:_,objects:S}=m;l.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:_,objects:S,type:f.DrawingApplyType.UPDATE}}),h.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:S,type:f.DrawingApplyType.UPDATE}})}if(g.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(g),p=m.undo,_=m.redo,S=m.objects;l.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:_,objects:S,type:f.DrawingApplyType.REMOVE}}),h.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:S,type:f.DrawingApplyType.INSERT}})}return l.push({id:$.id,params:[e]}),h.push({id:$.id,params:[e]}),{redos:l,undos:h}}_moveColInterceptor(i,r){const n=this._getUnitIdAndSubUnitId(i,r);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=i,a=o.startColumn,s=o.endColumn,l=[],h=[],u=this._sheetDrawingService.getDrawingData(e,t),c=[],g=[];if(Object.keys(u).forEach(m=>{const p=u[m],{sheetTransform:_,transform:S,anchorType:v=f.SheetDrawingAnchorType.Position}=p;if(_==null||S==null)return;let C,D;if(r==="insert"){const y=this._expandCol(_,S,a,s,v);C=y==null?void 0:y.newSheetTransform,D=y==null?void 0:y.newTransform}else{const{from:y,to:T}=_,{column:I}=y,{column:U}=T;if(v===f.SheetDrawingAnchorType.Both&&I>=a&&U<=s)g.push({unitId:e,subUnitId:t,drawingId:m});else{const E=this._shrinkCol(_,S,a,s,v);C=E==null?void 0:E.newSheetTransform,D=E==null?void 0:E.newTransform}}if(!C||!D)return;const R={unitId:e,subUnitId:t,drawingId:m,transform:D,sheetTransform:C};c.push(R)}),c.length===0&&g.length===0)return{redos:[],undos:[]};if(c.length>0){const m=this._sheetDrawingService.getBatchUpdateOp(c),{undo:p,redo:_,objects:S}=m;l.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:_,objects:S,type:f.DrawingApplyType.UPDATE}}),h.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:S,type:f.DrawingApplyType.UPDATE}})}if(g.length>0){const m=this._sheetDrawingService.getBatchRemoveOp(g),p=m.undo,_=m.redo,S=m.objects;l.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:_,objects:S,type:f.DrawingApplyType.REMOVE}}),h.push({id:f.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:S,type:f.DrawingApplyType.INSERT}})}return l.push({id:$.id,params:[e]}),h.push({id:$.id,params:[e]}),{redos:l,undos:h}}_expandCol(i,r,n,e,t=f.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=i,{column:l}=a,{column:h}=s;if(t===f.SheetDrawingAnchorType.None)return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(l>=n){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:s.row});if(g==null)return;c={...r,left:(r.left||0)+g.endX-g.startX},u=V(c,this._selectionRenderService)}else if(h>=e)if(t===f.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:h+o}},c=z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(i,r,n,e,t=f.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=i,{column:l}=a,{column:h}=s;if(t===f.SheetDrawingAnchorType.None)return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(l>e)u={from:{...a,column:l-o},to:{...s,column:h-o}},c=z(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=n&&h<=e)return null;if(l<n&&h>e)if(t===f.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:h-o}},c=z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};else if(l>=n&&l<=e){if(l===n)c={...r,left:(r.left||0)-i.from.columnOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:l-1,startRow:a.row,endRow:s.row});if(g==null)return;c={...r,left:(r.left||0)-g.endX+g.startX-i.from.columnOffset}}u=V(c,this._selectionRenderService)}else if(h>=n&&h<=e&&t===f.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:s.row});if(g==null)return;u={from:{...a},to:{...s,column:n-1,columnOffset:g.endX-g.startX}},c=z(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(i,r,n,e,t=f.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=i,{row:l}=a,{row:h}=s;if(t===f.SheetDrawingAnchorType.None)return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(l>=n){const g=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:s.column});if(g==null)return;c={...r,top:(r.top||0)+g.endY-g.startY},u=V(c,this._selectionRenderService)}else if(h>=e)if(t===f.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:h+o}},c=z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(i,r,n,e,t=f.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=i,{row:l}=a,{row:h}=s;if(t===f.SheetDrawingAnchorType.None)return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};let u=null,c=null;if(l>e)u={from:{...a,row:l-o},to:{...s,row:h-o}},c=z(u,this._selectionRenderService,this._skeletonManagerService);else{if(l>=n&&h<=e)return null;if(l<n&&h>e)if(t===f.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:h-o}},c=z(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...r},this._selectionRenderService),newTransform:r};else if(l>=n&&l<=e){if(l===n)c={...r,top:(r.top||0)-i.from.rowOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:l-1,startColumn:a.column,endColumn:s.column});if(g==null)return;c={...r,top:(r.top||0)-g.endY+g.startY-i.from.rowOffset}}u=V(c,this._selectionRenderService)}else if(h>=n&&h<=e&&t===f.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(g==null)return;u={from:{...a},to:{...s,row:n-1,rowOffset:g.endY-g.startY}},c=z(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===w.SetWorksheetActiveOperation.id&&setTimeout(()=>{const r=i.params,{unitId:n,subUnitId:e}=r,t=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(t).forEach(s=>{const l=t[s];l!=null&&Object.keys(l).forEach(h=>{const u=l[h].data;u!=null&&Object.keys(u).forEach(c=>{if(s===n&&h===e){const g=u[c];g.transform=z(g.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(u[c])}else a.push(u[c])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Tn.includes(i.id)&&requestIdleCallback(()=>{const r=i.params,{unitId:n,subUnitId:e,ranges:t}=r;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(i,r,n){const e=this._drawingManagerService.getDrawingData(i,r),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:s,transform:l,anchorType:h=f.SheetDrawingAnchorType.Position}=a;if(h===f.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=s,{row:g,column:m}=u,{row:p,column:_}=c;for(let S=0;S<n.length;S++){const v=n[S],{startRow:C,endRow:D,startColumn:R,endColumn:y}=v;if(d.Rectangle.intersects({startRow:C,endRow:D,startColumn:R,endColumn:y},{startRow:g,endRow:p,startColumn:m,endColumn:_})||g>D||m>y){const T=h===f.SheetDrawingAnchorType.Position,I=z(s,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...I,width:T?l==null?void 0:l.width:I==null?void 0:I.width,height:T?l==null?void 0:l.height:I==null?void 0:I.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand($.id,[i]))}};ft=Dn([ge(1,N.IRenderManagerService),ge(2,d.ICommandService),ge(3,P.ISheetSelectionRenderService),ge(4,d.Inject(P.SheetSkeletonManagerService)),ge(5,d.Inject(w.SheetInterceptorService)),ge(6,f.ISheetDrawingService),ge(7,O.IDrawingManagerService),ge(8,d.IUniverInstanceService)],ft);var te=function(){return te=Object.assign||function(i){for(var r,n=1,e=arguments.length;n<e;n++){r=arguments[n];for(var t in r)Object.prototype.hasOwnProperty.call(r,t)&&(i[t]=r[t])}return i},te.apply(this,arguments)},Rn=function(i,r){var n={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&r.indexOf(e)<0&&(n[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(i);t<e.length;t++)r.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(i,e[t])&&(n[e[t]]=i[e[t]]);return n},Nt=Q.forwardRef(function(i,r){var n=i.icon,e=i.id,t=i.className,o=i.extend,a=Rn(i,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),l=Q.useRef("_".concat(On()));return jt(n,"".concat(e),{defIds:n.defIds,idSuffix:l.current},te({ref:r,className:s},a),o)});function jt(i,r,n,e,t){return Q.createElement(i.tag,te(te({key:r},bn(i,n,t)),e),(En(i,n).children||[]).map(function(o,a){return jt(o,"".concat(r,"-").concat(i.tag,"-").concat(a),n,void 0,t)}))}function bn(i,r,n){var e=te({},i.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=r.defIds;return!t||t.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+r.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(r.idSuffix,")")))})),e}function En(i,r){var n,e=r.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((n=i.children)===null||n===void 0)&&n.length)?te(te({},i),{children:i.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?te(te({},t),{attrs:te(te({},t.attrs),{id:t.attrs.id+r.idSuffix})}):t})}):i}function On(){return Math.random().toString(36).substring(2,8)}Nt.displayName="UniverIcon";var Pn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z"}}]},Wt=Q.forwardRef(function(i,r){return Q.createElement(Nt,Object.assign({},i,{id:"add-image-single",ref:r,icon:Pn}))});Wt.displayName="AddImageSingle";const St={id:"sheet.command.delete-drawing",type:d.CommandType.COMMAND,handler:i=>{const r=i.get(d.ICommandService),e=i.get(f.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:l,drawingId:h,drawingType:u}=a;return{unitId:s,subUnitId:l,drawingId:h,drawingType:u}});return r.executeCommand(Oe.id,{unitId:t,drawings:o})}},et={id:"sheet.command.insert-float-image",type:d.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(d.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(Ne).insertFloatImage())!=null?e:!1}},_t={id:"sheet.command.insert-cell-image",type:d.CommandType.COMMAND,handler:i=>{var n,e;return(e=(n=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(d.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(Ne).insertCellImage())!=null?e:!1}},Re={id:"sheet.command.move-drawing",type:d.CommandType.COMMAND,handler:(i,r)=>{const n=i.get(d.ICommandService),e=i.get(f.ISheetDrawingService),t=i.get(P.ISheetSelectionRenderService),{direction:o}=r,a=e.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,l=a.map(u=>{const{transform:c}=u;if(c==null)return null;const g={...c},{left:m=0,top:p=0}=c;return o===d.Direction.UP?g.top=p-1:o===d.Direction.DOWN?g.top=p+1:o===d.Direction.LEFT?g.left=m-1:o===d.Direction.RIGHT&&(g.left=m+1),{...u,transform:g,sheetTransform:V(g,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(Ue.id,{unitId:s,drawings:l})?(n.syncExecuteCommand($.id,[s]),!0):!1}},Bt="addition-and-subtraction-single",vt="sheet.menu.image";function An(i){return{id:vt,type:Y.MenuItemType.SUBITEMS,icon:Bt,tooltip:"sheetImage.title",hidden$:Y.getMenuHiddenObservable(i,d.UniverInstanceType.UNIVER_SHEET),disabled$:P.getCurrentRangeDisable$(i,{workbookTypes:[w.WorkbookEditablePermission],worksheetTypes:[w.WorksheetEditPermission],rangeTypes:[w.RangeProtectionPermissionEditPoint]})}}function Un(i){return{id:et.id,title:"sheetImage.upload.float",type:Y.MenuItemType.BUTTON,hidden$:Y.getMenuHiddenObservable(i,d.UniverInstanceType.UNIVER_SHEET)}}function Nn(i){return{id:_t.id,title:"sheetImage.upload.cell",type:Y.MenuItemType.BUTTON}}const he={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function kt(i){var r,n,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var t=i.length;for(r=0;r<t;r++)i[r]&&(n=kt(i[r]))&&(e&&(e+=" "),e+=n)}else for(n in i)i[n]&&(e&&(e+=" "),e+=n);return e}function tt(){for(var i,r,n=0,e="",t=arguments.length;n<t;n++)(i=arguments[n])&&(r=kt(i))&&(e&&(e+=" "),e+=r);return e}const jn=i=>{var D;const r=d.useDependency(d.ICommandService),n=d.useDependency(d.LocaleService),e=d.useDependency(O.IDrawingManagerService),t=d.useDependency(N.IRenderManagerService),{drawings:o}=i,a=o[0];if(a==null)return;const{unitId:s}=a,l=t.getRenderById(s),h=l==null?void 0:l.scene;if(h==null)return;const u=h.getTransformerByCreate(),[c,g]=Q.useState(!0),m=(D=a.anchorType)!=null?D:f.SheetDrawingAnchorType.Position,[p,_]=Q.useState(m);function S(R,y){const T=[];return R.forEach(I=>{const{oKey:U}=I,E=y.getDrawingOKey(U);if(E==null)return T.push(null),!0;const{unitId:F,subUnitId:B,drawingId:A,drawingType:M,anchorType:L,sheetTransform:G}=E;T.push({unitId:F,subUnitId:B,drawingId:A,anchorType:L,sheetTransform:G,drawingType:M})}),T}Q.useEffect(()=>{const R=u.clearControl$.subscribe(T=>{T===!0&&g(!1)}),y=u.changeStart$.subscribe(T=>{var E;const{objects:I}=T,U=S(I,e);if(U.length===0)g(!1);else if(U.length>=1){g(!0);const F=((E=U[0])==null?void 0:E.anchorType)||f.SheetDrawingAnchorType.Position;_(F)}});return()=>{y.unsubscribe(),R.unsubscribe()}},[]);function v(R){_(R);const y=e.getFocusDrawings();if(y.length===0)return;const T=y.map(I=>({unitId:I.unitId,subUnitId:I.subUnitId,drawingId:I.drawingId,anchorType:R}));r.executeCommand(Ue.id,{unitId:y[0].unitId,drawings:T})}const C=R=>R?"block":"none";return K.jsxs("div",{className:tt(he.imageCommonPanelGrid,he.imageCommonPanelBorder),style:{display:C(c)},children:[K.jsx("div",{className:he.imageCommonPanelRow,children:K.jsx("div",{className:tt(he.imageCommonPanelColumn,he.imageCommonPanelTitle),children:K.jsx("div",{children:n.t("drawing-anchor.title")})})}),K.jsx("div",{className:tt(he.imageCommonPanelRow),children:K.jsx("div",{className:tt(he.imageCommonPanelColumn),children:K.jsxs(ne.RadioGroup,{value:p,onChange:v,direction:"vertical",children:[K.jsx(ne.Radio,{value:f.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),K.jsx(ne.Radio,{value:f.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),K.jsx(ne.Radio,{value:f.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},Wn=()=>{const i=d.useDependency(O.IDrawingManagerService),r=i.getFocusDrawings(),[n,e]=Q.useState(r);return Q.useEffect(()=>{const t=i.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&K.jsxs("div",{className:he.imageCommonPanel,children:[K.jsx(ue.DrawingCommonPanel,{drawings:n}),K.jsx(jn,{drawings:n})]})},Bn={[Y.RibbonStartGroup.FORMULAS_INSERT]:{[vt]:{order:3,menuItemFactory:An,[et.id]:{order:0,menuItemFactory:Un},[_t.id]:{order:1,menuItemFactory:Nn}}}};function We(i){return!i.getContextValue(d.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(d.EDITOR_ACTIVATED)&&!i.getContextValue(d.FOCUSING_PANEL_EDITOR)&&i.getContextValue(d.FOCUSING_COMMON_DRAWINGS)}const kn={id:Re.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_DOWN,priority:100,preconditions:We,staticParameters:{direction:d.Direction.DOWN}},Ln={id:Re.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_UP,priority:100,preconditions:We,staticParameters:{direction:d.Direction.UP}},Gn={id:Re.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_LEFT,priority:100,preconditions:We,staticParameters:{direction:d.Direction.LEFT}},Fn={id:Re.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:Y.KeyCode.ARROW_RIGHT,priority:100,preconditions:We,staticParameters:{direction:d.Direction.RIGHT}},$n={id:St.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:We,binding:Y.KeyCode.DELETE,mac:Y.KeyCode.BACKSPACE};var Hn=Object.defineProperty,Yn=Object.getOwnPropertyDescriptor,Vn=(i,r,n,e)=>{for(var t=e>1?void 0:e?Yn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Hn(r,n,t),t},nt=(i,r)=>(n,e)=>r(n,e,i);let rt=class extends d.Disposable{constructor(i,r,n,e){super(),this._componentManager=i,this._menuManagerService=r,this._commandService=n,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Bt,Wt)),this.disposeWithMe(i.register(Et,Wn))}_initMenus(){this._menuManagerService.mergeMenu(Bn)}_initCommands(){[et,_t,Ae,Oe,Ue,st,$,ct,ut,gt,Re,St,mt].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[kn,Ln,Gn,Fn,$n].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};rt=Vn([nt(0,d.Inject(Y.ComponentManager)),nt(1,Y.IMenuManagerService),nt(2,d.ICommandService),nt(3,Y.IShortcutService)],rt);var xn=Object.defineProperty,Xn=Object.getOwnPropertyDescriptor,Kn=(i,r,n,e)=>{for(var t=e>1?void 0:e?Xn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&xn(r,n,t),t},ve=(i,r)=>(n,e)=>r(n,e,i);function zn(i,r,n,e,t){const{scaleX:o,scaleY:a}=r.getAncestorScale(),s=r.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),l={left:!0,top:!0};if(!s)return{...i,absolute:l};const{left:h,right:u,top:c,bottom:g}=i;let{top:m,left:p,viewportScrollX:_,viewportScrollY:S}=s;const{boundsOfViewArea:v,scrollDirectionResponse:C}=t||{};v&&(d.Tools.isDefine(v.top)&&(m=v.top),d.Tools.isDefine(v.left)&&(p=v.left)),C==="HORIZONTAL"&&(S=0),C==="VERTICAL"&&(_=0);let D,R;h<p?(l.left=!0,D=(p+(h-p))*o,R=Math.max(Math.min((p+(u-p))*o,p*o),(u-_)*o)):(l.left=!1,D=Math.max((h-_)*o,p*o),R=Math.max((u-_)*o,p*o));let y,T;return c<m?(l.top=!0,y=(m+(c-m))*a,T=Math.max(Math.min((m+(u-m))*a,m*a),(g-S)*a)):(l.top=!1,y=Math.max((c-S)*a,m*a),T=Math.max((g-S)*a,m*a)),{left:D,right:R,top:y,bottom:T,absolute:l}}const we=(i,r,n,e,t)=>{const{scene:o}=r,{left:a,top:s,width:l,height:h,angle:u}=i,c={left:a,right:a+l,top:s,bottom:s+h},g=zn(c,o,n,e,t),{scaleX:m,scaleY:p}=o.getAncestorScale();return{startX:g.left,endX:g.right,startY:g.top,endY:g.bottom,rotate:u,width:l*m,height:h*p,absolute:g.absolute}};b.SheetCanvasFloatDomManagerService=class extends d.Disposable{constructor(n,e,t,o,a,s,l){super();q(this,"_domLayerMap",new Map);q(this,"_domLayerInfoMap",new Map);q(this,"_transformChange$",new j.Subject);q(this,"transformChange$",this._transformChange$.asObservable());q(this,"_add$",new j.Subject);q(this,"add$",this._add$.asObservable());q(this,"_remove$",new j.Subject);q(this,"remove$",this._remove$.asObservable());q(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._lifecycleService=l,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(j.filter(n=>n===d.LifecycleStages.Rendered),j.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderUnit:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var Ie,pe,ae;const{unitId:t,subUnitId:o,drawingId:a}=e,s=w.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),l=this._drawingManagerService.getDrawingByParam(e),h=this._univerInstanceService.getUnit(t,d.UniverInstanceType.UNIVER_SHEET);if(!h)return;const u=h.getActiveSheet().getSheetId();if(!l||!s)return;const c=(Ie=this._renderManagerService.getRenderById(t))==null?void 0:Ie.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!c)return;const{transform:g,drawingType:m,data:p}=l;if(m!==d.DrawingTypeEnum.DRAWING_DOM&&m!==d.DrawingTypeEnum.DRAWING_CHART)return;const _=this._getSceneAndTransformerByDrawingSearch(t);if(_==null)return;const{scene:S,canvas:v}=_;if(g==null)return!0;if(u!==o)return;const{left:C,top:D,width:R,height:y,angle:T,flipX:I,flipY:U,skewX:E,skewY:F}=g,B=O.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),A=S.getObject(B);if(A!=null){A.transformByState({left:C,top:D,width:R,height:y,angle:T,flipX:I,flipY:U,skewX:E,skewY:F});return}const M={left:C,top:D,width:R,height:y,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},L=m===d.DrawingTypeEnum.DRAWING_CHART;if(L){const H=p?p.backgroundColor:"white";M.fill=H,M.rotateEnabled=!1,p&&p.border&&(M.stroke=p.border),M.paintFirst="stroke",M.strokeWidth=1,M.borderEnabled=!1,M.radius=8}const G=new N.Rect(B,M);L&&G.setObjectType(N.ObjectType.CHART),S.addObject(G,N.DRAWING_OBJECT_LAYER_INDEX),l.allowTransform!==!1&&S.attachTransformerTo(G);const x=this._ensureMap(t,o),W=new d.DisposableCollection,X=we(G,_.renderUnit,c.skeleton,s.worksheet),J=new j.BehaviorSubject(X),ie={dispose:W,rect:G,position$:J,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:J,id:a,componentKey:l.componentKey,onPointerDown:H=>{v.dispatchEvent(new PointerEvent(H.type,H))},onPointerMove:H=>{v.dispatchEvent(new PointerEvent(H.type,H))},onPointerUp:H=>{v.dispatchEvent(new PointerEvent(H.type,H))},onWheel:H=>{v.dispatchEvent(new WheelEvent(H.type,H))},props:(ae=(pe=x.get(a))==null?void 0:pe.props)!=null?ae:this._getFloatDomProps(a),data:p,unitId:t});const oe=G.onTransformChange$.subscribeEvent(()=>{const H=we(G,_.renderUnit,c.skeleton,s.worksheet);J.next(H)});W.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),oe&&W.add(oe),this._domLayerInfoMap.set(a,ie),x.set(a,{...x.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,s=O.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),l=this._getSceneAndTransformerByDrawingSearch(t);if(l==null)return;const{transformer:h,scene:u}=l,c=u.getObject(s);c!=null&&c.oKey&&h.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),s=Array.from(a.keys()),l=w.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),h=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!l||!h||s.forEach(c=>{const g=this._domLayerInfoMap.get(c);if(g){const m=we(g.rect,o.renderUnit,h.skeleton,l.worksheet,g);g.position$.next(m)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(d.UniverInstanceType.UNIVER_SHEET).pipe(j.filter(e=>!!e),j.switchMap(e=>e.activeSheet$),j.filter(e=>!!e),j.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),j.filter(e=>!!e),j.switchMap(e=>d.fromEventSubject(e.render.scene.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(j.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===P.SetZoomRatioOperation.id){const a=e.params,{unitId:s}=a;Array.from((o=(t=this._domLayerMap.get(s))==null?void 0:t.keys())!=null?o:[]).forEach(h=>{n(s,h)})}else if(e.id===w.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=e.params;n(a,s)}}))}_getPosition(n,e){var m;const{startX:t,endX:o,startY:a,endY:s}=n,l=(m=this._renderManagerService.getRenderById(e))==null?void 0:m.with(P.ISheetSelectionRenderService);if(l==null)return;const h=l.getCellWithCoordByOffset(t,a);if(h==null)return;const u={column:h.actualColumn,columnOffset:t-h.startX,row:h.actualRow,rowOffset:a-h.startY},c=l.getCellWithCoordByOffset(o,s);if(c==null)return;const g={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:s-c.startY};return{from:u,to:g}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==d.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==d.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),s=this._getSceneAndTransformerByDrawingSearch(n);if(a&&s){const{scene:l}=s,h=O.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=l.getObject(h);u&&u instanceof N.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=w.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:s,componentKey:l,data:h,allowTransform:u=!0}=n,c=e!=null?e:d.generateRandomId(),g=this._getPosition(s,o);if(g==null)return;this._ensureMap(o,a).set(c,n);const p={unitId:o,subUnitId:a,drawingId:c,drawingType:n.type||d.DrawingTypeEnum.DRAWING_DOM,componentKey:l,sheetTransform:g,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:h,allowTransform:u};return this._commandService.executeCommand(Ae.id,{unitId:o,drawings:[p]}),this._add$.next({unitId:o,subUnitId:a,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const h=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!h)return;const u=this._sheetDrawingService.getBatchRemoveOp([h]),{redo:c,objects:g}=u;this._commandService.syncExecuteCommand(f.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:c,objects:g,type:f.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}addFloatDomToRange(n,e,t,o){var F,B,A,M,L,G;const a=w.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:l}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(F=this._renderManagerService.getRenderById(s))==null?void 0:F.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!c)return;const{componentKey:g,data:m,allowTransform:p=!0}=e,_=o!=null?o:d.generateRandomId(),{position:S}=this._createRangePositionObserver(n,u,c.skeleton),v=this._getPosition(S,s);if(v==null)return;this._ensureMap(s,l).set(_,e);const D=S.endX-S.startX,R=S.endY-S.startY,y=(B=t.width)!=null?B:D,T=(A=t.height)!=null?A:R,I=S.startX+be(t.marginX,D),U=S.startY+be(t.marginY,R),E={unitId:s,subUnitId:l,drawingId:_,drawingType:e.type||d.DrawingTypeEnum.DRAWING_DOM,componentKey:g,sheetTransform:v,transform:{left:I,top:U,width:y,height:T},data:m,allowTransform:p};{const{unitId:x,subUnitId:W,drawingId:X}=E,J=w.getSheetCommandTarget(this._univerInstanceService,{unitId:x,subUnitId:W}),ie=E,oe=this._univerInstanceService.getUnit(x,d.UniverInstanceType.UNIVER_SHEET);if(!oe)return;const Ie=oe.getActiveSheet().getSheetId();if(!ie||!J)return;const pe=(M=this._renderManagerService.getRenderById(x))==null?void 0:M.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(W);if(!pe)return;const{transform:ae,drawingType:H,data:se}=ie;if(H!==d.DrawingTypeEnum.DRAWING_DOM&&H!==d.DrawingTypeEnum.DRAWING_CHART)return;const Ee=this._getSceneAndTransformerByDrawingSearch(x);if(Ee==null)return;const{scene:ce,canvas:de}=Ee;if(ae==null||Ie!==W)return;const{left:Ce,top:ke,width:Le,height:Ge,angle:it,flipX:It,flipY:Ct,skewX:yt,skewY:Dt}=ae,ot=O.getDrawingShapeKeyByDrawingSearch({unitId:x,subUnitId:W,drawingId:X}),Fe=ce.getObject(ot);if(Fe!=null){Fe.transformByState({left:Ce,top:ke,width:Le,height:Ge,angle:it,flipX:It,flipY:Ct,skewX:yt,skewY:Dt});return}const re={left:Ce,top:ke,width:Le,height:Ge,zIndex:this._drawingManagerService.getDrawingOrder(x,W).length-1},at=H===d.DrawingTypeEnum.DRAWING_CHART;if(at){const k=se?se.backgroundColor:"white";re.fill=k,re.rotateEnabled=!1,se&&se.border&&(re.stroke=se.border),re.paintFirst="stroke",re.strokeWidth=1,re.borderEnabled=!1,re.radius=8}const Z=new N.Rect(ot,re);at&&Z.setObjectType(N.ObjectType.CHART),ce.addObject(Z,N.DRAWING_OBJECT_LAYER_INDEX),ie.allowTransform!==!1&&ce.attachTransformerTo(Z);const ye=this._ensureMap(x,W),De=new d.DisposableCollection,fe=ce.getMainViewport(),Mt={top:fe.top,left:fe.left,bottom:fe.bottom,right:fe.right},le={dispose:De,rect:Z,boundsOfViewArea:Mt,unitId:x,subUnitId:W},Tt=we(Z,Ee.renderUnit,pe.skeleton,J.worksheet,le),Me=new j.BehaviorSubject(Tt);le.position$=Me;let Te={position$:Me,id:X,componentKey:ie.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:k=>{de.dispatchEvent(new WheelEvent(k.type,k))},props:(G=(L=ye.get(X))==null?void 0:L.props)!=null?G:this._getFloatDomProps(X),data:se,unitId:x};e.eventPassThrough&&(Te={...Te,onPointerDown:k=>{de.dispatchEvent(new PointerEvent(k.type,k))},onPointerMove:k=>{de.dispatchEvent(new PointerEvent(k.type,k))},onPointerUp:k=>{de.dispatchEvent(new PointerEvent(k.type,k))}}),this._canvasFloatDomService.addFloatDom(Te);const $e=Z.onTransformChange$.subscribeEvent(()=>{const k=we(Z,Ee.renderUnit,pe.skeleton,J.worksheet,le);Me.next(k)});De.add(()=>{this._canvasFloatDomService.removeFloatDom(X)}),$e&&De.add($e),this._domLayerInfoMap.set(X,le),ye.set(X,{...ye.get(X)})}return{id:_,dispose:()=>{this._removeDom(_,!0)}}}addFloatDomToColumnHeader(n,e,t,o){var B,A,M,L,G,x;const a=w.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:l}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(B=this._renderManagerService.getRenderById(s))==null?void 0:B.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(l);if(!c)return;const{componentKey:g,data:m,allowTransform:p=!0}=e,_=o!=null?o:d.generateRandomId(),{position:S}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:n,endColumn:n},u,c.skeleton),v=S;v.startY=0;const C=this._getPosition(S,s);if(C==null)return;this._ensureMap(s,l).set(_,e);const R=S.endX-S.startX,y=S.endY-S.startY,T=(A=t.width)!=null?A:R,I=(M=t.height)!=null?M:y;let U=0,E=0;if(t.horizonOffsetAlign==="right"){const W=be(t.marginX,R);U=v.endX-W-T}else U=v.startX+be(t.marginX,R);if(t.verticalOffsetAlign==="bottom"){const W=be(t.marginY,y);E=v.endY-W-I}else E=v.startY+be(t.marginY,y);const F={unitId:s,subUnitId:l,drawingId:_,drawingType:e.type||d.DrawingTypeEnum.DRAWING_DOM,componentKey:g,sheetTransform:C,transform:{left:U,top:E,width:T,height:I},data:m,allowTransform:p};{const{unitId:W,subUnitId:X,drawingId:J}=F,ie=w.getSheetCommandTarget(this._univerInstanceService,{unitId:W,subUnitId:X}),oe=F,Ie=this._univerInstanceService.getUnit(W,d.UniverInstanceType.UNIVER_SHEET);if(!Ie)return;const pe=Ie.getActiveSheet().getSheetId();if(!oe||!ie)return;const ae=(L=this._renderManagerService.getRenderById(W))==null?void 0:L.with(P.SheetSkeletonManagerService).getWorksheetSkeleton(X);if(!ae)return;const{transform:H,drawingType:se,data:Ee}=oe;if(se!==d.DrawingTypeEnum.DRAWING_DOM&&se!==d.DrawingTypeEnum.DRAWING_CHART)return;const ce=this._getSceneAndTransformerByDrawingSearch(W);if(ce==null)return;const{scene:de,canvas:Ce}=ce;if(H==null||pe!==X)return;const{left:ke,top:Le,width:Ge,height:it,angle:It,flipX:Ct,flipY:yt,skewX:Dt,skewY:ot}=H,Fe=O.getDrawingShapeKeyByDrawingSearch({unitId:W,subUnitId:X,drawingId:J}),re=de.getObject(Fe);if(re!=null){re.transformByState({left:ke,top:Le,width:Ge,height:it,angle:It,flipX:Ct,flipY:yt,skewX:Dt,skewY:ot});return}const at={left:ke,top:Le,width:Ge,height:it,zIndex:this._drawingManagerService.getDrawingOrder(W,X).length-1},Z=new N.Rect(Fe,at);de.addObject(Z,N.DRAWING_OBJECT_LAYER_INDEX),oe.allowTransform!==!1&&de.attachTransformerTo(Z);const ye=this._ensureMap(W,X),De=new d.DisposableCollection,fe=de.getMainViewport(),Mt={top:0,left:fe.left,bottom:fe.bottom,right:fe.right},le={dispose:De,rect:Z,unitId:W,subUnitId:X,boundsOfViewArea:Mt,scrollDirectionResponse:"HORIZONTAL"},Tt=we(Z,ce.renderUnit,ae.skeleton,ie.worksheet,le),Me=new j.BehaviorSubject(Tt);le.position$=Me;let Te={position$:Me,id:J,componentKey:oe.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:k=>{Ce.dispatchEvent(new WheelEvent(k.type,k))},props:(x=(G=ye.get(J))==null?void 0:G.props)!=null?x:this._getFloatDomProps(J),data:Ee,unitId:W};e.eventPassThrough&&(Te={...Te,onPointerDown:k=>{Ce.dispatchEvent(new PointerEvent(k.type,k))},onPointerMove:k=>{Ce.dispatchEvent(new PointerEvent(k.type,k))},onPointerUp:k=>{Ce.dispatchEvent(new PointerEvent(k.type,k))}}),this._canvasFloatDomService.addFloatDom(Te);const $e=Z.onTransformChange$.subscribeEvent(()=>{const k=we(Z,ce.renderUnit,ae.skeleton,ie.worksheet,le);Me.next(k)});De.add(()=>{this._canvasFloatDomService.removeFloatDom(J)}),$e&&De.add($e),this._domLayerInfoMap.set(J,le),ye.set(J,{...ye.get(J)})}return{id:_,dispose:()=>{this._removeDom(_,!0)}}}_createRangePositionObserver(n,e,t){let{startRow:o,startColumn:a}=n;const s=Be(o,a,t),l=new j.BehaviorSubject(s),h=Be(n.endRow,n.endColumn,t),u=new j.BehaviorSubject(h),c=()=>{const v=Be(o,a,t),C=Be(n.endRow,n.endColumn,t);l.next(v),u.next(C)},g=new d.DisposableCollection;g.add(e.engine.clientRect$.subscribe(()=>c())),g.add(this._commandService.onCommandExecuted(v=>{if(v.id===w.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(D=>D.row===o)>-1){c();return}(w.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===P.SetScrollOperation.id||v.id===P.SetZoomRatioOperation.id)&&c()}));const m=(v,C)=>{o=v,a=C,c()},p=()=>({rotate:0,width:h.right-s.left,height:h.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:h.right,endY:h.bottom}),_=l.pipe(j.map(v=>{const C=Be(n.endRow,n.endColumn,t);return console.log("service",v.left,v.top),{rotate:0,width:C.right-v.left,height:C.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:C.right,endY:C.bottom}})),S=p();return console.log("init position",S),{position$:_,position:S,updateRowCol:m,topLeftPos$:l,rightBottomPos$:u,disposable:g}}},b.SheetCanvasFloatDomManagerService=Kn([ve(0,d.Inject(N.IRenderManagerService)),ve(1,d.IUniverInstanceService),ve(2,d.Inject(d.ICommandService)),ve(3,O.IDrawingManagerService),ve(4,d.Inject(Y.CanvasFloatDomService)),ve(5,f.ISheetDrawingService),ve(6,d.Inject(d.LifecycleService))],b.SheetCanvasFloatDomManagerService);function Be(i,r,n){const e=n.getCellWithCoordByIndex(i,r),t=e.isMergedMainCell?e.mergeInfo:e;return{left:t.startX,right:t.endX,top:t.startY,bottom:t.endY}}function be(i,r){if(i===void 0)return 0;if(typeof i=="number")return i;const n=Number.parseFloat(i);return r*n/100}var Lt=Object.defineProperty,Jn=Object.getOwnPropertyDescriptor,Zn=(i,r,n)=>r in i?Lt(i,r,{enumerable:!0,configurable:!0,writable:!0,value:n}):i[r]=n,qn=(i,r,n,e)=>{for(var t=e>1?void 0:e?Jn(r,n):r,o=i.length-1,a;o>=0;o--)(a=i[o])&&(t=(e?a(r,n,t):a(t))||t);return e&&t&&Lt(r,n,t),t},wt=(i,r)=>(n,e)=>r(n,e,i),Gt=(i,r,n)=>Zn(i,typeof r!="symbol"?r+"":r,n);const Qn="SHEET_IMAGE_UI_PLUGIN";b.UniverSheetsDrawingUIPlugin=class extends d.Plugin{constructor(r=bt,n,e,t){super(),this._config=r,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=d.merge({},bt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Ft,a)}onStarting(){d.registerDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService],[rt],[Ye],[Qe],[Ze],[Je],[xe],[ze],[Xe]]),d.touchDependencies(this._injector,[[b.SheetCanvasFloatDomManagerService]])}onReady(){d.touchDependencies(this._injector,[[Je]])}onRendered(){this._registerRenderModules(),d.touchDependencies(this._injector,[[Ze],[Qe],[rt],[xe],[ze],[Xe]])}onSteady(){this._injector.get(Ye)}_registerRenderModules(){[[Ne],[ft],[lt]].forEach(r=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(d.UniverInstanceType.UNIVER_SHEET,r))})}},Gt(b.UniverSheetsDrawingUIPlugin,"type",d.UniverInstanceType.UNIVER_SHEET),Gt(b.UniverSheetsDrawingUIPlugin,"pluginName",Qn),b.UniverSheetsDrawingUIPlugin=qn([d.DependentOn(O.UniverDrawingPlugin,Se.UniverDocsDrawingPlugin,ue.UniverDrawingUIPlugin,f.UniverSheetsDrawingPlugin),wt(1,d.Inject(d.Injector)),wt(2,N.IRenderManagerService),wt(3,d.IConfigService)],b.UniverSheetsDrawingUIPlugin),b.ClearSheetDrawingTransformerOperation=$,b.DeleteDrawingsCommand=St,b.EditSheetDrawingOperation=ct,b.GroupSheetDrawingCommand=ut,b.InsertFloatImageCommand=et,b.InsertSheetDrawingCommand=Ae,b.MoveDrawingsCommand=Re,b.RemoveSheetDrawingCommand=Oe,b.SHEETS_IMAGE_MENU_ID=vt,b.SetDrawingArrangeCommand=mt,b.SetSheetDrawingCommand=Ue,b.SidebarSheetDrawingOperation=st,b.UngroupSheetDrawingCommand=gt,Object.defineProperty(b,Symbol.toStringTag,{value:"Module"})});
|
|
1
|
+
(function(E,l){typeof exports=="object"&&typeof module<"u"?l(exports,require("@univerjs/core"),require("@univerjs/docs-drawing"),require("@univerjs/drawing"),require("@univerjs/drawing-ui"),require("@univerjs/engine-render"),require("@univerjs/sheets-drawing"),require("@univerjs/sheets-ui"),require("@univerjs/ui"),require("rxjs"),require("@univerjs/sheets"),require("react/jsx-runtime"),require("react"),require("@univerjs/docs-ui"),require("@univerjs/design")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/docs-drawing","@univerjs/drawing","@univerjs/drawing-ui","@univerjs/engine-render","@univerjs/sheets-drawing","@univerjs/sheets-ui","@univerjs/ui","rxjs","@univerjs/sheets","react/jsx-runtime","react","@univerjs/docs-ui","@univerjs/design"],l):(E=typeof globalThis<"u"?globalThis:E||self,l(E.UniverSheetsDrawingUi={},E.UniverCore,E.UniverDocsDrawing,E.UniverDrawing,E.UniverDrawingUi,E.UniverEngineRender,E.UniverSheetsDrawing,E.UniverSheetsUi,E.UniverUi,E.rxjs,E.UniverSheets,E.React,E.React,E.UniverDocsUi,E.UniverDesign))})(this,function(E,l,Se,P,ge,N,w,R,F,W,_,X,q,Tt,ee){"use strict";var si=Object.defineProperty;var ci=(E,l,Se)=>l in E?si(E,l,{enumerable:!0,configurable:!0,writable:!0,value:Se}):E[l]=Se;var z=(E,l,Se)=>ci(E,typeof l!="symbol"?l+"":l,Se);const Ht="sheets-drawing-ui.config",bt={},H={id:"sheet.operation.clear-drawing-transformer",type:l.CommandType.MUTATION,handler:(r,i)=>{const n=r.get(N.IRenderManagerService);return i.forEach(e=>{var t,o;(o=(t=n.getRenderById(e))==null?void 0:t.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},Ce={id:"sheet.command.remove-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{var I,M,b;const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(_.SheetInterceptorService),o=r.get(w.ISheetDrawingService);if(!i)return!1;const{drawings:a}=i,s=[];a.forEach(y=>{const{unitId:T}=y;s.push(T)});const d=o.getBatchRemoveOp(a),{unitId:m,subUnitId:u,undo:c,redo:h,objects:g}=d,p=t.onCommandExecute({id:Ce.id,params:i}),S={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:h,objects:g,type:w.DrawingApplyType.REMOVE}},f={id:w.SetDrawingApplyMutation.id,params:{unitId:m,subUnitId:u,op:c,objects:g,type:w.DrawingApplyType.INSERT}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=p.preUndos)!=null?M:[],f,...p.undos,{id:H.id,params:s}],redoMutations:[...(b=p.preRedos)!=null?b:[],S,...p.redos,{id:H.id,params:s}]}),!0):!1}},Rt="COMPONENT_SHEET_DRAWING_PANEL",gt={id:"sidebar.operation.sheet-image",type:l.CommandType.COMMAND,handler:async(r,i)=>{const n=r.get(F.ISidebarService),e=r.get(l.LocaleService),t=r.get(l.IUniverInstanceService),o=r.get(l.ICommandService);if(!_.getSheetCommandTarget(t))return!1;switch(i.value){case"open":n.open({header:{title:e.t("sheetImage.panel.title")},children:{label:Rt},onClose:()=>{o.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])},width:360});break;case"close":default:n.close();break}return!0}},ht={id:"sheet.operation.edit-sheet-image",type:l.CommandType.OPERATION,handler:(r,i)=>{const n=r.get(l.ICommandService);return i==null?!1:(n.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[i]),n.executeCommand(gt.id,{value:"open"}),!0)}},Ye={uploadLoading:"univer-upload-loading",uploadLoadingBody:"univer-upload-loading-body",uploadLoadingBodyAnimation:"univer-upload-loading-body-animation",univerCircleAnimation:"univer-UniverCircleAnimation",uploadLoadingBodyText:"univer-upload-loading-body-text"},Vt=()=>{const r=l.useDependency(P.IImageIoService),i=l.useDependency(l.LocaleService),[n,e]=q.useState(0);return q.useEffect(()=>{const t=r.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[r]),X.jsx("div",{style:{display:n>0?"block":"none"},className:Ye.uploadLoading,children:X.jsxs("div",{className:Ye.uploadLoadingBody,children:[X.jsx("div",{className:Ye.uploadLoadingBodyAnimation}),X.jsx("div",{className:Ye.uploadLoadingBodyText,children:`${i.t("uploadLoading.loading")}: ${n}`})]})})};var Xt=Object.defineProperty,xt=Object.getOwnPropertyDescriptor,Kt=(r,i,n,e)=>{for(var t=e>1?void 0:e?xt(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Xt(i,n,t),t},he=(r,i)=>(n,e)=>i(n,e,r);let Ge=class extends l.RxDisposable{constructor(i,n,e,t,o,a,s,d){super();z(this,"_initImagePopupMenu",new Set);this._injector=i,this._drawingManagerService=n,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=a,this._uiPartsService=s,this._commandService=d,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(i=>this._create(i)),this._univerInstanceService.getTypeOfUnitDisposed$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.takeUntil(this.dispose$)).subscribe(i=>this._dispose(i)),this._univerInstanceService.getAllUnitsForType(l.UniverInstanceType.UNIVER_SHEET).forEach(i=>this._create(i)),this._uiPartsService.registerComponent(F.BuiltInUIPart.CONTENT,()=>l.connectInjector(Vt,this._injector))}_dispose(i){const n=i.getUnitId();this._renderManagerService.removeRender(n)}_create(i){if(!i)return;const n=i.getUnitId();this._renderManagerService.has(n)&&!this._initImagePopupMenu.has(n)&&(this._popupMenuListener(n),this._initImagePopupMenu.add(n))}_hasCropObject(i){const n=i.getAllObjectsByOrder();for(const e of n)if(e instanceof ge.ImageCropperObject)return!0;return!1}_popupMenuListener(i){var o;const n=(o=this._renderManagerService.getRenderById(i))==null?void 0:o.scene;if(!n)return;const e=n.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(l.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(n))return;const a=e.getSelectedObjectMap();if(a.size>1){t==null||t.dispose();return}const s=a.values().next().value;if(!s)return;const d=s.oKey,m=this._drawingManagerService.getDrawingOKey(d);if(!m)return;const{unitId:u,subUnitId:c,drawingId:h,drawingType:g}=m,p=m.data;if(p&&p.disablePopup)return;t==null||t.dispose();const S=this._canvasPopManagerService.getFeatureMenu(u,c,h,g);t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(s,{componentKey:ge.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:S||this._getImageMenuItems(u,c,h,g)}}))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[])})),this.disposeWithMe(this._contextService.contextChanged$.subscribe(a=>{a[l.FOCUSING_COMMON_DRAWINGS]===!1&&(t==null||t.dispose())})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(i,n,e,t){return[{label:"image-popup.edit",index:0,commandId:ht.id,commandParams:{unitId:i,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:Ce.id,commandParams:{unitId:i,drawings:[{unitId:i,subUnitId:n,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:ge.OpenImageCropOperation.id,commandParams:{unitId:i,subUnitId:n,drawingId:e},disable:t===l.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:ge.ImageResetSizeOperation.id,commandParams:[{unitId:i,subUnitId:n,drawingId:e}],disable:t===l.DrawingTypeEnum.DRAWING_DOM}]}};Ge=Kt([he(0,l.Inject(l.Injector)),he(1,P.IDrawingManagerService),he(2,l.Inject(R.SheetCanvasPopManagerService)),he(3,N.IRenderManagerService),he(4,l.IUniverInstanceService),he(5,l.IContextService),he(6,l.Inject(F.IUIPartsService)),he(7,l.ICommandService)],Ge);function x(r,i,n){const{from:e,to:t,flipY:o=!1,flipX:a=!1,angle:s=0,skewX:d=0,skewY:m=0}=r,u=n.getCurrent();if(u==null)return;const c=R.convertPositionSheetOverGridToAbsolute(u.unitId,u.sheetId,{from:e,to:t},n);let{left:h,top:g,width:p,height:S}=c;const f=n.getCurrentSkeleton(),v=f.rowHeaderWidth+f.columnTotalWidth,I=f.columnHeaderHeight+f.rowTotalHeight;return h+p>v&&(h=v-p),g+S>I&&(g=I-S),{flipY:o,flipX:a,angle:s,skewX:d,skewY:m,left:h,top:g,width:p,height:S}}function V(r,i){const{left:n=0,top:e=0,width:t=0,height:o=0,flipY:a=!1,flipX:s=!1,angle:d=0,skewX:m=0,skewY:u=0}=r,c=i.getCellWithCoordByOffset(n,e);if(c==null)return;const h={column:c.actualColumn,columnOffset:N.precisionTo(n-c.startX,1),row:c.actualRow,rowOffset:N.precisionTo(e-c.startY,1)},g=i.getCellWithCoordByOffset(n+t,e+o);if(g==null)return;const p={column:g.actualColumn,columnOffset:N.precisionTo(n+t-g.startX,1),row:g.actualRow,rowOffset:N.precisionTo(e+o-g.startY,1)};return{flipY:a,flipX:s,angle:d,skewX:m,skewY:u,from:h,to:p}}var zt=Object.defineProperty,qt=Object.getOwnPropertyDescriptor,Zt=(r,i,n,e)=>{for(var t=e>1?void 0:e?qt(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&zt(i,n,t),t},Fe=(r,i)=>(n,e)=>i(n,e,r);let mt=class extends l.Disposable{constructor(r,i,n,e,t){super(),this._context=r,this._sheetDrawingService=i,this._drawingManagerService=n,this._sheetSelectionRenderService=e,this._sheetSkeletonManagerService=t,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const r=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const i in r){const n=r[i];for(const e in n.data){const t=n.data[e];t.transform=x(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};mt=Zt([Fe(1,w.ISheetDrawingService),Fe(2,P.IDrawingManagerService),Fe(3,l.Inject(R.ISheetSelectionRenderService)),Fe(4,l.Inject(R.SheetSkeletonManagerService))],mt);function Jt(r){const i=[];return r.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s}=e,d=N.getGroupState(0,0,t.map(c=>c.transform||{})),m=t.map(c=>{const h=c.transform||{left:0,top:0},{unitId:g,subUnitId:p,drawingId:S}=c;return{unitId:g,subUnitId:p,drawingId:S,transform:{...h,left:h.left-d.left,top:h.top-d.top},groupId:s}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:d};i.push({parent:u,children:m})}),i}function Qt(r){const i=[];return r.forEach(n=>{const{parent:e,children:t}=n,{unitId:o,subUnitId:a,drawingId:s,transform:d={width:0,height:0}}=e;if(d==null)return;const m=t.map(c=>{const{transform:h}=c,{unitId:g,subUnitId:p,drawingId:S}=c,f=N.transformObjectOutOfGroup(h||{},d,d.width||0,d.height||0);return{unitId:g,subUnitId:p,drawingId:S,transform:f,groupId:void 0}}),u={unitId:o,subUnitId:a,drawingId:s,drawingType:l.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};i.push({parent:u,children:m})}),i}const pt={id:"sheet.command.group-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const o=[];i.forEach(({parent:g,children:p})=>{o.push(g.unitId),p.forEach(S=>{o.push(S.unitId)})});const a=t.getGroupDrawingOp(i),{unitId:s,subUnitId:d,undo:m,redo:u,objects:c}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:d,objects:Qt(c),type:w.DrawingApplyType.UNGROUP}},{id:H.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.GROUP}},{id:H.id,params:o}]}),!0):!1}},Pe={id:"sheet.command.insert-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{var I,M,b;const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService),o=r.get(_.SheetInterceptorService);if(!i)return!1;const a=i.drawings,s=a.map(y=>y.unitId),d=t.getBatchAddOp(a),{unitId:m,subUnitId:u,undo:c,redo:h,objects:g}=d,p=o.onCommandExecute({id:Pe.id,params:i}),S={id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:m,subUnitId:u,objects:g,type:w.DrawingApplyType.INSERT}},f={id:w.SetDrawingApplyMutation.id,params:{op:c,unitId:m,subUnitId:u,objects:g,type:w.DrawingApplyType.REMOVE}};return l.sequenceExecute([...(I=p.preRedos)!=null?I:[],S,...p.redos],n)?(e.pushUndoRedo({unitID:m,undoMutations:[...(M=p.preUndos)!=null?M:[],f,...p.undos,{id:H.id,params:s}],redoMutations:[...(b=p.preRedos)!=null?b:[],S,...p.redos,{id:H.id,params:s}]}),!0):!1}},ft={id:"sheet.command.set-drawing-arrange",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService);if(!i)return!1;const t=r.get(w.ISheetDrawingService),{unitId:o,subUnitId:a,drawingIds:s,arrangeType:d}=i,m={unitId:o,subUnitId:a,drawingIds:s};let u;if(d===l.ArrangeTypeEnum.forward?u=t.getForwardDrawingsOp(m):d===l.ArrangeTypeEnum.backward?u=t.getBackwardDrawingOp(m):d===l.ArrangeTypeEnum.front?u=t.getFrontDrawingsOp(m):d===l.ArrangeTypeEnum.back&&(u=t.getBackDrawingsOp(m)),u==null)return!1;const{objects:c,redo:h,undo:g}=u;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:h,unitId:o,subUnitId:a,objects:c,type:w.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:a,objects:c,type:w.DrawingApplyType.ARRANGE}}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:h,unitId:o,subUnitId:a,objects:c,type:w.DrawingApplyType.ARRANGE}}]}),!0):!1}},Ae={id:"sheet.command.set-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const{drawings:o}=i,a=t.getBatchUpdateOp(o),{unitId:s,subUnitId:d,undo:m,redo:u,objects:c}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:s,subUnitId:d,op:u,objects:c,type:w.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:m,objects:c,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[s]}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{unitId:s,subUnitId:d,op:u,objects:c,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[s]}]}),!0):!1}},St={id:"sheet.command.ungroup-sheet-image",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(l.IUndoRedoService),t=r.get(w.ISheetDrawingService);if(!i)return!1;const o=[];i.forEach(({parent:g,children:p})=>{o.push(g.unitId),p.forEach(S=>{o.push(S.unitId)})});const a=t.getUngroupDrawingOp(i),{unitId:s,subUnitId:d,undo:m,redo:u,objects:c}=a;return n.syncExecuteCommand(w.SetDrawingApplyMutation.id,{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:s,undoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:m,unitId:s,subUnitId:d,objects:Jt(c),type:w.DrawingApplyType.GROUP}},{id:H.id,params:o}],redoMutations:[{id:w.SetDrawingApplyMutation.id,params:{op:u,unitId:s,subUnitId:d,objects:c,type:w.DrawingApplyType.UNGROUP}},{id:H.id,params:o}]}),!0):!1}};var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(r,i,n,e)=>{for(var t=e>1?void 0:e?tn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&en(i,n,t),t},Z=(r,i)=>(n,e)=>i(n,e,r);function rn(r,i,n){const e=n*Math.PI/180,t=Math.abs(r*Math.cos(e))+Math.abs(i*Math.sin(e)),o=Math.abs(r*Math.sin(e))+Math.abs(i*Math.cos(e));return{rotatedWidth:t,rotatedHeight:o}}function Et(r,i,n,e,t){var I;const{rotatedHeight:o,rotatedWidth:a}=rn(n,e,t),d=r.get(N.IRenderManagerService).getRenderById(i.unitId);if(!d)return!1;const u=(I=d.with(R.SheetSkeletonManagerService).getWorksheetSkeleton(i.subUnitId))==null?void 0:I.skeleton;if(u==null)return!1;const c=u.getCellByIndex(i.row,i.col),h=c.mergeInfo.endX-c.mergeInfo.startX-2,g=c.mergeInfo.endY-c.mergeInfo.startY-2,p=a/o,f=Math.ceil(Math.min(h,g*p))/a,v=!f||Number.isNaN(f)?.001:f;return{width:n*v,height:e*v}}let Ue=class extends l.Disposable{constructor(i,n,e,t,o,a,s,d,m,u,c,h,g){super();z(this,"_workbookSelections");this._context=i,this._skeletonManagerService=n,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=a,this._sheetDrawingService=s,this._drawingManagerService=d,this._contextService=m,this._messageService=u,this._localeService=c,this._injector=g,this._workbookSelections=h.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const i=await this._fileOpenerService.openFile({multiple:!0,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),n=i.length;return n>P.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(P.DRAWING_IMAGE_COUNT_LIMIT))}),!1):n===0?!1:(i.forEach(async e=>await this.insertFloatImageByFile(e)),!0)}async insertCellImage(){const n=(await this._fileOpenerService.openFile({multiple:!1,accept:P.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}))[0];return n?(await this._insertCellImage(n),!0):!1}async insertFloatImageByFile(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(I){const M=I.message;M===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):M===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):M===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:a,imageSourceType:s,source:d,base64Cache:m}=n,{width:u,height:c,image:h}=await P.getImageSize(m||""),{width:g,height:p}=this._context.scene;this._imageIoService.addImageSourceCache(d,s,h);let S=1;if(u>P.DRAWING_IMAGE_WIDTH_LIMIT||c>P.DRAWING_IMAGE_HEIGHT_LIMIT){const I=P.DRAWING_IMAGE_WIDTH_LIMIT/u,M=P.DRAWING_IMAGE_HEIGHT_LIMIT/c;S=Math.max(I,M)}const f=this._getImagePosition(u*S,c*S,g,p);if(f==null)return;const v={unitId:t,subUnitId:o,drawingId:a,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:s,source:d,transform:x(f,this._selectionRenderService,this._skeletonManagerService),sheetTransform:f};return this._commandService.executeCommand(Pe.id,{unitId:t,drawings:[v]})}async _insertCellImage(i){let n;try{n=await this._imageIoService.saveImage(i)}catch(f){const v=f.message;v===P.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(P.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):v===P.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):v===P.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:ee.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(n==null)return;const{imageId:e,imageSourceType:t,source:o,base64Cache:a}=n,{width:s,height:d,image:m}=await P.getImageSize(a||"");this._imageIoService.addImageSourceCache(o,t,m);const u=this._workbookSelections.getCurrentLastSelection();if(!u)return!1;const c=l.createDocumentModelWithStyle("",{}),h=Et(this._injector,{unitId:this._context.unitId,subUnitId:this._context.unit.getActiveSheet().getSheetId(),row:u.primary.actualRow,col:u.primary.actualColumn},s,d,0);if(!h)return!1;const g={size:{width:h.width,height:h.height},positionH:{relativeFrom:l.ObjectRelativeFromH.PAGE,posOffset:0},positionV:{relativeFrom:l.ObjectRelativeFromV.PARAGRAPH,posOffset:0},angle:0},p={unitId:c.getUnitId(),subUnitId:c.getUnitId(),drawingId:e,drawingType:l.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:t,source:o,transform:Tt.docDrawingPositionToTransform(g),docTransform:g,behindDoc:l.BooleanNumber.FALSE,title:"",description:"",layoutType:l.PositionedObjectLayoutType.INLINE,wrapText:l.WrapTextType.BOTH_SIDES,distB:0,distL:0,distR:0,distT:0},S=l.BuildTextUtils.drawing.add({documentDataModel:c,drawings:[p],selection:{collapsed:!0,startOffset:0,endOffset:0}});return S?(c.apply(S),this._commandService.syncExecuteCommand(_.SetRangeValuesCommand.id,{value:{[u.primary.actualRow]:{[u.primary.actualColumn]:{p:c.getSnapshot(),t:1}}}})):!1}_getUnitInfo(){const i=this._context.unit,n=i.getActiveSheet(),e=i.getUnitId(),t=n.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(i,n,e,t){const o=this._workbookSelections.getCurrentSelections();let a={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(a=o[o.length-1].range);const s=R.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,a);if(s==null)return;let{startColumn:d,startRow:m,startX:u,startY:c}=s,h=!1;if(u+i>e&&(u=e-i,u<0&&(u=0,i=e),h=!0),c+n>t&&(c=t-n,c<0&&(c=0,n=t),h=!0),h){const f=this._selectionRenderService.getCellWithCoordByOffset(u,c);if(f==null)return;u=f.startX,c=f.startY,d=f.actualColumn,m=f.actualRow}const g={column:d,columnOffset:0,row:m,rowOffset:0},p=this._selectionRenderService.getCellWithCoordByOffset(u+i,c+n);if(p==null)return;const S={column:p.actualColumn,columnOffset:u+i-p.startX,row:p.actualRow,rowOffset:c+n-p.startY};return{from:g,to:S}}_updateOrderListener(){this.disposeWithMe(this._drawingManagerService.featurePluginOrderUpdate$.subscribe(i=>{const{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o}=i;this._commandService.executeCommand(ft.id,{unitId:n,subUnitId:e,drawingIds:t,arrangeType:o})}))}_updateImageListener(){this.disposeWithMe(this._drawingManagerService.featurePluginUpdate$.subscribe(i=>{const n=[];i.length!==0&&(i.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a,drawingType:s,transform:d}=e;if(d==null)return;const m=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:a});if(m==null||m.unitId!==this._context.unitId)return;const u=V({...m.transform,...d},this._selectionRenderService);if(u==null)return;const c={...e,transform:{...m.transform,...d,...x(u,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...u}};n.push(c)}),n.length>0&&this._commandService.executeCommand(Ae.id,{unitId:i[0].unitId,drawings:n}))}))}_groupDrawingListener(){this.disposeWithMe(this._drawingManagerService.featurePluginGroupUpdate$.subscribe(i=>{this._commandService.executeCommand(pt.id,i);const{unitId:n,subUnitId:e,drawingId:t}=i[0].parent;this._commandService.syncExecuteCommand(P.SetDrawingSelectedOperation.id,[{unitId:n,subUnitId:e,drawingId:t}])})),this.disposeWithMe(this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(i=>{this._commandService.executeCommand(St.id,i)}))}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(i=>{i==null||i.length===0?(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(l.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(i))}))}};Ue=nn([Z(1,l.Inject(R.SheetSkeletonManagerService)),Z(2,l.ICommandService),Z(3,R.ISheetSelectionRenderService),Z(4,P.IImageIoService),Z(5,F.ILocalFileService),Z(6,w.ISheetDrawingService),Z(7,P.IDrawingManagerService),Z(8,l.IContextService),Z(9,F.IMessageService),Z(10,l.Inject(l.LocaleService)),Z(11,l.Inject(_.SheetsSelectionsService)),Z(12,l.Inject(l.Injector))],Ue);var on=Object.defineProperty,an=Object.getOwnPropertyDescriptor,sn=(r,i,n,e)=>{for(var t=e>1?void 0:e?an(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&on(i,n,t),t},we=(r,i)=>(n,e)=>i(n,e,r);function wt(r,i,n){var e,t,o,a;if(((t=(e=n==null?void 0:n.p)==null?void 0:e.body)==null?void 0:t.dataStream.length)===3&&((a=(o=n.p)==null?void 0:o.drawingsOrder)==null?void 0:a.length)===1){const s=n.p.drawings[n.p.drawingsOrder[0]],d=Et(r,{unitId:i.unitId,subUnitId:i.subUnitId,row:i.row,col:i.col},s.docTransform.size.width,s.docTransform.size.height,s.docTransform.angle);if(d)return s.transform.width=d.width,s.transform.height=d.height,s.docTransform.size.width=d.width,s.docTransform.size.height=d.height,s.transform.left=0,s.transform.top=0,s.docTransform.positionH.posOffset=0,s.docTransform.positionV.posOffset=0,n.p.documentStyle.pageSize.width=1/0,n.p.documentStyle.pageSize.height=1/0,!0}return!1}let He=class extends l.Disposable{constructor(r,i,n,e,t,o,a){super(),this._commandService=r,this._sheetInterceptorService=i,this._univerInstanceService=n,this._injector=e,this._drawingManagerService=t,this._docDrawingController=o,this._editorBridgeService=a,this._initHandleResize(),this._handleInitEditor(),this._handleWriteCell(),this._initCellContentInterceptor()}_initHandleResize(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{let i,n=[];if(r.id===_.SetWorksheetRowHeightMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===_.SetWorksheetColWidthMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===_.SetWorksheetRowIsAutoHeightMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===_.SetWorksheetRowAutoHeightMutation.id){const e=r.params;i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId}),n=e.rowsAutoHeightInfo.map(t=>({startRow:t.row,endRow:t.row,startColumn:0,endColumn:9999}))}else if(r.id===_.AddWorksheetMergeMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}else if(r.id===_.RemoveWorksheetMergeMutation.id){const e=r.params;n=e.ranges,i=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId})}i&&n.length&&n.forEach(e=>{const t=l.Range.transformRange(e,i.worksheet);for(let o=t.startRow;o<=t.endRow;o++)for(let a=t.startColumn;a<=t.endColumn;a++)wt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:o,col:a},i.worksheet.getCellRaw(o,a))})}))}_handleInitEditor(){this.disposeWithMe(this._editorBridgeService.visible$.subscribe(r=>{r.visible?r.visible&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)):this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY)})),this.disposeWithMe(this._commandService.onCommandExecuted(r=>{r.id===Tt.ReplaceSnapshotCommand.id&&r.params.unitId===l.DOCS_ZEN_EDITOR_UNIT_ID_KEY&&(this._drawingManagerService.removeDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._docDrawingController.loadDrawingDataForUnit(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY),this._drawingManagerService.initializeNotification(l.DOCS_ZEN_EDITOR_UNIT_ID_KEY))}))}_handleWriteCell(){this.disposeWithMe(this._sheetInterceptorService.writeCellInterceptor.intercept(_.AFTER_CELL_EDIT,{priority:9999,handler:(r,i,n)=>(wt(this._injector,{unitId:i.unitId,subUnitId:i.subUnitId,row:i.row,col:i.col},r),n(r))}))}_initCellContentInterceptor(){this.disposeWithMe(this._sheetInterceptorService.intercept(_.INTERCEPTOR_POINT.CELL_CONTENT,{effect:l.InterceptorEffectEnum.Style,priority:_.InterceptCellContentPriority.CELL_IMAGE,handler:(r,i,n)=>{var e;return r!=null&&r.p&&((e=r.p.drawingsOrder)!=null&&e.length)&&(r.interceptorStyle||(r.interceptorStyle={}),r.interceptorStyle.tr={a:0}),n(r)}}))}};He=sn([we(0,l.ICommandService),we(1,l.Inject(_.SheetInterceptorService)),we(2,l.IUniverInstanceService),we(3,l.Inject(l.Injector)),we(4,P.IDrawingManagerService),we(5,l.Inject(Se.DocDrawingController)),we(6,l.Inject(R.IEditorBridgeService))],He);var cn=Object.defineProperty,dn=Object.getOwnPropertyDescriptor,ln=(r,i,n,e)=>{for(var t=e>1?void 0:e?dn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&cn(i,n,t),t},Ot=(r,i)=>(n,e)=>i(n,e,r);let Ve=class extends l.Disposable{constructor(r,i){super(),this._autoFillService=r,this._injector=i,this._initAutoFillHooks()}_initAutoFillHooks(){this.disposeWithMe(this._autoFillService.addHook({id:"sheet-cell-image-autofill",onBeforeSubmit:(r,i,n,e)=>{new l.ObjectMatrix(e).forValue((t,o,a)=>{wt(this._injector,{unitId:r.unitId,subUnitId:r.subUnitId,row:t,col:o},a)})}}))}};Ve=ln([Ot(0,l.Inject(R.IAutoFillService)),Ot(1,l.Inject(l.Injector))],Ve);var un=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,hn=(r,i,n,e)=>{for(var t=e>1?void 0:e?gn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&un(i,n,t),t},Xe=(r,i)=>(n,e)=>i(n,e,r);let xe=class extends l.Disposable{constructor(i,n,e,t){super();z(this,"_isSetCursor",!1);this._hoverManagerService=i,this._renderManagerService=n,this._selectionsService=e,this._drawingRenderService=t}_initHover(){}_initImageClick(){}};xe=hn([Xe(0,l.Inject(R.HoverManagerService)),Xe(1,l.Inject(N.IRenderManagerService)),Xe(2,l.Inject(_.SheetsSelectionsService)),Xe(3,l.Inject(ge.DrawingRenderService))],xe);const Ne={id:"sheet.command.insert-float-image",type:l.CommandType.COMMAND,handler:async(r,i)=>{var o,a;const e=(o=r.get(N.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:o.with(Ue);if(!e)return!1;const t=i==null?void 0:i.files;if(t){const s=t.map(d=>e.insertFloatImageByFile(d));return(await Promise.all(s)).every(d=>d)}else return(a=e.insertFloatImage())!=null?a:!1}},vt={id:"sheet.command.insert-cell-image",type:l.CommandType.COMMAND,handler:r=>{var n,e;return(e=(n=r.get(N.IRenderManagerService).getCurrentTypeOfRenderer(l.UniverInstanceType.UNIVER_SHEET))==null?void 0:n.with(Ue).insertCellImage())!=null?e:!1}};var mn=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,fn=(r,i,n,e)=>{for(var t=e>1?void 0:e?pn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&mn(i,n,t),t},je=(r,i)=>(n,e)=>i(n,e,r);const Pt="image/png";function Sn(r){const i=r.split(","),n=atob(i[1]),e=n.length,t=new Uint8Array(e);for(let o=0;o<e;o++)t[o]=n.charCodeAt(o);return new Blob([t],{type:Pt})}function wn(r){const i=new ClipboardItem({[Pt]:Sn(r)});navigator.clipboard.write([i]).catch(n=>{console.error("Could not copy image using clipboard API: ",n)})}function vn(){function r(){const e=document.createElement("input");return e.style.position="absolute",e.style.height="1px",e.style.width="1px",e.style.opacity="0",e}const i=document.activeElement,n=r();return document.body.appendChild(n),n.focus(),()=>{n.blur(),document.body.removeChild(n),i instanceof HTMLElement&&i.focus()}}const At=[R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,R.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA];let Ke=class extends l.Disposable{constructor(i,n,e,t,o){super();z(this,"_copyInfo");this._sheetClipboardService=i,this._renderManagerService=n,this._drawingService=e,this._clipboardInterfaceService=t,this._commandService=o,this._initCopyPaste()}get _focusedDrawings(){return this._drawingService.getFocusDrawings()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(i,n,e,t)=>{const o=this._focusedDrawings;if(o.length>0){const[a]=o;if(t===R.COPY_TYPE.CUT){const d={unitId:i,drawings:[a]};this._commandService.executeCommand(Ce.id,d)}setTimeout(()=>{const d=vn();a.drawingType===l.DrawingTypeEnum.DRAWING_IMAGE&&a.imageSourceType===P.ImageSourceType.BASE64?wn(a.source):this._clipboardInterfaceService.writeText(""),d()},200);const s={unitId:a.unitId,subUnitId:a.subUnitId,drawings:[a]};this._copyInfo=s}else{const a=this._createDrawingsCopyInfoByRange(i,n,e);this._copyInfo=a}},onPasteCells:(i,n,e,t)=>{if(!this._copyInfo)return{redos:[],undos:[]};const{copyType:o=R.COPY_TYPE.COPY,pasteType:a}=t,{range:s}=i||{},{range:d,unitId:m,subUnitId:u}=n;return this._copyInfo.copyRange?this._generateRangeDrawingsPasteMutations({pasteType:a,unitId:m,subUnitId:u,pasteRange:d},{copyRange:s,copyType:o}):this._generateSingleDrawingPasteMutations({pasteTo:n,pasteType:a},R.COPY_TYPE.COPY)},onPastePlainText:(i,n)=>({undos:[],redos:[]}),onPasteUnrecognized:i=>this._copyInfo?this._generateSingleDrawingPasteMutations({pasteTo:i,pasteType:R.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},R.COPY_TYPE.COPY):{undos:[],redos:[]},onPasteFiles:(i,n)=>{if(this._copyInfo)return this._generateSingleDrawingPasteMutations({pasteTo:i,pasteType:R.PREDEFINED_HOOK_NAME.DEFAULT_PASTE},R.COPY_TYPE.COPY);{const e=n.filter(t=>t.type.includes("image"));if(e.length)return{undos:[],redos:[{id:Ne.id,params:{files:e}}]}}return{undos:[],redos:[]}}})}_createDrawingsCopyInfoByRange(i,n,e){var h;const t=(h=this._renderManagerService.getRenderById(i))==null?void 0:h.with(R.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:a,endX:s,startY:d,endY:m}=o,u=this._drawingService.getDrawingData(i,n),c=this._focusedDrawings.slice();if(Object.keys(u).forEach(g=>{const p=u[g],{transform:S}=p;if(p.anchorType!==w.SheetDrawingAnchorType.Both||!S)return;const{left:f=0,top:v=0,width:I=0,height:M=0}=S,{drawingStartX:b,drawingEndX:y,drawingStartY:T,drawingEndY:C}={drawingStartX:f,drawingEndX:f+I,drawingStartY:v,drawingEndY:v+M};a<=b&&y<=s&&d<=T&&C<=m&&c.push(p)}),c.length)return{copyRange:e,drawings:c,unitId:i,subUnitId:n}}_generateSingleDrawingPasteMutations(i,n){const{pasteType:e,pasteTo:t}=i;if(At.includes(e))return{redos:[],undos:[]};const{unitId:o,subUnitId:a,range:s}=t,d=this._renderManagerService.getRenderById(o),m=d==null?void 0:d.with(R.SheetSkeletonManagerService),u=d==null?void 0:d.with(R.ISheetSelectionRenderService),c=this._copyInfo;if(!m||!u)return{redos:[],undos:[]};const{drawings:h}=c,g=R.discreteRangeToRange(s);return this._generateMutations(h,{unitId:o,subUnitId:a,isCut:n===R.COPY_TYPE.CUT,getTransform:(p,S)=>{var I;const f=m.attachRangeWithCoord({startRow:g.startRow,endRow:g.endRow,startColumn:g.startColumn,endColumn:g.endColumn}),v={...p,left:f==null?void 0:f.startX,top:f==null?void 0:f.startY};return{transform:v,sheetTransform:(I=V(v,u))!=null?I:S}}})}_generateMutations(i,n){const{unitId:e,subUnitId:t,getTransform:o,isCut:a}=n,s=[],d=[],{_drawingService:m}=this;return i.forEach(u=>{const{transform:c,sheetTransform:h}=u;if(!c)return;const g=o(c,h),p={...u,unitId:e,subUnitId:t,drawingId:a?u.drawingId:l.Tools.generateRandomId(),transform:g.transform,sheetTransform:g.sheetTransform};if(a){const{undo:S,redo:f,objects:v}=m.getBatchUpdateOp([p]);s.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,type:w.DrawingApplyType.UPDATE,op:f,objects:v}}),d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,type:w.DrawingApplyType.UPDATE,op:S,objects:v}})}else{const{undo:S,redo:f,objects:v}=m.getBatchAddOp([p]);s.push({id:w.SetDrawingApplyMutation.id,params:{op:f,unitId:e,subUnitId:t,objects:v,type:w.DrawingApplyType.INSERT}}),d.push({id:w.SetDrawingApplyMutation.id,params:{op:S,unitId:e,subUnitId:t,objects:v,type:w.DrawingApplyType.REMOVE}})}}),{redos:s,undos:d}}_generateRangeDrawingsPasteMutations(i,n){var j;const{unitId:e,subUnitId:t,pasteType:o,pasteRange:a}=i,{copyRange:s,copyType:d}=n;if(At.includes(o))return{redos:[],undos:[]};const m=(j=this._renderManagerService.getRenderById(e))==null?void 0:j.with(R.SheetSkeletonManagerService);if(!m||!this._copyInfo)return{redos:[],undos:[]};const{drawings:u}=this._copyInfo;if(!s)return this._generateSingleDrawingPasteMutations({pasteTo:{unitId:e,subUnitId:t,range:R.discreteRangeToRange(a)},pasteType:o},d);const{ranges:[c,h],mapFunc:g}=R.virtualizeDiscreteRanges([s,a]),{row:p,col:S}=g(c.startRow,c.startColumn),{row:f,col:v}=g(h.startRow,h.startColumn),I=m.attachRangeWithCoord({startRow:p,endRow:p,startColumn:S,endColumn:S}),M=m.attachRangeWithCoord({startRow:f,endRow:f,startColumn:v,endColumn:v});if(!I||!M||!this._copyInfo)return{redos:[],undos:[]};const b=M.startX-I.startX,y=M.startY-I.startY,T=f-p,C=v-S;return this._generateMutations(u,{unitId:e,subUnitId:t,getTransform:(O,L)=>{var U,A;return{transform:{...O,left:((U=O==null?void 0:O.left)!=null?U:0)+b,top:((A=O==null?void 0:O.top)!=null?A:0)+y},sheetTransform:{...L,to:{...L.to,row:L.to.row+T,column:L.to.column+C},from:{...L.from,row:L.from.row+T,column:L.from.column+C}}}},isCut:d===R.COPY_TYPE.CUT})}};Ke=fn([je(0,R.ISheetClipboardService),je(1,N.IRenderManagerService),je(2,P.IDrawingManagerService),je(3,F.IClipboardInterfaceService),je(4,l.ICommandService)],Ke);var _n=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Cn=(r,i,n,e)=>{for(var t=e>1?void 0:e?In(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&_n(i,n,t),t},We=(r,i)=>(n,e)=>i(n,e,r);let ze=class extends l.Disposable{constructor(r,i,n,e,t){super(),this._drawingManagerService=r,this._renderManagerService=i,this._permissionService=n,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{if(!i){this._drawingManagerService.setDrawingVisible(!1);return}i.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=i.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const s=i.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,d),u=Object.values(m),c=this._renderManagerService.getRenderById(s),h=c==null?void 0:c.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(p=>{p.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>p.oKey.includes(S.drawingId))&&h.removeObject(p)})}})}))}_initDrawingEditable(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{if(!i){this._drawingManagerService.setDrawingEditable(!1);return}i.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=i.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).every(s=>s.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const s=i.getUnitId(),d=e.getSheetId(),m=this._drawingManagerService.getDrawingData(s,d),u=Object.values(m),c=this._renderManagerService.getRenderById(s),h=c==null?void 0:c.scene;if(h==null)return;h.getAllObjectsByOrder().forEach(p=>{p.classType===N.RENDER_CLASS_TYPE.IMAGE&&u.some(S=>p.oKey.includes(S.drawingId))&&h.detachTransformerFrom(p)})}})}))}_initViewPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{i&&i.activeSheet$.subscribe(e=>{var c;if(!e)return;const t=i.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),d=s==null?void 0:s.scene;if(d==null)return;const m=d.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookViewPermission(t).id,new _.WorksheetViewPermission(t,o).id]).pipe(W.map(h=>h.every(g=>g.value)));u==null||u.pipe(W.filter(h=>h!==a),W.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingVisible(h);const g=d.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),S=Object.values(p);h?this._drawingManagerService.addNotification(S):(g.forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(v=>f.oKey.includes(v.drawingId))&&d.removeObject(f)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetViewPermission(t,o).id))==null||c.pipe(W.filter(h=>h.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0,this._drawingManagerService.setDrawingVisible(!0);const h=this._drawingManagerService.getDrawingData(t,o),g=Object.values(h);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const r=this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(W.combineLatest([r,this._userManagerService.currentUser$]).subscribe(([i,n])=>{i&&i.activeSheet$.subscribe(e=>{var c;if(!e)return;const t=i.getUnitId(),o=e.getSheetId();let a=!0;const s=this._renderManagerService.getRenderById(t),d=s==null?void 0:s.scene;if(d==null)return;const m=d.getTransformerByCreate(),u=this._permissionService.composePermission$([new _.WorkbookEditablePermission(t).id,new _.WorksheetEditPermission(t,o).id]).pipe(W.map(h=>h.every(g=>g.value)));u==null||u.pipe(W.filter(h=>h!==a),W.distinctUntilChanged()).subscribe({next:h=>{a=h,this._drawingManagerService.setDrawingEditable(h);const g=d.getAllObjectsByOrder(),p=this._drawingManagerService.getDrawingData(t,o),S=Object.values(p);h?(g.forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(v=>f.oKey.includes(v.drawingId))&&d.attachTransformerTo(f)}),this._drawingManagerService.addNotification(S)):(g.forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(v=>f.oKey.includes(v.drawingId))&&d.detachTransformerFrom(f)}),m.clearSelectedObjects())}}),(c=this._permissionService.getPermissionPoint$(new _.WorksheetEditPermission(t,o).id))==null||c.pipe(W.filter(h=>h.value!==a),W.distinctUntilChanged()).subscribe({complete:()=>{a=!0;const h=i.getUnitId(),g=e.getSheetId(),p=this._drawingManagerService.getDrawingData(h,g),S=Object.values(p),f=this._renderManagerService.getRenderById(h),v=f==null?void 0:f.scene;if(v==null)return;this._drawingManagerService.setDrawingEditable(!0),v.getAllObjectsByOrder().forEach(M=>{M.classType===N.RENDER_CLASS_TYPE.IMAGE&&S.some(b=>M.oKey.includes(b.drawingId))&&v.detachTransformerFrom(M)})}})})}))}};ze=Cn([We(0,P.IDrawingManagerService),We(1,N.IRenderManagerService),We(2,l.IPermissionService),We(3,l.IUniverInstanceService),We(4,l.Inject(l.UserManagerService))],ze);var yn=Object.defineProperty,Dn=Object.getOwnPropertyDescriptor,Mn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Dn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&yn(i,n,t),t},qe=(r,i)=>(n,e)=>i(n,e,r);let Ze=class extends l.Disposable{constructor(r,i,n,e){super(),this._sheetPrintInterceptorService=r,this._drawingRenderService=i,this._drawingManagerService=n,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(r,i,n)=>{const{unitId:e,scene:t,subUnitId:o}=i,a=this._drawingManagerService.getDrawingDataForUnit(e),s=a==null?void 0:a[o];return s&&s.order.forEach(d=>{this._drawingRenderService.renderDrawing(s.data[d],t)}),n()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(r,i,n)=>{const{unitId:e,subUnitId:t}=i,o=this._renderManagerService.getRenderById(e);if(!o)return n(r);const a=o.with(R.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!a)return n(r);const s=this._drawingManagerService.getDrawingDataForUnit(e),d=s==null?void 0:s[i.subUnitId];if(!d)return n(r);const{scaleX:m,scaleY:u}=o.scene,c=r?{...r}:{startColumn:0,endColumn:0,endRow:0,startRow:0},h=d.order.map(g=>d.data[g]).filter(g=>g.drawingType!==l.DrawingTypeEnum.DRAWING_DOM);return h.length?(h.forEach(g=>{if(!g.groupId&&g.transform&&l.Tools.isDefine(g.transform.left)&&l.Tools.isDefine(g.transform.top)&&l.Tools.isDefine(g.transform.width)&&l.Tools.isDefine(g.transform.height)){const p=a.skeleton.getCellIndexByOffset(g.transform.left,g.transform.top,m,u,{x:0,y:0}),S=a.skeleton.getCellIndexByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,m,u,{x:0,y:0});p.column<c.startColumn&&(c.startColumn=p.column),p.row<c.startRow&&(c.startRow=p.row),c.endRow<S.row&&(c.endRow=S.row),c.endColumn<S.column&&(c.endColumn=S.column)}}),n(c)):n(r)}}))}};Ze=Mn([qe(0,l.Inject(R.SheetPrintInterceptorService)),qe(1,l.Inject(ge.DrawingRenderService)),qe(2,P.IDrawingManagerService),qe(3,N.IRenderManagerService)],Ze);var Tn=Object.defineProperty,bn=Object.getOwnPropertyDescriptor,Rn=(r,i,n,e)=>{for(var t=e>1?void 0:e?bn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&Tn(i,n,t),t},me=(r,i)=>(n,e)=>i(n,e,r);const En=[_.InsertRowCommand.id,_.InsertColCommand.id,_.RemoveRowCommand.id,_.RemoveColCommand.id,_.DeleteRangeMoveLeftCommand.id,_.DeleteRangeMoveUpCommand.id,_.InsertRangeMoveDownCommand.id,_.InsertRangeMoveRightCommand.id,_.DeltaRowHeightCommand.id,_.SetRowHeightCommand.id,_.DeltaColumnWidthCommand.id,_.SetColWidthCommand.id,_.SetRowHiddenCommand.id,_.SetSpecificRowsVisibleCommand.id,_.SetSpecificColsVisibleCommand.id,_.SetColHiddenCommand.id,_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id],On=[_.SetRowVisibleMutation.id,_.SetRowHiddenMutation.id,_.SetColVisibleMutation.id,_.SetColHiddenMutation.id,_.SetWorksheetRowHeightMutation.id,_.SetWorksheetColWidthMutation.id];let _t=class extends l.Disposable{constructor(r,i,n,e,t,o,a,s,d){super(),this._context=r,this._renderManagerService=i,this._commandService=n,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=a,this._drawingManagerService=s,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:r=>{if(!En.includes(r.id))return{redos:[],undos:[]};if(r.params==null)return{redos:[],undos:[]};const i=r.id;if(i===_.InsertRowCommand.id)return this._moveRowInterceptor(r.params,"insert");if([_.MoveColsCommand.id,_.MoveRowsCommand.id,_.MoveRangeCommand.id].includes(i))return this._moveRangeInterceptor(r.params);if(i===_.InsertColCommand.id)return this._moveColInterceptor(r.params,"insert");if(i===_.RemoveRowCommand.id)return this._moveRowInterceptor(r.params,"remove");if(i===_.RemoveColCommand.id)return this._moveColInterceptor(r.params,"remove");if(i===_.DeleteRangeMoveLeftCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,0)}else if(i===_.DeleteRangeMoveUpCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,1)}else if(i===_.InsertRangeMoveDownCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,2)}else if(i===_.InsertRangeMoveRightCommand.id){const{range:n}=r.params;return this._getRangeMoveUndo(n,3)}else if(i===_.SetRowHiddenCommand.id||i===_.SetSpecificRowsVisibleCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForRowVisible(e,t,o)}else if(i===_.SetSpecificColsVisibleCommand.id||i===_.SetColHiddenCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n;return this._getDrawingUndoForColVisible(e,t,o)}else if(i===_.DeltaRowHeightCommand.id||i===_.SetRowHeightCommand.id||i===_.DeltaColumnWidthCommand.id||i===_.SetColWidthCommand.id){const n=r.params,{unitId:e,subUnitId:t,ranges:o}=n,a=i===_.DeltaRowHeightCommand.id||i===_.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,a)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(r,i){const n=_.getSheetCommandTarget(this._univerInstanceService);if(n==null)return{redos:[],undos:[]};const e=n.unitId,t=n.subUnitId,o=[],a=[],s=this._sheetDrawingService.getDrawingData(e,t),d=[],m=[];if(Object.keys(s).forEach(u=>{const c=s[u],{updateDrawings:h,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(r,i,c);d.push(...h),m.push(...g)}),d.length===0&&m.length===0)return{redos:[],undos:[]};if(d.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(d),{undo:c,redo:h,objects:g}=u;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:w.DrawingApplyType.UPDATE}}),a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:c,objects:g,type:w.DrawingApplyType.UPDATE}})}if(m.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(m),c=u.undo,h=u.redo,g=u.objects;o.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:h,objects:g,type:w.DrawingApplyType.REMOVE}}),a.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:c,objects:g,type:w.DrawingApplyType.INSERT}})}return o.push({id:H.id,params:[e]}),a.push({id:H.id,params:[e]}),{redos:o,undos:a}}_getUpdateOrDeleteDrawings(r,i,n){const e=[],t=[],{sheetTransform:o,anchorType:a=w.SheetDrawingAnchorType.Position,transform:s,unitId:d,subUnitId:m,drawingId:u}=n,{from:c,to:h}=o,{row:g,column:p}=c,{row:S,column:f}=h;if(o==null||s==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:v,endRow:I,startColumn:M,endColumn:b}=r;let y=null,T=null;if(i===0&&g>=v&&S<=I)if(p>=M&&f<=b)t.push({unitId:d,subUnitId:m,drawingId:u});else{const C=this._shrinkCol(o,s,M,b,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===1&&p>=M&&f<=b)if(g>=v&&S<=I)t.push({unitId:d,subUnitId:m,drawingId:u});else{const C=this._shrinkRow(o,s,v,I,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===2){const C=this._expandRow(o,s,v,I,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}else if(i===3){const C=this._expandCol(o,s,M,b,a);y=C==null?void 0:C.newSheetTransform,T=C==null?void 0:C.newTransform}if(y!=null&&T!=null){const C=x(y,this._selectionRenderService,this._skeletonManagerService);e.push({...n,sheetTransform:y,transform:C})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(r,i,n){const e=V({...r},this._selectionRenderService);e!=null&&i.push({...n,sheetTransform:e})}_getDrawingUndoForColVisible(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:h,transform:g,anchorType:p=w.SheetDrawingAnchorType.Position}=c;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,c);else{const{from:S,to:f}=h,{row:v,column:I}=S,{row:M,column:b}=f;for(let y=0;y<n.length;y++){const T=n[y],{startRow:C,endRow:j,startColumn:O,endColumn:L}=T;if(b<O)continue;if(p===w.SheetDrawingAnchorType.Position){let D=null,B=null;if(I>=O&&I<=L){const k=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:L,startRow:S.row,endRow:f.row});if(k==null)return;B={...g,left:k.startX}}if(B!=null&&(D=V(B,this._selectionRenderService),D!=null&&B!=null)){t.push({...c,sheetTransform:D,transform:B});break}this._remainDrawingSize(g,t,c);continue}if(I>=O&&b<=L)continue;let U=null,A=null;if(I>=O&&I<=L){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:I,endColumn:L,startRow:S.row,endRow:f.row});if(D==null)return;A={...g,left:(D==null?void 0:D.startX)||0,width:((g==null?void 0:g.width)||0)-D.endX+D.startX}}else if(b>=O&&b<=L){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:b,startRow:S.row,endRow:f.row});if(D==null)return;A={...g,left:D.startX-((g==null?void 0:g.width)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:O,endColumn:L,startRow:S.row,endRow:f.row});if(D==null)return;if(A={...g,width:((g==null?void 0:g.width)||0)-D.endX+D.startX},U=V(A,this._selectionRenderService),U!=null&&A!=null){o.push({...c,sheetTransform:U,transform:A});break}}if(A!=null&&(U=V(A,this._selectionRenderService)),A!=null&&U!=null){t.push({...c,sheetTransform:U,transform:A});break}else this._remainDrawingSize(g,t,c)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(r,i,t),d=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(r,i,o);d.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:d,preUndos:m}}_createUndoAndRedoMutation(r,i,n){const e=this._sheetDrawingService.getBatchUpdateOp(n),{undo:t,redo:o,objects:a}=e,s=[{id:w.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,op:o,objects:a,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[r]}],d=[{id:w.SetDrawingApplyMutation.id,params:{unitId:r,subUnitId:i,op:t,objects:a,type:w.DrawingApplyType.UPDATE}},{id:H.id,params:[r]}];return{redos:s,undos:d}}_getDrawingUndoForRowVisible(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[],o=[];if(Object.keys(e).forEach(u=>{const c=e[u],{sheetTransform:h,transform:g,anchorType:p=w.SheetDrawingAnchorType.Position}=c;if(p===w.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,c);else{const{from:S,to:f}=h,{row:v,column:I}=S,{row:M,column:b}=f;for(let y=0;y<n.length;y++){const T=n[y],{startRow:C,endRow:j,startColumn:O,endColumn:L}=T;if(M<C)continue;if(p===w.SheetDrawingAnchorType.Position){let D=null,B=null;if(v>=C&&v<=j){const k=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:v,endRow:j});if(k==null)return;B={...g,top:k.startY}}if(B!=null&&(D=V(B,this._selectionRenderService),D!=null&&B!=null)){t.push({...c,sheetTransform:D,transform:B});break}this._remainDrawingSize(g,t,c);continue}if(v>=C&&M<=j)continue;let U=null,A=null;if(v>=C&&v<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:v,endRow:j});if(D==null)return;A={...g,top:(D==null?void 0:D.startY)||0,height:((g==null?void 0:g.height)||0)-D.endY+D.startY}}else if(M>=C&&M<=j){const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:C,endRow:M});if(D==null)return;A={...g,top:D.startY-((g==null?void 0:g.height)||0)}}else{const D=this._skeletonManagerService.attachRangeWithCoord({startColumn:S.column,endColumn:f.column,startRow:C,endRow:j});if(D==null)return;if(A={...g,height:((g==null?void 0:g.height)||0)-D.endY+D.startY},U=V(A,this._selectionRenderService),U!=null&&A!=null){o.push({...c,sheetTransform:U,transform:A});break}}if(A!=null&&(U=V(A,this._selectionRenderService)),A!=null&&U!=null){t.push({...c,sheetTransform:U,transform:A});break}else this._remainDrawingSize(g,t,c)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:a,undos:s}=this._createUndoAndRedoMutation(r,i,t),d=[],m=[];if(o.length>0){const{redos:u,undos:c}=this._createUndoAndRedoMutation(r,i,o);d.push(...u),m.push(...c)}return{redos:a,undos:s,preRedos:d,preUndos:m}}_getDrawingUndoForRowAndColSize(r,i,n,e){const t=this._drawingManagerService.getDrawingData(r,i),o=[];return Object.keys(t).forEach(a=>{const s=t[a],{sheetTransform:d,transform:m,anchorType:u=w.SheetDrawingAnchorType.Position}=s;if(u===w.SheetDrawingAnchorType.None)this._remainDrawingSize(m,o,s);else{const{from:c,to:h}=d,{row:g,column:p}=c,{row:S,column:f}=h;for(let v=0;v<n.length;v++){const I=n[v],{startRow:M,endRow:b,startColumn:y,endColumn:T}=I;if(S<M||f<y)continue;if(u===w.SheetDrawingAnchorType.Position&&(g<=M&&S>=b||p<=y&&f>=T)){this._remainDrawingSize(m,o,s);continue}const C=x({...d},this._selectionRenderService,this._skeletonManagerService);if(C!=null){o.push({...s,transform:C});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(r,i,o)}_getUnitIdAndSubUnitId(r,i){let n,e;if(i==="insert")n=r.unitId,e=r.subUnitId;else{const t=_.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;n=t.unitId,e=t.subUnitId}return{unitId:n,subUnitId:e}}_moveRangeInterceptor(r){var M,b;const{toRange:i,fromRange:n}=r,e=_.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,a=(b=(M=this._renderManagerService.getRenderById(t))==null?void 0:M.with(R.SheetSkeletonManagerService))==null?void 0:b.getCurrentSkeleton();if(!a)return{redos:[],undos:[]};const s=R.attachRangeWithCoord(a,n);if(!s)return{redos:[],undos:[]};const{startX:d,endX:m,startY:u,endY:c}=s,h=this._sheetDrawingService.getDrawingData(t,o),g=[];Object.keys(h).forEach(y=>{const T=h[y];if(T.anchorType!==w.SheetDrawingAnchorType.Both)return;const{transform:C}=T;if(!C)return;const{left:j=0,top:O=0,width:L=0,height:U=0}=C,{drawingStartX:A,drawingEndX:D,drawingStartY:B,drawingEndY:k}={drawingStartX:j,drawingEndX:j+L,drawingStartY:O,drawingEndY:O+U};d<=A&&D<=m&&u<=B&&k<=c&&g.push(T)});const p=[],S=[],f=i.startRow-n.startRow,v=i.startColumn-n.startColumn,I=g.map(y=>{const T=y.sheetTransform,C={to:{...T.to,row:T.to.row+f,column:T.to.column+v},from:{...T.from,row:T.from.row+f,column:T.from.column+v}},j=x(C,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:y.drawingId,transform:j,sheetTransform:C}});if(I.length){const y=this._sheetDrawingService.getBatchUpdateOp(I),{undo:T,redo:C,objects:j}=y;p.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:C,objects:j,type:w.DrawingApplyType.UPDATE}}),S.push({id:w.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:T,objects:j,type:w.DrawingApplyType.UPDATE}})}return{redos:p,undos:S}}_moveRowInterceptor(r,i){const n=this._getUnitIdAndSubUnitId(r,i);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=r,a=o.startRow,s=o.endRow,d=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),c=[],h=[];if(Object.keys(u).forEach(g=>{const p=u[g],{sheetTransform:S,transform:f,anchorType:v=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,M;if(i==="insert"){const y=this._expandRow(S,f,a,s,v);I=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{row:C}=y,{row:j}=T;if(v===w.SheetDrawingAnchorType.Both&&C>=a&&j<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const O=this._shrinkRow(S,f,a,s,v);I=O==null?void 0:O.newSheetTransform,M=O==null?void 0:O.newTransform}}if(!I||!M)return;const b={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:I};c.push(b)}),c.length===0&&h.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:p,redo:S,objects:f}=g;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),p=g.undo,S=g.redo,f=g.objects;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return d.push({id:H.id,params:[e]}),m.push({id:H.id,params:[e]}),{redos:d,undos:m}}_moveColInterceptor(r,i){const n=this._getUnitIdAndSubUnitId(r,i);if(n==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=n,{range:o}=r,a=o.startColumn,s=o.endColumn,d=[],m=[],u=this._sheetDrawingService.getDrawingData(e,t),c=[],h=[];if(Object.keys(u).forEach(g=>{const p=u[g],{sheetTransform:S,transform:f,anchorType:v=w.SheetDrawingAnchorType.Position}=p;if(S==null||f==null)return;let I,M;if(i==="insert"){const y=this._expandCol(S,f,a,s,v);I=y==null?void 0:y.newSheetTransform,M=y==null?void 0:y.newTransform}else{const{from:y,to:T}=S,{column:C}=y,{column:j}=T;if(v===w.SheetDrawingAnchorType.Both&&C>=a&&j<=s)h.push({unitId:e,subUnitId:t,drawingId:g});else{const O=this._shrinkCol(S,f,a,s,v);I=O==null?void 0:O.newSheetTransform,M=O==null?void 0:O.newTransform}}if(!I||!M)return;const b={unitId:e,subUnitId:t,drawingId:g,transform:M,sheetTransform:I};c.push(b)}),c.length===0&&h.length===0)return{redos:[],undos:[]};if(c.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(c),{undo:p,redo:S,objects:f}=g;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.UPDATE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.UPDATE}})}if(h.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(h),p=g.undo,S=g.redo,f=g.objects;d.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:S,objects:f,type:w.DrawingApplyType.REMOVE}}),m.push({id:w.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:p,objects:f,type:w.DrawingApplyType.INSERT}})}return d.push({id:H.id,params:[e]}),m.push({id:H.id,params:[e]}),{redos:d,undos:m}}_expandCol(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{column:d}=a,{column:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,c=null;if(d>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:e,startRow:a.row,endRow:s.row});if(h==null)return;c={...i,left:(i.left||0)+h.endX-h.startX},u=V(c,this._selectionRenderService)}else if(m>=e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m+o}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkCol(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{column:d}=a,{column:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,c=null;if(d>e)u={from:{...a,column:d-o},to:{...s,column:m-o}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&m<=e)return null;if(d<n&&m>e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,column:m-o}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};else if(d>=n&&d<=e){if(d===n)c={...i,left:(i.left||0)-r.from.columnOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n,endColumn:d-1,startRow:a.row,endRow:s.row});if(h==null)return;c={...i,left:(i.left||0)-h.endX+h.startX-r.from.columnOffset}}u=V(c,this._selectionRenderService)}else if(m>=n&&m<=e&&t===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:n-1,endColumn:n-1,startRow:a.row,endRow:s.row});if(h==null)return;u={from:{...a},to:{...s,column:n-1,columnOffset:h.endX-h.startX}},c=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_expandRow(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{row:d}=a,{row:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,c=null;if(d>=n){const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:e,startColumn:a.column,endColumn:s.column});if(h==null)return;c={...i,top:(i.top||0)+h.endY-h.startY},u=V(c,this._selectionRenderService)}else if(m>=e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m+o}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_shrinkRow(r,i,n,e,t=w.SheetDrawingAnchorType.Position){const o=e-n+1,{from:a,to:s}=r,{row:d}=a,{row:m}=s;if(t===w.SheetDrawingAnchorType.None)return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};let u=null,c=null;if(d>e)u={from:{...a,row:d-o},to:{...s,row:m-o}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else{if(d>=n&&m<=e)return null;if(d<n&&m>e)if(t===w.SheetDrawingAnchorType.Both)u={from:{...a},to:{...s,row:m-o}},c=x(u,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:V({...i},this._selectionRenderService),newTransform:i};else if(d>=n&&d<=e){if(d===n)c={...i,top:(i.top||0)-r.from.rowOffset};else{const h=this._skeletonManagerService.attachRangeWithCoord({startRow:n,endRow:d-1,startColumn:a.column,endColumn:s.column});if(h==null)return;c={...i,top:(i.top||0)-h.endY+h.startY-r.from.rowOffset}}u=V(c,this._selectionRenderService)}else if(m>=n&&m<=e&&t===w.SheetDrawingAnchorType.Both){const h=this._skeletonManagerService.attachRangeWithCoord({startColumn:a.column,endColumn:a.column,startRow:n-1,endRow:n-1});if(h==null)return;u={from:{...a},to:{...s,row:n-1,rowOffset:h.endY-h.startY}},c=x(u,this._selectionRenderService,this._skeletonManagerService)}}return u!=null&&c!=null?{newSheetTransform:u,newTransform:c}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{r.id===_.SetWorksheetActiveOperation.id&&setTimeout(()=>{const i=r.params,{unitId:n,subUnitId:e}=i,t=this._drawingManagerService.drawingManagerData,o=[],a=[];Object.keys(t).forEach(s=>{const d=t[s];d!=null&&Object.keys(d).forEach(m=>{const u=d[m].data;u!=null&&Object.keys(u).forEach(c=>{if(s===n&&m===e){const h=u[c];h.transform=x(h.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(u[c])}else a.push(u[c])})})}),this._drawingManagerService.removeNotification(a),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(r=>{On.includes(r.id)&&requestIdleCallback(()=>{const i=r.params,{unitId:n,subUnitId:e,ranges:t}=i;this._refreshDrawingTransform(n,e,t)})}))}_refreshDrawingTransform(r,i,n){const e=this._drawingManagerService.getDrawingData(r,i),t=[];Object.keys(e).forEach(o=>{const a=e[o],{sheetTransform:s,transform:d,anchorType:m=w.SheetDrawingAnchorType.Position}=a;if(m===w.SheetDrawingAnchorType.None)return!0;const{from:u,to:c}=s,{row:h,column:g}=u,{row:p,column:S}=c;for(let f=0;f<n.length;f++){const v=n[f],{startRow:I,endRow:M,startColumn:b,endColumn:y}=v;if(l.Rectangle.intersects({startRow:I,endRow:M,startColumn:b,endColumn:y},{startRow:h,endRow:p,startColumn:g,endColumn:S})||h>M||g>y){const T=m===w.SheetDrawingAnchorType.Position,C=x(s,this._selectionRenderService,this._skeletonManagerService);t.push({...a,transform:{...C,width:T?d==null?void 0:d.width:C==null?void 0:C.width,height:T?d==null?void 0:d.height:C==null?void 0:C.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(H.id,[r]))}};_t=Rn([me(1,N.IRenderManagerService),me(2,l.ICommandService),me(3,R.ISheetSelectionRenderService),me(4,l.Inject(R.SheetSkeletonManagerService)),me(5,l.Inject(_.SheetInterceptorService)),me(6,w.ISheetDrawingService),me(7,P.IDrawingManagerService),me(8,l.IUniverInstanceService)],_t);var J=function(){return J=Object.assign||function(r){for(var i,n=1,e=arguments.length;n<e;n++){i=arguments[n];for(var t in i)Object.prototype.hasOwnProperty.call(i,t)&&(r[t]=i[t])}return r},J.apply(this,arguments)},Pn=function(r,i){var n={};for(var e in r)Object.prototype.hasOwnProperty.call(r,e)&&i.indexOf(e)<0&&(n[e]=r[e]);if(r!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(r);t<e.length;t++)i.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(r,e[t])&&(n[e[t]]=r[e[t]]);return n},Ut=q.forwardRef(function(r,i){var n=r.icon,e=r.id,t=r.className,o=r.extend,a=Pn(r,["icon","id","className","extend"]),s="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),d=q.useRef("_".concat(Nn()));return Nt(n,"".concat(e),{defIds:n.defIds,idSuffix:d.current},J({ref:i,className:s},a),o)});function Nt(r,i,n,e,t){return q.createElement(r.tag,J(J({key:i},An(r,n,t)),e),(Un(r,n).children||[]).map(function(o,a){return Nt(o,"".concat(i,"-").concat(r.tag,"-").concat(a),n,void 0,t)}))}function An(r,i,n){var e=J({},r.attrs);n!=null&&n.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=n.colorChannel1);var t=i.defIds;return!t||t.length===0||(r.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+i.idSuffix),Object.entries(e).forEach(function(o){var a=o[0],s=o[1];typeof s=="string"&&(e[a]=s.replace(/url\(#(.*)\)/,"url(#$1".concat(i.idSuffix,")")))})),e}function Un(r,i){var n,e=i.defIds;return!e||e.length===0?r:r.tag==="defs"&&(!((n=r.children)===null||n===void 0)&&n.length)?J(J({},r),{children:r.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?J(J({},t),{attrs:J(J({},t.attrs),{id:t.attrs.id+i.idSuffix})}):t})}):r}function Nn(){return Math.random().toString(36).substring(2,8)}Ut.displayName="UniverIcon";var jn={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"path",attrs:{fill:"currentColor",d:"M2.2498 3.65005C2.2498 2.87685 2.87661 2.25005 3.64981 2.25005H7.9998C8.33118 2.25005 8.5998 1.98142 8.5998 1.65005C8.5998 1.31868 8.33118 1.05005 7.9998 1.05005H3.64981C2.21387 1.05005 1.0498 2.21411 1.0498 3.65005V12.35C1.0498 13.786 2.21386 14.95 3.6498 14.95H12.3498C13.7857 14.95 14.9498 13.786 14.9498 12.3501V8.00005C14.9498 7.66868 14.6812 7.40005 14.3498 7.40005C14.0184 7.40005 13.7498 7.66868 13.7498 8.00005V9.23974L12.2385 8.1063C11.7252 7.72129 11.0068 7.7723 10.5531 8.22605L9.00869 9.77041L6.73916 7.8251C6.24387 7.40055 5.5095 7.41278 5.02864 7.85359L2.2498 10.4009V3.65005ZM2.2498 12.0287V12.35C2.2498 13.1232 2.87661 13.75 3.6498 13.75H12.3498C13.123 13.75 13.7498 13.1232 13.7498 12.3501V10.7397L11.5186 9.06631C11.4829 9.03956 11.433 9.04314 11.4016 9.07458L9.92249 10.5537L11.1015 11.5642C11.3531 11.7799 11.3822 12.1587 11.1666 12.4103C10.9509 12.6619 10.5721 12.691 10.3205 12.4753L5.9582 8.7362C5.92384 8.70674 5.87288 8.70758 5.83952 8.73816L2.2498 12.0287Z",fillRule:"evenodd",clipRule:"evenodd"}},{tag:"path",attrs:{fill:"currentColor",d:"M11.8097 1.14783C12.1411 1.14783 12.4097 1.41646 12.4097 1.74783V3.297H14.1541C14.4855 3.297 14.7541 3.56563 14.7541 3.897C14.7541 4.22837 14.4855 4.497 14.1541 4.497H12.4097V6.24167C12.4097 6.57304 12.1411 6.84167 11.8097 6.84167C11.4783 6.84167 11.2097 6.57304 11.2097 6.24167V4.497H9.6603C9.32893 4.497 9.0603 4.22837 9.0603 3.897C9.0603 3.56563 9.32893 3.297 9.6603 3.297H11.2097V1.74783C11.2097 1.41646 11.4783 1.14783 11.8097 1.14783Z"}}]},jt=q.forwardRef(function(r,i){return q.createElement(Ut,Object.assign({},r,{id:"add-image-single",ref:i,icon:jn}))});jt.displayName="AddImageSingle";const It={id:"sheet.command.delete-drawing",type:l.CommandType.COMMAND,handler:r=>{const i=r.get(l.ICommandService),e=r.get(w.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(a=>{const{unitId:s,subUnitId:d,drawingId:m,drawingType:u}=a;return{unitId:s,subUnitId:d,drawingId:m,drawingType:u}});return i.executeCommand(Ce.id,{unitId:t,drawings:o})}},ye={id:"sheet.command.move-drawing",type:l.CommandType.COMMAND,handler:(r,i)=>{const n=r.get(l.ICommandService),e=r.get(w.ISheetDrawingService),t=r.get(R.ISheetSelectionRenderService),{direction:o}=i,a=e.getFocusDrawings();if(a.length===0)return!1;const s=a[0].unitId,d=a.map(u=>{const{transform:c}=u;if(c==null)return null;const h={...c},{left:g=0,top:p=0}=c;return o===l.Direction.UP?h.top=p-1:o===l.Direction.DOWN?h.top=p+1:o===l.Direction.LEFT?h.left=g-1:o===l.Direction.RIGHT&&(h.left=g+1),{...u,transform:h,sheetTransform:V(h,t)}}).filter(u=>u!=null);return n.syncExecuteCommand(Ae.id,{unitId:s,drawings:d})?(n.syncExecuteCommand(H.id,[s]),!0):!1}},Wt="addition-and-subtraction-single",Ct="sheet.menu.image";function Wn(r){return{id:Ct,type:F.MenuItemType.SUBITEMS,icon:Wt,tooltip:"sheetImage.title",hidden$:F.getMenuHiddenObservable(r,l.UniverInstanceType.UNIVER_SHEET),disabled$:R.getCurrentRangeDisable$(r,{workbookTypes:[_.WorkbookEditablePermission],worksheetTypes:[_.WorksheetEditPermission],rangeTypes:[_.RangeProtectionPermissionEditPoint]})}}function Bn(r){return{id:Ne.id,title:"sheetImage.upload.float",type:F.MenuItemType.BUTTON,hidden$:F.getMenuHiddenObservable(r,l.UniverInstanceType.UNIVER_SHEET)}}function kn(r){return{id:vt.id,title:"sheetImage.upload.cell",type:F.MenuItemType.BUTTON}}const pe={imageCommonPanel:"univer-image-common-panel",imageCommonPanelGrid:"univer-image-common-panel-grid",imageCommonPanelBorder:"univer-image-common-panel-border",imageCommonPanelTitle:"univer-image-common-panel-title",imageCommonPanelSubtitle:"univer-image-common-panel-subtitle",imageCommonPanelRow:"univer-image-common-panel-row",imageCommonPanelRowVertical:"univer-image-common-panel-row-vertical",imageCommonPanelColumn:"univer-image-common-panel-column",imageCommonPanelColumnCenter:"univer-image-common-panel-column-center",imageCommonPanelInline:"univer-image-common-panel-inline",imageCommonPanelSpan2:"univer-image-common-panel-span2",imageCommonPanelSpan3:"univer-image-common-panel-span3",imageCommonPanelInput:"univer-image-common-panel-input",sheetImageMenu:"univer-sheet-image-menu",sheetImageMenuInput:"univer-sheet-image-menu-input"};function Bt(r){var i,n,e="";if(typeof r=="string"||typeof r=="number")e+=r;else if(typeof r=="object")if(Array.isArray(r)){var t=r.length;for(i=0;i<t;i++)r[i]&&(n=Bt(r[i]))&&(e&&(e+=" "),e+=n)}else for(n in r)r[n]&&(e&&(e+=" "),e+=n);return e}function Je(){for(var r,i,n=0,e="",t=arguments.length;n<t;n++)(r=arguments[n])&&(i=Bt(r))&&(e&&(e+=" "),e+=i);return e}const Ln=r=>{var M;const i=l.useDependency(l.ICommandService),n=l.useDependency(l.LocaleService),e=l.useDependency(P.IDrawingManagerService),t=l.useDependency(N.IRenderManagerService),{drawings:o}=r,a=o[0];if(a==null)return;const{unitId:s}=a,d=t.getRenderById(s),m=d==null?void 0:d.scene;if(m==null)return;const u=m.getTransformerByCreate(),[c,h]=q.useState(!0),g=(M=a.anchorType)!=null?M:w.SheetDrawingAnchorType.Position,[p,S]=q.useState(g);function f(b,y){const T=[];return b.forEach(C=>{const{oKey:j}=C,O=y.getDrawingOKey(j);if(O==null)return T.push(null),!0;const{unitId:L,subUnitId:U,drawingId:A,drawingType:D,anchorType:B,sheetTransform:k}=O;T.push({unitId:L,subUnitId:U,drawingId:A,anchorType:B,sheetTransform:k,drawingType:D})}),T}q.useEffect(()=>{const b=u.clearControl$.subscribe(T=>{T===!0&&h(!1)}),y=u.changeStart$.subscribe(T=>{var O;const{objects:C}=T,j=f(C,e);if(j.length===0)h(!1);else if(j.length>=1){h(!0);const L=((O=j[0])==null?void 0:O.anchorType)||w.SheetDrawingAnchorType.Position;S(L)}});return()=>{y.unsubscribe(),b.unsubscribe()}},[]);function v(b){S(b);const y=e.getFocusDrawings();if(y.length===0)return;const T=y.map(C=>({unitId:C.unitId,subUnitId:C.subUnitId,drawingId:C.drawingId,anchorType:b}));i.executeCommand(Ae.id,{unitId:y[0].unitId,drawings:T})}const I=b=>b?"block":"none";return X.jsxs("div",{className:Je(pe.imageCommonPanelGrid,pe.imageCommonPanelBorder),style:{display:I(c)},children:[X.jsx("div",{className:pe.imageCommonPanelRow,children:X.jsx("div",{className:Je(pe.imageCommonPanelColumn,pe.imageCommonPanelTitle),children:X.jsx("div",{children:n.t("drawing-anchor.title")})})}),X.jsx("div",{className:Je(pe.imageCommonPanelRow),children:X.jsx("div",{className:Je(pe.imageCommonPanelColumn),children:X.jsxs(ee.RadioGroup,{value:p,onChange:v,direction:"vertical",children:[X.jsx(ee.Radio,{value:w.SheetDrawingAnchorType.Both,children:n.t("drawing-anchor.both")}),X.jsx(ee.Radio,{value:w.SheetDrawingAnchorType.Position,children:n.t("drawing-anchor.position")}),X.jsx(ee.Radio,{value:w.SheetDrawingAnchorType.None,children:n.t("drawing-anchor.none")})]})})})]})},$n=()=>{const r=l.useDependency(P.IDrawingManagerService),i=r.getFocusDrawings(),[n,e]=q.useState(i);return q.useEffect(()=>{const t=r.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(n!=null&&n.length)&&X.jsxs("div",{className:pe.imageCommonPanel,children:[X.jsx(ge.DrawingCommonPanel,{drawings:n}),X.jsx(Ln,{drawings:n})]})},Yn={[F.RibbonStartGroup.FORMULAS_INSERT]:{[Ct]:{order:3,menuItemFactory:Wn,[Ne.id]:{order:0,menuItemFactory:Bn},[vt.id]:{order:1,menuItemFactory:kn}}}};function Be(r){return!r.getContextValue(l.FOCUSING_FX_BAR_EDITOR)&&!r.getContextValue(l.EDITOR_ACTIVATED)&&!r.getContextValue(l.FOCUSING_PANEL_EDITOR)&&r.getContextValue(l.FOCUSING_COMMON_DRAWINGS)}const Gn={id:ye.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_DOWN,priority:100,preconditions:Be,staticParameters:{direction:l.Direction.DOWN}},Fn={id:ye.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_UP,priority:100,preconditions:Be,staticParameters:{direction:l.Direction.UP}},Hn={id:ye.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_LEFT,priority:100,preconditions:Be,staticParameters:{direction:l.Direction.LEFT}},Vn={id:ye.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:F.KeyCode.ARROW_RIGHT,priority:100,preconditions:Be,staticParameters:{direction:l.Direction.RIGHT}},Xn={id:It.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:Be,binding:F.KeyCode.DELETE,mac:F.KeyCode.BACKSPACE};var xn=Object.defineProperty,Kn=Object.getOwnPropertyDescriptor,zn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Kn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&xn(i,n,t),t},De=(r,i)=>(n,e)=>i(n,e,r);let Qe=class extends l.Disposable{constructor(r,i,n,e,t,o){super(),this._componentManager=r,this._menuManagerService=i,this._commandService=n,this._shortcutService=e,this._drawingManagerService=t,this._sheetsSelectionsService=o,this._init()}_initCustomComponents(){const r=this._componentManager;this.disposeWithMe(r.register(Wt,jt)),this.disposeWithMe(r.register(Rt,$n))}_initMenus(){this._menuManagerService.mergeMenu(Yn)}_initCommands(){[Ne,vt,Pe,Ce,Ae,gt,H,ht,pt,St,ye,It,ft].forEach(r=>this.disposeWithMe(this._commandService.registerCommand(r)))}_initShortcuts(){[Gn,Fn,Hn,Vn,Xn].forEach(r=>{this.disposeWithMe(this._shortcutService.registerShortcut(r))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};Qe=zn([De(0,l.Inject(F.ComponentManager)),De(1,F.IMenuManagerService),De(2,l.ICommandService),De(3,F.IShortcutService),De(4,P.IDrawingManagerService),De(5,l.Inject(_.SheetsSelectionsService))],Qe);var qn=Object.defineProperty,Zn=Object.getOwnPropertyDescriptor,Jn=(r,i,n,e)=>{for(var t=e>1?void 0:e?Zn(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&qn(i,n,t),t},ve=(r,i)=>(n,e)=>i(n,e,r);function Qn(r,i,n,e,t){const{scaleX:o,scaleY:a}=i.getAncestorScale(),s=i.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),d={left:!0,top:!0};if(!s)return{...r,absolute:d};const{left:m,right:u,top:c,bottom:h}=r;let{top:g,left:p,viewportScrollX:S,viewportScrollY:f}=s;const{boundsOfViewArea:v,scrollDirectionResponse:I}=t||{};v&&(l.Tools.isDefine(v.top)&&(g=v.top),l.Tools.isDefine(v.left)&&(p=v.left)),I==="HORIZONTAL"&&(f=0),I==="VERTICAL"&&(S=0);let M,b;m<p?(d.left=!0,M=(p+(m-p))*o,b=Math.max(Math.min((p+(u-p))*o,p*o),(u-S)*o)):(d.left=!1,M=Math.max((m-S)*o,p*o),b=Math.max((u-S)*o,p*o));let y,T;return c<g?(d.top=!0,y=(g+(c-g))*a,T=Math.max(Math.min((g+(u-g))*a,g*a),(h-f)*a)):(d.top=!1,y=Math.max((c-f)*a,g*a),T=Math.max((h-f)*a,g*a)),{left:M,right:b,top:y,bottom:T,absolute:d}}const se=(r,i,n,e,t)=>{const{scene:o}=i,{left:a,top:s,width:d,height:m,angle:u}=r,c={left:a,right:a+d,top:s,bottom:s+m},h=Qn(c,o,n,e,t),{scaleX:g,scaleY:p}=o.getAncestorScale();return{startX:h.left,endX:h.right,startY:h.top,endY:h.bottom,rotate:u,width:d*g,height:m*p,absolute:h.absolute}};E.SheetCanvasFloatDomManagerService=class extends l.Disposable{constructor(n,e,t,o,a,s,d){super();z(this,"_domLayerMap",new Map);z(this,"_domLayerInfoMap",new Map);z(this,"_transformChange$",new W.Subject);z(this,"transformChange$",this._transformChange$.asObservable());z(this,"_add$",new W.Subject);z(this,"add$",this._add$.asObservable());z(this,"_remove$",new W.Subject);z(this,"remove$",this._remove$.asObservable());z(this,"_hooks",[]);this._renderManagerService=n,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=a,this._sheetDrawingService=s,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(W.filter(n=>n===l.LifecycleStages.Rendered),W.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(n,e){let t=this._domLayerMap.get(n);t||(t=new Map,this._domLayerMap.set(n,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(n){return this._domLayerInfoMap.get(n)}_getSceneAndTransformerByDrawingSearch(n){if(n==null)return;const e=this._renderManagerService.getRenderById(n),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),a=e.engine.getCanvasElement();return{scene:t,transformer:o,renderUnit:e,canvas:a}}_getFloatDomProps(n){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(n)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(n=>{n.forEach(e=>{var ne,ie,K;const{unitId:t,subUnitId:o,drawingId:a}=e,s=_.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),m=this._univerInstanceService.getUnit(t,l.UniverInstanceType.UNIVER_SHEET);if(!m)return;const u=m.getActiveSheet().getSheetId();if(!d||!s)return;const c=(ne=this._renderManagerService.getRenderById(t))==null?void 0:ne.with(R.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!c)return;const{transform:h,drawingType:g,data:p}=d;if(g!==l.DrawingTypeEnum.DRAWING_DOM&&g!==l.DrawingTypeEnum.DRAWING_CHART)return;const S=this._getSceneAndTransformerByDrawingSearch(t);if(S==null)return;const{scene:f,canvas:v}=S;if(h==null)return!0;if(u!==o)return;const{left:I,top:M,width:b,height:y,angle:T,flipX:C,flipY:j,skewX:O,skewY:L}=h,U=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),A=f.getObject(U);if(A!=null){A.transformByState({left:I,top:M,width:b,height:y,angle:T,flipX:C,flipY:j,skewX:O,skewY:L});return}const D={left:I,top:M,width:b,height:y,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},B=g===l.DrawingTypeEnum.DRAWING_CHART;if(B){const G=p?p.backgroundColor:"white";D.fill=G,D.rotateEnabled=!1,p&&p.border&&(D.stroke=p.border),D.paintFirst="stroke",D.strokeWidth=1,D.borderEnabled=!1,D.radius=8}const k=new N.Rect(U,D);B&&k.setObjectType(N.ObjectType.CHART),f.addObject(k,N.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&f.attachTransformerTo(k);const te=this._ensureMap(t,o),oe=new l.DisposableCollection,_e=se(k,S.renderUnit,c.skeleton,s.worksheet),ae=new W.BehaviorSubject(_e),Ie={dispose:oe,rect:k,position$:ae,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:ae,id:a,componentKey:d.componentKey,onPointerDown:G=>{v.dispatchEvent(new PointerEvent(G.type,G))},onPointerMove:G=>{v.dispatchEvent(new PointerEvent(G.type,G))},onPointerUp:G=>{v.dispatchEvent(new PointerEvent(G.type,G))},onWheel:G=>{v.dispatchEvent(new WheelEvent(G.type,G))},props:(K=(ie=te.get(a))==null?void 0:ie.props)!=null?K:this._getFloatDomProps(a),data:p,unitId:t});const ce=k.onTransformChange$.subscribeEvent(()=>{const G=se(k,S.renderUnit,c.skeleton,s.worksheet);ae.next(G)});oe.add(()=>{this._canvasFloatDomService.removeFloatDom(a)}),ce&&oe.add(ce),this._domLayerInfoMap.set(a,Ie),te.set(a,{...te.get(a)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:a}=e,s=P.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:a}),d=this._getSceneAndTransformerByDrawingSearch(t);if(d==null)return;const{transformer:m,scene:u}=d,c=u.getObject(s);c!=null&&c.oKey&&m.clearControlByIds([c==null?void 0:c.oKey])})}))}_scrollUpdateListener(){const n=(e,t)=>{var u;const o=this._getSceneAndTransformerByDrawingSearch(e),a=this._ensureMap(e,t),s=Array.from(a.keys()),d=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),m=(u=this._renderManagerService.getRenderById(e))==null?void 0:u.with(R.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!d||!m||s.forEach(c=>{const h=this._domLayerInfoMap.get(c);if(h){const g=se(h.rect,o.renderUnit,m.skeleton,d.worksheet,h);h.position$.next(g)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).pipe(W.filter(e=>!!e),W.switchMap(e=>e.activeSheet$),W.filter(e=>!!e),W.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getSheetId()}:null}),W.filter(e=>!!e),W.switchMap(e=>l.fromEventSubject(e.render.scene.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(W.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{n(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===R.SetZoomRatioOperation.id){const a=e.params,{unitId:s}=a;Array.from((o=(t=this._domLayerMap.get(s))==null?void 0:t.keys())!=null?o:[]).forEach(m=>{n(s,m)})}else if(e.id===_.SetFrozenMutation.id){const{unitId:a,subUnitId:s}=e.params;n(a,s)}}))}_getPosition(n,e){var g;const{startX:t,endX:o,startY:a,endY:s}=n,d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(R.ISheetSelectionRenderService);if(d==null)return;const m=d.getCellWithCoordByOffset(t,a);if(m==null)return;const u={column:m.actualColumn,columnOffset:t-m.startX,row:m.actualRow,rowOffset:a-m.startY},c=d.getCellWithCoordByOffset(o,s);if(c==null)return;const h={column:c.actualColumn,columnOffset:o-c.startX,row:c.actualRow,rowOffset:s-c.startY};return{from:u,to:h}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==l.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==l.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(n=>{n.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(n,e,t,o){const a=this._domLayerInfoMap.get(t),s=this._getSceneAndTransformerByDrawingSearch(n);if(a&&s){const{scene:d}=s,m=P.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:t}),u=d.getObject(m);u&&u instanceof N.Rect&&u.setProps(o)}}addFloatDomToPosition(n,e){const t=_.getSheetCommandTarget(this._univerInstanceService,{unitId:n.unitId,subUnitId:n.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:a}=t,{initPosition:s,componentKey:d,data:m,allowTransform:u=!0}=n,c=e!=null?e:l.generateRandomId(),h=this._getPosition(s,o);if(h==null)return;this._ensureMap(o,a).set(c,n);const p={unitId:o,subUnitId:a,drawingId:c,drawingType:n.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:h,transform:{left:s.startX,top:s.startY,width:s.endX-s.startX,height:s.endY-s.startY},data:m,allowTransform:u};return this._commandService.executeCommand(Pe.id,{unitId:o,drawings:[p]}),this._add$.next({unitId:o,subUnitId:a,id:c}),{id:c,dispose:()=>{this._removeDom(c,!0)}}}_removeDom(n,e=!1){const t=this._domLayerInfoMap.get(n);if(!t)return;const{unitId:o,subUnitId:a}=t;this._domLayerInfoMap.delete(n),t.dispose.dispose();const s=this._getSceneAndTransformerByDrawingSearch(o);if(s&&s.scene.removeObject(t.rect),e){this._ensureMap(o,a).delete(n);const m=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:a,drawingId:n});if(!m)return;const u=this._sheetDrawingService.getBatchRemoveOp([m]),{redo:c,objects:h}=u;this._commandService.syncExecuteCommand(w.SetDrawingApplyMutation.id,{unitId:o,subUnitId:a,op:c,objects:h,type:w.DrawingApplyType.REMOVE})}}addHook(n){return this._hooks.push(n),{dispose:()=>{const e=this._hooks.findIndex(t=>t===n);this._hooks.splice(e,1)}}}addFloatDomToRange(n,e,t,o){var j,O,L,U,A;const a=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:d}=a,m=this._getSceneAndTransformerByDrawingSearch(s);if(!m)return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(j=this._renderManagerService.getRenderById(s))==null?void 0:j.with(R.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:h,data:g,allowTransform:p=!0}=e,S=o!=null?o:l.generateRandomId(),{position:f,position$:v}=this._createRangePositionObserver(n,u,c.skeleton),I=this._getPosition(f,s);if(I==null)return;this._ensureMap(s,d).set(S,e);const b=m.scene,{scaleX:y}=b.getAncestorScale(),T=et(f,t,y),C={unitId:s,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:I,transform:{left:T.startX,top:T.startY,width:T.width,height:T.height},data:g,allowTransform:p};{const{unitId:D,subUnitId:B,drawingId:k}=C,te=_.getSheetCommandTarget(this._univerInstanceService,{unitId:D,subUnitId:B}),oe=C,_e=this._univerInstanceService.getUnit(D,l.UniverInstanceType.UNIVER_SHEET);if(!_e)return;const ae=_e.getActiveSheet().getSheetId();if(!oe||!te)return;const Ie=(O=this._renderManagerService.getRenderById(D))==null?void 0:O.with(R.SheetSkeletonManagerService);if(!Ie)return;const ce=Ie.getWorksheetSkeleton(B);if(!ce)return;const{transform:ne,drawingType:ie,data:K}=oe;if(ie!==l.DrawingTypeEnum.DRAWING_DOM&&ie!==l.DrawingTypeEnum.DRAWING_CHART)return;const G=this._getSceneAndTransformerByDrawingSearch(D);if(G==null)return;const{scene:Me,canvas:Te}=G;if(ne==null||ae!==B)return;const{left:nt,top:it,width:rt,height:ot,angle:Dt,flipX:Mt,flipY:at,skewX:st,skewY:be}=ne,ct=P.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:B,drawingId:k}),de=Me.getObject(ct);if(de!=null){de.transformByState({left:nt,top:it,width:rt,height:ot,angle:Dt,flipX:Mt,flipY:at,skewX:st,skewY:be});return}const Q={left:nt,top:it,width:rt,height:ot,zIndex:this._drawingManagerService.getDrawingOrder(D,B).length-1},Re=ie===l.DrawingTypeEnum.DRAWING_CHART;if(Re){const $=K?K.backgroundColor:"white";Q.fill=$,Q.rotateEnabled=!1,K&&K.border&&(Q.stroke=K.border),Q.paintFirst="stroke",Q.strokeWidth=1,Q.borderEnabled=!1,Q.radius=8}const re=new N.Rect(ct,Q);Re&&re.setObjectType(N.ObjectType.CHART),Me.addObject(re,N.DRAWING_OBJECT_LAYER_INDEX),oe.allowTransform!==!1&&Me.attachTransformerTo(re);const Le=this._ensureMap(D,B),le=new l.DisposableCollection,Ee=Me.getMainViewport(),Oe={top:Ee.top,left:Ee.left,bottom:Ee.bottom,right:Ee.right},ue={dispose:le,rect:re,boundsOfViewArea:Oe,domAnchor:t,unitId:D,subUnitId:B},dt=se(re,G.renderUnit,ce.skeleton,te.worksheet,ue),fe=new W.BehaviorSubject(dt);ue.position$=fe;let Y={position$:fe,id:k,componentKey:oe.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:$=>{Te.dispatchEvent(new WheelEvent($.type,$))},props:(U=(L=Le.get(k))==null?void 0:L.props)!=null?U:this._getFloatDomProps(k),data:K,unitId:D};e.eventPassThrough&&(Y={...Y,onPointerDown:$=>{Te.dispatchEvent(new PointerEvent($.type,$))},onPointerMove:$=>{Te.dispatchEvent(new PointerEvent($.type,$))},onPointerUp:$=>{Te.dispatchEvent(new PointerEvent($.type,$))}}),this._canvasFloatDomService.addFloatDom(Y),this.disposeWithMe(v.subscribe($=>{var $t,Yt,Gt,Ft;const ut=et({rotate:0,startX:$.startX,startY:$.startY,endX:$.endX,endY:$.endY,width:($t=t.width)!=null?$t:$.width,height:(Yt=t.height)!=null?Yt:$.height,absolute:{left:f.absolute.left,top:f.absolute.top}},t),ri=P.getDrawingShapeKeyByDrawingSearch({unitId:D,subUnitId:B,drawingId:k}),oi=new N.Rect(ri,{left:ut.startX,top:ut.startY,width:(Gt=t.width)!=null?Gt:$.width,height:(Ft=t.height)!=null?Ft:$.height,zIndex:this._drawingManagerService.getDrawingOrder(D,B).length-1}),ai=se(oi,G.renderUnit,ce.skeleton,te.worksheet,ue);fe.next(ai)}));const $e=(A=this._renderManagerService.getRenderById(D))==null?void 0:A.with(R.SheetSkeletonManagerService);$e==null||$e.currentSkeleton$.subscribe($=>{$&&c.sheetId!==$.sheetId&&this._removeDom(S,!0)});const lt=re.onTransformChange$.subscribeEvent(()=>{const $=se(re,G.renderUnit,ce.skeleton,te.worksheet,ue);fe.next($)});le.add(()=>{this._canvasFloatDomService.removeFloatDom(k)}),lt&&le.add(lt),this._domLayerInfoMap.set(k,ue),Le.set(k,{...Le.get(k)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}addFloatDomToColumnHeader(n,e,t,o){var T,C,j,O,L;const a=_.getSheetCommandTarget(this._univerInstanceService,{unitId:e.unitId,subUnitId:e.subUnitId});if(!a)throw new Error("cannot find current target!");const{unitId:s,subUnitId:d}=a;if(!this._getSceneAndTransformerByDrawingSearch(s))return;const u=this._renderManagerService.getRenderById(s);if(!u)return;const c=(T=this._renderManagerService.getRenderById(s))==null?void 0:T.with(R.SheetSkeletonManagerService).getWorksheetSkeleton(d);if(!c)return;const{componentKey:h,data:g,allowTransform:p=!0}=e,S=o!=null?o:l.generateRandomId(),{position:f,position$:v}=this._createRangePositionObserver({startRow:0,endRow:0,startColumn:n,endColumn:n},u,c.skeleton),I=f;I.startY=0;const M=this._getPosition(f,s);if(M==null)return;this._ensureMap(s,d).set(S,e);const y={unitId:s,subUnitId:d,drawingId:S,drawingType:e.type||l.DrawingTypeEnum.DRAWING_DOM,componentKey:h,sheetTransform:M,transform:{left:I.startX,top:I.startY,width:I.width,height:I.height},data:g,allowTransform:p};{const{unitId:U,subUnitId:A,drawingId:D}=y,B=_.getSheetCommandTarget(this._univerInstanceService,{unitId:U,subUnitId:A}),k=y,te=this._univerInstanceService.getUnit(U,l.UniverInstanceType.UNIVER_SHEET);if(!te)return;const oe=te.getActiveSheet().getSheetId();if(!k||!B)return;const _e=(C=this._renderManagerService.getRenderById(U))==null?void 0:C.with(R.SheetSkeletonManagerService);if(!_e)return;const ae=_e.getWorksheetSkeleton(A);if(!ae)return;const{transform:Ie,data:ce}=k,ne=this._getSceneAndTransformerByDrawingSearch(U);if(ne==null)return;const{scene:ie,canvas:K}=ne;if(Ie==null||oe!==A)return;const{left:G,top:Me,width:Te,height:nt,angle:it,flipX:rt,flipY:ot,skewX:Dt,skewY:Mt}=Ie,at=P.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:A,drawingId:D}),st=ie.getObject(at);if(st!=null){st.transformByState({left:G,top:Me,width:Te,height:nt,angle:it,flipX:rt,flipY:ot,skewX:Dt,skewY:Mt});return}const be=et({rotate:0,startX:I.startX,startY:0,endX:f.endX,endY:f.endY,width:t.width,height:t.height,absolute:{left:f.absolute.left,top:f.absolute.top}},t),ct={left:be.startX,top:be.startY,width:be.width,height:be.height,zIndex:this._drawingManagerService.getDrawingOrder(U,A).length-1},de=new N.Rect(at,ct);ie.addObject(de,N.DRAWING_OBJECT_LAYER_INDEX),k.allowTransform!==!1&&ie.attachTransformerTo(de);const Q=this._ensureMap(U,A),Re=new l.DisposableCollection,re=ie.getMainViewport(),Le={top:0,left:re.left,bottom:re.bottom,right:re.right},le={dispose:Re,rect:de,unitId:U,subUnitId:A,boundsOfViewArea:Le,domAnchor:t,scrollDirectionResponse:"HORIZONTAL"},Ee=se(de,ne.renderUnit,ae.skeleton,B.worksheet,le),Oe=new W.BehaviorSubject(Ee);le.position$=Oe;let ue={position$:Oe,id:D,componentKey:k.componentKey,onPointerDown:()=>{},onPointerMove:()=>{},onPointerUp:()=>{},onWheel:Y=>{K.dispatchEvent(new WheelEvent(Y.type,Y))},props:(O=(j=Q.get(D))==null?void 0:j.props)!=null?O:this._getFloatDomProps(D),data:ce,unitId:U};e.eventPassThrough&&(ue={...ue,onPointerDown:Y=>{K.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerMove:Y=>{K.dispatchEvent(new PointerEvent(Y.type,Y))},onPointerUp:Y=>{K.dispatchEvent(new PointerEvent(Y.type,Y))}}),this._canvasFloatDomService.addFloatDom(ue);const dt=de.onTransformChange$.subscribeEvent(()=>{const Y=se(de,ne.renderUnit,ae.skeleton,B.worksheet,le);Oe.next(Y)});this.disposeWithMe(v.subscribe(Y=>{const $e=et({rotate:0,startX:Y.startX,startY:0,endX:Y.endX,endY:Y.endY,width:t.width,height:t.height,absolute:{left:f.absolute.left,top:f.absolute.top}},t),lt=P.getDrawingShapeKeyByDrawingSearch({unitId:U,subUnitId:A,drawingId:D}),$=new N.Rect(lt,{left:$e.startX,top:0,width:t.width,height:t.height,zIndex:this._drawingManagerService.getDrawingOrder(U,A).length-1}),ut=se($,ne.renderUnit,ae.skeleton,B.worksheet,le);Oe.next(ut)}));const fe=(L=this._renderManagerService.getRenderById(U))==null?void 0:L.with(R.SheetSkeletonManagerService);fe==null||fe.currentSkeleton$.subscribe(Y=>{Y&&c.sheetId!==Y.sheetId&&this._removeDom(S,!0)}),Re.add(()=>{this._canvasFloatDomService.removeFloatDom(D)}),dt&&Re.add(dt),this._domLayerInfoMap.set(D,le),Q.set(D,{...Q.get(D)})}return{id:S,dispose:()=>{this._removeDom(S,!0)}}}_createRangePositionObserver(n,e,t){let{startRow:o,startColumn:a}=n;const s=ke(o,a,t),d=new W.BehaviorSubject(s),m=ke(n.endRow,n.endColumn,t),u=new W.BehaviorSubject(m),c=()=>{const v=ke(o,a,t),I=ke(n.endRow,n.endColumn,t);d.next(v),u.next(I)},h=new l.DisposableCollection;h.add(e.engine.clientRect$.subscribe(()=>c())),h.add(this._commandService.onCommandExecuted(v=>{if(v.id===_.SetWorksheetRowAutoHeightMutation.id&&v.params.rowsAutoHeightInfo.findIndex(M=>M.row===o)>-1){c();return}(_.COMMAND_LISTENER_SKELETON_CHANGE.indexOf(v.id)>-1||v.id===R.SetScrollOperation.id||v.id===R.SetZoomRatioOperation.id)&&c()}));const g=(v,I)=>{o=v,a=I,c()},p=()=>({rotate:0,width:m.right-s.left,height:m.bottom-s.top,absolute:{left:!0,top:!0},startX:s.left,startY:s.top,endX:m.right,endY:m.bottom}),S=d.pipe(W.map(v=>{const I=ke(n.endRow,n.endColumn,t);return{rotate:0,width:I.right-v.left,height:I.bottom-v.top,absolute:{left:!0,top:!0},startX:v.left,startY:v.top,endX:I.right,endY:I.bottom}})),f=p();return{position$:S,position:f,updateRowCol:g,topLeftPos$:d,rightBottomPos$:u,disposable:h}}},E.SheetCanvasFloatDomManagerService=Jn([ve(0,l.Inject(N.IRenderManagerService)),ve(1,l.IUniverInstanceService),ve(2,l.Inject(l.ICommandService)),ve(3,P.IDrawingManagerService),ve(4,l.Inject(F.CanvasFloatDomService)),ve(5,w.ISheetDrawingService),ve(6,l.Inject(l.LifecycleService))],E.SheetCanvasFloatDomManagerService);function ke(r,i,n){const e=n.getCellWithCoordByIndex(r,i),t=e.isMergedMainCell?e.mergeInfo:e;return{left:t.startX,right:t.endX,top:t.startY,bottom:t.endY}}function et(r,i,n){var m,u;n=n!=null?n:1;const e=r.endX-r.startX,t=r.endY-r.startY,o=(m=i==null?void 0:i.width)!=null?m:e,a=(u=i==null?void 0:i.height)!=null?u:t;let s=0,d=0;if(i){if(i.horizonOffsetAlign==="right"){const c=tt(i.marginX,e*n);s=r.endX-c-o}else s=r.startX+tt(i.marginX,e);if(i.verticalOffsetAlign==="bottom"){const c=tt(i.marginY,t*n);d=r.endY-c-a}else d=r.startY+tt(i.marginY,t)}return{rotate:0,startX:s,startY:d,endX:r.endX,endY:r.endY,width:o,height:a,absolute:{left:r.absolute.left,top:r.absolute.top}}}function tt(r,i){if(r===void 0)return 0;if(typeof r=="number")return r;const n=Number.parseFloat(r);return i*n/100}var kt=Object.defineProperty,ei=Object.getOwnPropertyDescriptor,ti=(r,i,n)=>i in r?kt(r,i,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[i]=n,ni=(r,i,n,e)=>{for(var t=e>1?void 0:e?ei(i,n):i,o=r.length-1,a;o>=0;o--)(a=r[o])&&(t=(e?a(i,n,t):a(t))||t);return e&&t&&kt(i,n,t),t},yt=(r,i)=>(n,e)=>i(n,e,r),Lt=(r,i,n)=>ti(r,typeof i!="symbol"?i+"":i,n);const ii="SHEET_IMAGE_UI_PLUGIN";E.UniverSheetsDrawingUIPlugin=class extends l.Plugin{constructor(i=bt,n,e,t){super(),this._config=i,this._injector=n,this._renderManagerService=e,this._configService=t;const{menu:o,...a}=l.merge({},bt,this._config);o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Ht,a)}onStarting(){l.registerDependencies(this._injector,[[E.SheetCanvasFloatDomManagerService],[Qe],[Ge],[Ze],[ze],[Ke],[He],[xe],[Ve]]),l.touchDependencies(this._injector,[[E.SheetCanvasFloatDomManagerService]])}onReady(){l.touchDependencies(this._injector,[[Ke]])}onRendered(){this._registerRenderModules(),l.touchDependencies(this._injector,[[ze],[Ze],[Qe],[He],[xe],[Ve]])}onSteady(){this._injector.get(Ge)}_registerRenderModules(){[[Ue],[_t],[mt]].forEach(i=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,i))})}},Lt(E.UniverSheetsDrawingUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET),Lt(E.UniverSheetsDrawingUIPlugin,"pluginName",ii),E.UniverSheetsDrawingUIPlugin=ni([l.DependentOn(P.UniverDrawingPlugin,Se.UniverDocsDrawingPlugin,ge.UniverDrawingUIPlugin,w.UniverSheetsDrawingPlugin),yt(1,l.Inject(l.Injector)),yt(2,N.IRenderManagerService),yt(3,l.IConfigService)],E.UniverSheetsDrawingUIPlugin),E.ClearSheetDrawingTransformerOperation=H,E.DeleteDrawingsCommand=It,E.EditSheetDrawingOperation=ht,E.GroupSheetDrawingCommand=pt,E.InsertFloatImageCommand=Ne,E.InsertSheetDrawingCommand=Pe,E.MoveDrawingsCommand=ye,E.RemoveSheetDrawingCommand=Ce,E.SHEETS_IMAGE_MENU_ID=Ct,E.SetDrawingArrangeCommand=ft,E.SetSheetDrawingCommand=Ae,E.SidebarSheetDrawingOperation=gt,E.UngroupSheetDrawingCommand=St,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-drawing-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0-alpha.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -53,23 +53,23 @@
|
|
|
53
53
|
"lib"
|
|
54
54
|
],
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"react": "
|
|
56
|
+
"react": ">=16.9.0 || >=17 || >=18 || >=19",
|
|
57
57
|
"rxjs": ">=7.0.0"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@univerjs/icons": "^0.2.
|
|
60
|
+
"@univerjs/icons": "^0.2.14",
|
|
61
61
|
"clsx": "^2.1.1",
|
|
62
|
-
"@univerjs/core": "0.
|
|
63
|
-
"@univerjs/design": "0.
|
|
64
|
-
"@univerjs/docs-drawing": "0.
|
|
65
|
-
"@univerjs/docs-ui": "0.
|
|
66
|
-
"@univerjs/drawing": "0.
|
|
67
|
-
"@univerjs/drawing-ui": "0.
|
|
68
|
-
"@univerjs/sheets": "0.
|
|
69
|
-
"@univerjs/
|
|
70
|
-
"@univerjs/
|
|
71
|
-
"@univerjs/sheets-ui": "0.
|
|
72
|
-
"@univerjs/ui": "0.
|
|
62
|
+
"@univerjs/core": "0.6.0-alpha.0",
|
|
63
|
+
"@univerjs/design": "0.6.0-alpha.0",
|
|
64
|
+
"@univerjs/docs-drawing": "0.6.0-alpha.0",
|
|
65
|
+
"@univerjs/docs-ui": "0.6.0-alpha.0",
|
|
66
|
+
"@univerjs/drawing": "0.6.0-alpha.0",
|
|
67
|
+
"@univerjs/drawing-ui": "0.6.0-alpha.0",
|
|
68
|
+
"@univerjs/sheets": "0.6.0-alpha.0",
|
|
69
|
+
"@univerjs/engine-render": "0.6.0-alpha.0",
|
|
70
|
+
"@univerjs/sheets-drawing": "0.6.0-alpha.0",
|
|
71
|
+
"@univerjs/sheets-ui": "0.6.0-alpha.0",
|
|
72
|
+
"@univerjs/ui": "0.6.0-alpha.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"less": "^4.2.1",
|
|
@@ -77,10 +77,10 @@
|
|
|
77
77
|
"react": "18.3.1",
|
|
78
78
|
"rxjs": "^7.8.1",
|
|
79
79
|
"tailwindcss": "^3.4.17",
|
|
80
|
-
"typescript": "^5.7.
|
|
80
|
+
"typescript": "^5.7.3",
|
|
81
81
|
"vite": "^6.0.7",
|
|
82
82
|
"vitest": "^2.1.8",
|
|
83
|
-
"@univerjs-infra/shared": "0.
|
|
83
|
+
"@univerjs-infra/shared": "0.6.0-alpha.0"
|
|
84
84
|
},
|
|
85
85
|
"scripts": {
|
|
86
86
|
"test": "vitest run",
|