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 3.1.9 to 3.2.0

6

CHANGELOG.md

@@ -5,2 +5,8 @@ # Changelog

## [3.2.0] 2020-12-18
### Fixed
- Including `tslib` as a separate dependency.
## [3.1.9] 2020-07-23

@@ -7,0 +13,0 @@

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=r||self).valueTypes={})}(this,function(r){"use strict";function t(t,e){return function(r){return Math.max(Math.min(r,e),t)}}function c(r){return r%1?Number(r.toFixed(5)):r}function e(t){return{test:function(r){return"string"==typeof r&&r.endsWith(t)&&1===r.split(" ").length},parse:parseFloat,transform:function(r){return""+r+t}}}function n(r){return void 0!==r.red}function a(r){return void 0!==r.hue}var s=function(){return(s=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)},f=/(-)?(\d[\d\.]*)/g,i=/(#[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,u={test:function(r){return"number"==typeof r},parse:parseFloat,transform:function(r){return r}},l=s(s({},u),{transform:t(0,1)}),p=s(s({},u),{default:1}),h=e("deg"),m=e("%"),g=e("px"),d=e("vh"),v=e("vw"),b=s(s({},m),{parse:function(r){return m.parse(r)/100},transform:function(r){return m.transform(100*r)}}),y=t(0,255);function x(s){return function(r){if("string"!=typeof r)return r;for(var t,e={},n=(t=r).substring(t.indexOf("(")+1,t.lastIndexOf(")")).replace(/(,|\/)/g," ").split(/ \s*/),a=0;a<4;a++)e[s[a]]=void 0!==n[a]?parseFloat(n[a]):1;return e}}var O=s(s({},u),{transform:function(r){return Math.round(y(r))}});function M(r,t){return r.startsWith(t)&&o.test(r)}function j(r){return"number"==typeof r?0:r}var F={test:function(r){return"string"==typeof r?M(r,"rgb"):n(r)},parse:x(["red","green","blue","alpha"]),transform:function(r){var t,e,n,a,s,o=r.red,u=r.green,f=r.blue,i=r.alpha,p=void 0===i?1:i;return t={red:O.transform(o),green:O.transform(u),blue:O.transform(f),alpha:c(l.transform(p))},e=t.red,n=t.green,a=t.blue,s=t.alpha,"rgba("+e+", "+n+", "+a+", "+(void 0===s?1:s)+")"}},I={test:function(r){return"string"==typeof r?M(r,"hsl"):a(r)},parse:x(["hue","saturation","lightness","alpha"]),transform:function(r){var t,e,n,a,s,o=r.hue,u=r.saturation,f=r.lightness,i=r.alpha,p=void 0===i?1:i;return t={hue:Math.round(o),saturation:m.transform(c(u)),lightness:m.transform(c(f)),alpha:c(l.transform(p))},e=t.hue,n=t.saturation,a=t.lightness,s=t.alpha,"hsla("+e+", "+n+", "+a+", "+(void 0===s?1:s)+")"}},N=s(s({},F),{test:function(r){return"string"==typeof r&&M(r,"#")},parse:function(r){var t="",e="",n="";return 4<r.length?(t=r.substr(1,2),e=r.substr(3,2),n=r.substr(5,2)):(t=r.substr(1,1),e=r.substr(2,1),n=r.substr(3,1),t+=t,e+=e,n+=n),{red:parseInt(t,16),green:parseInt(e,16),blue:parseInt(n,16),alpha:1}}}),w={test:function(r){return"string"==typeof r&&o.test(r)||n(r)||a(r)},parse:function(r){return F.test(r)?F.parse(r):I.test(r)?I.parse(r):N.test(r)?N.parse(r):r},transform:function(r){return n(r)?F.transform(r):a(r)?I.transform(r):r}},P="${c}",T="${n}",$={test:function(r){if("string"!=typeof r||!isNaN(r))return!1;var t=0,e=r.match(f),n=r.match(i);return e&&(t+=e.length),n&&(t+=n.length),0<t},parse:function(r){var t=r,e=[],n=t.match(i);n&&(t=t.replace(i,P),e.push.apply(e,n.map(w.parse)));var a=t.match(f);return a&&e.push.apply(e,a.map(u.parse)),e},createTransformer:function(r){var n=r,a=0,t=r.match(i),s=t?t.length:0;if(t)for(var e=0;e<s;e++)n=n.replace(t[e],P),a++;var o=n.match(f),u=o?o.length:0;if(o)for(e=0;e<u;e++)n=n.replace(o[e],T),a++;return function(r){for(var t=n,e=0;e<a;e++)t=t.replace(e<s?P:T,e<s?w.transform(r[e]):c(r[e]));return t}},getAnimatableNone:function(r){var t=$.parse(r);return $.createTransformer(r)(t.map(j))}};r.alpha=l,r.color=w,r.complex=$,r.degrees=h,r.hex=N,r.hsla=I,r.number=u,r.percent=m,r.progressPercentage=b,r.px=g,r.rgbUnit=O,r.rgba=F,r.scale=p,r.vh=d,r.vw=v,Object.defineProperty(r,"__esModule",{value:!0})});
!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r=r||self).valueTypes={})}(this,function(r){"use strict";function f(r){return r%1?Number(r.toFixed(5)):r}function t(r){return void 0!==r.red}function e(r){return void 0!==r.hue}var n=function(){return(n=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)},a=function(t,e){return function(r){return Math.max(Math.min(r,e),t)}},i=/(-)?(\d[\d\.]*)/g,p=/(#[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,s=/^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i,o={test:function(r){return"number"==typeof r},parse:parseFloat,transform:function(r){return r}},u=n(n({},o),{transform:a(0,1)}),c=n(n({},o),{default:1}),l=function(t){return{test:function(r){return"string"==typeof r&&r.endsWith(t)&&1===r.split(" ").length},parse:parseFloat,transform:function(r){return""+r+t}}},h=l("deg"),m=l("%"),g=l("px"),d=l("vh"),v=l("vw"),l=n(n({},m),{parse:function(r){return m.parse(r)/100},transform:function(r){return m.transform(100*r)}}),b=a(0,255);var a=function(a){return function(r){if("string"!=typeof r)return r;for(var t={},e=(r=r=r).substring(r.indexOf("(")+1,r.lastIndexOf(")")).replace(/(,|\/)/g," ").split(/ \s*/),n=0;n<4;n++)t[a[n]]=void 0!==e[n]?parseFloat(e[n]):1;return t}},y=n(n({},o),{transform:function(r){return Math.round(b(r))}});function x(r,t){return r.startsWith(t)&&s.test(r)}function O(r){return"number"==typeof r?0:r}var M={test:function(r){return"string"==typeof r?x(r,"rgb"):t(r)},parse:a(["red","green","blue","alpha"]),transform:function(r){var t=r.red,e=r.green,n=r.blue,r=r.alpha,r=void 0===r?1:r;return t={red:y.transform(t),green:y.transform(e),blue:y.transform(n),alpha:f(u.transform(r))},e=t.red,n=t.green,r=t.blue,t=t.alpha,"rgba("+e+", "+n+", "+r+", "+(void 0===t?1:t)+")"}},j={test:function(r){return"string"==typeof r?x(r,"hsl"):e(r)},parse:a(["hue","saturation","lightness","alpha"]),transform:function(r){var t=r.hue,e=r.saturation,n=r.lightness,r=r.alpha,r=void 0===r?1:r;return t={hue:Math.round(t),saturation:m.transform(f(e)),lightness:m.transform(f(n)),alpha:f(u.transform(r))},e=t.hue,n=t.saturation,r=t.lightness,t=t.alpha,"hsla("+e+", "+n+", "+r+", "+(void 0===t?1:t)+")"}},F=n(n({},M),{test:function(r){return"string"==typeof r&&x(r,"#")},parse:function(r){var t="",e="",n="";return 4<r.length?(t=r.substr(1,2),e=r.substr(3,2),n=r.substr(5,2)):(t=r.substr(1,1),e=r.substr(2,1),n=r.substr(3,1),t+=t,e+=e,n+=n),{red:parseInt(t,16),green:parseInt(e,16),blue:parseInt(n,16),alpha:1}}}),I={test:function(r){return"string"==typeof r&&s.test(r)||t(r)||e(r)},parse:function(r){return M.test(r)?M.parse(r):j.test(r)?j.parse(r):F.test(r)?F.parse(r):r},transform:function(r){return t(r)?M.transform(r):e(r)?j.transform(r):r}},N="${c}",w="${n}",P={test:function(r){if("string"!=typeof r||!isNaN(r))return!1;var t=0,e=r.match(i),r=r.match(p);return e&&(t+=e.length),r&&(t+=r.length),0<t},parse:function(r){var t=r,e=[],r=t.match(p);r&&(t=t.replace(p,N),e.push.apply(e,r.map(I.parse)));t=t.match(i);return t&&e.push.apply(e,t.map(o.parse)),e},createTransformer:function(r){var n=r,a=0,t=r.match(p),s=t?t.length:0;if(t)for(var e=0;e<s;e++)n=n.replace(t[e],N),a++;var o=n.match(i),u=o?o.length:0;if(o)for(e=0;e<u;e++)n=n.replace(o[e],w),a++;return function(r){for(var t=n,e=0;e<a;e++)t=t.replace(e<s?N:w,e<s?I.transform(r[e]):f(r[e]));return t}},getAnimatableNone:function(r){var t=P.parse(r);return P.createTransformer(r)(t.map(O))}};r.alpha=u,r.color=I,r.complex=P,r.degrees=h,r.hex=F,r.hsla=j,r.number=o,r.percent=m,r.progressPercentage=l,r.px=g,r.rgbUnit=y,r.rgba=M,r.scale=c,r.vh=d,r.vw=v,Object.defineProperty(r,"__esModule",{value:!0})});
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.valueTypes = {}));
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.valueTypes = {}));
}(this, (function (exports) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
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 __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;
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;
var number = {
test: function (v) { return typeof v === 'number'; },
parse: parseFloat,
transform: function (v) { return v; }
};
var alpha = __assign(__assign({}, number), { transform: clamp(0, 1) });
var scale = __assign(__assign({}, number), { default: 1 });
var number = {
test: function (v) { return typeof v === 'number'; },
parse: parseFloat,
transform: function (v) { return v; }
};
var alpha = __assign(__assign({}, number), { transform: clamp(0, 1) });
var scale = __assign(__assign({}, number), { default: 1 });
var createUnitType = function (unit) { return ({
test: function (v) {
return typeof v === 'string' && 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); } });
var createUnitType = function (unit) { return ({
test: function (v) {
return typeof v === 'string' && 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); } });
var getValueFromFunctionString = function (value) {
return value.substring(value.indexOf('(') + 1, value.lastIndexOf(')'));
};
var clampRgbUnit = clamp(0, 255);
var isRgba = function (v) { return v.red !== undefined; };
var isHsla = function (v) { return v.hue !== undefined; };
function getValuesAsArray(value) {
return getValueFromFunctionString(value)
.replace(/(,|\/)/g, ' ')
.split(/ \s*/);
}
var splitColorValues = function (terms) {
return function (v) {
if (typeof v !== 'string')
return v;
var values = {};
var valuesArray = getValuesAsArray(v);
for (var i = 0; i < 4; i++) {
values[terms[i]] =
valuesArray[i] !== undefined ? parseFloat(valuesArray[i]) : 1;
}
return values;
};
};
var rgbaTemplate = function (_a) {
var red = _a.red, green = _a.green, blue = _a.blue, _b = _a.alpha, alpha = _b === void 0 ? 1 : _b;
return "rgba(" + red + ", " + green + ", " + blue + ", " + alpha + ")";
};
var hslaTemplate = function (_a) {
var hue = _a.hue, saturation = _a.saturation, lightness = _a.lightness, _b = _a.alpha, alpha = _b === void 0 ? 1 : _b;
return "hsla(" + hue + ", " + saturation + ", " + lightness + ", " + alpha + ")";
};
var rgbUnit = __assign(__assign({}, number), { transform: function (v) { return Math.round(clampRgbUnit(v)); } });
function isColorString(color, colorType) {
return color.startsWith(colorType) && singleColorRegex.test(color);
}
var rgba = {
test: function (v) { return (typeof v === 'string' ? isColorString(v, 'rgb') : isRgba(v)); },
parse: splitColorValues(['red', 'green', 'blue', 'alpha']),
transform: function (_a) {
var red = _a.red, green = _a.green, blue = _a.blue, _b = _a.alpha, alpha$1 = _b === void 0 ? 1 : _b;
return rgbaTemplate({
red: rgbUnit.transform(red),
green: rgbUnit.transform(green),
blue: rgbUnit.transform(blue),
alpha: sanitize(alpha.transform(alpha$1))
});
}
};
var hsla = {
test: function (v) { return (typeof v === 'string' ? isColorString(v, 'hsl') : isHsla(v)); },
parse: splitColorValues(['hue', 'saturation', 'lightness', 'alpha']),
transform: function (_a) {
var hue = _a.hue, saturation = _a.saturation, lightness = _a.lightness, _b = _a.alpha, alpha$1 = _b === void 0 ? 1 : _b;
return hslaTemplate({
hue: Math.round(hue),
saturation: percent.transform(sanitize(saturation)),
lightness: percent.transform(sanitize(lightness)),
alpha: sanitize(alpha.transform(alpha$1))
});
}
};
var hex = __assign(__assign({}, rgba), { test: function (v) { return typeof v === 'string' && isColorString(v, '#'); }, parse: function (v) {
var r = '';
var g = '';
var b = '';
if (v.length > 4) {
r = v.substr(1, 2);
g = v.substr(3, 2);
b = v.substr(5, 2);
}
else {
r = v.substr(1, 1);
g = v.substr(2, 1);
b = v.substr(3, 1);
r += r;
g += g;
b += b;
}
return {
red: parseInt(r, 16),
green: parseInt(g, 16),
blue: parseInt(b, 16),
alpha: 1
};
} });
var color = {
test: function (v) {
return (typeof v === 'string' && singleColorRegex.test(v)) ||
isRgba(v) ||
isHsla(v);
},
parse: function (v) {
if (rgba.test(v)) {
return rgba.parse(v);
}
else if (hsla.test(v)) {
return hsla.parse(v);
}
else if (hex.test(v)) {
return hex.parse(v);
}
return v;
},
transform: function (v) {
if (isRgba(v)) {
return rgba.transform(v);
}
else if (isHsla(v)) {
return hsla.transform(v);
}
return v;
}
};
var getValueFromFunctionString = function (value) {
return value.substring(value.indexOf('(') + 1, value.lastIndexOf(')'));
};
var clampRgbUnit = clamp(0, 255);
var isRgba = function (v) { return v.red !== undefined; };
var isHsla = function (v) { return v.hue !== undefined; };
function getValuesAsArray(value) {
return getValueFromFunctionString(value)
.replace(/(,|\/)/g, ' ')
.split(/ \s*/);
}
var splitColorValues = function (terms) {
return function (v) {
if (typeof v !== 'string')
return v;
var values = {};
var valuesArray = getValuesAsArray(v);
for (var i = 0; i < 4; i++) {
values[terms[i]] =
valuesArray[i] !== undefined ? parseFloat(valuesArray[i]) : 1;
}
return values;
};
};
var rgbaTemplate = function (_a) {
var red = _a.red, green = _a.green, blue = _a.blue, _b = _a.alpha, alpha = _b === void 0 ? 1 : _b;
return "rgba(" + red + ", " + green + ", " + blue + ", " + alpha + ")";
};
var hslaTemplate = function (_a) {
var hue = _a.hue, saturation = _a.saturation, lightness = _a.lightness, _b = _a.alpha, alpha = _b === void 0 ? 1 : _b;
return "hsla(" + hue + ", " + saturation + ", " + lightness + ", " + alpha + ")";
};
var rgbUnit = __assign(__assign({}, number), { transform: function (v) { return Math.round(clampRgbUnit(v)); } });
function isColorString(color, colorType) {
return color.startsWith(colorType) && singleColorRegex.test(color);
}
var rgba = {
test: function (v) { return (typeof v === 'string' ? isColorString(v, 'rgb') : isRgba(v)); },
parse: splitColorValues(['red', 'green', 'blue', 'alpha']),
transform: function (_a) {
var red = _a.red, green = _a.green, blue = _a.blue, _b = _a.alpha, alpha$1 = _b === void 0 ? 1 : _b;
return rgbaTemplate({
red: rgbUnit.transform(red),
green: rgbUnit.transform(green),
blue: rgbUnit.transform(blue),
alpha: sanitize(alpha.transform(alpha$1))
});
}
};
var hsla = {
test: function (v) { return (typeof v === 'string' ? isColorString(v, 'hsl') : isHsla(v)); },
parse: splitColorValues(['hue', 'saturation', 'lightness', 'alpha']),
transform: function (_a) {
var hue = _a.hue, saturation = _a.saturation, lightness = _a.lightness, _b = _a.alpha, alpha$1 = _b === void 0 ? 1 : _b;
return hslaTemplate({
hue: Math.round(hue),
saturation: percent.transform(sanitize(saturation)),
lightness: percent.transform(sanitize(lightness)),
alpha: sanitize(alpha.transform(alpha$1))
});
}
};
var hex = __assign(__assign({}, rgba), { test: function (v) { return typeof v === 'string' && isColorString(v, '#'); }, parse: function (v) {
var r = '';
var g = '';
var b = '';
if (v.length > 4) {
r = v.substr(1, 2);
g = v.substr(3, 2);
b = v.substr(5, 2);
}
else {
r = v.substr(1, 1);
g = v.substr(2, 1);
b = v.substr(3, 1);
r += r;
g += g;
b += b;
}
return {
red: parseInt(r, 16),
green: parseInt(g, 16),
blue: parseInt(b, 16),
alpha: 1
};
} });
var color = {
test: function (v) {
return (typeof v === 'string' && singleColorRegex.test(v)) ||
isRgba(v) ||
isHsla(v);
},
parse: function (v) {
if (rgba.test(v)) {
return rgba.parse(v);
}
else if (hsla.test(v)) {
return hsla.parse(v);
}
else if (hex.test(v)) {
return hex.parse(v);
}
return v;
},
transform: function (v) {
if (isRgba(v)) {
return rgba.transform(v);
}
else if (isHsla(v)) {
return hsla.transform(v);
}
return v;
}
};
var COLOR_TOKEN = '${c}';
var NUMBER_TOKEN = '${n}';
var convertNumbersToZero = function (v) {
return typeof v === 'number' ? 0 : v;
};
var complex = {
test: function (v) {
if (typeof v !== 'string' || !isNaN(v))
return false;
var numValues = 0;
var foundNumbers = v.match(floatRegex);
var foundColors = v.match(colorRegex);
if (foundNumbers)
numValues += foundNumbers.length;
if (foundColors)
numValues += foundColors.length;
return numValues > 0;
},
parse: function (v) {
var input = v;
var parsed = [];
var foundColors = input.match(colorRegex);
if (foundColors) {
input = input.replace(colorRegex, COLOR_TOKEN);
parsed.push.apply(parsed, foundColors.map(color.parse));
}
var foundNumbers = input.match(floatRegex);
if (foundNumbers) {
parsed.push.apply(parsed, foundNumbers.map(number.parse));
}
return parsed;
},
createTransformer: function (prop) {
var template = prop;
var token = 0;
var foundColors = prop.match(colorRegex);
var numColors = foundColors ? foundColors.length : 0;
if (foundColors) {
for (var i = 0; i < numColors; i++) {
template = template.replace(foundColors[i], COLOR_TOKEN);
token++;
}
}
var foundNumbers = template.match(floatRegex);
var numNumbers = foundNumbers ? foundNumbers.length : 0;
if (foundNumbers) {
for (var i = 0; i < numNumbers; i++) {
template = template.replace(foundNumbers[i], NUMBER_TOKEN);
token++;
}
}
return function (v) {
var output = template;
for (var i = 0; i < token; i++) {
output = output.replace(i < numColors ? COLOR_TOKEN : NUMBER_TOKEN, i < numColors ? color.transform(v[i]) : sanitize(v[i]));
}
return output;
};
},
getAnimatableNone: function (target) {
var parsedTarget = complex.parse(target);
var targetTransformer = complex.createTransformer(target);
return targetTransformer(parsedTarget.map(convertNumbersToZero));
}
};
var COLOR_TOKEN = '${c}';
var NUMBER_TOKEN = '${n}';
var convertNumbersToZero = function (v) {
return typeof v === 'number' ? 0 : v;
};
var complex = {
test: function (v) {
if (typeof v !== 'string' || !isNaN(v))
return false;
var numValues = 0;
var foundNumbers = v.match(floatRegex);
var foundColors = v.match(colorRegex);
if (foundNumbers)
numValues += foundNumbers.length;
if (foundColors)
numValues += foundColors.length;
return numValues > 0;
},
parse: function (v) {
var input = v;
var parsed = [];
var foundColors = input.match(colorRegex);
if (foundColors) {
input = input.replace(colorRegex, COLOR_TOKEN);
parsed.push.apply(parsed, foundColors.map(color.parse));
}
var foundNumbers = input.match(floatRegex);
if (foundNumbers) {
parsed.push.apply(parsed, foundNumbers.map(number.parse));
}
return parsed;
},
createTransformer: function (prop) {
var template = prop;
var token = 0;
var foundColors = prop.match(colorRegex);
var numColors = foundColors ? foundColors.length : 0;
if (foundColors) {
for (var i = 0; i < numColors; i++) {
template = template.replace(foundColors[i], COLOR_TOKEN);
token++;
}
}
var foundNumbers = template.match(floatRegex);
var numNumbers = foundNumbers ? foundNumbers.length : 0;
if (foundNumbers) {
for (var i = 0; i < numNumbers; i++) {
template = template.replace(foundNumbers[i], NUMBER_TOKEN);
token++;
}
}
return function (v) {
var output = template;
for (var i = 0; i < token; i++) {
output = output.replace(i < numColors ? COLOR_TOKEN : NUMBER_TOKEN, i < numColors ? color.transform(v[i]) : sanitize(v[i]));
}
return output;
};
},
getAnimatableNone: function (target) {
var parsedTarget = complex.parse(target);
var targetTransformer = complex.createTransformer(target);
return targetTransformer(parsedTarget.map(convertNumbersToZero));
}
};
exports.alpha = alpha;
exports.color = color;
exports.complex = complex;
exports.degrees = degrees;
exports.hex = hex;
exports.hsla = hsla;
exports.number = number;
exports.percent = percent;
exports.progressPercentage = progressPercentage;
exports.px = px;
exports.rgbUnit = rgbUnit;
exports.rgba = rgba;
exports.scale = scale;
exports.vh = vh;
exports.vw = vw;
exports.alpha = alpha;
exports.color = color;
exports.complex = complex;
exports.degrees = degrees;
exports.hex = hex;
exports.hsla = hsla;
exports.number = number;
exports.percent = percent;
exports.progressPercentage = progressPercentage;
exports.px = px;
exports.rgbUnit = rgbUnit;
exports.rgba = rgba;
exports.scale = scale;
exports.vh = vh;
exports.vw = vw;
Object.defineProperty(exports, '__esModule', { value: true });
Object.defineProperty(exports, '__esModule', { value: true });
})));

@@ -0,6 +1,7 @@

import { Color } from '../types';
export declare const complex: {
test: (v: any) => boolean;
parse: (v: any) => (number | import("../types").RGBA | import("../types").HSLA)[];
createTransformer: (prop: string) => (v: (number | import("../types").RGBA | import("../types").HSLA)[]) => string;
createTransformer: (prop: string) => (v: Array<Color | number>) => string;
getAnimatableNone: (target: string) => string;
};
{
"name": "style-value-types",
"version": "3.1.9",
"version": "3.2.0",
"description": "Parsers, transformers and tests for special value types, eg: %, hex codes etc.",

@@ -14,3 +14,3 @@ "main": "lib/index.js",

"scripts": {
"build": "rollup -c && tsc --emitDeclarationOnly",
"build": "rollup -c && tsc --emitDeclarationOnly && yarn measure",
"watch": "rollup -c -w",

@@ -41,4 +41,2 @@ "lint": "tslint -c tslint.json 'src/**/*.{ts}'",

"@types/jest": "^23.1.1",
"jest": "^23.1.0",
"jest-cli": "^23.1.0",
"webpack": "^3.12.0"

@@ -45,0 +43,0 @@ },

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