UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

102 lines (100 loc) • 3.43 kB
/** * DevExtreme (cjs/__internal/viz/core/base_theme_manager.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseThemeManager = void 0; var _m_extend = require("../../core/utils/m_extend"); var _m_iterator = require("../../core/utils/m_iterator"); var _m_type = require("../../core/utils/m_type"); var _utils = require("../../viz/core/utils"); var _palette = require("../../viz/palette"); var _themes = require("../../viz/themes"); function getThemePart(theme, path) { let themePart = theme; if (path) { (0, _m_iterator.each)(path.split("."), (_, pathItem) => { themePart = themePart[pathItem]; return false !== themePart }) } return themePart } let BaseThemeManager = exports.BaseThemeManager = class { constructor(options) { this._themeSection = options.themeSection; this._fontFields = options.fontFields || []; (0, _themes.addCacheItem)(this) } dispose() { (0, _themes.removeCacheItem)(this); Object.assign(this, { _font: null, _theme: null, _callback: null }); return this } setCallback(callback) { this._callback = callback; return this } setTheme(theme, rtl) { this._current = theme; this._rtl = rtl; return this.refresh() } refresh() { const current = this._current || {}; const currentTheme = (0, _m_type.isString)(current) ? {} : current; let theme = (0, _themes.getTheme)(currentTheme.name || current); this._themeName = theme.name; this._defaultPalette = theme.defaultPalette; this._font = (0, _m_extend.extend)({}, theme.font, currentTheme.font); if (this._themeSection) { (0, _m_iterator.each)(this._themeSection.split("."), (_, path) => { theme = (0, _m_extend.extend)(true, {}, theme[path]) }) } this._theme = (0, _m_extend.extend)(true, {}, theme, currentTheme); this._initializeTheme(); if ((0, _utils.parseScalar)(this._rtl, this._theme.rtlEnabled)) { (0, _m_extend.extend)(true, this._theme, this._theme._rtl) } this._callback(); return this } theme(path) { return getThemePart(this._theme, path) } themeName() { return this._themeName } createPalette(palette, options) { return (0, _palette.createPalette)(palette, options, this._defaultPalette) } createDiscretePalette(palette, count) { return (0, _palette.getDiscretePalette)(palette, count, this._defaultPalette) } createGradientPalette(palette) { return (0, _palette.getGradientPalette)(palette, this._defaultPalette) } getAccentColor(palette) { return (0, _palette.getAccentColor)(palette, this._defaultPalette) } _initializeTheme() { (0, _m_iterator.each)(this._fontFields || [], (_, path) => { this._initializeFont(getThemePart(this._theme, path)) }) } _initializeFont(font) { (0, _m_extend.extend)(font, this._font, (0, _m_extend.extend)({}, font)) } };