@@ -24,6 +24,11 @@ export interface DDResizableOpt {
24
24
resize ?: ( event : Event , ui : DDUIData ) => void ;
25
25
}
26
26
27
+ interface RectScaleReciprocal {
28
+ x : number ;
29
+ y : number ;
30
+ }
31
+
27
32
export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt < DDResizableOpt > {
28
33
29
34
// have to be public else complains for HTMLElementExtendOpt ?
@@ -35,6 +40,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
35
40
/** @internal */
36
41
protected originalRect : Rect ;
37
42
/** @internal */
43
+ protected rectScale : RectScaleReciprocal = { x : 1 , y : 1 } ;
44
+ /** @internal */
38
45
protected temporalRect : Rect ;
39
46
/** @internal */
40
47
protected scrollY : number ;
@@ -217,6 +224,26 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
217
224
protected _setupHelper ( ) : DDResizable {
218
225
this . elOriginStyleVal = DDResizable . _originStyleProp . map ( prop => this . el . style [ prop ] ) ;
219
226
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
+
220
247
if ( getComputedStyle ( this . el . parentElement ) . position . match ( / s t a t i c / ) ) {
221
248
this . el . parentElement . style . position = 'relative' ;
222
249
}
@@ -278,9 +305,9 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
278
305
/** @internal constrain the size to the set min/max values */
279
306
protected _constrainSize ( oWidth : number , oHeight : number ) : Size {
280
307
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 ;
282
309
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 ;
284
311
const width = Math . min ( maxWidth , Math . max ( minWidth , oWidth ) ) ;
285
312
const height = Math . min ( maxHeight , Math . max ( minHeight , oHeight ) ) ;
286
313
return { width, height } ;
@@ -297,7 +324,8 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
297
324
if ( ! this . temporalRect ) return this ;
298
325
Object . keys ( this . temporalRect ) . forEach ( key => {
299
326
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' ;
301
329
} ) ;
302
330
return this ;
303
331
}
@@ -322,12 +350,12 @@ export class DDResizable extends DDBaseImplement implements HTMLElementExtendOpt
322
350
const rect = this . temporalRect || newRect ;
323
351
return {
324
352
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
327
355
} ,
328
356
size : {
329
- width : rect . width ,
330
- height : rect . height
357
+ width : rect . width * this . rectScale . x ,
358
+ height : rect . height * this . rectScale . y
331
359
}
332
360
/* Gridstack ONLY needs position set above... keep around in case.
333
361
element: [this.el], // The object representing the element to be resized
0 commit comments