File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 1+ // store color themes
2+ const colorTheme = [ ] ;
3+ const htmlStyles = getComputedStyle ( document . documentElement ) ;
4+ const targetStylesheet = document . querySelector ( "#color-themes" ) ;
5+ const regex = / - - ( [ ^ : \s ] + ) : \s * v a r \( - - ( [ ^ ) ] + ) \) ; / g;
6+ if ( targetStylesheet ) {
7+ const rules = targetStylesheet . sheet . cssRules || targetStylesheet . sheet . rules ;
8+ for ( const rule of rules ) {
9+ if ( rule . cssText . includes ( "data-theme=" ) && ! rule . cssText . includes ( `data-theme="0"` ) ) {
10+ const styleObject = { } ;
11+ let match ;
12+ while ( ( match = regex . exec ( rule . cssText ) ) !== null ) {
13+ const key = "--" + match [ 1 ] ;
14+ const value = htmlStyles . getPropertyValue ( "--" + match [ 2 ] ) ;
15+ styleObject [ key ] = value ;
16+ }
17+ colorTheme . push ( styleObject ) ;
18+ }
19+ }
20+ }
21+ // ...colorThemes[0]
22+ export const colorThemes = colorTheme ;
You can’t perform that action at this time.
0 commit comments