@palett/util-fluo
Advanced tools
Comparing version 0.3.7 to 0.4.0-alpha.0
@@ -6,9 +6,2 @@ 'use strict'; | ||
var enumCheckLevels = require('@typen/enum-check-levels'); | ||
var comparer = require('@aryth/comparer'); | ||
var convert = require('@palett/convert'); | ||
var dye = require('@palett/dye'); | ||
var boundVector = require('@aryth/bound-vector'); | ||
var vectorMapper = require('@vect/vector-mapper'); | ||
var numStrict = require('@typen/num-strict'); | ||
var vectorZipper = require('@vect/vector-zipper'); | ||
@@ -19,217 +12,2 @@ const NL = { | ||
/** | ||
* Create a dye from a hsl array | ||
* @param {[number,number,number]} hsl | ||
* @returns {function} | ||
*/ | ||
const hslToDye = hsl => { | ||
var _ref, _hsl; | ||
return _ref = (_hsl = hsl, convert.hslToRgb(_hsl)), dye.Dye(_ref); | ||
}; | ||
const leverage = ([h, s, l], base) => [h / base, s / base, l / base]; | ||
const scale = (x, min, lever, base, ceil) => comparer.min((comparer.max(x, min) - min) * lever + base, ceil); | ||
const projectDye = function (x) { | ||
var _ref; | ||
const { | ||
min: m, | ||
lever: [rH, rS, rL], | ||
base: [mH, mS, mL] | ||
} = this; | ||
return _ref = [scale(x, m, rH, mH, 360), scale(x, m, rS, mS, 100), scale(x, m, rL, mL, 100)], hslToDye(_ref); | ||
}; | ||
/** | ||
* | ||
* @param {{min:number,dif:number}} valueLeap | ||
* @param {{min:number[],dif:number[]}} colorLeap | ||
* @returns {function(*):function} | ||
* @constructor | ||
*/ | ||
const Projector = (valueLeap, colorLeap) => projectDye.bind({ | ||
min: valueLeap.min, | ||
lever: leverage(colorLeap.dif, valueLeap.dif), | ||
base: colorLeap.min | ||
}); | ||
// from x => typeof x | ||
const STR = 'string'; | ||
const parseHsl = color => { | ||
var _color; | ||
return typeof color === STR ? (_color = color, convert.hexToHsl(_color)) : color; | ||
}; | ||
/** | ||
* | ||
* @param max | ||
* @param min | ||
* @returns {{dif: [number,number,number], min: [number,number,number]}} | ||
*/ | ||
const colorBound = ([maxH, maxS, maxL], [minH, minS, minL]) => ({ | ||
min: [minH, minS, minL], | ||
dif: [maxH - minH, maxS - minS, maxL - minL] | ||
}); | ||
const presetToLeap = ({ | ||
max, | ||
min | ||
}) => { | ||
var _max, _min; | ||
return colorBound((_max = max, parseHsl(_max)), (_min = min, parseHsl(_min))); | ||
}; | ||
const presetToFlat = ({ | ||
na | ||
}) => { | ||
var _ref, _na; | ||
return _ref = (_na = na, parseHsl(_na)), hslToDye(_ref); | ||
}; | ||
/** | ||
* | ||
* @param preset | ||
* @return {{someDif: boolean, dye:Function, leap:{min:*[],dif:*[]}}} | ||
*/ | ||
const presetParser = preset => { | ||
var _preset, _preset2; | ||
const leap = (_preset = preset, presetToLeap(_preset)); | ||
return { | ||
leap, | ||
dye: (_preset2 = preset, presetToFlat(_preset2)), | ||
someDif: leap.dif.some(n => n) | ||
}; | ||
}; | ||
function Dyer(valueBound, positivePreset, negativePreset) { | ||
const { | ||
colorant, | ||
zipper | ||
} = this; | ||
const { | ||
max, | ||
min | ||
} = valueBound, | ||
x = presetParser(positivePreset), | ||
y = presetParser(negativePreset); // ({ | ||
// bound: { max, min }, | ||
// xdyeConf: { dif: max, min: 0 }, | ||
// ydyeConf: { dif: 0 - min, min: min }, | ||
// zipper: !!zipper | ||
// }) |> delogger | ||
if (max === min) { | ||
const prim = max >= 0 ? x : y; | ||
const dye = hslToDye(prim.leap.min); | ||
return zipper ? colorant ? (v, n) => numStrict.isNumeric(n) ? dye : prim.dye : (v, n) => { | ||
var _v, _v2; | ||
return numStrict.isNumeric(n) ? (_v = v, dye(_v)) : (_v2 = v, prim.dye(_v2)); | ||
} : colorant ? v => numStrict.isNumeric(v) ? dye : prim.dye : v => { | ||
var _v3, _v4; | ||
return numStrict.isNumeric(v) ? (_v3 = v, dye(_v3)) : (_v4 = v, prim.dye(_v4)); | ||
}; | ||
} else { | ||
const xdye = Projector({ | ||
dif: max, | ||
min: 0 | ||
}, x.leap); | ||
const ydye = Projector({ | ||
dif: 0 - min, | ||
min: min | ||
}, y.leap); | ||
return zipper ? colorant ? (v, n) => numStrict.isNumeric(n) ? n >= 0 ? xdye(n) : ydye(n) : x.dye : (v, n) => { | ||
var _v5, _v6, _v7; | ||
return numStrict.isNumeric(n) ? n >= 0 ? (_v5 = v, xdye(n)(_v5)) : (_v6 = v, ydye(n)(_v6)) : (_v7 = v, x.dye(_v7)); | ||
} : colorant ? v => numStrict.isNumeric(v) ? v >= 0 ? xdye(v) : ydye(v) : x.dye : v => { | ||
var _v8, _v9, _v10; | ||
return numStrict.isNumeric(v) ? v >= 0 ? (_v8 = v, xdye(v)(_v8)) : (_v9 = v, ydye(v)(_v9)) : (_v10 = v, x.dye(_v10)); | ||
}; | ||
} | ||
} | ||
/** | ||
* | ||
* @param {*[]} items | ||
* @param {Object} positivePreset | ||
* @param {Object} negativePreset | ||
* @returns {function[]|*[]} | ||
*/ | ||
const dyemap = function (items, positivePreset, negativePreset) { | ||
const { | ||
colorant = true, | ||
mapper = vectorMapper.mapper, | ||
bound = boundVector.bound | ||
} = this; | ||
const valueBound = bound.call(NL, items); | ||
const dye = Dyer.call({ | ||
colorant | ||
}, valueBound, positivePreset, negativePreset); | ||
return mapper(items, dye); | ||
}; | ||
/** | ||
* | ||
* @param {*[]} items | ||
* @param {*[]} values | ||
* @param {Object} positivePreset | ||
* @param {Object} negativePreset | ||
* @returns {Function[]|*[]} | ||
*/ | ||
const dyezip = function (items, values, positivePreset, negativePreset) { | ||
const { | ||
colorant = true, | ||
zipper = vectorZipper.zipper, | ||
bound = boundVector.bound | ||
} = this; | ||
const valueBound = bound.call(NL, values); | ||
const dye = Dyer.call({ | ||
colorant, | ||
zipper | ||
}, valueBound, positivePreset, negativePreset); | ||
return zipper(items, values, dye); | ||
}; | ||
/** | ||
* | ||
* @param {*[]} items | ||
* @param {*[]} values | ||
* @param positivePreset | ||
* @param negativePreset | ||
* @returns {function[]|*[]} | ||
*/ | ||
const fluo = function (items, values, positivePreset, negativePreset) { | ||
const { | ||
mapper, | ||
zipper, | ||
bound, | ||
colorant = false | ||
} = this; | ||
return values ? dyezip.call({ | ||
colorant, | ||
zipper, | ||
bound | ||
}, items, values, positivePreset, negativePreset) : dyemap.call({ | ||
colorant, | ||
mapper, | ||
bound | ||
}, items, positivePreset, negativePreset); | ||
}; | ||
const extractBound = objectWithBound => { | ||
@@ -243,12 +21,2 @@ return objectWithBound ? { | ||
exports.NL = NL; | ||
exports.Projector = Projector; | ||
exports.dyemap = dyemap; | ||
exports.dyezip = dyezip; | ||
exports.extractBound = extractBound; | ||
exports.fluo = fluo; | ||
exports.fluoZip = fluo; | ||
exports.hslToDye = hslToDye; | ||
exports.leverage = leverage; | ||
exports.parseHsl = parseHsl; | ||
exports.presetToFlat = presetToFlat; | ||
exports.presetToLeap = presetToLeap; |
import { STRICT } from '@typen/enum-check-levels'; | ||
import { min, max } from '@aryth/comparer'; | ||
import { hslToRgb, hexToHsl } from '@palett/convert'; | ||
import { Dye } from '@palett/dye'; | ||
import { bound } from '@aryth/bound-vector'; | ||
import { mapper } from '@vect/vector-mapper'; | ||
import { isNumeric } from '@typen/num-strict'; | ||
import { zipper } from '@vect/vector-zipper'; | ||
@@ -14,217 +7,2 @@ const NL = { | ||
/** | ||
* Create a dye from a hsl array | ||
* @param {[number,number,number]} hsl | ||
* @returns {function} | ||
*/ | ||
const hslToDye = hsl => { | ||
var _ref, _hsl; | ||
return _ref = (_hsl = hsl, hslToRgb(_hsl)), Dye(_ref); | ||
}; | ||
const leverage = ([h, s, l], base) => [h / base, s / base, l / base]; | ||
const scale = (x, min$1, lever, base, ceil) => min((max(x, min$1) - min$1) * lever + base, ceil); | ||
const projectDye = function (x) { | ||
var _ref; | ||
const { | ||
min: m, | ||
lever: [rH, rS, rL], | ||
base: [mH, mS, mL] | ||
} = this; | ||
return _ref = [scale(x, m, rH, mH, 360), scale(x, m, rS, mS, 100), scale(x, m, rL, mL, 100)], hslToDye(_ref); | ||
}; | ||
/** | ||
* | ||
* @param {{min:number,dif:number}} valueLeap | ||
* @param {{min:number[],dif:number[]}} colorLeap | ||
* @returns {function(*):function} | ||
* @constructor | ||
*/ | ||
const Projector = (valueLeap, colorLeap) => projectDye.bind({ | ||
min: valueLeap.min, | ||
lever: leverage(colorLeap.dif, valueLeap.dif), | ||
base: colorLeap.min | ||
}); | ||
// from x => typeof x | ||
const STR = 'string'; | ||
const parseHsl = color => { | ||
var _color; | ||
return typeof color === STR ? (_color = color, hexToHsl(_color)) : color; | ||
}; | ||
/** | ||
* | ||
* @param max | ||
* @param min | ||
* @returns {{dif: [number,number,number], min: [number,number,number]}} | ||
*/ | ||
const colorBound = ([maxH, maxS, maxL], [minH, minS, minL]) => ({ | ||
min: [minH, minS, minL], | ||
dif: [maxH - minH, maxS - minS, maxL - minL] | ||
}); | ||
const presetToLeap = ({ | ||
max, | ||
min | ||
}) => { | ||
var _max, _min; | ||
return colorBound((_max = max, parseHsl(_max)), (_min = min, parseHsl(_min))); | ||
}; | ||
const presetToFlat = ({ | ||
na | ||
}) => { | ||
var _ref, _na; | ||
return _ref = (_na = na, parseHsl(_na)), hslToDye(_ref); | ||
}; | ||
/** | ||
* | ||
* @param preset | ||
* @return {{someDif: boolean, dye:Function, leap:{min:*[],dif:*[]}}} | ||
*/ | ||
const presetParser = preset => { | ||
var _preset, _preset2; | ||
const leap = (_preset = preset, presetToLeap(_preset)); | ||
return { | ||
leap, | ||
dye: (_preset2 = preset, presetToFlat(_preset2)), | ||
someDif: leap.dif.some(n => n) | ||
}; | ||
}; | ||
function Dyer(valueBound, positivePreset, negativePreset) { | ||
const { | ||
colorant, | ||
zipper | ||
} = this; | ||
const { | ||
max, | ||
min | ||
} = valueBound, | ||
x = presetParser(positivePreset), | ||
y = presetParser(negativePreset); // ({ | ||
// bound: { max, min }, | ||
// xdyeConf: { dif: max, min: 0 }, | ||
// ydyeConf: { dif: 0 - min, min: min }, | ||
// zipper: !!zipper | ||
// }) |> delogger | ||
if (max === min) { | ||
const prim = max >= 0 ? x : y; | ||
const dye = hslToDye(prim.leap.min); | ||
return zipper ? colorant ? (v, n) => isNumeric(n) ? dye : prim.dye : (v, n) => { | ||
var _v, _v2; | ||
return isNumeric(n) ? (_v = v, dye(_v)) : (_v2 = v, prim.dye(_v2)); | ||
} : colorant ? v => isNumeric(v) ? dye : prim.dye : v => { | ||
var _v3, _v4; | ||
return isNumeric(v) ? (_v3 = v, dye(_v3)) : (_v4 = v, prim.dye(_v4)); | ||
}; | ||
} else { | ||
const xdye = Projector({ | ||
dif: max, | ||
min: 0 | ||
}, x.leap); | ||
const ydye = Projector({ | ||
dif: 0 - min, | ||
min: min | ||
}, y.leap); | ||
return zipper ? colorant ? (v, n) => isNumeric(n) ? n >= 0 ? xdye(n) : ydye(n) : x.dye : (v, n) => { | ||
var _v5, _v6, _v7; | ||
return isNumeric(n) ? n >= 0 ? (_v5 = v, xdye(n)(_v5)) : (_v6 = v, ydye(n)(_v6)) : (_v7 = v, x.dye(_v7)); | ||
} : colorant ? v => isNumeric(v) ? v >= 0 ? xdye(v) : ydye(v) : x.dye : v => { | ||
var _v8, _v9, _v10; | ||
return isNumeric(v) ? v >= 0 ? (_v8 = v, xdye(v)(_v8)) : (_v9 = v, ydye(v)(_v9)) : (_v10 = v, x.dye(_v10)); | ||
}; | ||
} | ||
} | ||
/** | ||
* | ||
* @param {*[]} items | ||
* @param {Object} positivePreset | ||
* @param {Object} negativePreset | ||
* @returns {function[]|*[]} | ||
*/ | ||
const dyemap = function (items, positivePreset, negativePreset) { | ||
const { | ||
colorant = true, | ||
mapper: mapper$1 = mapper, | ||
bound: bound$1 = bound | ||
} = this; | ||
const valueBound = bound$1.call(NL, items); | ||
const dye = Dyer.call({ | ||
colorant | ||
}, valueBound, positivePreset, negativePreset); | ||
return mapper$1(items, dye); | ||
}; | ||
/** | ||
* | ||
* @param {*[]} items | ||
* @param {*[]} values | ||
* @param {Object} positivePreset | ||
* @param {Object} negativePreset | ||
* @returns {Function[]|*[]} | ||
*/ | ||
const dyezip = function (items, values, positivePreset, negativePreset) { | ||
const { | ||
colorant = true, | ||
zipper: zipper$1 = zipper, | ||
bound: bound$1 = bound | ||
} = this; | ||
const valueBound = bound$1.call(NL, values); | ||
const dye = Dyer.call({ | ||
colorant, | ||
zipper: zipper$1 | ||
}, valueBound, positivePreset, negativePreset); | ||
return zipper$1(items, values, dye); | ||
}; | ||
/** | ||
* | ||
* @param {*[]} items | ||
* @param {*[]} values | ||
* @param positivePreset | ||
* @param negativePreset | ||
* @returns {function[]|*[]} | ||
*/ | ||
const fluo = function (items, values, positivePreset, negativePreset) { | ||
const { | ||
mapper, | ||
zipper, | ||
bound, | ||
colorant = false | ||
} = this; | ||
return values ? dyezip.call({ | ||
colorant, | ||
zipper, | ||
bound | ||
}, items, values, positivePreset, negativePreset) : dyemap.call({ | ||
colorant, | ||
mapper, | ||
bound | ||
}, items, positivePreset, negativePreset); | ||
}; | ||
const extractBound = objectWithBound => { | ||
@@ -237,2 +15,2 @@ return objectWithBound ? { | ||
export { NL, Projector, dyemap, dyezip, extractBound, fluo, fluo as fluoZip, hslToDye, leverage, parseHsl, presetToFlat, presetToLeap }; | ||
export { NL, extractBound }; |
{ | ||
"name": "@palett/util-fluo", | ||
"version": "0.3.7", | ||
"version": "0.4.0-alpha.0", | ||
"description": "A colorant to string", | ||
@@ -20,4 +20,4 @@ "main": "dist/index.cjs.js", | ||
"@aryth/comparer": "^0.2.9", | ||
"@palett/convert": "^0.3.7", | ||
"@palett/dye": "^0.3.7", | ||
"@palett/convert": "^0.4.0-alpha.0", | ||
"@palett/dye": "^0.4.0-alpha.0", | ||
"@typen/enum-check-levels": "^0.1.5", | ||
@@ -46,3 +46,3 @@ "@typen/num-strict": "^0.1.5", | ||
"homepage": "https://github.com/hoyeungw/palett/util-fluo#readme", | ||
"gitHead": "c05a5650638d6968b9120fe823bf12689e0cdd96" | ||
"gitHead": "2e00a485ba43b107a3f1b2bee41c5a9ed22c01f9" | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
4358
25
1
+ Added@palett/convert@0.4.6(transitive)
+ Added@palett/dye@0.4.6(transitive)
+ Added@palett/util-ansi@0.4.6(transitive)
- Removed@palett/convert@0.3.7(transitive)
- Removed@palett/dye@0.3.7(transitive)
- Removed@palett/util-ansi@0.3.7(transitive)
Updated@palett/dye@^0.4.0-alpha.0