12345678910111213141516171819202122232425262728 |
- import * as AST from '../ast';
- import Env, { EnvError } from '../env';
-
- export class MediaQuery {
- public predicate: AST.MediaQueryPredicate;
- public children: AST.Node[];
-
- public constructor(predicate: AST.MediaQueryPredicate, children: AST.Node[]) {
- this.predicate = predicate;
- this.children = children;
- }
-
- public compile(env: Env, opts: AST.Opts): string | EnvError {
- const lineSpacer = opts.prettyPrint ? '\n' : '';
- const wordSpacer = opts.prettyPrint ? ' ' : '';
- const predicate = this.predicate.compile(env, opts);
-
- const children = this.children.map((child) =>
- child.compile(env, { ...opts, depth: opts.depth + 2 })
- );
- const childrenError = children.find((node) => node instanceof EnvError);
- if (childrenError instanceof EnvError) return childrenError;
-
- return `@media(${predicate})${wordSpacer}{${lineSpacer}${children.join(
- lineSpacer
- )}${lineSpacer}}`;
- }
- }
|