( Outdated ) Master CSS v2.0 Beta Release #79
Replies: 3 comments 3 replies
-
Amazing Job, can't wait to try it out on my new personal blog. |
Beta Was this translation helpful? Give feedback.
-
Amazing! Add webcharm language service |
Beta Was this translation helpful? Give feedback.
-
Good job on the v2, I see a lot of improvements! Tbh not really in love with the Is it possible to add/extend the config so I can use it like that? Also, when you extend/add new classes to config, will that be reflected in the vs code plugin, it would be cool to have intellisense for custom classes? |
Beta Was this translation helpful? Give feedback.
-
Release & Changelog・Discord
Keep you all waiting! After several weeks of sprinting, the Master CSS v2.0 beta version was finally released. The purpose of the early trial is to gather everyone's reactions, feedback, and even suggestions for generality and stability.
Install the latest Master CSS Beta:
Let's get a sneak peek at some of the new features with the beta notes!
On this page
fg|foreground
forcolor
%
-webkit-text-fill-color
(t|text):color
config.themes
greatly simplifies markup with custom themesconfig.selectors
custom selector tokensfade
->slate
MasterStyleSheet
->MasterCSS
MasterStyle
->Rule
id="master-css"
->title="master"
config.colorSchemes
->config.themes
render()
renderFromHTML()
renderIntoHTML()
fillColorScale()
config
Ahead-of-time compilation
Master.CSS.AOT.with.Webpack.mp4
Before introducing the precompiled mode, let's review the advantages of v1.0.
Master CSS in v1.0 focuses on creating a JIT engine that runs efficiently during runtime. The class name generation cycle only takes
~0.01ms/class
, with the following characteristics:⚡️ No CSS transformer —— Tailwind CSS uses
postcss
andautoprefixer
to pre-transform CSS during build time⚡️ No CSS preprocessor —— Styled Components uses
css-to-react-native
andstylis
to preprocess CSS at runtime⚡️ No hashed class names —— Styled Components hashes classes at runtime to group CSS rules
⚡️ Standalone rules engine container —— Most CSS-in-JS tools such as Styled Components are dependent on the rendering cycle of the framework such as React. When re-rendering, such tools are bound to sacrifice considerable rendering costs during runtime.
The JIT of Master CSS relies on the browser's native API and is only executed when the class name changes, regardless of the framework.
⚡️ Performant rule engine —— The JIT of Master CSS only performs some low-cost execution behaviors, such as comparing class names, parsing class names, and Efficient operation during execution has always been the core consideration of v1.0
⚡️ Parsable structured syntax —— Since Master CSS is a brand new CSS language, there're consistent rules in syntax, and native CSS can be deduced through the same process, which is why it's so lightweight
In v2.0, we directly applied the fast JIT engine to the AOT compilation mode, which works by scanning the compiled
.html
and.js
for strings or template tags (Both tailwind CSS and Windi CSS scan the source code, such as.jsx
,.vue
), through the rule engine to compare whether it's the Master CSS class name and output as a CSS file.We provide integration with mainstream build tools, and you can start Master CSS's AOT compilation mode with almost zero configuration.
✨ Webpack
https://github.com/master-co/css/tree/beta/packages/webpack
✨ Vite
https://github.com/master-co/css/tree/beta/packages/vite
✨ Next.js
https://github.com/master-co/css/tree/beta/packages/webpack
More guides for the frameworks and build tools coming with v2.0...
🥳 Now, start your development server directly, and the AOT compilation engine of Master CSS will run right away!
New syntax
✨ Grouping Selectors
In native CSS, you can use
,
to group selectors:The same is now faster via the class name
The group syntax also supports group selectors
✨ An alternative
fg|foreground
forcolor
Traditionally you'll see
text-blue
/font-blue
naming style and CSS rules are usually:However, the object set by CSS
color
is not only text, it also sets color-related properties such asborder-color
,box-shadow
, so it is not strange to usetext-*
as the name ofcolor
?Even native CSS calling the foreground
color
is too broad, so we providefg|foreground
as an alternative name for you to set the foreground color, and the foreground also happens to echo the backgroundbg|background
:The big change here is that we no longer support
(f|font):color
:You can replace it globally in VSCode with the following Regular Expression:
Replace as
commit
theunstaged
file before execution to avoid irreversible errors during the replacement process.✨ Support setting color transparency via percentage
%
和原生相同,支援透過百分比變更色彩透明度的語法。兩種寫法皆可,因人而異。
<div class="bg:sky-50/.75">v1.0+</div> + <div class="bg:sky-50/75%">v2.0+</div>
✨ Shorthand for
-webkit-text-fill-color
(t|text):color
A new shorthand is provided for text color:
New configuration and management
在 v1.0 時我們提供
Style.extend
讓你自定義配置:Many people said that this configuration is not so friendly and neat, after weeks of design and improvement, we finally have no suspense 😌
Let's take a look at the new
master.css.js
configuration file ✨You may have noticed some new configurations, which we will mention later.
⚙️ Extend and merge configuration
Often you'll want to add additional configuration in an extended way, we have built-in
extend()
method that allows you to extend and merge configuration while keeping the default configuration.merge
objectconcat
arrayExample: Add
'hide-text'
semantic class name and'ocean'
theme tomaster.css.js
, and keep the default values.Import custom configuration in centrally managed
master.js
and initialize:Extended configuration
css.config
results:⚙️ Manual Initial Master CSS
We removed the behavior of automatic initialization of
CommonJS
andESM
output bundles, and instead usednew MasterCSS()
to manually initialize Master CSS with additional custom configuration:Don't forget to include
./master.js
at the entry point of the application, e.g../main.js
⚙️ Automatic Initial Master CSS
In the
IIFE
browser bundle we retain the v1 auto-initialization behavior and provide a new APIwindow.masterCSSConfig
to allow you to customize the configuration directly in HTML:✨
config.themes
greatly simplifies markup with custom themesCustomize
classes
,colors
according to different themes and combine and keep default values:Set the content foreground color according to
light
anddark
:Let's look at an advanced selection, set the key foreground color according to
light
anddark
:✨
config.selectors
custom selector tokensExtend custom selector tokens, merge and keep defaults:
Apply it:
hide:first-child
->hide:first
, and it's recommended to consider the maintainability of the project while reducing.You can also map one selector token to multiple ones, take the default vendor prefix as an example:
Apply it:
Generated CSS rules:
In native CSS, as long as one selector is invalid, the entire rule will not be applied. Master CSS will automatically separate the selector containing the vendor prefix into two rules to generate.
Check out selector tokens for all presets
Built-in theme switching and synchronization
Since the logic of theme switching is similar and is often used, we decided to build this function in v2.0, including:
system
with your OS preferenceslocalStorage
color-scheme
, for example:<html style="color-scheme: dark">
class
, for example:<html class="dark">
✨ Switching themes
✨ Accessing themes
✨ Customing theme configuration
The following configurations are all default values, where
scheme.preference
is the default theme scheme preference of the app.✨ Implement theme switching and UI in React
We provide the useScheme hook, allowing you to painlessly rely on React's rendering mechanism
New packages, upgrades and changes
✨ CSS React
@master/css.react - React hooks for Master CSS
✨ CSS Compiler
@master/css-compiler - Compile Master CSS ahead of time with zero-configuration integration with build tools
✨ CSS Vite
@master/css.vite
✨ CSS Webpack
@master/css.webpack
⬆️ Upgrade Normal CSS
@master/normal.css - Normalize browser's styles. ~500B
Removed support for
--font-mono
,--font-sans
,--font-serif
Please use Master CSS syntax instead to preset global fonts:
⬆️ Upgrade CSS language service
Please upgrade the Master CSS Language Service Extension on VSCode to v2.0
🔄
fade
->slate
Renamed
fade
in colors toslate
lime to match common color names.🔄
MasterStyleSheet
->MasterCSS
🔄
MasterStyle
->Rule
🔄
id="master-css"
->title="master"
🔄
config.colorSchemes
->config.themes
More APIs
Rendering-related APIs are mainly used for Server-side Rendering and Static-site Generation in v1.0. There are no major changes in v2.0, except for partial API optimization.
render()
Pass in an array of class names and return the resulting CSS text.
rendered result:
renderFromHTML()
Pass in HTML text, scan and return to produce CSS text.
rendered result:
renderIntoHTML()
Pass in HTML text → scan and produce CSS text → inject into HTML
<head>
→ return rendered HTML text result.rendered result:
fillColorScale()
Fills undefined level values to
1,2,...99
with the average of adjacent level values.In this way, you can choose not only
blue-40
,blue-50
but alsoblue-67
,blue-72
and other values for better color rendering.config
We export all the default configuration Config, you can access it by:
or imported separately:
Check out all preset configurations
What's next?
docs.master.co
revision: new site-wide search feautre and UIcss.master.co
revision: In the past, we put all our energy into the research and development of the core functions of Master CSS, and many classic features have been buried in the documentation. The communication of the advantages through visual enhancement.button
,card
,tabs
, etc. before the end of the year.Feedbacks here ↓
Beta Was this translation helpful? Give feedback.
All reactions