style-value-types
Advanced tools
Comparing version 4.0.0 to 4.0.1
@@ -5,6 +5,12 @@ # Changelog | ||
## [4.0.0] Unreleased | ||
## [4.0.1] 2020-01-08 | ||
### Added | ||
- Restoring support for RGBA/HSLA objects in rgba.parse/hsla.parse. | ||
## [4.0.0] 2020-01-08 | ||
### Added | ||
- Support for hex alpha. | ||
@@ -11,0 +17,0 @@ - `filter` type. |
@@ -36,7 +36,10 @@ import { __assign } from 'tslib'; | ||
var isColorString = function (type) { return function (v) { | ||
return isString(v) && singleColorRegex.test(v) && v.startsWith(type); | ||
var isColorString = function (type, testProp) { return function (v) { | ||
return ((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) || | ||
(testProp && v.hasOwnProperty(testProp))); | ||
}; }; | ||
var splitColor = function (aName, bName, cName) { return function (v) { | ||
var _a; | ||
if (!isString(v)) | ||
return v; | ||
var _b = v.match(floatRegex), a = _b[0], b = _b[1], c = _b[2], alpha = _b[3]; | ||
@@ -52,3 +55,3 @@ return _a = {}, | ||
var hsla = { | ||
test: isColorString('hsl'), | ||
test: isColorString('hsl', 'hue'), | ||
parse: splitColor('hue', 'saturation', 'lightness'), | ||
@@ -72,3 +75,3 @@ transform: function (_a) { | ||
var rgba = { | ||
test: isColorString('rgb'), | ||
test: isColorString('rgb', 'red'), | ||
parse: splitColor('red', 'green', 'blue'), | ||
@@ -137,3 +140,7 @@ transform: function (_a) { | ||
transform: function (v) { | ||
return v.hasOwnProperty('red') ? rgba.transform(v) : hsla.transform(v); | ||
return isString(v) | ||
? v | ||
: v.hasOwnProperty('red') | ||
? rgba.transform(v) | ||
: hsla.transform(v); | ||
}, | ||
@@ -140,0 +147,0 @@ }; |
@@ -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,n){return function(r){return Math.max(Math.min(r,n),t)}}var n=function(){return(n=Object.assign||function(r){for(var t,n=1,e=arguments.length;n<e;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=t[a]);return r}).apply(this,arguments)},o=function(r){return r%1?Number(r.toFixed(5)):r},f=/(-)?([\d]*\.?[\d])+/g,a=/(#[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,e=/^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;function s(r){return"string"==typeof r}var u={test:function(r){return"number"==typeof r},parse:parseFloat,transform:function(r){return r}},i=n(n({},u),{transform:t(0,1)}),p=n(n({},u),{default:1}),l=function(t){return{test:function(r){return s(r)&&r.endsWith(t)&&1===r.split(" ").length},parse:parseFloat,transform:function(r){return""+r+t}}},c=l("deg"),h=l("%"),m=l("px"),d=l("vh"),v=l("vw"),g=n(n({},h),{parse:function(r){return h.parse(r)/100},transform:function(r){return h.transform(100*r)}}),b=function(t){return function(r){return s(r)&&e.test(r)&&r.startsWith(t)}},l=function(s,o,u){return function(r){var t=r.match(f),n=t[0],e=t[1],a=t[2],r=t[3],t={};return t[s]=parseFloat(n),t[o]=parseFloat(e),t[u]=parseFloat(a),t.alpha=void 0!==r?parseFloat(r):1,t}},y={test:b("hsl"),parse:l("hue","saturation","lightness"),transform:function(r){var t=r.hue,n=r.saturation,e=r.lightness,r=r.alpha,r=void 0===r?1:r;return"hsla("+Math.round(t)+", "+h.transform(o(n))+", "+h.transform(o(e))+", "+o(i.transform(r))+")"}},x=t(0,255),F=n(n({},u),{transform:function(r){return Math.round(x(r))}}),w={test:b("rgb"),parse:l("red","green","blue"),transform:function(r){var t=r.red,n=r.green,e=r.blue,r=r.alpha,r=void 0===r?1:r;return"rgba("+F.transform(t)+", "+F.transform(n)+", "+F.transform(e)+", "+o(i.transform(r))+")"}};var j={test:b("#"),parse:function(r){var t="",n="",e="",a="";return 5<r.length?(t=r.substr(1,2),n=r.substr(3,2),e=r.substr(5,2),a=r.substr(7,2)):(t=r.substr(1,1),n=r.substr(2,1),e=r.substr(3,1),a=r.substr(4,1),t+=t,n+=n,e+=e,a+=a),{red:parseInt(t,16),green:parseInt(n,16),blue:parseInt(e,16),alpha:a?parseInt(a,16)/255:1}},transform:w.transform},M={test:function(r){return w.test(r)||j.test(r)||y.test(r)},parse:function(r){return(w.test(r)?w:y.test(r)?y:j).parse(r)},transform:function(r){return(r.hasOwnProperty("red")?w:y).transform(r)}},N="${c}",O="${n}";function I(r){var t=[],n=0,e=r.match(a);e&&(n=e.length,r=r.replace(a,N),t.push.apply(t,e.map(M.parse)));e=r.match(f);return e&&(r=r.replace(f,O),t.push.apply(t,e.map(u.parse))),{values:t,numColors:n,tokenised:r}}function P(r){return I(r).values}function $(r){var t=I(r),r=t.values,e=t.numColors,a=t.tokenised,s=r.length;return function(r){for(var t=a,n=0;n<s;n++)t=t.replace(n<e?N:O,n<e?M.transform(r[n]):o(r[n]));return t}}function k(r){return"number"==typeof r?0:r}var l={test:function(r){var t;return isNaN(r)&&s(r)&&0<(null!==(t=null===(t=r.match(f))||void 0===t?void 0:t.length)&&void 0!==t?t:0)+(null!==(r=null===(r=r.match(a))||void 0===r?void 0:r.length)&&void 0!==r?r:0)},parse:P,createTransformer:$,getAnimatableNone:function(r){var t=P(r);return $(r)(t.map(k))}},A=new Set(["brightness","contrast","saturate","opacity"]);function C(r){var t=r.slice(0,-1).split("("),n=t[0],e=t[1];if("drop-shadow"===n)return r;var a=(e.match(f)||[])[0];if(!a)return r;t=e.replace(a,""),r=A.has(n)?1:0;return a!==e&&(r*=100),n+"("+r+t+")"}var T=/([a-z-]*)\(.*?\)/g,b=n(n({},l),{getAnimatableNone:function(r){var t=r.match(T);return t?t.map(C).join(" "):r}});r.alpha=i,r.color=M,r.complex=l,r.degrees=c,r.filter=b,r.hex=j,r.hsla=y,r.number=u,r.percent=h,r.progressPercentage=g,r.px=m,r.rgbUnit=F,r.rgba=w,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 t(t,n){return function(r){return Math.max(Math.min(r,n),t)}}var n=function(){return(n=Object.assign||function(r){for(var t,n=1,e=arguments.length;n<e;n++)for(var a in t=arguments[n])Object.prototype.hasOwnProperty.call(t,a)&&(r[a]=t[a]);return r}).apply(this,arguments)},o=function(r){return r%1?Number(r.toFixed(5)):r},f=/(-)?([\d]*\.?[\d])+/g,a=/(#[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,e=/^(#[0-9a-f]{3}|#(?:[0-9a-f]{2}){2,4}|(rgb|hsl)a?\((-?[\d\.]+%?[,\s]+){2,3}\s*\/*\s*[\d\.]+%?\))$/i;function i(r){return"string"==typeof r}var s={test:function(r){return"number"==typeof r},parse:parseFloat,transform:function(r){return r}},u=n(n({},s),{transform:t(0,1)}),p=n(n({},s),{default:1}),l=function(t){return{test:function(r){return i(r)&&r.endsWith(t)&&1===r.split(" ").length},parse:parseFloat,transform:function(r){return""+r+t}}},c=l("deg"),h=l("%"),m=l("px"),d=l("vh"),v=l("vw"),g=n(n({},h),{parse:function(r){return h.parse(r)/100},transform:function(r){return h.transform(100*r)}}),b=function(t,n){return function(r){return i(r)&&e.test(r)&&r.startsWith(t)||n&&r.hasOwnProperty(n)}},l=function(s,o,u){return function(r){if(!i(r))return r;var t=r.match(f),n=t[0],e=t[1],a=t[2],r=t[3];return(t={})[s]=parseFloat(n),t[o]=parseFloat(e),t[u]=parseFloat(a),t.alpha=void 0!==r?parseFloat(r):1,t}},y={test:b("hsl","hue"),parse:l("hue","saturation","lightness"),transform:function(r){var t=r.hue,n=r.saturation,e=r.lightness,r=r.alpha,r=void 0===r?1:r;return"hsla("+Math.round(t)+", "+h.transform(o(n))+", "+h.transform(o(e))+", "+o(u.transform(r))+")"}},x=t(0,255),w=n(n({},s),{transform:function(r){return Math.round(x(r))}}),F={test:b("rgb","red"),parse:l("red","green","blue"),transform:function(r){var t=r.red,n=r.green,e=r.blue,r=r.alpha,r=void 0===r?1:r;return"rgba("+w.transform(t)+", "+w.transform(n)+", "+w.transform(e)+", "+o(u.transform(r))+")"}};var O={test:b("#"),parse:function(r){var t="",n="",e="",a="";return 5<r.length?(t=r.substr(1,2),n=r.substr(3,2),e=r.substr(5,2),a=r.substr(7,2)):(t=r.substr(1,1),n=r.substr(2,1),e=r.substr(3,1),a=r.substr(4,1),t+=t,n+=n,e+=e,a+=a),{red:parseInt(t,16),green:parseInt(n,16),blue:parseInt(e,16),alpha:a?parseInt(a,16)/255:1}},transform:F.transform},j={test:function(r){return F.test(r)||O.test(r)||y.test(r)},parse:function(r){return(F.test(r)?F:y.test(r)?y:O).parse(r)},transform:function(r){return i(r)?r:(r.hasOwnProperty("red")?F:y).transform(r)}},M="${c}",N="${n}";function P(r){var t=[],n=0,e=r.match(a);e&&(n=e.length,r=r.replace(a,M),t.push.apply(t,e.map(j.parse)));e=r.match(f);return e&&(r=r.replace(f,N),t.push.apply(t,e.map(s.parse))),{values:t,numColors:n,tokenised:r}}function I(r){return P(r).values}function $(r){var t=P(r),r=t.values,e=t.numColors,a=t.tokenised,s=r.length;return function(r){for(var t=a,n=0;n<s;n++)t=t.replace(n<e?M:N,n<e?j.transform(r[n]):o(r[n]));return t}}function k(r){return"number"==typeof r?0:r}var l={test:function(r){var t;return isNaN(r)&&i(r)&&0<(null!==(t=null===(t=r.match(f))||void 0===t?void 0:t.length)&&void 0!==t?t:0)+(null!==(r=null===(r=r.match(a))||void 0===r?void 0:r.length)&&void 0!==r?r:0)},parse:I,createTransformer:$,getAnimatableNone:function(r){var t=I(r);return $(r)(t.map(k))}},A=new Set(["brightness","contrast","saturate","opacity"]);function C(r){var t=r.slice(0,-1).split("("),n=t[0],e=t[1];if("drop-shadow"===n)return r;var a=(e.match(f)||[])[0];if(!a)return r;t=e.replace(a,""),r=A.has(n)?1:0;return a!==e&&(r*=100),n+"("+r+t+")"}var T=/([a-z-]*)\(.*?\)/g,b=n(n({},l),{getAnimatableNone:function(r){var t=r.match(T);return t?t.map(C).join(" "):r}});r.alpha=u,r.color=j,r.complex=l,r.degrees=c,r.filter=b,r.hex=O,r.hsla=y,r.number=s,r.percent=h,r.progressPercentage=g,r.px=m,r.rgbUnit=w,r.rgba=F,r.scale=p,r.vh=d,r.vw=v,Object.defineProperty(r,"__esModule",{value:!0})}); |
@@ -66,7 +66,10 @@ (function (global, factory) { | ||
var isColorString = function (type) { return function (v) { | ||
return isString(v) && singleColorRegex.test(v) && v.startsWith(type); | ||
var isColorString = function (type, testProp) { return function (v) { | ||
return ((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) || | ||
(testProp && v.hasOwnProperty(testProp))); | ||
}; }; | ||
var splitColor = function (aName, bName, cName) { return function (v) { | ||
var _a; | ||
if (!isString(v)) | ||
return v; | ||
var _b = v.match(floatRegex), a = _b[0], b = _b[1], c = _b[2], alpha = _b[3]; | ||
@@ -82,3 +85,3 @@ return _a = {}, | ||
var hsla = { | ||
test: isColorString('hsl'), | ||
test: isColorString('hsl', 'hue'), | ||
parse: splitColor('hue', 'saturation', 'lightness'), | ||
@@ -102,3 +105,3 @@ transform: function (_a) { | ||
var rgba = { | ||
test: isColorString('rgb'), | ||
test: isColorString('rgb', 'red'), | ||
parse: splitColor('red', 'green', 'blue'), | ||
@@ -167,3 +170,7 @@ transform: function (_a) { | ||
transform: function (v) { | ||
return v.hasOwnProperty('red') ? rgba.transform(v) : hsla.transform(v); | ||
return isString(v) | ||
? v | ||
: v.hasOwnProperty('red') | ||
? rgba.transform(v) | ||
: hsla.transform(v); | ||
}, | ||
@@ -170,0 +177,0 @@ }; |
@@ -1,5 +0,6 @@ | ||
export declare const isColorString: (type: string) => (v: any) => any; | ||
export declare const splitColor: (aName: string, bName: string, cName: string) => (v: string) => { | ||
import { Color } from '../types'; | ||
export declare const isColorString: (type: string, testProp?: string) => (v: any) => any; | ||
export declare const splitColor: (aName: string, bName: string, cName: string) => (v: string | Color) => import("../types").RGBA | import("../types").HSLA | { | ||
[x: string]: number; | ||
alpha: number; | ||
}; |
@@ -5,3 +5,3 @@ export declare const filter: { | ||
parse: (v: string) => (number | import("..").RGBA | import("..").HSLA)[]; | ||
createTransformer: (v: string) => (v: (number | import("..").RGBA | import("..").HSLA)[]) => string; | ||
createTransformer: (v: string) => (v: (string | number | import("..").RGBA | import("..").HSLA)[]) => string; | ||
}; |
import { Color } from '../types'; | ||
declare function test(v: any): boolean; | ||
declare function parse(v: string): (number | import("../types").RGBA | import("../types").HSLA)[]; | ||
declare function createTransformer(v: string): (v: Array<Color | number>) => string; | ||
declare function createTransformer(v: string): (v: Array<Color | number | string>) => string; | ||
declare function getAnimatableNone(v: string): string; | ||
@@ -6,0 +6,0 @@ export declare const complex: { |
@@ -40,7 +40,10 @@ 'use strict'; | ||
var isColorString = function (type) { return function (v) { | ||
return isString(v) && singleColorRegex.test(v) && v.startsWith(type); | ||
var isColorString = function (type, testProp) { return function (v) { | ||
return ((isString(v) && singleColorRegex.test(v) && v.startsWith(type)) || | ||
(testProp && v.hasOwnProperty(testProp))); | ||
}; }; | ||
var splitColor = function (aName, bName, cName) { return function (v) { | ||
var _a; | ||
if (!isString(v)) | ||
return v; | ||
var _b = v.match(floatRegex), a = _b[0], b = _b[1], c = _b[2], alpha = _b[3]; | ||
@@ -56,3 +59,3 @@ return _a = {}, | ||
var hsla = { | ||
test: isColorString('hsl'), | ||
test: isColorString('hsl', 'hue'), | ||
parse: splitColor('hue', 'saturation', 'lightness'), | ||
@@ -76,3 +79,3 @@ transform: function (_a) { | ||
var rgba = { | ||
test: isColorString('rgb'), | ||
test: isColorString('rgb', 'red'), | ||
parse: splitColor('red', 'green', 'blue'), | ||
@@ -141,3 +144,7 @@ transform: function (_a) { | ||
transform: function (v) { | ||
return v.hasOwnProperty('red') ? rgba.transform(v) : hsla.transform(v); | ||
return isString(v) | ||
? v | ||
: v.hasOwnProperty('red') | ||
? rgba.transform(v) | ||
: hsla.transform(v); | ||
}, | ||
@@ -144,0 +151,0 @@ }; |
@@ -6,2 +6,2 @@ export declare const clamp: (min: number, max: number) => (v: number) => number; | ||
export declare const singleColorRegex: RegExp; | ||
export declare function isString(v: any): boolean; | ||
export declare function isString(v: any): v is string; |
{ | ||
"name": "style-value-types", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Parsers, transformers and tests for special value types, eg: %, hex codes etc.", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
40912
798
0