@@ -296,7 +296,9 @@ def __init__(
296296 self .brand = brand
297297
298298 # Prep Sass and CSS Variables -------------------------------------------------
299- sass_vars_colors , css_vars_colors = ThemeBrand ._prepare_color_vars (brand )
299+ sass_vars_colors , sass_vars_brand , css_vars_brand = (
300+ ThemeBrand ._prepare_color_vars (brand )
301+ )
300302 sass_vars_typography = ThemeBrand ._prepare_typography_vars (brand )
301303
302304 # Theme -----------------------------------------------------------------------
@@ -312,10 +314,10 @@ def __init__(
312314 self ._add_sass_brand_grays ()
313315 self ._add_defaults_brand_bootstrap (brand_bootstrap )
314316 self ._add_defaults_typography (sass_vars_typography )
315- self ._add_defaults_color (sass_vars_colors )
317+ self ._add_defaults_color (sass_vars_colors , sass_vars_brand )
316318
317319 # Brand rules (now in forwards order)
318- self ._add_rules_brand_colors (css_vars_colors )
320+ self ._add_rules_brand_colors (css_vars_brand )
319321 self ._add_sass_brand_rules ()
320322 self ._add_brand_bootstrap_other (brand_bootstrap )
321323
@@ -326,7 +328,9 @@ def _get_theme_name(self, brand: Brand) -> str:
326328 return brand .meta .name .short or brand .meta .name .full or "brand"
327329
328330 @staticmethod
329- def _prepare_color_vars (brand : Brand ) -> tuple [dict [str , str ], list [str ]]:
331+ def _prepare_color_vars (
332+ brand : Brand ,
333+ ) -> tuple [dict [str , str ], dict [str , str ], list [str ]]:
330334 """Colors: create a dictionary of Sass variables and a list of brand CSS variables"""
331335 if not brand .color :
332336 return {}, []
@@ -359,7 +363,9 @@ def _prepare_color_vars(brand: Brand) -> tuple[dict[str, str], list[str]]:
359363 # => CSS var: `--brand-{name}: {value}`
360364 brand_css_vars .append (f"--brand-{ color_var } : { pal_color } ;" )
361365
362- return {** brand_sass_vars , ** mapped }, brand_css_vars
366+ # We keep Sass and Brand vars separate so we can ensure Brand Sass vars come
367+ # first in the compiled Sass definitions.
368+ return mapped , brand_sass_vars , brand_css_vars
363369
364370 @staticmethod
365371 def _prepare_typography_vars (brand : Brand ) -> dict [str , str ]:
@@ -541,8 +547,13 @@ def _add_sass_brand_rules(self):
541547 """
542548 )
543549
544- def _add_defaults_color (self , sass_vars_colors : dict [str , str ]):
550+ def _add_defaults_color (
551+ self ,
552+ sass_vars_colors : dict [str , str ],
553+ sass_vars_brand : dict [str , str ],
554+ ):
545555 self .add_defaults (** sass_vars_colors )
556+ self .add_defaults (** sass_vars_brand )
546557 self .add_defaults ("\n // *---- brand.color ----* //" )
547558
548559 def _add_rules_brand_colors (self , css_vars_colors : list [str ]):
0 commit comments