colorjs / color-namer

:art: Give me a color and I'll name it.
MIT License
441 stars 39 forks source link

adds color-name-list #7

Closed meodai closed 6 years ago

meodai commented 6 years ago

So by adding color-name-list (~16k entries) that this was way to slow.

Would be awesome to preload a list for example something like require('color-namer').load(require('color-name-list'))

What do you think?

Used https://github.com/dtao/nearest-color until now, makes it blazing fast but visually less accurate. (Does not matter that much with that many entries anyway: https://codepen.io/meodai/pen/mEvZRx?editors=0110) click the brush

meodai commented 6 years ago

any thoughts on this @zeke ?

zeke commented 6 years ago

Thanks for the @-mention. Probably would have missed this otherwise.

I'm definitely open to changing the interface for this module. I don't really like the current API, which produces an object with results from different color sets. It's needlessly slow and probably not what most people actually want.

I haven't use this module in a while, but thinking out loud I would image redoing the API something like this:

namer(color[, list])

The list is optional. If you don't specify a list, then the one we think is "best" is used. Maybe that's color-name-list? I don't know.

const namer = require('color-namer')
const names = namer('#FF0000')

Instead of returning an object with keys like roygbiv and pantone, we'd just return an array of colors:

[
  { name: 'red',
    hex: '#FF0000',
    distance: 0
  },{
    name: 'orangered',
    hex: '#FF4500',
    distance: 13.170205025755513
  }, ...

The optional list argument could potentially be a dataset or a nickname:

// dataset
const names = namer('#FF0000', require('color-name-list'))

// nickname
const names = namer('#FF0000', 'roygbiv')

So.. sensible defaults, reduced overall computation, and flexibility to BYOC (bring your own colors).

What do you think?

zeke commented 6 years ago

Alternatively, the list could be an argument to the require module:

const namer = require('color-namer')('roygbiv')
meodai commented 6 years ago

@zeke this sounds very elegant to me. Will you work on that? PS: Should we still have color-name-list be default? Its a pretty big file.

I also think you could have the lists as JSON. No need to module.export = []. Will make it easier to import lists.

zeke commented 6 years ago

Will you work on that?

Maybe? But probably not immediately. Currently traveling and focusing on Electron stuff.

Should we still have color-name-list be default? Its a pretty big file.

Oh wow it is big.

$ ls -alh node_modules/color-name-list/dist | grep json
-rw-r--r--   1 z  staff   587K Sep 11 08:40 colornames.json

Maybe the default should be roygbiv then?

have the lists as JSON

Works for me.

meodai commented 6 years ago

@zeke OK Il create a new pull request. We should close that one ;)