UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

114 lines (112 loc) • 3.19 kB
/** * DevExtreme (esm/__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/ */ import { extend } from "../../core/utils/m_extend"; import { each } from "../../core/utils/m_iterator"; import { isString } from "../../core/utils/m_type"; import { parseScalar } from "../../viz/core/utils"; import { createPalette as getPalette, getAccentColor as accentColor, getDiscretePalette, getGradientPalette } from "../../viz/palette"; import { addCacheItem, getTheme, removeCacheItem } from "../../viz/themes"; function getThemePart(theme, path) { let themePart = theme; if (path) { each(path.split("."), (_, pathItem) => { themePart = themePart[pathItem]; return false !== themePart }) } return themePart } export let BaseThemeManager = class { constructor(options) { this._themeSection = options.themeSection; this._fontFields = options.fontFields || []; addCacheItem(this) } dispose() { 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 = isString(current) ? {} : current; let theme = getTheme(currentTheme.name || current); this._themeName = theme.name; this._defaultPalette = theme.defaultPalette; this._font = extend({}, theme.font, currentTheme.font); if (this._themeSection) { each(this._themeSection.split("."), (_, path) => { theme = extend(true, {}, theme[path]) }) } this._theme = extend(true, {}, theme, currentTheme); this._initializeTheme(); if (parseScalar(this._rtl, this._theme.rtlEnabled)) { 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 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() { each(this._fontFields || [], (_, path) => { this._initializeFont(getThemePart(this._theme, path)) }) } _initializeFont(font) { extend(font, this._font, extend({}, font)) } };