tdesign-vue
Version:
152 lines (148 loc) • 5.69 kB
JavaScript
/**
* tdesign v1.12.1
* (c) 2025 tdesign
* @license MIT
*/
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { camelCase } from 'lodash-es';
var _excluded = ["from", "to", "direction"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function omit(obj, fields) {
var shallowCopy = _objectSpread({}, obj);
for (var i = 0; i < fields.length; i++) {
var key = fields[i];
delete shallowCopy[key];
}
return shallowCopy;
}
function removeEmptyAttrs(obj) {
var newObj = {};
Object.keys(obj).forEach(function (key) {
if (typeof obj[key] !== "undefined" || obj[key] === null) {
newObj[key] = obj[key];
}
});
return newObj;
}
function getTabElementByValue() {
var tabs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var value = arguments.length > 1 ? arguments[1] : undefined;
var _tabs$filter = tabs.filter(function (item) {
var id = item.id;
return id === value;
}),
_tabs$filter2 = _slicedToArray(_tabs$filter, 1),
result = _tabs$filter2[0];
return result || null;
}
function firstUpperCase(str) {
return str.toLowerCase().replace(/( |^)[a-z]/g, function (_char) {
return _char.toUpperCase();
});
}
function getBackgroundColor(color) {
if (typeof color === "string") {
return color;
}
if (Array.isArray(color)) {
if (color[0] && color[0][0] === "#") {
color.unshift("90deg");
}
return "linear-gradient( ".concat(color.join(","), " )");
}
var from = color.from,
to = color.to,
_color$direction = color.direction,
direction = _color$direction === void 0 ? "to right" : _color$direction,
rest = _objectWithoutProperties(color, _excluded);
var keys = Object.keys(rest);
if (keys.length) {
keys = keys.sort(function (a, b) {
return parseFloat(a.substr(0, a.length - 1)) - parseFloat(b.substr(0, b.length - 1));
});
var tempArr = keys.map(function (key) {
return "".concat(rest[key], " ").concat(key);
});
return "linear-gradient(".concat(direction, ", ").concat(tempArr.join(","), ")");
}
return "linear-gradient(".concat(direction, ", ").concat(from, ", ").concat(to, ")");
}
function getPropsApiByEvent(eventName) {
return camelCase("on-".concat(eventName));
}
function getIEVersion() {
var _navigator = navigator,
userAgent = _navigator.userAgent;
var isIE = userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1;
var isIE11 = userAgent.indexOf("Trident") > -1 && userAgent.indexOf("rv:11.0") > -1;
if (isIE) {
var reIE = new RegExp("MSIE (\\d+\\.\\d+);");
var match = userAgent.match(reIE);
if (!match) return -1;
var fIEVersion = parseFloat(match[1]);
return fIEVersion < 7 ? 6 : fIEVersion;
}
if (isIE11) {
return 11;
}
return Number.MAX_SAFE_INTEGER;
}
function getCharacterLength(str, maxCharacter) {
var hasMaxCharacter = typeof maxCharacter === "number";
if (!str || str.length === 0) {
if (hasMaxCharacter) {
return {
length: 0,
characters: str
};
}
return 0;
}
var len = 0;
for (var i = 0; i < str.length; i++) {
var currentStringLength = 0;
if (str.charCodeAt(i) > 127) {
currentStringLength = 2;
} else {
currentStringLength = 1;
}
if (hasMaxCharacter && len + currentStringLength > maxCharacter) {
return {
length: len,
characters: str.slice(0, i)
};
}
len += currentStringLength;
}
if (hasMaxCharacter) {
return {
length: len,
characters: str
};
}
return len;
}
function pxCompat(param) {
return typeof param === "number" ? "".concat(param, "px") : param;
}
function setTransform(value) {
return {
transform: value,
"-ms-transform": value,
"-moz-transform": value,
"-webkit-transform": value
};
}
function getVueComponentName(component) {
var _component$options;
return (component === null || component === void 0 || (_component$options = component.options) === null || _component$options === void 0 ? void 0 : _component$options.name) || (component === null || component === void 0 ? void 0 : component.name);
}
function getVNodeComponentName(vnode) {
var _vnode$componentOptio;
return vnode === null || vnode === void 0 || (_vnode$componentOptio = vnode.componentOptions) === null || _vnode$componentOptio === void 0 || (_vnode$componentOptio = _vnode$componentOptio.Ctor) === null || _vnode$componentOptio === void 0 || (_vnode$componentOptio = _vnode$componentOptio.options) === null || _vnode$componentOptio === void 0 ? void 0 : _vnode$componentOptio.name;
}
export { firstUpperCase, getBackgroundColor, getCharacterLength, getIEVersion, getPropsApiByEvent, getTabElementByValue, getVNodeComponentName, getVueComponentName, omit, pxCompat, removeEmptyAttrs, setTransform };
//# sourceMappingURL=helper.js.map