@exadel/esl
Version:
Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components
34 lines (33 loc) • 1.02 kB
JavaScript
import { ALL, NOT_ALL } from './media-query-const';
export class MediaQueryNegation {
constructor(condition) {
this.condition = condition;
}
get matches() {
return !this.condition.matches;
}
optimize() {
if (ALL.eq(this.condition))
return NOT_ALL;
if (NOT_ALL.eq(this.condition))
return ALL;
if (this.condition instanceof MediaQueryNegation) {
return this.condition.condition.optimize();
}
return this;
}
toString() {
const query = this.condition.toString();
const complex = /\)[\s\w]+\(/.test(query);
return (complex ? `not (${query})` : `not ${query}`).trim();
}
addEventListener(...args) {
this.condition.addEventListener.apply(this.condition, args);
}
removeEventListener(...args) {
this.condition.removeEventListener.apply(this.condition, args);
}
dispatchEvent(event) {
return this.condition.dispatchEvent(event);
}
}