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

style-value-types

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

style-value-types - npm Package Compare versions

Comparing version 4.1.5 to 5.0.0

dist/es/color/hex.mjs

2

dist/style-value-types.min.js

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

!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r="undefined"!=typeof globalThis?globalThis:r||self).valueTypes={})}(this,(function(r){"use strict";var t=function(){return(t=Object.assign||function(r){for(var t,e=1,n=arguments.length;e<n;e++)for(var a in t=arguments[e])Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=t[a]);return r}).apply(this,arguments)},e=function(r,t){return function(e){return Math.max(Math.min(e,t),r)}},n=function(r){return r%1?Number(r.toFixed(5)):r},a=/(-)?([\d]*\.?[\d])+/g,s=/(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi,o=/^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;function u(r){return"string"==typeof r}var f={test:function(r){return"number"==typeof r},parse:parseFloat,transform:function(r){return r}},i=t(t({},f),{transform:e(0,1)}),p=t(t({},f),{default:1}),l=function(r){return{test:function(t){return u(t)&&t.endsWith(r)&&1===t.split(" ").length},parse:parseFloat,transform:function(t){return""+t+r}}},c=l("deg"),h=l("%"),m=l("px"),d=l("vh"),v=l("vw"),b=t(t({},h),{parse:function(r){return h.parse(r)/100},transform:function(r){return h.transform(100*r)}}),g=function(r,t){return function(e){return Boolean(u(e)&&o.test(e)&&e.startsWith(r)||t&&Object.prototype.hasOwnProperty.call(e,t))}},y=function(r,t,e){return function(n){var s;if(!u(n))return n;var o=n.match(a),f=o[0],i=o[1],p=o[2],l=o[3];return(s={})[r]=parseFloat(f),s[t]=parseFloat(i),s[e]=parseFloat(p),s.alpha=void 0!==l?parseFloat(l):1,s}},x={test:g("hsl","hue"),parse:y("hue","saturation","lightness"),transform:function(r){var t=r.hue,e=r.saturation,a=r.lightness,s=r.alpha,o=void 0===s?1:s;return"hsla("+Math.round(t)+", "+h.transform(n(e))+", "+h.transform(n(a))+", "+n(i.transform(o))+")"}},w=e(0,255),F=t(t({},f),{transform:function(r){return Math.round(w(r))}}),O={test:g("rgb","red"),parse:y("red","green","blue"),transform:function(r){var t=r.red,e=r.green,a=r.blue,s=r.alpha,o=void 0===s?1:s;return"rgba("+F.transform(t)+", "+F.transform(e)+", "+F.transform(a)+", "+n(i.transform(o))+")"}};var j={test:g("#"),parse:function(r){var t="",e="",n="",a="";return r.length>5?(t=r.substr(1,2),e=r.substr(3,2),n=r.substr(5,2),a=r.substr(7,2)):(t=r.substr(1,1),e=r.substr(2,1),n=r.substr(3,1),a=r.substr(4,1),t+=t,e+=e,n+=n,a+=a),{red:parseInt(t,16),green:parseInt(e,16),blue:parseInt(n,16),alpha:a?parseInt(a,16)/255:1}},transform:O.transform},M={test:function(r){return O.test(r)||j.test(r)||x.test(r)},parse:function(r){return O.test(r)?O.parse(r):x.test(r)?x.parse(r):j.parse(r)},transform:function(r){return u(r)?r:r.hasOwnProperty("red")?O.transform(r):x.transform(r)}},N="${c}",P="${n}";function I(r){"number"==typeof r&&(r=""+r);var t=[],e=0,n=r.match(s);n&&(e=n.length,r=r.replace(s,N),t.push.apply(t,n.map(M.parse)));var o=r.match(a);return o&&(r=r.replace(a,P),t.push.apply(t,o.map(f.parse))),{values:t,numColors:e,tokenised:r}}function T(r){return I(r).values}function $(r){var t=I(r),e=t.values,a=t.numColors,s=t.tokenised,o=e.length;return function(r){for(var t=s,e=0;e<o;e++)t=t.replace(e<a?N:P,e<a?M.transform(r[e]):n(r[e]));return t}}var k=function(r){return"number"==typeof r?0:r};var A={test:function(r){var t,e,n,o;return isNaN(r)&&u(r)&&(null!==(e=null===(t=r.match(a))||void 0===t?void 0:t.length)&&void 0!==e?e:0)+(null!==(o=null===(n=r.match(s))||void 0===n?void 0:n.length)&&void 0!==o?o:0)>0},parse:T,createTransformer:$,getAnimatableNone:function(r){var t=T(r);return $(r)(t.map(k))}},C=new Set(["brightness","contrast","saturate","opacity"]);function W(r){var t=r.slice(0,-1).split("("),e=t[0],n=t[1];if("drop-shadow"===e)return r;var s=(n.match(a)||[])[0];if(!s)return r;var o=n.replace(s,""),u=C.has(e)?1:0;return s!==n&&(u*=100),e+"("+u+o+")"}var _=/([a-z-]*)\(.*?\)/g,z=t(t({},A),{getAnimatableNone:function(r){var t=r.match(_);return t?t.map(W).join(" "):r}});r.alpha=i,r.color=M,r.complex=A,r.degrees=c,r.filter=z,r.hex=j,r.hsla=x,r.number=f,r.percent=h,r.progressPercentage=b,r.px=m,r.rgbUnit=F,r.rgba=O,r.scale=p,r.vh=d,r.vw=v,Object.defineProperty(r,"__esModule",{value:!0})}));
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).valueTypes={})}(this,(function(t){"use strict";const e=(t,e)=>s=>Math.max(Math.min(s,e),t),s=t=>t%1?Number(t.toFixed(5)):t,r=/(-)?([\d]*\.?[\d])+/g,n=/(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi,a=/^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;function o(t){return"string"==typeof t}const l={test:t=>"number"==typeof t,parse:parseFloat,transform:t=>t},u=Object.assign(Object.assign({},l),{transform:e(0,1)}),i=Object.assign(Object.assign({},l),{default:1}),p=t=>({test:e=>o(e)&&e.endsWith(t)&&1===e.split(" ").length,parse:parseFloat,transform:e=>`${e}${t}`}),c=p("deg"),f=p("%"),h=p("px"),m=p("vh"),b=p("vw"),d=Object.assign(Object.assign({},f),{parse:t=>f.parse(t)/100,transform:t=>f.transform(100*t)}),g=(t,e)=>s=>Boolean(o(s)&&a.test(s)&&s.startsWith(t)||e&&Object.prototype.hasOwnProperty.call(s,e)),v=(t,e,s)=>n=>{if(!o(n))return n;const[a,l,u,i]=n.match(r);return{[t]:parseFloat(a),[e]:parseFloat(l),[s]:parseFloat(u),alpha:void 0!==i?parseFloat(i):1}},j={test:g("hsl","hue"),parse:v("hue","saturation","lightness"),transform:({hue:t,saturation:e,lightness:r,alpha:n=1})=>"hsla("+Math.round(t)+", "+f.transform(s(e))+", "+f.transform(s(r))+", "+s(u.transform(n))+")"},y=e(0,255),O=Object.assign(Object.assign({},l),{transform:t=>Math.round(y(t))}),x={test:g("rgb","red"),parse:v("red","green","blue"),transform:({red:t,green:e,blue:r,alpha:n=1})=>"rgba("+O.transform(t)+", "+O.transform(e)+", "+O.transform(r)+", "+s(u.transform(n))+")"};const F={test:g("#"),parse:function(t){let e="",s="",r="",n="";return t.length>5?(e=t.substr(1,2),s=t.substr(3,2),r=t.substr(5,2),n=t.substr(7,2)):(e=t.substr(1,1),s=t.substr(2,1),r=t.substr(3,1),n=t.substr(4,1),e+=e,s+=s,r+=r,n+=n),{red:parseInt(e,16),green:parseInt(s,16),blue:parseInt(r,16),alpha:n?parseInt(n,16)/255:1}},transform:x.transform},w={test:t=>x.test(t)||F.test(t)||j.test(t),parse:t=>x.test(t)?x.parse(t):j.test(t)?j.parse(t):F.parse(t),transform:t=>o(t)?t:t.hasOwnProperty("red")?x.transform(t):j.transform(t)},$="${c}",M="${n}";function N(t){"number"==typeof t&&(t=`${t}`);const e=[];let s=0;const a=t.match(n);a&&(s=a.length,t=t.replace(n,$),e.push(...a.map(w.parse)));const o=t.match(r);return o&&(t=t.replace(r,M),e.push(...o.map(l.parse))),{values:e,numColors:s,tokenised:t}}function I(t){return N(t).values}function P(t){const{values:e,numColors:r,tokenised:n}=N(t),a=e.length;return t=>{let e=n;for(let n=0;n<a;n++)e=e.replace(n<r?$:M,n<r?w.transform(t[n]):s(t[n]));return e}}const T=t=>"number"==typeof t?0:t;const k={test:function(t){var e,s,a,l;return isNaN(t)&&o(t)&&(null!==(s=null===(e=t.match(r))||void 0===e?void 0:e.length)&&void 0!==s?s:0)+(null!==(l=null===(a=t.match(n))||void 0===a?void 0:a.length)&&void 0!==l?l:0)>0},parse:I,createTransformer:P,getAnimatableNone:function(t){const e=I(t);return P(t)(e.map(T))}},A=new Set(["brightness","contrast","saturate","opacity"]);function C(t){let[e,s]=t.slice(0,-1).split("(");if("drop-shadow"===e)return t;const[n]=s.match(r)||[];if(!n)return t;const a=s.replace(n,"");let o=A.has(e)?1:0;return n!==s&&(o*=100),e+"("+o+a+")"}const W=/([a-z-]*)\(.*?\)/g,_=Object.assign(Object.assign({},k),{getAnimatableNone:t=>{const e=t.match(W);return e?e.map(C).join(" "):t}});t.alpha=u,t.color=w,t.complex=k,t.degrees=c,t.filter=_,t.hex=F,t.hsla=j,t.number=l,t.percent=f,t.progressPercentage=d,t.px=h,t.rgbUnit=O,t.rgba=x,t.scale=i,t.vh=m,t.vw=b,Object.defineProperty(t,"__esModule",{value:!0})}));

@@ -5,11 +5,7 @@ 'use strict';

var tslib = require('tslib');
var clamp = function (min, max) { return function (v) {
return Math.max(Math.min(v, max), min);
}; };
var sanitize = function (v) { return (v % 1 ? Number(v.toFixed(5)) : v); };
var floatRegex = /(-)?([\d]*\.?[\d])+/g;
var colorRegex = /(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi;
var singleColorRegex = /^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;
const clamp = (min, max) => (v) => Math.max(Math.min(v, max), min);
const sanitize = (v) => (v % 1 ? Number(v.toFixed(5)) : v);
const floatRegex = /(-)?([\d]*\.?[\d])+/g;
const colorRegex = /(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi;
const singleColorRegex = /^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;
function isString(v) {

@@ -19,46 +15,42 @@ return typeof v === 'string';

var number = {
test: function (v) { return typeof v === 'number'; },
const number = {
test: (v) => typeof v === 'number',
parse: parseFloat,
transform: function (v) { return v; },
transform: (v) => v,
};
var alpha = tslib.__assign(tslib.__assign({}, number), { transform: clamp(0, 1) });
var scale = tslib.__assign(tslib.__assign({}, number), { default: 1 });
const alpha = Object.assign(Object.assign({}, number), { transform: clamp(0, 1) });
const scale = Object.assign(Object.assign({}, number), { default: 1 });
var createUnitType = function (unit) { return ({
test: function (v) {
return isString(v) && v.endsWith(unit) && v.split(' ').length === 1;
},
const createUnitType = (unit) => ({
test: (v) => isString(v) && v.endsWith(unit) && v.split(' ').length === 1,
parse: parseFloat,
transform: function (v) { return "" + v + unit; },
}); };
var degrees = createUnitType('deg');
var percent = createUnitType('%');
var px = createUnitType('px');
var vh = createUnitType('vh');
var vw = createUnitType('vw');
var progressPercentage = tslib.__assign(tslib.__assign({}, percent), { parse: function (v) { return percent.parse(v) / 100; }, transform: function (v) { return percent.transform(v * 100); } });
transform: (v) => `${v}${unit}`,
});
const degrees = createUnitType('deg');
const percent = createUnitType('%');
const px = createUnitType('px');
const vh = createUnitType('vh');
const vw = createUnitType('vw');
const progressPercentage = Object.assign(Object.assign({}, percent), { parse: (v) => percent.parse(v) / 100, transform: (v) => percent.transform(v * 100) });
var isColorString = function (type, testProp) { return function (v) {
const isColorString = (type, testProp) => (v) => {
return Boolean((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) ||
(testProp && Object.prototype.hasOwnProperty.call(v, testProp)));
}; };
var splitColor = function (aName, bName, cName) { return function (v) {
var _a;
};
const splitColor = (aName, bName, cName) => (v) => {
if (!isString(v))
return v;
var _b = v.match(floatRegex), a = _b[0], b = _b[1], c = _b[2], alpha = _b[3];
return _a = {},
_a[aName] = parseFloat(a),
_a[bName] = parseFloat(b),
_a[cName] = parseFloat(c),
_a.alpha = alpha !== undefined ? parseFloat(alpha) : 1,
_a;
}; };
const [a, b, c, alpha] = v.match(floatRegex);
return {
[aName]: parseFloat(a),
[bName]: parseFloat(b),
[cName]: parseFloat(c),
alpha: alpha !== undefined ? parseFloat(alpha) : 1,
};
};
var hsla = {
const hsla = {
test: isColorString('hsl', 'hue'),
parse: splitColor('hue', 'saturation', 'lightness'),
transform: function (_a) {
var hue = _a.hue, saturation = _a.saturation, lightness = _a.lightness, _b = _a.alpha, alpha$1 = _b === void 0 ? 1 : _b;
transform: ({ hue, saturation, lightness, alpha: alpha$1 = 1 }) => {
return ('hsla(' +

@@ -76,26 +68,23 @@ Math.round(hue) +

var clampRgbUnit = clamp(0, 255);
var rgbUnit = tslib.__assign(tslib.__assign({}, number), { transform: function (v) { return Math.round(clampRgbUnit(v)); } });
var rgba = {
const clampRgbUnit = clamp(0, 255);
const rgbUnit = Object.assign(Object.assign({}, number), { transform: (v) => Math.round(clampRgbUnit(v)) });
const rgba = {
test: isColorString('rgb', 'red'),
parse: splitColor('red', 'green', 'blue'),
transform: function (_a) {
var red = _a.red, green = _a.green, blue = _a.blue, _b = _a.alpha, alpha$1 = _b === void 0 ? 1 : _b;
return 'rgba(' +
rgbUnit.transform(red) +
', ' +
rgbUnit.transform(green) +
', ' +
rgbUnit.transform(blue) +
', ' +
sanitize(alpha.transform(alpha$1)) +
')';
},
transform: ({ red, green, blue, alpha: alpha$1 = 1 }) => 'rgba(' +
rgbUnit.transform(red) +
', ' +
rgbUnit.transform(green) +
', ' +
rgbUnit.transform(blue) +
', ' +
sanitize(alpha.transform(alpha$1)) +
')',
};
function parseHex(v) {
var r = '';
var g = '';
var b = '';
var a = '';
let r = '';
let g = '';
let b = '';
let a = '';
if (v.length > 5) {

@@ -124,3 +113,3 @@ r = v.substr(1, 2);

}
var hex = {
const hex = {
test: isColorString('#'),

@@ -131,5 +120,5 @@ parse: parseHex,

var color = {
test: function (v) { return rgba.test(v) || hex.test(v) || hsla.test(v); },
parse: function (v) {
const color = {
test: (v) => rgba.test(v) || hex.test(v) || hsla.test(v),
parse: (v) => {
if (rgba.test(v)) {

@@ -145,3 +134,3 @@ return rgba.parse(v);

},
transform: function (v) {
transform: (v) => {
return isString(v)

@@ -155,4 +144,4 @@ ? v

var colorToken = '${c}';
var numberToken = '${n}';
const colorToken = '${c}';
const numberToken = '${n}';
function test(v) {

@@ -166,17 +155,17 @@ var _a, _b, _c, _d;

if (typeof v === 'number')
v = "" + v;
var values = [];
var numColors = 0;
var colors = v.match(colorRegex);
v = `${v}`;
const values = [];
let numColors = 0;
const colors = v.match(colorRegex);
if (colors) {
numColors = colors.length;
v = v.replace(colorRegex, colorToken);
values.push.apply(values, colors.map(color.parse));
values.push(...colors.map(color.parse));
}
var numbers = v.match(floatRegex);
const numbers = v.match(floatRegex);
if (numbers) {
v = v.replace(floatRegex, numberToken);
values.push.apply(values, numbers.map(number.parse));
values.push(...numbers.map(number.parse));
}
return { values: values, numColors: numColors, tokenised: v };
return { values, numColors, tokenised: v };
}

@@ -187,7 +176,7 @@ function parse(v) {

function createTransformer(v) {
var _a = analyse(v), values = _a.values, numColors = _a.numColors, tokenised = _a.tokenised;
var numValues = values.length;
return function (v) {
var output = tokenised;
for (var i = 0; i < numValues; i++) {
const { values, numColors, tokenised } = analyse(v);
const numValues = values.length;
return (v) => {
let output = tokenised;
for (let i = 0; i < numValues; i++) {
output = output.replace(i < numColors ? colorToken : numberToken, i < numColors ? color.transform(v[i]) : sanitize(v[i]));

@@ -198,22 +187,20 @@ }

}
var convertNumbersToZero = function (v) {
return typeof v === 'number' ? 0 : v;
};
const convertNumbersToZero = (v) => typeof v === 'number' ? 0 : v;
function getAnimatableNone(v) {
var parsed = parse(v);
var transformer = createTransformer(v);
const parsed = parse(v);
const transformer = createTransformer(v);
return transformer(parsed.map(convertNumbersToZero));
}
var complex = { test: test, parse: parse, createTransformer: createTransformer, getAnimatableNone: getAnimatableNone };
const complex = { test, parse, createTransformer, getAnimatableNone };
var maxDefaults = new Set(['brightness', 'contrast', 'saturate', 'opacity']);
const maxDefaults = new Set(['brightness', 'contrast', 'saturate', 'opacity']);
function applyDefaultFilter(v) {
var _a = v.slice(0, -1).split('('), name = _a[0], value = _a[1];
let [name, value] = v.slice(0, -1).split('(');
if (name === 'drop-shadow')
return v;
var number = (value.match(floatRegex) || [])[0];
const [number] = value.match(floatRegex) || [];
if (!number)
return v;
var unit = value.replace(number, '');
var defaultValue = maxDefaults.has(name) ? 1 : 0;
const unit = value.replace(number, '');
let defaultValue = maxDefaults.has(name) ? 1 : 0;
if (number !== value)

@@ -223,5 +210,5 @@ defaultValue *= 100;

}
var functionRegex = /([a-z-]*)\(.*?\)/g;
var filter = tslib.__assign(tslib.__assign({}, complex), { getAnimatableNone: function (v) {
var functions = v.match(functionRegex);
const functionRegex = /([a-z-]*)\(.*?\)/g;
const filter = Object.assign(Object.assign({}, complex), { getAnimatableNone: (v) => {
const functions = v.match(functionRegex);
return functions ? functions.map(applyDefaultFilter).join(' ') : v;

@@ -228,0 +215,0 @@ } });

@@ -7,35 +7,7 @@ (function (global, factory) {

/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var clamp = function (min, max) { return function (v) {
return Math.max(Math.min(v, max), min);
}; };
var sanitize = function (v) { return (v % 1 ? Number(v.toFixed(5)) : v); };
var floatRegex = /(-)?([\d]*\.?[\d])+/g;
var colorRegex = /(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi;
var singleColorRegex = /^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;
const clamp = (min, max) => (v) => Math.max(Math.min(v, max), min);
const sanitize = (v) => (v % 1 ? Number(v.toFixed(5)) : v);
const floatRegex = /(-)?([\d]*\.?[\d])+/g;
const colorRegex = /(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi;
const singleColorRegex = /^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;
function isString(v) {

@@ -45,46 +17,42 @@ return typeof v === 'string';

var number = {
test: function (v) { return typeof v === 'number'; },
const number = {
test: (v) => typeof v === 'number',
parse: parseFloat,
transform: function (v) { return v; },
transform: (v) => v,
};
var alpha = __assign(__assign({}, number), { transform: clamp(0, 1) });
var scale = __assign(__assign({}, number), { default: 1 });
const alpha = Object.assign(Object.assign({}, number), { transform: clamp(0, 1) });
const scale = Object.assign(Object.assign({}, number), { default: 1 });
var createUnitType = function (unit) { return ({
test: function (v) {
return isString(v) && v.endsWith(unit) && v.split(' ').length === 1;
},
const createUnitType = (unit) => ({
test: (v) => isString(v) && v.endsWith(unit) && v.split(' ').length === 1,
parse: parseFloat,
transform: function (v) { return "" + v + unit; },
}); };
var degrees = createUnitType('deg');
var percent = createUnitType('%');
var px = createUnitType('px');
var vh = createUnitType('vh');
var vw = createUnitType('vw');
var progressPercentage = __assign(__assign({}, percent), { parse: function (v) { return percent.parse(v) / 100; }, transform: function (v) { return percent.transform(v * 100); } });
transform: (v) => `${v}${unit}`,
});
const degrees = createUnitType('deg');
const percent = createUnitType('%');
const px = createUnitType('px');
const vh = createUnitType('vh');
const vw = createUnitType('vw');
const progressPercentage = Object.assign(Object.assign({}, percent), { parse: (v) => percent.parse(v) / 100, transform: (v) => percent.transform(v * 100) });
var isColorString = function (type, testProp) { return function (v) {
const isColorString = (type, testProp) => (v) => {
return Boolean((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) ||
(testProp && Object.prototype.hasOwnProperty.call(v, testProp)));
}; };
var splitColor = function (aName, bName, cName) { return function (v) {
var _a;
};
const splitColor = (aName, bName, cName) => (v) => {
if (!isString(v))
return v;
var _b = v.match(floatRegex), a = _b[0], b = _b[1], c = _b[2], alpha = _b[3];
return _a = {},
_a[aName] = parseFloat(a),
_a[bName] = parseFloat(b),
_a[cName] = parseFloat(c),
_a.alpha = alpha !== undefined ? parseFloat(alpha) : 1,
_a;
}; };
const [a, b, c, alpha] = v.match(floatRegex);
return {
[aName]: parseFloat(a),
[bName]: parseFloat(b),
[cName]: parseFloat(c),
alpha: alpha !== undefined ? parseFloat(alpha) : 1,
};
};
var hsla = {
const hsla = {
test: isColorString('hsl', 'hue'),
parse: splitColor('hue', 'saturation', 'lightness'),
transform: function (_a) {
var hue = _a.hue, saturation = _a.saturation, lightness = _a.lightness, _b = _a.alpha, alpha$1 = _b === void 0 ? 1 : _b;
transform: ({ hue, saturation, lightness, alpha: alpha$1 = 1 }) => {
return ('hsla(' +

@@ -102,26 +70,23 @@ Math.round(hue) +

var clampRgbUnit = clamp(0, 255);
var rgbUnit = __assign(__assign({}, number), { transform: function (v) { return Math.round(clampRgbUnit(v)); } });
var rgba = {
const clampRgbUnit = clamp(0, 255);
const rgbUnit = Object.assign(Object.assign({}, number), { transform: (v) => Math.round(clampRgbUnit(v)) });
const rgba = {
test: isColorString('rgb', 'red'),
parse: splitColor('red', 'green', 'blue'),
transform: function (_a) {
var red = _a.red, green = _a.green, blue = _a.blue, _b = _a.alpha, alpha$1 = _b === void 0 ? 1 : _b;
return 'rgba(' +
rgbUnit.transform(red) +
', ' +
rgbUnit.transform(green) +
', ' +
rgbUnit.transform(blue) +
', ' +
sanitize(alpha.transform(alpha$1)) +
')';
},
transform: ({ red, green, blue, alpha: alpha$1 = 1 }) => 'rgba(' +
rgbUnit.transform(red) +
', ' +
rgbUnit.transform(green) +
', ' +
rgbUnit.transform(blue) +
', ' +
sanitize(alpha.transform(alpha$1)) +
')',
};
function parseHex(v) {
var r = '';
var g = '';
var b = '';
var a = '';
let r = '';
let g = '';
let b = '';
let a = '';
if (v.length > 5) {

@@ -150,3 +115,3 @@ r = v.substr(1, 2);

}
var hex = {
const hex = {
test: isColorString('#'),

@@ -157,5 +122,5 @@ parse: parseHex,

var color = {
test: function (v) { return rgba.test(v) || hex.test(v) || hsla.test(v); },
parse: function (v) {
const color = {
test: (v) => rgba.test(v) || hex.test(v) || hsla.test(v),
parse: (v) => {
if (rgba.test(v)) {

@@ -171,3 +136,3 @@ return rgba.parse(v);

},
transform: function (v) {
transform: (v) => {
return isString(v)

@@ -181,4 +146,4 @@ ? v

var colorToken = '${c}';
var numberToken = '${n}';
const colorToken = '${c}';
const numberToken = '${n}';
function test(v) {

@@ -192,17 +157,17 @@ var _a, _b, _c, _d;

if (typeof v === 'number')
v = "" + v;
var values = [];
var numColors = 0;
var colors = v.match(colorRegex);
v = `${v}`;
const values = [];
let numColors = 0;
const colors = v.match(colorRegex);
if (colors) {
numColors = colors.length;
v = v.replace(colorRegex, colorToken);
values.push.apply(values, colors.map(color.parse));
values.push(...colors.map(color.parse));
}
var numbers = v.match(floatRegex);
const numbers = v.match(floatRegex);
if (numbers) {
v = v.replace(floatRegex, numberToken);
values.push.apply(values, numbers.map(number.parse));
values.push(...numbers.map(number.parse));
}
return { values: values, numColors: numColors, tokenised: v };
return { values, numColors, tokenised: v };
}

@@ -213,7 +178,7 @@ function parse(v) {

function createTransformer(v) {
var _a = analyse(v), values = _a.values, numColors = _a.numColors, tokenised = _a.tokenised;
var numValues = values.length;
return function (v) {
var output = tokenised;
for (var i = 0; i < numValues; i++) {
const { values, numColors, tokenised } = analyse(v);
const numValues = values.length;
return (v) => {
let output = tokenised;
for (let i = 0; i < numValues; i++) {
output = output.replace(i < numColors ? colorToken : numberToken, i < numColors ? color.transform(v[i]) : sanitize(v[i]));

@@ -224,22 +189,20 @@ }

}
var convertNumbersToZero = function (v) {
return typeof v === 'number' ? 0 : v;
};
const convertNumbersToZero = (v) => typeof v === 'number' ? 0 : v;
function getAnimatableNone(v) {
var parsed = parse(v);
var transformer = createTransformer(v);
const parsed = parse(v);
const transformer = createTransformer(v);
return transformer(parsed.map(convertNumbersToZero));
}
var complex = { test: test, parse: parse, createTransformer: createTransformer, getAnimatableNone: getAnimatableNone };
const complex = { test, parse, createTransformer, getAnimatableNone };
var maxDefaults = new Set(['brightness', 'contrast', 'saturate', 'opacity']);
const maxDefaults = new Set(['brightness', 'contrast', 'saturate', 'opacity']);
function applyDefaultFilter(v) {
var _a = v.slice(0, -1).split('('), name = _a[0], value = _a[1];
let [name, value] = v.slice(0, -1).split('(');
if (name === 'drop-shadow')
return v;
var number = (value.match(floatRegex) || [])[0];
const [number] = value.match(floatRegex) || [];
if (!number)
return v;
var unit = value.replace(number, '');
var defaultValue = maxDefaults.has(name) ? 1 : 0;
const unit = value.replace(number, '');
let defaultValue = maxDefaults.has(name) ? 1 : 0;
if (number !== value)

@@ -249,5 +212,5 @@ defaultValue *= 100;

}
var functionRegex = /([a-z-]*)\(.*?\)/g;
var filter = __assign(__assign({}, complex), { getAnimatableNone: function (v) {
var functions = v.match(functionRegex);
const functionRegex = /([a-z-]*)\(.*?\)/g;
const filter = Object.assign(Object.assign({}, complex), { getAnimatableNone: (v) => {
const functions = v.match(functionRegex);
return functions ? functions.map(applyDefaultFilter).join(' ') : v;

@@ -254,0 +217,0 @@ } });

import { rgba } from './rgba';
import { isColorString } from './utils';
function parseHex(v) {
var r = '';
var g = '';
var b = '';
var a = '';
let r = '';
let g = '';
let b = '';
let a = '';
if (v.length > 5) {

@@ -31,3 +31,3 @@ r = v.substr(1, 2);

}
export var hex = {
export const hex = {
test: isColorString('#'),

@@ -34,0 +34,0 @@ parse: parseHex,

@@ -5,7 +5,6 @@ import { alpha as alphaType } from '../numbers';

import { isColorString, splitColor } from './utils';
export var hsla = {
export const hsla = {
test: isColorString('hsl', 'hue'),
parse: splitColor('hue', 'saturation', 'lightness'),
transform: function (_a) {
var hue = _a.hue, saturation = _a.saturation, lightness = _a.lightness, _b = _a.alpha, alpha = _b === void 0 ? 1 : _b;
transform: ({ hue, saturation, lightness, alpha = 1 }) => {
return ('hsla(' +

@@ -12,0 +11,0 @@ Math.round(hue) +

@@ -5,5 +5,5 @@ import { isString } from '../utils';

import { rgba } from './rgba';
export var color = {
test: function (v) { return rgba.test(v) || hex.test(v) || hsla.test(v); },
parse: function (v) {
export const color = {
test: (v) => rgba.test(v) || hex.test(v) || hsla.test(v),
parse: (v) => {
if (rgba.test(v)) {

@@ -19,3 +19,3 @@ return rgba.parse(v);

},
transform: function (v) {
transform: (v) => {
return isString(v)

@@ -22,0 +22,0 @@ ? v

@@ -1,23 +0,19 @@

import { __assign } from "tslib";
import { alpha as alphaType, number } from '../numbers';
import { clamp, sanitize } from '../utils';
import { isColorString, splitColor } from './utils';
var clampRgbUnit = clamp(0, 255);
export var rgbUnit = __assign(__assign({}, number), { transform: function (v) { return Math.round(clampRgbUnit(v)); } });
export var rgba = {
const clampRgbUnit = clamp(0, 255);
export const rgbUnit = Object.assign(Object.assign({}, number), { transform: (v) => Math.round(clampRgbUnit(v)) });
export const rgba = {
test: isColorString('rgb', 'red'),
parse: splitColor('red', 'green', 'blue'),
transform: function (_a) {
var red = _a.red, green = _a.green, blue = _a.blue, _b = _a.alpha, alpha = _b === void 0 ? 1 : _b;
return 'rgba(' +
rgbUnit.transform(red) +
', ' +
rgbUnit.transform(green) +
', ' +
rgbUnit.transform(blue) +
', ' +
sanitize(alphaType.transform(alpha)) +
')';
},
transform: ({ red, green, blue, alpha = 1 }) => 'rgba(' +
rgbUnit.transform(red) +
', ' +
rgbUnit.transform(green) +
', ' +
rgbUnit.transform(blue) +
', ' +
sanitize(alphaType.transform(alpha)) +
')',
};
//# sourceMappingURL=rgba.js.map
import { floatRegex, isString, singleColorRegex } from '../utils';
export var isColorString = function (type, testProp) { return function (v) {
export const isColorString = (type, testProp) => (v) => {
return Boolean((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) ||
(testProp && Object.prototype.hasOwnProperty.call(v, testProp)));
}; };
export var splitColor = function (aName, bName, cName) { return function (v) {
var _a;
};
export const splitColor = (aName, bName, cName) => (v) => {
if (!isString(v))
return v;
var _b = v.match(floatRegex), a = _b[0], b = _b[1], c = _b[2], alpha = _b[3];
return _a = {},
_a[aName] = parseFloat(a),
_a[bName] = parseFloat(b),
_a[cName] = parseFloat(c),
_a.alpha = alpha !== undefined ? parseFloat(alpha) : 1,
_a;
}; };
const [a, b, c, alpha] = v.match(floatRegex);
return {
[aName]: parseFloat(a),
[bName]: parseFloat(b),
[cName]: parseFloat(c),
alpha: alpha !== undefined ? parseFloat(alpha) : 1,
};
};
//# sourceMappingURL=utils.js.map

@@ -1,14 +0,13 @@

import { __assign } from "tslib";
import { complex } from '.';
import { floatRegex } from '../utils';
var maxDefaults = new Set(['brightness', 'contrast', 'saturate', 'opacity']);
const maxDefaults = new Set(['brightness', 'contrast', 'saturate', 'opacity']);
function applyDefaultFilter(v) {
var _a = v.slice(0, -1).split('('), name = _a[0], value = _a[1];
let [name, value] = v.slice(0, -1).split('(');
if (name === 'drop-shadow')
return v;
var number = (value.match(floatRegex) || [])[0];
const [number] = value.match(floatRegex) || [];
if (!number)
return v;
var unit = value.replace(number, '');
var defaultValue = maxDefaults.has(name) ? 1 : 0;
const unit = value.replace(number, '');
let defaultValue = maxDefaults.has(name) ? 1 : 0;
if (number !== value)

@@ -18,7 +17,7 @@ defaultValue *= 100;

}
var functionRegex = /([a-z-]*)\(.*?\)/g;
export var filter = __assign(__assign({}, complex), { getAnimatableNone: function (v) {
var functions = v.match(functionRegex);
const functionRegex = /([a-z-]*)\(.*?\)/g;
export const filter = Object.assign(Object.assign({}, complex), { getAnimatableNone: (v) => {
const functions = v.match(functionRegex);
return functions ? functions.map(applyDefaultFilter).join(' ') : v;
} });
//# sourceMappingURL=filter.js.map
import { color } from '../color';
import { number } from '../numbers';
import { colorRegex, floatRegex, isString, sanitize } from '../utils';
var colorToken = '${c}';
var numberToken = '${n}';
const colorToken = '${c}';
const numberToken = '${n}';
function test(v) {

@@ -14,17 +14,17 @@ var _a, _b, _c, _d;

if (typeof v === 'number')
v = "" + v;
var values = [];
var numColors = 0;
var colors = v.match(colorRegex);
v = `${v}`;
const values = [];
let numColors = 0;
const colors = v.match(colorRegex);
if (colors) {
numColors = colors.length;
v = v.replace(colorRegex, colorToken);
values.push.apply(values, colors.map(color.parse));
values.push(...colors.map(color.parse));
}
var numbers = v.match(floatRegex);
const numbers = v.match(floatRegex);
if (numbers) {
v = v.replace(floatRegex, numberToken);
values.push.apply(values, numbers.map(number.parse));
values.push(...numbers.map(number.parse));
}
return { values: values, numColors: numColors, tokenised: v };
return { values, numColors, tokenised: v };
}

@@ -35,7 +35,7 @@ function parse(v) {

function createTransformer(v) {
var _a = analyse(v), values = _a.values, numColors = _a.numColors, tokenised = _a.tokenised;
var numValues = values.length;
return function (v) {
var output = tokenised;
for (var i = 0; i < numValues; i++) {
const { values, numColors, tokenised } = analyse(v);
const numValues = values.length;
return (v) => {
let output = tokenised;
for (let i = 0; i < numValues; i++) {
output = output.replace(i < numColors ? colorToken : numberToken, i < numColors ? color.transform(v[i]) : sanitize(v[i]));

@@ -46,11 +46,9 @@ }

}
var convertNumbersToZero = function (v) {
return typeof v === 'number' ? 0 : v;
};
const convertNumbersToZero = (v) => typeof v === 'number' ? 0 : v;
function getAnimatableNone(v) {
var parsed = parse(v);
var transformer = createTransformer(v);
const parsed = parse(v);
const transformer = createTransformer(v);
return transformer(parsed.map(convertNumbersToZero));
}
export var complex = { test: test, parse: parse, createTransformer: createTransformer, getAnimatableNone: getAnimatableNone };
export const complex = { test, parse, createTransformer, getAnimatableNone };
//# sourceMappingURL=index.js.map

@@ -1,10 +0,9 @@

import { __assign } from "tslib";
import { clamp } from '../utils';
export var number = {
test: function (v) { return typeof v === 'number'; },
export const number = {
test: (v) => typeof v === 'number',
parse: parseFloat,
transform: function (v) { return v; },
transform: (v) => v,
};
export var alpha = __assign(__assign({}, number), { transform: clamp(0, 1) });
export var scale = __assign(__assign({}, number), { default: 1 });
export const alpha = Object.assign(Object.assign({}, number), { transform: clamp(0, 1) });
export const scale = Object.assign(Object.assign({}, number), { default: 1 });
//# sourceMappingURL=index.js.map

@@ -1,16 +0,13 @@

import { __assign } from "tslib";
import { isString } from '../utils';
var createUnitType = function (unit) { return ({
test: function (v) {
return isString(v) && v.endsWith(unit) && v.split(' ').length === 1;
},
const createUnitType = (unit) => ({
test: (v) => isString(v) && v.endsWith(unit) && v.split(' ').length === 1,
parse: parseFloat,
transform: function (v) { return "" + v + unit; },
}); };
export var degrees = createUnitType('deg');
export var percent = createUnitType('%');
export var px = createUnitType('px');
export var vh = createUnitType('vh');
export var vw = createUnitType('vw');
export var progressPercentage = __assign(__assign({}, percent), { parse: function (v) { return percent.parse(v) / 100; }, transform: function (v) { return percent.transform(v * 100); } });
transform: (v) => `${v}${unit}`,
});
export const degrees = createUnitType('deg');
export const percent = createUnitType('%');
export const px = createUnitType('px');
export const vh = createUnitType('vh');
export const vw = createUnitType('vw');
export const progressPercentage = Object.assign(Object.assign({}, percent), { parse: (v) => percent.parse(v) / 100, transform: (v) => percent.transform(v * 100) });
//# sourceMappingURL=units.js.map

@@ -1,8 +0,6 @@

export var clamp = function (min, max) { return function (v) {
return Math.max(Math.min(v, max), min);
}; };
export var sanitize = function (v) { return (v % 1 ? Number(v.toFixed(5)) : v); };
export var floatRegex = /(-)?([\d]*\.?[\d])+/g;
export var colorRegex = /(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi;
export var singleColorRegex = /^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;
export const clamp = (min, max) => (v) => Math.max(Math.min(v, max), min);
export const sanitize = (v) => (v % 1 ? Number(v.toFixed(5)) : v);
export const floatRegex = /(-)?([\d]*\.?[\d])+/g;
export const colorRegex = /(#[0-9a-f]{6}|#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))/gi;
export const singleColorRegex = /^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;
export function isString(v) {

@@ -9,0 +7,0 @@ return typeof v === 'string';

{
"name": "style-value-types",
"version": "4.1.5",
"version": "5.0.0",
"description": "Parsers, transformers and tests for special value types, eg: %, hex codes etc.",
"main": "dist/valueTypes.cjs.js",
"types": "lib/index.d.ts",
"module": "dist/es/index.js",
"jsnext:main": "dist/es/index.js",
"module": "dist/es/index.mjs",
"jsnext:main": "dist/es/index.mjs",
"exports": {
"import": "./dist/es/index.js",
"require": "./dist/valueTypes.cjs.js",
"default": "./dist/es/index.js"
".": {
"import": "./dist/es/index.mjs",
"require": "./dist/valueTypes.cjs.js",
"default": "./dist/valueTypes.cjs.js"
},
"./package.json": "./package.json"
},

@@ -14,0 +17,0 @@ "files": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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