@@ -24,6 +24,11 @@ export interface DDResizableOpt {
2424 resize ?: ( event : Event , ui : DDUIData ) => void ;
2525}
2626
27+ interface RectScaleReciprocal {
28+ x : number ;
29+ y : number ;
30+ }
31+
2732export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt < DDResizableOpt > {
2833
2934 // have to be public else complains for HTMLElementExtendOpt ?
@@ -35,6 +40,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
3540 /** @internal */
3641 protected originalRect : Rect ;
3742 /** @internal */
43+ protected rectScale : RectScaleReciprocal = { x : 1 , y : 1 } ;
44+ /** @internal */
3845 protected temporalRect : Rect ;
3946 /** @internal */
4047 protected scrollY : number ;
@@ -217,6 +224,26 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
217224 protected _setupHelper ( ) : DDResizable {
218225 this . elOriginStyleVal = DDResizable . _originStyleProp . map ( prop => this . el . style [ prop ] ) ;
219226 this . parentOriginStylePosition = this . el . parentElement . style . position ;
227+
228+ const parent = this . el . parentElement ;
229+ const testEl = document . createElement ( 'div' ) ;
230+ Utils . addElStyles ( testEl , {
231+ opacity : '0' ,
232+ position : 'fixed' ,
233+ top : 0 + 'px' ,
234+ left : 0 + 'px' ,
235+ width : '1px' ,
236+ height : '1px' ,
237+ zIndex : '-999999' ,
238+ } ) ;
239+ parent . appendChild ( testEl ) ;
240+ const testElPosition = testEl . getBoundingClientRect ( ) ;
241+ parent . removeChild ( testEl ) ;
242+ this . rectScale = {
243+ x : 1 / testElPosition . width ,
244+ y : 1 / testElPosition . height
245+ } ;
246+
220247 if ( getComputedStyle ( this . el . parentElement ) . position . match ( / s t a t i c / ) ) {
221248 this . el . parentElement . style . position = 'relative' ;
222249 }
@@ -278,9 +305,9 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
278305 /** @internal constrain the size to the set min/max values */
279306 protected _constrainSize ( oWidth : number , oHeight : number ) : Size {
280307 const maxWidth = this . option . maxWidth || Number . MAX_SAFE_INTEGER ;
281- const minWidth = this . option . minWidth || oWidth ;
308+ const minWidth = this . option . minWidth / this . rectScale . x || oWidth ;
282309 const maxHeight = this . option . maxHeight || Number . MAX_SAFE_INTEGER ;
283- const minHeight = this . option . minHeight || oHeight ;
310+ const minHeight = this . option . minHeight / this . rectScale . y || oHeight ;
284311 const width = Math . min ( maxWidth , Math . max ( minWidth , oWidth ) ) ;
285312 const height = Math . min ( maxHeight , Math . max ( minHeight , oHeight ) ) ;
286313 return { width, height } ;
@@ -297,7 +324,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
297324 if ( ! this . temporalRect ) return this ;
298325 Object . keys ( this . temporalRect ) . forEach ( key => {
299326 const value = this . temporalRect [ key ] ;
300- this . el . style [ key ] = value - containmentRect [ key ] + 'px' ;
327+ const scaleReciprocal = key === 'width' || key === 'left' ? this . rectScale . x : key === 'height' || key === 'top' ? this . rectScale . y : 1 ;
328+ this . el . style [ key ] = ( value - containmentRect [ key ] ) * scaleReciprocal + 'px' ;
301329 } ) ;
302330 return this ;
303331 }
@@ -322,12 +350,12 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
322350 const rect = this . temporalRect || newRect ;
323351 return {
324352 position : {
325- left : rect . left - containmentRect . left ,
326- top : rect . top - containmentRect . top
353+ left : ( rect . left - containmentRect . left ) * this . rectScale . x ,
354+ top : ( rect . top - containmentRect . top ) * this . rectScale . y
327355 } ,
328356 size : {
329- width : rect . width ,
330- height : rect . height
357+ width : rect . width * this . rectScale . x ,
358+ height : rect . height * this . rectScale . y
331359 }
332360 /* Gridstack ONLY needs position set above... keep around in case.
333361 element: [this.el], // The object representing the element to be resized
0 commit comments