Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Support CSS variables for theming #236

Open
stereobooster opened this issue Jan 4, 2024 · 4 comments
Open

Feature Request: Support CSS variables for theming #236

stereobooster opened this issue Jan 4, 2024 · 4 comments

Comments

@stereobooster
Copy link

I want to pre-render diagram as SVG and embed it in HTML. And I want to style SVG with the help of CSS variables, so that I can add support for dark theme using CSS.

I tried something like this:

const themeCSS = {
  primaryColor: `rgb(var(--primaryColor))`,
  secondaryColor: `rgb(var(--secondaryColor))`,
  tertiaryColor: `rgb(var(--tertiaryColor))`,

  lineColor: `rgb(var(--lineColor))`,

  primaryLineColor: `rgb(var(--primaryLineColor))`,
  secondaryLineColor: `rgb(var(--secondaryLineColor))`,

  textColor: `rgb(var(--textColor))`,
  primaryTextColor: `rgb(var(--primaryTextColor))`,
  secondaryTextColor: `rgb(var(--secondaryTextColor))`,
  teritaryTextColor: `rgb(var(--teritaryTextColor))`,

  primaryBorderColor: `rgb(var(--primaryBorderColor))`,
  secondaryBorderColor: `rgb(var(--secondaryBorderColor))`,
  tertiaryBorderColor: `rgb(var(--tertiaryBorderColor))`,

  canvasBackground: `rgb(var(--canvasBackground))`,
  background1: `rgb(var(--background1))`,
  lightestBackground: `rgb(var(--lightestBackground))`,
  groupBackground: `rgb(var(--groupBackground))`,

  noteBackground: `rgb(var(--noteBackground))`,
  noteTextColor: `rgb(var(--noteTextColor))`,
};

But it won't work because some diagrams use tinycolor

getConfigFromTheme(t) {
const primaryCorlorInstance = tinycolor(t.primaryColor)
const canvasBgInstance = tinycolor(t.canvasBackground || PALETTE.white)
const isBgLight = canvasBgInstance.isLight()
let relationLineColor: string
if (isBgLight) {
relationLineColor = PALETTE.normalDark
} else {
relationLineColor = PALETTE.white
}
const entityBodyBackground = primaryCorlorInstance.brighten(60).toHexString()
return {
entityBackground: t.primaryColor,
entityBodyBackground,
relationLineColor,
}
},

@stereobooster stereobooster changed the title Support CSS variables for theming Feature Request: Support CSS variables for theming Jan 4, 2024
@hikerpig
Copy link
Owner

hikerpig commented Jan 4, 2024

The core of the implementation does not rely on CSS because it might be rendered inside any container so the diagrams would have to evaluate CSS vars during run-time or detect that it is a CSS var and do nothing, this is too complicated. Plus it also have one canvas renderer.
In your case, I figured that you may need to evaluate CSS vars to actual color string , and pass it to the config of render function.

@hikerpig
Copy link
Owner

hikerpig commented Jan 4, 2024

I'm guessing you want to pre-render SVG from server , and adjust the colors in the browser later ?

@stereobooster
Copy link
Author

stereobooster commented Jan 4, 2024

I'm guessing you want to pre-render SVG from server , and adjust the colors in the browser later ?

Yes. This is the main benefit of Pintora compared to Mermaid - I don't need runtime on the client.

I could as well render two images (light and dark) and use different version depending on the theme, but CSS variables solution seems to be more clear and straightforward (from consumer point of view).

Another pros of using inline SVG:

  • I can use Cmd + F to search through text
  • I can add small (optional) JS to pan/zoom, something like (there are a lot solutions for this):

@hikerpig
Copy link
Owner

hikerpig commented Jan 5, 2024

Yes SVG indeed gives you all the possibilities to manipulation and enhancement.
I can see what you want now but I guess the complexity will hold me for a while for more considerations.

By now I need to focus on the core functionalities and add more tests for classDiagram for 0.7.0 release.

Let's keep this in mind for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants