Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@palett/presets

Package Overview
Dependencies
Maintainers
1
Versions
125
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@palett/presets - npm Package Compare versions

Comparing version 0.3.7 to 0.4.0-alpha.0

211

dist/index.cjs.js

@@ -9,2 +9,3 @@ 'use strict';

var tonerHsl = require('@palett/toner-hsl');
var oneself = require('@ject/oneself');

@@ -41,8 +42,2 @@ const AQUA = {

const MOSS = {
max: cards.Palett.lightGreen.accent_3,
min: cards.Palett.teal.lighten_3,
na: cards.Palett.brown.accent_1
};
const INSTA = {

@@ -72,2 +67,8 @@ max: cards.Palett.orange.accent_2,

const MOSS = {
max: cards.Palett.lightGreen.accent_3,
min: cards.Palett.teal.lighten_3,
na: cards.Palett.brown.accent_1
};
const OCEAN = {

@@ -103,20 +104,2 @@ max: cards.Palett.lightBlue.accent_2,

const Presets = {
aqua: AQUA,
atlas: ATLAS,
aurora: AURORA,
azure: AZURE,
fresh: FRESH,
moss: MOSS,
jungle: JUNGLE,
ocean: OCEAN,
lava: LAVA,
planet: PLANET,
metro: METRO,
subtle: SUBTLE,
insta: INSTA,
pome: POME,
viola: VIOLA
};
const reverseHue = hue => {

@@ -146,5 +129,3 @@ hue += 180;

for (let preset of presets) list.push({
preset
});
for (let preset of presets) list.push(preset);

@@ -154,2 +135,176 @@ return list;

const ESC = '\u001b';
const L = ESC + '[';
const R = 'm';
const SC = ';';
const FORE = '38;2';
const CLR_FORE = '39';
// black: 30,
// Red: 31,
// Green: 32,
// Yellow: 33,
// Blue: 34,
// magenta: 35,
// Cyan: 36,
// white: 37,
// Grey: 90,
// }
const BOLD = '1';
const ITALIC = '3';
const UNDERLINE = '4';
const INVERSE = '7';
const CLR_BOLD = '22';
const CLR_ITALIC = '23';
const CLR_UNDERLINE = '24';
const CLR_INVERSE = '27';
const Effects = {
bold: [BOLD, CLR_BOLD],
italic: [ITALIC, CLR_ITALIC],
underline: [UNDERLINE, CLR_UNDERLINE],
inverse: [INVERSE, CLR_INVERSE]
};
/**
*
* @param {string} code
* @returns {string}
*/
const brt = code => L + code + R;
/**
*
* @param {number[]} rgb - array of three integers, each from 0 to 255
* @returns {string}
*/
const rgbToAnsi = rgb => FORE + SC + rgb[0] + SC + rgb[1] + SC + rgb[2];
/**
*
* @param {string} tx
* @returns {string}
*/
function codedDyer(tx) {
const {
h,
t
} = this;
return brt(h) + tx + brt(t);
}
const parseEffects = effects => {
let h = '',
t = '';
if (effects.length) {
let l, r;
for (let e of effects) if (e in Effects && ([l, r] = Effects[e])) h += SC + l, t += SC + r;
}
return {
h,
t
};
};
/***
*
* @param {number[]} rgb
* @param {...string} [effects]
* @returns {function(string):string}
*/
const Dye = (rgb, ...effects) => {
const config = parseEffects(effects);
config.h += SC + rgbToAnsi(rgb), config.t += SC + CLR_FORE;
return codedDyer.bind(config);
};
/**
* 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(_ref);
};
// from x => typeof x
const STR = 'string';
const parseHsl = color => {
var _color;
return typeof color === STR ? (_color = color, convert.hexToHsl(_color)) : color;
};
/**
* @param {Object} [preset]
* @param {string} preset.na
* @return {Function}
*/
const presetToFlat = preset => {
var _ref, _na;
if (!preset) return oneself.oneself;
const na = preset.na;
return _ref = (_na = na, parseHsl(_na)), hslToDye(_ref);
};
/**
*
* @param {Object} [preset]
* @param {string} preset.max
* @param {string} preset.min
* @return {?{dif: number[], min: number[]}}
*/
const presetToLeap = preset => {
var _max, _min;
if (!preset) return null;
const {
max,
min
} = preset;
return colorBound((_max = max, parseHsl(_max)), (_min = min, parseHsl(_min)));
};
/**
*
* @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 Presets = {
aqua: AQUA,
atlas: ATLAS,
aurora: AURORA,
azure: AZURE,
fresh: FRESH,
moss: MOSS,
jungle: JUNGLE,
ocean: OCEAN,
lava: LAVA,
planet: PLANET,
metro: METRO,
subtle: SUBTLE,
insta: INSTA,
pome: POME,
viola: VIOLA
};
exports.AQUA = AQUA;

@@ -171,3 +326,5 @@ exports.ATLAS = ATLAS;

exports.VIOLA = VIOLA;
exports.presetToFlat = presetToFlat;
exports.presetToLeap = presetToLeap;
exports.randPreset = randPreset;
exports.tapPresets = tapPresets;
import { Palett } from '@palett/cards';
import { randIntBetw } from '@aryth/rand';
import { hexToHsl, hslToHex } from '@palett/convert';
import { hexToHsl, hslToHex, hslToRgb } from '@palett/convert';
import { toner } from '@palett/toner-hsl';
import { oneself } from '@ject/oneself';

@@ -36,8 +37,2 @@ const AQUA = {

const MOSS = {
max: Palett.lightGreen.accent_3,
min: Palett.teal.lighten_3,
na: Palett.brown.accent_1
};
const INSTA = {

@@ -67,2 +62,8 @@ max: Palett.orange.accent_2,

const MOSS = {
max: Palett.lightGreen.accent_3,
min: Palett.teal.lighten_3,
na: Palett.brown.accent_1
};
const OCEAN = {

@@ -98,20 +99,2 @@ max: Palett.lightBlue.accent_2,

const Presets = {
aqua: AQUA,
atlas: ATLAS,
aurora: AURORA,
azure: AZURE,
fresh: FRESH,
moss: MOSS,
jungle: JUNGLE,
ocean: OCEAN,
lava: LAVA,
planet: PLANET,
metro: METRO,
subtle: SUBTLE,
insta: INSTA,
pome: POME,
viola: VIOLA
};
const reverseHue = hue => {

@@ -141,5 +124,3 @@ hue += 180;

for (let preset of presets) list.push({
preset
});
for (let preset of presets) list.push(preset);

@@ -149,2 +130,176 @@ return list;

export { AQUA, ATLAS, AURORA, AZURE, FRESH, INSTA, JUNGLE, LAVA, METRO, MOSS, OCEAN, PLANET, POME, Presets, SUBTLE, VIOLA, randPreset, tapPresets };
const ESC = '\u001b';
const L = ESC + '[';
const R = 'm';
const SC = ';';
const FORE = '38;2';
const CLR_FORE = '39';
// black: 30,
// Red: 31,
// Green: 32,
// Yellow: 33,
// Blue: 34,
// magenta: 35,
// Cyan: 36,
// white: 37,
// Grey: 90,
// }
const BOLD = '1';
const ITALIC = '3';
const UNDERLINE = '4';
const INVERSE = '7';
const CLR_BOLD = '22';
const CLR_ITALIC = '23';
const CLR_UNDERLINE = '24';
const CLR_INVERSE = '27';
const Effects = {
bold: [BOLD, CLR_BOLD],
italic: [ITALIC, CLR_ITALIC],
underline: [UNDERLINE, CLR_UNDERLINE],
inverse: [INVERSE, CLR_INVERSE]
};
/**
*
* @param {string} code
* @returns {string}
*/
const brt = code => L + code + R;
/**
*
* @param {number[]} rgb - array of three integers, each from 0 to 255
* @returns {string}
*/
const rgbToAnsi = rgb => FORE + SC + rgb[0] + SC + rgb[1] + SC + rgb[2];
/**
*
* @param {string} tx
* @returns {string}
*/
function codedDyer(tx) {
const {
h,
t
} = this;
return brt(h) + tx + brt(t);
}
const parseEffects = effects => {
let h = '',
t = '';
if (effects.length) {
let l, r;
for (let e of effects) if (e in Effects && ([l, r] = Effects[e])) h += SC + l, t += SC + r;
}
return {
h,
t
};
};
/***
*
* @param {number[]} rgb
* @param {...string} [effects]
* @returns {function(string):string}
*/
const Dye = (rgb, ...effects) => {
const config = parseEffects(effects);
config.h += SC + rgbToAnsi(rgb), config.t += SC + CLR_FORE;
return codedDyer.bind(config);
};
/**
* 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);
};
// from x => typeof x
const STR = 'string';
const parseHsl = color => {
var _color;
return typeof color === STR ? (_color = color, hexToHsl(_color)) : color;
};
/**
* @param {Object} [preset]
* @param {string} preset.na
* @return {Function}
*/
const presetToFlat = preset => {
var _ref, _na;
if (!preset) return oneself;
const na = preset.na;
return _ref = (_na = na, parseHsl(_na)), hslToDye(_ref);
};
/**
*
* @param {Object} [preset]
* @param {string} preset.max
* @param {string} preset.min
* @return {?{dif: number[], min: number[]}}
*/
const presetToLeap = preset => {
var _max, _min;
if (!preset) return null;
const {
max,
min
} = preset;
return colorBound((_max = max, parseHsl(_max)), (_min = min, parseHsl(_min)));
};
/**
*
* @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 Presets = {
aqua: AQUA,
atlas: ATLAS,
aurora: AURORA,
azure: AZURE,
fresh: FRESH,
moss: MOSS,
jungle: JUNGLE,
ocean: OCEAN,
lava: LAVA,
planet: PLANET,
metro: METRO,
subtle: SUBTLE,
insta: INSTA,
pome: POME,
viola: VIOLA
};
export { AQUA, ATLAS, AURORA, AZURE, FRESH, INSTA, JUNGLE, LAVA, METRO, MOSS, OCEAN, PLANET, POME, Presets, SUBTLE, VIOLA, presetToFlat, presetToLeap, randPreset, tapPresets };

11

package.json
{
"name": "@palett/presets",
"version": "0.3.7",
"version": "0.4.0-alpha.0",
"description": "A color converter",

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

"@aryth/rand": "^0.2.9",
"@palett/cards": "^0.3.7",
"@palett/convert": "^0.3.7",
"@palett/toner-hsl": "^0.3.7"
"@ject/oneself": "^0.0.5",
"@palett/cards": "^0.4.0-alpha.0",
"@palett/convert": "^0.4.0-alpha.0",
"@palett/toner-hsl": "^0.4.0-alpha.0"
},

@@ -45,3 +46,3 @@ "repository": {

"homepage": "https://github.com/hoyeungw/palett/presets#readme",
"gitHead": "c05a5650638d6968b9120fe823bf12689e0cdd96"
"gitHead": "2e00a485ba43b107a3f1b2bee41c5a9ed22c01f9"
}
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