UNPKG

tdesign-react

Version:
57 lines (53 loc) 3.14 kB
/** * tdesign v1.13.2 * (c) 2025 tdesign * @license MIT */ import { _ as _slicedToArray } from '../_chunks/dep-118954e6.js'; import { useState } from 'react'; import { T as THEME_MODE } from '../_chunks/dep-5fa28cf2.js'; import { j as getCurrentPrimaryColor } from '../_chunks/dep-82b8abc2.js'; import useMutationObservable from './useMutationObserver.js'; import '../_chunks/dep-61f5e3d1.js'; import 'lodash-es'; import './useLatest.js'; function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } function useThemeColor() { var _document; var _useState = useState(getCurrentPrimaryColor("--td-text-color-primary")), _useState2 = _slicedToArray(_useState, 2), color = _useState2[0], setColor = _useState2[1]; var _useState3 = useState(getCurrentPrimaryColor("--td-bg-color-specialcomponent")), _useState4 = _slicedToArray(_useState3, 2), bgColor = _useState4[0], setBgColor = _useState4[1]; var targetElement = (_document = document) === null || _document === void 0 ? void 0 : _document.documentElement; useMutationObservable(targetElement, function (mutationsList) { var _iterator = _createForOfIteratorHelper(mutationsList), _step; try { for (_iterator.s(); !(_step = _iterator.n()).done;) { var mutation = _step.value; if (mutation.type === "attributes") { if (mutation.attributeName === THEME_MODE) { setColor(getCurrentPrimaryColor("--td-text-color-primary")); setBgColor(getCurrentPrimaryColor("--td-bg-color-specialcomponent")); } } } } catch (err) { _iterator.e(err); } finally { _iterator.f(); } }); return { color: color, bgColor: bgColor }; } export { useThemeColor as default }; //# sourceMappingURL=useThemeColor.js.map