1 import { jQuery } from "../core.js";
2 import { isAutoPx } from "./isAutoPx.js";
3 import { rcssNum } from "../var/rcssNum.js";
5 export function adjustCSS( elem, prop, valueParts, tween ) {
13 return jQuery.css( elem, prop, "" );
15 initial = currentValue(),
16 unit = valueParts && valueParts[ 3 ] || ( isAutoPx( prop ) ? "px" : "" ),
18 // Starting value computation is required for potential unit mismatches
19 initialInUnit = elem.nodeType &&
20 ( !isAutoPx( prop ) || unit !== "px" && +initial ) &&
21 rcssNum.exec( jQuery.css( elem, prop ) );
23 if ( initialInUnit && initialInUnit[ 3 ] !== unit ) {
25 // Support: Firefox <=54 - 66+
26 // Halve the iteration target value to prevent interference from CSS upper bounds (gh-2144)
27 initial = initial / 2;
29 // Trust units reported by jQuery.css
30 unit = unit || initialInUnit[ 3 ];
32 // Iteratively approximate from a nonzero starting point
33 initialInUnit = +initial || 1;
35 while ( maxIterations-- ) {
37 // Evaluate and update our best guess (doubling guesses that zero out).
38 // Finish if the scale equals or crosses 1 (making the old*new product non-positive).
39 jQuery.style( elem, prop, initialInUnit + unit );
40 if ( ( 1 - scale ) * ( 1 - ( scale = currentValue() / initial || 0.5 ) ) <= 0 ) {
43 initialInUnit = initialInUnit / scale;
47 initialInUnit = initialInUnit * 2;
48 jQuery.style( elem, prop, initialInUnit + unit );
50 // Make sure we update the tween properties later on
51 valueParts = valueParts || [];
55 initialInUnit = +initialInUnit || +initial || 0;
57 // Apply relative offset (+=/-=) if specified
58 adjusted = valueParts[ 1 ] ?
59 initialInUnit + ( valueParts[ 1 ] + 1 ) * valueParts[ 2 ] :
63 tween.start = initialInUnit;