public virtual string BuildMediaScheme(ThemeValue theme)
        {
            var scheme = theme.IsDark() ? "dark" : "light";

            return(@$ "@media (prefers-color-scheme: {scheme}) {{
                {BuildScheme(theme)}
            }}");
Esempio n. 2
0
        public virtual string BuildScheme(ThemeValue theme)
        {
            var palette = theme.Palette;

            string ToContrastText(string color)
            {
                return(color.ToContrastText(palette.ContrastThreshold));
            }

            var isDark = theme.IsDark();

            return(Wrap($@"
            --theme-mode-dark: {(isDark ? 1 : 0).ToString(CultureInfo.InvariantCulture)};

            --theme-palette-common-background: {(isDark ? palette.Common.White : palette.Common.Black).ToString(CultureInfo.InvariantCulture)};
            {Variables("--theme-palette-common", palette.Common.Custom)}

            --theme-palette-text-primary: {palette.Text.Primary.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-text-secondary: {palette.Text.Secondary.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-text-disabled: {palette.Text.Disabled.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-text-hint: {palette.Text.Hint.ToString(CultureInfo.InvariantCulture)};
            {Variables("--theme-palette-text", palette.Text.Custom)}

            --theme-palette-background-paper: {palette.Background.Paper.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-background-default: {palette.Background.Default.ToString(CultureInfo.InvariantCulture)};
            {Variables("--theme-palette-background", palette.Background.Custom)}

            --theme-palette-action-active: {palette.Action.Active.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-action-hover: {palette.Action.Hover.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-action-hover-opacity: {palette.Action.HoverOpacity.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-action-selected: {palette.Action.Selected.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-action-disabled: {palette.Action.Disabled.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-action-disabled-background: {palette.Action.DisabledBackground.ToString(CultureInfo.InvariantCulture)};
            {Variables("--theme-palette-action", palette.Action.Custom)}

            --theme-palette-primary-main: {palette.Primary.Main.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-primary-light: {palette.Primary.Light.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-primary-dark: {palette.Primary.Dark.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-primary-contrast-text: {palette.Primary.ContrastText.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-primary-alternate: {(isDark ? palette.Primary.Light : palette.Primary.Dark).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-primary-hover: {palette.Primary.Main.Fade(palette.Action.HoverOpacity).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-primary-background: {(isDark ? palette.Primary.Main.Darken(0.5m) : palette.Primary.Main.Lighten(0.62m)).ToString(CultureInfo.InvariantCulture)};
            {Variables("--theme-palette-primary", palette.Primary.Custom)}

            --theme-palette-secondary-main: {palette.Secondary.Main.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-secondary-light: {palette.Secondary.Light.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-secondary-dark: {palette.Secondary.Dark.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-secondary-contrast-text: {palette.Secondary.ContrastText.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-secondary-hover: {palette.Secondary.Main.Fade(palette.Action.HoverOpacity).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-secondary-border: {palette.Secondary.Main.Fade(0.5m).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-secondary-background:  {(isDark ? palette.Secondary.Main.Darken(0.5m) : palette.Secondary.Main.Lighten(0.62m)).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-secondary-alternate: {(isDark ? palette.Secondary.Light : palette.Secondary.Dark).ToString(CultureInfo.InvariantCulture)};
            {Variables("--theme-palette-secondary", palette.Secondary.Custom)}

            --theme-palette-error-main: {palette.Error.Main.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-error-light: {palette.Error.Light.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-error-dark: {palette.Error.Dark.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-error-contrast-text: {palette.Error.ContrastText.ToString(CultureInfo.InvariantCulture)};
            {Variables("--theme-palette-error", palette.Error.Custom)}

            --theme-palette-divider: {palette.Divider.ToString(CultureInfo.InvariantCulture)};

            --theme-palette-grey50: {palette.Grey.X50.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey50-contrast-text: {ToContrastText(palette.Grey.X50).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey100: {palette.Grey.X100.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey100-contrast-text: {ToContrastText(palette.Grey.X100).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey200: {palette.Grey.X200.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey200-contrast-text: {ToContrastText(palette.Grey.X200).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey300: {palette.Grey.X300.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey300-contrast-text: {ToContrastText(palette.Grey.X300).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey400: {palette.Grey.X400.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey400-contrast-text: {ToContrastText(palette.Grey.X400).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey500: {palette.Grey.X500.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey500-contrast-text: {ToContrastText(palette.Grey.X500).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey600: {palette.Grey.X600.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey600-contrast-text: {ToContrastText(palette.Grey.X600).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey700: {palette.Grey.X700.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey700-contrast-text: {ToContrastText(palette.Grey.X700).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey800: {palette.Grey.X800.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey800-contrast-text: {ToContrastText(palette.Grey.X800).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey900: {palette.Grey.X900.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey900-contrast-text: {ToContrastText(palette.Grey.X900).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-greyA100: {palette.Grey.A100.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-greyA100-contrast-text: {ToContrastText(palette.Grey.A100).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-greyA200: {palette.Grey.A200.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-greyA200-contrast-text: {ToContrastText(palette.Grey.A200).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-greyA400: {palette.Grey.A400.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-greyA400-contrast-text: {ToContrastText(palette.Grey.A400).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-greyA700: {palette.Grey.A700.ToString(CultureInfo.InvariantCulture)};
            --theme-palette-greyA700-contrast-text: {ToContrastText(palette.Grey.A700).ToString(CultureInfo.InvariantCulture)};

            --theme-palette-grey-contrast-text-default: {ToContrastText(isDark ? palette.Grey.X900 : palette.Grey.X100).ToString(CultureInfo.InvariantCulture)};
            --theme-palette-grey-background-default: {(isDark ? palette.Grey.X900 : palette.Grey.X100).ToString(CultureInfo.InvariantCulture)};

            --theme-custom-light-or-dark: {palette.Custom.LightOrDark.ToString(CultureInfo.InvariantCulture)};
            --theme-custom-light-or-dark-contrast-text: {palette.Custom.LightOrDarkContrastText.ToString(CultureInfo.InvariantCulture)};
            --theme-custom-content-background-color: {palette.Custom.ContentBackground.ToString(CultureInfo.InvariantCulture)};
            --theme-custom-content-background-default: {palette.Custom.ContentBackgroundDefault.ToString(CultureInfo.InvariantCulture)};
            --theme-custom-palette-common-alternate: {palette.Custom.PaletteCommonAlternate.ToString(CultureInfo.InvariantCulture)};
            --theme-custom-palette-opacity: {palette.Custom.PaletteOpacity.ToString(CultureInfo.InvariantCulture)};
            --theme-custom-layout-backward: {palette.Custom.LayoutBackward.ToString(CultureInfo.InvariantCulture)};
            --theme-custom-layout-forward: {palette.Custom.LayoutForward.ToString(CultureInfo.InvariantCulture)};
            --theme-custom-palette-primary-main: {palette.Custom.PrimaryMain.ToString(CultureInfo.InvariantCulture)};
            --theme-custom-palette-primary-contrast-text: {palette.Custom.PrimaryContrastText.ToString(CultureInfo.InvariantCulture)};

            {Styles(theme)}
          "));
        }