GithubHelp home page GithubHelp logo

meduzen / true-hsl.scss Goto Github PK

View Code? Open in Web Editor NEW
11.0 3.0 3.0 5 KB

Let HSL stay HSL in SCSS.

License: Do What The F*ck You Want To Public License

SCSS 100.00%
css scss sass scss-function hsl-color hsl hsla

true-hsl.scss's People

Contributors

meduzen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

true-hsl.scss's Issues

(info) This package and Dart SASS

My initial plan for this package was to not upgrade it to Dart SASS. But unfortunately, hsl and hsla remain global (despite the existence of a namespaced color module with color.hue(), color.saturate() and color.lightness()) and their behavior is still chaotic.

Current algorithm and examples

Basically, the current result of using hsl and hsla seems to follow this decision tree:

  • if there’s one CSS custom property in hsl/hsla, it’s left untouched by SASS;
  • otherwise, it does the following:
    • add missing deg to the hue;
    • before SASS 1.52.1: if the hue angle unit is turn or rad, it replaces it by deg without converting;
    • add missing % in saturation and lightness;
    • check the number for the alpha channel:
      • if hsl with alpha channel, replaces hsl by hsla;
      • if hsla without alpha channel, replaces hsla by hsl.

This matches phase 1 of 3 (or 2 of 3 for the hue) in the deprecation plan for color units, leading to these outputs:

.class {

  color: hsla(34deg, 20%, 40%); // ✔ valid
     // `hsl(34deg, 20%, 40%)`

  color: hsla(34, 20%, 40%); // ✔ valid
     // `hsl(34deg, 20%, 40%)`

  color: hsl(34, 35%, 92%, 0.2); // ✔ valid
     // `hsla(34deg, 35%, 92%, 0.2)`

  color: hsla(.5turn, 20%, 40%);
     //  `hsl(180deg, 20%, 40%)` // ✔ valid since SASS 1.52.1
     //  `hsl(1deg, 20%, 40%)` // ❌ invalid, should be `180deg`

  color: hsl(34, 20, 40, var(--some-number, 'aa')); // ❌ invalid, missing `deg` and `%`
     // `hsla(34, 20, 40, var(--some-number, 'aa'))`

  color: hsl(34deg, 20, 40, .8); // ✔ valid, warns about missing `%` (deprecated)
     // `hsla(34deg, 20%, 40%, 0.8)`

  color: hsla(34 35 92); // ✔ valid, warns about missing `%` (deprecated)
     // `hsl(34deg, 35%, 92%)`

  color: hsl(34 35 92 / .5); // ✔ valid, warns about missing `%` (deprecated)
     // `hsla(34deg, 35%, 92%, 0.5)`

  color: hsl(34 35 92 / var(--some-number)); // ❌ invalid, missing `deg` and `%`
     // `hsl(34 35 92/var(--some-number))`
}

For these reasons, this package is (unfortunately) still useful in Dart SASS. No matter the deprecation phase, for now there’s no decent plan for hsl and hsla.

Currently, hsl.scss perfectly works both @import and @use, but its documentation should be improved to reflect the current state of hsl/hsla in SASS.

Related tasks:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.