@univerjs/drawing-ui 0.18.0 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/index.js +1 -32
- package/lib/es/index.js +1 -32
- package/lib/index.js +1 -32
- package/lib/umd/index.js +1 -32
- package/package.json +9 -9
package/lib/cjs/index.js
CHANGED
|
@@ -1,32 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/drawing`),n=require(`@univerjs/engine-render`),r=require(`@univerjs/icons`),i=require(`@univerjs/ui`),a=require(`rxjs`),o=require(`@univerjs/design`),s=require(`react`),c=require(`react/jsx-runtime`),l=function(e){return e.default=`0`,e.left=`1`,e.center=`2`,e.right=`3`,e.top=`4`,e.middle=`5`,e.bottom=`6`,e.horizon=`7`,e.vertical=`8`,e}({});const u={id:`sheet.operation.set-image-align`,type:e.CommandType.OPERATION,handler:(e,t)=>!0},d={id:`sheet.operation.set-drawing-align-left`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.left})},f={id:`sheet.operation.set-drawing-align-center`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.center})},p={id:`sheet.operation.set-drawing-align-right`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.right})},m={id:`sheet.operation.set-drawing-align-top`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.top})},h={id:`sheet.operation.set-drawing-align-middle`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.middle})},g={id:`sheet.operation.set-drawing-align-bottom`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.bottom})},_={id:`sheet.operation.set-drawing-align-horizon`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.horizon})},v={id:`sheet.operation.set-drawing-align-vertical`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.vertical})},y={id:`drawing.operation.set-drawing-arrange`,type:e.CommandType.OPERATION,handler:(e,n)=>{let r=e.get(t.IDrawingManagerService),{arrangeType:i}=n,a=n.drawings||r.getFocusDrawings(),{unitId:o,subUnitId:s}=a[0],c=a.map(e=>e.drawingId);return r.featurePluginOrderUpdateNotification({unitId:o,subUnitId:s,drawingIds:c,arrangeType:i}),!0}},b={id:`drawing.operation.set-drawing-arrange-front`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(y.id,{arrangeType:e.ArrangeTypeEnum.front})},x={id:`drawing.operation.set-drawing-arrange-forward`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(y.id,{arrangeType:e.ArrangeTypeEnum.forward})},S={id:`drawing.operation.set-drawing-arrange-back`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(y.id,{arrangeType:e.ArrangeTypeEnum.back})},C={id:`drawing.operation.set-drawing-arrange-backward`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(y.id,{arrangeType:e.ArrangeTypeEnum.backward})},w=[e.DrawingTypeEnum.DRAWING_IMAGE,e.DrawingTypeEnum.DRAWING_SHAPE,e.DrawingTypeEnum.DRAWING_GROUP],T={id:`drawing.operation.set-drawing-group`,type:e.CommandType.OPERATION,handler:(r,i)=>{let a=r.get(t.IDrawingManagerService),o=i.drawings||a.getFocusDrawings();if(o.length<2||!o.every(e=>w.includes(e.drawingType)))return!1;let{unitId:s,subUnitId:c}=o[0],l=(0,e.generateRandomId)(10),u=(0,n.getGroupState)(0,0,o.map(e=>e.transform||{})),d={unitId:s,subUnitId:c,drawingId:l,drawingType:e.DrawingTypeEnum.DRAWING_GROUP,transform:u,groupBaseBound:{left:u.left,top:u.top,width:u.width,height:u.height}},f=o.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t},groupId:l}});return a.featurePluginGroupUpdateNotification([{parent:d,children:f}]),!0}},E={id:`drawing.operation.cancel-drawing-group`,type:e.CommandType.OPERATION,handler:(r,i)=>{let a=r.get(t.IDrawingManagerService),o=(i.drawings||a.getFocusDrawings()).map(t=>{if(t.drawingType!==e.DrawingTypeEnum.DRAWING_GROUP)return null;let{unitId:r,subUnitId:i,drawingId:o,transform:s={width:0,height:0},groupBaseBound:c}=t;if(s===null)return null;let l=a.getDrawingsByGroup({unitId:r,subUnitId:i,drawingId:o});return l.length===0?null:{parent:t,children:l.map(e=>{let{transform:t}=e,{unitId:r,subUnitId:i,drawingId:a}=e,o=(0,n.transformObjectOutOfGroup)(t||{},s,s.width||0,s.height||0,c);return{unitId:r,subUnitId:i,drawingId:a,transform:{...t,...o},groupId:void 0}})}}).filter(e=>e!==null);return o.length===0?!1:(a.featurePluginUngroupUpdateNotification(o),!0)}},D={id:`sheet.operation.open-image-crop`,type:e.CommandType.OPERATION,handler:(e,t)=>!0},O={id:`sheet.operation.close-image-crop`,type:e.CommandType.OPERATION,handler:(e,t)=>!0};let k=function(e){return e.FREE=`0`,e.R1_1=`1`,e.R16_9=`2`,e.R9_16=`3`,e.R5_4=`4`,e.R4_5=`5`,e.R4_3=`6`,e.R3_4=`7`,e.R3_2=`8`,e.R2_3=`9`,e}({});const A={id:`sheet.operation.Auto-image-crop`,type:e.CommandType.OPERATION,handler:(e,t)=>!0},j={id:`sheet.operation.image-reset-size`,type:e.CommandType.OPERATION,handler:(e,t)=>!0};function M(e,r,i,a){let o=a.getDrawingByParam(e);if(o==null)return;let s=(0,t.getDrawingShapeKeyByDrawingSearch)(e),c=i.getObjectIncludeInGroup(s);if(c&&!(c instanceof n.Group))return;if(c!=null){let e=c.getObjects();for(let t of e)if(t.oKey===r.oKey)return;c.addObject(r);return}let l=new n.DrawingGroupObject(s);i.addObject(l,n.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(l),l.addObject(r);let{transform:u,groupBaseBound:d}=o;d&&l.setBaseBound(d),o.groupId&&(l.isInGroup=!0,M({drawingId:o.groupId,unitId:e.unitId,subUnitId:e.subUnitId},l,i,a)),u&&l.transformByState({left:u.left,top:u.top,angle:u.angle,width:u.width,height:u.height})}function N(t,n){let r=n?t.getUnit(n):t.getFocusedUnit();if(r==null)return;let i=r.getUnitId(),a;if(r.type===e.UniverInstanceType.UNIVER_SHEET){var o;a=(o=r.getActiveSheet())==null?void 0:o.getSheetId()}else (r.type===e.UniverInstanceType.UNIVER_DOC||r.type===e.UniverInstanceType.UNIVER_SLIDE)&&(a=i);return{unitId:i,subUnitId:a,current:r}}var P=`@univerjs/drawing-ui`,F=`0.18.0`;const I=`drawing-ui.config`;Symbol(I);const ee={},L=e=>{let n=e.get(t.IDrawingManagerService);return new a.Observable(e=>{let t=t=>{if(!t||t.length===0||t.length<2)return e.next(!0);e.next(!1)},r=n.focus$.subscribe(n=>{if(!n||n.length===0)return e.next(!0);t(n)});return t(n.getFocusDrawings()),()=>r.unsubscribe()})},R=`contextMenu.drawing-align`;function te(e){return{id:R,type:i.MenuItemType.SUBITEMS,icon:`HorizontallyIcon`,title:`image-panel.align.title`,hidden$:L(e)}}function z(){return{id:d.id,type:i.MenuItemType.BUTTON,icon:`LeftJustifyingIcon`,title:`image-panel.align.left`}}function B(){return{id:f.id,type:i.MenuItemType.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.center`}}function ne(){return{id:p.id,type:i.MenuItemType.BUTTON,icon:`RightJustifyingIcon`,title:`image-panel.align.right`}}function re(){return{id:m.id,type:i.MenuItemType.BUTTON,icon:`AlignTopIcon`,title:`image-panel.align.top`}}function ie(){return{id:h.id,type:i.MenuItemType.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.middle`}}function ae(){return{id:g.id,type:i.MenuItemType.BUTTON,icon:`AlignBottomIcon`,title:`image-panel.align.bottom`}}function oe(){return{id:_.id,type:i.MenuItemType.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.horizon`}}function se(){return{id:v.id,type:i.MenuItemType.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.vertical`}}const ce=`contextMenu.drawing-arrange`;function le(){return{id:ce,type:i.MenuItemType.SUBITEMS,icon:`TopmostIcon`,title:`image-panel.arrange.title`}}function ue(){return{id:b.id,type:i.MenuItemType.BUTTON,icon:`TopmostIcon`,title:`image-panel.arrange.front`}}function de(){return{id:x.id,type:i.MenuItemType.BUTTON,icon:`MoveUpIcon`,title:`image-panel.arrange.forward`}}function fe(){return{id:S.id,type:i.MenuItemType.BUTTON,icon:`BottomIcon`,title:`image-panel.arrange.back`}}function pe(){return{id:C.id,type:i.MenuItemType.BUTTON,icon:`MoveDownIcon`,title:`image-panel.arrange.backward`}}const me=(n,r)=>{let i=n.get(t.IDrawingManagerService);return new a.Observable(t=>{let n=n=>{if(!n||n.length===0)return t.next(!0);if(r===`group`){if(n.length<2||!n.every(e=>w.includes(e.drawingType)))return t.next(!0)}else if(r===`unGroup`){if(n.filter(t=>t.drawingType===e.DrawingTypeEnum.DRAWING_GROUP).length===0)return t.next(!0)}else if(!n.every(e=>w.includes(e.drawingType)))return t.next(!0);t.next(!1)},a=i.focus$.subscribe(e=>{if(!e||e.length===0)return t.next(!0);n(e)});return n(i.getFocusDrawings()),()=>a.unsubscribe()})},he=`contextMenu.drawing-group`;function ge(e){return{id:he,type:i.MenuItemType.SUBITEMS,icon:`GroupIcon`,title:`image-panel.group.title`,hidden$:me(e)}}function _e(e){return{id:T.id,type:i.MenuItemType.BUTTON,icon:`GroupIcon`,title:`image-panel.group.group`,disabled$:me(e,`group`)}}function ve(e){return{id:E.id,type:i.MenuItemType.BUTTON,icon:`UngroupIcon`,title:`image-panel.group.unGroup`,disabled$:me(e,`unGroup`)}}const ye={[i.ContextMenuPosition.DRAWING]:{[i.ContextMenuGroup.OTHERS]:{[he]:{order:1,menuItemFactory:ge,[T.id]:{order:0,menuItemFactory:_e},[E.id]:{order:1,menuItemFactory:ve}},[ce]:{order:2,menuItemFactory:le,[b.id]:{order:0,menuItemFactory:ue},[x.id]:{order:1,menuItemFactory:de},[S.id]:{order:2,menuItemFactory:fe},[C.id]:{order:3,menuItemFactory:pe}},[R]:{order:3,menuItemFactory:te,[d.id]:{order:0,menuItemFactory:z},[f.id]:{order:1,menuItemFactory:B},[p.id]:{order:2,menuItemFactory:ne},[m.id]:{order:3,menuItemFactory:re},[h.id]:{order:4,menuItemFactory:ie},[g.id]:{order:5,menuItemFactory:ae},[_.id]:{order:6,menuItemFactory:oe},[v.id]:{order:7,menuItemFactory:se}}}}},be=`COMPONENT_IMAGE_POPUP_MENU`;function xe(t){var n;let{popup:a}=t,l=a==null||(n=a.extraProps)==null?void 0:n.menuItems;if(!l)return null;let u=(0,i.useDependency)(e.ICommandService),d=(0,i.useDependency)(e.LocaleService),[f,p]=(0,s.useState)(!1),[m,h]=(0,s.useState)(!1),g=()=>{h(!0)},_=()=>{h(!1)},v=e=>{p(e)},y=e=>{u.executeCommand(e.commandId,e.commandParams),p(!1)},b=f||m;return(0,c.jsx)(`div`,{onMouseEnter:g,onMouseLeave:_,children:(0,c.jsx)(o.DropdownMenu,{align:`start`,items:l.filter(e=>!e.disable).map(e=>({type:`item`,children:d.t(e.label),onSelect:()=>y(e)})),open:f,onOpenChange:v,children:(0,c.jsxs)(`div`,{className:(0,o.clsx)(`
|
|
2
|
-
univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1
|
|
3
|
-
hover:univer-bg-gray-100
|
|
4
|
-
dark:hover:!univer-bg-gray-800
|
|
5
|
-
`,o.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":f,"univer-bg-white dark:!univer-bg-gray-900":!f}),children:[(0,c.jsx)(r.AutofillDoubleIcon,{className:`
|
|
6
|
-
univer-fill-primary-600 univer-text-gray-900
|
|
7
|
-
dark:!univer-text-white
|
|
8
|
-
`}),b&&(0,c.jsx)(r.MoreDownIcon,{className:`dark:!univer-text-white`})]})})})}function V(e,t){return function(n,r){t(n,r,e)}}function H(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let U=class extends e.Disposable{constructor(e,t,n){super(),this._componentManager=e,this._commandService=t,this._menuManagerService=n,this._init()}_init(){this._initMenus(),this._initCommands(),this._initComponents()}_initMenus(){this._menuManagerService.mergeMenu(ye)}_initCommands(){[D,O,j,u,d,f,p,m,h,g,_,v,A,T,E,y,b,x,S,C].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initComponents(){[[be,xe],[`BottomIcon`,r.BottomIcon],[`GroupIcon`,r.GroupIcon],[`MoveDownIcon`,r.MoveDownIcon],[`MoveUpIcon`,r.MoveUpIcon],[`TopmostIcon`,r.TopmostIcon],[`UngroupIcon`,r.UngroupIcon]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};U=H([V(0,(0,e.Inject)(i.ComponentManager)),V(1,e.ICommandService),V(2,i.IMenuManagerService)],U);function W(t,n){let r=[];return t.forEach(t=>{let{oKey:i,left:a,top:o,height:s,width:c,angle:l}=t,u=n.getDrawingOKey(i);if(u==null)return r.push(null),!0;let{unitId:d,subUnitId:f,drawingId:p,drawingType:m}=u,h={unitId:d,subUnitId:f,drawingId:p,drawingType:m,transform:{left:a,top:o,height:s,width:c,angle:l}};m===e.DrawingTypeEnum.DRAWING_IMAGE&&(h.srcRect=t.srcRect),r.push(h)}),r}function G(e){"@babel/helpers - typeof";return G=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},G(e)}function Se(e,t){if(G(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(G(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ce(e){var t=Se(e,`string`);return G(t)==`symbol`?t:t+``}function K(e,t,n){return(t=Ce(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let q=class extends e.Disposable{constructor(e,t,n,r){super(),this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._drawingManagerService=r,K(this,`_sceneListenerOnDrawingMap`,new WeakSet),this._initialize()}dispose(){super.dispose()}_initialize(){this._recoveryImages(),this._drawingAddListener(),this._drawingRemoveListener(),this._drawingUpdateListener(),this._commandExecutedListener(),this._drawingArrangeListener(),this._drawingGroupListener(),this._drawingRefreshListener(),this._drawingVisibleListener()}_recoveryImages(){let e=this._drawingManagerService.drawingManagerData,t=N(this._currentUniverService);if(t==null)return;let{unitId:n,subUnitId:r}=t;Object.keys(e).forEach(t=>{Object.keys(e[t]).forEach(i=>{let a=e[t][i].data;a==null||t!==n||i!==r||Object.keys(a).forEach(e=>{a[e]&&this._insertDrawing([{unitId:t,subUnitId:i,drawingId:e}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===u.id){let t=e.params;if(t==null)return;this._drawingAlign(t)}}))}_drawingGroupListener(){this.disposeWithMe(this._drawingManagerService.group$.subscribe(e=>{this._groupDrawings(e)})),this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe(e=>{this._ungroupDrawings(e)}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_groupDrawings(e){e.forEach(e=>{this._groupDrawing(e)})}_groupDrawing(e){let{parent:r,children:i}=e,{unitId:a,subUnitId:o,drawingId:s}=r,c=this._getSceneAndTransformerByDrawingSearch(r.unitId);if(c==null)return;let{scene:l,transformer:u}=c;this._commandService.syncExecuteCommand(O.id);let d=[];if(i.forEach(e=>{let r=(0,t.getDrawingShapeKeyByDrawingSearch)(e),i=l.getObjectIncludeInGroup(r);if(i==null||d.includes(i))return;d.push(i);let{transform:a}=e;a!=null&&(i.classType===n.RENDER_CLASS_TYPE.GROUP?i.transformByState({left:a.left,top:a.top}):i.transformByState(a))}),d.length===0)return;let f=new n.DrawingGroupObject((0,t.getDrawingShapeKeyByDrawingSearch)({unitId:a,subUnitId:o,drawingId:s}));l.addObject(f,n.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(f),f.addObjects(...d),r.groupBaseBound&&f.setBaseBound(r.groupBaseBound),r.groupId&&(f.isInGroup=!0,M({drawingId:r.groupId,unitId:a,subUnitId:o},f,l,this._drawingManagerService)),r.transform&&f.transformByState({left:r.transform.left,top:r.transform.top,width:r.transform.width,height:r.transform.height,angle:r.transform.angle}),u.clearSelectedObjects(),u.setSelectedControl(f)}_ungroupDrawings(e){e.forEach(e=>{this._ungroupDrawing(e)})}_ungroupDrawing(e){let{parent:r,children:i}=e,a=this._getSceneAndTransformerByDrawingSearch(r.unitId);if(a==null)return;let{scene:o,transformer:s}=a;i.forEach(e=>{let r=(0,t.getDrawingShapeKeyByDrawingSearch)(e),i=o.getObjectIncludeInGroup(r);if(i==null)return!0;if(i==null)return;let{transform:a}=e;a!=null&&(i.classType===n.RENDER_CLASS_TYPE.GROUP?i.transformByState({left:a.left,top:a.top}):i.transformByState(a))});let c=(0,t.getDrawingShapeKeyByDrawingSearch)(r),l=o.getObject(c),{width:u,height:d}=l;l.getObjects().forEach(e=>{l.removeSelfObjectAndTransform(e.oKey,u,d)}),l.dispose(),s.clearSelectedObjects()}_drawingAlign(e){let{alignType:t}=e,n=e.drawings||this._drawingManagerService.getFocusDrawings();if(t===l.default)return;let r=[],i=1/0,a=1/0,o=-1/0,s=-1/0,c=0;n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:l,drawingType:u}=e,d=this._drawingManagerService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:l});if(d==null||d.transform==null)return;r.push({unitId:t,subUnitId:n,drawingId:l,drawingType:u,transform:d.transform});let{left:f=0,top:p=0,width:m=0,height:h=0}=d.transform;i=Math.min(i,f),a=Math.min(a,p),o=Math.max(o,f+m),s=Math.max(s,p+h),c++}),c!==0&&(this._sortDrawingTransform(r,t),this._applyAlignType(r,t,i,a,o,s,c))}_applyAlignType(e,t,n,r,i,a,o){let s=Math.round((i-n)/o*10)/10,c=Math.round((a-r)/o*10)/10,u=[],d=this._getSceneAndTransformerByDrawingSearch(e[0].unitId);if(d==null)return;let{scene:f,transformer:p}=d;e.forEach((e,o)=>{let{unitId:d,subUnitId:f,drawingId:p,transform:m,drawingType:h}=e,{left:g=0,top:_=0,width:v=0,height:y=0}=m,b=g,x=_;switch(t){case l.left:b=n;break;case l.center:b=n+(i-n)/2-v/2;break;case l.right:b=i-v;break;case l.top:x=r;break;case l.middle:x=r+(a-r)/2-y/2;break;case l.bottom:x=a-y;break;case l.horizon:b=n+s*o;break;case l.vertical:x=r+c*o;break;default:break}(b!==g||x!==_)&&u.push({unitId:d,subUnitId:f,drawingId:p,drawingType:h,transform:{left:b,top:x}})}),this._drawingManagerService.featurePluginUpdateNotification(u),p.refreshControls().changeNotification()}_sortDrawingTransform(e,t){e.sort((e,n)=>{let r=e.transform,i=n.transform,{left:a=0,top:o=0,width:s=0,height:c=0}=r,{left:u=0,top:d=0,width:f=0,height:p=0}=i;switch(t){case l.left:return a-u;case l.center:return a+s/2-(u+f/2);case l.right:return a+s-(u+f);case l.top:return o-d;case l.middle:return o+c/2-(d+p/2);case l.bottom:return o+c-(d+p);case l.horizon:return a+s/2-(u+f/2);case l.vertical:return o+c/2-(d+p/2);default:return 0}})}_drawingArrangeListener(){this.disposeWithMe(this._drawingManagerService.order$.subscribe(e=>{this._drawingArrange(e)}))}_drawingArrange(e){let{unitId:n,subUnitId:r,drawingIds:i}=e,a=this._getSceneAndTransformerByDrawingSearch(n);if(a==null)return;let{scene:o}=a;i.forEach(e=>{let i=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:r,drawingId:e}),a=o.fuzzyMathObjects(i,!0);if(a==null||a.length===0)return;let s=this._drawingManagerService.getDrawingOrder(n,r).indexOf(e);for(let e of a)e.setProps({zIndex:s}),e.makeDirty()})}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{this._insertDrawing(e)}))}_insertDrawing(e){let t=[];e.forEach(e=>{let{unitId:n}=e;if(this._drawingManagerService.getDrawingByParam(e)==null)return;let r=this._getSceneAndTransformerByDrawingSearch(n);if(r==null)return;let{scene:i}=r;t.includes(i)||t.push(i)}),t.forEach(e=>{this._sceneListenerOnDrawingMap.has(e)||(this._addListenerOnDrawing(e),this._sceneListenerOnDrawingMap.add(e))})}_drawingRemoveListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:n,subUnitId:r,drawingId:i}=e,a=this._getSceneAndTransformerByDrawingSearch(n);if(a==null)return;let{scene:o}=a,s=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:r,drawingId:i}),c=o.fuzzyMathObjects(s,!0);if(c.length>0){var l;for(let e of c)e.dispose();(l=o.getTransformer())==null||l.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{var n;let{unitId:r,subUnitId:i,drawingId:a}=e,o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let{transform:s,drawingType:c}=o,l=this._getSceneAndTransformerByDrawingSearch(r);if(l==null)return;let{scene:u,transformer:d}=l;if(s==null)return!0;let{left:f=0,top:p=0,width:m=0,height:h=0,angle:g=0,flipX:_=!1,flipY:v=!1,skewX:y=0,skewY:b=0}=s,x=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:r,subUnitId:i,drawingId:a}),S=u.getObject(x);if(S==null)return!0;S.transformByState({left:f,top:p,width:m,height:h,angle:g,flipX:_,flipY:v,skewX:y,skewY:b}),(n=u.getTransformer())==null||n.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(e=>{e.forEach(e=>{let{unitId:n,subUnitId:r,drawingId:i}=e,a=this._getSceneAndTransformerByDrawingSearch(n);if(a==null)return;let o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let{transform:s}=o,{scene:c}=a,l=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:r,drawingId:i}),u=c.getObject(l);if(u==null||s==null)return!0;let{left:d=0,top:f=0,width:p=0,height:m=0,angle:h=0,flipX:g=!1,flipY:_=!1,skewX:v=0,skewY:y=0}=s;u.transformByState({left:d,top:f,width:p,height:m,angle:h,flipX:g,flipY:_,skewX:v,skewY:y})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(e=>{e.forEach(e=>{let{unitId:n,subUnitId:r,drawingId:i,visible:a}=e,o=this._getSceneAndTransformerByDrawingSearch(n);if(o==null)return;let{scene:s}=o,c=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:r,drawingId:i}),l=s.getObject(c);if(l==null)return!0;a?l.show():l.hide()})}))}_filterUpdateParams(t,n){return t.filter((t,r)=>{if(t==null)return!1;let{transform:i}=t;return(0,e.checkIfMove)(i,n==null?void 0:n[r])})}_addListenerOnDrawing(r){let i=r.getTransformerByCreate(),a=null;this.disposeWithMe((0,e.toDisposable)(i.changeStart$.subscribe(e=>{let{objects:r}=e,i=Array.from(r.values()),o=[];a=i.map(e=>{let{left:t,top:r,height:i,width:a,angle:s,oKey:c,isInGroup:l}=e,u=this._drawingManagerService.getDrawingOKey(c);if(l||e instanceof n.Group){let t=e.ancestorGroup;if(t==null&&e instanceof n.Group&&(t=e),t==null)return null;let r=this._drawingManagerService.getDrawingOKey(t.oKey);if(r){let{unitId:e,subUnitId:n,drawingId:i}=r;o.push({unitId:e,subUnitId:n,drawingId:i});let{left:a,top:s,height:c,width:l,angle:u}=t;return{left:a,top:s,height:c,width:l,angle:u}}}else if(u!=null){let{unitId:e,subUnitId:n,drawingId:c}=u;return o.push({unitId:e,subUnitId:n,drawingId:c}),{left:t,top:r,height:i,width:a,angle:s}}return null}).filter(e=>e!=null),o.length>0?this._commandService.syncExecuteCommand(t.SetDrawingSelectedOperation.id,o):this._commandService.syncExecuteCommand(t.SetDrawingSelectedOperation.id,[])}))),this.disposeWithMe((0,e.toDisposable)(i.changeEnd$.subscribe(e=>{let{objects:t}=e,n=this._filterUpdateParams(W(t,this._drawingManagerService),a);n.length>0&&this._drawingManagerService.featurePluginUpdateNotification(n)})))}};q=H([V(0,e.IUniverInstanceService),V(1,e.ICommandService),V(2,n.IRenderManagerService),V(3,t.IDrawingManagerService)],q);var J=function(e){return e[e.RECT=0]=`RECT`,e[e.PATH=1]=`PATH`,e}(J||{}),Y=class extends n.Shape{constructor(e,t){t==null&&(t={}),t.transformerConfig={keepRatio:!1,isCropper:!0,anchorFill:`rgb(0, 0, 0)`,anchorStroke:`rgb(255, 255, 255)`,anchorSize:24},super(e,t),K(this,`_srcRect`,void 0),K(this,`_prstGeom`,void 0),K(this,`_applyTransform`,void 0),K(this,`_dragPadding`,8),K(this,`_cacheCanvas`,void 0),t!=null&&t.srcRect&&(this._srcRect=t.srcRect),t!=null&&t.prstGeom&&(this._prstGeom=t.prstGeom),t!=null&&t.applyTransform&&(this._applyTransform=t.applyTransform),t!=null&&t.dragPadding&&(this._dragPadding=t.dragPadding),this._applyProps()}refreshSrcRect(e,t){this._srcRect=e,this._applyTransform=t,this._applyProps()}get srcRect(){return this._srcRect}dispose(){var e;super.dispose(),(e=this._cacheCanvas)==null||e.dispose(),this._srcRect=null}isHit(e){let t=this.getInverseCoord(e);return t.x>=-this.strokeWidth/2&&t.x<=this.width+this.strokeWidth/2&&t.y>=-this.strokeWidth/2&&t.y<=this.height+this.strokeWidth/2&&!this._inSurround(t)}_inSurround(e){let t=this._dragPadding;return e.x>=t-this.strokeWidth/2&&e.x<=this.width+this.strokeWidth/2-t&&e.y>=t-this.strokeWidth/2&&e.y<=this.height+this.strokeWidth/2-t}render(e,t){return this.visible?(e.save(),this._draw(e),e.restore(),this.makeDirty(!1),this):(this.makeDirty(!1),this)}_draw(e){var t,r;let{width:i,height:a}=this.getScene().getEngine();this._initialCacheCanvas(),(t=this._cacheCanvas)==null||t.clear();let o=(r=this._cacheCanvas)==null?void 0:r.getContext();o!=null&&(o.save(),n.Rect.drawWith(o,{left:0,top:0,width:i,height:a,fill:`rgba(0, 0, 0, 0.5)`}),o.setTransform(e.getTransform()),this._clipForApplyObject(o),this._applyCache(e),o.restore())}_clipForApplyObject(e){let t=J.RECT;if(this._prstGeom!=null&&(t=J.PATH),e.globalCompositeOperation=`destination-out`,e.beginPath(),t===J.RECT){let t=this.transform.getMatrix();e.transform(t[0],t[1],t[2],t[3],t[4],t[5]),e.rect(0,0,this.width,this.height),e.fill()}}_applyProps(){if(this._applyTransform==null)return;let e=0,t=0,n=0,r=0,{left:i=0,top:a=0,width:o=0,height:s=0,angle:c}=this._applyTransform;if(this._srcRect!=null){let{left:i=0,top:a=0,right:o=0,bottom:s=0}=this._srcRect;e=i,t=a,n=o,r=s}let l=i+e,u=a+t;this.transformByState({left:l,top:u,width:i+o-n-l,height:a+s-r-u,angle:c})}_applyCache(e){if(!e||this._cacheCanvas==null)return;let t=this._cacheCanvas.getContext();t.save(),e.save(),e.setTransform(1,0,0,1,0,0),t.setTransform(1,0,0,1,0,0),e.drawImage(this._cacheCanvas.getCanvasEle(),0,0),e.restore(),t.restore()}_initialCacheCanvas(){if(this._cacheCanvas!=null)return;let e=this.getScene();if(e==null)return;this._cacheCanvas=new n.Canvas;let t=e.getEngine();this._cacheCanvas.setSize(t.width,t.height),t.onTransformChange$.subscribeEvent(()=>{var e;(e=this._cacheCanvas)==null||e.setSize(t.width,t.height),this.makeDirty(!0)})}};let X=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._commandService=e,this._drawingManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._messageService=i,this._localeService=a,K(this,`_sceneListenerOnImageMap`,new WeakSet),this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==A.id)return;let r=e.params;if(r==null)return;let{cropType:i}=r,a=this._drawingManagerService.getFocusDrawings();if(a.length!==1)return;let{unitId:s,subUnitId:c,drawingId:l}=a[0],u=this._renderManagerService.getRenderById(s),d=u==null?void 0:u.scene;if(d==null)return!0;this._searchCropObject(d)!=null&&this._commandService.syncExecuteCommand(O.id,{isAuto:!0});let f=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:s,subUnitId:c,drawingId:l}),p=d.getObject(f);if(!(p instanceof n.Image)){this._messageService.show({type:o.MessageType.Error,content:this._localeService.t(`image-cropper.error`)});return}p!=null&&(this._updateCropperObject(i,p),this._commandService.executeCommand(D.id,{unitId:s,subUnitId:c,drawingId:l}))}))}_calculateSrcRectByRatio(e,t,r,i,a,o){let s=r/i,c=a/o,l=r,u=i;s>c?l=i*c:u=r/c;let d=(r-l)/2,f=(i-u)/2;return{left:(0,n.precisionTo)(d,1),top:(0,n.precisionTo)(f,1),right:(0,n.precisionTo)(r-(d+l),1),bottom:(0,n.precisionTo)(i-(f+u),1)}}_updateCropperObject(e,t){let{left:n,top:r,width:i,height:a}=t.calculateTransformWithSrcRect(),o;switch(e){case k.R1_1:o=this._calculateSrcRectByRatio(n,r,i,a,1,1);break;case k.R16_9:o=this._calculateSrcRectByRatio(n,r,i,a,16,9);break;case k.R9_16:o=this._calculateSrcRectByRatio(n,r,i,a,9,16);break;case k.R5_4:o=this._calculateSrcRectByRatio(n,r,i,a,5,4);break;case k.R4_5:o=this._calculateSrcRectByRatio(n,r,i,a,4,5);break;case k.R4_3:o=this._calculateSrcRectByRatio(n,r,i,a,4,3);break;case k.R3_4:o=this._calculateSrcRectByRatio(n,r,i,a,3,4);break;case k.R3_2:o=this._calculateSrcRectByRatio(n,r,i,a,3,2);break;case k.R2_3:o=this._calculateSrcRectByRatio(n,r,i,a,2,3);break;case k.FREE:default:break}if(o==null)return;t.setSrcRect(o);let{left:s=0,top:c=0,bottom:l=0,right:u=0}=o;t.transformByStateCloseCropper({left:n+s,top:r+c,width:i-u-s,height:a-l-c})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==D.id)return;let r=e.params;if(r==null)return;let{unitId:i,subUnitId:a,drawingId:s}=r,c=this._renderManagerService.getRenderById(i),l=c==null?void 0:c.scene;if(l==null)return!0;if(this._sceneListenerOnImageMap.has(l)||(this._addListenerOnImage(l),this._sceneListenerOnImageMap.add(l)),this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:a,drawingId:s})==null)return;let u=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:s}),d=l.getObject(u);if(d==null)return;if(!(d instanceof n.Image)){this._messageService.show({type:o.MessageType.Error,content:this._localeService.t(`image-cropper.error`)});return}let f=l.getTransformer();f==null||f.clearControls();let p=new Y(`${u}-crop`,{srcRect:d.srcRect,prstGeom:d.prstGeom,applyTransform:d.calculateTransformWithSrcRect()});l.addObject(p,d.getLayerIndex()+1).attachTransformerTo(p),f==null||f.createControlForCopper(p),this._addHoverForImageCopper(p),d.openRenderByCropper(),f==null||f.refreshControls(),p.makeDirty(!0),this._commandService.syncExecuteCommand(t.SetDrawingSelectedOperation.id,[{unitId:i,subUnitId:a,drawingId:s}])}))}_searchCropObject(e){let t=e.getAllObjectsByOrder();for(let e of t)if(e instanceof Y)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==O.id)return;let t=this._univerInstanceService.getFocusedUnit();if(t==null)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n),i=r==null?void 0:r.scene;if(i==null)return!0;let a=this._searchCropObject(i);if(a==null)return;let o=this._getApplyObjectByCropObject(a);if(o==null)return;let s=i.getTransformerByCreate();s.detachFrom(a),s.clearCopperControl();let c=this._getSrcRectByTransformState(o,a),l=this._drawingManagerService.getDrawingOKey(o.oKey);if(l!=null){let{left:e,top:t,height:n,width:r}=a;this._drawingManagerService.featurePluginUpdateNotification([{...l,transform:{...l.transform,left:e,top:t,height:n,width:r},srcRect:c.srcRectAngle}])}o.setSrcRect({...c.srcRectAngle}),o.closeRenderByCropper(),o.makeDirty(!0),a==null||a.dispose()}));let t=this._univerInstanceService.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SHEET).pipe((0,a.switchMap)(e=>e?e.activeSheet$:(0,a.of)(null)));this.disposeWithMe(t.subscribe(()=>{this._commandService.syncExecuteCommand(O.id)}))}_getApplyObjectByCropObject(e){let t=e.oKey,n=t.slice(0,t.length-5),r=e.getScene();if(!r)return null;let i=r.getObject(n);return i==null?null:i}_addListenerOnImage(t){let n=t.getTransformerByCreate(),r=null;this.disposeWithMe(n.changeStart$.subscribe(e=>{let{objects:t}=e,i=t.values().next().value;if(i==null||!(i instanceof Y))return;let{left:a,top:o,height:s,width:c,angle:l}=i;r={left:a,top:o,height:s,width:c,angle:l},n.clearCopperControl()})),this.disposeWithMe(n.changeEnd$.subscribe(t=>{let{objects:i}=t,a=i.values().next().value;if(a==null||!(a instanceof Y))return;let{left:o,top:s,height:c,width:l,angle:u}=a;if(!(0,e.checkIfMove)({left:o,top:s,height:c,width:l,angle:u},r))return;let d=this._getApplyObjectByCropObject(a);if(d==null)return;let f=this._getSrcRectByTransformState(d,a);a.refreshSrcRect(f.srcRect,d.getState()),n.createControlForCopper(a)})),this._endCropListener(t)}_addHoverForImageCopper(e){this.disposeWithMe(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=n.CURSOR_TYPE.MOVE})),this.disposeWithMe(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=n.CURSOR_TYPE.DEFAULT}))}_endCropListener(e){let t=e.getTransformerByCreate();this.disposeWithMe(t.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(O.id)}))}_getSrcRectByTransformState(e,t){let{left:r,top:i,height:a,width:o,strokeWidth:s,angle:c}=t,{left:l,top:u,width:d,height:f,angle:p,strokeWidth:m}=e,h=r-l,g=i-u,_={left:h,top:g,right:d-h-o,bottom:f-g-a},v={..._};if(p!==0){let e=new n.Vector2(r+o/2,i+a/2),t=new n.Vector2(d/2+l,f/2+u),s=new n.Vector2(l,u);s.rotateByPoint((0,n.degToRad)(p),t);let c=s.clone();c.rotateByPoint((0,n.degToRad)(-p),e);let m=r-c.x,h=i-c.y;v.left=m,v.top=h,v.right=d-m-o,v.bottom=f-h-a}return{srcRect:_,srcRectAngle:v}}};X=H([V(0,e.ICommandService),V(1,t.IDrawingManagerService),V(2,n.IRenderManagerService),V(3,e.IUniverInstanceService),V(4,i.IMessageService),V(5,(0,e.Inject)(e.LocaleService))],X);let Z=class{constructor(e,t,n,r,i){this._drawingManagerService=e,this._imageIoService=t,this._galleryService=n,this._urlImageService=r,this._univerInstanceService=i}async renderImages(r,i){let{transform:a,drawingType:o,source:s,imageSourceType:c,srcRect:l,prstGeom:u,groupId:d,unitId:f,subUnitId:p,drawingId:m,isMultiTransform:h,transforms:g}=r;if(o!==e.DrawingTypeEnum.DRAWING_IMAGE||!this._drawingManagerService.getDrawingVisible()||this._univerInstanceService.getUnitType(f)===e.UniverInstanceType.UNIVER_SHEET&&p!==this._getActiveSheetId()||a==null)return;let _=h&&g?g:[a],v=[];for(let e of _){let{left:r,top:a,width:o,height:g,angle:y,flipX:b,flipY:x,skewX:S,skewY:C}=e,w=_.indexOf(e),T=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:f,subUnitId:p,drawingId:m},h?w:void 0),E=i.getObject(T);if(E!=null){E.transformByState({left:r,top:a,width:o,height:g,angle:y,flipX:b,flipY:x,skewX:S,skewY:C});continue}let D=this._drawingManagerService.getDrawingOrder(f,p),O=D.indexOf(m),k={...e,zIndex:O===-1?D.length-1:O},A=this._imageIoService.getImageSourceCache(s,c),j=!1;if(A!=null)k.image=A;else if(c===t.ImageSourceType.UUID)try{k.url=await this._imageIoService.getImage(s)}catch(e){console.error(e);continue}else if(c===t.ImageSourceType.URL){try{k.url=await this._urlImageService.getImage(s)}catch(e){console.error(e),k.url=s}j=!0}else k.url=s,j=!0;if(i.getObject(T))continue;k.printable=!0;let N=new n.Image(T,k);j&&this._imageIoService.addImageSourceCache(s,c,N.getNative()),i.addObject(N,n.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&i.attachTransformerTo(N),d&&M({drawingId:d,unitId:f,subUnitId:p},N,i,this._drawingManagerService),u!=null&&N.setPrstGeom(u),l!=null&&N.setSrcRect(l),v.push(N)}return v}_getActiveSheetId(){var t;return(t=this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_SHEET))==null||(t=t.getActiveSheet())==null?void 0:t.getSheetId()}renderFloatDom(r,i){let{transform:a,drawingType:o,groupId:s,unitId:c,subUnitId:l,drawingId:u,isMultiTransform:d,transforms:f}=r;if(o!==e.DrawingTypeEnum.DRAWING_DOM||!this._drawingManagerService.getDrawingVisible()||a==null)return;let p=d&&f?f:[a],m=[];for(let e of p){let{left:a,top:o,width:f,height:h,angle:g,flipX:_,flipY:v,skewX:y,skewY:b}=e,x=p.indexOf(e),S=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:c,subUnitId:l,drawingId:u},d?x:void 0),C=i.getObject(S);if(C!=null){C.transformByState({left:a,top:o,width:f,height:h,angle:g,flipX:_,flipY:v,skewX:y,skewY:b});continue}let w=this._drawingManagerService.getDrawingOrder(c,l),T=w.indexOf(u),E={...e,zIndex:T===-1?w.length-1:T};if(i.getObject(S))continue;E.printable=!1;let D=new n.Rect(S,E);this._drawingManagerService.getDrawingVisible()&&(i.addObject(D,n.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&r.allowTransform!==!1&&i.attachTransformerTo(D),s&&M({drawingId:s,unitId:c,subUnitId:l},D,i,this._drawingManagerService),m.push(D))}return m}renderDrawing(t,n){let r=this._drawingManagerService.getDrawingByParam(t);if(r!=null)switch(r.drawingType){case e.DrawingTypeEnum.DRAWING_IMAGE:return this.renderImages(r,n);default:}}previewImage(e,t,n,r){this._galleryService.open({images:[t],onOpenChange:e=>{e||this._galleryService.close()}})}_adjustImageSize(e,t,n,r){if(e<=n&&t<=r)return{width:e,height:t};let i=n/e,a=r/t,o=Math.min(i,a);return{width:Math.floor(e*o),height:Math.floor(t*o)}}};Z=H([V(0,t.IDrawingManagerService),V(1,t.IImageIoService),V(2,i.IGalleryService),V(3,e.IURLImageService),V(4,e.IUniverInstanceService)],Z);let Q=class extends e.Disposable{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._drawingManagerService=n,this._dialogService=r,this._imageIoService=i,this._currentUniverService=a,this._drawingRenderService=o,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===j.id){let t=e.params;if(t==null)return;this._resetImageSize(t)}}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_resetImageSize(n){let r=[],i=[];n.forEach(n=>{let{unitId:a,subUnitId:o,drawingId:s}=n,c=this._getSceneAndTransformerByDrawingSearch(a);if(c==null)return;let{scene:l}=c,u=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:a,subUnitId:o,drawingId:s}),d=l.getObject(u);if(d==null)return!0;let f=this._drawingManagerService.getDrawingByParam(n);if(f==null)return!0;if(f.drawingType!==e.DrawingTypeEnum.DRAWING_IMAGE)return;d.resetSize();let{width:p,height:m}=d.getNativeSize();i.includes(l)===!1&&i.push(l),r.push({...f,transform:{...f.transform,height:m,width:p,angle:0},srcRect:null,prstGeom:null})}),this._drawingManagerService.featurePluginUpdateNotification(r),i.forEach(e=>{e.getTransformerByCreate().refreshControls().changeNotification()}),this._commandService.syncExecuteCommand(t.SetDrawingSelectedOperation.id,n)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.pipe((0,a.bufferTime)(33),(0,a.filter)(e=>e.length>0),(0,a.map)(e=>e.flat()),(0,a.map)(e=>{let t=new Map;for(let n of e)t.set(`${n.unitId}|${n.subUnitId}|${n.drawingId}`,n);return[...t.values()]}),(0,a.filter)(e=>e.length>0)).subscribe(e=>{this._insertImages(e)}))}_insertImages(e){e.forEach(async e=>{var t;let{unitId:n,subUnitId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(n),a=(t=N(this._currentUniverService,n))==null?void 0:t.subUnitId;if(i==null||a!==r)return;let o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let s=await this._drawingRenderService.renderImages(o,i.scene);if(this._drawingManagerService.refreshTransform([o]),!(s==null||s.length===0))for(let e of s)this._addHoverForImage(e),this._addDialogForImage(e)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(n=>{let{unitId:r,subUnitId:i,drawingId:a}=n,o=this._drawingManagerService.getDrawingByParam(n);if(o==null)return;let{transform:s,drawingType:c,srcRect:l,prstGeom:u,source:d,imageSourceType:f}=o;if(c!==e.DrawingTypeEnum.DRAWING_IMAGE)return;let p=this._getSceneAndTransformerByDrawingSearch(r);if(p==null)return;let{scene:m,transformer:h}=p;if(s==null)return!0;let g=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:r,subUnitId:i,drawingId:a}),_=m.getObject(g);if(_==null)return!0;_.setSrcRect(l),_.setPrstGeom(u),d!=null&&d.length>0&&(f===e.ImageSourceType.BASE64||f===e.ImageSourceType.URL)&&_.changeSource(d)})}))}_addHoverForImage(t){this.disposeWithMe((0,e.toDisposable)(t.onPointerEnter$.subscribeEvent(()=>{t.cursor=n.CURSOR_TYPE.GRAB}))),this.disposeWithMe((0,e.toDisposable)(t.onPointerLeave$.subscribeEvent(()=>{t.cursor=n.CURSOR_TYPE.DEFAULT})))}_addDialogForImage(t){this.disposeWithMe((0,e.toDisposable)(t.onDblclick$.subscribeEvent(()=>{let e=`${t.oKey}-viewer-dialog`;this._drawingRenderService.previewImage(e,t.getNative().src,t.getNativeSize().width,t.getNativeSize().height)})))}};Q=H([V(0,e.ICommandService),V(1,n.IRenderManagerService),V(2,t.IDrawingManagerService),V(3,i.IDialogService),V(4,t.IImageIoService),V(5,e.IUniverInstanceService),V(6,(0,e.Inject)(Z))],Q);let $=class extends e.Plugin{constructor(t=ee,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{menu:i,...a}=(0,e.merge)({},ee,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(I,a)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(q),this._injector.get(U),this._injector.get(X),this._injector.get(Q)}_initDependencies(){[[Z],[q],[U],[X],[Q]].forEach(e=>this._injector.add(e))}};K($,`pluginName`,`UNIVER_DRAWING_UI_PLUGIN`),K($,`packageName`,P),K($,`version`,F),$=H([V(1,(0,e.Inject)(e.Injector)),V(2,e.IConfigService)],$);const we=t=>{let n=(0,i.useDependency)(e.ICommandService),r=(0,i.useDependency)(e.LocaleService),{drawings:a,alignShow:d}=t,[f,p]=(0,s.useState)(l.default),m=[{label:r.t(`image-panel.align.default`),value:l.default},{options:[{label:r.t(`image-panel.align.left`),value:l.left},{label:r.t(`image-panel.align.center`),value:l.center},{label:r.t(`image-panel.align.right`),value:l.right}]},{options:[{label:r.t(`image-panel.align.top`),value:l.top},{label:r.t(`image-panel.align.middle`),value:l.middle},{label:r.t(`image-panel.align.bottom`),value:l.bottom}]},{options:[{label:r.t(`image-panel.align.horizon`),value:l.horizon},{label:r.t(`image-panel.align.vertical`),value:l.vertical}]}];function h(e){p(e),n.executeCommand(u.id,{alignType:e,drawings:a})}return(0,c.jsxs)(`div`,{className:(0,o.clsx)(`univer-relative univer-w-full`,{"univer-hidden":!d}),children:[(0,c.jsx)(`header`,{className:`
|
|
9
|
-
univer-text-gray-600
|
|
10
|
-
dark:!univer-text-gray-200
|
|
11
|
-
`,children:(0,c.jsx)(`div`,{children:r.t(`image-panel.align.title`)})}),(0,c.jsx)(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:(0,c.jsx)(`div`,{className:`
|
|
12
|
-
univer-w-full univer-text-gray-900
|
|
13
|
-
dark:!univer-text-white
|
|
14
|
-
`,children:(0,c.jsx)(o.Select,{value:f,options:m,onChange:h})})})]})},Te=n=>{let{arrangeShow:r,drawings:a}=n,l=(0,i.useDependency)(e.LocaleService),u=(0,i.useDependency)(t.IDrawingManagerService),d=(0,i.useDependency)(e.ICommandService),f=(0,i.useDependency)(i.ComponentManager),p=f.get(`MoveUpIcon`),m=f.get(`MoveDownIcon`),h=f.get(`TopmostIcon`),g=f.get(`BottomIcon`),[_,v]=(0,s.useState)(a);(0,s.useEffect)(()=>{let e=u.focus$.subscribe(e=>{v(e)});return()=>{e.unsubscribe()}},[]);let b=e=>{d.syncExecuteCommand(y.id,{arrangeType:e,drawings:_})};return(0,c.jsxs)(`div`,{className:(0,o.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!r}),children:[(0,c.jsx)(`header`,{className:`
|
|
15
|
-
univer-text-gray-600
|
|
16
|
-
dark:!univer-text-gray-200
|
|
17
|
-
`,children:(0,c.jsx)(`div`,{children:l.t(`image-panel.arrange.title`)})}),(0,c.jsxs)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:[(0,c.jsxs)(o.Button,{onClick:()=>{b(e.ArrangeTypeEnum.forward)},children:[(0,c.jsx)(p,{}),l.t(`image-panel.arrange.forward`)]}),(0,c.jsxs)(o.Button,{onClick:()=>{b(e.ArrangeTypeEnum.backward)},children:[(0,c.jsx)(m,{}),l.t(`image-panel.arrange.backward`)]}),(0,c.jsxs)(o.Button,{onClick:()=>{b(e.ArrangeTypeEnum.front)},children:[(0,c.jsx)(h,{}),l.t(`image-panel.arrange.front`)]}),(0,c.jsxs)(o.Button,{onClick:()=>{b(e.ArrangeTypeEnum.back)},children:[(0,c.jsx)(g,{}),l.t(`image-panel.arrange.back`)]})]})]})},Ee=r=>{let a=(0,i.useDependency)(e.LocaleService),l=(0,i.useDependency)(n.IRenderManagerService),u=(0,i.useDependency)(t.IDrawingManagerService),d=(0,i.useDependency)(e.ICommandService),f=(0,i.useDependency)(i.ComponentManager),{hasGroup:p,drawings:m}=r,h=f.get(`GroupIcon`),g=f.get(`UngroupIcon`),[_,v]=(0,s.useState)(!1),[y,b]=(0,s.useState)(!0),[x,S]=(0,s.useState)(!0),C=()=>{d.syncExecuteCommand(T.id,{drawings:m})},w=()=>{d.syncExecuteCommand(E.id,{drawings:m})};return(0,s.useEffect)(()=>{let t=m[0];if(t==null)return;let{unitId:n}=t,r=l.getRenderById(n),i=r==null?void 0:r.scene;if(i==null)return;let a=i.getTransformerByCreate(),o=a.clearControl$.subscribe(e=>{e===!0&&v(!1)}),s=a.changeStart$.subscribe(t=>{let{objects:n}=t,r=W(n,u),i=r.filter(t=>(t==null?void 0:t.drawingType)===e.DrawingTypeEnum.DRAWING_GROUP),a=!1,o=!1;r.length>1&&(a=!0),i.length>0&&(o=!0),v(a||o),b(a),S(o)});return()=>{s.unsubscribe(),o.unsubscribe()}},[]),(0,c.jsxs)(`div`,{className:(0,o.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":p===!0&&_===!1||p===!1}),children:[(0,c.jsx)(`header`,{className:`
|
|
18
|
-
univer-text-gray-600
|
|
19
|
-
dark:!univer-text-gray-200
|
|
20
|
-
`,children:(0,c.jsx)(`div`,{children:a.t(`image-panel.group.title`)})}),(0,c.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[(0,c.jsxs)(o.Button,{className:(0,o.clsx)({"univer-hidden":!y}),onClick:C,children:[(0,c.jsx)(h,{}),a.t(`image-panel.group.group`)]}),(0,c.jsxs)(o.Button,{className:(0,o.clsx)({"univer-hidden":!x}),onClick:w,children:[(0,c.jsx)(g,{}),a.t(`image-panel.group.unGroup`)]})]})]})},De=[-360,360],Oe=r=>{var a;let l=(0,i.useDependency)(e.LocaleService),u=(0,i.useDependency)(t.IDrawingManagerService),d=(0,i.useDependency)(n.IRenderManagerService),{drawings:f,transformShow:p}=r,m=f[0];if(m==null)return;let h=m.transform;if(h==null)return;let{unitId:g,subUnitId:_,drawingId:v,drawingType:y}=m,b=d.getRenderById(g),x=b==null?void 0:b.scene;if(x==null)return;let S=(a=x.getEngine())==null?void 0:a.activeScene;if(S==null)return;let C=x.getTransformerByCreate(),{width:w=0,height:T=0,left:E=0,top:D=0,angle:O=0}=h,[k,A]=(0,s.useState)(w),[j,M]=(0,s.useState)(T),[N,P]=(0,s.useState)(E),[F,I]=(0,s.useState)(D),[ee,L]=(0,s.useState)(O),[R,te]=(0,s.useState)(C.keepRatio),z=(e,t,n,r)=>{let{width:i,height:a}=S,{ancestorLeft:o,ancestorTop:s}=x,c=e,l=t,u=n,d=r;return e+o<0&&(c=-o),t+s<0&&(l=-s),u=i-c-o,u<20&&(u=20),d=a-l-s,d<20&&(d=20),e+u+o>i&&(c=i-n-o),t+d+s>a&&(l=a-r-s),{limitLeft:c,limitTop:l,limitWidth:u,limitHeight:d}},B=e=>{let{objects:t}=e,n=W(t,u);if(n.length!==1)return;let r=n[0];if(r==null)return;let{transform:i}=r;if(i==null)return;let{width:a,height:o,left:s,top:c,angle:l}=i;a!=null&&A(a),o!=null&&M(o),s!=null&&P(s),c!=null&&I(c),l!=null&&L(l)};(0,s.useEffect)(()=>{let e=[C.changeStart$.subscribe(e=>{B(e)}),C.changing$.subscribe(e=>{B(e)}),C.changeEnd$.subscribe(e=>{B(e)}),u.focus$.subscribe(e=>{if(e.length!==1)return;let t=u.getDrawingByParam(e[0]);if(t==null)return;let n=t.transform;if(n==null)return;let{width:r,height:i,left:a,top:o,angle:s}=n;r!=null&&A(r),i!=null&&M(i),a!=null&&P(a),o!=null&&I(o),s!=null&&L(s)})];return()=>{e.forEach(e=>e.unsubscribe())}},[]);let ne=(0,e.debounce)(e=>{if(e==null)return;let{limitWidth:t,limitHeight:n}=z(N,F,e,j);e=Math.min(e,t);let r={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{width:e}};if(R){let t=e/k*j;if(t=Math.max(t,20),t>n)return;M(t),r.transform.height=t}A(e),u.featurePluginUpdateNotification([r]),C.refreshControls().changeNotification()},300),re=(0,e.debounce)(e=>{if(e==null)return;let{limitHeight:t,limitWidth:n}=z(N,F,k,e);e=Math.min(e,t);let r={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{height:e}};if(R){let t=e/j*k;if(t=Math.max(t,20),t>n)return;A(t),r.transform.width=t}M(e),u.featurePluginUpdateNotification([r]),C.refreshControls().changeNotification()},300),ie=(0,e.debounce)(e=>{if(e==null)return;let{limitLeft:t}=z(e,F,k,j);e=t;let n={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{left:e}};P(e),u.featurePluginUpdateNotification([n]),C.refreshControls().changeNotification()},300),ae=(0,e.debounce)(e=>{if(e==null)return;let{limitTop:t}=z(N,e,k,j);e=t;let n={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{top:e}};I(e),u.featurePluginUpdateNotification([n]),C.refreshControls().changeNotification()},300),oe=e=>{if(e==null)return;let t={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{angle:e}};L(e),u.featurePluginUpdateNotification([t]),C.refreshControls().changeNotification()},se=e=>{te(e),C.keepRatio=e};return(0,c.jsxs)(`div`,{className:(0,o.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!p}),children:[(0,c.jsx)(`header`,{className:`
|
|
21
|
-
univer-text-gray-600
|
|
22
|
-
dark:!univer-text-gray-200
|
|
23
|
-
`,children:(0,c.jsx)(`div`,{children:l.t(`image-panel.transform.title`)})}),(0,c.jsxs)(`div`,{className:`
|
|
24
|
-
univer-grid univer-grid-cols-3 univer-gap-2
|
|
25
|
-
[&>div]:univer-grid [&>div]:univer-gap-2
|
|
26
|
-
`,children:[(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.width`)}),(0,c.jsx)(o.InputNumber,{precision:1,value:k,min:20,onChange:e=>{ne(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.height`)}),(0,c.jsx)(o.InputNumber,{precision:1,value:j,min:20,onChange:e=>{re(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.lock`)}),(0,c.jsx)(`div`,{className:`univer-text-center`,children:(0,c.jsx)(o.Checkbox,{checked:R,onChange:se})})]})]}),(0,c.jsxs)(`div`,{className:`
|
|
27
|
-
univer-grid univer-grid-cols-3 univer-gap-2
|
|
28
|
-
[&>div]:univer-grid [&>div]:univer-gap-2
|
|
29
|
-
`,children:[(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.x`)}),(0,c.jsx)(o.InputNumber,{precision:1,value:N,onChange:e=>{ie(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.y`)}),(0,c.jsx)(o.InputNumber,{precision:1,value:F,onChange:e=>{ae(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.rotate`)}),(0,c.jsx)(o.InputNumber,{precision:1,value:ee,min:De[0],max:De[1],onChange:oe})]})]})]})},ke=t=>{let n=(0,i.useDependency)(e.ICommandService),a=(0,i.useDependency)(e.LocaleService),{drawings:l,cropperShow:u}=t;if(l[0]==null)return;let[d,f]=(0,s.useState)(k.FREE),p=(0,s.useRef)(!1),m=[{label:a.t(`image-panel.crop.mode`),value:k.FREE},{label:`1:1`,value:k.R1_1},{label:`16:9`,value:k.R16_9},{label:`9:16`,value:k.R9_16},{label:`5:4`,value:k.R5_4},{label:`4:5`,value:k.R4_5},{label:`4:3`,value:k.R4_3},{label:`3:4`,value:k.R3_4},{label:`3:2`,value:k.R3_2},{label:`2:3`,value:k.R2_3}];(0,s.useEffect)(()=>{let e=n.onCommandExecuted(e=>{if(e.id===O.id){let t=e.params;t!=null&&t.isAuto||(p.current=!1)}});return()=>{e==null||e.dispose()}},[]);function h(e){f(e),p.current&&n.executeCommand(A.id,{cropType:e})}let g=e=>{n.executeCommand(A.id,{cropType:e}),p.current=!0};return(0,c.jsxs)(`div`,{className:(0,o.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!u}),children:[(0,c.jsx)(`header`,{className:`
|
|
30
|
-
univer-text-gray-600
|
|
31
|
-
dark:!univer-text-gray-200
|
|
32
|
-
`,children:(0,c.jsx)(`div`,{children:a.t(`image-panel.crop.title`)})}),(0,c.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[(0,c.jsxs)(o.Button,{onClick:()=>{g(d)},children:[(0,c.jsx)(r.CreateCopyIcon,{}),a.t(`image-panel.crop.start`)]}),(0,c.jsx)(o.Select,{value:d,options:m,onChange:h})]})]})},Ae=r=>{let a=(0,i.useDependency)(t.IDrawingManagerService),l=(0,i.useDependency)(n.IRenderManagerService),u=(0,i.useDependency)(e.LocaleService),{drawings:d,hasArrange:f=!0,hasTransform:p=!0,hasAlign:m=!0,hasCropper:h=!0,hasGroup:g=!0}=r,_=d[0];if(_==null)return;let{unitId:v}=_,y=l.getRenderById(v),b=y==null?void 0:y.scene;if(b==null)return;let x=b.getTransformerByCreate(),[S,C]=(0,s.useState)(!0),[w,T]=(0,s.useState)(!0),[E,D]=(0,s.useState)(!1),[O,k]=(0,s.useState)(!0),[A,j]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{let e=x.clearControl$.subscribe(e=>{e===!0&&(C(!1),T(!1),D(!1),k(!1),j(!0))}),t=x.changeStart$.subscribe(e=>{let{objects:t}=e,n=W(t,a);n.length===0?(C(!1),T(!1),D(!1),k(!1),j(!0)):n.length===1?(C(!0),T(!0),D(!1),k(!0),j(!1)):(C(!0),T(!1),D(!0),k(!1),j(!1))}),n=a.focus$.subscribe(e=>{e.length===0?(C(!1),T(!1),D(!1),k(!1),j(!0)):e.length===1?(C(!0),T(!0),D(!1),k(!0),j(!1)):(C(!0),T(!1),D(!0),k(!1),j(!1))});return()=>{t.unsubscribe(),e.unsubscribe(),n.unsubscribe()}},[]),(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`div`,{className:(0,o.clsx)(`univer-h-full`,{"univer-hidden":!A}),children:(0,c.jsx)(`div`,{className:`univer-flex univer-h-full univer-items-center univer-justify-center`,children:(0,c.jsx)(`span`,{children:u.t(`image-panel.null`)})})}),(0,c.jsx)(Te,{arrangeShow:f===!0?S:!1,drawings:d}),(0,c.jsx)(Oe,{transformShow:p===!0?w:!1,drawings:d}),(0,c.jsx)(we,{alignShow:m===!0?E:!1,drawings:d}),(0,c.jsx)(ke,{cropperShow:h===!0?O:!1,drawings:d}),(0,c.jsx)(Ee,{hasGroup:g,drawings:d})]})};exports.AutoImageCropOperation=A,exports.COMPONENT_IMAGE_POPUP_MENU=be,exports.CancelDrawingGroupOperation=E,exports.CloseImageCropOperation=O,exports.DRAWING_GROUP_TYPES=w,exports.DrawingCommonPanel=Ae,Object.defineProperty(exports,`DrawingRenderService`,{enumerable:!0,get:function(){return Z}}),exports.ImageCropperObject=Y,exports.ImagePopupMenu=xe,exports.ImageResetSizeOperation=j,exports.OpenImageCropOperation=D,exports.SetDrawingAlignOperation=u,exports.SetDrawingArrangeOperation=y,exports.SetDrawingGroupOperation=T,Object.defineProperty(exports,`UniverDrawingUIPlugin`,{enumerable:!0,get:function(){return $}}),exports.getCurrentUnitInfo=N,exports.getUpdateParams=W,exports.insertGroupObject=M;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`@univerjs/core`),t=require(`@univerjs/drawing`),n=require(`@univerjs/engine-render`),r=require(`@univerjs/icons`),i=require(`@univerjs/ui`),a=require(`rxjs`),o=require(`@univerjs/design`),s=require(`react`),c=require(`react/jsx-runtime`),l=function(e){return e.default=`0`,e.left=`1`,e.center=`2`,e.right=`3`,e.top=`4`,e.middle=`5`,e.bottom=`6`,e.horizon=`7`,e.vertical=`8`,e}({});const u={id:`sheet.operation.set-image-align`,type:e.CommandType.OPERATION,handler:(e,t)=>!0},d={id:`sheet.operation.set-drawing-align-left`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.left})},f={id:`sheet.operation.set-drawing-align-center`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.center})},p={id:`sheet.operation.set-drawing-align-right`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.right})},m={id:`sheet.operation.set-drawing-align-top`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.top})},h={id:`sheet.operation.set-drawing-align-middle`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.middle})},g={id:`sheet.operation.set-drawing-align-bottom`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.bottom})},_={id:`sheet.operation.set-drawing-align-horizon`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.horizon})},v={id:`sheet.operation.set-drawing-align-vertical`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(u.id,{alignType:l.vertical})},y={id:`drawing.operation.set-drawing-arrange`,type:e.CommandType.OPERATION,handler:(e,n)=>{let r=e.get(t.IDrawingManagerService),{arrangeType:i}=n,a=n.drawings||r.getFocusDrawings(),{unitId:o,subUnitId:s}=a[0],c=a.map(e=>e.drawingId);return r.featurePluginOrderUpdateNotification({unitId:o,subUnitId:s,drawingIds:c,arrangeType:i}),!0}},b={id:`drawing.operation.set-drawing-arrange-front`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(y.id,{arrangeType:e.ArrangeTypeEnum.front})},x={id:`drawing.operation.set-drawing-arrange-forward`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(y.id,{arrangeType:e.ArrangeTypeEnum.forward})},S={id:`drawing.operation.set-drawing-arrange-back`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(y.id,{arrangeType:e.ArrangeTypeEnum.back})},C={id:`drawing.operation.set-drawing-arrange-backward`,type:e.CommandType.OPERATION,handler:t=>t.get(e.ICommandService).syncExecuteCommand(y.id,{arrangeType:e.ArrangeTypeEnum.backward})},w=[e.DrawingTypeEnum.DRAWING_IMAGE,e.DrawingTypeEnum.DRAWING_SHAPE,e.DrawingTypeEnum.DRAWING_GROUP],T={id:`drawing.operation.set-drawing-group`,type:e.CommandType.OPERATION,handler:(r,i)=>{let a=r.get(t.IDrawingManagerService),o=i.drawings||a.getFocusDrawings();if(o.length<2||!o.every(e=>w.includes(e.drawingType)))return!1;let{unitId:s,subUnitId:c}=o[0],l=(0,e.generateRandomId)(10),u=(0,n.getGroupState)(0,0,o.map(e=>e.transform||{})),d={unitId:s,subUnitId:c,drawingId:l,drawingType:e.DrawingTypeEnum.DRAWING_GROUP,transform:u,groupBaseBound:{left:u.left,top:u.top,width:u.width,height:u.height}},f=o.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t},groupId:l}});return a.featurePluginGroupUpdateNotification([{parent:d,children:f}]),!0}},E={id:`drawing.operation.cancel-drawing-group`,type:e.CommandType.OPERATION,handler:(r,i)=>{let a=r.get(t.IDrawingManagerService),o=(i.drawings||a.getFocusDrawings()).map(t=>{if(t.drawingType!==e.DrawingTypeEnum.DRAWING_GROUP)return null;let{unitId:r,subUnitId:i,drawingId:o,transform:s={width:0,height:0},groupBaseBound:c}=t;if(s===null)return null;let l=a.getDrawingsByGroup({unitId:r,subUnitId:i,drawingId:o});return l.length===0?null:{parent:t,children:l.map(e=>{let{transform:t}=e,{unitId:r,subUnitId:i,drawingId:a}=e,o=(0,n.transformObjectOutOfGroup)(t||{},s,s.width||0,s.height||0,c);return{unitId:r,subUnitId:i,drawingId:a,transform:{...t,...o},groupId:void 0}})}}).filter(e=>e!==null);return o.length===0?!1:(a.featurePluginUngroupUpdateNotification(o),!0)}},D={id:`sheet.operation.open-image-crop`,type:e.CommandType.OPERATION,handler:(e,t)=>!0},O={id:`sheet.operation.close-image-crop`,type:e.CommandType.OPERATION,handler:(e,t)=>!0};let k=function(e){return e.FREE=`0`,e.R1_1=`1`,e.R16_9=`2`,e.R9_16=`3`,e.R5_4=`4`,e.R4_5=`5`,e.R4_3=`6`,e.R3_4=`7`,e.R3_2=`8`,e.R2_3=`9`,e}({});const A={id:`sheet.operation.Auto-image-crop`,type:e.CommandType.OPERATION,handler:(e,t)=>!0},j={id:`sheet.operation.image-reset-size`,type:e.CommandType.OPERATION,handler:(e,t)=>!0};function M(e,r,i,a){let o=a.getDrawingByParam(e);if(o==null)return;let s=(0,t.getDrawingShapeKeyByDrawingSearch)(e),c=i.getObjectIncludeInGroup(s);if(c&&!(c instanceof n.Group))return;if(c!=null){let e=c.getObjects();for(let t of e)if(t.oKey===r.oKey)return;c.addObject(r);return}let l=new n.DrawingGroupObject(s);i.addObject(l,n.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(l),l.addObject(r);let{transform:u,groupBaseBound:d}=o;d&&l.setBaseBound(d),o.groupId&&(l.isInGroup=!0,M({drawingId:o.groupId,unitId:e.unitId,subUnitId:e.subUnitId},l,i,a)),u&&l.transformByState({left:u.left,top:u.top,angle:u.angle,width:u.width,height:u.height})}function N(t,n){let r=n?t.getUnit(n):t.getFocusedUnit();if(r==null)return;let i=r.getUnitId(),a;if(r.type===e.UniverInstanceType.UNIVER_SHEET){var o;a=(o=r.getActiveSheet())==null?void 0:o.getSheetId()}else (r.type===e.UniverInstanceType.UNIVER_DOC||r.type===e.UniverInstanceType.UNIVER_SLIDE)&&(a=i);return{unitId:i,subUnitId:a,current:r}}var P=`@univerjs/drawing-ui`,F=`0.19.0`;const I=`drawing-ui.config`;Symbol(I);const ee={},L=e=>{let n=e.get(t.IDrawingManagerService);return new a.Observable(e=>{let t=t=>{if(!t||t.length===0||t.length<2)return e.next(!0);e.next(!1)},r=n.focus$.subscribe(n=>{if(!n||n.length===0)return e.next(!0);t(n)});return t(n.getFocusDrawings()),()=>r.unsubscribe()})},R=`contextMenu.drawing-align`;function te(e){return{id:R,type:i.MenuItemType.SUBITEMS,icon:`HorizontallyIcon`,title:`image-panel.align.title`,hidden$:L(e)}}function z(){return{id:d.id,type:i.MenuItemType.BUTTON,icon:`LeftJustifyingIcon`,title:`image-panel.align.left`}}function B(){return{id:f.id,type:i.MenuItemType.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.center`}}function ne(){return{id:p.id,type:i.MenuItemType.BUTTON,icon:`RightJustifyingIcon`,title:`image-panel.align.right`}}function re(){return{id:m.id,type:i.MenuItemType.BUTTON,icon:`AlignTopIcon`,title:`image-panel.align.top`}}function ie(){return{id:h.id,type:i.MenuItemType.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.middle`}}function ae(){return{id:g.id,type:i.MenuItemType.BUTTON,icon:`AlignBottomIcon`,title:`image-panel.align.bottom`}}function oe(){return{id:_.id,type:i.MenuItemType.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.horizon`}}function se(){return{id:v.id,type:i.MenuItemType.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.vertical`}}const ce=`contextMenu.drawing-arrange`;function le(){return{id:ce,type:i.MenuItemType.SUBITEMS,icon:`TopmostIcon`,title:`image-panel.arrange.title`}}function ue(){return{id:b.id,type:i.MenuItemType.BUTTON,icon:`TopmostIcon`,title:`image-panel.arrange.front`}}function de(){return{id:x.id,type:i.MenuItemType.BUTTON,icon:`MoveUpIcon`,title:`image-panel.arrange.forward`}}function fe(){return{id:S.id,type:i.MenuItemType.BUTTON,icon:`BottomIcon`,title:`image-panel.arrange.back`}}function pe(){return{id:C.id,type:i.MenuItemType.BUTTON,icon:`MoveDownIcon`,title:`image-panel.arrange.backward`}}const me=(n,r)=>{let i=n.get(t.IDrawingManagerService);return new a.Observable(t=>{let n=n=>{if(!n||n.length===0)return t.next(!0);if(r===`group`){if(n.length<2||!n.every(e=>w.includes(e.drawingType)))return t.next(!0)}else if(r===`unGroup`){if(n.filter(t=>t.drawingType===e.DrawingTypeEnum.DRAWING_GROUP).length===0)return t.next(!0)}else if(!n.every(e=>w.includes(e.drawingType)))return t.next(!0);t.next(!1)},a=i.focus$.subscribe(e=>{if(!e||e.length===0)return t.next(!0);n(e)});return n(i.getFocusDrawings()),()=>a.unsubscribe()})},he=`contextMenu.drawing-group`;function ge(e){return{id:he,type:i.MenuItemType.SUBITEMS,icon:`GroupIcon`,title:`image-panel.group.title`,hidden$:me(e)}}function _e(e){return{id:T.id,type:i.MenuItemType.BUTTON,icon:`GroupIcon`,title:`image-panel.group.group`,disabled$:me(e,`group`)}}function ve(e){return{id:E.id,type:i.MenuItemType.BUTTON,icon:`UngroupIcon`,title:`image-panel.group.unGroup`,disabled$:me(e,`unGroup`)}}const ye={[i.ContextMenuPosition.DRAWING]:{[i.ContextMenuGroup.OTHERS]:{[he]:{order:1,menuItemFactory:ge,[T.id]:{order:0,menuItemFactory:_e},[E.id]:{order:1,menuItemFactory:ve}},[ce]:{order:2,menuItemFactory:le,[b.id]:{order:0,menuItemFactory:ue},[x.id]:{order:1,menuItemFactory:de},[S.id]:{order:2,menuItemFactory:fe},[C.id]:{order:3,menuItemFactory:pe}},[R]:{order:3,menuItemFactory:te,[d.id]:{order:0,menuItemFactory:z},[f.id]:{order:1,menuItemFactory:B},[p.id]:{order:2,menuItemFactory:ne},[m.id]:{order:3,menuItemFactory:re},[h.id]:{order:4,menuItemFactory:ie},[g.id]:{order:5,menuItemFactory:ae},[_.id]:{order:6,menuItemFactory:oe},[v.id]:{order:7,menuItemFactory:se}}}}},be=`COMPONENT_IMAGE_POPUP_MENU`;function xe(t){var n;let{popup:a}=t,l=a==null||(n=a.extraProps)==null?void 0:n.menuItems;if(!l)return null;let u=(0,i.useDependency)(e.ICommandService),d=(0,i.useDependency)(e.LocaleService),[f,p]=(0,s.useState)(!1),[m,h]=(0,s.useState)(!1),g=()=>{h(!0)},_=()=>{h(!1)},v=e=>{p(e)},y=e=>{u.executeCommand(e.commandId,e.commandParams),p(!1)},b=f||m;return(0,c.jsx)(`div`,{onMouseEnter:g,onMouseLeave:_,children:(0,c.jsx)(o.DropdownMenu,{align:`start`,items:l.filter(e=>!e.disable).map(e=>({type:`item`,children:d.t(e.label),onSelect:()=>y(e)})),open:f,onOpenChange:v,children:(0,c.jsxs)(`div`,{className:(0,o.clsx)(`univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800`,o.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":f,"univer-bg-white dark:!univer-bg-gray-900":!f}),children:[(0,c.jsx)(r.AutofillDoubleIcon,{className:`univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white`}),b&&(0,c.jsx)(r.MoreDownIcon,{className:`dark:!univer-text-white`})]})})})}function V(e,t){return function(n,r){t(n,r,e)}}function H(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let U=class extends e.Disposable{constructor(e,t,n){super(),this._componentManager=e,this._commandService=t,this._menuManagerService=n,this._init()}_init(){this._initMenus(),this._initCommands(),this._initComponents()}_initMenus(){this._menuManagerService.mergeMenu(ye)}_initCommands(){[D,O,j,u,d,f,p,m,h,g,_,v,A,T,E,y,b,x,S,C].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initComponents(){[[be,xe],[`BottomIcon`,r.BottomIcon],[`GroupIcon`,r.GroupIcon],[`MoveDownIcon`,r.MoveDownIcon],[`MoveUpIcon`,r.MoveUpIcon],[`TopmostIcon`,r.TopmostIcon],[`UngroupIcon`,r.UngroupIcon]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};U=H([V(0,(0,e.Inject)(i.ComponentManager)),V(1,e.ICommandService),V(2,i.IMenuManagerService)],U);function W(t,n){let r=[];return t.forEach(t=>{let{oKey:i,left:a,top:o,height:s,width:c,angle:l}=t,u=n.getDrawingOKey(i);if(u==null)return r.push(null),!0;let{unitId:d,subUnitId:f,drawingId:p,drawingType:m}=u,h={unitId:d,subUnitId:f,drawingId:p,drawingType:m,transform:{left:a,top:o,height:s,width:c,angle:l}};m===e.DrawingTypeEnum.DRAWING_IMAGE&&(h.srcRect=t.srcRect),r.push(h)}),r}function G(e){"@babel/helpers - typeof";return G=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},G(e)}function Se(e,t){if(G(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(G(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ce(e){var t=Se(e,`string`);return G(t)==`symbol`?t:t+``}function K(e,t,n){return(t=Ce(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let q=class extends e.Disposable{constructor(e,t,n,r){super(),this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._drawingManagerService=r,K(this,`_sceneListenerOnDrawingMap`,new WeakSet),this._initialize()}dispose(){super.dispose()}_initialize(){this._recoveryImages(),this._drawingAddListener(),this._drawingRemoveListener(),this._drawingUpdateListener(),this._commandExecutedListener(),this._drawingArrangeListener(),this._drawingGroupListener(),this._drawingRefreshListener(),this._drawingVisibleListener()}_recoveryImages(){let e=this._drawingManagerService.drawingManagerData,t=N(this._currentUniverService);if(t==null)return;let{unitId:n,subUnitId:r}=t;Object.keys(e).forEach(t=>{Object.keys(e[t]).forEach(i=>{let a=e[t][i].data;a==null||t!==n||i!==r||Object.keys(a).forEach(e=>{a[e]&&this._insertDrawing([{unitId:t,subUnitId:i,drawingId:e}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===u.id){let t=e.params;if(t==null)return;this._drawingAlign(t)}}))}_drawingGroupListener(){this.disposeWithMe(this._drawingManagerService.group$.subscribe(e=>{this._groupDrawings(e)})),this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe(e=>{this._ungroupDrawings(e)}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_groupDrawings(e){e.forEach(e=>{this._groupDrawing(e)})}_groupDrawing(e){let{parent:r,children:i}=e,{unitId:a,subUnitId:o,drawingId:s}=r,c=this._getSceneAndTransformerByDrawingSearch(r.unitId);if(c==null)return;let{scene:l,transformer:u}=c;this._commandService.syncExecuteCommand(O.id);let d=[];if(i.forEach(e=>{let r=(0,t.getDrawingShapeKeyByDrawingSearch)(e),i=l.getObjectIncludeInGroup(r);if(i==null||d.includes(i))return;d.push(i);let{transform:a}=e;a!=null&&(i.classType===n.RENDER_CLASS_TYPE.GROUP?i.transformByState({left:a.left,top:a.top}):i.transformByState(a))}),d.length===0)return;let f=new n.DrawingGroupObject((0,t.getDrawingShapeKeyByDrawingSearch)({unitId:a,subUnitId:o,drawingId:s}));l.addObject(f,n.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(f),f.addObjects(...d),r.groupBaseBound&&f.setBaseBound(r.groupBaseBound),r.groupId&&(f.isInGroup=!0,M({drawingId:r.groupId,unitId:a,subUnitId:o},f,l,this._drawingManagerService)),r.transform&&f.transformByState({left:r.transform.left,top:r.transform.top,width:r.transform.width,height:r.transform.height,angle:r.transform.angle}),u.clearSelectedObjects(),u.setSelectedControl(f)}_ungroupDrawings(e){e.forEach(e=>{this._ungroupDrawing(e)})}_ungroupDrawing(e){let{parent:r,children:i}=e,a=this._getSceneAndTransformerByDrawingSearch(r.unitId);if(a==null)return;let{scene:o,transformer:s}=a;i.forEach(e=>{let r=(0,t.getDrawingShapeKeyByDrawingSearch)(e),i=o.getObjectIncludeInGroup(r);if(i==null)return!0;if(i==null)return;let{transform:a}=e;a!=null&&(i.classType===n.RENDER_CLASS_TYPE.GROUP?i.transformByState({left:a.left,top:a.top}):i.transformByState(a))});let c=(0,t.getDrawingShapeKeyByDrawingSearch)(r),l=o.getObject(c),{width:u,height:d}=l;l.getObjects().forEach(e=>{l.removeSelfObjectAndTransform(e.oKey,u,d)}),l.dispose(),s.clearSelectedObjects()}_drawingAlign(e){let{alignType:t}=e,n=e.drawings||this._drawingManagerService.getFocusDrawings();if(t===l.default)return;let r=[],i=1/0,a=1/0,o=-1/0,s=-1/0,c=0;n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:l,drawingType:u}=e,d=this._drawingManagerService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:l});if(d==null||d.transform==null)return;r.push({unitId:t,subUnitId:n,drawingId:l,drawingType:u,transform:d.transform});let{left:f=0,top:p=0,width:m=0,height:h=0}=d.transform;i=Math.min(i,f),a=Math.min(a,p),o=Math.max(o,f+m),s=Math.max(s,p+h),c++}),c!==0&&(this._sortDrawingTransform(r,t),this._applyAlignType(r,t,i,a,o,s,c))}_applyAlignType(e,t,n,r,i,a,o){let s=Math.round((i-n)/o*10)/10,c=Math.round((a-r)/o*10)/10,u=[],d=this._getSceneAndTransformerByDrawingSearch(e[0].unitId);if(d==null)return;let{scene:f,transformer:p}=d;e.forEach((e,o)=>{let{unitId:d,subUnitId:f,drawingId:p,transform:m,drawingType:h}=e,{left:g=0,top:_=0,width:v=0,height:y=0}=m,b=g,x=_;switch(t){case l.left:b=n;break;case l.center:b=n+(i-n)/2-v/2;break;case l.right:b=i-v;break;case l.top:x=r;break;case l.middle:x=r+(a-r)/2-y/2;break;case l.bottom:x=a-y;break;case l.horizon:b=n+s*o;break;case l.vertical:x=r+c*o;break;default:break}(b!==g||x!==_)&&u.push({unitId:d,subUnitId:f,drawingId:p,drawingType:h,transform:{left:b,top:x}})}),this._drawingManagerService.featurePluginUpdateNotification(u),p.refreshControls().changeNotification()}_sortDrawingTransform(e,t){e.sort((e,n)=>{let r=e.transform,i=n.transform,{left:a=0,top:o=0,width:s=0,height:c=0}=r,{left:u=0,top:d=0,width:f=0,height:p=0}=i;switch(t){case l.left:return a-u;case l.center:return a+s/2-(u+f/2);case l.right:return a+s-(u+f);case l.top:return o-d;case l.middle:return o+c/2-(d+p/2);case l.bottom:return o+c-(d+p);case l.horizon:return a+s/2-(u+f/2);case l.vertical:return o+c/2-(d+p/2);default:return 0}})}_drawingArrangeListener(){this.disposeWithMe(this._drawingManagerService.order$.subscribe(e=>{this._drawingArrange(e)}))}_drawingArrange(e){let{unitId:n,subUnitId:r,drawingIds:i}=e,a=this._getSceneAndTransformerByDrawingSearch(n);if(a==null)return;let{scene:o}=a;i.forEach(e=>{let i=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:r,drawingId:e}),a=o.fuzzyMathObjects(i,!0);if(a==null||a.length===0)return;let s=this._drawingManagerService.getDrawingOrder(n,r).indexOf(e);for(let e of a)e.setProps({zIndex:s}),e.makeDirty()})}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{this._insertDrawing(e)}))}_insertDrawing(e){let t=[];e.forEach(e=>{let{unitId:n}=e;if(this._drawingManagerService.getDrawingByParam(e)==null)return;let r=this._getSceneAndTransformerByDrawingSearch(n);if(r==null)return;let{scene:i}=r;t.includes(i)||t.push(i)}),t.forEach(e=>{this._sceneListenerOnDrawingMap.has(e)||(this._addListenerOnDrawing(e),this._sceneListenerOnDrawingMap.add(e))})}_drawingRemoveListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:n,subUnitId:r,drawingId:i}=e,a=this._getSceneAndTransformerByDrawingSearch(n);if(a==null)return;let{scene:o}=a,s=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:r,drawingId:i}),c=o.fuzzyMathObjects(s,!0);if(c.length>0){var l;for(let e of c)e.dispose();(l=o.getTransformer())==null||l.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{var n;let{unitId:r,subUnitId:i,drawingId:a}=e,o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let{transform:s,drawingType:c}=o,l=this._getSceneAndTransformerByDrawingSearch(r);if(l==null)return;let{scene:u,transformer:d}=l;if(s==null)return!0;let{left:f=0,top:p=0,width:m=0,height:h=0,angle:g=0,flipX:_=!1,flipY:v=!1,skewX:y=0,skewY:b=0}=s,x=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:r,subUnitId:i,drawingId:a}),S=u.getObject(x);if(S==null)return!0;S.transformByState({left:f,top:p,width:m,height:h,angle:g,flipX:_,flipY:v,skewX:y,skewY:b}),(n=u.getTransformer())==null||n.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(e=>{e.forEach(e=>{let{unitId:n,subUnitId:r,drawingId:i}=e,a=this._getSceneAndTransformerByDrawingSearch(n);if(a==null)return;let o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let{transform:s}=o,{scene:c}=a,l=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:r,drawingId:i}),u=c.getObject(l);if(u==null||s==null)return!0;let{left:d=0,top:f=0,width:p=0,height:m=0,angle:h=0,flipX:g=!1,flipY:_=!1,skewX:v=0,skewY:y=0}=s;u.transformByState({left:d,top:f,width:p,height:m,angle:h,flipX:g,flipY:_,skewX:v,skewY:y})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(e=>{e.forEach(e=>{let{unitId:n,subUnitId:r,drawingId:i,visible:a}=e,o=this._getSceneAndTransformerByDrawingSearch(n);if(o==null)return;let{scene:s}=o,c=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:n,subUnitId:r,drawingId:i}),l=s.getObject(c);if(l==null)return!0;a?l.show():l.hide()})}))}_filterUpdateParams(t,n){return t.filter((t,r)=>{if(t==null)return!1;let{transform:i}=t;return(0,e.checkIfMove)(i,n==null?void 0:n[r])})}_addListenerOnDrawing(r){let i=r.getTransformerByCreate(),a=null;this.disposeWithMe((0,e.toDisposable)(i.changeStart$.subscribe(e=>{let{objects:r}=e,i=Array.from(r.values()),o=[];a=i.map(e=>{let{left:t,top:r,height:i,width:a,angle:s,oKey:c,isInGroup:l}=e,u=this._drawingManagerService.getDrawingOKey(c);if(l||e instanceof n.Group){let t=e.ancestorGroup;if(t==null&&e instanceof n.Group&&(t=e),t==null)return null;let r=this._drawingManagerService.getDrawingOKey(t.oKey);if(r){let{unitId:e,subUnitId:n,drawingId:i}=r;o.push({unitId:e,subUnitId:n,drawingId:i});let{left:a,top:s,height:c,width:l,angle:u}=t;return{left:a,top:s,height:c,width:l,angle:u}}}else if(u!=null){let{unitId:e,subUnitId:n,drawingId:c}=u;return o.push({unitId:e,subUnitId:n,drawingId:c}),{left:t,top:r,height:i,width:a,angle:s}}return null}).filter(e=>e!=null),o.length>0?this._commandService.syncExecuteCommand(t.SetDrawingSelectedOperation.id,o):this._commandService.syncExecuteCommand(t.SetDrawingSelectedOperation.id,[])}))),this.disposeWithMe((0,e.toDisposable)(i.changeEnd$.subscribe(e=>{let{objects:t}=e,n=this._filterUpdateParams(W(t,this._drawingManagerService),a);n.length>0&&this._drawingManagerService.featurePluginUpdateNotification(n)})))}};q=H([V(0,e.IUniverInstanceService),V(1,e.ICommandService),V(2,n.IRenderManagerService),V(3,t.IDrawingManagerService)],q);var J=function(e){return e[e.RECT=0]=`RECT`,e[e.PATH=1]=`PATH`,e}(J||{}),Y=class extends n.Shape{constructor(e,t){t==null&&(t={}),t.transformerConfig={keepRatio:!1,isCropper:!0,anchorFill:`rgb(0, 0, 0)`,anchorStroke:`rgb(255, 255, 255)`,anchorSize:24},super(e,t),K(this,`_srcRect`,void 0),K(this,`_prstGeom`,void 0),K(this,`_applyTransform`,void 0),K(this,`_dragPadding`,8),K(this,`_cacheCanvas`,void 0),t!=null&&t.srcRect&&(this._srcRect=t.srcRect),t!=null&&t.prstGeom&&(this._prstGeom=t.prstGeom),t!=null&&t.applyTransform&&(this._applyTransform=t.applyTransform),t!=null&&t.dragPadding&&(this._dragPadding=t.dragPadding),this._applyProps()}refreshSrcRect(e,t){this._srcRect=e,this._applyTransform=t,this._applyProps()}get srcRect(){return this._srcRect}dispose(){var e;super.dispose(),(e=this._cacheCanvas)==null||e.dispose(),this._srcRect=null}isHit(e){let t=this.getInverseCoord(e);return t.x>=-this.strokeWidth/2&&t.x<=this.width+this.strokeWidth/2&&t.y>=-this.strokeWidth/2&&t.y<=this.height+this.strokeWidth/2&&!this._inSurround(t)}_inSurround(e){let t=this._dragPadding;return e.x>=t-this.strokeWidth/2&&e.x<=this.width+this.strokeWidth/2-t&&e.y>=t-this.strokeWidth/2&&e.y<=this.height+this.strokeWidth/2-t}render(e,t){return this.visible?(e.save(),this._draw(e),e.restore(),this.makeDirty(!1),this):(this.makeDirty(!1),this)}_draw(e){var t,r;let{width:i,height:a}=this.getScene().getEngine();this._initialCacheCanvas(),(t=this._cacheCanvas)==null||t.clear();let o=(r=this._cacheCanvas)==null?void 0:r.getContext();o!=null&&(o.save(),n.Rect.drawWith(o,{left:0,top:0,width:i,height:a,fill:`rgba(0, 0, 0, 0.5)`}),o.setTransform(e.getTransform()),this._clipForApplyObject(o),this._applyCache(e),o.restore())}_clipForApplyObject(e){let t=J.RECT;if(this._prstGeom!=null&&(t=J.PATH),e.globalCompositeOperation=`destination-out`,e.beginPath(),t===J.RECT){let t=this.transform.getMatrix();e.transform(t[0],t[1],t[2],t[3],t[4],t[5]),e.rect(0,0,this.width,this.height),e.fill()}}_applyProps(){if(this._applyTransform==null)return;let e=0,t=0,n=0,r=0,{left:i=0,top:a=0,width:o=0,height:s=0,angle:c}=this._applyTransform;if(this._srcRect!=null){let{left:i=0,top:a=0,right:o=0,bottom:s=0}=this._srcRect;e=i,t=a,n=o,r=s}let l=i+e,u=a+t;this.transformByState({left:l,top:u,width:i+o-n-l,height:a+s-r-u,angle:c})}_applyCache(e){if(!e||this._cacheCanvas==null)return;let t=this._cacheCanvas.getContext();t.save(),e.save(),e.setTransform(1,0,0,1,0,0),t.setTransform(1,0,0,1,0,0),e.drawImage(this._cacheCanvas.getCanvasEle(),0,0),e.restore(),t.restore()}_initialCacheCanvas(){if(this._cacheCanvas!=null)return;let e=this.getScene();if(e==null)return;this._cacheCanvas=new n.Canvas;let t=e.getEngine();this._cacheCanvas.setSize(t.width,t.height),t.onTransformChange$.subscribeEvent(()=>{var e;(e=this._cacheCanvas)==null||e.setSize(t.width,t.height),this.makeDirty(!0)})}};let X=class extends e.Disposable{constructor(e,t,n,r,i,a){super(),this._commandService=e,this._drawingManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._messageService=i,this._localeService=a,K(this,`_sceneListenerOnImageMap`,new WeakSet),this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==A.id)return;let r=e.params;if(r==null)return;let{cropType:i}=r,a=this._drawingManagerService.getFocusDrawings();if(a.length!==1)return;let{unitId:s,subUnitId:c,drawingId:l}=a[0],u=this._renderManagerService.getRenderById(s),d=u==null?void 0:u.scene;if(d==null)return!0;this._searchCropObject(d)!=null&&this._commandService.syncExecuteCommand(O.id,{isAuto:!0});let f=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:s,subUnitId:c,drawingId:l}),p=d.getObject(f);if(!(p instanceof n.Image)){this._messageService.show({type:o.MessageType.Error,content:this._localeService.t(`image-cropper.error`)});return}p!=null&&(this._updateCropperObject(i,p),this._commandService.executeCommand(D.id,{unitId:s,subUnitId:c,drawingId:l}))}))}_calculateSrcRectByRatio(e,t,r,i,a,o){let s=r/i,c=a/o,l=r,u=i;s>c?l=i*c:u=r/c;let d=(r-l)/2,f=(i-u)/2;return{left:(0,n.precisionTo)(d,1),top:(0,n.precisionTo)(f,1),right:(0,n.precisionTo)(r-(d+l),1),bottom:(0,n.precisionTo)(i-(f+u),1)}}_updateCropperObject(e,t){let{left:n,top:r,width:i,height:a}=t.calculateTransformWithSrcRect(),o;switch(e){case k.R1_1:o=this._calculateSrcRectByRatio(n,r,i,a,1,1);break;case k.R16_9:o=this._calculateSrcRectByRatio(n,r,i,a,16,9);break;case k.R9_16:o=this._calculateSrcRectByRatio(n,r,i,a,9,16);break;case k.R5_4:o=this._calculateSrcRectByRatio(n,r,i,a,5,4);break;case k.R4_5:o=this._calculateSrcRectByRatio(n,r,i,a,4,5);break;case k.R4_3:o=this._calculateSrcRectByRatio(n,r,i,a,4,3);break;case k.R3_4:o=this._calculateSrcRectByRatio(n,r,i,a,3,4);break;case k.R3_2:o=this._calculateSrcRectByRatio(n,r,i,a,3,2);break;case k.R2_3:o=this._calculateSrcRectByRatio(n,r,i,a,2,3);break;case k.FREE:default:break}if(o==null)return;t.setSrcRect(o);let{left:s=0,top:c=0,bottom:l=0,right:u=0}=o;t.transformByStateCloseCropper({left:n+s,top:r+c,width:i-u-s,height:a-l-c})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==D.id)return;let r=e.params;if(r==null)return;let{unitId:i,subUnitId:a,drawingId:s}=r,c=this._renderManagerService.getRenderById(i),l=c==null?void 0:c.scene;if(l==null)return!0;if(this._sceneListenerOnImageMap.has(l)||(this._addListenerOnImage(l),this._sceneListenerOnImageMap.add(l)),this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:a,drawingId:s})==null)return;let u=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:s}),d=l.getObject(u);if(d==null)return;if(!(d instanceof n.Image)){this._messageService.show({type:o.MessageType.Error,content:this._localeService.t(`image-cropper.error`)});return}let f=l.getTransformer();f==null||f.clearControls();let p=new Y(`${u}-crop`,{srcRect:d.srcRect,prstGeom:d.prstGeom,applyTransform:d.calculateTransformWithSrcRect()});l.addObject(p,d.getLayerIndex()+1).attachTransformerTo(p),f==null||f.createControlForCopper(p),this._addHoverForImageCopper(p),d.openRenderByCropper(),f==null||f.refreshControls(),p.makeDirty(!0),this._commandService.syncExecuteCommand(t.SetDrawingSelectedOperation.id,[{unitId:i,subUnitId:a,drawingId:s}])}))}_searchCropObject(e){let t=e.getAllObjectsByOrder();for(let e of t)if(e instanceof Y)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==O.id)return;let t=this._univerInstanceService.getFocusedUnit();if(t==null)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n),i=r==null?void 0:r.scene;if(i==null)return!0;let a=this._searchCropObject(i);if(a==null)return;let o=this._getApplyObjectByCropObject(a);if(o==null)return;let s=i.getTransformerByCreate();s.detachFrom(a),s.clearCopperControl();let c=this._getSrcRectByTransformState(o,a),l=this._drawingManagerService.getDrawingOKey(o.oKey);if(l!=null){let{left:e,top:t,height:n,width:r}=a;this._drawingManagerService.featurePluginUpdateNotification([{...l,transform:{...l.transform,left:e,top:t,height:n,width:r},srcRect:c.srcRectAngle}])}o.setSrcRect({...c.srcRectAngle}),o.closeRenderByCropper(),o.makeDirty(!0),a==null||a.dispose()}));let t=this._univerInstanceService.getCurrentTypeOfUnit$(e.UniverInstanceType.UNIVER_SHEET).pipe((0,a.switchMap)(e=>e?e.activeSheet$:(0,a.of)(null)));this.disposeWithMe(t.subscribe(()=>{this._commandService.syncExecuteCommand(O.id)}))}_getApplyObjectByCropObject(e){let t=e.oKey,n=t.slice(0,t.length-5),r=e.getScene();if(!r)return null;let i=r.getObject(n);return i==null?null:i}_addListenerOnImage(t){let n=t.getTransformerByCreate(),r=null;this.disposeWithMe(n.changeStart$.subscribe(e=>{let{objects:t}=e,i=t.values().next().value;if(i==null||!(i instanceof Y))return;let{left:a,top:o,height:s,width:c,angle:l}=i;r={left:a,top:o,height:s,width:c,angle:l},n.clearCopperControl()})),this.disposeWithMe(n.changeEnd$.subscribe(t=>{let{objects:i}=t,a=i.values().next().value;if(a==null||!(a instanceof Y))return;let{left:o,top:s,height:c,width:l,angle:u}=a;if(!(0,e.checkIfMove)({left:o,top:s,height:c,width:l,angle:u},r))return;let d=this._getApplyObjectByCropObject(a);if(d==null)return;let f=this._getSrcRectByTransformState(d,a);a.refreshSrcRect(f.srcRect,d.getState()),n.createControlForCopper(a)})),this._endCropListener(t)}_addHoverForImageCopper(e){this.disposeWithMe(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=n.CURSOR_TYPE.MOVE})),this.disposeWithMe(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=n.CURSOR_TYPE.DEFAULT}))}_endCropListener(e){let t=e.getTransformerByCreate();this.disposeWithMe(t.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(O.id)}))}_getSrcRectByTransformState(e,t){let{left:r,top:i,height:a,width:o,strokeWidth:s,angle:c}=t,{left:l,top:u,width:d,height:f,angle:p,strokeWidth:m}=e,h=r-l,g=i-u,_={left:h,top:g,right:d-h-o,bottom:f-g-a},v={..._};if(p!==0){let e=new n.Vector2(r+o/2,i+a/2),t=new n.Vector2(d/2+l,f/2+u),s=new n.Vector2(l,u);s.rotateByPoint((0,n.degToRad)(p),t);let c=s.clone();c.rotateByPoint((0,n.degToRad)(-p),e);let m=r-c.x,h=i-c.y;v.left=m,v.top=h,v.right=d-m-o,v.bottom=f-h-a}return{srcRect:_,srcRectAngle:v}}};X=H([V(0,e.ICommandService),V(1,t.IDrawingManagerService),V(2,n.IRenderManagerService),V(3,e.IUniverInstanceService),V(4,i.IMessageService),V(5,(0,e.Inject)(e.LocaleService))],X);let Z=class{constructor(e,t,n,r,i){this._drawingManagerService=e,this._imageIoService=t,this._galleryService=n,this._urlImageService=r,this._univerInstanceService=i}async renderImages(r,i){let{transform:a,drawingType:o,source:s,imageSourceType:c,srcRect:l,prstGeom:u,groupId:d,unitId:f,subUnitId:p,drawingId:m,isMultiTransform:h,transforms:g}=r;if(o!==e.DrawingTypeEnum.DRAWING_IMAGE||!this._drawingManagerService.getDrawingVisible()||this._univerInstanceService.getUnitType(f)===e.UniverInstanceType.UNIVER_SHEET&&p!==this._getActiveSheetId()||a==null)return;let _=h&&g?g:[a],v=[];for(let e of _){let{left:r,top:a,width:o,height:g,angle:y,flipX:b,flipY:x,skewX:S,skewY:C}=e,w=_.indexOf(e),T=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:f,subUnitId:p,drawingId:m},h?w:void 0),E=i.getObject(T);if(E!=null){E.transformByState({left:r,top:a,width:o,height:g,angle:y,flipX:b,flipY:x,skewX:S,skewY:C});continue}let D=this._drawingManagerService.getDrawingOrder(f,p),O=D.indexOf(m),k={...e,zIndex:O===-1?D.length-1:O},A=this._imageIoService.getImageSourceCache(s,c),j=!1;if(A!=null)k.image=A;else if(c===t.ImageSourceType.UUID)try{k.url=await this._imageIoService.getImage(s)}catch(e){console.error(e);continue}else if(c===t.ImageSourceType.URL){try{k.url=await this._urlImageService.getImage(s)}catch(e){console.error(e),k.url=s}j=!0}else k.url=s,j=!0;if(i.getObject(T))continue;k.printable=!0;let N=new n.Image(T,k);j&&this._imageIoService.addImageSourceCache(s,c,N.getNative()),i.addObject(N,n.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&i.attachTransformerTo(N),d&&M({drawingId:d,unitId:f,subUnitId:p},N,i,this._drawingManagerService),u!=null&&N.setPrstGeom(u),l!=null&&N.setSrcRect(l),v.push(N)}return v}_getActiveSheetId(){var t;return(t=this._univerInstanceService.getCurrentUnitOfType(e.UniverInstanceType.UNIVER_SHEET))==null||(t=t.getActiveSheet())==null?void 0:t.getSheetId()}renderFloatDom(r,i){let{transform:a,drawingType:o,groupId:s,unitId:c,subUnitId:l,drawingId:u,isMultiTransform:d,transforms:f}=r;if(o!==e.DrawingTypeEnum.DRAWING_DOM||!this._drawingManagerService.getDrawingVisible()||a==null)return;let p=d&&f?f:[a],m=[];for(let e of p){let{left:a,top:o,width:f,height:h,angle:g,flipX:_,flipY:v,skewX:y,skewY:b}=e,x=p.indexOf(e),S=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:c,subUnitId:l,drawingId:u},d?x:void 0),C=i.getObject(S);if(C!=null){C.transformByState({left:a,top:o,width:f,height:h,angle:g,flipX:_,flipY:v,skewX:y,skewY:b});continue}let w=this._drawingManagerService.getDrawingOrder(c,l),T=w.indexOf(u),E={...e,zIndex:T===-1?w.length-1:T};if(i.getObject(S))continue;E.printable=!1;let D=new n.Rect(S,E);this._drawingManagerService.getDrawingVisible()&&(i.addObject(D,n.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&r.allowTransform!==!1&&i.attachTransformerTo(D),s&&M({drawingId:s,unitId:c,subUnitId:l},D,i,this._drawingManagerService),m.push(D))}return m}renderDrawing(t,n){let r=this._drawingManagerService.getDrawingByParam(t);if(r!=null)switch(r.drawingType){case e.DrawingTypeEnum.DRAWING_IMAGE:return this.renderImages(r,n);default:}}previewImage(e,t,n,r){this._galleryService.open({images:[t],onOpenChange:e=>{e||this._galleryService.close()}})}_adjustImageSize(e,t,n,r){if(e<=n&&t<=r)return{width:e,height:t};let i=n/e,a=r/t,o=Math.min(i,a);return{width:Math.floor(e*o),height:Math.floor(t*o)}}};Z=H([V(0,t.IDrawingManagerService),V(1,t.IImageIoService),V(2,i.IGalleryService),V(3,e.IURLImageService),V(4,e.IUniverInstanceService)],Z);let Q=class extends e.Disposable{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._drawingManagerService=n,this._dialogService=r,this._imageIoService=i,this._currentUniverService=a,this._drawingRenderService=o,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===j.id){let t=e.params;if(t==null)return;this._resetImageSize(t)}}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_resetImageSize(n){let r=[],i=[];n.forEach(n=>{let{unitId:a,subUnitId:o,drawingId:s}=n,c=this._getSceneAndTransformerByDrawingSearch(a);if(c==null)return;let{scene:l}=c,u=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:a,subUnitId:o,drawingId:s}),d=l.getObject(u);if(d==null)return!0;let f=this._drawingManagerService.getDrawingByParam(n);if(f==null)return!0;if(f.drawingType!==e.DrawingTypeEnum.DRAWING_IMAGE)return;d.resetSize();let{width:p,height:m}=d.getNativeSize();i.includes(l)===!1&&i.push(l),r.push({...f,transform:{...f.transform,height:m,width:p,angle:0},srcRect:null,prstGeom:null})}),this._drawingManagerService.featurePluginUpdateNotification(r),i.forEach(e=>{e.getTransformerByCreate().refreshControls().changeNotification()}),this._commandService.syncExecuteCommand(t.SetDrawingSelectedOperation.id,n)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.pipe((0,a.bufferTime)(33),(0,a.filter)(e=>e.length>0),(0,a.map)(e=>e.flat()),(0,a.map)(e=>{let t=new Map;for(let n of e)t.set(`${n.unitId}|${n.subUnitId}|${n.drawingId}`,n);return[...t.values()]}),(0,a.filter)(e=>e.length>0)).subscribe(e=>{this._insertImages(e)}))}_insertImages(e){e.forEach(async e=>{var t;let{unitId:n,subUnitId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(n),a=(t=N(this._currentUniverService,n))==null?void 0:t.subUnitId;if(i==null||a!==r)return;let o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let s=await this._drawingRenderService.renderImages(o,i.scene);if(this._drawingManagerService.refreshTransform([o]),!(s==null||s.length===0))for(let e of s)this._addHoverForImage(e),this._addDialogForImage(e)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(n=>{n.forEach(n=>{let{unitId:r,subUnitId:i,drawingId:a}=n,o=this._drawingManagerService.getDrawingByParam(n);if(o==null)return;let{transform:s,drawingType:c,srcRect:l,prstGeom:u,source:d,imageSourceType:f}=o;if(c!==e.DrawingTypeEnum.DRAWING_IMAGE)return;let p=this._getSceneAndTransformerByDrawingSearch(r);if(p==null)return;let{scene:m,transformer:h}=p;if(s==null)return!0;let g=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:r,subUnitId:i,drawingId:a}),_=m.getObject(g);if(_==null)return!0;_.setSrcRect(l),_.setPrstGeom(u),d!=null&&d.length>0&&(f===e.ImageSourceType.BASE64||f===e.ImageSourceType.URL)&&_.changeSource(d)})}))}_addHoverForImage(t){this.disposeWithMe((0,e.toDisposable)(t.onPointerEnter$.subscribeEvent(()=>{t.cursor=n.CURSOR_TYPE.GRAB}))),this.disposeWithMe((0,e.toDisposable)(t.onPointerLeave$.subscribeEvent(()=>{t.cursor=n.CURSOR_TYPE.DEFAULT})))}_addDialogForImage(t){this.disposeWithMe((0,e.toDisposable)(t.onDblclick$.subscribeEvent(()=>{let e=`${t.oKey}-viewer-dialog`;this._drawingRenderService.previewImage(e,t.getNative().src,t.getNativeSize().width,t.getNativeSize().height)})))}};Q=H([V(0,e.ICommandService),V(1,n.IRenderManagerService),V(2,t.IDrawingManagerService),V(3,i.IDialogService),V(4,t.IImageIoService),V(5,e.IUniverInstanceService),V(6,(0,e.Inject)(Z))],Q);let $=class extends e.Plugin{constructor(t=ee,n,r){super(),this._config=t,this._injector=n,this._configService=r;let{menu:i,...a}=(0,e.merge)({},ee,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(I,a)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(q),this._injector.get(U),this._injector.get(X),this._injector.get(Q)}_initDependencies(){[[Z],[q],[U],[X],[Q]].forEach(e=>this._injector.add(e))}};K($,`pluginName`,`UNIVER_DRAWING_UI_PLUGIN`),K($,`packageName`,P),K($,`version`,F),$=H([V(1,(0,e.Inject)(e.Injector)),V(2,e.IConfigService)],$);const we=t=>{let n=(0,i.useDependency)(e.ICommandService),r=(0,i.useDependency)(e.LocaleService),{drawings:a,alignShow:d}=t,[f,p]=(0,s.useState)(l.default),m=[{label:r.t(`image-panel.align.default`),value:l.default},{options:[{label:r.t(`image-panel.align.left`),value:l.left},{label:r.t(`image-panel.align.center`),value:l.center},{label:r.t(`image-panel.align.right`),value:l.right}]},{options:[{label:r.t(`image-panel.align.top`),value:l.top},{label:r.t(`image-panel.align.middle`),value:l.middle},{label:r.t(`image-panel.align.bottom`),value:l.bottom}]},{options:[{label:r.t(`image-panel.align.horizon`),value:l.horizon},{label:r.t(`image-panel.align.vertical`),value:l.vertical}]}];function h(e){p(e),n.executeCommand(u.id,{alignType:e,drawings:a})}return(0,c.jsxs)(`div`,{className:(0,o.clsx)(`univer-relative univer-w-full`,{"univer-hidden":!d}),children:[(0,c.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,c.jsx)(`div`,{children:r.t(`image-panel.align.title`)})}),(0,c.jsx)(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:(0,c.jsx)(`div`,{className:`univer-w-full univer-text-gray-900 dark:!univer-text-white`,children:(0,c.jsx)(o.Select,{value:f,options:m,onChange:h})})})]})},Te=n=>{let{arrangeShow:r,drawings:a}=n,l=(0,i.useDependency)(e.LocaleService),u=(0,i.useDependency)(t.IDrawingManagerService),d=(0,i.useDependency)(e.ICommandService),f=(0,i.useDependency)(i.ComponentManager),p=f.get(`MoveUpIcon`),m=f.get(`MoveDownIcon`),h=f.get(`TopmostIcon`),g=f.get(`BottomIcon`),[_,v]=(0,s.useState)(a);(0,s.useEffect)(()=>{let e=u.focus$.subscribe(e=>{v(e)});return()=>{e.unsubscribe()}},[]);let b=e=>{d.syncExecuteCommand(y.id,{arrangeType:e,drawings:_})};return(0,c.jsxs)(`div`,{className:(0,o.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!r}),children:[(0,c.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,c.jsx)(`div`,{children:l.t(`image-panel.arrange.title`)})}),(0,c.jsxs)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:[(0,c.jsxs)(o.Button,{onClick:()=>{b(e.ArrangeTypeEnum.forward)},children:[(0,c.jsx)(p,{}),l.t(`image-panel.arrange.forward`)]}),(0,c.jsxs)(o.Button,{onClick:()=>{b(e.ArrangeTypeEnum.backward)},children:[(0,c.jsx)(m,{}),l.t(`image-panel.arrange.backward`)]}),(0,c.jsxs)(o.Button,{onClick:()=>{b(e.ArrangeTypeEnum.front)},children:[(0,c.jsx)(h,{}),l.t(`image-panel.arrange.front`)]}),(0,c.jsxs)(o.Button,{onClick:()=>{b(e.ArrangeTypeEnum.back)},children:[(0,c.jsx)(g,{}),l.t(`image-panel.arrange.back`)]})]})]})},Ee=r=>{let a=(0,i.useDependency)(e.LocaleService),l=(0,i.useDependency)(n.IRenderManagerService),u=(0,i.useDependency)(t.IDrawingManagerService),d=(0,i.useDependency)(e.ICommandService),f=(0,i.useDependency)(i.ComponentManager),{hasGroup:p,drawings:m}=r,h=f.get(`GroupIcon`),g=f.get(`UngroupIcon`),[_,v]=(0,s.useState)(!1),[y,b]=(0,s.useState)(!0),[x,S]=(0,s.useState)(!0),C=()=>{d.syncExecuteCommand(T.id,{drawings:m})},w=()=>{d.syncExecuteCommand(E.id,{drawings:m})};return(0,s.useEffect)(()=>{let t=m[0];if(t==null)return;let{unitId:n}=t,r=l.getRenderById(n),i=r==null?void 0:r.scene;if(i==null)return;let a=i.getTransformerByCreate(),o=a.clearControl$.subscribe(e=>{e===!0&&v(!1)}),s=a.changeStart$.subscribe(t=>{let{objects:n}=t,r=W(n,u),i=r.filter(t=>(t==null?void 0:t.drawingType)===e.DrawingTypeEnum.DRAWING_GROUP),a=!1,o=!1;r.length>1&&(a=!0),i.length>0&&(o=!0),v(a||o),b(a),S(o)});return()=>{s.unsubscribe(),o.unsubscribe()}},[]),(0,c.jsxs)(`div`,{className:(0,o.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":p===!0&&_===!1||p===!1}),children:[(0,c.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,c.jsx)(`div`,{children:a.t(`image-panel.group.title`)})}),(0,c.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[(0,c.jsxs)(o.Button,{className:(0,o.clsx)({"univer-hidden":!y}),onClick:C,children:[(0,c.jsx)(h,{}),a.t(`image-panel.group.group`)]}),(0,c.jsxs)(o.Button,{className:(0,o.clsx)({"univer-hidden":!x}),onClick:w,children:[(0,c.jsx)(g,{}),a.t(`image-panel.group.unGroup`)]})]})]})},De=[-360,360],Oe=r=>{var a;let l=(0,i.useDependency)(e.LocaleService),u=(0,i.useDependency)(t.IDrawingManagerService),d=(0,i.useDependency)(n.IRenderManagerService),{drawings:f,transformShow:p}=r,m=f[0];if(m==null)return;let h=m.transform;if(h==null)return;let{unitId:g,subUnitId:_,drawingId:v,drawingType:y}=m,b=d.getRenderById(g),x=b==null?void 0:b.scene;if(x==null)return;let S=(a=x.getEngine())==null?void 0:a.activeScene;if(S==null)return;let C=x.getTransformerByCreate(),{width:w=0,height:T=0,left:E=0,top:D=0,angle:O=0}=h,[k,A]=(0,s.useState)(w),[j,M]=(0,s.useState)(T),[N,P]=(0,s.useState)(E),[F,I]=(0,s.useState)(D),[ee,L]=(0,s.useState)(O),[R,te]=(0,s.useState)(C.keepRatio),z=(e,t,n,r)=>{let{width:i,height:a}=S,{ancestorLeft:o,ancestorTop:s}=x,c=e,l=t,u=n,d=r;return e+o<0&&(c=-o),t+s<0&&(l=-s),u=i-c-o,u<20&&(u=20),d=a-l-s,d<20&&(d=20),e+u+o>i&&(c=i-n-o),t+d+s>a&&(l=a-r-s),{limitLeft:c,limitTop:l,limitWidth:u,limitHeight:d}},B=e=>{let{objects:t}=e,n=W(t,u);if(n.length!==1)return;let r=n[0];if(r==null)return;let{transform:i}=r;if(i==null)return;let{width:a,height:o,left:s,top:c,angle:l}=i;a!=null&&A(a),o!=null&&M(o),s!=null&&P(s),c!=null&&I(c),l!=null&&L(l)};(0,s.useEffect)(()=>{let e=[C.changeStart$.subscribe(e=>{B(e)}),C.changing$.subscribe(e=>{B(e)}),C.changeEnd$.subscribe(e=>{B(e)}),u.focus$.subscribe(e=>{if(e.length!==1)return;let t=u.getDrawingByParam(e[0]);if(t==null)return;let n=t.transform;if(n==null)return;let{width:r,height:i,left:a,top:o,angle:s}=n;r!=null&&A(r),i!=null&&M(i),a!=null&&P(a),o!=null&&I(o),s!=null&&L(s)})];return()=>{e.forEach(e=>e.unsubscribe())}},[]);let ne=(0,e.debounce)(e=>{if(e==null)return;let{limitWidth:t,limitHeight:n}=z(N,F,e,j);e=Math.min(e,t);let r={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{width:e}};if(R){let t=e/k*j;if(t=Math.max(t,20),t>n)return;M(t),r.transform.height=t}A(e),u.featurePluginUpdateNotification([r]),C.refreshControls().changeNotification()},300),re=(0,e.debounce)(e=>{if(e==null)return;let{limitHeight:t,limitWidth:n}=z(N,F,k,e);e=Math.min(e,t);let r={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{height:e}};if(R){let t=e/j*k;if(t=Math.max(t,20),t>n)return;A(t),r.transform.width=t}M(e),u.featurePluginUpdateNotification([r]),C.refreshControls().changeNotification()},300),ie=(0,e.debounce)(e=>{if(e==null)return;let{limitLeft:t}=z(e,F,k,j);e=t;let n={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{left:e}};P(e),u.featurePluginUpdateNotification([n]),C.refreshControls().changeNotification()},300),ae=(0,e.debounce)(e=>{if(e==null)return;let{limitTop:t}=z(N,e,k,j);e=t;let n={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{top:e}};I(e),u.featurePluginUpdateNotification([n]),C.refreshControls().changeNotification()},300),oe=e=>{if(e==null)return;let t={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{angle:e}};L(e),u.featurePluginUpdateNotification([t]),C.refreshControls().changeNotification()},se=e=>{te(e),C.keepRatio=e};return(0,c.jsxs)(`div`,{className:(0,o.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!p}),children:[(0,c.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,c.jsx)(`div`,{children:l.t(`image-panel.transform.title`)})}),(0,c.jsxs)(`div`,{className:`univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2`,children:[(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.width`)}),(0,c.jsx)(o.InputNumber,{precision:1,value:k,min:20,onChange:e=>{ne(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.height`)}),(0,c.jsx)(o.InputNumber,{precision:1,value:j,min:20,onChange:e=>{re(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.lock`)}),(0,c.jsx)(`div`,{className:`univer-text-center`,children:(0,c.jsx)(o.Checkbox,{checked:R,onChange:se})})]})]}),(0,c.jsxs)(`div`,{className:`univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2`,children:[(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.x`)}),(0,c.jsx)(o.InputNumber,{precision:1,value:N,onChange:e=>{ie(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.y`)}),(0,c.jsx)(o.InputNumber,{precision:1,value:F,onChange:e=>{ae(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.rotate`)}),(0,c.jsx)(o.InputNumber,{precision:1,value:ee,min:De[0],max:De[1],onChange:oe})]})]})]})},ke=t=>{let n=(0,i.useDependency)(e.ICommandService),a=(0,i.useDependency)(e.LocaleService),{drawings:l,cropperShow:u}=t;if(l[0]==null)return;let[d,f]=(0,s.useState)(k.FREE),p=(0,s.useRef)(!1),m=[{label:a.t(`image-panel.crop.mode`),value:k.FREE},{label:`1:1`,value:k.R1_1},{label:`16:9`,value:k.R16_9},{label:`9:16`,value:k.R9_16},{label:`5:4`,value:k.R5_4},{label:`4:5`,value:k.R4_5},{label:`4:3`,value:k.R4_3},{label:`3:4`,value:k.R3_4},{label:`3:2`,value:k.R3_2},{label:`2:3`,value:k.R2_3}];(0,s.useEffect)(()=>{let e=n.onCommandExecuted(e=>{if(e.id===O.id){let t=e.params;t!=null&&t.isAuto||(p.current=!1)}});return()=>{e==null||e.dispose()}},[]);function h(e){f(e),p.current&&n.executeCommand(A.id,{cropType:e})}let g=e=>{n.executeCommand(A.id,{cropType:e}),p.current=!0};return(0,c.jsxs)(`div`,{className:(0,o.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!u}),children:[(0,c.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,c.jsx)(`div`,{children:a.t(`image-panel.crop.title`)})}),(0,c.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[(0,c.jsxs)(o.Button,{onClick:()=>{g(d)},children:[(0,c.jsx)(r.CreateCopyIcon,{}),a.t(`image-panel.crop.start`)]}),(0,c.jsx)(o.Select,{value:d,options:m,onChange:h})]})]})},Ae=r=>{let a=(0,i.useDependency)(t.IDrawingManagerService),l=(0,i.useDependency)(n.IRenderManagerService),u=(0,i.useDependency)(e.LocaleService),{drawings:d,hasArrange:f=!0,hasTransform:p=!0,hasAlign:m=!0,hasCropper:h=!0,hasGroup:g=!0}=r,_=d[0];if(_==null)return;let{unitId:v}=_,y=l.getRenderById(v),b=y==null?void 0:y.scene;if(b==null)return;let x=b.getTransformerByCreate(),[S,C]=(0,s.useState)(!0),[w,T]=(0,s.useState)(!0),[E,D]=(0,s.useState)(!1),[O,k]=(0,s.useState)(!0),[A,j]=(0,s.useState)(!1);return(0,s.useEffect)(()=>{let e=x.clearControl$.subscribe(e=>{e===!0&&(C(!1),T(!1),D(!1),k(!1),j(!0))}),t=x.changeStart$.subscribe(e=>{let{objects:t}=e,n=W(t,a);n.length===0?(C(!1),T(!1),D(!1),k(!1),j(!0)):n.length===1?(C(!0),T(!0),D(!1),k(!0),j(!1)):(C(!0),T(!1),D(!0),k(!1),j(!1))}),n=a.focus$.subscribe(e=>{e.length===0?(C(!1),T(!1),D(!1),k(!1),j(!0)):e.length===1?(C(!0),T(!0),D(!1),k(!0),j(!1)):(C(!0),T(!1),D(!0),k(!1),j(!1))});return()=>{t.unsubscribe(),e.unsubscribe(),n.unsubscribe()}},[]),(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`div`,{className:(0,o.clsx)(`univer-h-full`,{"univer-hidden":!A}),children:(0,c.jsx)(`div`,{className:`univer-flex univer-h-full univer-items-center univer-justify-center`,children:(0,c.jsx)(`span`,{children:u.t(`image-panel.null`)})})}),(0,c.jsx)(Te,{arrangeShow:f===!0?S:!1,drawings:d}),(0,c.jsx)(Oe,{transformShow:p===!0?w:!1,drawings:d}),(0,c.jsx)(we,{alignShow:m===!0?E:!1,drawings:d}),(0,c.jsx)(ke,{cropperShow:h===!0?O:!1,drawings:d}),(0,c.jsx)(Ee,{hasGroup:g,drawings:d})]})};exports.AutoImageCropOperation=A,exports.COMPONENT_IMAGE_POPUP_MENU=be,exports.CancelDrawingGroupOperation=E,exports.CloseImageCropOperation=O,exports.DRAWING_GROUP_TYPES=w,exports.DrawingCommonPanel=Ae,Object.defineProperty(exports,`DrawingRenderService`,{enumerable:!0,get:function(){return Z}}),exports.ImageCropperObject=Y,exports.ImagePopupMenu=xe,exports.ImageResetSizeOperation=j,exports.OpenImageCropOperation=D,exports.SetDrawingAlignOperation=u,exports.SetDrawingArrangeOperation=y,exports.SetDrawingGroupOperation=T,Object.defineProperty(exports,`UniverDrawingUIPlugin`,{enumerable:!0,get:function(){return $}}),exports.getCurrentUnitInfo=N,exports.getUpdateParams=W,exports.insertGroupObject=M;
|
package/lib/es/index.js
CHANGED
|
@@ -1,32 +1 @@
|
|
|
1
|
-
import{ArrangeTypeEnum as e,CommandType as t,Disposable as n,DrawingTypeEnum as r,ICommandService as i,IConfigService as a,IURLImageService as o,IUniverInstanceService as s,ImageSourceType as c,Inject as l,Injector as u,LocaleService as d,Plugin as f,UniverInstanceType as p,checkIfMove as m,debounce as h,generateRandomId as g,merge as _,toDisposable as v}from"@univerjs/core";import{IDrawingManagerService as y,IImageIoService as b,ImageSourceType as x,SetDrawingSelectedOperation as S,getDrawingShapeKeyByDrawingSearch as C}from"@univerjs/drawing";import{CURSOR_TYPE as w,Canvas as T,DRAWING_OBJECT_LAYER_INDEX as E,DrawingGroupObject as D,Group as O,IRenderManagerService as k,Image as A,RENDER_CLASS_TYPE as j,Rect as M,Shape as N,Vector2 as P,degToRad as ee,getGroupState as te,precisionTo as ne,transformObjectOutOfGroup as re}from"@univerjs/engine-render";import{AutofillDoubleIcon as ie,BottomIcon as ae,CreateCopyIcon as oe,GroupIcon as se,MoreDownIcon as ce,MoveDownIcon as le,MoveUpIcon as ue,TopmostIcon as de,UngroupIcon as fe}from"@univerjs/icons";import{ComponentManager as pe,ContextMenuGroup as me,ContextMenuPosition as he,IDialogService as ge,IGalleryService as _e,IMenuManagerService as ve,IMessageService as ye,MenuItemType as F,useDependency as I}from"@univerjs/ui";import{Observable as be,bufferTime as xe,filter as Se,map as Ce,of as we,switchMap as Te}from"rxjs";import{Button as L,Checkbox as Ee,DropdownMenu as De,InputNumber as R,MessageType as Oe,Select as ke,borderClassName as Ae,clsx as z}from"@univerjs/design";import{useEffect as je,useRef as Me,useState as B}from"react";import{Fragment as Ne,jsx as V,jsxs as H}from"react/jsx-runtime";let U=function(e){return e.default=`0`,e.left=`1`,e.center=`2`,e.right=`3`,e.top=`4`,e.middle=`5`,e.bottom=`6`,e.horizon=`7`,e.vertical=`8`,e}({});const W={id:`sheet.operation.set-image-align`,type:t.OPERATION,handler:(e,t)=>!0},Pe={id:`sheet.operation.set-drawing-align-left`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.left})},Fe={id:`sheet.operation.set-drawing-align-center`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.center})},Ie={id:`sheet.operation.set-drawing-align-right`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.right})},Le={id:`sheet.operation.set-drawing-align-top`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.top})},Re={id:`sheet.operation.set-drawing-align-middle`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.middle})},ze={id:`sheet.operation.set-drawing-align-bottom`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.bottom})},Be={id:`sheet.operation.set-drawing-align-horizon`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.horizon})},Ve={id:`sheet.operation.set-drawing-align-vertical`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.vertical})},G={id:`drawing.operation.set-drawing-arrange`,type:t.OPERATION,handler:(e,t)=>{let n=e.get(y),{arrangeType:r}=t,i=t.drawings||n.getFocusDrawings(),{unitId:a,subUnitId:o}=i[0],s=i.map(e=>e.drawingId);return n.featurePluginOrderUpdateNotification({unitId:a,subUnitId:o,drawingIds:s,arrangeType:r}),!0}},He={id:`drawing.operation.set-drawing-arrange-front`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.front})},Ue={id:`drawing.operation.set-drawing-arrange-forward`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.forward})},We={id:`drawing.operation.set-drawing-arrange-back`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.back})},Ge={id:`drawing.operation.set-drawing-arrange-backward`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.backward})},Ke=[r.DRAWING_IMAGE,r.DRAWING_SHAPE,r.DRAWING_GROUP],K={id:`drawing.operation.set-drawing-group`,type:t.OPERATION,handler:(e,t)=>{let n=e.get(y),i=t.drawings||n.getFocusDrawings();if(i.length<2||!i.every(e=>Ke.includes(e.drawingType)))return!1;let{unitId:a,subUnitId:o}=i[0],s=g(10),c=te(0,0,i.map(e=>e.transform||{})),l={unitId:a,subUnitId:o,drawingId:s,drawingType:r.DRAWING_GROUP,transform:c,groupBaseBound:{left:c.left,top:c.top,width:c.width,height:c.height}},u=i.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t},groupId:s}});return n.featurePluginGroupUpdateNotification([{parent:l,children:u}]),!0}},q={id:`drawing.operation.cancel-drawing-group`,type:t.OPERATION,handler:(e,t)=>{let n=e.get(y),i=(t.drawings||n.getFocusDrawings()).map(e=>{if(e.drawingType!==r.DRAWING_GROUP)return null;let{unitId:t,subUnitId:i,drawingId:a,transform:o={width:0,height:0},groupBaseBound:s}=e;if(o===null)return null;let c=n.getDrawingsByGroup({unitId:t,subUnitId:i,drawingId:a});return c.length===0?null:{parent:e,children:c.map(e=>{let{transform:t}=e,{unitId:n,subUnitId:r,drawingId:i}=e,a=re(t||{},o,o.width||0,o.height||0,s);return{unitId:n,subUnitId:r,drawingId:i,transform:{...t,...a},groupId:void 0}})}}).filter(e=>e!==null);return i.length===0?!1:(n.featurePluginUngroupUpdateNotification(i),!0)}},qe={id:`sheet.operation.open-image-crop`,type:t.OPERATION,handler:(e,t)=>!0},J={id:`sheet.operation.close-image-crop`,type:t.OPERATION,handler:(e,t)=>!0};let Y=function(e){return e.FREE=`0`,e.R1_1=`1`,e.R16_9=`2`,e.R9_16=`3`,e.R5_4=`4`,e.R4_5=`5`,e.R4_3=`6`,e.R3_4=`7`,e.R3_2=`8`,e.R2_3=`9`,e}({});const Je={id:`sheet.operation.Auto-image-crop`,type:t.OPERATION,handler:(e,t)=>!0},Ye={id:`sheet.operation.image-reset-size`,type:t.OPERATION,handler:(e,t)=>!0};function Xe(e,t,n,r){let i=r.getDrawingByParam(e);if(i==null)return;let a=C(e),o=n.getObjectIncludeInGroup(a);if(o&&!(o instanceof O))return;if(o!=null){let e=o.getObjects();for(let n of e)if(n.oKey===t.oKey)return;o.addObject(t);return}let s=new D(a);n.addObject(s,E).attachTransformerTo(s),s.addObject(t);let{transform:c,groupBaseBound:l}=i;l&&s.setBaseBound(l),i.groupId&&(s.isInGroup=!0,Xe({drawingId:i.groupId,unitId:e.unitId,subUnitId:e.subUnitId},s,n,r)),c&&s.transformByState({left:c.left,top:c.top,angle:c.angle,width:c.width,height:c.height})}function Ze(e,t){let n=t?e.getUnit(t):e.getFocusedUnit();if(n==null)return;let r=n.getUnitId(),i;if(n.type===p.UNIVER_SHEET){var a;i=(a=n.getActiveSheet())==null?void 0:a.getSheetId()}else (n.type===p.UNIVER_DOC||n.type===p.UNIVER_SLIDE)&&(i=r);return{unitId:r,subUnitId:i,current:n}}var Qe=`@univerjs/drawing-ui`,$e=`0.18.0`;const et=`drawing-ui.config`;Symbol(et);const tt={},nt=e=>{let t=e.get(y);return new be(e=>{let n=t=>{if(!t||t.length===0||t.length<2)return e.next(!0);e.next(!1)},r=t.focus$.subscribe(t=>{if(!t||t.length===0)return e.next(!0);n(t)});return n(t.getFocusDrawings()),()=>r.unsubscribe()})},rt=`contextMenu.drawing-align`;function it(e){return{id:rt,type:F.SUBITEMS,icon:`HorizontallyIcon`,title:`image-panel.align.title`,hidden$:nt(e)}}function at(){return{id:Pe.id,type:F.BUTTON,icon:`LeftJustifyingIcon`,title:`image-panel.align.left`}}function ot(){return{id:Fe.id,type:F.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.center`}}function st(){return{id:Ie.id,type:F.BUTTON,icon:`RightJustifyingIcon`,title:`image-panel.align.right`}}function ct(){return{id:Le.id,type:F.BUTTON,icon:`AlignTopIcon`,title:`image-panel.align.top`}}function lt(){return{id:Re.id,type:F.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.middle`}}function ut(){return{id:ze.id,type:F.BUTTON,icon:`AlignBottomIcon`,title:`image-panel.align.bottom`}}function dt(){return{id:Be.id,type:F.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.horizon`}}function ft(){return{id:Ve.id,type:F.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.vertical`}}const pt=`contextMenu.drawing-arrange`;function mt(){return{id:pt,type:F.SUBITEMS,icon:`TopmostIcon`,title:`image-panel.arrange.title`}}function ht(){return{id:He.id,type:F.BUTTON,icon:`TopmostIcon`,title:`image-panel.arrange.front`}}function gt(){return{id:Ue.id,type:F.BUTTON,icon:`MoveUpIcon`,title:`image-panel.arrange.forward`}}function _t(){return{id:We.id,type:F.BUTTON,icon:`BottomIcon`,title:`image-panel.arrange.back`}}function vt(){return{id:Ge.id,type:F.BUTTON,icon:`MoveDownIcon`,title:`image-panel.arrange.backward`}}const yt=(e,t)=>{let n=e.get(y);return new be(e=>{let i=n=>{if(!n||n.length===0)return e.next(!0);if(t===`group`){if(n.length<2||!n.every(e=>Ke.includes(e.drawingType)))return e.next(!0)}else if(t===`unGroup`){if(n.filter(e=>e.drawingType===r.DRAWING_GROUP).length===0)return e.next(!0)}else if(!n.every(e=>Ke.includes(e.drawingType)))return e.next(!0);e.next(!1)},a=n.focus$.subscribe(t=>{if(!t||t.length===0)return e.next(!0);i(t)});return i(n.getFocusDrawings()),()=>a.unsubscribe()})},bt=`contextMenu.drawing-group`;function xt(e){return{id:bt,type:F.SUBITEMS,icon:`GroupIcon`,title:`image-panel.group.title`,hidden$:yt(e)}}function St(e){return{id:K.id,type:F.BUTTON,icon:`GroupIcon`,title:`image-panel.group.group`,disabled$:yt(e,`group`)}}function Ct(e){return{id:q.id,type:F.BUTTON,icon:`UngroupIcon`,title:`image-panel.group.unGroup`,disabled$:yt(e,`unGroup`)}}const wt={[he.DRAWING]:{[me.OTHERS]:{[bt]:{order:1,menuItemFactory:xt,[K.id]:{order:0,menuItemFactory:St},[q.id]:{order:1,menuItemFactory:Ct}},[pt]:{order:2,menuItemFactory:mt,[He.id]:{order:0,menuItemFactory:ht},[Ue.id]:{order:1,menuItemFactory:gt},[We.id]:{order:2,menuItemFactory:_t},[Ge.id]:{order:3,menuItemFactory:vt}},[rt]:{order:3,menuItemFactory:it,[Pe.id]:{order:0,menuItemFactory:at},[Fe.id]:{order:1,menuItemFactory:ot},[Ie.id]:{order:2,menuItemFactory:st},[Le.id]:{order:3,menuItemFactory:ct},[Re.id]:{order:4,menuItemFactory:lt},[ze.id]:{order:5,menuItemFactory:ut},[Be.id]:{order:6,menuItemFactory:dt},[Ve.id]:{order:7,menuItemFactory:ft}}}}},Tt=`COMPONENT_IMAGE_POPUP_MENU`;function Et(e){var t;let{popup:n}=e,r=n==null||(t=n.extraProps)==null?void 0:t.menuItems;if(!r)return null;let a=I(i),o=I(d),[s,c]=B(!1),[l,u]=B(!1),f=()=>{u(!0)},p=()=>{u(!1)},m=e=>{c(e)},h=e=>{a.executeCommand(e.commandId,e.commandParams),c(!1)},g=s||l;return V(`div`,{onMouseEnter:f,onMouseLeave:p,children:V(De,{align:`start`,items:r.filter(e=>!e.disable).map(e=>({type:`item`,children:o.t(e.label),onSelect:()=>h(e)})),open:s,onOpenChange:m,children:H(`div`,{className:z(`
|
|
2
|
-
univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1
|
|
3
|
-
hover:univer-bg-gray-100
|
|
4
|
-
dark:hover:!univer-bg-gray-800
|
|
5
|
-
`,Ae,{"univer-bg-gray-100 dark:!univer-bg-gray-800":s,"univer-bg-white dark:!univer-bg-gray-900":!s}),children:[V(ie,{className:`
|
|
6
|
-
univer-fill-primary-600 univer-text-gray-900
|
|
7
|
-
dark:!univer-text-white
|
|
8
|
-
`}),g&&V(ce,{className:`dark:!univer-text-white`})]})})})}function X(e,t){return function(n,r){t(n,r,e)}}function Z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Dt=class extends n{constructor(e,t,n){super(),this._componentManager=e,this._commandService=t,this._menuManagerService=n,this._init()}_init(){this._initMenus(),this._initCommands(),this._initComponents()}_initMenus(){this._menuManagerService.mergeMenu(wt)}_initCommands(){[qe,J,Ye,W,Pe,Fe,Ie,Le,Re,ze,Be,Ve,Je,K,q,G,He,Ue,We,Ge].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initComponents(){[[Tt,Et],[`BottomIcon`,ae],[`GroupIcon`,se],[`MoveDownIcon`,le],[`MoveUpIcon`,ue],[`TopmostIcon`,de],[`UngroupIcon`,fe]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Dt=Z([X(0,l(pe)),X(1,i),X(2,ve)],Dt);function Ot(e,t){let n=[];return e.forEach(e=>{let{oKey:i,left:a,top:o,height:s,width:c,angle:l}=e,u=t.getDrawingOKey(i);if(u==null)return n.push(null),!0;let{unitId:d,subUnitId:f,drawingId:p,drawingType:m}=u,h={unitId:d,subUnitId:f,drawingId:p,drawingType:m,transform:{left:a,top:o,height:s,width:c,angle:l}};m===r.DRAWING_IMAGE&&(h.srcRect=e.srcRect),n.push(h)}),n}function kt(e){"@babel/helpers - typeof";return kt=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},kt(e)}function At(e,t){if(kt(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(kt(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function jt(e){var t=At(e,`string`);return kt(t)==`symbol`?t:t+``}function Q(e,t,n){return(t=jt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let Mt=class extends n{constructor(e,t,n,r){super(),this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._drawingManagerService=r,Q(this,`_sceneListenerOnDrawingMap`,new WeakSet),this._initialize()}dispose(){super.dispose()}_initialize(){this._recoveryImages(),this._drawingAddListener(),this._drawingRemoveListener(),this._drawingUpdateListener(),this._commandExecutedListener(),this._drawingArrangeListener(),this._drawingGroupListener(),this._drawingRefreshListener(),this._drawingVisibleListener()}_recoveryImages(){let e=this._drawingManagerService.drawingManagerData,t=Ze(this._currentUniverService);if(t==null)return;let{unitId:n,subUnitId:r}=t;Object.keys(e).forEach(t=>{Object.keys(e[t]).forEach(i=>{let a=e[t][i].data;a==null||t!==n||i!==r||Object.keys(a).forEach(e=>{a[e]&&this._insertDrawing([{unitId:t,subUnitId:i,drawingId:e}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===W.id){let t=e.params;if(t==null)return;this._drawingAlign(t)}}))}_drawingGroupListener(){this.disposeWithMe(this._drawingManagerService.group$.subscribe(e=>{this._groupDrawings(e)})),this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe(e=>{this._ungroupDrawings(e)}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_groupDrawings(e){e.forEach(e=>{this._groupDrawing(e)})}_groupDrawing(e){let{parent:t,children:n}=e,{unitId:r,subUnitId:i,drawingId:a}=t,o=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(o==null)return;let{scene:s,transformer:c}=o;this._commandService.syncExecuteCommand(J.id);let l=[];if(n.forEach(e=>{let t=C(e),n=s.getObjectIncludeInGroup(t);if(n==null||l.includes(n))return;l.push(n);let{transform:r}=e;r!=null&&(n.classType===j.GROUP?n.transformByState({left:r.left,top:r.top}):n.transformByState(r))}),l.length===0)return;let u=new D(C({unitId:r,subUnitId:i,drawingId:a}));s.addObject(u,E).attachTransformerTo(u),u.addObjects(...l),t.groupBaseBound&&u.setBaseBound(t.groupBaseBound),t.groupId&&(u.isInGroup=!0,Xe({drawingId:t.groupId,unitId:r,subUnitId:i},u,s,this._drawingManagerService)),t.transform&&u.transformByState({left:t.transform.left,top:t.transform.top,width:t.transform.width,height:t.transform.height,angle:t.transform.angle}),c.clearSelectedObjects(),c.setSelectedControl(u)}_ungroupDrawings(e){e.forEach(e=>{this._ungroupDrawing(e)})}_ungroupDrawing(e){let{parent:t,children:n}=e,r=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(r==null)return;let{scene:i,transformer:a}=r;n.forEach(e=>{let t=C(e),n=i.getObjectIncludeInGroup(t);if(n==null)return!0;if(n==null)return;let{transform:r}=e;r!=null&&(n.classType===j.GROUP?n.transformByState({left:r.left,top:r.top}):n.transformByState(r))});let o=C(t),s=i.getObject(o),{width:c,height:l}=s;s.getObjects().forEach(e=>{s.removeSelfObjectAndTransform(e.oKey,c,l)}),s.dispose(),a.clearSelectedObjects()}_drawingAlign(e){let{alignType:t}=e,n=e.drawings||this._drawingManagerService.getFocusDrawings();if(t===U.default)return;let r=[],i=1/0,a=1/0,o=-1/0,s=-1/0,c=0;n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:l,drawingType:u}=e,d=this._drawingManagerService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:l});if(d==null||d.transform==null)return;r.push({unitId:t,subUnitId:n,drawingId:l,drawingType:u,transform:d.transform});let{left:f=0,top:p=0,width:m=0,height:h=0}=d.transform;i=Math.min(i,f),a=Math.min(a,p),o=Math.max(o,f+m),s=Math.max(s,p+h),c++}),c!==0&&(this._sortDrawingTransform(r,t),this._applyAlignType(r,t,i,a,o,s,c))}_applyAlignType(e,t,n,r,i,a,o){let s=Math.round((i-n)/o*10)/10,c=Math.round((a-r)/o*10)/10,l=[],u=this._getSceneAndTransformerByDrawingSearch(e[0].unitId);if(u==null)return;let{scene:d,transformer:f}=u;e.forEach((e,o)=>{let{unitId:u,subUnitId:d,drawingId:f,transform:p,drawingType:m}=e,{left:h=0,top:g=0,width:_=0,height:v=0}=p,y=h,b=g;switch(t){case U.left:y=n;break;case U.center:y=n+(i-n)/2-_/2;break;case U.right:y=i-_;break;case U.top:b=r;break;case U.middle:b=r+(a-r)/2-v/2;break;case U.bottom:b=a-v;break;case U.horizon:y=n+s*o;break;case U.vertical:b=r+c*o;break;default:break}(y!==h||b!==g)&&l.push({unitId:u,subUnitId:d,drawingId:f,drawingType:m,transform:{left:y,top:b}})}),this._drawingManagerService.featurePluginUpdateNotification(l),f.refreshControls().changeNotification()}_sortDrawingTransform(e,t){e.sort((e,n)=>{let r=e.transform,i=n.transform,{left:a=0,top:o=0,width:s=0,height:c=0}=r,{left:l=0,top:u=0,width:d=0,height:f=0}=i;switch(t){case U.left:return a-l;case U.center:return a+s/2-(l+d/2);case U.right:return a+s-(l+d);case U.top:return o-u;case U.middle:return o+c/2-(u+f/2);case U.bottom:return o+c-(u+f);case U.horizon:return a+s/2-(l+d/2);case U.vertical:return o+c/2-(u+f/2);default:return 0}})}_drawingArrangeListener(){this.disposeWithMe(this._drawingManagerService.order$.subscribe(e=>{this._drawingArrange(e)}))}_drawingArrange(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=this._getSceneAndTransformerByDrawingSearch(t);if(i==null)return;let{scene:a}=i;r.forEach(e=>{let r=C({unitId:t,subUnitId:n,drawingId:e}),i=a.fuzzyMathObjects(r,!0);if(i==null||i.length===0)return;let o=this._drawingManagerService.getDrawingOrder(t,n).indexOf(e);for(let e of i)e.setProps({zIndex:o}),e.makeDirty()})}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{this._insertDrawing(e)}))}_insertDrawing(e){let t=[];e.forEach(e=>{let{unitId:n}=e;if(this._drawingManagerService.getDrawingByParam(e)==null)return;let r=this._getSceneAndTransformerByDrawingSearch(n);if(r==null)return;let{scene:i}=r;t.includes(i)||t.push(i)}),t.forEach(e=>{this._sceneListenerOnDrawingMap.has(e)||(this._addListenerOnDrawing(e),this._sceneListenerOnDrawingMap.add(e))})}_drawingRemoveListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(t);if(i==null)return;let{scene:a}=i,o=C({unitId:t,subUnitId:n,drawingId:r}),s=a.fuzzyMathObjects(o,!0);if(s.length>0){var c;for(let e of s)e.dispose();(c=a.getTransformer())==null||c.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{var t;let{unitId:n,subUnitId:r,drawingId:i}=e,a=this._drawingManagerService.getDrawingByParam(e);if(a==null)return;let{transform:o,drawingType:s}=a,c=this._getSceneAndTransformerByDrawingSearch(n);if(c==null)return;let{scene:l,transformer:u}=c;if(o==null)return!0;let{left:d=0,top:f=0,width:p=0,height:m=0,angle:h=0,flipX:g=!1,flipY:_=!1,skewX:v=0,skewY:y=0}=o,b=C({unitId:n,subUnitId:r,drawingId:i}),x=l.getObject(b);if(x==null)return!0;x.transformByState({left:d,top:f,width:p,height:m,angle:h,flipX:g,flipY:_,skewX:v,skewY:y}),(t=l.getTransformer())==null||t.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(t);if(i==null)return;let a=this._drawingManagerService.getDrawingByParam(e);if(a==null)return;let{transform:o}=a,{scene:s}=i,c=C({unitId:t,subUnitId:n,drawingId:r}),l=s.getObject(c);if(l==null||o==null)return!0;let{left:u=0,top:d=0,width:f=0,height:p=0,angle:m=0,flipX:h=!1,flipY:g=!1,skewX:_=0,skewY:v=0}=o;l.transformByState({left:u,top:d,width:f,height:p,angle:m,flipX:h,flipY:g,skewX:_,skewY:v})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r,visible:i}=e,a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{scene:o}=a,s=C({unitId:t,subUnitId:n,drawingId:r}),c=o.getObject(s);if(c==null)return!0;i?c.show():c.hide()})}))}_filterUpdateParams(e,t){return e.filter((e,n)=>{if(e==null)return!1;let{transform:r}=e;return m(r,t==null?void 0:t[n])})}_addListenerOnDrawing(e){let t=e.getTransformerByCreate(),n=null;this.disposeWithMe(v(t.changeStart$.subscribe(e=>{let{objects:t}=e,r=Array.from(t.values()),i=[];n=r.map(e=>{let{left:t,top:n,height:r,width:a,angle:o,oKey:s,isInGroup:c}=e,l=this._drawingManagerService.getDrawingOKey(s);if(c||e instanceof O){let t=e.ancestorGroup;if(t==null&&e instanceof O&&(t=e),t==null)return null;let n=this._drawingManagerService.getDrawingOKey(t.oKey);if(n){let{unitId:e,subUnitId:r,drawingId:a}=n;i.push({unitId:e,subUnitId:r,drawingId:a});let{left:o,top:s,height:c,width:l,angle:u}=t;return{left:o,top:s,height:c,width:l,angle:u}}}else if(l!=null){let{unitId:e,subUnitId:s,drawingId:c}=l;return i.push({unitId:e,subUnitId:s,drawingId:c}),{left:t,top:n,height:r,width:a,angle:o}}return null}).filter(e=>e!=null),i.length>0?this._commandService.syncExecuteCommand(S.id,i):this._commandService.syncExecuteCommand(S.id,[])}))),this.disposeWithMe(v(t.changeEnd$.subscribe(e=>{let{objects:t}=e,r=this._filterUpdateParams(Ot(t,this._drawingManagerService),n);r.length>0&&this._drawingManagerService.featurePluginUpdateNotification(r)})))}};Mt=Z([X(0,s),X(1,i),X(2,k),X(3,y)],Mt);var Nt=function(e){return e[e.RECT=0]=`RECT`,e[e.PATH=1]=`PATH`,e}(Nt||{}),Pt=class extends N{constructor(e,t){t==null&&(t={}),t.transformerConfig={keepRatio:!1,isCropper:!0,anchorFill:`rgb(0, 0, 0)`,anchorStroke:`rgb(255, 255, 255)`,anchorSize:24},super(e,t),Q(this,`_srcRect`,void 0),Q(this,`_prstGeom`,void 0),Q(this,`_applyTransform`,void 0),Q(this,`_dragPadding`,8),Q(this,`_cacheCanvas`,void 0),t!=null&&t.srcRect&&(this._srcRect=t.srcRect),t!=null&&t.prstGeom&&(this._prstGeom=t.prstGeom),t!=null&&t.applyTransform&&(this._applyTransform=t.applyTransform),t!=null&&t.dragPadding&&(this._dragPadding=t.dragPadding),this._applyProps()}refreshSrcRect(e,t){this._srcRect=e,this._applyTransform=t,this._applyProps()}get srcRect(){return this._srcRect}dispose(){var e;super.dispose(),(e=this._cacheCanvas)==null||e.dispose(),this._srcRect=null}isHit(e){let t=this.getInverseCoord(e);return t.x>=-this.strokeWidth/2&&t.x<=this.width+this.strokeWidth/2&&t.y>=-this.strokeWidth/2&&t.y<=this.height+this.strokeWidth/2&&!this._inSurround(t)}_inSurround(e){let t=this._dragPadding;return e.x>=t-this.strokeWidth/2&&e.x<=this.width+this.strokeWidth/2-t&&e.y>=t-this.strokeWidth/2&&e.y<=this.height+this.strokeWidth/2-t}render(e,t){return this.visible?(e.save(),this._draw(e),e.restore(),this.makeDirty(!1),this):(this.makeDirty(!1),this)}_draw(e){var t,n;let{width:r,height:i}=this.getScene().getEngine();this._initialCacheCanvas(),(t=this._cacheCanvas)==null||t.clear();let a=(n=this._cacheCanvas)==null?void 0:n.getContext();a!=null&&(a.save(),M.drawWith(a,{left:0,top:0,width:r,height:i,fill:`rgba(0, 0, 0, 0.5)`}),a.setTransform(e.getTransform()),this._clipForApplyObject(a),this._applyCache(e),a.restore())}_clipForApplyObject(e){let t=Nt.RECT;if(this._prstGeom!=null&&(t=Nt.PATH),e.globalCompositeOperation=`destination-out`,e.beginPath(),t===Nt.RECT){let t=this.transform.getMatrix();e.transform(t[0],t[1],t[2],t[3],t[4],t[5]),e.rect(0,0,this.width,this.height),e.fill()}}_applyProps(){if(this._applyTransform==null)return;let e=0,t=0,n=0,r=0,{left:i=0,top:a=0,width:o=0,height:s=0,angle:c}=this._applyTransform;if(this._srcRect!=null){let{left:i=0,top:a=0,right:o=0,bottom:s=0}=this._srcRect;e=i,t=a,n=o,r=s}let l=i+e,u=a+t;this.transformByState({left:l,top:u,width:i+o-n-l,height:a+s-r-u,angle:c})}_applyCache(e){if(!e||this._cacheCanvas==null)return;let t=this._cacheCanvas.getContext();t.save(),e.save(),e.setTransform(1,0,0,1,0,0),t.setTransform(1,0,0,1,0,0),e.drawImage(this._cacheCanvas.getCanvasEle(),0,0),e.restore(),t.restore()}_initialCacheCanvas(){if(this._cacheCanvas!=null)return;let e=this.getScene();if(e==null)return;this._cacheCanvas=new T;let t=e.getEngine();this._cacheCanvas.setSize(t.width,t.height),t.onTransformChange$.subscribeEvent(()=>{var e;(e=this._cacheCanvas)==null||e.setSize(t.width,t.height),this.makeDirty(!0)})}};let Ft=class extends n{constructor(e,t,n,r,i,a){super(),this._commandService=e,this._drawingManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._messageService=i,this._localeService=a,Q(this,`_sceneListenerOnImageMap`,new WeakSet),this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==Je.id)return;let t=e.params;if(t==null)return;let{cropType:n}=t,r=this._drawingManagerService.getFocusDrawings();if(r.length!==1)return;let{unitId:i,subUnitId:a,drawingId:o}=r[0],s=this._renderManagerService.getRenderById(i),c=s==null?void 0:s.scene;if(c==null)return!0;this._searchCropObject(c)!=null&&this._commandService.syncExecuteCommand(J.id,{isAuto:!0});let l=C({unitId:i,subUnitId:a,drawingId:o}),u=c.getObject(l);if(!(u instanceof A)){this._messageService.show({type:Oe.Error,content:this._localeService.t(`image-cropper.error`)});return}u!=null&&(this._updateCropperObject(n,u),this._commandService.executeCommand(qe.id,{unitId:i,subUnitId:a,drawingId:o}))}))}_calculateSrcRectByRatio(e,t,n,r,i,a){let o=n/r,s=i/a,c=n,l=r;o>s?c=r*s:l=n/s;let u=(n-c)/2,d=(r-l)/2;return{left:ne(u,1),top:ne(d,1),right:ne(n-(u+c),1),bottom:ne(r-(d+l),1)}}_updateCropperObject(e,t){let{left:n,top:r,width:i,height:a}=t.calculateTransformWithSrcRect(),o;switch(e){case Y.R1_1:o=this._calculateSrcRectByRatio(n,r,i,a,1,1);break;case Y.R16_9:o=this._calculateSrcRectByRatio(n,r,i,a,16,9);break;case Y.R9_16:o=this._calculateSrcRectByRatio(n,r,i,a,9,16);break;case Y.R5_4:o=this._calculateSrcRectByRatio(n,r,i,a,5,4);break;case Y.R4_5:o=this._calculateSrcRectByRatio(n,r,i,a,4,5);break;case Y.R4_3:o=this._calculateSrcRectByRatio(n,r,i,a,4,3);break;case Y.R3_4:o=this._calculateSrcRectByRatio(n,r,i,a,3,4);break;case Y.R3_2:o=this._calculateSrcRectByRatio(n,r,i,a,3,2);break;case Y.R2_3:o=this._calculateSrcRectByRatio(n,r,i,a,2,3);break;case Y.FREE:default:break}if(o==null)return;t.setSrcRect(o);let{left:s=0,top:c=0,bottom:l=0,right:u=0}=o;t.transformByStateCloseCropper({left:n+s,top:r+c,width:i-u-s,height:a-l-c})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==qe.id)return;let t=e.params;if(t==null)return;let{unitId:n,subUnitId:r,drawingId:i}=t,a=this._renderManagerService.getRenderById(n),o=a==null?void 0:a.scene;if(o==null)return!0;if(this._sceneListenerOnImageMap.has(o)||(this._addListenerOnImage(o),this._sceneListenerOnImageMap.add(o)),this._drawingManagerService.getDrawingByParam({unitId:n,subUnitId:r,drawingId:i})==null)return;let s=C({unitId:n,subUnitId:r,drawingId:i}),c=o.getObject(s);if(c==null)return;if(!(c instanceof A)){this._messageService.show({type:Oe.Error,content:this._localeService.t(`image-cropper.error`)});return}let l=o.getTransformer();l==null||l.clearControls();let u=new Pt(`${s}-crop`,{srcRect:c.srcRect,prstGeom:c.prstGeom,applyTransform:c.calculateTransformWithSrcRect()});o.addObject(u,c.getLayerIndex()+1).attachTransformerTo(u),l==null||l.createControlForCopper(u),this._addHoverForImageCopper(u),c.openRenderByCropper(),l==null||l.refreshControls(),u.makeDirty(!0),this._commandService.syncExecuteCommand(S.id,[{unitId:n,subUnitId:r,drawingId:i}])}))}_searchCropObject(e){let t=e.getAllObjectsByOrder();for(let e of t)if(e instanceof Pt)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==J.id)return;let t=this._univerInstanceService.getFocusedUnit();if(t==null)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n),i=r==null?void 0:r.scene;if(i==null)return!0;let a=this._searchCropObject(i);if(a==null)return;let o=this._getApplyObjectByCropObject(a);if(o==null)return;let s=i.getTransformerByCreate();s.detachFrom(a),s.clearCopperControl();let c=this._getSrcRectByTransformState(o,a),l=this._drawingManagerService.getDrawingOKey(o.oKey);if(l!=null){let{left:e,top:t,height:n,width:r}=a;this._drawingManagerService.featurePluginUpdateNotification([{...l,transform:{...l.transform,left:e,top:t,height:n,width:r},srcRect:c.srcRectAngle}])}o.setSrcRect({...c.srcRectAngle}),o.closeRenderByCropper(),o.makeDirty(!0),a==null||a.dispose()}));let e=this._univerInstanceService.getCurrentTypeOfUnit$(p.UNIVER_SHEET).pipe(Te(e=>e?e.activeSheet$:we(null)));this.disposeWithMe(e.subscribe(()=>{this._commandService.syncExecuteCommand(J.id)}))}_getApplyObjectByCropObject(e){let t=e.oKey,n=t.slice(0,t.length-5),r=e.getScene();if(!r)return null;let i=r.getObject(n);return i==null?null:i}_addListenerOnImage(e){let t=e.getTransformerByCreate(),n=null;this.disposeWithMe(t.changeStart$.subscribe(e=>{let{objects:r}=e,i=r.values().next().value;if(i==null||!(i instanceof Pt))return;let{left:a,top:o,height:s,width:c,angle:l}=i;n={left:a,top:o,height:s,width:c,angle:l},t.clearCopperControl()})),this.disposeWithMe(t.changeEnd$.subscribe(e=>{let{objects:r}=e,i=r.values().next().value;if(i==null||!(i instanceof Pt))return;let{left:a,top:o,height:s,width:c,angle:l}=i;if(!m({left:a,top:o,height:s,width:c,angle:l},n))return;let u=this._getApplyObjectByCropObject(i);if(u==null)return;let d=this._getSrcRectByTransformState(u,i);i.refreshSrcRect(d.srcRect,u.getState()),t.createControlForCopper(i)})),this._endCropListener(e)}_addHoverForImageCopper(e){this.disposeWithMe(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=w.MOVE})),this.disposeWithMe(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=w.DEFAULT}))}_endCropListener(e){let t=e.getTransformerByCreate();this.disposeWithMe(t.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(J.id)}))}_getSrcRectByTransformState(e,t){let{left:n,top:r,height:i,width:a,strokeWidth:o,angle:s}=t,{left:c,top:l,width:u,height:d,angle:f,strokeWidth:p}=e,m=n-c,h=r-l,g={left:m,top:h,right:u-m-a,bottom:d-h-i},_={...g};if(f!==0){let e=new P(n+a/2,r+i/2),t=new P(u/2+c,d/2+l),o=new P(c,l);o.rotateByPoint(ee(f),t);let s=o.clone();s.rotateByPoint(ee(-f),e);let p=n-s.x,m=r-s.y;_.left=p,_.top=m,_.right=u-p-a,_.bottom=d-m-i}return{srcRect:g,srcRectAngle:_}}};Ft=Z([X(0,i),X(1,y),X(2,k),X(3,s),X(4,ye),X(5,l(d))],Ft);let It=class{constructor(e,t,n,r,i){this._drawingManagerService=e,this._imageIoService=t,this._galleryService=n,this._urlImageService=r,this._univerInstanceService=i}async renderImages(e,t){let{transform:n,drawingType:i,source:a,imageSourceType:o,srcRect:s,prstGeom:c,groupId:l,unitId:u,subUnitId:d,drawingId:f,isMultiTransform:m,transforms:h}=e;if(i!==r.DRAWING_IMAGE||!this._drawingManagerService.getDrawingVisible()||this._univerInstanceService.getUnitType(u)===p.UNIVER_SHEET&&d!==this._getActiveSheetId()||n==null)return;let g=m&&h?h:[n],_=[];for(let e of g){let{left:n,top:r,width:i,height:p,angle:h,flipX:v,flipY:y,skewX:b,skewY:S}=e,w=g.indexOf(e),T=C({unitId:u,subUnitId:d,drawingId:f},m?w:void 0),D=t.getObject(T);if(D!=null){D.transformByState({left:n,top:r,width:i,height:p,angle:h,flipX:v,flipY:y,skewX:b,skewY:S});continue}let O=this._drawingManagerService.getDrawingOrder(u,d),k=O.indexOf(f),j={...e,zIndex:k===-1?O.length-1:k},M=this._imageIoService.getImageSourceCache(a,o),N=!1;if(M!=null)j.image=M;else if(o===x.UUID)try{j.url=await this._imageIoService.getImage(a)}catch(e){console.error(e);continue}else if(o===x.URL){try{j.url=await this._urlImageService.getImage(a)}catch(e){console.error(e),j.url=a}N=!0}else j.url=a,N=!0;if(t.getObject(T))continue;j.printable=!0;let P=new A(T,j);N&&this._imageIoService.addImageSourceCache(a,o,P.getNative()),t.addObject(P,E),this._drawingManagerService.getDrawingEditable()&&t.attachTransformerTo(P),l&&Xe({drawingId:l,unitId:u,subUnitId:d},P,t,this._drawingManagerService),c!=null&&P.setPrstGeom(c),s!=null&&P.setSrcRect(s),_.push(P)}return _}_getActiveSheetId(){var e;return(e=this._univerInstanceService.getCurrentUnitOfType(p.UNIVER_SHEET))==null||(e=e.getActiveSheet())==null?void 0:e.getSheetId()}renderFloatDom(e,t){let{transform:n,drawingType:i,groupId:a,unitId:o,subUnitId:s,drawingId:c,isMultiTransform:l,transforms:u}=e;if(i!==r.DRAWING_DOM||!this._drawingManagerService.getDrawingVisible()||n==null)return;let d=l&&u?u:[n],f=[];for(let n of d){let{left:r,top:i,width:u,height:p,angle:m,flipX:h,flipY:g,skewX:_,skewY:v}=n,y=d.indexOf(n),b=C({unitId:o,subUnitId:s,drawingId:c},l?y:void 0),x=t.getObject(b);if(x!=null){x.transformByState({left:r,top:i,width:u,height:p,angle:m,flipX:h,flipY:g,skewX:_,skewY:v});continue}let S=this._drawingManagerService.getDrawingOrder(o,s),w=S.indexOf(c),T={...n,zIndex:w===-1?S.length-1:w};if(t.getObject(b))continue;T.printable=!1;let D=new M(b,T);this._drawingManagerService.getDrawingVisible()&&(t.addObject(D,E),this._drawingManagerService.getDrawingEditable()&&e.allowTransform!==!1&&t.attachTransformerTo(D),a&&Xe({drawingId:a,unitId:o,subUnitId:s},D,t,this._drawingManagerService),f.push(D))}return f}renderDrawing(e,t){let n=this._drawingManagerService.getDrawingByParam(e);if(n!=null)switch(n.drawingType){case r.DRAWING_IMAGE:return this.renderImages(n,t);default:}}previewImage(e,t,n,r){this._galleryService.open({images:[t],onOpenChange:e=>{e||this._galleryService.close()}})}_adjustImageSize(e,t,n,r){if(e<=n&&t<=r)return{width:e,height:t};let i=n/e,a=r/t,o=Math.min(i,a);return{width:Math.floor(e*o),height:Math.floor(t*o)}}};It=Z([X(0,y),X(1,b),X(2,_e),X(3,o),X(4,s)],It);let Lt=class extends n{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._drawingManagerService=n,this._dialogService=r,this._imageIoService=i,this._currentUniverService=a,this._drawingRenderService=o,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===Ye.id){let t=e.params;if(t==null)return;this._resetImageSize(t)}}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_resetImageSize(e){let t=[],n=[];e.forEach(e=>{let{unitId:i,subUnitId:a,drawingId:o}=e,s=this._getSceneAndTransformerByDrawingSearch(i);if(s==null)return;let{scene:c}=s,l=C({unitId:i,subUnitId:a,drawingId:o}),u=c.getObject(l);if(u==null)return!0;let d=this._drawingManagerService.getDrawingByParam(e);if(d==null)return!0;if(d.drawingType!==r.DRAWING_IMAGE)return;u.resetSize();let{width:f,height:p}=u.getNativeSize();n.includes(c)===!1&&n.push(c),t.push({...d,transform:{...d.transform,height:p,width:f,angle:0},srcRect:null,prstGeom:null})}),this._drawingManagerService.featurePluginUpdateNotification(t),n.forEach(e=>{e.getTransformerByCreate().refreshControls().changeNotification()}),this._commandService.syncExecuteCommand(S.id,e)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.pipe(xe(33),Se(e=>e.length>0),Ce(e=>e.flat()),Ce(e=>{let t=new Map;for(let n of e)t.set(`${n.unitId}|${n.subUnitId}|${n.drawingId}`,n);return[...t.values()]}),Se(e=>e.length>0)).subscribe(e=>{this._insertImages(e)}))}_insertImages(e){e.forEach(async e=>{var t;let{unitId:n,subUnitId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(n),a=(t=Ze(this._currentUniverService,n))==null?void 0:t.subUnitId;if(i==null||a!==r)return;let o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let s=await this._drawingRenderService.renderImages(o,i.scene);if(this._drawingManagerService.refreshTransform([o]),!(s==null||s.length===0))for(let e of s)this._addHoverForImage(e),this._addDialogForImage(e)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:i}=e,a=this._drawingManagerService.getDrawingByParam(e);if(a==null)return;let{transform:o,drawingType:s,srcRect:l,prstGeom:u,source:d,imageSourceType:f}=a;if(s!==r.DRAWING_IMAGE)return;let p=this._getSceneAndTransformerByDrawingSearch(t);if(p==null)return;let{scene:m,transformer:h}=p;if(o==null)return!0;let g=C({unitId:t,subUnitId:n,drawingId:i}),_=m.getObject(g);if(_==null)return!0;_.setSrcRect(l),_.setPrstGeom(u),d!=null&&d.length>0&&(f===c.BASE64||f===c.URL)&&_.changeSource(d)})}))}_addHoverForImage(e){this.disposeWithMe(v(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=w.GRAB}))),this.disposeWithMe(v(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=w.DEFAULT})))}_addDialogForImage(e){this.disposeWithMe(v(e.onDblclick$.subscribeEvent(()=>{let t=`${e.oKey}-viewer-dialog`;this._drawingRenderService.previewImage(t,e.getNative().src,e.getNativeSize().width,e.getNativeSize().height)})))}};Lt=Z([X(0,i),X(1,k),X(2,y),X(3,ge),X(4,b),X(5,s),X(6,l(It))],Lt);let $=class extends f{constructor(e=tt,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=_({},tt,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(et,i)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(Mt),this._injector.get(Dt),this._injector.get(Ft),this._injector.get(Lt)}_initDependencies(){[[It],[Mt],[Dt],[Ft],[Lt]].forEach(e=>this._injector.add(e))}};Q($,`pluginName`,`UNIVER_DRAWING_UI_PLUGIN`),Q($,`packageName`,Qe),Q($,`version`,$e),$=Z([X(1,l(u)),X(2,a)],$);const Rt=e=>{let t=I(i),n=I(d),{drawings:r,alignShow:a}=e,[o,s]=B(U.default),c=[{label:n.t(`image-panel.align.default`),value:U.default},{options:[{label:n.t(`image-panel.align.left`),value:U.left},{label:n.t(`image-panel.align.center`),value:U.center},{label:n.t(`image-panel.align.right`),value:U.right}]},{options:[{label:n.t(`image-panel.align.top`),value:U.top},{label:n.t(`image-panel.align.middle`),value:U.middle},{label:n.t(`image-panel.align.bottom`),value:U.bottom}]},{options:[{label:n.t(`image-panel.align.horizon`),value:U.horizon},{label:n.t(`image-panel.align.vertical`),value:U.vertical}]}];function l(e){s(e),t.executeCommand(W.id,{alignType:e,drawings:r})}return H(`div`,{className:z(`univer-relative univer-w-full`,{"univer-hidden":!a}),children:[V(`header`,{className:`
|
|
9
|
-
univer-text-gray-600
|
|
10
|
-
dark:!univer-text-gray-200
|
|
11
|
-
`,children:V(`div`,{children:n.t(`image-panel.align.title`)})}),V(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:V(`div`,{className:`
|
|
12
|
-
univer-w-full univer-text-gray-900
|
|
13
|
-
dark:!univer-text-white
|
|
14
|
-
`,children:V(ke,{value:o,options:c,onChange:l})})})]})},zt=t=>{let{arrangeShow:n,drawings:r}=t,a=I(d),o=I(y),s=I(i),c=I(pe),l=c.get(`MoveUpIcon`),u=c.get(`MoveDownIcon`),f=c.get(`TopmostIcon`),p=c.get(`BottomIcon`),[m,h]=B(r);je(()=>{let e=o.focus$.subscribe(e=>{h(e)});return()=>{e.unsubscribe()}},[]);let g=e=>{s.syncExecuteCommand(G.id,{arrangeType:e,drawings:m})};return H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!n}),children:[V(`header`,{className:`
|
|
15
|
-
univer-text-gray-600
|
|
16
|
-
dark:!univer-text-gray-200
|
|
17
|
-
`,children:V(`div`,{children:a.t(`image-panel.arrange.title`)})}),H(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:[H(L,{onClick:()=>{g(e.forward)},children:[V(l,{}),a.t(`image-panel.arrange.forward`)]}),H(L,{onClick:()=>{g(e.backward)},children:[V(u,{}),a.t(`image-panel.arrange.backward`)]}),H(L,{onClick:()=>{g(e.front)},children:[V(f,{}),a.t(`image-panel.arrange.front`)]}),H(L,{onClick:()=>{g(e.back)},children:[V(p,{}),a.t(`image-panel.arrange.back`)]})]})]})},Bt=e=>{let t=I(d),n=I(k),a=I(y),o=I(i),s=I(pe),{hasGroup:c,drawings:l}=e,u=s.get(`GroupIcon`),f=s.get(`UngroupIcon`),[p,m]=B(!1),[h,g]=B(!0),[_,v]=B(!0),b=()=>{o.syncExecuteCommand(K.id,{drawings:l})},x=()=>{o.syncExecuteCommand(q.id,{drawings:l})};return je(()=>{let e=l[0];if(e==null)return;let{unitId:t}=e,i=n.getRenderById(t),o=i==null?void 0:i.scene;if(o==null)return;let s=o.getTransformerByCreate(),c=s.clearControl$.subscribe(e=>{e===!0&&m(!1)}),u=s.changeStart$.subscribe(e=>{let{objects:t}=e,n=Ot(t,a),i=n.filter(e=>(e==null?void 0:e.drawingType)===r.DRAWING_GROUP),o=!1,s=!1;n.length>1&&(o=!0),i.length>0&&(s=!0),m(o||s),g(o),v(s)});return()=>{u.unsubscribe(),c.unsubscribe()}},[]),H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":c===!0&&p===!1||c===!1}),children:[V(`header`,{className:`
|
|
18
|
-
univer-text-gray-600
|
|
19
|
-
dark:!univer-text-gray-200
|
|
20
|
-
`,children:V(`div`,{children:t.t(`image-panel.group.title`)})}),H(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[H(L,{className:z({"univer-hidden":!h}),onClick:b,children:[V(u,{}),t.t(`image-panel.group.group`)]}),H(L,{className:z({"univer-hidden":!_}),onClick:x,children:[V(f,{}),t.t(`image-panel.group.unGroup`)]})]})]})},Vt=[-360,360],Ht=e=>{var t;let n=I(d),r=I(y),i=I(k),{drawings:a,transformShow:o}=e,s=a[0];if(s==null)return;let c=s.transform;if(c==null)return;let{unitId:l,subUnitId:u,drawingId:f,drawingType:p}=s,m=i.getRenderById(l),g=m==null?void 0:m.scene;if(g==null)return;let _=(t=g.getEngine())==null?void 0:t.activeScene;if(_==null)return;let v=g.getTransformerByCreate(),{width:b=0,height:x=0,left:S=0,top:C=0,angle:w=0}=c,[T,E]=B(b),[D,O]=B(x),[A,j]=B(S),[M,N]=B(C),[P,ee]=B(w),[te,ne]=B(v.keepRatio),re=(e,t,n,r)=>{let{width:i,height:a}=_,{ancestorLeft:o,ancestorTop:s}=g,c=e,l=t,u=n,d=r;return e+o<0&&(c=-o),t+s<0&&(l=-s),u=i-c-o,u<20&&(u=20),d=a-l-s,d<20&&(d=20),e+u+o>i&&(c=i-n-o),t+d+s>a&&(l=a-r-s),{limitLeft:c,limitTop:l,limitWidth:u,limitHeight:d}},ie=e=>{let{objects:t}=e,n=Ot(t,r);if(n.length!==1)return;let i=n[0];if(i==null)return;let{transform:a}=i;if(a==null)return;let{width:o,height:s,left:c,top:l,angle:u}=a;o!=null&&E(o),s!=null&&O(s),c!=null&&j(c),l!=null&&N(l),u!=null&&ee(u)};je(()=>{let e=[v.changeStart$.subscribe(e=>{ie(e)}),v.changing$.subscribe(e=>{ie(e)}),v.changeEnd$.subscribe(e=>{ie(e)}),r.focus$.subscribe(e=>{if(e.length!==1)return;let t=r.getDrawingByParam(e[0]);if(t==null)return;let n=t.transform;if(n==null)return;let{width:i,height:a,left:o,top:s,angle:c}=n;i!=null&&E(i),a!=null&&O(a),o!=null&&j(o),s!=null&&N(s),c!=null&&ee(c)})];return()=>{e.forEach(e=>e.unsubscribe())}},[]);let ae=h(e=>{if(e==null)return;let{limitWidth:t,limitHeight:n}=re(A,M,e,D);e=Math.min(e,t);let i={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{width:e}};if(te){let t=e/T*D;if(t=Math.max(t,20),t>n)return;O(t),i.transform.height=t}E(e),r.featurePluginUpdateNotification([i]),v.refreshControls().changeNotification()},300),oe=h(e=>{if(e==null)return;let{limitHeight:t,limitWidth:n}=re(A,M,T,e);e=Math.min(e,t);let i={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{height:e}};if(te){let t=e/D*T;if(t=Math.max(t,20),t>n)return;E(t),i.transform.width=t}O(e),r.featurePluginUpdateNotification([i]),v.refreshControls().changeNotification()},300),se=h(e=>{if(e==null)return;let{limitLeft:t}=re(e,M,T,D);e=t;let n={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{left:e}};j(e),r.featurePluginUpdateNotification([n]),v.refreshControls().changeNotification()},300),ce=h(e=>{if(e==null)return;let{limitTop:t}=re(A,e,T,D);e=t;let n={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{top:e}};N(e),r.featurePluginUpdateNotification([n]),v.refreshControls().changeNotification()},300),le=e=>{if(e==null)return;let t={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{angle:e}};ee(e),r.featurePluginUpdateNotification([t]),v.refreshControls().changeNotification()},ue=e=>{ne(e),v.keepRatio=e};return H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!o}),children:[V(`header`,{className:`
|
|
21
|
-
univer-text-gray-600
|
|
22
|
-
dark:!univer-text-gray-200
|
|
23
|
-
`,children:V(`div`,{children:n.t(`image-panel.transform.title`)})}),H(`div`,{className:`
|
|
24
|
-
univer-grid univer-grid-cols-3 univer-gap-2
|
|
25
|
-
[&>div]:univer-grid [&>div]:univer-gap-2
|
|
26
|
-
`,children:[H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.width`)}),V(R,{precision:1,value:T,min:20,onChange:e=>{ae(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.height`)}),V(R,{precision:1,value:D,min:20,onChange:e=>{oe(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.lock`)}),V(`div`,{className:`univer-text-center`,children:V(Ee,{checked:te,onChange:ue})})]})]}),H(`div`,{className:`
|
|
27
|
-
univer-grid univer-grid-cols-3 univer-gap-2
|
|
28
|
-
[&>div]:univer-grid [&>div]:univer-gap-2
|
|
29
|
-
`,children:[H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.x`)}),V(R,{precision:1,value:A,onChange:e=>{se(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.y`)}),V(R,{precision:1,value:M,onChange:e=>{ce(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.rotate`)}),V(R,{precision:1,value:P,min:Vt[0],max:Vt[1],onChange:le})]})]})]})},Ut=e=>{let t=I(i),n=I(d),{drawings:r,cropperShow:a}=e;if(r[0]==null)return;let[o,s]=B(Y.FREE),c=Me(!1),l=[{label:n.t(`image-panel.crop.mode`),value:Y.FREE},{label:`1:1`,value:Y.R1_1},{label:`16:9`,value:Y.R16_9},{label:`9:16`,value:Y.R9_16},{label:`5:4`,value:Y.R5_4},{label:`4:5`,value:Y.R4_5},{label:`4:3`,value:Y.R4_3},{label:`3:4`,value:Y.R3_4},{label:`3:2`,value:Y.R3_2},{label:`2:3`,value:Y.R2_3}];je(()=>{let e=t.onCommandExecuted(e=>{if(e.id===J.id){let t=e.params;t!=null&&t.isAuto||(c.current=!1)}});return()=>{e==null||e.dispose()}},[]);function u(e){s(e),c.current&&t.executeCommand(Je.id,{cropType:e})}let f=e=>{t.executeCommand(Je.id,{cropType:e}),c.current=!0};return H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!a}),children:[V(`header`,{className:`
|
|
30
|
-
univer-text-gray-600
|
|
31
|
-
dark:!univer-text-gray-200
|
|
32
|
-
`,children:V(`div`,{children:n.t(`image-panel.crop.title`)})}),H(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[H(L,{onClick:()=>{f(o)},children:[V(oe,{}),n.t(`image-panel.crop.start`)]}),V(ke,{value:o,options:l,onChange:u})]})]})},Wt=e=>{let t=I(y),n=I(k),r=I(d),{drawings:i,hasArrange:a=!0,hasTransform:o=!0,hasAlign:s=!0,hasCropper:c=!0,hasGroup:l=!0}=e,u=i[0];if(u==null)return;let{unitId:f}=u,p=n.getRenderById(f),m=p==null?void 0:p.scene;if(m==null)return;let h=m.getTransformerByCreate(),[g,_]=B(!0),[v,b]=B(!0),[x,S]=B(!1),[C,w]=B(!0),[T,E]=B(!1);return je(()=>{let e=h.clearControl$.subscribe(e=>{e===!0&&(_(!1),b(!1),S(!1),w(!1),E(!0))}),n=h.changeStart$.subscribe(e=>{let{objects:n}=e,r=Ot(n,t);r.length===0?(_(!1),b(!1),S(!1),w(!1),E(!0)):r.length===1?(_(!0),b(!0),S(!1),w(!0),E(!1)):(_(!0),b(!1),S(!0),w(!1),E(!1))}),r=t.focus$.subscribe(e=>{e.length===0?(_(!1),b(!1),S(!1),w(!1),E(!0)):e.length===1?(_(!0),b(!0),S(!1),w(!0),E(!1)):(_(!0),b(!1),S(!0),w(!1),E(!1))});return()=>{n.unsubscribe(),e.unsubscribe(),r.unsubscribe()}},[]),H(Ne,{children:[V(`div`,{className:z(`univer-h-full`,{"univer-hidden":!T}),children:V(`div`,{className:`univer-flex univer-h-full univer-items-center univer-justify-center`,children:V(`span`,{children:r.t(`image-panel.null`)})})}),V(zt,{arrangeShow:a===!0?g:!1,drawings:i}),V(Ht,{transformShow:o===!0?v:!1,drawings:i}),V(Rt,{alignShow:s===!0?x:!1,drawings:i}),V(Ut,{cropperShow:c===!0?C:!1,drawings:i}),V(Bt,{hasGroup:l,drawings:i})]})};export{Je as AutoImageCropOperation,Tt as COMPONENT_IMAGE_POPUP_MENU,q as CancelDrawingGroupOperation,J as CloseImageCropOperation,Ke as DRAWING_GROUP_TYPES,Wt as DrawingCommonPanel,It as DrawingRenderService,Pt as ImageCropperObject,Et as ImagePopupMenu,Ye as ImageResetSizeOperation,qe as OpenImageCropOperation,W as SetDrawingAlignOperation,G as SetDrawingArrangeOperation,K as SetDrawingGroupOperation,$ as UniverDrawingUIPlugin,Ze as getCurrentUnitInfo,Ot as getUpdateParams,Xe as insertGroupObject};
|
|
1
|
+
import{ArrangeTypeEnum as e,CommandType as t,Disposable as n,DrawingTypeEnum as r,ICommandService as i,IConfigService as a,IURLImageService as o,IUniverInstanceService as s,ImageSourceType as c,Inject as l,Injector as u,LocaleService as d,Plugin as f,UniverInstanceType as p,checkIfMove as m,debounce as h,generateRandomId as g,merge as _,toDisposable as v}from"@univerjs/core";import{IDrawingManagerService as y,IImageIoService as b,ImageSourceType as x,SetDrawingSelectedOperation as S,getDrawingShapeKeyByDrawingSearch as C}from"@univerjs/drawing";import{CURSOR_TYPE as w,Canvas as T,DRAWING_OBJECT_LAYER_INDEX as E,DrawingGroupObject as D,Group as O,IRenderManagerService as k,Image as A,RENDER_CLASS_TYPE as j,Rect as M,Shape as N,Vector2 as P,degToRad as ee,getGroupState as te,precisionTo as ne,transformObjectOutOfGroup as re}from"@univerjs/engine-render";import{AutofillDoubleIcon as ie,BottomIcon as ae,CreateCopyIcon as oe,GroupIcon as se,MoreDownIcon as ce,MoveDownIcon as le,MoveUpIcon as ue,TopmostIcon as de,UngroupIcon as fe}from"@univerjs/icons";import{ComponentManager as pe,ContextMenuGroup as me,ContextMenuPosition as he,IDialogService as ge,IGalleryService as _e,IMenuManagerService as ve,IMessageService as ye,MenuItemType as F,useDependency as I}from"@univerjs/ui";import{Observable as be,bufferTime as xe,filter as Se,map as Ce,of as we,switchMap as Te}from"rxjs";import{Button as L,Checkbox as Ee,DropdownMenu as De,InputNumber as R,MessageType as Oe,Select as ke,borderClassName as Ae,clsx as z}from"@univerjs/design";import{useEffect as je,useRef as Me,useState as B}from"react";import{Fragment as Ne,jsx as V,jsxs as H}from"react/jsx-runtime";let U=function(e){return e.default=`0`,e.left=`1`,e.center=`2`,e.right=`3`,e.top=`4`,e.middle=`5`,e.bottom=`6`,e.horizon=`7`,e.vertical=`8`,e}({});const W={id:`sheet.operation.set-image-align`,type:t.OPERATION,handler:(e,t)=>!0},Pe={id:`sheet.operation.set-drawing-align-left`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.left})},Fe={id:`sheet.operation.set-drawing-align-center`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.center})},Ie={id:`sheet.operation.set-drawing-align-right`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.right})},Le={id:`sheet.operation.set-drawing-align-top`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.top})},Re={id:`sheet.operation.set-drawing-align-middle`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.middle})},ze={id:`sheet.operation.set-drawing-align-bottom`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.bottom})},Be={id:`sheet.operation.set-drawing-align-horizon`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.horizon})},Ve={id:`sheet.operation.set-drawing-align-vertical`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.vertical})},G={id:`drawing.operation.set-drawing-arrange`,type:t.OPERATION,handler:(e,t)=>{let n=e.get(y),{arrangeType:r}=t,i=t.drawings||n.getFocusDrawings(),{unitId:a,subUnitId:o}=i[0],s=i.map(e=>e.drawingId);return n.featurePluginOrderUpdateNotification({unitId:a,subUnitId:o,drawingIds:s,arrangeType:r}),!0}},He={id:`drawing.operation.set-drawing-arrange-front`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.front})},Ue={id:`drawing.operation.set-drawing-arrange-forward`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.forward})},We={id:`drawing.operation.set-drawing-arrange-back`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.back})},Ge={id:`drawing.operation.set-drawing-arrange-backward`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.backward})},Ke=[r.DRAWING_IMAGE,r.DRAWING_SHAPE,r.DRAWING_GROUP],K={id:`drawing.operation.set-drawing-group`,type:t.OPERATION,handler:(e,t)=>{let n=e.get(y),i=t.drawings||n.getFocusDrawings();if(i.length<2||!i.every(e=>Ke.includes(e.drawingType)))return!1;let{unitId:a,subUnitId:o}=i[0],s=g(10),c=te(0,0,i.map(e=>e.transform||{})),l={unitId:a,subUnitId:o,drawingId:s,drawingType:r.DRAWING_GROUP,transform:c,groupBaseBound:{left:c.left,top:c.top,width:c.width,height:c.height}},u=i.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t},groupId:s}});return n.featurePluginGroupUpdateNotification([{parent:l,children:u}]),!0}},q={id:`drawing.operation.cancel-drawing-group`,type:t.OPERATION,handler:(e,t)=>{let n=e.get(y),i=(t.drawings||n.getFocusDrawings()).map(e=>{if(e.drawingType!==r.DRAWING_GROUP)return null;let{unitId:t,subUnitId:i,drawingId:a,transform:o={width:0,height:0},groupBaseBound:s}=e;if(o===null)return null;let c=n.getDrawingsByGroup({unitId:t,subUnitId:i,drawingId:a});return c.length===0?null:{parent:e,children:c.map(e=>{let{transform:t}=e,{unitId:n,subUnitId:r,drawingId:i}=e,a=re(t||{},o,o.width||0,o.height||0,s);return{unitId:n,subUnitId:r,drawingId:i,transform:{...t,...a},groupId:void 0}})}}).filter(e=>e!==null);return i.length===0?!1:(n.featurePluginUngroupUpdateNotification(i),!0)}},qe={id:`sheet.operation.open-image-crop`,type:t.OPERATION,handler:(e,t)=>!0},J={id:`sheet.operation.close-image-crop`,type:t.OPERATION,handler:(e,t)=>!0};let Y=function(e){return e.FREE=`0`,e.R1_1=`1`,e.R16_9=`2`,e.R9_16=`3`,e.R5_4=`4`,e.R4_5=`5`,e.R4_3=`6`,e.R3_4=`7`,e.R3_2=`8`,e.R2_3=`9`,e}({});const Je={id:`sheet.operation.Auto-image-crop`,type:t.OPERATION,handler:(e,t)=>!0},Ye={id:`sheet.operation.image-reset-size`,type:t.OPERATION,handler:(e,t)=>!0};function Xe(e,t,n,r){let i=r.getDrawingByParam(e);if(i==null)return;let a=C(e),o=n.getObjectIncludeInGroup(a);if(o&&!(o instanceof O))return;if(o!=null){let e=o.getObjects();for(let n of e)if(n.oKey===t.oKey)return;o.addObject(t);return}let s=new D(a);n.addObject(s,E).attachTransformerTo(s),s.addObject(t);let{transform:c,groupBaseBound:l}=i;l&&s.setBaseBound(l),i.groupId&&(s.isInGroup=!0,Xe({drawingId:i.groupId,unitId:e.unitId,subUnitId:e.subUnitId},s,n,r)),c&&s.transformByState({left:c.left,top:c.top,angle:c.angle,width:c.width,height:c.height})}function Ze(e,t){let n=t?e.getUnit(t):e.getFocusedUnit();if(n==null)return;let r=n.getUnitId(),i;if(n.type===p.UNIVER_SHEET){var a;i=(a=n.getActiveSheet())==null?void 0:a.getSheetId()}else (n.type===p.UNIVER_DOC||n.type===p.UNIVER_SLIDE)&&(i=r);return{unitId:r,subUnitId:i,current:n}}var Qe=`@univerjs/drawing-ui`,$e=`0.19.0`;const et=`drawing-ui.config`;Symbol(et);const tt={},nt=e=>{let t=e.get(y);return new be(e=>{let n=t=>{if(!t||t.length===0||t.length<2)return e.next(!0);e.next(!1)},r=t.focus$.subscribe(t=>{if(!t||t.length===0)return e.next(!0);n(t)});return n(t.getFocusDrawings()),()=>r.unsubscribe()})},rt=`contextMenu.drawing-align`;function it(e){return{id:rt,type:F.SUBITEMS,icon:`HorizontallyIcon`,title:`image-panel.align.title`,hidden$:nt(e)}}function at(){return{id:Pe.id,type:F.BUTTON,icon:`LeftJustifyingIcon`,title:`image-panel.align.left`}}function ot(){return{id:Fe.id,type:F.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.center`}}function st(){return{id:Ie.id,type:F.BUTTON,icon:`RightJustifyingIcon`,title:`image-panel.align.right`}}function ct(){return{id:Le.id,type:F.BUTTON,icon:`AlignTopIcon`,title:`image-panel.align.top`}}function lt(){return{id:Re.id,type:F.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.middle`}}function ut(){return{id:ze.id,type:F.BUTTON,icon:`AlignBottomIcon`,title:`image-panel.align.bottom`}}function dt(){return{id:Be.id,type:F.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.horizon`}}function ft(){return{id:Ve.id,type:F.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.vertical`}}const pt=`contextMenu.drawing-arrange`;function mt(){return{id:pt,type:F.SUBITEMS,icon:`TopmostIcon`,title:`image-panel.arrange.title`}}function ht(){return{id:He.id,type:F.BUTTON,icon:`TopmostIcon`,title:`image-panel.arrange.front`}}function gt(){return{id:Ue.id,type:F.BUTTON,icon:`MoveUpIcon`,title:`image-panel.arrange.forward`}}function _t(){return{id:We.id,type:F.BUTTON,icon:`BottomIcon`,title:`image-panel.arrange.back`}}function vt(){return{id:Ge.id,type:F.BUTTON,icon:`MoveDownIcon`,title:`image-panel.arrange.backward`}}const yt=(e,t)=>{let n=e.get(y);return new be(e=>{let i=n=>{if(!n||n.length===0)return e.next(!0);if(t===`group`){if(n.length<2||!n.every(e=>Ke.includes(e.drawingType)))return e.next(!0)}else if(t===`unGroup`){if(n.filter(e=>e.drawingType===r.DRAWING_GROUP).length===0)return e.next(!0)}else if(!n.every(e=>Ke.includes(e.drawingType)))return e.next(!0);e.next(!1)},a=n.focus$.subscribe(t=>{if(!t||t.length===0)return e.next(!0);i(t)});return i(n.getFocusDrawings()),()=>a.unsubscribe()})},bt=`contextMenu.drawing-group`;function xt(e){return{id:bt,type:F.SUBITEMS,icon:`GroupIcon`,title:`image-panel.group.title`,hidden$:yt(e)}}function St(e){return{id:K.id,type:F.BUTTON,icon:`GroupIcon`,title:`image-panel.group.group`,disabled$:yt(e,`group`)}}function Ct(e){return{id:q.id,type:F.BUTTON,icon:`UngroupIcon`,title:`image-panel.group.unGroup`,disabled$:yt(e,`unGroup`)}}const wt={[he.DRAWING]:{[me.OTHERS]:{[bt]:{order:1,menuItemFactory:xt,[K.id]:{order:0,menuItemFactory:St},[q.id]:{order:1,menuItemFactory:Ct}},[pt]:{order:2,menuItemFactory:mt,[He.id]:{order:0,menuItemFactory:ht},[Ue.id]:{order:1,menuItemFactory:gt},[We.id]:{order:2,menuItemFactory:_t},[Ge.id]:{order:3,menuItemFactory:vt}},[rt]:{order:3,menuItemFactory:it,[Pe.id]:{order:0,menuItemFactory:at},[Fe.id]:{order:1,menuItemFactory:ot},[Ie.id]:{order:2,menuItemFactory:st},[Le.id]:{order:3,menuItemFactory:ct},[Re.id]:{order:4,menuItemFactory:lt},[ze.id]:{order:5,menuItemFactory:ut},[Be.id]:{order:6,menuItemFactory:dt},[Ve.id]:{order:7,menuItemFactory:ft}}}}},Tt=`COMPONENT_IMAGE_POPUP_MENU`;function Et(e){var t;let{popup:n}=e,r=n==null||(t=n.extraProps)==null?void 0:t.menuItems;if(!r)return null;let a=I(i),o=I(d),[s,c]=B(!1),[l,u]=B(!1),f=()=>{u(!0)},p=()=>{u(!1)},m=e=>{c(e)},h=e=>{a.executeCommand(e.commandId,e.commandParams),c(!1)},g=s||l;return V(`div`,{onMouseEnter:f,onMouseLeave:p,children:V(De,{align:`start`,items:r.filter(e=>!e.disable).map(e=>({type:`item`,children:o.t(e.label),onSelect:()=>h(e)})),open:s,onOpenChange:m,children:H(`div`,{className:z(`univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800`,Ae,{"univer-bg-gray-100 dark:!univer-bg-gray-800":s,"univer-bg-white dark:!univer-bg-gray-900":!s}),children:[V(ie,{className:`univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white`}),g&&V(ce,{className:`dark:!univer-text-white`})]})})})}function X(e,t){return function(n,r){t(n,r,e)}}function Z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Dt=class extends n{constructor(e,t,n){super(),this._componentManager=e,this._commandService=t,this._menuManagerService=n,this._init()}_init(){this._initMenus(),this._initCommands(),this._initComponents()}_initMenus(){this._menuManagerService.mergeMenu(wt)}_initCommands(){[qe,J,Ye,W,Pe,Fe,Ie,Le,Re,ze,Be,Ve,Je,K,q,G,He,Ue,We,Ge].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initComponents(){[[Tt,Et],[`BottomIcon`,ae],[`GroupIcon`,se],[`MoveDownIcon`,le],[`MoveUpIcon`,ue],[`TopmostIcon`,de],[`UngroupIcon`,fe]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Dt=Z([X(0,l(pe)),X(1,i),X(2,ve)],Dt);function Ot(e,t){let n=[];return e.forEach(e=>{let{oKey:i,left:a,top:o,height:s,width:c,angle:l}=e,u=t.getDrawingOKey(i);if(u==null)return n.push(null),!0;let{unitId:d,subUnitId:f,drawingId:p,drawingType:m}=u,h={unitId:d,subUnitId:f,drawingId:p,drawingType:m,transform:{left:a,top:o,height:s,width:c,angle:l}};m===r.DRAWING_IMAGE&&(h.srcRect=e.srcRect),n.push(h)}),n}function kt(e){"@babel/helpers - typeof";return kt=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},kt(e)}function At(e,t){if(kt(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(kt(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function jt(e){var t=At(e,`string`);return kt(t)==`symbol`?t:t+``}function Q(e,t,n){return(t=jt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let Mt=class extends n{constructor(e,t,n,r){super(),this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._drawingManagerService=r,Q(this,`_sceneListenerOnDrawingMap`,new WeakSet),this._initialize()}dispose(){super.dispose()}_initialize(){this._recoveryImages(),this._drawingAddListener(),this._drawingRemoveListener(),this._drawingUpdateListener(),this._commandExecutedListener(),this._drawingArrangeListener(),this._drawingGroupListener(),this._drawingRefreshListener(),this._drawingVisibleListener()}_recoveryImages(){let e=this._drawingManagerService.drawingManagerData,t=Ze(this._currentUniverService);if(t==null)return;let{unitId:n,subUnitId:r}=t;Object.keys(e).forEach(t=>{Object.keys(e[t]).forEach(i=>{let a=e[t][i].data;a==null||t!==n||i!==r||Object.keys(a).forEach(e=>{a[e]&&this._insertDrawing([{unitId:t,subUnitId:i,drawingId:e}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===W.id){let t=e.params;if(t==null)return;this._drawingAlign(t)}}))}_drawingGroupListener(){this.disposeWithMe(this._drawingManagerService.group$.subscribe(e=>{this._groupDrawings(e)})),this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe(e=>{this._ungroupDrawings(e)}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_groupDrawings(e){e.forEach(e=>{this._groupDrawing(e)})}_groupDrawing(e){let{parent:t,children:n}=e,{unitId:r,subUnitId:i,drawingId:a}=t,o=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(o==null)return;let{scene:s,transformer:c}=o;this._commandService.syncExecuteCommand(J.id);let l=[];if(n.forEach(e=>{let t=C(e),n=s.getObjectIncludeInGroup(t);if(n==null||l.includes(n))return;l.push(n);let{transform:r}=e;r!=null&&(n.classType===j.GROUP?n.transformByState({left:r.left,top:r.top}):n.transformByState(r))}),l.length===0)return;let u=new D(C({unitId:r,subUnitId:i,drawingId:a}));s.addObject(u,E).attachTransformerTo(u),u.addObjects(...l),t.groupBaseBound&&u.setBaseBound(t.groupBaseBound),t.groupId&&(u.isInGroup=!0,Xe({drawingId:t.groupId,unitId:r,subUnitId:i},u,s,this._drawingManagerService)),t.transform&&u.transformByState({left:t.transform.left,top:t.transform.top,width:t.transform.width,height:t.transform.height,angle:t.transform.angle}),c.clearSelectedObjects(),c.setSelectedControl(u)}_ungroupDrawings(e){e.forEach(e=>{this._ungroupDrawing(e)})}_ungroupDrawing(e){let{parent:t,children:n}=e,r=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(r==null)return;let{scene:i,transformer:a}=r;n.forEach(e=>{let t=C(e),n=i.getObjectIncludeInGroup(t);if(n==null)return!0;if(n==null)return;let{transform:r}=e;r!=null&&(n.classType===j.GROUP?n.transformByState({left:r.left,top:r.top}):n.transformByState(r))});let o=C(t),s=i.getObject(o),{width:c,height:l}=s;s.getObjects().forEach(e=>{s.removeSelfObjectAndTransform(e.oKey,c,l)}),s.dispose(),a.clearSelectedObjects()}_drawingAlign(e){let{alignType:t}=e,n=e.drawings||this._drawingManagerService.getFocusDrawings();if(t===U.default)return;let r=[],i=1/0,a=1/0,o=-1/0,s=-1/0,c=0;n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:l,drawingType:u}=e,d=this._drawingManagerService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:l});if(d==null||d.transform==null)return;r.push({unitId:t,subUnitId:n,drawingId:l,drawingType:u,transform:d.transform});let{left:f=0,top:p=0,width:m=0,height:h=0}=d.transform;i=Math.min(i,f),a=Math.min(a,p),o=Math.max(o,f+m),s=Math.max(s,p+h),c++}),c!==0&&(this._sortDrawingTransform(r,t),this._applyAlignType(r,t,i,a,o,s,c))}_applyAlignType(e,t,n,r,i,a,o){let s=Math.round((i-n)/o*10)/10,c=Math.round((a-r)/o*10)/10,l=[],u=this._getSceneAndTransformerByDrawingSearch(e[0].unitId);if(u==null)return;let{scene:d,transformer:f}=u;e.forEach((e,o)=>{let{unitId:u,subUnitId:d,drawingId:f,transform:p,drawingType:m}=e,{left:h=0,top:g=0,width:_=0,height:v=0}=p,y=h,b=g;switch(t){case U.left:y=n;break;case U.center:y=n+(i-n)/2-_/2;break;case U.right:y=i-_;break;case U.top:b=r;break;case U.middle:b=r+(a-r)/2-v/2;break;case U.bottom:b=a-v;break;case U.horizon:y=n+s*o;break;case U.vertical:b=r+c*o;break;default:break}(y!==h||b!==g)&&l.push({unitId:u,subUnitId:d,drawingId:f,drawingType:m,transform:{left:y,top:b}})}),this._drawingManagerService.featurePluginUpdateNotification(l),f.refreshControls().changeNotification()}_sortDrawingTransform(e,t){e.sort((e,n)=>{let r=e.transform,i=n.transform,{left:a=0,top:o=0,width:s=0,height:c=0}=r,{left:l=0,top:u=0,width:d=0,height:f=0}=i;switch(t){case U.left:return a-l;case U.center:return a+s/2-(l+d/2);case U.right:return a+s-(l+d);case U.top:return o-u;case U.middle:return o+c/2-(u+f/2);case U.bottom:return o+c-(u+f);case U.horizon:return a+s/2-(l+d/2);case U.vertical:return o+c/2-(u+f/2);default:return 0}})}_drawingArrangeListener(){this.disposeWithMe(this._drawingManagerService.order$.subscribe(e=>{this._drawingArrange(e)}))}_drawingArrange(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=this._getSceneAndTransformerByDrawingSearch(t);if(i==null)return;let{scene:a}=i;r.forEach(e=>{let r=C({unitId:t,subUnitId:n,drawingId:e}),i=a.fuzzyMathObjects(r,!0);if(i==null||i.length===0)return;let o=this._drawingManagerService.getDrawingOrder(t,n).indexOf(e);for(let e of i)e.setProps({zIndex:o}),e.makeDirty()})}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{this._insertDrawing(e)}))}_insertDrawing(e){let t=[];e.forEach(e=>{let{unitId:n}=e;if(this._drawingManagerService.getDrawingByParam(e)==null)return;let r=this._getSceneAndTransformerByDrawingSearch(n);if(r==null)return;let{scene:i}=r;t.includes(i)||t.push(i)}),t.forEach(e=>{this._sceneListenerOnDrawingMap.has(e)||(this._addListenerOnDrawing(e),this._sceneListenerOnDrawingMap.add(e))})}_drawingRemoveListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(t);if(i==null)return;let{scene:a}=i,o=C({unitId:t,subUnitId:n,drawingId:r}),s=a.fuzzyMathObjects(o,!0);if(s.length>0){var c;for(let e of s)e.dispose();(c=a.getTransformer())==null||c.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{var t;let{unitId:n,subUnitId:r,drawingId:i}=e,a=this._drawingManagerService.getDrawingByParam(e);if(a==null)return;let{transform:o,drawingType:s}=a,c=this._getSceneAndTransformerByDrawingSearch(n);if(c==null)return;let{scene:l,transformer:u}=c;if(o==null)return!0;let{left:d=0,top:f=0,width:p=0,height:m=0,angle:h=0,flipX:g=!1,flipY:_=!1,skewX:v=0,skewY:y=0}=o,b=C({unitId:n,subUnitId:r,drawingId:i}),x=l.getObject(b);if(x==null)return!0;x.transformByState({left:d,top:f,width:p,height:m,angle:h,flipX:g,flipY:_,skewX:v,skewY:y}),(t=l.getTransformer())==null||t.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(t);if(i==null)return;let a=this._drawingManagerService.getDrawingByParam(e);if(a==null)return;let{transform:o}=a,{scene:s}=i,c=C({unitId:t,subUnitId:n,drawingId:r}),l=s.getObject(c);if(l==null||o==null)return!0;let{left:u=0,top:d=0,width:f=0,height:p=0,angle:m=0,flipX:h=!1,flipY:g=!1,skewX:_=0,skewY:v=0}=o;l.transformByState({left:u,top:d,width:f,height:p,angle:m,flipX:h,flipY:g,skewX:_,skewY:v})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r,visible:i}=e,a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{scene:o}=a,s=C({unitId:t,subUnitId:n,drawingId:r}),c=o.getObject(s);if(c==null)return!0;i?c.show():c.hide()})}))}_filterUpdateParams(e,t){return e.filter((e,n)=>{if(e==null)return!1;let{transform:r}=e;return m(r,t==null?void 0:t[n])})}_addListenerOnDrawing(e){let t=e.getTransformerByCreate(),n=null;this.disposeWithMe(v(t.changeStart$.subscribe(e=>{let{objects:t}=e,r=Array.from(t.values()),i=[];n=r.map(e=>{let{left:t,top:n,height:r,width:a,angle:o,oKey:s,isInGroup:c}=e,l=this._drawingManagerService.getDrawingOKey(s);if(c||e instanceof O){let t=e.ancestorGroup;if(t==null&&e instanceof O&&(t=e),t==null)return null;let n=this._drawingManagerService.getDrawingOKey(t.oKey);if(n){let{unitId:e,subUnitId:r,drawingId:a}=n;i.push({unitId:e,subUnitId:r,drawingId:a});let{left:o,top:s,height:c,width:l,angle:u}=t;return{left:o,top:s,height:c,width:l,angle:u}}}else if(l!=null){let{unitId:e,subUnitId:s,drawingId:c}=l;return i.push({unitId:e,subUnitId:s,drawingId:c}),{left:t,top:n,height:r,width:a,angle:o}}return null}).filter(e=>e!=null),i.length>0?this._commandService.syncExecuteCommand(S.id,i):this._commandService.syncExecuteCommand(S.id,[])}))),this.disposeWithMe(v(t.changeEnd$.subscribe(e=>{let{objects:t}=e,r=this._filterUpdateParams(Ot(t,this._drawingManagerService),n);r.length>0&&this._drawingManagerService.featurePluginUpdateNotification(r)})))}};Mt=Z([X(0,s),X(1,i),X(2,k),X(3,y)],Mt);var Nt=function(e){return e[e.RECT=0]=`RECT`,e[e.PATH=1]=`PATH`,e}(Nt||{}),Pt=class extends N{constructor(e,t){t==null&&(t={}),t.transformerConfig={keepRatio:!1,isCropper:!0,anchorFill:`rgb(0, 0, 0)`,anchorStroke:`rgb(255, 255, 255)`,anchorSize:24},super(e,t),Q(this,`_srcRect`,void 0),Q(this,`_prstGeom`,void 0),Q(this,`_applyTransform`,void 0),Q(this,`_dragPadding`,8),Q(this,`_cacheCanvas`,void 0),t!=null&&t.srcRect&&(this._srcRect=t.srcRect),t!=null&&t.prstGeom&&(this._prstGeom=t.prstGeom),t!=null&&t.applyTransform&&(this._applyTransform=t.applyTransform),t!=null&&t.dragPadding&&(this._dragPadding=t.dragPadding),this._applyProps()}refreshSrcRect(e,t){this._srcRect=e,this._applyTransform=t,this._applyProps()}get srcRect(){return this._srcRect}dispose(){var e;super.dispose(),(e=this._cacheCanvas)==null||e.dispose(),this._srcRect=null}isHit(e){let t=this.getInverseCoord(e);return t.x>=-this.strokeWidth/2&&t.x<=this.width+this.strokeWidth/2&&t.y>=-this.strokeWidth/2&&t.y<=this.height+this.strokeWidth/2&&!this._inSurround(t)}_inSurround(e){let t=this._dragPadding;return e.x>=t-this.strokeWidth/2&&e.x<=this.width+this.strokeWidth/2-t&&e.y>=t-this.strokeWidth/2&&e.y<=this.height+this.strokeWidth/2-t}render(e,t){return this.visible?(e.save(),this._draw(e),e.restore(),this.makeDirty(!1),this):(this.makeDirty(!1),this)}_draw(e){var t,n;let{width:r,height:i}=this.getScene().getEngine();this._initialCacheCanvas(),(t=this._cacheCanvas)==null||t.clear();let a=(n=this._cacheCanvas)==null?void 0:n.getContext();a!=null&&(a.save(),M.drawWith(a,{left:0,top:0,width:r,height:i,fill:`rgba(0, 0, 0, 0.5)`}),a.setTransform(e.getTransform()),this._clipForApplyObject(a),this._applyCache(e),a.restore())}_clipForApplyObject(e){let t=Nt.RECT;if(this._prstGeom!=null&&(t=Nt.PATH),e.globalCompositeOperation=`destination-out`,e.beginPath(),t===Nt.RECT){let t=this.transform.getMatrix();e.transform(t[0],t[1],t[2],t[3],t[4],t[5]),e.rect(0,0,this.width,this.height),e.fill()}}_applyProps(){if(this._applyTransform==null)return;let e=0,t=0,n=0,r=0,{left:i=0,top:a=0,width:o=0,height:s=0,angle:c}=this._applyTransform;if(this._srcRect!=null){let{left:i=0,top:a=0,right:o=0,bottom:s=0}=this._srcRect;e=i,t=a,n=o,r=s}let l=i+e,u=a+t;this.transformByState({left:l,top:u,width:i+o-n-l,height:a+s-r-u,angle:c})}_applyCache(e){if(!e||this._cacheCanvas==null)return;let t=this._cacheCanvas.getContext();t.save(),e.save(),e.setTransform(1,0,0,1,0,0),t.setTransform(1,0,0,1,0,0),e.drawImage(this._cacheCanvas.getCanvasEle(),0,0),e.restore(),t.restore()}_initialCacheCanvas(){if(this._cacheCanvas!=null)return;let e=this.getScene();if(e==null)return;this._cacheCanvas=new T;let t=e.getEngine();this._cacheCanvas.setSize(t.width,t.height),t.onTransformChange$.subscribeEvent(()=>{var e;(e=this._cacheCanvas)==null||e.setSize(t.width,t.height),this.makeDirty(!0)})}};let Ft=class extends n{constructor(e,t,n,r,i,a){super(),this._commandService=e,this._drawingManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._messageService=i,this._localeService=a,Q(this,`_sceneListenerOnImageMap`,new WeakSet),this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==Je.id)return;let t=e.params;if(t==null)return;let{cropType:n}=t,r=this._drawingManagerService.getFocusDrawings();if(r.length!==1)return;let{unitId:i,subUnitId:a,drawingId:o}=r[0],s=this._renderManagerService.getRenderById(i),c=s==null?void 0:s.scene;if(c==null)return!0;this._searchCropObject(c)!=null&&this._commandService.syncExecuteCommand(J.id,{isAuto:!0});let l=C({unitId:i,subUnitId:a,drawingId:o}),u=c.getObject(l);if(!(u instanceof A)){this._messageService.show({type:Oe.Error,content:this._localeService.t(`image-cropper.error`)});return}u!=null&&(this._updateCropperObject(n,u),this._commandService.executeCommand(qe.id,{unitId:i,subUnitId:a,drawingId:o}))}))}_calculateSrcRectByRatio(e,t,n,r,i,a){let o=n/r,s=i/a,c=n,l=r;o>s?c=r*s:l=n/s;let u=(n-c)/2,d=(r-l)/2;return{left:ne(u,1),top:ne(d,1),right:ne(n-(u+c),1),bottom:ne(r-(d+l),1)}}_updateCropperObject(e,t){let{left:n,top:r,width:i,height:a}=t.calculateTransformWithSrcRect(),o;switch(e){case Y.R1_1:o=this._calculateSrcRectByRatio(n,r,i,a,1,1);break;case Y.R16_9:o=this._calculateSrcRectByRatio(n,r,i,a,16,9);break;case Y.R9_16:o=this._calculateSrcRectByRatio(n,r,i,a,9,16);break;case Y.R5_4:o=this._calculateSrcRectByRatio(n,r,i,a,5,4);break;case Y.R4_5:o=this._calculateSrcRectByRatio(n,r,i,a,4,5);break;case Y.R4_3:o=this._calculateSrcRectByRatio(n,r,i,a,4,3);break;case Y.R3_4:o=this._calculateSrcRectByRatio(n,r,i,a,3,4);break;case Y.R3_2:o=this._calculateSrcRectByRatio(n,r,i,a,3,2);break;case Y.R2_3:o=this._calculateSrcRectByRatio(n,r,i,a,2,3);break;case Y.FREE:default:break}if(o==null)return;t.setSrcRect(o);let{left:s=0,top:c=0,bottom:l=0,right:u=0}=o;t.transformByStateCloseCropper({left:n+s,top:r+c,width:i-u-s,height:a-l-c})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==qe.id)return;let t=e.params;if(t==null)return;let{unitId:n,subUnitId:r,drawingId:i}=t,a=this._renderManagerService.getRenderById(n),o=a==null?void 0:a.scene;if(o==null)return!0;if(this._sceneListenerOnImageMap.has(o)||(this._addListenerOnImage(o),this._sceneListenerOnImageMap.add(o)),this._drawingManagerService.getDrawingByParam({unitId:n,subUnitId:r,drawingId:i})==null)return;let s=C({unitId:n,subUnitId:r,drawingId:i}),c=o.getObject(s);if(c==null)return;if(!(c instanceof A)){this._messageService.show({type:Oe.Error,content:this._localeService.t(`image-cropper.error`)});return}let l=o.getTransformer();l==null||l.clearControls();let u=new Pt(`${s}-crop`,{srcRect:c.srcRect,prstGeom:c.prstGeom,applyTransform:c.calculateTransformWithSrcRect()});o.addObject(u,c.getLayerIndex()+1).attachTransformerTo(u),l==null||l.createControlForCopper(u),this._addHoverForImageCopper(u),c.openRenderByCropper(),l==null||l.refreshControls(),u.makeDirty(!0),this._commandService.syncExecuteCommand(S.id,[{unitId:n,subUnitId:r,drawingId:i}])}))}_searchCropObject(e){let t=e.getAllObjectsByOrder();for(let e of t)if(e instanceof Pt)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==J.id)return;let t=this._univerInstanceService.getFocusedUnit();if(t==null)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n),i=r==null?void 0:r.scene;if(i==null)return!0;let a=this._searchCropObject(i);if(a==null)return;let o=this._getApplyObjectByCropObject(a);if(o==null)return;let s=i.getTransformerByCreate();s.detachFrom(a),s.clearCopperControl();let c=this._getSrcRectByTransformState(o,a),l=this._drawingManagerService.getDrawingOKey(o.oKey);if(l!=null){let{left:e,top:t,height:n,width:r}=a;this._drawingManagerService.featurePluginUpdateNotification([{...l,transform:{...l.transform,left:e,top:t,height:n,width:r},srcRect:c.srcRectAngle}])}o.setSrcRect({...c.srcRectAngle}),o.closeRenderByCropper(),o.makeDirty(!0),a==null||a.dispose()}));let e=this._univerInstanceService.getCurrentTypeOfUnit$(p.UNIVER_SHEET).pipe(Te(e=>e?e.activeSheet$:we(null)));this.disposeWithMe(e.subscribe(()=>{this._commandService.syncExecuteCommand(J.id)}))}_getApplyObjectByCropObject(e){let t=e.oKey,n=t.slice(0,t.length-5),r=e.getScene();if(!r)return null;let i=r.getObject(n);return i==null?null:i}_addListenerOnImage(e){let t=e.getTransformerByCreate(),n=null;this.disposeWithMe(t.changeStart$.subscribe(e=>{let{objects:r}=e,i=r.values().next().value;if(i==null||!(i instanceof Pt))return;let{left:a,top:o,height:s,width:c,angle:l}=i;n={left:a,top:o,height:s,width:c,angle:l},t.clearCopperControl()})),this.disposeWithMe(t.changeEnd$.subscribe(e=>{let{objects:r}=e,i=r.values().next().value;if(i==null||!(i instanceof Pt))return;let{left:a,top:o,height:s,width:c,angle:l}=i;if(!m({left:a,top:o,height:s,width:c,angle:l},n))return;let u=this._getApplyObjectByCropObject(i);if(u==null)return;let d=this._getSrcRectByTransformState(u,i);i.refreshSrcRect(d.srcRect,u.getState()),t.createControlForCopper(i)})),this._endCropListener(e)}_addHoverForImageCopper(e){this.disposeWithMe(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=w.MOVE})),this.disposeWithMe(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=w.DEFAULT}))}_endCropListener(e){let t=e.getTransformerByCreate();this.disposeWithMe(t.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(J.id)}))}_getSrcRectByTransformState(e,t){let{left:n,top:r,height:i,width:a,strokeWidth:o,angle:s}=t,{left:c,top:l,width:u,height:d,angle:f,strokeWidth:p}=e,m=n-c,h=r-l,g={left:m,top:h,right:u-m-a,bottom:d-h-i},_={...g};if(f!==0){let e=new P(n+a/2,r+i/2),t=new P(u/2+c,d/2+l),o=new P(c,l);o.rotateByPoint(ee(f),t);let s=o.clone();s.rotateByPoint(ee(-f),e);let p=n-s.x,m=r-s.y;_.left=p,_.top=m,_.right=u-p-a,_.bottom=d-m-i}return{srcRect:g,srcRectAngle:_}}};Ft=Z([X(0,i),X(1,y),X(2,k),X(3,s),X(4,ye),X(5,l(d))],Ft);let It=class{constructor(e,t,n,r,i){this._drawingManagerService=e,this._imageIoService=t,this._galleryService=n,this._urlImageService=r,this._univerInstanceService=i}async renderImages(e,t){let{transform:n,drawingType:i,source:a,imageSourceType:o,srcRect:s,prstGeom:c,groupId:l,unitId:u,subUnitId:d,drawingId:f,isMultiTransform:m,transforms:h}=e;if(i!==r.DRAWING_IMAGE||!this._drawingManagerService.getDrawingVisible()||this._univerInstanceService.getUnitType(u)===p.UNIVER_SHEET&&d!==this._getActiveSheetId()||n==null)return;let g=m&&h?h:[n],_=[];for(let e of g){let{left:n,top:r,width:i,height:p,angle:h,flipX:v,flipY:y,skewX:b,skewY:S}=e,w=g.indexOf(e),T=C({unitId:u,subUnitId:d,drawingId:f},m?w:void 0),D=t.getObject(T);if(D!=null){D.transformByState({left:n,top:r,width:i,height:p,angle:h,flipX:v,flipY:y,skewX:b,skewY:S});continue}let O=this._drawingManagerService.getDrawingOrder(u,d),k=O.indexOf(f),j={...e,zIndex:k===-1?O.length-1:k},M=this._imageIoService.getImageSourceCache(a,o),N=!1;if(M!=null)j.image=M;else if(o===x.UUID)try{j.url=await this._imageIoService.getImage(a)}catch(e){console.error(e);continue}else if(o===x.URL){try{j.url=await this._urlImageService.getImage(a)}catch(e){console.error(e),j.url=a}N=!0}else j.url=a,N=!0;if(t.getObject(T))continue;j.printable=!0;let P=new A(T,j);N&&this._imageIoService.addImageSourceCache(a,o,P.getNative()),t.addObject(P,E),this._drawingManagerService.getDrawingEditable()&&t.attachTransformerTo(P),l&&Xe({drawingId:l,unitId:u,subUnitId:d},P,t,this._drawingManagerService),c!=null&&P.setPrstGeom(c),s!=null&&P.setSrcRect(s),_.push(P)}return _}_getActiveSheetId(){var e;return(e=this._univerInstanceService.getCurrentUnitOfType(p.UNIVER_SHEET))==null||(e=e.getActiveSheet())==null?void 0:e.getSheetId()}renderFloatDom(e,t){let{transform:n,drawingType:i,groupId:a,unitId:o,subUnitId:s,drawingId:c,isMultiTransform:l,transforms:u}=e;if(i!==r.DRAWING_DOM||!this._drawingManagerService.getDrawingVisible()||n==null)return;let d=l&&u?u:[n],f=[];for(let n of d){let{left:r,top:i,width:u,height:p,angle:m,flipX:h,flipY:g,skewX:_,skewY:v}=n,y=d.indexOf(n),b=C({unitId:o,subUnitId:s,drawingId:c},l?y:void 0),x=t.getObject(b);if(x!=null){x.transformByState({left:r,top:i,width:u,height:p,angle:m,flipX:h,flipY:g,skewX:_,skewY:v});continue}let S=this._drawingManagerService.getDrawingOrder(o,s),w=S.indexOf(c),T={...n,zIndex:w===-1?S.length-1:w};if(t.getObject(b))continue;T.printable=!1;let D=new M(b,T);this._drawingManagerService.getDrawingVisible()&&(t.addObject(D,E),this._drawingManagerService.getDrawingEditable()&&e.allowTransform!==!1&&t.attachTransformerTo(D),a&&Xe({drawingId:a,unitId:o,subUnitId:s},D,t,this._drawingManagerService),f.push(D))}return f}renderDrawing(e,t){let n=this._drawingManagerService.getDrawingByParam(e);if(n!=null)switch(n.drawingType){case r.DRAWING_IMAGE:return this.renderImages(n,t);default:}}previewImage(e,t,n,r){this._galleryService.open({images:[t],onOpenChange:e=>{e||this._galleryService.close()}})}_adjustImageSize(e,t,n,r){if(e<=n&&t<=r)return{width:e,height:t};let i=n/e,a=r/t,o=Math.min(i,a);return{width:Math.floor(e*o),height:Math.floor(t*o)}}};It=Z([X(0,y),X(1,b),X(2,_e),X(3,o),X(4,s)],It);let Lt=class extends n{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._drawingManagerService=n,this._dialogService=r,this._imageIoService=i,this._currentUniverService=a,this._drawingRenderService=o,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===Ye.id){let t=e.params;if(t==null)return;this._resetImageSize(t)}}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_resetImageSize(e){let t=[],n=[];e.forEach(e=>{let{unitId:i,subUnitId:a,drawingId:o}=e,s=this._getSceneAndTransformerByDrawingSearch(i);if(s==null)return;let{scene:c}=s,l=C({unitId:i,subUnitId:a,drawingId:o}),u=c.getObject(l);if(u==null)return!0;let d=this._drawingManagerService.getDrawingByParam(e);if(d==null)return!0;if(d.drawingType!==r.DRAWING_IMAGE)return;u.resetSize();let{width:f,height:p}=u.getNativeSize();n.includes(c)===!1&&n.push(c),t.push({...d,transform:{...d.transform,height:p,width:f,angle:0},srcRect:null,prstGeom:null})}),this._drawingManagerService.featurePluginUpdateNotification(t),n.forEach(e=>{e.getTransformerByCreate().refreshControls().changeNotification()}),this._commandService.syncExecuteCommand(S.id,e)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.pipe(xe(33),Se(e=>e.length>0),Ce(e=>e.flat()),Ce(e=>{let t=new Map;for(let n of e)t.set(`${n.unitId}|${n.subUnitId}|${n.drawingId}`,n);return[...t.values()]}),Se(e=>e.length>0)).subscribe(e=>{this._insertImages(e)}))}_insertImages(e){e.forEach(async e=>{var t;let{unitId:n,subUnitId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(n),a=(t=Ze(this._currentUniverService,n))==null?void 0:t.subUnitId;if(i==null||a!==r)return;let o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let s=await this._drawingRenderService.renderImages(o,i.scene);if(this._drawingManagerService.refreshTransform([o]),!(s==null||s.length===0))for(let e of s)this._addHoverForImage(e),this._addDialogForImage(e)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:i}=e,a=this._drawingManagerService.getDrawingByParam(e);if(a==null)return;let{transform:o,drawingType:s,srcRect:l,prstGeom:u,source:d,imageSourceType:f}=a;if(s!==r.DRAWING_IMAGE)return;let p=this._getSceneAndTransformerByDrawingSearch(t);if(p==null)return;let{scene:m,transformer:h}=p;if(o==null)return!0;let g=C({unitId:t,subUnitId:n,drawingId:i}),_=m.getObject(g);if(_==null)return!0;_.setSrcRect(l),_.setPrstGeom(u),d!=null&&d.length>0&&(f===c.BASE64||f===c.URL)&&_.changeSource(d)})}))}_addHoverForImage(e){this.disposeWithMe(v(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=w.GRAB}))),this.disposeWithMe(v(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=w.DEFAULT})))}_addDialogForImage(e){this.disposeWithMe(v(e.onDblclick$.subscribeEvent(()=>{let t=`${e.oKey}-viewer-dialog`;this._drawingRenderService.previewImage(t,e.getNative().src,e.getNativeSize().width,e.getNativeSize().height)})))}};Lt=Z([X(0,i),X(1,k),X(2,y),X(3,ge),X(4,b),X(5,s),X(6,l(It))],Lt);let $=class extends f{constructor(e=tt,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=_({},tt,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(et,i)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(Mt),this._injector.get(Dt),this._injector.get(Ft),this._injector.get(Lt)}_initDependencies(){[[It],[Mt],[Dt],[Ft],[Lt]].forEach(e=>this._injector.add(e))}};Q($,`pluginName`,`UNIVER_DRAWING_UI_PLUGIN`),Q($,`packageName`,Qe),Q($,`version`,$e),$=Z([X(1,l(u)),X(2,a)],$);const Rt=e=>{let t=I(i),n=I(d),{drawings:r,alignShow:a}=e,[o,s]=B(U.default),c=[{label:n.t(`image-panel.align.default`),value:U.default},{options:[{label:n.t(`image-panel.align.left`),value:U.left},{label:n.t(`image-panel.align.center`),value:U.center},{label:n.t(`image-panel.align.right`),value:U.right}]},{options:[{label:n.t(`image-panel.align.top`),value:U.top},{label:n.t(`image-panel.align.middle`),value:U.middle},{label:n.t(`image-panel.align.bottom`),value:U.bottom}]},{options:[{label:n.t(`image-panel.align.horizon`),value:U.horizon},{label:n.t(`image-panel.align.vertical`),value:U.vertical}]}];function l(e){s(e),t.executeCommand(W.id,{alignType:e,drawings:r})}return H(`div`,{className:z(`univer-relative univer-w-full`,{"univer-hidden":!a}),children:[V(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:V(`div`,{children:n.t(`image-panel.align.title`)})}),V(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:V(`div`,{className:`univer-w-full univer-text-gray-900 dark:!univer-text-white`,children:V(ke,{value:o,options:c,onChange:l})})})]})},zt=t=>{let{arrangeShow:n,drawings:r}=t,a=I(d),o=I(y),s=I(i),c=I(pe),l=c.get(`MoveUpIcon`),u=c.get(`MoveDownIcon`),f=c.get(`TopmostIcon`),p=c.get(`BottomIcon`),[m,h]=B(r);je(()=>{let e=o.focus$.subscribe(e=>{h(e)});return()=>{e.unsubscribe()}},[]);let g=e=>{s.syncExecuteCommand(G.id,{arrangeType:e,drawings:m})};return H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!n}),children:[V(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:V(`div`,{children:a.t(`image-panel.arrange.title`)})}),H(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:[H(L,{onClick:()=>{g(e.forward)},children:[V(l,{}),a.t(`image-panel.arrange.forward`)]}),H(L,{onClick:()=>{g(e.backward)},children:[V(u,{}),a.t(`image-panel.arrange.backward`)]}),H(L,{onClick:()=>{g(e.front)},children:[V(f,{}),a.t(`image-panel.arrange.front`)]}),H(L,{onClick:()=>{g(e.back)},children:[V(p,{}),a.t(`image-panel.arrange.back`)]})]})]})},Bt=e=>{let t=I(d),n=I(k),a=I(y),o=I(i),s=I(pe),{hasGroup:c,drawings:l}=e,u=s.get(`GroupIcon`),f=s.get(`UngroupIcon`),[p,m]=B(!1),[h,g]=B(!0),[_,v]=B(!0),b=()=>{o.syncExecuteCommand(K.id,{drawings:l})},x=()=>{o.syncExecuteCommand(q.id,{drawings:l})};return je(()=>{let e=l[0];if(e==null)return;let{unitId:t}=e,i=n.getRenderById(t),o=i==null?void 0:i.scene;if(o==null)return;let s=o.getTransformerByCreate(),c=s.clearControl$.subscribe(e=>{e===!0&&m(!1)}),u=s.changeStart$.subscribe(e=>{let{objects:t}=e,n=Ot(t,a),i=n.filter(e=>(e==null?void 0:e.drawingType)===r.DRAWING_GROUP),o=!1,s=!1;n.length>1&&(o=!0),i.length>0&&(s=!0),m(o||s),g(o),v(s)});return()=>{u.unsubscribe(),c.unsubscribe()}},[]),H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":c===!0&&p===!1||c===!1}),children:[V(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:V(`div`,{children:t.t(`image-panel.group.title`)})}),H(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[H(L,{className:z({"univer-hidden":!h}),onClick:b,children:[V(u,{}),t.t(`image-panel.group.group`)]}),H(L,{className:z({"univer-hidden":!_}),onClick:x,children:[V(f,{}),t.t(`image-panel.group.unGroup`)]})]})]})},Vt=[-360,360],Ht=e=>{var t;let n=I(d),r=I(y),i=I(k),{drawings:a,transformShow:o}=e,s=a[0];if(s==null)return;let c=s.transform;if(c==null)return;let{unitId:l,subUnitId:u,drawingId:f,drawingType:p}=s,m=i.getRenderById(l),g=m==null?void 0:m.scene;if(g==null)return;let _=(t=g.getEngine())==null?void 0:t.activeScene;if(_==null)return;let v=g.getTransformerByCreate(),{width:b=0,height:x=0,left:S=0,top:C=0,angle:w=0}=c,[T,E]=B(b),[D,O]=B(x),[A,j]=B(S),[M,N]=B(C),[P,ee]=B(w),[te,ne]=B(v.keepRatio),re=(e,t,n,r)=>{let{width:i,height:a}=_,{ancestorLeft:o,ancestorTop:s}=g,c=e,l=t,u=n,d=r;return e+o<0&&(c=-o),t+s<0&&(l=-s),u=i-c-o,u<20&&(u=20),d=a-l-s,d<20&&(d=20),e+u+o>i&&(c=i-n-o),t+d+s>a&&(l=a-r-s),{limitLeft:c,limitTop:l,limitWidth:u,limitHeight:d}},ie=e=>{let{objects:t}=e,n=Ot(t,r);if(n.length!==1)return;let i=n[0];if(i==null)return;let{transform:a}=i;if(a==null)return;let{width:o,height:s,left:c,top:l,angle:u}=a;o!=null&&E(o),s!=null&&O(s),c!=null&&j(c),l!=null&&N(l),u!=null&&ee(u)};je(()=>{let e=[v.changeStart$.subscribe(e=>{ie(e)}),v.changing$.subscribe(e=>{ie(e)}),v.changeEnd$.subscribe(e=>{ie(e)}),r.focus$.subscribe(e=>{if(e.length!==1)return;let t=r.getDrawingByParam(e[0]);if(t==null)return;let n=t.transform;if(n==null)return;let{width:i,height:a,left:o,top:s,angle:c}=n;i!=null&&E(i),a!=null&&O(a),o!=null&&j(o),s!=null&&N(s),c!=null&&ee(c)})];return()=>{e.forEach(e=>e.unsubscribe())}},[]);let ae=h(e=>{if(e==null)return;let{limitWidth:t,limitHeight:n}=re(A,M,e,D);e=Math.min(e,t);let i={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{width:e}};if(te){let t=e/T*D;if(t=Math.max(t,20),t>n)return;O(t),i.transform.height=t}E(e),r.featurePluginUpdateNotification([i]),v.refreshControls().changeNotification()},300),oe=h(e=>{if(e==null)return;let{limitHeight:t,limitWidth:n}=re(A,M,T,e);e=Math.min(e,t);let i={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{height:e}};if(te){let t=e/D*T;if(t=Math.max(t,20),t>n)return;E(t),i.transform.width=t}O(e),r.featurePluginUpdateNotification([i]),v.refreshControls().changeNotification()},300),se=h(e=>{if(e==null)return;let{limitLeft:t}=re(e,M,T,D);e=t;let n={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{left:e}};j(e),r.featurePluginUpdateNotification([n]),v.refreshControls().changeNotification()},300),ce=h(e=>{if(e==null)return;let{limitTop:t}=re(A,e,T,D);e=t;let n={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{top:e}};N(e),r.featurePluginUpdateNotification([n]),v.refreshControls().changeNotification()},300),le=e=>{if(e==null)return;let t={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{angle:e}};ee(e),r.featurePluginUpdateNotification([t]),v.refreshControls().changeNotification()},ue=e=>{ne(e),v.keepRatio=e};return H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!o}),children:[V(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:V(`div`,{children:n.t(`image-panel.transform.title`)})}),H(`div`,{className:`univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2`,children:[H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.width`)}),V(R,{precision:1,value:T,min:20,onChange:e=>{ae(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.height`)}),V(R,{precision:1,value:D,min:20,onChange:e=>{oe(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.lock`)}),V(`div`,{className:`univer-text-center`,children:V(Ee,{checked:te,onChange:ue})})]})]}),H(`div`,{className:`univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2`,children:[H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.x`)}),V(R,{precision:1,value:A,onChange:e=>{se(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.y`)}),V(R,{precision:1,value:M,onChange:e=>{ce(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.rotate`)}),V(R,{precision:1,value:P,min:Vt[0],max:Vt[1],onChange:le})]})]})]})},Ut=e=>{let t=I(i),n=I(d),{drawings:r,cropperShow:a}=e;if(r[0]==null)return;let[o,s]=B(Y.FREE),c=Me(!1),l=[{label:n.t(`image-panel.crop.mode`),value:Y.FREE},{label:`1:1`,value:Y.R1_1},{label:`16:9`,value:Y.R16_9},{label:`9:16`,value:Y.R9_16},{label:`5:4`,value:Y.R5_4},{label:`4:5`,value:Y.R4_5},{label:`4:3`,value:Y.R4_3},{label:`3:4`,value:Y.R3_4},{label:`3:2`,value:Y.R3_2},{label:`2:3`,value:Y.R2_3}];je(()=>{let e=t.onCommandExecuted(e=>{if(e.id===J.id){let t=e.params;t!=null&&t.isAuto||(c.current=!1)}});return()=>{e==null||e.dispose()}},[]);function u(e){s(e),c.current&&t.executeCommand(Je.id,{cropType:e})}let f=e=>{t.executeCommand(Je.id,{cropType:e}),c.current=!0};return H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!a}),children:[V(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:V(`div`,{children:n.t(`image-panel.crop.title`)})}),H(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[H(L,{onClick:()=>{f(o)},children:[V(oe,{}),n.t(`image-panel.crop.start`)]}),V(ke,{value:o,options:l,onChange:u})]})]})},Wt=e=>{let t=I(y),n=I(k),r=I(d),{drawings:i,hasArrange:a=!0,hasTransform:o=!0,hasAlign:s=!0,hasCropper:c=!0,hasGroup:l=!0}=e,u=i[0];if(u==null)return;let{unitId:f}=u,p=n.getRenderById(f),m=p==null?void 0:p.scene;if(m==null)return;let h=m.getTransformerByCreate(),[g,_]=B(!0),[v,b]=B(!0),[x,S]=B(!1),[C,w]=B(!0),[T,E]=B(!1);return je(()=>{let e=h.clearControl$.subscribe(e=>{e===!0&&(_(!1),b(!1),S(!1),w(!1),E(!0))}),n=h.changeStart$.subscribe(e=>{let{objects:n}=e,r=Ot(n,t);r.length===0?(_(!1),b(!1),S(!1),w(!1),E(!0)):r.length===1?(_(!0),b(!0),S(!1),w(!0),E(!1)):(_(!0),b(!1),S(!0),w(!1),E(!1))}),r=t.focus$.subscribe(e=>{e.length===0?(_(!1),b(!1),S(!1),w(!1),E(!0)):e.length===1?(_(!0),b(!0),S(!1),w(!0),E(!1)):(_(!0),b(!1),S(!0),w(!1),E(!1))});return()=>{n.unsubscribe(),e.unsubscribe(),r.unsubscribe()}},[]),H(Ne,{children:[V(`div`,{className:z(`univer-h-full`,{"univer-hidden":!T}),children:V(`div`,{className:`univer-flex univer-h-full univer-items-center univer-justify-center`,children:V(`span`,{children:r.t(`image-panel.null`)})})}),V(zt,{arrangeShow:a===!0?g:!1,drawings:i}),V(Ht,{transformShow:o===!0?v:!1,drawings:i}),V(Rt,{alignShow:s===!0?x:!1,drawings:i}),V(Ut,{cropperShow:c===!0?C:!1,drawings:i}),V(Bt,{hasGroup:l,drawings:i})]})};export{Je as AutoImageCropOperation,Tt as COMPONENT_IMAGE_POPUP_MENU,q as CancelDrawingGroupOperation,J as CloseImageCropOperation,Ke as DRAWING_GROUP_TYPES,Wt as DrawingCommonPanel,It as DrawingRenderService,Pt as ImageCropperObject,Et as ImagePopupMenu,Ye as ImageResetSizeOperation,qe as OpenImageCropOperation,W as SetDrawingAlignOperation,G as SetDrawingArrangeOperation,K as SetDrawingGroupOperation,$ as UniverDrawingUIPlugin,Ze as getCurrentUnitInfo,Ot as getUpdateParams,Xe as insertGroupObject};
|
package/lib/index.js
CHANGED
|
@@ -1,32 +1 @@
|
|
|
1
|
-
import{ArrangeTypeEnum as e,CommandType as t,Disposable as n,DrawingTypeEnum as r,ICommandService as i,IConfigService as a,IURLImageService as o,IUniverInstanceService as s,ImageSourceType as c,Inject as l,Injector as u,LocaleService as d,Plugin as f,UniverInstanceType as p,checkIfMove as m,debounce as h,generateRandomId as g,merge as _,toDisposable as v}from"@univerjs/core";import{IDrawingManagerService as y,IImageIoService as b,ImageSourceType as x,SetDrawingSelectedOperation as S,getDrawingShapeKeyByDrawingSearch as C}from"@univerjs/drawing";import{CURSOR_TYPE as w,Canvas as T,DRAWING_OBJECT_LAYER_INDEX as E,DrawingGroupObject as D,Group as O,IRenderManagerService as k,Image as A,RENDER_CLASS_TYPE as j,Rect as M,Shape as N,Vector2 as P,degToRad as ee,getGroupState as te,precisionTo as ne,transformObjectOutOfGroup as re}from"@univerjs/engine-render";import{AutofillDoubleIcon as ie,BottomIcon as ae,CreateCopyIcon as oe,GroupIcon as se,MoreDownIcon as ce,MoveDownIcon as le,MoveUpIcon as ue,TopmostIcon as de,UngroupIcon as fe}from"@univerjs/icons";import{ComponentManager as pe,ContextMenuGroup as me,ContextMenuPosition as he,IDialogService as ge,IGalleryService as _e,IMenuManagerService as ve,IMessageService as ye,MenuItemType as F,useDependency as I}from"@univerjs/ui";import{Observable as be,bufferTime as xe,filter as Se,map as Ce,of as we,switchMap as Te}from"rxjs";import{Button as L,Checkbox as Ee,DropdownMenu as De,InputNumber as R,MessageType as Oe,Select as ke,borderClassName as Ae,clsx as z}from"@univerjs/design";import{useEffect as je,useRef as Me,useState as B}from"react";import{Fragment as Ne,jsx as V,jsxs as H}from"react/jsx-runtime";let U=function(e){return e.default=`0`,e.left=`1`,e.center=`2`,e.right=`3`,e.top=`4`,e.middle=`5`,e.bottom=`6`,e.horizon=`7`,e.vertical=`8`,e}({});const W={id:`sheet.operation.set-image-align`,type:t.OPERATION,handler:(e,t)=>!0},Pe={id:`sheet.operation.set-drawing-align-left`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.left})},Fe={id:`sheet.operation.set-drawing-align-center`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.center})},Ie={id:`sheet.operation.set-drawing-align-right`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.right})},Le={id:`sheet.operation.set-drawing-align-top`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.top})},Re={id:`sheet.operation.set-drawing-align-middle`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.middle})},ze={id:`sheet.operation.set-drawing-align-bottom`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.bottom})},Be={id:`sheet.operation.set-drawing-align-horizon`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.horizon})},Ve={id:`sheet.operation.set-drawing-align-vertical`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.vertical})},G={id:`drawing.operation.set-drawing-arrange`,type:t.OPERATION,handler:(e,t)=>{let n=e.get(y),{arrangeType:r}=t,i=t.drawings||n.getFocusDrawings(),{unitId:a,subUnitId:o}=i[0],s=i.map(e=>e.drawingId);return n.featurePluginOrderUpdateNotification({unitId:a,subUnitId:o,drawingIds:s,arrangeType:r}),!0}},He={id:`drawing.operation.set-drawing-arrange-front`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.front})},Ue={id:`drawing.operation.set-drawing-arrange-forward`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.forward})},We={id:`drawing.operation.set-drawing-arrange-back`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.back})},Ge={id:`drawing.operation.set-drawing-arrange-backward`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.backward})},Ke=[r.DRAWING_IMAGE,r.DRAWING_SHAPE,r.DRAWING_GROUP],K={id:`drawing.operation.set-drawing-group`,type:t.OPERATION,handler:(e,t)=>{let n=e.get(y),i=t.drawings||n.getFocusDrawings();if(i.length<2||!i.every(e=>Ke.includes(e.drawingType)))return!1;let{unitId:a,subUnitId:o}=i[0],s=g(10),c=te(0,0,i.map(e=>e.transform||{})),l={unitId:a,subUnitId:o,drawingId:s,drawingType:r.DRAWING_GROUP,transform:c,groupBaseBound:{left:c.left,top:c.top,width:c.width,height:c.height}},u=i.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t},groupId:s}});return n.featurePluginGroupUpdateNotification([{parent:l,children:u}]),!0}},q={id:`drawing.operation.cancel-drawing-group`,type:t.OPERATION,handler:(e,t)=>{let n=e.get(y),i=(t.drawings||n.getFocusDrawings()).map(e=>{if(e.drawingType!==r.DRAWING_GROUP)return null;let{unitId:t,subUnitId:i,drawingId:a,transform:o={width:0,height:0},groupBaseBound:s}=e;if(o===null)return null;let c=n.getDrawingsByGroup({unitId:t,subUnitId:i,drawingId:a});return c.length===0?null:{parent:e,children:c.map(e=>{let{transform:t}=e,{unitId:n,subUnitId:r,drawingId:i}=e,a=re(t||{},o,o.width||0,o.height||0,s);return{unitId:n,subUnitId:r,drawingId:i,transform:{...t,...a},groupId:void 0}})}}).filter(e=>e!==null);return i.length===0?!1:(n.featurePluginUngroupUpdateNotification(i),!0)}},qe={id:`sheet.operation.open-image-crop`,type:t.OPERATION,handler:(e,t)=>!0},J={id:`sheet.operation.close-image-crop`,type:t.OPERATION,handler:(e,t)=>!0};let Y=function(e){return e.FREE=`0`,e.R1_1=`1`,e.R16_9=`2`,e.R9_16=`3`,e.R5_4=`4`,e.R4_5=`5`,e.R4_3=`6`,e.R3_4=`7`,e.R3_2=`8`,e.R2_3=`9`,e}({});const Je={id:`sheet.operation.Auto-image-crop`,type:t.OPERATION,handler:(e,t)=>!0},Ye={id:`sheet.operation.image-reset-size`,type:t.OPERATION,handler:(e,t)=>!0};function Xe(e,t,n,r){let i=r.getDrawingByParam(e);if(i==null)return;let a=C(e),o=n.getObjectIncludeInGroup(a);if(o&&!(o instanceof O))return;if(o!=null){let e=o.getObjects();for(let n of e)if(n.oKey===t.oKey)return;o.addObject(t);return}let s=new D(a);n.addObject(s,E).attachTransformerTo(s),s.addObject(t);let{transform:c,groupBaseBound:l}=i;l&&s.setBaseBound(l),i.groupId&&(s.isInGroup=!0,Xe({drawingId:i.groupId,unitId:e.unitId,subUnitId:e.subUnitId},s,n,r)),c&&s.transformByState({left:c.left,top:c.top,angle:c.angle,width:c.width,height:c.height})}function Ze(e,t){let n=t?e.getUnit(t):e.getFocusedUnit();if(n==null)return;let r=n.getUnitId(),i;if(n.type===p.UNIVER_SHEET){var a;i=(a=n.getActiveSheet())==null?void 0:a.getSheetId()}else (n.type===p.UNIVER_DOC||n.type===p.UNIVER_SLIDE)&&(i=r);return{unitId:r,subUnitId:i,current:n}}var Qe=`@univerjs/drawing-ui`,$e=`0.18.0`;const et=`drawing-ui.config`;Symbol(et);const tt={},nt=e=>{let t=e.get(y);return new be(e=>{let n=t=>{if(!t||t.length===0||t.length<2)return e.next(!0);e.next(!1)},r=t.focus$.subscribe(t=>{if(!t||t.length===0)return e.next(!0);n(t)});return n(t.getFocusDrawings()),()=>r.unsubscribe()})},rt=`contextMenu.drawing-align`;function it(e){return{id:rt,type:F.SUBITEMS,icon:`HorizontallyIcon`,title:`image-panel.align.title`,hidden$:nt(e)}}function at(){return{id:Pe.id,type:F.BUTTON,icon:`LeftJustifyingIcon`,title:`image-panel.align.left`}}function ot(){return{id:Fe.id,type:F.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.center`}}function st(){return{id:Ie.id,type:F.BUTTON,icon:`RightJustifyingIcon`,title:`image-panel.align.right`}}function ct(){return{id:Le.id,type:F.BUTTON,icon:`AlignTopIcon`,title:`image-panel.align.top`}}function lt(){return{id:Re.id,type:F.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.middle`}}function ut(){return{id:ze.id,type:F.BUTTON,icon:`AlignBottomIcon`,title:`image-panel.align.bottom`}}function dt(){return{id:Be.id,type:F.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.horizon`}}function ft(){return{id:Ve.id,type:F.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.vertical`}}const pt=`contextMenu.drawing-arrange`;function mt(){return{id:pt,type:F.SUBITEMS,icon:`TopmostIcon`,title:`image-panel.arrange.title`}}function ht(){return{id:He.id,type:F.BUTTON,icon:`TopmostIcon`,title:`image-panel.arrange.front`}}function gt(){return{id:Ue.id,type:F.BUTTON,icon:`MoveUpIcon`,title:`image-panel.arrange.forward`}}function _t(){return{id:We.id,type:F.BUTTON,icon:`BottomIcon`,title:`image-panel.arrange.back`}}function vt(){return{id:Ge.id,type:F.BUTTON,icon:`MoveDownIcon`,title:`image-panel.arrange.backward`}}const yt=(e,t)=>{let n=e.get(y);return new be(e=>{let i=n=>{if(!n||n.length===0)return e.next(!0);if(t===`group`){if(n.length<2||!n.every(e=>Ke.includes(e.drawingType)))return e.next(!0)}else if(t===`unGroup`){if(n.filter(e=>e.drawingType===r.DRAWING_GROUP).length===0)return e.next(!0)}else if(!n.every(e=>Ke.includes(e.drawingType)))return e.next(!0);e.next(!1)},a=n.focus$.subscribe(t=>{if(!t||t.length===0)return e.next(!0);i(t)});return i(n.getFocusDrawings()),()=>a.unsubscribe()})},bt=`contextMenu.drawing-group`;function xt(e){return{id:bt,type:F.SUBITEMS,icon:`GroupIcon`,title:`image-panel.group.title`,hidden$:yt(e)}}function St(e){return{id:K.id,type:F.BUTTON,icon:`GroupIcon`,title:`image-panel.group.group`,disabled$:yt(e,`group`)}}function Ct(e){return{id:q.id,type:F.BUTTON,icon:`UngroupIcon`,title:`image-panel.group.unGroup`,disabled$:yt(e,`unGroup`)}}const wt={[he.DRAWING]:{[me.OTHERS]:{[bt]:{order:1,menuItemFactory:xt,[K.id]:{order:0,menuItemFactory:St},[q.id]:{order:1,menuItemFactory:Ct}},[pt]:{order:2,menuItemFactory:mt,[He.id]:{order:0,menuItemFactory:ht},[Ue.id]:{order:1,menuItemFactory:gt},[We.id]:{order:2,menuItemFactory:_t},[Ge.id]:{order:3,menuItemFactory:vt}},[rt]:{order:3,menuItemFactory:it,[Pe.id]:{order:0,menuItemFactory:at},[Fe.id]:{order:1,menuItemFactory:ot},[Ie.id]:{order:2,menuItemFactory:st},[Le.id]:{order:3,menuItemFactory:ct},[Re.id]:{order:4,menuItemFactory:lt},[ze.id]:{order:5,menuItemFactory:ut},[Be.id]:{order:6,menuItemFactory:dt},[Ve.id]:{order:7,menuItemFactory:ft}}}}},Tt=`COMPONENT_IMAGE_POPUP_MENU`;function Et(e){var t;let{popup:n}=e,r=n==null||(t=n.extraProps)==null?void 0:t.menuItems;if(!r)return null;let a=I(i),o=I(d),[s,c]=B(!1),[l,u]=B(!1),f=()=>{u(!0)},p=()=>{u(!1)},m=e=>{c(e)},h=e=>{a.executeCommand(e.commandId,e.commandParams),c(!1)},g=s||l;return V(`div`,{onMouseEnter:f,onMouseLeave:p,children:V(De,{align:`start`,items:r.filter(e=>!e.disable).map(e=>({type:`item`,children:o.t(e.label),onSelect:()=>h(e)})),open:s,onOpenChange:m,children:H(`div`,{className:z(`
|
|
2
|
-
univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1
|
|
3
|
-
hover:univer-bg-gray-100
|
|
4
|
-
dark:hover:!univer-bg-gray-800
|
|
5
|
-
`,Ae,{"univer-bg-gray-100 dark:!univer-bg-gray-800":s,"univer-bg-white dark:!univer-bg-gray-900":!s}),children:[V(ie,{className:`
|
|
6
|
-
univer-fill-primary-600 univer-text-gray-900
|
|
7
|
-
dark:!univer-text-white
|
|
8
|
-
`}),g&&V(ce,{className:`dark:!univer-text-white`})]})})})}function X(e,t){return function(n,r){t(n,r,e)}}function Z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Dt=class extends n{constructor(e,t,n){super(),this._componentManager=e,this._commandService=t,this._menuManagerService=n,this._init()}_init(){this._initMenus(),this._initCommands(),this._initComponents()}_initMenus(){this._menuManagerService.mergeMenu(wt)}_initCommands(){[qe,J,Ye,W,Pe,Fe,Ie,Le,Re,ze,Be,Ve,Je,K,q,G,He,Ue,We,Ge].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initComponents(){[[Tt,Et],[`BottomIcon`,ae],[`GroupIcon`,se],[`MoveDownIcon`,le],[`MoveUpIcon`,ue],[`TopmostIcon`,de],[`UngroupIcon`,fe]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Dt=Z([X(0,l(pe)),X(1,i),X(2,ve)],Dt);function Ot(e,t){let n=[];return e.forEach(e=>{let{oKey:i,left:a,top:o,height:s,width:c,angle:l}=e,u=t.getDrawingOKey(i);if(u==null)return n.push(null),!0;let{unitId:d,subUnitId:f,drawingId:p,drawingType:m}=u,h={unitId:d,subUnitId:f,drawingId:p,drawingType:m,transform:{left:a,top:o,height:s,width:c,angle:l}};m===r.DRAWING_IMAGE&&(h.srcRect=e.srcRect),n.push(h)}),n}function kt(e){"@babel/helpers - typeof";return kt=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},kt(e)}function At(e,t){if(kt(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(kt(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function jt(e){var t=At(e,`string`);return kt(t)==`symbol`?t:t+``}function Q(e,t,n){return(t=jt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let Mt=class extends n{constructor(e,t,n,r){super(),this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._drawingManagerService=r,Q(this,`_sceneListenerOnDrawingMap`,new WeakSet),this._initialize()}dispose(){super.dispose()}_initialize(){this._recoveryImages(),this._drawingAddListener(),this._drawingRemoveListener(),this._drawingUpdateListener(),this._commandExecutedListener(),this._drawingArrangeListener(),this._drawingGroupListener(),this._drawingRefreshListener(),this._drawingVisibleListener()}_recoveryImages(){let e=this._drawingManagerService.drawingManagerData,t=Ze(this._currentUniverService);if(t==null)return;let{unitId:n,subUnitId:r}=t;Object.keys(e).forEach(t=>{Object.keys(e[t]).forEach(i=>{let a=e[t][i].data;a==null||t!==n||i!==r||Object.keys(a).forEach(e=>{a[e]&&this._insertDrawing([{unitId:t,subUnitId:i,drawingId:e}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===W.id){let t=e.params;if(t==null)return;this._drawingAlign(t)}}))}_drawingGroupListener(){this.disposeWithMe(this._drawingManagerService.group$.subscribe(e=>{this._groupDrawings(e)})),this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe(e=>{this._ungroupDrawings(e)}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_groupDrawings(e){e.forEach(e=>{this._groupDrawing(e)})}_groupDrawing(e){let{parent:t,children:n}=e,{unitId:r,subUnitId:i,drawingId:a}=t,o=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(o==null)return;let{scene:s,transformer:c}=o;this._commandService.syncExecuteCommand(J.id);let l=[];if(n.forEach(e=>{let t=C(e),n=s.getObjectIncludeInGroup(t);if(n==null||l.includes(n))return;l.push(n);let{transform:r}=e;r!=null&&(n.classType===j.GROUP?n.transformByState({left:r.left,top:r.top}):n.transformByState(r))}),l.length===0)return;let u=new D(C({unitId:r,subUnitId:i,drawingId:a}));s.addObject(u,E).attachTransformerTo(u),u.addObjects(...l),t.groupBaseBound&&u.setBaseBound(t.groupBaseBound),t.groupId&&(u.isInGroup=!0,Xe({drawingId:t.groupId,unitId:r,subUnitId:i},u,s,this._drawingManagerService)),t.transform&&u.transformByState({left:t.transform.left,top:t.transform.top,width:t.transform.width,height:t.transform.height,angle:t.transform.angle}),c.clearSelectedObjects(),c.setSelectedControl(u)}_ungroupDrawings(e){e.forEach(e=>{this._ungroupDrawing(e)})}_ungroupDrawing(e){let{parent:t,children:n}=e,r=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(r==null)return;let{scene:i,transformer:a}=r;n.forEach(e=>{let t=C(e),n=i.getObjectIncludeInGroup(t);if(n==null)return!0;if(n==null)return;let{transform:r}=e;r!=null&&(n.classType===j.GROUP?n.transformByState({left:r.left,top:r.top}):n.transformByState(r))});let o=C(t),s=i.getObject(o),{width:c,height:l}=s;s.getObjects().forEach(e=>{s.removeSelfObjectAndTransform(e.oKey,c,l)}),s.dispose(),a.clearSelectedObjects()}_drawingAlign(e){let{alignType:t}=e,n=e.drawings||this._drawingManagerService.getFocusDrawings();if(t===U.default)return;let r=[],i=1/0,a=1/0,o=-1/0,s=-1/0,c=0;n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:l,drawingType:u}=e,d=this._drawingManagerService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:l});if(d==null||d.transform==null)return;r.push({unitId:t,subUnitId:n,drawingId:l,drawingType:u,transform:d.transform});let{left:f=0,top:p=0,width:m=0,height:h=0}=d.transform;i=Math.min(i,f),a=Math.min(a,p),o=Math.max(o,f+m),s=Math.max(s,p+h),c++}),c!==0&&(this._sortDrawingTransform(r,t),this._applyAlignType(r,t,i,a,o,s,c))}_applyAlignType(e,t,n,r,i,a,o){let s=Math.round((i-n)/o*10)/10,c=Math.round((a-r)/o*10)/10,l=[],u=this._getSceneAndTransformerByDrawingSearch(e[0].unitId);if(u==null)return;let{scene:d,transformer:f}=u;e.forEach((e,o)=>{let{unitId:u,subUnitId:d,drawingId:f,transform:p,drawingType:m}=e,{left:h=0,top:g=0,width:_=0,height:v=0}=p,y=h,b=g;switch(t){case U.left:y=n;break;case U.center:y=n+(i-n)/2-_/2;break;case U.right:y=i-_;break;case U.top:b=r;break;case U.middle:b=r+(a-r)/2-v/2;break;case U.bottom:b=a-v;break;case U.horizon:y=n+s*o;break;case U.vertical:b=r+c*o;break;default:break}(y!==h||b!==g)&&l.push({unitId:u,subUnitId:d,drawingId:f,drawingType:m,transform:{left:y,top:b}})}),this._drawingManagerService.featurePluginUpdateNotification(l),f.refreshControls().changeNotification()}_sortDrawingTransform(e,t){e.sort((e,n)=>{let r=e.transform,i=n.transform,{left:a=0,top:o=0,width:s=0,height:c=0}=r,{left:l=0,top:u=0,width:d=0,height:f=0}=i;switch(t){case U.left:return a-l;case U.center:return a+s/2-(l+d/2);case U.right:return a+s-(l+d);case U.top:return o-u;case U.middle:return o+c/2-(u+f/2);case U.bottom:return o+c-(u+f);case U.horizon:return a+s/2-(l+d/2);case U.vertical:return o+c/2-(u+f/2);default:return 0}})}_drawingArrangeListener(){this.disposeWithMe(this._drawingManagerService.order$.subscribe(e=>{this._drawingArrange(e)}))}_drawingArrange(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=this._getSceneAndTransformerByDrawingSearch(t);if(i==null)return;let{scene:a}=i;r.forEach(e=>{let r=C({unitId:t,subUnitId:n,drawingId:e}),i=a.fuzzyMathObjects(r,!0);if(i==null||i.length===0)return;let o=this._drawingManagerService.getDrawingOrder(t,n).indexOf(e);for(let e of i)e.setProps({zIndex:o}),e.makeDirty()})}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{this._insertDrawing(e)}))}_insertDrawing(e){let t=[];e.forEach(e=>{let{unitId:n}=e;if(this._drawingManagerService.getDrawingByParam(e)==null)return;let r=this._getSceneAndTransformerByDrawingSearch(n);if(r==null)return;let{scene:i}=r;t.includes(i)||t.push(i)}),t.forEach(e=>{this._sceneListenerOnDrawingMap.has(e)||(this._addListenerOnDrawing(e),this._sceneListenerOnDrawingMap.add(e))})}_drawingRemoveListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(t);if(i==null)return;let{scene:a}=i,o=C({unitId:t,subUnitId:n,drawingId:r}),s=a.fuzzyMathObjects(o,!0);if(s.length>0){var c;for(let e of s)e.dispose();(c=a.getTransformer())==null||c.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{var t;let{unitId:n,subUnitId:r,drawingId:i}=e,a=this._drawingManagerService.getDrawingByParam(e);if(a==null)return;let{transform:o,drawingType:s}=a,c=this._getSceneAndTransformerByDrawingSearch(n);if(c==null)return;let{scene:l,transformer:u}=c;if(o==null)return!0;let{left:d=0,top:f=0,width:p=0,height:m=0,angle:h=0,flipX:g=!1,flipY:_=!1,skewX:v=0,skewY:y=0}=o,b=C({unitId:n,subUnitId:r,drawingId:i}),x=l.getObject(b);if(x==null)return!0;x.transformByState({left:d,top:f,width:p,height:m,angle:h,flipX:g,flipY:_,skewX:v,skewY:y}),(t=l.getTransformer())==null||t.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(t);if(i==null)return;let a=this._drawingManagerService.getDrawingByParam(e);if(a==null)return;let{transform:o}=a,{scene:s}=i,c=C({unitId:t,subUnitId:n,drawingId:r}),l=s.getObject(c);if(l==null||o==null)return!0;let{left:u=0,top:d=0,width:f=0,height:p=0,angle:m=0,flipX:h=!1,flipY:g=!1,skewX:_=0,skewY:v=0}=o;l.transformByState({left:u,top:d,width:f,height:p,angle:m,flipX:h,flipY:g,skewX:_,skewY:v})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r,visible:i}=e,a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{scene:o}=a,s=C({unitId:t,subUnitId:n,drawingId:r}),c=o.getObject(s);if(c==null)return!0;i?c.show():c.hide()})}))}_filterUpdateParams(e,t){return e.filter((e,n)=>{if(e==null)return!1;let{transform:r}=e;return m(r,t==null?void 0:t[n])})}_addListenerOnDrawing(e){let t=e.getTransformerByCreate(),n=null;this.disposeWithMe(v(t.changeStart$.subscribe(e=>{let{objects:t}=e,r=Array.from(t.values()),i=[];n=r.map(e=>{let{left:t,top:n,height:r,width:a,angle:o,oKey:s,isInGroup:c}=e,l=this._drawingManagerService.getDrawingOKey(s);if(c||e instanceof O){let t=e.ancestorGroup;if(t==null&&e instanceof O&&(t=e),t==null)return null;let n=this._drawingManagerService.getDrawingOKey(t.oKey);if(n){let{unitId:e,subUnitId:r,drawingId:a}=n;i.push({unitId:e,subUnitId:r,drawingId:a});let{left:o,top:s,height:c,width:l,angle:u}=t;return{left:o,top:s,height:c,width:l,angle:u}}}else if(l!=null){let{unitId:e,subUnitId:s,drawingId:c}=l;return i.push({unitId:e,subUnitId:s,drawingId:c}),{left:t,top:n,height:r,width:a,angle:o}}return null}).filter(e=>e!=null),i.length>0?this._commandService.syncExecuteCommand(S.id,i):this._commandService.syncExecuteCommand(S.id,[])}))),this.disposeWithMe(v(t.changeEnd$.subscribe(e=>{let{objects:t}=e,r=this._filterUpdateParams(Ot(t,this._drawingManagerService),n);r.length>0&&this._drawingManagerService.featurePluginUpdateNotification(r)})))}};Mt=Z([X(0,s),X(1,i),X(2,k),X(3,y)],Mt);var Nt=function(e){return e[e.RECT=0]=`RECT`,e[e.PATH=1]=`PATH`,e}(Nt||{}),Pt=class extends N{constructor(e,t){t==null&&(t={}),t.transformerConfig={keepRatio:!1,isCropper:!0,anchorFill:`rgb(0, 0, 0)`,anchorStroke:`rgb(255, 255, 255)`,anchorSize:24},super(e,t),Q(this,`_srcRect`,void 0),Q(this,`_prstGeom`,void 0),Q(this,`_applyTransform`,void 0),Q(this,`_dragPadding`,8),Q(this,`_cacheCanvas`,void 0),t!=null&&t.srcRect&&(this._srcRect=t.srcRect),t!=null&&t.prstGeom&&(this._prstGeom=t.prstGeom),t!=null&&t.applyTransform&&(this._applyTransform=t.applyTransform),t!=null&&t.dragPadding&&(this._dragPadding=t.dragPadding),this._applyProps()}refreshSrcRect(e,t){this._srcRect=e,this._applyTransform=t,this._applyProps()}get srcRect(){return this._srcRect}dispose(){var e;super.dispose(),(e=this._cacheCanvas)==null||e.dispose(),this._srcRect=null}isHit(e){let t=this.getInverseCoord(e);return t.x>=-this.strokeWidth/2&&t.x<=this.width+this.strokeWidth/2&&t.y>=-this.strokeWidth/2&&t.y<=this.height+this.strokeWidth/2&&!this._inSurround(t)}_inSurround(e){let t=this._dragPadding;return e.x>=t-this.strokeWidth/2&&e.x<=this.width+this.strokeWidth/2-t&&e.y>=t-this.strokeWidth/2&&e.y<=this.height+this.strokeWidth/2-t}render(e,t){return this.visible?(e.save(),this._draw(e),e.restore(),this.makeDirty(!1),this):(this.makeDirty(!1),this)}_draw(e){var t,n;let{width:r,height:i}=this.getScene().getEngine();this._initialCacheCanvas(),(t=this._cacheCanvas)==null||t.clear();let a=(n=this._cacheCanvas)==null?void 0:n.getContext();a!=null&&(a.save(),M.drawWith(a,{left:0,top:0,width:r,height:i,fill:`rgba(0, 0, 0, 0.5)`}),a.setTransform(e.getTransform()),this._clipForApplyObject(a),this._applyCache(e),a.restore())}_clipForApplyObject(e){let t=Nt.RECT;if(this._prstGeom!=null&&(t=Nt.PATH),e.globalCompositeOperation=`destination-out`,e.beginPath(),t===Nt.RECT){let t=this.transform.getMatrix();e.transform(t[0],t[1],t[2],t[3],t[4],t[5]),e.rect(0,0,this.width,this.height),e.fill()}}_applyProps(){if(this._applyTransform==null)return;let e=0,t=0,n=0,r=0,{left:i=0,top:a=0,width:o=0,height:s=0,angle:c}=this._applyTransform;if(this._srcRect!=null){let{left:i=0,top:a=0,right:o=0,bottom:s=0}=this._srcRect;e=i,t=a,n=o,r=s}let l=i+e,u=a+t;this.transformByState({left:l,top:u,width:i+o-n-l,height:a+s-r-u,angle:c})}_applyCache(e){if(!e||this._cacheCanvas==null)return;let t=this._cacheCanvas.getContext();t.save(),e.save(),e.setTransform(1,0,0,1,0,0),t.setTransform(1,0,0,1,0,0),e.drawImage(this._cacheCanvas.getCanvasEle(),0,0),e.restore(),t.restore()}_initialCacheCanvas(){if(this._cacheCanvas!=null)return;let e=this.getScene();if(e==null)return;this._cacheCanvas=new T;let t=e.getEngine();this._cacheCanvas.setSize(t.width,t.height),t.onTransformChange$.subscribeEvent(()=>{var e;(e=this._cacheCanvas)==null||e.setSize(t.width,t.height),this.makeDirty(!0)})}};let Ft=class extends n{constructor(e,t,n,r,i,a){super(),this._commandService=e,this._drawingManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._messageService=i,this._localeService=a,Q(this,`_sceneListenerOnImageMap`,new WeakSet),this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==Je.id)return;let t=e.params;if(t==null)return;let{cropType:n}=t,r=this._drawingManagerService.getFocusDrawings();if(r.length!==1)return;let{unitId:i,subUnitId:a,drawingId:o}=r[0],s=this._renderManagerService.getRenderById(i),c=s==null?void 0:s.scene;if(c==null)return!0;this._searchCropObject(c)!=null&&this._commandService.syncExecuteCommand(J.id,{isAuto:!0});let l=C({unitId:i,subUnitId:a,drawingId:o}),u=c.getObject(l);if(!(u instanceof A)){this._messageService.show({type:Oe.Error,content:this._localeService.t(`image-cropper.error`)});return}u!=null&&(this._updateCropperObject(n,u),this._commandService.executeCommand(qe.id,{unitId:i,subUnitId:a,drawingId:o}))}))}_calculateSrcRectByRatio(e,t,n,r,i,a){let o=n/r,s=i/a,c=n,l=r;o>s?c=r*s:l=n/s;let u=(n-c)/2,d=(r-l)/2;return{left:ne(u,1),top:ne(d,1),right:ne(n-(u+c),1),bottom:ne(r-(d+l),1)}}_updateCropperObject(e,t){let{left:n,top:r,width:i,height:a}=t.calculateTransformWithSrcRect(),o;switch(e){case Y.R1_1:o=this._calculateSrcRectByRatio(n,r,i,a,1,1);break;case Y.R16_9:o=this._calculateSrcRectByRatio(n,r,i,a,16,9);break;case Y.R9_16:o=this._calculateSrcRectByRatio(n,r,i,a,9,16);break;case Y.R5_4:o=this._calculateSrcRectByRatio(n,r,i,a,5,4);break;case Y.R4_5:o=this._calculateSrcRectByRatio(n,r,i,a,4,5);break;case Y.R4_3:o=this._calculateSrcRectByRatio(n,r,i,a,4,3);break;case Y.R3_4:o=this._calculateSrcRectByRatio(n,r,i,a,3,4);break;case Y.R3_2:o=this._calculateSrcRectByRatio(n,r,i,a,3,2);break;case Y.R2_3:o=this._calculateSrcRectByRatio(n,r,i,a,2,3);break;case Y.FREE:default:break}if(o==null)return;t.setSrcRect(o);let{left:s=0,top:c=0,bottom:l=0,right:u=0}=o;t.transformByStateCloseCropper({left:n+s,top:r+c,width:i-u-s,height:a-l-c})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==qe.id)return;let t=e.params;if(t==null)return;let{unitId:n,subUnitId:r,drawingId:i}=t,a=this._renderManagerService.getRenderById(n),o=a==null?void 0:a.scene;if(o==null)return!0;if(this._sceneListenerOnImageMap.has(o)||(this._addListenerOnImage(o),this._sceneListenerOnImageMap.add(o)),this._drawingManagerService.getDrawingByParam({unitId:n,subUnitId:r,drawingId:i})==null)return;let s=C({unitId:n,subUnitId:r,drawingId:i}),c=o.getObject(s);if(c==null)return;if(!(c instanceof A)){this._messageService.show({type:Oe.Error,content:this._localeService.t(`image-cropper.error`)});return}let l=o.getTransformer();l==null||l.clearControls();let u=new Pt(`${s}-crop`,{srcRect:c.srcRect,prstGeom:c.prstGeom,applyTransform:c.calculateTransformWithSrcRect()});o.addObject(u,c.getLayerIndex()+1).attachTransformerTo(u),l==null||l.createControlForCopper(u),this._addHoverForImageCopper(u),c.openRenderByCropper(),l==null||l.refreshControls(),u.makeDirty(!0),this._commandService.syncExecuteCommand(S.id,[{unitId:n,subUnitId:r,drawingId:i}])}))}_searchCropObject(e){let t=e.getAllObjectsByOrder();for(let e of t)if(e instanceof Pt)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==J.id)return;let t=this._univerInstanceService.getFocusedUnit();if(t==null)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n),i=r==null?void 0:r.scene;if(i==null)return!0;let a=this._searchCropObject(i);if(a==null)return;let o=this._getApplyObjectByCropObject(a);if(o==null)return;let s=i.getTransformerByCreate();s.detachFrom(a),s.clearCopperControl();let c=this._getSrcRectByTransformState(o,a),l=this._drawingManagerService.getDrawingOKey(o.oKey);if(l!=null){let{left:e,top:t,height:n,width:r}=a;this._drawingManagerService.featurePluginUpdateNotification([{...l,transform:{...l.transform,left:e,top:t,height:n,width:r},srcRect:c.srcRectAngle}])}o.setSrcRect({...c.srcRectAngle}),o.closeRenderByCropper(),o.makeDirty(!0),a==null||a.dispose()}));let e=this._univerInstanceService.getCurrentTypeOfUnit$(p.UNIVER_SHEET).pipe(Te(e=>e?e.activeSheet$:we(null)));this.disposeWithMe(e.subscribe(()=>{this._commandService.syncExecuteCommand(J.id)}))}_getApplyObjectByCropObject(e){let t=e.oKey,n=t.slice(0,t.length-5),r=e.getScene();if(!r)return null;let i=r.getObject(n);return i==null?null:i}_addListenerOnImage(e){let t=e.getTransformerByCreate(),n=null;this.disposeWithMe(t.changeStart$.subscribe(e=>{let{objects:r}=e,i=r.values().next().value;if(i==null||!(i instanceof Pt))return;let{left:a,top:o,height:s,width:c,angle:l}=i;n={left:a,top:o,height:s,width:c,angle:l},t.clearCopperControl()})),this.disposeWithMe(t.changeEnd$.subscribe(e=>{let{objects:r}=e,i=r.values().next().value;if(i==null||!(i instanceof Pt))return;let{left:a,top:o,height:s,width:c,angle:l}=i;if(!m({left:a,top:o,height:s,width:c,angle:l},n))return;let u=this._getApplyObjectByCropObject(i);if(u==null)return;let d=this._getSrcRectByTransformState(u,i);i.refreshSrcRect(d.srcRect,u.getState()),t.createControlForCopper(i)})),this._endCropListener(e)}_addHoverForImageCopper(e){this.disposeWithMe(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=w.MOVE})),this.disposeWithMe(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=w.DEFAULT}))}_endCropListener(e){let t=e.getTransformerByCreate();this.disposeWithMe(t.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(J.id)}))}_getSrcRectByTransformState(e,t){let{left:n,top:r,height:i,width:a,strokeWidth:o,angle:s}=t,{left:c,top:l,width:u,height:d,angle:f,strokeWidth:p}=e,m=n-c,h=r-l,g={left:m,top:h,right:u-m-a,bottom:d-h-i},_={...g};if(f!==0){let e=new P(n+a/2,r+i/2),t=new P(u/2+c,d/2+l),o=new P(c,l);o.rotateByPoint(ee(f),t);let s=o.clone();s.rotateByPoint(ee(-f),e);let p=n-s.x,m=r-s.y;_.left=p,_.top=m,_.right=u-p-a,_.bottom=d-m-i}return{srcRect:g,srcRectAngle:_}}};Ft=Z([X(0,i),X(1,y),X(2,k),X(3,s),X(4,ye),X(5,l(d))],Ft);let It=class{constructor(e,t,n,r,i){this._drawingManagerService=e,this._imageIoService=t,this._galleryService=n,this._urlImageService=r,this._univerInstanceService=i}async renderImages(e,t){let{transform:n,drawingType:i,source:a,imageSourceType:o,srcRect:s,prstGeom:c,groupId:l,unitId:u,subUnitId:d,drawingId:f,isMultiTransform:m,transforms:h}=e;if(i!==r.DRAWING_IMAGE||!this._drawingManagerService.getDrawingVisible()||this._univerInstanceService.getUnitType(u)===p.UNIVER_SHEET&&d!==this._getActiveSheetId()||n==null)return;let g=m&&h?h:[n],_=[];for(let e of g){let{left:n,top:r,width:i,height:p,angle:h,flipX:v,flipY:y,skewX:b,skewY:S}=e,w=g.indexOf(e),T=C({unitId:u,subUnitId:d,drawingId:f},m?w:void 0),D=t.getObject(T);if(D!=null){D.transformByState({left:n,top:r,width:i,height:p,angle:h,flipX:v,flipY:y,skewX:b,skewY:S});continue}let O=this._drawingManagerService.getDrawingOrder(u,d),k=O.indexOf(f),j={...e,zIndex:k===-1?O.length-1:k},M=this._imageIoService.getImageSourceCache(a,o),N=!1;if(M!=null)j.image=M;else if(o===x.UUID)try{j.url=await this._imageIoService.getImage(a)}catch(e){console.error(e);continue}else if(o===x.URL){try{j.url=await this._urlImageService.getImage(a)}catch(e){console.error(e),j.url=a}N=!0}else j.url=a,N=!0;if(t.getObject(T))continue;j.printable=!0;let P=new A(T,j);N&&this._imageIoService.addImageSourceCache(a,o,P.getNative()),t.addObject(P,E),this._drawingManagerService.getDrawingEditable()&&t.attachTransformerTo(P),l&&Xe({drawingId:l,unitId:u,subUnitId:d},P,t,this._drawingManagerService),c!=null&&P.setPrstGeom(c),s!=null&&P.setSrcRect(s),_.push(P)}return _}_getActiveSheetId(){var e;return(e=this._univerInstanceService.getCurrentUnitOfType(p.UNIVER_SHEET))==null||(e=e.getActiveSheet())==null?void 0:e.getSheetId()}renderFloatDom(e,t){let{transform:n,drawingType:i,groupId:a,unitId:o,subUnitId:s,drawingId:c,isMultiTransform:l,transforms:u}=e;if(i!==r.DRAWING_DOM||!this._drawingManagerService.getDrawingVisible()||n==null)return;let d=l&&u?u:[n],f=[];for(let n of d){let{left:r,top:i,width:u,height:p,angle:m,flipX:h,flipY:g,skewX:_,skewY:v}=n,y=d.indexOf(n),b=C({unitId:o,subUnitId:s,drawingId:c},l?y:void 0),x=t.getObject(b);if(x!=null){x.transformByState({left:r,top:i,width:u,height:p,angle:m,flipX:h,flipY:g,skewX:_,skewY:v});continue}let S=this._drawingManagerService.getDrawingOrder(o,s),w=S.indexOf(c),T={...n,zIndex:w===-1?S.length-1:w};if(t.getObject(b))continue;T.printable=!1;let D=new M(b,T);this._drawingManagerService.getDrawingVisible()&&(t.addObject(D,E),this._drawingManagerService.getDrawingEditable()&&e.allowTransform!==!1&&t.attachTransformerTo(D),a&&Xe({drawingId:a,unitId:o,subUnitId:s},D,t,this._drawingManagerService),f.push(D))}return f}renderDrawing(e,t){let n=this._drawingManagerService.getDrawingByParam(e);if(n!=null)switch(n.drawingType){case r.DRAWING_IMAGE:return this.renderImages(n,t);default:}}previewImage(e,t,n,r){this._galleryService.open({images:[t],onOpenChange:e=>{e||this._galleryService.close()}})}_adjustImageSize(e,t,n,r){if(e<=n&&t<=r)return{width:e,height:t};let i=n/e,a=r/t,o=Math.min(i,a);return{width:Math.floor(e*o),height:Math.floor(t*o)}}};It=Z([X(0,y),X(1,b),X(2,_e),X(3,o),X(4,s)],It);let Lt=class extends n{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._drawingManagerService=n,this._dialogService=r,this._imageIoService=i,this._currentUniverService=a,this._drawingRenderService=o,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===Ye.id){let t=e.params;if(t==null)return;this._resetImageSize(t)}}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_resetImageSize(e){let t=[],n=[];e.forEach(e=>{let{unitId:i,subUnitId:a,drawingId:o}=e,s=this._getSceneAndTransformerByDrawingSearch(i);if(s==null)return;let{scene:c}=s,l=C({unitId:i,subUnitId:a,drawingId:o}),u=c.getObject(l);if(u==null)return!0;let d=this._drawingManagerService.getDrawingByParam(e);if(d==null)return!0;if(d.drawingType!==r.DRAWING_IMAGE)return;u.resetSize();let{width:f,height:p}=u.getNativeSize();n.includes(c)===!1&&n.push(c),t.push({...d,transform:{...d.transform,height:p,width:f,angle:0},srcRect:null,prstGeom:null})}),this._drawingManagerService.featurePluginUpdateNotification(t),n.forEach(e=>{e.getTransformerByCreate().refreshControls().changeNotification()}),this._commandService.syncExecuteCommand(S.id,e)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.pipe(xe(33),Se(e=>e.length>0),Ce(e=>e.flat()),Ce(e=>{let t=new Map;for(let n of e)t.set(`${n.unitId}|${n.subUnitId}|${n.drawingId}`,n);return[...t.values()]}),Se(e=>e.length>0)).subscribe(e=>{this._insertImages(e)}))}_insertImages(e){e.forEach(async e=>{var t;let{unitId:n,subUnitId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(n),a=(t=Ze(this._currentUniverService,n))==null?void 0:t.subUnitId;if(i==null||a!==r)return;let o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let s=await this._drawingRenderService.renderImages(o,i.scene);if(this._drawingManagerService.refreshTransform([o]),!(s==null||s.length===0))for(let e of s)this._addHoverForImage(e),this._addDialogForImage(e)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:i}=e,a=this._drawingManagerService.getDrawingByParam(e);if(a==null)return;let{transform:o,drawingType:s,srcRect:l,prstGeom:u,source:d,imageSourceType:f}=a;if(s!==r.DRAWING_IMAGE)return;let p=this._getSceneAndTransformerByDrawingSearch(t);if(p==null)return;let{scene:m,transformer:h}=p;if(o==null)return!0;let g=C({unitId:t,subUnitId:n,drawingId:i}),_=m.getObject(g);if(_==null)return!0;_.setSrcRect(l),_.setPrstGeom(u),d!=null&&d.length>0&&(f===c.BASE64||f===c.URL)&&_.changeSource(d)})}))}_addHoverForImage(e){this.disposeWithMe(v(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=w.GRAB}))),this.disposeWithMe(v(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=w.DEFAULT})))}_addDialogForImage(e){this.disposeWithMe(v(e.onDblclick$.subscribeEvent(()=>{let t=`${e.oKey}-viewer-dialog`;this._drawingRenderService.previewImage(t,e.getNative().src,e.getNativeSize().width,e.getNativeSize().height)})))}};Lt=Z([X(0,i),X(1,k),X(2,y),X(3,ge),X(4,b),X(5,s),X(6,l(It))],Lt);let $=class extends f{constructor(e=tt,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=_({},tt,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(et,i)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(Mt),this._injector.get(Dt),this._injector.get(Ft),this._injector.get(Lt)}_initDependencies(){[[It],[Mt],[Dt],[Ft],[Lt]].forEach(e=>this._injector.add(e))}};Q($,`pluginName`,`UNIVER_DRAWING_UI_PLUGIN`),Q($,`packageName`,Qe),Q($,`version`,$e),$=Z([X(1,l(u)),X(2,a)],$);const Rt=e=>{let t=I(i),n=I(d),{drawings:r,alignShow:a}=e,[o,s]=B(U.default),c=[{label:n.t(`image-panel.align.default`),value:U.default},{options:[{label:n.t(`image-panel.align.left`),value:U.left},{label:n.t(`image-panel.align.center`),value:U.center},{label:n.t(`image-panel.align.right`),value:U.right}]},{options:[{label:n.t(`image-panel.align.top`),value:U.top},{label:n.t(`image-panel.align.middle`),value:U.middle},{label:n.t(`image-panel.align.bottom`),value:U.bottom}]},{options:[{label:n.t(`image-panel.align.horizon`),value:U.horizon},{label:n.t(`image-panel.align.vertical`),value:U.vertical}]}];function l(e){s(e),t.executeCommand(W.id,{alignType:e,drawings:r})}return H(`div`,{className:z(`univer-relative univer-w-full`,{"univer-hidden":!a}),children:[V(`header`,{className:`
|
|
9
|
-
univer-text-gray-600
|
|
10
|
-
dark:!univer-text-gray-200
|
|
11
|
-
`,children:V(`div`,{children:n.t(`image-panel.align.title`)})}),V(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:V(`div`,{className:`
|
|
12
|
-
univer-w-full univer-text-gray-900
|
|
13
|
-
dark:!univer-text-white
|
|
14
|
-
`,children:V(ke,{value:o,options:c,onChange:l})})})]})},zt=t=>{let{arrangeShow:n,drawings:r}=t,a=I(d),o=I(y),s=I(i),c=I(pe),l=c.get(`MoveUpIcon`),u=c.get(`MoveDownIcon`),f=c.get(`TopmostIcon`),p=c.get(`BottomIcon`),[m,h]=B(r);je(()=>{let e=o.focus$.subscribe(e=>{h(e)});return()=>{e.unsubscribe()}},[]);let g=e=>{s.syncExecuteCommand(G.id,{arrangeType:e,drawings:m})};return H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!n}),children:[V(`header`,{className:`
|
|
15
|
-
univer-text-gray-600
|
|
16
|
-
dark:!univer-text-gray-200
|
|
17
|
-
`,children:V(`div`,{children:a.t(`image-panel.arrange.title`)})}),H(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:[H(L,{onClick:()=>{g(e.forward)},children:[V(l,{}),a.t(`image-panel.arrange.forward`)]}),H(L,{onClick:()=>{g(e.backward)},children:[V(u,{}),a.t(`image-panel.arrange.backward`)]}),H(L,{onClick:()=>{g(e.front)},children:[V(f,{}),a.t(`image-panel.arrange.front`)]}),H(L,{onClick:()=>{g(e.back)},children:[V(p,{}),a.t(`image-panel.arrange.back`)]})]})]})},Bt=e=>{let t=I(d),n=I(k),a=I(y),o=I(i),s=I(pe),{hasGroup:c,drawings:l}=e,u=s.get(`GroupIcon`),f=s.get(`UngroupIcon`),[p,m]=B(!1),[h,g]=B(!0),[_,v]=B(!0),b=()=>{o.syncExecuteCommand(K.id,{drawings:l})},x=()=>{o.syncExecuteCommand(q.id,{drawings:l})};return je(()=>{let e=l[0];if(e==null)return;let{unitId:t}=e,i=n.getRenderById(t),o=i==null?void 0:i.scene;if(o==null)return;let s=o.getTransformerByCreate(),c=s.clearControl$.subscribe(e=>{e===!0&&m(!1)}),u=s.changeStart$.subscribe(e=>{let{objects:t}=e,n=Ot(t,a),i=n.filter(e=>(e==null?void 0:e.drawingType)===r.DRAWING_GROUP),o=!1,s=!1;n.length>1&&(o=!0),i.length>0&&(s=!0),m(o||s),g(o),v(s)});return()=>{u.unsubscribe(),c.unsubscribe()}},[]),H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":c===!0&&p===!1||c===!1}),children:[V(`header`,{className:`
|
|
18
|
-
univer-text-gray-600
|
|
19
|
-
dark:!univer-text-gray-200
|
|
20
|
-
`,children:V(`div`,{children:t.t(`image-panel.group.title`)})}),H(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[H(L,{className:z({"univer-hidden":!h}),onClick:b,children:[V(u,{}),t.t(`image-panel.group.group`)]}),H(L,{className:z({"univer-hidden":!_}),onClick:x,children:[V(f,{}),t.t(`image-panel.group.unGroup`)]})]})]})},Vt=[-360,360],Ht=e=>{var t;let n=I(d),r=I(y),i=I(k),{drawings:a,transformShow:o}=e,s=a[0];if(s==null)return;let c=s.transform;if(c==null)return;let{unitId:l,subUnitId:u,drawingId:f,drawingType:p}=s,m=i.getRenderById(l),g=m==null?void 0:m.scene;if(g==null)return;let _=(t=g.getEngine())==null?void 0:t.activeScene;if(_==null)return;let v=g.getTransformerByCreate(),{width:b=0,height:x=0,left:S=0,top:C=0,angle:w=0}=c,[T,E]=B(b),[D,O]=B(x),[A,j]=B(S),[M,N]=B(C),[P,ee]=B(w),[te,ne]=B(v.keepRatio),re=(e,t,n,r)=>{let{width:i,height:a}=_,{ancestorLeft:o,ancestorTop:s}=g,c=e,l=t,u=n,d=r;return e+o<0&&(c=-o),t+s<0&&(l=-s),u=i-c-o,u<20&&(u=20),d=a-l-s,d<20&&(d=20),e+u+o>i&&(c=i-n-o),t+d+s>a&&(l=a-r-s),{limitLeft:c,limitTop:l,limitWidth:u,limitHeight:d}},ie=e=>{let{objects:t}=e,n=Ot(t,r);if(n.length!==1)return;let i=n[0];if(i==null)return;let{transform:a}=i;if(a==null)return;let{width:o,height:s,left:c,top:l,angle:u}=a;o!=null&&E(o),s!=null&&O(s),c!=null&&j(c),l!=null&&N(l),u!=null&&ee(u)};je(()=>{let e=[v.changeStart$.subscribe(e=>{ie(e)}),v.changing$.subscribe(e=>{ie(e)}),v.changeEnd$.subscribe(e=>{ie(e)}),r.focus$.subscribe(e=>{if(e.length!==1)return;let t=r.getDrawingByParam(e[0]);if(t==null)return;let n=t.transform;if(n==null)return;let{width:i,height:a,left:o,top:s,angle:c}=n;i!=null&&E(i),a!=null&&O(a),o!=null&&j(o),s!=null&&N(s),c!=null&&ee(c)})];return()=>{e.forEach(e=>e.unsubscribe())}},[]);let ae=h(e=>{if(e==null)return;let{limitWidth:t,limitHeight:n}=re(A,M,e,D);e=Math.min(e,t);let i={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{width:e}};if(te){let t=e/T*D;if(t=Math.max(t,20),t>n)return;O(t),i.transform.height=t}E(e),r.featurePluginUpdateNotification([i]),v.refreshControls().changeNotification()},300),oe=h(e=>{if(e==null)return;let{limitHeight:t,limitWidth:n}=re(A,M,T,e);e=Math.min(e,t);let i={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{height:e}};if(te){let t=e/D*T;if(t=Math.max(t,20),t>n)return;E(t),i.transform.width=t}O(e),r.featurePluginUpdateNotification([i]),v.refreshControls().changeNotification()},300),se=h(e=>{if(e==null)return;let{limitLeft:t}=re(e,M,T,D);e=t;let n={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{left:e}};j(e),r.featurePluginUpdateNotification([n]),v.refreshControls().changeNotification()},300),ce=h(e=>{if(e==null)return;let{limitTop:t}=re(A,e,T,D);e=t;let n={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{top:e}};N(e),r.featurePluginUpdateNotification([n]),v.refreshControls().changeNotification()},300),le=e=>{if(e==null)return;let t={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{angle:e}};ee(e),r.featurePluginUpdateNotification([t]),v.refreshControls().changeNotification()},ue=e=>{ne(e),v.keepRatio=e};return H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!o}),children:[V(`header`,{className:`
|
|
21
|
-
univer-text-gray-600
|
|
22
|
-
dark:!univer-text-gray-200
|
|
23
|
-
`,children:V(`div`,{children:n.t(`image-panel.transform.title`)})}),H(`div`,{className:`
|
|
24
|
-
univer-grid univer-grid-cols-3 univer-gap-2
|
|
25
|
-
[&>div]:univer-grid [&>div]:univer-gap-2
|
|
26
|
-
`,children:[H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.width`)}),V(R,{precision:1,value:T,min:20,onChange:e=>{ae(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.height`)}),V(R,{precision:1,value:D,min:20,onChange:e=>{oe(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.lock`)}),V(`div`,{className:`univer-text-center`,children:V(Ee,{checked:te,onChange:ue})})]})]}),H(`div`,{className:`
|
|
27
|
-
univer-grid univer-grid-cols-3 univer-gap-2
|
|
28
|
-
[&>div]:univer-grid [&>div]:univer-gap-2
|
|
29
|
-
`,children:[H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.x`)}),V(R,{precision:1,value:A,onChange:e=>{se(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.y`)}),V(R,{precision:1,value:M,onChange:e=>{ce(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.rotate`)}),V(R,{precision:1,value:P,min:Vt[0],max:Vt[1],onChange:le})]})]})]})},Ut=e=>{let t=I(i),n=I(d),{drawings:r,cropperShow:a}=e;if(r[0]==null)return;let[o,s]=B(Y.FREE),c=Me(!1),l=[{label:n.t(`image-panel.crop.mode`),value:Y.FREE},{label:`1:1`,value:Y.R1_1},{label:`16:9`,value:Y.R16_9},{label:`9:16`,value:Y.R9_16},{label:`5:4`,value:Y.R5_4},{label:`4:5`,value:Y.R4_5},{label:`4:3`,value:Y.R4_3},{label:`3:4`,value:Y.R3_4},{label:`3:2`,value:Y.R3_2},{label:`2:3`,value:Y.R2_3}];je(()=>{let e=t.onCommandExecuted(e=>{if(e.id===J.id){let t=e.params;t!=null&&t.isAuto||(c.current=!1)}});return()=>{e==null||e.dispose()}},[]);function u(e){s(e),c.current&&t.executeCommand(Je.id,{cropType:e})}let f=e=>{t.executeCommand(Je.id,{cropType:e}),c.current=!0};return H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!a}),children:[V(`header`,{className:`
|
|
30
|
-
univer-text-gray-600
|
|
31
|
-
dark:!univer-text-gray-200
|
|
32
|
-
`,children:V(`div`,{children:n.t(`image-panel.crop.title`)})}),H(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[H(L,{onClick:()=>{f(o)},children:[V(oe,{}),n.t(`image-panel.crop.start`)]}),V(ke,{value:o,options:l,onChange:u})]})]})},Wt=e=>{let t=I(y),n=I(k),r=I(d),{drawings:i,hasArrange:a=!0,hasTransform:o=!0,hasAlign:s=!0,hasCropper:c=!0,hasGroup:l=!0}=e,u=i[0];if(u==null)return;let{unitId:f}=u,p=n.getRenderById(f),m=p==null?void 0:p.scene;if(m==null)return;let h=m.getTransformerByCreate(),[g,_]=B(!0),[v,b]=B(!0),[x,S]=B(!1),[C,w]=B(!0),[T,E]=B(!1);return je(()=>{let e=h.clearControl$.subscribe(e=>{e===!0&&(_(!1),b(!1),S(!1),w(!1),E(!0))}),n=h.changeStart$.subscribe(e=>{let{objects:n}=e,r=Ot(n,t);r.length===0?(_(!1),b(!1),S(!1),w(!1),E(!0)):r.length===1?(_(!0),b(!0),S(!1),w(!0),E(!1)):(_(!0),b(!1),S(!0),w(!1),E(!1))}),r=t.focus$.subscribe(e=>{e.length===0?(_(!1),b(!1),S(!1),w(!1),E(!0)):e.length===1?(_(!0),b(!0),S(!1),w(!0),E(!1)):(_(!0),b(!1),S(!0),w(!1),E(!1))});return()=>{n.unsubscribe(),e.unsubscribe(),r.unsubscribe()}},[]),H(Ne,{children:[V(`div`,{className:z(`univer-h-full`,{"univer-hidden":!T}),children:V(`div`,{className:`univer-flex univer-h-full univer-items-center univer-justify-center`,children:V(`span`,{children:r.t(`image-panel.null`)})})}),V(zt,{arrangeShow:a===!0?g:!1,drawings:i}),V(Ht,{transformShow:o===!0?v:!1,drawings:i}),V(Rt,{alignShow:s===!0?x:!1,drawings:i}),V(Ut,{cropperShow:c===!0?C:!1,drawings:i}),V(Bt,{hasGroup:l,drawings:i})]})};export{Je as AutoImageCropOperation,Tt as COMPONENT_IMAGE_POPUP_MENU,q as CancelDrawingGroupOperation,J as CloseImageCropOperation,Ke as DRAWING_GROUP_TYPES,Wt as DrawingCommonPanel,It as DrawingRenderService,Pt as ImageCropperObject,Et as ImagePopupMenu,Ye as ImageResetSizeOperation,qe as OpenImageCropOperation,W as SetDrawingAlignOperation,G as SetDrawingArrangeOperation,K as SetDrawingGroupOperation,$ as UniverDrawingUIPlugin,Ze as getCurrentUnitInfo,Ot as getUpdateParams,Xe as insertGroupObject};
|
|
1
|
+
import{ArrangeTypeEnum as e,CommandType as t,Disposable as n,DrawingTypeEnum as r,ICommandService as i,IConfigService as a,IURLImageService as o,IUniverInstanceService as s,ImageSourceType as c,Inject as l,Injector as u,LocaleService as d,Plugin as f,UniverInstanceType as p,checkIfMove as m,debounce as h,generateRandomId as g,merge as _,toDisposable as v}from"@univerjs/core";import{IDrawingManagerService as y,IImageIoService as b,ImageSourceType as x,SetDrawingSelectedOperation as S,getDrawingShapeKeyByDrawingSearch as C}from"@univerjs/drawing";import{CURSOR_TYPE as w,Canvas as T,DRAWING_OBJECT_LAYER_INDEX as E,DrawingGroupObject as D,Group as O,IRenderManagerService as k,Image as A,RENDER_CLASS_TYPE as j,Rect as M,Shape as N,Vector2 as P,degToRad as ee,getGroupState as te,precisionTo as ne,transformObjectOutOfGroup as re}from"@univerjs/engine-render";import{AutofillDoubleIcon as ie,BottomIcon as ae,CreateCopyIcon as oe,GroupIcon as se,MoreDownIcon as ce,MoveDownIcon as le,MoveUpIcon as ue,TopmostIcon as de,UngroupIcon as fe}from"@univerjs/icons";import{ComponentManager as pe,ContextMenuGroup as me,ContextMenuPosition as he,IDialogService as ge,IGalleryService as _e,IMenuManagerService as ve,IMessageService as ye,MenuItemType as F,useDependency as I}from"@univerjs/ui";import{Observable as be,bufferTime as xe,filter as Se,map as Ce,of as we,switchMap as Te}from"rxjs";import{Button as L,Checkbox as Ee,DropdownMenu as De,InputNumber as R,MessageType as Oe,Select as ke,borderClassName as Ae,clsx as z}from"@univerjs/design";import{useEffect as je,useRef as Me,useState as B}from"react";import{Fragment as Ne,jsx as V,jsxs as H}from"react/jsx-runtime";let U=function(e){return e.default=`0`,e.left=`1`,e.center=`2`,e.right=`3`,e.top=`4`,e.middle=`5`,e.bottom=`6`,e.horizon=`7`,e.vertical=`8`,e}({});const W={id:`sheet.operation.set-image-align`,type:t.OPERATION,handler:(e,t)=>!0},Pe={id:`sheet.operation.set-drawing-align-left`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.left})},Fe={id:`sheet.operation.set-drawing-align-center`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.center})},Ie={id:`sheet.operation.set-drawing-align-right`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.right})},Le={id:`sheet.operation.set-drawing-align-top`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.top})},Re={id:`sheet.operation.set-drawing-align-middle`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.middle})},ze={id:`sheet.operation.set-drawing-align-bottom`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.bottom})},Be={id:`sheet.operation.set-drawing-align-horizon`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.horizon})},Ve={id:`sheet.operation.set-drawing-align-vertical`,type:t.OPERATION,handler:e=>e.get(i).syncExecuteCommand(W.id,{alignType:U.vertical})},G={id:`drawing.operation.set-drawing-arrange`,type:t.OPERATION,handler:(e,t)=>{let n=e.get(y),{arrangeType:r}=t,i=t.drawings||n.getFocusDrawings(),{unitId:a,subUnitId:o}=i[0],s=i.map(e=>e.drawingId);return n.featurePluginOrderUpdateNotification({unitId:a,subUnitId:o,drawingIds:s,arrangeType:r}),!0}},He={id:`drawing.operation.set-drawing-arrange-front`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.front})},Ue={id:`drawing.operation.set-drawing-arrange-forward`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.forward})},We={id:`drawing.operation.set-drawing-arrange-back`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.back})},Ge={id:`drawing.operation.set-drawing-arrange-backward`,type:t.OPERATION,handler:t=>t.get(i).syncExecuteCommand(G.id,{arrangeType:e.backward})},Ke=[r.DRAWING_IMAGE,r.DRAWING_SHAPE,r.DRAWING_GROUP],K={id:`drawing.operation.set-drawing-group`,type:t.OPERATION,handler:(e,t)=>{let n=e.get(y),i=t.drawings||n.getFocusDrawings();if(i.length<2||!i.every(e=>Ke.includes(e.drawingType)))return!1;let{unitId:a,subUnitId:o}=i[0],s=g(10),c=te(0,0,i.map(e=>e.transform||{})),l={unitId:a,subUnitId:o,drawingId:s,drawingType:r.DRAWING_GROUP,transform:c,groupBaseBound:{left:c.left,top:c.top,width:c.width,height:c.height}},u=i.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t},groupId:s}});return n.featurePluginGroupUpdateNotification([{parent:l,children:u}]),!0}},q={id:`drawing.operation.cancel-drawing-group`,type:t.OPERATION,handler:(e,t)=>{let n=e.get(y),i=(t.drawings||n.getFocusDrawings()).map(e=>{if(e.drawingType!==r.DRAWING_GROUP)return null;let{unitId:t,subUnitId:i,drawingId:a,transform:o={width:0,height:0},groupBaseBound:s}=e;if(o===null)return null;let c=n.getDrawingsByGroup({unitId:t,subUnitId:i,drawingId:a});return c.length===0?null:{parent:e,children:c.map(e=>{let{transform:t}=e,{unitId:n,subUnitId:r,drawingId:i}=e,a=re(t||{},o,o.width||0,o.height||0,s);return{unitId:n,subUnitId:r,drawingId:i,transform:{...t,...a},groupId:void 0}})}}).filter(e=>e!==null);return i.length===0?!1:(n.featurePluginUngroupUpdateNotification(i),!0)}},qe={id:`sheet.operation.open-image-crop`,type:t.OPERATION,handler:(e,t)=>!0},J={id:`sheet.operation.close-image-crop`,type:t.OPERATION,handler:(e,t)=>!0};let Y=function(e){return e.FREE=`0`,e.R1_1=`1`,e.R16_9=`2`,e.R9_16=`3`,e.R5_4=`4`,e.R4_5=`5`,e.R4_3=`6`,e.R3_4=`7`,e.R3_2=`8`,e.R2_3=`9`,e}({});const Je={id:`sheet.operation.Auto-image-crop`,type:t.OPERATION,handler:(e,t)=>!0},Ye={id:`sheet.operation.image-reset-size`,type:t.OPERATION,handler:(e,t)=>!0};function Xe(e,t,n,r){let i=r.getDrawingByParam(e);if(i==null)return;let a=C(e),o=n.getObjectIncludeInGroup(a);if(o&&!(o instanceof O))return;if(o!=null){let e=o.getObjects();for(let n of e)if(n.oKey===t.oKey)return;o.addObject(t);return}let s=new D(a);n.addObject(s,E).attachTransformerTo(s),s.addObject(t);let{transform:c,groupBaseBound:l}=i;l&&s.setBaseBound(l),i.groupId&&(s.isInGroup=!0,Xe({drawingId:i.groupId,unitId:e.unitId,subUnitId:e.subUnitId},s,n,r)),c&&s.transformByState({left:c.left,top:c.top,angle:c.angle,width:c.width,height:c.height})}function Ze(e,t){let n=t?e.getUnit(t):e.getFocusedUnit();if(n==null)return;let r=n.getUnitId(),i;if(n.type===p.UNIVER_SHEET){var a;i=(a=n.getActiveSheet())==null?void 0:a.getSheetId()}else (n.type===p.UNIVER_DOC||n.type===p.UNIVER_SLIDE)&&(i=r);return{unitId:r,subUnitId:i,current:n}}var Qe=`@univerjs/drawing-ui`,$e=`0.19.0`;const et=`drawing-ui.config`;Symbol(et);const tt={},nt=e=>{let t=e.get(y);return new be(e=>{let n=t=>{if(!t||t.length===0||t.length<2)return e.next(!0);e.next(!1)},r=t.focus$.subscribe(t=>{if(!t||t.length===0)return e.next(!0);n(t)});return n(t.getFocusDrawings()),()=>r.unsubscribe()})},rt=`contextMenu.drawing-align`;function it(e){return{id:rt,type:F.SUBITEMS,icon:`HorizontallyIcon`,title:`image-panel.align.title`,hidden$:nt(e)}}function at(){return{id:Pe.id,type:F.BUTTON,icon:`LeftJustifyingIcon`,title:`image-panel.align.left`}}function ot(){return{id:Fe.id,type:F.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.center`}}function st(){return{id:Ie.id,type:F.BUTTON,icon:`RightJustifyingIcon`,title:`image-panel.align.right`}}function ct(){return{id:Le.id,type:F.BUTTON,icon:`AlignTopIcon`,title:`image-panel.align.top`}}function lt(){return{id:Re.id,type:F.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.middle`}}function ut(){return{id:ze.id,type:F.BUTTON,icon:`AlignBottomIcon`,title:`image-panel.align.bottom`}}function dt(){return{id:Be.id,type:F.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.horizon`}}function ft(){return{id:Ve.id,type:F.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.vertical`}}const pt=`contextMenu.drawing-arrange`;function mt(){return{id:pt,type:F.SUBITEMS,icon:`TopmostIcon`,title:`image-panel.arrange.title`}}function ht(){return{id:He.id,type:F.BUTTON,icon:`TopmostIcon`,title:`image-panel.arrange.front`}}function gt(){return{id:Ue.id,type:F.BUTTON,icon:`MoveUpIcon`,title:`image-panel.arrange.forward`}}function _t(){return{id:We.id,type:F.BUTTON,icon:`BottomIcon`,title:`image-panel.arrange.back`}}function vt(){return{id:Ge.id,type:F.BUTTON,icon:`MoveDownIcon`,title:`image-panel.arrange.backward`}}const yt=(e,t)=>{let n=e.get(y);return new be(e=>{let i=n=>{if(!n||n.length===0)return e.next(!0);if(t===`group`){if(n.length<2||!n.every(e=>Ke.includes(e.drawingType)))return e.next(!0)}else if(t===`unGroup`){if(n.filter(e=>e.drawingType===r.DRAWING_GROUP).length===0)return e.next(!0)}else if(!n.every(e=>Ke.includes(e.drawingType)))return e.next(!0);e.next(!1)},a=n.focus$.subscribe(t=>{if(!t||t.length===0)return e.next(!0);i(t)});return i(n.getFocusDrawings()),()=>a.unsubscribe()})},bt=`contextMenu.drawing-group`;function xt(e){return{id:bt,type:F.SUBITEMS,icon:`GroupIcon`,title:`image-panel.group.title`,hidden$:yt(e)}}function St(e){return{id:K.id,type:F.BUTTON,icon:`GroupIcon`,title:`image-panel.group.group`,disabled$:yt(e,`group`)}}function Ct(e){return{id:q.id,type:F.BUTTON,icon:`UngroupIcon`,title:`image-panel.group.unGroup`,disabled$:yt(e,`unGroup`)}}const wt={[he.DRAWING]:{[me.OTHERS]:{[bt]:{order:1,menuItemFactory:xt,[K.id]:{order:0,menuItemFactory:St},[q.id]:{order:1,menuItemFactory:Ct}},[pt]:{order:2,menuItemFactory:mt,[He.id]:{order:0,menuItemFactory:ht},[Ue.id]:{order:1,menuItemFactory:gt},[We.id]:{order:2,menuItemFactory:_t},[Ge.id]:{order:3,menuItemFactory:vt}},[rt]:{order:3,menuItemFactory:it,[Pe.id]:{order:0,menuItemFactory:at},[Fe.id]:{order:1,menuItemFactory:ot},[Ie.id]:{order:2,menuItemFactory:st},[Le.id]:{order:3,menuItemFactory:ct},[Re.id]:{order:4,menuItemFactory:lt},[ze.id]:{order:5,menuItemFactory:ut},[Be.id]:{order:6,menuItemFactory:dt},[Ve.id]:{order:7,menuItemFactory:ft}}}}},Tt=`COMPONENT_IMAGE_POPUP_MENU`;function Et(e){var t;let{popup:n}=e,r=n==null||(t=n.extraProps)==null?void 0:t.menuItems;if(!r)return null;let a=I(i),o=I(d),[s,c]=B(!1),[l,u]=B(!1),f=()=>{u(!0)},p=()=>{u(!1)},m=e=>{c(e)},h=e=>{a.executeCommand(e.commandId,e.commandParams),c(!1)},g=s||l;return V(`div`,{onMouseEnter:f,onMouseLeave:p,children:V(De,{align:`start`,items:r.filter(e=>!e.disable).map(e=>({type:`item`,children:o.t(e.label),onSelect:()=>h(e)})),open:s,onOpenChange:m,children:H(`div`,{className:z(`univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800`,Ae,{"univer-bg-gray-100 dark:!univer-bg-gray-800":s,"univer-bg-white dark:!univer-bg-gray-900":!s}),children:[V(ie,{className:`univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white`}),g&&V(ce,{className:`dark:!univer-text-white`})]})})})}function X(e,t){return function(n,r){t(n,r,e)}}function Z(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let Dt=class extends n{constructor(e,t,n){super(),this._componentManager=e,this._commandService=t,this._menuManagerService=n,this._init()}_init(){this._initMenus(),this._initCommands(),this._initComponents()}_initMenus(){this._menuManagerService.mergeMenu(wt)}_initCommands(){[qe,J,Ye,W,Pe,Fe,Ie,Le,Re,ze,Be,Ve,Je,K,q,G,He,Ue,We,Ge].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initComponents(){[[Tt,Et],[`BottomIcon`,ae],[`GroupIcon`,se],[`MoveDownIcon`,le],[`MoveUpIcon`,ue],[`TopmostIcon`,de],[`UngroupIcon`,fe]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};Dt=Z([X(0,l(pe)),X(1,i),X(2,ve)],Dt);function Ot(e,t){let n=[];return e.forEach(e=>{let{oKey:i,left:a,top:o,height:s,width:c,angle:l}=e,u=t.getDrawingOKey(i);if(u==null)return n.push(null),!0;let{unitId:d,subUnitId:f,drawingId:p,drawingType:m}=u,h={unitId:d,subUnitId:f,drawingId:p,drawingType:m,transform:{left:a,top:o,height:s,width:c,angle:l}};m===r.DRAWING_IMAGE&&(h.srcRect=e.srcRect),n.push(h)}),n}function kt(e){"@babel/helpers - typeof";return kt=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},kt(e)}function At(e,t){if(kt(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(kt(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function jt(e){var t=At(e,`string`);return kt(t)==`symbol`?t:t+``}function Q(e,t,n){return(t=jt(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let Mt=class extends n{constructor(e,t,n,r){super(),this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._drawingManagerService=r,Q(this,`_sceneListenerOnDrawingMap`,new WeakSet),this._initialize()}dispose(){super.dispose()}_initialize(){this._recoveryImages(),this._drawingAddListener(),this._drawingRemoveListener(),this._drawingUpdateListener(),this._commandExecutedListener(),this._drawingArrangeListener(),this._drawingGroupListener(),this._drawingRefreshListener(),this._drawingVisibleListener()}_recoveryImages(){let e=this._drawingManagerService.drawingManagerData,t=Ze(this._currentUniverService);if(t==null)return;let{unitId:n,subUnitId:r}=t;Object.keys(e).forEach(t=>{Object.keys(e[t]).forEach(i=>{let a=e[t][i].data;a==null||t!==n||i!==r||Object.keys(a).forEach(e=>{a[e]&&this._insertDrawing([{unitId:t,subUnitId:i,drawingId:e}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===W.id){let t=e.params;if(t==null)return;this._drawingAlign(t)}}))}_drawingGroupListener(){this.disposeWithMe(this._drawingManagerService.group$.subscribe(e=>{this._groupDrawings(e)})),this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe(e=>{this._ungroupDrawings(e)}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_groupDrawings(e){e.forEach(e=>{this._groupDrawing(e)})}_groupDrawing(e){let{parent:t,children:n}=e,{unitId:r,subUnitId:i,drawingId:a}=t,o=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(o==null)return;let{scene:s,transformer:c}=o;this._commandService.syncExecuteCommand(J.id);let l=[];if(n.forEach(e=>{let t=C(e),n=s.getObjectIncludeInGroup(t);if(n==null||l.includes(n))return;l.push(n);let{transform:r}=e;r!=null&&(n.classType===j.GROUP?n.transformByState({left:r.left,top:r.top}):n.transformByState(r))}),l.length===0)return;let u=new D(C({unitId:r,subUnitId:i,drawingId:a}));s.addObject(u,E).attachTransformerTo(u),u.addObjects(...l),t.groupBaseBound&&u.setBaseBound(t.groupBaseBound),t.groupId&&(u.isInGroup=!0,Xe({drawingId:t.groupId,unitId:r,subUnitId:i},u,s,this._drawingManagerService)),t.transform&&u.transformByState({left:t.transform.left,top:t.transform.top,width:t.transform.width,height:t.transform.height,angle:t.transform.angle}),c.clearSelectedObjects(),c.setSelectedControl(u)}_ungroupDrawings(e){e.forEach(e=>{this._ungroupDrawing(e)})}_ungroupDrawing(e){let{parent:t,children:n}=e,r=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(r==null)return;let{scene:i,transformer:a}=r;n.forEach(e=>{let t=C(e),n=i.getObjectIncludeInGroup(t);if(n==null)return!0;if(n==null)return;let{transform:r}=e;r!=null&&(n.classType===j.GROUP?n.transformByState({left:r.left,top:r.top}):n.transformByState(r))});let o=C(t),s=i.getObject(o),{width:c,height:l}=s;s.getObjects().forEach(e=>{s.removeSelfObjectAndTransform(e.oKey,c,l)}),s.dispose(),a.clearSelectedObjects()}_drawingAlign(e){let{alignType:t}=e,n=e.drawings||this._drawingManagerService.getFocusDrawings();if(t===U.default)return;let r=[],i=1/0,a=1/0,o=-1/0,s=-1/0,c=0;n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:l,drawingType:u}=e,d=this._drawingManagerService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:l});if(d==null||d.transform==null)return;r.push({unitId:t,subUnitId:n,drawingId:l,drawingType:u,transform:d.transform});let{left:f=0,top:p=0,width:m=0,height:h=0}=d.transform;i=Math.min(i,f),a=Math.min(a,p),o=Math.max(o,f+m),s=Math.max(s,p+h),c++}),c!==0&&(this._sortDrawingTransform(r,t),this._applyAlignType(r,t,i,a,o,s,c))}_applyAlignType(e,t,n,r,i,a,o){let s=Math.round((i-n)/o*10)/10,c=Math.round((a-r)/o*10)/10,l=[],u=this._getSceneAndTransformerByDrawingSearch(e[0].unitId);if(u==null)return;let{scene:d,transformer:f}=u;e.forEach((e,o)=>{let{unitId:u,subUnitId:d,drawingId:f,transform:p,drawingType:m}=e,{left:h=0,top:g=0,width:_=0,height:v=0}=p,y=h,b=g;switch(t){case U.left:y=n;break;case U.center:y=n+(i-n)/2-_/2;break;case U.right:y=i-_;break;case U.top:b=r;break;case U.middle:b=r+(a-r)/2-v/2;break;case U.bottom:b=a-v;break;case U.horizon:y=n+s*o;break;case U.vertical:b=r+c*o;break;default:break}(y!==h||b!==g)&&l.push({unitId:u,subUnitId:d,drawingId:f,drawingType:m,transform:{left:y,top:b}})}),this._drawingManagerService.featurePluginUpdateNotification(l),f.refreshControls().changeNotification()}_sortDrawingTransform(e,t){e.sort((e,n)=>{let r=e.transform,i=n.transform,{left:a=0,top:o=0,width:s=0,height:c=0}=r,{left:l=0,top:u=0,width:d=0,height:f=0}=i;switch(t){case U.left:return a-l;case U.center:return a+s/2-(l+d/2);case U.right:return a+s-(l+d);case U.top:return o-u;case U.middle:return o+c/2-(u+f/2);case U.bottom:return o+c-(u+f);case U.horizon:return a+s/2-(l+d/2);case U.vertical:return o+c/2-(u+f/2);default:return 0}})}_drawingArrangeListener(){this.disposeWithMe(this._drawingManagerService.order$.subscribe(e=>{this._drawingArrange(e)}))}_drawingArrange(e){let{unitId:t,subUnitId:n,drawingIds:r}=e,i=this._getSceneAndTransformerByDrawingSearch(t);if(i==null)return;let{scene:a}=i;r.forEach(e=>{let r=C({unitId:t,subUnitId:n,drawingId:e}),i=a.fuzzyMathObjects(r,!0);if(i==null||i.length===0)return;let o=this._drawingManagerService.getDrawingOrder(t,n).indexOf(e);for(let e of i)e.setProps({zIndex:o}),e.makeDirty()})}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{this._insertDrawing(e)}))}_insertDrawing(e){let t=[];e.forEach(e=>{let{unitId:n}=e;if(this._drawingManagerService.getDrawingByParam(e)==null)return;let r=this._getSceneAndTransformerByDrawingSearch(n);if(r==null)return;let{scene:i}=r;t.includes(i)||t.push(i)}),t.forEach(e=>{this._sceneListenerOnDrawingMap.has(e)||(this._addListenerOnDrawing(e),this._sceneListenerOnDrawingMap.add(e))})}_drawingRemoveListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(t);if(i==null)return;let{scene:a}=i,o=C({unitId:t,subUnitId:n,drawingId:r}),s=a.fuzzyMathObjects(o,!0);if(s.length>0){var c;for(let e of s)e.dispose();(c=a.getTransformer())==null||c.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{var t;let{unitId:n,subUnitId:r,drawingId:i}=e,a=this._drawingManagerService.getDrawingByParam(e);if(a==null)return;let{transform:o,drawingType:s}=a,c=this._getSceneAndTransformerByDrawingSearch(n);if(c==null)return;let{scene:l,transformer:u}=c;if(o==null)return!0;let{left:d=0,top:f=0,width:p=0,height:m=0,angle:h=0,flipX:g=!1,flipY:_=!1,skewX:v=0,skewY:y=0}=o,b=C({unitId:n,subUnitId:r,drawingId:i}),x=l.getObject(b);if(x==null)return!0;x.transformByState({left:d,top:f,width:p,height:m,angle:h,flipX:g,flipY:_,skewX:v,skewY:y}),(t=l.getTransformer())==null||t.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(t);if(i==null)return;let a=this._drawingManagerService.getDrawingByParam(e);if(a==null)return;let{transform:o}=a,{scene:s}=i,c=C({unitId:t,subUnitId:n,drawingId:r}),l=s.getObject(c);if(l==null||o==null)return!0;let{left:u=0,top:d=0,width:f=0,height:p=0,angle:m=0,flipX:h=!1,flipY:g=!1,skewX:_=0,skewY:v=0}=o;l.transformByState({left:u,top:d,width:f,height:p,angle:m,flipX:h,flipY:g,skewX:_,skewY:v})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:r,visible:i}=e,a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{scene:o}=a,s=C({unitId:t,subUnitId:n,drawingId:r}),c=o.getObject(s);if(c==null)return!0;i?c.show():c.hide()})}))}_filterUpdateParams(e,t){return e.filter((e,n)=>{if(e==null)return!1;let{transform:r}=e;return m(r,t==null?void 0:t[n])})}_addListenerOnDrawing(e){let t=e.getTransformerByCreate(),n=null;this.disposeWithMe(v(t.changeStart$.subscribe(e=>{let{objects:t}=e,r=Array.from(t.values()),i=[];n=r.map(e=>{let{left:t,top:n,height:r,width:a,angle:o,oKey:s,isInGroup:c}=e,l=this._drawingManagerService.getDrawingOKey(s);if(c||e instanceof O){let t=e.ancestorGroup;if(t==null&&e instanceof O&&(t=e),t==null)return null;let n=this._drawingManagerService.getDrawingOKey(t.oKey);if(n){let{unitId:e,subUnitId:r,drawingId:a}=n;i.push({unitId:e,subUnitId:r,drawingId:a});let{left:o,top:s,height:c,width:l,angle:u}=t;return{left:o,top:s,height:c,width:l,angle:u}}}else if(l!=null){let{unitId:e,subUnitId:s,drawingId:c}=l;return i.push({unitId:e,subUnitId:s,drawingId:c}),{left:t,top:n,height:r,width:a,angle:o}}return null}).filter(e=>e!=null),i.length>0?this._commandService.syncExecuteCommand(S.id,i):this._commandService.syncExecuteCommand(S.id,[])}))),this.disposeWithMe(v(t.changeEnd$.subscribe(e=>{let{objects:t}=e,r=this._filterUpdateParams(Ot(t,this._drawingManagerService),n);r.length>0&&this._drawingManagerService.featurePluginUpdateNotification(r)})))}};Mt=Z([X(0,s),X(1,i),X(2,k),X(3,y)],Mt);var Nt=function(e){return e[e.RECT=0]=`RECT`,e[e.PATH=1]=`PATH`,e}(Nt||{}),Pt=class extends N{constructor(e,t){t==null&&(t={}),t.transformerConfig={keepRatio:!1,isCropper:!0,anchorFill:`rgb(0, 0, 0)`,anchorStroke:`rgb(255, 255, 255)`,anchorSize:24},super(e,t),Q(this,`_srcRect`,void 0),Q(this,`_prstGeom`,void 0),Q(this,`_applyTransform`,void 0),Q(this,`_dragPadding`,8),Q(this,`_cacheCanvas`,void 0),t!=null&&t.srcRect&&(this._srcRect=t.srcRect),t!=null&&t.prstGeom&&(this._prstGeom=t.prstGeom),t!=null&&t.applyTransform&&(this._applyTransform=t.applyTransform),t!=null&&t.dragPadding&&(this._dragPadding=t.dragPadding),this._applyProps()}refreshSrcRect(e,t){this._srcRect=e,this._applyTransform=t,this._applyProps()}get srcRect(){return this._srcRect}dispose(){var e;super.dispose(),(e=this._cacheCanvas)==null||e.dispose(),this._srcRect=null}isHit(e){let t=this.getInverseCoord(e);return t.x>=-this.strokeWidth/2&&t.x<=this.width+this.strokeWidth/2&&t.y>=-this.strokeWidth/2&&t.y<=this.height+this.strokeWidth/2&&!this._inSurround(t)}_inSurround(e){let t=this._dragPadding;return e.x>=t-this.strokeWidth/2&&e.x<=this.width+this.strokeWidth/2-t&&e.y>=t-this.strokeWidth/2&&e.y<=this.height+this.strokeWidth/2-t}render(e,t){return this.visible?(e.save(),this._draw(e),e.restore(),this.makeDirty(!1),this):(this.makeDirty(!1),this)}_draw(e){var t,n;let{width:r,height:i}=this.getScene().getEngine();this._initialCacheCanvas(),(t=this._cacheCanvas)==null||t.clear();let a=(n=this._cacheCanvas)==null?void 0:n.getContext();a!=null&&(a.save(),M.drawWith(a,{left:0,top:0,width:r,height:i,fill:`rgba(0, 0, 0, 0.5)`}),a.setTransform(e.getTransform()),this._clipForApplyObject(a),this._applyCache(e),a.restore())}_clipForApplyObject(e){let t=Nt.RECT;if(this._prstGeom!=null&&(t=Nt.PATH),e.globalCompositeOperation=`destination-out`,e.beginPath(),t===Nt.RECT){let t=this.transform.getMatrix();e.transform(t[0],t[1],t[2],t[3],t[4],t[5]),e.rect(0,0,this.width,this.height),e.fill()}}_applyProps(){if(this._applyTransform==null)return;let e=0,t=0,n=0,r=0,{left:i=0,top:a=0,width:o=0,height:s=0,angle:c}=this._applyTransform;if(this._srcRect!=null){let{left:i=0,top:a=0,right:o=0,bottom:s=0}=this._srcRect;e=i,t=a,n=o,r=s}let l=i+e,u=a+t;this.transformByState({left:l,top:u,width:i+o-n-l,height:a+s-r-u,angle:c})}_applyCache(e){if(!e||this._cacheCanvas==null)return;let t=this._cacheCanvas.getContext();t.save(),e.save(),e.setTransform(1,0,0,1,0,0),t.setTransform(1,0,0,1,0,0),e.drawImage(this._cacheCanvas.getCanvasEle(),0,0),e.restore(),t.restore()}_initialCacheCanvas(){if(this._cacheCanvas!=null)return;let e=this.getScene();if(e==null)return;this._cacheCanvas=new T;let t=e.getEngine();this._cacheCanvas.setSize(t.width,t.height),t.onTransformChange$.subscribeEvent(()=>{var e;(e=this._cacheCanvas)==null||e.setSize(t.width,t.height),this.makeDirty(!0)})}};let Ft=class extends n{constructor(e,t,n,r,i,a){super(),this._commandService=e,this._drawingManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._messageService=i,this._localeService=a,Q(this,`_sceneListenerOnImageMap`,new WeakSet),this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==Je.id)return;let t=e.params;if(t==null)return;let{cropType:n}=t,r=this._drawingManagerService.getFocusDrawings();if(r.length!==1)return;let{unitId:i,subUnitId:a,drawingId:o}=r[0],s=this._renderManagerService.getRenderById(i),c=s==null?void 0:s.scene;if(c==null)return!0;this._searchCropObject(c)!=null&&this._commandService.syncExecuteCommand(J.id,{isAuto:!0});let l=C({unitId:i,subUnitId:a,drawingId:o}),u=c.getObject(l);if(!(u instanceof A)){this._messageService.show({type:Oe.Error,content:this._localeService.t(`image-cropper.error`)});return}u!=null&&(this._updateCropperObject(n,u),this._commandService.executeCommand(qe.id,{unitId:i,subUnitId:a,drawingId:o}))}))}_calculateSrcRectByRatio(e,t,n,r,i,a){let o=n/r,s=i/a,c=n,l=r;o>s?c=r*s:l=n/s;let u=(n-c)/2,d=(r-l)/2;return{left:ne(u,1),top:ne(d,1),right:ne(n-(u+c),1),bottom:ne(r-(d+l),1)}}_updateCropperObject(e,t){let{left:n,top:r,width:i,height:a}=t.calculateTransformWithSrcRect(),o;switch(e){case Y.R1_1:o=this._calculateSrcRectByRatio(n,r,i,a,1,1);break;case Y.R16_9:o=this._calculateSrcRectByRatio(n,r,i,a,16,9);break;case Y.R9_16:o=this._calculateSrcRectByRatio(n,r,i,a,9,16);break;case Y.R5_4:o=this._calculateSrcRectByRatio(n,r,i,a,5,4);break;case Y.R4_5:o=this._calculateSrcRectByRatio(n,r,i,a,4,5);break;case Y.R4_3:o=this._calculateSrcRectByRatio(n,r,i,a,4,3);break;case Y.R3_4:o=this._calculateSrcRectByRatio(n,r,i,a,3,4);break;case Y.R3_2:o=this._calculateSrcRectByRatio(n,r,i,a,3,2);break;case Y.R2_3:o=this._calculateSrcRectByRatio(n,r,i,a,2,3);break;case Y.FREE:default:break}if(o==null)return;t.setSrcRect(o);let{left:s=0,top:c=0,bottom:l=0,right:u=0}=o;t.transformByStateCloseCropper({left:n+s,top:r+c,width:i-u-s,height:a-l-c})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==qe.id)return;let t=e.params;if(t==null)return;let{unitId:n,subUnitId:r,drawingId:i}=t,a=this._renderManagerService.getRenderById(n),o=a==null?void 0:a.scene;if(o==null)return!0;if(this._sceneListenerOnImageMap.has(o)||(this._addListenerOnImage(o),this._sceneListenerOnImageMap.add(o)),this._drawingManagerService.getDrawingByParam({unitId:n,subUnitId:r,drawingId:i})==null)return;let s=C({unitId:n,subUnitId:r,drawingId:i}),c=o.getObject(s);if(c==null)return;if(!(c instanceof A)){this._messageService.show({type:Oe.Error,content:this._localeService.t(`image-cropper.error`)});return}let l=o.getTransformer();l==null||l.clearControls();let u=new Pt(`${s}-crop`,{srcRect:c.srcRect,prstGeom:c.prstGeom,applyTransform:c.calculateTransformWithSrcRect()});o.addObject(u,c.getLayerIndex()+1).attachTransformerTo(u),l==null||l.createControlForCopper(u),this._addHoverForImageCopper(u),c.openRenderByCropper(),l==null||l.refreshControls(),u.makeDirty(!0),this._commandService.syncExecuteCommand(S.id,[{unitId:n,subUnitId:r,drawingId:i}])}))}_searchCropObject(e){let t=e.getAllObjectsByOrder();for(let e of t)if(e instanceof Pt)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==J.id)return;let t=this._univerInstanceService.getFocusedUnit();if(t==null)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n),i=r==null?void 0:r.scene;if(i==null)return!0;let a=this._searchCropObject(i);if(a==null)return;let o=this._getApplyObjectByCropObject(a);if(o==null)return;let s=i.getTransformerByCreate();s.detachFrom(a),s.clearCopperControl();let c=this._getSrcRectByTransformState(o,a),l=this._drawingManagerService.getDrawingOKey(o.oKey);if(l!=null){let{left:e,top:t,height:n,width:r}=a;this._drawingManagerService.featurePluginUpdateNotification([{...l,transform:{...l.transform,left:e,top:t,height:n,width:r},srcRect:c.srcRectAngle}])}o.setSrcRect({...c.srcRectAngle}),o.closeRenderByCropper(),o.makeDirty(!0),a==null||a.dispose()}));let e=this._univerInstanceService.getCurrentTypeOfUnit$(p.UNIVER_SHEET).pipe(Te(e=>e?e.activeSheet$:we(null)));this.disposeWithMe(e.subscribe(()=>{this._commandService.syncExecuteCommand(J.id)}))}_getApplyObjectByCropObject(e){let t=e.oKey,n=t.slice(0,t.length-5),r=e.getScene();if(!r)return null;let i=r.getObject(n);return i==null?null:i}_addListenerOnImage(e){let t=e.getTransformerByCreate(),n=null;this.disposeWithMe(t.changeStart$.subscribe(e=>{let{objects:r}=e,i=r.values().next().value;if(i==null||!(i instanceof Pt))return;let{left:a,top:o,height:s,width:c,angle:l}=i;n={left:a,top:o,height:s,width:c,angle:l},t.clearCopperControl()})),this.disposeWithMe(t.changeEnd$.subscribe(e=>{let{objects:r}=e,i=r.values().next().value;if(i==null||!(i instanceof Pt))return;let{left:a,top:o,height:s,width:c,angle:l}=i;if(!m({left:a,top:o,height:s,width:c,angle:l},n))return;let u=this._getApplyObjectByCropObject(i);if(u==null)return;let d=this._getSrcRectByTransformState(u,i);i.refreshSrcRect(d.srcRect,u.getState()),t.createControlForCopper(i)})),this._endCropListener(e)}_addHoverForImageCopper(e){this.disposeWithMe(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=w.MOVE})),this.disposeWithMe(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=w.DEFAULT}))}_endCropListener(e){let t=e.getTransformerByCreate();this.disposeWithMe(t.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(J.id)}))}_getSrcRectByTransformState(e,t){let{left:n,top:r,height:i,width:a,strokeWidth:o,angle:s}=t,{left:c,top:l,width:u,height:d,angle:f,strokeWidth:p}=e,m=n-c,h=r-l,g={left:m,top:h,right:u-m-a,bottom:d-h-i},_={...g};if(f!==0){let e=new P(n+a/2,r+i/2),t=new P(u/2+c,d/2+l),o=new P(c,l);o.rotateByPoint(ee(f),t);let s=o.clone();s.rotateByPoint(ee(-f),e);let p=n-s.x,m=r-s.y;_.left=p,_.top=m,_.right=u-p-a,_.bottom=d-m-i}return{srcRect:g,srcRectAngle:_}}};Ft=Z([X(0,i),X(1,y),X(2,k),X(3,s),X(4,ye),X(5,l(d))],Ft);let It=class{constructor(e,t,n,r,i){this._drawingManagerService=e,this._imageIoService=t,this._galleryService=n,this._urlImageService=r,this._univerInstanceService=i}async renderImages(e,t){let{transform:n,drawingType:i,source:a,imageSourceType:o,srcRect:s,prstGeom:c,groupId:l,unitId:u,subUnitId:d,drawingId:f,isMultiTransform:m,transforms:h}=e;if(i!==r.DRAWING_IMAGE||!this._drawingManagerService.getDrawingVisible()||this._univerInstanceService.getUnitType(u)===p.UNIVER_SHEET&&d!==this._getActiveSheetId()||n==null)return;let g=m&&h?h:[n],_=[];for(let e of g){let{left:n,top:r,width:i,height:p,angle:h,flipX:v,flipY:y,skewX:b,skewY:S}=e,w=g.indexOf(e),T=C({unitId:u,subUnitId:d,drawingId:f},m?w:void 0),D=t.getObject(T);if(D!=null){D.transformByState({left:n,top:r,width:i,height:p,angle:h,flipX:v,flipY:y,skewX:b,skewY:S});continue}let O=this._drawingManagerService.getDrawingOrder(u,d),k=O.indexOf(f),j={...e,zIndex:k===-1?O.length-1:k},M=this._imageIoService.getImageSourceCache(a,o),N=!1;if(M!=null)j.image=M;else if(o===x.UUID)try{j.url=await this._imageIoService.getImage(a)}catch(e){console.error(e);continue}else if(o===x.URL){try{j.url=await this._urlImageService.getImage(a)}catch(e){console.error(e),j.url=a}N=!0}else j.url=a,N=!0;if(t.getObject(T))continue;j.printable=!0;let P=new A(T,j);N&&this._imageIoService.addImageSourceCache(a,o,P.getNative()),t.addObject(P,E),this._drawingManagerService.getDrawingEditable()&&t.attachTransformerTo(P),l&&Xe({drawingId:l,unitId:u,subUnitId:d},P,t,this._drawingManagerService),c!=null&&P.setPrstGeom(c),s!=null&&P.setSrcRect(s),_.push(P)}return _}_getActiveSheetId(){var e;return(e=this._univerInstanceService.getCurrentUnitOfType(p.UNIVER_SHEET))==null||(e=e.getActiveSheet())==null?void 0:e.getSheetId()}renderFloatDom(e,t){let{transform:n,drawingType:i,groupId:a,unitId:o,subUnitId:s,drawingId:c,isMultiTransform:l,transforms:u}=e;if(i!==r.DRAWING_DOM||!this._drawingManagerService.getDrawingVisible()||n==null)return;let d=l&&u?u:[n],f=[];for(let n of d){let{left:r,top:i,width:u,height:p,angle:m,flipX:h,flipY:g,skewX:_,skewY:v}=n,y=d.indexOf(n),b=C({unitId:o,subUnitId:s,drawingId:c},l?y:void 0),x=t.getObject(b);if(x!=null){x.transformByState({left:r,top:i,width:u,height:p,angle:m,flipX:h,flipY:g,skewX:_,skewY:v});continue}let S=this._drawingManagerService.getDrawingOrder(o,s),w=S.indexOf(c),T={...n,zIndex:w===-1?S.length-1:w};if(t.getObject(b))continue;T.printable=!1;let D=new M(b,T);this._drawingManagerService.getDrawingVisible()&&(t.addObject(D,E),this._drawingManagerService.getDrawingEditable()&&e.allowTransform!==!1&&t.attachTransformerTo(D),a&&Xe({drawingId:a,unitId:o,subUnitId:s},D,t,this._drawingManagerService),f.push(D))}return f}renderDrawing(e,t){let n=this._drawingManagerService.getDrawingByParam(e);if(n!=null)switch(n.drawingType){case r.DRAWING_IMAGE:return this.renderImages(n,t);default:}}previewImage(e,t,n,r){this._galleryService.open({images:[t],onOpenChange:e=>{e||this._galleryService.close()}})}_adjustImageSize(e,t,n,r){if(e<=n&&t<=r)return{width:e,height:t};let i=n/e,a=r/t,o=Math.min(i,a);return{width:Math.floor(e*o),height:Math.floor(t*o)}}};It=Z([X(0,y),X(1,b),X(2,_e),X(3,o),X(4,s)],It);let Lt=class extends n{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._drawingManagerService=n,this._dialogService=r,this._imageIoService=i,this._currentUniverService=a,this._drawingRenderService=o,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===Ye.id){let t=e.params;if(t==null)return;this._resetImageSize(t)}}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_resetImageSize(e){let t=[],n=[];e.forEach(e=>{let{unitId:i,subUnitId:a,drawingId:o}=e,s=this._getSceneAndTransformerByDrawingSearch(i);if(s==null)return;let{scene:c}=s,l=C({unitId:i,subUnitId:a,drawingId:o}),u=c.getObject(l);if(u==null)return!0;let d=this._drawingManagerService.getDrawingByParam(e);if(d==null)return!0;if(d.drawingType!==r.DRAWING_IMAGE)return;u.resetSize();let{width:f,height:p}=u.getNativeSize();n.includes(c)===!1&&n.push(c),t.push({...d,transform:{...d.transform,height:p,width:f,angle:0},srcRect:null,prstGeom:null})}),this._drawingManagerService.featurePluginUpdateNotification(t),n.forEach(e=>{e.getTransformerByCreate().refreshControls().changeNotification()}),this._commandService.syncExecuteCommand(S.id,e)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.pipe(xe(33),Se(e=>e.length>0),Ce(e=>e.flat()),Ce(e=>{let t=new Map;for(let n of e)t.set(`${n.unitId}|${n.subUnitId}|${n.drawingId}`,n);return[...t.values()]}),Se(e=>e.length>0)).subscribe(e=>{this._insertImages(e)}))}_insertImages(e){e.forEach(async e=>{var t;let{unitId:n,subUnitId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(n),a=(t=Ze(this._currentUniverService,n))==null?void 0:t.subUnitId;if(i==null||a!==r)return;let o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let s=await this._drawingRenderService.renderImages(o,i.scene);if(this._drawingManagerService.refreshTransform([o]),!(s==null||s.length===0))for(let e of s)this._addHoverForImage(e),this._addDialogForImage(e)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:i}=e,a=this._drawingManagerService.getDrawingByParam(e);if(a==null)return;let{transform:o,drawingType:s,srcRect:l,prstGeom:u,source:d,imageSourceType:f}=a;if(s!==r.DRAWING_IMAGE)return;let p=this._getSceneAndTransformerByDrawingSearch(t);if(p==null)return;let{scene:m,transformer:h}=p;if(o==null)return!0;let g=C({unitId:t,subUnitId:n,drawingId:i}),_=m.getObject(g);if(_==null)return!0;_.setSrcRect(l),_.setPrstGeom(u),d!=null&&d.length>0&&(f===c.BASE64||f===c.URL)&&_.changeSource(d)})}))}_addHoverForImage(e){this.disposeWithMe(v(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=w.GRAB}))),this.disposeWithMe(v(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=w.DEFAULT})))}_addDialogForImage(e){this.disposeWithMe(v(e.onDblclick$.subscribeEvent(()=>{let t=`${e.oKey}-viewer-dialog`;this._drawingRenderService.previewImage(t,e.getNative().src,e.getNativeSize().width,e.getNativeSize().height)})))}};Lt=Z([X(0,i),X(1,k),X(2,y),X(3,ge),X(4,b),X(5,s),X(6,l(It))],Lt);let $=class extends f{constructor(e=tt,t,n){super(),this._config=e,this._injector=t,this._configService=n;let{menu:r,...i}=_({},tt,this._config);r&&this._configService.setConfig(`menu`,r,{merge:!0}),this._configService.setConfig(et,i)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(Mt),this._injector.get(Dt),this._injector.get(Ft),this._injector.get(Lt)}_initDependencies(){[[It],[Mt],[Dt],[Ft],[Lt]].forEach(e=>this._injector.add(e))}};Q($,`pluginName`,`UNIVER_DRAWING_UI_PLUGIN`),Q($,`packageName`,Qe),Q($,`version`,$e),$=Z([X(1,l(u)),X(2,a)],$);const Rt=e=>{let t=I(i),n=I(d),{drawings:r,alignShow:a}=e,[o,s]=B(U.default),c=[{label:n.t(`image-panel.align.default`),value:U.default},{options:[{label:n.t(`image-panel.align.left`),value:U.left},{label:n.t(`image-panel.align.center`),value:U.center},{label:n.t(`image-panel.align.right`),value:U.right}]},{options:[{label:n.t(`image-panel.align.top`),value:U.top},{label:n.t(`image-panel.align.middle`),value:U.middle},{label:n.t(`image-panel.align.bottom`),value:U.bottom}]},{options:[{label:n.t(`image-panel.align.horizon`),value:U.horizon},{label:n.t(`image-panel.align.vertical`),value:U.vertical}]}];function l(e){s(e),t.executeCommand(W.id,{alignType:e,drawings:r})}return H(`div`,{className:z(`univer-relative univer-w-full`,{"univer-hidden":!a}),children:[V(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:V(`div`,{children:n.t(`image-panel.align.title`)})}),V(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:V(`div`,{className:`univer-w-full univer-text-gray-900 dark:!univer-text-white`,children:V(ke,{value:o,options:c,onChange:l})})})]})},zt=t=>{let{arrangeShow:n,drawings:r}=t,a=I(d),o=I(y),s=I(i),c=I(pe),l=c.get(`MoveUpIcon`),u=c.get(`MoveDownIcon`),f=c.get(`TopmostIcon`),p=c.get(`BottomIcon`),[m,h]=B(r);je(()=>{let e=o.focus$.subscribe(e=>{h(e)});return()=>{e.unsubscribe()}},[]);let g=e=>{s.syncExecuteCommand(G.id,{arrangeType:e,drawings:m})};return H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!n}),children:[V(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:V(`div`,{children:a.t(`image-panel.arrange.title`)})}),H(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:[H(L,{onClick:()=>{g(e.forward)},children:[V(l,{}),a.t(`image-panel.arrange.forward`)]}),H(L,{onClick:()=>{g(e.backward)},children:[V(u,{}),a.t(`image-panel.arrange.backward`)]}),H(L,{onClick:()=>{g(e.front)},children:[V(f,{}),a.t(`image-panel.arrange.front`)]}),H(L,{onClick:()=>{g(e.back)},children:[V(p,{}),a.t(`image-panel.arrange.back`)]})]})]})},Bt=e=>{let t=I(d),n=I(k),a=I(y),o=I(i),s=I(pe),{hasGroup:c,drawings:l}=e,u=s.get(`GroupIcon`),f=s.get(`UngroupIcon`),[p,m]=B(!1),[h,g]=B(!0),[_,v]=B(!0),b=()=>{o.syncExecuteCommand(K.id,{drawings:l})},x=()=>{o.syncExecuteCommand(q.id,{drawings:l})};return je(()=>{let e=l[0];if(e==null)return;let{unitId:t}=e,i=n.getRenderById(t),o=i==null?void 0:i.scene;if(o==null)return;let s=o.getTransformerByCreate(),c=s.clearControl$.subscribe(e=>{e===!0&&m(!1)}),u=s.changeStart$.subscribe(e=>{let{objects:t}=e,n=Ot(t,a),i=n.filter(e=>(e==null?void 0:e.drawingType)===r.DRAWING_GROUP),o=!1,s=!1;n.length>1&&(o=!0),i.length>0&&(s=!0),m(o||s),g(o),v(s)});return()=>{u.unsubscribe(),c.unsubscribe()}},[]),H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":c===!0&&p===!1||c===!1}),children:[V(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:V(`div`,{children:t.t(`image-panel.group.title`)})}),H(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[H(L,{className:z({"univer-hidden":!h}),onClick:b,children:[V(u,{}),t.t(`image-panel.group.group`)]}),H(L,{className:z({"univer-hidden":!_}),onClick:x,children:[V(f,{}),t.t(`image-panel.group.unGroup`)]})]})]})},Vt=[-360,360],Ht=e=>{var t;let n=I(d),r=I(y),i=I(k),{drawings:a,transformShow:o}=e,s=a[0];if(s==null)return;let c=s.transform;if(c==null)return;let{unitId:l,subUnitId:u,drawingId:f,drawingType:p}=s,m=i.getRenderById(l),g=m==null?void 0:m.scene;if(g==null)return;let _=(t=g.getEngine())==null?void 0:t.activeScene;if(_==null)return;let v=g.getTransformerByCreate(),{width:b=0,height:x=0,left:S=0,top:C=0,angle:w=0}=c,[T,E]=B(b),[D,O]=B(x),[A,j]=B(S),[M,N]=B(C),[P,ee]=B(w),[te,ne]=B(v.keepRatio),re=(e,t,n,r)=>{let{width:i,height:a}=_,{ancestorLeft:o,ancestorTop:s}=g,c=e,l=t,u=n,d=r;return e+o<0&&(c=-o),t+s<0&&(l=-s),u=i-c-o,u<20&&(u=20),d=a-l-s,d<20&&(d=20),e+u+o>i&&(c=i-n-o),t+d+s>a&&(l=a-r-s),{limitLeft:c,limitTop:l,limitWidth:u,limitHeight:d}},ie=e=>{let{objects:t}=e,n=Ot(t,r);if(n.length!==1)return;let i=n[0];if(i==null)return;let{transform:a}=i;if(a==null)return;let{width:o,height:s,left:c,top:l,angle:u}=a;o!=null&&E(o),s!=null&&O(s),c!=null&&j(c),l!=null&&N(l),u!=null&&ee(u)};je(()=>{let e=[v.changeStart$.subscribe(e=>{ie(e)}),v.changing$.subscribe(e=>{ie(e)}),v.changeEnd$.subscribe(e=>{ie(e)}),r.focus$.subscribe(e=>{if(e.length!==1)return;let t=r.getDrawingByParam(e[0]);if(t==null)return;let n=t.transform;if(n==null)return;let{width:i,height:a,left:o,top:s,angle:c}=n;i!=null&&E(i),a!=null&&O(a),o!=null&&j(o),s!=null&&N(s),c!=null&&ee(c)})];return()=>{e.forEach(e=>e.unsubscribe())}},[]);let ae=h(e=>{if(e==null)return;let{limitWidth:t,limitHeight:n}=re(A,M,e,D);e=Math.min(e,t);let i={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{width:e}};if(te){let t=e/T*D;if(t=Math.max(t,20),t>n)return;O(t),i.transform.height=t}E(e),r.featurePluginUpdateNotification([i]),v.refreshControls().changeNotification()},300),oe=h(e=>{if(e==null)return;let{limitHeight:t,limitWidth:n}=re(A,M,T,e);e=Math.min(e,t);let i={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{height:e}};if(te){let t=e/D*T;if(t=Math.max(t,20),t>n)return;E(t),i.transform.width=t}O(e),r.featurePluginUpdateNotification([i]),v.refreshControls().changeNotification()},300),se=h(e=>{if(e==null)return;let{limitLeft:t}=re(e,M,T,D);e=t;let n={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{left:e}};j(e),r.featurePluginUpdateNotification([n]),v.refreshControls().changeNotification()},300),ce=h(e=>{if(e==null)return;let{limitTop:t}=re(A,e,T,D);e=t;let n={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{top:e}};N(e),r.featurePluginUpdateNotification([n]),v.refreshControls().changeNotification()},300),le=e=>{if(e==null)return;let t={unitId:l,subUnitId:u,drawingId:f,drawingType:p,transform:{angle:e}};ee(e),r.featurePluginUpdateNotification([t]),v.refreshControls().changeNotification()},ue=e=>{ne(e),v.keepRatio=e};return H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!o}),children:[V(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:V(`div`,{children:n.t(`image-panel.transform.title`)})}),H(`div`,{className:`univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2`,children:[H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.width`)}),V(R,{precision:1,value:T,min:20,onChange:e=>{ae(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.height`)}),V(R,{precision:1,value:D,min:20,onChange:e=>{oe(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.lock`)}),V(`div`,{className:`univer-text-center`,children:V(Ee,{checked:te,onChange:ue})})]})]}),H(`div`,{className:`univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2`,children:[H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.x`)}),V(R,{precision:1,value:A,onChange:e=>{se(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.y`)}),V(R,{precision:1,value:M,onChange:e=>{ce(e)}})]}),H(`div`,{children:[V(`span`,{children:n.t(`image-panel.transform.rotate`)}),V(R,{precision:1,value:P,min:Vt[0],max:Vt[1],onChange:le})]})]})]})},Ut=e=>{let t=I(i),n=I(d),{drawings:r,cropperShow:a}=e;if(r[0]==null)return;let[o,s]=B(Y.FREE),c=Me(!1),l=[{label:n.t(`image-panel.crop.mode`),value:Y.FREE},{label:`1:1`,value:Y.R1_1},{label:`16:9`,value:Y.R16_9},{label:`9:16`,value:Y.R9_16},{label:`5:4`,value:Y.R5_4},{label:`4:5`,value:Y.R4_5},{label:`4:3`,value:Y.R4_3},{label:`3:4`,value:Y.R3_4},{label:`3:2`,value:Y.R3_2},{label:`2:3`,value:Y.R2_3}];je(()=>{let e=t.onCommandExecuted(e=>{if(e.id===J.id){let t=e.params;t!=null&&t.isAuto||(c.current=!1)}});return()=>{e==null||e.dispose()}},[]);function u(e){s(e),c.current&&t.executeCommand(Je.id,{cropType:e})}let f=e=>{t.executeCommand(Je.id,{cropType:e}),c.current=!0};return H(`div`,{className:z(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!a}),children:[V(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:V(`div`,{children:n.t(`image-panel.crop.title`)})}),H(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[H(L,{onClick:()=>{f(o)},children:[V(oe,{}),n.t(`image-panel.crop.start`)]}),V(ke,{value:o,options:l,onChange:u})]})]})},Wt=e=>{let t=I(y),n=I(k),r=I(d),{drawings:i,hasArrange:a=!0,hasTransform:o=!0,hasAlign:s=!0,hasCropper:c=!0,hasGroup:l=!0}=e,u=i[0];if(u==null)return;let{unitId:f}=u,p=n.getRenderById(f),m=p==null?void 0:p.scene;if(m==null)return;let h=m.getTransformerByCreate(),[g,_]=B(!0),[v,b]=B(!0),[x,S]=B(!1),[C,w]=B(!0),[T,E]=B(!1);return je(()=>{let e=h.clearControl$.subscribe(e=>{e===!0&&(_(!1),b(!1),S(!1),w(!1),E(!0))}),n=h.changeStart$.subscribe(e=>{let{objects:n}=e,r=Ot(n,t);r.length===0?(_(!1),b(!1),S(!1),w(!1),E(!0)):r.length===1?(_(!0),b(!0),S(!1),w(!0),E(!1)):(_(!0),b(!1),S(!0),w(!1),E(!1))}),r=t.focus$.subscribe(e=>{e.length===0?(_(!1),b(!1),S(!1),w(!1),E(!0)):e.length===1?(_(!0),b(!0),S(!1),w(!0),E(!1)):(_(!0),b(!1),S(!0),w(!1),E(!1))});return()=>{n.unsubscribe(),e.unsubscribe(),r.unsubscribe()}},[]),H(Ne,{children:[V(`div`,{className:z(`univer-h-full`,{"univer-hidden":!T}),children:V(`div`,{className:`univer-flex univer-h-full univer-items-center univer-justify-center`,children:V(`span`,{children:r.t(`image-panel.null`)})})}),V(zt,{arrangeShow:a===!0?g:!1,drawings:i}),V(Ht,{transformShow:o===!0?v:!1,drawings:i}),V(Rt,{alignShow:s===!0?x:!1,drawings:i}),V(Ut,{cropperShow:c===!0?C:!1,drawings:i}),V(Bt,{hasGroup:l,drawings:i})]})};export{Je as AutoImageCropOperation,Tt as COMPONENT_IMAGE_POPUP_MENU,q as CancelDrawingGroupOperation,J as CloseImageCropOperation,Ke as DRAWING_GROUP_TYPES,Wt as DrawingCommonPanel,It as DrawingRenderService,Pt as ImageCropperObject,Et as ImagePopupMenu,Ye as ImageResetSizeOperation,qe as OpenImageCropOperation,W as SetDrawingAlignOperation,G as SetDrawingArrangeOperation,K as SetDrawingGroupOperation,$ as UniverDrawingUIPlugin,Ze as getCurrentUnitInfo,Ot as getUpdateParams,Xe as insertGroupObject};
|
package/lib/umd/index.js
CHANGED
|
@@ -1,32 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/drawing`),require(`@univerjs/engine-render`),require(`react`),require(`@univerjs/ui`),require(`rxjs`),require(`@univerjs/design`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/drawing`,`@univerjs/engine-render`,`react`,`@univerjs/ui`,`rxjs`,`@univerjs/design`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDrawingUi={},e.UniverCore,e.UniverDrawing,e.UniverEngineRender,e.React,e.UniverUi,e.rxjs,e.UniverDesign,e.React))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let l=function(e){return e.default=`0`,e.left=`1`,e.center=`2`,e.right=`3`,e.top=`4`,e.middle=`5`,e.bottom=`6`,e.horizon=`7`,e.vertical=`8`,e}({}),u={id:`sheet.operation.set-image-align`,type:t.CommandType.OPERATION,handler:(e,t)=>!0},d={id:`sheet.operation.set-drawing-align-left`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.left})},f={id:`sheet.operation.set-drawing-align-center`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.center})},p={id:`sheet.operation.set-drawing-align-right`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.right})},m={id:`sheet.operation.set-drawing-align-top`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.top})},h={id:`sheet.operation.set-drawing-align-middle`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.middle})},g={id:`sheet.operation.set-drawing-align-bottom`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.bottom})},_={id:`sheet.operation.set-drawing-align-horizon`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.horizon})},v={id:`sheet.operation.set-drawing-align-vertical`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.vertical})},y={id:`drawing.operation.set-drawing-arrange`,type:t.CommandType.OPERATION,handler:(e,t)=>{let r=e.get(n.IDrawingManagerService),{arrangeType:i}=t,a=t.drawings||r.getFocusDrawings(),{unitId:o,subUnitId:s}=a[0],c=a.map(e=>e.drawingId);return r.featurePluginOrderUpdateNotification({unitId:o,subUnitId:s,drawingIds:c,arrangeType:i}),!0}},b={id:`drawing.operation.set-drawing-arrange-front`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(y.id,{arrangeType:t.ArrangeTypeEnum.front})},x={id:`drawing.operation.set-drawing-arrange-forward`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(y.id,{arrangeType:t.ArrangeTypeEnum.forward})},S={id:`drawing.operation.set-drawing-arrange-back`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(y.id,{arrangeType:t.ArrangeTypeEnum.back})},C={id:`drawing.operation.set-drawing-arrange-backward`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(y.id,{arrangeType:t.ArrangeTypeEnum.backward})},w=[t.DrawingTypeEnum.DRAWING_IMAGE,t.DrawingTypeEnum.DRAWING_SHAPE,t.DrawingTypeEnum.DRAWING_GROUP],T={id:`drawing.operation.set-drawing-group`,type:t.CommandType.OPERATION,handler:(e,i)=>{let a=e.get(n.IDrawingManagerService),o=i.drawings||a.getFocusDrawings();if(o.length<2||!o.every(e=>w.includes(e.drawingType)))return!1;let{unitId:s,subUnitId:c}=o[0],l=(0,t.generateRandomId)(10),u=(0,r.getGroupState)(0,0,o.map(e=>e.transform||{})),d={unitId:s,subUnitId:c,drawingId:l,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,transform:u,groupBaseBound:{left:u.left,top:u.top,width:u.width,height:u.height}},f=o.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t},groupId:l}});return a.featurePluginGroupUpdateNotification([{parent:d,children:f}]),!0}},E={id:`drawing.operation.cancel-drawing-group`,type:t.CommandType.OPERATION,handler:(e,i)=>{let a=e.get(n.IDrawingManagerService),o=(i.drawings||a.getFocusDrawings()).map(e=>{if(e.drawingType!==t.DrawingTypeEnum.DRAWING_GROUP)return null;let{unitId:n,subUnitId:i,drawingId:o,transform:s={width:0,height:0},groupBaseBound:c}=e;if(s===null)return null;let l=a.getDrawingsByGroup({unitId:n,subUnitId:i,drawingId:o});return l.length===0?null:{parent:e,children:l.map(e=>{let{transform:t}=e,{unitId:n,subUnitId:i,drawingId:a}=e,o=(0,r.transformObjectOutOfGroup)(t||{},s,s.width||0,s.height||0,c);return{unitId:n,subUnitId:i,drawingId:a,transform:{...t,...o},groupId:void 0}})}}).filter(e=>e!==null);return o.length===0?!1:(a.featurePluginUngroupUpdateNotification(o),!0)}},D={id:`sheet.operation.open-image-crop`,type:t.CommandType.OPERATION,handler:(e,t)=>!0},O={id:`sheet.operation.close-image-crop`,type:t.CommandType.OPERATION,handler:(e,t)=>!0},k=function(e){return e.FREE=`0`,e.R1_1=`1`,e.R16_9=`2`,e.R9_16=`3`,e.R5_4=`4`,e.R4_5=`5`,e.R4_3=`6`,e.R3_4=`7`,e.R3_2=`8`,e.R2_3=`9`,e}({}),A={id:`sheet.operation.Auto-image-crop`,type:t.CommandType.OPERATION,handler:(e,t)=>!0},j={id:`sheet.operation.image-reset-size`,type:t.CommandType.OPERATION,handler:(e,t)=>!0};function M(e,t,i,a){let o=a.getDrawingByParam(e);if(o==null)return;let s=(0,n.getDrawingShapeKeyByDrawingSearch)(e),c=i.getObjectIncludeInGroup(s);if(c&&!(c instanceof r.Group))return;if(c!=null){let e=c.getObjects();for(let n of e)if(n.oKey===t.oKey)return;c.addObject(t);return}let l=new r.DrawingGroupObject(s);i.addObject(l,r.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(l),l.addObject(t);let{transform:u,groupBaseBound:d}=o;d&&l.setBaseBound(d),o.groupId&&(l.isInGroup=!0,M({drawingId:o.groupId,unitId:e.unitId,subUnitId:e.subUnitId},l,i,a)),u&&l.transformByState({left:u.left,top:u.top,angle:u.angle,width:u.width,height:u.height})}function N(e,n){let r=n?e.getUnit(n):e.getFocusedUnit();if(r==null)return;let i=r.getUnitId(),a;if(r.type===t.UniverInstanceType.UNIVER_SHEET){var o;a=(o=r.getActiveSheet())==null?void 0:o.getSheetId()}else (r.type===t.UniverInstanceType.UNIVER_DOC||r.type===t.UniverInstanceType.UNIVER_SLIDE)&&(a=i);return{unitId:i,subUnitId:a,current:r}}var P=`@univerjs/drawing-ui`,F=`0.18.0`;let I=`drawing-ui.config`;Symbol(I);let ee={};function L({ref:e,...t}){let{icon:n,id:r,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${r} ${a||``}`.trim(),l=(0,i.useRef)(`_${B()}`);return R(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...s},o)}function R(e,t,n,r,a){return(0,i.createElement)(e.tag,{key:t,...te(e,n,a),...r},(z(e,n).children||[]).map((r,i)=>R(r,`${t}-${e.tag}-${i}`,n,void 0,a)))}function te(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function z(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function B(){return Math.random().toString(36).substring(2,8)}L.displayName=`UniverIcon`;let ne={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M14.0045 4.4334C14.8881 4.4334 15.6045 3.71705 15.6045 2.8334C15.6045 1.94974 14.8881 1.2334 14.0045 1.2334H3.70449C2.82084 1.2334 2.10449 1.94974 2.10449 2.8334C2.10449 3.71705 2.82084 4.4334 3.70449 4.4334H14.0045ZM14.4045 2.8334C14.4045 3.05431 14.2254 3.2334 14.0045 3.2334H3.70449C3.48358 3.2334 3.30449 3.05431 3.30449 2.8334C3.30449 2.61248 3.48358 2.4334 3.70449 2.4334H14.0045C14.2254 2.4334 14.4045 2.61249 14.4045 2.8334Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M14.1544 8.5999C15.038 8.5999 15.7544 7.88356 15.7544 6.9999C15.7544 6.11625 15.038 5.3999 14.1544 5.3999H3.85439C2.97074 5.3999 2.25439 6.11625 2.25439 6.9999C2.25439 7.88356 2.97074 8.5999 3.85439 8.5999H14.1544ZM14.5544 6.9999C14.5544 7.22082 14.3753 7.3999 14.1544 7.3999H3.85439C3.63348 7.3999 3.45439 7.22082 3.45439 6.9999C3.45439 6.77899 3.63348 6.5999 3.85439 6.5999H14.1544C14.3753 6.5999 14.5544 6.77899 14.5544 6.9999Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.57975 14.5902L6.58023 12.5907C6.34591 12.3564 6.34591 11.9765 6.58023 11.7421C6.81454 11.5078 7.19444 11.5078 7.42876 11.7421L8.40449 12.7179V10.1664C8.40449 9.83504 8.67312 9.56641 9.00449 9.56641C9.33586 9.56641 9.60449 9.83504 9.60449 10.1664V12.7179L10.5802 11.7421C10.8145 11.5078 11.1944 11.5078 11.4288 11.7421C11.6631 11.9765 11.6631 12.3564 11.4288 12.5907L9.42923 14.5902`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.57975 14.5902C8.58121 14.5917 8.58268 14.5931 8.58416 14.5946C8.64077 14.6502 8.70566 14.6923 8.77482 14.7209C8.84557 14.7502 8.92314 14.7664 9.00449 14.7664C9.08585 14.7664 9.16342 14.7502 9.23416 14.7209C9.30332 14.6923 9.36821 14.6502 9.42482 14.5946`}}]},re=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`bottom-icon`,ref:t,icon:ne}))});re.displayName=`BottomIcon`;let ie={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M5.97705 7.51296C5.97705 7.18159 6.24568 6.91296 6.57705 6.91296H8.48632C8.81769 6.91296 9.08632 7.18159 9.08632 7.51296C9.08632 7.84433 8.81769 8.11296 8.48632 8.11296H6.57705C6.24568 8.11296 5.97705 7.84433 5.97705 7.51296Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.57705 9.41028C6.24568 9.41028 5.97705 9.67891 5.97705 10.0103C5.97705 10.3416 6.24568 10.6103 6.57705 10.6103H10.8199C11.1512 10.6103 11.4199 10.3416 11.4199 10.0103C11.4199 9.67891 11.1512 9.41028 10.8199 9.41028H6.57705Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.51074 2.37063C3.51074 1.48697 4.22709 0.77063 5.11074 0.77063H9.80318L9.81294 0.770708C9.97168 0.768161 10.1311 0.82824 10.2511 0.95055L14.4317 5.21408C14.5165 5.30049 14.5697 5.406 14.5917 5.51645C14.6041 5.5644 14.6106 5.61467 14.6106 5.66648V11.6406C14.6106 12.5243 13.8943 13.2406 13.0106 13.2406H5.11074C4.22709 13.2406 3.51074 12.5243 3.51074 11.6406V2.37063ZM10.4032 4.66648V2.81964L12.6063 5.06648H10.8032C10.5823 5.06648 10.4032 4.88739 10.4032 4.66648ZM5.11074 1.97063C4.88983 1.97063 4.71074 2.14972 4.71074 2.37063V11.6406C4.71074 11.8615 4.88983 12.0406 5.11074 12.0406H13.0106C13.2316 12.0406 13.4106 11.8615 13.4106 11.6406V6.26648H10.8032C9.91953 6.26648 9.20318 5.55013 9.20318 4.66648V1.97063H5.11074Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M2.58916 6.6741C2.58916 6.34273 2.32053 6.0741 1.98916 6.0741C1.65779 6.0741 1.38916 6.34273 1.38916 6.6741V12.6294C1.38916 14.0653 2.55322 15.2294 3.98916 15.2294H9.41408C9.74545 15.2294 10.0141 14.9607 10.0141 14.6294C10.0141 14.298 9.74545 14.0294 9.41408 14.0294H3.98916C3.21596 14.0294 2.58916 13.4026 2.58916 12.6294V6.6741Z`}}]},ae=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`create-copy-icon`,ref:t,icon:ie}))});ae.displayName=`CreateCopyIcon`;let oe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M7.38125 1.16211C6.49759 1.16211 5.78125 1.87845 5.78125 2.76211V5.6377H2.87783C1.99418 5.6377 1.27783 6.35404 1.27783 7.2377V13.2377C1.27783 14.1214 1.99418 14.8377 2.87783 14.8377H8.87783C9.76149 14.8377 10.4778 14.1214 10.4778 13.2377V10.3621H13.3813C14.2649 10.3621 14.9813 9.64577 14.9813 8.76211V2.76211C14.9813 1.87845 14.2649 1.16211 13.3813 1.16211H7.38125ZM10.4778 9.16211H13.3813C13.6022 9.16211 13.7812 8.98302 13.7812 8.76211V2.76211C13.7812 2.5412 13.6022 2.36211 13.3813 2.36211H7.38125C7.16034 2.36211 6.98125 2.5412 6.98125 2.76211V5.6377H8.87783C9.76149 5.6377 10.4778 6.35404 10.4778 7.2377V9.16211ZM6.98125 6.8377H8.87783C9.09875 6.8377 9.27783 7.01678 9.27783 7.2377V9.16211H7.38125C7.16034 9.16211 6.98125 8.98302 6.98125 8.76211V6.8377ZM5.78125 6.8377V8.76211C5.78125 9.64577 6.49759 10.3621 7.38125 10.3621H9.27783V13.2377C9.27783 13.4586 9.09875 13.6377 8.87783 13.6377H2.87783C2.65692 13.6377 2.47783 13.4586 2.47783 13.2377V7.2377C2.47783 7.01678 2.65692 6.8377 2.87783 6.8377H5.78125Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},se=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`group-icon`,ref:t,icon:oe}))});se.displayName=`GroupIcon`;let ce={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},le=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`more-down-icon`,ref:t,icon:ce}))});le.displayName=`MoreDownIcon`;let ue={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.25 2.96401C1.25 3.84767 1.96634 4.56401 2.85 4.56401H13.15C14.0337 4.56401 14.75 3.84767 14.75 2.96401C14.75 2.08036 14.0337 1.36401 13.15 1.36401H2.85C1.96635 1.36401 1.25 2.08036 1.25 2.96401ZM2.85 3.36401C2.62909 3.36401 2.45 3.18493 2.45 2.96401C2.45 2.7431 2.62909 2.56401 2.85 2.56401H13.15C13.3709 2.56401 13.55 2.7431 13.55 2.96401C13.55 3.18493 13.3709 3.36401 13.15 3.36401H2.85Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.57564 11.6118C5.80995 11.3774 6.18985 11.3774 6.42417 11.6118L7.3999 12.5875V6.36951C7.3999 6.03814 7.66853 5.76951 7.9999 5.76951C8.33127 5.76951 8.5999 6.03814 8.5999 6.36951V12.5875L9.57564 11.6118C9.80995 11.3774 10.1899 11.3774 10.4242 11.6118C10.6585 11.8461 10.6585 12.226 10.4242 12.4603L8.4324 14.452C8.32324 14.5655 8.16982 14.6362 7.9999 14.6362C7.82998 14.6362 7.67655 14.5655 7.56739 14.452L5.57564 12.4603C5.34132 12.226 5.34132 11.8461 5.57564 11.6118Z`}}]},de=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`move-down-icon`,ref:t,icon:ue}))});de.displayName=`MoveDownIcon`;let fe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.25 13.036C1.25 12.1523 1.96634 11.436 2.85 11.436H13.15C14.0337 11.436 14.75 12.1523 14.75 13.036C14.75 13.9196 14.0337 14.636 13.15 14.636H2.85C1.96635 14.636 1.25 13.9196 1.25 13.036ZM2.85 12.636C2.62909 12.636 2.45 12.8151 2.45 13.036C2.45 13.2569 2.62909 13.436 2.85 13.436H13.15C13.3709 13.436 13.55 13.2569 13.55 13.036C13.55 12.8151 13.3709 12.636 13.15 12.636H2.85Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.57564 4.38825C5.80995 4.62256 6.18985 4.62256 6.42417 4.38825L7.3999 3.41251V9.63049C7.3999 9.96186 7.66853 10.2305 7.9999 10.2305C8.33127 10.2305 8.5999 9.96186 8.5999 9.63049V3.41251L9.57564 4.38825C9.80995 4.62256 10.1899 4.62256 10.4242 4.38825C10.6585 4.15393 10.6585 3.77403 10.4242 3.53972L8.4324 1.54796C8.32324 1.43445 8.16982 1.36382 7.9999 1.36382C7.82998 1.36382 7.67655 1.43446 7.56739 1.54797L5.57564 3.53972C5.34132 3.77403 5.34132 4.15393 5.57564 4.38825Z`}}]},pe=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`move-up-icon`,ref:t,icon:fe}))});pe.displayName=`MoveUpIcon`;let me={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M7.82994 1.40913C7.88746 1.35161 7.95376 1.30821 8.02453 1.27893C8.09527 1.24959 8.17285 1.2334 8.2542 1.2334C8.33555 1.2334 8.41313 1.24959 8.48387 1.27893C8.55464 1.30821 8.62094 1.35161 8.67846 1.40913L10.6785 3.40913C10.9128 3.64345 10.9128 4.02335 10.6785 4.25766C10.4441 4.49198 10.0642 4.49198 9.82994 4.25766L8.8542 3.28193V5.8334C8.8542 6.16477 8.58557 6.4334 8.2542 6.4334C7.92283 6.4334 7.6542 6.16477 7.6542 5.8334V3.28193L6.67846 4.25766C6.44415 4.49198 6.06425 4.49198 5.82994 4.25766C5.59562 4.02335 5.59562 3.64345 5.82994 3.40913L7.82994 1.40913Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.50439 9C1.50439 8.11634 2.22074 7.4 3.10439 7.4H13.4044C14.288 7.4 15.0044 8.11634 15.0044 9C15.0044 9.88366 14.2881 10.6 13.4044 10.6H3.1044C2.22074 10.6 1.50439 9.88366 1.50439 9ZM3.10439 8.6C2.88348 8.6 2.70439 8.77909 2.70439 9C2.70439 9.22091 2.88348 9.4 3.1044 9.4H13.4044C13.6253 9.4 13.8044 9.22091 13.8044 9C13.8044 8.77909 13.6253 8.6 13.4044 8.6H3.10439Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.6543 13.1665C1.6543 12.2828 2.37064 11.5665 3.2543 11.5665H13.5543C14.438 11.5665 15.1543 12.2828 15.1543 13.1665C15.1543 14.0502 14.438 14.7665 13.5543 14.7665H3.2543C2.37064 14.7665 1.6543 14.0502 1.6543 13.1665ZM3.2543 12.7665C3.03338 12.7665 2.8543 12.9456 2.8543 13.1665C2.8543 13.3874 3.03338 13.5665 3.2543 13.5665H13.5543C13.7752 13.5665 13.9543 13.3874 13.9543 13.1665C13.9543 12.9456 13.7752 12.7665 13.5543 12.7665H3.2543Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},he=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`topmost-icon`,ref:t,icon:me}))});he.displayName=`TopmostIcon`;let ge={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M7.46855 2.83731C7.46855 2.61639 7.64764 2.4373 7.86855 2.4373H13.8603C14.0812 2.4373 14.2603 2.61639 14.2603 2.8373V9.5049C14.2603 9.72581 14.0812 9.90489 13.8603 9.90489H12.866C12.5346 9.90489 12.266 10.1735 12.266 10.5049C12.266 10.8363 12.5346 11.1049 12.866 11.1049H13.8603C14.7439 11.1049 15.4603 10.3886 15.4603 9.5049V2.8373C15.4603 1.95365 14.7439 1.2373 13.8603 1.2373H7.86855C6.9849 1.2373 6.26855 1.95365 6.26855 2.83731V3.48688C6.26855 3.81825 6.53718 4.08688 6.86855 4.08688C7.19993 4.08688 7.46855 3.81825 7.46855 3.48688V2.83731Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.19888 5.56299C2.31522 5.56299 1.59888 6.27933 1.59888 7.16299V13.163C1.59888 14.0466 2.31522 14.763 3.19888 14.763H9.19888C10.0825 14.763 10.7989 14.0466 10.7989 13.163V7.16299C10.7989 6.27933 10.0825 5.56299 9.19888 5.56299H3.19888ZM2.79888 7.16299C2.79888 6.94207 2.97796 6.76299 3.19888 6.76299H9.19888C9.41979 6.76299 9.59888 6.94207 9.59888 7.16299V13.163C9.59888 13.3839 9.41979 13.563 9.19888 13.563H3.19888C2.97796 13.563 2.79888 13.3839 2.79888 13.163V7.16299Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},_e=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`ungroup-icon`,ref:t,icon:ge}))});_e.displayName=`UngroupIcon`;let ve={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`colorChannel1`,d:`M11.0363 12.2367V14.0367C11.0363 14.3681 11.3049 14.6367 11.6363 14.6367C11.9676 14.6367 12.2363 14.3681 12.2363 14.0367V12.2367H14.0364C14.3677 12.2367 14.6364 11.9681 14.6364 11.6367C14.6364 11.3054 14.3677 11.0367 14.0364 11.0367H12.2363V9.23672C12.2363 8.90535 11.9676 8.63672 11.6363 8.63672C11.3049 8.63672 11.0363 8.90535 11.0363 9.23672V11.0367H9.23635C8.90498 11.0367 8.63635 11.3054 8.63635 11.6367C8.63635 11.9681 8.90498 12.2367 9.23635 12.2367H11.0363Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M2.56365 1.36377C1.90091 1.36377 1.36365 1.90103 1.36365 2.56377V6.16377C1.36365 6.82651 1.90091 7.36377 2.56365 7.36377H6.16365C6.82639 7.36377 7.36365 6.82651 7.36365 6.16377V2.56377C7.36365 1.90103 6.82639 1.36377 6.16365 1.36377H2.56365ZM6.16365 2.56377H2.56365L2.56365 6.16377H6.16365V2.56377Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M2.56365 8.63647C1.90091 8.63647 1.36365 9.17373 1.36365 9.83647V13.4365C1.36365 14.0992 1.90091 14.6365 2.56365 14.6365H6.16365C6.82639 14.6365 7.36365 14.0992 7.36365 13.4365V9.83647C7.36365 9.17373 6.82639 8.63647 6.16365 8.63647H2.56365ZM6.16365 9.83647H2.56365L2.56365 13.4365H6.16365V9.83647Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.83635 7.36377C9.17361 7.36377 8.63635 6.82651 8.63635 6.16377V2.56377C8.63635 1.90103 9.17361 1.36377 9.83635 1.36377H13.4364C14.0991 1.36377 14.6364 1.90103 14.6364 2.56377V6.16377C14.6364 6.82651 14.0991 7.36377 13.4364 7.36377H9.83635ZM9.83635 6.16377V2.56377L13.4364 2.56377V6.16377H9.83635Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},ye=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`autofill-double-icon`,ref:t,icon:ve}))});ye.displayName=`AutofillDoubleIcon`;let be=e=>{let t=e.get(n.IDrawingManagerService);return new o.Observable(e=>{let n=t=>{if(!t||t.length===0||t.length<2)return e.next(!0);e.next(!1)},r=t.focus$.subscribe(t=>{if(!t||t.length===0)return e.next(!0);n(t)});return n(t.getFocusDrawings()),()=>r.unsubscribe()})},xe=`contextMenu.drawing-align`;function Se(e){return{id:xe,type:a.MenuItemType.SUBITEMS,icon:`HorizontallyIcon`,title:`image-panel.align.title`,hidden$:be(e)}}function Ce(){return{id:d.id,type:a.MenuItemType.BUTTON,icon:`LeftJustifyingIcon`,title:`image-panel.align.left`}}function we(){return{id:f.id,type:a.MenuItemType.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.center`}}function Te(){return{id:p.id,type:a.MenuItemType.BUTTON,icon:`RightJustifyingIcon`,title:`image-panel.align.right`}}function Ee(){return{id:m.id,type:a.MenuItemType.BUTTON,icon:`AlignTopIcon`,title:`image-panel.align.top`}}function De(){return{id:h.id,type:a.MenuItemType.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.middle`}}function Oe(){return{id:g.id,type:a.MenuItemType.BUTTON,icon:`AlignBottomIcon`,title:`image-panel.align.bottom`}}function ke(){return{id:_.id,type:a.MenuItemType.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.horizon`}}function Ae(){return{id:v.id,type:a.MenuItemType.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.vertical`}}let je=`contextMenu.drawing-arrange`;function Me(){return{id:je,type:a.MenuItemType.SUBITEMS,icon:`TopmostIcon`,title:`image-panel.arrange.title`}}function Ne(){return{id:b.id,type:a.MenuItemType.BUTTON,icon:`TopmostIcon`,title:`image-panel.arrange.front`}}function Pe(){return{id:x.id,type:a.MenuItemType.BUTTON,icon:`MoveUpIcon`,title:`image-panel.arrange.forward`}}function Fe(){return{id:S.id,type:a.MenuItemType.BUTTON,icon:`BottomIcon`,title:`image-panel.arrange.back`}}function Ie(){return{id:C.id,type:a.MenuItemType.BUTTON,icon:`MoveDownIcon`,title:`image-panel.arrange.backward`}}let Le=(e,r)=>{let i=e.get(n.IDrawingManagerService);return new o.Observable(e=>{let n=n=>{if(!n||n.length===0)return e.next(!0);if(r===`group`){if(n.length<2||!n.every(e=>w.includes(e.drawingType)))return e.next(!0)}else if(r===`unGroup`){if(n.filter(e=>e.drawingType===t.DrawingTypeEnum.DRAWING_GROUP).length===0)return e.next(!0)}else if(!n.every(e=>w.includes(e.drawingType)))return e.next(!0);e.next(!1)},a=i.focus$.subscribe(t=>{if(!t||t.length===0)return e.next(!0);n(t)});return n(i.getFocusDrawings()),()=>a.unsubscribe()})},Re=`contextMenu.drawing-group`;function ze(e){return{id:Re,type:a.MenuItemType.SUBITEMS,icon:`GroupIcon`,title:`image-panel.group.title`,hidden$:Le(e)}}function Be(e){return{id:T.id,type:a.MenuItemType.BUTTON,icon:`GroupIcon`,title:`image-panel.group.group`,disabled$:Le(e,`group`)}}function Ve(e){return{id:E.id,type:a.MenuItemType.BUTTON,icon:`UngroupIcon`,title:`image-panel.group.unGroup`,disabled$:Le(e,`unGroup`)}}let He={[a.ContextMenuPosition.DRAWING]:{[a.ContextMenuGroup.OTHERS]:{[Re]:{order:1,menuItemFactory:ze,[T.id]:{order:0,menuItemFactory:Be},[E.id]:{order:1,menuItemFactory:Ve}},[je]:{order:2,menuItemFactory:Me,[b.id]:{order:0,menuItemFactory:Ne},[x.id]:{order:1,menuItemFactory:Pe},[S.id]:{order:2,menuItemFactory:Fe},[C.id]:{order:3,menuItemFactory:Ie}},[xe]:{order:3,menuItemFactory:Se,[d.id]:{order:0,menuItemFactory:Ce},[f.id]:{order:1,menuItemFactory:we},[p.id]:{order:2,menuItemFactory:Te},[m.id]:{order:3,menuItemFactory:Ee},[h.id]:{order:4,menuItemFactory:De},[g.id]:{order:5,menuItemFactory:Oe},[_.id]:{order:6,menuItemFactory:ke},[v.id]:{order:7,menuItemFactory:Ae}}}}},Ue=`COMPONENT_IMAGE_POPUP_MENU`;function We(e){var n;let{popup:r}=e,o=r==null||(n=r.extraProps)==null?void 0:n.menuItems;if(!o)return null;let l=(0,a.useDependency)(t.ICommandService),u=(0,a.useDependency)(t.LocaleService),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(!1),h=()=>{m(!0)},g=()=>{m(!1)},_=e=>{f(e)},v=e=>{l.executeCommand(e.commandId,e.commandParams),f(!1)},y=d||p;return(0,c.jsx)(`div`,{onMouseEnter:h,onMouseLeave:g,children:(0,c.jsx)(s.DropdownMenu,{align:`start`,items:o.filter(e=>!e.disable).map(e=>({type:`item`,children:u.t(e.label),onSelect:()=>v(e)})),open:d,onOpenChange:_,children:(0,c.jsxs)(`div`,{className:(0,s.clsx)(`
|
|
2
|
-
univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1
|
|
3
|
-
hover:univer-bg-gray-100
|
|
4
|
-
dark:hover:!univer-bg-gray-800
|
|
5
|
-
`,s.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":d,"univer-bg-white dark:!univer-bg-gray-900":!d}),children:[(0,c.jsx)(ye,{className:`
|
|
6
|
-
univer-fill-primary-600 univer-text-gray-900
|
|
7
|
-
dark:!univer-text-white
|
|
8
|
-
`}),y&&(0,c.jsx)(le,{className:`dark:!univer-text-white`})]})})})}function V(e,t){return function(n,r){t(n,r,e)}}function H(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let U=class extends t.Disposable{constructor(e,t,n){super(),this._componentManager=e,this._commandService=t,this._menuManagerService=n,this._init()}_init(){this._initMenus(),this._initCommands(),this._initComponents()}_initMenus(){this._menuManagerService.mergeMenu(He)}_initCommands(){[D,O,j,u,d,f,p,m,h,g,_,v,A,T,E,y,b,x,S,C].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initComponents(){[[Ue,We],[`BottomIcon`,re],[`GroupIcon`,se],[`MoveDownIcon`,de],[`MoveUpIcon`,pe],[`TopmostIcon`,he],[`UngroupIcon`,_e]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};U=H([V(0,(0,t.Inject)(a.ComponentManager)),V(1,t.ICommandService),V(2,a.IMenuManagerService)],U);function W(e,n){let r=[];return e.forEach(e=>{let{oKey:i,left:a,top:o,height:s,width:c,angle:l}=e,u=n.getDrawingOKey(i);if(u==null)return r.push(null),!0;let{unitId:d,subUnitId:f,drawingId:p,drawingType:m}=u,h={unitId:d,subUnitId:f,drawingId:p,drawingType:m,transform:{left:a,top:o,height:s,width:c,angle:l}};m===t.DrawingTypeEnum.DRAWING_IMAGE&&(h.srcRect=e.srcRect),r.push(h)}),r}function G(e){"@babel/helpers - typeof";return G=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},G(e)}function Ge(e,t){if(G(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(G(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ke(e){var t=Ge(e,`string`);return G(t)==`symbol`?t:t+``}function K(e,t,n){return(t=Ke(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let q=class extends t.Disposable{constructor(e,t,n,r){super(),this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._drawingManagerService=r,K(this,`_sceneListenerOnDrawingMap`,new WeakSet),this._initialize()}dispose(){super.dispose()}_initialize(){this._recoveryImages(),this._drawingAddListener(),this._drawingRemoveListener(),this._drawingUpdateListener(),this._commandExecutedListener(),this._drawingArrangeListener(),this._drawingGroupListener(),this._drawingRefreshListener(),this._drawingVisibleListener()}_recoveryImages(){let e=this._drawingManagerService.drawingManagerData,t=N(this._currentUniverService);if(t==null)return;let{unitId:n,subUnitId:r}=t;Object.keys(e).forEach(t=>{Object.keys(e[t]).forEach(i=>{let a=e[t][i].data;a==null||t!==n||i!==r||Object.keys(a).forEach(e=>{a[e]&&this._insertDrawing([{unitId:t,subUnitId:i,drawingId:e}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===u.id){let t=e.params;if(t==null)return;this._drawingAlign(t)}}))}_drawingGroupListener(){this.disposeWithMe(this._drawingManagerService.group$.subscribe(e=>{this._groupDrawings(e)})),this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe(e=>{this._ungroupDrawings(e)}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_groupDrawings(e){e.forEach(e=>{this._groupDrawing(e)})}_groupDrawing(e){let{parent:t,children:i}=e,{unitId:a,subUnitId:o,drawingId:s}=t,c=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(c==null)return;let{scene:l,transformer:u}=c;this._commandService.syncExecuteCommand(O.id);let d=[];if(i.forEach(e=>{let t=(0,n.getDrawingShapeKeyByDrawingSearch)(e),i=l.getObjectIncludeInGroup(t);if(i==null||d.includes(i))return;d.push(i);let{transform:a}=e;a!=null&&(i.classType===r.RENDER_CLASS_TYPE.GROUP?i.transformByState({left:a.left,top:a.top}):i.transformByState(a))}),d.length===0)return;let f=new r.DrawingGroupObject((0,n.getDrawingShapeKeyByDrawingSearch)({unitId:a,subUnitId:o,drawingId:s}));l.addObject(f,r.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(f),f.addObjects(...d),t.groupBaseBound&&f.setBaseBound(t.groupBaseBound),t.groupId&&(f.isInGroup=!0,M({drawingId:t.groupId,unitId:a,subUnitId:o},f,l,this._drawingManagerService)),t.transform&&f.transformByState({left:t.transform.left,top:t.transform.top,width:t.transform.width,height:t.transform.height,angle:t.transform.angle}),u.clearSelectedObjects(),u.setSelectedControl(f)}_ungroupDrawings(e){e.forEach(e=>{this._ungroupDrawing(e)})}_ungroupDrawing(e){let{parent:t,children:i}=e,a=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(a==null)return;let{scene:o,transformer:s}=a;i.forEach(e=>{let t=(0,n.getDrawingShapeKeyByDrawingSearch)(e),i=o.getObjectIncludeInGroup(t);if(i==null)return!0;if(i==null)return;let{transform:a}=e;a!=null&&(i.classType===r.RENDER_CLASS_TYPE.GROUP?i.transformByState({left:a.left,top:a.top}):i.transformByState(a))});let c=(0,n.getDrawingShapeKeyByDrawingSearch)(t),l=o.getObject(c),{width:u,height:d}=l;l.getObjects().forEach(e=>{l.removeSelfObjectAndTransform(e.oKey,u,d)}),l.dispose(),s.clearSelectedObjects()}_drawingAlign(e){let{alignType:t}=e,n=e.drawings||this._drawingManagerService.getFocusDrawings();if(t===l.default)return;let r=[],i=1/0,a=1/0,o=-1/0,s=-1/0,c=0;n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:l,drawingType:u}=e,d=this._drawingManagerService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:l});if(d==null||d.transform==null)return;r.push({unitId:t,subUnitId:n,drawingId:l,drawingType:u,transform:d.transform});let{left:f=0,top:p=0,width:m=0,height:h=0}=d.transform;i=Math.min(i,f),a=Math.min(a,p),o=Math.max(o,f+m),s=Math.max(s,p+h),c++}),c!==0&&(this._sortDrawingTransform(r,t),this._applyAlignType(r,t,i,a,o,s,c))}_applyAlignType(e,t,n,r,i,a,o){let s=Math.round((i-n)/o*10)/10,c=Math.round((a-r)/o*10)/10,u=[],d=this._getSceneAndTransformerByDrawingSearch(e[0].unitId);if(d==null)return;let{scene:f,transformer:p}=d;e.forEach((e,o)=>{let{unitId:d,subUnitId:f,drawingId:p,transform:m,drawingType:h}=e,{left:g=0,top:_=0,width:v=0,height:y=0}=m,b=g,x=_;switch(t){case l.left:b=n;break;case l.center:b=n+(i-n)/2-v/2;break;case l.right:b=i-v;break;case l.top:x=r;break;case l.middle:x=r+(a-r)/2-y/2;break;case l.bottom:x=a-y;break;case l.horizon:b=n+s*o;break;case l.vertical:x=r+c*o;break;default:break}(b!==g||x!==_)&&u.push({unitId:d,subUnitId:f,drawingId:p,drawingType:h,transform:{left:b,top:x}})}),this._drawingManagerService.featurePluginUpdateNotification(u),p.refreshControls().changeNotification()}_sortDrawingTransform(e,t){e.sort((e,n)=>{let r=e.transform,i=n.transform,{left:a=0,top:o=0,width:s=0,height:c=0}=r,{left:u=0,top:d=0,width:f=0,height:p=0}=i;switch(t){case l.left:return a-u;case l.center:return a+s/2-(u+f/2);case l.right:return a+s-(u+f);case l.top:return o-d;case l.middle:return o+c/2-(d+p/2);case l.bottom:return o+c-(d+p);case l.horizon:return a+s/2-(u+f/2);case l.vertical:return o+c/2-(d+p/2);default:return 0}})}_drawingArrangeListener(){this.disposeWithMe(this._drawingManagerService.order$.subscribe(e=>{this._drawingArrange(e)}))}_drawingArrange(e){let{unitId:t,subUnitId:r,drawingIds:i}=e,a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{scene:o}=a;i.forEach(e=>{let i=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:r,drawingId:e}),a=o.fuzzyMathObjects(i,!0);if(a==null||a.length===0)return;let s=this._drawingManagerService.getDrawingOrder(t,r).indexOf(e);for(let e of a)e.setProps({zIndex:s}),e.makeDirty()})}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{this._insertDrawing(e)}))}_insertDrawing(e){let t=[];e.forEach(e=>{let{unitId:n}=e;if(this._drawingManagerService.getDrawingByParam(e)==null)return;let r=this._getSceneAndTransformerByDrawingSearch(n);if(r==null)return;let{scene:i}=r;t.includes(i)||t.push(i)}),t.forEach(e=>{this._sceneListenerOnDrawingMap.has(e)||(this._addListenerOnDrawing(e),this._sceneListenerOnDrawingMap.add(e))})}_drawingRemoveListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:r,drawingId:i}=e,a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{scene:o}=a,s=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:r,drawingId:i}),c=o.fuzzyMathObjects(s,!0);if(c.length>0){var l;for(let e of c)e.dispose();(l=o.getTransformer())==null||l.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{var t;let{unitId:r,subUnitId:i,drawingId:a}=e,o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let{transform:s,drawingType:c}=o,l=this._getSceneAndTransformerByDrawingSearch(r);if(l==null)return;let{scene:u,transformer:d}=l;if(s==null)return!0;let{left:f=0,top:p=0,width:m=0,height:h=0,angle:g=0,flipX:_=!1,flipY:v=!1,skewX:y=0,skewY:b=0}=s,x=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:r,subUnitId:i,drawingId:a}),S=u.getObject(x);if(S==null)return!0;S.transformByState({left:f,top:p,width:m,height:h,angle:g,flipX:_,flipY:v,skewX:y,skewY:b}),(t=u.getTransformer())==null||t.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:r,drawingId:i}=e,a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let{transform:s}=o,{scene:c}=a,l=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:r,drawingId:i}),u=c.getObject(l);if(u==null||s==null)return!0;let{left:d=0,top:f=0,width:p=0,height:m=0,angle:h=0,flipX:g=!1,flipY:_=!1,skewX:v=0,skewY:y=0}=s;u.transformByState({left:d,top:f,width:p,height:m,angle:h,flipX:g,flipY:_,skewX:v,skewY:y})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:r,drawingId:i,visible:a}=e,o=this._getSceneAndTransformerByDrawingSearch(t);if(o==null)return;let{scene:s}=o,c=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:r,drawingId:i}),l=s.getObject(c);if(l==null)return!0;a?l.show():l.hide()})}))}_filterUpdateParams(e,n){return e.filter((e,r)=>{if(e==null)return!1;let{transform:i}=e;return(0,t.checkIfMove)(i,n==null?void 0:n[r])})}_addListenerOnDrawing(e){let i=e.getTransformerByCreate(),a=null;this.disposeWithMe((0,t.toDisposable)(i.changeStart$.subscribe(e=>{let{objects:t}=e,i=Array.from(t.values()),o=[];a=i.map(e=>{let{left:t,top:n,height:i,width:a,angle:s,oKey:c,isInGroup:l}=e,u=this._drawingManagerService.getDrawingOKey(c);if(l||e instanceof r.Group){let t=e.ancestorGroup;if(t==null&&e instanceof r.Group&&(t=e),t==null)return null;let n=this._drawingManagerService.getDrawingOKey(t.oKey);if(n){let{unitId:e,subUnitId:r,drawingId:i}=n;o.push({unitId:e,subUnitId:r,drawingId:i});let{left:a,top:s,height:c,width:l,angle:u}=t;return{left:a,top:s,height:c,width:l,angle:u}}}else if(u!=null){let{unitId:e,subUnitId:r,drawingId:c}=u;return o.push({unitId:e,subUnitId:r,drawingId:c}),{left:t,top:n,height:i,width:a,angle:s}}return null}).filter(e=>e!=null),o.length>0?this._commandService.syncExecuteCommand(n.SetDrawingSelectedOperation.id,o):this._commandService.syncExecuteCommand(n.SetDrawingSelectedOperation.id,[])}))),this.disposeWithMe((0,t.toDisposable)(i.changeEnd$.subscribe(e=>{let{objects:t}=e,n=this._filterUpdateParams(W(t,this._drawingManagerService),a);n.length>0&&this._drawingManagerService.featurePluginUpdateNotification(n)})))}};q=H([V(0,t.IUniverInstanceService),V(1,t.ICommandService),V(2,r.IRenderManagerService),V(3,n.IDrawingManagerService)],q);var J=function(e){return e[e.RECT=0]=`RECT`,e[e.PATH=1]=`PATH`,e}(J||{}),Y=class extends r.Shape{constructor(e,t){t==null&&(t={}),t.transformerConfig={keepRatio:!1,isCropper:!0,anchorFill:`rgb(0, 0, 0)`,anchorStroke:`rgb(255, 255, 255)`,anchorSize:24},super(e,t),K(this,`_srcRect`,void 0),K(this,`_prstGeom`,void 0),K(this,`_applyTransform`,void 0),K(this,`_dragPadding`,8),K(this,`_cacheCanvas`,void 0),t!=null&&t.srcRect&&(this._srcRect=t.srcRect),t!=null&&t.prstGeom&&(this._prstGeom=t.prstGeom),t!=null&&t.applyTransform&&(this._applyTransform=t.applyTransform),t!=null&&t.dragPadding&&(this._dragPadding=t.dragPadding),this._applyProps()}refreshSrcRect(e,t){this._srcRect=e,this._applyTransform=t,this._applyProps()}get srcRect(){return this._srcRect}dispose(){var e;super.dispose(),(e=this._cacheCanvas)==null||e.dispose(),this._srcRect=null}isHit(e){let t=this.getInverseCoord(e);return t.x>=-this.strokeWidth/2&&t.x<=this.width+this.strokeWidth/2&&t.y>=-this.strokeWidth/2&&t.y<=this.height+this.strokeWidth/2&&!this._inSurround(t)}_inSurround(e){let t=this._dragPadding;return e.x>=t-this.strokeWidth/2&&e.x<=this.width+this.strokeWidth/2-t&&e.y>=t-this.strokeWidth/2&&e.y<=this.height+this.strokeWidth/2-t}render(e,t){return this.visible?(e.save(),this._draw(e),e.restore(),this.makeDirty(!1),this):(this.makeDirty(!1),this)}_draw(e){var t,n;let{width:i,height:a}=this.getScene().getEngine();this._initialCacheCanvas(),(t=this._cacheCanvas)==null||t.clear();let o=(n=this._cacheCanvas)==null?void 0:n.getContext();o!=null&&(o.save(),r.Rect.drawWith(o,{left:0,top:0,width:i,height:a,fill:`rgba(0, 0, 0, 0.5)`}),o.setTransform(e.getTransform()),this._clipForApplyObject(o),this._applyCache(e),o.restore())}_clipForApplyObject(e){let t=J.RECT;if(this._prstGeom!=null&&(t=J.PATH),e.globalCompositeOperation=`destination-out`,e.beginPath(),t===J.RECT){let t=this.transform.getMatrix();e.transform(t[0],t[1],t[2],t[3],t[4],t[5]),e.rect(0,0,this.width,this.height),e.fill()}}_applyProps(){if(this._applyTransform==null)return;let e=0,t=0,n=0,r=0,{left:i=0,top:a=0,width:o=0,height:s=0,angle:c}=this._applyTransform;if(this._srcRect!=null){let{left:i=0,top:a=0,right:o=0,bottom:s=0}=this._srcRect;e=i,t=a,n=o,r=s}let l=i+e,u=a+t;this.transformByState({left:l,top:u,width:i+o-n-l,height:a+s-r-u,angle:c})}_applyCache(e){if(!e||this._cacheCanvas==null)return;let t=this._cacheCanvas.getContext();t.save(),e.save(),e.setTransform(1,0,0,1,0,0),t.setTransform(1,0,0,1,0,0),e.drawImage(this._cacheCanvas.getCanvasEle(),0,0),e.restore(),t.restore()}_initialCacheCanvas(){if(this._cacheCanvas!=null)return;let e=this.getScene();if(e==null)return;this._cacheCanvas=new r.Canvas;let t=e.getEngine();this._cacheCanvas.setSize(t.width,t.height),t.onTransformChange$.subscribeEvent(()=>{var e;(e=this._cacheCanvas)==null||e.setSize(t.width,t.height),this.makeDirty(!0)})}};let X=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._commandService=e,this._drawingManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._messageService=i,this._localeService=a,K(this,`_sceneListenerOnImageMap`,new WeakSet),this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==A.id)return;let t=e.params;if(t==null)return;let{cropType:i}=t,a=this._drawingManagerService.getFocusDrawings();if(a.length!==1)return;let{unitId:o,subUnitId:c,drawingId:l}=a[0],u=this._renderManagerService.getRenderById(o),d=u==null?void 0:u.scene;if(d==null)return!0;this._searchCropObject(d)!=null&&this._commandService.syncExecuteCommand(O.id,{isAuto:!0});let f=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:o,subUnitId:c,drawingId:l}),p=d.getObject(f);if(!(p instanceof r.Image)){this._messageService.show({type:s.MessageType.Error,content:this._localeService.t(`image-cropper.error`)});return}p!=null&&(this._updateCropperObject(i,p),this._commandService.executeCommand(D.id,{unitId:o,subUnitId:c,drawingId:l}))}))}_calculateSrcRectByRatio(e,t,n,i,a,o){let s=n/i,c=a/o,l=n,u=i;s>c?l=i*c:u=n/c;let d=(n-l)/2,f=(i-u)/2;return{left:(0,r.precisionTo)(d,1),top:(0,r.precisionTo)(f,1),right:(0,r.precisionTo)(n-(d+l),1),bottom:(0,r.precisionTo)(i-(f+u),1)}}_updateCropperObject(e,t){let{left:n,top:r,width:i,height:a}=t.calculateTransformWithSrcRect(),o;switch(e){case k.R1_1:o=this._calculateSrcRectByRatio(n,r,i,a,1,1);break;case k.R16_9:o=this._calculateSrcRectByRatio(n,r,i,a,16,9);break;case k.R9_16:o=this._calculateSrcRectByRatio(n,r,i,a,9,16);break;case k.R5_4:o=this._calculateSrcRectByRatio(n,r,i,a,5,4);break;case k.R4_5:o=this._calculateSrcRectByRatio(n,r,i,a,4,5);break;case k.R4_3:o=this._calculateSrcRectByRatio(n,r,i,a,4,3);break;case k.R3_4:o=this._calculateSrcRectByRatio(n,r,i,a,3,4);break;case k.R3_2:o=this._calculateSrcRectByRatio(n,r,i,a,3,2);break;case k.R2_3:o=this._calculateSrcRectByRatio(n,r,i,a,2,3);break;case k.FREE:default:break}if(o==null)return;t.setSrcRect(o);let{left:s=0,top:c=0,bottom:l=0,right:u=0}=o;t.transformByStateCloseCropper({left:n+s,top:r+c,width:i-u-s,height:a-l-c})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==D.id)return;let t=e.params;if(t==null)return;let{unitId:i,subUnitId:a,drawingId:o}=t,c=this._renderManagerService.getRenderById(i),l=c==null?void 0:c.scene;if(l==null)return!0;if(this._sceneListenerOnImageMap.has(l)||(this._addListenerOnImage(l),this._sceneListenerOnImageMap.add(l)),this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:a,drawingId:o})==null)return;let u=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:o}),d=l.getObject(u);if(d==null)return;if(!(d instanceof r.Image)){this._messageService.show({type:s.MessageType.Error,content:this._localeService.t(`image-cropper.error`)});return}let f=l.getTransformer();f==null||f.clearControls();let p=new Y(`${u}-crop`,{srcRect:d.srcRect,prstGeom:d.prstGeom,applyTransform:d.calculateTransformWithSrcRect()});l.addObject(p,d.getLayerIndex()+1).attachTransformerTo(p),f==null||f.createControlForCopper(p),this._addHoverForImageCopper(p),d.openRenderByCropper(),f==null||f.refreshControls(),p.makeDirty(!0),this._commandService.syncExecuteCommand(n.SetDrawingSelectedOperation.id,[{unitId:i,subUnitId:a,drawingId:o}])}))}_searchCropObject(e){let t=e.getAllObjectsByOrder();for(let e of t)if(e instanceof Y)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==O.id)return;let t=this._univerInstanceService.getFocusedUnit();if(t==null)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n),i=r==null?void 0:r.scene;if(i==null)return!0;let a=this._searchCropObject(i);if(a==null)return;let o=this._getApplyObjectByCropObject(a);if(o==null)return;let s=i.getTransformerByCreate();s.detachFrom(a),s.clearCopperControl();let c=this._getSrcRectByTransformState(o,a),l=this._drawingManagerService.getDrawingOKey(o.oKey);if(l!=null){let{left:e,top:t,height:n,width:r}=a;this._drawingManagerService.featurePluginUpdateNotification([{...l,transform:{...l.transform,left:e,top:t,height:n,width:r},srcRect:c.srcRectAngle}])}o.setSrcRect({...c.srcRectAngle}),o.closeRenderByCropper(),o.makeDirty(!0),a==null||a.dispose()}));let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,o.switchMap)(e=>e?e.activeSheet$:(0,o.of)(null)));this.disposeWithMe(e.subscribe(()=>{this._commandService.syncExecuteCommand(O.id)}))}_getApplyObjectByCropObject(e){let t=e.oKey,n=t.slice(0,t.length-5),r=e.getScene();if(!r)return null;let i=r.getObject(n);return i==null?null:i}_addListenerOnImage(e){let n=e.getTransformerByCreate(),r=null;this.disposeWithMe(n.changeStart$.subscribe(e=>{let{objects:t}=e,i=t.values().next().value;if(i==null||!(i instanceof Y))return;let{left:a,top:o,height:s,width:c,angle:l}=i;r={left:a,top:o,height:s,width:c,angle:l},n.clearCopperControl()})),this.disposeWithMe(n.changeEnd$.subscribe(e=>{let{objects:i}=e,a=i.values().next().value;if(a==null||!(a instanceof Y))return;let{left:o,top:s,height:c,width:l,angle:u}=a;if(!(0,t.checkIfMove)({left:o,top:s,height:c,width:l,angle:u},r))return;let d=this._getApplyObjectByCropObject(a);if(d==null)return;let f=this._getSrcRectByTransformState(d,a);a.refreshSrcRect(f.srcRect,d.getState()),n.createControlForCopper(a)})),this._endCropListener(e)}_addHoverForImageCopper(e){this.disposeWithMe(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=r.CURSOR_TYPE.MOVE})),this.disposeWithMe(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=r.CURSOR_TYPE.DEFAULT}))}_endCropListener(e){let t=e.getTransformerByCreate();this.disposeWithMe(t.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(O.id)}))}_getSrcRectByTransformState(e,t){let{left:n,top:i,height:a,width:o,strokeWidth:s,angle:c}=t,{left:l,top:u,width:d,height:f,angle:p,strokeWidth:m}=e,h=n-l,g=i-u,_={left:h,top:g,right:d-h-o,bottom:f-g-a},v={..._};if(p!==0){let e=new r.Vector2(n+o/2,i+a/2),t=new r.Vector2(d/2+l,f/2+u),s=new r.Vector2(l,u);s.rotateByPoint((0,r.degToRad)(p),t);let c=s.clone();c.rotateByPoint((0,r.degToRad)(-p),e);let m=n-c.x,h=i-c.y;v.left=m,v.top=h,v.right=d-m-o,v.bottom=f-h-a}return{srcRect:_,srcRectAngle:v}}};X=H([V(0,t.ICommandService),V(1,n.IDrawingManagerService),V(2,r.IRenderManagerService),V(3,t.IUniverInstanceService),V(4,a.IMessageService),V(5,(0,t.Inject)(t.LocaleService))],X);let Z=class{constructor(e,t,n,r,i){this._drawingManagerService=e,this._imageIoService=t,this._galleryService=n,this._urlImageService=r,this._univerInstanceService=i}async renderImages(e,i){let{transform:a,drawingType:o,source:s,imageSourceType:c,srcRect:l,prstGeom:u,groupId:d,unitId:f,subUnitId:p,drawingId:m,isMultiTransform:h,transforms:g}=e;if(o!==t.DrawingTypeEnum.DRAWING_IMAGE||!this._drawingManagerService.getDrawingVisible()||this._univerInstanceService.getUnitType(f)===t.UniverInstanceType.UNIVER_SHEET&&p!==this._getActiveSheetId()||a==null)return;let _=h&&g?g:[a],v=[];for(let e of _){let{left:t,top:a,width:o,height:g,angle:y,flipX:b,flipY:x,skewX:S,skewY:C}=e,w=_.indexOf(e),T=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:f,subUnitId:p,drawingId:m},h?w:void 0),E=i.getObject(T);if(E!=null){E.transformByState({left:t,top:a,width:o,height:g,angle:y,flipX:b,flipY:x,skewX:S,skewY:C});continue}let D=this._drawingManagerService.getDrawingOrder(f,p),O=D.indexOf(m),k={...e,zIndex:O===-1?D.length-1:O},A=this._imageIoService.getImageSourceCache(s,c),j=!1;if(A!=null)k.image=A;else if(c===n.ImageSourceType.UUID)try{k.url=await this._imageIoService.getImage(s)}catch(e){console.error(e);continue}else if(c===n.ImageSourceType.URL){try{k.url=await this._urlImageService.getImage(s)}catch(e){console.error(e),k.url=s}j=!0}else k.url=s,j=!0;if(i.getObject(T))continue;k.printable=!0;let N=new r.Image(T,k);j&&this._imageIoService.addImageSourceCache(s,c,N.getNative()),i.addObject(N,r.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&i.attachTransformerTo(N),d&&M({drawingId:d,unitId:f,subUnitId:p},N,i,this._drawingManagerService),u!=null&&N.setPrstGeom(u),l!=null&&N.setSrcRect(l),v.push(N)}return v}_getActiveSheetId(){var e;return(e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET))==null||(e=e.getActiveSheet())==null?void 0:e.getSheetId()}renderFloatDom(e,i){let{transform:a,drawingType:o,groupId:s,unitId:c,subUnitId:l,drawingId:u,isMultiTransform:d,transforms:f}=e;if(o!==t.DrawingTypeEnum.DRAWING_DOM||!this._drawingManagerService.getDrawingVisible()||a==null)return;let p=d&&f?f:[a],m=[];for(let t of p){let{left:a,top:o,width:f,height:h,angle:g,flipX:_,flipY:v,skewX:y,skewY:b}=t,x=p.indexOf(t),S=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:c,subUnitId:l,drawingId:u},d?x:void 0),C=i.getObject(S);if(C!=null){C.transformByState({left:a,top:o,width:f,height:h,angle:g,flipX:_,flipY:v,skewX:y,skewY:b});continue}let w=this._drawingManagerService.getDrawingOrder(c,l),T=w.indexOf(u),E={...t,zIndex:T===-1?w.length-1:T};if(i.getObject(S))continue;E.printable=!1;let D=new r.Rect(S,E);this._drawingManagerService.getDrawingVisible()&&(i.addObject(D,r.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&e.allowTransform!==!1&&i.attachTransformerTo(D),s&&M({drawingId:s,unitId:c,subUnitId:l},D,i,this._drawingManagerService),m.push(D))}return m}renderDrawing(e,n){let r=this._drawingManagerService.getDrawingByParam(e);if(r!=null)switch(r.drawingType){case t.DrawingTypeEnum.DRAWING_IMAGE:return this.renderImages(r,n);default:}}previewImage(e,t,n,r){this._galleryService.open({images:[t],onOpenChange:e=>{e||this._galleryService.close()}})}_adjustImageSize(e,t,n,r){if(e<=n&&t<=r)return{width:e,height:t};let i=n/e,a=r/t,o=Math.min(i,a);return{width:Math.floor(e*o),height:Math.floor(t*o)}}};Z=H([V(0,n.IDrawingManagerService),V(1,n.IImageIoService),V(2,a.IGalleryService),V(3,t.IURLImageService),V(4,t.IUniverInstanceService)],Z);let Q=class extends t.Disposable{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._drawingManagerService=n,this._dialogService=r,this._imageIoService=i,this._currentUniverService=a,this._drawingRenderService=o,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===j.id){let t=e.params;if(t==null)return;this._resetImageSize(t)}}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_resetImageSize(e){let r=[],i=[];e.forEach(e=>{let{unitId:a,subUnitId:o,drawingId:s}=e,c=this._getSceneAndTransformerByDrawingSearch(a);if(c==null)return;let{scene:l}=c,u=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:a,subUnitId:o,drawingId:s}),d=l.getObject(u);if(d==null)return!0;let f=this._drawingManagerService.getDrawingByParam(e);if(f==null)return!0;if(f.drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE)return;d.resetSize();let{width:p,height:m}=d.getNativeSize();i.includes(l)===!1&&i.push(l),r.push({...f,transform:{...f.transform,height:m,width:p,angle:0},srcRect:null,prstGeom:null})}),this._drawingManagerService.featurePluginUpdateNotification(r),i.forEach(e=>{e.getTransformerByCreate().refreshControls().changeNotification()}),this._commandService.syncExecuteCommand(n.SetDrawingSelectedOperation.id,e)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.pipe((0,o.bufferTime)(33),(0,o.filter)(e=>e.length>0),(0,o.map)(e=>e.flat()),(0,o.map)(e=>{let t=new Map;for(let n of e)t.set(`${n.unitId}|${n.subUnitId}|${n.drawingId}`,n);return[...t.values()]}),(0,o.filter)(e=>e.length>0)).subscribe(e=>{this._insertImages(e)}))}_insertImages(e){e.forEach(async e=>{var t;let{unitId:n,subUnitId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(n),a=(t=N(this._currentUniverService,n))==null?void 0:t.subUnitId;if(i==null||a!==r)return;let o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let s=await this._drawingRenderService.renderImages(o,i.scene);if(this._drawingManagerService.refreshTransform([o]),!(s==null||s.length===0))for(let e of s)this._addHoverForImage(e),this._addDialogForImage(e)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let{unitId:r,subUnitId:i,drawingId:a}=e,o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let{transform:s,drawingType:c,srcRect:l,prstGeom:u,source:d,imageSourceType:f}=o;if(c!==t.DrawingTypeEnum.DRAWING_IMAGE)return;let p=this._getSceneAndTransformerByDrawingSearch(r);if(p==null)return;let{scene:m,transformer:h}=p;if(s==null)return!0;let g=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:r,subUnitId:i,drawingId:a}),_=m.getObject(g);if(_==null)return!0;_.setSrcRect(l),_.setPrstGeom(u),d!=null&&d.length>0&&(f===t.ImageSourceType.BASE64||f===t.ImageSourceType.URL)&&_.changeSource(d)})}))}_addHoverForImage(e){this.disposeWithMe((0,t.toDisposable)(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=r.CURSOR_TYPE.GRAB}))),this.disposeWithMe((0,t.toDisposable)(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=r.CURSOR_TYPE.DEFAULT})))}_addDialogForImage(e){this.disposeWithMe((0,t.toDisposable)(e.onDblclick$.subscribeEvent(()=>{let t=`${e.oKey}-viewer-dialog`;this._drawingRenderService.previewImage(t,e.getNative().src,e.getNativeSize().width,e.getNativeSize().height)})))}};Q=H([V(0,t.ICommandService),V(1,r.IRenderManagerService),V(2,n.IDrawingManagerService),V(3,a.IDialogService),V(4,n.IImageIoService),V(5,t.IUniverInstanceService),V(6,(0,t.Inject)(Z))],Q);let $=class extends t.Plugin{constructor(e=ee,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},ee,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(I,a)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(q),this._injector.get(U),this._injector.get(X),this._injector.get(Q)}_initDependencies(){[[Z],[q],[U],[X],[Q]].forEach(e=>this._injector.add(e))}};K($,`pluginName`,`UNIVER_DRAWING_UI_PLUGIN`),K($,`packageName`,P),K($,`version`,F),$=H([V(1,(0,t.Inject)(t.Injector)),V(2,t.IConfigService)],$);let qe=e=>{let n=(0,a.useDependency)(t.ICommandService),r=(0,a.useDependency)(t.LocaleService),{drawings:o,alignShow:d}=e,[f,p]=(0,i.useState)(l.default),m=[{label:r.t(`image-panel.align.default`),value:l.default},{options:[{label:r.t(`image-panel.align.left`),value:l.left},{label:r.t(`image-panel.align.center`),value:l.center},{label:r.t(`image-panel.align.right`),value:l.right}]},{options:[{label:r.t(`image-panel.align.top`),value:l.top},{label:r.t(`image-panel.align.middle`),value:l.middle},{label:r.t(`image-panel.align.bottom`),value:l.bottom}]},{options:[{label:r.t(`image-panel.align.horizon`),value:l.horizon},{label:r.t(`image-panel.align.vertical`),value:l.vertical}]}];function h(e){p(e),n.executeCommand(u.id,{alignType:e,drawings:o})}return(0,c.jsxs)(`div`,{className:(0,s.clsx)(`univer-relative univer-w-full`,{"univer-hidden":!d}),children:[(0,c.jsx)(`header`,{className:`
|
|
9
|
-
univer-text-gray-600
|
|
10
|
-
dark:!univer-text-gray-200
|
|
11
|
-
`,children:(0,c.jsx)(`div`,{children:r.t(`image-panel.align.title`)})}),(0,c.jsx)(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:(0,c.jsx)(`div`,{className:`
|
|
12
|
-
univer-w-full univer-text-gray-900
|
|
13
|
-
dark:!univer-text-white
|
|
14
|
-
`,children:(0,c.jsx)(s.Select,{value:f,options:m,onChange:h})})})]})},Je=e=>{let{arrangeShow:r,drawings:o}=e,l=(0,a.useDependency)(t.LocaleService),u=(0,a.useDependency)(n.IDrawingManagerService),d=(0,a.useDependency)(t.ICommandService),f=(0,a.useDependency)(a.ComponentManager),p=f.get(`MoveUpIcon`),m=f.get(`MoveDownIcon`),h=f.get(`TopmostIcon`),g=f.get(`BottomIcon`),[_,v]=(0,i.useState)(o);(0,i.useEffect)(()=>{let e=u.focus$.subscribe(e=>{v(e)});return()=>{e.unsubscribe()}},[]);let b=e=>{d.syncExecuteCommand(y.id,{arrangeType:e,drawings:_})};return(0,c.jsxs)(`div`,{className:(0,s.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!r}),children:[(0,c.jsx)(`header`,{className:`
|
|
15
|
-
univer-text-gray-600
|
|
16
|
-
dark:!univer-text-gray-200
|
|
17
|
-
`,children:(0,c.jsx)(`div`,{children:l.t(`image-panel.arrange.title`)})}),(0,c.jsxs)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:[(0,c.jsxs)(s.Button,{onClick:()=>{b(t.ArrangeTypeEnum.forward)},children:[(0,c.jsx)(p,{}),l.t(`image-panel.arrange.forward`)]}),(0,c.jsxs)(s.Button,{onClick:()=>{b(t.ArrangeTypeEnum.backward)},children:[(0,c.jsx)(m,{}),l.t(`image-panel.arrange.backward`)]}),(0,c.jsxs)(s.Button,{onClick:()=>{b(t.ArrangeTypeEnum.front)},children:[(0,c.jsx)(h,{}),l.t(`image-panel.arrange.front`)]}),(0,c.jsxs)(s.Button,{onClick:()=>{b(t.ArrangeTypeEnum.back)},children:[(0,c.jsx)(g,{}),l.t(`image-panel.arrange.back`)]})]})]})},Ye=e=>{let o=(0,a.useDependency)(t.LocaleService),l=(0,a.useDependency)(r.IRenderManagerService),u=(0,a.useDependency)(n.IDrawingManagerService),d=(0,a.useDependency)(t.ICommandService),f=(0,a.useDependency)(a.ComponentManager),{hasGroup:p,drawings:m}=e,h=f.get(`GroupIcon`),g=f.get(`UngroupIcon`),[_,v]=(0,i.useState)(!1),[y,b]=(0,i.useState)(!0),[x,S]=(0,i.useState)(!0),C=()=>{d.syncExecuteCommand(T.id,{drawings:m})},w=()=>{d.syncExecuteCommand(E.id,{drawings:m})};return(0,i.useEffect)(()=>{let e=m[0];if(e==null)return;let{unitId:n}=e,r=l.getRenderById(n),i=r==null?void 0:r.scene;if(i==null)return;let a=i.getTransformerByCreate(),o=a.clearControl$.subscribe(e=>{e===!0&&v(!1)}),s=a.changeStart$.subscribe(e=>{let{objects:n}=e,r=W(n,u),i=r.filter(e=>(e==null?void 0:e.drawingType)===t.DrawingTypeEnum.DRAWING_GROUP),a=!1,o=!1;r.length>1&&(a=!0),i.length>0&&(o=!0),v(a||o),b(a),S(o)});return()=>{s.unsubscribe(),o.unsubscribe()}},[]),(0,c.jsxs)(`div`,{className:(0,s.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":p===!0&&_===!1||p===!1}),children:[(0,c.jsx)(`header`,{className:`
|
|
18
|
-
univer-text-gray-600
|
|
19
|
-
dark:!univer-text-gray-200
|
|
20
|
-
`,children:(0,c.jsx)(`div`,{children:o.t(`image-panel.group.title`)})}),(0,c.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[(0,c.jsxs)(s.Button,{className:(0,s.clsx)({"univer-hidden":!y}),onClick:C,children:[(0,c.jsx)(h,{}),o.t(`image-panel.group.group`)]}),(0,c.jsxs)(s.Button,{className:(0,s.clsx)({"univer-hidden":!x}),onClick:w,children:[(0,c.jsx)(g,{}),o.t(`image-panel.group.unGroup`)]})]})]})},Xe=[-360,360],Ze=e=>{var o;let l=(0,a.useDependency)(t.LocaleService),u=(0,a.useDependency)(n.IDrawingManagerService),d=(0,a.useDependency)(r.IRenderManagerService),{drawings:f,transformShow:p}=e,m=f[0];if(m==null)return;let h=m.transform;if(h==null)return;let{unitId:g,subUnitId:_,drawingId:v,drawingType:y}=m,b=d.getRenderById(g),x=b==null?void 0:b.scene;if(x==null)return;let S=(o=x.getEngine())==null?void 0:o.activeScene;if(S==null)return;let C=x.getTransformerByCreate(),{width:w=0,height:T=0,left:E=0,top:D=0,angle:O=0}=h,[k,A]=(0,i.useState)(w),[j,M]=(0,i.useState)(T),[N,P]=(0,i.useState)(E),[F,I]=(0,i.useState)(D),[ee,L]=(0,i.useState)(O),[R,te]=(0,i.useState)(C.keepRatio),z=(e,t,n,r)=>{let{width:i,height:a}=S,{ancestorLeft:o,ancestorTop:s}=x,c=e,l=t,u=n,d=r;return e+o<0&&(c=-o),t+s<0&&(l=-s),u=i-c-o,u<20&&(u=20),d=a-l-s,d<20&&(d=20),e+u+o>i&&(c=i-n-o),t+d+s>a&&(l=a-r-s),{limitLeft:c,limitTop:l,limitWidth:u,limitHeight:d}},B=e=>{let{objects:t}=e,n=W(t,u);if(n.length!==1)return;let r=n[0];if(r==null)return;let{transform:i}=r;if(i==null)return;let{width:a,height:o,left:s,top:c,angle:l}=i;a!=null&&A(a),o!=null&&M(o),s!=null&&P(s),c!=null&&I(c),l!=null&&L(l)};(0,i.useEffect)(()=>{let e=[C.changeStart$.subscribe(e=>{B(e)}),C.changing$.subscribe(e=>{B(e)}),C.changeEnd$.subscribe(e=>{B(e)}),u.focus$.subscribe(e=>{if(e.length!==1)return;let t=u.getDrawingByParam(e[0]);if(t==null)return;let n=t.transform;if(n==null)return;let{width:r,height:i,left:a,top:o,angle:s}=n;r!=null&&A(r),i!=null&&M(i),a!=null&&P(a),o!=null&&I(o),s!=null&&L(s)})];return()=>{e.forEach(e=>e.unsubscribe())}},[]);let ne=(0,t.debounce)(e=>{if(e==null)return;let{limitWidth:t,limitHeight:n}=z(N,F,e,j);e=Math.min(e,t);let r={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{width:e}};if(R){let t=e/k*j;if(t=Math.max(t,20),t>n)return;M(t),r.transform.height=t}A(e),u.featurePluginUpdateNotification([r]),C.refreshControls().changeNotification()},300),re=(0,t.debounce)(e=>{if(e==null)return;let{limitHeight:t,limitWidth:n}=z(N,F,k,e);e=Math.min(e,t);let r={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{height:e}};if(R){let t=e/j*k;if(t=Math.max(t,20),t>n)return;A(t),r.transform.width=t}M(e),u.featurePluginUpdateNotification([r]),C.refreshControls().changeNotification()},300),ie=(0,t.debounce)(e=>{if(e==null)return;let{limitLeft:t}=z(e,F,k,j);e=t;let n={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{left:e}};P(e),u.featurePluginUpdateNotification([n]),C.refreshControls().changeNotification()},300),ae=(0,t.debounce)(e=>{if(e==null)return;let{limitTop:t}=z(N,e,k,j);e=t;let n={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{top:e}};I(e),u.featurePluginUpdateNotification([n]),C.refreshControls().changeNotification()},300),oe=e=>{if(e==null)return;let t={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{angle:e}};L(e),u.featurePluginUpdateNotification([t]),C.refreshControls().changeNotification()},se=e=>{te(e),C.keepRatio=e};return(0,c.jsxs)(`div`,{className:(0,s.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!p}),children:[(0,c.jsx)(`header`,{className:`
|
|
21
|
-
univer-text-gray-600
|
|
22
|
-
dark:!univer-text-gray-200
|
|
23
|
-
`,children:(0,c.jsx)(`div`,{children:l.t(`image-panel.transform.title`)})}),(0,c.jsxs)(`div`,{className:`
|
|
24
|
-
univer-grid univer-grid-cols-3 univer-gap-2
|
|
25
|
-
[&>div]:univer-grid [&>div]:univer-gap-2
|
|
26
|
-
`,children:[(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.width`)}),(0,c.jsx)(s.InputNumber,{precision:1,value:k,min:20,onChange:e=>{ne(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.height`)}),(0,c.jsx)(s.InputNumber,{precision:1,value:j,min:20,onChange:e=>{re(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.lock`)}),(0,c.jsx)(`div`,{className:`univer-text-center`,children:(0,c.jsx)(s.Checkbox,{checked:R,onChange:se})})]})]}),(0,c.jsxs)(`div`,{className:`
|
|
27
|
-
univer-grid univer-grid-cols-3 univer-gap-2
|
|
28
|
-
[&>div]:univer-grid [&>div]:univer-gap-2
|
|
29
|
-
`,children:[(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.x`)}),(0,c.jsx)(s.InputNumber,{precision:1,value:N,onChange:e=>{ie(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.y`)}),(0,c.jsx)(s.InputNumber,{precision:1,value:F,onChange:e=>{ae(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.rotate`)}),(0,c.jsx)(s.InputNumber,{precision:1,value:ee,min:Xe[0],max:Xe[1],onChange:oe})]})]})]})},Qe=e=>{let n=(0,a.useDependency)(t.ICommandService),r=(0,a.useDependency)(t.LocaleService),{drawings:o,cropperShow:l}=e;if(o[0]==null)return;let[u,d]=(0,i.useState)(k.FREE),f=(0,i.useRef)(!1),p=[{label:r.t(`image-panel.crop.mode`),value:k.FREE},{label:`1:1`,value:k.R1_1},{label:`16:9`,value:k.R16_9},{label:`9:16`,value:k.R9_16},{label:`5:4`,value:k.R5_4},{label:`4:5`,value:k.R4_5},{label:`4:3`,value:k.R4_3},{label:`3:4`,value:k.R3_4},{label:`3:2`,value:k.R3_2},{label:`2:3`,value:k.R2_3}];(0,i.useEffect)(()=>{let e=n.onCommandExecuted(e=>{if(e.id===O.id){let t=e.params;t!=null&&t.isAuto||(f.current=!1)}});return()=>{e==null||e.dispose()}},[]);function m(e){d(e),f.current&&n.executeCommand(A.id,{cropType:e})}let h=e=>{n.executeCommand(A.id,{cropType:e}),f.current=!0};return(0,c.jsxs)(`div`,{className:(0,s.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!l}),children:[(0,c.jsx)(`header`,{className:`
|
|
30
|
-
univer-text-gray-600
|
|
31
|
-
dark:!univer-text-gray-200
|
|
32
|
-
`,children:(0,c.jsx)(`div`,{children:r.t(`image-panel.crop.title`)})}),(0,c.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[(0,c.jsxs)(s.Button,{onClick:()=>{h(u)},children:[(0,c.jsx)(ae,{}),r.t(`image-panel.crop.start`)]}),(0,c.jsx)(s.Select,{value:u,options:p,onChange:m})]})]})};e.AutoImageCropOperation=A,e.COMPONENT_IMAGE_POPUP_MENU=Ue,e.CancelDrawingGroupOperation=E,e.CloseImageCropOperation=O,e.DRAWING_GROUP_TYPES=w,e.DrawingCommonPanel=e=>{let o=(0,a.useDependency)(n.IDrawingManagerService),l=(0,a.useDependency)(r.IRenderManagerService),u=(0,a.useDependency)(t.LocaleService),{drawings:d,hasArrange:f=!0,hasTransform:p=!0,hasAlign:m=!0,hasCropper:h=!0,hasGroup:g=!0}=e,_=d[0];if(_==null)return;let{unitId:v}=_,y=l.getRenderById(v),b=y==null?void 0:y.scene;if(b==null)return;let x=b.getTransformerByCreate(),[S,C]=(0,i.useState)(!0),[w,T]=(0,i.useState)(!0),[E,D]=(0,i.useState)(!1),[O,k]=(0,i.useState)(!0),[A,j]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let e=x.clearControl$.subscribe(e=>{e===!0&&(C(!1),T(!1),D(!1),k(!1),j(!0))}),t=x.changeStart$.subscribe(e=>{let{objects:t}=e,n=W(t,o);n.length===0?(C(!1),T(!1),D(!1),k(!1),j(!0)):n.length===1?(C(!0),T(!0),D(!1),k(!0),j(!1)):(C(!0),T(!1),D(!0),k(!1),j(!1))}),n=o.focus$.subscribe(e=>{e.length===0?(C(!1),T(!1),D(!1),k(!1),j(!0)):e.length===1?(C(!0),T(!0),D(!1),k(!0),j(!1)):(C(!0),T(!1),D(!0),k(!1),j(!1))});return()=>{t.unsubscribe(),e.unsubscribe(),n.unsubscribe()}},[]),(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`div`,{className:(0,s.clsx)(`univer-h-full`,{"univer-hidden":!A}),children:(0,c.jsx)(`div`,{className:`univer-flex univer-h-full univer-items-center univer-justify-center`,children:(0,c.jsx)(`span`,{children:u.t(`image-panel.null`)})})}),(0,c.jsx)(Je,{arrangeShow:f===!0?S:!1,drawings:d}),(0,c.jsx)(Ze,{transformShow:p===!0?w:!1,drawings:d}),(0,c.jsx)(qe,{alignShow:m===!0?E:!1,drawings:d}),(0,c.jsx)(Qe,{cropperShow:h===!0?O:!1,drawings:d}),(0,c.jsx)(Ye,{hasGroup:g,drawings:d})]})},Object.defineProperty(e,`DrawingRenderService`,{enumerable:!0,get:function(){return Z}}),e.ImageCropperObject=Y,e.ImagePopupMenu=We,e.ImageResetSizeOperation=j,e.OpenImageCropOperation=D,e.SetDrawingAlignOperation=u,e.SetDrawingArrangeOperation=y,e.SetDrawingGroupOperation=T,Object.defineProperty(e,`UniverDrawingUIPlugin`,{enumerable:!0,get:function(){return $}}),e.getCurrentUnitInfo=N,e.getUpdateParams=W,e.insertGroupObject=M});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`@univerjs/core`),require(`@univerjs/drawing`),require(`@univerjs/engine-render`),require(`react`),require(`@univerjs/ui`),require(`rxjs`),require(`@univerjs/design`),require(`react/jsx-runtime`)):typeof define==`function`&&define.amd?define([`exports`,`@univerjs/core`,`@univerjs/drawing`,`@univerjs/engine-render`,`react`,`@univerjs/ui`,`rxjs`,`@univerjs/design`,`react/jsx-runtime`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.UniverDrawingUi={},e.UniverCore,e.UniverDrawing,e.UniverEngineRender,e.React,e.UniverUi,e.rxjs,e.UniverDesign,e.React))})(this,function(e,t,n,r,i,a,o,s,c){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let l=function(e){return e.default=`0`,e.left=`1`,e.center=`2`,e.right=`3`,e.top=`4`,e.middle=`5`,e.bottom=`6`,e.horizon=`7`,e.vertical=`8`,e}({}),u={id:`sheet.operation.set-image-align`,type:t.CommandType.OPERATION,handler:(e,t)=>!0},d={id:`sheet.operation.set-drawing-align-left`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.left})},f={id:`sheet.operation.set-drawing-align-center`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.center})},p={id:`sheet.operation.set-drawing-align-right`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.right})},m={id:`sheet.operation.set-drawing-align-top`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.top})},h={id:`sheet.operation.set-drawing-align-middle`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.middle})},g={id:`sheet.operation.set-drawing-align-bottom`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.bottom})},_={id:`sheet.operation.set-drawing-align-horizon`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.horizon})},v={id:`sheet.operation.set-drawing-align-vertical`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(u.id,{alignType:l.vertical})},y={id:`drawing.operation.set-drawing-arrange`,type:t.CommandType.OPERATION,handler:(e,t)=>{let r=e.get(n.IDrawingManagerService),{arrangeType:i}=t,a=t.drawings||r.getFocusDrawings(),{unitId:o,subUnitId:s}=a[0],c=a.map(e=>e.drawingId);return r.featurePluginOrderUpdateNotification({unitId:o,subUnitId:s,drawingIds:c,arrangeType:i}),!0}},b={id:`drawing.operation.set-drawing-arrange-front`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(y.id,{arrangeType:t.ArrangeTypeEnum.front})},x={id:`drawing.operation.set-drawing-arrange-forward`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(y.id,{arrangeType:t.ArrangeTypeEnum.forward})},S={id:`drawing.operation.set-drawing-arrange-back`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(y.id,{arrangeType:t.ArrangeTypeEnum.back})},C={id:`drawing.operation.set-drawing-arrange-backward`,type:t.CommandType.OPERATION,handler:e=>e.get(t.ICommandService).syncExecuteCommand(y.id,{arrangeType:t.ArrangeTypeEnum.backward})},w=[t.DrawingTypeEnum.DRAWING_IMAGE,t.DrawingTypeEnum.DRAWING_SHAPE,t.DrawingTypeEnum.DRAWING_GROUP],T={id:`drawing.operation.set-drawing-group`,type:t.CommandType.OPERATION,handler:(e,i)=>{let a=e.get(n.IDrawingManagerService),o=i.drawings||a.getFocusDrawings();if(o.length<2||!o.every(e=>w.includes(e.drawingType)))return!1;let{unitId:s,subUnitId:c}=o[0],l=(0,t.generateRandomId)(10),u=(0,r.getGroupState)(0,0,o.map(e=>e.transform||{})),d={unitId:s,subUnitId:c,drawingId:l,drawingType:t.DrawingTypeEnum.DRAWING_GROUP,transform:u,groupBaseBound:{left:u.left,top:u.top,width:u.width,height:u.height}},f=o.map(e=>{let t=e.transform||{left:0,top:0},{unitId:n,subUnitId:r,drawingId:i}=e;return{unitId:n,subUnitId:r,drawingId:i,transform:{...t},groupId:l}});return a.featurePluginGroupUpdateNotification([{parent:d,children:f}]),!0}},E={id:`drawing.operation.cancel-drawing-group`,type:t.CommandType.OPERATION,handler:(e,i)=>{let a=e.get(n.IDrawingManagerService),o=(i.drawings||a.getFocusDrawings()).map(e=>{if(e.drawingType!==t.DrawingTypeEnum.DRAWING_GROUP)return null;let{unitId:n,subUnitId:i,drawingId:o,transform:s={width:0,height:0},groupBaseBound:c}=e;if(s===null)return null;let l=a.getDrawingsByGroup({unitId:n,subUnitId:i,drawingId:o});return l.length===0?null:{parent:e,children:l.map(e=>{let{transform:t}=e,{unitId:n,subUnitId:i,drawingId:a}=e,o=(0,r.transformObjectOutOfGroup)(t||{},s,s.width||0,s.height||0,c);return{unitId:n,subUnitId:i,drawingId:a,transform:{...t,...o},groupId:void 0}})}}).filter(e=>e!==null);return o.length===0?!1:(a.featurePluginUngroupUpdateNotification(o),!0)}},D={id:`sheet.operation.open-image-crop`,type:t.CommandType.OPERATION,handler:(e,t)=>!0},O={id:`sheet.operation.close-image-crop`,type:t.CommandType.OPERATION,handler:(e,t)=>!0},k=function(e){return e.FREE=`0`,e.R1_1=`1`,e.R16_9=`2`,e.R9_16=`3`,e.R5_4=`4`,e.R4_5=`5`,e.R4_3=`6`,e.R3_4=`7`,e.R3_2=`8`,e.R2_3=`9`,e}({}),A={id:`sheet.operation.Auto-image-crop`,type:t.CommandType.OPERATION,handler:(e,t)=>!0},j={id:`sheet.operation.image-reset-size`,type:t.CommandType.OPERATION,handler:(e,t)=>!0};function M(e,t,i,a){let o=a.getDrawingByParam(e);if(o==null)return;let s=(0,n.getDrawingShapeKeyByDrawingSearch)(e),c=i.getObjectIncludeInGroup(s);if(c&&!(c instanceof r.Group))return;if(c!=null){let e=c.getObjects();for(let n of e)if(n.oKey===t.oKey)return;c.addObject(t);return}let l=new r.DrawingGroupObject(s);i.addObject(l,r.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(l),l.addObject(t);let{transform:u,groupBaseBound:d}=o;d&&l.setBaseBound(d),o.groupId&&(l.isInGroup=!0,M({drawingId:o.groupId,unitId:e.unitId,subUnitId:e.subUnitId},l,i,a)),u&&l.transformByState({left:u.left,top:u.top,angle:u.angle,width:u.width,height:u.height})}function N(e,n){let r=n?e.getUnit(n):e.getFocusedUnit();if(r==null)return;let i=r.getUnitId(),a;if(r.type===t.UniverInstanceType.UNIVER_SHEET){var o;a=(o=r.getActiveSheet())==null?void 0:o.getSheetId()}else (r.type===t.UniverInstanceType.UNIVER_DOC||r.type===t.UniverInstanceType.UNIVER_SLIDE)&&(a=i);return{unitId:i,subUnitId:a,current:r}}var P=`@univerjs/drawing-ui`,F=`0.19.0`;let I=`drawing-ui.config`;Symbol(I);let ee={};function L({ref:e,...t}){let{icon:n,id:r,className:a,extend:o,...s}=t,c=`univerjs-icon univerjs-icon-${r} ${a||``}`.trim(),l=(0,i.useRef)(`_${B()}`);return R(n,`${r}`,{defIds:n.defIds,idSuffix:l.current},{ref:e,className:c,...s},o)}function R(e,t,n,r,a){return(0,i.createElement)(e.tag,{key:t,...te(e,n,a),...r},(z(e,n).children||[]).map((r,i)=>R(r,`${t}-${e.tag}-${i}`,n,void 0,a)))}function te(e,t,n){let r={...e.attrs};n!=null&&n.colorChannel1&&r.fill===`colorChannel1`&&(r.fill=n.colorChannel1),e.tag===`mask`&&r.id&&(r.id+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{e===`mask`&&typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))});let{defIds:i}=t;return!i||i.length===0?r:(e.tag===`use`&&r[`xlink:href`]&&(r[`xlink:href`]+=t.idSuffix),Object.entries(r).forEach(([e,n])=>{typeof n==`string`&&(r[e]=n.replace(/url\(#(.*)\)/,`url(#$1${t.idSuffix})`))}),r)}function z(e,t){var n;let{defIds:r}=t;return!r||r.length===0?e:e.tag===`defs`&&(n=e.children)!=null&&n.length?{...e,children:e.children.map(e=>typeof e.attrs.id==`string`&&r&&r.includes(e.attrs.id)?{...e,attrs:{...e.attrs,id:e.attrs.id+t.idSuffix}}:e)}:e}function B(){return Math.random().toString(36).substring(2,8)}L.displayName=`UniverIcon`;let ne={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M14.0045 4.4334C14.8881 4.4334 15.6045 3.71705 15.6045 2.8334C15.6045 1.94974 14.8881 1.2334 14.0045 1.2334H3.70449C2.82084 1.2334 2.10449 1.94974 2.10449 2.8334C2.10449 3.71705 2.82084 4.4334 3.70449 4.4334H14.0045ZM14.4045 2.8334C14.4045 3.05431 14.2254 3.2334 14.0045 3.2334H3.70449C3.48358 3.2334 3.30449 3.05431 3.30449 2.8334C3.30449 2.61248 3.48358 2.4334 3.70449 2.4334H14.0045C14.2254 2.4334 14.4045 2.61249 14.4045 2.8334Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M14.1544 8.5999C15.038 8.5999 15.7544 7.88356 15.7544 6.9999C15.7544 6.11625 15.038 5.3999 14.1544 5.3999H3.85439C2.97074 5.3999 2.25439 6.11625 2.25439 6.9999C2.25439 7.88356 2.97074 8.5999 3.85439 8.5999H14.1544ZM14.5544 6.9999C14.5544 7.22082 14.3753 7.3999 14.1544 7.3999H3.85439C3.63348 7.3999 3.45439 7.22082 3.45439 6.9999C3.45439 6.77899 3.63348 6.5999 3.85439 6.5999H14.1544C14.3753 6.5999 14.5544 6.77899 14.5544 6.9999Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.57975 14.5902L6.58023 12.5907C6.34591 12.3564 6.34591 11.9765 6.58023 11.7421C6.81454 11.5078 7.19444 11.5078 7.42876 11.7421L8.40449 12.7179V10.1664C8.40449 9.83504 8.67312 9.56641 9.00449 9.56641C9.33586 9.56641 9.60449 9.83504 9.60449 10.1664V12.7179L10.5802 11.7421C10.8145 11.5078 11.1944 11.5078 11.4288 11.7421C11.6631 11.9765 11.6631 12.3564 11.4288 12.5907L9.42923 14.5902`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M8.57975 14.5902C8.58121 14.5917 8.58268 14.5931 8.58416 14.5946C8.64077 14.6502 8.70566 14.6923 8.77482 14.7209C8.84557 14.7502 8.92314 14.7664 9.00449 14.7664C9.08585 14.7664 9.16342 14.7502 9.23416 14.7209C9.30332 14.6923 9.36821 14.6502 9.42482 14.5946`}}]},re=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`bottom-icon`,ref:t,icon:ne}))});re.displayName=`BottomIcon`;let ie={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M5.97705 7.51296C5.97705 7.18159 6.24568 6.91296 6.57705 6.91296H8.48632C8.81769 6.91296 9.08632 7.18159 9.08632 7.51296C9.08632 7.84433 8.81769 8.11296 8.48632 8.11296H6.57705C6.24568 8.11296 5.97705 7.84433 5.97705 7.51296Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M6.57705 9.41028C6.24568 9.41028 5.97705 9.67891 5.97705 10.0103C5.97705 10.3416 6.24568 10.6103 6.57705 10.6103H10.8199C11.1512 10.6103 11.4199 10.3416 11.4199 10.0103C11.4199 9.67891 11.1512 9.41028 10.8199 9.41028H6.57705Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.51074 2.37063C3.51074 1.48697 4.22709 0.77063 5.11074 0.77063H9.80318L9.81294 0.770708C9.97168 0.768161 10.1311 0.82824 10.2511 0.95055L14.4317 5.21408C14.5165 5.30049 14.5697 5.406 14.5917 5.51645C14.6041 5.5644 14.6106 5.61467 14.6106 5.66648V11.6406C14.6106 12.5243 13.8943 13.2406 13.0106 13.2406H5.11074C4.22709 13.2406 3.51074 12.5243 3.51074 11.6406V2.37063ZM10.4032 4.66648V2.81964L12.6063 5.06648H10.8032C10.5823 5.06648 10.4032 4.88739 10.4032 4.66648ZM5.11074 1.97063C4.88983 1.97063 4.71074 2.14972 4.71074 2.37063V11.6406C4.71074 11.8615 4.88983 12.0406 5.11074 12.0406H13.0106C13.2316 12.0406 13.4106 11.8615 13.4106 11.6406V6.26648H10.8032C9.91953 6.26648 9.20318 5.55013 9.20318 4.66648V1.97063H5.11074Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M2.58916 6.6741C2.58916 6.34273 2.32053 6.0741 1.98916 6.0741C1.65779 6.0741 1.38916 6.34273 1.38916 6.6741V12.6294C1.38916 14.0653 2.55322 15.2294 3.98916 15.2294H9.41408C9.74545 15.2294 10.0141 14.9607 10.0141 14.6294C10.0141 14.298 9.74545 14.0294 9.41408 14.0294H3.98916C3.21596 14.0294 2.58916 13.4026 2.58916 12.6294V6.6741Z`}}]},ae=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`create-copy-icon`,ref:t,icon:ie}))});ae.displayName=`CreateCopyIcon`;let oe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M7.38125 1.16211C6.49759 1.16211 5.78125 1.87845 5.78125 2.76211V5.6377H2.87783C1.99418 5.6377 1.27783 6.35404 1.27783 7.2377V13.2377C1.27783 14.1214 1.99418 14.8377 2.87783 14.8377H8.87783C9.76149 14.8377 10.4778 14.1214 10.4778 13.2377V10.3621H13.3813C14.2649 10.3621 14.9813 9.64577 14.9813 8.76211V2.76211C14.9813 1.87845 14.2649 1.16211 13.3813 1.16211H7.38125ZM10.4778 9.16211H13.3813C13.6022 9.16211 13.7812 8.98302 13.7812 8.76211V2.76211C13.7812 2.5412 13.6022 2.36211 13.3813 2.36211H7.38125C7.16034 2.36211 6.98125 2.5412 6.98125 2.76211V5.6377H8.87783C9.76149 5.6377 10.4778 6.35404 10.4778 7.2377V9.16211ZM6.98125 6.8377H8.87783C9.09875 6.8377 9.27783 7.01678 9.27783 7.2377V9.16211H7.38125C7.16034 9.16211 6.98125 8.98302 6.98125 8.76211V6.8377ZM5.78125 6.8377V8.76211C5.78125 9.64577 6.49759 10.3621 7.38125 10.3621H9.27783V13.2377C9.27783 13.4586 9.09875 13.6377 8.87783 13.6377H2.87783C2.65692 13.6377 2.47783 13.4586 2.47783 13.2377V7.2377C2.47783 7.01678 2.65692 6.8377 2.87783 6.8377H5.78125Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},se=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`group-icon`,ref:t,icon:oe}))});se.displayName=`GroupIcon`;let ce={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M11.3536 6.14645C11.5488 6.34171 11.5488 6.65829 11.3536 6.85355L8.35355 9.85355C8.15829 10.0488 7.84171 10.0488 7.64645 9.85355L4.64645 6.85355C4.45118 6.65829 4.45118 6.34171 4.64645 6.14645C4.84171 5.95118 5.15829 5.95118 5.35355 6.14645L8 8.79289L10.6464 6.14645C10.8417 5.95118 11.1583 5.95118 11.3536 6.14645Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},le=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`more-down-icon`,ref:t,icon:ce}))});le.displayName=`MoreDownIcon`;let ue={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.25 2.96401C1.25 3.84767 1.96634 4.56401 2.85 4.56401H13.15C14.0337 4.56401 14.75 3.84767 14.75 2.96401C14.75 2.08036 14.0337 1.36401 13.15 1.36401H2.85C1.96635 1.36401 1.25 2.08036 1.25 2.96401ZM2.85 3.36401C2.62909 3.36401 2.45 3.18493 2.45 2.96401C2.45 2.7431 2.62909 2.56401 2.85 2.56401H13.15C13.3709 2.56401 13.55 2.7431 13.55 2.96401C13.55 3.18493 13.3709 3.36401 13.15 3.36401H2.85Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.57564 11.6118C5.80995 11.3774 6.18985 11.3774 6.42417 11.6118L7.3999 12.5875V6.36951C7.3999 6.03814 7.66853 5.76951 7.9999 5.76951C8.33127 5.76951 8.5999 6.03814 8.5999 6.36951V12.5875L9.57564 11.6118C9.80995 11.3774 10.1899 11.3774 10.4242 11.6118C10.6585 11.8461 10.6585 12.226 10.4242 12.4603L8.4324 14.452C8.32324 14.5655 8.16982 14.6362 7.9999 14.6362C7.82998 14.6362 7.67655 14.5655 7.56739 14.452L5.57564 12.4603C5.34132 12.226 5.34132 11.8461 5.57564 11.6118Z`}}]},de=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`move-down-icon`,ref:t,icon:ue}))});de.displayName=`MoveDownIcon`;let fe={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M1.25 13.036C1.25 12.1523 1.96634 11.436 2.85 11.436H13.15C14.0337 11.436 14.75 12.1523 14.75 13.036C14.75 13.9196 14.0337 14.636 13.15 14.636H2.85C1.96635 14.636 1.25 13.9196 1.25 13.036ZM2.85 12.636C2.62909 12.636 2.45 12.8151 2.45 13.036C2.45 13.2569 2.62909 13.436 2.85 13.436H13.15C13.3709 13.436 13.55 13.2569 13.55 13.036C13.55 12.8151 13.3709 12.636 13.15 12.636H2.85Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M5.57564 4.38825C5.80995 4.62256 6.18985 4.62256 6.42417 4.38825L7.3999 3.41251V9.63049C7.3999 9.96186 7.66853 10.2305 7.9999 10.2305C8.33127 10.2305 8.5999 9.96186 8.5999 9.63049V3.41251L9.57564 4.38825C9.80995 4.62256 10.1899 4.62256 10.4242 4.38825C10.6585 4.15393 10.6585 3.77403 10.4242 3.53972L8.4324 1.54796C8.32324 1.43445 8.16982 1.36382 7.9999 1.36382C7.82998 1.36382 7.67655 1.43446 7.56739 1.54797L5.57564 3.53972C5.34132 3.77403 5.34132 4.15393 5.57564 4.38825Z`}}]},pe=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`move-up-icon`,ref:t,icon:fe}))});pe.displayName=`MoveUpIcon`;let me={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M7.82994 1.40913C7.88746 1.35161 7.95376 1.30821 8.02453 1.27893C8.09527 1.24959 8.17285 1.2334 8.2542 1.2334C8.33555 1.2334 8.41313 1.24959 8.48387 1.27893C8.55464 1.30821 8.62094 1.35161 8.67846 1.40913L10.6785 3.40913C10.9128 3.64345 10.9128 4.02335 10.6785 4.25766C10.4441 4.49198 10.0642 4.49198 9.82994 4.25766L8.8542 3.28193V5.8334C8.8542 6.16477 8.58557 6.4334 8.2542 6.4334C7.92283 6.4334 7.6542 6.16477 7.6542 5.8334V3.28193L6.67846 4.25766C6.44415 4.49198 6.06425 4.49198 5.82994 4.25766C5.59562 4.02335 5.59562 3.64345 5.82994 3.40913L7.82994 1.40913Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.50439 9C1.50439 8.11634 2.22074 7.4 3.10439 7.4H13.4044C14.288 7.4 15.0044 8.11634 15.0044 9C15.0044 9.88366 14.2881 10.6 13.4044 10.6H3.1044C2.22074 10.6 1.50439 9.88366 1.50439 9ZM3.10439 8.6C2.88348 8.6 2.70439 8.77909 2.70439 9C2.70439 9.22091 2.88348 9.4 3.1044 9.4H13.4044C13.6253 9.4 13.8044 9.22091 13.8044 9C13.8044 8.77909 13.6253 8.6 13.4044 8.6H3.10439Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M1.6543 13.1665C1.6543 12.2828 2.37064 11.5665 3.2543 11.5665H13.5543C14.438 11.5665 15.1543 12.2828 15.1543 13.1665C15.1543 14.0502 14.438 14.7665 13.5543 14.7665H3.2543C2.37064 14.7665 1.6543 14.0502 1.6543 13.1665ZM3.2543 12.7665C3.03338 12.7665 2.8543 12.9456 2.8543 13.1665C2.8543 13.3874 3.03338 13.5665 3.2543 13.5665H13.5543C13.7752 13.5665 13.9543 13.3874 13.9543 13.1665C13.9543 12.9456 13.7752 12.7665 13.5543 12.7665H3.2543Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},he=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`topmost-icon`,ref:t,icon:me}))});he.displayName=`TopmostIcon`;let ge={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 17 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`currentColor`,d:`M7.46855 2.83731C7.46855 2.61639 7.64764 2.4373 7.86855 2.4373H13.8603C14.0812 2.4373 14.2603 2.61639 14.2603 2.8373V9.5049C14.2603 9.72581 14.0812 9.90489 13.8603 9.90489H12.866C12.5346 9.90489 12.266 10.1735 12.266 10.5049C12.266 10.8363 12.5346 11.1049 12.866 11.1049H13.8603C14.7439 11.1049 15.4603 10.3886 15.4603 9.5049V2.8373C15.4603 1.95365 14.7439 1.2373 13.8603 1.2373H7.86855C6.9849 1.2373 6.26855 1.95365 6.26855 2.83731V3.48688C6.26855 3.81825 6.53718 4.08688 6.86855 4.08688C7.19993 4.08688 7.46855 3.81825 7.46855 3.48688V2.83731Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M3.19888 5.56299C2.31522 5.56299 1.59888 6.27933 1.59888 7.16299V13.163C1.59888 14.0466 2.31522 14.763 3.19888 14.763H9.19888C10.0825 14.763 10.7989 14.0466 10.7989 13.163V7.16299C10.7989 6.27933 10.0825 5.56299 9.19888 5.56299H3.19888ZM2.79888 7.16299C2.79888 6.94207 2.97796 6.76299 3.19888 6.76299H9.19888C9.41979 6.76299 9.59888 6.94207 9.59888 7.16299V13.163C9.59888 13.3839 9.41979 13.563 9.19888 13.563H3.19888C2.97796 13.563 2.79888 13.3839 2.79888 13.163V7.16299Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},_e=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`ungroup-icon`,ref:t,icon:ge}))});_e.displayName=`UngroupIcon`;let ve={tag:`svg`,attrs:{xmlns:`http://www.w3.org/2000/svg`,fill:`none`,viewBox:`0 0 16 16`,width:`1em`,height:`1em`},children:[{tag:`path`,attrs:{fill:`colorChannel1`,d:`M11.0363 12.2367V14.0367C11.0363 14.3681 11.3049 14.6367 11.6363 14.6367C11.9676 14.6367 12.2363 14.3681 12.2363 14.0367V12.2367H14.0364C14.3677 12.2367 14.6364 11.9681 14.6364 11.6367C14.6364 11.3054 14.3677 11.0367 14.0364 11.0367H12.2363V9.23672C12.2363 8.90535 11.9676 8.63672 11.6363 8.63672C11.3049 8.63672 11.0363 8.90535 11.0363 9.23672V11.0367H9.23635C8.90498 11.0367 8.63635 11.3054 8.63635 11.6367C8.63635 11.9681 8.90498 12.2367 9.23635 12.2367H11.0363Z`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M2.56365 1.36377C1.90091 1.36377 1.36365 1.90103 1.36365 2.56377V6.16377C1.36365 6.82651 1.90091 7.36377 2.56365 7.36377H6.16365C6.82639 7.36377 7.36365 6.82651 7.36365 6.16377V2.56377C7.36365 1.90103 6.82639 1.36377 6.16365 1.36377H2.56365ZM6.16365 2.56377H2.56365L2.56365 6.16377H6.16365V2.56377Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M2.56365 8.63647C1.90091 8.63647 1.36365 9.17373 1.36365 9.83647V13.4365C1.36365 14.0992 1.90091 14.6365 2.56365 14.6365H6.16365C6.82639 14.6365 7.36365 14.0992 7.36365 13.4365V9.83647C7.36365 9.17373 6.82639 8.63647 6.16365 8.63647H2.56365ZM6.16365 9.83647H2.56365L2.56365 13.4365H6.16365V9.83647Z`,fillRule:`evenodd`,clipRule:`evenodd`}},{tag:`path`,attrs:{fill:`currentColor`,d:`M9.83635 7.36377C9.17361 7.36377 8.63635 6.82651 8.63635 6.16377V2.56377C8.63635 1.90103 9.17361 1.36377 9.83635 1.36377H13.4364C14.0991 1.36377 14.6364 1.90103 14.6364 2.56377V6.16377C14.6364 6.82651 14.0991 7.36377 13.4364 7.36377H9.83635ZM9.83635 6.16377V2.56377L13.4364 2.56377V6.16377H9.83635Z`,fillRule:`evenodd`,clipRule:`evenodd`}}]},ye=(0,i.forwardRef)(function(e,t){return(0,i.createElement)(L,Object.assign({},e,{id:`autofill-double-icon`,ref:t,icon:ve}))});ye.displayName=`AutofillDoubleIcon`;let be=e=>{let t=e.get(n.IDrawingManagerService);return new o.Observable(e=>{let n=t=>{if(!t||t.length===0||t.length<2)return e.next(!0);e.next(!1)},r=t.focus$.subscribe(t=>{if(!t||t.length===0)return e.next(!0);n(t)});return n(t.getFocusDrawings()),()=>r.unsubscribe()})},xe=`contextMenu.drawing-align`;function Se(e){return{id:xe,type:a.MenuItemType.SUBITEMS,icon:`HorizontallyIcon`,title:`image-panel.align.title`,hidden$:be(e)}}function Ce(){return{id:d.id,type:a.MenuItemType.BUTTON,icon:`LeftJustifyingIcon`,title:`image-panel.align.left`}}function we(){return{id:f.id,type:a.MenuItemType.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.center`}}function Te(){return{id:p.id,type:a.MenuItemType.BUTTON,icon:`RightJustifyingIcon`,title:`image-panel.align.right`}}function Ee(){return{id:m.id,type:a.MenuItemType.BUTTON,icon:`AlignTopIcon`,title:`image-panel.align.top`}}function De(){return{id:h.id,type:a.MenuItemType.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.middle`}}function Oe(){return{id:g.id,type:a.MenuItemType.BUTTON,icon:`AlignBottomIcon`,title:`image-panel.align.bottom`}}function ke(){return{id:_.id,type:a.MenuItemType.BUTTON,icon:`HorizontallyIcon`,title:`image-panel.align.horizon`}}function Ae(){return{id:v.id,type:a.MenuItemType.BUTTON,icon:`VerticalCenterIcon`,title:`image-panel.align.vertical`}}let je=`contextMenu.drawing-arrange`;function Me(){return{id:je,type:a.MenuItemType.SUBITEMS,icon:`TopmostIcon`,title:`image-panel.arrange.title`}}function Ne(){return{id:b.id,type:a.MenuItemType.BUTTON,icon:`TopmostIcon`,title:`image-panel.arrange.front`}}function Pe(){return{id:x.id,type:a.MenuItemType.BUTTON,icon:`MoveUpIcon`,title:`image-panel.arrange.forward`}}function Fe(){return{id:S.id,type:a.MenuItemType.BUTTON,icon:`BottomIcon`,title:`image-panel.arrange.back`}}function Ie(){return{id:C.id,type:a.MenuItemType.BUTTON,icon:`MoveDownIcon`,title:`image-panel.arrange.backward`}}let Le=(e,r)=>{let i=e.get(n.IDrawingManagerService);return new o.Observable(e=>{let n=n=>{if(!n||n.length===0)return e.next(!0);if(r===`group`){if(n.length<2||!n.every(e=>w.includes(e.drawingType)))return e.next(!0)}else if(r===`unGroup`){if(n.filter(e=>e.drawingType===t.DrawingTypeEnum.DRAWING_GROUP).length===0)return e.next(!0)}else if(!n.every(e=>w.includes(e.drawingType)))return e.next(!0);e.next(!1)},a=i.focus$.subscribe(t=>{if(!t||t.length===0)return e.next(!0);n(t)});return n(i.getFocusDrawings()),()=>a.unsubscribe()})},Re=`contextMenu.drawing-group`;function ze(e){return{id:Re,type:a.MenuItemType.SUBITEMS,icon:`GroupIcon`,title:`image-panel.group.title`,hidden$:Le(e)}}function Be(e){return{id:T.id,type:a.MenuItemType.BUTTON,icon:`GroupIcon`,title:`image-panel.group.group`,disabled$:Le(e,`group`)}}function Ve(e){return{id:E.id,type:a.MenuItemType.BUTTON,icon:`UngroupIcon`,title:`image-panel.group.unGroup`,disabled$:Le(e,`unGroup`)}}let He={[a.ContextMenuPosition.DRAWING]:{[a.ContextMenuGroup.OTHERS]:{[Re]:{order:1,menuItemFactory:ze,[T.id]:{order:0,menuItemFactory:Be},[E.id]:{order:1,menuItemFactory:Ve}},[je]:{order:2,menuItemFactory:Me,[b.id]:{order:0,menuItemFactory:Ne},[x.id]:{order:1,menuItemFactory:Pe},[S.id]:{order:2,menuItemFactory:Fe},[C.id]:{order:3,menuItemFactory:Ie}},[xe]:{order:3,menuItemFactory:Se,[d.id]:{order:0,menuItemFactory:Ce},[f.id]:{order:1,menuItemFactory:we},[p.id]:{order:2,menuItemFactory:Te},[m.id]:{order:3,menuItemFactory:Ee},[h.id]:{order:4,menuItemFactory:De},[g.id]:{order:5,menuItemFactory:Oe},[_.id]:{order:6,menuItemFactory:ke},[v.id]:{order:7,menuItemFactory:Ae}}}}},Ue=`COMPONENT_IMAGE_POPUP_MENU`;function We(e){var n;let{popup:r}=e,o=r==null||(n=r.extraProps)==null?void 0:n.menuItems;if(!o)return null;let l=(0,a.useDependency)(t.ICommandService),u=(0,a.useDependency)(t.LocaleService),[d,f]=(0,i.useState)(!1),[p,m]=(0,i.useState)(!1),h=()=>{m(!0)},g=()=>{m(!1)},_=e=>{f(e)},v=e=>{l.executeCommand(e.commandId,e.commandParams),f(!1)},y=d||p;return(0,c.jsx)(`div`,{onMouseEnter:h,onMouseLeave:g,children:(0,c.jsx)(s.DropdownMenu,{align:`start`,items:o.filter(e=>!e.disable).map(e=>({type:`item`,children:u.t(e.label),onSelect:()=>v(e)})),open:d,onOpenChange:_,children:(0,c.jsxs)(`div`,{className:(0,s.clsx)(`univer-flex univer-items-center univer-gap-2 univer-rounded univer-p-1 hover:univer-bg-gray-100 dark:hover:!univer-bg-gray-800`,s.borderClassName,{"univer-bg-gray-100 dark:!univer-bg-gray-800":d,"univer-bg-white dark:!univer-bg-gray-900":!d}),children:[(0,c.jsx)(ye,{className:`univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white`}),y&&(0,c.jsx)(le,{className:`dark:!univer-text-white`})]})})})}function V(e,t){return function(n,r){t(n,r,e)}}function H(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}let U=class extends t.Disposable{constructor(e,t,n){super(),this._componentManager=e,this._commandService=t,this._menuManagerService=n,this._init()}_init(){this._initMenus(),this._initCommands(),this._initComponents()}_initMenus(){this._menuManagerService.mergeMenu(He)}_initCommands(){[D,O,j,u,d,f,p,m,h,g,_,v,A,T,E,y,b,x,S,C].forEach(e=>this.disposeWithMe(this._commandService.registerCommand(e)))}_initComponents(){[[Ue,We],[`BottomIcon`,re],[`GroupIcon`,se],[`MoveDownIcon`,de],[`MoveUpIcon`,pe],[`TopmostIcon`,he],[`UngroupIcon`,_e]].forEach(([e,t])=>{this.disposeWithMe(this._componentManager.register(e,t))})}};U=H([V(0,(0,t.Inject)(a.ComponentManager)),V(1,t.ICommandService),V(2,a.IMenuManagerService)],U);function W(e,n){let r=[];return e.forEach(e=>{let{oKey:i,left:a,top:o,height:s,width:c,angle:l}=e,u=n.getDrawingOKey(i);if(u==null)return r.push(null),!0;let{unitId:d,subUnitId:f,drawingId:p,drawingType:m}=u,h={unitId:d,subUnitId:f,drawingId:p,drawingType:m,transform:{left:a,top:o,height:s,width:c,angle:l}};m===t.DrawingTypeEnum.DRAWING_IMAGE&&(h.srcRect=e.srcRect),r.push(h)}),r}function G(e){"@babel/helpers - typeof";return G=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},G(e)}function Ge(e,t){if(G(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(G(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function Ke(e){var t=Ge(e,`string`);return G(t)==`symbol`?t:t+``}function K(e,t,n){return(t=Ke(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}let q=class extends t.Disposable{constructor(e,t,n,r){super(),this._currentUniverService=e,this._commandService=t,this._renderManagerService=n,this._drawingManagerService=r,K(this,`_sceneListenerOnDrawingMap`,new WeakSet),this._initialize()}dispose(){super.dispose()}_initialize(){this._recoveryImages(),this._drawingAddListener(),this._drawingRemoveListener(),this._drawingUpdateListener(),this._commandExecutedListener(),this._drawingArrangeListener(),this._drawingGroupListener(),this._drawingRefreshListener(),this._drawingVisibleListener()}_recoveryImages(){let e=this._drawingManagerService.drawingManagerData,t=N(this._currentUniverService);if(t==null)return;let{unitId:n,subUnitId:r}=t;Object.keys(e).forEach(t=>{Object.keys(e[t]).forEach(i=>{let a=e[t][i].data;a==null||t!==n||i!==r||Object.keys(a).forEach(e=>{a[e]&&this._insertDrawing([{unitId:t,subUnitId:i,drawingId:e}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===u.id){let t=e.params;if(t==null)return;this._drawingAlign(t)}}))}_drawingGroupListener(){this.disposeWithMe(this._drawingManagerService.group$.subscribe(e=>{this._groupDrawings(e)})),this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe(e=>{this._ungroupDrawings(e)}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_groupDrawings(e){e.forEach(e=>{this._groupDrawing(e)})}_groupDrawing(e){let{parent:t,children:i}=e,{unitId:a,subUnitId:o,drawingId:s}=t,c=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(c==null)return;let{scene:l,transformer:u}=c;this._commandService.syncExecuteCommand(O.id);let d=[];if(i.forEach(e=>{let t=(0,n.getDrawingShapeKeyByDrawingSearch)(e),i=l.getObjectIncludeInGroup(t);if(i==null||d.includes(i))return;d.push(i);let{transform:a}=e;a!=null&&(i.classType===r.RENDER_CLASS_TYPE.GROUP?i.transformByState({left:a.left,top:a.top}):i.transformByState(a))}),d.length===0)return;let f=new r.DrawingGroupObject((0,n.getDrawingShapeKeyByDrawingSearch)({unitId:a,subUnitId:o,drawingId:s}));l.addObject(f,r.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(f),f.addObjects(...d),t.groupBaseBound&&f.setBaseBound(t.groupBaseBound),t.groupId&&(f.isInGroup=!0,M({drawingId:t.groupId,unitId:a,subUnitId:o},f,l,this._drawingManagerService)),t.transform&&f.transformByState({left:t.transform.left,top:t.transform.top,width:t.transform.width,height:t.transform.height,angle:t.transform.angle}),u.clearSelectedObjects(),u.setSelectedControl(f)}_ungroupDrawings(e){e.forEach(e=>{this._ungroupDrawing(e)})}_ungroupDrawing(e){let{parent:t,children:i}=e,a=this._getSceneAndTransformerByDrawingSearch(t.unitId);if(a==null)return;let{scene:o,transformer:s}=a;i.forEach(e=>{let t=(0,n.getDrawingShapeKeyByDrawingSearch)(e),i=o.getObjectIncludeInGroup(t);if(i==null)return!0;if(i==null)return;let{transform:a}=e;a!=null&&(i.classType===r.RENDER_CLASS_TYPE.GROUP?i.transformByState({left:a.left,top:a.top}):i.transformByState(a))});let c=(0,n.getDrawingShapeKeyByDrawingSearch)(t),l=o.getObject(c),{width:u,height:d}=l;l.getObjects().forEach(e=>{l.removeSelfObjectAndTransform(e.oKey,u,d)}),l.dispose(),s.clearSelectedObjects()}_drawingAlign(e){let{alignType:t}=e,n=e.drawings||this._drawingManagerService.getFocusDrawings();if(t===l.default)return;let r=[],i=1/0,a=1/0,o=-1/0,s=-1/0,c=0;n.forEach(e=>{let{unitId:t,subUnitId:n,drawingId:l,drawingType:u}=e,d=this._drawingManagerService.getDrawingByParam({unitId:t,subUnitId:n,drawingId:l});if(d==null||d.transform==null)return;r.push({unitId:t,subUnitId:n,drawingId:l,drawingType:u,transform:d.transform});let{left:f=0,top:p=0,width:m=0,height:h=0}=d.transform;i=Math.min(i,f),a=Math.min(a,p),o=Math.max(o,f+m),s=Math.max(s,p+h),c++}),c!==0&&(this._sortDrawingTransform(r,t),this._applyAlignType(r,t,i,a,o,s,c))}_applyAlignType(e,t,n,r,i,a,o){let s=Math.round((i-n)/o*10)/10,c=Math.round((a-r)/o*10)/10,u=[],d=this._getSceneAndTransformerByDrawingSearch(e[0].unitId);if(d==null)return;let{scene:f,transformer:p}=d;e.forEach((e,o)=>{let{unitId:d,subUnitId:f,drawingId:p,transform:m,drawingType:h}=e,{left:g=0,top:_=0,width:v=0,height:y=0}=m,b=g,x=_;switch(t){case l.left:b=n;break;case l.center:b=n+(i-n)/2-v/2;break;case l.right:b=i-v;break;case l.top:x=r;break;case l.middle:x=r+(a-r)/2-y/2;break;case l.bottom:x=a-y;break;case l.horizon:b=n+s*o;break;case l.vertical:x=r+c*o;break;default:break}(b!==g||x!==_)&&u.push({unitId:d,subUnitId:f,drawingId:p,drawingType:h,transform:{left:b,top:x}})}),this._drawingManagerService.featurePluginUpdateNotification(u),p.refreshControls().changeNotification()}_sortDrawingTransform(e,t){e.sort((e,n)=>{let r=e.transform,i=n.transform,{left:a=0,top:o=0,width:s=0,height:c=0}=r,{left:u=0,top:d=0,width:f=0,height:p=0}=i;switch(t){case l.left:return a-u;case l.center:return a+s/2-(u+f/2);case l.right:return a+s-(u+f);case l.top:return o-d;case l.middle:return o+c/2-(d+p/2);case l.bottom:return o+c-(d+p);case l.horizon:return a+s/2-(u+f/2);case l.vertical:return o+c/2-(d+p/2);default:return 0}})}_drawingArrangeListener(){this.disposeWithMe(this._drawingManagerService.order$.subscribe(e=>{this._drawingArrange(e)}))}_drawingArrange(e){let{unitId:t,subUnitId:r,drawingIds:i}=e,a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{scene:o}=a;i.forEach(e=>{let i=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:r,drawingId:e}),a=o.fuzzyMathObjects(i,!0);if(a==null||a.length===0)return;let s=this._drawingManagerService.getDrawingOrder(t,r).indexOf(e);for(let e of a)e.setProps({zIndex:s}),e.makeDirty()})}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(e=>{this._insertDrawing(e)}))}_insertDrawing(e){let t=[];e.forEach(e=>{let{unitId:n}=e;if(this._drawingManagerService.getDrawingByParam(e)==null)return;let r=this._getSceneAndTransformerByDrawingSearch(n);if(r==null)return;let{scene:i}=r;t.includes(i)||t.push(i)}),t.forEach(e=>{this._sceneListenerOnDrawingMap.has(e)||(this._addListenerOnDrawing(e),this._sceneListenerOnDrawingMap.add(e))})}_drawingRemoveListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:r,drawingId:i}=e,a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let{scene:o}=a,s=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:r,drawingId:i}),c=o.fuzzyMathObjects(s,!0);if(c.length>0){var l;for(let e of c)e.dispose();(l=o.getTransformer())==null||l.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{var t;let{unitId:r,subUnitId:i,drawingId:a}=e,o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let{transform:s,drawingType:c}=o,l=this._getSceneAndTransformerByDrawingSearch(r);if(l==null)return;let{scene:u,transformer:d}=l;if(s==null)return!0;let{left:f=0,top:p=0,width:m=0,height:h=0,angle:g=0,flipX:_=!1,flipY:v=!1,skewX:y=0,skewY:b=0}=s,x=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:r,subUnitId:i,drawingId:a}),S=u.getObject(x);if(S==null)return!0;S.transformByState({left:f,top:p,width:m,height:h,angle:g,flipX:_,flipY:v,skewX:y,skewY:b}),(t=u.getTransformer())==null||t.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:r,drawingId:i}=e,a=this._getSceneAndTransformerByDrawingSearch(t);if(a==null)return;let o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let{transform:s}=o,{scene:c}=a,l=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:r,drawingId:i}),u=c.getObject(l);if(u==null||s==null)return!0;let{left:d=0,top:f=0,width:p=0,height:m=0,angle:h=0,flipX:g=!1,flipY:_=!1,skewX:v=0,skewY:y=0}=s;u.transformByState({left:d,top:f,width:p,height:m,angle:h,flipX:g,flipY:_,skewX:v,skewY:y})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(e=>{e.forEach(e=>{let{unitId:t,subUnitId:r,drawingId:i,visible:a}=e,o=this._getSceneAndTransformerByDrawingSearch(t);if(o==null)return;let{scene:s}=o,c=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:t,subUnitId:r,drawingId:i}),l=s.getObject(c);if(l==null)return!0;a?l.show():l.hide()})}))}_filterUpdateParams(e,n){return e.filter((e,r)=>{if(e==null)return!1;let{transform:i}=e;return(0,t.checkIfMove)(i,n==null?void 0:n[r])})}_addListenerOnDrawing(e){let i=e.getTransformerByCreate(),a=null;this.disposeWithMe((0,t.toDisposable)(i.changeStart$.subscribe(e=>{let{objects:t}=e,i=Array.from(t.values()),o=[];a=i.map(e=>{let{left:t,top:n,height:i,width:a,angle:s,oKey:c,isInGroup:l}=e,u=this._drawingManagerService.getDrawingOKey(c);if(l||e instanceof r.Group){let t=e.ancestorGroup;if(t==null&&e instanceof r.Group&&(t=e),t==null)return null;let n=this._drawingManagerService.getDrawingOKey(t.oKey);if(n){let{unitId:e,subUnitId:r,drawingId:i}=n;o.push({unitId:e,subUnitId:r,drawingId:i});let{left:a,top:s,height:c,width:l,angle:u}=t;return{left:a,top:s,height:c,width:l,angle:u}}}else if(u!=null){let{unitId:e,subUnitId:r,drawingId:c}=u;return o.push({unitId:e,subUnitId:r,drawingId:c}),{left:t,top:n,height:i,width:a,angle:s}}return null}).filter(e=>e!=null),o.length>0?this._commandService.syncExecuteCommand(n.SetDrawingSelectedOperation.id,o):this._commandService.syncExecuteCommand(n.SetDrawingSelectedOperation.id,[])}))),this.disposeWithMe((0,t.toDisposable)(i.changeEnd$.subscribe(e=>{let{objects:t}=e,n=this._filterUpdateParams(W(t,this._drawingManagerService),a);n.length>0&&this._drawingManagerService.featurePluginUpdateNotification(n)})))}};q=H([V(0,t.IUniverInstanceService),V(1,t.ICommandService),V(2,r.IRenderManagerService),V(3,n.IDrawingManagerService)],q);var J=function(e){return e[e.RECT=0]=`RECT`,e[e.PATH=1]=`PATH`,e}(J||{}),Y=class extends r.Shape{constructor(e,t){t==null&&(t={}),t.transformerConfig={keepRatio:!1,isCropper:!0,anchorFill:`rgb(0, 0, 0)`,anchorStroke:`rgb(255, 255, 255)`,anchorSize:24},super(e,t),K(this,`_srcRect`,void 0),K(this,`_prstGeom`,void 0),K(this,`_applyTransform`,void 0),K(this,`_dragPadding`,8),K(this,`_cacheCanvas`,void 0),t!=null&&t.srcRect&&(this._srcRect=t.srcRect),t!=null&&t.prstGeom&&(this._prstGeom=t.prstGeom),t!=null&&t.applyTransform&&(this._applyTransform=t.applyTransform),t!=null&&t.dragPadding&&(this._dragPadding=t.dragPadding),this._applyProps()}refreshSrcRect(e,t){this._srcRect=e,this._applyTransform=t,this._applyProps()}get srcRect(){return this._srcRect}dispose(){var e;super.dispose(),(e=this._cacheCanvas)==null||e.dispose(),this._srcRect=null}isHit(e){let t=this.getInverseCoord(e);return t.x>=-this.strokeWidth/2&&t.x<=this.width+this.strokeWidth/2&&t.y>=-this.strokeWidth/2&&t.y<=this.height+this.strokeWidth/2&&!this._inSurround(t)}_inSurround(e){let t=this._dragPadding;return e.x>=t-this.strokeWidth/2&&e.x<=this.width+this.strokeWidth/2-t&&e.y>=t-this.strokeWidth/2&&e.y<=this.height+this.strokeWidth/2-t}render(e,t){return this.visible?(e.save(),this._draw(e),e.restore(),this.makeDirty(!1),this):(this.makeDirty(!1),this)}_draw(e){var t,n;let{width:i,height:a}=this.getScene().getEngine();this._initialCacheCanvas(),(t=this._cacheCanvas)==null||t.clear();let o=(n=this._cacheCanvas)==null?void 0:n.getContext();o!=null&&(o.save(),r.Rect.drawWith(o,{left:0,top:0,width:i,height:a,fill:`rgba(0, 0, 0, 0.5)`}),o.setTransform(e.getTransform()),this._clipForApplyObject(o),this._applyCache(e),o.restore())}_clipForApplyObject(e){let t=J.RECT;if(this._prstGeom!=null&&(t=J.PATH),e.globalCompositeOperation=`destination-out`,e.beginPath(),t===J.RECT){let t=this.transform.getMatrix();e.transform(t[0],t[1],t[2],t[3],t[4],t[5]),e.rect(0,0,this.width,this.height),e.fill()}}_applyProps(){if(this._applyTransform==null)return;let e=0,t=0,n=0,r=0,{left:i=0,top:a=0,width:o=0,height:s=0,angle:c}=this._applyTransform;if(this._srcRect!=null){let{left:i=0,top:a=0,right:o=0,bottom:s=0}=this._srcRect;e=i,t=a,n=o,r=s}let l=i+e,u=a+t;this.transformByState({left:l,top:u,width:i+o-n-l,height:a+s-r-u,angle:c})}_applyCache(e){if(!e||this._cacheCanvas==null)return;let t=this._cacheCanvas.getContext();t.save(),e.save(),e.setTransform(1,0,0,1,0,0),t.setTransform(1,0,0,1,0,0),e.drawImage(this._cacheCanvas.getCanvasEle(),0,0),e.restore(),t.restore()}_initialCacheCanvas(){if(this._cacheCanvas!=null)return;let e=this.getScene();if(e==null)return;this._cacheCanvas=new r.Canvas;let t=e.getEngine();this._cacheCanvas.setSize(t.width,t.height),t.onTransformChange$.subscribeEvent(()=>{var e;(e=this._cacheCanvas)==null||e.setSize(t.width,t.height),this.makeDirty(!0)})}};let X=class extends t.Disposable{constructor(e,t,n,r,i,a){super(),this._commandService=e,this._drawingManagerService=t,this._renderManagerService=n,this._univerInstanceService=r,this._messageService=i,this._localeService=a,K(this,`_sceneListenerOnImageMap`,new WeakSet),this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==A.id)return;let t=e.params;if(t==null)return;let{cropType:i}=t,a=this._drawingManagerService.getFocusDrawings();if(a.length!==1)return;let{unitId:o,subUnitId:c,drawingId:l}=a[0],u=this._renderManagerService.getRenderById(o),d=u==null?void 0:u.scene;if(d==null)return!0;this._searchCropObject(d)!=null&&this._commandService.syncExecuteCommand(O.id,{isAuto:!0});let f=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:o,subUnitId:c,drawingId:l}),p=d.getObject(f);if(!(p instanceof r.Image)){this._messageService.show({type:s.MessageType.Error,content:this._localeService.t(`image-cropper.error`)});return}p!=null&&(this._updateCropperObject(i,p),this._commandService.executeCommand(D.id,{unitId:o,subUnitId:c,drawingId:l}))}))}_calculateSrcRectByRatio(e,t,n,i,a,o){let s=n/i,c=a/o,l=n,u=i;s>c?l=i*c:u=n/c;let d=(n-l)/2,f=(i-u)/2;return{left:(0,r.precisionTo)(d,1),top:(0,r.precisionTo)(f,1),right:(0,r.precisionTo)(n-(d+l),1),bottom:(0,r.precisionTo)(i-(f+u),1)}}_updateCropperObject(e,t){let{left:n,top:r,width:i,height:a}=t.calculateTransformWithSrcRect(),o;switch(e){case k.R1_1:o=this._calculateSrcRectByRatio(n,r,i,a,1,1);break;case k.R16_9:o=this._calculateSrcRectByRatio(n,r,i,a,16,9);break;case k.R9_16:o=this._calculateSrcRectByRatio(n,r,i,a,9,16);break;case k.R5_4:o=this._calculateSrcRectByRatio(n,r,i,a,5,4);break;case k.R4_5:o=this._calculateSrcRectByRatio(n,r,i,a,4,5);break;case k.R4_3:o=this._calculateSrcRectByRatio(n,r,i,a,4,3);break;case k.R3_4:o=this._calculateSrcRectByRatio(n,r,i,a,3,4);break;case k.R3_2:o=this._calculateSrcRectByRatio(n,r,i,a,3,2);break;case k.R2_3:o=this._calculateSrcRectByRatio(n,r,i,a,2,3);break;case k.FREE:default:break}if(o==null)return;t.setSrcRect(o);let{left:s=0,top:c=0,bottom:l=0,right:u=0}=o;t.transformByStateCloseCropper({left:n+s,top:r+c,width:i-u-s,height:a-l-c})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==D.id)return;let t=e.params;if(t==null)return;let{unitId:i,subUnitId:a,drawingId:o}=t,c=this._renderManagerService.getRenderById(i),l=c==null?void 0:c.scene;if(l==null)return!0;if(this._sceneListenerOnImageMap.has(l)||(this._addListenerOnImage(l),this._sceneListenerOnImageMap.add(l)),this._drawingManagerService.getDrawingByParam({unitId:i,subUnitId:a,drawingId:o})==null)return;let u=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:i,subUnitId:a,drawingId:o}),d=l.getObject(u);if(d==null)return;if(!(d instanceof r.Image)){this._messageService.show({type:s.MessageType.Error,content:this._localeService.t(`image-cropper.error`)});return}let f=l.getTransformer();f==null||f.clearControls();let p=new Y(`${u}-crop`,{srcRect:d.srcRect,prstGeom:d.prstGeom,applyTransform:d.calculateTransformWithSrcRect()});l.addObject(p,d.getLayerIndex()+1).attachTransformerTo(p),f==null||f.createControlForCopper(p),this._addHoverForImageCopper(p),d.openRenderByCropper(),f==null||f.refreshControls(),p.makeDirty(!0),this._commandService.syncExecuteCommand(n.SetDrawingSelectedOperation.id,[{unitId:i,subUnitId:a,drawingId:o}])}))}_searchCropObject(e){let t=e.getAllObjectsByOrder();for(let e of t)if(e instanceof Y)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id!==O.id)return;let t=this._univerInstanceService.getFocusedUnit();if(t==null)return;let n=t.getUnitId(),r=this._renderManagerService.getRenderById(n),i=r==null?void 0:r.scene;if(i==null)return!0;let a=this._searchCropObject(i);if(a==null)return;let o=this._getApplyObjectByCropObject(a);if(o==null)return;let s=i.getTransformerByCreate();s.detachFrom(a),s.clearCopperControl();let c=this._getSrcRectByTransformState(o,a),l=this._drawingManagerService.getDrawingOKey(o.oKey);if(l!=null){let{left:e,top:t,height:n,width:r}=a;this._drawingManagerService.featurePluginUpdateNotification([{...l,transform:{...l.transform,left:e,top:t,height:n,width:r},srcRect:c.srcRectAngle}])}o.setSrcRect({...c.srcRectAngle}),o.closeRenderByCropper(),o.makeDirty(!0),a==null||a.dispose()}));let e=this._univerInstanceService.getCurrentTypeOfUnit$(t.UniverInstanceType.UNIVER_SHEET).pipe((0,o.switchMap)(e=>e?e.activeSheet$:(0,o.of)(null)));this.disposeWithMe(e.subscribe(()=>{this._commandService.syncExecuteCommand(O.id)}))}_getApplyObjectByCropObject(e){let t=e.oKey,n=t.slice(0,t.length-5),r=e.getScene();if(!r)return null;let i=r.getObject(n);return i==null?null:i}_addListenerOnImage(e){let n=e.getTransformerByCreate(),r=null;this.disposeWithMe(n.changeStart$.subscribe(e=>{let{objects:t}=e,i=t.values().next().value;if(i==null||!(i instanceof Y))return;let{left:a,top:o,height:s,width:c,angle:l}=i;r={left:a,top:o,height:s,width:c,angle:l},n.clearCopperControl()})),this.disposeWithMe(n.changeEnd$.subscribe(e=>{let{objects:i}=e,a=i.values().next().value;if(a==null||!(a instanceof Y))return;let{left:o,top:s,height:c,width:l,angle:u}=a;if(!(0,t.checkIfMove)({left:o,top:s,height:c,width:l,angle:u},r))return;let d=this._getApplyObjectByCropObject(a);if(d==null)return;let f=this._getSrcRectByTransformState(d,a);a.refreshSrcRect(f.srcRect,d.getState()),n.createControlForCopper(a)})),this._endCropListener(e)}_addHoverForImageCopper(e){this.disposeWithMe(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=r.CURSOR_TYPE.MOVE})),this.disposeWithMe(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=r.CURSOR_TYPE.DEFAULT}))}_endCropListener(e){let t=e.getTransformerByCreate();this.disposeWithMe(t.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(O.id)}))}_getSrcRectByTransformState(e,t){let{left:n,top:i,height:a,width:o,strokeWidth:s,angle:c}=t,{left:l,top:u,width:d,height:f,angle:p,strokeWidth:m}=e,h=n-l,g=i-u,_={left:h,top:g,right:d-h-o,bottom:f-g-a},v={..._};if(p!==0){let e=new r.Vector2(n+o/2,i+a/2),t=new r.Vector2(d/2+l,f/2+u),s=new r.Vector2(l,u);s.rotateByPoint((0,r.degToRad)(p),t);let c=s.clone();c.rotateByPoint((0,r.degToRad)(-p),e);let m=n-c.x,h=i-c.y;v.left=m,v.top=h,v.right=d-m-o,v.bottom=f-h-a}return{srcRect:_,srcRectAngle:v}}};X=H([V(0,t.ICommandService),V(1,n.IDrawingManagerService),V(2,r.IRenderManagerService),V(3,t.IUniverInstanceService),V(4,a.IMessageService),V(5,(0,t.Inject)(t.LocaleService))],X);let Z=class{constructor(e,t,n,r,i){this._drawingManagerService=e,this._imageIoService=t,this._galleryService=n,this._urlImageService=r,this._univerInstanceService=i}async renderImages(e,i){let{transform:a,drawingType:o,source:s,imageSourceType:c,srcRect:l,prstGeom:u,groupId:d,unitId:f,subUnitId:p,drawingId:m,isMultiTransform:h,transforms:g}=e;if(o!==t.DrawingTypeEnum.DRAWING_IMAGE||!this._drawingManagerService.getDrawingVisible()||this._univerInstanceService.getUnitType(f)===t.UniverInstanceType.UNIVER_SHEET&&p!==this._getActiveSheetId()||a==null)return;let _=h&&g?g:[a],v=[];for(let e of _){let{left:t,top:a,width:o,height:g,angle:y,flipX:b,flipY:x,skewX:S,skewY:C}=e,w=_.indexOf(e),T=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:f,subUnitId:p,drawingId:m},h?w:void 0),E=i.getObject(T);if(E!=null){E.transformByState({left:t,top:a,width:o,height:g,angle:y,flipX:b,flipY:x,skewX:S,skewY:C});continue}let D=this._drawingManagerService.getDrawingOrder(f,p),O=D.indexOf(m),k={...e,zIndex:O===-1?D.length-1:O},A=this._imageIoService.getImageSourceCache(s,c),j=!1;if(A!=null)k.image=A;else if(c===n.ImageSourceType.UUID)try{k.url=await this._imageIoService.getImage(s)}catch(e){console.error(e);continue}else if(c===n.ImageSourceType.URL){try{k.url=await this._urlImageService.getImage(s)}catch(e){console.error(e),k.url=s}j=!0}else k.url=s,j=!0;if(i.getObject(T))continue;k.printable=!0;let N=new r.Image(T,k);j&&this._imageIoService.addImageSourceCache(s,c,N.getNative()),i.addObject(N,r.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&i.attachTransformerTo(N),d&&M({drawingId:d,unitId:f,subUnitId:p},N,i,this._drawingManagerService),u!=null&&N.setPrstGeom(u),l!=null&&N.setSrcRect(l),v.push(N)}return v}_getActiveSheetId(){var e;return(e=this._univerInstanceService.getCurrentUnitOfType(t.UniverInstanceType.UNIVER_SHEET))==null||(e=e.getActiveSheet())==null?void 0:e.getSheetId()}renderFloatDom(e,i){let{transform:a,drawingType:o,groupId:s,unitId:c,subUnitId:l,drawingId:u,isMultiTransform:d,transforms:f}=e;if(o!==t.DrawingTypeEnum.DRAWING_DOM||!this._drawingManagerService.getDrawingVisible()||a==null)return;let p=d&&f?f:[a],m=[];for(let t of p){let{left:a,top:o,width:f,height:h,angle:g,flipX:_,flipY:v,skewX:y,skewY:b}=t,x=p.indexOf(t),S=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:c,subUnitId:l,drawingId:u},d?x:void 0),C=i.getObject(S);if(C!=null){C.transformByState({left:a,top:o,width:f,height:h,angle:g,flipX:_,flipY:v,skewX:y,skewY:b});continue}let w=this._drawingManagerService.getDrawingOrder(c,l),T=w.indexOf(u),E={...t,zIndex:T===-1?w.length-1:T};if(i.getObject(S))continue;E.printable=!1;let D=new r.Rect(S,E);this._drawingManagerService.getDrawingVisible()&&(i.addObject(D,r.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&e.allowTransform!==!1&&i.attachTransformerTo(D),s&&M({drawingId:s,unitId:c,subUnitId:l},D,i,this._drawingManagerService),m.push(D))}return m}renderDrawing(e,n){let r=this._drawingManagerService.getDrawingByParam(e);if(r!=null)switch(r.drawingType){case t.DrawingTypeEnum.DRAWING_IMAGE:return this.renderImages(r,n);default:}}previewImage(e,t,n,r){this._galleryService.open({images:[t],onOpenChange:e=>{e||this._galleryService.close()}})}_adjustImageSize(e,t,n,r){if(e<=n&&t<=r)return{width:e,height:t};let i=n/e,a=r/t,o=Math.min(i,a);return{width:Math.floor(e*o),height:Math.floor(t*o)}}};Z=H([V(0,n.IDrawingManagerService),V(1,n.IImageIoService),V(2,a.IGalleryService),V(3,t.IURLImageService),V(4,t.IUniverInstanceService)],Z);let Q=class extends t.Disposable{constructor(e,t,n,r,i,a,o){super(),this._commandService=e,this._renderManagerService=t,this._drawingManagerService=n,this._dialogService=r,this._imageIoService=i,this._currentUniverService=a,this._drawingRenderService=o,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(e=>{if(e.id===j.id){let t=e.params;if(t==null)return;this._resetImageSize(t)}}))}_getSceneAndTransformerByDrawingSearch(e){if(e==null)return;let t=this._renderManagerService.getRenderById(e),n=t==null?void 0:t.scene;return n==null?null:{scene:n,transformer:n.getTransformerByCreate()}}_resetImageSize(e){let r=[],i=[];e.forEach(e=>{let{unitId:a,subUnitId:o,drawingId:s}=e,c=this._getSceneAndTransformerByDrawingSearch(a);if(c==null)return;let{scene:l}=c,u=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:a,subUnitId:o,drawingId:s}),d=l.getObject(u);if(d==null)return!0;let f=this._drawingManagerService.getDrawingByParam(e);if(f==null)return!0;if(f.drawingType!==t.DrawingTypeEnum.DRAWING_IMAGE)return;d.resetSize();let{width:p,height:m}=d.getNativeSize();i.includes(l)===!1&&i.push(l),r.push({...f,transform:{...f.transform,height:m,width:p,angle:0},srcRect:null,prstGeom:null})}),this._drawingManagerService.featurePluginUpdateNotification(r),i.forEach(e=>{e.getTransformerByCreate().refreshControls().changeNotification()}),this._commandService.syncExecuteCommand(n.SetDrawingSelectedOperation.id,e)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.pipe((0,o.bufferTime)(33),(0,o.filter)(e=>e.length>0),(0,o.map)(e=>e.flat()),(0,o.map)(e=>{let t=new Map;for(let n of e)t.set(`${n.unitId}|${n.subUnitId}|${n.drawingId}`,n);return[...t.values()]}),(0,o.filter)(e=>e.length>0)).subscribe(e=>{this._insertImages(e)}))}_insertImages(e){e.forEach(async e=>{var t;let{unitId:n,subUnitId:r}=e,i=this._getSceneAndTransformerByDrawingSearch(n),a=(t=N(this._currentUniverService,n))==null?void 0:t.subUnitId;if(i==null||a!==r)return;let o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let s=await this._drawingRenderService.renderImages(o,i.scene);if(this._drawingManagerService.refreshTransform([o]),!(s==null||s.length===0))for(let e of s)this._addHoverForImage(e),this._addDialogForImage(e)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(e=>{e.forEach(e=>{let{unitId:r,subUnitId:i,drawingId:a}=e,o=this._drawingManagerService.getDrawingByParam(e);if(o==null)return;let{transform:s,drawingType:c,srcRect:l,prstGeom:u,source:d,imageSourceType:f}=o;if(c!==t.DrawingTypeEnum.DRAWING_IMAGE)return;let p=this._getSceneAndTransformerByDrawingSearch(r);if(p==null)return;let{scene:m,transformer:h}=p;if(s==null)return!0;let g=(0,n.getDrawingShapeKeyByDrawingSearch)({unitId:r,subUnitId:i,drawingId:a}),_=m.getObject(g);if(_==null)return!0;_.setSrcRect(l),_.setPrstGeom(u),d!=null&&d.length>0&&(f===t.ImageSourceType.BASE64||f===t.ImageSourceType.URL)&&_.changeSource(d)})}))}_addHoverForImage(e){this.disposeWithMe((0,t.toDisposable)(e.onPointerEnter$.subscribeEvent(()=>{e.cursor=r.CURSOR_TYPE.GRAB}))),this.disposeWithMe((0,t.toDisposable)(e.onPointerLeave$.subscribeEvent(()=>{e.cursor=r.CURSOR_TYPE.DEFAULT})))}_addDialogForImage(e){this.disposeWithMe((0,t.toDisposable)(e.onDblclick$.subscribeEvent(()=>{let t=`${e.oKey}-viewer-dialog`;this._drawingRenderService.previewImage(t,e.getNative().src,e.getNativeSize().width,e.getNativeSize().height)})))}};Q=H([V(0,t.ICommandService),V(1,r.IRenderManagerService),V(2,n.IDrawingManagerService),V(3,a.IDialogService),V(4,n.IImageIoService),V(5,t.IUniverInstanceService),V(6,(0,t.Inject)(Z))],Q);let $=class extends t.Plugin{constructor(e=ee,n,r){super(),this._config=e,this._injector=n,this._configService=r;let{menu:i,...a}=(0,t.merge)({},ee,this._config);i&&this._configService.setConfig(`menu`,i,{merge:!0}),this._configService.setConfig(I,a)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(q),this._injector.get(U),this._injector.get(X),this._injector.get(Q)}_initDependencies(){[[Z],[q],[U],[X],[Q]].forEach(e=>this._injector.add(e))}};K($,`pluginName`,`UNIVER_DRAWING_UI_PLUGIN`),K($,`packageName`,P),K($,`version`,F),$=H([V(1,(0,t.Inject)(t.Injector)),V(2,t.IConfigService)],$);let qe=e=>{let n=(0,a.useDependency)(t.ICommandService),r=(0,a.useDependency)(t.LocaleService),{drawings:o,alignShow:d}=e,[f,p]=(0,i.useState)(l.default),m=[{label:r.t(`image-panel.align.default`),value:l.default},{options:[{label:r.t(`image-panel.align.left`),value:l.left},{label:r.t(`image-panel.align.center`),value:l.center},{label:r.t(`image-panel.align.right`),value:l.right}]},{options:[{label:r.t(`image-panel.align.top`),value:l.top},{label:r.t(`image-panel.align.middle`),value:l.middle},{label:r.t(`image-panel.align.bottom`),value:l.bottom}]},{options:[{label:r.t(`image-panel.align.horizon`),value:l.horizon},{label:r.t(`image-panel.align.vertical`),value:l.vertical}]}];function h(e){p(e),n.executeCommand(u.id,{alignType:e,drawings:o})}return(0,c.jsxs)(`div`,{className:(0,s.clsx)(`univer-relative univer-w-full`,{"univer-hidden":!d}),children:[(0,c.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,c.jsx)(`div`,{children:r.t(`image-panel.align.title`)})}),(0,c.jsx)(`div`,{className:`univer-relative univer-mt-2.5 univer-flex univer-h-full`,children:(0,c.jsx)(`div`,{className:`univer-w-full univer-text-gray-900 dark:!univer-text-white`,children:(0,c.jsx)(s.Select,{value:f,options:m,onChange:h})})})]})},Je=e=>{let{arrangeShow:r,drawings:o}=e,l=(0,a.useDependency)(t.LocaleService),u=(0,a.useDependency)(n.IDrawingManagerService),d=(0,a.useDependency)(t.ICommandService),f=(0,a.useDependency)(a.ComponentManager),p=f.get(`MoveUpIcon`),m=f.get(`MoveDownIcon`),h=f.get(`TopmostIcon`),g=f.get(`BottomIcon`),[_,v]=(0,i.useState)(o);(0,i.useEffect)(()=>{let e=u.focus$.subscribe(e=>{v(e)});return()=>{e.unsubscribe()}},[]);let b=e=>{d.syncExecuteCommand(y.id,{arrangeType:e,drawings:_})};return(0,c.jsxs)(`div`,{className:(0,s.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!r}),children:[(0,c.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,c.jsx)(`div`,{children:l.t(`image-panel.arrange.title`)})}),(0,c.jsxs)(`div`,{className:`univer-grid univer-grid-cols-2 univer-gap-2`,children:[(0,c.jsxs)(s.Button,{onClick:()=>{b(t.ArrangeTypeEnum.forward)},children:[(0,c.jsx)(p,{}),l.t(`image-panel.arrange.forward`)]}),(0,c.jsxs)(s.Button,{onClick:()=>{b(t.ArrangeTypeEnum.backward)},children:[(0,c.jsx)(m,{}),l.t(`image-panel.arrange.backward`)]}),(0,c.jsxs)(s.Button,{onClick:()=>{b(t.ArrangeTypeEnum.front)},children:[(0,c.jsx)(h,{}),l.t(`image-panel.arrange.front`)]}),(0,c.jsxs)(s.Button,{onClick:()=>{b(t.ArrangeTypeEnum.back)},children:[(0,c.jsx)(g,{}),l.t(`image-panel.arrange.back`)]})]})]})},Ye=e=>{let o=(0,a.useDependency)(t.LocaleService),l=(0,a.useDependency)(r.IRenderManagerService),u=(0,a.useDependency)(n.IDrawingManagerService),d=(0,a.useDependency)(t.ICommandService),f=(0,a.useDependency)(a.ComponentManager),{hasGroup:p,drawings:m}=e,h=f.get(`GroupIcon`),g=f.get(`UngroupIcon`),[_,v]=(0,i.useState)(!1),[y,b]=(0,i.useState)(!0),[x,S]=(0,i.useState)(!0),C=()=>{d.syncExecuteCommand(T.id,{drawings:m})},w=()=>{d.syncExecuteCommand(E.id,{drawings:m})};return(0,i.useEffect)(()=>{let e=m[0];if(e==null)return;let{unitId:n}=e,r=l.getRenderById(n),i=r==null?void 0:r.scene;if(i==null)return;let a=i.getTransformerByCreate(),o=a.clearControl$.subscribe(e=>{e===!0&&v(!1)}),s=a.changeStart$.subscribe(e=>{let{objects:n}=e,r=W(n,u),i=r.filter(e=>(e==null?void 0:e.drawingType)===t.DrawingTypeEnum.DRAWING_GROUP),a=!1,o=!1;r.length>1&&(a=!0),i.length>0&&(o=!0),v(a||o),b(a),S(o)});return()=>{s.unsubscribe(),o.unsubscribe()}},[]),(0,c.jsxs)(`div`,{className:(0,s.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":p===!0&&_===!1||p===!1}),children:[(0,c.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,c.jsx)(`div`,{children:o.t(`image-panel.group.title`)})}),(0,c.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[(0,c.jsxs)(s.Button,{className:(0,s.clsx)({"univer-hidden":!y}),onClick:C,children:[(0,c.jsx)(h,{}),o.t(`image-panel.group.group`)]}),(0,c.jsxs)(s.Button,{className:(0,s.clsx)({"univer-hidden":!x}),onClick:w,children:[(0,c.jsx)(g,{}),o.t(`image-panel.group.unGroup`)]})]})]})},Xe=[-360,360],Ze=e=>{var o;let l=(0,a.useDependency)(t.LocaleService),u=(0,a.useDependency)(n.IDrawingManagerService),d=(0,a.useDependency)(r.IRenderManagerService),{drawings:f,transformShow:p}=e,m=f[0];if(m==null)return;let h=m.transform;if(h==null)return;let{unitId:g,subUnitId:_,drawingId:v,drawingType:y}=m,b=d.getRenderById(g),x=b==null?void 0:b.scene;if(x==null)return;let S=(o=x.getEngine())==null?void 0:o.activeScene;if(S==null)return;let C=x.getTransformerByCreate(),{width:w=0,height:T=0,left:E=0,top:D=0,angle:O=0}=h,[k,A]=(0,i.useState)(w),[j,M]=(0,i.useState)(T),[N,P]=(0,i.useState)(E),[F,I]=(0,i.useState)(D),[ee,L]=(0,i.useState)(O),[R,te]=(0,i.useState)(C.keepRatio),z=(e,t,n,r)=>{let{width:i,height:a}=S,{ancestorLeft:o,ancestorTop:s}=x,c=e,l=t,u=n,d=r;return e+o<0&&(c=-o),t+s<0&&(l=-s),u=i-c-o,u<20&&(u=20),d=a-l-s,d<20&&(d=20),e+u+o>i&&(c=i-n-o),t+d+s>a&&(l=a-r-s),{limitLeft:c,limitTop:l,limitWidth:u,limitHeight:d}},B=e=>{let{objects:t}=e,n=W(t,u);if(n.length!==1)return;let r=n[0];if(r==null)return;let{transform:i}=r;if(i==null)return;let{width:a,height:o,left:s,top:c,angle:l}=i;a!=null&&A(a),o!=null&&M(o),s!=null&&P(s),c!=null&&I(c),l!=null&&L(l)};(0,i.useEffect)(()=>{let e=[C.changeStart$.subscribe(e=>{B(e)}),C.changing$.subscribe(e=>{B(e)}),C.changeEnd$.subscribe(e=>{B(e)}),u.focus$.subscribe(e=>{if(e.length!==1)return;let t=u.getDrawingByParam(e[0]);if(t==null)return;let n=t.transform;if(n==null)return;let{width:r,height:i,left:a,top:o,angle:s}=n;r!=null&&A(r),i!=null&&M(i),a!=null&&P(a),o!=null&&I(o),s!=null&&L(s)})];return()=>{e.forEach(e=>e.unsubscribe())}},[]);let ne=(0,t.debounce)(e=>{if(e==null)return;let{limitWidth:t,limitHeight:n}=z(N,F,e,j);e=Math.min(e,t);let r={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{width:e}};if(R){let t=e/k*j;if(t=Math.max(t,20),t>n)return;M(t),r.transform.height=t}A(e),u.featurePluginUpdateNotification([r]),C.refreshControls().changeNotification()},300),re=(0,t.debounce)(e=>{if(e==null)return;let{limitHeight:t,limitWidth:n}=z(N,F,k,e);e=Math.min(e,t);let r={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{height:e}};if(R){let t=e/j*k;if(t=Math.max(t,20),t>n)return;A(t),r.transform.width=t}M(e),u.featurePluginUpdateNotification([r]),C.refreshControls().changeNotification()},300),ie=(0,t.debounce)(e=>{if(e==null)return;let{limitLeft:t}=z(e,F,k,j);e=t;let n={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{left:e}};P(e),u.featurePluginUpdateNotification([n]),C.refreshControls().changeNotification()},300),ae=(0,t.debounce)(e=>{if(e==null)return;let{limitTop:t}=z(N,e,k,j);e=t;let n={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{top:e}};I(e),u.featurePluginUpdateNotification([n]),C.refreshControls().changeNotification()},300),oe=e=>{if(e==null)return;let t={unitId:g,subUnitId:_,drawingId:v,drawingType:y,transform:{angle:e}};L(e),u.featurePluginUpdateNotification([t]),C.refreshControls().changeNotification()},se=e=>{te(e),C.keepRatio=e};return(0,c.jsxs)(`div`,{className:(0,s.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!p}),children:[(0,c.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,c.jsx)(`div`,{children:l.t(`image-panel.transform.title`)})}),(0,c.jsxs)(`div`,{className:`univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2`,children:[(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.width`)}),(0,c.jsx)(s.InputNumber,{precision:1,value:k,min:20,onChange:e=>{ne(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.height`)}),(0,c.jsx)(s.InputNumber,{precision:1,value:j,min:20,onChange:e=>{re(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.lock`)}),(0,c.jsx)(`div`,{className:`univer-text-center`,children:(0,c.jsx)(s.Checkbox,{checked:R,onChange:se})})]})]}),(0,c.jsxs)(`div`,{className:`univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2`,children:[(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.x`)}),(0,c.jsx)(s.InputNumber,{precision:1,value:N,onChange:e=>{ie(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.y`)}),(0,c.jsx)(s.InputNumber,{precision:1,value:F,onChange:e=>{ae(e)}})]}),(0,c.jsxs)(`div`,{children:[(0,c.jsx)(`span`,{children:l.t(`image-panel.transform.rotate`)}),(0,c.jsx)(s.InputNumber,{precision:1,value:ee,min:Xe[0],max:Xe[1],onChange:oe})]})]})]})},Qe=e=>{let n=(0,a.useDependency)(t.ICommandService),r=(0,a.useDependency)(t.LocaleService),{drawings:o,cropperShow:l}=e;if(o[0]==null)return;let[u,d]=(0,i.useState)(k.FREE),f=(0,i.useRef)(!1),p=[{label:r.t(`image-panel.crop.mode`),value:k.FREE},{label:`1:1`,value:k.R1_1},{label:`16:9`,value:k.R16_9},{label:`9:16`,value:k.R9_16},{label:`5:4`,value:k.R5_4},{label:`4:5`,value:k.R4_5},{label:`4:3`,value:k.R4_3},{label:`3:4`,value:k.R3_4},{label:`3:2`,value:k.R3_2},{label:`2:3`,value:k.R2_3}];(0,i.useEffect)(()=>{let e=n.onCommandExecuted(e=>{if(e.id===O.id){let t=e.params;t!=null&&t.isAuto||(f.current=!1)}});return()=>{e==null||e.dispose()}},[]);function m(e){d(e),f.current&&n.executeCommand(A.id,{cropType:e})}let h=e=>{n.executeCommand(A.id,{cropType:e}),f.current=!0};return(0,c.jsxs)(`div`,{className:(0,s.clsx)(`univer-grid univer-gap-2 univer-py-2 univer-text-gray-400`,{"univer-hidden":!l}),children:[(0,c.jsx)(`header`,{className:`univer-text-gray-600 dark:!univer-text-gray-200`,children:(0,c.jsx)(`div`,{children:r.t(`image-panel.crop.title`)})}),(0,c.jsxs)(`div`,{className:`univer-flex univer-items-center univer-justify-center univer-gap-2`,children:[(0,c.jsxs)(s.Button,{onClick:()=>{h(u)},children:[(0,c.jsx)(ae,{}),r.t(`image-panel.crop.start`)]}),(0,c.jsx)(s.Select,{value:u,options:p,onChange:m})]})]})};e.AutoImageCropOperation=A,e.COMPONENT_IMAGE_POPUP_MENU=Ue,e.CancelDrawingGroupOperation=E,e.CloseImageCropOperation=O,e.DRAWING_GROUP_TYPES=w,e.DrawingCommonPanel=e=>{let o=(0,a.useDependency)(n.IDrawingManagerService),l=(0,a.useDependency)(r.IRenderManagerService),u=(0,a.useDependency)(t.LocaleService),{drawings:d,hasArrange:f=!0,hasTransform:p=!0,hasAlign:m=!0,hasCropper:h=!0,hasGroup:g=!0}=e,_=d[0];if(_==null)return;let{unitId:v}=_,y=l.getRenderById(v),b=y==null?void 0:y.scene;if(b==null)return;let x=b.getTransformerByCreate(),[S,C]=(0,i.useState)(!0),[w,T]=(0,i.useState)(!0),[E,D]=(0,i.useState)(!1),[O,k]=(0,i.useState)(!0),[A,j]=(0,i.useState)(!1);return(0,i.useEffect)(()=>{let e=x.clearControl$.subscribe(e=>{e===!0&&(C(!1),T(!1),D(!1),k(!1),j(!0))}),t=x.changeStart$.subscribe(e=>{let{objects:t}=e,n=W(t,o);n.length===0?(C(!1),T(!1),D(!1),k(!1),j(!0)):n.length===1?(C(!0),T(!0),D(!1),k(!0),j(!1)):(C(!0),T(!1),D(!0),k(!1),j(!1))}),n=o.focus$.subscribe(e=>{e.length===0?(C(!1),T(!1),D(!1),k(!1),j(!0)):e.length===1?(C(!0),T(!0),D(!1),k(!0),j(!1)):(C(!0),T(!1),D(!0),k(!1),j(!1))});return()=>{t.unsubscribe(),e.unsubscribe(),n.unsubscribe()}},[]),(0,c.jsxs)(c.Fragment,{children:[(0,c.jsx)(`div`,{className:(0,s.clsx)(`univer-h-full`,{"univer-hidden":!A}),children:(0,c.jsx)(`div`,{className:`univer-flex univer-h-full univer-items-center univer-justify-center`,children:(0,c.jsx)(`span`,{children:u.t(`image-panel.null`)})})}),(0,c.jsx)(Je,{arrangeShow:f===!0?S:!1,drawings:d}),(0,c.jsx)(Ze,{transformShow:p===!0?w:!1,drawings:d}),(0,c.jsx)(qe,{alignShow:m===!0?E:!1,drawings:d}),(0,c.jsx)(Qe,{cropperShow:h===!0?O:!1,drawings:d}),(0,c.jsx)(Ye,{hasGroup:g,drawings:d})]})},Object.defineProperty(e,`DrawingRenderService`,{enumerable:!0,get:function(){return Z}}),e.ImageCropperObject=Y,e.ImagePopupMenu=We,e.ImageResetSizeOperation=j,e.OpenImageCropOperation=D,e.SetDrawingAlignOperation=u,e.SetDrawingArrangeOperation=y,e.SetDrawingGroupOperation=T,Object.defineProperty(e,`UniverDrawingUIPlugin`,{enumerable:!0,get:function(){return $}}),e.getCurrentUnitInfo=N,e.getUpdateParams=W,e.insertGroupObject=M});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/drawing-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.19.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "",
|
|
6
6
|
"author": "DreamNum <developer@univer.ai>",
|
|
@@ -53,20 +53,20 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@univerjs/icons": "^1.1.1",
|
|
56
|
-
"@univerjs/
|
|
57
|
-
"@univerjs/
|
|
58
|
-
"@univerjs/drawing": "0.
|
|
59
|
-
"@univerjs/
|
|
60
|
-
"@univerjs/
|
|
56
|
+
"@univerjs/design": "0.19.0",
|
|
57
|
+
"@univerjs/core": "0.19.0",
|
|
58
|
+
"@univerjs/drawing": "0.19.0",
|
|
59
|
+
"@univerjs/ui": "0.19.0",
|
|
60
|
+
"@univerjs/engine-render": "0.19.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
63
|
"postcss": "^8.5.8",
|
|
64
64
|
"react": "18.3.1",
|
|
65
65
|
"rxjs": "^7.8.2",
|
|
66
66
|
"tailwindcss": "3.4.18",
|
|
67
|
-
"typescript": "^
|
|
68
|
-
"vitest": "^4.1.
|
|
69
|
-
"@univerjs-infra/shared": "0.
|
|
67
|
+
"typescript": "^6.0.2",
|
|
68
|
+
"vitest": "^4.1.1",
|
|
69
|
+
"@univerjs-infra/shared": "0.19.0"
|
|
70
70
|
},
|
|
71
71
|
"scripts": {
|
|
72
72
|
"test": "vitest run",
|