@@ -27,7 +27,6 @@ class WorkspacePlugin implements IPluginTempl {
2727 workspaceEl ! : HTMLElement ;
2828 workspace : null | fabric . Rect ;
2929 resizeObserver ! : ResizeObserver ;
30- coverMask : null | fabric . Rect = null ;
3130 option : any ;
3231 zoomRatio : number ;
3332 constructor ( public canvas : fabric . Canvas , public editor : IEditor ) {
@@ -61,6 +60,7 @@ class WorkspacePlugin implements IPluginTempl {
6160 workspace . set ( 'hasControls' , false ) ;
6261 workspace . set ( 'evented' , false ) ;
6362 this . setSize ( workspace . width , workspace . height ) ;
63+ this . editor . emit ( 'sizeChange' , workspace . width , workspace . height ) ;
6464 }
6565 resolve ( '' ) ;
6666 } ) ;
@@ -159,8 +159,12 @@ class WorkspacePlugin implements IPluginTempl {
159159 this . canvas . zoomToPoint ( new fabric . Point ( center . left , center . top ) , scale ) ;
160160 if ( ! this . workspace ) return ;
161161 this . setCenterFromObject ( this . workspace ) ;
162- this . editor . getPlugin ( 'MaskPlugin' ) && this . editor ?. setCoverMask ( true ) ;
163162
163+ // 超出画布不展示
164+ this . workspace . clone ( ( cloned : fabric . Rect ) => {
165+ this . canvas . clipPath = cloned ;
166+ this . canvas . requestRenderAll ( ) ;
167+ } ) ;
164168 if ( cb ) cb ( this . workspace . left , this . workspace . top ) ;
165169 }
166170
@@ -208,17 +212,14 @@ class WorkspacePlugin implements IPluginTempl {
208212 }
209213
210214 _bindWheel ( ) {
211- this . canvas . on ( 'mouse:wheel' , ( opt ) => {
215+ this . canvas . on ( 'mouse:wheel' , function ( this : fabric . Canvas , opt ) {
212216 const delta = opt . e . deltaY ;
213- let zoom = this . canvas . getZoom ( ) ;
217+ let zoom = this . getZoom ( ) ;
214218 zoom *= 0.999 ** delta ;
215219 if ( zoom > 20 ) zoom = 20 ;
216220 if ( zoom < 0.01 ) zoom = 0.01 ;
217- const center = this . canvas . getCenter ( ) ;
218- this . canvas . zoomToPoint ( new fabric . Point ( center . left , center . top ) , zoom ) ;
219-
220- this . editor . getPlugin ( 'MaskPlugin' ) && this . editor ?. setCoverMask ( true ) ;
221-
221+ const center = this . getCenter ( ) ;
222+ this . zoomToPoint ( new fabric . Point ( center . left , center . top ) , zoom ) ;
222223 opt . e . preventDefault ( ) ;
223224 opt . e . stopPropagation ( ) ;
224225 } ) ;
0 commit comments