source: trip-planner-front/node_modules/css/lib/stringify/compress.js@ 188ee53

Last change on this file since 188ee53 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[6a3a178]1
2/**
3 * Module dependencies.
4 */
5
6var Base = require('./compiler');
7var inherits = require('inherits');
8
9/**
10 * Expose compiler.
11 */
12
13module.exports = Compiler;
14
15/**
16 * Initialize a new `Compiler`.
17 */
18
19function Compiler(options) {
20 Base.call(this, options);
21}
22
23/**
24 * Inherit from `Base.prototype`.
25 */
26
27inherits(Compiler, Base);
28
29/**
30 * Compile `node`.
31 */
32
33Compiler.prototype.compile = function(node){
34 return node.stylesheet
35 .rules.map(this.visit, this)
36 .join('');
37};
38
39/**
40 * Visit comment node.
41 */
42
43Compiler.prototype.comment = function(node){
44 return this.emit('', node.position);
45};
46
47/**
48 * Visit import node.
49 */
50
51Compiler.prototype.import = function(node){
52 return this.emit('@import ' + node.import + ';', node.position);
53};
54
55/**
56 * Visit media node.
57 */
58
59Compiler.prototype.media = function(node){
60 return this.emit('@media ' + node.media, node.position)
61 + this.emit('{')
62 + this.mapVisit(node.rules)
63 + this.emit('}');
64};
65
66/**
67 * Visit document node.
68 */
69
70Compiler.prototype.document = function(node){
71 var doc = '@' + (node.vendor || '') + 'document ' + node.document;
72
73 return this.emit(doc, node.position)
74 + this.emit('{')
75 + this.mapVisit(node.rules)
76 + this.emit('}');
77};
78
79/**
80 * Visit charset node.
81 */
82
83Compiler.prototype.charset = function(node){
84 return this.emit('@charset ' + node.charset + ';', node.position);
85};
86
87/**
88 * Visit namespace node.
89 */
90
91Compiler.prototype.namespace = function(node){
92 return this.emit('@namespace ' + node.namespace + ';', node.position);
93};
94
95/**
96 * Visit supports node.
97 */
98
99Compiler.prototype.supports = function(node){
100 return this.emit('@supports ' + node.supports, node.position)
101 + this.emit('{')
102 + this.mapVisit(node.rules)
103 + this.emit('}');
104};
105
106/**
107 * Visit keyframes node.
108 */
109
110Compiler.prototype.keyframes = function(node){
111 return this.emit('@'
112 + (node.vendor || '')
113 + 'keyframes '
114 + node.name, node.position)
115 + this.emit('{')
116 + this.mapVisit(node.keyframes)
117 + this.emit('}');
118};
119
120/**
121 * Visit keyframe node.
122 */
123
124Compiler.prototype.keyframe = function(node){
125 var decls = node.declarations;
126
127 return this.emit(node.values.join(','), node.position)
128 + this.emit('{')
129 + this.mapVisit(decls)
130 + this.emit('}');
131};
132
133/**
134 * Visit page node.
135 */
136
137Compiler.prototype.page = function(node){
138 var sel = node.selectors.length
139 ? node.selectors.join(', ')
140 : '';
141
142 return this.emit('@page ' + sel, node.position)
143 + this.emit('{')
144 + this.mapVisit(node.declarations)
145 + this.emit('}');
146};
147
148/**
149 * Visit font-face node.
150 */
151
152Compiler.prototype['font-face'] = function(node){
153 return this.emit('@font-face', node.position)
154 + this.emit('{')
155 + this.mapVisit(node.declarations)
156 + this.emit('}');
157};
158
159/**
160 * Visit host node.
161 */
162
163Compiler.prototype.host = function(node){
164 return this.emit('@host', node.position)
165 + this.emit('{')
166 + this.mapVisit(node.rules)
167 + this.emit('}');
168};
169
170/**
171 * Visit custom-media node.
172 */
173
174Compiler.prototype['custom-media'] = function(node){
175 return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position);
176};
177
178/**
179 * Visit rule node.
180 */
181
182Compiler.prototype.rule = function(node){
183 var decls = node.declarations;
184 if (!decls.length) return '';
185
186 return this.emit(node.selectors.join(','), node.position)
187 + this.emit('{')
188 + this.mapVisit(decls)
189 + this.emit('}');
190};
191
192/**
193 * Visit declaration node.
194 */
195
196Compiler.prototype.declaration = function(node){
197 return this.emit(node.property + ':' + node.value, node.position) + this.emit(';');
198};
199
Note: See TracBrowser for help on using the repository browser.