@univerjs/drawing-ui 0.20.1 → 0.21.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 +2922 -1
- package/lib/cjs/locale/ca-ES.js +66 -1
- package/lib/cjs/locale/en-US.js +81 -1
- package/lib/cjs/locale/es-ES.js +66 -1
- package/lib/cjs/locale/fa-IR.js +66 -1
- package/lib/cjs/locale/fr-FR.js +66 -1
- package/lib/cjs/locale/ja-JP.js +66 -1
- package/lib/cjs/locale/ko-KR.js +66 -1
- package/lib/cjs/locale/ru-RU.js +66 -1
- package/lib/cjs/locale/sk-SK.js +66 -1
- package/lib/cjs/locale/vi-VN.js +66 -1
- package/lib/cjs/locale/zh-CN.js +66 -1
- package/lib/cjs/locale/zh-TW.js +66 -1
- package/lib/es/index.js +2892 -1
- package/lib/es/locale/ca-ES.js +65 -1
- package/lib/es/locale/en-US.js +80 -1
- package/lib/es/locale/es-ES.js +65 -1
- package/lib/es/locale/fa-IR.js +65 -1
- package/lib/es/locale/fr-FR.js +65 -1
- package/lib/es/locale/ja-JP.js +65 -1
- package/lib/es/locale/ko-KR.js +65 -1
- package/lib/es/locale/ru-RU.js +65 -1
- package/lib/es/locale/sk-SK.js +65 -1
- package/lib/es/locale/vi-VN.js +65 -1
- package/lib/es/locale/zh-CN.js +65 -1
- package/lib/es/locale/zh-TW.js +65 -1
- package/lib/index.js +2892 -1
- package/lib/locale/ca-ES.js +65 -1
- package/lib/locale/en-US.js +80 -1
- package/lib/locale/es-ES.js +65 -1
- package/lib/locale/fa-IR.js +65 -1
- package/lib/locale/fr-FR.js +65 -1
- package/lib/locale/ja-JP.js +65 -1
- package/lib/locale/ko-KR.js +65 -1
- package/lib/locale/ru-RU.js +65 -1
- package/lib/locale/sk-SK.js +65 -1
- package/lib/locale/vi-VN.js +65 -1
- package/lib/locale/zh-CN.js +65 -1
- package/lib/locale/zh-TW.js +65 -1
- package/lib/types/controllers/utils.d.ts +2 -1
- package/lib/umd/index.js +1 -1
- package/package.json +9 -9
package/lib/cjs/index.js
CHANGED
|
@@ -1 +1,2922 @@
|
|
|
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.20.1`;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.map(e=>({type:`item`,children:d.t(e.label),disabled:e.disable,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 we=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}}};we=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))],we);var X=class extends e.Disposable{constructor(){super(),K(this,`_clipDelegate`,null),K(this,`_canUseShapeClip$`,new a.BehaviorSubject(!1)),K(this,`canUseShapeClip$`,this._canUseShapeClip$.asObservable())}setCanUseShapeClip(e){this._canUseShapeClip$.next(e)}registerClipDelegate(t){return this._clipDelegate=t,(0,e.toDisposable)(()=>{this._clipDelegate===t&&(this._clipDelegate=null)})}applyShapeClip(e,t,n,r,i){return this._clipDelegate?this._clipDelegate(e,t,n,r,i):!1}dispose(){this._clipDelegate=null,this._canUseShapeClip$.complete(),super.dispose()}};let Z=class{constructor(e,t,n,r,i,a){this._drawingManagerService=e,this._imageIoService=t,this._galleryService=n,this._urlImageService=r,this._univerInstanceService=i,this._drawingImageClipService=a}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,adjustValues:_}=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 v=h&&g?g:[a],y=[];for(let e of v){let{left:r,top:a,width:o,height:g,angle:b,flipX:x,flipY:S,skewX:C,skewY:w}=e,T=v.indexOf(e),E=(0,t.getDrawingShapeKeyByDrawingSearch)({unitId:f,subUnitId:p,drawingId:m},h?T:void 0),D=i.getObject(E);if(D!=null){D.transformByState({left:r,top:a,width:o,height:g,angle:b,flipX:x,flipY:S,skewX:C,skewY:w});continue}let O=this._drawingManagerService.getDrawingOrder(f,p),k=O.indexOf(m),A={...e,zIndex:k===-1?O.length-1:k},j=this._imageIoService.getImageSourceCache(s,c),N=!1;if(j!=null)A.image=j;else if(c===t.ImageSourceType.UUID)try{A.url=await this._imageIoService.getImage(s)}catch(e){console.error(e);continue}else if(c===t.ImageSourceType.URL){try{A.url=await this._urlImageService.getImage(s)}catch(e){console.error(e),A.url=s}N=!0}else A.url=s,N=!0;if(i.getObject(E))continue;A.printable=!0;let P=new n.Image(E,A);P.setClipService(this._drawingImageClipService),N&&this._imageIoService.addImageSourceCache(s,c,P.getNative()),i.addObject(P,n.DRAWING_OBJECT_LAYER_INDEX),this._drawingManagerService.getDrawingEditable()&&i.attachTransformerTo(P),d&&M({drawingId:d,unitId:f,subUnitId:p},P,i,this._drawingManagerService),u!=null&&P.setPrstGeom(u),_!=null&&P.setPrstGeomAdjValues(_),l!=null&&P.setSrcRect(l),y.push(P)}return y}_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),V(5,(0,e.Inject)(X))],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(we),this._injector.get(Q)}_initDependencies(){[[X],[Z],[q],[U],[we],[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 Te=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})})})]})},Ee=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`)]})]})]})},De=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`)]})]})]})},Oe=[-360,360],ke=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:Oe[0],max:Oe[1],onChange:oe})]})]})]})},Ae=t=>{let n=(0,i.useDependency)(e.ICommandService),a=(0,i.useDependency)(e.LocaleService),l=(0,i.useDependency)(X),u=(0,i.useDependency)(i.ComponentManager),d=(0,i.useObservable)(l.canUseShapeClip$,!1),{drawings:f,cropperShow:p}=t;if(f[0]==null)return;let[m,h]=(0,s.useState)(k.FREE),g=(0,s.useRef)(!1),_=[{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||(g.current=!1)}});return()=>{e==null||e.dispose()}},[]);function v(e){h(e),g.current&&n.executeCommand(A.id,{cropType:e})}let y=e=>{n.executeCommand(A.id,{cropType:e}),g.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":!p}),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:()=>{y(m)},children:[(0,c.jsx)(r.CreateCopyIcon,{}),a.t(`image-panel.crop.start`)]}),(0,c.jsx)(o.Select,{value:m,options:_,onChange:v})]}),d&&(()=>{let e=u.get(`sheet.image-clip.shape.picker.component`);return e?(0,c.jsx)(e,{}):null})()]})},je=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)(Ee,{arrangeShow:f===!0?S:!1,drawings:d}),(0,c.jsx)(ke,{transformShow:p===!0?w:!1,drawings:d}),(0,c.jsx)(Te,{alignShow:m===!0?E:!1,drawings:d}),(0,c.jsx)(Ae,{cropperShow:h===!0?O:!1,drawings:d}),(0,c.jsx)(De,{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=je,exports.DrawingImageClipService=X,Object.defineProperty(exports,`DrawingRenderService`,{enumerable:!0,get:function(){return Z}}),exports.IMAGE_CLIP_SHAPE_PICKER_COMPONENT=`sheet.image-clip.shape.picker.component`,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' });
|
|
2
|
+
let _univerjs_core = require("@univerjs/core");
|
|
3
|
+
let _univerjs_drawing = require("@univerjs/drawing");
|
|
4
|
+
let _univerjs_engine_render = require("@univerjs/engine-render");
|
|
5
|
+
let _univerjs_icons = require("@univerjs/icons");
|
|
6
|
+
let _univerjs_ui = require("@univerjs/ui");
|
|
7
|
+
let rxjs = require("rxjs");
|
|
8
|
+
let _univerjs_design = require("@univerjs/design");
|
|
9
|
+
let react = require("react");
|
|
10
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
11
|
+
|
|
12
|
+
//#region src/commands/operations/drawing-align.operation.ts
|
|
13
|
+
let AlignType = /* @__PURE__ */ function(AlignType) {
|
|
14
|
+
AlignType["default"] = "0";
|
|
15
|
+
AlignType["left"] = "1";
|
|
16
|
+
AlignType["center"] = "2";
|
|
17
|
+
AlignType["right"] = "3";
|
|
18
|
+
AlignType["top"] = "4";
|
|
19
|
+
AlignType["middle"] = "5";
|
|
20
|
+
AlignType["bottom"] = "6";
|
|
21
|
+
AlignType["horizon"] = "7";
|
|
22
|
+
AlignType["vertical"] = "8";
|
|
23
|
+
return AlignType;
|
|
24
|
+
}({});
|
|
25
|
+
/**
|
|
26
|
+
* Set drawing align operation, including left, center, right, top, middle, bottom, horizon and vertical align.
|
|
27
|
+
*/
|
|
28
|
+
const SetDrawingAlignOperation = {
|
|
29
|
+
id: "sheet.operation.set-image-align",
|
|
30
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
31
|
+
handler: (accessor, params) => {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const SetDrawingAlignLeftOperation = {
|
|
36
|
+
id: "sheet.operation.set-drawing-align-left",
|
|
37
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
38
|
+
handler: (accessor) => {
|
|
39
|
+
return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.left });
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
const SetDrawingAlignCenterOperation = {
|
|
43
|
+
id: "sheet.operation.set-drawing-align-center",
|
|
44
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
45
|
+
handler: (accessor) => {
|
|
46
|
+
return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.center });
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const SetDrawingAlignRightOperation = {
|
|
50
|
+
id: "sheet.operation.set-drawing-align-right",
|
|
51
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
52
|
+
handler: (accessor) => {
|
|
53
|
+
return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.right });
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const SetDrawingAlignTopOperation = {
|
|
57
|
+
id: "sheet.operation.set-drawing-align-top",
|
|
58
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
59
|
+
handler: (accessor) => {
|
|
60
|
+
return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.top });
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const SetDrawingAlignMiddleOperation = {
|
|
64
|
+
id: "sheet.operation.set-drawing-align-middle",
|
|
65
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
66
|
+
handler: (accessor) => {
|
|
67
|
+
return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.middle });
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const SetDrawingAlignBottomOperation = {
|
|
71
|
+
id: "sheet.operation.set-drawing-align-bottom",
|
|
72
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
73
|
+
handler: (accessor) => {
|
|
74
|
+
return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.bottom });
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const SetDrawingAlignHorizonOperation = {
|
|
78
|
+
id: "sheet.operation.set-drawing-align-horizon",
|
|
79
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
80
|
+
handler: (accessor) => {
|
|
81
|
+
return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.horizon });
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
const SetDrawingAlignVerticalOperation = {
|
|
85
|
+
id: "sheet.operation.set-drawing-align-vertical",
|
|
86
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
87
|
+
handler: (accessor) => {
|
|
88
|
+
return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(SetDrawingAlignOperation.id, { alignType: AlignType.vertical });
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/commands/operations/drawing-arrange.operation.ts
|
|
94
|
+
/**
|
|
95
|
+
* Set the layer of the drawing, including forward, backward, front, and back
|
|
96
|
+
*/
|
|
97
|
+
const SetDrawingArrangeOperation = {
|
|
98
|
+
id: "drawing.operation.set-drawing-arrange",
|
|
99
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
100
|
+
handler: (accessor, params) => {
|
|
101
|
+
const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
|
|
102
|
+
const { arrangeType } = params;
|
|
103
|
+
const drawings = params.drawings || drawingManagerService.getFocusDrawings();
|
|
104
|
+
const { unitId, subUnitId } = drawings[0];
|
|
105
|
+
const drawingIds = drawings.map((drawing) => drawing.drawingId);
|
|
106
|
+
drawingManagerService.featurePluginOrderUpdateNotification({
|
|
107
|
+
unitId,
|
|
108
|
+
subUnitId,
|
|
109
|
+
drawingIds,
|
|
110
|
+
arrangeType
|
|
111
|
+
});
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const SetDrawingArrangeFrontOperation = {
|
|
116
|
+
id: "drawing.operation.set-drawing-arrange-front",
|
|
117
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
118
|
+
handler: (accessor) => {
|
|
119
|
+
return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType: _univerjs_core.ArrangeTypeEnum.front });
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
const SetDrawingArrangeForwardOperation = {
|
|
123
|
+
id: "drawing.operation.set-drawing-arrange-forward",
|
|
124
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
125
|
+
handler: (accessor) => {
|
|
126
|
+
return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType: _univerjs_core.ArrangeTypeEnum.forward });
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const SetDrawingArrangeBackOperation = {
|
|
130
|
+
id: "drawing.operation.set-drawing-arrange-back",
|
|
131
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
132
|
+
handler: (accessor) => {
|
|
133
|
+
return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType: _univerjs_core.ArrangeTypeEnum.back });
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const SetDrawingArrangeBackwardOperation = {
|
|
137
|
+
id: "drawing.operation.set-drawing-arrange-backward",
|
|
138
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
139
|
+
handler: (accessor) => {
|
|
140
|
+
return accessor.get(_univerjs_core.ICommandService).syncExecuteCommand(SetDrawingArrangeOperation.id, { arrangeType: _univerjs_core.ArrangeTypeEnum.backward });
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
//#endregion
|
|
145
|
+
//#region src/commands/operations/drawing-group.operation.ts
|
|
146
|
+
/**
|
|
147
|
+
* Now only support grouping images, shapes, and groups.
|
|
148
|
+
*/
|
|
149
|
+
const DRAWING_GROUP_TYPES = [
|
|
150
|
+
_univerjs_core.DrawingTypeEnum.DRAWING_IMAGE,
|
|
151
|
+
_univerjs_core.DrawingTypeEnum.DRAWING_SHAPE,
|
|
152
|
+
_univerjs_core.DrawingTypeEnum.DRAWING_GROUP
|
|
153
|
+
];
|
|
154
|
+
/**
|
|
155
|
+
* Group the selected drawings into a new group. The selected drawings must be of type image, shape, or group, and there must be at least 2 drawings selected.
|
|
156
|
+
*/
|
|
157
|
+
const SetDrawingGroupOperation = {
|
|
158
|
+
id: "drawing.operation.set-drawing-group",
|
|
159
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
160
|
+
handler: (accessor, params) => {
|
|
161
|
+
const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
|
|
162
|
+
const drawings = params.drawings || drawingManagerService.getFocusDrawings();
|
|
163
|
+
if (drawings.length < 2) return false;
|
|
164
|
+
if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return false;
|
|
165
|
+
const { unitId, subUnitId } = drawings[0];
|
|
166
|
+
const groupId = (0, _univerjs_core.generateRandomId)(10);
|
|
167
|
+
const groupTransform = (0, _univerjs_engine_render.getGroupState)(0, 0, drawings.map((o) => o.transform || {}));
|
|
168
|
+
const groupParam = {
|
|
169
|
+
unitId,
|
|
170
|
+
subUnitId,
|
|
171
|
+
drawingId: groupId,
|
|
172
|
+
drawingType: _univerjs_core.DrawingTypeEnum.DRAWING_GROUP,
|
|
173
|
+
transform: groupTransform,
|
|
174
|
+
groupBaseBound: {
|
|
175
|
+
left: groupTransform.left,
|
|
176
|
+
top: groupTransform.top,
|
|
177
|
+
width: groupTransform.width,
|
|
178
|
+
height: groupTransform.height
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const children = drawings.map((drawing) => {
|
|
182
|
+
const transform = drawing.transform || {
|
|
183
|
+
left: 0,
|
|
184
|
+
top: 0
|
|
185
|
+
};
|
|
186
|
+
const { unitId, subUnitId, drawingId } = drawing;
|
|
187
|
+
return {
|
|
188
|
+
unitId,
|
|
189
|
+
subUnitId,
|
|
190
|
+
drawingId,
|
|
191
|
+
transform: { ...transform },
|
|
192
|
+
groupId
|
|
193
|
+
};
|
|
194
|
+
});
|
|
195
|
+
drawingManagerService.featurePluginGroupUpdateNotification([{
|
|
196
|
+
parent: groupParam,
|
|
197
|
+
children
|
|
198
|
+
}]);
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
/**
|
|
203
|
+
* Ungroup the selected groups. The selected drawings must be at least 1 group selected.
|
|
204
|
+
*/
|
|
205
|
+
const CancelDrawingGroupOperation = {
|
|
206
|
+
id: "drawing.operation.cancel-drawing-group",
|
|
207
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
208
|
+
handler: (accessor, params) => {
|
|
209
|
+
const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
|
|
210
|
+
const groupParams = (params.drawings || drawingManagerService.getFocusDrawings()).map((drawing) => {
|
|
211
|
+
if (drawing.drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_GROUP) return null;
|
|
212
|
+
const { unitId, subUnitId, drawingId, transform: groupTransform = {
|
|
213
|
+
width: 0,
|
|
214
|
+
height: 0
|
|
215
|
+
}, groupBaseBound } = drawing;
|
|
216
|
+
if (groupTransform === null) return null;
|
|
217
|
+
const objects = drawingManagerService.getDrawingsByGroup({
|
|
218
|
+
unitId,
|
|
219
|
+
subUnitId,
|
|
220
|
+
drawingId
|
|
221
|
+
});
|
|
222
|
+
if (objects.length === 0) return null;
|
|
223
|
+
return {
|
|
224
|
+
parent: drawing,
|
|
225
|
+
children: objects.map((object) => {
|
|
226
|
+
const { transform } = object;
|
|
227
|
+
const { unitId, subUnitId, drawingId } = object;
|
|
228
|
+
const newTransform = (0, _univerjs_engine_render.transformObjectOutOfGroup)(transform || {}, groupTransform, groupTransform.width || 0, groupTransform.height || 0, groupBaseBound);
|
|
229
|
+
return {
|
|
230
|
+
unitId,
|
|
231
|
+
subUnitId,
|
|
232
|
+
drawingId,
|
|
233
|
+
transform: {
|
|
234
|
+
...transform,
|
|
235
|
+
...newTransform
|
|
236
|
+
},
|
|
237
|
+
groupId: void 0
|
|
238
|
+
};
|
|
239
|
+
})
|
|
240
|
+
};
|
|
241
|
+
}).filter((o) => o !== null);
|
|
242
|
+
if (groupParams.length === 0) return false;
|
|
243
|
+
drawingManagerService.featurePluginUngroupUpdateNotification(groupParams);
|
|
244
|
+
return true;
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
//#endregion
|
|
249
|
+
//#region src/commands/operations/image-crop.operation.ts
|
|
250
|
+
const OpenImageCropOperation = {
|
|
251
|
+
id: "sheet.operation.open-image-crop",
|
|
252
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
253
|
+
handler: (accessor, params) => {
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
const CloseImageCropOperation = {
|
|
258
|
+
id: "sheet.operation.close-image-crop",
|
|
259
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
260
|
+
handler: (accessor, params) => {
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
let CropType = /* @__PURE__ */ function(CropType) {
|
|
265
|
+
CropType["FREE"] = "0";
|
|
266
|
+
CropType["R1_1"] = "1";
|
|
267
|
+
CropType["R16_9"] = "2";
|
|
268
|
+
CropType["R9_16"] = "3";
|
|
269
|
+
CropType["R5_4"] = "4";
|
|
270
|
+
CropType["R4_5"] = "5";
|
|
271
|
+
CropType["R4_3"] = "6";
|
|
272
|
+
CropType["R3_4"] = "7";
|
|
273
|
+
CropType["R3_2"] = "8";
|
|
274
|
+
CropType["R2_3"] = "9";
|
|
275
|
+
return CropType;
|
|
276
|
+
}({});
|
|
277
|
+
const AutoImageCropOperation = {
|
|
278
|
+
id: "sheet.operation.Auto-image-crop",
|
|
279
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
280
|
+
handler: (accessor, params) => {
|
|
281
|
+
return true;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
//#endregion
|
|
286
|
+
//#region src/commands/operations/image-reset-size.operation.ts
|
|
287
|
+
const ImageResetSizeOperation = {
|
|
288
|
+
id: "sheet.operation.image-reset-size",
|
|
289
|
+
type: _univerjs_core.CommandType.OPERATION,
|
|
290
|
+
handler: (accessor, params) => {
|
|
291
|
+
return true;
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
//#endregion
|
|
296
|
+
//#region src/controllers/utils.ts
|
|
297
|
+
function insertGroupObject(objectParam, object, scene, drawingManagerService) {
|
|
298
|
+
const groupParam = drawingManagerService.getDrawingByParam(objectParam);
|
|
299
|
+
if (groupParam == null) return;
|
|
300
|
+
const groupKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)(objectParam);
|
|
301
|
+
const groupObject = scene.getObjectIncludeInGroup(groupKey);
|
|
302
|
+
if (groupObject && !(groupObject instanceof _univerjs_engine_render.Group)) return;
|
|
303
|
+
if (groupObject != null) {
|
|
304
|
+
const objects = groupObject.getObjects();
|
|
305
|
+
for (const obj of objects) if (obj.oKey === object.oKey) return;
|
|
306
|
+
groupObject.addObject(object);
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
const group = new _univerjs_engine_render.DrawingGroupObject(groupKey);
|
|
310
|
+
scene.addObject(group, _univerjs_engine_render.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(group);
|
|
311
|
+
group.addObject(object);
|
|
312
|
+
const { transform, groupBaseBound } = groupParam;
|
|
313
|
+
if (groupBaseBound) group.setBaseBound(groupBaseBound);
|
|
314
|
+
if (groupParam.groupId) {
|
|
315
|
+
group.isInGroup = true;
|
|
316
|
+
insertGroupObject({
|
|
317
|
+
drawingId: groupParam.groupId,
|
|
318
|
+
unitId: objectParam.unitId,
|
|
319
|
+
subUnitId: objectParam.subUnitId
|
|
320
|
+
}, group, scene, drawingManagerService);
|
|
321
|
+
}
|
|
322
|
+
transform && group.transformByState({
|
|
323
|
+
left: transform.left,
|
|
324
|
+
top: transform.top,
|
|
325
|
+
angle: transform.angle,
|
|
326
|
+
width: transform.width,
|
|
327
|
+
height: transform.height
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
function getCurrentUnitInfo(currentUniverService, propUnitId) {
|
|
331
|
+
const current = propUnitId ? currentUniverService.getUnit(propUnitId) : currentUniverService.getFocusedUnit();
|
|
332
|
+
if (current == null) return;
|
|
333
|
+
const unitId = current.getUnitId();
|
|
334
|
+
let subUnitId;
|
|
335
|
+
if (current.type === _univerjs_core.UniverInstanceType.UNIVER_SHEET) {
|
|
336
|
+
var _getActiveSheet;
|
|
337
|
+
subUnitId = (_getActiveSheet = current.getActiveSheet()) === null || _getActiveSheet === void 0 ? void 0 : _getActiveSheet.getSheetId();
|
|
338
|
+
} else if (current.type === _univerjs_core.UniverInstanceType.UNIVER_DOC) subUnitId = unitId;
|
|
339
|
+
else if (current.type === _univerjs_core.UniverInstanceType.UNIVER_SLIDE) subUnitId = unitId;
|
|
340
|
+
return {
|
|
341
|
+
unitId,
|
|
342
|
+
subUnitId,
|
|
343
|
+
current
|
|
344
|
+
};
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
//#endregion
|
|
348
|
+
//#region package.json
|
|
349
|
+
var name = "@univerjs/drawing-ui";
|
|
350
|
+
var version = "0.21.0";
|
|
351
|
+
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region src/config/config.ts
|
|
354
|
+
const DRAWING_UI_PLUGIN_CONFIG_KEY = "drawing-ui.config";
|
|
355
|
+
const configSymbol = Symbol(DRAWING_UI_PLUGIN_CONFIG_KEY);
|
|
356
|
+
const defaultPluginConfig = {};
|
|
357
|
+
|
|
358
|
+
//#endregion
|
|
359
|
+
//#region src/menu/align.menu.ts
|
|
360
|
+
const getMenuStateByDrawingFocusChangedObservable$$1 = (accessor) => {
|
|
361
|
+
const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
|
|
362
|
+
return new rxjs.Observable((subscriber) => {
|
|
363
|
+
const update = (drawings) => {
|
|
364
|
+
if (!drawings || drawings.length === 0) return subscriber.next(true);
|
|
365
|
+
if (drawings.length < 2) return subscriber.next(true);
|
|
366
|
+
subscriber.next(false);
|
|
367
|
+
};
|
|
368
|
+
const subscription = drawingManagerService.focus$.subscribe((drawings) => {
|
|
369
|
+
if (!drawings || drawings.length === 0) return subscriber.next(true);
|
|
370
|
+
update(drawings);
|
|
371
|
+
});
|
|
372
|
+
update(drawingManagerService.getFocusDrawings());
|
|
373
|
+
return () => subscription.unsubscribe();
|
|
374
|
+
});
|
|
375
|
+
};
|
|
376
|
+
const DRAWING_ALIGN_CONTEXT_MENU_ID = "contextMenu.drawing-align";
|
|
377
|
+
function DrawingAlignContextMenuItemFactory(accessor) {
|
|
378
|
+
return {
|
|
379
|
+
id: DRAWING_ALIGN_CONTEXT_MENU_ID,
|
|
380
|
+
type: _univerjs_ui.MenuItemType.SUBITEMS,
|
|
381
|
+
icon: "HorizontallyIcon",
|
|
382
|
+
title: "image-panel.align.title",
|
|
383
|
+
hidden$: getMenuStateByDrawingFocusChangedObservable$$1(accessor)
|
|
384
|
+
};
|
|
385
|
+
}
|
|
386
|
+
function SetDrawingAlignLeftMenuItemFactory() {
|
|
387
|
+
return {
|
|
388
|
+
id: SetDrawingAlignLeftOperation.id,
|
|
389
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
390
|
+
icon: "LeftJustifyingIcon",
|
|
391
|
+
title: "image-panel.align.left"
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
function SetDrawingAlignCenterMenuItemFactory() {
|
|
395
|
+
return {
|
|
396
|
+
id: SetDrawingAlignCenterOperation.id,
|
|
397
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
398
|
+
icon: "HorizontallyIcon",
|
|
399
|
+
title: "image-panel.align.center"
|
|
400
|
+
};
|
|
401
|
+
}
|
|
402
|
+
function SetDrawingAlignRightMenuItemFactory() {
|
|
403
|
+
return {
|
|
404
|
+
id: SetDrawingAlignRightOperation.id,
|
|
405
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
406
|
+
icon: "RightJustifyingIcon",
|
|
407
|
+
title: "image-panel.align.right"
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
function SetDrawingAlignTopMenuItemFactory() {
|
|
411
|
+
return {
|
|
412
|
+
id: SetDrawingAlignTopOperation.id,
|
|
413
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
414
|
+
icon: "AlignTopIcon",
|
|
415
|
+
title: "image-panel.align.top"
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
function SetDrawingAlignMiddleMenuItemFactory() {
|
|
419
|
+
return {
|
|
420
|
+
id: SetDrawingAlignMiddleOperation.id,
|
|
421
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
422
|
+
icon: "VerticalCenterIcon",
|
|
423
|
+
title: "image-panel.align.middle"
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
function SetDrawingAlignBottomMenuItemFactory() {
|
|
427
|
+
return {
|
|
428
|
+
id: SetDrawingAlignBottomOperation.id,
|
|
429
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
430
|
+
icon: "AlignBottomIcon",
|
|
431
|
+
title: "image-panel.align.bottom"
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
function SetDrawingAlignHorizonMenuItemFactory() {
|
|
435
|
+
return {
|
|
436
|
+
id: SetDrawingAlignHorizonOperation.id,
|
|
437
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
438
|
+
icon: "HorizontallyIcon",
|
|
439
|
+
title: "image-panel.align.horizon"
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
function SetDrawingAlignVerticalMenuItemFactory() {
|
|
443
|
+
return {
|
|
444
|
+
id: SetDrawingAlignVerticalOperation.id,
|
|
445
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
446
|
+
icon: "VerticalCenterIcon",
|
|
447
|
+
title: "image-panel.align.vertical"
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
//#endregion
|
|
452
|
+
//#region src/menu/arrange.menu.ts
|
|
453
|
+
const DRAWING_ARRANGE_CONTEXT_MENU_ID = "contextMenu.drawing-arrange";
|
|
454
|
+
function DrawingArrangeContextMenuItemFactory() {
|
|
455
|
+
return {
|
|
456
|
+
id: DRAWING_ARRANGE_CONTEXT_MENU_ID,
|
|
457
|
+
type: _univerjs_ui.MenuItemType.SUBITEMS,
|
|
458
|
+
icon: "TopmostIcon",
|
|
459
|
+
title: "image-panel.arrange.title"
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
function SetDrawingArrangeFrontMenuItemFactory() {
|
|
463
|
+
return {
|
|
464
|
+
id: SetDrawingArrangeFrontOperation.id,
|
|
465
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
466
|
+
icon: "TopmostIcon",
|
|
467
|
+
title: "image-panel.arrange.front"
|
|
468
|
+
};
|
|
469
|
+
}
|
|
470
|
+
function SetDrawingArrangeForwardMenuItemFactory() {
|
|
471
|
+
return {
|
|
472
|
+
id: SetDrawingArrangeForwardOperation.id,
|
|
473
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
474
|
+
icon: "MoveUpIcon",
|
|
475
|
+
title: "image-panel.arrange.forward"
|
|
476
|
+
};
|
|
477
|
+
}
|
|
478
|
+
function SetDrawingArrangeBackMenuItemFactory() {
|
|
479
|
+
return {
|
|
480
|
+
id: SetDrawingArrangeBackOperation.id,
|
|
481
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
482
|
+
icon: "BottomIcon",
|
|
483
|
+
title: "image-panel.arrange.back"
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
function SetDrawingArrangeBackwardMenuItemFactory() {
|
|
487
|
+
return {
|
|
488
|
+
id: SetDrawingArrangeBackwardOperation.id,
|
|
489
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
490
|
+
icon: "MoveDownIcon",
|
|
491
|
+
title: "image-panel.arrange.backward"
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
//#endregion
|
|
496
|
+
//#region src/menu/group.menu.ts
|
|
497
|
+
const getMenuStateByDrawingFocusChangedObservable$ = (accessor, type) => {
|
|
498
|
+
const drawingManagerService = accessor.get(_univerjs_drawing.IDrawingManagerService);
|
|
499
|
+
return new rxjs.Observable((subscriber) => {
|
|
500
|
+
const update = (drawings) => {
|
|
501
|
+
if (!drawings || drawings.length === 0) return subscriber.next(true);
|
|
502
|
+
if (type === "group") {
|
|
503
|
+
if (drawings.length < 2) return subscriber.next(true);
|
|
504
|
+
if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return subscriber.next(true);
|
|
505
|
+
} else if (type === "unGroup") {
|
|
506
|
+
if (drawings.filter((drawing) => drawing.drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_GROUP).length === 0) return subscriber.next(true);
|
|
507
|
+
} else if (!drawings.every((drawing) => DRAWING_GROUP_TYPES.includes(drawing.drawingType))) return subscriber.next(true);
|
|
508
|
+
subscriber.next(false);
|
|
509
|
+
};
|
|
510
|
+
const subscription = drawingManagerService.focus$.subscribe((drawings) => {
|
|
511
|
+
if (!drawings || drawings.length === 0) return subscriber.next(true);
|
|
512
|
+
update(drawings);
|
|
513
|
+
});
|
|
514
|
+
update(drawingManagerService.getFocusDrawings());
|
|
515
|
+
return () => subscription.unsubscribe();
|
|
516
|
+
});
|
|
517
|
+
};
|
|
518
|
+
const DRAWING_GROUP_CONTEXT_MENU_ID = "contextMenu.drawing-group";
|
|
519
|
+
function DrawingGroupContextMenuItemFactory(accessor) {
|
|
520
|
+
return {
|
|
521
|
+
id: DRAWING_GROUP_CONTEXT_MENU_ID,
|
|
522
|
+
type: _univerjs_ui.MenuItemType.SUBITEMS,
|
|
523
|
+
icon: "GroupIcon",
|
|
524
|
+
title: "image-panel.group.title",
|
|
525
|
+
hidden$: getMenuStateByDrawingFocusChangedObservable$(accessor)
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
function SetDrawingGroupMenuItemFactory(accessor) {
|
|
529
|
+
return {
|
|
530
|
+
id: SetDrawingGroupOperation.id,
|
|
531
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
532
|
+
icon: "GroupIcon",
|
|
533
|
+
title: "image-panel.group.group",
|
|
534
|
+
disabled$: getMenuStateByDrawingFocusChangedObservable$(accessor, "group")
|
|
535
|
+
};
|
|
536
|
+
}
|
|
537
|
+
function CancelDrawingGroupMenuItemFactory(accessor) {
|
|
538
|
+
return {
|
|
539
|
+
id: CancelDrawingGroupOperation.id,
|
|
540
|
+
type: _univerjs_ui.MenuItemType.BUTTON,
|
|
541
|
+
icon: "UngroupIcon",
|
|
542
|
+
title: "image-panel.group.unGroup",
|
|
543
|
+
disabled$: getMenuStateByDrawingFocusChangedObservable$(accessor, "unGroup")
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
//#endregion
|
|
548
|
+
//#region src/menu/schema.ts
|
|
549
|
+
const menuSchema = { [_univerjs_ui.ContextMenuPosition.DRAWING]: { [_univerjs_ui.ContextMenuGroup.OTHERS]: {
|
|
550
|
+
[DRAWING_GROUP_CONTEXT_MENU_ID]: {
|
|
551
|
+
order: 1,
|
|
552
|
+
menuItemFactory: DrawingGroupContextMenuItemFactory,
|
|
553
|
+
[SetDrawingGroupOperation.id]: {
|
|
554
|
+
order: 0,
|
|
555
|
+
menuItemFactory: SetDrawingGroupMenuItemFactory
|
|
556
|
+
},
|
|
557
|
+
[CancelDrawingGroupOperation.id]: {
|
|
558
|
+
order: 1,
|
|
559
|
+
menuItemFactory: CancelDrawingGroupMenuItemFactory
|
|
560
|
+
}
|
|
561
|
+
},
|
|
562
|
+
[DRAWING_ARRANGE_CONTEXT_MENU_ID]: {
|
|
563
|
+
order: 2,
|
|
564
|
+
menuItemFactory: DrawingArrangeContextMenuItemFactory,
|
|
565
|
+
[SetDrawingArrangeFrontOperation.id]: {
|
|
566
|
+
order: 0,
|
|
567
|
+
menuItemFactory: SetDrawingArrangeFrontMenuItemFactory
|
|
568
|
+
},
|
|
569
|
+
[SetDrawingArrangeForwardOperation.id]: {
|
|
570
|
+
order: 1,
|
|
571
|
+
menuItemFactory: SetDrawingArrangeForwardMenuItemFactory
|
|
572
|
+
},
|
|
573
|
+
[SetDrawingArrangeBackOperation.id]: {
|
|
574
|
+
order: 2,
|
|
575
|
+
menuItemFactory: SetDrawingArrangeBackMenuItemFactory
|
|
576
|
+
},
|
|
577
|
+
[SetDrawingArrangeBackwardOperation.id]: {
|
|
578
|
+
order: 3,
|
|
579
|
+
menuItemFactory: SetDrawingArrangeBackwardMenuItemFactory
|
|
580
|
+
}
|
|
581
|
+
},
|
|
582
|
+
[DRAWING_ALIGN_CONTEXT_MENU_ID]: {
|
|
583
|
+
order: 3,
|
|
584
|
+
menuItemFactory: DrawingAlignContextMenuItemFactory,
|
|
585
|
+
[SetDrawingAlignLeftOperation.id]: {
|
|
586
|
+
order: 0,
|
|
587
|
+
menuItemFactory: SetDrawingAlignLeftMenuItemFactory
|
|
588
|
+
},
|
|
589
|
+
[SetDrawingAlignCenterOperation.id]: {
|
|
590
|
+
order: 1,
|
|
591
|
+
menuItemFactory: SetDrawingAlignCenterMenuItemFactory
|
|
592
|
+
},
|
|
593
|
+
[SetDrawingAlignRightOperation.id]: {
|
|
594
|
+
order: 2,
|
|
595
|
+
menuItemFactory: SetDrawingAlignRightMenuItemFactory
|
|
596
|
+
},
|
|
597
|
+
[SetDrawingAlignTopOperation.id]: {
|
|
598
|
+
order: 3,
|
|
599
|
+
menuItemFactory: SetDrawingAlignTopMenuItemFactory
|
|
600
|
+
},
|
|
601
|
+
[SetDrawingAlignMiddleOperation.id]: {
|
|
602
|
+
order: 4,
|
|
603
|
+
menuItemFactory: SetDrawingAlignMiddleMenuItemFactory
|
|
604
|
+
},
|
|
605
|
+
[SetDrawingAlignBottomOperation.id]: {
|
|
606
|
+
order: 5,
|
|
607
|
+
menuItemFactory: SetDrawingAlignBottomMenuItemFactory
|
|
608
|
+
},
|
|
609
|
+
[SetDrawingAlignHorizonOperation.id]: {
|
|
610
|
+
order: 6,
|
|
611
|
+
menuItemFactory: SetDrawingAlignHorizonMenuItemFactory
|
|
612
|
+
},
|
|
613
|
+
[SetDrawingAlignVerticalOperation.id]: {
|
|
614
|
+
order: 7,
|
|
615
|
+
menuItemFactory: SetDrawingAlignVerticalMenuItemFactory
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
} } };
|
|
619
|
+
|
|
620
|
+
//#endregion
|
|
621
|
+
//#region src/views/image-popup-menu/component-name.ts
|
|
622
|
+
/**
|
|
623
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
624
|
+
*
|
|
625
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
626
|
+
* you may not use this file except in compliance with the License.
|
|
627
|
+
* You may obtain a copy of the License at
|
|
628
|
+
*
|
|
629
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
630
|
+
*
|
|
631
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
632
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
633
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
634
|
+
* See the License for the specific language governing permissions and
|
|
635
|
+
* limitations under the License.
|
|
636
|
+
*/
|
|
637
|
+
const COMPONENT_IMAGE_POPUP_MENU = "COMPONENT_IMAGE_POPUP_MENU";
|
|
638
|
+
|
|
639
|
+
//#endregion
|
|
640
|
+
//#region src/views/image-popup-menu/ImagePopupMenu.tsx
|
|
641
|
+
function ImagePopupMenu(props) {
|
|
642
|
+
var _popup$extraProps;
|
|
643
|
+
const { popup } = props;
|
|
644
|
+
const menuItems = popup === null || popup === void 0 || (_popup$extraProps = popup.extraProps) === null || _popup$extraProps === void 0 ? void 0 : _popup$extraProps.menuItems;
|
|
645
|
+
if (!menuItems) return null;
|
|
646
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
647
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
648
|
+
const [visible, setVisible] = (0, react.useState)(false);
|
|
649
|
+
const [isHovered, setHovered] = (0, react.useState)(false);
|
|
650
|
+
const handleMouseEnter = () => {
|
|
651
|
+
setHovered(true);
|
|
652
|
+
};
|
|
653
|
+
const handleMouseLeave = () => {
|
|
654
|
+
setHovered(false);
|
|
655
|
+
};
|
|
656
|
+
const onVisibleChange = (visible) => {
|
|
657
|
+
setVisible(visible);
|
|
658
|
+
};
|
|
659
|
+
const handleClick = (item) => {
|
|
660
|
+
commandService.executeCommand(item.commandId, item.commandParams);
|
|
661
|
+
setVisible(false);
|
|
662
|
+
};
|
|
663
|
+
const showMore = visible || isHovered;
|
|
664
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
665
|
+
onMouseEnter: handleMouseEnter,
|
|
666
|
+
onMouseLeave: handleMouseLeave,
|
|
667
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.DropdownMenu, {
|
|
668
|
+
align: "start",
|
|
669
|
+
items: menuItems.map((item) => ({
|
|
670
|
+
type: "item",
|
|
671
|
+
children: localeService.t(item.label),
|
|
672
|
+
disabled: item.disable,
|
|
673
|
+
onSelect: () => handleClick(item)
|
|
674
|
+
})),
|
|
675
|
+
open: visible,
|
|
676
|
+
onOpenChange: onVisibleChange,
|
|
677
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
678
|
+
className: (0, _univerjs_design.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", _univerjs_design.borderClassName, {
|
|
679
|
+
"univer-bg-gray-100 dark:!univer-bg-gray-800": visible,
|
|
680
|
+
"univer-bg-white dark:!univer-bg-gray-900": !visible
|
|
681
|
+
}),
|
|
682
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.AutofillDoubleIcon, { className: "univer-fill-primary-600 univer-text-gray-900 dark:!univer-text-white" }), showMore && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.MoreDownIcon, { className: "dark:!univer-text-white" })]
|
|
683
|
+
})
|
|
684
|
+
})
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
//#endregion
|
|
689
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorateParam.js
|
|
690
|
+
function __decorateParam(paramIndex, decorator) {
|
|
691
|
+
return function(target, key) {
|
|
692
|
+
decorator(target, key, paramIndex);
|
|
693
|
+
};
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
//#endregion
|
|
697
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/decorate.js
|
|
698
|
+
function __decorate(decorators, target, key, desc) {
|
|
699
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
700
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
701
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
702
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
//#endregion
|
|
706
|
+
//#region src/controllers/drawing-ui.controller.ts
|
|
707
|
+
/**
|
|
708
|
+
* Copyright 2023-present DreamNum Co., Ltd.
|
|
709
|
+
*
|
|
710
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
711
|
+
* you may not use this file except in compliance with the License.
|
|
712
|
+
* You may obtain a copy of the License at
|
|
713
|
+
*
|
|
714
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
715
|
+
*
|
|
716
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
717
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
718
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
719
|
+
* See the License for the specific language governing permissions and
|
|
720
|
+
* limitations under the License.
|
|
721
|
+
*/
|
|
722
|
+
let DrawingUIController = class DrawingUIController extends _univerjs_core.Disposable {
|
|
723
|
+
constructor(_componentManager, _commandService, _menuManagerService) {
|
|
724
|
+
super();
|
|
725
|
+
this._componentManager = _componentManager;
|
|
726
|
+
this._commandService = _commandService;
|
|
727
|
+
this._menuManagerService = _menuManagerService;
|
|
728
|
+
this._init();
|
|
729
|
+
}
|
|
730
|
+
_init() {
|
|
731
|
+
this._initMenus();
|
|
732
|
+
this._initCommands();
|
|
733
|
+
this._initComponents();
|
|
734
|
+
}
|
|
735
|
+
_initMenus() {
|
|
736
|
+
this._menuManagerService.mergeMenu(menuSchema);
|
|
737
|
+
}
|
|
738
|
+
_initCommands() {
|
|
739
|
+
[
|
|
740
|
+
OpenImageCropOperation,
|
|
741
|
+
CloseImageCropOperation,
|
|
742
|
+
ImageResetSizeOperation,
|
|
743
|
+
SetDrawingAlignOperation,
|
|
744
|
+
SetDrawingAlignLeftOperation,
|
|
745
|
+
SetDrawingAlignCenterOperation,
|
|
746
|
+
SetDrawingAlignRightOperation,
|
|
747
|
+
SetDrawingAlignTopOperation,
|
|
748
|
+
SetDrawingAlignMiddleOperation,
|
|
749
|
+
SetDrawingAlignBottomOperation,
|
|
750
|
+
SetDrawingAlignHorizonOperation,
|
|
751
|
+
SetDrawingAlignVerticalOperation,
|
|
752
|
+
AutoImageCropOperation,
|
|
753
|
+
SetDrawingGroupOperation,
|
|
754
|
+
CancelDrawingGroupOperation,
|
|
755
|
+
SetDrawingArrangeOperation,
|
|
756
|
+
SetDrawingArrangeFrontOperation,
|
|
757
|
+
SetDrawingArrangeForwardOperation,
|
|
758
|
+
SetDrawingArrangeBackOperation,
|
|
759
|
+
SetDrawingArrangeBackwardOperation
|
|
760
|
+
].forEach((command) => this.disposeWithMe(this._commandService.registerCommand(command)));
|
|
761
|
+
}
|
|
762
|
+
_initComponents() {
|
|
763
|
+
[
|
|
764
|
+
[COMPONENT_IMAGE_POPUP_MENU, ImagePopupMenu],
|
|
765
|
+
["BottomIcon", _univerjs_icons.BottomIcon],
|
|
766
|
+
["GroupIcon", _univerjs_icons.GroupIcon],
|
|
767
|
+
["MoveDownIcon", _univerjs_icons.MoveDownIcon],
|
|
768
|
+
["MoveUpIcon", _univerjs_icons.MoveUpIcon],
|
|
769
|
+
["TopmostIcon", _univerjs_icons.TopmostIcon],
|
|
770
|
+
["UngroupIcon", _univerjs_icons.UngroupIcon]
|
|
771
|
+
].forEach(([key, component]) => {
|
|
772
|
+
this.disposeWithMe(this._componentManager.register(key, component));
|
|
773
|
+
});
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
DrawingUIController = __decorate([
|
|
777
|
+
__decorateParam(0, (0, _univerjs_core.Inject)(_univerjs_ui.ComponentManager)),
|
|
778
|
+
__decorateParam(1, _univerjs_core.ICommandService),
|
|
779
|
+
__decorateParam(2, _univerjs_ui.IMenuManagerService)
|
|
780
|
+
], DrawingUIController);
|
|
781
|
+
|
|
782
|
+
//#endregion
|
|
783
|
+
//#region src/utils/get-update-params.ts
|
|
784
|
+
function getUpdateParams(objects, drawingManagerService) {
|
|
785
|
+
const params = [];
|
|
786
|
+
objects.forEach((object) => {
|
|
787
|
+
const { oKey, left, top, height, width, angle } = object;
|
|
788
|
+
const searchParam = drawingManagerService.getDrawingOKey(oKey);
|
|
789
|
+
if (searchParam == null) {
|
|
790
|
+
params.push(null);
|
|
791
|
+
return true;
|
|
792
|
+
}
|
|
793
|
+
const { unitId, subUnitId, drawingId, drawingType } = searchParam;
|
|
794
|
+
const param = {
|
|
795
|
+
unitId,
|
|
796
|
+
subUnitId,
|
|
797
|
+
drawingId,
|
|
798
|
+
drawingType,
|
|
799
|
+
transform: {
|
|
800
|
+
left,
|
|
801
|
+
top,
|
|
802
|
+
height,
|
|
803
|
+
width,
|
|
804
|
+
angle
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
if (drawingType === _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) param.srcRect = object.srcRect;
|
|
808
|
+
params.push(param);
|
|
809
|
+
});
|
|
810
|
+
return params;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
//#endregion
|
|
814
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/typeof.js
|
|
815
|
+
function _typeof(o) {
|
|
816
|
+
"@babel/helpers - typeof";
|
|
817
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
|
|
818
|
+
return typeof o;
|
|
819
|
+
} : function(o) {
|
|
820
|
+
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
|
|
821
|
+
}, _typeof(o);
|
|
822
|
+
}
|
|
823
|
+
|
|
824
|
+
//#endregion
|
|
825
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPrimitive.js
|
|
826
|
+
function toPrimitive(t, r) {
|
|
827
|
+
if ("object" != _typeof(t) || !t) return t;
|
|
828
|
+
var e = t[Symbol.toPrimitive];
|
|
829
|
+
if (void 0 !== e) {
|
|
830
|
+
var i = e.call(t, r || "default");
|
|
831
|
+
if ("object" != _typeof(i)) return i;
|
|
832
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
833
|
+
}
|
|
834
|
+
return ("string" === r ? String : Number)(t);
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
//#endregion
|
|
838
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/toPropertyKey.js
|
|
839
|
+
function toPropertyKey(t) {
|
|
840
|
+
var i = toPrimitive(t, "string");
|
|
841
|
+
return "symbol" == _typeof(i) ? i : i + "";
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
//#endregion
|
|
845
|
+
//#region \0@oxc-project+runtime@0.124.0/helpers/defineProperty.js
|
|
846
|
+
function _defineProperty(e, r, t) {
|
|
847
|
+
return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
848
|
+
value: t,
|
|
849
|
+
enumerable: !0,
|
|
850
|
+
configurable: !0,
|
|
851
|
+
writable: !0
|
|
852
|
+
}) : e[r] = t, e;
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
//#endregion
|
|
856
|
+
//#region src/controllers/drawing-update.controller.ts
|
|
857
|
+
let DrawingUpdateController = class DrawingUpdateController extends _univerjs_core.Disposable {
|
|
858
|
+
constructor(_currentUniverService, _commandService, _renderManagerService, _drawingManagerService) {
|
|
859
|
+
super();
|
|
860
|
+
this._currentUniverService = _currentUniverService;
|
|
861
|
+
this._commandService = _commandService;
|
|
862
|
+
this._renderManagerService = _renderManagerService;
|
|
863
|
+
this._drawingManagerService = _drawingManagerService;
|
|
864
|
+
_defineProperty(this, "_sceneListenerOnDrawingMap", /* @__PURE__ */ new WeakSet());
|
|
865
|
+
this._initialize();
|
|
866
|
+
}
|
|
867
|
+
dispose() {
|
|
868
|
+
super.dispose();
|
|
869
|
+
}
|
|
870
|
+
_initialize() {
|
|
871
|
+
this._recoveryImages();
|
|
872
|
+
this._drawingAddListener();
|
|
873
|
+
this._drawingRemoveListener();
|
|
874
|
+
this._drawingUpdateListener();
|
|
875
|
+
this._commandExecutedListener();
|
|
876
|
+
this._drawingArrangeListener();
|
|
877
|
+
this._drawingGroupListener();
|
|
878
|
+
this._drawingRefreshListener();
|
|
879
|
+
this._drawingVisibleListener();
|
|
880
|
+
}
|
|
881
|
+
_recoveryImages() {
|
|
882
|
+
const drawingList = this._drawingManagerService.drawingManagerData;
|
|
883
|
+
const info = getCurrentUnitInfo(this._currentUniverService);
|
|
884
|
+
if (info == null) return;
|
|
885
|
+
const { unitId: currentUnitId, subUnitId: currentSubUnitId } = info;
|
|
886
|
+
Object.keys(drawingList).forEach((unitId) => {
|
|
887
|
+
Object.keys(drawingList[unitId]).forEach((subUnitId) => {
|
|
888
|
+
const drawingMap = drawingList[unitId][subUnitId].data;
|
|
889
|
+
if (drawingMap == null || unitId !== currentUnitId || subUnitId !== currentSubUnitId) return;
|
|
890
|
+
Object.keys(drawingMap).forEach((drawingId) => {
|
|
891
|
+
if (drawingMap[drawingId]) this._insertDrawing([{
|
|
892
|
+
unitId,
|
|
893
|
+
subUnitId,
|
|
894
|
+
drawingId
|
|
895
|
+
}]);
|
|
896
|
+
});
|
|
897
|
+
});
|
|
898
|
+
});
|
|
899
|
+
}
|
|
900
|
+
_commandExecutedListener() {
|
|
901
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
902
|
+
if (command.id === SetDrawingAlignOperation.id) {
|
|
903
|
+
const params = command.params;
|
|
904
|
+
if (params == null) return;
|
|
905
|
+
this._drawingAlign(params);
|
|
906
|
+
}
|
|
907
|
+
}));
|
|
908
|
+
}
|
|
909
|
+
_drawingGroupListener() {
|
|
910
|
+
this.disposeWithMe(this._drawingManagerService.group$.subscribe((params) => {
|
|
911
|
+
this._groupDrawings(params);
|
|
912
|
+
}));
|
|
913
|
+
this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe((params) => {
|
|
914
|
+
this._ungroupDrawings(params);
|
|
915
|
+
}));
|
|
916
|
+
}
|
|
917
|
+
_getSceneAndTransformerByDrawingSearch(unitId) {
|
|
918
|
+
if (unitId == null) return;
|
|
919
|
+
const renderObject = this._renderManagerService.getRenderById(unitId);
|
|
920
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
921
|
+
if (scene == null) return null;
|
|
922
|
+
return {
|
|
923
|
+
scene,
|
|
924
|
+
transformer: scene.getTransformerByCreate()
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
_groupDrawings(drawings) {
|
|
928
|
+
drawings.forEach((drawing) => {
|
|
929
|
+
this._groupDrawing(drawing);
|
|
930
|
+
});
|
|
931
|
+
}
|
|
932
|
+
_groupDrawing(params) {
|
|
933
|
+
const { parent, children } = params;
|
|
934
|
+
const { unitId, subUnitId, drawingId } = parent;
|
|
935
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(parent.unitId);
|
|
936
|
+
if (renderObject == null) return;
|
|
937
|
+
const { scene, transformer } = renderObject;
|
|
938
|
+
this._commandService.syncExecuteCommand(CloseImageCropOperation.id);
|
|
939
|
+
const objects = [];
|
|
940
|
+
children.forEach((drawing) => {
|
|
941
|
+
const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)(drawing);
|
|
942
|
+
const object = scene.getObjectIncludeInGroup(drawingShapeKey);
|
|
943
|
+
if (object == null || objects.includes(object)) return;
|
|
944
|
+
objects.push(object);
|
|
945
|
+
const { transform } = drawing;
|
|
946
|
+
if (transform == null) return;
|
|
947
|
+
if (object.classType === _univerjs_engine_render.RENDER_CLASS_TYPE.GROUP) object.transformByState({
|
|
948
|
+
left: transform.left,
|
|
949
|
+
top: transform.top
|
|
950
|
+
});
|
|
951
|
+
else object.transformByState(transform);
|
|
952
|
+
});
|
|
953
|
+
if (objects.length === 0) return;
|
|
954
|
+
const group = new _univerjs_engine_render.DrawingGroupObject((0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
955
|
+
unitId,
|
|
956
|
+
subUnitId,
|
|
957
|
+
drawingId
|
|
958
|
+
}));
|
|
959
|
+
scene.addObject(group, _univerjs_engine_render.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(group);
|
|
960
|
+
group.addObjects(...objects);
|
|
961
|
+
if (parent.groupBaseBound) group.setBaseBound(parent.groupBaseBound);
|
|
962
|
+
if (parent.groupId) {
|
|
963
|
+
group.isInGroup = true;
|
|
964
|
+
insertGroupObject({
|
|
965
|
+
drawingId: parent.groupId,
|
|
966
|
+
unitId,
|
|
967
|
+
subUnitId
|
|
968
|
+
}, group, scene, this._drawingManagerService);
|
|
969
|
+
}
|
|
970
|
+
parent.transform && group.transformByState({
|
|
971
|
+
left: parent.transform.left,
|
|
972
|
+
top: parent.transform.top,
|
|
973
|
+
width: parent.transform.width,
|
|
974
|
+
height: parent.transform.height,
|
|
975
|
+
angle: parent.transform.angle
|
|
976
|
+
});
|
|
977
|
+
transformer.clearSelectedObjects();
|
|
978
|
+
transformer.setSelectedControl(group);
|
|
979
|
+
}
|
|
980
|
+
_ungroupDrawings(drawings) {
|
|
981
|
+
drawings.forEach((drawing) => {
|
|
982
|
+
this._ungroupDrawing(drawing);
|
|
983
|
+
});
|
|
984
|
+
}
|
|
985
|
+
_ungroupDrawing(drawing) {
|
|
986
|
+
const { parent, children } = drawing;
|
|
987
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(parent.unitId);
|
|
988
|
+
if (renderObject == null) return;
|
|
989
|
+
const { scene, transformer } = renderObject;
|
|
990
|
+
children.forEach((drawing) => {
|
|
991
|
+
const drawingKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)(drawing);
|
|
992
|
+
const object = scene.getObjectIncludeInGroup(drawingKey);
|
|
993
|
+
if (object == null) return true;
|
|
994
|
+
if (object == null) return;
|
|
995
|
+
const { transform } = drawing;
|
|
996
|
+
if (transform == null) return;
|
|
997
|
+
if (object.classType === _univerjs_engine_render.RENDER_CLASS_TYPE.GROUP) object.transformByState({
|
|
998
|
+
left: transform.left,
|
|
999
|
+
top: transform.top
|
|
1000
|
+
});
|
|
1001
|
+
else object.transformByState(transform);
|
|
1002
|
+
});
|
|
1003
|
+
const groupKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)(parent);
|
|
1004
|
+
const group = scene.getObject(groupKey);
|
|
1005
|
+
const { width, height } = group;
|
|
1006
|
+
group.getObjects().forEach((object) => {
|
|
1007
|
+
group.removeSelfObjectAndTransform(object.oKey, width, height);
|
|
1008
|
+
});
|
|
1009
|
+
group.dispose();
|
|
1010
|
+
transformer.clearSelectedObjects();
|
|
1011
|
+
}
|
|
1012
|
+
_drawingAlign(params) {
|
|
1013
|
+
const { alignType } = params;
|
|
1014
|
+
const drawings = params.drawings || this._drawingManagerService.getFocusDrawings();
|
|
1015
|
+
if (alignType === AlignType.default) return;
|
|
1016
|
+
const drawingTransformCaches = [];
|
|
1017
|
+
let minLeft = Number.POSITIVE_INFINITY;
|
|
1018
|
+
let minTop = Number.POSITIVE_INFINITY;
|
|
1019
|
+
let maxRight = Number.NEGATIVE_INFINITY;
|
|
1020
|
+
let maxBottom = Number.NEGATIVE_INFINITY;
|
|
1021
|
+
let drawingCount = 0;
|
|
1022
|
+
drawings.forEach((drawing) => {
|
|
1023
|
+
const { unitId, subUnitId, drawingId, drawingType } = drawing;
|
|
1024
|
+
const drawingParam = this._drawingManagerService.getDrawingByParam({
|
|
1025
|
+
unitId,
|
|
1026
|
+
subUnitId,
|
|
1027
|
+
drawingId
|
|
1028
|
+
});
|
|
1029
|
+
if (drawingParam == null || drawingParam.transform == null) return;
|
|
1030
|
+
drawingTransformCaches.push({
|
|
1031
|
+
unitId,
|
|
1032
|
+
subUnitId,
|
|
1033
|
+
drawingId,
|
|
1034
|
+
drawingType,
|
|
1035
|
+
transform: drawingParam.transform
|
|
1036
|
+
});
|
|
1037
|
+
const { left = 0, top = 0, width = 0, height = 0 } = drawingParam.transform;
|
|
1038
|
+
minLeft = Math.min(minLeft, left);
|
|
1039
|
+
minTop = Math.min(minTop, top);
|
|
1040
|
+
maxRight = Math.max(maxRight, left + width);
|
|
1041
|
+
maxBottom = Math.max(maxBottom, top + height);
|
|
1042
|
+
drawingCount++;
|
|
1043
|
+
});
|
|
1044
|
+
if (drawingCount === 0) return;
|
|
1045
|
+
this._sortDrawingTransform(drawingTransformCaches, alignType);
|
|
1046
|
+
this._applyAlignType(drawingTransformCaches, alignType, minLeft, minTop, maxRight, maxBottom, drawingCount);
|
|
1047
|
+
}
|
|
1048
|
+
_applyAlignType(drawingTransformCaches, alignType, minLeft, minTop, maxRight, maxBottom, drawingCount) {
|
|
1049
|
+
const averageHorizon = Math.round((maxRight - minLeft) / drawingCount * 10) / 10;
|
|
1050
|
+
const averageVertical = Math.round((maxBottom - minTop) / drawingCount * 10) / 10;
|
|
1051
|
+
const updateParams = [];
|
|
1052
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(drawingTransformCaches[0].unitId);
|
|
1053
|
+
if (renderObject == null) return;
|
|
1054
|
+
const { scene, transformer } = renderObject;
|
|
1055
|
+
drawingTransformCaches.forEach((drawingTransformCache, index) => {
|
|
1056
|
+
const { unitId, subUnitId, drawingId, transform, drawingType } = drawingTransformCache;
|
|
1057
|
+
const { left = 0, top = 0, width = 0, height = 0 } = transform;
|
|
1058
|
+
let newLeft = left;
|
|
1059
|
+
let newTop = top;
|
|
1060
|
+
switch (alignType) {
|
|
1061
|
+
case AlignType.left:
|
|
1062
|
+
newLeft = minLeft;
|
|
1063
|
+
break;
|
|
1064
|
+
case AlignType.center:
|
|
1065
|
+
newLeft = minLeft + (maxRight - minLeft) / 2 - width / 2;
|
|
1066
|
+
break;
|
|
1067
|
+
case AlignType.right:
|
|
1068
|
+
newLeft = maxRight - width;
|
|
1069
|
+
break;
|
|
1070
|
+
case AlignType.top:
|
|
1071
|
+
newTop = minTop;
|
|
1072
|
+
break;
|
|
1073
|
+
case AlignType.middle:
|
|
1074
|
+
newTop = minTop + (maxBottom - minTop) / 2 - height / 2;
|
|
1075
|
+
break;
|
|
1076
|
+
case AlignType.bottom:
|
|
1077
|
+
newTop = maxBottom - height;
|
|
1078
|
+
break;
|
|
1079
|
+
case AlignType.horizon:
|
|
1080
|
+
newLeft = minLeft + averageHorizon * index;
|
|
1081
|
+
break;
|
|
1082
|
+
case AlignType.vertical:
|
|
1083
|
+
newTop = minTop + averageVertical * index;
|
|
1084
|
+
break;
|
|
1085
|
+
default: break;
|
|
1086
|
+
}
|
|
1087
|
+
if (newLeft !== left || newTop !== top) updateParams.push({
|
|
1088
|
+
unitId,
|
|
1089
|
+
subUnitId,
|
|
1090
|
+
drawingId,
|
|
1091
|
+
drawingType,
|
|
1092
|
+
transform: {
|
|
1093
|
+
left: newLeft,
|
|
1094
|
+
top: newTop
|
|
1095
|
+
}
|
|
1096
|
+
});
|
|
1097
|
+
});
|
|
1098
|
+
this._drawingManagerService.featurePluginUpdateNotification(updateParams);
|
|
1099
|
+
transformer.refreshControls().changeNotification();
|
|
1100
|
+
}
|
|
1101
|
+
_sortDrawingTransform(drawingTransformCaches, alignType) {
|
|
1102
|
+
drawingTransformCaches.sort((a, b) => {
|
|
1103
|
+
const aTransform = a.transform;
|
|
1104
|
+
const bTransform = b.transform;
|
|
1105
|
+
const { left: aLeft = 0, top: aTop = 0, width: aWidth = 0, height: aHeight = 0 } = aTransform;
|
|
1106
|
+
const { left: bLeft = 0, top: bTop = 0, width: bWidth = 0, height: bHeight = 0 } = bTransform;
|
|
1107
|
+
switch (alignType) {
|
|
1108
|
+
case AlignType.left: return aLeft - bLeft;
|
|
1109
|
+
case AlignType.center: return aLeft + aWidth / 2 - (bLeft + bWidth / 2);
|
|
1110
|
+
case AlignType.right: return aLeft + aWidth - (bLeft + bWidth);
|
|
1111
|
+
case AlignType.top: return aTop - bTop;
|
|
1112
|
+
case AlignType.middle: return aTop + aHeight / 2 - (bTop + bHeight / 2);
|
|
1113
|
+
case AlignType.bottom: return aTop + aHeight - (bTop + bHeight);
|
|
1114
|
+
case AlignType.horizon: return aLeft + aWidth / 2 - (bLeft + bWidth / 2);
|
|
1115
|
+
case AlignType.vertical: return aTop + aHeight / 2 - (bTop + bHeight / 2);
|
|
1116
|
+
default: return 0;
|
|
1117
|
+
}
|
|
1118
|
+
});
|
|
1119
|
+
}
|
|
1120
|
+
_drawingArrangeListener() {
|
|
1121
|
+
this.disposeWithMe(this._drawingManagerService.order$.subscribe((params) => {
|
|
1122
|
+
this._drawingArrange(params);
|
|
1123
|
+
}));
|
|
1124
|
+
}
|
|
1125
|
+
_drawingArrange(params) {
|
|
1126
|
+
const { unitId, subUnitId, drawingIds } = params;
|
|
1127
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
1128
|
+
if (renderObject == null) return;
|
|
1129
|
+
const { scene } = renderObject;
|
|
1130
|
+
drawingIds.forEach((drawingId) => {
|
|
1131
|
+
const oKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
1132
|
+
unitId,
|
|
1133
|
+
subUnitId,
|
|
1134
|
+
drawingId
|
|
1135
|
+
});
|
|
1136
|
+
const drawingShapes = scene.fuzzyMathObjects(oKey, true);
|
|
1137
|
+
if (drawingShapes == null || drawingShapes.length === 0) return;
|
|
1138
|
+
const index = this._drawingManagerService.getDrawingOrder(unitId, subUnitId).indexOf(drawingId);
|
|
1139
|
+
for (const shape of drawingShapes) {
|
|
1140
|
+
shape.setProps({ zIndex: index });
|
|
1141
|
+
shape.makeDirty();
|
|
1142
|
+
}
|
|
1143
|
+
});
|
|
1144
|
+
}
|
|
1145
|
+
_drawingAddListener() {
|
|
1146
|
+
this.disposeWithMe(this._drawingManagerService.add$.subscribe((params) => {
|
|
1147
|
+
this._insertDrawing(params);
|
|
1148
|
+
}));
|
|
1149
|
+
}
|
|
1150
|
+
_insertDrawing(params) {
|
|
1151
|
+
const sceneList = [];
|
|
1152
|
+
params.forEach((param) => {
|
|
1153
|
+
const { unitId } = param;
|
|
1154
|
+
if (this._drawingManagerService.getDrawingByParam(param) == null) return;
|
|
1155
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
1156
|
+
if (renderObject == null) return;
|
|
1157
|
+
const { scene } = renderObject;
|
|
1158
|
+
if (!sceneList.includes(scene)) sceneList.push(scene);
|
|
1159
|
+
});
|
|
1160
|
+
sceneList.forEach((scene) => {
|
|
1161
|
+
if (this._sceneListenerOnDrawingMap.has(scene)) return;
|
|
1162
|
+
this._addListenerOnDrawing(scene);
|
|
1163
|
+
this._sceneListenerOnDrawingMap.add(scene);
|
|
1164
|
+
});
|
|
1165
|
+
}
|
|
1166
|
+
_drawingRemoveListener() {
|
|
1167
|
+
this.disposeWithMe(this._drawingManagerService.remove$.subscribe((params) => {
|
|
1168
|
+
params.forEach((param) => {
|
|
1169
|
+
const { unitId, subUnitId, drawingId } = param;
|
|
1170
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
1171
|
+
if (renderObject == null) return;
|
|
1172
|
+
const { scene } = renderObject;
|
|
1173
|
+
const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
1174
|
+
unitId,
|
|
1175
|
+
subUnitId,
|
|
1176
|
+
drawingId
|
|
1177
|
+
});
|
|
1178
|
+
const drawingShapes = scene.fuzzyMathObjects(drawingShapeKey, true);
|
|
1179
|
+
if (drawingShapes.length > 0) {
|
|
1180
|
+
var _scene$getTransformer;
|
|
1181
|
+
for (const drawingShape of drawingShapes) drawingShape.dispose();
|
|
1182
|
+
(_scene$getTransformer = scene.getTransformer()) === null || _scene$getTransformer === void 0 || _scene$getTransformer.clearSelectedObjects();
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
}));
|
|
1186
|
+
}
|
|
1187
|
+
_drawingUpdateListener() {
|
|
1188
|
+
this.disposeWithMe(this._drawingManagerService.update$.subscribe((params) => {
|
|
1189
|
+
params.forEach((param) => {
|
|
1190
|
+
var _scene$getTransformer2;
|
|
1191
|
+
const { unitId, subUnitId, drawingId } = param;
|
|
1192
|
+
const drawingParam = this._drawingManagerService.getDrawingByParam(param);
|
|
1193
|
+
if (drawingParam == null) return;
|
|
1194
|
+
const { transform, drawingType } = drawingParam;
|
|
1195
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
1196
|
+
if (renderObject == null) return;
|
|
1197
|
+
const { scene, transformer } = renderObject;
|
|
1198
|
+
if (transform == null) return true;
|
|
1199
|
+
const { left = 0, top = 0, width = 0, height = 0, angle = 0, flipX = false, flipY = false, skewX = 0, skewY = 0 } = transform;
|
|
1200
|
+
const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
1201
|
+
unitId,
|
|
1202
|
+
subUnitId,
|
|
1203
|
+
drawingId
|
|
1204
|
+
});
|
|
1205
|
+
const drawingShape = scene.getObject(drawingShapeKey);
|
|
1206
|
+
if (drawingShape == null) return true;
|
|
1207
|
+
drawingShape.transformByState({
|
|
1208
|
+
left,
|
|
1209
|
+
top,
|
|
1210
|
+
width,
|
|
1211
|
+
height,
|
|
1212
|
+
angle,
|
|
1213
|
+
flipX,
|
|
1214
|
+
flipY,
|
|
1215
|
+
skewX,
|
|
1216
|
+
skewY
|
|
1217
|
+
});
|
|
1218
|
+
(_scene$getTransformer2 = scene.getTransformer()) === null || _scene$getTransformer2 === void 0 || _scene$getTransformer2.debounceRefreshControls();
|
|
1219
|
+
});
|
|
1220
|
+
}));
|
|
1221
|
+
}
|
|
1222
|
+
_drawingRefreshListener() {
|
|
1223
|
+
this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe((params) => {
|
|
1224
|
+
params.forEach((param) => {
|
|
1225
|
+
const { unitId, subUnitId, drawingId } = param;
|
|
1226
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
1227
|
+
if (renderObject == null) return;
|
|
1228
|
+
const drawingParam = this._drawingManagerService.getDrawingByParam(param);
|
|
1229
|
+
if (drawingParam == null) return;
|
|
1230
|
+
const { transform } = drawingParam;
|
|
1231
|
+
const { scene } = renderObject;
|
|
1232
|
+
const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
1233
|
+
unitId,
|
|
1234
|
+
subUnitId,
|
|
1235
|
+
drawingId
|
|
1236
|
+
});
|
|
1237
|
+
const drawingShape = scene.getObject(drawingShapeKey);
|
|
1238
|
+
if (drawingShape == null || transform == null) return true;
|
|
1239
|
+
const { left = 0, top = 0, width = 0, height = 0, angle = 0, flipX = false, flipY = false, skewX = 0, skewY = 0 } = transform;
|
|
1240
|
+
drawingShape.transformByState({
|
|
1241
|
+
left,
|
|
1242
|
+
top,
|
|
1243
|
+
width,
|
|
1244
|
+
height,
|
|
1245
|
+
angle,
|
|
1246
|
+
flipX,
|
|
1247
|
+
flipY,
|
|
1248
|
+
skewX,
|
|
1249
|
+
skewY
|
|
1250
|
+
});
|
|
1251
|
+
});
|
|
1252
|
+
}));
|
|
1253
|
+
}
|
|
1254
|
+
_drawingVisibleListener() {
|
|
1255
|
+
this.disposeWithMe(this._drawingManagerService.visible$.subscribe((params) => {
|
|
1256
|
+
params.forEach((param) => {
|
|
1257
|
+
const { unitId, subUnitId, drawingId, visible } = param;
|
|
1258
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
1259
|
+
if (renderObject == null) return;
|
|
1260
|
+
const { scene } = renderObject;
|
|
1261
|
+
const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
1262
|
+
unitId,
|
|
1263
|
+
subUnitId,
|
|
1264
|
+
drawingId
|
|
1265
|
+
});
|
|
1266
|
+
const drawingShape = scene.getObject(drawingShapeKey);
|
|
1267
|
+
if (drawingShape == null) return true;
|
|
1268
|
+
if (visible) drawingShape.show();
|
|
1269
|
+
else drawingShape.hide();
|
|
1270
|
+
});
|
|
1271
|
+
}));
|
|
1272
|
+
}
|
|
1273
|
+
_filterUpdateParams(params, startTransforms) {
|
|
1274
|
+
return params.filter((param, index) => {
|
|
1275
|
+
if (param == null) return false;
|
|
1276
|
+
const { transform } = param;
|
|
1277
|
+
return (0, _univerjs_core.checkIfMove)(transform, startTransforms === null || startTransforms === void 0 ? void 0 : startTransforms[index]);
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
_addListenerOnDrawing(scene) {
|
|
1281
|
+
const transformer = scene.getTransformerByCreate();
|
|
1282
|
+
let startTransforms = null;
|
|
1283
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(transformer.changeStart$.subscribe((state) => {
|
|
1284
|
+
const { objects } = state;
|
|
1285
|
+
const objectArray = Array.from(objects.values());
|
|
1286
|
+
const drawings = [];
|
|
1287
|
+
startTransforms = objectArray.map((object) => {
|
|
1288
|
+
const { left, top, height, width, angle, oKey, isInGroup } = object;
|
|
1289
|
+
const drawing = this._drawingManagerService.getDrawingOKey(oKey);
|
|
1290
|
+
if (isInGroup || object instanceof _univerjs_engine_render.Group) {
|
|
1291
|
+
let group = object.ancestorGroup;
|
|
1292
|
+
if (group == null && object instanceof _univerjs_engine_render.Group) group = object;
|
|
1293
|
+
if (group == null) return null;
|
|
1294
|
+
const groupDrawing = this._drawingManagerService.getDrawingOKey(group.oKey);
|
|
1295
|
+
if (groupDrawing) {
|
|
1296
|
+
const { unitId, subUnitId, drawingId } = groupDrawing;
|
|
1297
|
+
drawings.push({
|
|
1298
|
+
unitId,
|
|
1299
|
+
subUnitId,
|
|
1300
|
+
drawingId
|
|
1301
|
+
});
|
|
1302
|
+
const { left, top, height, width, angle } = group;
|
|
1303
|
+
return {
|
|
1304
|
+
left,
|
|
1305
|
+
top,
|
|
1306
|
+
height,
|
|
1307
|
+
width,
|
|
1308
|
+
angle
|
|
1309
|
+
};
|
|
1310
|
+
}
|
|
1311
|
+
} else if (drawing != null) {
|
|
1312
|
+
const { unitId, subUnitId, drawingId } = drawing;
|
|
1313
|
+
drawings.push({
|
|
1314
|
+
unitId,
|
|
1315
|
+
subUnitId,
|
|
1316
|
+
drawingId
|
|
1317
|
+
});
|
|
1318
|
+
return {
|
|
1319
|
+
left,
|
|
1320
|
+
top,
|
|
1321
|
+
height,
|
|
1322
|
+
width,
|
|
1323
|
+
angle
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
return null;
|
|
1327
|
+
}).filter((transform) => transform != null);
|
|
1328
|
+
if (drawings.length > 0) this._commandService.syncExecuteCommand(_univerjs_drawing.SetDrawingSelectedOperation.id, drawings);
|
|
1329
|
+
else this._commandService.syncExecuteCommand(_univerjs_drawing.SetDrawingSelectedOperation.id, []);
|
|
1330
|
+
})));
|
|
1331
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(transformer.changeEnd$.subscribe((state) => {
|
|
1332
|
+
const { objects } = state;
|
|
1333
|
+
const params = this._filterUpdateParams(getUpdateParams(objects, this._drawingManagerService), startTransforms);
|
|
1334
|
+
if (params.length > 0) this._drawingManagerService.featurePluginUpdateNotification(params);
|
|
1335
|
+
})));
|
|
1336
|
+
}
|
|
1337
|
+
};
|
|
1338
|
+
DrawingUpdateController = __decorate([
|
|
1339
|
+
__decorateParam(0, _univerjs_core.IUniverInstanceService),
|
|
1340
|
+
__decorateParam(1, _univerjs_core.ICommandService),
|
|
1341
|
+
__decorateParam(2, _univerjs_engine_render.IRenderManagerService),
|
|
1342
|
+
__decorateParam(3, _univerjs_drawing.IDrawingManagerService)
|
|
1343
|
+
], DrawingUpdateController);
|
|
1344
|
+
|
|
1345
|
+
//#endregion
|
|
1346
|
+
//#region src/views/crop/image-cropper-object.ts
|
|
1347
|
+
var ImageCropperObjectType = /* @__PURE__ */ function(ImageCropperObjectType) {
|
|
1348
|
+
ImageCropperObjectType[ImageCropperObjectType["RECT"] = 0] = "RECT";
|
|
1349
|
+
ImageCropperObjectType[ImageCropperObjectType["PATH"] = 1] = "PATH";
|
|
1350
|
+
return ImageCropperObjectType;
|
|
1351
|
+
}(ImageCropperObjectType || {});
|
|
1352
|
+
var ImageCropperObject = class extends _univerjs_engine_render.Shape {
|
|
1353
|
+
constructor(key, props) {
|
|
1354
|
+
if (props == null) props = {};
|
|
1355
|
+
props.transformerConfig = {
|
|
1356
|
+
keepRatio: false,
|
|
1357
|
+
isCropper: true,
|
|
1358
|
+
anchorFill: "rgb(0, 0, 0)",
|
|
1359
|
+
anchorStroke: "rgb(255, 255, 255)",
|
|
1360
|
+
anchorSize: 24
|
|
1361
|
+
};
|
|
1362
|
+
super(key, props);
|
|
1363
|
+
_defineProperty(this, "_srcRect", void 0);
|
|
1364
|
+
_defineProperty(this, "_prstGeom", void 0);
|
|
1365
|
+
_defineProperty(this, "_applyTransform", void 0);
|
|
1366
|
+
_defineProperty(this, "_dragPadding", 8);
|
|
1367
|
+
_defineProperty(this, "_cacheCanvas", void 0);
|
|
1368
|
+
if (props === null || props === void 0 ? void 0 : props.srcRect) this._srcRect = props.srcRect;
|
|
1369
|
+
if (props === null || props === void 0 ? void 0 : props.prstGeom) this._prstGeom = props.prstGeom;
|
|
1370
|
+
if (props === null || props === void 0 ? void 0 : props.applyTransform) this._applyTransform = props.applyTransform;
|
|
1371
|
+
if (props === null || props === void 0 ? void 0 : props.dragPadding) this._dragPadding = props.dragPadding;
|
|
1372
|
+
this._applyProps();
|
|
1373
|
+
}
|
|
1374
|
+
refreshSrcRect(value, transform) {
|
|
1375
|
+
this._srcRect = value;
|
|
1376
|
+
this._applyTransform = transform;
|
|
1377
|
+
this._applyProps();
|
|
1378
|
+
}
|
|
1379
|
+
get srcRect() {
|
|
1380
|
+
return this._srcRect;
|
|
1381
|
+
}
|
|
1382
|
+
dispose() {
|
|
1383
|
+
var _this$_cacheCanvas;
|
|
1384
|
+
super.dispose();
|
|
1385
|
+
(_this$_cacheCanvas = this._cacheCanvas) === null || _this$_cacheCanvas === void 0 || _this$_cacheCanvas.dispose();
|
|
1386
|
+
this._srcRect = null;
|
|
1387
|
+
}
|
|
1388
|
+
isHit(coord) {
|
|
1389
|
+
const oCoord = this.getInverseCoord(coord);
|
|
1390
|
+
if (oCoord.x >= -this.strokeWidth / 2 && oCoord.x <= this.width + this.strokeWidth / 2 && oCoord.y >= -this.strokeWidth / 2 && oCoord.y <= this.height + this.strokeWidth / 2 && !this._inSurround(oCoord)) return true;
|
|
1391
|
+
return false;
|
|
1392
|
+
}
|
|
1393
|
+
_inSurround(oCoord) {
|
|
1394
|
+
const padding = this._dragPadding;
|
|
1395
|
+
if (oCoord.x >= padding - this.strokeWidth / 2 && oCoord.x <= this.width + this.strokeWidth / 2 - padding && oCoord.y >= padding - this.strokeWidth / 2 && oCoord.y <= this.height + this.strokeWidth / 2 - padding) return true;
|
|
1396
|
+
return false;
|
|
1397
|
+
}
|
|
1398
|
+
render(mainCtx, bounds) {
|
|
1399
|
+
if (!this.visible) {
|
|
1400
|
+
this.makeDirty(false);
|
|
1401
|
+
return this;
|
|
1402
|
+
}
|
|
1403
|
+
mainCtx.save();
|
|
1404
|
+
this._draw(mainCtx);
|
|
1405
|
+
mainCtx.restore();
|
|
1406
|
+
this.makeDirty(false);
|
|
1407
|
+
return this;
|
|
1408
|
+
}
|
|
1409
|
+
_draw(ctx) {
|
|
1410
|
+
var _this$_cacheCanvas2, _this$_cacheCanvas3;
|
|
1411
|
+
const { width: engineWidth, height: engineHeight } = this.getScene().getEngine();
|
|
1412
|
+
this._initialCacheCanvas();
|
|
1413
|
+
(_this$_cacheCanvas2 = this._cacheCanvas) === null || _this$_cacheCanvas2 === void 0 || _this$_cacheCanvas2.clear();
|
|
1414
|
+
const cacheCtx = (_this$_cacheCanvas3 = this._cacheCanvas) === null || _this$_cacheCanvas3 === void 0 ? void 0 : _this$_cacheCanvas3.getContext();
|
|
1415
|
+
if (cacheCtx == null) return;
|
|
1416
|
+
cacheCtx.save();
|
|
1417
|
+
_univerjs_engine_render.Rect.drawWith(cacheCtx, {
|
|
1418
|
+
left: 0,
|
|
1419
|
+
top: 0,
|
|
1420
|
+
width: engineWidth,
|
|
1421
|
+
height: engineHeight,
|
|
1422
|
+
fill: "rgba(0, 0, 0, 0.5)"
|
|
1423
|
+
});
|
|
1424
|
+
cacheCtx.setTransform(ctx.getTransform());
|
|
1425
|
+
this._clipForApplyObject(cacheCtx);
|
|
1426
|
+
this._applyCache(ctx);
|
|
1427
|
+
cacheCtx.restore();
|
|
1428
|
+
}
|
|
1429
|
+
_clipForApplyObject(cacheCtx) {
|
|
1430
|
+
let objectType = ImageCropperObjectType.RECT;
|
|
1431
|
+
if (this._prstGeom != null) objectType = ImageCropperObjectType.PATH;
|
|
1432
|
+
cacheCtx.globalCompositeOperation = "destination-out";
|
|
1433
|
+
cacheCtx.beginPath();
|
|
1434
|
+
if (objectType === ImageCropperObjectType.RECT) {
|
|
1435
|
+
const m = this.transform.getMatrix();
|
|
1436
|
+
cacheCtx.transform(m[0], m[1], m[2], m[3], m[4], m[5]);
|
|
1437
|
+
cacheCtx.rect(0, 0, this.width, this.height);
|
|
1438
|
+
cacheCtx.fill();
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
_applyProps() {
|
|
1442
|
+
if (this._applyTransform == null) return;
|
|
1443
|
+
let cropLeft = 0;
|
|
1444
|
+
let cropTop = 0;
|
|
1445
|
+
let cropRight = 0;
|
|
1446
|
+
let cropBottom = 0;
|
|
1447
|
+
const { left: applyLeft = 0, top: applyTop = 0, width: applyWidth = 0, height: applyHeight = 0, angle } = this._applyTransform;
|
|
1448
|
+
if (this._srcRect != null) {
|
|
1449
|
+
const { left = 0, top = 0, right = 0, bottom = 0 } = this._srcRect;
|
|
1450
|
+
cropLeft = left;
|
|
1451
|
+
cropTop = top;
|
|
1452
|
+
cropRight = right;
|
|
1453
|
+
cropBottom = bottom;
|
|
1454
|
+
}
|
|
1455
|
+
const left = applyLeft + cropLeft;
|
|
1456
|
+
const top = applyTop + cropTop;
|
|
1457
|
+
this.transformByState({
|
|
1458
|
+
left,
|
|
1459
|
+
top,
|
|
1460
|
+
width: applyLeft + applyWidth - cropRight - left,
|
|
1461
|
+
height: applyTop + applyHeight - cropBottom - top,
|
|
1462
|
+
angle
|
|
1463
|
+
});
|
|
1464
|
+
}
|
|
1465
|
+
_applyCache(ctx) {
|
|
1466
|
+
if (!ctx || this._cacheCanvas == null) return;
|
|
1467
|
+
const cacheCtx = this._cacheCanvas.getContext();
|
|
1468
|
+
cacheCtx.save();
|
|
1469
|
+
ctx.save();
|
|
1470
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
1471
|
+
cacheCtx.setTransform(1, 0, 0, 1, 0, 0);
|
|
1472
|
+
ctx.drawImage(this._cacheCanvas.getCanvasEle(), 0, 0);
|
|
1473
|
+
ctx.restore();
|
|
1474
|
+
cacheCtx.restore();
|
|
1475
|
+
}
|
|
1476
|
+
_initialCacheCanvas() {
|
|
1477
|
+
if (this._cacheCanvas != null) return;
|
|
1478
|
+
const scene = this.getScene();
|
|
1479
|
+
if (scene == null) return;
|
|
1480
|
+
this._cacheCanvas = new _univerjs_engine_render.Canvas();
|
|
1481
|
+
const engine = scene.getEngine();
|
|
1482
|
+
this._cacheCanvas.setSize(engine.width, engine.height);
|
|
1483
|
+
engine.onTransformChange$.subscribeEvent(() => {
|
|
1484
|
+
var _this$_cacheCanvas4;
|
|
1485
|
+
(_this$_cacheCanvas4 = this._cacheCanvas) === null || _this$_cacheCanvas4 === void 0 || _this$_cacheCanvas4.setSize(engine.width, engine.height);
|
|
1486
|
+
this.makeDirty(true);
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
};
|
|
1490
|
+
|
|
1491
|
+
//#endregion
|
|
1492
|
+
//#region src/controllers/image-cropper.controller.ts
|
|
1493
|
+
let ImageCropperController = class ImageCropperController extends _univerjs_core.Disposable {
|
|
1494
|
+
constructor(_commandService, _drawingManagerService, _renderManagerService, _univerInstanceService, _messageService, _localeService) {
|
|
1495
|
+
super();
|
|
1496
|
+
this._commandService = _commandService;
|
|
1497
|
+
this._drawingManagerService = _drawingManagerService;
|
|
1498
|
+
this._renderManagerService = _renderManagerService;
|
|
1499
|
+
this._univerInstanceService = _univerInstanceService;
|
|
1500
|
+
this._messageService = _messageService;
|
|
1501
|
+
this._localeService = _localeService;
|
|
1502
|
+
_defineProperty(this, "_sceneListenerOnImageMap", /* @__PURE__ */ new WeakSet());
|
|
1503
|
+
this._init();
|
|
1504
|
+
}
|
|
1505
|
+
_init() {
|
|
1506
|
+
this._initOpenCrop();
|
|
1507
|
+
this._initCloseCrop();
|
|
1508
|
+
this._initAutoCrop();
|
|
1509
|
+
}
|
|
1510
|
+
_initAutoCrop() {
|
|
1511
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
1512
|
+
if (command.id !== AutoImageCropOperation.id) return;
|
|
1513
|
+
const params = command.params;
|
|
1514
|
+
if (params == null) return;
|
|
1515
|
+
const { cropType } = params;
|
|
1516
|
+
const drawingParams = this._drawingManagerService.getFocusDrawings();
|
|
1517
|
+
if (drawingParams.length !== 1) return;
|
|
1518
|
+
const { unitId, subUnitId, drawingId } = drawingParams[0];
|
|
1519
|
+
const renderObject = this._renderManagerService.getRenderById(unitId);
|
|
1520
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1521
|
+
if (scene == null) return true;
|
|
1522
|
+
if (this._searchCropObject(scene) != null) this._commandService.syncExecuteCommand(CloseImageCropOperation.id, { isAuto: true });
|
|
1523
|
+
const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
1524
|
+
unitId,
|
|
1525
|
+
subUnitId,
|
|
1526
|
+
drawingId
|
|
1527
|
+
});
|
|
1528
|
+
const imageShape = scene.getObject(imageShapeKey);
|
|
1529
|
+
if (!(imageShape instanceof _univerjs_engine_render.Image)) {
|
|
1530
|
+
this._messageService.show({
|
|
1531
|
+
type: _univerjs_design.MessageType.Error,
|
|
1532
|
+
content: this._localeService.t("image-cropper.error")
|
|
1533
|
+
});
|
|
1534
|
+
return;
|
|
1535
|
+
}
|
|
1536
|
+
if (imageShape == null) return;
|
|
1537
|
+
this._updateCropperObject(cropType, imageShape);
|
|
1538
|
+
this._commandService.executeCommand(OpenImageCropOperation.id, {
|
|
1539
|
+
unitId,
|
|
1540
|
+
subUnitId,
|
|
1541
|
+
drawingId
|
|
1542
|
+
});
|
|
1543
|
+
}));
|
|
1544
|
+
}
|
|
1545
|
+
_calculateSrcRectByRatio(left, top, width, height, numerator, denominator) {
|
|
1546
|
+
const srcRatio = width / height;
|
|
1547
|
+
const ratio = numerator / denominator;
|
|
1548
|
+
let newWidth = width;
|
|
1549
|
+
let newHeight = height;
|
|
1550
|
+
if (srcRatio > ratio) newWidth = height * ratio;
|
|
1551
|
+
else newHeight = width / ratio;
|
|
1552
|
+
const newLeft = (width - newWidth) / 2;
|
|
1553
|
+
const newTop = (height - newHeight) / 2;
|
|
1554
|
+
return {
|
|
1555
|
+
left: (0, _univerjs_engine_render.precisionTo)(newLeft, 1),
|
|
1556
|
+
top: (0, _univerjs_engine_render.precisionTo)(newTop, 1),
|
|
1557
|
+
right: (0, _univerjs_engine_render.precisionTo)(width - (newLeft + newWidth), 1),
|
|
1558
|
+
bottom: (0, _univerjs_engine_render.precisionTo)(height - (newTop + newHeight), 1)
|
|
1559
|
+
};
|
|
1560
|
+
}
|
|
1561
|
+
_updateCropperObject(cropType, imageShape) {
|
|
1562
|
+
const { left, top, width, height } = imageShape.calculateTransformWithSrcRect();
|
|
1563
|
+
let newSrcRect;
|
|
1564
|
+
switch (cropType) {
|
|
1565
|
+
case CropType.R1_1:
|
|
1566
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 1, 1);
|
|
1567
|
+
break;
|
|
1568
|
+
case CropType.R16_9:
|
|
1569
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 16, 9);
|
|
1570
|
+
break;
|
|
1571
|
+
case CropType.R9_16:
|
|
1572
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 9, 16);
|
|
1573
|
+
break;
|
|
1574
|
+
case CropType.R5_4:
|
|
1575
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 5, 4);
|
|
1576
|
+
break;
|
|
1577
|
+
case CropType.R4_5:
|
|
1578
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 4, 5);
|
|
1579
|
+
break;
|
|
1580
|
+
case CropType.R4_3:
|
|
1581
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 4, 3);
|
|
1582
|
+
break;
|
|
1583
|
+
case CropType.R3_4:
|
|
1584
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 3, 4);
|
|
1585
|
+
break;
|
|
1586
|
+
case CropType.R3_2:
|
|
1587
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 3, 2);
|
|
1588
|
+
break;
|
|
1589
|
+
case CropType.R2_3:
|
|
1590
|
+
newSrcRect = this._calculateSrcRectByRatio(left, top, width, height, 2, 3);
|
|
1591
|
+
break;
|
|
1592
|
+
case CropType.FREE:
|
|
1593
|
+
default: break;
|
|
1594
|
+
}
|
|
1595
|
+
if (newSrcRect == null) return;
|
|
1596
|
+
imageShape.setSrcRect(newSrcRect);
|
|
1597
|
+
const { left: newLeft = 0, top: newTop = 0, bottom: newBottom = 0, right: newRight = 0 } = newSrcRect;
|
|
1598
|
+
imageShape.transformByStateCloseCropper({
|
|
1599
|
+
left: left + newLeft,
|
|
1600
|
+
top: top + newTop,
|
|
1601
|
+
width: width - newRight - newLeft,
|
|
1602
|
+
height: height - newBottom - newTop
|
|
1603
|
+
});
|
|
1604
|
+
}
|
|
1605
|
+
_initOpenCrop() {
|
|
1606
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
1607
|
+
if (command.id !== OpenImageCropOperation.id) return;
|
|
1608
|
+
const params = command.params;
|
|
1609
|
+
if (params == null) return;
|
|
1610
|
+
const { unitId, subUnitId, drawingId } = params;
|
|
1611
|
+
const renderObject = this._renderManagerService.getRenderById(unitId);
|
|
1612
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1613
|
+
if (scene == null) return true;
|
|
1614
|
+
if (!this._sceneListenerOnImageMap.has(scene)) {
|
|
1615
|
+
this._addListenerOnImage(scene);
|
|
1616
|
+
this._sceneListenerOnImageMap.add(scene);
|
|
1617
|
+
}
|
|
1618
|
+
if (this._drawingManagerService.getDrawingByParam({
|
|
1619
|
+
unitId,
|
|
1620
|
+
subUnitId,
|
|
1621
|
+
drawingId
|
|
1622
|
+
}) == null) return;
|
|
1623
|
+
const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
1624
|
+
unitId,
|
|
1625
|
+
subUnitId,
|
|
1626
|
+
drawingId
|
|
1627
|
+
});
|
|
1628
|
+
const imageShape = scene.getObject(imageShapeKey);
|
|
1629
|
+
if (imageShape == null) return;
|
|
1630
|
+
if (!(imageShape instanceof _univerjs_engine_render.Image)) {
|
|
1631
|
+
this._messageService.show({
|
|
1632
|
+
type: _univerjs_design.MessageType.Error,
|
|
1633
|
+
content: this._localeService.t("image-cropper.error")
|
|
1634
|
+
});
|
|
1635
|
+
return;
|
|
1636
|
+
}
|
|
1637
|
+
const transformer = scene.getTransformer();
|
|
1638
|
+
transformer === null || transformer === void 0 || transformer.clearControls();
|
|
1639
|
+
const imageCropperObject = new ImageCropperObject(`${imageShapeKey}-crop`, {
|
|
1640
|
+
srcRect: imageShape.srcRect,
|
|
1641
|
+
prstGeom: imageShape.prstGeom,
|
|
1642
|
+
applyTransform: imageShape.calculateTransformWithSrcRect()
|
|
1643
|
+
});
|
|
1644
|
+
scene.addObject(imageCropperObject, imageShape.getLayerIndex() + 1).attachTransformerTo(imageCropperObject);
|
|
1645
|
+
transformer === null || transformer === void 0 || transformer.createControlForCopper(imageCropperObject);
|
|
1646
|
+
this._addHoverForImageCopper(imageCropperObject);
|
|
1647
|
+
imageShape.openRenderByCropper();
|
|
1648
|
+
transformer === null || transformer === void 0 || transformer.refreshControls();
|
|
1649
|
+
imageCropperObject.makeDirty(true);
|
|
1650
|
+
this._commandService.syncExecuteCommand(_univerjs_drawing.SetDrawingSelectedOperation.id, [{
|
|
1651
|
+
unitId,
|
|
1652
|
+
subUnitId,
|
|
1653
|
+
drawingId
|
|
1654
|
+
}]);
|
|
1655
|
+
}));
|
|
1656
|
+
}
|
|
1657
|
+
_searchCropObject(scene) {
|
|
1658
|
+
const objects = scene.getAllObjectsByOrder();
|
|
1659
|
+
for (const object of objects) if (object instanceof ImageCropperObject) return object;
|
|
1660
|
+
}
|
|
1661
|
+
_initCloseCrop() {
|
|
1662
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
1663
|
+
if (command.id !== CloseImageCropOperation.id) return;
|
|
1664
|
+
const currentUnit = this._univerInstanceService.getFocusedUnit();
|
|
1665
|
+
if (currentUnit == null) return;
|
|
1666
|
+
const unitId = currentUnit.getUnitId();
|
|
1667
|
+
const renderObject = this._renderManagerService.getRenderById(unitId);
|
|
1668
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
1669
|
+
if (scene == null) return true;
|
|
1670
|
+
const imageCropperObject = this._searchCropObject(scene);
|
|
1671
|
+
if (imageCropperObject == null) return;
|
|
1672
|
+
const imageShape = this._getApplyObjectByCropObject(imageCropperObject);
|
|
1673
|
+
if (imageShape == null) return;
|
|
1674
|
+
const transformer = scene.getTransformerByCreate();
|
|
1675
|
+
transformer.detachFrom(imageCropperObject);
|
|
1676
|
+
transformer.clearCopperControl();
|
|
1677
|
+
const srcRect = this._getSrcRectByTransformState(imageShape, imageCropperObject);
|
|
1678
|
+
const drawingParam = this._drawingManagerService.getDrawingOKey(imageShape.oKey);
|
|
1679
|
+
if (drawingParam != null) {
|
|
1680
|
+
const { left, top, height, width } = imageCropperObject;
|
|
1681
|
+
this._drawingManagerService.featurePluginUpdateNotification([{
|
|
1682
|
+
...drawingParam,
|
|
1683
|
+
transform: {
|
|
1684
|
+
...drawingParam.transform,
|
|
1685
|
+
left,
|
|
1686
|
+
top,
|
|
1687
|
+
height,
|
|
1688
|
+
width
|
|
1689
|
+
},
|
|
1690
|
+
srcRect: srcRect.srcRectAngle
|
|
1691
|
+
}]);
|
|
1692
|
+
}
|
|
1693
|
+
imageShape.setSrcRect({ ...srcRect.srcRectAngle });
|
|
1694
|
+
imageShape.closeRenderByCropper();
|
|
1695
|
+
imageShape.makeDirty(true);
|
|
1696
|
+
imageCropperObject === null || imageCropperObject === void 0 || imageCropperObject.dispose();
|
|
1697
|
+
}));
|
|
1698
|
+
const sheetUnit$ = this._univerInstanceService.getCurrentTypeOfUnit$(_univerjs_core.UniverInstanceType.UNIVER_SHEET).pipe((0, rxjs.switchMap)((workbook) => workbook ? workbook.activeSheet$ : (0, rxjs.of)(null)));
|
|
1699
|
+
this.disposeWithMe(sheetUnit$.subscribe(() => {
|
|
1700
|
+
this._commandService.syncExecuteCommand(CloseImageCropOperation.id);
|
|
1701
|
+
}));
|
|
1702
|
+
}
|
|
1703
|
+
_getApplyObjectByCropObject(cropObject) {
|
|
1704
|
+
const cropOKey = cropObject.oKey;
|
|
1705
|
+
const applyOKey = cropOKey.slice(0, cropOKey.length - 5);
|
|
1706
|
+
const scene = cropObject.getScene();
|
|
1707
|
+
if (!scene) return null;
|
|
1708
|
+
const applyObject = scene.getObject(applyOKey);
|
|
1709
|
+
if (applyObject == null) return null;
|
|
1710
|
+
return applyObject;
|
|
1711
|
+
}
|
|
1712
|
+
_addListenerOnImage(scene) {
|
|
1713
|
+
const transformer = scene.getTransformerByCreate();
|
|
1714
|
+
let startTransform = null;
|
|
1715
|
+
this.disposeWithMe(transformer.changeStart$.subscribe((state) => {
|
|
1716
|
+
const { objects } = state;
|
|
1717
|
+
const cropObject = objects.values().next().value;
|
|
1718
|
+
if (cropObject == null || !(cropObject instanceof ImageCropperObject)) return;
|
|
1719
|
+
const { left, top, height, width, angle } = cropObject;
|
|
1720
|
+
startTransform = {
|
|
1721
|
+
left,
|
|
1722
|
+
top,
|
|
1723
|
+
height,
|
|
1724
|
+
width,
|
|
1725
|
+
angle
|
|
1726
|
+
};
|
|
1727
|
+
transformer.clearCopperControl();
|
|
1728
|
+
}));
|
|
1729
|
+
this.disposeWithMe(transformer.changeEnd$.subscribe((state) => {
|
|
1730
|
+
const { objects } = state;
|
|
1731
|
+
const cropObject = objects.values().next().value;
|
|
1732
|
+
if (cropObject == null || !(cropObject instanceof ImageCropperObject)) return;
|
|
1733
|
+
const { left, top, height, width, angle } = cropObject;
|
|
1734
|
+
if (!(0, _univerjs_core.checkIfMove)({
|
|
1735
|
+
left,
|
|
1736
|
+
top,
|
|
1737
|
+
height,
|
|
1738
|
+
width,
|
|
1739
|
+
angle
|
|
1740
|
+
}, startTransform)) return;
|
|
1741
|
+
const applyObject = this._getApplyObjectByCropObject(cropObject);
|
|
1742
|
+
if (applyObject == null) return;
|
|
1743
|
+
const srcRect = this._getSrcRectByTransformState(applyObject, cropObject);
|
|
1744
|
+
cropObject.refreshSrcRect(srcRect.srcRect, applyObject.getState());
|
|
1745
|
+
transformer.createControlForCopper(cropObject);
|
|
1746
|
+
}));
|
|
1747
|
+
this._endCropListener(scene);
|
|
1748
|
+
}
|
|
1749
|
+
_addHoverForImageCopper(o) {
|
|
1750
|
+
this.disposeWithMe(o.onPointerEnter$.subscribeEvent(() => {
|
|
1751
|
+
o.cursor = _univerjs_engine_render.CURSOR_TYPE.MOVE;
|
|
1752
|
+
}));
|
|
1753
|
+
this.disposeWithMe(o.onPointerLeave$.subscribeEvent(() => {
|
|
1754
|
+
o.cursor = _univerjs_engine_render.CURSOR_TYPE.DEFAULT;
|
|
1755
|
+
}));
|
|
1756
|
+
}
|
|
1757
|
+
_endCropListener(scene) {
|
|
1758
|
+
const transformer = scene.getTransformerByCreate();
|
|
1759
|
+
this.disposeWithMe(transformer.clearControl$.subscribe((changeSelf) => {
|
|
1760
|
+
if (changeSelf === true) this._commandService.syncExecuteCommand(CloseImageCropOperation.id);
|
|
1761
|
+
}));
|
|
1762
|
+
}
|
|
1763
|
+
_getSrcRectByTransformState(applyObject, imageCropperObject) {
|
|
1764
|
+
const { left, top, height, width, strokeWidth, angle: copperAngle } = imageCropperObject;
|
|
1765
|
+
const { left: applyLeft, top: applyTop, width: applyWidth, height: applyHeight, angle: applyAngle, strokeWidth: applyStrokeWidth } = applyObject;
|
|
1766
|
+
const newLeft = left - applyLeft;
|
|
1767
|
+
const newTop = top - applyTop;
|
|
1768
|
+
const srcRect = {
|
|
1769
|
+
left: newLeft,
|
|
1770
|
+
top: newTop,
|
|
1771
|
+
right: applyWidth - newLeft - width,
|
|
1772
|
+
bottom: applyHeight - newTop - height
|
|
1773
|
+
};
|
|
1774
|
+
const srcRectAngle = { ...srcRect };
|
|
1775
|
+
if (applyAngle !== 0) {
|
|
1776
|
+
const centerPoint = new _univerjs_engine_render.Vector2(left + width / 2, top + height / 2);
|
|
1777
|
+
const newCenterPoint = new _univerjs_engine_render.Vector2(applyWidth / 2 + applyLeft, applyHeight / 2 + applyTop);
|
|
1778
|
+
const vertexPoint = new _univerjs_engine_render.Vector2(applyLeft, applyTop);
|
|
1779
|
+
vertexPoint.rotateByPoint((0, _univerjs_engine_render.degToRad)(applyAngle), newCenterPoint);
|
|
1780
|
+
const applyFinalPoint = vertexPoint.clone();
|
|
1781
|
+
applyFinalPoint.rotateByPoint((0, _univerjs_engine_render.degToRad)(-applyAngle), centerPoint);
|
|
1782
|
+
const newAngleLeft = left - applyFinalPoint.x;
|
|
1783
|
+
const newAngleTop = top - applyFinalPoint.y;
|
|
1784
|
+
srcRectAngle.left = newAngleLeft;
|
|
1785
|
+
srcRectAngle.top = newAngleTop;
|
|
1786
|
+
srcRectAngle.right = applyWidth - newAngleLeft - width;
|
|
1787
|
+
srcRectAngle.bottom = applyHeight - newAngleTop - height;
|
|
1788
|
+
}
|
|
1789
|
+
return {
|
|
1790
|
+
srcRect,
|
|
1791
|
+
srcRectAngle
|
|
1792
|
+
};
|
|
1793
|
+
}
|
|
1794
|
+
};
|
|
1795
|
+
ImageCropperController = __decorate([
|
|
1796
|
+
__decorateParam(0, _univerjs_core.ICommandService),
|
|
1797
|
+
__decorateParam(1, _univerjs_drawing.IDrawingManagerService),
|
|
1798
|
+
__decorateParam(2, _univerjs_engine_render.IRenderManagerService),
|
|
1799
|
+
__decorateParam(3, _univerjs_core.IUniverInstanceService),
|
|
1800
|
+
__decorateParam(4, _univerjs_ui.IMessageService),
|
|
1801
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(_univerjs_core.LocaleService))
|
|
1802
|
+
], ImageCropperController);
|
|
1803
|
+
|
|
1804
|
+
//#endregion
|
|
1805
|
+
//#region src/services/drawing-image-clip.service.ts
|
|
1806
|
+
const IMAGE_CLIP_SHAPE_PICKER_COMPONENT = "sheet.image-clip.shape.picker.component";
|
|
1807
|
+
/**
|
|
1808
|
+
* Bridge service that enables shape-based image clipping.
|
|
1809
|
+
* This service lives in the open-source drawing-ui package and delegates
|
|
1810
|
+
* to a registered clip implementation (provided by pro engine-shape package).
|
|
1811
|
+
*
|
|
1812
|
+
* When no delegate is registered, applyShapeClip returns false and images render normally without shape clipping.
|
|
1813
|
+
*/
|
|
1814
|
+
var DrawingImageClipService = class extends _univerjs_core.Disposable {
|
|
1815
|
+
constructor() {
|
|
1816
|
+
super();
|
|
1817
|
+
_defineProperty(this, "_clipDelegate", null);
|
|
1818
|
+
_defineProperty(this, "_canUseShapeClip$", new rxjs.BehaviorSubject(false));
|
|
1819
|
+
_defineProperty(this, "canUseShapeClip$", this._canUseShapeClip$.asObservable());
|
|
1820
|
+
}
|
|
1821
|
+
setCanUseShapeClip(canUse) {
|
|
1822
|
+
this._canUseShapeClip$.next(canUse);
|
|
1823
|
+
}
|
|
1824
|
+
/**
|
|
1825
|
+
* Register a clip delegate that knows how to build shape clip paths.
|
|
1826
|
+
* Typically called by the pro-side plugin with a ShapeModel-based implementation.
|
|
1827
|
+
* @returns IDisposable to unregister the delegate
|
|
1828
|
+
*/
|
|
1829
|
+
registerClipDelegate(delegate) {
|
|
1830
|
+
this._clipDelegate = delegate;
|
|
1831
|
+
return (0, _univerjs_core.toDisposable)(() => {
|
|
1832
|
+
if (this._clipDelegate === delegate) this._clipDelegate = null;
|
|
1833
|
+
});
|
|
1834
|
+
}
|
|
1835
|
+
applyShapeClip(ctx, prstGeom, width, height, adjustValues) {
|
|
1836
|
+
if (this._clipDelegate) return this._clipDelegate(ctx, prstGeom, width, height, adjustValues);
|
|
1837
|
+
return false;
|
|
1838
|
+
}
|
|
1839
|
+
dispose() {
|
|
1840
|
+
this._clipDelegate = null;
|
|
1841
|
+
this._canUseShapeClip$.complete();
|
|
1842
|
+
super.dispose();
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
|
|
1846
|
+
//#endregion
|
|
1847
|
+
//#region src/services/drawing-render.service.ts
|
|
1848
|
+
let DrawingRenderService = class DrawingRenderService {
|
|
1849
|
+
constructor(_drawingManagerService, _imageIoService, _galleryService, _urlImageService, _univerInstanceService, _drawingImageClipService) {
|
|
1850
|
+
this._drawingManagerService = _drawingManagerService;
|
|
1851
|
+
this._imageIoService = _imageIoService;
|
|
1852
|
+
this._galleryService = _galleryService;
|
|
1853
|
+
this._urlImageService = _urlImageService;
|
|
1854
|
+
this._univerInstanceService = _univerInstanceService;
|
|
1855
|
+
this._drawingImageClipService = _drawingImageClipService;
|
|
1856
|
+
}
|
|
1857
|
+
async renderImages(imageParam, scene) {
|
|
1858
|
+
const { transform: singleTransform, drawingType, source, imageSourceType, srcRect, prstGeom, groupId, unitId, subUnitId, drawingId, isMultiTransform, transforms: multiTransforms, adjustValues } = imageParam;
|
|
1859
|
+
if (drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
|
|
1860
|
+
if (!this._drawingManagerService.getDrawingVisible()) return;
|
|
1861
|
+
if (this._univerInstanceService.getUnitType(unitId) === _univerjs_core.UniverInstanceType.UNIVER_SHEET && subUnitId !== this._getActiveSheetId()) return;
|
|
1862
|
+
if (singleTransform == null) return;
|
|
1863
|
+
const transforms = isMultiTransform && multiTransforms ? multiTransforms : [singleTransform];
|
|
1864
|
+
const images = [];
|
|
1865
|
+
for (const transform of transforms) {
|
|
1866
|
+
const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
|
|
1867
|
+
const index = transforms.indexOf(transform);
|
|
1868
|
+
const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
1869
|
+
unitId,
|
|
1870
|
+
subUnitId,
|
|
1871
|
+
drawingId
|
|
1872
|
+
}, isMultiTransform ? index : void 0);
|
|
1873
|
+
const imageShape = scene.getObject(imageShapeKey);
|
|
1874
|
+
if (imageShape != null) {
|
|
1875
|
+
imageShape.transformByState({
|
|
1876
|
+
left,
|
|
1877
|
+
top,
|
|
1878
|
+
width,
|
|
1879
|
+
height,
|
|
1880
|
+
angle,
|
|
1881
|
+
flipX,
|
|
1882
|
+
flipY,
|
|
1883
|
+
skewX,
|
|
1884
|
+
skewY
|
|
1885
|
+
});
|
|
1886
|
+
continue;
|
|
1887
|
+
}
|
|
1888
|
+
const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
|
|
1889
|
+
const zIndex = orders.indexOf(drawingId);
|
|
1890
|
+
const imageConfig = {
|
|
1891
|
+
...transform,
|
|
1892
|
+
zIndex: zIndex === -1 ? orders.length - 1 : zIndex
|
|
1893
|
+
};
|
|
1894
|
+
const imageNativeCache = this._imageIoService.getImageSourceCache(source, imageSourceType);
|
|
1895
|
+
let shouldBeCache = false;
|
|
1896
|
+
if (imageNativeCache != null) imageConfig.image = imageNativeCache;
|
|
1897
|
+
else if (imageSourceType === _univerjs_drawing.ImageSourceType.UUID) try {
|
|
1898
|
+
imageConfig.url = await this._imageIoService.getImage(source);
|
|
1899
|
+
} catch (error) {
|
|
1900
|
+
console.error(error);
|
|
1901
|
+
continue;
|
|
1902
|
+
}
|
|
1903
|
+
else if (imageSourceType === _univerjs_drawing.ImageSourceType.URL) {
|
|
1904
|
+
try {
|
|
1905
|
+
imageConfig.url = await this._urlImageService.getImage(source);
|
|
1906
|
+
} catch (error) {
|
|
1907
|
+
console.error(error);
|
|
1908
|
+
imageConfig.url = source;
|
|
1909
|
+
}
|
|
1910
|
+
shouldBeCache = true;
|
|
1911
|
+
} else {
|
|
1912
|
+
imageConfig.url = source;
|
|
1913
|
+
shouldBeCache = true;
|
|
1914
|
+
}
|
|
1915
|
+
if (scene.getObject(imageShapeKey)) continue;
|
|
1916
|
+
imageConfig.printable = true;
|
|
1917
|
+
const image = new _univerjs_engine_render.Image(imageShapeKey, imageConfig);
|
|
1918
|
+
image.setClipService(this._drawingImageClipService);
|
|
1919
|
+
if (shouldBeCache) this._imageIoService.addImageSourceCache(source, imageSourceType, image.getNative());
|
|
1920
|
+
scene.addObject(image, _univerjs_engine_render.DRAWING_OBJECT_LAYER_INDEX);
|
|
1921
|
+
if (this._drawingManagerService.getDrawingEditable()) scene.attachTransformerTo(image);
|
|
1922
|
+
groupId && insertGroupObject({
|
|
1923
|
+
drawingId: groupId,
|
|
1924
|
+
unitId,
|
|
1925
|
+
subUnitId
|
|
1926
|
+
}, image, scene, this._drawingManagerService);
|
|
1927
|
+
if (prstGeom != null) image.setPrstGeom(prstGeom);
|
|
1928
|
+
if (adjustValues != null) image.setPrstGeomAdjValues(adjustValues);
|
|
1929
|
+
if (srcRect != null) image.setSrcRect(srcRect);
|
|
1930
|
+
images.push(image);
|
|
1931
|
+
}
|
|
1932
|
+
return images;
|
|
1933
|
+
}
|
|
1934
|
+
_getActiveSheetId() {
|
|
1935
|
+
var _this$_univerInstance;
|
|
1936
|
+
return (_this$_univerInstance = this._univerInstanceService.getCurrentUnitOfType(_univerjs_core.UniverInstanceType.UNIVER_SHEET)) === null || _this$_univerInstance === void 0 || (_this$_univerInstance = _this$_univerInstance.getActiveSheet()) === null || _this$_univerInstance === void 0 ? void 0 : _this$_univerInstance.getSheetId();
|
|
1937
|
+
}
|
|
1938
|
+
renderFloatDom(param, scene) {
|
|
1939
|
+
const { transform: singleTransform, drawingType, groupId, unitId, subUnitId, drawingId, isMultiTransform, transforms: multiTransforms } = param;
|
|
1940
|
+
if (drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_DOM) return;
|
|
1941
|
+
if (!this._drawingManagerService.getDrawingVisible()) return;
|
|
1942
|
+
if (singleTransform == null) return;
|
|
1943
|
+
const transforms = isMultiTransform && multiTransforms ? multiTransforms : [singleTransform];
|
|
1944
|
+
const rects = [];
|
|
1945
|
+
for (const transform of transforms) {
|
|
1946
|
+
const { left, top, width, height, angle, flipX, flipY, skewX, skewY } = transform;
|
|
1947
|
+
const index = transforms.indexOf(transform);
|
|
1948
|
+
const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
1949
|
+
unitId,
|
|
1950
|
+
subUnitId,
|
|
1951
|
+
drawingId
|
|
1952
|
+
}, isMultiTransform ? index : void 0);
|
|
1953
|
+
const imageShape = scene.getObject(imageShapeKey);
|
|
1954
|
+
if (imageShape != null) {
|
|
1955
|
+
imageShape.transformByState({
|
|
1956
|
+
left,
|
|
1957
|
+
top,
|
|
1958
|
+
width,
|
|
1959
|
+
height,
|
|
1960
|
+
angle,
|
|
1961
|
+
flipX,
|
|
1962
|
+
flipY,
|
|
1963
|
+
skewX,
|
|
1964
|
+
skewY
|
|
1965
|
+
});
|
|
1966
|
+
continue;
|
|
1967
|
+
}
|
|
1968
|
+
const orders = this._drawingManagerService.getDrawingOrder(unitId, subUnitId);
|
|
1969
|
+
const zIndex = orders.indexOf(drawingId);
|
|
1970
|
+
const rectConfig = {
|
|
1971
|
+
...transform,
|
|
1972
|
+
zIndex: zIndex === -1 ? orders.length - 1 : zIndex
|
|
1973
|
+
};
|
|
1974
|
+
if (scene.getObject(imageShapeKey)) continue;
|
|
1975
|
+
rectConfig.printable = false;
|
|
1976
|
+
const rect = new _univerjs_engine_render.Rect(imageShapeKey, rectConfig);
|
|
1977
|
+
if (!this._drawingManagerService.getDrawingVisible()) continue;
|
|
1978
|
+
scene.addObject(rect, _univerjs_engine_render.DRAWING_OBJECT_LAYER_INDEX);
|
|
1979
|
+
if (this._drawingManagerService.getDrawingEditable() && param.allowTransform !== false) scene.attachTransformerTo(rect);
|
|
1980
|
+
groupId && insertGroupObject({
|
|
1981
|
+
drawingId: groupId,
|
|
1982
|
+
unitId,
|
|
1983
|
+
subUnitId
|
|
1984
|
+
}, rect, scene, this._drawingManagerService);
|
|
1985
|
+
rects.push(rect);
|
|
1986
|
+
}
|
|
1987
|
+
return rects;
|
|
1988
|
+
}
|
|
1989
|
+
renderDrawing(param, scene) {
|
|
1990
|
+
const drawingParam = this._drawingManagerService.getDrawingByParam(param);
|
|
1991
|
+
if (drawingParam == null) return;
|
|
1992
|
+
switch (drawingParam.drawingType) {
|
|
1993
|
+
case _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE: return this.renderImages(drawingParam, scene);
|
|
1994
|
+
default:
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
previewImage(key, src, width, height) {
|
|
1998
|
+
this._galleryService.open({
|
|
1999
|
+
images: [src],
|
|
2000
|
+
onOpenChange: (open) => {
|
|
2001
|
+
if (!open) this._galleryService.close();
|
|
2002
|
+
}
|
|
2003
|
+
});
|
|
2004
|
+
}
|
|
2005
|
+
_adjustImageSize(nativeWidth, nativeHeight, screenWidth, screenHeight) {
|
|
2006
|
+
if (nativeWidth <= screenWidth && nativeHeight <= screenHeight) return {
|
|
2007
|
+
width: nativeWidth,
|
|
2008
|
+
height: nativeHeight
|
|
2009
|
+
};
|
|
2010
|
+
const widthRatio = screenWidth / nativeWidth;
|
|
2011
|
+
const heightRatio = screenHeight / nativeHeight;
|
|
2012
|
+
const scale = Math.min(widthRatio, heightRatio);
|
|
2013
|
+
return {
|
|
2014
|
+
width: Math.floor(nativeWidth * scale),
|
|
2015
|
+
height: Math.floor(nativeHeight * scale)
|
|
2016
|
+
};
|
|
2017
|
+
}
|
|
2018
|
+
};
|
|
2019
|
+
DrawingRenderService = __decorate([
|
|
2020
|
+
__decorateParam(0, _univerjs_drawing.IDrawingManagerService),
|
|
2021
|
+
__decorateParam(1, _univerjs_drawing.IImageIoService),
|
|
2022
|
+
__decorateParam(2, _univerjs_ui.IGalleryService),
|
|
2023
|
+
__decorateParam(3, _univerjs_core.IURLImageService),
|
|
2024
|
+
__decorateParam(4, _univerjs_core.IUniverInstanceService),
|
|
2025
|
+
__decorateParam(5, (0, _univerjs_core.Inject)(DrawingImageClipService))
|
|
2026
|
+
], DrawingRenderService);
|
|
2027
|
+
|
|
2028
|
+
//#endregion
|
|
2029
|
+
//#region src/controllers/image-update.controller.ts
|
|
2030
|
+
let ImageUpdateController = class ImageUpdateController extends _univerjs_core.Disposable {
|
|
2031
|
+
constructor(_commandService, _renderManagerService, _drawingManagerService, _dialogService, _imageIoService, _currentUniverService, _drawingRenderService) {
|
|
2032
|
+
super();
|
|
2033
|
+
this._commandService = _commandService;
|
|
2034
|
+
this._renderManagerService = _renderManagerService;
|
|
2035
|
+
this._drawingManagerService = _drawingManagerService;
|
|
2036
|
+
this._dialogService = _dialogService;
|
|
2037
|
+
this._imageIoService = _imageIoService;
|
|
2038
|
+
this._currentUniverService = _currentUniverService;
|
|
2039
|
+
this._drawingRenderService = _drawingRenderService;
|
|
2040
|
+
this._initialize();
|
|
2041
|
+
}
|
|
2042
|
+
dispose() {
|
|
2043
|
+
super.dispose();
|
|
2044
|
+
}
|
|
2045
|
+
_initialize() {
|
|
2046
|
+
this._drawingAddListener();
|
|
2047
|
+
this._commandExecutedListener();
|
|
2048
|
+
this._imageUpdateListener();
|
|
2049
|
+
}
|
|
2050
|
+
_commandExecutedListener() {
|
|
2051
|
+
this.disposeWithMe(this._commandService.onCommandExecuted((command) => {
|
|
2052
|
+
if (command.id === ImageResetSizeOperation.id) {
|
|
2053
|
+
const params = command.params;
|
|
2054
|
+
if (params == null) return;
|
|
2055
|
+
this._resetImageSize(params);
|
|
2056
|
+
}
|
|
2057
|
+
}));
|
|
2058
|
+
}
|
|
2059
|
+
_getSceneAndTransformerByDrawingSearch(unitId) {
|
|
2060
|
+
if (unitId == null) return;
|
|
2061
|
+
const renderObject = this._renderManagerService.getRenderById(unitId);
|
|
2062
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
2063
|
+
if (scene == null) return null;
|
|
2064
|
+
return {
|
|
2065
|
+
scene,
|
|
2066
|
+
transformer: scene.getTransformerByCreate()
|
|
2067
|
+
};
|
|
2068
|
+
}
|
|
2069
|
+
_resetImageSize(params) {
|
|
2070
|
+
const updateParams = [];
|
|
2071
|
+
const sceneList = [];
|
|
2072
|
+
params.forEach((param) => {
|
|
2073
|
+
const { unitId, subUnitId, drawingId } = param;
|
|
2074
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
2075
|
+
if (renderObject == null) return;
|
|
2076
|
+
const { scene } = renderObject;
|
|
2077
|
+
const imageShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
2078
|
+
unitId,
|
|
2079
|
+
subUnitId,
|
|
2080
|
+
drawingId
|
|
2081
|
+
});
|
|
2082
|
+
const imageShape = scene.getObject(imageShapeKey);
|
|
2083
|
+
if (imageShape == null) return true;
|
|
2084
|
+
const imageData = this._drawingManagerService.getDrawingByParam(param);
|
|
2085
|
+
if (imageData == null) return true;
|
|
2086
|
+
if (imageData.drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
|
|
2087
|
+
imageShape.resetSize();
|
|
2088
|
+
const { width, height } = imageShape.getNativeSize();
|
|
2089
|
+
if (sceneList.includes(scene) === false) sceneList.push(scene);
|
|
2090
|
+
updateParams.push({
|
|
2091
|
+
...imageData,
|
|
2092
|
+
transform: {
|
|
2093
|
+
...imageData.transform,
|
|
2094
|
+
height,
|
|
2095
|
+
width,
|
|
2096
|
+
angle: 0
|
|
2097
|
+
},
|
|
2098
|
+
srcRect: null,
|
|
2099
|
+
prstGeom: null
|
|
2100
|
+
});
|
|
2101
|
+
});
|
|
2102
|
+
this._drawingManagerService.featurePluginUpdateNotification(updateParams);
|
|
2103
|
+
sceneList.forEach((scene) => {
|
|
2104
|
+
scene.getTransformerByCreate().refreshControls().changeNotification();
|
|
2105
|
+
});
|
|
2106
|
+
this._commandService.syncExecuteCommand(_univerjs_drawing.SetDrawingSelectedOperation.id, params);
|
|
2107
|
+
}
|
|
2108
|
+
_drawingAddListener() {
|
|
2109
|
+
this.disposeWithMe(this._drawingManagerService.add$.pipe((0, rxjs.bufferTime)(33), (0, rxjs.filter)((batches) => batches.length > 0), (0, rxjs.map)((batches) => batches.flat()), (0, rxjs.map)((items) => {
|
|
2110
|
+
const map = /* @__PURE__ */ new Map();
|
|
2111
|
+
for (const it of items) map.set(`${it.unitId}|${it.subUnitId}|${it.drawingId}`, it);
|
|
2112
|
+
return [...map.values()];
|
|
2113
|
+
}), (0, rxjs.filter)((items) => items.length > 0)).subscribe((uniqueParams) => {
|
|
2114
|
+
this._insertImages(uniqueParams);
|
|
2115
|
+
}));
|
|
2116
|
+
}
|
|
2117
|
+
_insertImages(params) {
|
|
2118
|
+
params.forEach(async (param) => {
|
|
2119
|
+
var _getCurrentUnitInfo;
|
|
2120
|
+
const { unitId, subUnitId } = param;
|
|
2121
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
2122
|
+
const currentSubUnitId = (_getCurrentUnitInfo = getCurrentUnitInfo(this._currentUniverService, unitId)) === null || _getCurrentUnitInfo === void 0 ? void 0 : _getCurrentUnitInfo.subUnitId;
|
|
2123
|
+
if (renderObject == null || currentSubUnitId !== subUnitId) return;
|
|
2124
|
+
const imageParam = this._drawingManagerService.getDrawingByParam(param);
|
|
2125
|
+
if (imageParam == null) return;
|
|
2126
|
+
const images = await this._drawingRenderService.renderImages(imageParam, renderObject.scene);
|
|
2127
|
+
this._drawingManagerService.refreshTransform([imageParam]);
|
|
2128
|
+
if (images == null || images.length === 0) return;
|
|
2129
|
+
for (const image of images) {
|
|
2130
|
+
this._addHoverForImage(image);
|
|
2131
|
+
this._addDialogForImage(image);
|
|
2132
|
+
}
|
|
2133
|
+
});
|
|
2134
|
+
}
|
|
2135
|
+
_imageUpdateListener() {
|
|
2136
|
+
this.disposeWithMe(this._drawingManagerService.update$.subscribe((params) => {
|
|
2137
|
+
params.forEach((param) => {
|
|
2138
|
+
const { unitId, subUnitId, drawingId } = param;
|
|
2139
|
+
const drawingParam = this._drawingManagerService.getDrawingByParam(param);
|
|
2140
|
+
if (drawingParam == null) return;
|
|
2141
|
+
const { transform, drawingType, srcRect, prstGeom, source, imageSourceType } = drawingParam;
|
|
2142
|
+
if (drawingType !== _univerjs_core.DrawingTypeEnum.DRAWING_IMAGE) return;
|
|
2143
|
+
const renderObject = this._getSceneAndTransformerByDrawingSearch(unitId);
|
|
2144
|
+
if (renderObject == null) return;
|
|
2145
|
+
const { scene, transformer } = renderObject;
|
|
2146
|
+
if (transform == null) return true;
|
|
2147
|
+
const drawingShapeKey = (0, _univerjs_drawing.getDrawingShapeKeyByDrawingSearch)({
|
|
2148
|
+
unitId,
|
|
2149
|
+
subUnitId,
|
|
2150
|
+
drawingId
|
|
2151
|
+
});
|
|
2152
|
+
const imageShape = scene.getObject(drawingShapeKey);
|
|
2153
|
+
if (imageShape == null) return true;
|
|
2154
|
+
imageShape.setSrcRect(srcRect);
|
|
2155
|
+
imageShape.setPrstGeom(prstGeom);
|
|
2156
|
+
if (source != null && source.length > 0 && (imageSourceType === _univerjs_core.ImageSourceType.BASE64 || imageSourceType === _univerjs_core.ImageSourceType.URL)) imageShape.changeSource(source);
|
|
2157
|
+
});
|
|
2158
|
+
}));
|
|
2159
|
+
}
|
|
2160
|
+
_addHoverForImage(o) {
|
|
2161
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(o.onPointerEnter$.subscribeEvent(() => {
|
|
2162
|
+
o.cursor = _univerjs_engine_render.CURSOR_TYPE.GRAB;
|
|
2163
|
+
})));
|
|
2164
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(o.onPointerLeave$.subscribeEvent(() => {
|
|
2165
|
+
o.cursor = _univerjs_engine_render.CURSOR_TYPE.DEFAULT;
|
|
2166
|
+
})));
|
|
2167
|
+
}
|
|
2168
|
+
_addDialogForImage(o) {
|
|
2169
|
+
this.disposeWithMe((0, _univerjs_core.toDisposable)(o.onDblclick$.subscribeEvent(() => {
|
|
2170
|
+
const dialogId = `${o.oKey}-viewer-dialog`;
|
|
2171
|
+
this._drawingRenderService.previewImage(dialogId, o.getNative().src, o.getNativeSize().width, o.getNativeSize().height);
|
|
2172
|
+
})));
|
|
2173
|
+
}
|
|
2174
|
+
};
|
|
2175
|
+
ImageUpdateController = __decorate([
|
|
2176
|
+
__decorateParam(0, _univerjs_core.ICommandService),
|
|
2177
|
+
__decorateParam(1, _univerjs_engine_render.IRenderManagerService),
|
|
2178
|
+
__decorateParam(2, _univerjs_drawing.IDrawingManagerService),
|
|
2179
|
+
__decorateParam(3, _univerjs_ui.IDialogService),
|
|
2180
|
+
__decorateParam(4, _univerjs_drawing.IImageIoService),
|
|
2181
|
+
__decorateParam(5, _univerjs_core.IUniverInstanceService),
|
|
2182
|
+
__decorateParam(6, (0, _univerjs_core.Inject)(DrawingRenderService))
|
|
2183
|
+
], ImageUpdateController);
|
|
2184
|
+
|
|
2185
|
+
//#endregion
|
|
2186
|
+
//#region src/plugin.ts
|
|
2187
|
+
let UniverDrawingUIPlugin = class UniverDrawingUIPlugin extends _univerjs_core.Plugin {
|
|
2188
|
+
constructor(_config = defaultPluginConfig, _injector, _configService) {
|
|
2189
|
+
super();
|
|
2190
|
+
this._config = _config;
|
|
2191
|
+
this._injector = _injector;
|
|
2192
|
+
this._configService = _configService;
|
|
2193
|
+
const { menu, ...rest } = (0, _univerjs_core.merge)({}, defaultPluginConfig, this._config);
|
|
2194
|
+
if (menu) this._configService.setConfig("menu", menu, { merge: true });
|
|
2195
|
+
this._configService.setConfig(DRAWING_UI_PLUGIN_CONFIG_KEY, rest);
|
|
2196
|
+
}
|
|
2197
|
+
onStarting() {
|
|
2198
|
+
this._initDependencies();
|
|
2199
|
+
}
|
|
2200
|
+
onRendered() {
|
|
2201
|
+
this._injector.get(DrawingUpdateController);
|
|
2202
|
+
this._injector.get(DrawingUIController);
|
|
2203
|
+
this._injector.get(ImageCropperController);
|
|
2204
|
+
this._injector.get(ImageUpdateController);
|
|
2205
|
+
}
|
|
2206
|
+
_initDependencies() {
|
|
2207
|
+
[
|
|
2208
|
+
[DrawingImageClipService],
|
|
2209
|
+
[DrawingRenderService],
|
|
2210
|
+
[DrawingUpdateController],
|
|
2211
|
+
[DrawingUIController],
|
|
2212
|
+
[ImageCropperController],
|
|
2213
|
+
[ImageUpdateController]
|
|
2214
|
+
].forEach((dependency) => this._injector.add(dependency));
|
|
2215
|
+
}
|
|
2216
|
+
};
|
|
2217
|
+
_defineProperty(UniverDrawingUIPlugin, "pluginName", "UNIVER_DRAWING_UI_PLUGIN");
|
|
2218
|
+
_defineProperty(UniverDrawingUIPlugin, "packageName", name);
|
|
2219
|
+
_defineProperty(UniverDrawingUIPlugin, "version", version);
|
|
2220
|
+
UniverDrawingUIPlugin = __decorate([__decorateParam(1, (0, _univerjs_core.Inject)(_univerjs_core.Injector)), __decorateParam(2, _univerjs_core.IConfigService)], UniverDrawingUIPlugin);
|
|
2221
|
+
|
|
2222
|
+
//#endregion
|
|
2223
|
+
//#region src/views/panel/DrawingAlign.tsx
|
|
2224
|
+
const DrawingAlign = (props) => {
|
|
2225
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
2226
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
2227
|
+
const { drawings, alignShow } = props;
|
|
2228
|
+
const [alignValue, setAlignValue] = (0, react.useState)(AlignType.default);
|
|
2229
|
+
const alignOptions = [
|
|
2230
|
+
{
|
|
2231
|
+
label: localeService.t("image-panel.align.default"),
|
|
2232
|
+
value: AlignType.default
|
|
2233
|
+
},
|
|
2234
|
+
{ options: [
|
|
2235
|
+
{
|
|
2236
|
+
label: localeService.t("image-panel.align.left"),
|
|
2237
|
+
value: AlignType.left
|
|
2238
|
+
},
|
|
2239
|
+
{
|
|
2240
|
+
label: localeService.t("image-panel.align.center"),
|
|
2241
|
+
value: AlignType.center
|
|
2242
|
+
},
|
|
2243
|
+
{
|
|
2244
|
+
label: localeService.t("image-panel.align.right"),
|
|
2245
|
+
value: AlignType.right
|
|
2246
|
+
}
|
|
2247
|
+
] },
|
|
2248
|
+
{ options: [
|
|
2249
|
+
{
|
|
2250
|
+
label: localeService.t("image-panel.align.top"),
|
|
2251
|
+
value: AlignType.top
|
|
2252
|
+
},
|
|
2253
|
+
{
|
|
2254
|
+
label: localeService.t("image-panel.align.middle"),
|
|
2255
|
+
value: AlignType.middle
|
|
2256
|
+
},
|
|
2257
|
+
{
|
|
2258
|
+
label: localeService.t("image-panel.align.bottom"),
|
|
2259
|
+
value: AlignType.bottom
|
|
2260
|
+
}
|
|
2261
|
+
] },
|
|
2262
|
+
{ options: [{
|
|
2263
|
+
label: localeService.t("image-panel.align.horizon"),
|
|
2264
|
+
value: AlignType.horizon
|
|
2265
|
+
}, {
|
|
2266
|
+
label: localeService.t("image-panel.align.vertical"),
|
|
2267
|
+
value: AlignType.vertical
|
|
2268
|
+
}] }
|
|
2269
|
+
];
|
|
2270
|
+
function handleAlignChange(value) {
|
|
2271
|
+
setAlignValue(value);
|
|
2272
|
+
commandService.executeCommand(SetDrawingAlignOperation.id, {
|
|
2273
|
+
alignType: value,
|
|
2274
|
+
drawings
|
|
2275
|
+
});
|
|
2276
|
+
}
|
|
2277
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2278
|
+
className: (0, _univerjs_design.clsx)("univer-relative univer-w-full", { "univer-hidden": !alignShow }),
|
|
2279
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
|
|
2280
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2281
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("image-panel.align.title") })
|
|
2282
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2283
|
+
className: "univer-relative univer-mt-2.5 univer-flex univer-h-full",
|
|
2284
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2285
|
+
className: "univer-w-full univer-text-gray-900 dark:!univer-text-white",
|
|
2286
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
|
|
2287
|
+
value: alignValue,
|
|
2288
|
+
options: alignOptions,
|
|
2289
|
+
onChange: handleAlignChange
|
|
2290
|
+
})
|
|
2291
|
+
})
|
|
2292
|
+
})]
|
|
2293
|
+
});
|
|
2294
|
+
};
|
|
2295
|
+
|
|
2296
|
+
//#endregion
|
|
2297
|
+
//#region src/views/panel/DrawingArrange.tsx
|
|
2298
|
+
const DrawingArrange = (props) => {
|
|
2299
|
+
const { arrangeShow, drawings: focusDrawings } = props;
|
|
2300
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
2301
|
+
const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
|
|
2302
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
2303
|
+
const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
|
|
2304
|
+
const MoveUpIcon = componentManager.get("MoveUpIcon");
|
|
2305
|
+
const MoveDownIcon = componentManager.get("MoveDownIcon");
|
|
2306
|
+
const TopmostIcon = componentManager.get("TopmostIcon");
|
|
2307
|
+
const BottomIcon = componentManager.get("BottomIcon");
|
|
2308
|
+
const [drawings, setDrawings] = (0, react.useState)(focusDrawings);
|
|
2309
|
+
(0, react.useEffect)(() => {
|
|
2310
|
+
const focusDispose = drawingManagerService.focus$.subscribe((drawings) => {
|
|
2311
|
+
setDrawings(drawings);
|
|
2312
|
+
});
|
|
2313
|
+
return () => {
|
|
2314
|
+
focusDispose.unsubscribe();
|
|
2315
|
+
};
|
|
2316
|
+
}, []);
|
|
2317
|
+
const onArrangeBtnClick = (arrangeType) => {
|
|
2318
|
+
commandService.syncExecuteCommand(SetDrawingArrangeOperation.id, {
|
|
2319
|
+
arrangeType,
|
|
2320
|
+
drawings
|
|
2321
|
+
});
|
|
2322
|
+
};
|
|
2323
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2324
|
+
className: (0, _univerjs_design.clsx)("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !arrangeShow }),
|
|
2325
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
|
|
2326
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2327
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("image-panel.arrange.title") })
|
|
2328
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2329
|
+
className: "univer-grid univer-grid-cols-2 univer-gap-2",
|
|
2330
|
+
children: [
|
|
2331
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
|
|
2332
|
+
onClick: () => {
|
|
2333
|
+
onArrangeBtnClick(_univerjs_core.ArrangeTypeEnum.forward);
|
|
2334
|
+
},
|
|
2335
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MoveUpIcon, {}), localeService.t("image-panel.arrange.forward")]
|
|
2336
|
+
}),
|
|
2337
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
|
|
2338
|
+
onClick: () => {
|
|
2339
|
+
onArrangeBtnClick(_univerjs_core.ArrangeTypeEnum.backward);
|
|
2340
|
+
},
|
|
2341
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(MoveDownIcon, {}), localeService.t("image-panel.arrange.backward")]
|
|
2342
|
+
}),
|
|
2343
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
|
|
2344
|
+
onClick: () => {
|
|
2345
|
+
onArrangeBtnClick(_univerjs_core.ArrangeTypeEnum.front);
|
|
2346
|
+
},
|
|
2347
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(TopmostIcon, {}), localeService.t("image-panel.arrange.front")]
|
|
2348
|
+
}),
|
|
2349
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
|
|
2350
|
+
onClick: () => {
|
|
2351
|
+
onArrangeBtnClick(_univerjs_core.ArrangeTypeEnum.back);
|
|
2352
|
+
},
|
|
2353
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(BottomIcon, {}), localeService.t("image-panel.arrange.back")]
|
|
2354
|
+
})
|
|
2355
|
+
]
|
|
2356
|
+
})]
|
|
2357
|
+
});
|
|
2358
|
+
};
|
|
2359
|
+
|
|
2360
|
+
//#endregion
|
|
2361
|
+
//#region src/views/panel/DrawingGroup.tsx
|
|
2362
|
+
const DrawingGroup = (props) => {
|
|
2363
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
2364
|
+
const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
|
|
2365
|
+
const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
|
|
2366
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
2367
|
+
const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
|
|
2368
|
+
const { hasGroup, drawings } = props;
|
|
2369
|
+
const GroupIcon = componentManager.get("GroupIcon");
|
|
2370
|
+
const UngroupIcon = componentManager.get("UngroupIcon");
|
|
2371
|
+
const [groupShow, setGroupShow] = (0, react.useState)(false);
|
|
2372
|
+
const [groupBtnShow, setGroupBtnShow] = (0, react.useState)(true);
|
|
2373
|
+
const [ungroupBtnShow, setUngroupBtnShow] = (0, react.useState)(true);
|
|
2374
|
+
const onGroupBtnClick = () => {
|
|
2375
|
+
commandService.syncExecuteCommand(SetDrawingGroupOperation.id, { drawings });
|
|
2376
|
+
};
|
|
2377
|
+
const onUngroupBtnClick = () => {
|
|
2378
|
+
commandService.syncExecuteCommand(CancelDrawingGroupOperation.id, { drawings });
|
|
2379
|
+
};
|
|
2380
|
+
(0, react.useEffect)(() => {
|
|
2381
|
+
const drawingParam = drawings[0];
|
|
2382
|
+
if (drawingParam == null) return;
|
|
2383
|
+
const { unitId } = drawingParam;
|
|
2384
|
+
const renderObject = renderManagerService.getRenderById(unitId);
|
|
2385
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
2386
|
+
if (scene == null) return;
|
|
2387
|
+
const transformer = scene.getTransformerByCreate();
|
|
2388
|
+
const onClearControlObserver = transformer.clearControl$.subscribe((changeSelf) => {
|
|
2389
|
+
if (changeSelf === true) setGroupShow(false);
|
|
2390
|
+
});
|
|
2391
|
+
const onChangeStartObserver = transformer.changeStart$.subscribe((state) => {
|
|
2392
|
+
const { objects } = state;
|
|
2393
|
+
const params = getUpdateParams(objects, drawingManagerService);
|
|
2394
|
+
const groupParams = params.filter((o) => (o === null || o === void 0 ? void 0 : o.drawingType) === _univerjs_core.DrawingTypeEnum.DRAWING_GROUP);
|
|
2395
|
+
let groupBtnShow = false;
|
|
2396
|
+
let ungroupBtnShow = false;
|
|
2397
|
+
if (params.length > 1) groupBtnShow = true;
|
|
2398
|
+
if (groupParams.length > 0) ungroupBtnShow = true;
|
|
2399
|
+
setGroupShow(groupBtnShow || ungroupBtnShow);
|
|
2400
|
+
setGroupBtnShow(groupBtnShow);
|
|
2401
|
+
setUngroupBtnShow(ungroupBtnShow);
|
|
2402
|
+
});
|
|
2403
|
+
return () => {
|
|
2404
|
+
onChangeStartObserver.unsubscribe();
|
|
2405
|
+
onClearControlObserver.unsubscribe();
|
|
2406
|
+
};
|
|
2407
|
+
}, []);
|
|
2408
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2409
|
+
className: (0, _univerjs_design.clsx)("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": hasGroup === true && groupShow === false || hasGroup === false }),
|
|
2410
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
|
|
2411
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2412
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("image-panel.group.title") })
|
|
2413
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2414
|
+
className: "univer-flex univer-items-center univer-justify-center univer-gap-2",
|
|
2415
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
|
|
2416
|
+
className: (0, _univerjs_design.clsx)({ "univer-hidden": !groupBtnShow }),
|
|
2417
|
+
onClick: onGroupBtnClick,
|
|
2418
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(GroupIcon, {}), localeService.t("image-panel.group.group")]
|
|
2419
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
|
|
2420
|
+
className: (0, _univerjs_design.clsx)({ "univer-hidden": !ungroupBtnShow }),
|
|
2421
|
+
onClick: onUngroupBtnClick,
|
|
2422
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(UngroupIcon, {}), localeService.t("image-panel.group.unGroup")]
|
|
2423
|
+
})]
|
|
2424
|
+
})]
|
|
2425
|
+
});
|
|
2426
|
+
};
|
|
2427
|
+
|
|
2428
|
+
//#endregion
|
|
2429
|
+
//#region src/utils/config.ts
|
|
2430
|
+
const RANGE_DRAWING_ROTATION_LIMIT = [-360, 360];
|
|
2431
|
+
|
|
2432
|
+
//#endregion
|
|
2433
|
+
//#region src/views/panel/DrawingTransform.tsx
|
|
2434
|
+
const INPUT_DEBOUNCE_TIME = 300;
|
|
2435
|
+
const DrawingTransform = (props) => {
|
|
2436
|
+
var _scene$getEngine;
|
|
2437
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
2438
|
+
const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
|
|
2439
|
+
const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
|
|
2440
|
+
const { drawings, transformShow } = props;
|
|
2441
|
+
const drawingParam = drawings[0];
|
|
2442
|
+
if (drawingParam == null) return;
|
|
2443
|
+
const transform = drawingParam.transform;
|
|
2444
|
+
if (transform == null) return;
|
|
2445
|
+
const { unitId, subUnitId, drawingId, drawingType } = drawingParam;
|
|
2446
|
+
const renderObject = renderManagerService.getRenderById(unitId);
|
|
2447
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
2448
|
+
if (scene == null) return;
|
|
2449
|
+
const topScene = (_scene$getEngine = scene.getEngine()) === null || _scene$getEngine === void 0 ? void 0 : _scene$getEngine.activeScene;
|
|
2450
|
+
if (topScene == null) return;
|
|
2451
|
+
const transformer = scene.getTransformerByCreate();
|
|
2452
|
+
const { width: originWidth = 0, height: originHeight = 0, left: originX = 0, top: originY = 0, angle: originRotation = 0 } = transform;
|
|
2453
|
+
const [width, setWidth] = (0, react.useState)(originWidth);
|
|
2454
|
+
const [height, setHeight] = (0, react.useState)(originHeight);
|
|
2455
|
+
const [xPosition, setXPosition] = (0, react.useState)(originX);
|
|
2456
|
+
const [yPosition, setYPosition] = (0, react.useState)(originY);
|
|
2457
|
+
const [rotation, setRotation] = (0, react.useState)(originRotation);
|
|
2458
|
+
const [lockRatio, setLockRatio] = (0, react.useState)(transformer.keepRatio);
|
|
2459
|
+
const checkMoveBoundary = (left, top, width, height) => {
|
|
2460
|
+
const { width: topSceneWidth, height: topSceneHeight } = topScene;
|
|
2461
|
+
const { ancestorLeft, ancestorTop } = scene;
|
|
2462
|
+
let limitLeft = left;
|
|
2463
|
+
let limitTop = top;
|
|
2464
|
+
let limitWidth = width;
|
|
2465
|
+
let limitHeight = height;
|
|
2466
|
+
if (left + ancestorLeft < 0) limitLeft = -ancestorLeft;
|
|
2467
|
+
if (top + ancestorTop < 0) limitTop = -ancestorTop;
|
|
2468
|
+
limitWidth = topSceneWidth - limitLeft - ancestorLeft;
|
|
2469
|
+
if (limitWidth < 20) limitWidth = 20;
|
|
2470
|
+
limitHeight = topSceneHeight - limitTop - ancestorTop;
|
|
2471
|
+
if (limitHeight < 20) limitHeight = 20;
|
|
2472
|
+
if (left + limitWidth + ancestorLeft > topSceneWidth) limitLeft = topSceneWidth - width - ancestorLeft;
|
|
2473
|
+
if (top + limitHeight + ancestorTop > topSceneHeight) limitTop = topSceneHeight - height - ancestorTop;
|
|
2474
|
+
return {
|
|
2475
|
+
limitLeft,
|
|
2476
|
+
limitTop,
|
|
2477
|
+
limitWidth,
|
|
2478
|
+
limitHeight
|
|
2479
|
+
};
|
|
2480
|
+
};
|
|
2481
|
+
const changeObs = (state) => {
|
|
2482
|
+
const { objects } = state;
|
|
2483
|
+
const params = getUpdateParams(objects, drawingManagerService);
|
|
2484
|
+
if (params.length !== 1) return;
|
|
2485
|
+
const drawingParam = params[0];
|
|
2486
|
+
if (drawingParam == null) return;
|
|
2487
|
+
const { transform } = drawingParam;
|
|
2488
|
+
if (transform == null) return;
|
|
2489
|
+
const { width: originWidth, height: originHeight, left: originX, top: originY, angle: originRotation } = transform;
|
|
2490
|
+
if (originWidth != null) setWidth(originWidth);
|
|
2491
|
+
if (originHeight != null) setHeight(originHeight);
|
|
2492
|
+
if (originX != null) setXPosition(originX);
|
|
2493
|
+
if (originY != null) setYPosition(originY);
|
|
2494
|
+
if (originRotation != null) setRotation(originRotation);
|
|
2495
|
+
};
|
|
2496
|
+
(0, react.useEffect)(() => {
|
|
2497
|
+
const subscriptions = [
|
|
2498
|
+
transformer.changeStart$.subscribe((state) => {
|
|
2499
|
+
changeObs(state);
|
|
2500
|
+
}),
|
|
2501
|
+
transformer.changing$.subscribe((state) => {
|
|
2502
|
+
changeObs(state);
|
|
2503
|
+
}),
|
|
2504
|
+
transformer.changeEnd$.subscribe((state) => {
|
|
2505
|
+
changeObs(state);
|
|
2506
|
+
}),
|
|
2507
|
+
drawingManagerService.focus$.subscribe((drawings) => {
|
|
2508
|
+
if (drawings.length !== 1) return;
|
|
2509
|
+
const drawingParam = drawingManagerService.getDrawingByParam(drawings[0]);
|
|
2510
|
+
if (drawingParam == null) return;
|
|
2511
|
+
const transform = drawingParam.transform;
|
|
2512
|
+
if (transform == null) return;
|
|
2513
|
+
const { width: originWidth, height: originHeight, left: originX, top: originY, angle: originRotation } = transform;
|
|
2514
|
+
if (originWidth != null) setWidth(originWidth);
|
|
2515
|
+
if (originHeight != null) setHeight(originHeight);
|
|
2516
|
+
if (originX != null) setXPosition(originX);
|
|
2517
|
+
if (originY != null) setYPosition(originY);
|
|
2518
|
+
if (originRotation != null) setRotation(originRotation);
|
|
2519
|
+
})
|
|
2520
|
+
];
|
|
2521
|
+
return () => {
|
|
2522
|
+
subscriptions.forEach((sub) => sub.unsubscribe());
|
|
2523
|
+
};
|
|
2524
|
+
}, []);
|
|
2525
|
+
const handleWidthChange = (0, _univerjs_core.debounce)((val) => {
|
|
2526
|
+
if (val == null) return;
|
|
2527
|
+
const { limitWidth, limitHeight } = checkMoveBoundary(xPosition, yPosition, val, height);
|
|
2528
|
+
val = Math.min(val, limitWidth);
|
|
2529
|
+
const updateParam = {
|
|
2530
|
+
unitId,
|
|
2531
|
+
subUnitId,
|
|
2532
|
+
drawingId,
|
|
2533
|
+
drawingType,
|
|
2534
|
+
transform: { width: val }
|
|
2535
|
+
};
|
|
2536
|
+
if (lockRatio) {
|
|
2537
|
+
let heightFix = val / width * height;
|
|
2538
|
+
heightFix = Math.max(heightFix, 20);
|
|
2539
|
+
if (heightFix > limitHeight) return;
|
|
2540
|
+
setHeight(heightFix);
|
|
2541
|
+
updateParam.transform.height = heightFix;
|
|
2542
|
+
}
|
|
2543
|
+
setWidth(val);
|
|
2544
|
+
drawingManagerService.featurePluginUpdateNotification([updateParam]);
|
|
2545
|
+
transformer.refreshControls().changeNotification();
|
|
2546
|
+
}, INPUT_DEBOUNCE_TIME);
|
|
2547
|
+
const handleHeightChange = (0, _univerjs_core.debounce)((val) => {
|
|
2548
|
+
if (val == null) return;
|
|
2549
|
+
const { limitHeight, limitWidth } = checkMoveBoundary(xPosition, yPosition, width, val);
|
|
2550
|
+
val = Math.min(val, limitHeight);
|
|
2551
|
+
const updateParam = {
|
|
2552
|
+
unitId,
|
|
2553
|
+
subUnitId,
|
|
2554
|
+
drawingId,
|
|
2555
|
+
drawingType,
|
|
2556
|
+
transform: { height: val }
|
|
2557
|
+
};
|
|
2558
|
+
if (lockRatio) {
|
|
2559
|
+
let widthFix = val / height * width;
|
|
2560
|
+
widthFix = Math.max(widthFix, 20);
|
|
2561
|
+
if (widthFix > limitWidth) return;
|
|
2562
|
+
setWidth(widthFix);
|
|
2563
|
+
updateParam.transform.width = widthFix;
|
|
2564
|
+
}
|
|
2565
|
+
setHeight(val);
|
|
2566
|
+
drawingManagerService.featurePluginUpdateNotification([updateParam]);
|
|
2567
|
+
transformer.refreshControls().changeNotification();
|
|
2568
|
+
}, INPUT_DEBOUNCE_TIME);
|
|
2569
|
+
const handleXChange = (0, _univerjs_core.debounce)((val) => {
|
|
2570
|
+
if (val == null) return;
|
|
2571
|
+
const { limitLeft } = checkMoveBoundary(val, yPosition, width, height);
|
|
2572
|
+
val = limitLeft;
|
|
2573
|
+
const updateParam = {
|
|
2574
|
+
unitId,
|
|
2575
|
+
subUnitId,
|
|
2576
|
+
drawingId,
|
|
2577
|
+
drawingType,
|
|
2578
|
+
transform: { left: val }
|
|
2579
|
+
};
|
|
2580
|
+
setXPosition(val);
|
|
2581
|
+
drawingManagerService.featurePluginUpdateNotification([updateParam]);
|
|
2582
|
+
transformer.refreshControls().changeNotification();
|
|
2583
|
+
}, INPUT_DEBOUNCE_TIME);
|
|
2584
|
+
const handleYChange = (0, _univerjs_core.debounce)((val) => {
|
|
2585
|
+
if (val == null) return;
|
|
2586
|
+
const { limitTop } = checkMoveBoundary(xPosition, val, width, height);
|
|
2587
|
+
val = limitTop;
|
|
2588
|
+
const updateParam = {
|
|
2589
|
+
unitId,
|
|
2590
|
+
subUnitId,
|
|
2591
|
+
drawingId,
|
|
2592
|
+
drawingType,
|
|
2593
|
+
transform: { top: val }
|
|
2594
|
+
};
|
|
2595
|
+
setYPosition(val);
|
|
2596
|
+
drawingManagerService.featurePluginUpdateNotification([updateParam]);
|
|
2597
|
+
transformer.refreshControls().changeNotification();
|
|
2598
|
+
}, INPUT_DEBOUNCE_TIME);
|
|
2599
|
+
const handleRotationChange = (val) => {
|
|
2600
|
+
if (val == null) return;
|
|
2601
|
+
const updateParam = {
|
|
2602
|
+
unitId,
|
|
2603
|
+
subUnitId,
|
|
2604
|
+
drawingId,
|
|
2605
|
+
drawingType,
|
|
2606
|
+
transform: { angle: val }
|
|
2607
|
+
};
|
|
2608
|
+
setRotation(val);
|
|
2609
|
+
drawingManagerService.featurePluginUpdateNotification([updateParam]);
|
|
2610
|
+
transformer.refreshControls().changeNotification();
|
|
2611
|
+
};
|
|
2612
|
+
const handleLockRatioChange = (val) => {
|
|
2613
|
+
setLockRatio(val);
|
|
2614
|
+
transformer.keepRatio = val;
|
|
2615
|
+
};
|
|
2616
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2617
|
+
className: (0, _univerjs_design.clsx)("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !transformShow }),
|
|
2618
|
+
children: [
|
|
2619
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
|
|
2620
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2621
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("image-panel.transform.title") })
|
|
2622
|
+
}),
|
|
2623
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2624
|
+
className: "univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
|
|
2625
|
+
children: [
|
|
2626
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("image-panel.transform.width") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
2627
|
+
precision: 1,
|
|
2628
|
+
value: width,
|
|
2629
|
+
min: 20,
|
|
2630
|
+
onChange: (val) => {
|
|
2631
|
+
handleWidthChange(val);
|
|
2632
|
+
}
|
|
2633
|
+
})] }),
|
|
2634
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("image-panel.transform.height") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
2635
|
+
precision: 1,
|
|
2636
|
+
value: height,
|
|
2637
|
+
min: 20,
|
|
2638
|
+
onChange: (val) => {
|
|
2639
|
+
handleHeightChange(val);
|
|
2640
|
+
}
|
|
2641
|
+
})] }),
|
|
2642
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("image-panel.transform.lock") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2643
|
+
className: "univer-text-center",
|
|
2644
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Checkbox, {
|
|
2645
|
+
checked: lockRatio,
|
|
2646
|
+
onChange: handleLockRatioChange
|
|
2647
|
+
})
|
|
2648
|
+
})] })
|
|
2649
|
+
]
|
|
2650
|
+
}),
|
|
2651
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2652
|
+
className: "univer-grid univer-grid-cols-3 univer-gap-2 [&>div]:univer-grid [&>div]:univer-gap-2",
|
|
2653
|
+
children: [
|
|
2654
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("image-panel.transform.x") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
2655
|
+
precision: 1,
|
|
2656
|
+
value: xPosition,
|
|
2657
|
+
onChange: (val) => {
|
|
2658
|
+
handleXChange(val);
|
|
2659
|
+
}
|
|
2660
|
+
})] }),
|
|
2661
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("image-panel.transform.y") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
2662
|
+
precision: 1,
|
|
2663
|
+
value: yPosition,
|
|
2664
|
+
onChange: (val) => {
|
|
2665
|
+
handleYChange(val);
|
|
2666
|
+
}
|
|
2667
|
+
})] }),
|
|
2668
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("image-panel.transform.rotate") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.InputNumber, {
|
|
2669
|
+
precision: 1,
|
|
2670
|
+
value: rotation,
|
|
2671
|
+
min: RANGE_DRAWING_ROTATION_LIMIT[0],
|
|
2672
|
+
max: RANGE_DRAWING_ROTATION_LIMIT[1],
|
|
2673
|
+
onChange: handleRotationChange
|
|
2674
|
+
})] })
|
|
2675
|
+
]
|
|
2676
|
+
})
|
|
2677
|
+
]
|
|
2678
|
+
});
|
|
2679
|
+
};
|
|
2680
|
+
|
|
2681
|
+
//#endregion
|
|
2682
|
+
//#region src/views/panel/ImageCropper.tsx
|
|
2683
|
+
const ImageCropper = (props) => {
|
|
2684
|
+
const commandService = (0, _univerjs_ui.useDependency)(_univerjs_core.ICommandService);
|
|
2685
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
2686
|
+
const clipService = (0, _univerjs_ui.useDependency)(DrawingImageClipService);
|
|
2687
|
+
const componentManager = (0, _univerjs_ui.useDependency)(_univerjs_ui.ComponentManager);
|
|
2688
|
+
const canUseShapeClip = (0, _univerjs_ui.useObservable)(clipService.canUseShapeClip$, false);
|
|
2689
|
+
const { drawings, cropperShow } = props;
|
|
2690
|
+
if (drawings[0] == null) return;
|
|
2691
|
+
const [cropValue, setCropValue] = (0, react.useState)(CropType.FREE);
|
|
2692
|
+
const cropStateRef = (0, react.useRef)(false);
|
|
2693
|
+
const cropOptions = [
|
|
2694
|
+
{
|
|
2695
|
+
label: localeService.t("image-panel.crop.mode"),
|
|
2696
|
+
value: CropType.FREE
|
|
2697
|
+
},
|
|
2698
|
+
{
|
|
2699
|
+
label: "1:1",
|
|
2700
|
+
value: CropType.R1_1
|
|
2701
|
+
},
|
|
2702
|
+
{
|
|
2703
|
+
label: "16:9",
|
|
2704
|
+
value: CropType.R16_9
|
|
2705
|
+
},
|
|
2706
|
+
{
|
|
2707
|
+
label: "9:16",
|
|
2708
|
+
value: CropType.R9_16
|
|
2709
|
+
},
|
|
2710
|
+
{
|
|
2711
|
+
label: "5:4",
|
|
2712
|
+
value: CropType.R5_4
|
|
2713
|
+
},
|
|
2714
|
+
{
|
|
2715
|
+
label: "4:5",
|
|
2716
|
+
value: CropType.R4_5
|
|
2717
|
+
},
|
|
2718
|
+
{
|
|
2719
|
+
label: "4:3",
|
|
2720
|
+
value: CropType.R4_3
|
|
2721
|
+
},
|
|
2722
|
+
{
|
|
2723
|
+
label: "3:4",
|
|
2724
|
+
value: CropType.R3_4
|
|
2725
|
+
},
|
|
2726
|
+
{
|
|
2727
|
+
label: "3:2",
|
|
2728
|
+
value: CropType.R3_2
|
|
2729
|
+
},
|
|
2730
|
+
{
|
|
2731
|
+
label: "2:3",
|
|
2732
|
+
value: CropType.R2_3
|
|
2733
|
+
}
|
|
2734
|
+
];
|
|
2735
|
+
(0, react.useEffect)(() => {
|
|
2736
|
+
const onChangeStartObserver = commandService.onCommandExecuted((command) => {
|
|
2737
|
+
if (command.id === CloseImageCropOperation.id) {
|
|
2738
|
+
const params = command.params;
|
|
2739
|
+
if (!(params === null || params === void 0 ? void 0 : params.isAuto)) cropStateRef.current = false;
|
|
2740
|
+
}
|
|
2741
|
+
});
|
|
2742
|
+
return () => {
|
|
2743
|
+
onChangeStartObserver === null || onChangeStartObserver === void 0 || onChangeStartObserver.dispose();
|
|
2744
|
+
};
|
|
2745
|
+
}, []);
|
|
2746
|
+
function handleCropChange(value) {
|
|
2747
|
+
setCropValue(value);
|
|
2748
|
+
if (cropStateRef.current) commandService.executeCommand(AutoImageCropOperation.id, { cropType: value });
|
|
2749
|
+
}
|
|
2750
|
+
const onCropperBtnClick = (val) => {
|
|
2751
|
+
commandService.executeCommand(AutoImageCropOperation.id, { cropType: val });
|
|
2752
|
+
cropStateRef.current = true;
|
|
2753
|
+
};
|
|
2754
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2755
|
+
className: (0, _univerjs_design.clsx)("univer-grid univer-gap-2 univer-py-2 univer-text-gray-400", { "univer-hidden": !cropperShow }),
|
|
2756
|
+
children: [
|
|
2757
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("header", {
|
|
2758
|
+
className: "univer-text-gray-600 dark:!univer-text-gray-200",
|
|
2759
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: localeService.t("image-panel.crop.title") })
|
|
2760
|
+
}),
|
|
2761
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
2762
|
+
className: "univer-flex univer-items-center univer-justify-center univer-gap-2",
|
|
2763
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_univerjs_design.Button, {
|
|
2764
|
+
onClick: () => {
|
|
2765
|
+
onCropperBtnClick(cropValue);
|
|
2766
|
+
},
|
|
2767
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_icons.CreateCopyIcon, {}), localeService.t("image-panel.crop.start")]
|
|
2768
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_univerjs_design.Select, {
|
|
2769
|
+
value: cropValue,
|
|
2770
|
+
options: cropOptions,
|
|
2771
|
+
onChange: handleCropChange
|
|
2772
|
+
})]
|
|
2773
|
+
}),
|
|
2774
|
+
canUseShapeClip && (() => {
|
|
2775
|
+
const ShapeClipPicker = componentManager.get("sheet.image-clip.shape.picker.component");
|
|
2776
|
+
return ShapeClipPicker ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ShapeClipPicker, {}) : null;
|
|
2777
|
+
})()
|
|
2778
|
+
]
|
|
2779
|
+
});
|
|
2780
|
+
};
|
|
2781
|
+
|
|
2782
|
+
//#endregion
|
|
2783
|
+
//#region src/views/panel/DrawingCommonPanel.tsx
|
|
2784
|
+
const DrawingCommonPanel = (props) => {
|
|
2785
|
+
const drawingManagerService = (0, _univerjs_ui.useDependency)(_univerjs_drawing.IDrawingManagerService);
|
|
2786
|
+
const renderManagerService = (0, _univerjs_ui.useDependency)(_univerjs_engine_render.IRenderManagerService);
|
|
2787
|
+
const localeService = (0, _univerjs_ui.useDependency)(_univerjs_core.LocaleService);
|
|
2788
|
+
const { drawings, hasArrange = true, hasTransform = true, hasAlign = true, hasCropper = true, hasGroup = true } = props;
|
|
2789
|
+
const drawingParam = drawings[0];
|
|
2790
|
+
if (drawingParam == null) return;
|
|
2791
|
+
const { unitId } = drawingParam;
|
|
2792
|
+
const renderObject = renderManagerService.getRenderById(unitId);
|
|
2793
|
+
const scene = renderObject === null || renderObject === void 0 ? void 0 : renderObject.scene;
|
|
2794
|
+
if (scene == null) return;
|
|
2795
|
+
const transformer = scene.getTransformerByCreate();
|
|
2796
|
+
const [arrangeShow, setArrangeShow] = (0, react.useState)(true);
|
|
2797
|
+
const [transformShow, setTransformShow] = (0, react.useState)(true);
|
|
2798
|
+
const [alignShow, setAlignShow] = (0, react.useState)(false);
|
|
2799
|
+
const [cropperShow, setCropperShow] = (0, react.useState)(true);
|
|
2800
|
+
const [nullShow, setNullShow] = (0, react.useState)(false);
|
|
2801
|
+
(0, react.useEffect)(() => {
|
|
2802
|
+
const clearControlSub = transformer.clearControl$.subscribe((changeSelf) => {
|
|
2803
|
+
if (changeSelf === true) {
|
|
2804
|
+
setArrangeShow(false);
|
|
2805
|
+
setTransformShow(false);
|
|
2806
|
+
setAlignShow(false);
|
|
2807
|
+
setCropperShow(false);
|
|
2808
|
+
setNullShow(true);
|
|
2809
|
+
}
|
|
2810
|
+
});
|
|
2811
|
+
const changeStartSub = transformer.changeStart$.subscribe((state) => {
|
|
2812
|
+
const { objects } = state;
|
|
2813
|
+
const params = getUpdateParams(objects, drawingManagerService);
|
|
2814
|
+
if (params.length === 0) {
|
|
2815
|
+
setArrangeShow(false);
|
|
2816
|
+
setTransformShow(false);
|
|
2817
|
+
setAlignShow(false);
|
|
2818
|
+
setCropperShow(false);
|
|
2819
|
+
setNullShow(true);
|
|
2820
|
+
} else if (params.length === 1) {
|
|
2821
|
+
setArrangeShow(true);
|
|
2822
|
+
setTransformShow(true);
|
|
2823
|
+
setAlignShow(false);
|
|
2824
|
+
setCropperShow(true);
|
|
2825
|
+
setNullShow(false);
|
|
2826
|
+
} else {
|
|
2827
|
+
setArrangeShow(true);
|
|
2828
|
+
setTransformShow(false);
|
|
2829
|
+
setAlignShow(true);
|
|
2830
|
+
setCropperShow(false);
|
|
2831
|
+
setNullShow(false);
|
|
2832
|
+
}
|
|
2833
|
+
});
|
|
2834
|
+
const focusSub = drawingManagerService.focus$.subscribe((drawings) => {
|
|
2835
|
+
if (drawings.length === 0) {
|
|
2836
|
+
setArrangeShow(false);
|
|
2837
|
+
setTransformShow(false);
|
|
2838
|
+
setAlignShow(false);
|
|
2839
|
+
setCropperShow(false);
|
|
2840
|
+
setNullShow(true);
|
|
2841
|
+
} else if (drawings.length === 1) {
|
|
2842
|
+
setArrangeShow(true);
|
|
2843
|
+
setTransformShow(true);
|
|
2844
|
+
setAlignShow(false);
|
|
2845
|
+
setCropperShow(true);
|
|
2846
|
+
setNullShow(false);
|
|
2847
|
+
} else {
|
|
2848
|
+
setArrangeShow(true);
|
|
2849
|
+
setTransformShow(false);
|
|
2850
|
+
setAlignShow(true);
|
|
2851
|
+
setCropperShow(false);
|
|
2852
|
+
setNullShow(false);
|
|
2853
|
+
}
|
|
2854
|
+
});
|
|
2855
|
+
return () => {
|
|
2856
|
+
changeStartSub.unsubscribe();
|
|
2857
|
+
clearControlSub.unsubscribe();
|
|
2858
|
+
focusSub.unsubscribe();
|
|
2859
|
+
};
|
|
2860
|
+
}, []);
|
|
2861
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
|
|
2862
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2863
|
+
className: (0, _univerjs_design.clsx)("univer-h-full", { "univer-hidden": !nullShow }),
|
|
2864
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
|
|
2865
|
+
className: "univer-flex univer-h-full univer-items-center univer-justify-center",
|
|
2866
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: localeService.t("image-panel.null") })
|
|
2867
|
+
})
|
|
2868
|
+
}),
|
|
2869
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DrawingArrange, {
|
|
2870
|
+
arrangeShow: hasArrange === true ? arrangeShow : false,
|
|
2871
|
+
drawings
|
|
2872
|
+
}),
|
|
2873
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DrawingTransform, {
|
|
2874
|
+
transformShow: hasTransform === true ? transformShow : false,
|
|
2875
|
+
drawings
|
|
2876
|
+
}),
|
|
2877
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DrawingAlign, {
|
|
2878
|
+
alignShow: hasAlign === true ? alignShow : false,
|
|
2879
|
+
drawings
|
|
2880
|
+
}),
|
|
2881
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ImageCropper, {
|
|
2882
|
+
cropperShow: hasCropper === true ? cropperShow : false,
|
|
2883
|
+
drawings
|
|
2884
|
+
}),
|
|
2885
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(DrawingGroup, {
|
|
2886
|
+
hasGroup,
|
|
2887
|
+
drawings
|
|
2888
|
+
})
|
|
2889
|
+
] });
|
|
2890
|
+
};
|
|
2891
|
+
|
|
2892
|
+
//#endregion
|
|
2893
|
+
exports.AutoImageCropOperation = AutoImageCropOperation;
|
|
2894
|
+
exports.COMPONENT_IMAGE_POPUP_MENU = COMPONENT_IMAGE_POPUP_MENU;
|
|
2895
|
+
exports.CancelDrawingGroupOperation = CancelDrawingGroupOperation;
|
|
2896
|
+
exports.CloseImageCropOperation = CloseImageCropOperation;
|
|
2897
|
+
exports.DRAWING_GROUP_TYPES = DRAWING_GROUP_TYPES;
|
|
2898
|
+
exports.DrawingCommonPanel = DrawingCommonPanel;
|
|
2899
|
+
exports.DrawingImageClipService = DrawingImageClipService;
|
|
2900
|
+
Object.defineProperty(exports, 'DrawingRenderService', {
|
|
2901
|
+
enumerable: true,
|
|
2902
|
+
get: function () {
|
|
2903
|
+
return DrawingRenderService;
|
|
2904
|
+
}
|
|
2905
|
+
});
|
|
2906
|
+
exports.IMAGE_CLIP_SHAPE_PICKER_COMPONENT = IMAGE_CLIP_SHAPE_PICKER_COMPONENT;
|
|
2907
|
+
exports.ImageCropperObject = ImageCropperObject;
|
|
2908
|
+
exports.ImagePopupMenu = ImagePopupMenu;
|
|
2909
|
+
exports.ImageResetSizeOperation = ImageResetSizeOperation;
|
|
2910
|
+
exports.OpenImageCropOperation = OpenImageCropOperation;
|
|
2911
|
+
exports.SetDrawingAlignOperation = SetDrawingAlignOperation;
|
|
2912
|
+
exports.SetDrawingArrangeOperation = SetDrawingArrangeOperation;
|
|
2913
|
+
exports.SetDrawingGroupOperation = SetDrawingGroupOperation;
|
|
2914
|
+
Object.defineProperty(exports, 'UniverDrawingUIPlugin', {
|
|
2915
|
+
enumerable: true,
|
|
2916
|
+
get: function () {
|
|
2917
|
+
return UniverDrawingUIPlugin;
|
|
2918
|
+
}
|
|
2919
|
+
});
|
|
2920
|
+
exports.getCurrentUnitInfo = getCurrentUnitInfo;
|
|
2921
|
+
exports.getUpdateParams = getUpdateParams;
|
|
2922
|
+
exports.insertGroupObject = insertGroupObject;
|