Code Monkey home page Code Monkey logo

Comments (3)

matteo-de-carli avatar matteo-de-carli commented on September 28, 2024 1

That's very kind of you, thank you for that and for this amazing powerhouse of an extension!

from vscode-swissknife.

luisfontes19 avatar luisfontes19 commented on September 28, 2024

Hi @matteo-de-carli

Just to give you an update I'm working on it...

I will only implement a single convertion for HSL and HWB.

Otherwise I would need to implement all possible combinations like HEX to HSL, RGB to HSL, HWB to HSL, etc. And that would be a bit noisy in the menu section

You can always invoke multiple scripts to go from the format you have to the format you need. Also you can create user scripts to do conversions directly from the ones you need, just by invoking the native conversion methods. I'll provide you with a working example for that when I close this one :)

from vscode-swissknife.

luisfontes19 avatar luisfontes19 commented on September 28, 2024

Hi @matteo-de-carli

Sorry for the late reply... I've been focusing on other projects...

Anyway, this is now done and released in 1.8.1

The conversions are to and from Hex (hsl to hex, hex to hsl, etc) otherwise I would end up creating a lot of scripts to cover all possible combinations.

If you want a specific combination you can create your own custom script to achieve this...

Take a look on how to create custom scripts here

Also, I'll leave here the code to do a custom script to do HSL to HWB, in case it helps:

Object.defineProperty(exports, "__esModule", { value: true });

exports.hslToHwb = async (text) => {

}

const scripts = [
  {
    title: "HSL to HWB",
    detail: "Convert HSL color to HWB",
    cb: (context) => {
      const hslToHwb = async (text) => {
        const res = text.match(/hsl\((\d+),\s*(\d+)%,\s*(\d+)%\)?/)
        if (!res) {
          context.informationRoutine(async () => "Invalid HSL Format")
          return text
        }

        res.shift()
        const [h, s, l] = res.map(Number)


        const hex = context.modules.colors.hslToHex(h, s, l)
        const hwb = context.modules.colors.hexToHwb(hex)

        return Promise.resolve(hwb)
      }
      return context.replaceRoutine(hslToHwb)
    }
  }
]

exports.default = scripts;

Also, for reference, the variable context.modules holds a variable for each file in the lib folder and the methods for each are the same you can find in those files :)

from vscode-swissknife.

Related Issues (13)

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.