Files
ai/web/public/charting_library/bundles/custom-themes-api.91c6261b25d95d0206c9.js

2 lines
3.0 KiB
JavaScript

"use strict";(self.webpackChunktradingview=self.webpackChunktradingview||[]).push([[2413],{82753:(e,t,o)=>{o.r(t),o.d(t,{CustomThemesApi:()=>a});var r=o(79736),n=o(52959);class a{async applyCustomThemes(e){const t=(0,n.getChartingLibraryGlobalContext)(),o=t.tradingViewApi.themes().getCurrentThemeName();(0,r.overrideStandardThemes)(e),await t.tradingViewApi.themes().setStdTheme(o,void 0,!0)}async resetCustomThemes(){const e=(0,n.getChartingLibraryGlobalContext)(),t=e.tradingViewApi.themes().getCurrentThemeName();(0,r.restoreStandardThemes)(),await e.tradingViewApi.themes().setStdTheme(t,void 0,!0)}}},79736:(e,t,o)=>{o.r(t),o.d(t,{addCustomThemesRootClass:()=>f,overrideStandardThemes:()=>h,removeCustomThemesRootClass:()=>b,restoreStandardThemes:()=>g});var r=o(30551),n=o(24317),a=o(22489),c=o(24633),s=o(30714);const i={};for(const[e,t]of Object.entries(s))i[t]=e;function l(e,t){const o=i[e];if(void 0!==o)return function(e,t){const o=/([a-z]+[\-a-z+]+-[a-z]+)-?([0-9]+)?/.exec(e);if(null===o)return;const r=o[1],n=parseInt(o[2])/50-1;switch(r){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}}(o,t)}var d=o(52959);const m="theme-custom",u="custom-theme-styles";function h(e){p(c.StdTheme.Light,e[c.StdTheme.Light]),p(c.StdTheme.Dark,e[c.StdTheme.Dark]),window.requestAnimationFrame((()=>{f(),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}(),o=[C(":root",c.StdTheme.Light,e[c.StdTheme.Light]),C(".theme-dark:root",c.StdTheme.Dark,e[c.StdTheme.Dark])].join("\n\n");t.textContent=o}(e)}))}function g(){(0,n.restoreStdThemes)(),window.requestAnimationFrame((()=>{!function(){const e=(0,d.getChartingLibraryGlobalContext)().document.getElementById(u);e&&e.remove()}(),b()}))}function f(){const e=window.document.documentElement.classList;e.contains(m)||e.add(m)}function b(){window.document.documentElement.classList.remove(m)}const w={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 C(e,t,o){const r=[];for(const[e,t]of Object.entries(o)){const n=w[e];if(Array.isArray(t))for(let t=0;t<o[e].length;t++)r.push(`--color-${n}-${50*(t+1)}: ${o[e][t]};`);else r.push(`--color-${n}: ${o[e]};`)}return`${e} {\n${r.sort().join("\n")}\n}`}function p(e,t){const o=(0,a.getStdTheme)(e);(0,n.overrideStdTheme)(e,function e(o){for(const[n,a]of Object.entries(o))if((0,r.isObject)(a))e(a);else if("string"==typeof a){let e=l(a,t);"backgroundGradientStartColor"===n&&(e=l(o.backgroundGradientEndColor,t)),
void 0!==e&&(o[n]=e)}return o}(o))}}}]);