@@ -47,6 +47,42 @@ const createDataThemeDiv = (elementType, theme) => {
4747 document . body . appendChild ( element )
4848 return element
4949}
50+
51+ const mapSettingVariables = ( element , mapping ) => {
52+ let result = ''
53+ for ( const cssVarKey in mapping ) {
54+ const computedStyle = window . getComputedStyle ( element ) . getPropertyValue ( cssVarKey )
55+ if ( ! computedStyle ) continue
56+ const tokenName = mapping [ cssVarKey ]
57+ result += tokenName + '=' + computedStyle . trim ( ) + ';'
58+ }
59+ return result
60+ }
61+
62+ const generateSettingCssVarTokens = ( ) => {
63+ let str = ''
64+ const lightElement = createDataThemeDiv ( 'div' , 'light' )
65+ const darkElement = createDataThemeDiv ( 'div' , 'dark' )
66+ const settingVarMapping = {
67+ '--color-primary-element' : '--co-settings-btn-primary' ,
68+ '--color-primary-element-text' : '--co-settings-btn-primary-text' ,
69+ '--color-primary-element-light' : '--co-settings-btn-light' ,
70+ '--color-primary-element-light-text' : '--co-settings-btn-light-text' ,
71+ '--color-border' : '--co-settings-border' ,
72+ '--color-border-dark' : '--co--settings-border-contrast' ,
73+ '--color-main-text' : '--co-settings-text' ,
74+ '--color-text-maxcontrast' : '--co-settings-text-maxcontrast' ,
75+ '--color-main-background' : '--co-settings-background' ,
76+ 'color-background-hover' : '--co-settings-background-hover' ,
77+ }
78+ if ( getUITheme ( ) === 'dark' ) {
79+ str += mapSettingVariables ( darkElement , settingVarMapping )
80+ } else {
81+ str += mapSettingVariables ( lightElement , settingVarMapping )
82+ }
83+ return str . replace ( / [ " ' ] / g, '\\\'' )
84+ }
85+
5086const generateCSSVarTokens = ( ) => {
5187 /* NC versus COOL */
5288 const cssVarMap = {
@@ -169,4 +205,6 @@ export {
169205 getCollaboraTheme ,
170206 generateCSSVarTokens ,
171207 getUITheme ,
208+ generateSettingCssVarTokens ,
209+
172210}
0 commit comments