|
|
|
@ -30,18 +30,14 @@ function minify_declarations(
|
|
|
|
start: number,
|
|
|
|
start: number,
|
|
|
|
declarations: Declaration[]
|
|
|
|
declarations: Declaration[]
|
|
|
|
): number {
|
|
|
|
): number {
|
|
|
|
let c = start;
|
|
|
|
return declarations.reduce((result, declaration, i) => {
|
|
|
|
|
|
|
|
|
|
|
|
declarations.forEach((declaration, i) => {
|
|
|
|
|
|
|
|
const separator = i > 0 ? ';' : '';
|
|
|
|
const separator = i > 0 ? ';' : '';
|
|
|
|
if ((declaration.node.start - c) > separator.length) {
|
|
|
|
if ((declaration.node.start - result) > separator.length) {
|
|
|
|
code.overwrite(c, declaration.node.start, separator);
|
|
|
|
code.overwrite(result, declaration.node.start, separator);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
declaration.minify(code);
|
|
|
|
declaration.minify(code);
|
|
|
|
c = declaration.node.end;
|
|
|
|
return declaration.node.end;
|
|
|
|
});
|
|
|
|
}, start);
|
|
|
|
|
|
|
|
|
|
|
|
return c;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class Rule {
|
|
|
|
class Rule {
|
|
|
|
@ -72,7 +68,7 @@ class Rule {
|
|
|
|
let started = false;
|
|
|
|
let started = false;
|
|
|
|
|
|
|
|
|
|
|
|
this.selectors.forEach((selector) => {
|
|
|
|
this.selectors.forEach((selector) => {
|
|
|
|
if (selector.used) {
|
|
|
|
if (!selector.used) return;
|
|
|
|
const separator = started ? ',' : '';
|
|
|
|
const separator = started ? ',' : '';
|
|
|
|
if ((selector.node.start - c) > separator.length) {
|
|
|
|
if ((selector.node.start - c) > separator.length) {
|
|
|
|
code.overwrite(c, selector.node.start, separator);
|
|
|
|
code.overwrite(c, selector.node.start, separator);
|
|
|
|
@ -82,7 +78,6 @@ class Rule {
|
|
|
|
c = selector.node.end;
|
|
|
|
c = selector.node.end;
|
|
|
|
|
|
|
|
|
|
|
|
started = true;
|
|
|
|
started = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
code.remove(c, this.node.block.start);
|
|
|
|
code.remove(c, this.node.block.start);
|
|
|
|
@ -128,17 +123,15 @@ class Declaration {
|
|
|
|
|
|
|
|
|
|
|
|
transform(code: MagicString, keyframes: Map<string, string>) {
|
|
|
|
transform(code: MagicString, keyframes: Map<string, string>) {
|
|
|
|
const property = this.node.property && remove_css_prefix(this.node.property.toLowerCase());
|
|
|
|
const property = this.node.property && remove_css_prefix(this.node.property.toLowerCase());
|
|
|
|
if (property === 'animation' || property === 'animation-name') {
|
|
|
|
if (property !== 'animation' && property !== 'animation-name') return;
|
|
|
|
this.node.value.children.forEach((block: CssNode) => {
|
|
|
|
this.node.value.children.forEach((block: CssNode) => {
|
|
|
|
if (block.type === 'Identifier') {
|
|
|
|
if (block.type !== 'Identifier') return;
|
|
|
|
const name = block.name;
|
|
|
|
const name = block.name;
|
|
|
|
if (keyframes.has(name)) {
|
|
|
|
if (keyframes.has(name)) {
|
|
|
|
code.overwrite(block.start, block.end, keyframes.get(name));
|
|
|
|
code.overwrite(block.start, block.end, keyframes.get(name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
minify(code: MagicString) {
|
|
|
|
minify(code: MagicString) {
|
|
|
|
if (!this.node.property) return; // @apply, and possibly other weird cases?
|
|
|
|
if (!this.node.property) return; // @apply, and possibly other weird cases?
|
|
|
|
@ -174,9 +167,7 @@ class Atrule {
|
|
|
|
|
|
|
|
|
|
|
|
apply(node: Element) {
|
|
|
|
apply(node: Element) {
|
|
|
|
if (this.node.name === 'media' || this.node.name === 'supports' || this.node.name === 'layer') {
|
|
|
|
if (this.node.name === 'media' || this.node.name === 'supports' || this.node.name === 'layer') {
|
|
|
|
this.children.forEach(child => {
|
|
|
|
this.children.forEach(child => child.apply(node));
|
|
|
|
child.apply(node);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
} else if (is_keyframes_node(this.node)) {
|
|
|
|
} else if (is_keyframes_node(this.node)) {
|
|
|
|
this.children.forEach((rule: Rule) => {
|
|
|
|
this.children.forEach((rule: Rule) => {
|
|
|
|
rule.selectors.forEach(selector => {
|
|
|
|
rule.selectors.forEach(selector => {
|
|
|
|
@ -246,7 +237,7 @@ class Atrule {
|
|
|
|
transform(code: MagicString, id: string, keyframes: Map<string, string>, max_amount_class_specificity_increased: number) {
|
|
|
|
transform(code: MagicString, id: string, keyframes: Map<string, string>, max_amount_class_specificity_increased: number) {
|
|
|
|
if (is_keyframes_node(this.node)) {
|
|
|
|
if (is_keyframes_node(this.node)) {
|
|
|
|
this.node.prelude.children.forEach(({ type, name, start, end }: CssNode) => {
|
|
|
|
this.node.prelude.children.forEach(({ type, name, start, end }: CssNode) => {
|
|
|
|
if (type === 'Identifier') {
|
|
|
|
if (type !== 'Identifier') return;
|
|
|
|
if (name.startsWith('-global-')) {
|
|
|
|
if (name.startsWith('-global-')) {
|
|
|
|
code.remove(start, start + 8);
|
|
|
|
code.remove(start, start + 8);
|
|
|
|
this.children.forEach((rule: Rule) => {
|
|
|
|
this.children.forEach((rule: Rule) => {
|
|
|
|
@ -257,7 +248,6 @@ class Atrule {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
code.overwrite(start, end, keyframes.get(name));
|
|
|
|
code.overwrite(start, end, keyframes.get(name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -267,17 +257,12 @@ class Atrule {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
validate(component: Component) {
|
|
|
|
validate(component: Component) {
|
|
|
|
this.children.forEach(child => {
|
|
|
|
this.children.forEach(child => child.validate(component));
|
|
|
|
child.validate(component);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
warn_on_unused_selector(handler: (selector: Selector) => void) {
|
|
|
|
warn_on_unused_selector(handler: (selector: Selector) => void) {
|
|
|
|
if (this.node.name !== 'media') return;
|
|
|
|
if (this.node.name !== 'media') return;
|
|
|
|
|
|
|
|
this.children.forEach(child => child.warn_on_unused_selector(handler));
|
|
|
|
this.children.forEach(child => {
|
|
|
|
|
|
|
|
child.warn_on_unused_selector(handler);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
get_max_amount_class_specificity_increased() {
|
|
|
|
get_max_amount_class_specificity_increased() {
|
|
|
|
@ -322,8 +307,11 @@ export default class Stylesheet {
|
|
|
|
this.ast = ast;
|
|
|
|
this.ast = ast;
|
|
|
|
this.filename = filename;
|
|
|
|
this.filename = filename;
|
|
|
|
this.dev = dev;
|
|
|
|
this.dev = dev;
|
|
|
|
|
|
|
|
if (!ast.css || !ast.css.children.length) {
|
|
|
|
|
|
|
|
this.has_styles = false;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (ast.css && ast.css.children.length) {
|
|
|
|
|
|
|
|
this.id = get_css_hash({
|
|
|
|
this.id = get_css_hash({
|
|
|
|
filename,
|
|
|
|
filename,
|
|
|
|
name: component_name,
|
|
|
|
name: component_name,
|
|
|
|
@ -387,9 +375,7 @@ export default class Stylesheet {
|
|
|
|
depth -= 1;
|
|
|
|
depth -= 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
|
|
|
|
this.has_styles = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
apply(node: Element) {
|
|
|
|
apply(node: Element) {
|
|
|
|
@ -402,9 +388,7 @@ export default class Stylesheet {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
reify() {
|
|
|
|
reify() {
|
|
|
|
this.nodes_with_css_class.forEach((node: Element) => {
|
|
|
|
this.nodes_with_css_class.forEach((node: Element) => node.add_css_class());
|
|
|
|
node.add_css_class();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render(file: string, should_transform_selectors: boolean) {
|
|
|
|
render(file: string, should_transform_selectors: boolean) {
|
|
|
|
@ -450,9 +434,7 @@ export default class Stylesheet {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
validate(component: Component) {
|
|
|
|
validate(component: Component) {
|
|
|
|
this.children.forEach(child => {
|
|
|
|
this.children.forEach(child => child.validate(component));
|
|
|
|
child.validate(component);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
warn_on_unused_selectors(component: Component) {
|
|
|
|
warn_on_unused_selectors(component: Component) {
|
|
|
|
|