@univerjs/preset-docs-drawing 0.6.10-nightly.202504101607 → 0.6.10-nightly.202504121606

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.
Files changed (2) hide show
  1. package/lib/umd/index.js +1 -1
  2. package/package.json +6 -6
package/lib/umd/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  univer-flex univer-items-center univer-gap-2 univer-rounded univer-border univer-border-solid
4
4
  univer-border-gray-200 univer-p-1
5
5
  hover:univer-bg-gray-100
6
- `,{"univer-bg-gray-100":s,"univer-bg-white":!s}),children:[l.jsx(Ue,{style:{color:"#35322B"},extend:{colorChannel1:"rgb(var(--green-700, #409f11))"}}),p&&l.jsx(Le,{className:"univer-text-[10px] univer-text-gray-400"})]})})})},We="COMPONENT_IMAGE_POPUP_MENU",wn="drawing-ui.config",$e={},be={id:"sheet.operation.image-reset-size",type:h.CommandType.OPERATION,handler:(a,t)=>!0},vn=a=>{const{src:t}=a;return t?l.jsx("div",{children:l.jsx("img",{src:t,alt:"Univer Image Viewer",style:{width:"100%",height:"100%",position:"relative"}})}):null};var Sn=Object.getOwnPropertyDescriptor,_n=(a,t,n,e)=>{for(var r=e>1?void 0:e?Sn(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},ze=(a,t)=>(n,e)=>t(n,e,a);let we=class extends h.Disposable{constructor(a,t){super(),this._componentManager=a,this._commandService=t,this._init()}_initCustomComponents(){const a=this._componentManager;this.disposeWithMe(a.register(We,ke)),this.disposeWithMe(a.register(Ee,vn))}_initCommands(){[Ce,ne,be,fe,me].forEach(a=>this.disposeWithMe(this._commandService.registerCommand(a)))}_init(){this._initCommands(),this._initCustomComponents()}};we=_n([ze(0,h.Inject(V.ComponentManager)),ze(1,h.ICommandService)],we);var In=Object.getOwnPropertyDescriptor,yn=(a,t,n,e)=>{for(var r=e>1?void 0:e?In(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},ve=(a,t)=>(n,e)=>t(n,e,a);let Se=class extends h.Disposable{constructor(t,n,e,r){super();ee(this,"_sceneListenerOnDrawingMap",new WeakSet);this._currentUniverService=t,this._commandService=n,this._renderManagerService=e,this._drawingManagerService=r,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(){const t=this._drawingManagerService.drawingManagerData,n=Ne(this._currentUniverService);if(n==null)return;const{unitId:e,subUnitId:r}=n;Object.keys(t).forEach(s=>{Object.keys(t[s]).forEach(i=>{const o=t[s][i].data;o==null||s!==e||i!==r||Object.keys(o).forEach(c=>{o[c]&&this._insertDrawing([{unitId:s,subUnitId:i,drawingId:c}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===fe.id){const n=t.params;if(n==null)return;this._drawingAlign(n)}}))}_drawingGroupListener(){this.disposeWithMe(this._drawingManagerService.group$.subscribe(t=>{this._groupDrawings(t)})),this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe(t=>{this._ungroupDrawings(t)}))}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const n=this._renderManagerService.getRenderById(t),e=n==null?void 0:n.scene;if(e==null)return null;const r=e.getTransformerByCreate();return{scene:e,transformer:r}}_groupDrawings(t){t.forEach(n=>{this._groupDrawing(n)})}_groupDrawing(t){const{parent:n,children:e}=t,{unitId:r,subUnitId:s,drawingId:i}=n,o=this._getSceneAndTransformerByDrawingSearch(n.unitId);if(o==null)return;const{scene:c,transformer:g}=o;this._commandService.syncExecuteCommand(ne.id);const d=[];if(e.forEach(p=>{const S=M.getDrawingShapeKeyByDrawingSearch(p),v=c.getObjectIncludeInGroup(S);if(v==null||d.includes(v))return;d.push(v);const{transform:C}=p;C!=null&&(v.classType===b.RENDER_CLASS_TYPE.GROUP?v.transformByState({left:C.left,top:C.top}):v.transformByState(C))}),d.length===0)return;const u=M.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:s,drawingId:i}),f=new b.Group(u);c.addObject(f,b.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(f),f.addObjects(...d),n.transform&&f.transformByState({left:n.transform.left,top:n.transform.top}),g.clearSelectedObjects(),g.setSelectedControl(f)}_ungroupDrawings(t){t.forEach(n=>{this._ungroupDrawing(n)})}_ungroupDrawing(t){const{parent:n,children:e}=t,r=this._getSceneAndTransformerByDrawingSearch(n.unitId);if(r==null)return;const{scene:s,transformer:i}=r;e.forEach(u=>{const f=M.getDrawingShapeKeyByDrawingSearch(u),p=s.getObjectIncludeInGroup(f);if(p==null)return!0;if(p==null)return;const{transform:S}=u;S!=null&&(p.classType===b.RENDER_CLASS_TYPE.GROUP?p.transformByState({left:S.left,top:S.top}):p.transformByState(S))});const o=M.getDrawingShapeKeyByDrawingSearch(n),c=s.getObject(o),{width:g,height:d}=c;c.getObjects().forEach(u=>{c.removeSelfObjectAndTransform(u.oKey,g,d)}),c.dispose(),i.clearSelectedObjects()}_drawingAlign(t){const{alignType:n}=t,e=this._drawingManagerService.getFocusDrawings();if(n===A.default)return;const r=[];let s=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY,g=0;e.forEach(d=>{const{unitId:u,subUnitId:f,drawingId:p,drawingType:S}=d,v=this._drawingManagerService.getDrawingByParam({unitId:u,subUnitId:f,drawingId:p});if(v==null||v.transform==null)return;r.push({unitId:u,subUnitId:f,drawingId:p,drawingType:S,transform:v.transform});const{left:C=0,top:P=0,width:y=0,height:U=0}=v.transform;s=Math.min(s,C),i=Math.min(i,P),o=Math.max(o,C+y),c=Math.max(c,P+U),g++}),g!==0&&(this._sortDrawingTransform(r,n),this._applyAlignType(r,n,s,i,o,c,g))}_applyAlignType(t,n,e,r,s,i,o){const c=Math.round((s-e)/o*10)/10,g=Math.round((i-r)/o*10)/10,d=[],u=this._getSceneAndTransformerByDrawingSearch(t[0].unitId);if(u==null)return;const{scene:f,transformer:p}=u;t.forEach((S,v)=>{const{unitId:C,subUnitId:P,drawingId:y,transform:U,drawingType:O}=S,{left:R=0,top:T=0,width:N=0,height:E=0}=U;let B=R,j=T;switch(n){case A.left:B=e;break;case A.center:B=e+(s-e)/2-N/2;break;case A.right:B=s-N;break;case A.top:j=r;break;case A.middle:j=r+(i-r)/2-E/2;break;case A.bottom:j=i-E;break;case A.horizon:B=e+c*v;break;case A.vertical:j=r+g*v;break}(B!==R||j!==T)&&d.push({unitId:C,subUnitId:P,drawingId:y,drawingType:O,transform:{left:B,top:j}})}),this._drawingManagerService.featurePluginUpdateNotification(d),p.refreshControls().changeNotification()}_sortDrawingTransform(t,n){t.sort((e,r)=>{const s=e.transform,i=r.transform,{left:o=0,top:c=0,width:g=0,height:d=0}=s,{left:u=0,top:f=0,width:p=0,height:S=0}=i;switch(n){case A.left:return o-u;case A.center:return o+g/2-(u+p/2);case A.right:return o+g-(u+p);case A.top:return c-f;case A.middle:return c+d/2-(f+S/2);case A.bottom:return c+d-(f+S);case A.horizon:return o+g/2-(u+p/2);case A.vertical:return c+d/2-(f+S/2);default:return 0}})}_drawingArrangeListener(){this.disposeWithMe(this._drawingManagerService.order$.subscribe(t=>{this._drawingArrange(t)}))}_drawingArrange(t){const{unitId:n,subUnitId:e,drawingIds:r}=t,s=this._getSceneAndTransformerByDrawingSearch(n);if(s==null)return;const{scene:i}=s;r.forEach(o=>{const c=M.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:o}),g=i.fuzzyMathObjects(c,!0);if(g==null||g.length===0)return;const d=this._drawingManagerService.getDrawingOrder(n,e).indexOf(o);for(const u of g)u.setProps({zIndex:d}),u.makeDirty()})}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{this._insertDrawing(t)}))}_insertDrawing(t){const n=[];t.forEach(e=>{const{unitId:r}=e;if(this._drawingManagerService.getDrawingByParam(e)==null)return;const i=this._getSceneAndTransformerByDrawingSearch(r);if(i==null)return;const{scene:o}=i;n.includes(o)||n.push(o)}),n.forEach(e=>{this._sceneListenerOnDrawingMap.has(e)||(this._addListenerOnDrawing(e),this._sceneListenerOnDrawingMap.add(e))})}_drawingRemoveListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(n=>{var d;const{unitId:e,subUnitId:r,drawingId:s}=n,i=this._getSceneAndTransformerByDrawingSearch(e);if(i==null)return;const{scene:o}=i,c=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),g=o.fuzzyMathObjects(c,!0);if(g.length>0){for(const u of g)u.dispose();(d=o.getTransformer())==null||d.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(n=>{var N;const{unitId:e,subUnitId:r,drawingId:s}=n,i=this._drawingManagerService.getDrawingByParam(n);if(i==null)return;const{transform:o,drawingType:c}=i,g=this._getSceneAndTransformerByDrawingSearch(e);if(g==null)return;const{scene:d,transformer:u}=g;if(o==null)return!0;const{left:f=0,top:p=0,width:S=0,height:v=0,angle:C=0,flipX:P=!1,flipY:y=!1,skewX:U=0,skewY:O=0}=o,R=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),T=d.getObject(R);if(T==null)return!0;T.transformByState({left:f,top:p,width:S,height:v,angle:C,flipX:P,flipY:y,skewX:U,skewY:O}),(N=d.getTransformer())==null||N.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(t=>{t.forEach(n=>{const{unitId:e,subUnitId:r,drawingId:s}=n,i=this._getSceneAndTransformerByDrawingSearch(e);if(i==null)return;const o=this._drawingManagerService.getDrawingByParam(n);if(o==null)return;const{transform:c}=o,{scene:g}=i,d=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),u=g.getObject(d);if(u==null||c==null)return!0;const{left:f=0,top:p=0,width:S=0,height:v=0,angle:C=0,flipX:P=!1,flipY:y=!1,skewX:U=0,skewY:O=0}=c;u.transformByState({left:f,top:p,width:S,height:v,angle:C,flipX:P,flipY:y,skewX:U,skewY:O})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(t=>{t.forEach(n=>{const{unitId:e,subUnitId:r,drawingId:s,visible:i}=n,o=this._getSceneAndTransformerByDrawingSearch(e);if(o==null)return;const{scene:c}=o,g=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),d=c.getObject(g);if(d==null)return!0;i?d.show():d.hide()})}))}_filterUpdateParams(t,n){return t.filter((e,r)=>{if(e==null)return!1;const{transform:s}=e;return h.checkIfMove(s,n==null?void 0:n[r])})}_addListenerOnDrawing(t){const n=t.getTransformerByCreate();let e=null;this.disposeWithMe(h.toDisposable(n.changeStart$.subscribe(r=>{const{objects:s}=r,i=Array.from(s.values()),o=[];e=i.map(c=>{const{left:g,top:d,height:u,width:f,angle:p,oKey:S,isInGroup:v}=c,C=this._drawingManagerService.getDrawingOKey(S);if(v||c instanceof b.Group){let P=c.ancestorGroup;if(P==null&&c instanceof b.Group&&(P=c),P==null)return null;const y=this._drawingManagerService.getDrawingOKey(P.oKey);if(y){const{unitId:U,subUnitId:O,drawingId:R}=y;o.push({unitId:U,subUnitId:O,drawingId:R});const{left:T,top:N,height:E,width:B,angle:j}=P;return{left:T,top:N,height:E,width:B,angle:j}}}else if(C!=null){const{unitId:P,subUnitId:y,drawingId:U}=C;return o.push({unitId:P,subUnitId:y,drawingId:U}),{left:g,top:d,height:u,width:f,angle:p}}return null}).filter(c=>c!=null),o.length>0?this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,o):this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,[])}))),this.disposeWithMe(h.toDisposable(n.changeEnd$.subscribe(r=>{const{objects:s}=r,i=this._filterUpdateParams(ge(s,this._drawingManagerService),e);i.length>0&&this._drawingManagerService.featurePluginUpdateNotification(i)})))}};Se=yn([ve(0,h.IUniverInstanceService),ve(1,h.ICommandService),ve(2,b.IRenderManagerService),ve(3,M.IDrawingManagerService)],Se);class de extends b.Shape{constructor(n,e){e==null&&(e={}),e.transformerConfig={keepRatio:!1,isCropper:!0,anchorFill:"rgb(0, 0, 0)",anchorStroke:"rgb(255, 255, 255)",anchorSize:24};super(n,e);ee(this,"_srcRect");ee(this,"_prstGeom");ee(this,"_applyTransform");ee(this,"_dragPadding",8);ee(this,"_cacheCanvas");e!=null&&e.srcRect&&(this._srcRect=e.srcRect),e!=null&&e.prstGeom&&(this._prstGeom=e.prstGeom),e!=null&&e.applyTransform&&(this._applyTransform=e.applyTransform),e!=null&&e.dragPadding&&(this._dragPadding=e.dragPadding),this._applyProps()}refreshSrcRect(n,e){this._srcRect=n,this._applyTransform=e,this._applyProps()}get srcRect(){return this._srcRect}dispose(){var n;super.dispose(),(n=this._cacheCanvas)==null||n.dispose(),this._srcRect=null}isHit(n){const e=this.getInverseCoord(n);return e.x>=-this.strokeWidth/2&&e.x<=this.width+this.strokeWidth/2&&e.y>=-this.strokeWidth/2&&e.y<=this.height+this.strokeWidth/2&&!this._inSurround(e)}_inSurround(n){const e=this._dragPadding;return n.x>=e-this.strokeWidth/2&&n.x<=this.width+this.strokeWidth/2-e&&n.y>=e-this.strokeWidth/2&&n.y<=this.height+this.strokeWidth/2-e}render(n,e){return this.visible?(n.save(),this._draw(n),n.restore(),this.makeDirty(!1),this):(this.makeDirty(!1),this)}_draw(n){var c,g;const r=this.getScene().getEngine(),{width:s,height:i}=r;this._initialCacheCanvas(),(c=this._cacheCanvas)==null||c.clear();const o=(g=this._cacheCanvas)==null?void 0:g.getContext();o!=null&&(o.save(),b.Rect.drawWith(o,{left:0,top:0,width:s,height:i,fill:"rgba(0, 0, 0, 0.5)"}),o.setTransform(n.getTransform()),this._clipForApplyObject(o),this._applyCache(n),o.restore())}_clipForApplyObject(n){let e=0;if(this._prstGeom!=null&&(e=1),n.globalCompositeOperation="destination-out",n.beginPath(),e===0){const r=this.transform.getMatrix();n.transform(r[0],r[1],r[2],r[3],r[4],r[5]),n.rect(0,0,this.width,this.height),n.fill()}}_applyProps(){if(this._applyTransform==null)return;let n=0,e=0,r=0,s=0;const{left:i=0,top:o=0,width:c=0,height:g=0,angle:d}=this._applyTransform;if(this._srcRect!=null){const{left:p=0,top:S=0,right:v=0,bottom:C=0}=this._srcRect;n=p,e=S,r=v,s=C}const u=i+n,f=o+e;this.transformByState({left:u,top:f,width:i+c-r-u,height:o+g-s-f,angle:d})}_applyCache(n){if(!n||this._cacheCanvas==null)return;const e=this._cacheCanvas.getContext();e.save(),n.save(),n.setTransform(1,0,0,1,0,0),e.setTransform(1,0,0,1,0,0),n.drawImage(this._cacheCanvas.getCanvasEle(),0,0),n.restore(),e.restore()}_initialCacheCanvas(){if(this._cacheCanvas!=null)return;const n=this.getScene();if(n==null)return;this._cacheCanvas=new b.Canvas;const e=n.getEngine();this._cacheCanvas.setSize(e.width,e.height),e.onTransformChange$.subscribeEvent(()=>{var r;(r=this._cacheCanvas)==null||r.setSize(e.width,e.height),this.makeDirty(!0)})}}var bn=Object.getOwnPropertyDescriptor,Pn=(a,t,n,e)=>{for(var r=e>1?void 0:e?bn(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},oe=(a,t)=>(n,e)=>t(n,e,a);let _e=class extends h.Disposable{constructor(t,n,e,r,s,i){super();ee(this,"_sceneListenerOnImageMap",new WeakSet);this._commandService=t,this._drawingManagerService=n,this._renderManagerService=e,this._univerInstanceService=r,this._messageService=s,this._localeService=i,this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id!==me.id)return;const n=t.params;if(n==null)return;const{cropType:e}=n,r=this._drawingManagerService.getFocusDrawings();if(r.length!==1)return;const s=r[0],{unitId:i,subUnitId:o,drawingId:c}=s,g=this._renderManagerService.getRenderById(i),d=g==null?void 0:g.scene;if(d==null)return!0;this._searchCropObject(d)!=null&&this._commandService.syncExecuteCommand(ne.id,{isAuto:!0});const f=M.getDrawingShapeKeyByDrawingSearch({unitId:i,subUnitId:o,drawingId:c}),p=d.getObject(f);if(!(p instanceof b.Image)){this._messageService.show({type:I.MessageType.Error,content:this._localeService.t("image-cropper.error")});return}p!=null&&(this._updateCropperObject(e,p),this._commandService.executeCommand(Ce.id,{unitId:i,subUnitId:o,drawingId:c}))}))}_calculateSrcRectByRatio(t,n,e,r,s,i){const o=e/r,c=s/i;let g=e,d=r;o>c?g=r*c:d=e/c;const u=(e-g)/2,f=(r-d)/2;return{left:b.precisionTo(u,1),top:b.precisionTo(f,1),right:b.precisionTo(e-(u+g),1),bottom:b.precisionTo(r-(f+d),1)}}_updateCropperObject(t,n){const{left:e,top:r,width:s,height:i}=n.calculateTransformWithSrcRect();let o;switch(t){case H.R1_1:o=this._calculateSrcRectByRatio(e,r,s,i,1,1);break;case H.R16_9:o=this._calculateSrcRectByRatio(e,r,s,i,16,9);break;case H.R9_16:o=this._calculateSrcRectByRatio(e,r,s,i,9,16);break;case H.R5_4:o=this._calculateSrcRectByRatio(e,r,s,i,5,4);break;case H.R4_5:o=this._calculateSrcRectByRatio(e,r,s,i,4,5);break;case H.R4_3:o=this._calculateSrcRectByRatio(e,r,s,i,4,3);break;case H.R3_4:o=this._calculateSrcRectByRatio(e,r,s,i,3,4);break;case H.R3_2:o=this._calculateSrcRectByRatio(e,r,s,i,3,2);break;case H.R2_3:o=this._calculateSrcRectByRatio(e,r,s,i,2,3);break;case H.FREE:}if(o==null)return;n.setSrcRect(o);const{left:c=0,top:g=0,bottom:d=0,right:u=0}=o;n.transformByStateCloseCropper({left:e+c,top:r+g,width:s-u-c,height:i-d-g})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id!==Ce.id)return;const n=t.params;if(n==null)return;const{unitId:e,subUnitId:r,drawingId:s}=n,i=this._renderManagerService.getRenderById(e),o=i==null?void 0:i.scene;if(o==null)return!0;if(this._sceneListenerOnImageMap.has(o)||(this._addListenerOnImage(o),this._sceneListenerOnImageMap.add(o)),this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:r,drawingId:s})==null)return;const g=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),d=o.getObject(g);if(d==null)return;if(!(d instanceof b.Image)){this._messageService.show({type:I.MessageType.Error,content:this._localeService.t("image-cropper.error")});return}const u=o.getTransformer();u==null||u.clearControls();const f=new de(`${g}-crop`,{srcRect:d.srcRect,prstGeom:d.prstGeom,applyTransform:d.calculateTransformWithSrcRect()});o.addObject(f,d.getLayerIndex()+1).attachTransformerTo(f),u==null||u.createControlForCopper(f),this._addHoverForImageCopper(f),d.openRenderByCropper(),u==null||u.refreshControls(),f.makeDirty(!0),this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:r,drawingId:s}])}))}_searchCropObject(t){const n=t.getAllObjectsByOrder();for(const e of n)if(e instanceof de)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id!==ne.id)return;const e=this._univerInstanceService.getFocusedUnit();if(e==null)return;const r=e.getUnitId(),s=this._renderManagerService.getRenderById(r),i=s==null?void 0:s.scene;if(i==null)return!0;const o=this._searchCropObject(i);if(o==null)return;const c=this._getApplyObjectByCropObject(o);if(c==null)return;const g=i.getTransformerByCreate();g.detachFrom(o),g.clearCopperControl();const d=this._getSrcRectByTransformState(c,o),u=this._drawingManagerService.getDrawingOKey(c.oKey);if(u!=null){const{left:f,top:p,height:S,width:v}=o;this._drawingManagerService.featurePluginUpdateNotification([{...u,transform:{...u.transform,left:f,top:p,height:S,width:v},srcRect:d.srcRectAngle}])}c.setSrcRect({...d.srcRectAngle}),c.closeRenderByCropper(),c.makeDirty(!0),o==null||o.dispose()}));const t=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET).pipe(Me.switchMap(n=>n?n.activeSheet$:Me.of(null)));this.disposeWithMe(t.subscribe(()=>{this._commandService.syncExecuteCommand(ne.id)}))}_getApplyObjectByCropObject(t){const n=t.oKey,e=n.slice(0,n.length-5),r=t.getScene();if(!r)return null;const s=r.getObject(e);return s==null?null:s}_addListenerOnImage(t){const n=t.getTransformerByCreate();let e=null;this.disposeWithMe(n.changeStart$.subscribe(r=>{const{objects:s}=r,i=s.values().next().value;if(i==null||!(i instanceof de))return;const{left:o,top:c,height:g,width:d,angle:u}=i;e={left:o,top:c,height:g,width:d,angle:u},n.clearCopperControl()})),this.disposeWithMe(n.changeEnd$.subscribe(r=>{const{objects:s}=r,i=s.values().next().value;if(i==null||!(i instanceof de))return;const{left:o,top:c,height:g,width:d,angle:u}=i;if(!h.checkIfMove({left:o,top:c,height:g,width:d,angle:u},e))return;const f=this._getApplyObjectByCropObject(i);if(f==null)return;const p=this._getSrcRectByTransformState(f,i);i.refreshSrcRect(p.srcRect,f.getState()),n.createControlForCopper(i)})),this._endCropListener(t)}_addHoverForImageCopper(t){this.disposeWithMe(t.onPointerEnter$.subscribeEvent(()=>{t.cursor=b.CURSOR_TYPE.MOVE})),this.disposeWithMe(t.onPointerLeave$.subscribeEvent(()=>{t.cursor=b.CURSOR_TYPE.DEFAULT}))}_endCropListener(t){const n=t.getTransformerByCreate();this.disposeWithMe(n.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(ne.id)}))}_getSrcRectByTransformState(t,n){const{left:e,top:r,height:s,width:i,strokeWidth:o,angle:c}=n,{left:g,top:d,width:u,height:f,angle:p,strokeWidth:S}=t,v=e-g,C=r-d,P={left:v,top:C,right:u-v-i,bottom:f-C-s},y={...P};if(p!==0){const U=e+i/2,O=r+s/2,R=new b.Vector2(U,O),T=u/2+g,N=f/2+d,E=new b.Vector2(T,N),B=new b.Vector2(g,d);B.rotateByPoint(b.degToRad(p),E);const j=B.clone();j.rotateByPoint(b.degToRad(-p),R);const G=e-j.x,x=r-j.y;y.left=G,y.top=x,y.right=u-G-i,y.bottom=f-x-s}return{srcRect:P,srcRectAngle:y}}};_e=Pn([oe(0,h.ICommandService),oe(1,M.IDrawingManagerService),oe(2,b.IRenderManagerService),oe(3,h.IUniverInstanceService),oe(4,V.IMessageService),oe(5,h.Inject(h.LocaleService))],_e);var Dn=Object.getOwnPropertyDescriptor,Mn=(a,t,n,e)=>{for(var r=e>1?void 0:e?Dn(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},re=(a,t)=>(n,e)=>t(n,e,a);let Ie=class extends h.Disposable{constructor(a,t,n,e,r,s,i){super(),this._commandService=a,this._renderManagerService=t,this._drawingManagerService=n,this._dialogService=e,this._imageIoService=r,this._currentUniverService=s,this._drawingRenderService=i,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(a=>{if(a.id===be.id){const t=a.params;if(t==null)return;this._resetImageSize(t)}}))}_getSceneAndTransformerByDrawingSearch(a){if(a==null)return;const t=this._renderManagerService.getRenderById(a),n=t==null?void 0:t.scene;if(n==null)return null;const e=n.getTransformerByCreate();return{scene:n,transformer:e}}_resetImageSize(a){const t=[],n=[];a.forEach(e=>{const{unitId:r,subUnitId:s,drawingId:i}=e,o=this._getSceneAndTransformerByDrawingSearch(r);if(o==null)return;const{scene:c}=o,g=M.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:s,drawingId:i}),d=c.getObject(g);if(d==null)return!0;const u=this._drawingManagerService.getDrawingByParam(e);if(u==null)return!0;if(u.drawingType!==h.DrawingTypeEnum.DRAWING_IMAGE)return;d.resetSize();const{width:f,height:p}=d.getNativeSize();n.includes(c)===!1&&n.push(c),t.push({...u,transform:{...u.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(M.SetDrawingSelectedOperation.id,a)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(a=>{this._insertImages(a)}))}_insertImages(a){a.forEach(async t=>{var c;const{unitId:n,subUnitId:e}=t,r=this._getSceneAndTransformerByDrawingSearch(n),s=(c=Ne(this._currentUniverService,n))==null?void 0:c.subUnitId;if(r==null||s!==e)return;const i=this._drawingManagerService.getDrawingByParam(t);if(i==null)return;const o=await this._drawingRenderService.renderImages(i,r.scene);if(!(o==null||o.length===0))for(const g of o)this._addHoverForImage(g),this._addDialogForImage(g)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(a=>{a.forEach(t=>{const{unitId:n,subUnitId:e,drawingId:r}=t,s=this._drawingManagerService.getDrawingByParam(t);if(s==null)return;const{transform:i,drawingType:o,srcRect:c,prstGeom:g,source:d,imageSourceType:u}=s;if(o!==h.DrawingTypeEnum.DRAWING_IMAGE)return;const f=this._getSceneAndTransformerByDrawingSearch(n);if(f==null)return;const{scene:p,transformer:S}=f;if(i==null)return!0;const v=M.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:r}),C=p.getObject(v);if(C==null)return!0;C.setSrcRect(c),C.setPrstGeom(g),d!=null&&d.length>0&&(u===h.ImageSourceType.BASE64||u===h.ImageSourceType.URL)&&C.changeSource(d)})}))}_addHoverForImage(a){this.disposeWithMe(h.toDisposable(a.onPointerEnter$.subscribeEvent(()=>{a.cursor=b.CURSOR_TYPE.GRAB}))),this.disposeWithMe(h.toDisposable(a.onPointerLeave$.subscribeEvent(()=>{a.cursor=b.CURSOR_TYPE.DEFAULT})))}_addDialogForImage(a){this.disposeWithMe(h.toDisposable(a.onDblclick$.subscribeEvent(()=>{const t=`${a.oKey}-viewer-dialog`;this._drawingRenderService.previewImage(t,a.getNative().src,a.getNativeSize().width,a.getNativeSize().height)})))}};Ie=Mn([re(0,h.ICommandService),re(1,b.IRenderManagerService),re(2,M.IDrawingManagerService),re(3,V.IDialogService),re(4,M.IImageIoService),re(5,h.IUniverInstanceService),re(6,h.Inject(D.DrawingRenderService))],Ie);var On=Object.getOwnPropertyDescriptor,Nn=(a,t,n,e)=>{for(var r=e>1?void 0:e?On(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},Ke=(a,t)=>(n,e)=>t(n,e,a);const En="UNIVER_DRAWING_UI_PLUGIN";D.UniverDrawingUIPlugin=(Pe=class extends h.Plugin{constructor(t=$e,n,e){super(),this._config=t,this._injector=n,this._configService=e;const{menu:r,...s}=h.merge({},$e,this._config);r&&this._configService.setConfig("menu",r,{merge:!0}),this._configService.setConfig(wn,s)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(Se),this._injector.get(we),this._injector.get(_e),this._injector.get(Ie)}_initDependencies(){[[D.DrawingRenderService],[Se],[we],[_e],[Ie]].forEach(n=>this._injector.add(n))}},ee(Pe,"pluginName",En),Pe),D.UniverDrawingUIPlugin=Nn([Ke(1,h.Inject(h.Injector)),Ke(2,h.IConfigService)],D.UniverDrawingUIPlugin),D.AutoImageCropOperation=me,D.COMPONENT_IMAGE_POPUP_MENU=We,D.CloseImageCropOperation=ne,D.DrawingCommonPanel=Cn,D.ImageCropperObject=de,D.ImagePopupMenu=ke,D.ImageResetSizeOperation=be,D.OpenImageCropOperation=Ce,D.SetDrawingAlignOperation=fe,D.getUpdateParams=ge,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
6
+ `,{"univer-bg-gray-100":s,"univer-bg-white":!s}),children:[l.jsx(Ue,{style:{color:"#35322B"},extend:{colorChannel1:"rgb(var(--green-700, #409f11))"}}),p&&l.jsx(Le,{className:"univer-text-[10px] univer-text-gray-400"})]})})})},We="COMPONENT_IMAGE_POPUP_MENU",wn="drawing-ui.config",$e={},be={id:"sheet.operation.image-reset-size",type:h.CommandType.OPERATION,handler:(a,t)=>!0},vn=a=>{const{src:t}=a;return t?l.jsx("div",{children:l.jsx("img",{src:t,alt:"Univer Image Viewer",style:{width:"100%",height:"100%",position:"relative"}})}):null};var Sn=Object.getOwnPropertyDescriptor,_n=(a,t,n,e)=>{for(var r=e>1?void 0:e?Sn(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},ze=(a,t)=>(n,e)=>t(n,e,a);let we=class extends h.Disposable{constructor(a,t){super(),this._componentManager=a,this._commandService=t,this._init()}_initCustomComponents(){const a=this._componentManager;this.disposeWithMe(a.register(We,ke)),this.disposeWithMe(a.register(Ee,vn))}_initCommands(){[Ce,ne,be,fe,me].forEach(a=>this.disposeWithMe(this._commandService.registerCommand(a)))}_init(){this._initCommands(),this._initCustomComponents()}};we=_n([ze(0,h.Inject(V.ComponentManager)),ze(1,h.ICommandService)],we);var In=Object.getOwnPropertyDescriptor,yn=(a,t,n,e)=>{for(var r=e>1?void 0:e?In(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},ve=(a,t)=>(n,e)=>t(n,e,a);let Se=class extends h.Disposable{constructor(t,n,e,r){super();ee(this,"_sceneListenerOnDrawingMap",new WeakSet);this._currentUniverService=t,this._commandService=n,this._renderManagerService=e,this._drawingManagerService=r,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(){const t=this._drawingManagerService.drawingManagerData,n=Ne(this._currentUniverService);if(n==null)return;const{unitId:e,subUnitId:r}=n;Object.keys(t).forEach(s=>{Object.keys(t[s]).forEach(i=>{const o=t[s][i].data;o==null||s!==e||i!==r||Object.keys(o).forEach(c=>{o[c]&&this._insertDrawing([{unitId:s,subUnitId:i,drawingId:c}])})})})}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id===fe.id){const n=t.params;if(n==null)return;this._drawingAlign(n)}}))}_drawingGroupListener(){this.disposeWithMe(this._drawingManagerService.group$.subscribe(t=>{this._groupDrawings(t)})),this.disposeWithMe(this._drawingManagerService.ungroup$.subscribe(t=>{this._ungroupDrawings(t)}))}_getSceneAndTransformerByDrawingSearch(t){if(t==null)return;const n=this._renderManagerService.getRenderById(t),e=n==null?void 0:n.scene;if(e==null)return null;const r=e.getTransformerByCreate();return{scene:e,transformer:r}}_groupDrawings(t){t.forEach(n=>{this._groupDrawing(n)})}_groupDrawing(t){const{parent:n,children:e}=t,{unitId:r,subUnitId:s,drawingId:i}=n,o=this._getSceneAndTransformerByDrawingSearch(n.unitId);if(o==null)return;const{scene:c,transformer:g}=o;this._commandService.syncExecuteCommand(ne.id);const d=[];if(e.forEach(p=>{const S=M.getDrawingShapeKeyByDrawingSearch(p),v=c.getObjectIncludeInGroup(S);if(v==null||d.includes(v))return;d.push(v);const{transform:C}=p;C!=null&&(v.classType===b.RENDER_CLASS_TYPE.GROUP?v.transformByState({left:C.left,top:C.top}):v.transformByState(C))}),d.length===0)return;const u=M.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:s,drawingId:i}),f=new b.Group(u);c.addObject(f,b.DRAWING_OBJECT_LAYER_INDEX).attachTransformerTo(f),f.addObjects(...d),n.transform&&f.transformByState({left:n.transform.left,top:n.transform.top}),g.clearSelectedObjects(),g.setSelectedControl(f)}_ungroupDrawings(t){t.forEach(n=>{this._ungroupDrawing(n)})}_ungroupDrawing(t){const{parent:n,children:e}=t,r=this._getSceneAndTransformerByDrawingSearch(n.unitId);if(r==null)return;const{scene:s,transformer:i}=r;e.forEach(u=>{const f=M.getDrawingShapeKeyByDrawingSearch(u),p=s.getObjectIncludeInGroup(f);if(p==null)return!0;if(p==null)return;const{transform:S}=u;S!=null&&(p.classType===b.RENDER_CLASS_TYPE.GROUP?p.transformByState({left:S.left,top:S.top}):p.transformByState(S))});const o=M.getDrawingShapeKeyByDrawingSearch(n),c=s.getObject(o),{width:g,height:d}=c;c.getObjects().forEach(u=>{c.removeSelfObjectAndTransform(u.oKey,g,d)}),c.dispose(),i.clearSelectedObjects()}_drawingAlign(t){const{alignType:n}=t,e=this._drawingManagerService.getFocusDrawings();if(n===A.default)return;const r=[];let s=Number.POSITIVE_INFINITY,i=Number.POSITIVE_INFINITY,o=Number.NEGATIVE_INFINITY,c=Number.NEGATIVE_INFINITY,g=0;e.forEach(d=>{const{unitId:u,subUnitId:f,drawingId:p,drawingType:S}=d,v=this._drawingManagerService.getDrawingByParam({unitId:u,subUnitId:f,drawingId:p});if(v==null||v.transform==null)return;r.push({unitId:u,subUnitId:f,drawingId:p,drawingType:S,transform:v.transform});const{left:C=0,top:P=0,width:y=0,height:U=0}=v.transform;s=Math.min(s,C),i=Math.min(i,P),o=Math.max(o,C+y),c=Math.max(c,P+U),g++}),g!==0&&(this._sortDrawingTransform(r,n),this._applyAlignType(r,n,s,i,o,c,g))}_applyAlignType(t,n,e,r,s,i,o){const c=Math.round((s-e)/o*10)/10,g=Math.round((i-r)/o*10)/10,d=[],u=this._getSceneAndTransformerByDrawingSearch(t[0].unitId);if(u==null)return;const{scene:f,transformer:p}=u;t.forEach((S,v)=>{const{unitId:C,subUnitId:P,drawingId:y,transform:U,drawingType:O}=S,{left:R=0,top:T=0,width:N=0,height:E=0}=U;let B=R,j=T;switch(n){case A.left:B=e;break;case A.center:B=e+(s-e)/2-N/2;break;case A.right:B=s-N;break;case A.top:j=r;break;case A.middle:j=r+(i-r)/2-E/2;break;case A.bottom:j=i-E;break;case A.horizon:B=e+c*v;break;case A.vertical:j=r+g*v;break}(B!==R||j!==T)&&d.push({unitId:C,subUnitId:P,drawingId:y,drawingType:O,transform:{left:B,top:j}})}),this._drawingManagerService.featurePluginUpdateNotification(d),p.refreshControls().changeNotification()}_sortDrawingTransform(t,n){t.sort((e,r)=>{const s=e.transform,i=r.transform,{left:o=0,top:c=0,width:g=0,height:d=0}=s,{left:u=0,top:f=0,width:p=0,height:S=0}=i;switch(n){case A.left:return o-u;case A.center:return o+g/2-(u+p/2);case A.right:return o+g-(u+p);case A.top:return c-f;case A.middle:return c+d/2-(f+S/2);case A.bottom:return c+d-(f+S);case A.horizon:return o+g/2-(u+p/2);case A.vertical:return c+d/2-(f+S/2);default:return 0}})}_drawingArrangeListener(){this.disposeWithMe(this._drawingManagerService.order$.subscribe(t=>{this._drawingArrange(t)}))}_drawingArrange(t){const{unitId:n,subUnitId:e,drawingIds:r}=t,s=this._getSceneAndTransformerByDrawingSearch(n);if(s==null)return;const{scene:i}=s;r.forEach(o=>{const c=M.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:o}),g=i.fuzzyMathObjects(c,!0);if(g==null||g.length===0)return;const d=this._drawingManagerService.getDrawingOrder(n,e).indexOf(o);for(const u of g)u.setProps({zIndex:d}),u.makeDirty()})}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(t=>{this._insertDrawing(t)}))}_insertDrawing(t){const n=[];t.forEach(e=>{const{unitId:r}=e;if(this._drawingManagerService.getDrawingByParam(e)==null)return;const i=this._getSceneAndTransformerByDrawingSearch(r);if(i==null)return;const{scene:o}=i;n.includes(o)||n.push(o)}),n.forEach(e=>{this._sceneListenerOnDrawingMap.has(e)||(this._addListenerOnDrawing(e),this._sceneListenerOnDrawingMap.add(e))})}_drawingRemoveListener(){this.disposeWithMe(this._drawingManagerService.remove$.subscribe(t=>{t.forEach(n=>{var d;const{unitId:e,subUnitId:r,drawingId:s}=n,i=this._getSceneAndTransformerByDrawingSearch(e);if(i==null)return;const{scene:o}=i,c=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),g=o.fuzzyMathObjects(c,!0);if(g.length>0){for(const u of g)u.dispose();(d=o.getTransformer())==null||d.clearSelectedObjects()}})}))}_drawingUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(t=>{t.forEach(n=>{var N;const{unitId:e,subUnitId:r,drawingId:s}=n,i=this._drawingManagerService.getDrawingByParam(n);if(i==null)return;const{transform:o,drawingType:c}=i,g=this._getSceneAndTransformerByDrawingSearch(e);if(g==null)return;const{scene:d,transformer:u}=g;if(o==null)return!0;const{left:f=0,top:p=0,width:S=0,height:v=0,angle:C=0,flipX:P=!1,flipY:y=!1,skewX:U=0,skewY:O=0}=o,R=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),T=d.getObject(R);if(T==null)return!0;T.transformByState({left:f,top:p,width:S,height:v,angle:C,flipX:P,flipY:y,skewX:U,skewY:O}),(N=d.getTransformer())==null||N.debounceRefreshControls()})}))}_drawingRefreshListener(){this.disposeWithMe(this._drawingManagerService.refreshTransform$.subscribe(t=>{t.forEach(n=>{const{unitId:e,subUnitId:r,drawingId:s}=n,i=this._getSceneAndTransformerByDrawingSearch(e);if(i==null)return;const o=this._drawingManagerService.getDrawingByParam(n);if(o==null)return;const{transform:c}=o,{scene:g}=i,d=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),u=g.getObject(d);if(u==null||c==null)return!0;const{left:f=0,top:p=0,width:S=0,height:v=0,angle:C=0,flipX:P=!1,flipY:y=!1,skewX:U=0,skewY:O=0}=c;u.transformByState({left:f,top:p,width:S,height:v,angle:C,flipX:P,flipY:y,skewX:U,skewY:O})})}))}_drawingVisibleListener(){this.disposeWithMe(this._drawingManagerService.visible$.subscribe(t=>{t.forEach(n=>{const{unitId:e,subUnitId:r,drawingId:s,visible:i}=n,o=this._getSceneAndTransformerByDrawingSearch(e);if(o==null)return;const{scene:c}=o,g=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),d=c.getObject(g);if(d==null)return!0;i?d.show():d.hide()})}))}_filterUpdateParams(t,n){return t.filter((e,r)=>{if(e==null)return!1;const{transform:s}=e;return h.checkIfMove(s,n==null?void 0:n[r])})}_addListenerOnDrawing(t){const n=t.getTransformerByCreate();let e=null;this.disposeWithMe(h.toDisposable(n.changeStart$.subscribe(r=>{const{objects:s}=r,i=Array.from(s.values()),o=[];e=i.map(c=>{const{left:g,top:d,height:u,width:f,angle:p,oKey:S,isInGroup:v}=c,C=this._drawingManagerService.getDrawingOKey(S);if(v||c instanceof b.Group){let P=c.ancestorGroup;if(P==null&&c instanceof b.Group&&(P=c),P==null)return null;const y=this._drawingManagerService.getDrawingOKey(P.oKey);if(y){const{unitId:U,subUnitId:O,drawingId:R}=y;o.push({unitId:U,subUnitId:O,drawingId:R});const{left:T,top:N,height:E,width:B,angle:j}=P;return{left:T,top:N,height:E,width:B,angle:j}}}else if(C!=null){const{unitId:P,subUnitId:y,drawingId:U}=C;return o.push({unitId:P,subUnitId:y,drawingId:U}),{left:g,top:d,height:u,width:f,angle:p}}return null}).filter(c=>c!=null),o.length>0?this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,o):this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,[])}))),this.disposeWithMe(h.toDisposable(n.changeEnd$.subscribe(r=>{const{objects:s}=r,i=this._filterUpdateParams(ge(s,this._drawingManagerService),e);i.length>0&&this._drawingManagerService.featurePluginUpdateNotification(i)})))}};Se=yn([ve(0,h.IUniverInstanceService),ve(1,h.ICommandService),ve(2,b.IRenderManagerService),ve(3,M.IDrawingManagerService)],Se);class de extends b.Shape{constructor(n,e){e==null&&(e={}),e.transformerConfig={keepRatio:!1,isCropper:!0,anchorFill:"rgb(0, 0, 0)",anchorStroke:"rgb(255, 255, 255)",anchorSize:24};super(n,e);ee(this,"_srcRect");ee(this,"_prstGeom");ee(this,"_applyTransform");ee(this,"_dragPadding",8);ee(this,"_cacheCanvas");e!=null&&e.srcRect&&(this._srcRect=e.srcRect),e!=null&&e.prstGeom&&(this._prstGeom=e.prstGeom),e!=null&&e.applyTransform&&(this._applyTransform=e.applyTransform),e!=null&&e.dragPadding&&(this._dragPadding=e.dragPadding),this._applyProps()}refreshSrcRect(n,e){this._srcRect=n,this._applyTransform=e,this._applyProps()}get srcRect(){return this._srcRect}dispose(){var n;super.dispose(),(n=this._cacheCanvas)==null||n.dispose(),this._srcRect=null}isHit(n){const e=this.getInverseCoord(n);return e.x>=-this.strokeWidth/2&&e.x<=this.width+this.strokeWidth/2&&e.y>=-this.strokeWidth/2&&e.y<=this.height+this.strokeWidth/2&&!this._inSurround(e)}_inSurround(n){const e=this._dragPadding;return n.x>=e-this.strokeWidth/2&&n.x<=this.width+this.strokeWidth/2-e&&n.y>=e-this.strokeWidth/2&&n.y<=this.height+this.strokeWidth/2-e}render(n,e){return this.visible?(n.save(),this._draw(n),n.restore(),this.makeDirty(!1),this):(this.makeDirty(!1),this)}_draw(n){var c,g;const r=this.getScene().getEngine(),{width:s,height:i}=r;this._initialCacheCanvas(),(c=this._cacheCanvas)==null||c.clear();const o=(g=this._cacheCanvas)==null?void 0:g.getContext();o!=null&&(o.save(),b.Rect.drawWith(o,{left:0,top:0,width:s,height:i,fill:"rgba(0, 0, 0, 0.5)"}),o.setTransform(n.getTransform()),this._clipForApplyObject(o),this._applyCache(n),o.restore())}_clipForApplyObject(n){let e=0;if(this._prstGeom!=null&&(e=1),n.globalCompositeOperation="destination-out",n.beginPath(),e===0){const r=this.transform.getMatrix();n.transform(r[0],r[1],r[2],r[3],r[4],r[5]),n.rect(0,0,this.width,this.height),n.fill()}}_applyProps(){if(this._applyTransform==null)return;let n=0,e=0,r=0,s=0;const{left:i=0,top:o=0,width:c=0,height:g=0,angle:d}=this._applyTransform;if(this._srcRect!=null){const{left:p=0,top:S=0,right:v=0,bottom:C=0}=this._srcRect;n=p,e=S,r=v,s=C}const u=i+n,f=o+e;this.transformByState({left:u,top:f,width:i+c-r-u,height:o+g-s-f,angle:d})}_applyCache(n){if(!n||this._cacheCanvas==null)return;const e=this._cacheCanvas.getContext();e.save(),n.save(),n.setTransform(1,0,0,1,0,0),e.setTransform(1,0,0,1,0,0),n.drawImage(this._cacheCanvas.getCanvasEle(),0,0),n.restore(),e.restore()}_initialCacheCanvas(){if(this._cacheCanvas!=null)return;const n=this.getScene();if(n==null)return;this._cacheCanvas=new b.Canvas;const e=n.getEngine();this._cacheCanvas.setSize(e.width,e.height),e.onTransformChange$.subscribeEvent(()=>{var r;(r=this._cacheCanvas)==null||r.setSize(e.width,e.height),this.makeDirty(!0)})}}var bn=Object.getOwnPropertyDescriptor,Pn=(a,t,n,e)=>{for(var r=e>1?void 0:e?bn(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},oe=(a,t)=>(n,e)=>t(n,e,a);let _e=class extends h.Disposable{constructor(t,n,e,r,s,i){super();ee(this,"_sceneListenerOnImageMap",new WeakSet);this._commandService=t,this._drawingManagerService=n,this._renderManagerService=e,this._univerInstanceService=r,this._messageService=s,this._localeService=i,this._init()}_init(){this._initOpenCrop(),this._initCloseCrop(),this._initAutoCrop()}_initAutoCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id!==me.id)return;const n=t.params;if(n==null)return;const{cropType:e}=n,r=this._drawingManagerService.getFocusDrawings();if(r.length!==1)return;const s=r[0],{unitId:i,subUnitId:o,drawingId:c}=s,g=this._renderManagerService.getRenderById(i),d=g==null?void 0:g.scene;if(d==null)return!0;this._searchCropObject(d)!=null&&this._commandService.syncExecuteCommand(ne.id,{isAuto:!0});const f=M.getDrawingShapeKeyByDrawingSearch({unitId:i,subUnitId:o,drawingId:c}),p=d.getObject(f);if(!(p instanceof b.Image)){this._messageService.show({type:I.MessageType.Error,content:this._localeService.t("image-cropper.error")});return}p!=null&&(this._updateCropperObject(e,p),this._commandService.executeCommand(Ce.id,{unitId:i,subUnitId:o,drawingId:c}))}))}_calculateSrcRectByRatio(t,n,e,r,s,i){const o=e/r,c=s/i;let g=e,d=r;o>c?g=r*c:d=e/c;const u=(e-g)/2,f=(r-d)/2;return{left:b.precisionTo(u,1),top:b.precisionTo(f,1),right:b.precisionTo(e-(u+g),1),bottom:b.precisionTo(r-(f+d),1)}}_updateCropperObject(t,n){const{left:e,top:r,width:s,height:i}=n.calculateTransformWithSrcRect();let o;switch(t){case H.R1_1:o=this._calculateSrcRectByRatio(e,r,s,i,1,1);break;case H.R16_9:o=this._calculateSrcRectByRatio(e,r,s,i,16,9);break;case H.R9_16:o=this._calculateSrcRectByRatio(e,r,s,i,9,16);break;case H.R5_4:o=this._calculateSrcRectByRatio(e,r,s,i,5,4);break;case H.R4_5:o=this._calculateSrcRectByRatio(e,r,s,i,4,5);break;case H.R4_3:o=this._calculateSrcRectByRatio(e,r,s,i,4,3);break;case H.R3_4:o=this._calculateSrcRectByRatio(e,r,s,i,3,4);break;case H.R3_2:o=this._calculateSrcRectByRatio(e,r,s,i,3,2);break;case H.R2_3:o=this._calculateSrcRectByRatio(e,r,s,i,2,3);break;case H.FREE:}if(o==null)return;n.setSrcRect(o);const{left:c=0,top:g=0,bottom:d=0,right:u=0}=o;n.transformByStateCloseCropper({left:e+c,top:r+g,width:s-u-c,height:i-d-g})}_initOpenCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.id!==Ce.id)return;const n=t.params;if(n==null)return;const{unitId:e,subUnitId:r,drawingId:s}=n,i=this._renderManagerService.getRenderById(e),o=i==null?void 0:i.scene;if(o==null)return!0;if(this._sceneListenerOnImageMap.has(o)||(this._addListenerOnImage(o),this._sceneListenerOnImageMap.add(o)),this._drawingManagerService.getDrawingByParam({unitId:e,subUnitId:r,drawingId:s})==null)return;const g=M.getDrawingShapeKeyByDrawingSearch({unitId:e,subUnitId:r,drawingId:s}),d=o.getObject(g);if(d==null)return;if(!(d instanceof b.Image)){this._messageService.show({type:I.MessageType.Error,content:this._localeService.t("image-cropper.error")});return}const u=o.getTransformer();u==null||u.clearControls();const f=new de(`${g}-crop`,{srcRect:d.srcRect,prstGeom:d.prstGeom,applyTransform:d.calculateTransformWithSrcRect()});o.addObject(f,d.getLayerIndex()+1).attachTransformerTo(f),u==null||u.createControlForCopper(f),this._addHoverForImageCopper(f),d.openRenderByCropper(),u==null||u.refreshControls(),f.makeDirty(!0),this._commandService.syncExecuteCommand(M.SetDrawingSelectedOperation.id,[{unitId:e,subUnitId:r,drawingId:s}])}))}_searchCropObject(t){const n=t.getAllObjectsByOrder();for(const e of n)if(e instanceof de)return e}_initCloseCrop(){this.disposeWithMe(this._commandService.onCommandExecuted(n=>{if(n.id!==ne.id)return;const e=this._univerInstanceService.getFocusedUnit();if(e==null)return;const r=e.getUnitId(),s=this._renderManagerService.getRenderById(r),i=s==null?void 0:s.scene;if(i==null)return!0;const o=this._searchCropObject(i);if(o==null)return;const c=this._getApplyObjectByCropObject(o);if(c==null)return;const g=i.getTransformerByCreate();g.detachFrom(o),g.clearCopperControl();const d=this._getSrcRectByTransformState(c,o),u=this._drawingManagerService.getDrawingOKey(c.oKey);if(u!=null){const{left:f,top:p,height:S,width:v}=o;this._drawingManagerService.featurePluginUpdateNotification([{...u,transform:{...u.transform,left:f,top:p,height:S,width:v},srcRect:d.srcRectAngle}])}c.setSrcRect({...d.srcRectAngle}),c.closeRenderByCropper(),c.makeDirty(!0),o==null||o.dispose()}));const t=this._univerInstanceService.getCurrentTypeOfUnit$(h.UniverInstanceType.UNIVER_SHEET).pipe(Me.switchMap(n=>n?n.activeSheet$:Me.of(null)));this.disposeWithMe(t.subscribe(()=>{this._commandService.syncExecuteCommand(ne.id)}))}_getApplyObjectByCropObject(t){const n=t.oKey,e=n.slice(0,n.length-5),r=t.getScene();if(!r)return null;const s=r.getObject(e);return s==null?null:s}_addListenerOnImage(t){const n=t.getTransformerByCreate();let e=null;this.disposeWithMe(n.changeStart$.subscribe(r=>{const{objects:s}=r,i=s.values().next().value;if(i==null||!(i instanceof de))return;const{left:o,top:c,height:g,width:d,angle:u}=i;e={left:o,top:c,height:g,width:d,angle:u},n.clearCopperControl()})),this.disposeWithMe(n.changeEnd$.subscribe(r=>{const{objects:s}=r,i=s.values().next().value;if(i==null||!(i instanceof de))return;const{left:o,top:c,height:g,width:d,angle:u}=i;if(!h.checkIfMove({left:o,top:c,height:g,width:d,angle:u},e))return;const f=this._getApplyObjectByCropObject(i);if(f==null)return;const p=this._getSrcRectByTransformState(f,i);i.refreshSrcRect(p.srcRect,f.getState()),n.createControlForCopper(i)})),this._endCropListener(t)}_addHoverForImageCopper(t){this.disposeWithMe(t.onPointerEnter$.subscribeEvent(()=>{t.cursor=b.CURSOR_TYPE.MOVE})),this.disposeWithMe(t.onPointerLeave$.subscribeEvent(()=>{t.cursor=b.CURSOR_TYPE.DEFAULT}))}_endCropListener(t){const n=t.getTransformerByCreate();this.disposeWithMe(n.clearControl$.subscribe(e=>{e===!0&&this._commandService.syncExecuteCommand(ne.id)}))}_getSrcRectByTransformState(t,n){const{left:e,top:r,height:s,width:i,strokeWidth:o,angle:c}=n,{left:g,top:d,width:u,height:f,angle:p,strokeWidth:S}=t,v=e-g,C=r-d,P={left:v,top:C,right:u-v-i,bottom:f-C-s},y={...P};if(p!==0){const U=e+i/2,O=r+s/2,R=new b.Vector2(U,O),T=u/2+g,N=f/2+d,E=new b.Vector2(T,N),B=new b.Vector2(g,d);B.rotateByPoint(b.degToRad(p),E);const j=B.clone();j.rotateByPoint(b.degToRad(-p),R);const G=e-j.x,x=r-j.y;y.left=G,y.top=x,y.right=u-G-i,y.bottom=f-x-s}return{srcRect:P,srcRectAngle:y}}};_e=Pn([oe(0,h.ICommandService),oe(1,M.IDrawingManagerService),oe(2,b.IRenderManagerService),oe(3,h.IUniverInstanceService),oe(4,V.IMessageService),oe(5,h.Inject(h.LocaleService))],_e);var Dn=Object.getOwnPropertyDescriptor,Mn=(a,t,n,e)=>{for(var r=e>1?void 0:e?Dn(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},re=(a,t)=>(n,e)=>t(n,e,a);let Ie=class extends h.Disposable{constructor(a,t,n,e,r,s,i){super(),this._commandService=a,this._renderManagerService=t,this._drawingManagerService=n,this._dialogService=e,this._imageIoService=r,this._currentUniverService=s,this._drawingRenderService=i,this._initialize()}dispose(){super.dispose()}_initialize(){this._drawingAddListener(),this._commandExecutedListener(),this._imageUpdateListener()}_commandExecutedListener(){this.disposeWithMe(this._commandService.onCommandExecuted(a=>{if(a.id===be.id){const t=a.params;if(t==null)return;this._resetImageSize(t)}}))}_getSceneAndTransformerByDrawingSearch(a){if(a==null)return;const t=this._renderManagerService.getRenderById(a),n=t==null?void 0:t.scene;if(n==null)return null;const e=n.getTransformerByCreate();return{scene:n,transformer:e}}_resetImageSize(a){const t=[],n=[];a.forEach(e=>{const{unitId:r,subUnitId:s,drawingId:i}=e,o=this._getSceneAndTransformerByDrawingSearch(r);if(o==null)return;const{scene:c}=o,g=M.getDrawingShapeKeyByDrawingSearch({unitId:r,subUnitId:s,drawingId:i}),d=c.getObject(g);if(d==null)return!0;const u=this._drawingManagerService.getDrawingByParam(e);if(u==null)return!0;if(u.drawingType!==h.DrawingTypeEnum.DRAWING_IMAGE)return;d.resetSize();const{width:f,height:p}=d.getNativeSize();n.includes(c)===!1&&n.push(c),t.push({...u,transform:{...u.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(M.SetDrawingSelectedOperation.id,a)}_drawingAddListener(){this.disposeWithMe(this._drawingManagerService.add$.subscribe(a=>{this._insertImages(a)}))}_insertImages(a){a.forEach(async t=>{var c;const{unitId:n,subUnitId:e}=t,r=this._getSceneAndTransformerByDrawingSearch(n),s=(c=Ne(this._currentUniverService,n))==null?void 0:c.subUnitId;if(r==null||s!==e)return;const i=this._drawingManagerService.getDrawingByParam(t);if(i==null)return;const o=await this._drawingRenderService.renderImages(i,r.scene);if(this._drawingManagerService.refreshTransform([i]),!(o==null||o.length===0))for(const g of o)this._addHoverForImage(g),this._addDialogForImage(g)})}_imageUpdateListener(){this.disposeWithMe(this._drawingManagerService.update$.subscribe(a=>{a.forEach(t=>{const{unitId:n,subUnitId:e,drawingId:r}=t,s=this._drawingManagerService.getDrawingByParam(t);if(s==null)return;const{transform:i,drawingType:o,srcRect:c,prstGeom:g,source:d,imageSourceType:u}=s;if(o!==h.DrawingTypeEnum.DRAWING_IMAGE)return;const f=this._getSceneAndTransformerByDrawingSearch(n);if(f==null)return;const{scene:p,transformer:S}=f;if(i==null)return!0;const v=M.getDrawingShapeKeyByDrawingSearch({unitId:n,subUnitId:e,drawingId:r}),C=p.getObject(v);if(C==null)return!0;C.setSrcRect(c),C.setPrstGeom(g),d!=null&&d.length>0&&(u===h.ImageSourceType.BASE64||u===h.ImageSourceType.URL)&&C.changeSource(d)})}))}_addHoverForImage(a){this.disposeWithMe(h.toDisposable(a.onPointerEnter$.subscribeEvent(()=>{a.cursor=b.CURSOR_TYPE.GRAB}))),this.disposeWithMe(h.toDisposable(a.onPointerLeave$.subscribeEvent(()=>{a.cursor=b.CURSOR_TYPE.DEFAULT})))}_addDialogForImage(a){this.disposeWithMe(h.toDisposable(a.onDblclick$.subscribeEvent(()=>{const t=`${a.oKey}-viewer-dialog`;this._drawingRenderService.previewImage(t,a.getNative().src,a.getNativeSize().width,a.getNativeSize().height)})))}};Ie=Mn([re(0,h.ICommandService),re(1,b.IRenderManagerService),re(2,M.IDrawingManagerService),re(3,V.IDialogService),re(4,M.IImageIoService),re(5,h.IUniverInstanceService),re(6,h.Inject(D.DrawingRenderService))],Ie);var On=Object.getOwnPropertyDescriptor,Nn=(a,t,n,e)=>{for(var r=e>1?void 0:e?On(t,n):t,s=a.length-1,i;s>=0;s--)(i=a[s])&&(r=i(r)||r);return r},Ke=(a,t)=>(n,e)=>t(n,e,a);const En="UNIVER_DRAWING_UI_PLUGIN";D.UniverDrawingUIPlugin=(Pe=class extends h.Plugin{constructor(t=$e,n,e){super(),this._config=t,this._injector=n,this._configService=e;const{menu:r,...s}=h.merge({},$e,this._config);r&&this._configService.setConfig("menu",r,{merge:!0}),this._configService.setConfig(wn,s)}onStarting(){this._initDependencies()}onRendered(){this._injector.get(Se),this._injector.get(we),this._injector.get(_e),this._injector.get(Ie)}_initDependencies(){[[D.DrawingRenderService],[Se],[we],[_e],[Ie]].forEach(n=>this._injector.add(n))}},ee(Pe,"pluginName",En),Pe),D.UniverDrawingUIPlugin=Nn([Ke(1,h.Inject(h.Injector)),Ke(2,h.IConfigService)],D.UniverDrawingUIPlugin),D.AutoImageCropOperation=me,D.COMPONENT_IMAGE_POPUP_MENU=We,D.CloseImageCropOperation=ne,D.DrawingCommonPanel=Cn,D.ImageCropperObject=de,D.ImagePopupMenu=ke,D.ImageResetSizeOperation=be,D.OpenImageCropOperation=Ce,D.SetDrawingAlignOperation=fe,D.getUpdateParams=ge,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
7
7
 
8
8
 
9
9
  // @univerjs/docs-drawing/index
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@univerjs/preset-docs-drawing",
3
- "version": "0.6.10-nightly.202504101607",
3
+ "version": "0.6.10-nightly.202504121606",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "author": "DreamNum <developer@univer.ai>",
@@ -57,13 +57,13 @@
57
57
  "rxjs": ">=7.0.0"
58
58
  },
59
59
  "dependencies": {
60
- "@univerjs/docs-drawing": "0.6.10-nightly.202504101607",
61
- "@univerjs/docs-drawing-ui": "0.6.10-nightly.202504101607",
62
- "@univerjs/drawing": "0.6.10-nightly.202504101607",
63
- "@univerjs/drawing-ui": "0.6.10-nightly.202504101607"
60
+ "@univerjs/docs-drawing": "0.6.10-nightly.202504121606",
61
+ "@univerjs/docs-drawing-ui": "0.6.10-nightly.202504121606",
62
+ "@univerjs/drawing": "0.6.10-nightly.202504121606",
63
+ "@univerjs/drawing-ui": "0.6.10-nightly.202504121606"
64
64
  },
65
65
  "devDependencies": {
66
- "@univerjs/core": "0.6.10-nightly.202504101607",
66
+ "@univerjs/core": "0.6.10-nightly.202504121606",
67
67
  "react": "18.3.1",
68
68
  "react-dom": "18.3.1",
69
69
  "typescript": "^5.8.2",