12345678910111213141516171819202122232425262728 |
- import * as AST from '../ast';
- import Env, { EnvError } from '../env';
-
- export class Keyframes {
- public name: AST.Literal;
- public children: AST.Node[];
-
- public constructor(name: AST.Literal, children: AST.Node[]) {
- this.name = name;
- this.children = children;
- }
-
- public compile(env: Env, opts: AST.Opts): string | EnvError {
- const lineSpacer = opts.prettyPrint ? '\n' : '';
- const wordSpacer = opts.prettyPrint ? ' ' : '';
- const name = this.name.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 `@keyframes ${name}${wordSpacer}{${lineSpacer}${children.join(
- lineSpacer
- )}${lineSpacer}}`;
- }
- }
|