123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275 |
- var understandable = require('./properties/understandable');
-
- function animationIterationCount(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !(validator.isAnimationIterationCountKeyword(value2) || validator.isPositiveNumber(value2))) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- }
-
- return validator.isAnimationIterationCountKeyword(value2) || validator.isPositiveNumber(value2);
- }
-
- function animationName(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !(validator.isAnimationNameKeyword(value2) || validator.isIdentifier(value2))) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- }
-
- return validator.isAnimationNameKeyword(value2) || validator.isIdentifier(value2);
- }
-
- function animationTimingFunction(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !(validator.isAnimationTimingFunction(value2) || validator.isGlobal(value2))) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- }
-
- return validator.isAnimationTimingFunction(value2) || validator.isGlobal(value2);
- }
-
- function areSameFunction(validator, value1, value2) {
- if (!validator.isFunction(value1) || !validator.isFunction(value2)) {
- return false;
- }
-
- var function1Name = value1.substring(0, value1.indexOf('('));
- var function2Name = value2.substring(0, value2.indexOf('('));
-
- return function1Name === function2Name;
- }
-
- function backgroundPosition(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !(validator.isBackgroundPositionKeyword(value2) || validator.isGlobal(value2))) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- } else if (validator.isBackgroundPositionKeyword(value2) || validator.isGlobal(value2)) {
- return true;
- }
-
- return unit(validator, value1, value2);
- }
-
- function backgroundSize(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !(validator.isBackgroundSizeKeyword(value2) || validator.isGlobal(value2))) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- } else if (validator.isBackgroundSizeKeyword(value2) || validator.isGlobal(value2)) {
- return true;
- }
-
- return unit(validator, value1, value2);
- }
-
- function color(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !validator.isColor(value2)) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- } else if (!validator.colorOpacity && (validator.isRgbColor(value1) || validator.isHslColor(value1))) {
- return false;
- } else if (!validator.colorOpacity && (validator.isRgbColor(value2) || validator.isHslColor(value2))) {
- return false;
- } else if (validator.isColor(value1) && validator.isColor(value2)) {
- return true;
- }
-
- return sameFunctionOrValue(validator, value1, value2);
- }
-
- function components(overrideCheckers) {
- return function (validator, value1, value2, position) {
- return overrideCheckers[position](validator, value1, value2);
- };
- }
-
- function fontFamily(validator, value1, value2) {
- return understandable(validator, value1, value2, 0, true);
- }
-
- function image(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !validator.isImage(value2)) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- } else if (validator.isImage(value2)) {
- return true;
- } else if (validator.isImage(value1)) {
- return false;
- }
-
- return sameFunctionOrValue(validator, value1, value2);
- }
-
- function keyword(propertyName) {
- return function(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !validator.isKeyword(propertyName)(value2)) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- }
-
- return validator.isKeyword(propertyName)(value2);
- };
- }
-
- function keywordWithGlobal(propertyName) {
- return function(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !(validator.isKeyword(propertyName)(value2) || validator.isGlobal(value2))) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- }
-
- return validator.isKeyword(propertyName)(value2) || validator.isGlobal(value2);
- };
- }
-
- function sameFunctionOrValue(validator, value1, value2) {
- return areSameFunction(validator, value1, value2) ?
- true :
- value1 === value2;
- }
-
-
-
- function textShadow(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !(validator.isUnit(value2) || validator.isColor(value2) || validator.isGlobal(value2))) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- }
-
- return validator.isUnit(value2) || validator.isColor(value2) || validator.isGlobal(value2);
- }
-
- function time(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !validator.isTime(value2)) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- } else if (validator.isTime(value1) && !validator.isTime(value2)) {
- return false;
- } else if (validator.isTime(value2)) {
- return true;
- } else if (validator.isTime(value1)) {
- return false;
- } else if (validator.isFunction(value1) && !validator.isPrefixed(value1) && validator.isFunction(value2) && !validator.isPrefixed(value2)) {
- return true;
- }
-
- return sameFunctionOrValue(validator, value1, value2);
- }
-
- function unit(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !validator.isUnit(value2)) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- } else if (validator.isUnit(value1) && !validator.isUnit(value2)) {
- return false;
- } else if (validator.isUnit(value2)) {
- return true;
- } else if (validator.isUnit(value1)) {
- return false;
- } else if (validator.isFunction(value1) && !validator.isPrefixed(value1) && validator.isFunction(value2) && !validator.isPrefixed(value2)) {
- return true;
- }
-
- return sameFunctionOrValue(validator, value1, value2);
- }
-
- function unitOrKeywordWithGlobal(propertyName) {
- var byKeyword = keywordWithGlobal(propertyName);
-
- return function(validator, value1, value2) {
- return unit(validator, value1, value2) || byKeyword(validator, value1, value2);
- };
- }
-
- function unitOrNumber(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !(validator.isUnit(value2) || validator.isNumber(value2))) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- } else if ((validator.isUnit(value1) || validator.isNumber(value1)) && !(validator.isUnit(value2) || validator.isNumber(value2))) {
- return false;
- } else if (validator.isUnit(value2) || validator.isNumber(value2)) {
- return true;
- } else if (validator.isUnit(value1) || validator.isNumber(value1)) {
- return false;
- } else if (validator.isFunction(value1) && !validator.isPrefixed(value1) && validator.isFunction(value2) && !validator.isPrefixed(value2)) {
- return true;
- }
-
- return sameFunctionOrValue(validator, value1, value2);
- }
-
- function zIndex(validator, value1, value2) {
- if (!understandable(validator, value1, value2, 0, true) && !validator.isZIndex(value2)) {
- return false;
- } else if (validator.isVariable(value1) && validator.isVariable(value2)) {
- return true;
- }
-
- return validator.isZIndex(value2);
- }
-
- module.exports = {
- generic: {
- color: color,
- components: components,
- image: image,
- time: time,
- unit: unit,
- unitOrNumber: unitOrNumber
- },
- property: {
- animationDirection: keywordWithGlobal('animation-direction'),
- animationFillMode: keyword('animation-fill-mode'),
- animationIterationCount: animationIterationCount,
- animationName: animationName,
- animationPlayState: keywordWithGlobal('animation-play-state'),
- animationTimingFunction: animationTimingFunction,
- backgroundAttachment: keyword('background-attachment'),
- backgroundClip: keywordWithGlobal('background-clip'),
- backgroundOrigin: keyword('background-origin'),
- backgroundPosition: backgroundPosition,
- backgroundRepeat: keyword('background-repeat'),
- backgroundSize: backgroundSize,
- bottom: unitOrKeywordWithGlobal('bottom'),
- borderCollapse: keyword('border-collapse'),
- borderStyle: keywordWithGlobal('*-style'),
- clear: keywordWithGlobal('clear'),
- cursor: keywordWithGlobal('cursor'),
- display: keywordWithGlobal('display'),
- float: keywordWithGlobal('float'),
- left: unitOrKeywordWithGlobal('left'),
- fontFamily: fontFamily,
- fontStretch: keywordWithGlobal('font-stretch'),
- fontStyle: keywordWithGlobal('font-style'),
- fontVariant: keywordWithGlobal('font-variant'),
- fontWeight: keywordWithGlobal('font-weight'),
- listStyleType: keywordWithGlobal('list-style-type'),
- listStylePosition: keywordWithGlobal('list-style-position'),
- outlineStyle: keywordWithGlobal('*-style'),
- overflow: keywordWithGlobal('overflow'),
- position: keywordWithGlobal('position'),
- right: unitOrKeywordWithGlobal('right'),
- textAlign: keywordWithGlobal('text-align'),
- textDecoration: keywordWithGlobal('text-decoration'),
- textOverflow: keywordWithGlobal('text-overflow'),
- textShadow: textShadow,
- top: unitOrKeywordWithGlobal('top'),
- transform: sameFunctionOrValue,
- verticalAlign: unitOrKeywordWithGlobal('vertical-align'),
- visibility: keywordWithGlobal('visibility'),
- whiteSpace: keywordWithGlobal('white-space'),
- zIndex: zIndex
- }
- };
|