@@ -44,7 +44,10 @@ const featureValidatorMap = {
4444 'device-width' : 'number' ,
4545 'min-device-width' : 'number' ,
4646 'max-device-width' : 'number' ,
47- 'prefers-color-scheme' : 'preferColorScheme'
47+ 'prefers-color-scheme' : 'preferColorScheme' ,
48+ scene : 'scene' ,
49+ 'widget-size' : 'widgetSize' ,
50+ 'device-type' : 'deviceType'
4851}
4952
5053/**
@@ -107,6 +110,64 @@ const featureValidator = {
107110 }
108111 }
109112 } ,
113+ scene ( value ) {
114+ const reg =
115+ / ^ ( a s s i s t a n t s c r e e n | l a u n c h e r | g l o b a l s e a r c h | c a l e n d a r | l o c k s c r e e n | s u g g e s t i o n | v o i c e a s s i s t a n t | s m s | s e r v i c e c e n t e r ) $ /
116+ if ( reg . test ( value ) ) {
117+ return { value }
118+ }
119+ return {
120+ reason : function ( feature ) {
121+ return (
122+ 'WARN: 媒体特征 `' +
123+ feature +
124+ '` 的值 `' +
125+ value +
126+ '` 不正确, 必须为 `assistantscreen | launcher | globalsearch | calendar | lockscreen | suggestion | voiceassistant | sms | servicecenter`'
127+ )
128+ }
129+ }
130+ } ,
131+ widgetSize ( value ) {
132+ if ( value ) {
133+ let sizeStr = value . trim ( )
134+ if ( sizeStr [ 0 ] === '"' || sizeStr [ 0 ] === "'" ) {
135+ sizeStr = sizeStr . slice ( 1 , sizeStr . length - 1 )
136+ }
137+ const reg = / ^ ( 1 x 1 | 1 x 2 | 2 x 1 | 2 x 2 | 4 x 2 | 4 x 4 | 4 x N ) $ /
138+ if ( reg . test ( sizeStr ) ) {
139+ return { value : sizeStr }
140+ }
141+ }
142+ return {
143+ reason : function ( feature ) {
144+ return (
145+ 'WARN: 媒体特征 `' +
146+ feature +
147+ '` 的值 `' +
148+ value +
149+ '` 不正确, 必须为 `1x1 | 1x2 | 2x1 | 2x2 | 4x2 | 4x4 | 4xN`'
150+ )
151+ }
152+ }
153+ } ,
154+ deviceType ( value ) {
155+ const reg = / ^ ( p h o n e | w a t c h | c a r ) $ /
156+ if ( reg . test ( value ) ) {
157+ return { value }
158+ }
159+ return {
160+ reason : function ( feature ) {
161+ return (
162+ 'WARN: 媒体特征 `' +
163+ feature +
164+ '` 的值 `' +
165+ value +
166+ '` 不正确, 必须为 `phone | watch | car`'
167+ )
168+ }
169+ }
170+ } ,
110171 ratio ( value ) {
111172 const reg = / ^ ( \d + \s * \/ \s * \d + | \d + \. \d + | \d + ) $ /
112173 if ( reg . test ( value ) ) {
0 commit comments