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