Sublime Forum

Support for the OKLCH color model?

#1

As part of the CSS Color 4 spec, the oklch color model appears to be the one to rule them all.
It carries the readability of hsl but adds predictability, where eg a drop in the lightness value results in the same difference across all hues.
More info: https://evilmartians.com/chronicles/oklch-in-css-why-quit-rgb-hsl

Currently only Safari supports it.
I hope Sublime Text adds support for it internally for e.g. easier and more coherent theming

1 Like

#2

I realize this is not a 100% replacement for what you want, but more mitigation. This is not to invalidate or replace your request.

If you are using the packages ColorHelper and PackageDev, you could work in OkLCh even if Sublime doesn’t recognize it.

ColorHelper is enabled by default in sublime-color-scheme files that are syntax highlighted with PackageDev. Out of the box, neither will recognize Oklab or OkLCh in sublime-color-scheme files, but if you add the following to ColorHelper’s settings, ColorHelper will allow you to get color previews for Oklab and OkLCh and convert back to something that Sublime recognizes. PackageDev will still not recognize the OkLCh and Oklab syntax, but you can at least get color previews and color conversion.

// Settings in here override those in "ColorHelper/color_helper.sublime-settings",

{
    // User rules. These will be appended to the normal `color_rules` unless they
    // share the same name. In that case, a shallow merge will be performed allowing
    // the values of top level keys to be overridden and new keys to be added.
    "user_color_rules": [
        {
            "name": "PackageDev Sublime Schemes/Theme",
            "color_trigger": "(?i)(?:\\b(?<![-#&$])(?:color\\((?!\\s*-)|(?:hsla?|hwb|rgba|oklab|oklch?)\\()|\\b(?<![-#&$])[\\w]{3,}(?![(-])\\b|(?!<&)\\#)"
        },
    ],

    // User color classes. These will be added to the normal `color_classes` unless they
    // share the same name with an existing entry. In that case, a shallow merge will be performed allowing
    // the values of top level keys to be overridden and new keys to be added.
    "user_color_classes": {
        "sublime-colormod": {
            "filters": ["srgb", "hsl", "hwb", "oklab", "oklch"],
            "output": [
                {"space": "srgb", "format": {"hex": true}}, 
                {"space": "srgb", "format": {"comma": true, "precision": 3}},
                {"space": "hsl", "format": {"comma": true, "precision": 3}},
                {"space": "oklab", "format": {"precision": 5}},
                {"space": "oklch", "format": {"precision": 5}}
            ]
        },
    }
}

Sublime will still apply color blending changes in sRGB and will adjust saturation and lightness in HSL, but you can at least more easily convert to and manually adjust values within OkLCh allowing you have better hue preservation if manually adjusting things like lightness, etc.

1 Like