168 lines
4.7 KiB
JavaScript
Executable File
168 lines
4.7 KiB
JavaScript
Executable File
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.toArray = toArray;
|
|
exports.getActiveIndex = getActiveIndex;
|
|
exports.getActiveKey = getActiveKey;
|
|
exports.setTransform = setTransform;
|
|
exports.isTransform3dSupported = isTransform3dSupported;
|
|
exports.setTransition = setTransition;
|
|
exports.getTransformPropValue = getTransformPropValue;
|
|
exports.isVertical = isVertical;
|
|
exports.getTransformByIndex = getTransformByIndex;
|
|
exports.getMarginStyle = getMarginStyle;
|
|
exports.getStyle = getStyle;
|
|
exports.setPxStyle = setPxStyle;
|
|
exports.getDataAttr = getDataAttr;
|
|
exports.getLeft = getLeft;
|
|
exports.getTop = getTop;
|
|
|
|
var _react = _interopRequireDefault(require("react"));
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
|
|
function toArray(children) {
|
|
// allow [c,[a,b]]
|
|
var c = [];
|
|
|
|
_react.default.Children.forEach(children, function (child) {
|
|
if (child) {
|
|
c.push(child);
|
|
}
|
|
});
|
|
|
|
return c;
|
|
}
|
|
|
|
function getActiveIndex(children, activeKey) {
|
|
var c = toArray(children);
|
|
|
|
for (var i = 0; i < c.length; i++) {
|
|
if (c[i].key === activeKey) {
|
|
return i;
|
|
}
|
|
}
|
|
|
|
return -1;
|
|
}
|
|
|
|
function getActiveKey(children, index) {
|
|
var c = toArray(children);
|
|
return c[index].key;
|
|
}
|
|
|
|
function setTransform(style, v) {
|
|
style.transform = v;
|
|
style.webkitTransform = v;
|
|
style.mozTransform = v;
|
|
}
|
|
|
|
function isTransform3dSupported(style) {
|
|
return ('transform' in style || 'webkitTransform' in style || 'MozTransform' in style) && window.atob;
|
|
}
|
|
|
|
function setTransition(style, v) {
|
|
style.transition = v;
|
|
style.webkitTransition = v;
|
|
style.MozTransition = v;
|
|
}
|
|
|
|
function getTransformPropValue(v) {
|
|
return {
|
|
transform: v,
|
|
WebkitTransform: v,
|
|
MozTransform: v
|
|
};
|
|
}
|
|
|
|
function isVertical(tabBarPosition) {
|
|
return tabBarPosition === 'left' || tabBarPosition === 'right';
|
|
}
|
|
|
|
function getTransformByIndex(index, tabBarPosition) {
|
|
var direction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'ltr';
|
|
var translate = isVertical(tabBarPosition) ? 'translateY' : 'translateX';
|
|
|
|
if (!isVertical(tabBarPosition) && direction === 'rtl') {
|
|
return "".concat(translate, "(").concat(index * 100, "%) translateZ(0)");
|
|
}
|
|
|
|
return "".concat(translate, "(").concat(-index * 100, "%) translateZ(0)");
|
|
}
|
|
|
|
function getMarginStyle(index, tabBarPosition) {
|
|
var direction = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'ltr';
|
|
var marginDirection = isVertical(tabBarPosition) ? 'marginTop' : 'marginLeft';
|
|
|
|
if (!isVertical(tabBarPosition) && direction === 'rtl') {
|
|
return _defineProperty({}, marginDirection, "".concat((index + 1) * 100, "%"));
|
|
}
|
|
|
|
return _defineProperty({}, marginDirection, "".concat(-index * 100, "%"));
|
|
}
|
|
|
|
function getStyle(el, property) {
|
|
return +window.getComputedStyle(el).getPropertyValue(property).replace('px', '');
|
|
}
|
|
|
|
function setPxStyle(el, value, vertical) {
|
|
value = vertical ? "0px, ".concat(value, "px, 0px") : "".concat(value, "px, 0px, 0px");
|
|
setTransform(el.style, "translate3d(".concat(value, ")"));
|
|
}
|
|
|
|
function getDataAttr(props) {
|
|
return Object.keys(props).reduce(function (prev, key) {
|
|
if (key.substr(0, 5) === 'aria-' || key.substr(0, 5) === 'data-' || key === 'role') {
|
|
prev[key] = props[key];
|
|
}
|
|
|
|
return prev;
|
|
}, {});
|
|
}
|
|
|
|
function toNum(style, property) {
|
|
return +style.getPropertyValue(property).replace('px', '');
|
|
}
|
|
|
|
function getTypeValue(start, current, end, tabNode, wrapperNode) {
|
|
var total = getStyle(wrapperNode, "padding-".concat(start));
|
|
|
|
if (!tabNode || !tabNode.parentNode) {
|
|
return total;
|
|
}
|
|
|
|
var childNodes = tabNode.parentNode.childNodes;
|
|
Array.prototype.some.call(childNodes, function (node) {
|
|
var style = window.getComputedStyle(node);
|
|
|
|
if (node !== tabNode) {
|
|
total += toNum(style, "margin-".concat(start));
|
|
total += node[current];
|
|
total += toNum(style, "margin-".concat(end));
|
|
|
|
if (style.boxSizing === 'content-box') {
|
|
total += toNum(style, "border-".concat(start, "-width")) + toNum(style, "border-".concat(end, "-width"));
|
|
}
|
|
|
|
return false;
|
|
} // We need count current node margin
|
|
// ref: https://github.com/react-component/tabs/pull/139#issuecomment-431005262
|
|
|
|
|
|
total += toNum(style, "margin-".concat(start));
|
|
return true;
|
|
});
|
|
return total;
|
|
}
|
|
|
|
function getLeft(tabNode, wrapperNode) {
|
|
return getTypeValue('left', 'offsetWidth', 'right', tabNode, wrapperNode);
|
|
}
|
|
|
|
function getTop(tabNode, wrapperNode) {
|
|
return getTypeValue('top', 'offsetHeight', 'bottom', tabNode, wrapperNode);
|
|
} |