A stylesheet language written in TypeScript that compiles to CSS
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

1234567891011121314151617181920212223242526272829
  1. import * as AST from '../ast';
  2. import Env, { EnvError } from '../env';
  3. export class Rule {
  4. public property: AST.Property;
  5. public values: AST.Value[];
  6. public constructor(
  7. property: AST.Property,
  8. values: AST.Value[]
  9. ) {
  10. this.property = property;
  11. this.values = values;
  12. }
  13. public compile(env: Env, opts: AST.Opts): string | EnvError {
  14. const wordSpacer = opts.prettyPrint ? ' ' : '';
  15. const indentSpacer = opts.prettyPrint ? ' ' + Array(opts.depth).fill(' ').join('') : '';
  16. const property = this.property.compile(env, opts);
  17. if (property instanceof EnvError) return property;
  18. const values: string[] = [];
  19. for (const value of this.values) {
  20. const compiledValue = value.compile(env, opts);
  21. if (compiledValue instanceof EnvError) return compiledValue;
  22. values.push(compiledValue);
  23. }
  24. return `${indentSpacer}${property}:${wordSpacer}${values.join(',')};`;
  25. }
  26. }