This repository was archived by the owner on Nov 26, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +21
-10
lines changed Expand file tree Collapse file tree 2 files changed +21
-10
lines changed Original file line number Diff line number Diff line change @@ -22,12 +22,20 @@ export const getCSSVariablesFromStylesheet = (varPrefix: string): Color => {
2222 // Access rules from the stylesheet, handle security errors when accessing cross-origin stylesheets
2323 return Array . from ( styleSheet . cssRules ) ;
2424 } catch ( err ) {
25- console . error (
26- 'Access denied to stylesheet: ' ,
27- styleSheet . href ,
28- '; Error: ' ,
29- err . message ,
30- ) ;
25+ if ( err instanceof Error ) {
26+ console . error (
27+ 'Access denied to stylesheet: ' ,
28+ styleSheet . href ,
29+ '; Error: ' ,
30+ err . message ,
31+ ) ;
32+ } else {
33+ console . error (
34+ 'Access denied to stylesheet: ' ,
35+ styleSheet . href ,
36+ '; Unknown error occurred.' ,
37+ ) ;
38+ }
3139 return [ ] ;
3240 }
3341 } )
@@ -47,7 +55,7 @@ export const getCSSVariablesFromStylesheet = (varPrefix: string): Color => {
4755 // Iterate over each property in the style rule
4856 for ( let i = 0 ; i < style . length ; i ++ ) {
4957 const varName = style [ i ] ;
50- if ( varName . startsWith ( varPrefix ) ) {
58+ if ( varName ? .startsWith ( varPrefix ) ) {
5159 // Get the actual CSS variable value from the computed styles of the document's root element
5260 const value = getComputedStyle ( document . documentElement )
5361 . getPropertyValue ( varName )
Original file line number Diff line number Diff line change @@ -68,20 +68,23 @@ export const useJsonColor = (): CompiledColors => {
6868 } ) : CompiledColors => {
6969 const compiledColors : CompiledColors = { } ;
7070 Object . entries ( themes ) . forEach ( ( [ themeName , theme ] ) => {
71- compiledColors [ themeName ] = { } ;
71+ const tempThemeColors : Theme = { } ;
7272 Object . entries ( theme ) . forEach ( ( [ colorName , colorValues ] ) => {
73- compiledColors [ themeName ] [ colorName ] = { } ;
73+ const tempThemeColorPalette : ColorPalette = { } ;
7474 Object . entries ( colorValues ) . forEach ( ( [ shade , details ] ) => {
7575 const { value, description } = details ;
7676 const resolvedValue = parseColorValue ( value , figmaBrandColors ) ;
77- compiledColors [ themeName ] [ colorName ] [ shade ] = {
77+ const tempShadeColor = {
7878 ...details ,
7979 value : resolvedValue ,
8080 description :
8181 description + ( value === resolvedValue ? '' : ` ${ value } ` ) ,
8282 } ;
83+ tempThemeColorPalette [ shade ] = tempShadeColor ;
8384 } ) ;
85+ tempThemeColors [ colorName ] = tempThemeColorPalette ;
8486 } ) ;
87+ compiledColors [ themeName ] = tempThemeColors ;
8588 } ) ;
8689 return compiledColors ;
8790 } ;
You can’t perform that action at this time.
0 commit comments