11// @ts -nocheck
2+ /* eslint @typescript-eslint/no-unused-vars: 2 */
3+
24/*
35 * Copyright 2020 Adobe. All rights reserved.
46 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -209,14 +211,8 @@ function computePosition(
209211 containerOffsetWithBoundary : Offset ,
210212 isContainerPositioned : boolean
211213) {
212- let {
213- placement,
214- crossPlacement,
215- axis,
216- crossAxis,
217- size,
218- crossSize,
219- } = placementInfo ;
214+ let { placement, crossPlacement, axis, crossAxis, size, crossSize } =
215+ placementInfo ;
220216 let position : Position = { } ;
221217
222218 // button position
@@ -280,22 +276,22 @@ function getMaxHeight(
280276) {
281277 return position . top != null
282278 ? // We want the distance between the top of the overlay to the bottom of the boundary
283- Math . max (
284- 0 ,
285- boundaryDimensions . height +
286- boundaryDimensions . top +
287- boundaryDimensions . scroll . top - // this is the bottom of the boundary
288- ( containerOffsetWithBoundary . top + position . top ) - // this is the top of the overlay
289- ( margins . top + margins . bottom + padding ) // save additional space for margin and padding
290- )
279+ Math . max (
280+ 0 ,
281+ boundaryDimensions . height +
282+ boundaryDimensions . top +
283+ boundaryDimensions . scroll . top - // this is the bottom of the boundary
284+ ( containerOffsetWithBoundary . top + position . top ) - // this is the top of the overlay
285+ ( margins . top + margins . bottom + padding ) // save additional space for margin and padding
286+ )
291287 : // We want the distance between the top of the trigger to the top of the boundary
292- Math . max (
293- 0 ,
294- childOffset . top +
295- containerOffsetWithBoundary . top - // this is the top of the trigger
296- ( boundaryDimensions . top + boundaryDimensions . scroll . top ) - // this is the top of the boundary
297- ( margins . top + margins . bottom + padding ) // save additional space for margin and padding
298- ) ;
288+ Math . max (
289+ 0 ,
290+ childOffset . top +
291+ containerOffsetWithBoundary . top - // this is the top of the trigger
292+ ( boundaryDimensions . top + boundaryDimensions . scroll . top ) - // this is the top of the boundary
293+ ( margins . top + margins . bottom + padding ) // save additional space for margin and padding
294+ ) ;
299295}
300296
301297function getAvailableSpace (
@@ -311,26 +307,26 @@ function getAvailableSpace(
311307 return Math . max (
312308 0 ,
313309 childOffset [ axis ] -
314- boundaryDimensions [ axis ] -
315- boundaryDimensions . scroll [ axis ] +
316- containerOffsetWithBoundary [ axis ] -
317- margins [ axis ] -
318- margins [ FLIPPED_DIRECTION [ axis ] ] -
319- padding
310+ boundaryDimensions [ axis ] -
311+ boundaryDimensions . scroll [ axis ] +
312+ containerOffsetWithBoundary [ axis ] -
313+ margins [ axis ] -
314+ margins [ FLIPPED_DIRECTION [ axis ] ] -
315+ padding
320316 ) ;
321317 }
322318
323319 return Math . max (
324320 0 ,
325321 boundaryDimensions [ size ] +
326- boundaryDimensions [ axis ] +
327- boundaryDimensions . scroll [ axis ] -
328- containerOffsetWithBoundary [ axis ] -
329- childOffset [ axis ] -
330- childOffset [ size ] -
331- margins [ axis ] -
332- margins [ FLIPPED_DIRECTION [ axis ] ] -
333- padding
322+ boundaryDimensions [ axis ] +
323+ boundaryDimensions . scroll [ axis ] -
324+ containerOffsetWithBoundary [ axis ] -
325+ childOffset [ axis ] -
326+ childOffset [ size ] -
327+ margins [ axis ] -
328+ margins [ FLIPPED_DIRECTION [ axis ] ] -
329+ padding
334330 ) ;
335331}
336332
@@ -350,14 +346,9 @@ export function calculatePositionInternal(
350346 shouldOverlapWithTrigger : boolean
351347) : PositionResult {
352348 let placementInfo = parsePlacement ( placementInput ) ;
353- let {
354- size,
355- crossAxis,
356- crossSize,
357- placement,
358- crossPlacement,
359- axis,
360- } = placementInfo ;
349+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
350+ let { size, crossAxis, crossSize, placement, crossPlacement, axis } =
351+ placementInfo ;
361352 let position = computePosition (
362353 childOffset ,
363354 boundaryDimensions ,
@@ -368,7 +359,7 @@ export function calculatePositionInternal(
368359 containerOffsetWithBoundary ,
369360 isContainerPositioned
370361 ) ;
371-
362+ let isFlipped = false ;
372363 let normalizedOffset = offset ;
373364 let space = getAvailableSpace (
374365 boundaryDimensions ,
@@ -405,10 +396,15 @@ export function calculatePositionInternal(
405396
406397 // If the available space for the flipped position is greater than the original available space, flip.
407398 if ( flippedSpace > space ) {
399+ isFlipped = true ;
408400 placementInfo = flippedPlacementInfo ;
409401 position = flippedPosition ;
410402 normalizedOffset = offset ;
403+ } else {
404+ isFlipped = false ;
411405 }
406+ } else {
407+ isFlipped = false ;
412408 }
413409
414410 let delta = getDelta (
@@ -465,6 +461,7 @@ export function calculatePositionInternal(
465461 arrowOffsetLeft : arrowPosition . left ,
466462 arrowOffsetTop : arrowPosition . top ,
467463 placement : placementInfo . placement ,
464+ isFlipped,
468465 } ;
469466}
470467
@@ -502,7 +499,8 @@ export function calculatePosition(opts: PositionOpts): PositionResult {
502499 let overlaySize : Offset = getOffset ( overlayNode ) ;
503500 const matrix = getComputedStyle ( overlayNode ) . getPropertyValue ( 'transform' ) ;
504501 const transform = matrix ;
505- const regex = / m a t r i x \( ( - ? \d * \. ? \d + ) , \s * ( - ? \d * \. ? \d + ) , \s * ( - ? \d * \. ? \d + ) , \s * ( - ? \d * \. ? \d + ) , \s * ( - ? \d * \. ? \d + ) , \s * ( - ? \d * \. ? \d + ) \) / ;
502+ const regex =
503+ / m a t r i x \( ( - ? \d * \. ? \d + ) , \s * ( - ? \d * \. ? \d + ) , \s * ( - ? \d * \. ? \d + ) , \s * ( - ? \d * \. ? \d + ) , \s * ( - ? \d * \. ? \d + ) , \s * ( - ? \d * \. ? \d + ) \) / ;
506504 const matches = transform . match ( regex ) ;
507505 let scaleX = 1 ;
508506 let scaleY = 1 ;
0 commit comments