@@ -106,6 +106,24 @@ export class VuetifyView extends VueView {
106106 } ;
107107 onColorsDark ( ) ;
108108
109+ const stopSyncColorsLight = Vue . watch (
110+ ( ) => {
111+ const light = this . theme . themes . value . light ;
112+ return light && light . colors ;
113+ } ,
114+ ( colors ) => syncColorsToModel ( colors , this . themeLightModel ) ,
115+ { deep : true }
116+ ) ;
117+
118+ const stopSyncColorsDark = Vue . watch (
119+ ( ) => {
120+ const dark = this . theme . themes . value . dark ;
121+ return dark && dark . colors ;
122+ } ,
123+ ( colors ) => syncColorsToModel ( colors , this . themeDarkModel ) ,
124+ { deep : true }
125+ ) ;
126+
109127 if ( this . themeModel . get ( "dark" ) !== null ) {
110128 onDark ( ) ;
111129 } else if ( document . body . dataset . jpThemeLight ) {
@@ -132,6 +150,8 @@ export class VuetifyView extends VueView {
132150 this . themeModel . off ( "change:dark" , onDark ) ;
133151 this . themeLightModel . off ( "change" , onColorsLight ) ;
134152 this . themeDarkModel . off ( "change" , onColorsDark ) ;
153+ stopSyncColorsLight ( ) ;
154+ stopSyncColorsDark ( ) ;
135155 } ) ;
136156 }
137157}
@@ -159,3 +179,32 @@ function getColors(colorModel) {
159179 ( v , k ) => k . replace ( / _ / g, "-" )
160180 ) ;
161181}
182+
183+ function syncColorsToModel ( colors , colorModel ) {
184+ if ( ! colors || ! colorModel ) {
185+ return ;
186+ }
187+
188+ let hasChanges = false ;
189+
190+ Object . entries ( colors ) . forEach ( ( [ key , value ] ) => {
191+ const modelKey = key . replace ( / - / g, "_" ) ;
192+ if (
193+ modelKey . startsWith ( "_" ) ||
194+ modelKey === "accent" ||
195+ modelKey === "anchor" ||
196+ ! ( modelKey in colorModel . attributes ) ||
197+ typeof value !== "string" ||
198+ colorModel . get ( modelKey ) === value
199+ ) {
200+ return ;
201+ }
202+
203+ colorModel . set ( modelKey , value ) ;
204+ hasChanges = true ;
205+ } ) ;
206+
207+ if ( hasChanges ) {
208+ colorModel . save_changes ( ) ;
209+ }
210+ }
0 commit comments