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

#3

That would indeed be a great improvement in theming, though to make it even greater I’d suggest the ability to

  • Use OKHSL/HSV instead of unintuitive OKLCH
  • Be able to set those as “global” options so that by default you can use the simplest form of
 29 100  57 // okHSL due to global config

for pure red when you global color model is set to OKHSL (no commas, no function names, no parentheses, nothing but pure numbers and whitespace separation). And you could also have a simple switch between hsl/v like so:

  29 100  57 // okHSL due to global config
v 29 100 100 // okHSV
0 Likes

#4

ColorHelper does allow you to enable Okhsl and Okhsv support and convert to and from those spaces as well, much like the OkLCh example above. It even allows you to use an Okhsl and Okhsv color picker.

With that said, OkLCh may not be intuitive for picking colors but excels in other ways. Okhsl and Okhsv is probably best if wanting to pick colors specifically, and only, in sRGB and is kind of a perceptual-ish color space, but it does lose some of the perceptual qualities in the HSL and HSV form.

If there are color spaces you prefer to work in, it may make sense to work in your preferred spaces to pick your palette and then convert them to standard, supported colors.

Of course, more natively supported spaces would make it more convenient for those specifically wishing to work in those spacs.

0 Likes