color-octree
Advanced tools
Comparing version 1.0.1 to 1.1.0
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _slicedToArray(arr, i) { | ||
@@ -53,10 +55,15 @@ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); | ||
const hexToRgb = hex => Array.from({ | ||
length: 3 | ||
}, (_, i) => parseInt(hex.slice(2 * i, 2 * i + 2), 16)); | ||
const hexToRgb = hex => { | ||
const h = parseHex(hex); | ||
return Array.from({ | ||
length: 3 | ||
}, (_, i) => parseInt(h.slice(2 * i, 2 * i + 2), 16)); | ||
}; | ||
const hexToOctants = hex => { | ||
const h = parseHex(hex); | ||
const _Array$from = Array.from({ | ||
length: 3 | ||
}, (_, i) => parseInt(hex.slice(2 * i, 2 * i + 2), 16).toString(2).padStart(8, 0)), | ||
}, (_, i) => parseInt(h.slice(2 * i, 2 * i + 2), 16).toString(2).padStart(8, 0)), | ||
_Array$from2 = _slicedToArray(_Array$from, 3), | ||
@@ -71,3 +78,2 @@ r = _Array$from2[0], | ||
}; | ||
class ColorOctant { | ||
@@ -80,3 +86,3 @@ constructor(path = []) { | ||
this.closest = hex => { | ||
const octants = hexToOctants(parseHex(hex)); | ||
const octants = hexToOctants(hex); | ||
let child = this; | ||
@@ -90,7 +96,7 @@ | ||
if (child.colors.length === 1) return child.colors[0]; | ||
const targ = hexToRgb(parseHex(hex)); | ||
const targ = hexToRgb(hex); | ||
let maxDist = Infinity, | ||
closest; | ||
child.colors.forEach(col => { | ||
const c = hexToRgb(parseHex(col.hex)); | ||
const c = hexToRgb(col.hex); | ||
const d = dist(c, targ); | ||
@@ -117,3 +123,3 @@ | ||
name, | ||
octants: hexToOctants(parseHex(hex)) | ||
octants: hexToOctants(hex) | ||
})); | ||
@@ -154,2 +160,3 @@ } | ||
module.exports = ColorOctant; | ||
exports.hexToOctants = hexToOctants; | ||
exports.default = ColorOctant; |
@@ -51,10 +51,15 @@ function _slicedToArray(arr, i) { | ||
const hexToRgb = hex => Array.from({ | ||
length: 3 | ||
}, (_, i) => parseInt(hex.slice(2 * i, 2 * i + 2), 16)); | ||
const hexToRgb = hex => { | ||
const h = parseHex(hex); | ||
return Array.from({ | ||
length: 3 | ||
}, (_, i) => parseInt(h.slice(2 * i, 2 * i + 2), 16)); | ||
}; | ||
const hexToOctants = hex => { | ||
const h = parseHex(hex); | ||
const _Array$from = Array.from({ | ||
length: 3 | ||
}, (_, i) => parseInt(hex.slice(2 * i, 2 * i + 2), 16).toString(2).padStart(8, 0)), | ||
}, (_, i) => parseInt(h.slice(2 * i, 2 * i + 2), 16).toString(2).padStart(8, 0)), | ||
_Array$from2 = _slicedToArray(_Array$from, 3), | ||
@@ -69,3 +74,2 @@ r = _Array$from2[0], | ||
}; | ||
class ColorOctant { | ||
@@ -78,3 +82,3 @@ constructor(path = []) { | ||
this.closest = hex => { | ||
const octants = hexToOctants(parseHex(hex)); | ||
const octants = hexToOctants(hex); | ||
let child = this; | ||
@@ -88,7 +92,7 @@ | ||
if (child.colors.length === 1) return child.colors[0]; | ||
const targ = hexToRgb(parseHex(hex)); | ||
const targ = hexToRgb(hex); | ||
let maxDist = Infinity, | ||
closest; | ||
child.colors.forEach(col => { | ||
const c = hexToRgb(parseHex(col.hex)); | ||
const c = hexToRgb(col.hex); | ||
const d = dist(c, targ); | ||
@@ -115,3 +119,3 @@ | ||
name, | ||
octants: hexToOctants(parseHex(hex)) | ||
octants: hexToOctants(hex) | ||
})); | ||
@@ -153,1 +157,2 @@ } | ||
export default ColorOctant; | ||
export { hexToOctants }; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.colorutil = factory()); | ||
}(this, (function () { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.colorutil = {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
@@ -57,10 +57,15 @@ function _slicedToArray(arr, i) { | ||
const hexToRgb = hex => Array.from({ | ||
length: 3 | ||
}, (_, i) => parseInt(hex.slice(2 * i, 2 * i + 2), 16)); | ||
const hexToRgb = hex => { | ||
const h = parseHex(hex); | ||
return Array.from({ | ||
length: 3 | ||
}, (_, i) => parseInt(h.slice(2 * i, 2 * i + 2), 16)); | ||
}; | ||
const hexToOctants = hex => { | ||
const h = parseHex(hex); | ||
const _Array$from = Array.from({ | ||
length: 3 | ||
}, (_, i) => parseInt(hex.slice(2 * i, 2 * i + 2), 16).toString(2).padStart(8, 0)), | ||
}, (_, i) => parseInt(h.slice(2 * i, 2 * i + 2), 16).toString(2).padStart(8, 0)), | ||
_Array$from2 = _slicedToArray(_Array$from, 3), | ||
@@ -75,3 +80,2 @@ r = _Array$from2[0], | ||
}; | ||
class ColorOctant { | ||
@@ -84,3 +88,3 @@ constructor(path = []) { | ||
this.closest = hex => { | ||
const octants = hexToOctants(parseHex(hex)); | ||
const octants = hexToOctants(hex); | ||
let child = this; | ||
@@ -94,7 +98,7 @@ | ||
if (child.colors.length === 1) return child.colors[0]; | ||
const targ = hexToRgb(parseHex(hex)); | ||
const targ = hexToRgb(hex); | ||
let maxDist = Infinity, | ||
closest; | ||
child.colors.forEach(col => { | ||
const c = hexToRgb(parseHex(col.hex)); | ||
const c = hexToRgb(col.hex); | ||
const d = dist(c, targ); | ||
@@ -121,3 +125,3 @@ | ||
name, | ||
octants: hexToOctants(parseHex(hex)) | ||
octants: hexToOctants(hex) | ||
})); | ||
@@ -158,4 +162,7 @@ } | ||
return ColorOctant; | ||
exports.hexToOctants = hexToOctants; | ||
exports.default = ColorOctant; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
19
index.js
@@ -5,6 +5,10 @@ const parseHex = hex => hex.length < 6 ? hex[hex.length-3].repeat(2)+hex[hex.length-2].repeat(2)+hex[hex.length-1].repeat(2) : hex.slice(-6); | ||
const hexToRgb = hex => Array.from({length:3}, (_,i)=>parseInt(hex.slice(2*i, 2*i+2), 16)); | ||
const hexToRgb = hex => { | ||
const h = parseHex(hex); | ||
return Array.from({length:3}, (_,i)=>parseInt(h.slice(2*i, 2*i+2), 16)); | ||
} | ||
const hexToOctants = hex => { | ||
const [r,g,b] = Array.from({length:3}, (_,i)=>parseInt(hex.slice(2*i, 2*i+2), 16).toString(2).padStart(8,0)) | ||
export const hexToOctants = hex => { | ||
const h = parseHex(hex); | ||
const [r,g,b] = Array.from({length:3}, (_,i)=>parseInt(h.slice(2*i, 2*i+2), 16).toString(2).padStart(8,0)) | ||
return Array.from({length:8}, (_,i) => r[i]+g[i]+b[i]); | ||
@@ -21,3 +25,3 @@ } | ||
this.closest = hex => { | ||
const octants = hexToOctants(parseHex(hex)); | ||
const octants = hexToOctants(hex); | ||
let child = this; | ||
@@ -31,6 +35,6 @@ for (const octant of octants) { | ||
if (child.colors.length === 1) return child.colors[0]; | ||
const targ = hexToRgb(parseHex(hex)) | ||
const targ = hexToRgb(hex) | ||
let maxDist = Infinity, closest; | ||
child.colors.forEach(col => { | ||
const c = hexToRgb(parseHex(col.hex)); | ||
const c = hexToRgb(col.hex); | ||
const d = dist(c, targ); | ||
@@ -48,3 +52,3 @@ if (d < maxDist) { | ||
addAll(colors) { | ||
colors.forEach(({hex, name}) => this.add({hex, name, octants: hexToOctants(parseHex(hex))})); | ||
colors.forEach(({hex, name}) => this.add({hex, name, octants: hexToOctants(hex)})); | ||
} | ||
@@ -72,1 +76,2 @@ | ||
} | ||
{ | ||
"name": "color-octree", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Get closest hex color", | ||
@@ -5,0 +5,0 @@ "main": "dist/cjs.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15064
446