UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

110 lines (108 loc) 3.35 kB
/** * DevExtreme (esm/__internal/viz/core/base_theme_manager.js) * Version: 25.2.3 * Build date: Fri Dec 12 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import Class from "../../../core/class"; import { extend } from "../../../core/utils/extend"; import { each } from "../../../core/utils/iterator"; import { isString as _isString } from "../../../core/utils/type"; import { createPalette as getPalette, getAccentColor as accentColor, getDiscretePalette, getGradientPalette } from "../palette"; import { addCacheItem, getTheme, removeCacheItem } from "../themes"; import { parseScalar as _parseScalar } from "./utils"; const _getTheme = getTheme; const _addCacheItem = addCacheItem; const _removeCacheItem = removeCacheItem; const _extend = extend; const _each = each; function getThemePart(theme, path) { let _theme = theme; path && _each(path.split("."), ((_, pathItem) => _theme = _theme[pathItem])); return _theme } export const BaseThemeManager = Class.inherit({ ctor(options) { this._themeSection = options.themeSection; this._fontFields = options.fontFields || []; _addCacheItem(this) }, dispose() { _removeCacheItem(this); this._callback = this._theme = this._font = null; return this }, setCallback(callback) { this._callback = callback; return this }, setTheme(theme, rtl) { this._current = theme; this._rtl = rtl; return this.refresh() }, refresh() { const that = this; const current = that._current || {}; let theme = _getTheme(current.name || current); that._themeName = theme.name; that._defaultPalette = theme.defaultPalette; that._font = _extend({}, theme.font, current.font); that._themeSection && _each(that._themeSection.split("."), ((_, path) => { theme = _extend(true, {}, theme[path]) })); that._theme = _extend(true, {}, theme, _isString(current) ? {} : current); that._initializeTheme(); if (_parseScalar(that._rtl, that._theme.rtlEnabled)) { _extend(true, that._theme, that._theme._rtl) } that._callback(); return that }, theme(path) { return getThemePart(this._theme, path) }, themeName() { return this._themeName }, createPalette(palette, options) { return getPalette(palette, options, this._defaultPalette) }, createDiscretePalette(palette, count) { return getDiscretePalette(palette, count, this._defaultPalette) }, createGradientPalette(palette) { return getGradientPalette(palette, this._defaultPalette) }, getAccentColor(palette) { return accentColor(palette, this._defaultPalette) }, _initializeTheme() { const that = this; _each(that._fontFields || [], ((_, path) => { that._initializeFont(getThemePart(that._theme, path)) })) }, _initializeFont(font) { _extend(font, this._font, _extend({}, font)) } });