{"id":16125699,"url":"https://github.com/dy/color-ranger","last_synced_at":"2026-02-15T02:32:29.903Z","repository":{"id":21895923,"uuid":"25219815","full_name":"dy/color-ranger","owner":"dy","description":"Render range for a color space. Useful in color pickers.","archived":false,"fork":false,"pushed_at":"2015-06-14T19:27:38.000Z","size":4476,"stargazers_count":5,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-08T13:39:52.026Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://cdn.rawgit.com/dfcreative/color-ranger/master/test/index.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-14T18:11:26.000Z","updated_at":"2019-07-23T18:58:33.000Z","dependencies_parsed_at":"2022-09-17T00:50:42.908Z","dependency_job_id":null,"html_url":"https://github.com/dy/color-ranger","commit_stats":null,"previous_names":["dfcreative/color-ranger","dfcreative/color-range"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dy/color-ranger","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fcolor-ranger","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fcolor-ranger/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fcolor-ranger/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fcolor-ranger/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dy","download_url":"https://codeload.github.com/dy/color-ranger/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fcolor-ranger/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29465714,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-15T01:01:38.065Z","status":"online","status_checked_at":"2026-02-15T02:00:07.449Z","response_time":118,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T21:30:46.673Z","updated_at":"2026-02-15T02:32:29.874Z","avatar_url":"https://github.com/dy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cimg src=\"https://cdn.rawgit.com/dfcreative/color-ranger/design/logo.png\" height=\"190\"/\u003e\n\n\u003ccode\u003e**C O L O R − R A N G E R**\u003c/code\u003e\u0026nbsp; renders a color range for a color in rectangular or polar coordinate system by manipulating _ImageData_’s buffer. It is primarily needed for building color pickers.\n\n[Test \u0026 demo](https://cdn.rawgit.com/dfcreative/color-ranger/master/test/index.html), [color picker](https://github.com/dfcreative/picky).\n\n[![alt](https://travis-ci.org/dfcreative/color-ranger.svg?branch=master)](https://travis-ci.org/dfcreative/color-ranger)\n[![alt](https://codeclimate.com/github/dfcreative/color-ranger/badges/gpa.svg)](https://codeclimate.com/github/dfcreative/color-ranger)\n[![alt](https://david-dm.org/dfcreative/color-ranger.svg)](https://david-dm.org/dfcreative/color-ranger)\n[![unstable](http://badges.github.io/stability-badges/dist/unstable.svg)](http://github.com/badges/stability-badges)\n\n\n## Use\n\n[![NPM](https://nodei.co/npm/color-ranger.png?mini=true)](https://nodei.co/npm/color-ranger/)\n\n\n```js\nvar colorRanger = require('color-ranger');\n\n//create a canvas\nvar canvas = document.createElement('canvas');\ncanvas.width = 50;\ncanvas.height = 50;\nvar context = canvas.getContext('2d');\nvar imageData = context.getImageData(0, 0, canvas.width, canvas.height);\n\n//render\nimageData.data = colorRanger.render([0, 255, 255], imageData.data, {\n\ttype: 'polar',\n\tspace: 'hsl',\n\tchannel: [0, 1]\n});\n\n//put image data back to canvas\ncontext.putImageData(imageData, 0, 0);\ndocument.documentElement.style.background = 'url(' + canvas.toDataURL() + ') 0 0 / cover';\n```\n\n\n## API\n\n### ranger.render(color, buffer, options)\n\n\u003cimg src=\"https://cdn.rawgit.com/dfcreative/color-ranger/design/rect.png\" height=\"128\"/\u003e\n\u003cimg src=\"https://cdn.rawgit.com/dfcreative/color-ranger/design/polar.png\" height=\"132\"/\u003e\n\nRender rectangular or polar range into an imageData’s buffer. Size of the final image is taken such that it fills the whole imageData area.\n\n| Parameter | Type | Description |\n|----|----|----|\n| `color` | _Array_ | An array of input values, defined in `sourceSpace` - rgb by default. |\n| `buffer` | _Uint8ClampedArray_ | An `imageData.data` object to which render the range. |\n| `options.space` | _string_ | A color space name for the range taken from the [color-space](https://github.com/dfcreative/color-space/) module. E. g. `'hsl'`. |\n| `options.channel` | _Array_ | An array of x/y space channel indexes. E. g. `[0,2]` from `'hsv'` are _hue_ and _value_ channels. One of the channels can be omitted, e. g. `[null, 1]` means render saturation by y-axis. |\n| `options.min`, `options.max` | _Array_ | Arrays of left and right values for the range, corresponding to the channels in x/y axis. |\n| `options.type` | _String_ | Render whether `polar`, `rect` or `chess`. |\n| `options.sourceSpace` | _String_ | If you have `color` in a space different from `rgb`, pass the sourceSpace. |\n\n\n### ranger.chess(colorA, colorB, buffer)\n\n\u003cimg src=\"https://cdn.rawgit.com/dfcreative/color-ranger/design/alpha.png\"/\u003e\n\nRender a chess grid, useful for transparency grid image rendering. Grid size is automatically figured out from the `imageData` size.\n\n| Parameter | Type | Description |\n|----|----|----|\n| `colorA` | _Array_ | Black cell color. |\n| `colorB` | _Array_ | White cell color. |\n| `buffer` | _Uint8ClampedArray_ | An `ImageData` object into which to render grid. |\n\n\n### require('color-ranger/worker')\n\nReturn worker for [workerify](http://github.com/substack/workerify), able to render range in a background.\n\n```js\nvar work = require('webworkify');\nvar worker = work(require('color-ranger/worker'));\n\nworker.addEvenListener('message', function(evt){\n\tif (evt.data.id !== 1) return;\n\n\t//image data buffer is returned as `event.data.data`\n\timageData.data = evt.data.data;\n\tcontext.putImageData(imageData, 0, 0);\n\n\tdocument.body.style.background = 'url(' + canvas.toDataURL() + ') 0 0 / cover';\n});\n\nworker.postMessage({\n\tcolor: [255, 255, 255],\n\ttype: 'polar',\n\tspace: 'lab',\n\tsourceSpace: 'rgb'\n\tchannel: [0,1],\n\tmax: [360, 100],\n\tmin: [0, 100],\n\tdata: imageData,\n\tid: 1\n});\n```\n\nWorker gets all the parameters of `.render`, with additional option `id`, an id of request to identify in response.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Fcolor-ranger","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdy%2Fcolor-ranger","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Fcolor-ranger/lists"}