New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@palett/fluo

Package Overview
Dependencies
Maintainers
1
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@palett/fluo - npm Package Compare versions

Comparing version 0.8.2 to 0.8.3

863

dist/index.cjs.js

@@ -5,5 +5,2 @@ 'use strict';

var fluoVector = require('@palett/fluo-vector');
var fluoMatrix = require('@palett/fluo-matrix');
var fluoEntries = require('@palett/fluo-entries');
require('@palett/presets');

@@ -16,7 +13,781 @@ var stringValue = require('@spare/string-value');

require('@typen/nullish');
var fluoVector = require('@palett/fluo-vector');
var fluoMatrix = require('@palett/fluo-matrix');
var fluoEntries = require('@palett/fluo-entries');
const POINTWISE = 0;
const ROWWISE = 1;
const COLUMNWISE = 2;
const RGB = 'rgb',
HSL = 'hsl',
HEX = 'hex',
INT = 'int';
/**
*
* applicable for smaller number
* @param {number} x
* @returns {number}
*/
const round$1 = x => x + (x > 0 ? 0.5 : -0.5) << 0;
const oneself$1 = x => x;
const rgbToInt = ([r, g, b]) => ((r & 0xFF) << 16) + ((g & 0xFF) << 8) + (b & 0xFF);
/**
* @param {[number,number,number]} rgb
* @returns {string}
*/
const rgbToHex = rgb => '#' + rgbToInt(rgb).toString(16).toUpperCase().padStart(6, '0');
const bound$2 = ([r, g, b]) => {
let ma = r,
mi = r;
if (g > r) {
ma = g;
} else {
mi = g;
}
if (b > ma) ma = b;
if (b < mi) mi = b;
return {
max: ma,
sum: ma + mi,
dif: ma - mi
};
};
const hue$2 = (r, g, b, max, dif) => {
if (dif === 0) return 0;
switch (max) {
case r:
return ((g - b) / dif + (g < b ? 6 : 0)) % 6;
case g:
return (b - r) / dif + 2;
case b:
return (r - g) / dif + 4;
}
};
const THOUSAND$1$2 = 1000;
/**
* !dif: dif===0
* @param {number} r - [0,255]
* @param {number} g - [0,255]
* @param {number} b - [0,255]
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function rgbToHsl([r, g, b]) {
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound$2([r, g, b]);
let h = hue$2(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round$1(h), round$1(s * THOUSAND$1$2) / 10, round$1(l * THOUSAND$1$2) / 10];
}
const diluteHex$2 = (hex, hi) => {
hi = hi || hex.length;
let x = '';
for (let i = 0, el; i < hi; i++) {
el = hex[i];
x += el + el;
} // for (let c of hex) x += c + c
return x;
};
/**
* @param {string} hex
* @returns {number}
*/
function hexToInt$2(hex) {
if (hex.charAt(0) === '#') hex = hex.substring(1);
if (!hex[3]) hex = diluteHex$2(hex);
return parseInt(hex, 16);
}
/**
*
* @param {string} hex
* @returns {number[]}
*/
function hexToRgb(hex) {
const int = hexToInt$2(hex);
return [int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF];
}
const THOUSAND = 1000;
/**
* !dif: dif===0
* @param {number} int
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function intToHsl$2(int) {
let r = int >> 16 & 0xFF,
g = int >> 8 & 0xFF,
b = int & 0xFF;
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound$2([r, g, b]);
let h = hue$2(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round$1(h), round$1(s * THOUSAND) / 10, round$1(l * THOUSAND) / 10];
}
const hexToHsl = hex => {
var _ref, _hex;
return _ref = (_hex = hex, hexToInt$2(_hex)), intToHsl$2(_ref);
};
/**
*
* @param {number} n
* @param {number} h
* @param {number} a
* @param {number} l
* @returns {number}
*/
const hf$2 = (n, h, a, l) => {
const k = (n + h / 30) % 12;
return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
};
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number[]}
*/
function hslToRgb$2([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf$2(0, h, a, l),
g = hf$2(8, h, a, l),
b = hf$2(4, h, a, l);
return [round$1(r * 0xFF), round$1(g * 0xFF), round$1(b * 0xFF)]; // return [r * 0xFF & 0xFF, g * 0xFF & 0xFF, b * 0xFF & 0xFF]
}
const hslToHex = hsl => {
var _ref, _hsl;
return _ref = (_hsl = hsl, hslToRgb$2(_hsl)), rgbToHex(_ref);
};
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number}
*/
function hslToInt$1([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf$2(0, h, a, l),
g = hf$2(8, h, a, l),
b = hf$2(4, h, a, l);
return ((round$1(r * 0xFF) & 0xFF) << 16) + ((round$1(g * 0xFF) & 0xFF) << 8) + (round$1(b * 0xFF) & 0xFF);
}
const intToRgb = n => [n >> 16 & 0xFF, n >> 8 & 0xFF, n & 0xFF];
const intToHex$1 = int => '#' + int.toString(16).toUpperCase().padStart(6, '0');
var _class$1, _temp$1, _class2$1, _temp2$1, _class3$1, _temp3$1, _class4$1, _temp4$1;
(_temp$1 = _class$1 = class Rgb {}, _class$1.rgb = oneself$1, _class$1.hex = rgbToHex, _class$1.hsl = rgbToHsl, _class$1.int = rgbToInt, _temp$1);
(_temp2$1 = _class2$1 = class Rgb {}, _class2$1.rgb = hexToRgb, _class2$1.hex = oneself$1, _class2$1.hsl = hexToHsl, _class2$1.int = hexToInt$2, _temp2$1);
(_temp3$1 = _class3$1 = class Rgb {}, _class3$1.rgb = hslToRgb$2, _class3$1.hex = hslToHex, _class3$1.hsl = oneself$1, _class3$1.int = hslToInt$1, _temp3$1);
(_temp4$1 = _class4$1 = class Rgb {}, _class4$1.rgb = intToRgb, _class4$1.hex = intToHex$1, _class4$1.hsl = intToHsl$2, _class4$1.int = oneself$1, _temp4$1);
const SC = ';';
const CSI = '[';
const SGR = 'm'; // // // // // // // // // // //
const BOL_ON = '1'; // BOLD / INCREASE_INTENSITY
const DIM_ON = '2'; // DIM / DECREASE_INTENSITY / FAINT
const ITA_ON = '3'; // ITALIC
const UND_ON = '4'; // UNDERLINE
const BLI_ON = '5'; // BLINK
const INV_ON = '7'; // INVERSE
const HID_ON = '8'; // HIDE / CONCEAL
const CRO_ON = '9'; // CROSSED_OUT / STRIKE
// // // // // // // // // // //
const BOL_OFF = '21'; // NOT_BOLD / DOUBLE_UNDERLINE
const DIM_OFF = '22'; // NOT_DIM / NORMAL_INTENSITY
const ITA_OFF = '23'; // NOT_ITALIC
const UND_OFF = '24'; // NOT_UNDERLINE
const BLI_OFF = '25'; // NOT_BLINK
const INV_OFF = '27'; // NOT_INVERSE
const HID_OFF = '28'; // NOT_HIDE / REVEAL
const CRO_OFF = '29'; // NOT_CROSSED_OUT / UNSTRIKE
const FORE_INI = '38;2'; // SET_FORECOLOR (24 bit (true-color))
const FORE_DEF = '39'; // DEFAULT_FORECOLOR
/**
*
* applicable for smaller number
* @param {number} x
* @returns {number}
*/
const round = x => x + (x > 0 ? 0.5 : -0.5) << 0;
const oneself = x => x;
const rgbToInt$1 = ([r, g, b]) => ((r & 0xFF) << 16) + ((g & 0xFF) << 8) + (b & 0xFF);
/**
* @param {[number,number,number]} rgb
* @returns {string}
*/
const rgbToHex$1 = rgb => '#' + rgbToInt$1(rgb).toString(16).toUpperCase().padStart(6, '0');
const bound$1 = ([r, g, b]) => {
let ma = r,
mi = r;
if (g > r) {
ma = g;
} else {
mi = g;
}
if (b > ma) ma = b;
if (b < mi) mi = b;
return {
max: ma,
sum: ma + mi,
dif: ma - mi
};
};
const hue$1 = (r, g, b, max, dif) => {
if (dif === 0) return 0;
switch (max) {
case r:
return ((g - b) / dif + (g < b ? 6 : 0)) % 6;
case g:
return (b - r) / dif + 2;
case b:
return (r - g) / dif + 4;
}
};
const THOUSAND$1$1 = 1000;
/**
* !dif: dif===0
* @param {number} r - [0,255]
* @param {number} g - [0,255]
* @param {number} b - [0,255]
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function rgbToHsl$1([r, g, b]) {
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound$1([r, g, b]);
let h = hue$1(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round(h), round(s * THOUSAND$1$1) / 10, round(l * THOUSAND$1$1) / 10];
}
const diluteHex$1 = (hex, hi) => {
hi = hi || hex.length;
let x = '';
for (let i = 0, el; i < hi; i++) {
el = hex[i];
x += el + el;
} // for (let c of hex) x += c + c
return x;
};
/**
* @param {string} hex
* @returns {number}
*/
function hexToInt$1(hex) {
if (hex.charAt(0) === '#') hex = hex.substring(1);
if (!hex[3]) hex = diluteHex$1(hex);
return parseInt(hex, 16);
}
/**
*
* @param {string} hex
* @returns {number[]}
*/
function hexToRgb$1(hex) {
const int = hexToInt$1(hex);
return [int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF];
}
const THOUSAND$2 = 1000;
/**
* !dif: dif===0
* @param {number} int
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function intToHsl$1(int) {
let r = int >> 16 & 0xFF,
g = int >> 8 & 0xFF,
b = int & 0xFF;
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound$1([r, g, b]);
let h = hue$1(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round(h), round(s * THOUSAND$2) / 10, round(l * THOUSAND$2) / 10];
}
const hexToHsl$1 = hex => {
var _ref, _hex;
return _ref = (_hex = hex, hexToInt$1(_hex)), intToHsl$1(_ref);
};
/**
*
* @param {number} n
* @param {number} h
* @param {number} a
* @param {number} l
* @returns {number}
*/
const hf$1 = (n, h, a, l) => {
const k = (n + h / 30) % 12;
return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
};
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number[]}
*/
function hslToRgb$1([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf$1(0, h, a, l),
g = hf$1(8, h, a, l),
b = hf$1(4, h, a, l);
return [round(r * 0xFF), round(g * 0xFF), round(b * 0xFF)]; // return [r * 0xFF & 0xFF, g * 0xFF & 0xFF, b * 0xFF & 0xFF]
}
const hslToHex$1 = hsl => {
var _ref, _hsl;
return _ref = (_hsl = hsl, hslToRgb$1(_hsl)), rgbToHex$1(_ref);
};
const intToRgb$1 = n => [n >> 16 & 0xFF, n >> 8 & 0xFF, n & 0xFF];
/**
*
* @param {number} n
* @param {number} h
* @param {number} a
* @param {number} l
* @returns {number}
*/
const hf = (n, h, a, l) => {
const k = (n + h / 30) % 12;
return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
};
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number}
*/
function hslToInt([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf(0, h, a, l),
g = hf(8, h, a, l),
b = hf(4, h, a, l);
return ((round(r * 0xFF) & 0xFF) << 16) + ((round(g * 0xFF) & 0xFF) << 8) + (round(b * 0xFF) & 0xFF);
}
const intToHex = int => '#' + int.toString(16).toUpperCase().padStart(6, '0');
const bound = ([r, g, b]) => {
let ma = r,
mi = r;
if (g > r) {
ma = g;
} else {
mi = g;
}
if (b > ma) ma = b;
if (b < mi) mi = b;
return {
max: ma,
sum: ma + mi,
dif: ma - mi
};
};
const hue = (r, g, b, max, dif) => {
if (dif === 0) return 0;
switch (max) {
case r:
return ((g - b) / dif + (g < b ? 6 : 0)) % 6;
case g:
return (b - r) / dif + 2;
case b:
return (r - g) / dif + 4;
}
};
const THOUSAND$1 = 1000;
/**
* !dif: dif===0
* @param {number} int
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function intToHsl(int) {
let r = int >> 16 & 0xFF,
g = int >> 8 & 0xFF,
b = int & 0xFF;
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound([r, g, b]);
let h = hue(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round(h), round(s * THOUSAND$1) / 10, round(l * THOUSAND$1) / 10];
}
const diluteHex = (hex, hi) => {
hi = hi || hex.length;
let x = '';
for (let i = 0, el; i < hi; i++) {
el = hex[i];
x += el + el;
} // for (let c of hex) x += c + c
return x;
};
/**
* @param {string} hex
* @returns {number}
*/
function hexToInt(hex) {
if (hex.charAt(0) === '#') hex = hex.substring(1);
if (!hex[3]) hex = diluteHex(hex);
return parseInt(hex, 16);
}
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number[]}
*/
function hslToRgb([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf(0, h, a, l),
g = hf(8, h, a, l),
b = hf(4, h, a, l);
return [round(r * 0xFF), round(g * 0xFF), round(b * 0xFF)]; // return [r * 0xFF & 0xFF, g * 0xFF & 0xFF, b * 0xFF & 0xFF]
}
var _class, _temp, _class2, _temp2, _class3, _temp3, _class4, _temp4;
_temp = _class = class Rgb {}, _class.rgb = oneself, _class.hex = rgbToHex$1, _class.hsl = rgbToHsl$1, _class.int = rgbToInt$1, _temp;
_temp2 = _class2 = class Rgb {}, _class2.rgb = hexToRgb$1, _class2.hex = oneself, _class2.hsl = hexToHsl$1, _class2.int = hexToInt$1, _temp2;
_temp3 = _class3 = class Rgb {}, _class3.rgb = hslToRgb$1, _class3.hex = hslToHex$1, _class3.hsl = oneself, _class3.int = hslToInt, _temp3;
_temp4 = _class4 = class Rgb {}, _class4.rgb = intToRgb$1, _class4.hex = intToHex, _class4.hsl = intToHsl, _class4.int = oneself, _temp4;
function excite() {
if (this.head.length) this.head += ';';
if (this.tail.length) this.tail += ';';
return this;
}
/** @param {number} int */
function pushInt(int) {
excite.call(this);
this.head += FORE_INI + SC + (int >> 16 & 0xFF) + SC + (int >> 8 & 0xFF) + SC + (int & 0xFF);
this.tail += FORE_DEF;
return this;
}
/** @param {number[]} rgb */
function pushRgb(rgb) {
excite.call(this);
this.head += FORE_INI + SC + rgb[0] + SC + rgb[1] + SC + rgb[2];
this.tail += FORE_DEF;
return this;
}
/** @param {string} hex */
function pushHex(hex) {
var _hex;
return pushInt.call(this, (_hex = hex, hexToInt(_hex)));
}
/** @param {number[]} hsl */
function pushHsl(hsl) {
var _hsl;
return pushRgb.call(this, (_hsl = hsl, hslToRgb(_hsl)));
}
const selectEncolor = space => space === RGB ? pushRgb : space === HEX ? pushHex : space === HSL ? pushHsl : space === INT ? pushInt : pushRgb;
/** @param {string[]} style */
function enstyle(style) {
if (!(style != null && style.length)) return this;
excite.call(this);
for (let t of style) t[0] === 'b' ? (this.head += BOL_ON, this.tail += BOL_OFF // BOLD
) : t[0] === 'd' ? (this.head += DIM_ON, this.tail += DIM_OFF // DIM
) : t[0] === 'i' && t[1] === 't' ? (this.head += ITA_ON, this.tail += ITA_OFF // ITALIC
) : t[0] === 'u' ? (this.head += UND_ON, this.tail += UND_OFF // UNDERLINE
) : t[0] === 'b' ? (this.head += BLI_ON, this.tail += BLI_OFF // BLINK
) : t[0] === 'i' ? (this.head += INV_ON, this.tail += INV_OFF // INVERSE
) : t[0] === 'h' ? (this.head += HID_ON, this.tail += HID_OFF // HIDE
) : t[0] === 's' ? (this.head += CRO_ON, this.tail += CRO_OFF // STRIKE
) : void 0;
return this;
}
class DyeFab {
constructor(space, style) {
this.head = '';
this.tail = '';
if (space) this.setEncolor(space);
if (style) this.enstyle(style);
}
static build(space, style) {
return new DyeFab(space, style);
}
static prep(...effects) {
return new DyeFab().enstyle(effects);
}
static shallow() {
return {
head: '',
tail: ''
};
}
reboot() {
return this.head = '', this.tail = '', this;
}
slice() {
return {
head: this.head ?? '',
tail: this.tail ?? ''
};
}
copy() {
return new DyeFab().assign(this);
}
/**
* @param {string} head
* @param {string} tail
*/
inject(head, tail) {
if (head) this.head = head;
if (tail) this.tail = tail;
return this;
}
assign(another) {
const {
head,
tail
} = another;
if (head) this.head = head;
if (tail) this.tail = tail;
return this;
}
/** @param {string[]} styles */
enstyle(styles) {
return enstyle.call(this, styles);
}
setEncolor(space) {
return this.encolor = selectEncolor(space), this;
}
render(text) {
return CSI + this.head + SGR + text + CSI + this.tail + SGR;
}
}
/**
* @typedef {string|number|number[]} chroma
*/
/**
*
* @this {DyeFab}
* @param {string|any} text
* @param {chroma} color
* @returns {function(string):string}
*/
class Fluo {
/**
*
* @this {DyeFab}
* @param {function(chroma):string} encolor
* @param {string|any} text
* @param {chroma} color
* @returns {function(string):string}
*/
static render(encolor, text, color) {
var _this$slice;
const local = (this == null ? void 0 : (_this$slice = this.slice) == null ? void 0 : _this$slice.call(this)) ?? DyeFab.shallow();
if (color) (encolor ?? local.encolor).call(local, color);
return DyeFab.prototype.render.call(local, text);
}
static rgb(text, rgb) {
return Fluo.render.call(this, pushRgb, text, rgb);
}
static hex(text, hex) {
return Fluo.render.call(this, pushHex, text, hex);
}
static hsl(text, hsl) {
return Fluo.render.call(this, pushHsl, text, hsl);
}
static int(text, int) {
return Fluo.render.call(this, pushInt, text, int);
}
}
function fluo(text, color) {
var _this$slice2;
const local = (this == null ? void 0 : (_this$slice2 = this.slice) == null ? void 0 : _this$slice2.call(this)) ?? DyeFab.shallow();
if (color) (local.encolor ?? pushRgb).call(local, color);
return DyeFab.prototype.render.call(local, text);
}
const iterate$1 = function (vec, fn, l) {

@@ -52,7 +823,7 @@ l = l || (vec === null || vec === void 0 ? void 0 : vec.length);

var Mapper = /*#__PURE__*/Object.freeze({
__proto__: null,
iterate: iterate$1,
mapper: mapper$1,
mutate: mutate$1,
reviter: reviter$1
__proto__: null,
iterate: iterate$1,
mapper: mapper$1,
mutate: mutate$1,
reviter: reviter$1
});

@@ -167,8 +938,8 @@

var Zipper = /*#__PURE__*/Object.freeze({
__proto__: null,
Duozipper: Duozipper$1,
Quazipper: Quazipper$1,
Trizipper: Trizipper$1,
mutazip: mutazip$1,
zipper: zipper$1
__proto__: null,
Duozipper: Duozipper$1,
Quazipper: Quazipper$1,
Trizipper: Trizipper$1,
mutazip: mutazip$1,
zipper: zipper$1
});

@@ -239,41 +1010,47 @@

const POINTWISE = 0;
const ROWWISE = 1;
const COLUMNWISE = 2;
Object.defineProperty(exports, 'fluoVector', {
enumerable: true,
get: function () {
return fluoVector.fluoVector;
}
enumerable: true,
get: function () {
return fluoVector.fluoVector;
}
});
Object.defineProperty(exports, 'fluoByColumns', {
enumerable: true,
get: function () {
return fluoMatrix.fluoByColumns;
}
enumerable: true,
get: function () {
return fluoMatrix.fluoByColumns;
}
});
Object.defineProperty(exports, 'fluoByPoints', {
enumerable: true,
get: function () {
return fluoMatrix.fluoByPoints;
}
});
Object.defineProperty(exports, 'fluoByRows', {
enumerable: true,
get: function () {
return fluoMatrix.fluoByRows;
}
enumerable: true,
get: function () {
return fluoMatrix.fluoByRows;
}
});
Object.defineProperty(exports, 'fluoMatrix', {
enumerable: true,
get: function () {
return fluoMatrix.fluoMatrix;
}
enumerable: true,
get: function () {
return fluoMatrix.fluoMatrix;
}
});
Object.defineProperty(exports, 'fluoPointwise', {
enumerable: true,
get: function () {
return fluoMatrix.fluoPointwise;
}
});
Object.defineProperty(exports, 'fluoEntries', {
enumerable: true,
get: function () {
return fluoEntries.fluoEntries;
}
enumerable: true,
get: function () {
return fluoEntries.fluoEntries;
}
});
exports.COLUMNWISE = COLUMNWISE;
exports.Fluo = Fluo;
exports.POINTWISE = POINTWISE;
exports.PresetCollection = PresetCollection;
exports.ROWWISE = ROWWISE;
exports.fluo = fluo;

@@ -1,4 +0,1 @@

export { fluoVector } from '@palett/fluo-vector';
export { fluoByColumns, fluoByRows, fluoMatrix, fluoPointwise } from '@palett/fluo-matrix';
export { fluoEntries } from '@palett/fluo-entries';
import '@palett/presets';

@@ -11,7 +8,781 @@ import { stringValue } from '@spare/string-value';

import '@typen/nullish';
export { fluoVector } from '@palett/fluo-vector';
export { fluoByColumns, fluoByPoints, fluoByRows, fluoMatrix } from '@palett/fluo-matrix';
export { fluoEntries } from '@palett/fluo-entries';
const POINTWISE = 0;
const ROWWISE = 1;
const COLUMNWISE = 2;
const RGB = 'rgb',
HSL = 'hsl',
HEX = 'hex',
INT = 'int';
/**
*
* applicable for smaller number
* @param {number} x
* @returns {number}
*/
const round$1 = x => x + (x > 0 ? 0.5 : -0.5) << 0;
const oneself$1 = x => x;
const rgbToInt = ([r, g, b]) => ((r & 0xFF) << 16) + ((g & 0xFF) << 8) + (b & 0xFF);
/**
* @param {[number,number,number]} rgb
* @returns {string}
*/
const rgbToHex = rgb => '#' + rgbToInt(rgb).toString(16).toUpperCase().padStart(6, '0');
const bound$2 = ([r, g, b]) => {
let ma = r,
mi = r;
if (g > r) {
ma = g;
} else {
mi = g;
}
if (b > ma) ma = b;
if (b < mi) mi = b;
return {
max: ma,
sum: ma + mi,
dif: ma - mi
};
};
const hue$2 = (r, g, b, max, dif) => {
if (dif === 0) return 0;
switch (max) {
case r:
return ((g - b) / dif + (g < b ? 6 : 0)) % 6;
case g:
return (b - r) / dif + 2;
case b:
return (r - g) / dif + 4;
}
};
const THOUSAND$1$2 = 1000;
/**
* !dif: dif===0
* @param {number} r - [0,255]
* @param {number} g - [0,255]
* @param {number} b - [0,255]
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function rgbToHsl([r, g, b]) {
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound$2([r, g, b]);
let h = hue$2(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round$1(h), round$1(s * THOUSAND$1$2) / 10, round$1(l * THOUSAND$1$2) / 10];
}
const diluteHex$2 = (hex, hi) => {
hi = hi || hex.length;
let x = '';
for (let i = 0, el; i < hi; i++) {
el = hex[i];
x += el + el;
} // for (let c of hex) x += c + c
return x;
};
/**
* @param {string} hex
* @returns {number}
*/
function hexToInt$2(hex) {
if (hex.charAt(0) === '#') hex = hex.substring(1);
if (!hex[3]) hex = diluteHex$2(hex);
return parseInt(hex, 16);
}
/**
*
* @param {string} hex
* @returns {number[]}
*/
function hexToRgb(hex) {
const int = hexToInt$2(hex);
return [int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF];
}
const THOUSAND = 1000;
/**
* !dif: dif===0
* @param {number} int
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function intToHsl$2(int) {
let r = int >> 16 & 0xFF,
g = int >> 8 & 0xFF,
b = int & 0xFF;
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound$2([r, g, b]);
let h = hue$2(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round$1(h), round$1(s * THOUSAND) / 10, round$1(l * THOUSAND) / 10];
}
const hexToHsl = hex => {
var _ref, _hex;
return _ref = (_hex = hex, hexToInt$2(_hex)), intToHsl$2(_ref);
};
/**
*
* @param {number} n
* @param {number} h
* @param {number} a
* @param {number} l
* @returns {number}
*/
const hf$2 = (n, h, a, l) => {
const k = (n + h / 30) % 12;
return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
};
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number[]}
*/
function hslToRgb$2([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf$2(0, h, a, l),
g = hf$2(8, h, a, l),
b = hf$2(4, h, a, l);
return [round$1(r * 0xFF), round$1(g * 0xFF), round$1(b * 0xFF)]; // return [r * 0xFF & 0xFF, g * 0xFF & 0xFF, b * 0xFF & 0xFF]
}
const hslToHex = hsl => {
var _ref, _hsl;
return _ref = (_hsl = hsl, hslToRgb$2(_hsl)), rgbToHex(_ref);
};
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number}
*/
function hslToInt$1([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf$2(0, h, a, l),
g = hf$2(8, h, a, l),
b = hf$2(4, h, a, l);
return ((round$1(r * 0xFF) & 0xFF) << 16) + ((round$1(g * 0xFF) & 0xFF) << 8) + (round$1(b * 0xFF) & 0xFF);
}
const intToRgb = n => [n >> 16 & 0xFF, n >> 8 & 0xFF, n & 0xFF];
const intToHex$1 = int => '#' + int.toString(16).toUpperCase().padStart(6, '0');
var _class$1, _temp$1, _class2$1, _temp2$1, _class3$1, _temp3$1, _class4$1, _temp4$1;
(_temp$1 = _class$1 = class Rgb {}, _class$1.rgb = oneself$1, _class$1.hex = rgbToHex, _class$1.hsl = rgbToHsl, _class$1.int = rgbToInt, _temp$1);
(_temp2$1 = _class2$1 = class Rgb {}, _class2$1.rgb = hexToRgb, _class2$1.hex = oneself$1, _class2$1.hsl = hexToHsl, _class2$1.int = hexToInt$2, _temp2$1);
(_temp3$1 = _class3$1 = class Rgb {}, _class3$1.rgb = hslToRgb$2, _class3$1.hex = hslToHex, _class3$1.hsl = oneself$1, _class3$1.int = hslToInt$1, _temp3$1);
(_temp4$1 = _class4$1 = class Rgb {}, _class4$1.rgb = intToRgb, _class4$1.hex = intToHex$1, _class4$1.hsl = intToHsl$2, _class4$1.int = oneself$1, _temp4$1);
const SC = ';';
const CSI = '[';
const SGR = 'm'; // // // // // // // // // // //
const BOL_ON = '1'; // BOLD / INCREASE_INTENSITY
const DIM_ON = '2'; // DIM / DECREASE_INTENSITY / FAINT
const ITA_ON = '3'; // ITALIC
const UND_ON = '4'; // UNDERLINE
const BLI_ON = '5'; // BLINK
const INV_ON = '7'; // INVERSE
const HID_ON = '8'; // HIDE / CONCEAL
const CRO_ON = '9'; // CROSSED_OUT / STRIKE
// // // // // // // // // // //
const BOL_OFF = '21'; // NOT_BOLD / DOUBLE_UNDERLINE
const DIM_OFF = '22'; // NOT_DIM / NORMAL_INTENSITY
const ITA_OFF = '23'; // NOT_ITALIC
const UND_OFF = '24'; // NOT_UNDERLINE
const BLI_OFF = '25'; // NOT_BLINK
const INV_OFF = '27'; // NOT_INVERSE
const HID_OFF = '28'; // NOT_HIDE / REVEAL
const CRO_OFF = '29'; // NOT_CROSSED_OUT / UNSTRIKE
const FORE_INI = '38;2'; // SET_FORECOLOR (24 bit (true-color))
const FORE_DEF = '39'; // DEFAULT_FORECOLOR
/**
*
* applicable for smaller number
* @param {number} x
* @returns {number}
*/
const round = x => x + (x > 0 ? 0.5 : -0.5) << 0;
const oneself = x => x;
const rgbToInt$1 = ([r, g, b]) => ((r & 0xFF) << 16) + ((g & 0xFF) << 8) + (b & 0xFF);
/**
* @param {[number,number,number]} rgb
* @returns {string}
*/
const rgbToHex$1 = rgb => '#' + rgbToInt$1(rgb).toString(16).toUpperCase().padStart(6, '0');
const bound$1 = ([r, g, b]) => {
let ma = r,
mi = r;
if (g > r) {
ma = g;
} else {
mi = g;
}
if (b > ma) ma = b;
if (b < mi) mi = b;
return {
max: ma,
sum: ma + mi,
dif: ma - mi
};
};
const hue$1 = (r, g, b, max, dif) => {
if (dif === 0) return 0;
switch (max) {
case r:
return ((g - b) / dif + (g < b ? 6 : 0)) % 6;
case g:
return (b - r) / dif + 2;
case b:
return (r - g) / dif + 4;
}
};
const THOUSAND$1$1 = 1000;
/**
* !dif: dif===0
* @param {number} r - [0,255]
* @param {number} g - [0,255]
* @param {number} b - [0,255]
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function rgbToHsl$1([r, g, b]) {
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound$1([r, g, b]);
let h = hue$1(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round(h), round(s * THOUSAND$1$1) / 10, round(l * THOUSAND$1$1) / 10];
}
const diluteHex$1 = (hex, hi) => {
hi = hi || hex.length;
let x = '';
for (let i = 0, el; i < hi; i++) {
el = hex[i];
x += el + el;
} // for (let c of hex) x += c + c
return x;
};
/**
* @param {string} hex
* @returns {number}
*/
function hexToInt$1(hex) {
if (hex.charAt(0) === '#') hex = hex.substring(1);
if (!hex[3]) hex = diluteHex$1(hex);
return parseInt(hex, 16);
}
/**
*
* @param {string} hex
* @returns {number[]}
*/
function hexToRgb$1(hex) {
const int = hexToInt$1(hex);
return [int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF];
}
const THOUSAND$2 = 1000;
/**
* !dif: dif===0
* @param {number} int
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function intToHsl$1(int) {
let r = int >> 16 & 0xFF,
g = int >> 8 & 0xFF,
b = int & 0xFF;
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound$1([r, g, b]);
let h = hue$1(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round(h), round(s * THOUSAND$2) / 10, round(l * THOUSAND$2) / 10];
}
const hexToHsl$1 = hex => {
var _ref, _hex;
return _ref = (_hex = hex, hexToInt$1(_hex)), intToHsl$1(_ref);
};
/**
*
* @param {number} n
* @param {number} h
* @param {number} a
* @param {number} l
* @returns {number}
*/
const hf$1 = (n, h, a, l) => {
const k = (n + h / 30) % 12;
return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
};
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number[]}
*/
function hslToRgb$1([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf$1(0, h, a, l),
g = hf$1(8, h, a, l),
b = hf$1(4, h, a, l);
return [round(r * 0xFF), round(g * 0xFF), round(b * 0xFF)]; // return [r * 0xFF & 0xFF, g * 0xFF & 0xFF, b * 0xFF & 0xFF]
}
const hslToHex$1 = hsl => {
var _ref, _hsl;
return _ref = (_hsl = hsl, hslToRgb$1(_hsl)), rgbToHex$1(_ref);
};
const intToRgb$1 = n => [n >> 16 & 0xFF, n >> 8 & 0xFF, n & 0xFF];
/**
*
* @param {number} n
* @param {number} h
* @param {number} a
* @param {number} l
* @returns {number}
*/
const hf = (n, h, a, l) => {
const k = (n + h / 30) % 12;
return l - a * Math.max(Math.min(k - 3, 9 - k, 1), -1);
};
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number}
*/
function hslToInt([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf(0, h, a, l),
g = hf(8, h, a, l),
b = hf(4, h, a, l);
return ((round(r * 0xFF) & 0xFF) << 16) + ((round(g * 0xFF) & 0xFF) << 8) + (round(b * 0xFF) & 0xFF);
}
const intToHex = int => '#' + int.toString(16).toUpperCase().padStart(6, '0');
const bound = ([r, g, b]) => {
let ma = r,
mi = r;
if (g > r) {
ma = g;
} else {
mi = g;
}
if (b > ma) ma = b;
if (b < mi) mi = b;
return {
max: ma,
sum: ma + mi,
dif: ma - mi
};
};
const hue = (r, g, b, max, dif) => {
if (dif === 0) return 0;
switch (max) {
case r:
return ((g - b) / dif + (g < b ? 6 : 0)) % 6;
case g:
return (b - r) / dif + 2;
case b:
return (r - g) / dif + 4;
}
};
const THOUSAND$1 = 1000;
/**
* !dif: dif===0
* @param {number} int
* @returns {[number,number,number]} [Hue([0,360]), Saturation([0,100]), Lightness([0,100])]
*/
function intToHsl(int) {
let r = int >> 16 & 0xFF,
g = int >> 8 & 0xFF,
b = int & 0xFF;
r /= 255;
g /= 255;
b /= 255;
const {
max,
sum,
dif
} = bound([r, g, b]);
let h = hue(r, g, b, max, dif) * 60,
s = !dif ? 0 : sum > 1 ? dif / (2 - sum) : dif / sum,
l = sum / 2;
return [round(h), round(s * THOUSAND$1) / 10, round(l * THOUSAND$1) / 10];
}
const diluteHex = (hex, hi) => {
hi = hi || hex.length;
let x = '';
for (let i = 0, el; i < hi; i++) {
el = hex[i];
x += el + el;
} // for (let c of hex) x += c + c
return x;
};
/**
* @param {string} hex
* @returns {number}
*/
function hexToInt(hex) {
if (hex.charAt(0) === '#') hex = hex.substring(1);
if (!hex[3]) hex = diluteHex(hex);
return parseInt(hex, 16);
}
/**
*
* @param {number} h
* @param {number} s
* @param {number} l
* @returns {number[]}
*/
function hslToRgb([h, s, l]) {
s /= 100;
l /= 100;
const a = s * Math.min(l, 1 - l),
r = hf(0, h, a, l),
g = hf(8, h, a, l),
b = hf(4, h, a, l);
return [round(r * 0xFF), round(g * 0xFF), round(b * 0xFF)]; // return [r * 0xFF & 0xFF, g * 0xFF & 0xFF, b * 0xFF & 0xFF]
}
var _class, _temp, _class2, _temp2, _class3, _temp3, _class4, _temp4;
_temp = _class = class Rgb {}, _class.rgb = oneself, _class.hex = rgbToHex$1, _class.hsl = rgbToHsl$1, _class.int = rgbToInt$1, _temp;
_temp2 = _class2 = class Rgb {}, _class2.rgb = hexToRgb$1, _class2.hex = oneself, _class2.hsl = hexToHsl$1, _class2.int = hexToInt$1, _temp2;
_temp3 = _class3 = class Rgb {}, _class3.rgb = hslToRgb$1, _class3.hex = hslToHex$1, _class3.hsl = oneself, _class3.int = hslToInt, _temp3;
_temp4 = _class4 = class Rgb {}, _class4.rgb = intToRgb$1, _class4.hex = intToHex, _class4.hsl = intToHsl, _class4.int = oneself, _temp4;
function excite() {
if (this.head.length) this.head += ';';
if (this.tail.length) this.tail += ';';
return this;
}
/** @param {number} int */
function pushInt(int) {
excite.call(this);
this.head += FORE_INI + SC + (int >> 16 & 0xFF) + SC + (int >> 8 & 0xFF) + SC + (int & 0xFF);
this.tail += FORE_DEF;
return this;
}
/** @param {number[]} rgb */
function pushRgb(rgb) {
excite.call(this);
this.head += FORE_INI + SC + rgb[0] + SC + rgb[1] + SC + rgb[2];
this.tail += FORE_DEF;
return this;
}
/** @param {string} hex */
function pushHex(hex) {
var _hex;
return pushInt.call(this, (_hex = hex, hexToInt(_hex)));
}
/** @param {number[]} hsl */
function pushHsl(hsl) {
var _hsl;
return pushRgb.call(this, (_hsl = hsl, hslToRgb(_hsl)));
}
const selectEncolor = space => space === RGB ? pushRgb : space === HEX ? pushHex : space === HSL ? pushHsl : space === INT ? pushInt : pushRgb;
/** @param {string[]} style */
function enstyle(style) {
if (!(style != null && style.length)) return this;
excite.call(this);
for (let t of style) t[0] === 'b' ? (this.head += BOL_ON, this.tail += BOL_OFF // BOLD
) : t[0] === 'd' ? (this.head += DIM_ON, this.tail += DIM_OFF // DIM
) : t[0] === 'i' && t[1] === 't' ? (this.head += ITA_ON, this.tail += ITA_OFF // ITALIC
) : t[0] === 'u' ? (this.head += UND_ON, this.tail += UND_OFF // UNDERLINE
) : t[0] === 'b' ? (this.head += BLI_ON, this.tail += BLI_OFF // BLINK
) : t[0] === 'i' ? (this.head += INV_ON, this.tail += INV_OFF // INVERSE
) : t[0] === 'h' ? (this.head += HID_ON, this.tail += HID_OFF // HIDE
) : t[0] === 's' ? (this.head += CRO_ON, this.tail += CRO_OFF // STRIKE
) : void 0;
return this;
}
class DyeFab {
constructor(space, style) {
this.head = '';
this.tail = '';
if (space) this.setEncolor(space);
if (style) this.enstyle(style);
}
static build(space, style) {
return new DyeFab(space, style);
}
static prep(...effects) {
return new DyeFab().enstyle(effects);
}
static shallow() {
return {
head: '',
tail: ''
};
}
reboot() {
return this.head = '', this.tail = '', this;
}
slice() {
return {
head: this.head ?? '',
tail: this.tail ?? ''
};
}
copy() {
return new DyeFab().assign(this);
}
/**
* @param {string} head
* @param {string} tail
*/
inject(head, tail) {
if (head) this.head = head;
if (tail) this.tail = tail;
return this;
}
assign(another) {
const {
head,
tail
} = another;
if (head) this.head = head;
if (tail) this.tail = tail;
return this;
}
/** @param {string[]} styles */
enstyle(styles) {
return enstyle.call(this, styles);
}
setEncolor(space) {
return this.encolor = selectEncolor(space), this;
}
render(text) {
return CSI + this.head + SGR + text + CSI + this.tail + SGR;
}
}
/**
* @typedef {string|number|number[]} chroma
*/
/**
*
* @this {DyeFab}
* @param {string|any} text
* @param {chroma} color
* @returns {function(string):string}
*/
class Fluo {
/**
*
* @this {DyeFab}
* @param {function(chroma):string} encolor
* @param {string|any} text
* @param {chroma} color
* @returns {function(string):string}
*/
static render(encolor, text, color) {
var _this$slice;
const local = (this == null ? void 0 : (_this$slice = this.slice) == null ? void 0 : _this$slice.call(this)) ?? DyeFab.shallow();
if (color) (encolor ?? local.encolor).call(local, color);
return DyeFab.prototype.render.call(local, text);
}
static rgb(text, rgb) {
return Fluo.render.call(this, pushRgb, text, rgb);
}
static hex(text, hex) {
return Fluo.render.call(this, pushHex, text, hex);
}
static hsl(text, hsl) {
return Fluo.render.call(this, pushHsl, text, hsl);
}
static int(text, int) {
return Fluo.render.call(this, pushInt, text, int);
}
}
function fluo(text, color) {
var _this$slice2;
const local = (this == null ? void 0 : (_this$slice2 = this.slice) == null ? void 0 : _this$slice2.call(this)) ?? DyeFab.shallow();
if (color) (local.encolor ?? pushRgb).call(local, color);
return DyeFab.prototype.render.call(local, text);
}
const iterate$1 = function (vec, fn, l) {

@@ -47,7 +818,7 @@ l = l || (vec === null || vec === void 0 ? void 0 : vec.length);

var Mapper = /*#__PURE__*/Object.freeze({
__proto__: null,
iterate: iterate$1,
mapper: mapper$1,
mutate: mutate$1,
reviter: reviter$1
__proto__: null,
iterate: iterate$1,
mapper: mapper$1,
mutate: mutate$1,
reviter: reviter$1
});

@@ -162,8 +933,8 @@

var Zipper = /*#__PURE__*/Object.freeze({
__proto__: null,
Duozipper: Duozipper$1,
Quazipper: Quazipper$1,
Trizipper: Trizipper$1,
mutazip: mutazip$1,
zipper: zipper$1
__proto__: null,
Duozipper: Duozipper$1,
Quazipper: Quazipper$1,
Trizipper: Trizipper$1,
mutazip: mutazip$1,
zipper: zipper$1
});

@@ -234,2 +1005,6 @@

export { COLUMNWISE, POINTWISE, PresetCollection, ROWWISE };
const POINTWISE = 0;
const ROWWISE = 1;
const COLUMNWISE = 2;
export { COLUMNWISE, Fluo, POINTWISE, PresetCollection, ROWWISE, fluo };

14

package.json
{
"name": "@palett/fluo",
"version": "0.8.2",
"version": "0.8.3",
"description": "A color converter",

@@ -19,7 +19,7 @@ "main": "dist/index.cjs.js",

"dependencies": {
"@palett/fluo-entries": "^0.8.2",
"@palett/fluo-matrix": "^0.8.2",
"@palett/fluo-vector": "^0.8.2",
"@palett/presets": "^0.8.2",
"@palett/projector-factory": "^0.8.2",
"@palett/fluo-entries": "^0.8.3",
"@palett/fluo-matrix": "^0.8.3",
"@palett/fluo-vector": "^0.8.3",
"@palett/presets": "^0.8.3",
"@palett/projector-factory": "^0.8.3",
"@spare/string-value": "^0.11.16",

@@ -53,3 +53,3 @@ "@texting/charset-fullwidth": "^0.0.10",

"homepage": "https://github.com/hoyeungw/palett/fluo#readme",
"gitHead": "ec8c56219ee71eea3504a63e1f7bd862dfd85d4a"
"gitHead": "e806c589dc4793f9c1e6eeb945647604672079b5"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc