media.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var tslib_1 = require("tslib");
  4. var ruleset_1 = tslib_1.__importDefault(require("./ruleset"));
  5. var value_1 = tslib_1.__importDefault(require("./value"));
  6. var selector_1 = tslib_1.__importDefault(require("./selector"));
  7. var atrule_1 = tslib_1.__importDefault(require("./atrule"));
  8. var nested_at_rule_1 = tslib_1.__importDefault(require("./nested-at-rule"));
  9. var Media = function (value, features, index, currentFileInfo, visibilityInfo) {
  10. this._index = index;
  11. this._fileInfo = currentFileInfo;
  12. var selectors = (new selector_1.default([], null, null, this._index, this._fileInfo)).createEmptySelectors();
  13. this.features = new value_1.default(features);
  14. this.rules = [new ruleset_1.default(selectors, value)];
  15. this.rules[0].allowImports = true;
  16. this.copyVisibilityInfo(visibilityInfo);
  17. this.allowRoot = true;
  18. this.setParent(selectors, this);
  19. this.setParent(this.features, this);
  20. this.setParent(this.rules, this);
  21. };
  22. Media.prototype = Object.assign(new atrule_1.default(), tslib_1.__assign(tslib_1.__assign({ type: 'Media' }, nested_at_rule_1.default), { genCSS: function (context, output) {
  23. output.add('@media ', this._fileInfo, this._index);
  24. this.features.genCSS(context, output);
  25. this.outputRuleset(context, output, this.rules);
  26. }, eval: function (context) {
  27. if (!context.mediaBlocks) {
  28. context.mediaBlocks = [];
  29. context.mediaPath = [];
  30. }
  31. var media = new Media(null, [], this._index, this._fileInfo, this.visibilityInfo());
  32. if (this.debugInfo) {
  33. this.rules[0].debugInfo = this.debugInfo;
  34. media.debugInfo = this.debugInfo;
  35. }
  36. media.features = this.features.eval(context);
  37. context.mediaPath.push(media);
  38. context.mediaBlocks.push(media);
  39. this.rules[0].functionRegistry = context.frames[0].functionRegistry.inherit();
  40. context.frames.unshift(this.rules[0]);
  41. media.rules = [this.rules[0].eval(context)];
  42. context.frames.shift();
  43. context.mediaPath.pop();
  44. return context.mediaPath.length === 0 ? media.evalTop(context) :
  45. media.evalNested(context);
  46. } }));
  47. exports.default = Media;
  48. //# sourceMappingURL=media.js.map