70 lines
1.8 KiB
JavaScript
70 lines
1.8 KiB
JavaScript
/**
|
|
* Source code reference from:
|
|
* https://github.com/facebook/fbjs/blob/d308fa83c9/packages/fbjs/src/dom/translateDOMPositionXY.js
|
|
*/
|
|
import BrowserSupportCore from '../BrowserSupportCore';
|
|
import getVendorPrefixedName from '../getVendorPrefixedName';
|
|
import getGlobal from '../getGlobal';
|
|
var g = getGlobal();
|
|
var TRANSFORM = getVendorPrefixedName('transform');
|
|
var BACKFACE_VISIBILITY = getVendorPrefixedName('backfaceVisibility');
|
|
export var getTranslateDOMPositionXY = function getTranslateDOMPositionXY(conf) {
|
|
if (conf === void 0) {
|
|
conf = {
|
|
enable3DTransform: true
|
|
};
|
|
}
|
|
|
|
if (BrowserSupportCore.hasCSSTransforms()) {
|
|
var ua = g.window ? g.window.navigator.userAgent : 'UNKNOWN';
|
|
var isSafari = /Safari\//.test(ua) && !/Chrome\//.test(ua); // It appears that Safari messes up the composition order
|
|
// of GPU-accelerated layers
|
|
// (see bug https://bugs.webkit.org/show_bug.cgi?id=61824).
|
|
// Use 2D translation instead.
|
|
|
|
if (!isSafari && BrowserSupportCore.hasCSS3DTransforms() && conf.enable3DTransform) {
|
|
return function (style, x, y) {
|
|
if (x === void 0) {
|
|
x = 0;
|
|
}
|
|
|
|
if (y === void 0) {
|
|
y = 0;
|
|
}
|
|
|
|
style[TRANSFORM] = "translate3d(" + x + "px," + y + "px,0)";
|
|
style[BACKFACE_VISIBILITY] = 'hidden';
|
|
return style;
|
|
};
|
|
}
|
|
|
|
return function (style, x, y) {
|
|
if (x === void 0) {
|
|
x = 0;
|
|
}
|
|
|
|
if (y === void 0) {
|
|
y = 0;
|
|
}
|
|
|
|
style[TRANSFORM] = "translate(" + x + "px," + y + "px)";
|
|
return style;
|
|
};
|
|
}
|
|
|
|
return function (style, x, y) {
|
|
if (x === void 0) {
|
|
x = 0;
|
|
}
|
|
|
|
if (y === void 0) {
|
|
y = 0;
|
|
}
|
|
|
|
style.left = x + "px";
|
|
style.top = y + "px";
|
|
return style;
|
|
};
|
|
};
|
|
var translateDOMPositionXY = getTranslateDOMPositionXY();
|
|
export default translateDOMPositionXY; |