@univerjs/sheets-drawing-ui 0.5.0-nightly.202411120616 → 0.5.0-nightly.202411121606
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +2 -2
- package/lib/es/index.js +1046 -1050
- package/lib/types/services/canvas-float-dom-manager.service.d.ts +0 -1
- package/lib/umd/index.js +2 -2
- package/package.json +10 -10
package/lib/cjs/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var Je=Object.defineProperty;var Ze=(i,t,r)=>t in i?Je(i,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[t]=r;var Y=(i,t,r)=>Ze(i,typeof t!="symbol"?t+"":t,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@univerjs/core"),E=require("@univerjs/drawing"),te=require("@univerjs/drawing-ui"),N=require("@univerjs/engine-render"),p=require("@univerjs/sheets-drawing"),U=require("@univerjs/sheets-ui"),k=require("@univerjs/ui"),L=require("rxjs"),D=require("@univerjs/sheets"),H=require("react"),Z=require("@univerjs/design"),Qe="sheets-drawing-ui.config",et={},x={id:"sheet.operation.clear-drawing-transformer",type:m.CommandType.MUTATION,handler:(i,t)=>{const r=i.get(N.IRenderManagerService);return t.forEach(n=>{var e,o;(o=(e=r.getRenderById(n))==null?void 0:e.scene.getTransformer())==null||o.debounceRefreshControls()}),!0}},ie={id:"sheet.command.remove-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{var y,I,T;const r=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),e=i.get(D.SheetInterceptorService),o=i.get(p.ISheetDrawingService);if(!t)return!1;const{drawings:s}=t,c=[];s.forEach(_=>{const{unitId:M}=_;c.push(M)});const d=o.getBatchRemoveOp(s),{unitId:h,subUnitId:l,undo:a,redo:g,objects:u}=d,f=e.onCommandExecute({id:ie.id,params:t}),w={id:p.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:l,op:g,objects:u,type:p.DrawingApplyType.REMOVE}},S={id:p.SetDrawingApplyMutation.id,params:{unitId:h,subUnitId:l,op:a,objects:u,type:p.DrawingApplyType.INSERT}};return m.sequenceExecute([...(y=f.preRedos)!=null?y:[],w,...f.redos],r)?(n.pushUndoRedo({unitID:h,undoMutations:[...(I=f.preUndos)!=null?I:[],S,...f.undos,{id:x.id,params:c}],redoMutations:[...(T=f.preRedos)!=null?T:[],w,...f.redos,{id:x.id,params:c}]}),!0):!1}},Be="COMPONENT_SHEET_DRAWING_PANEL",be={id:"sidebar.operation.sheet-image",type:m.CommandType.COMMAND,handler:async(i,t)=>{const r=i.get(k.ISidebarService),n=i.get(m.LocaleService),e=i.get(m.IUniverInstanceService),o=i.get(E.IDrawingManagerService);if(!D.getSheetCommandTarget(e))return!1;switch(t.value){case"open":r.open({header:{title:n.t("sheetImage.panel.title")},children:{label:Be},onClose:()=>{o.focusDrawing(null)},width:360});break;case"close":default:r.close();break}return!0}},Ee={id:"sheet.operation.edit-sheet-image",type:m.CommandType.OPERATION,handler:(i,t)=>{const r=i.get(E.IDrawingManagerService),n=i.get(m.ICommandService);return t==null?!1:(r.focusDrawing([t]),n.executeCommand(be.id,{value:"open"}),!0)}};var $e={exports:{}},ve={};/**
|
|
2
2
|
* @license React
|
|
3
3
|
* react-jsx-runtime.production.min.js
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This source code is licensed under the MIT license found in the
|
|
8
8
|
* LICENSE file in the root directory of this source tree.
|
|
9
|
-
*/var nt=Y,rt=Symbol.for("react.element"),it=Symbol.for("react.fragment"),ot=Object.prototype.hasOwnProperty,st=nt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,at={key:!0,ref:!0,__self:!0,__source:!0};function ke(i,n,r){var e,t={},o=null,s=null;r!==void 0&&(o=""+r),n.key!==void 0&&(o=""+n.key),n.ref!==void 0&&(s=n.ref);for(e in n)ot.call(n,e)&&!at.hasOwnProperty(e)&&(t[e]=n[e]);if(i&&i.defaultProps)for(e in n=i.defaultProps,n)t[e]===void 0&&(t[e]=n[e]);return{$$typeof:rt,type:i,key:o,ref:s,props:t,_owner:st.current}}_e.Fragment=it;_e.jsx=ke;_e.jsxs=ke;Ge.exports=_e;var k=Ge.exports;const ct="univer-upload-loading",dt="univer-upload-loading-body",lt="univer-upload-loading-body-animation",ut="univer-UniverCircleAnimation",gt="univer-upload-loading-body-text",de={uploadLoading:ct,uploadLoadingBody:dt,uploadLoadingBodyAnimation:lt,univerCircleAnimation:ut,uploadLoadingBodyText:gt},ht=()=>{const i=m.useDependency(E.IImageIoService),n=m.useDependency(m.LocaleService),[r,e]=Y.useState(0);return Y.useEffect(()=>{const t=i.change$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[i]),k.jsx("div",{style:{display:r>0?"block":"none"},className:de.uploadLoading,children:k.jsxs("div",{className:de.uploadLoadingBody,children:[k.jsx("div",{className:de.uploadLoadingBodyAnimation}),k.jsx("div",{className:de.uploadLoadingBodyText,children:`${n.t("uploadLoading.loading")}: ${r}`})]})})};var mt=Object.defineProperty,pt=Object.getOwnPropertyDescriptor,ft=(i,n,r,e)=>{for(var t=e>1?void 0:e?pt(n,r):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(n,r,t):s(t))||t);return e&&t&&mt(n,r,t),t},Q=(i,n)=>(r,e)=>n(r,e,i);let me=class extends m.RxDisposable{constructor(n,r,e,t,o,s,c){super();F(this,"_initImagePopupMenu",new Set);this._injector=n,this._drawingManagerService=r,this._canvasPopManagerService=e,this._renderManagerService=t,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=c,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET).pipe(L.takeUntil(this.dispose$)).subscribe(n=>this._create(n)),this._univerInstanceService.getTypeOfUnitDisposed$(m.UniverInstanceType.UNIVER_SHEET).pipe(L.takeUntil(this.dispose$)).subscribe(n=>this._dispose(n)),this._univerInstanceService.getAllUnitsForType(m.UniverInstanceType.UNIVER_SHEET).forEach(n=>this._create(n)),this._uiPartsService.registerComponent(G.BuiltInUIPart.CONTENT,()=>m.connectInjector(ht,this._injector))}_dispose(n){const r=n.getUnitId();this._renderManagerService.removeRender(r)}_create(n){if(!n)return;const r=n.getUnitId();this._renderManagerService.has(r)&&!this._initImagePopupMenu.has(r)&&(this._popupMenuListener(r),this._initImagePopupMenu.add(r))}_hasCropObject(n){const r=n.getAllObjectsByOrder();for(const e of r)if(e instanceof te.ImageCropperObject)return!0;return!1}_popupMenuListener(n){var o;const r=(o=this._renderManagerService.getRenderById(n))==null?void 0:o.scene;if(!r)return;const e=r.getTransformerByCreate();if(!e)return;let t;this.disposeWithMe(m.toDisposable(e.createControl$.subscribe(()=>{if(this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(r))return;const s=e.getSelectedObjectMap();if(s.size>1){t==null||t.dispose();return}const c=s.values().next().value;if(!c)return;const d=c.oKey,h=this._drawingManagerService.getDrawingOKey(d);if(!h)return;const{unitId:l,subUnitId:a,drawingId:u,drawingType:g}=h,f=h.data;f&&f.disablePopup||(t==null||t.dispose(),t=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:te.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(l,a,u,g)}})),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:a,drawingId:u}]))}))),this.disposeWithMe(e.clearControl$.subscribe(()=>{t==null||t.dispose(),this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(e.changing$.subscribe(()=>{t==null||t.dispose()}))}_getImageMenuItems(n,r,e,t){return[{label:"image-popup.edit",index:0,commandId:Oe.id,commandParams:{unitId:n,subUnitId:r,drawingId:e},disable:t===E.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:oe.id,commandParams:{unitId:n,drawings:[{unitId:n,subUnitId:r,drawingId:e}]},disable:!1},{label:"image-popup.crop",index:2,commandId:te.OpenImageCropOperation.id,commandParams:{unitId:n,subUnitId:r,drawingId:e},disable:t===E.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:te.ImageResetSizeOperation.id,commandParams:[{unitId:n,subUnitId:r,drawingId:e}],disable:t===E.DrawingTypeEnum.DRAWING_DOM}]}};me=ft([Q(0,m.Inject(m.Injector)),Q(1,E.IDrawingManagerService),Q(2,m.Inject(N.SheetCanvasPopManagerService)),Q(3,U.IRenderManagerService),Q(4,m.IUniverInstanceService),Q(5,m.IContextService),Q(6,m.Inject(G.IUIPartsService))],me);function V(i,n,r){const{from:e,to:t,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:d=0,skewY:h=0}=i,{column:l,columnOffset:a,row:u,rowOffset:g}=e,{column:f,columnOffset:w,row:S,rowOffset:C}=t,y=r.getCurrentSkeleton(),I=N.attachRangeWithCoord(y,{startColumn:l,endColumn:l,startRow:u,endRow:u});if(I==null)return;const T=N.attachRangeWithCoord(y,{startColumn:f,endColumn:f,startRow:S,endRow:S});if(T==null)return;const{startX:_,startY:M}=I,{startX:v,startY:P}=T;let b=U.precisionTo(_+a,1),j=U.precisionTo(M+g,1),A=U.precisionTo(v+w-b,1),O=U.precisionTo(P+C-j,1);I.startX===T.endX&&(A=0),I.startY===T.endY&&(O=0);const R=y.rowHeaderWidth+y.columnTotalWidth,W=y.columnHeaderHeight+y.rowTotalHeight;return b+A>R&&(b=R-A),j+O>W&&(j=W-O),{flipY:o,flipX:s,angle:c,skewX:d,skewY:h,left:b,top:j,width:A,height:O}}function $(i,n){const{left:r=0,top:e=0,width:t=0,height:o=0,flipY:s=!1,flipX:c=!1,angle:d=0,skewX:h=0,skewY:l=0}=i,a=n.getSelectionCellByPosition(r,e);if(a==null)return;const u={column:a.actualColumn,columnOffset:U.precisionTo(r-a.startX,1),row:a.actualRow,rowOffset:U.precisionTo(e-a.startY,1)},g=n.getSelectionCellByPosition(r+t,e+o);if(g==null)return;const f={column:g.actualColumn,columnOffset:U.precisionTo(r+t-g.startX,1),row:g.actualRow,rowOffset:U.precisionTo(e+o-g.startY,1)};return{flipY:s,flipX:c,angle:d,skewX:h,skewY:l,from:u,to:f}}var wt=Object.defineProperty,St=Object.getOwnPropertyDescriptor,vt=(i,n,r,e)=>{for(var t=e>1?void 0:e?St(n,r):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(n,r,t):s(t))||t);return e&&t&&wt(n,r,t),t},le=(i,n)=>(r,e)=>n(r,e,i);let Te=class extends m.Disposable{constructor(i,n,r,e,t){super(),this._context=i,this._sheetDrawingService=n,this._drawingManagerService=r,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 n in i){const r=i[n];for(const e in r.data){const t=r.data[e];t.transform=V(t.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Te=vt([le(1,p.ISheetDrawingService),le(2,E.IDrawingManagerService),le(3,m.Inject(N.ISheetSelectionRenderService)),le(4,m.Inject(N.SheetSkeletonManagerService))],Te);var H=function(){return H=Object.assign||function(i){for(var n,r=1,e=arguments.length;r<e;r++){n=arguments[r];for(var t in n)Object.prototype.hasOwnProperty.call(n,t)&&(i[t]=n[t])}return i},H.apply(this,arguments)},_t=function(i,n){var r={};for(var e in i)Object.prototype.hasOwnProperty.call(i,e)&&n.indexOf(e)<0&&(r[e]=i[e]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var t=0,e=Object.getOwnPropertySymbols(i);t<e.length;t++)n.indexOf(e[t])<0&&Object.prototype.propertyIsEnumerable.call(i,e[t])&&(r[e[t]]=i[e[t]]);return r},Ve=Y.forwardRef(function(i,n){var r=i.icon,e=i.id,t=i.className,o=i.extend,s=_t(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(e," ").concat(t||"").trim(),d=Y.useRef("_".concat(Ct()));return Fe(r,"".concat(e),{defIds:r.defIds,idSuffix:d.current},H({ref:n,className:c},s),o)});function Fe(i,n,r,e,t){return Y.createElement(i.tag,H(H({key:n},Dt(i,r,t)),e),(It(i,r).children||[]).map(function(o,s){return Fe(o,"".concat(n,"-").concat(i.tag,"-").concat(s),r,void 0,t)}))}function Dt(i,n,r){var e=H({},i.attrs);r!=null&&r.colorChannel1&&e.fill==="colorChannel1"&&(e.fill=r.colorChannel1);var t=n.defIds;return!t||t.length===0||(i.tag==="use"&&e["xlink:href"]&&(e["xlink:href"]=e["xlink:href"]+n.idSuffix),Object.entries(e).forEach(function(o){var s=o[0],c=o[1];typeof c=="string"&&(e[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(n.idSuffix,")")))})),e}function It(i,n){var r,e=n.defIds;return!e||e.length===0?i:i.tag==="defs"&&(!((r=i.children)===null||r===void 0)&&r.length)?H(H({},i),{children:i.children.map(function(t){return typeof t.attrs.id=="string"&&e&&e.indexOf(t.attrs.id)>-1?H(H({},t),{attrs:H(H({},t.attrs),{id:t.attrs.id+n.idSuffix})}):t})}):i}function Ct(){return Math.random().toString(36).substring(2,8)}Ve.displayName="UniverIcon";var yt={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"}}]},Ye=Y.forwardRef(function(i,n){return Y.createElement(Ve,Object.assign({},i,{id:"add-image-single",ref:n,icon:yt}))});Ye.displayName="AddImageSingle";const Pe={id:"sheet.command.delete-drawing",type:m.CommandType.COMMAND,handler:i=>{const n=i.get(m.ICommandService),e=i.get(p.ISheetDrawingService).getFocusDrawings();if(e.length===0)return!1;const t=e[0].unitId,o=e.map(s=>{const{unitId:c,subUnitId:d,drawingId:h,drawingType:l}=s;return{unitId:c,subUnitId:d,drawingId:h,drawingType:l}});return n.executeCommand(oe.id,{unitId:t,drawings:o})}};function Mt(i){const n=[];return i.forEach(r=>{const{parent:e,children:t}=r,{unitId:o,subUnitId:s,drawingId:c}=e,d=U.getGroupState(0,0,t.map(a=>a.transform||{})),h=t.map(a=>{const u=a.transform||{left:0,top:0},{unitId:g,subUnitId:f,drawingId:w}=a;return{unitId:g,subUnitId:f,drawingId:w,transform:{...u,left:u.left-d.left,top:u.top-d.top},groupId:c}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:d};n.push({parent:l,children:h})}),n}function Rt(i){const n=[];return i.forEach(r=>{const{parent:e,children:t}=r,{unitId:o,subUnitId:s,drawingId:c,transform:d={width:0,height:0}}=e;if(d==null)return;const h=t.map(a=>{const{transform:u}=a,{unitId:g,subUnitId:f,drawingId:w}=a,S=U.transformObjectOutOfGroup(u||{},d,d.width||0,d.height||0);return{unitId:g,subUnitId:f,drawingId:w,transform:S,groupId:void 0}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};n.push({parent:l,children:h})}),n}const Ae={id:"sheet.command.group-sheet-image",type:m.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(m.ICommandService),e=i.get(m.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:g,children:f})=>{o.push(g.unitId),f.forEach(w=>{o.push(w.unitId)})});const s=t.getGroupDrawingOp(n),{unitId:c,subUnitId:d,undo:h,redo:l,objects:a}=s;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.GROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:c,subUnitId:d,objects:Rt(a),type:p.DrawingApplyType.UNGROUP}},{id:x.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.GROUP}},{id:x.id,params:o}]}),!0):!1}},se={id:"sheet.command.insert-sheet-image",type:m.CommandType.COMMAND,handler:(i,n)=>{var y,I,T;const r=i.get(m.ICommandService),e=i.get(m.IUndoRedoService),t=i.get(p.ISheetDrawingService),o=i.get(D.SheetInterceptorService);if(!n)return!1;const s=n.drawings,c=s.map(_=>_.unitId),d=t.getBatchAddOp(s),{unitId:h,subUnitId:l,undo:a,redo:u,objects:g}=d,f=o.onCommandExecute({id:se.id,params:n}),w={id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:h,subUnitId:l,objects:g,type:p.DrawingApplyType.INSERT}},S={id:p.SetDrawingApplyMutation.id,params:{op:a,unitId:h,subUnitId:l,objects:g,type:p.DrawingApplyType.REMOVE}};return m.sequenceExecute([...(y=f.preRedos)!=null?y:[],w,...f.redos],r)?(e.pushUndoRedo({unitID:h,undoMutations:[...(I=f.preUndos)!=null?I:[],S,...f.undos,{id:x.id,params:c}],redoMutations:[...(T=f.preRedos)!=null?T:[],w,...f.redos,{id:x.id,params:c}]}),!0):!1}},Ue={id:"sheet.command.set-drawing-arrange",type:m.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(m.ICommandService),e=i.get(m.IUndoRedoService);if(!n)return!1;const t=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:d}=n,h={unitId:o,subUnitId:s,drawingIds:c};let l;if(d===E.ArrangeTypeEnum.forward?l=t.getForwardDrawingsOp(h):d===E.ArrangeTypeEnum.backward?l=t.getBackwardDrawingOp(h):d===E.ArrangeTypeEnum.front?l=t.getFrontDrawingsOp(h):d===E.ArrangeTypeEnum.back&&(l=t.getBackDrawingsOp(h)),l==null)return!1;const{objects:a,redo:u,undo:g}=l;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:u,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE})?(e.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},ae={id:"sheet.command.set-sheet-image",type:m.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(m.ICommandService),e=i.get(m.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!n)return!1;const{drawings:o}=n,s=t.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:h,redo:l,objects:a}=s;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:c,subUnitId:d,op:l,objects:a,type:p.DrawingApplyType.UPDATE})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:h,objects:a,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[c]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:l,objects:a,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[c]}]}),!0):!1}},Ne={id:"sheet.command.ungroup-sheet-image",type:m.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(m.ICommandService),e=i.get(m.IUndoRedoService),t=i.get(p.ISheetDrawingService);if(!n)return!1;const o=[];n.forEach(({parent:g,children:f})=>{o.push(g.unitId),f.forEach(w=>{o.push(w.unitId)})});const s=t.getUngroupDrawingOp(n),{unitId:c,subUnitId:d,undo:h,redo:l,objects:a}=s;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.UNGROUP})?(e.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:c,subUnitId:d,objects:Mt(a),type:p.DrawingApplyType.GROUP}},{id:x.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.UNGROUP}},{id:x.id,params:o}]}),!0):!1}};var Tt=Object.defineProperty,bt=Object.getOwnPropertyDescriptor,Et=(i,n,r,e)=>{for(var t=e>1?void 0:e?bt(n,r):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(n,r,t):s(t))||t);return e&&t&&Tt(n,r,t),t},X=(i,n)=>(r,e)=>n(r,e,i);let pe=class extends m.Disposable{constructor(n,r,e,t,o,s,c,d,h,l,a,u){super();F(this,"_workbookSelections");this._context=n,this._skeletonManagerService=r,this._commandService=e,this._selectionRenderService=t,this._imageIoService=o,this._fileOpenerService=s,this._sheetDrawingService=c,this._drawingManagerService=d,this._contextService=h,this._messageService=l,this._localeService=a,this._workbookSelections=u.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const n=await this._fileOpenerService.openFile({multiple:!0,accept:E.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(e=>`.${e.replace("image/","")}`).join(",")}),r=n.length;return r>E.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(E.DRAWING_IMAGE_COUNT_LIMIT))}),!1):r===0?!1:(n.forEach(async e=>await this._insertFloatImage(e)),!0)}async _insertFloatImage(n){let r;try{r=await this._imageIoService.saveImage(n)}catch(y){const I=y.message;I===E.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(E.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):I===E.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):I===E.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(r==null)return;const e=this._getUnitInfo(),{unitId:t,subUnitId:o}=e,{imageId:s,imageSourceType:c,source:d,base64Cache:h}=r,{width:l,height:a,image:u}=await E.getImageSize(h||""),{width:g,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(d,c,u);let w=1;if(l>E.DRAWING_IMAGE_WIDTH_LIMIT||a>E.DRAWING_IMAGE_HEIGHT_LIMIT){const y=E.DRAWING_IMAGE_WIDTH_LIMIT/l,I=E.DRAWING_IMAGE_HEIGHT_LIMIT/a;w=Math.max(y,I)}const S=this._getImagePosition(l*w,a*w,g,f);if(S==null)return;const C={unitId:t,subUnitId:o,drawingId:s,drawingType:E.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:d,transform:V(S,this._selectionRenderService,this._skeletonManagerService),sheetTransform:S};this._commandService.executeCommand(se.id,{unitId:t,drawings:[C]})}_getUnitInfo(){const n=this._context.unit,r=n.getActiveSheet(),e=n.getUnitId(),t=r.getSheetId();return{unitId:e,subUnitId:t}}_getImagePosition(n,r,e,t){const o=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(s=o[o.length-1].range);const c=N.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(c==null)return;let{startColumn:d,startRow:h,startX:l,startY:a}=c,u=!1;if(l+n>e&&(l=e-n,l<0&&(l=0,n=e),u=!0),a+r>t&&(a=t-r,a<0&&(a=0,r=t),u=!0),u){const S=this._selectionRenderService.getSelectionCellByPosition(l,a);if(S==null)return;l=S.startX,a=S.startY,d=S.actualColumn,h=S.actualRow}const g={column:d,columnOffset:0,row:h,rowOffset:0},f=this._selectionRenderService.getSelectionCellByPosition(l+n,a+r);if(f==null)return;const w={column:f.actualColumn,columnOffset:l+n-f.startX,row:f.actualRow,rowOffset:a+r-f.startY};return{from:g,to:w}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(n=>{const{unitId:r,subUnitId:e,drawingIds:t,arrangeType:o}=n;this._commandService.executeCommand(Ue.id,{unitId:r,subUnitId:e,drawingIds:t,arrangeType:o})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(n=>{const r=[];n.length!==0&&(n.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:s,drawingType:c,transform:d}=e;if(d==null)return;const h=this._sheetDrawingService.getDrawingByParam({unitId:t,subUnitId:o,drawingId:s});if(h==null||h.unitId!==this._context.unitId)return;const l=$({...h.transform,...d},this._selectionRenderService);if(l==null)return;const a={...e,transform:{...h.transform,...d,...V(l,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...l}};r.push(a)}),r.length>0&&this._commandService.executeCommand(ae.id,{unitId:n[0].unitId,drawings:r}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(n=>{this._commandService.executeCommand(Ae.id,n);const{unitId:r,subUnitId:e,drawingId:t}=n[0].parent;this._drawingManagerService.focusDrawing([{unitId:r,subUnitId:e,drawingId:t}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(n=>{this._commandService.executeCommand(Ne.id,n)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(n=>{n==null||n.length===0?(this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(n))}))}};pe=Et([X(1,m.Inject(N.SheetSkeletonManagerService)),X(2,m.ICommandService),X(3,N.ISheetSelectionRenderService),X(4,E.IImageIoService),X(5,G.ILocalFileService),X(6,p.ISheetDrawingService),X(7,E.IDrawingManagerService),X(8,m.IContextService),X(9,G.IMessageService),X(10,m.Inject(m.LocaleService)),X(11,m.Inject(D.SheetsSelectionsService))],pe);const De={id:"sheet.command.insert-float-image",type:m.CommandType.COMMAND,handler:i=>{var r,e;return(e=(r=i.get(U.IRenderManagerService).getCurrentTypeOfRenderer(m.UniverInstanceType.UNIVER_SHEET))==null?void 0:r.with(pe).insertFloatImage())!=null?e:!1}},re={id:"sheet.command.move-drawing",type:m.CommandType.COMMAND,handler:(i,n)=>{const r=i.get(m.ICommandService),e=i.get(p.ISheetDrawingService),t=i.get(N.ISheetSelectionRenderService),{direction:o}=n,s=e.getFocusDrawings();if(s.length===0)return!1;const c=s[0].unitId,d=s.map(l=>{const{transform:a}=l;if(a==null)return null;const u={...a},{left:g=0,top:f=0}=a;return o===m.Direction.UP?u.top=f-1:o===m.Direction.DOWN?u.top=f+1:o===m.Direction.LEFT?u.left=g-1:o===m.Direction.RIGHT&&(u.left=g+1),{...l,transform:u,sheetTransform:$(u,t)}}).filter(l=>l!=null);return r.syncExecuteCommand(ae.id,{unitId:c,drawings:d})?(r.syncExecuteCommand(x.id,[c]),!0):!1}},He="addition-and-subtraction-single",je="sheet.menu.image";function Ot(i){return{id:je,type:G.MenuItemType.SUBITEMS,icon:He,tooltip:"sheetImage.title",hidden$:G.getMenuHiddenObservable(i,m.UniverInstanceType.UNIVER_SHEET),disabled$:N.getCurrentRangeDisable$(i,{workbookTypes:[D.WorkbookEditablePermission],worksheetTypes:[D.WorksheetEditPermission],rangeTypes:[D.RangeProtectionPermissionEditPoint]})}}function Pt(i){return{id:De.id,title:"sheetImage.upload.float",type:G.MenuItemType.BUTTON,hidden$:G.getMenuHiddenObservable(i,m.UniverInstanceType.UNIVER_SHEET)}}const At="univer-image-common-panel",Ut="univer-image-common-panel-grid",Nt="univer-image-common-panel-border",jt="univer-image-common-panel-title",Wt="univer-image-common-panel-subtitle",Lt="univer-image-common-panel-row",xt="univer-image-common-panel-row-vertical",Bt="univer-image-common-panel-column",$t="univer-image-common-panel-column-center",Gt="univer-image-common-panel-inline",kt="univer-image-common-panel-span2",Vt="univer-image-common-panel-span3",Ft="univer-image-common-panel-input",Yt="univer-sheet-image-menu",Ht="univer-sheet-image-menu-input",J={imageCommonPanel:At,imageCommonPanelGrid:Ut,imageCommonPanelBorder:Nt,imageCommonPanelTitle:jt,imageCommonPanelSubtitle:Wt,imageCommonPanelRow:Lt,imageCommonPanelRowVertical:xt,imageCommonPanelColumn:Bt,imageCommonPanelColumnCenter:$t,imageCommonPanelInline:Gt,imageCommonPanelSpan2:kt,imageCommonPanelSpan3:Vt,imageCommonPanelInput:Ft,sheetImageMenu:Yt,sheetImageMenuInput:Ht};function Xe(i){var n,r,e="";if(typeof i=="string"||typeof i=="number")e+=i;else if(typeof i=="object")if(Array.isArray(i)){var t=i.length;for(n=0;n<t;n++)i[n]&&(r=Xe(i[n]))&&(e&&(e+=" "),e+=r)}else for(r in i)i[r]&&(e&&(e+=" "),e+=r);return e}function ue(){for(var i,n,r=0,e="",t=arguments.length;r<t;r++)(i=arguments[r])&&(n=Xe(i))&&(e&&(e+=" "),e+=n);return e}const Xt=i=>{var I;const n=m.useDependency(m.ICommandService),r=m.useDependency(m.LocaleService),e=m.useDependency(E.IDrawingManagerService),t=m.useDependency(U.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:c}=s,d=t.getRenderById(c),h=d==null?void 0:d.scene;if(h==null)return;const l=h.getTransformerByCreate(),[a,u]=Y.useState(!0),g=(I=s.anchorType)!=null?I:p.SheetDrawingAnchorType.Position,[f,w]=Y.useState(g);function S(T,_){const M=[];return T.forEach(v=>{const{oKey:P}=v,b=_.getDrawingOKey(P);if(b==null)return M.push(null),!0;const{unitId:j,subUnitId:A,drawingId:O,drawingType:R,anchorType:W,sheetTransform:B}=b;M.push({unitId:j,subUnitId:A,drawingId:O,anchorType:W,sheetTransform:B,drawingType:R})}),M}Y.useEffect(()=>{const T=l.clearControl$.subscribe(M=>{M===!0&&u(!1)}),_=l.changeStart$.subscribe(M=>{var b;const{objects:v}=M,P=S(v,e);if(P.length===0)u(!1);else if(P.length>=1){u(!0);const j=((b=P[0])==null?void 0:b.anchorType)||p.SheetDrawingAnchorType.Position;w(j)}});return()=>{_.unsubscribe(),T.unsubscribe()}},[]);function C(T){w(T);const _=e.getFocusDrawings();if(_.length===0)return;const M=_.map(v=>({unitId:v.unitId,subUnitId:v.subUnitId,drawingId:v.drawingId,anchorType:T}));n.executeCommand(ae.id,{unitId:_[0].unitId,drawings:M})}const y=T=>T?"block":"none";return k.jsxs("div",{className:ue(J.imageCommonPanelGrid,J.imageCommonPanelBorder),style:{display:y(a)},children:[k.jsx("div",{className:J.imageCommonPanelRow,children:k.jsx("div",{className:ue(J.imageCommonPanelColumn,J.imageCommonPanelTitle),children:k.jsx("div",{children:r.t("drawing-anchor.title")})})}),k.jsx("div",{className:ue(J.imageCommonPanelRow),children:k.jsx("div",{className:ue(J.imageCommonPanelColumn),children:k.jsxs(Z.RadioGroup,{value:f,onChange:C,direction:"vertical",children:[k.jsx(Z.Radio,{value:p.SheetDrawingAnchorType.Both,children:r.t("drawing-anchor.both")}),k.jsx(Z.Radio,{value:p.SheetDrawingAnchorType.Position,children:r.t("drawing-anchor.position")}),k.jsx(Z.Radio,{value:p.SheetDrawingAnchorType.None,children:r.t("drawing-anchor.none")})]})})})]})},Kt=()=>{const i=m.useDependency(E.IDrawingManagerService),n=i.getFocusDrawings(),[r,e]=Y.useState(n);return Y.useEffect(()=>{const t=i.focus$.subscribe(o=>{e(o)});return()=>{t.unsubscribe()}},[]),!!(r!=null&&r.length)&&k.jsxs("div",{className:J.imageCommonPanel,children:[k.jsx(te.DrawingCommonPanel,{drawings:r}),k.jsx(Xt,{drawings:r})]})},zt={[G.RibbonStartGroup.FORMULAS_INSERT]:{[je]:{order:3,menuItemFactory:Ot,[De.id]:{order:0,menuItemFactory:Pt}}}};function ce(i){return!i.getContextValue(m.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(m.EDITOR_ACTIVATED)&&!i.getContextValue(m.FOCUSING_PANEL_EDITOR)&&i.getContextValue(m.FOCUSING_COMMON_DRAWINGS)}const qt={id:re.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_DOWN,priority:100,preconditions:ce,staticParameters:{direction:m.Direction.DOWN}},Jt={id:re.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_UP,priority:100,preconditions:ce,staticParameters:{direction:m.Direction.UP}},Zt={id:re.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_LEFT,priority:100,preconditions:ce,staticParameters:{direction:m.Direction.LEFT}},Qt={id:re.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:G.KeyCode.ARROW_RIGHT,priority:100,preconditions:ce,staticParameters:{direction:m.Direction.RIGHT}},en={id:Pe.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ce,binding:G.KeyCode.DELETE,mac:G.KeyCode.BACKSPACE};var tn=Object.defineProperty,nn=Object.getOwnPropertyDescriptor,rn=(i,n,r,e)=>{for(var t=e>1?void 0:e?nn(n,r):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(n,r,t):s(t))||t);return e&&t&&tn(n,r,t),t},ge=(i,n)=>(r,e)=>n(r,e,i);let fe=class extends m.Disposable{constructor(i,n,r,e){super(),this._componentManager=i,this._menuManagerService=n,this._commandService=r,this._shortcutService=e,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(He,Ye)),this.disposeWithMe(i.register($e,Kt))}_initMenus(){this._menuManagerService.mergeMenu(zt)}_initCommands(){[De,se,oe,ae,Ee,x,Oe,Ae,Ne,re,Pe,Ue].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[qt,Jt,Zt,Qt,en].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};fe=rn([ge(0,m.Inject(G.ComponentManager)),ge(1,G.IMenuManagerService),ge(2,m.ICommandService),ge(3,G.IShortcutService)],fe);var on=Object.defineProperty,sn=Object.getOwnPropertyDescriptor,an=(i,n,r,e)=>{for(var t=e>1?void 0:e?sn(n,r):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(n,r,t):s(t))||t);return e&&t&&on(n,r,t),t},ye=(i,n)=>(r,e)=>n(r,e,i);let we=class extends m.Disposable{constructor(n,r,e){super();F(this,"_copyInfo");this._sheetClipboardService=n,this._renderManagerService=r,this._sheetDrawingService=e,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(n,r,e)=>this._collect(n,r,e),onPasteCells:(n,r,e,t)=>{const{copyType:o=N.COPY_TYPE.COPY,pasteType:s}=t,{range:c}=n||{},{range:d,unitId:h,subUnitId:l}=r;return this._generateMutations(d,{copyType:o,pasteType:s,copyRange:c,unitId:h,subUnitId:l})},onPastePlainText:(n,r)=>({undos:[],redos:[]})})}_collect(n,r,e){var u;const t=(u=this._renderManagerService.getRenderById(n))==null?void 0:u.with(N.SheetSkeletonManagerService);if(!t)return;const o=t.attachRangeWithCoord(e);if(!o)return;const{startX:s,endX:c,startY:d,endY:h}=o,l=this._sheetDrawingService.getDrawingData(n,r),a=[];Object.keys(l).forEach(g=>{const f=l[g],{transform:w}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!w)return;const{left:S=0,top:C=0,width:y=0,height:I=0}=w,{drawingStartX:T,drawingEndX:_,drawingStartY:M,drawingEndY:v}={drawingStartX:S,drawingEndX:S+y,drawingStartY:C,drawingEndY:C+I};s<=T&&_<=c&&d<=M&&v<=h&&a.push(f)}),a.length&&(this._copyInfo={drawings:a,unitId:n,subUnitId:r})}_generateMutations(n,r){var b;if(!this._copyInfo)return{redos:[],undos:[]};if([N.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,N.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,N.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,N.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(r.pasteType))return{redos:[],undos:[]};const{copyRange:e}=r;if(!e)return{redos:[],undos:[]};const{drawings:t,unitId:o,subUnitId:s}=this._copyInfo,{ranges:[c,d],mapFunc:h}=N.virtualizeDiscreteRanges([e,n]),{row:l,col:a}=h(c.startRow,c.startColumn),{row:u,col:g}=h(d.startRow,d.startColumn),f=(b=this._renderManagerService.getRenderById(o))==null?void 0:b.with(N.SheetSkeletonManagerService);if(!f)return{redos:[],undos:[]};const w=f.attachRangeWithCoord({startRow:l,endRow:l,startColumn:a,endColumn:a}),S=f.attachRangeWithCoord({startRow:u,endRow:u,startColumn:g,endColumn:g});if(!w||!S)return{redos:[],undos:[]};const C=[],y=[],I=S.startX-w.startX,T=S.startY-w.startY,_=u-l,M=g-a,v=r.copyType===N.COPY_TYPE.CUT,{_sheetDrawingService:P}=this;return t.forEach(j=>{const{transform:A,sheetTransform:O}=j;if(!A)return;const R={...j,unitId:o,subUnitId:s,drawingId:v?j.drawingId:m.Tools.generateRandomId(),transform:{...A,left:A.left+I,top:A.top+T},sheetTransform:{to:{...O.to,row:O.to.row+_,column:O.to.column+M},from:{...O.from,row:O.from.row+_,column:O.from.column+M}}};if(v){const{undo:W,redo:B,objects:z}=P.getBatchUpdateOp([R]);C.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:s,type:p.DrawingApplyType.UPDATE,op:B,objects:z}}),y.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:s,type:p.DrawingApplyType.UPDATE,op:W,objects:z}})}else{const{undo:W,redo:B,objects:z}=P.getBatchAddOp([R]);C.push({id:p.SetDrawingApplyMutation.id,params:{op:B,unitId:o,subUnitId:s,objects:z,type:p.DrawingApplyType.INSERT}}),y.push({id:p.SetDrawingApplyMutation.id,params:{op:W,unitId:o,subUnitId:s,objects:z,type:p.DrawingApplyType.REMOVE}})}}),{redos:C,undos:y}}};we=an([ye(0,N.ISheetClipboardService),ye(1,U.IRenderManagerService),ye(2,p.ISheetDrawingService)],we);var cn=Object.defineProperty,dn=Object.getOwnPropertyDescriptor,ln=(i,n,r,e)=>{for(var t=e>1?void 0:e?dn(n,r):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(n,r,t):s(t))||t);return e&&t&&cn(n,r,t),t},ie=(i,n)=>(r,e)=>n(r,e,i);let Se=class extends m.Disposable{constructor(i,n,r,e,t){super(),this._drawingManagerService=i,this._renderManagerService=n,this._permissionService=r,this._univerInstanceService=e,this._userManagerService=t,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,r])=>{if(!n){this._drawingManagerService.setDrawingVisible(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingVisible(!1);return}const t=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new D.WorkbookViewPermission(t).id,new D.WorksheetViewPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const c=n.getUnitId(),d=e.getSheetId(),h=this._drawingManagerService.getDrawingData(c,d),l=Object.values(h),a=this._renderManagerService.getRenderById(c),u=a==null?void 0:a.scene;if(u==null)return;u.getAllObjectsByOrder().forEach(f=>{f.classType===U.RENDER_CLASS_TYPE.IMAGE&&l.some(w=>f.oKey.includes(w.drawingId))&&u.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,r])=>{if(!n){this._drawingManagerService.setDrawingEditable(!1);return}n.activeSheet$.subscribe(e=>{if(!e){this._drawingManagerService.setDrawingEditable(!1);return}const t=n.getUnitId(),o=e.getSheetId();if(this._permissionService.composePermission([new D.WorkbookEditablePermission(t).id,new D.WorksheetEditPermission(t,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const c=n.getUnitId(),d=e.getSheetId(),h=this._drawingManagerService.getDrawingData(c,d),l=Object.values(h),a=this._renderManagerService.getRenderById(c),u=a==null?void 0:a.scene;if(u==null)return;u.getAllObjectsByOrder().forEach(f=>{f.classType===U.RENDER_CLASS_TYPE.IMAGE&&l.some(w=>f.oKey.includes(w.drawingId))&&u.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,r])=>{n&&n.activeSheet$.subscribe(e=>{var a;if(!e)return;const t=n.getUnitId(),o=e.getSheetId();let s=!0;const c=this._renderManagerService.getRenderById(t),d=c==null?void 0:c.scene;if(d==null)return;const h=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new D.WorkbookViewPermission(t).id,new D.WorksheetViewPermission(t,o).id]).pipe(L.map(u=>u.every(g=>g.value)));l==null||l.pipe(L.filter(u=>u!==s),L.distinctUntilChanged()).subscribe({next:u=>{s=u,this._drawingManagerService.setDrawingVisible(u);const g=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),w=Object.values(f);u?this._drawingManagerService.addNotification(w):(g.forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&w.some(C=>S.oKey.includes(C.drawingId))&&d.removeObject(S)}),h.clearSelectedObjects())}}),(a=this._permissionService.getPermissionPoint$(new D.WorksheetViewPermission(t,o).id))==null||a.pipe(L.filter(u=>u.value!==s),L.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const u=this._drawingManagerService.getDrawingData(t,o),g=Object.values(u);this._drawingManagerService.addNotification(g)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([n,r])=>{n&&n.activeSheet$.subscribe(e=>{var a;if(!e)return;const t=n.getUnitId(),o=e.getSheetId();let s=!0;const c=this._renderManagerService.getRenderById(t),d=c==null?void 0:c.scene;if(d==null)return;const h=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new D.WorkbookEditablePermission(t).id,new D.WorksheetEditPermission(t,o).id]).pipe(L.map(u=>u.every(g=>g.value)));l==null||l.pipe(L.filter(u=>u!==s),L.distinctUntilChanged()).subscribe({next:u=>{s=u,this._drawingManagerService.setDrawingEditable(u);const g=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(t,o),w=Object.values(f);u?(g.forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&w.some(C=>S.oKey.includes(C.drawingId))&&d.attachTransformerTo(S)}),this._drawingManagerService.addNotification(w)):(g.forEach(S=>{S.classType===U.RENDER_CLASS_TYPE.IMAGE&&w.some(C=>S.oKey.includes(C.drawingId))&&d.detachTransformerFrom(S)}),h.clearSelectedObjects())}}),(a=this._permissionService.getPermissionPoint$(new D.WorksheetEditPermission(t,o).id))==null||a.pipe(L.filter(u=>u.value!==s),L.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const u=n.getUnitId(),g=e.getSheetId(),f=this._drawingManagerService.getDrawingData(u,g),w=Object.values(f),S=this._renderManagerService.getRenderById(u),C=S==null?void 0:S.scene;if(C==null)return;this._drawingManagerService.setDrawingEditable(!0),C.getAllObjectsByOrder().forEach(I=>{I.classType===U.RENDER_CLASS_TYPE.IMAGE&&w.some(T=>I.oKey.includes(T.drawingId))&&C.detachTransformerFrom(I)})}})})}))}};Se=ln([ie(0,E.IDrawingManagerService),ie(1,U.IRenderManagerService),ie(2,m.IPermissionService),ie(3,m.IUniverInstanceService),ie(4,m.Inject(m.UserManagerService))],Se);var un=Object.defineProperty,gn=Object.getOwnPropertyDescriptor,hn=(i,n,r,e)=>{for(var t=e>1?void 0:e?gn(n,r):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(n,r,t):s(t))||t);return e&&t&&un(n,r,t),t},he=(i,n)=>(r,e)=>n(r,e,i);let ve=class extends m.Disposable{constructor(i,n,r,e){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=n,this._drawingManagerService=r,this._renderManagerService=e,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,n,r)=>{const{unitId:e,scene:t,subUnitId:o}=n,s=this._drawingManagerService.getDrawingDataForUnit(e),c=s==null?void 0:s[o];return c&&c.order.forEach(d=>{this._drawingRenderService.renderDrawing(c.data[d],t)}),r()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,n,r)=>{const{unitId:e,subUnitId:t}=n,o=this._renderManagerService.getRenderById(e);if(!o)return r(i);const s=o.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(t);if(!s)return r(i);const c=this._drawingManagerService.getDrawingDataForUnit(e),d=c==null?void 0:c[n.subUnitId];if(!d)return r(i);const{scaleX:h,scaleY:l}=o.scene,a=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},u=d.order.map(g=>d.data[g]).filter(g=>g.drawingType!==E.DrawingTypeEnum.DRAWING_DOM);return u.length?(u.forEach(g=>{if(!g.groupId&&g.transform&&m.Tools.isDefine(g.transform.left)&&m.Tools.isDefine(g.transform.top)&&m.Tools.isDefine(g.transform.width)&&m.Tools.isDefine(g.transform.height)){const f=s.skeleton.getCellPositionByOffset(g.transform.left,g.transform.top,h,l,{x:0,y:0}),w=s.skeleton.getCellPositionByOffset(g.transform.left+g.transform.width,g.transform.top+g.transform.height,h,l,{x:0,y:0});f.column<a.startColumn&&(a.startColumn=f.column),f.row<a.startRow&&(a.startRow=f.row),a.endRow<w.row&&(a.endRow=w.row),a.endColumn<w.column&&(a.endColumn=w.column)}}),r(a)):r(i)}}))}};ve=hn([he(0,m.Inject(N.SheetPrintInterceptorService)),he(1,m.Inject(te.DrawingRenderService)),he(2,E.IDrawingManagerService),he(3,U.IRenderManagerService)],ve);var mn=Object.defineProperty,pn=Object.getOwnPropertyDescriptor,fn=(i,n,r,e)=>{for(var t=e>1?void 0:e?pn(n,r):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(n,r,t):s(t))||t);return e&&t&&mn(n,r,t),t},q=(i,n)=>(r,e)=>n(r,e,i);const wn=[D.InsertRowCommand.id,D.InsertColCommand.id,D.RemoveRowCommand.id,D.RemoveColCommand.id,D.DeleteRangeMoveLeftCommand.id,D.DeleteRangeMoveUpCommand.id,D.InsertRangeMoveDownCommand.id,D.InsertRangeMoveRightCommand.id,D.DeltaRowHeightCommand.id,D.SetRowHeightCommand.id,D.DeltaColumnWidthCommand.id,D.SetColWidthCommand.id,D.SetRowHiddenCommand.id,D.SetSpecificRowsVisibleCommand.id,D.SetSpecificColsVisibleCommand.id,D.SetColHiddenCommand.id,D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id],Sn=[D.SetRowVisibleMutation.id,D.SetRowHiddenMutation.id,D.SetColVisibleMutation.id,D.SetColHiddenMutation.id,D.SetWorksheetRowHeightMutation.id,D.SetWorksheetColWidthMutation.id];let be=class extends m.Disposable{constructor(i,n,r,e,t,o,s,c,d){super(),this._context=i,this._renderManagerService=n,this._commandService=r,this._selectionRenderService=e,this._skeletonManagerService=t,this._sheetInterceptorService=o,this._sheetDrawingService=s,this._drawingManagerService=c,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!wn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const n=i.id;if(n===D.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id].includes(n))return this._moveRangeInterceptor(i.params);if(n===D.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(n===D.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(n===D.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(n===D.DeleteRangeMoveLeftCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,0)}else if(n===D.DeleteRangeMoveUpCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,1)}else if(n===D.InsertRangeMoveDownCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,2)}else if(n===D.InsertRangeMoveRightCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,3)}else if(n===D.SetRowHiddenCommand.id||n===D.SetSpecificRowsVisibleCommand.id){const r=i.params,{unitId:e,subUnitId:t,ranges:o}=r;return this._getDrawingUndoForRowVisible(e,t,o)}else if(n===D.SetSpecificColsVisibleCommand.id||n===D.SetColHiddenCommand.id){const r=i.params,{unitId:e,subUnitId:t,ranges:o}=r;return this._getDrawingUndoForColVisible(e,t,o)}else if(n===D.DeltaRowHeightCommand.id||n===D.SetRowHeightCommand.id||n===D.DeltaColumnWidthCommand.id||n===D.SetColWidthCommand.id){const r=i.params,{unitId:e,subUnitId:t,ranges:o}=r,s=n===D.DeltaRowHeightCommand.id||n===D.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(e,t,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,n){const r=D.getSheetCommandTarget(this._univerInstanceService);if(r==null)return{redos:[],undos:[]};const e=r.unitId,t=r.subUnitId,o=[],s=[],c=this._sheetDrawingService.getDrawingData(e,t),d=[],h=[];if(Object.keys(c).forEach(l=>{const a=c[l],{updateDrawings:u,deleteDrawings:g}=this._getUpdateOrDeleteDrawings(i,n,a);d.push(...u),h.push(...g)}),d.length===0&&h.length===0)return{redos:[],undos:[]};if(d.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(d),{undo:a,redo:u,objects:g}=l;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:u,objects:g,type:p.DrawingApplyType.UPDATE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:a,objects:g,type:p.DrawingApplyType.UPDATE}})}if(h.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(h),a=l.undo,u=l.redo,g=l.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:u,objects:g,type:p.DrawingApplyType.REMOVE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:a,objects:g,type:p.DrawingApplyType.INSERT}})}return o.push({id:x.id,params:[e]}),s.push({id:x.id,params:[e]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,n,r){const e=[],t=[],{sheetTransform:o,anchorType:s=p.SheetDrawingAnchorType.Position,transform:c,unitId:d,subUnitId:h,drawingId:l}=r,{from:a,to:u}=o,{row:g,column:f}=a,{row:w,column:S}=u;if(o==null||c==null)return{updateDrawings:e,deleteDrawings:t};const{startRow:C,endRow:y,startColumn:I,endColumn:T}=i;let _=null,M=null;if(n===0&&g>=C&&w<=y)if(f>=I&&S<=T)t.push({unitId:d,subUnitId:h,drawingId:l});else{const v=this._shrinkCol(o,c,I,T,s);_=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(n===1&&f>=I&&S<=T)if(g>=C&&w<=y)t.push({unitId:d,subUnitId:h,drawingId:l});else{const v=this._shrinkRow(o,c,C,y,s);_=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(n===2){const v=this._expandRow(o,c,C,y,s);_=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(n===3){const v=this._expandCol(o,c,I,T,s);_=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}if(_!=null&&M!=null){const v=V(_,this._selectionRenderService,this._skeletonManagerService);e.push({...r,sheetTransform:_,transform:v})}return{updateDrawings:e,deleteDrawings:t}}_remainDrawingSize(i,n,r){const e=$({...i},this._selectionRenderService);e!=null&&n.push({...r,sheetTransform:e})}_getDrawingUndoForColVisible(i,n,r){const e=this._drawingManagerService.getDrawingData(i,n),t=[],o=[];if(Object.keys(e).forEach(l=>{const a=e[l],{sheetTransform:u,transform:g,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,a);else{const{from:w,to:S}=u,{row:C,column:y}=w,{row:I,column:T}=S;for(let _=0;_<r.length;_++){const M=r[_],{startRow:v,endRow:P,startColumn:b,endColumn:j}=M;if(T<b)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,W=null;if(y>=b&&y<=j){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:j,startRow:w.row,endRow:S.row});if(B==null)return;W={...g,left:B.startX}}if(W!=null&&(R=$(W,this._selectionRenderService),R!=null&&W!=null)){t.push({...a,sheetTransform:R,transform:W});break}this._remainDrawingSize(g,t,a);continue}if(y>=b&&T<=j)continue;let A=null,O=null;if(y>=b&&y<=j){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:j,startRow:w.row,endRow:S.row});if(R==null)return;O={...g,left:(R==null?void 0:R.startX)||0,width:((g==null?void 0:g.width)||0)-R.endX+R.startX}}else if(T>=b&&T<=j){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:T,startRow:w.row,endRow:S.row});if(R==null)return;O={...g,left:R.startX-((g==null?void 0:g.width)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:j,startRow:w.row,endRow:S.row});if(R==null)return;if(O={...g,width:((g==null?void 0:g.width)||0)-R.endX+R.startX},A=$(O,this._selectionRenderService),A!=null&&O!=null){o.push({...a,sheetTransform:A,transform:O});break}}if(O!=null&&(A=$(O,this._selectionRenderService)),O!=null&&A!=null){t.push({...a,sheetTransform:A,transform:O});break}else this._remainDrawingSize(g,t,a)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:c}=this._createUndoAndRedoMutation(i,n,t),d=[],h=[];if(o.length>0){const{redos:l,undos:a}=this._createUndoAndRedoMutation(i,n,o);d.push(...l),h.push(...a)}return{redos:s,undos:c,preRedos:d,preUndos:h}}_createUndoAndRedoMutation(i,n,r){const e=this._sheetDrawingService.getBatchUpdateOp(r),{undo:t,redo:o,objects:s}=e,c=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:o,objects:s,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[i]}],d=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:n,op:t,objects:s,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[i]}];return{redos:c,undos:d}}_getDrawingUndoForRowVisible(i,n,r){const e=this._drawingManagerService.getDrawingData(i,n),t=[],o=[];if(Object.keys(e).forEach(l=>{const a=e[l],{sheetTransform:u,transform:g,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(g,t,a);else{const{from:w,to:S}=u,{row:C,column:y}=w,{row:I,column:T}=S;for(let _=0;_<r.length;_++){const M=r[_],{startRow:v,endRow:P,startColumn:b,endColumn:j}=M;if(I<v)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,W=null;if(C>=v&&C<=P){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:C,endRow:P});if(B==null)return;W={...g,top:B.startY}}if(W!=null&&(R=$(W,this._selectionRenderService),R!=null&&W!=null)){t.push({...a,sheetTransform:R,transform:W});break}this._remainDrawingSize(g,t,a);continue}if(C>=v&&I<=P)continue;let A=null,O=null;if(C>=v&&C<=P){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:C,endRow:P});if(R==null)return;O={...g,top:(R==null?void 0:R.startY)||0,height:((g==null?void 0:g.height)||0)-R.endY+R.startY}}else if(I>=v&&I<=P){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:I});if(R==null)return;O={...g,top:R.startY-((g==null?void 0:g.height)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:P});if(R==null)return;if(O={...g,height:((g==null?void 0:g.height)||0)-R.endY+R.startY},A=$(O,this._selectionRenderService),A!=null&&O!=null){o.push({...a,sheetTransform:A,transform:O});break}}if(O!=null&&(A=$(O,this._selectionRenderService)),O!=null&&A!=null){t.push({...a,sheetTransform:A,transform:O});break}else this._remainDrawingSize(g,t,a)}}}),t.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:c}=this._createUndoAndRedoMutation(i,n,t),d=[],h=[];if(o.length>0){const{redos:l,undos:a}=this._createUndoAndRedoMutation(i,n,o);d.push(...l),h.push(...a)}return{redos:s,undos:c,preRedos:d,preUndos:h}}_getDrawingUndoForRowAndColSize(i,n,r,e){const t=this._drawingManagerService.getDrawingData(i,n),o=[];return Object.keys(t).forEach(s=>{const c=t[s],{sheetTransform:d,transform:h,anchorType:l=p.SheetDrawingAnchorType.Position}=c;if(l===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,o,c);else{const{from:a,to:u}=d,{row:g,column:f}=a,{row:w,column:S}=u;for(let C=0;C<r.length;C++){const y=r[C],{startRow:I,endRow:T,startColumn:_,endColumn:M}=y;if(w<I||S<_)continue;if(l===p.SheetDrawingAnchorType.Position&&(g<=I&&w>=T||f<=_&&S>=M)){this._remainDrawingSize(h,o,c);continue}const v=V({...d},this._selectionRenderService,this._skeletonManagerService);if(v!=null){o.push({...c,transform:v});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,n,o)}_getUnitIdAndSubUnitId(i,n){let r,e;if(n==="insert")r=i.unitId,e=i.subUnitId;else{const t=D.getSheetCommandTarget(this._univerInstanceService);if(t==null)return;r=t.unitId,e=t.subUnitId}return{unitId:r,subUnitId:e}}_moveRangeInterceptor(i){var I,T;const{toRange:n,fromRange:r}=i,e=D.getSheetCommandTarget(this._univerInstanceService);if(!e)return{redos:[],undos:[]};const{unitId:t,subUnitId:o}=e,s=(T=(I=this._renderManagerService.getRenderById(t))==null?void 0:I.with(N.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const c=N.attachRangeWithCoord(s,r);if(!c)return{redos:[],undos:[]};const{startX:d,endX:h,startY:l,endY:a}=c,u=this._sheetDrawingService.getDrawingData(t,o),g=[];Object.keys(u).forEach(_=>{const M=u[_];if(M.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:v}=M;if(!v)return;const{left:P=0,top:b=0,width:j=0,height:A=0}=v,{drawingStartX:O,drawingEndX:R,drawingStartY:W,drawingEndY:B}={drawingStartX:P,drawingEndX:P+j,drawingStartY:b,drawingEndY:b+A};d<=O&&R<=h&&l<=W&&B<=a&&g.push(M)});const f=[],w=[],S=n.startRow-r.startRow,C=n.startColumn-r.startColumn,y=g.map(_=>{const M=_.sheetTransform,v={to:{...M.to,row:M.to.row+S,column:M.to.column+C},from:{...M.from,row:M.from.row+S,column:M.from.column+C}},P=V(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:t,subUnitId:o,drawingId:_.drawingId,transform:P,sheetTransform:v}});if(y.length){const _=this._sheetDrawingService.getBatchUpdateOp(y),{undo:M,redo:v,objects:P}=_;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:v,objects:P,type:p.DrawingApplyType.UPDATE}}),w.push({id:p.SetDrawingApplyMutation.id,params:{unitId:t,subUnitId:o,op:M,objects:P,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:w}}_moveRowInterceptor(i,n){const r=this._getUnitIdAndSubUnitId(i,n);if(r==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=r,{range:o}=i,s=o.startRow,c=o.endRow,d=[],h=[],l=this._sheetDrawingService.getDrawingData(e,t),a=[],u=[];if(Object.keys(l).forEach(g=>{const f=l[g],{sheetTransform:w,transform:S,anchorType:C=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let y,I;if(n==="insert"){const _=this._expandRow(w,S,s,c,C);y=_==null?void 0:_.newSheetTransform,I=_==null?void 0:_.newTransform}else{const{from:_,to:M}=w,{row:v}=_,{row:P}=M;if(C===p.SheetDrawingAnchorType.Both&&v>=s&&P<=c)u.push({unitId:e,subUnitId:t,drawingId:g});else{const b=this._shrinkRow(w,S,s,c,C);y=b==null?void 0:b.newSheetTransform,I=b==null?void 0:b.newTransform}}if(!y||!I)return;const T={unitId:e,subUnitId:t,drawingId:g,transform:I,sheetTransform:y};a.push(T)}),a.length===0&&u.length===0)return{redos:[],undos:[]};if(a.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(a),{undo:f,redo:w,objects:S}=g;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:S,type:p.DrawingApplyType.UPDATE}})}if(u.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(u),f=g.undo,w=g.redo,S=g.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:S,type:p.DrawingApplyType.INSERT}})}return d.push({id:x.id,params:[e]}),h.push({id:x.id,params:[e]}),{redos:d,undos:h}}_moveColInterceptor(i,n){const r=this._getUnitIdAndSubUnitId(i,n);if(r==null)return{redos:[],undos:[]};const{unitId:e,subUnitId:t}=r,{range:o}=i,s=o.startColumn,c=o.endColumn,d=[],h=[],l=this._sheetDrawingService.getDrawingData(e,t),a=[],u=[];if(Object.keys(l).forEach(g=>{const f=l[g],{sheetTransform:w,transform:S,anchorType:C=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let y,I;if(n==="insert"){const _=this._expandCol(w,S,s,c,C);y=_==null?void 0:_.newSheetTransform,I=_==null?void 0:_.newTransform}else{const{from:_,to:M}=w,{column:v}=_,{column:P}=M;if(C===p.SheetDrawingAnchorType.Both&&v>=s&&P<=c)u.push({unitId:e,subUnitId:t,drawingId:g});else{const b=this._shrinkCol(w,S,s,c,C);y=b==null?void 0:b.newSheetTransform,I=b==null?void 0:b.newTransform}}if(!y||!I)return;const T={unitId:e,subUnitId:t,drawingId:g,transform:I,sheetTransform:y};a.push(T)}),a.length===0&&u.length===0)return{redos:[],undos:[]};if(a.length>0){const g=this._sheetDrawingService.getBatchUpdateOp(a),{undo:f,redo:w,objects:S}=g;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:S,type:p.DrawingApplyType.UPDATE}})}if(u.length>0){const g=this._sheetDrawingService.getBatchRemoveOp(u),f=g.undo,w=g.redo,S=g.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:t,op:f,objects:S,type:p.DrawingApplyType.INSERT}})}return d.push({id:x.id,params:[e]}),h.push({id:x.id,params:[e]}),{redos:d,undos:h}}_expandCol(i,n,r,e,t=p.SheetDrawingAnchorType.Position){const o=e-r+1,{from:s,to:c}=i,{column:d}=s,{column:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};let l=null,a=null;if(d>=r){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:r,endColumn:e,startRow:s.row,endRow:c.row});if(u==null)return;a={...n,left:(n.left||0)+u.endX-u.startX},l=$(a,this._selectionRenderService)}else if(h>=e)if(t===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,column:h+o}},a=V(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_shrinkCol(i,n,r,e,t=p.SheetDrawingAnchorType.Position){const o=e-r+1,{from:s,to:c}=i,{column:d}=s,{column:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};let l=null,a=null;if(d>e)l={from:{...s,column:d-o},to:{...c,column:h-o}},a=V(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=r&&h<=e)return null;if(d<r&&h>e)if(t===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,column:h-o}},a=V(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};else if(d>=r&&d<=e){if(d===r)a={...n,left:(n.left||0)-i.from.columnOffset};else{const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:r,endColumn:d-1,startRow:s.row,endRow:c.row});if(u==null)return;a={...n,left:(n.left||0)-u.endX+u.startX-i.from.columnOffset}}l=$(a,this._selectionRenderService)}else if(h>=r&&h<=e&&t===p.SheetDrawingAnchorType.Both){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:r-1,endColumn:r-1,startRow:s.row,endRow:c.row});if(u==null)return;l={from:{...s},to:{...c,column:r-1,columnOffset:u.endX-u.startX}},a=V(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_expandRow(i,n,r,e,t=p.SheetDrawingAnchorType.Position){const o=e-r+1,{from:s,to:c}=i,{row:d}=s,{row:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};let l=null,a=null;if(d>=r){const u=this._skeletonManagerService.attachRangeWithCoord({startRow:r,endRow:e,startColumn:s.column,endColumn:c.column});if(u==null)return;a={...n,top:(n.top||0)+u.endY-u.startY},l=$(a,this._selectionRenderService)}else if(h>=e)if(t===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,row:h+o}},a=V(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_shrinkRow(i,n,r,e,t=p.SheetDrawingAnchorType.Position){const o=e-r+1,{from:s,to:c}=i,{row:d}=s,{row:h}=c;if(t===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};let l=null,a=null;if(d>e)l={from:{...s,row:d-o},to:{...c,row:h-o}},a=V(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=r&&h<=e)return null;if(d<r&&h>e)if(t===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,row:h-o}},a=V(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...n},this._selectionRenderService),newTransform:n};else if(d>=r&&d<=e){if(d===r)a={...n,top:(n.top||0)-i.from.rowOffset};else{const u=this._skeletonManagerService.attachRangeWithCoord({startRow:r,endRow:d-1,startColumn:s.column,endColumn:c.column});if(u==null)return;a={...n,top:(n.top||0)-u.endY+u.startY-i.from.rowOffset}}l=$(a,this._selectionRenderService)}else if(h>=r&&h<=e&&t===p.SheetDrawingAnchorType.Both){const u=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:r-1,endRow:r-1});if(u==null)return;l={from:{...s},to:{...c,row:r-1,rowOffset:u.endY-u.startY}},a=V(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===D.SetWorksheetActiveOperation.id&&setTimeout(()=>{const n=i.params,{unitId:r,subUnitId:e}=n,t=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(t).forEach(c=>{const d=t[c];d!=null&&Object.keys(d).forEach(h=>{const l=d[h].data;l!=null&&Object.keys(l).forEach(a=>{if(c===r&&h===e){const u=l[a];u.transform=V(u.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(l[a])}else s.push(l[a])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{Sn.includes(i.id)&&requestIdleCallback(()=>{const n=i.params,{unitId:r,subUnitId:e,ranges:t}=n;this._refreshDrawingTransform(r,e,t)})}))}_refreshDrawingTransform(i,n,r){const e=this._drawingManagerService.getDrawingData(i,n),t=[];Object.keys(e).forEach(o=>{const s=e[o],{sheetTransform:c,transform:d,anchorType:h=p.SheetDrawingAnchorType.Position}=s;if(h===p.SheetDrawingAnchorType.None)return!0;const{from:l,to:a}=c,{row:u,column:g}=l,{row:f,column:w}=a;for(let S=0;S<r.length;S++){const C=r[S],{startRow:y,endRow:I,startColumn:T,endColumn:_}=C;if(m.Rectangle.intersects({startRow:y,endRow:I,startColumn:T,endColumn:_},{startRow:u,endRow:f,startColumn:g,endColumn:w})||u>I||g>_){const M=h===p.SheetDrawingAnchorType.Position,v=V(c,this._selectionRenderService,this._skeletonManagerService);t.push({...s,transform:{...v,width:M?d==null?void 0:d.width:v==null?void 0:v.width,height:M?d==null?void 0:d.height:v==null?void 0:v.height}});break}}}),t.length!==0&&(this._drawingManagerService.refreshTransform(t),this._commandService.syncExecuteCommand(x.id,[i]))}};be=fn([q(1,U.IRenderManagerService),q(2,m.ICommandService),q(3,N.ISheetSelectionRenderService),q(4,m.Inject(N.SheetSkeletonManagerService)),q(5,m.Inject(D.SheetInterceptorService)),q(6,p.ISheetDrawingService),q(7,E.IDrawingManagerService),q(8,m.IUniverInstanceService)],be);var vn=Object.defineProperty,_n=Object.getOwnPropertyDescriptor,Dn=(i,n,r,e)=>{for(var t=e>1?void 0:e?_n(n,r):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(n,r,t):s(t))||t);return e&&t&&vn(n,r,t),t},ee=(i,n)=>(r,e)=>n(r,e,i);function In(i,n,r,e){const{scaleX:t,scaleY:o}=n.getAncestorScale(),s=n.getViewport(U.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!s)return{...i,absolute:c};const{left:d,right:h,top:l,bottom:a}=i,u=e.getFreeze(),{startColumn:g,startRow:f,xSplit:w,ySplit:S}=u,C=r.getNoMergeCellPositionByIndexWithNoHeader(f-S,g-w),y=r.getNoMergeCellPositionByIndexWithNoHeader(f,g),{rowHeaderWidth:I,columnHeaderHeight:T}=r,_=y.startX-C.startX,M=y.startY-C.startY,{top:v,left:P,viewportScrollX:b,viewportScrollY:j}=s;let A,O;d<P?(c.left=!0,A=(_+I+(d-P))*t,O=Math.max(Math.min((_+I+(h-P))*t,(_+I)*t),(h-b)*t)):(c.left=!1,A=Math.max((d-b)*t,(_+I)*t),O=Math.max((h-b)*t,(_+I)*t));let R,W;return l<v?(c.top=!0,R=(M+T+(l-v))*o,W=Math.max(Math.min((M+T+(h-v))*o,(M+T)*o),(a-j)*o)):(c.top=!1,R=Math.max((l-j)*o,(M+T)*o),W=Math.max((a-j)*o,(M+T)*o)),{left:A,right:O,top:R,bottom:W,absolute:c}}const Me=(i,n,r,e)=>{const{scene:t}=n,{left:o,top:s,width:c,height:d,angle:h}=i,l={left:o,right:o+c,top:s,bottom:s+d},a=In(l,t,r,e),{scaleX:u,scaleY:g}=t.getAncestorScale();return{startX:a.left,endX:a.right,startY:a.top,endY:a.bottom,rotate:h,width:c*u,height:d*g,absolute:a.absolute}};exports.SheetCanvasFloatDomManagerService=class extends m.Disposable{constructor(r,e,t,o,s,c,d){super();F(this,"_domLayerMap",new Map);F(this,"_domLayerInfoMap",new Map);F(this,"_transformChange$",new L.Subject);F(this,"transformChange$",this._transformChange$.asObservable());F(this,"_add$",new L.Subject);F(this,"add$",this._add$.asObservable());F(this,"_remove$",new L.Subject);F(this,"remove$",this._remove$.asObservable());F(this,"_hooks",[]);this._renderManagerService=r,this._univerInstanceService=e,this._commandService=t,this._drawingManagerService=o,this._canvasFloatDomService=s,this._sheetDrawingService=c,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(L.filter(r=>r===m.LifecycleStages.Rendered),L.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(r,e){let t=this._domLayerMap.get(r);t||(t=new Map,this._domLayerMap.set(r,t));let o=t.get(e);return o||(o=new Map,t.set(e,o)),o}getFloatDomInfo(r){return this._domLayerInfoMap.get(r)}_getSceneAndTransformerByDrawingSearch(r){if(r==null)return;const e=this._renderManagerService.getRenderById(r),t=e==null?void 0:e.scene;if(e==null||t==null)return null;const o=t.getTransformerByCreate(),s=e.engine.getCanvasElement();return{scene:t,transformer:o,renderObject:e,canvas:s}}_getFloatDomProps(r){let e;return this._hooks.forEach(t=>{e=t.onGetFloatDomProps(r)}),e}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(r=>{r.forEach(e=>{var Le,xe,Be;const{unitId:t,subUnitId:o,drawingId:s}=e,c=D.getSheetCommandTarget(this._univerInstanceService,{unitId:t,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(e),h=this._univerInstanceService.getUnit(t);if(!h)return;const l=h.getActiveSheet().getSheetId();if(!d||!c)return;const a=(Le=this._renderManagerService.getRenderById(t))==null?void 0:Le.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!a)return;const{transform:u,drawingType:g,data:f}=d;if(g!==E.DrawingTypeEnum.DRAWING_DOM&&g!==E.DrawingTypeEnum.DRAWING_CHART)return;const w=this._getSceneAndTransformerByDrawingSearch(t);if(w==null)return;const{scene:S,canvas:C}=w;if(u==null)return!0;if(l!==o)return;const{left:y,top:I,width:T,height:_,angle:M,flipX:v,flipY:P,skewX:b,skewY:j}=u,A=E.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:s}),O=S.getObject(A);if(O!=null){O.transformByState({left:y,top:I,width:T,height:_,angle:M,flipX:v,flipY:P,skewX:b,skewY:j});return}const R={left:y,top:I,width:T,height:_,zIndex:this._drawingManagerService.getDrawingOrder(t,o).length-1},W=g===E.DrawingTypeEnum.DRAWING_CHART;W&&(R.fill="white",R.rotateEnabled=!1,f&&f.border&&(R.stroke=f.border),R.paintFirst="stroke",R.strokeWidth=1,R.borderEnabled=!1,R.radius=8);const B=new U.Rect(A,R);W&&B.setObjectType(U.ObjectType.CHART),S.addObject(B,U.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(B);const z=this._ensureMap(t,o),Ie=new m.DisposableCollection,qe=Me(B,w.renderObject,a.skeleton,c.worksheet),Ce=new L.BehaviorSubject(qe),Je={dispose:Ie,rect:B,position$:Ce,unitId:t,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Ce,id:s,componentKey:d.componentKey,onPointerDown:K=>{const ne=this._createNewEvent(K);C.dispatchEvent(new PointerEvent(ne.type,ne))},onPointerMove:K=>{const ne=this._createNewEvent(K);C.dispatchEvent(ne)},onPointerUp:K=>{const ne=this._createNewEvent(K);C.dispatchEvent(ne)},onWheel:K=>{C.dispatchEvent(new WheelEvent(K.type,K))},props:(Be=(xe=z.get(s))==null?void 0:xe.props)!=null?Be:this._getFloatDomProps(s),data:f,unitId:t});const We=B.onTransformChange$.subscribeEvent(()=>{const K=Me(B,w.renderObject,a.skeleton,c.worksheet);Ce.next(K)});Ie.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),We&&Ie.add(We),this._domLayerInfoMap.set(s,Je),z.set(s,{...z.get(s)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.forEach(e=>{const{unitId:t,subUnitId:o,drawingId:s}=e,c=E.getDrawingShapeKeyByDrawingSearch({unitId:t,subUnitId:o,drawingId:s}),d=this._getSceneAndTransformerByDrawingSearch(t);if(d==null)return;const{transformer:h,scene:l}=d,a=l.getObject(c);a!=null&&a.oKey&&h.clearControlByIds([a==null?void 0:a.oKey])})}))}_createNewEvent(r){const e=U.copyPointEvent(r);return new PointerEvent(r.type,e)}_scrollUpdateListener(){const r=(e,t)=>{var l;const o=this._getSceneAndTransformerByDrawingSearch(e),s=this._ensureMap(e,t),c=Array.from(s.keys()),d=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:t}),h=(l=this._renderManagerService.getRenderById(e))==null?void 0:l.with(N.SheetSkeletonManagerService).getWorksheetSkeleton(t);!o||!d||!h||c.forEach(a=>{const u=this._domLayerInfoMap.get(a);if(u){const g=Me(u.rect,o.renderObject,h.skeleton,d.worksheet);u.position$.next(g)}})};this.disposeWithMe(this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET).pipe(L.filter(e=>!!e),L.map(e=>{const t=this._renderManagerService.getRenderById(e.getUnitId());return t?{render:t,unitId:e.getUnitId(),subUnitId:e.getActiveSheet().getSheetId()}:null}),L.filter(e=>!!e),L.switchMap(e=>m.fromEventSubject(e.render.scene.getViewport(N.VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(L.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:t})=>{r(e,t)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var t,o;if(e.id===N.SetZoomRatioOperation.id){const s=e.params,{unitId:c}=s;Array.from((o=(t=this._domLayerMap.get(c))==null?void 0:t.keys())!=null?o:[]).forEach(h=>{r(c,h)})}else if(e.id===D.SetFrozenMutation.id){const{unitId:s,subUnitId:c}=e.params;r(s,c)}}))}_getPosition(r,e){var g;const{startX:t,endX:o,startY:s,endY:c}=r,d=(g=this._renderManagerService.getRenderById(e))==null?void 0:g.with(N.ISheetSelectionRenderService);if(d==null)return;const h=d.getSelectionCellByPosition(t,s);if(h==null)return;const l={column:h.actualColumn,columnOffset:t-h.startX,row:h.actualRow,rowOffset:s-h.startY},a=d.getSelectionCellByPosition(o,c);if(a==null)return;const u={column:a.actualColumn,columnOffset:o-a.startX,row:a.actualRow,rowOffset:c-a.startY};return{from:l,to:u}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(r=>{r.forEach(e=>{const t=this._drawingManagerService.getDrawingByParam(e);if(!t||t.drawingType!==E.DrawingTypeEnum.DRAWING_DOM&&t.drawingType!==E.DrawingTypeEnum.DRAWING_CHART)return;const o={...t.transform};this._transformChange$.next({id:e.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.forEach(e=>{this._removeDom(e.drawingId)})}))}updateFloatDomProps(r,e,t,o){const s=this._domLayerInfoMap.get(t),c=this._getSceneAndTransformerByDrawingSearch(r);if(s&&c){const{scene:d}=c,h=E.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:e,drawingId:t}),l=d.getObject(h);l&&l instanceof U.Rect&&l.setProps(o)}}addFloatDomToPosition(r,e){const t=D.getSheetCommandTarget(this._univerInstanceService,{unitId:r.unitId,subUnitId:r.subUnitId});if(!t)throw new Error("cannot find current target!");const{unitId:o,subUnitId:s}=t,{initPosition:c,componentKey:d,data:h,allowTransform:l=!0}=r,a=e!=null?e:m.generateRandomId(),u=this._getPosition(c,o);if(u==null)return;this._ensureMap(o,s).set(a,r);const f={unitId:o,subUnitId:s,drawingId:a,drawingType:r.type||E.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:u,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},data:h,allowTransform:l};return this._commandService.executeCommand(se.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:s,id:a}),{id:a,dispose:()=>{this._removeDom(a,!0)}}}_removeDom(r,e=!1){const t=this._domLayerInfoMap.get(r);if(!t)return;const{unitId:o,subUnitId:s}=t;this._domLayerInfoMap.delete(r),t.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(t.rect),e){this._ensureMap(o,s).delete(r);const h=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:r});if(!h)return;const l=this._sheetDrawingService.getBatchRemoveOp([h]),{redo:a,objects:u}=l;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:a,objects:u,type:p.DrawingApplyType.REMOVE})}}addHook(r){return this._hooks.push(r),{dispose:()=>{const e=this._hooks.findIndex(t=>t===r);this._hooks.splice(e,1)}}}};exports.SheetCanvasFloatDomManagerService=Dn([ee(0,m.Inject(U.IRenderManagerService)),ee(1,m.IUniverInstanceService),ee(2,m.Inject(m.ICommandService)),ee(3,E.IDrawingManagerService),ee(4,m.Inject(G.CanvasFloatDomService)),ee(5,p.ISheetDrawingService),ee(6,m.Inject(m.LifecycleService))],exports.SheetCanvasFloatDomManagerService);var Ke=Object.defineProperty,Cn=Object.getOwnPropertyDescriptor,yn=(i,n,r)=>n in i?Ke(i,n,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[n]=r,Mn=(i,n,r,e)=>{for(var t=e>1?void 0:e?Cn(n,r):n,o=i.length-1,s;o>=0;o--)(s=i[o])&&(t=(e?s(n,r,t):s(t))||t);return e&&t&&Ke(n,r,t),t},Re=(i,n)=>(r,e)=>n(r,e,i),ze=(i,n,r)=>yn(i,typeof n!="symbol"?n+"":n,r);const Rn="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends m.Plugin{constructor(n=tt,r,e,t){super(),this._config=n,this._injector=r,this._renderManagerService=e,this._configService=t;const{menu:o,...s}=this._config;o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(et,s)}onStarting(){m.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[fe],[me],[ve],[Se],[we]]),m.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){m.touchDependencies(this._injector,[[we]])}onRendered(){this._registerRenderModules(),m.touchDependencies(this._injector,[[Se],[ve],[fe]])}onSteady(){this._injector.get(me)}_registerRenderModules(){[[pe],[be],[Te]].forEach(n=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(m.UniverInstanceType.UNIVER_SHEET,n))})}};ze(exports.UniverSheetsDrawingUIPlugin,"type",m.UniverInstanceType.UNIVER_SHEET);ze(exports.UniverSheetsDrawingUIPlugin,"pluginName",Rn);exports.UniverSheetsDrawingUIPlugin=Mn([m.DependentOn(E.UniverDrawingPlugin,te.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),Re(1,m.Inject(m.Injector)),Re(2,U.IRenderManagerService),Re(3,m.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=x;exports.DeleteDrawingsCommand=Pe;exports.EditSheetDrawingOperation=Oe;exports.GroupSheetDrawingCommand=Ae;exports.IMAGE_MENU_ID=je;exports.InsertFloatImageCommand=De;exports.InsertSheetDrawingCommand=se;exports.MoveDrawingsCommand=re;exports.RemoveSheetDrawingCommand=oe;exports.SetDrawingArrangeCommand=Ue;exports.SetSheetDrawingCommand=ae;exports.SidebarSheetDrawingOperation=Ee;exports.UngroupSheetDrawingCommand=Ne;
|
|
9
|
+
*/var tt=H,nt=Symbol.for("react.element"),rt=Symbol.for("react.fragment"),it=Object.prototype.hasOwnProperty,ot=tt.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,st={key:!0,ref:!0,__self:!0,__source:!0};function ke(i,t,r){var n,e={},o=null,s=null;r!==void 0&&(o=""+r),t.key!==void 0&&(o=""+t.key),t.ref!==void 0&&(s=t.ref);for(n in t)it.call(t,n)&&!st.hasOwnProperty(n)&&(e[n]=t[n]);if(i&&i.defaultProps)for(n in t=i.defaultProps,t)e[n]===void 0&&(e[n]=t[n]);return{$$typeof:nt,type:i,key:o,ref:s,props:e,_owner:ot.current}}ve.Fragment=rt;ve.jsx=ke;ve.jsxs=ke;$e.exports=ve;var G=$e.exports;const at="univer-upload-loading",ct="univer-upload-loading-body",dt="univer-upload-loading-body-animation",lt="univer-UniverCircleAnimation",ut="univer-upload-loading-body-text",ce={uploadLoading:at,uploadLoadingBody:ct,uploadLoadingBodyAnimation:dt,univerCircleAnimation:lt,uploadLoadingBodyText:ut},gt=()=>{const i=m.useDependency(E.IImageIoService),t=m.useDependency(m.LocaleService),[r,n]=H.useState(0);return H.useEffect(()=>{const e=i.change$.subscribe(o=>{n(o)});return()=>{e.unsubscribe()}},[i]),G.jsx("div",{style:{display:r>0?"block":"none"},className:ce.uploadLoading,children:G.jsxs("div",{className:ce.uploadLoadingBody,children:[G.jsx("div",{className:ce.uploadLoadingBodyAnimation}),G.jsx("div",{className:ce.uploadLoadingBodyText,children:`${t.t("uploadLoading.loading")}: ${r}`})]})})};var ht=Object.defineProperty,mt=Object.getOwnPropertyDescriptor,pt=(i,t,r,n)=>{for(var e=n>1?void 0:n?mt(t,r):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(e=(n?s(t,r,e):s(e))||e);return n&&e&&ht(t,r,e),e},Q=(i,t)=>(r,n)=>t(r,n,i);let he=class extends m.RxDisposable{constructor(t,r,n,e,o,s,c){super();Y(this,"_initImagePopupMenu",new Set);this._injector=t,this._drawingManagerService=r,this._canvasPopManagerService=n,this._renderManagerService=e,this._univerInstanceService=o,this._contextService=s,this._uiPartsService=c,this._init()}_init(){this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET).pipe(L.takeUntil(this.dispose$)).subscribe(t=>this._create(t)),this._univerInstanceService.getTypeOfUnitDisposed$(m.UniverInstanceType.UNIVER_SHEET).pipe(L.takeUntil(this.dispose$)).subscribe(t=>this._dispose(t)),this._univerInstanceService.getAllUnitsForType(m.UniverInstanceType.UNIVER_SHEET).forEach(t=>this._create(t)),this._uiPartsService.registerComponent(k.BuiltInUIPart.CONTENT,()=>m.connectInjector(gt,this._injector))}_dispose(t){const r=t.getUnitId();this._renderManagerService.removeRender(r)}_create(t){if(!t)return;const r=t.getUnitId();this._renderManagerService.has(r)&&!this._initImagePopupMenu.has(r)&&(this._popupMenuListener(r),this._initImagePopupMenu.add(r))}_hasCropObject(t){const r=t.getAllObjectsByOrder();for(const n of r)if(n instanceof te.ImageCropperObject)return!0;return!1}_popupMenuListener(t){var o;const r=(o=this._renderManagerService.getRenderById(t))==null?void 0:o.scene;if(!r)return;const n=r.getTransformerByCreate();if(!n)return;let e;this.disposeWithMe(m.toDisposable(n.createControl$.subscribe(()=>{if(this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!0),this._hasCropObject(r))return;const s=n.getSelectedObjectMap();if(s.size>1){e==null||e.dispose();return}const c=s.values().next().value;if(!c)return;const d=c.oKey,h=this._drawingManagerService.getDrawingOKey(d);if(!h)return;const{unitId:l,subUnitId:a,drawingId:g,drawingType:u}=h,f=h.data;f&&f.disablePopup||(e==null||e.dispose(),e=this.disposeWithMe(this._canvasPopManagerService.attachPopupToObject(c,{componentKey:te.COMPONENT_IMAGE_POPUP_MENU,direction:"horizontal",offset:[2,0],extraProps:{menuItems:this._getImageMenuItems(l,a,g,u)}})),this._drawingManagerService.focusDrawing([{unitId:l,subUnitId:a,drawingId:g}]))}))),this.disposeWithMe(n.clearControl$.subscribe(()=>{e==null||e.dispose(),this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!1),this._drawingManagerService.focusDrawing(null)})),this.disposeWithMe(n.changing$.subscribe(()=>{e==null||e.dispose()}))}_getImageMenuItems(t,r,n,e){return[{label:"image-popup.edit",index:0,commandId:Ee.id,commandParams:{unitId:t,subUnitId:r,drawingId:n},disable:e===E.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.delete",index:1,commandId:ie.id,commandParams:{unitId:t,drawings:[{unitId:t,subUnitId:r,drawingId:n}]},disable:!1},{label:"image-popup.crop",index:2,commandId:te.OpenImageCropOperation.id,commandParams:{unitId:t,subUnitId:r,drawingId:n},disable:e===E.DrawingTypeEnum.DRAWING_DOM},{label:"image-popup.reset",index:3,commandId:te.ImageResetSizeOperation.id,commandParams:[{unitId:t,subUnitId:r,drawingId:n}],disable:e===E.DrawingTypeEnum.DRAWING_DOM}]}};he=pt([Q(0,m.Inject(m.Injector)),Q(1,E.IDrawingManagerService),Q(2,m.Inject(U.SheetCanvasPopManagerService)),Q(3,N.IRenderManagerService),Q(4,m.IUniverInstanceService),Q(5,m.IContextService),Q(6,m.Inject(k.IUIPartsService))],he);function V(i,t,r){const{from:n,to:e,flipY:o=!1,flipX:s=!1,angle:c=0,skewX:d=0,skewY:h=0}=i,{column:l,columnOffset:a,row:g,rowOffset:u}=n,{column:f,columnOffset:w,row:S,rowOffset:C}=e,y=r.getCurrentSkeleton(),I=U.attachRangeWithCoord(y,{startColumn:l,endColumn:l,startRow:g,endRow:g});if(I==null)return;const T=U.attachRangeWithCoord(y,{startColumn:f,endColumn:f,startRow:S,endRow:S});if(T==null)return;const{startX:_,startY:M}=I,{startX:v,startY:P}=T;let b=N.precisionTo(_+a,1),j=N.precisionTo(M+u,1),A=N.precisionTo(v+w-b,1),O=N.precisionTo(P+C-j,1);I.startX===T.endX&&(A=0),I.startY===T.endY&&(O=0);const R=y.rowHeaderWidth+y.columnTotalWidth,W=y.columnHeaderHeight+y.rowTotalHeight;return b+A>R&&(b=R-A),j+O>W&&(j=W-O),{flipY:o,flipX:s,angle:c,skewX:d,skewY:h,left:b,top:j,width:A,height:O}}function $(i,t){const{left:r=0,top:n=0,width:e=0,height:o=0,flipY:s=!1,flipX:c=!1,angle:d=0,skewX:h=0,skewY:l=0}=i,a=t.getSelectionCellByPosition(r,n);if(a==null)return;const g={column:a.actualColumn,columnOffset:N.precisionTo(r-a.startX,1),row:a.actualRow,rowOffset:N.precisionTo(n-a.startY,1)},u=t.getSelectionCellByPosition(r+e,n+o);if(u==null)return;const f={column:u.actualColumn,columnOffset:N.precisionTo(r+e-u.startX,1),row:u.actualRow,rowOffset:N.precisionTo(n+o-u.startY,1)};return{flipY:s,flipX:c,angle:d,skewX:h,skewY:l,from:g,to:f}}var ft=Object.defineProperty,wt=Object.getOwnPropertyDescriptor,St=(i,t,r,n)=>{for(var e=n>1?void 0:n?wt(t,r):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(e=(n?s(t,r,e):s(e))||e);return n&&e&&ft(t,r,e),e},de=(i,t)=>(r,n)=>t(r,n,i);let Re=class extends m.Disposable{constructor(i,t,r,n,e){super(),this._context=i,this._sheetDrawingService=t,this._drawingManagerService=r,this._sheetSelectionRenderService=n,this._sheetSkeletonManagerService=e,this._init()}_init(){this._drawingInitializeListener()}_drawingInitializeListener(){this._sheetDrawingService.initializeNotification(this._context.unitId);const i=this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId);for(const t in i){const r=i[t];for(const n in r.data){const e=r.data[n];e.transform=V(e.sheetTransform,this._sheetSelectionRenderService,this._sheetSkeletonManagerService)}}this._drawingManagerService.registerDrawingData(this._context.unitId,this._sheetDrawingService.getDrawingDataForUnit(this._context.unitId)),this._drawingManagerService.initializeNotification(this._context.unitId)}};Re=St([de(1,p.ISheetDrawingService),de(2,E.IDrawingManagerService),de(3,m.Inject(U.ISheetSelectionRenderService)),de(4,m.Inject(U.SheetSkeletonManagerService))],Re);var X=function(){return X=Object.assign||function(i){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var e in t)Object.prototype.hasOwnProperty.call(t,e)&&(i[e]=t[e])}return i},X.apply(this,arguments)},vt=function(i,t){var r={};for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&t.indexOf(n)<0&&(r[n]=i[n]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var e=0,n=Object.getOwnPropertySymbols(i);e<n.length;e++)t.indexOf(n[e])<0&&Object.prototype.propertyIsEnumerable.call(i,n[e])&&(r[n[e]]=i[n[e]]);return r},Ge=H.forwardRef(function(i,t){var r=i.icon,n=i.id,e=i.className,o=i.extend,s=vt(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(n," ").concat(e||"").trim(),d=H.useRef("_".concat(It()));return Ve(r,"".concat(n),{defIds:r.defIds,idSuffix:d.current},X({ref:t,className:c},s),o)});function Ve(i,t,r,n,e){return H.createElement(i.tag,X(X({key:t},_t(i,r,e)),n),(Dt(i,r).children||[]).map(function(o,s){return Ve(o,"".concat(t,"-").concat(i.tag,"-").concat(s),r,void 0,e)}))}function _t(i,t,r){var n=X({},i.attrs);r!=null&&r.colorChannel1&&n.fill==="colorChannel1"&&(n.fill=r.colorChannel1);var e=t.defIds;return!e||e.length===0||(i.tag==="use"&&n["xlink:href"]&&(n["xlink:href"]=n["xlink:href"]+t.idSuffix),Object.entries(n).forEach(function(o){var s=o[0],c=o[1];typeof c=="string"&&(n[s]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),n}function Dt(i,t){var r,n=t.defIds;return!n||n.length===0?i:i.tag==="defs"&&(!((r=i.children)===null||r===void 0)&&r.length)?X(X({},i),{children:i.children.map(function(e){return typeof e.attrs.id=="string"&&n&&n.indexOf(e.attrs.id)>-1?X(X({},e),{attrs:X(X({},e.attrs),{id:e.attrs.id+t.idSuffix})}):e})}):i}function It(){return Math.random().toString(36).substring(2,8)}Ge.displayName="UniverIcon";var Ct={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"}}]},Fe=H.forwardRef(function(i,t){return H.createElement(Ge,Object.assign({},i,{id:"add-image-single",ref:t,icon:Ct}))});Fe.displayName="AddImageSingle";const Oe={id:"sheet.command.delete-drawing",type:m.CommandType.COMMAND,handler:i=>{const t=i.get(m.ICommandService),n=i.get(p.ISheetDrawingService).getFocusDrawings();if(n.length===0)return!1;const e=n[0].unitId,o=n.map(s=>{const{unitId:c,subUnitId:d,drawingId:h,drawingType:l}=s;return{unitId:c,subUnitId:d,drawingId:h,drawingType:l}});return t.executeCommand(ie.id,{unitId:e,drawings:o})}};function yt(i){const t=[];return i.forEach(r=>{const{parent:n,children:e}=r,{unitId:o,subUnitId:s,drawingId:c}=n,d=N.getGroupState(0,0,e.map(a=>a.transform||{})),h=e.map(a=>{const g=a.transform||{left:0,top:0},{unitId:u,subUnitId:f,drawingId:w}=a;return{unitId:u,subUnitId:f,drawingId:w,transform:{...g,left:g.left-d.left,top:g.top-d.top},groupId:c}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:d};t.push({parent:l,children:h})}),t}function Mt(i){const t=[];return i.forEach(r=>{const{parent:n,children:e}=r,{unitId:o,subUnitId:s,drawingId:c,transform:d={width:0,height:0}}=n;if(d==null)return;const h=e.map(a=>{const{transform:g}=a,{unitId:u,subUnitId:f,drawingId:w}=a,S=N.transformObjectOutOfGroup(g||{},d,d.width||0,d.height||0);return{unitId:u,subUnitId:f,drawingId:w,transform:S,groupId:void 0}}),l={unitId:o,subUnitId:s,drawingId:c,drawingType:E.DrawingTypeEnum.DRAWING_GROUP,transform:{left:0,top:0}};t.push({parent:l,children:h})}),t}const Pe={id:"sheet.command.group-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const r=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),e=i.get(p.ISheetDrawingService);if(!t)return!1;const o=[];t.forEach(({parent:u,children:f})=>{o.push(u.unitId),f.forEach(w=>{o.push(w.unitId)})});const s=e.getGroupDrawingOp(t),{unitId:c,subUnitId:d,undo:h,redo:l,objects:a}=s;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.GROUP})?(n.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:c,subUnitId:d,objects:Mt(a),type:p.DrawingApplyType.UNGROUP}},{id:x.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.GROUP}},{id:x.id,params:o}]}),!0):!1}},oe={id:"sheet.command.insert-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{var y,I,T;const r=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),e=i.get(p.ISheetDrawingService),o=i.get(D.SheetInterceptorService);if(!t)return!1;const s=t.drawings,c=s.map(_=>_.unitId),d=e.getBatchAddOp(s),{unitId:h,subUnitId:l,undo:a,redo:g,objects:u}=d,f=o.onCommandExecute({id:oe.id,params:t}),w={id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:h,subUnitId:l,objects:u,type:p.DrawingApplyType.INSERT}},S={id:p.SetDrawingApplyMutation.id,params:{op:a,unitId:h,subUnitId:l,objects:u,type:p.DrawingApplyType.REMOVE}};return m.sequenceExecute([...(y=f.preRedos)!=null?y:[],w,...f.redos],r)?(n.pushUndoRedo({unitID:h,undoMutations:[...(I=f.preUndos)!=null?I:[],S,...f.undos,{id:x.id,params:c}],redoMutations:[...(T=f.preRedos)!=null?T:[],w,...f.redos,{id:x.id,params:c}]}),!0):!1}},Ae={id:"sheet.command.set-drawing-arrange",type:m.CommandType.COMMAND,handler:(i,t)=>{const r=i.get(m.ICommandService),n=i.get(m.IUndoRedoService);if(!t)return!1;const e=i.get(p.ISheetDrawingService),{unitId:o,subUnitId:s,drawingIds:c,arrangeType:d}=t,h={unitId:o,subUnitId:s,drawingIds:c};let l;if(d===E.ArrangeTypeEnum.forward?l=e.getForwardDrawingsOp(h):d===E.ArrangeTypeEnum.backward?l=e.getBackwardDrawingOp(h):d===E.ArrangeTypeEnum.front?l=e.getFrontDrawingsOp(h):d===E.ArrangeTypeEnum.back&&(l=e.getBackDrawingsOp(h)),l==null)return!1;const{objects:a,redo:g,undo:u}=l;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:g,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE})?(n.pushUndoRedo({unitID:o,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:u,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE}}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:g,unitId:o,subUnitId:s,objects:a,type:p.DrawingApplyType.ARRANGE}}]}),!0):!1}},se={id:"sheet.command.set-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const r=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),e=i.get(p.ISheetDrawingService);if(!t)return!1;const{drawings:o}=t,s=e.getBatchUpdateOp(o),{unitId:c,subUnitId:d,undo:h,redo:l,objects:a}=s;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:c,subUnitId:d,op:l,objects:a,type:p.DrawingApplyType.UPDATE})?(n.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:h,objects:a,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[c]}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{unitId:c,subUnitId:d,op:l,objects:a,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[c]}]}),!0):!1}},Ue={id:"sheet.command.ungroup-sheet-image",type:m.CommandType.COMMAND,handler:(i,t)=>{const r=i.get(m.ICommandService),n=i.get(m.IUndoRedoService),e=i.get(p.ISheetDrawingService);if(!t)return!1;const o=[];t.forEach(({parent:u,children:f})=>{o.push(u.unitId),f.forEach(w=>{o.push(w.unitId)})});const s=e.getUngroupDrawingOp(t),{unitId:c,subUnitId:d,undo:h,redo:l,objects:a}=s;return r.syncExecuteCommand(p.SetDrawingApplyMutation.id,{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.UNGROUP})?(n.pushUndoRedo({unitID:c,undoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:h,unitId:c,subUnitId:d,objects:yt(a),type:p.DrawingApplyType.GROUP}},{id:x.id,params:o}],redoMutations:[{id:p.SetDrawingApplyMutation.id,params:{op:l,unitId:c,subUnitId:d,objects:a,type:p.DrawingApplyType.UNGROUP}},{id:x.id,params:o}]}),!0):!1}};var Rt=Object.defineProperty,Tt=Object.getOwnPropertyDescriptor,bt=(i,t,r,n)=>{for(var e=n>1?void 0:n?Tt(t,r):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(e=(n?s(t,r,e):s(e))||e);return n&&e&&Rt(t,r,e),e},K=(i,t)=>(r,n)=>t(r,n,i);let me=class extends m.Disposable{constructor(t,r,n,e,o,s,c,d,h,l,a,g){super();Y(this,"_workbookSelections");this._context=t,this._skeletonManagerService=r,this._commandService=n,this._selectionRenderService=e,this._imageIoService=o,this._fileOpenerService=s,this._sheetDrawingService=c,this._drawingManagerService=d,this._contextService=h,this._messageService=l,this._localeService=a,this._workbookSelections=g.getWorkbookSelections(this._context.unitId),this._updateImageListener(),this._updateOrderListener(),this._groupDrawingListener(),this._focusDrawingListener()}async insertFloatImage(){const t=await this._fileOpenerService.openFile({multiple:!0,accept:E.DRAWING_IMAGE_ALLOW_IMAGE_LIST.map(n=>`.${n.replace("image/","")}`).join(",")}),r=t.length;return r>E.DRAWING_IMAGE_COUNT_LIMIT?(this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxCount",String(E.DRAWING_IMAGE_COUNT_LIMIT))}),!1):r===0?!1:(t.forEach(async n=>await this._insertFloatImage(n)),!0)}async _insertFloatImage(t){let r;try{r=await this._imageIoService.saveImage(t)}catch(y){const I=y.message;I===E.ImageUploadStatusType.ERROR_EXCEED_SIZE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.exceedMaxSize",String(E.DRAWING_IMAGE_ALLOW_SIZE/(1024*1024)))}):I===E.ImageUploadStatusType.ERROR_IMAGE_TYPE?this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImageType")}):I===E.ImageUploadStatusType.ERROR_IMAGE&&this._messageService.show({type:Z.MessageType.Error,content:this._localeService.t("update-status.invalidImage")})}if(r==null)return;const n=this._getUnitInfo(),{unitId:e,subUnitId:o}=n,{imageId:s,imageSourceType:c,source:d,base64Cache:h}=r,{width:l,height:a,image:g}=await E.getImageSize(h||""),{width:u,height:f}=this._context.scene;this._imageIoService.addImageSourceCache(d,c,g);let w=1;if(l>E.DRAWING_IMAGE_WIDTH_LIMIT||a>E.DRAWING_IMAGE_HEIGHT_LIMIT){const y=E.DRAWING_IMAGE_WIDTH_LIMIT/l,I=E.DRAWING_IMAGE_HEIGHT_LIMIT/a;w=Math.max(y,I)}const S=this._getImagePosition(l*w,a*w,u,f);if(S==null)return;const C={unitId:e,subUnitId:o,drawingId:s,drawingType:E.DrawingTypeEnum.DRAWING_IMAGE,imageSourceType:c,source:d,transform:V(S,this._selectionRenderService,this._skeletonManagerService),sheetTransform:S};this._commandService.executeCommand(oe.id,{unitId:e,drawings:[C]})}_getUnitInfo(){const t=this._context.unit,r=t.getActiveSheet(),n=t.getUnitId(),e=r.getSheetId();return{unitId:n,subUnitId:e}}_getImagePosition(t,r,n,e){const o=this._workbookSelections.getCurrentSelections();let s={startRow:0,endRow:0,startColumn:0,endColumn:0};o&&o.length>0&&(s=o[o.length-1].range);const c=U.attachRangeWithCoord(this._skeletonManagerService.getCurrent().skeleton,s);if(c==null)return;let{startColumn:d,startRow:h,startX:l,startY:a}=c,g=!1;if(l+t>n&&(l=n-t,l<0&&(l=0,t=n),g=!0),a+r>e&&(a=e-r,a<0&&(a=0,r=e),g=!0),g){const S=this._selectionRenderService.getSelectionCellByPosition(l,a);if(S==null)return;l=S.startX,a=S.startY,d=S.actualColumn,h=S.actualRow}const u={column:d,columnOffset:0,row:h,rowOffset:0},f=this._selectionRenderService.getSelectionCellByPosition(l+t,a+r);if(f==null)return;const w={column:f.actualColumn,columnOffset:l+t-f.startX,row:f.actualRow,rowOffset:a+r-f.startY};return{from:u,to:w}}_updateOrderListener(){this._drawingManagerService.featurePluginOrderUpdate$.subscribe(t=>{const{unitId:r,subUnitId:n,drawingIds:e,arrangeType:o}=t;this._commandService.executeCommand(Ae.id,{unitId:r,subUnitId:n,drawingIds:e,arrangeType:o})})}_updateImageListener(){this._drawingManagerService.featurePluginUpdate$.subscribe(t=>{const r=[];t.length!==0&&(t.forEach(n=>{const{unitId:e,subUnitId:o,drawingId:s,drawingType:c,transform:d}=n;if(d==null)return;const h=this._sheetDrawingService.getDrawingByParam({unitId:e,subUnitId:o,drawingId:s});if(h==null||h.unitId!==this._context.unitId)return;const l=$({...h.transform,...d},this._selectionRenderService);if(l==null)return;const a={...n,transform:{...h.transform,...d,...V(l,this._selectionRenderService,this._skeletonManagerService)},sheetTransform:{...l}};r.push(a)}),r.length>0&&this._commandService.executeCommand(se.id,{unitId:t[0].unitId,drawings:r}))})}_groupDrawingListener(){this._drawingManagerService.featurePluginGroupUpdate$.subscribe(t=>{this._commandService.executeCommand(Pe.id,t);const{unitId:r,subUnitId:n,drawingId:e}=t[0].parent;this._drawingManagerService.focusDrawing([{unitId:r,subUnitId:n,drawingId:e}])}),this._drawingManagerService.featurePluginUngroupUpdate$.subscribe(t=>{this._commandService.executeCommand(Ue.id,t)})}_focusDrawingListener(){this.disposeWithMe(this._drawingManagerService.focus$.subscribe(t=>{t==null||t.length===0?(this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!1),this._sheetDrawingService.focusDrawing([])):(this._contextService.setContextValue(m.FOCUSING_COMMON_DRAWINGS,!0),this._sheetDrawingService.focusDrawing(t))}))}};me=bt([K(1,m.Inject(U.SheetSkeletonManagerService)),K(2,m.ICommandService),K(3,U.ISheetSelectionRenderService),K(4,E.IImageIoService),K(5,k.ILocalFileService),K(6,p.ISheetDrawingService),K(7,E.IDrawingManagerService),K(8,m.IContextService),K(9,k.IMessageService),K(10,m.Inject(m.LocaleService)),K(11,m.Inject(D.SheetsSelectionsService))],me);const _e={id:"sheet.command.insert-float-image",type:m.CommandType.COMMAND,handler:i=>{var r,n;return(n=(r=i.get(N.IRenderManagerService).getCurrentTypeOfRenderer(m.UniverInstanceType.UNIVER_SHEET))==null?void 0:r.with(me).insertFloatImage())!=null?n:!1}},ne={id:"sheet.command.move-drawing",type:m.CommandType.COMMAND,handler:(i,t)=>{const r=i.get(m.ICommandService),n=i.get(p.ISheetDrawingService),e=i.get(U.ISheetSelectionRenderService),{direction:o}=t,s=n.getFocusDrawings();if(s.length===0)return!1;const c=s[0].unitId,d=s.map(l=>{const{transform:a}=l;if(a==null)return null;const g={...a},{left:u=0,top:f=0}=a;return o===m.Direction.UP?g.top=f-1:o===m.Direction.DOWN?g.top=f+1:o===m.Direction.LEFT?g.left=u-1:o===m.Direction.RIGHT&&(g.left=u+1),{...l,transform:g,sheetTransform:$(g,e)}}).filter(l=>l!=null);return r.syncExecuteCommand(se.id,{unitId:c,drawings:d})?(r.syncExecuteCommand(x.id,[c]),!0):!1}},Ye="addition-and-subtraction-single",Ne="sheet.menu.image";function Et(i){return{id:Ne,type:k.MenuItemType.SUBITEMS,icon:Ye,tooltip:"sheetImage.title",hidden$:k.getMenuHiddenObservable(i,m.UniverInstanceType.UNIVER_SHEET),disabled$:U.getCurrentRangeDisable$(i,{workbookTypes:[D.WorkbookEditablePermission],worksheetTypes:[D.WorksheetEditPermission],rangeTypes:[D.RangeProtectionPermissionEditPoint]})}}function Ot(i){return{id:_e.id,title:"sheetImage.upload.float",type:k.MenuItemType.BUTTON,hidden$:k.getMenuHiddenObservable(i,m.UniverInstanceType.UNIVER_SHEET)}}const Pt="univer-image-common-panel",At="univer-image-common-panel-grid",Ut="univer-image-common-panel-border",Nt="univer-image-common-panel-title",jt="univer-image-common-panel-subtitle",Wt="univer-image-common-panel-row",Lt="univer-image-common-panel-row-vertical",xt="univer-image-common-panel-column",Bt="univer-image-common-panel-column-center",$t="univer-image-common-panel-inline",kt="univer-image-common-panel-span2",Gt="univer-image-common-panel-span3",Vt="univer-image-common-panel-input",Ft="univer-sheet-image-menu",Yt="univer-sheet-image-menu-input",J={imageCommonPanel:Pt,imageCommonPanelGrid:At,imageCommonPanelBorder:Ut,imageCommonPanelTitle:Nt,imageCommonPanelSubtitle:jt,imageCommonPanelRow:Wt,imageCommonPanelRowVertical:Lt,imageCommonPanelColumn:xt,imageCommonPanelColumnCenter:Bt,imageCommonPanelInline:$t,imageCommonPanelSpan2:kt,imageCommonPanelSpan3:Gt,imageCommonPanelInput:Vt,sheetImageMenu:Ft,sheetImageMenuInput:Yt};function He(i){var t,r,n="";if(typeof i=="string"||typeof i=="number")n+=i;else if(typeof i=="object")if(Array.isArray(i)){var e=i.length;for(t=0;t<e;t++)i[t]&&(r=He(i[t]))&&(n&&(n+=" "),n+=r)}else for(r in i)i[r]&&(n&&(n+=" "),n+=r);return n}function le(){for(var i,t,r=0,n="",e=arguments.length;r<e;r++)(i=arguments[r])&&(t=He(i))&&(n&&(n+=" "),n+=t);return n}const Ht=i=>{var I;const t=m.useDependency(m.ICommandService),r=m.useDependency(m.LocaleService),n=m.useDependency(E.IDrawingManagerService),e=m.useDependency(N.IRenderManagerService),{drawings:o}=i,s=o[0];if(s==null)return;const{unitId:c}=s,d=e.getRenderById(c),h=d==null?void 0:d.scene;if(h==null)return;const l=h.getTransformerByCreate(),[a,g]=H.useState(!0),u=(I=s.anchorType)!=null?I:p.SheetDrawingAnchorType.Position,[f,w]=H.useState(u);function S(T,_){const M=[];return T.forEach(v=>{const{oKey:P}=v,b=_.getDrawingOKey(P);if(b==null)return M.push(null),!0;const{unitId:j,subUnitId:A,drawingId:O,drawingType:R,anchorType:W,sheetTransform:B}=b;M.push({unitId:j,subUnitId:A,drawingId:O,anchorType:W,sheetTransform:B,drawingType:R})}),M}H.useEffect(()=>{const T=l.clearControl$.subscribe(M=>{M===!0&&g(!1)}),_=l.changeStart$.subscribe(M=>{var b;const{objects:v}=M,P=S(v,n);if(P.length===0)g(!1);else if(P.length>=1){g(!0);const j=((b=P[0])==null?void 0:b.anchorType)||p.SheetDrawingAnchorType.Position;w(j)}});return()=>{_.unsubscribe(),T.unsubscribe()}},[]);function C(T){w(T);const _=n.getFocusDrawings();if(_.length===0)return;const M=_.map(v=>({unitId:v.unitId,subUnitId:v.subUnitId,drawingId:v.drawingId,anchorType:T}));t.executeCommand(se.id,{unitId:_[0].unitId,drawings:M})}const y=T=>T?"block":"none";return G.jsxs("div",{className:le(J.imageCommonPanelGrid,J.imageCommonPanelBorder),style:{display:y(a)},children:[G.jsx("div",{className:J.imageCommonPanelRow,children:G.jsx("div",{className:le(J.imageCommonPanelColumn,J.imageCommonPanelTitle),children:G.jsx("div",{children:r.t("drawing-anchor.title")})})}),G.jsx("div",{className:le(J.imageCommonPanelRow),children:G.jsx("div",{className:le(J.imageCommonPanelColumn),children:G.jsxs(Z.RadioGroup,{value:f,onChange:C,direction:"vertical",children:[G.jsx(Z.Radio,{value:p.SheetDrawingAnchorType.Both,children:r.t("drawing-anchor.both")}),G.jsx(Z.Radio,{value:p.SheetDrawingAnchorType.Position,children:r.t("drawing-anchor.position")}),G.jsx(Z.Radio,{value:p.SheetDrawingAnchorType.None,children:r.t("drawing-anchor.none")})]})})})]})},Xt=()=>{const i=m.useDependency(E.IDrawingManagerService),t=i.getFocusDrawings(),[r,n]=H.useState(t);return H.useEffect(()=>{const e=i.focus$.subscribe(o=>{n(o)});return()=>{e.unsubscribe()}},[]),!!(r!=null&&r.length)&&G.jsxs("div",{className:J.imageCommonPanel,children:[G.jsx(te.DrawingCommonPanel,{drawings:r}),G.jsx(Ht,{drawings:r})]})},Kt={[k.RibbonStartGroup.FORMULAS_INSERT]:{[Ne]:{order:3,menuItemFactory:Et,[_e.id]:{order:0,menuItemFactory:Ot}}}};function ae(i){return!i.getContextValue(m.FOCUSING_FX_BAR_EDITOR)&&!i.getContextValue(m.EDITOR_ACTIVATED)&&!i.getContextValue(m.FOCUSING_PANEL_EDITOR)&&i.getContextValue(m.FOCUSING_COMMON_DRAWINGS)}const zt={id:ne.id,description:"shortcut.sheet.drawing-move-down",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_DOWN,priority:100,preconditions:ae,staticParameters:{direction:m.Direction.DOWN}},qt={id:ne.id,description:"shortcut.sheet.drawing-move-up",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_UP,priority:100,preconditions:ae,staticParameters:{direction:m.Direction.UP}},Jt={id:ne.id,description:"shortcut.sheet.drawing-move-left",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_LEFT,priority:100,preconditions:ae,staticParameters:{direction:m.Direction.LEFT}},Zt={id:ne.id,description:"shortcut.sheet.drawing-move-right",group:"4_sheet-drawing-view",binding:k.KeyCode.ARROW_RIGHT,priority:100,preconditions:ae,staticParameters:{direction:m.Direction.RIGHT}},Qt={id:Oe.id,description:"shortcut.sheet.drawing-delete",group:"4_sheet-drawing-view",preconditions:ae,binding:k.KeyCode.DELETE,mac:k.KeyCode.BACKSPACE};var en=Object.defineProperty,tn=Object.getOwnPropertyDescriptor,nn=(i,t,r,n)=>{for(var e=n>1?void 0:n?tn(t,r):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(e=(n?s(t,r,e):s(e))||e);return n&&e&&en(t,r,e),e},ue=(i,t)=>(r,n)=>t(r,n,i);let pe=class extends m.Disposable{constructor(i,t,r,n){super(),this._componentManager=i,this._menuManagerService=t,this._commandService=r,this._shortcutService=n,this._init()}_initCustomComponents(){const i=this._componentManager;this.disposeWithMe(i.register(Ye,Fe)),this.disposeWithMe(i.register(Be,Xt))}_initMenus(){this._menuManagerService.mergeMenu(Kt)}_initCommands(){[_e,oe,ie,se,be,x,Ee,Pe,Ue,ne,Oe,Ae].forEach(i=>this.disposeWithMe(this._commandService.registerCommand(i)))}_initShortcuts(){[zt,qt,Jt,Zt,Qt].forEach(i=>{this.disposeWithMe(this._shortcutService.registerShortcut(i))})}_init(){this._initCommands(),this._initCustomComponents(),this._initMenus(),this._initShortcuts()}};pe=nn([ue(0,m.Inject(k.ComponentManager)),ue(1,k.IMenuManagerService),ue(2,m.ICommandService),ue(3,k.IShortcutService)],pe);var rn=Object.defineProperty,on=Object.getOwnPropertyDescriptor,sn=(i,t,r,n)=>{for(var e=n>1?void 0:n?on(t,r):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(e=(n?s(t,r,e):s(e))||e);return n&&e&&rn(t,r,e),e},Ce=(i,t)=>(r,n)=>t(r,n,i);let fe=class extends m.Disposable{constructor(t,r,n){super();Y(this,"_copyInfo");this._sheetClipboardService=t,this._renderManagerService=r,this._sheetDrawingService=n,this._initCopyPaste()}_initCopyPaste(){this._sheetClipboardService.addClipboardHook({id:"SHEET_IMAGE_UI_PLUGIN",onBeforeCopy:(t,r,n)=>this._collect(t,r,n),onPasteCells:(t,r,n,e)=>{const{copyType:o=U.COPY_TYPE.COPY,pasteType:s}=e,{range:c}=t||{},{range:d,unitId:h,subUnitId:l}=r;return this._generateMutations(d,{copyType:o,pasteType:s,copyRange:c,unitId:h,subUnitId:l})},onPastePlainText:(t,r)=>({undos:[],redos:[]})})}_collect(t,r,n){var g;const e=(g=this._renderManagerService.getRenderById(t))==null?void 0:g.with(U.SheetSkeletonManagerService);if(!e)return;const o=e.attachRangeWithCoord(n);if(!o)return;const{startX:s,endX:c,startY:d,endY:h}=o,l=this._sheetDrawingService.getDrawingData(t,r),a=[];Object.keys(l).forEach(u=>{const f=l[u],{transform:w}=f;if(f.anchorType!==p.SheetDrawingAnchorType.Both||!w)return;const{left:S=0,top:C=0,width:y=0,height:I=0}=w,{drawingStartX:T,drawingEndX:_,drawingStartY:M,drawingEndY:v}={drawingStartX:S,drawingEndX:S+y,drawingStartY:C,drawingEndY:C+I};s<=T&&_<=c&&d<=M&&v<=h&&a.push(f)}),a.length&&(this._copyInfo={drawings:a,unitId:t,subUnitId:r})}_generateMutations(t,r){var b;if(!this._copyInfo)return{redos:[],undos:[]};if([U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_COL_WIDTH,U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_VALUE,U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMAT,U.PREDEFINED_HOOK_NAME.SPECIAL_PASTE_FORMULA].includes(r.pasteType))return{redos:[],undos:[]};const{copyRange:n}=r;if(!n)return{redos:[],undos:[]};const{drawings:e,unitId:o,subUnitId:s}=this._copyInfo,{ranges:[c,d],mapFunc:h}=U.virtualizeDiscreteRanges([n,t]),{row:l,col:a}=h(c.startRow,c.startColumn),{row:g,col:u}=h(d.startRow,d.startColumn),f=(b=this._renderManagerService.getRenderById(o))==null?void 0:b.with(U.SheetSkeletonManagerService);if(!f)return{redos:[],undos:[]};const w=f.attachRangeWithCoord({startRow:l,endRow:l,startColumn:a,endColumn:a}),S=f.attachRangeWithCoord({startRow:g,endRow:g,startColumn:u,endColumn:u});if(!w||!S)return{redos:[],undos:[]};const C=[],y=[],I=S.startX-w.startX,T=S.startY-w.startY,_=g-l,M=u-a,v=r.copyType===U.COPY_TYPE.CUT,{_sheetDrawingService:P}=this;return e.forEach(j=>{const{transform:A,sheetTransform:O}=j;if(!A)return;const R={...j,unitId:o,subUnitId:s,drawingId:v?j.drawingId:m.Tools.generateRandomId(),transform:{...A,left:A.left+I,top:A.top+T},sheetTransform:{to:{...O.to,row:O.to.row+_,column:O.to.column+M},from:{...O.from,row:O.from.row+_,column:O.from.column+M}}};if(v){const{undo:W,redo:B,objects:z}=P.getBatchUpdateOp([R]);C.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:s,type:p.DrawingApplyType.UPDATE,op:B,objects:z}}),y.push({id:p.SetDrawingApplyMutation.id,params:{unitId:o,subUnitId:s,type:p.DrawingApplyType.UPDATE,op:W,objects:z}})}else{const{undo:W,redo:B,objects:z}=P.getBatchAddOp([R]);C.push({id:p.SetDrawingApplyMutation.id,params:{op:B,unitId:o,subUnitId:s,objects:z,type:p.DrawingApplyType.INSERT}}),y.push({id:p.SetDrawingApplyMutation.id,params:{op:W,unitId:o,subUnitId:s,objects:z,type:p.DrawingApplyType.REMOVE}})}}),{redos:C,undos:y}}};fe=sn([Ce(0,U.ISheetClipboardService),Ce(1,N.IRenderManagerService),Ce(2,p.ISheetDrawingService)],fe);var an=Object.defineProperty,cn=Object.getOwnPropertyDescriptor,dn=(i,t,r,n)=>{for(var e=n>1?void 0:n?cn(t,r):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(e=(n?s(t,r,e):s(e))||e);return n&&e&&an(t,r,e),e},re=(i,t)=>(r,n)=>t(r,n,i);let we=class extends m.Disposable{constructor(i,t,r,n,e){super(),this._drawingManagerService=i,this._renderManagerService=t,this._permissionService=r,this._univerInstanceService=n,this._userManagerService=e,this._initDrawingVisible(),this._initDrawingEditable(),this._initViewPermissionChange(),this._initEditPermissionChange()}_initDrawingVisible(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([t,r])=>{if(!t){this._drawingManagerService.setDrawingVisible(!1);return}t.activeSheet$.subscribe(n=>{if(!n){this._drawingManagerService.setDrawingVisible(!1);return}const e=t.getUnitId(),o=n.getSheetId();if(this._permissionService.composePermission([new D.WorkbookViewPermission(e).id,new D.WorksheetViewPermission(e,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingVisible(!0);else{this._drawingManagerService.setDrawingVisible(!1);const c=t.getUnitId(),d=n.getSheetId(),h=this._drawingManagerService.getDrawingData(c,d),l=Object.values(h),a=this._renderManagerService.getRenderById(c),g=a==null?void 0:a.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&l.some(w=>f.oKey.includes(w.drawingId))&&g.removeObject(f)})}})}))}_initDrawingEditable(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([t,r])=>{if(!t){this._drawingManagerService.setDrawingEditable(!1);return}t.activeSheet$.subscribe(n=>{if(!n){this._drawingManagerService.setDrawingEditable(!1);return}const e=t.getUnitId(),o=n.getSheetId();if(this._permissionService.composePermission([new D.WorkbookEditablePermission(e).id,new D.WorksheetEditPermission(e,o).id]).every(c=>c.value))this._drawingManagerService.setDrawingEditable(!0);else{this._drawingManagerService.setDrawingEditable(!1);const c=t.getUnitId(),d=n.getSheetId(),h=this._drawingManagerService.getDrawingData(c,d),l=Object.values(h),a=this._renderManagerService.getRenderById(c),g=a==null?void 0:a.scene;if(g==null)return;g.getAllObjectsByOrder().forEach(f=>{f.classType===N.RENDER_CLASS_TYPE.IMAGE&&l.some(w=>f.oKey.includes(w.drawingId))&&g.detachTransformerFrom(f)})}})}))}_initViewPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([t,r])=>{t&&t.activeSheet$.subscribe(n=>{var a;if(!n)return;const e=t.getUnitId(),o=n.getSheetId();let s=!0;const c=this._renderManagerService.getRenderById(e),d=c==null?void 0:c.scene;if(d==null)return;const h=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new D.WorkbookViewPermission(e).id,new D.WorksheetViewPermission(e,o).id]).pipe(L.map(g=>g.every(u=>u.value)));l==null||l.pipe(L.filter(g=>g!==s),L.distinctUntilChanged()).subscribe({next:g=>{s=g,this._drawingManagerService.setDrawingVisible(g);const u=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(e,o),w=Object.values(f);g?this._drawingManagerService.addNotification(w):(u.forEach(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&w.some(C=>S.oKey.includes(C.drawingId))&&d.removeObject(S)}),h.clearSelectedObjects())}}),(a=this._permissionService.getPermissionPoint$(new D.WorksheetViewPermission(e,o).id))==null||a.pipe(L.filter(g=>g.value!==s),L.distinctUntilChanged()).subscribe({complete:()=>{s=!0,this._drawingManagerService.setDrawingVisible(!0);const g=this._drawingManagerService.getDrawingData(e,o),u=Object.values(g);this._drawingManagerService.addNotification(u)}})})}))}_initEditPermissionChange(){const i=this._univerInstanceService.getCurrentTypeOfUnit$(m.UniverInstanceType.UNIVER_SHEET);this.disposeWithMe(L.combineLatest([i,this._userManagerService.currentUser$]).subscribe(([t,r])=>{t&&t.activeSheet$.subscribe(n=>{var a;if(!n)return;const e=t.getUnitId(),o=n.getSheetId();let s=!0;const c=this._renderManagerService.getRenderById(e),d=c==null?void 0:c.scene;if(d==null)return;const h=d.getTransformerByCreate(),l=this._permissionService.composePermission$([new D.WorkbookEditablePermission(e).id,new D.WorksheetEditPermission(e,o).id]).pipe(L.map(g=>g.every(u=>u.value)));l==null||l.pipe(L.filter(g=>g!==s),L.distinctUntilChanged()).subscribe({next:g=>{s=g,this._drawingManagerService.setDrawingEditable(g);const u=d.getAllObjectsByOrder(),f=this._drawingManagerService.getDrawingData(e,o),w=Object.values(f);g?(u.forEach(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&w.some(C=>S.oKey.includes(C.drawingId))&&d.attachTransformerTo(S)}),this._drawingManagerService.addNotification(w)):(u.forEach(S=>{S.classType===N.RENDER_CLASS_TYPE.IMAGE&&w.some(C=>S.oKey.includes(C.drawingId))&&d.detachTransformerFrom(S)}),h.clearSelectedObjects())}}),(a=this._permissionService.getPermissionPoint$(new D.WorksheetEditPermission(e,o).id))==null||a.pipe(L.filter(g=>g.value!==s),L.distinctUntilChanged()).subscribe({complete:()=>{s=!0;const g=t.getUnitId(),u=n.getSheetId(),f=this._drawingManagerService.getDrawingData(g,u),w=Object.values(f),S=this._renderManagerService.getRenderById(g),C=S==null?void 0:S.scene;if(C==null)return;this._drawingManagerService.setDrawingEditable(!0),C.getAllObjectsByOrder().forEach(I=>{I.classType===N.RENDER_CLASS_TYPE.IMAGE&&w.some(T=>I.oKey.includes(T.drawingId))&&C.detachTransformerFrom(I)})}})})}))}};we=dn([re(0,E.IDrawingManagerService),re(1,N.IRenderManagerService),re(2,m.IPermissionService),re(3,m.IUniverInstanceService),re(4,m.Inject(m.UserManagerService))],we);var ln=Object.defineProperty,un=Object.getOwnPropertyDescriptor,gn=(i,t,r,n)=>{for(var e=n>1?void 0:n?un(t,r):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(e=(n?s(t,r,e):s(e))||e);return n&&e&&ln(t,r,e),e},ge=(i,t)=>(r,n)=>t(r,n,i);let Se=class extends m.Disposable{constructor(i,t,r,n){super(),this._sheetPrintInterceptorService=i,this._drawingRenderService=t,this._drawingManagerService=r,this._renderManagerService=n,this._initPrinting()}_initPrinting(){this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_COMPONENT_COLLECT,{handler:(i,t,r)=>{const{unitId:n,scene:e,subUnitId:o}=t,s=this._drawingManagerService.getDrawingDataForUnit(n),c=s==null?void 0:s[o];return c&&c.order.forEach(d=>{this._drawingRenderService.renderDrawing(c.data[d],e)}),r()}})),this.disposeWithMe(this._sheetPrintInterceptorService.interceptor.intercept(this._sheetPrintInterceptorService.interceptor.getInterceptPoints().PRINTING_RANGE,{handler:(i,t,r)=>{const{unitId:n,subUnitId:e}=t,o=this._renderManagerService.getRenderById(n);if(!o)return r(i);const s=o.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(e);if(!s)return r(i);const c=this._drawingManagerService.getDrawingDataForUnit(n),d=c==null?void 0:c[t.subUnitId];if(!d)return r(i);const{scaleX:h,scaleY:l}=o.scene,a=i?{...i}:{startColumn:0,endColumn:0,endRow:0,startRow:0},g=d.order.map(u=>d.data[u]).filter(u=>u.drawingType!==E.DrawingTypeEnum.DRAWING_DOM);return g.length?(g.forEach(u=>{if(!u.groupId&&u.transform&&m.Tools.isDefine(u.transform.left)&&m.Tools.isDefine(u.transform.top)&&m.Tools.isDefine(u.transform.width)&&m.Tools.isDefine(u.transform.height)){const f=s.skeleton.getCellPositionByOffset(u.transform.left,u.transform.top,h,l,{x:0,y:0}),w=s.skeleton.getCellPositionByOffset(u.transform.left+u.transform.width,u.transform.top+u.transform.height,h,l,{x:0,y:0});f.column<a.startColumn&&(a.startColumn=f.column),f.row<a.startRow&&(a.startRow=f.row),a.endRow<w.row&&(a.endRow=w.row),a.endColumn<w.column&&(a.endColumn=w.column)}}),r(a)):r(i)}}))}};Se=gn([ge(0,m.Inject(U.SheetPrintInterceptorService)),ge(1,m.Inject(te.DrawingRenderService)),ge(2,E.IDrawingManagerService),ge(3,N.IRenderManagerService)],Se);var hn=Object.defineProperty,mn=Object.getOwnPropertyDescriptor,pn=(i,t,r,n)=>{for(var e=n>1?void 0:n?mn(t,r):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(e=(n?s(t,r,e):s(e))||e);return n&&e&&hn(t,r,e),e},q=(i,t)=>(r,n)=>t(r,n,i);const fn=[D.InsertRowCommand.id,D.InsertColCommand.id,D.RemoveRowCommand.id,D.RemoveColCommand.id,D.DeleteRangeMoveLeftCommand.id,D.DeleteRangeMoveUpCommand.id,D.InsertRangeMoveDownCommand.id,D.InsertRangeMoveRightCommand.id,D.DeltaRowHeightCommand.id,D.SetRowHeightCommand.id,D.DeltaColumnWidthCommand.id,D.SetColWidthCommand.id,D.SetRowHiddenCommand.id,D.SetSpecificRowsVisibleCommand.id,D.SetSpecificColsVisibleCommand.id,D.SetColHiddenCommand.id,D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id],wn=[D.SetRowVisibleMutation.id,D.SetRowHiddenMutation.id,D.SetColVisibleMutation.id,D.SetColHiddenMutation.id,D.SetWorksheetRowHeightMutation.id,D.SetWorksheetColWidthMutation.id];let Te=class extends m.Disposable{constructor(i,t,r,n,e,o,s,c,d){super(),this._context=i,this._renderManagerService=t,this._commandService=r,this._selectionRenderService=n,this._skeletonManagerService=e,this._sheetInterceptorService=o,this._sheetDrawingService=s,this._drawingManagerService=c,this._univerInstanceService=d,this._sheetInterceptorListener(),this._commandListener(),this._sheetRefreshListener()}_sheetInterceptorListener(){this.disposeWithMe(this._sheetInterceptorService.interceptCommand({getMutations:i=>{if(!fn.includes(i.id))return{redos:[],undos:[]};if(i.params==null)return{redos:[],undos:[]};const t=i.id;if(t===D.InsertRowCommand.id)return this._moveRowInterceptor(i.params,"insert");if([D.MoveColsCommand.id,D.MoveRowsCommand.id,D.MoveRangeCommand.id].includes(t))return this._moveRangeInterceptor(i.params);if(t===D.InsertColCommand.id)return this._moveColInterceptor(i.params,"insert");if(t===D.RemoveRowCommand.id)return this._moveRowInterceptor(i.params,"remove");if(t===D.RemoveColCommand.id)return this._moveColInterceptor(i.params,"remove");if(t===D.DeleteRangeMoveLeftCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,0)}else if(t===D.DeleteRangeMoveUpCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,1)}else if(t===D.InsertRangeMoveDownCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,2)}else if(t===D.InsertRangeMoveRightCommand.id){const{range:r}=i.params;return this._getRangeMoveUndo(r,3)}else if(t===D.SetRowHiddenCommand.id||t===D.SetSpecificRowsVisibleCommand.id){const r=i.params,{unitId:n,subUnitId:e,ranges:o}=r;return this._getDrawingUndoForRowVisible(n,e,o)}else if(t===D.SetSpecificColsVisibleCommand.id||t===D.SetColHiddenCommand.id){const r=i.params,{unitId:n,subUnitId:e,ranges:o}=r;return this._getDrawingUndoForColVisible(n,e,o)}else if(t===D.DeltaRowHeightCommand.id||t===D.SetRowHeightCommand.id||t===D.DeltaColumnWidthCommand.id||t===D.SetColWidthCommand.id){const r=i.params,{unitId:n,subUnitId:e,ranges:o}=r,s=t===D.DeltaRowHeightCommand.id||t===D.SetRowHeightCommand.id;return this._getDrawingUndoForRowAndColSize(n,e,o,s)}return{redos:[],undos:[]}}}))}_getRangeMoveUndo(i,t){const r=D.getSheetCommandTarget(this._univerInstanceService);if(r==null)return{redos:[],undos:[]};const n=r.unitId,e=r.subUnitId,o=[],s=[],c=this._sheetDrawingService.getDrawingData(n,e),d=[],h=[];if(Object.keys(c).forEach(l=>{const a=c[l],{updateDrawings:g,deleteDrawings:u}=this._getUpdateOrDeleteDrawings(i,t,a);d.push(...g),h.push(...u)}),d.length===0&&h.length===0)return{redos:[],undos:[]};if(d.length>0){const l=this._sheetDrawingService.getBatchUpdateOp(d),{undo:a,redo:g,objects:u}=l;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:e,op:g,objects:u,type:p.DrawingApplyType.UPDATE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:e,op:a,objects:u,type:p.DrawingApplyType.UPDATE}})}if(h.length>0){const l=this._sheetDrawingService.getBatchRemoveOp(h),a=l.undo,g=l.redo,u=l.objects;o.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:e,op:g,objects:u,type:p.DrawingApplyType.REMOVE}}),s.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:e,op:a,objects:u,type:p.DrawingApplyType.INSERT}})}return o.push({id:x.id,params:[n]}),s.push({id:x.id,params:[n]}),{redos:o,undos:s}}_getUpdateOrDeleteDrawings(i,t,r){const n=[],e=[],{sheetTransform:o,anchorType:s=p.SheetDrawingAnchorType.Position,transform:c,unitId:d,subUnitId:h,drawingId:l}=r,{from:a,to:g}=o,{row:u,column:f}=a,{row:w,column:S}=g;if(o==null||c==null)return{updateDrawings:n,deleteDrawings:e};const{startRow:C,endRow:y,startColumn:I,endColumn:T}=i;let _=null,M=null;if(t===0&&u>=C&&w<=y)if(f>=I&&S<=T)e.push({unitId:d,subUnitId:h,drawingId:l});else{const v=this._shrinkCol(o,c,I,T,s);_=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(t===1&&f>=I&&S<=T)if(u>=C&&w<=y)e.push({unitId:d,subUnitId:h,drawingId:l});else{const v=this._shrinkRow(o,c,C,y,s);_=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(t===2){const v=this._expandRow(o,c,C,y,s);_=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}else if(t===3){const v=this._expandCol(o,c,I,T,s);_=v==null?void 0:v.newSheetTransform,M=v==null?void 0:v.newTransform}if(_!=null&&M!=null){const v=V(_,this._selectionRenderService,this._skeletonManagerService);n.push({...r,sheetTransform:_,transform:v})}return{updateDrawings:n,deleteDrawings:e}}_remainDrawingSize(i,t,r){const n=$({...i},this._selectionRenderService);n!=null&&t.push({...r,sheetTransform:n})}_getDrawingUndoForColVisible(i,t,r){const n=this._drawingManagerService.getDrawingData(i,t),e=[],o=[];if(Object.keys(n).forEach(l=>{const a=n[l],{sheetTransform:g,transform:u,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(u,e,a);else{const{from:w,to:S}=g,{row:C,column:y}=w,{row:I,column:T}=S;for(let _=0;_<r.length;_++){const M=r[_],{startRow:v,endRow:P,startColumn:b,endColumn:j}=M;if(T<b)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,W=null;if(y>=b&&y<=j){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:j,startRow:w.row,endRow:S.row});if(B==null)return;W={...u,left:B.startX}}if(W!=null&&(R=$(W,this._selectionRenderService),R!=null&&W!=null)){e.push({...a,sheetTransform:R,transform:W});break}this._remainDrawingSize(u,e,a);continue}if(y>=b&&T<=j)continue;let A=null,O=null;if(y>=b&&y<=j){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:y,endColumn:j,startRow:w.row,endRow:S.row});if(R==null)return;O={...u,left:(R==null?void 0:R.startX)||0,width:((u==null?void 0:u.width)||0)-R.endX+R.startX}}else if(T>=b&&T<=j){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:T,startRow:w.row,endRow:S.row});if(R==null)return;O={...u,left:R.startX-((u==null?void 0:u.width)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:b,endColumn:j,startRow:w.row,endRow:S.row});if(R==null)return;if(O={...u,width:((u==null?void 0:u.width)||0)-R.endX+R.startX},A=$(O,this._selectionRenderService),A!=null&&O!=null){o.push({...a,sheetTransform:A,transform:O});break}}if(O!=null&&(A=$(O,this._selectionRenderService)),O!=null&&A!=null){e.push({...a,sheetTransform:A,transform:O});break}else this._remainDrawingSize(u,e,a)}}}),e.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:c}=this._createUndoAndRedoMutation(i,t,e),d=[],h=[];if(o.length>0){const{redos:l,undos:a}=this._createUndoAndRedoMutation(i,t,o);d.push(...l),h.push(...a)}return{redos:s,undos:c,preRedos:d,preUndos:h}}_createUndoAndRedoMutation(i,t,r){const n=this._sheetDrawingService.getBatchUpdateOp(r),{undo:e,redo:o,objects:s}=n,c=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:t,op:o,objects:s,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[i]}],d=[{id:p.SetDrawingApplyMutation.id,params:{unitId:i,subUnitId:t,op:e,objects:s,type:p.DrawingApplyType.UPDATE}},{id:x.id,params:[i]}];return{redos:c,undos:d}}_getDrawingUndoForRowVisible(i,t,r){const n=this._drawingManagerService.getDrawingData(i,t),e=[],o=[];if(Object.keys(n).forEach(l=>{const a=n[l],{sheetTransform:g,transform:u,anchorType:f=p.SheetDrawingAnchorType.Position}=a;if(f===p.SheetDrawingAnchorType.None)this._remainDrawingSize(u,e,a);else{const{from:w,to:S}=g,{row:C,column:y}=w,{row:I,column:T}=S;for(let _=0;_<r.length;_++){const M=r[_],{startRow:v,endRow:P,startColumn:b,endColumn:j}=M;if(I<v)continue;if(f===p.SheetDrawingAnchorType.Position){let R=null,W=null;if(C>=v&&C<=P){const B=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:C,endRow:P});if(B==null)return;W={...u,top:B.startY}}if(W!=null&&(R=$(W,this._selectionRenderService),R!=null&&W!=null)){e.push({...a,sheetTransform:R,transform:W});break}this._remainDrawingSize(u,e,a);continue}if(C>=v&&I<=P)continue;let A=null,O=null;if(C>=v&&C<=P){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:C,endRow:P});if(R==null)return;O={...u,top:(R==null?void 0:R.startY)||0,height:((u==null?void 0:u.height)||0)-R.endY+R.startY}}else if(I>=v&&I<=P){const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:I});if(R==null)return;O={...u,top:R.startY-((u==null?void 0:u.height)||0)}}else{const R=this._skeletonManagerService.attachRangeWithCoord({startColumn:w.column,endColumn:S.column,startRow:v,endRow:P});if(R==null)return;if(O={...u,height:((u==null?void 0:u.height)||0)-R.endY+R.startY},A=$(O,this._selectionRenderService),A!=null&&O!=null){o.push({...a,sheetTransform:A,transform:O});break}}if(O!=null&&(A=$(O,this._selectionRenderService)),O!=null&&A!=null){e.push({...a,sheetTransform:A,transform:O});break}else this._remainDrawingSize(u,e,a)}}}),e.length===0&&o.length===0)return{redos:[],undos:[]};const{redos:s,undos:c}=this._createUndoAndRedoMutation(i,t,e),d=[],h=[];if(o.length>0){const{redos:l,undos:a}=this._createUndoAndRedoMutation(i,t,o);d.push(...l),h.push(...a)}return{redos:s,undos:c,preRedos:d,preUndos:h}}_getDrawingUndoForRowAndColSize(i,t,r,n){const e=this._drawingManagerService.getDrawingData(i,t),o=[];return Object.keys(e).forEach(s=>{const c=e[s],{sheetTransform:d,transform:h,anchorType:l=p.SheetDrawingAnchorType.Position}=c;if(l===p.SheetDrawingAnchorType.None)this._remainDrawingSize(h,o,c);else{const{from:a,to:g}=d,{row:u,column:f}=a,{row:w,column:S}=g;for(let C=0;C<r.length;C++){const y=r[C],{startRow:I,endRow:T,startColumn:_,endColumn:M}=y;if(w<I||S<_)continue;if(l===p.SheetDrawingAnchorType.Position&&(u<=I&&w>=T||f<=_&&S>=M)){this._remainDrawingSize(h,o,c);continue}const v=V({...d},this._selectionRenderService,this._skeletonManagerService);if(v!=null){o.push({...c,transform:v});break}}}}),o.length===0?{redos:[],undos:[]}:this._createUndoAndRedoMutation(i,t,o)}_getUnitIdAndSubUnitId(i,t){let r,n;if(t==="insert")r=i.unitId,n=i.subUnitId;else{const e=D.getSheetCommandTarget(this._univerInstanceService);if(e==null)return;r=e.unitId,n=e.subUnitId}return{unitId:r,subUnitId:n}}_moveRangeInterceptor(i){var I,T;const{toRange:t,fromRange:r}=i,n=D.getSheetCommandTarget(this._univerInstanceService);if(!n)return{redos:[],undos:[]};const{unitId:e,subUnitId:o}=n,s=(T=(I=this._renderManagerService.getRenderById(e))==null?void 0:I.with(U.SheetSkeletonManagerService))==null?void 0:T.getCurrentSkeleton();if(!s)return{redos:[],undos:[]};const c=U.attachRangeWithCoord(s,r);if(!c)return{redos:[],undos:[]};const{startX:d,endX:h,startY:l,endY:a}=c,g=this._sheetDrawingService.getDrawingData(e,o),u=[];Object.keys(g).forEach(_=>{const M=g[_];if(M.anchorType!==p.SheetDrawingAnchorType.Both)return;const{transform:v}=M;if(!v)return;const{left:P=0,top:b=0,width:j=0,height:A=0}=v,{drawingStartX:O,drawingEndX:R,drawingStartY:W,drawingEndY:B}={drawingStartX:P,drawingEndX:P+j,drawingStartY:b,drawingEndY:b+A};d<=O&&R<=h&&l<=W&&B<=a&&u.push(M)});const f=[],w=[],S=t.startRow-r.startRow,C=t.startColumn-r.startColumn,y=u.map(_=>{const M=_.sheetTransform,v={to:{...M.to,row:M.to.row+S,column:M.to.column+C},from:{...M.from,row:M.from.row+S,column:M.from.column+C}},P=V(v,this._selectionRenderService,this._skeletonManagerService);return{unitId:e,subUnitId:o,drawingId:_.drawingId,transform:P,sheetTransform:v}});if(y.length){const _=this._sheetDrawingService.getBatchUpdateOp(y),{undo:M,redo:v,objects:P}=_;f.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:o,op:v,objects:P,type:p.DrawingApplyType.UPDATE}}),w.push({id:p.SetDrawingApplyMutation.id,params:{unitId:e,subUnitId:o,op:M,objects:P,type:p.DrawingApplyType.UPDATE}})}return{redos:f,undos:w}}_moveRowInterceptor(i,t){const r=this._getUnitIdAndSubUnitId(i,t);if(r==null)return{redos:[],undos:[]};const{unitId:n,subUnitId:e}=r,{range:o}=i,s=o.startRow,c=o.endRow,d=[],h=[],l=this._sheetDrawingService.getDrawingData(n,e),a=[],g=[];if(Object.keys(l).forEach(u=>{const f=l[u],{sheetTransform:w,transform:S,anchorType:C=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let y,I;if(t==="insert"){const _=this._expandRow(w,S,s,c,C);y=_==null?void 0:_.newSheetTransform,I=_==null?void 0:_.newTransform}else{const{from:_,to:M}=w,{row:v}=_,{row:P}=M;if(C===p.SheetDrawingAnchorType.Both&&v>=s&&P<=c)g.push({unitId:n,subUnitId:e,drawingId:u});else{const b=this._shrinkRow(w,S,s,c,C);y=b==null?void 0:b.newSheetTransform,I=b==null?void 0:b.newTransform}}if(!y||!I)return;const T={unitId:n,subUnitId:e,drawingId:u,transform:I,sheetTransform:y};a.push(T)}),a.length===0&&g.length===0)return{redos:[],undos:[]};if(a.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(a),{undo:f,redo:w,objects:S}=u;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:e,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:e,op:f,objects:S,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),f=u.undo,w=u.redo,S=u.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:e,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:e,op:f,objects:S,type:p.DrawingApplyType.INSERT}})}return d.push({id:x.id,params:[n]}),h.push({id:x.id,params:[n]}),{redos:d,undos:h}}_moveColInterceptor(i,t){const r=this._getUnitIdAndSubUnitId(i,t);if(r==null)return{redos:[],undos:[]};const{unitId:n,subUnitId:e}=r,{range:o}=i,s=o.startColumn,c=o.endColumn,d=[],h=[],l=this._sheetDrawingService.getDrawingData(n,e),a=[],g=[];if(Object.keys(l).forEach(u=>{const f=l[u],{sheetTransform:w,transform:S,anchorType:C=p.SheetDrawingAnchorType.Position}=f;if(w==null||S==null)return;let y,I;if(t==="insert"){const _=this._expandCol(w,S,s,c,C);y=_==null?void 0:_.newSheetTransform,I=_==null?void 0:_.newTransform}else{const{from:_,to:M}=w,{column:v}=_,{column:P}=M;if(C===p.SheetDrawingAnchorType.Both&&v>=s&&P<=c)g.push({unitId:n,subUnitId:e,drawingId:u});else{const b=this._shrinkCol(w,S,s,c,C);y=b==null?void 0:b.newSheetTransform,I=b==null?void 0:b.newTransform}}if(!y||!I)return;const T={unitId:n,subUnitId:e,drawingId:u,transform:I,sheetTransform:y};a.push(T)}),a.length===0&&g.length===0)return{redos:[],undos:[]};if(a.length>0){const u=this._sheetDrawingService.getBatchUpdateOp(a),{undo:f,redo:w,objects:S}=u;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:e,op:w,objects:S,type:p.DrawingApplyType.UPDATE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:e,op:f,objects:S,type:p.DrawingApplyType.UPDATE}})}if(g.length>0){const u=this._sheetDrawingService.getBatchRemoveOp(g),f=u.undo,w=u.redo,S=u.objects;d.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:e,op:w,objects:S,type:p.DrawingApplyType.REMOVE}}),h.push({id:p.SetDrawingApplyMutation.id,params:{unitId:n,subUnitId:e,op:f,objects:S,type:p.DrawingApplyType.INSERT}})}return d.push({id:x.id,params:[n]}),h.push({id:x.id,params:[n]}),{redos:d,undos:h}}_expandCol(i,t,r,n,e=p.SheetDrawingAnchorType.Position){const o=n-r+1,{from:s,to:c}=i,{column:d}=s,{column:h}=c;if(e===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};let l=null,a=null;if(d>=r){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:r,endColumn:n,startRow:s.row,endRow:c.row});if(g==null)return;a={...t,left:(t.left||0)+g.endX-g.startX},l=$(a,this._selectionRenderService)}else if(h>=n)if(e===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,column:h+o}},a=V(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_shrinkCol(i,t,r,n,e=p.SheetDrawingAnchorType.Position){const o=n-r+1,{from:s,to:c}=i,{column:d}=s,{column:h}=c;if(e===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};let l=null,a=null;if(d>n)l={from:{...s,column:d-o},to:{...c,column:h-o}},a=V(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=r&&h<=n)return null;if(d<r&&h>n)if(e===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,column:h-o}},a=V(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};else if(d>=r&&d<=n){if(d===r)a={...t,left:(t.left||0)-i.from.columnOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:r,endColumn:d-1,startRow:s.row,endRow:c.row});if(g==null)return;a={...t,left:(t.left||0)-g.endX+g.startX-i.from.columnOffset}}l=$(a,this._selectionRenderService)}else if(h>=r&&h<=n&&e===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:r-1,endColumn:r-1,startRow:s.row,endRow:c.row});if(g==null)return;l={from:{...s},to:{...c,column:r-1,columnOffset:g.endX-g.startX}},a=V(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_expandRow(i,t,r,n,e=p.SheetDrawingAnchorType.Position){const o=n-r+1,{from:s,to:c}=i,{row:d}=s,{row:h}=c;if(e===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};let l=null,a=null;if(d>=r){const g=this._skeletonManagerService.attachRangeWithCoord({startRow:r,endRow:n,startColumn:s.column,endColumn:c.column});if(g==null)return;a={...t,top:(t.top||0)+g.endY-g.startY},l=$(a,this._selectionRenderService)}else if(h>=n)if(e===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,row:h+o}},a=V(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_shrinkRow(i,t,r,n,e=p.SheetDrawingAnchorType.Position){const o=n-r+1,{from:s,to:c}=i,{row:d}=s,{row:h}=c;if(e===p.SheetDrawingAnchorType.None)return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};let l=null,a=null;if(d>n)l={from:{...s,row:d-o},to:{...c,row:h-o}},a=V(l,this._selectionRenderService,this._skeletonManagerService);else{if(d>=r&&h<=n)return null;if(d<r&&h>n)if(e===p.SheetDrawingAnchorType.Both)l={from:{...s},to:{...c,row:h-o}},a=V(l,this._selectionRenderService,this._skeletonManagerService);else return{newSheetTransform:$({...t},this._selectionRenderService),newTransform:t};else if(d>=r&&d<=n){if(d===r)a={...t,top:(t.top||0)-i.from.rowOffset};else{const g=this._skeletonManagerService.attachRangeWithCoord({startRow:r,endRow:d-1,startColumn:s.column,endColumn:c.column});if(g==null)return;a={...t,top:(t.top||0)-g.endY+g.startY-i.from.rowOffset}}l=$(a,this._selectionRenderService)}else if(h>=r&&h<=n&&e===p.SheetDrawingAnchorType.Both){const g=this._skeletonManagerService.attachRangeWithCoord({startColumn:s.column,endColumn:s.column,startRow:r-1,endRow:r-1});if(g==null)return;l={from:{...s},to:{...c,row:r-1,rowOffset:g.endY-g.startY}},a=V(l,this._selectionRenderService,this._skeletonManagerService)}}return l!=null&&a!=null?{newSheetTransform:l,newTransform:a}:null}_commandListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{i.id===D.SetWorksheetActiveOperation.id&&setTimeout(()=>{const t=i.params,{unitId:r,subUnitId:n}=t,e=this._drawingManagerService.drawingManagerData,o=[],s=[];Object.keys(e).forEach(c=>{const d=e[c];d!=null&&Object.keys(d).forEach(h=>{const l=d[h].data;l!=null&&Object.keys(l).forEach(a=>{if(c===r&&h===n){const g=l[a];g.transform=V(g.sheetTransform,this._selectionRenderService,this._skeletonManagerService),o.push(l[a])}else s.push(l[a])})})}),this._drawingManagerService.removeNotification(s),this._drawingManagerService.addNotification(o)},0)}))}_sheetRefreshListener(){this.disposeWithMe(this._commandService.onCommandExecuted(i=>{wn.includes(i.id)&&requestIdleCallback(()=>{const t=i.params,{unitId:r,subUnitId:n,ranges:e}=t;this._refreshDrawingTransform(r,n,e)})}))}_refreshDrawingTransform(i,t,r){const n=this._drawingManagerService.getDrawingData(i,t),e=[];Object.keys(n).forEach(o=>{const s=n[o],{sheetTransform:c,transform:d,anchorType:h=p.SheetDrawingAnchorType.Position}=s;if(h===p.SheetDrawingAnchorType.None)return!0;const{from:l,to:a}=c,{row:g,column:u}=l,{row:f,column:w}=a;for(let S=0;S<r.length;S++){const C=r[S],{startRow:y,endRow:I,startColumn:T,endColumn:_}=C;if(m.Rectangle.intersects({startRow:y,endRow:I,startColumn:T,endColumn:_},{startRow:g,endRow:f,startColumn:u,endColumn:w})||g>I||u>_){const M=h===p.SheetDrawingAnchorType.Position,v=V(c,this._selectionRenderService,this._skeletonManagerService);e.push({...s,transform:{...v,width:M?d==null?void 0:d.width:v==null?void 0:v.width,height:M?d==null?void 0:d.height:v==null?void 0:v.height}});break}}}),e.length!==0&&(this._drawingManagerService.refreshTransform(e),this._commandService.syncExecuteCommand(x.id,[i]))}};Te=pn([q(1,N.IRenderManagerService),q(2,m.ICommandService),q(3,U.ISheetSelectionRenderService),q(4,m.Inject(U.SheetSkeletonManagerService)),q(5,m.Inject(D.SheetInterceptorService)),q(6,p.ISheetDrawingService),q(7,E.IDrawingManagerService),q(8,m.IUniverInstanceService)],Te);var Sn=Object.defineProperty,vn=Object.getOwnPropertyDescriptor,_n=(i,t,r,n)=>{for(var e=n>1?void 0:n?vn(t,r):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(e=(n?s(t,r,e):s(e))||e);return n&&e&&Sn(t,r,e),e},ee=(i,t)=>(r,n)=>t(r,n,i);function Dn(i,t,r,n){const{scaleX:e,scaleY:o}=t.getAncestorScale(),s=t.getViewport(N.SHEET_VIEWPORT_KEY.VIEW_MAIN),c={left:!0,top:!0};if(!s)return{...i,absolute:c};const{left:d,right:h,top:l,bottom:a}=i,g=n.getFreeze(),{startColumn:u,startRow:f,xSplit:w,ySplit:S}=g,C=r.getNoMergeCellPositionByIndexWithNoHeader(f-S,u-w),y=r.getNoMergeCellPositionByIndexWithNoHeader(f,u),{rowHeaderWidth:I,columnHeaderHeight:T}=r,_=y.startX-C.startX,M=y.startY-C.startY,{top:v,left:P,viewportScrollX:b,viewportScrollY:j}=s;let A,O;d<P?(c.left=!0,A=(_+I+(d-P))*e,O=Math.max(Math.min((_+I+(h-P))*e,(_+I)*e),(h-b)*e)):(c.left=!1,A=Math.max((d-b)*e,(_+I)*e),O=Math.max((h-b)*e,(_+I)*e));let R,W;return l<v?(c.top=!0,R=(M+T+(l-v))*o,W=Math.max(Math.min((M+T+(h-v))*o,(M+T)*o),(a-j)*o)):(c.top=!1,R=Math.max((l-j)*o,(M+T)*o),W=Math.max((a-j)*o,(M+T)*o)),{left:A,right:O,top:R,bottom:W,absolute:c}}const ye=(i,t,r,n)=>{const{scene:e}=t,{left:o,top:s,width:c,height:d,angle:h}=i,l={left:o,right:o+c,top:s,bottom:s+d},a=Dn(l,e,r,n),{scaleX:g,scaleY:u}=e.getAncestorScale();return{startX:a.left,endX:a.right,startY:a.top,endY:a.bottom,rotate:h,width:c*g,height:d*u,absolute:a.absolute}};exports.SheetCanvasFloatDomManagerService=class extends m.Disposable{constructor(r,n,e,o,s,c,d){super();Y(this,"_domLayerMap",new Map);Y(this,"_domLayerInfoMap",new Map);Y(this,"_transformChange$",new L.Subject);Y(this,"transformChange$",this._transformChange$.asObservable());Y(this,"_add$",new L.Subject);Y(this,"add$",this._add$.asObservable());Y(this,"_remove$",new L.Subject);Y(this,"remove$",this._remove$.asObservable());Y(this,"_hooks",[]);this._renderManagerService=r,this._univerInstanceService=n,this._commandService=e,this._drawingManagerService=o,this._canvasFloatDomService=s,this._sheetDrawingService=c,this._lifecycleService=d,this._drawingAddListener(),this._featureUpdateListener(),this._deleteListener(),this._bindScrollEvent()}_bindScrollEvent(){this._lifecycleService.lifecycle$.pipe(L.filter(r=>r===m.LifecycleStages.Rendered),L.take(1)).subscribe(()=>{this._scrollUpdateListener()})}_ensureMap(r,n){let e=this._domLayerMap.get(r);e||(e=new Map,this._domLayerMap.set(r,e));let o=e.get(n);return o||(o=new Map,e.set(n,o)),o}getFloatDomInfo(r){return this._domLayerInfoMap.get(r)}_getSceneAndTransformerByDrawingSearch(r){if(r==null)return;const n=this._renderManagerService.getRenderById(r),e=n==null?void 0:n.scene;if(n==null||e==null)return null;const o=e.getTransformerByCreate(),s=n.engine.getCanvasElement();return{scene:e,transformer:o,renderObject:n,canvas:s}}_getFloatDomProps(r){let n;return this._hooks.forEach(e=>{n=e.onGetFloatDomProps(r)}),n}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(r=>{r.forEach(n=>{var We,Le,xe;const{unitId:e,subUnitId:o,drawingId:s}=n,c=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:o}),d=this._drawingManagerService.getDrawingByParam(n),h=this._univerInstanceService.getUnit(e);if(!h)return;const l=h.getActiveSheet().getSheetId();if(!d||!c)return;const a=(We=this._renderManagerService.getRenderById(e))==null?void 0:We.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(o);if(!a)return;const{transform:g,drawingType:u,data:f}=d;if(u!==E.DrawingTypeEnum.DRAWING_DOM&&u!==E.DrawingTypeEnum.DRAWING_CHART)return;const w=this._getSceneAndTransformerByDrawingSearch(e);if(w==null)return;const{scene:S,canvas:C}=w;if(g==null)return!0;if(l!==o)return;const{left:y,top:I,width:T,height:_,angle:M,flipX:v,flipY:P,skewX:b,skewY:j}=g,A=E.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:o,drawingId:s}),O=S.getObject(A);if(O!=null){O.transformByState({left:y,top:I,width:T,height:_,angle:M,flipX:v,flipY:P,skewX:b,skewY:j});return}const R={left:y,top:I,width:T,height:_,zIndex:this._drawingManagerService.getDrawingOrder(e,o).length-1},W=u===E.DrawingTypeEnum.DRAWING_CHART;W&&(R.fill="white",R.rotateEnabled=!1,f&&f.border&&(R.stroke=f.border),R.paintFirst="stroke",R.strokeWidth=1,R.borderEnabled=!1,R.radius=8);const B=new N.Rect(A,R);W&&B.setObjectType(N.ObjectType.CHART),S.addObject(B,N.DRAWING_OBJECT_LAYER_INDEX),d.allowTransform!==!1&&S.attachTransformerTo(B);const z=this._ensureMap(e,o),De=new m.DisposableCollection,ze=ye(B,w.renderObject,a.skeleton,c.worksheet),Ie=new L.BehaviorSubject(ze),qe={dispose:De,rect:B,position$:Ie,unitId:e,subUnitId:o};this._canvasFloatDomService.addFloatDom({position$:Ie,id:s,componentKey:d.componentKey,onPointerDown:F=>{C.dispatchEvent(new PointerEvent(F.type,F))},onPointerMove:F=>{C.dispatchEvent(new PointerEvent(F.type,F))},onPointerUp:F=>{C.dispatchEvent(new PointerEvent(F.type,F))},onWheel:F=>{C.dispatchEvent(new WheelEvent(F.type,F))},props:(xe=(Le=z.get(s))==null?void 0:Le.props)!=null?xe:this._getFloatDomProps(s),data:f,unitId:e});const je=B.onTransformChange$.subscribeEvent(()=>{const F=ye(B,w.renderObject,a.skeleton,c.worksheet);Ie.next(F)});De.add(()=>{this._canvasFloatDomService.removeFloatDom(s)}),je&&De.add(je),this._domLayerInfoMap.set(s,qe),z.set(s,{...z.get(s)})})})),this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.forEach(n=>{const{unitId:e,subUnitId:o,drawingId:s}=n,c=E.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:o,drawingId:s}),d=this._getSceneAndTransformerByDrawingSearch(e);if(d==null)return;const{transformer:h,scene:l}=d,a=l.getObject(c);a!=null&&a.oKey&&h.clearControlByIds([a==null?void 0:a.oKey])})}))}_scrollUpdateListener(){const r=this._univerInstanceService.getCurrentUnitForType(m.UniverInstanceType.UNIVER_SHEET);if(!r)return;const n=(e,o)=>{var a;const s=this._getSceneAndTransformerByDrawingSearch(e),c=this._ensureMap(e,o),d=Array.from(c.keys()),h=D.getSheetCommandTarget(this._univerInstanceService,{unitId:e,subUnitId:o}),l=(a=this._renderManagerService.getRenderById(e))==null?void 0:a.with(U.SheetSkeletonManagerService).getWorksheetSkeleton(o);!s||!h||!l||d.forEach(g=>{const u=this._domLayerInfoMap.get(g);if(u){const f=ye(u.rect,s.renderObject,l.skeleton,h.worksheet);u.position$.next(f)}})};this.disposeWithMe(r.activeSheet$.pipe(L.filter(e=>!!e),L.map(e=>{const o=this._renderManagerService.getRenderById(e.getUnitId());return o?{render:o,unitId:r.getUnitId(),subUnitId:e.getSheetId()}:null}),L.filter(e=>!!e),L.switchMap(e=>m.fromEventSubject(e.render.scene.getViewport(U.VIEWPORT_KEY.VIEW_MAIN).onScrollAfter$).pipe(L.map(()=>({unitId:e.unitId,subUnitId:e.subUnitId}))))).subscribe(({unitId:e,subUnitId:o})=>{n(e,o)})),this.disposeWithMe(this._commandService.onCommandExecuted(e=>{var o,s;if(e.id===U.SetZoomRatioOperation.id){const c=e.params,{unitId:d}=c;Array.from((s=(o=this._domLayerMap.get(d))==null?void 0:o.keys())!=null?s:[]).forEach(l=>{n(d,l)})}else if(e.id===D.SetFrozenMutation.id){const{unitId:c,subUnitId:d}=e.params;n(c,d)}}))}_getPosition(r,n){var u;const{startX:e,endX:o,startY:s,endY:c}=r,d=(u=this._renderManagerService.getRenderById(n))==null?void 0:u.with(U.ISheetSelectionRenderService);if(d==null)return;const h=d.getSelectionCellByPosition(e,s);if(h==null)return;const l={column:h.actualColumn,columnOffset:e-h.startX,row:h.actualRow,rowOffset:s-h.startY},a=d.getSelectionCellByPosition(o,c);if(a==null)return;const g={column:a.actualColumn,columnOffset:o-a.startX,row:a.actualRow,rowOffset:c-a.startY};return{from:l,to:g}}_featureUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(r=>{r.forEach(n=>{const e=this._drawingManagerService.getDrawingByParam(n);if(!e||e.drawingType!==E.DrawingTypeEnum.DRAWING_DOM&&e.drawingType!==E.DrawingTypeEnum.DRAWING_CHART)return;const o={...e.transform};this._transformChange$.next({id:n.drawingId,value:o})})}))}_deleteListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(r=>{r.forEach(n=>{this._removeDom(n.drawingId)})}))}updateFloatDomProps(r,n,e,o){const s=this._domLayerInfoMap.get(e),c=this._getSceneAndTransformerByDrawingSearch(r);if(s&&c){const{scene:d}=c,h=E.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:n,drawingId:e}),l=d.getObject(h);l&&l instanceof N.Rect&&l.setProps(o)}}addFloatDomToPosition(r,n){const e=D.getSheetCommandTarget(this._univerInstanceService,{unitId:r.unitId,subUnitId:r.subUnitId});if(!e)throw new Error("cannot find current target!");const{unitId:o,subUnitId:s}=e,{initPosition:c,componentKey:d,data:h,allowTransform:l=!0}=r,a=n!=null?n:m.generateRandomId(),g=this._getPosition(c,o);if(g==null)return;this._ensureMap(o,s).set(a,r);const f={unitId:o,subUnitId:s,drawingId:a,drawingType:r.type||E.DrawingTypeEnum.DRAWING_DOM,componentKey:d,sheetTransform:g,transform:{left:c.startX,top:c.startY,width:c.endX-c.startX,height:c.endY-c.startY},data:h,allowTransform:l};return this._commandService.executeCommand(oe.id,{unitId:o,drawings:[f]}),this._add$.next({unitId:o,subUnitId:s,id:a}),{id:a,dispose:()=>{this._removeDom(a,!0)}}}_removeDom(r,n=!1){const e=this._domLayerInfoMap.get(r);if(!e)return;const{unitId:o,subUnitId:s}=e;this._domLayerInfoMap.delete(r),e.dispose.dispose();const c=this._getSceneAndTransformerByDrawingSearch(o);if(c&&c.scene.removeObject(e.rect),n){this._ensureMap(o,s).delete(r);const h=this._drawingManagerService.getDrawingByParam({unitId:o,subUnitId:s,drawingId:r});if(!h)return;const l=this._sheetDrawingService.getBatchRemoveOp([h]),{redo:a,objects:g}=l;this._commandService.syncExecuteCommand(p.SetDrawingApplyMutation.id,{unitId:o,subUnitId:s,op:a,objects:g,type:p.DrawingApplyType.REMOVE})}}addHook(r){return this._hooks.push(r),{dispose:()=>{const n=this._hooks.findIndex(e=>e===r);this._hooks.splice(n,1)}}}};exports.SheetCanvasFloatDomManagerService=_n([ee(0,m.Inject(N.IRenderManagerService)),ee(1,m.IUniverInstanceService),ee(2,m.Inject(m.ICommandService)),ee(3,E.IDrawingManagerService),ee(4,m.Inject(k.CanvasFloatDomService)),ee(5,p.ISheetDrawingService),ee(6,m.Inject(m.LifecycleService))],exports.SheetCanvasFloatDomManagerService);var Xe=Object.defineProperty,In=Object.getOwnPropertyDescriptor,Cn=(i,t,r)=>t in i?Xe(i,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):i[t]=r,yn=(i,t,r,n)=>{for(var e=n>1?void 0:n?In(t,r):t,o=i.length-1,s;o>=0;o--)(s=i[o])&&(e=(n?s(t,r,e):s(e))||e);return n&&e&&Xe(t,r,e),e},Me=(i,t)=>(r,n)=>t(r,n,i),Ke=(i,t,r)=>Cn(i,typeof t!="symbol"?t+"":t,r);const Mn="SHEET_IMAGE_UI_PLUGIN";exports.UniverSheetsDrawingUIPlugin=class extends m.Plugin{constructor(t=et,r,n,e){super(),this._config=t,this._injector=r,this._renderManagerService=n,this._configService=e;const{menu:o,...s}=this._config;o&&this._configService.setConfig("menu",o,{merge:!0}),this._configService.setConfig(Qe,s)}onStarting(){m.registerDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService],[pe],[he],[Se],[we],[fe]]),m.touchDependencies(this._injector,[[exports.SheetCanvasFloatDomManagerService]])}onReady(){m.touchDependencies(this._injector,[[fe]])}onRendered(){this._registerRenderModules(),m.touchDependencies(this._injector,[[we],[Se],[pe]])}onSteady(){this._injector.get(he)}_registerRenderModules(){[[me],[Te],[Re]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(m.UniverInstanceType.UNIVER_SHEET,t))})}};Ke(exports.UniverSheetsDrawingUIPlugin,"type",m.UniverInstanceType.UNIVER_SHEET);Ke(exports.UniverSheetsDrawingUIPlugin,"pluginName",Mn);exports.UniverSheetsDrawingUIPlugin=yn([m.DependentOn(E.UniverDrawingPlugin,te.UniverDrawingUIPlugin,p.UniverSheetsDrawingPlugin),Me(1,m.Inject(m.Injector)),Me(2,N.IRenderManagerService),Me(3,m.IConfigService)],exports.UniverSheetsDrawingUIPlugin);exports.ClearSheetDrawingTransformerOperation=x;exports.DeleteDrawingsCommand=Oe;exports.EditSheetDrawingOperation=Ee;exports.GroupSheetDrawingCommand=Pe;exports.IMAGE_MENU_ID=Ne;exports.InsertFloatImageCommand=_e;exports.InsertSheetDrawingCommand=oe;exports.MoveDrawingsCommand=ne;exports.RemoveSheetDrawingCommand=ie;exports.SetDrawingArrangeCommand=Ae;exports.SetSheetDrawingCommand=se;exports.SidebarSheetDrawingOperation=be;exports.UngroupSheetDrawingCommand=Ue;
|