-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Description
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_oklchin 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 likergb(...)orrgba(...)to access clean numerical representations for further manipulation. -
Missing mathematical methods:
Liquid lacks essential mathematical functions such asatan2,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(...) or rgba(...), 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, and sin would allow developers to perform advanced color manipulations and implement custom filters directly in Liquid.
Potential benefits
- Accessibility: Improved handling of contrast ratios for designs adhering to accessibility standards.
- Better animations: More natural color transitions for dynamic interfaces.
- Alignment with modern CSS standards: OKLCH is already supported natively in modern browsers and CSS workflows.
- Developer empowerment: Easier integration with advanced design systems like Daisy UI and custom implementations.
Call for suggestions
We welcome feedback, ideas, or use cases for these proposed additions.
- Are there other color filters you would like to see in Liquid?
- How would these filters improve your development process?
Example: Usage of color filters in Liquid
{% assign hex_color = "rgb(255, 0, 0)" %}
{% assign oklch_color = hex_color | color_to_oklch %}
{% assign raw_color = hex_color | color_to_raw %}
{{ oklch_color }} <!-- Example output: oklch(0.7035 0.2573 29.2346) -->
{{ raw_color }} <!-- Example output: 255, 0, 0 -->We appreciate your input to help make Liquid more powerful and aligned with modern web development needs!