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

Add base16 theme and inline it so that it can be swapped for css vars #24

Closed
wants to merge 6 commits into from

Conversation

imownbey
Copy link

Haha okay this is obviously very hacky and not actually ready to merge but I figured I would open just incase it is useful to someone or if you wanted me to actually clean it up. Basically what I did is add a base16 theme which uses simple hex codes. These can then later be swapped out for CSS vars when we are rendering the colors.

Also I realized that lighter will always request themes from your website when deployed because the JSON files do not get included in the nextjs bundle. The only way I could figure out how to get it to be inlined was by directly including it, this actually speeds up rendering a lot (~200ms) and so is probably something worth doing, although it will obviously make the bundle a little bigger. Here I obviously just hardcoded it to the base16 theme since thats the only one I use which would need to be changed.

The output of this can be used like:

const COLOR_TO_CSS_VAR = {
	"#000000": "var(--base16-00)", // - Default Background
	"#000001": "var(--base16-01)", // - Lighter Background (Used for status bars, line number and folding marks)
	"#000002": "var(--base16-02)", // - Selection Background
	"#000003": "var(--base16-03)", // - Comments, Invisibles, Line Highlighting
	"#000004": "var(--base16-04)", // - Dark Foreground (Used for status bars)
	"#000005": "var(--base16-05)", // - Default Foreground, Caret, Delimiters, Operators
	"#000006": "var(--base16-06)", // - Light Foreground (Not often used)
	"#000007": "var(--base16-07)", // - Light Background (Not often used)
	"#000008": "var(--base16-08)", // - Variables, XML Tags, Markup Link Text, Markup Lists, Diff Deleted
	"#000009": "var(--base16-09)", // - Integers, Boolean, Constants, XML Attributes, Markup Link Url
	"#00000A": "var(--base16-0A)", // - Classes, Markup Bold, Search Text Background
	"#00000B": "var(--base16-0B)", // - Strings, Inherited Class, Markup Code, Diff Inserted
	"#00000C": "var(--base16-0C)", // - Support, Regular Expressions, Escape Characters, Markup Quotes
	"#00000D": "var(--base16-0D)", // - Functions, Methods, Attribute IDs, Headings
	"#00000E": "var(--base16-0E)", // - Keywords, Storage, Selector, Markup Italic, Diff Changed
	"#00000F": "var(--base16-0F)", // - Deprecated, Opening/Closing Embedded Language Tags, e.g. <?php ?>
};
... generate highlighted tokens
... and use like:
style={{...token.style, color: COLOR_TO_CSS_VAR[token.style.color]}}

@vercel
Copy link

vercel bot commented May 26, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lighter ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 26, 2023 3:58pm

@@ -32,7 +32,7 @@
"vscode-textmate": "^7.0.0"
},
"scripts": {
"build": "rollup -c",
"build": "rollup -c --inlineDynamicImports",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to generate a single hunk with the theme inlined. I am not sure if it is actually ideal, though.

@pomber
Copy link
Contributor

pomber commented May 26, 2023

Thanks. I'm working on something similar today that I'm planning to merge very soon. I'll publish a material-from-css theme, that could be used as an example for other themes using CSS vars.

@pomber
Copy link
Contributor

pomber commented May 28, 2023

Merged #25

@pomber pomber closed this May 28, 2023
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

Successfully merging this pull request may close these issues.

2 participants