-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Request for improvements: Color Filters in Liquid #1856
Comments
Can you expand more on how you would use We do have the colour drops which expose Would introducing a What about something like this? {% assign color = "rgb(255, 0, 0)" | to_color %}
{{ color.red }} <!-- outputs the red channel of the colour 255 -->
{{ color | color_lighten: 20 }} <!-- "#ff6666" -->
{% assign oklch_color = color | color_to_oklch %} <!-- converts to an "oklch(...)" string -->
{% assign color = "oklch(0.7035 0.2573 29.2346)" | to_color %}
{{ color }} <!-- outputs the colour in its native colour space: "oklch(0.7035 0.2573 29.2346)" -->
{{ color.lightness }} <!-- 0.7035 -->
{{ color | color_lighten: 20 }} <!-- lightens the colour in its native color space: "oklch(0.9035 0.2573 29.2346)" -->
{% assign rgb_color = color | color_to_rgb %} <!-- converts to an "rgb(...)" string --> |
Hi @catlee, The idea of For example:
My objective is to extract color values from my theme settings and inject them easily as CSS variables in the root. {% assign raw_primary_color = settings.primary_color | color_to_rgb | color_to_raw %}
{% assign raw_primary_oklch = settings.primary_color | color_to_oklch | color_to_raw %}
<style>
:root {
--primary-rgb: {{ raw_primary_color }}; /* Output: 255, 0, 255 */
--primary-oklch: {{ raw_primary_oklch }}; /* Output: 0.7035 0.2573 29.2346 */
}
</style> This would generate the following CSS: :root {
--primary-rgb: 255, 0, 255;
--primary-oklch: 0.7035 0.2573 29.2346;
} |
@0xtlt, and what is the benefit of having the raw colour values as CSS variables, as opposed to the full |
Got it! Thanks for explaining! |
Request for improvements: Color Filters in Liquid
Background
Liquid, as the templating language for Shopify, provides a range of filters for working with colors (e.g.,
color_to_hex
,color_to_hsl
,color_to_rgb
). However, the current implementation lacks support for certain advanced color models and operations essential for modern web projects, such as OKLCH.For example, OKLCH has become increasingly popular due to its perceptually uniform color representation, making it highly suitable for animations, color accessibility, and advanced design systems. Design system libs like Daisy UI are already adopting OKLCH.
Current limitations
No support for
color_to_oklch
in Liquid filters:This limits the ability to work with modern color spaces that are increasingly adopted in web development.
Lack of a "raw value" filter for colors:
Developers currently cannot strip wrappers like
rgb(...)
orrgba(...)
to access clean numerical representations for further manipulation.Missing mathematical methods:
Liquid lacks essential mathematical functions such as
atan2
,cos
, andsin
, which are required to manually convert between advanced color spaces (e.g., HEX to OKLCH). This makes custom implementations cumbersome or impossible in plain Liquid.Proposal
1. Add a
color_to_oklch
filter:This filter would enable designers and developers to leverage OKLCH in their Shopify projects. Its adoption would align Shopify's Liquid language with modern CSS practices and empower merchants and developers to create more sophisticated and accessible designs.
2. Add a "raw value" filter for colors:
This filter would remove wrappers like
rgb(...)
orrgba(...)
, providing a clean numerical representation of color values for further manipulation or external use.3. Implement basic mathematical methods:
Adding functions such as
atan2
,cos
, andsin
would allow developers to perform advanced color manipulations and implement custom filters directly in Liquid.Potential benefits
Call for suggestions
We welcome feedback, ideas, or use cases for these proposed additions.
Example: Usage of color filters in Liquid
We appreciate your input to help make Liquid more powerful and aligned with modern web development needs!
The text was updated successfully, but these errors were encountered: