@@ -33,7 +33,8 @@ module.exports = function getSpec({ warn, error }) {
3333 }
3434 // 值类型
3535 const ValueType = {
36- number : 'number' ,
36+ integer : 'integer' ,
37+ length : 'length' ,
3738 color : 'color' ,
3839 enum : 'enum'
3940 }
@@ -63,26 +64,27 @@ module.exports = function getSpec({ warn, error }) {
6364 'align-items' : [ 'flex-start' , 'flex-end' , 'center' , 'stretch' , 'baseline' ] ,
6465 'align-self' : [ 'auto' , 'flex-start' , 'flex-end' , 'center' , 'stretch' , 'baseline' ] ,
6566 'justify-content' : [ 'flex-start' , 'flex-end' , 'center' , 'space-between' , 'space-around' , 'space-evenly' ] ,
66- 'background-size' : [ 'contain' , 'cover' , 'auto' , ValueType . number ] ,
67- 'background-position' : [ 'left' , 'right' , 'top' , 'bottom' , 'center' , ValueType . number ] ,
67+ 'background-size' : [ 'contain' , 'cover' , 'auto' , ValueType . length ] ,
68+ 'background-position' : [ 'left' , 'right' , 'top' , 'bottom' , 'center' , ValueType . length ] ,
6869 'background-repeat' : [ 'no-repeat' ] ,
69- width : [ 'auto' , ValueType . number ] ,
70- height : [ 'auto' , ValueType . number ] ,
71- 'flex-basis' : [ 'auto' , ValueType . number ] ,
72- margin : [ 'auto' , ValueType . number ] ,
73- 'margin-top' : [ 'auto' , ValueType . number ] ,
74- 'margin-left' : [ 'auto' , ValueType . number ] ,
75- 'margin-bottom' : [ 'auto' , ValueType . number ] ,
76- 'margin-right' : [ 'auto' , ValueType . number ] ,
77- 'margin-horizontal' : [ 'auto' , ValueType . number ] ,
78- 'margin-vertical' : [ 'auto' , ValueType . number ]
70+ width : [ 'auto' , ValueType . length ] ,
71+ height : [ 'auto' , ValueType . length ] ,
72+ 'flex-basis' : [ 'auto' , ValueType . length ] ,
73+ margin : [ 'auto' , ValueType . length ] ,
74+ 'margin-top' : [ 'auto' , ValueType . length ] ,
75+ 'margin-left' : [ 'auto' , ValueType . length ] ,
76+ 'margin-bottom' : [ 'auto' , ValueType . length ] ,
77+ 'margin-right' : [ 'auto' , ValueType . length ] ,
78+ 'margin-horizontal' : [ 'auto' , ValueType . length ] ,
79+ 'margin-vertical' : [ 'auto' , ValueType . length ]
7980 }
8081 // 获取值类型
8182 const getValueType = ( prop ) => {
8283 const propValueTypeRules = [
8384 // 重要!!优先判断是不是枚举类型
8485 [ ValueType . enum , new RegExp ( '^(' + Object . keys ( SUPPORTED_PROP_VAL_ARR ) . join ( '|' ) + ')$' ) ] ,
85- [ ValueType . number , / ^ ( ( o p a c i t y | f l e x - g r o w | f l e x - s h r i n k | g a p | l e f t | r i g h t | t o p | b o t t o m ) | ( .+ - ( w i d t h | h e i g h t | l e f t | r i g h t | t o p | b o t t o m | r a d i u s | s p a c i n g | s i z e | g a p | i n d e x | o f f s e t | o p a c i t y ) ) ) $ / ] ,
86+ [ ValueType . length , / ^ ( ( g a p | l e f t | r i g h t | t o p | b o t t o m ) | ( .+ - ( w i d t h | h e i g h t | l e f t | r i g h t | t o p | b o t t o m | r a d i u s | s p a c i n g | s i z e | g a p | o f f s e t ) ) ) $ / ] ,
87+ [ ValueType . integer , / ^ ( ( o p a c i t y | f l e x - g r o w | f l e x - s h r i n k | z - i n d e x ) | ( .+ - ( i n d e x | o p a c i t y ) ) ) $ / ] ,
8688 [ ValueType . color , / ^ ( c o l o r | ( .+ - c o l o r ) ) $ / ]
8789 ]
8890 for ( const rule of propValueTypeRules ) {
@@ -144,21 +146,29 @@ module.exports = function getSpec({ warn, error }) {
144146 if ( calcExp . test ( valueForVerify ) || envExp . test ( valueForVerify ) ) return true
145147 const namedColor = [ 'transparent' , 'aliceblue' , 'antiquewhite' , 'aqua' , 'aquamarine' , 'azure' , 'beige' , 'bisque' , 'black' , 'blanchedalmond' , 'blue' , 'blueviolet' , 'brown' , 'burlywood' , 'cadetblue' , 'chartreuse' , 'chocolate' , 'coral' , 'cornflowerblue' , 'cornsilk' , 'crimson' , 'cyan' , 'darkblue' , 'darkcyan' , 'darkgoldenrod' , 'darkgray' , 'darkgreen' , 'darkgrey' , 'darkkhaki' , 'darkmagenta' , 'darkolivegreen' , 'darkorange' , 'darkorchid' , 'darkred' , 'darksalmon' , 'darkseagreen' , 'darkslateblue' , 'darkslategrey' , 'darkturquoise' , 'darkviolet' , 'deeppink' , 'deepskyblue' , 'dimgray' , 'dimgrey' , 'dodgerblue' , 'firebrick' , 'floralwhite' , 'forestgreen' , 'fuchsia' , 'gainsboro' , 'ghostwhite' , 'gold' , 'goldenrod' , 'gray' , 'green' , 'greenyellow' , 'grey' , 'honeydew' , 'hotpink' , 'indianred' , 'indigo' , 'ivory' , 'khaki' , 'lavender' , 'lavenderblush' , 'lawngreen' , 'lemonchiffon' , 'lightblue' , 'lightcoral' , 'lightcyan' , 'lightgoldenrodyellow' , 'lightgray' , 'lightgreen' , 'lightgrey' , 'lightpink' , 'lightsalmon' , 'lightseagreen' , 'lightskyblue' , 'lightslategrey' , 'lightsteelblue' , 'lightyellow' , 'lime' , 'limegreen' , 'linen' , 'magenta' , 'maroon' , 'mediumaquamarine' , 'mediumblue' , 'mediumorchid' , 'mediumpurple' , 'mediumseagreen' , 'mediumslateblue' , 'mediumspringgreen' , 'mediumturquoise' , 'mediumvioletred' , 'midnightblue' , 'mintcream' , 'mistyrose' , 'moccasin' , 'navajowhite' , 'navy' , 'oldlace' , 'olive' , 'olivedrab' , 'orange' , 'orangered' , 'orchid' , 'palegoldenrod' , 'palegreen' , 'paleturquoise' , 'palevioletred' , 'papayawhip' , 'peachpuff' , 'peru' , 'pink' , 'plum' , 'powderblue' , 'purple' , 'rebeccapurple' , 'red' , 'rosybrown' , 'royalblue' , 'saddlebrown' , 'salmon' , 'sandybrown' , 'seagreen' , 'seashell' , 'sienna' , 'silver' , 'skyblue' , 'slateblue' , 'slategray' , 'snow' , 'springgreen' , 'steelblue' , 'tan' , 'teal' , 'thistle' , 'tomato' , 'turquoise' , 'violet' , 'wheat' , 'white' , 'whitesmoke' , 'yellow' , 'yellowgreen' ]
146148 const valueExp = {
147- number : / ^ ( ( - ? ( \d + ( \. \d + ) ? | \. \d + ) ) ( r p x | p x | % | v w | v h ) ? | h a i r l i n e W i d t h ) $ / ,
149+ integer : / ^ ( - ? ( \d + ( \. \d + ) ? | \. \d + ) ) $ / ,
150+ length : / ^ ( ( - ? ( \d + ( \. \d + ) ? | \. \d + ) ) ( r p x | p x | % | v w | v h ) ? | h a i r l i n e W i d t h ) $ / ,
148151 color : new RegExp ( ( '^(' + namedColor . join ( '|' ) + ')$' ) + '|(^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$)|^(rgb|rgba|hsl|hsla|hwb)\\(.+\\)$' )
149152 }
150153 const type = getValueType ( prop )
151154 const tipsType = ( type ) => {
152155 const info = {
153- [ ValueType . number ] : '2rpx,10%,30rpx' ,
156+ [ ValueType . length ] : '2rpx,10%,30rpx' ,
154157 [ ValueType . color ] : 'rgb,rgba,hsl,hsla,hwb,named color,#000000' ,
155158 [ ValueType . enum ] : `${ SUPPORTED_PROP_VAL_ARR [ prop ] ?. join ( ',' ) } `
156159 }
157- tips ( `Value of ${ prop } in ${ selector } should be ${ type } , eg ${ info [ type ] } , received [${ rawValue } ], please check again!` )
160+ tips ( `Value of ${ prop } in ${ selector } should be ${ type } ${ info [ type ] ? ` , eg ${ info [ type ] } ` : '' } , received [${ rawValue } ], please check again!` )
158161 }
159162 switch ( type ) {
160- case ValueType . number : {
161- if ( ! valueExp . number . test ( valueForVerify ) ) {
163+ case ValueType . length : {
164+ if ( ! valueExp . length . test ( valueForVerify ) ) {
165+ tipsType ( type )
166+ return false
167+ }
168+ return true
169+ }
170+ case ValueType . integer : {
171+ if ( ! valueExp . integer . test ( valueForVerify ) ) {
162172 tipsType ( type )
163173 return false
164174 }
0 commit comments