@@ -92,18 +92,18 @@ define(function () { 'use strict';
92
92
* @param {string } prefix - the current property or a prefix in case of nested
93
93
* sub-properties.
94
94
* @param {boolean } local - are we in @local or in @global scope.
95
- * @param {function } localize - @local helper.
95
+ * @param {function } state - @local helper.
96
96
*/
97
97
98
- function declarations ( o , emit , prefix , local , localize ) {
98
+ function declarations ( o , emit , prefix , local , state ) {
99
99
var k , v , kk
100
100
if ( o == null ) return
101
101
102
102
switch ( type . call ( o = o . valueOf ( ) ) ) {
103
103
case ARRAY :
104
104
for ( k = 0 ; k < o . length ; k ++ )
105
105
106
- declarations ( o [ k ] , emit , prefix , local , localize )
106
+ declarations ( o [ k ] , emit , prefix , local , state )
107
107
108
108
break
109
109
case OBJECT :
@@ -115,12 +115,12 @@ define(function () { 'use strict';
115
115
if ( / \$ / . test ( k ) ) {
116
116
for ( kk in ( k = k . split ( '$' ) ) ) if ( own . call ( k , kk ) ) {
117
117
118
- declarations ( v , emit , prefix + k [ kk ] , local , localize )
118
+ declarations ( v , emit , prefix + k [ kk ] , local , state )
119
119
120
120
}
121
121
} else {
122
122
123
- declarations ( v , emit , prefix + k , local , localize )
123
+ declarations ( v , emit , prefix + k , local , state )
124
124
125
125
}
126
126
}
@@ -138,10 +138,10 @@ define(function () { 'use strict';
138
138
139
139
if ( local && ( k == 'animation-name' || k == 'animation' || k == 'list-style' ) ) {
140
140
// no need to tokenize here a plain `.split(',')` has all bases covered.
141
- // We may 'localize ' a comment, but it's not a big deal.
141
+ // We may 'state ' a comment, but it's not a big deal.
142
142
o = o . split ( ',' ) . map ( function ( o ) {
143
143
144
- return o . replace ( / : ? g l o b a l \( \s * ( [ _ A - Z a - z ] [ - \w ] * ) \s * \) | ( ) ( - ? [ _ A - Z a - z ] [ - \w ] * ) / , localize )
144
+ return o . replace ( / : ? g l o b a l \( \s * ( [ _ A - Z a - z ] [ - \w ] * ) \s * \) | ( ) ( - ? [ _ A - Z a - z ] [ - \w ] * ) / , state . l )
145
145
146
146
} ) . join ( ',' )
147
147
}
@@ -160,23 +160,19 @@ define(function () { 'use strict';
160
160
* @param {string[] } v - Either parameters for block-less rules or their block
161
161
* for the others.
162
162
* @param {string } prefix - the current selector or a prefix in case of nested rules
163
- * @param {string } composes - the potential target of a @composes rule, if any
163
+ * @param {string } inAtRule - are we nested in an at- rule?
164
164
* @param {boolean } local - are we in @local or in @global scope?
165
- * @param {function } localize - @local helper
165
+ * @param {function } state - @local helper
166
166
*/
167
167
168
- function atRules ( k , v , emit , prefix , composes , local , localize ) {
168
+ function atRules ( k , v , emit , prefix , inAtRule , local , state ) {
169
169
k = / ^ ( .(?: - [ \w ] + - ) ? ( [ _ A - Z a - z ] [ - \w ] * ) ) \b \s * ( .* ?) \s * $ / . exec ( k ) || [ '@' , '@' , '' , '' ]
170
170
if ( ! k [ 3 ] && / ^ g l o b a l $ / . test ( k [ 2 ] ) ) {
171
- sheet ( v , emit , prefix , 1 , 0 , localize )
171
+ sheet ( v , emit , prefix , inAtRule , 0 , state )
172
172
173
173
} else if ( ! k [ 3 ] && / ^ l o c a l $ / . test ( k [ 2 ] ) ) {
174
174
175
- sheet ( v , emit , prefix , 1 , 1 , localize )
176
-
177
- } else if ( ! k [ 3 ] && / ^ m i x i n $ / . test ( k [ 2 ] ) ) {
178
-
179
- sheet ( v , emit , prefix , composes , local , localize )
175
+ sheet ( v , emit , prefix , inAtRule , 1 , state )
180
176
181
177
} else if ( ! k [ 3 ] && / ^ (?: n a m e s p a c e | i m p o r t | c h a r s e t ) $ / . test ( k [ 2 ] ) ) {
182
178
flatIter ( function ( v ) {
@@ -185,45 +181,45 @@ define(function () { 'use strict';
185
181
186
182
} ) ( v )
187
183
188
- } else if ( ! k [ 3 ] && / ^ (?: f o n t - f a c e | v i e w p o r t | s w a s h | o r n a m e n t s | a n n o t a t i o n | s t y l i s t i c | s t y l e s e t | c h a r a c t e r - v a r i a n t ) $ / . test ( k [ 2 ] ) ) {
184
+ } else if ( ! k [ 3 ] && / ^ (?: f o n t - f a c e | v i e w p o r t ) $ / . test ( k [ 2 ] ) ) {
189
185
flatIter ( function ( v ) {
190
186
191
187
emit . a ( k [ 1 ] , '' , '' , ' {\n' )
192
188
193
- declarations ( v , emit , '' , local , localize )
189
+ declarations ( v , emit , '' , local , state )
194
190
195
191
emit . c ( '}\n' )
196
192
197
193
} ) ( v )
198
194
199
- } else if ( k [ 3 ] && / ^ (?: m e d i a | s u p p o r t s | d o c u m e n t | p a g e | k e y f r a m e s | c o u n t e r - s t y l e | f o n t - f e a t u r e - v a l u e s ) $ / . test ( k [ 2 ] ) ) {
195
+ } else if ( k [ 3 ] && / ^ (?: m e d i a | s u p p o r t s | p a g e | k e y f r a m e s ) $ / . test ( k [ 2 ] ) ) {
200
196
201
- if ( local && / ^ (?: k e y f r a m e s | c o u n t e r - s t y l e ) $ / . test ( k [ 2 ] ) ) {
197
+ if ( local && ' keyframes' == k [ 2 ] ) {
202
198
k [ 3 ] = k [ 3 ] . replace (
203
199
// generated by script/regexps.js
204
200
/ : ? g l o b a l \( \s * ( [ _ A - Z a - z ] [ - \w ] * ) \s * \) | ( ) ( - ? [ _ A - Z a - z ] [ - \w ] * ) / ,
205
- localize
201
+ state . l
206
202
)
207
203
}
208
204
209
205
210
206
emit . a ( k [ 1 ] , ' ' , k [ 3 ] , ' {\n' )
211
207
212
- if ( / ^ (?: p a g e | c o u n t e r - s t y l e ) $ / . test ( k [ 2 ] ) ) {
208
+ if ( ' page' == k [ 2 ] ) {
213
209
214
- declarations ( v , emit , '' , local , localize )
210
+ declarations ( v , emit , '' , local , state )
215
211
216
212
} else {
217
213
218
- sheet ( v , emit , prefix , 1 , local , localize )
214
+ sheet ( v , emit , prefix , 0 , local , state )
219
215
220
216
}
221
217
222
218
emit . c ( '}\n' )
223
219
224
220
} else {
225
- for ( var i = 0 ; i < localize . a . length ; i ++ ) {
226
- if ( localize . a [ i ] ( k , v , emit , prefix , composes , local , localize , sheet , declarations ) ) return
221
+ for ( var i = 0 ; i < state . A . length ; i ++ ) {
222
+ if ( state . A [ i ] ( k , v , emit , prefix , inAtRule , local , state ) ) return
227
223
}
228
224
emit . a ( '@-error-unsupported-at-rule' , ' ' , JSON . stringify ( k [ 0 ] ) , ';\n' )
229
225
@@ -236,19 +232,19 @@ define(function () { 'use strict';
236
232
* @param {array|string|object } statements - a source object or sub-object.
237
233
* @param {string[] } emit - the contextual emitters to the final buffer
238
234
* @param {string } prefix - the current selector or a prefix in case of nested rules
239
- * @param {string } composes - the potential target of a @composes rule, if any
235
+ * @param {string } canCompose - are we allowed to @compose here?
240
236
* @param {boolean } local - are we in @local or in @global scope?
241
- * @param {function } localize - @local helper
237
+ * @param {function } state - @local helper
242
238
*/
243
- function sheet ( statements , emit , prefix , composes , local , localize ) {
239
+ function sheet ( statements , emit , prefix , canCompose , local , state ) {
244
240
var k , v , inDeclaration , kk
245
241
246
242
switch ( type . call ( statements ) ) {
247
243
248
244
case ARRAY :
249
245
for ( k = 0 ; k < statements . length ; k ++ ) {
250
246
251
- sheet ( statements [ k ] , emit , prefix , composes , local , localize )
247
+ sheet ( statements [ k ] , emit , prefix , canCompose , local , state )
252
248
253
249
}
254
250
break
@@ -266,20 +262,20 @@ define(function () { 'use strict';
266
262
if ( / \$ / . test ( k ) ) {
267
263
for ( kk in ( k = k . split ( '$' ) ) ) if ( own . call ( k , kk ) ) {
268
264
269
- declarations ( v , emit , k [ kk ] , local , localize )
265
+ declarations ( v , emit , k [ kk ] , local , state )
270
266
271
267
}
272
268
} else {
273
269
274
- declarations ( v , emit , k , local , localize )
270
+ declarations ( v , emit , k , local , state )
275
271
276
272
}
277
273
} else if ( / ^ @ / . test ( k ) ) {
278
274
// Handle At-rules
279
275
280
276
inDeclaration = ( inDeclaration && emit . c ( '}\n' ) && 0 )
281
277
282
- atRules ( k , v , emit , prefix , composes , local , localize )
278
+ atRules ( k , v , emit , prefix , canCompose , local , state )
283
279
284
280
} else {
285
281
// selector or nested sub-selectors
@@ -291,7 +287,7 @@ define(function () { 'use strict';
291
287
/*0*/ ( kk = splitSelector ( prefix ) , splitSelector ( local ?
292
288
293
289
k . replace (
294
- / : g l o b a l \( \s * ( \. - ? [ _ A - Z a - z ] [ - \w ] * ) \s * \) | ( \. ) ( - ? [ _ A - Z a - z ] [ - \w ] * ) / g, localize
290
+ / : g l o b a l \( \s * ( \. - ? [ _ A - Z a - z ] [ - \w ] * ) \s * \) | ( \. ) ( - ? [ _ A - Z a - z ] [ - \w ] * ) / g, state . l
295
291
) :
296
292
297
293
k
@@ -305,7 +301,7 @@ define(function () { 'use strict';
305
301
local ?
306
302
307
303
k . replace (
308
- / : g l o b a l \( \s * ( \. - ? [ _ A - Z a - z ] [ - \w ] * ) \s * \) | ( \. ) ( - ? [ _ A - Z a - z ] [ - \w ] * ) / g, localize
304
+ / : g l o b a l \( \s * ( \. - ? [ _ A - Z a - z ] [ - \w ] * ) \s * \) | ( \. ) ( - ? [ _ A - Z a - z ] [ - \w ] * ) / g, state . l
309
305
) :
310
306
311
307
k ,
@@ -315,13 +311,13 @@ define(function () { 'use strict';
315
311
local ?
316
312
317
313
k . replace (
318
- / : g l o b a l \( \s * ( \. - ? [ _ A - Z a - z ] [ - \w ] * ) \s * \) | ( \. ) ( - ? [ _ A - Z a - z ] [ - \w ] * ) / g, localize
314
+ / : g l o b a l \( \s * ( \. - ? [ _ A - Z a - z ] [ - \w ] * ) \s * \) | ( \. ) ( - ? [ _ A - Z a - z ] [ - \w ] * ) / g, state . l
319
315
) :
320
316
321
317
k
322
318
) ,
323
- composes || prefix ? '' : k ,
324
- local , localize
319
+ canCompose ,
320
+ local , state
325
321
)
326
322
}
327
323
}
@@ -334,7 +330,7 @@ define(function () { 'use strict';
334
330
335
331
emit . s ( ( prefix || ':-error-no-selector' ) , ' {\n' )
336
332
337
- declarations ( statements , emit , '' , local , localize )
333
+ declarations ( statements , emit , '' , local , state )
338
334
339
335
emit . c ( '}\n' )
340
336
}
@@ -412,7 +408,7 @@ define(function () { 'use strict';
412
408
_default ( instance , plugin )
413
409
} )
414
410
415
- function makeEmitter ( inline ) {
411
+ function makeEmitter ( inline , state ) {
416
412
var buf = [ ]
417
413
function push ( ) {
418
414
emptyArray . push . apply ( buf , arguments )
@@ -424,21 +420,10 @@ define(function () { 'use strict';
424
420
d : push , // declaration
425
421
c : push // close
426
422
}
427
- for ( var i = filters . length ; i -- ; ) emit = filters [ i ] ( emit , inline )
423
+ for ( var i = filters . length ; i -- ; ) emit = filters [ i ] ( emit , inline , state )
428
424
return emit
429
425
}
430
426
431
- instance . compose = function ( target , source ) {
432
- if ( ! / ^ - ? [ _ A - Z a - z ] [ - \w ] * $ / . test ( target ) )
433
- throw new Error ( 'Bad target class ' + JSON . stringify ( target ) )
434
-
435
- localize ( 0 , 0 , 0 , target )
436
-
437
- flatIter ( function ( source ) {
438
- instance . names [ target ] = instance . names [ target ] + ' ' + source
439
- } ) ( source )
440
- }
441
-
442
427
function localize ( match , global , dot , name ) {
443
428
if ( global ) return global
444
429
if ( ! instance . names [ name ] ) instance . names [ name ] = name + instance . suffix
@@ -449,24 +434,40 @@ define(function () { 'use strict';
449
434
450
435
/*/-statements-/*/
451
436
instance . sheet = function ( statements , emit ) {
437
+ var state = {
438
+ s : sheet ,
439
+ a : atRules ,
440
+ d : declarations ,
441
+ A : atHandlers ,
442
+ l : localize ,
443
+ n : instance . names
444
+ }
452
445
sheet (
453
446
statements ,
454
- emit = makeEmitter ( false ) ,
447
+ emit = makeEmitter ( false , state ) ,
455
448
'' , '' , // prefix and compose
456
449
1 , // local, by default
457
- localize
450
+ state
458
451
)
459
452
460
453
return emit . x ( )
461
454
}
462
455
/*/-statements-/*/
463
456
instance . inline = function ( _declarations , emit ) {
457
+ var state = {
458
+ s : sheet ,
459
+ a : atRules ,
460
+ d : declarations ,
461
+ A : atHandlers ,
462
+ l : localize ,
463
+ n : instance . names
464
+ }
464
465
declarations (
465
466
_declarations ,
466
- emit = makeEmitter ( true ) ,
467
+ emit = makeEmitter ( true , state ) ,
467
468
'' , // prefix
468
469
1 , //local
469
- localize
470
+ state
470
471
)
471
472
return emit . x ( )
472
473
}
@@ -475,7 +476,7 @@ define(function () { 'use strict';
475
476
}
476
477
477
478
var _j2c = j2c ( )
478
- 'sheet|inline|names|at|global|kv|suffix|compose ' . split ( '|' ) . map ( function ( m ) { j2c [ m ] = _j2c [ m ] } )
479
+ 'sheet|inline|names|at|global|kv|suffix' . split ( '|' ) . map ( function ( m ) { j2c [ m ] = _j2c [ m ] } )
479
480
480
481
return j2c ;
481
482
0 commit comments