11import { getRulesByBreakpoint , parseBreakpointsValues } from "./breakpoints" ;
2- import { createGetCssVariable } from "./cssVariable" ;
2+ import {
3+ createGetCssVariable ,
4+ isInvariantAcrossScreenSizes ,
5+ isInvariantAcrossTheme
6+ } from "./cssVariable" ;
37import { objectKeys } from "tsafe/objectKeys" ;
8+ import { assert } from "tsafe/assert" ;
9+ import { is } from "tsafe/is" ;
410
511// Object that represent a set of CSS rules, see https://www.npmjs.com/package/csstype
612// It's the argument of the `css()` function of @emotion/css.
@@ -20,8 +26,6 @@ export function parseTypographyVariants(rawCssCode: string): TypographyVariant[]
2026
2127 const { getCssVariable } = createGetCssVariable ( rawCssCode ) ;
2228
23- console . log ( "TODO use" , getCssVariable ) ;
24-
2529 objectKeys ( rulesByBreakpoint ) . forEach ( breakpoint => {
2630 const mediaQuery = breakpoint === "root" ? undefined : mediaQueryByBreakpoint [ breakpoint ] ;
2731
@@ -34,7 +38,39 @@ export function parseTypographyVariants(rawCssCode: string): TypographyVariant[]
3438
3539 const style : CSSObject = { } ;
3640
37- //TODO: fill up style
41+ rule . declarations . forEach (
42+ declaration =>
43+ ( style [ ( declaration as any ) . property ] = ( ( ) => {
44+ const value = declaration . value as string ;
45+
46+ int: {
47+ const n = parseInt ( value ) ;
48+
49+ if ( isNaN ( n ) ) {
50+ break int;
51+ }
52+
53+ return n ;
54+ }
55+
56+ return value . replace ( / v a r \( ( - - [ ^ ) ] + ) \) / g, ( ...[ , cssVariableName ] ) => {
57+ assert ( is < `--${string } `> ( cssVariableName ) ) ;
58+
59+ const cssVariableValue = getCssVariable ( cssVariableName ) ;
60+
61+ assert (
62+ isInvariantAcrossTheme ( cssVariableValue ) ,
63+ "CSS variable for TypoGraphy that depends on the theme have been introduce, the alg need to be made a bit more sophisticated."
64+ ) ;
65+ assert (
66+ isInvariantAcrossScreenSizes ( cssVariableValue ) ,
67+ "CSS variable for TypoGraphy that depends on screen width have been introduce, the alg need to be made a bit more sophisticated."
68+ ) ;
69+
70+ return cssVariableValue . root . light ;
71+ } ) ;
72+ } ) ( ) )
73+ ) ;
3874
3975 matchedSelectors . forEach ( selector => {
4076 const typographyVariant = typographyVariants . find (
0 commit comments