Files
ai/charting_library/bundles/custom-themes-api.346da64f8e2ba8cad2d8.js

1 line
2.9 KiB
JavaScript

"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[1102],{14683:(e,t,r)=>{r.r(t),r.d(t,{CustomThemesApi:()=>a});var o=r(26028),n=r(43763);class a{async applyCustomThemes(e){const t=(0,n.getChartingLibraryGlobalContext)(),r=t.tradingViewApi.themes().getCurrentThemeName();(0,o.overrideStandardThemes)(e),await t.tradingViewApi.themes().setStdTheme(r,void 0,!0)}async resetCustomThemes(){const e=(0,n.getChartingLibraryGlobalContext)(),t=e.tradingViewApi.themes().getCurrentThemeName();(0,o.restoreStandardThemes)(),await e.tradingViewApi.themes().setStdTheme(t,void 0,!0)}}},26028:(e,t,r)=>{r.d(t,{overrideStandardThemes:()=>h,restoreStandardThemes:()=>g});var o=r(22872),n=r(28507),a=r(40520),c=r(47097),i=r(30614);const s={};for(const[e,t]of Object.entries(i))s[t]=e;function l(e,t){const r=s[e];if(void 0!==r)return function(e,t){const r=/([a-z]+[\-a-z+]+-[a-z]+)-?([0-9]+)?/.exec(e);if(null===r)return;const o=r[1],n=parseInt(r[2])/50-1;switch(o){case"color-tv-blue":return t.color1[n];case"color-cold-gray":return t.color2[n];case"color-ripe-red":return t.color3[n];case"color-minty-green":return t.color4[n];case"color-tan-orange":return t.color5[n];case"color-grapes-purple":return t.color6[n];case"color-banana-yellow":return t.color7[n];case"color-white":return t.white;case"color-black":return t.black}}(r,t)}var d=r(43763);const m="theme-custom",u="custom-theme-styles";function h(e){w(c.StdTheme.Light,e[c.StdTheme.Light]),w(c.StdTheme.Dark,e[c.StdTheme.Dark]),window.requestAnimationFrame((()=>{!function(){const e=window.document.documentElement.classList;e.contains(m)||e.add(m)}(),function(e){const t=function(){const e=(0,d.getChartingLibraryGlobalContext)().document;let t=e.getElementById(u);t||(t=function(){const e=(0,d.getChartingLibraryGlobalContext)().document,t=e.createElement("style");return t.id=u,t}(),e.head.appendChild(t));return t}(),r=[b(":root",c.StdTheme.Light,e[c.StdTheme.Light]),b(".theme-dark:root",c.StdTheme.Dark,e[c.StdTheme.Dark])].join("\n\n");t.textContent=r}(e)}))}function g(){(0,n.restoreStdThemes)(),window.requestAnimationFrame((()=>{!function(){const e=(0,d.getChartingLibraryGlobalContext)().document.getElementById(u);e&&e.remove()}(),window.document.documentElement.classList.remove(m)}))}const f={color1:"tv-blue",color2:"cold-gray",color3:"ripe-red",color4:"minty-green",color5:"tan-orange",color6:"grapes-purple",color7:"banana-yellow",black:"black",white:"white"};function b(e,t,r){const o=[];for(const[e,t]of Object.entries(r)){const n=f[e];if(Array.isArray(t))for(let t=0;t<r[e].length;t++)o.push(`--color-${n}-${50*(t+1)}: ${r[e][t]};`);else o.push(`--color-${n}: ${r[e]};`)}return`${e} {\n${o.sort().join("\n")}\n}`}function w(e,t){const r=(0,a.getStdTheme)(e);(0,n.overrideStdTheme)(e,function e(r){for(const[n,a]of Object.entries(r))if((0,o.isObject)(a))e(a);else if("string"==typeof a){let e=l(a,t);"backgroundGradientStartColor"===n&&(e=l(r.backgroundGradientEndColor,t)),void 0!==e&&(r[n]=e)}return r}(r))}}}]);