A stylesheet language written in TypeScript that compiles to CSS
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

mediaQuery.ts 933B

12345678910111213141516171819202122232425262728
  1. import * as AST from '../ast';
  2. import Env, { EnvError } from '../env';
  3. export class MediaQuery {
  4. public predicate: AST.MediaQueryPredicate;
  5. public children: AST.Node[];
  6. public constructor(predicate: AST.MediaQueryPredicate, children: AST.Node[]) {
  7. this.predicate = predicate;
  8. this.children = children;
  9. }
  10. public compile(env: Env, opts: AST.Opts): string | EnvError {
  11. const lineSpacer = opts.prettyPrint ? '\n' : '';
  12. const wordSpacer = opts.prettyPrint ? ' ' : '';
  13. const predicate = this.predicate.compile(env, opts);
  14. const children = this.children.map((child) =>
  15. child.compile(env, { ...opts, depth: opts.depth + 2 })
  16. );
  17. const childrenError = children.find((node) => node instanceof EnvError);
  18. if (childrenError instanceof EnvError) return childrenError;
  19. return `@media(${predicate})${wordSpacer}{${lineSpacer}${children.join(
  20. lineSpacer
  21. )}${lineSpacer}}`;
  22. }
  23. }