@dooboostore/dom-render
Version:
html view template engine
147 lines • 3.75 kB
JavaScript
import { Compiler as BaseCompiler } from './compiler';
/**
* Compressed CSS compiler
*/
export class CompressCompiler extends BaseCompiler {
/**
* Override emit to handle position
*/
emit(str, pos) {
return super.emit(str);
}
/**
* Compile `node`.
*/
compile(node) {
return node.stylesheet.rules.map(rule => this.visit(rule)).join('');
}
/**
* Visit comment node.
*/
comment(node) {
return this.emit('', node.position);
}
/**
* Visit import node.
*/
import(node) {
return this.emit('@import ' + node.import + ';', node.position);
}
/**
* Visit media node.
*/
media(node) {
return this.emit('@media ' + node.media, node.position)
+ this.emit('{')
+ this.mapVisit(node.rules)
+ this.emit('}');
}
/**
* Visit document node.
*/
document(node) {
const doc = '@' + (node.vendor || '') + 'document ' + node.document;
return this.emit(doc, node.position)
+ this.emit('{')
+ this.mapVisit(node.rules)
+ this.emit('}');
}
/**
* Visit charset node.
*/
charset(node) {
return this.emit('@charset ' + node.charset + ';', node.position);
}
/**
* Visit namespace node.
*/
namespace(node) {
return this.emit('@namespace ' + node.namespace + ';', node.position);
}
/**
* Visit supports node.
*/
supports(node) {
return this.emit('@supports ' + node.supports, node.position)
+ this.emit('{')
+ this.mapVisit(node.rules)
+ this.emit('}');
}
/**
* Visit keyframes node.
*/
keyframes(node) {
return this.emit('@'
+ (node.vendor || '')
+ 'keyframes '
+ node.name, node.position)
+ this.emit('{')
+ this.mapVisit(node.keyframes)
+ this.emit('}');
}
/**
* Visit keyframe node.
*/
keyframe(node) {
const decls = node.declarations;
return this.emit(node.values.join(','), node.position)
+ this.emit('{')
+ this.mapVisit(decls)
+ this.emit('}');
}
/**
* Visit page node.
*/
page(node) {
const sel = node.selectors.length
? node.selectors.join(', ')
: '';
return this.emit('@page ' + sel, node.position)
+ this.emit('{')
+ this.mapVisit(node.declarations)
+ this.emit('}');
}
/**
* Visit font-face node.
*/
'font-face'(node) {
return this.emit('@font-face', node.position)
+ this.emit('{')
+ this.mapVisit(node.declarations)
+ this.emit('}');
}
/**
* Visit host node.
*/
host(node) {
return this.emit('@host', node.position)
+ this.emit('{')
+ this.mapVisit(node.rules)
+ this.emit('}');
}
/**
* Visit custom-media node.
*/
'custom-media'(node) {
return this.emit('@custom-media ' + node.name + ' ' + node.media + ';', node.position);
}
/**
* Visit rule node.
*/
rule(node) {
const decls = node.declarations;
if (!decls.length)
return '';
return this.emit(node.selectors.join(','), node.position)
+ this.emit('{')
+ this.mapVisit(decls)
+ this.emit('}');
}
/**
* Visit declaration node.
*/
declaration(node) {
return this.emit(node.property + ':' + node.value, node.position) + this.emit(';');
}
}
//# sourceMappingURL=compress.js.map