tdesign-vue
Version:
55 lines (51 loc) • 1.83 kB
JavaScript
/**
* tdesign v1.14.1
* (c) 2025 tdesign
* @license MIT
*/
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
import { ref } from '@vue/composition-api';
import { isString } from 'lodash-es';
import { getColorTokenColor } from '../_common/js/utils/getColorTokenColor.js';
import { THEME_MODE } from '../_common/js/common.js';
import { useMutationObservable } from './useMutationObservable.js';
import '@babel/runtime/helpers/defineProperty';
function useVariables(variables) {
var _document;
var values = {};
var varsArray = [];
varsArray = Object.values(variables);
Object.entries(variables).forEach(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
key = _ref2[0],
varName = _ref2[1];
values[key] = ref(getColorTokenColor(varName));
});
varsArray.forEach(function (varName) {
values[varName] = ref(getColorTokenColor(varName));
});
var targetElement = (_document = document) === null || _document === void 0 ? void 0 : _document.documentElement;
useMutationObservable(targetElement, function (mutationsList) {
mutationsList.some(function (mutation) {
if (mutation.type === "attributes" && mutation.attributeName === THEME_MODE) {
if (isString(variables) || Array.isArray(variables)) {
varsArray.forEach(function (varName) {
values[varName].value = getColorTokenColor(varName);
});
} else {
Object.entries(variables).forEach(function (_ref3) {
var _ref4 = _slicedToArray(_ref3, 2),
key = _ref4[0],
varName = _ref4[1];
values[key].value = getColorTokenColor(varName);
});
}
return true;
}
return false;
});
});
return values;
}
export { useVariables };
//# sourceMappingURL=useVariables.js.map