let convert = await npm("color-convert")
let createChoice = (type, value, input) => {
  return {
    name: type + ": " + value,
    value,
    html: `<div class="h-full w-full p-1 text-xs flex justify-center items-center font-bold" style="background-color:${input}">
      <span>${value}</span>
      </div>`,
  }
}
let conversion = await arg("Enter color:", input => {
  if (input.startsWith("#")) {
    return ["rgb", "cmyk", "hsl"].map(type => {
      let value = convert.hex[type](input).toString()
      return createChoice(type, value, input)
    })
  }
  
  if (input.match(/^[a-z]{2,}/)) {
    return ["rgb", "hex", "cmyk", "hsl"]
      .map(type => {
        try {
          let value =
            convert.keyword[type](input).toString()
          return createChoice(type, value, input)
        } catch (error) {
          return ""
        }
      })
      .filter(Boolean)
  }
  return []
})
setSelectedText(conversion)