[79a0317] | 1 | var all = require('./helpers').all;
|
---|
| 2 |
|
---|
| 3 | function store(serializeContext, token) {
|
---|
| 4 | var value = typeof token == 'string'
|
---|
| 5 | ? token
|
---|
| 6 | : token[1];
|
---|
| 7 | var wrap = serializeContext.wrap;
|
---|
| 8 |
|
---|
| 9 | wrap(serializeContext, value);
|
---|
| 10 | track(serializeContext, value);
|
---|
| 11 | serializeContext.output.push(value);
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | function wrap(serializeContext, value) {
|
---|
| 15 | if (serializeContext.column + value.length > serializeContext.format.wrapAt) {
|
---|
| 16 | track(serializeContext, serializeContext.format.breakWith);
|
---|
| 17 | serializeContext.output.push(serializeContext.format.breakWith);
|
---|
| 18 | }
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | function track(serializeContext, value) {
|
---|
| 22 | var parts = value.split('\n');
|
---|
| 23 |
|
---|
| 24 | serializeContext.line += parts.length - 1;
|
---|
| 25 | serializeContext.column = parts.length > 1 ? 0 : (serializeContext.column + parts.pop().length);
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | function serializeStyles(tokens, context) {
|
---|
| 29 | var serializeContext = {
|
---|
| 30 | column: 0,
|
---|
| 31 | format: context.options.format,
|
---|
| 32 | indentBy: 0,
|
---|
| 33 | indentWith: '',
|
---|
| 34 | line: 1,
|
---|
| 35 | output: [],
|
---|
| 36 | spaceAfterClosingBrace: context.options.compatibility.properties.spaceAfterClosingBrace,
|
---|
| 37 | store: store,
|
---|
| 38 | wrap: context.options.format.wrapAt
|
---|
| 39 | ? wrap
|
---|
| 40 | : function() { /* noop */ }
|
---|
| 41 | };
|
---|
| 42 |
|
---|
| 43 | all(serializeContext, tokens);
|
---|
| 44 |
|
---|
| 45 | return { styles: serializeContext.output.join('') };
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | module.exports = serializeStyles;
|
---|