|
|
@ -672,21 +672,17 @@ export default class Resizer { |
|
|
const maxDim = opts.maxDim; |
|
|
const maxDim = opts.maxDim; |
|
|
const deltaX = data.delta!.x; |
|
|
const deltaX = data.delta!.x; |
|
|
const deltaY = data.delta!.y; |
|
|
const deltaY = data.delta!.y; |
|
|
const parentEl = this.getParentEl(); |
|
|
|
|
|
const parentRect = parentEl ? this.getElementPos(parentEl) : { top: 0, left: 0, width: 0, height: 0 }; |
|
|
|
|
|
const parentW = this.parentDim!.w; |
|
|
const parentW = this.parentDim!.w; |
|
|
const parentH = this.parentDim!.h; |
|
|
const parentH = this.parentDim!.h; |
|
|
const unitWidth = this.opts.unitWidth; |
|
|
const unitWidth = this.opts.unitWidth; |
|
|
const unitHeight = this.opts.unitHeight; |
|
|
const unitHeight = this.opts.unitHeight; |
|
|
|
|
|
const parentRect = this.getParentRect(); |
|
|
const startW = unitWidth === '%' ? (startDim.w / 100) * parentW : startDim.w; |
|
|
const startW = unitWidth === '%' ? (startDim.w / 100) * parentW : startDim.w; |
|
|
const startH = unitHeight === '%' ? (startDim.h / 100) * parentH : startDim.h; |
|
|
const startH = unitHeight === '%' ? (startDim.h / 100) * parentH : startDim.h; |
|
|
|
|
|
|
|
|
// Check if the parent or any ancestor has `position: relative`, `absolute`, `fixed`, or `sticky`
|
|
|
|
|
|
const hasPositionedParent = parentEl && this.hasPositionedParent(parentEl); |
|
|
|
|
|
|
|
|
|
|
|
const box: RectDim = { |
|
|
const box: RectDim = { |
|
|
t: hasPositionedParent ? startDim.t - parentRect.top : startDim.t, // Subtract only if parent or ancestor is positioned
|
|
|
t: startDim.t - parentRect.top, |
|
|
l: hasPositionedParent ? startDim.l - parentRect.left : startDim.l, // Subtract only if parent or ancestor is positioned
|
|
|
l: startDim.l - parentRect.left, |
|
|
w: startW, |
|
|
w: startW, |
|
|
h: startH, |
|
|
h: startH, |
|
|
}; |
|
|
}; |
|
|
@ -757,10 +753,19 @@ export default class Resizer { |
|
|
return box; |
|
|
return box; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
hasPositionedParent(element: HTMLElement | null): boolean { |
|
|
getParentRect(): BoundingRect { |
|
|
if (!element) return false; |
|
|
let parentRect = { left: 0, top: 0, width: 0, height: 0 }; |
|
|
|
|
|
const { el } = this; |
|
|
|
|
|
|
|
|
|
|
|
if (!el) return parentRect; |
|
|
|
|
|
|
|
|
|
|
|
const { offsetParent } = el; |
|
|
|
|
|
|
|
|
|
|
|
// Check if the parent or any ancestor has `position: relative`, `absolute`, `fixed`, or `sticky`
|
|
|
|
|
|
if (offsetParent && offsetParent.tagName !== 'BODY') { |
|
|
|
|
|
parentRect = this.getElementPos(offsetParent as HTMLElement); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// If the element's offsetParent is not the body or null, it has a positioned ancestor
|
|
|
return parentRect; |
|
|
return element.offsetParent !== document.body && element.offsetParent !== null; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|