You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

4 years ago
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _postcss = require('postcss');
  6. var _postcss2 = _interopRequireDefault(_postcss);
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
  9. var createImports = function createImports(imports) {
  10. return Object.keys(imports).map(function (path) {
  11. var aliases = imports[path];
  12. var declarations = Object.keys(aliases).map(function (key) {
  13. return _postcss2.default.decl({
  14. prop: key,
  15. value: aliases[key],
  16. raws: { before: '\n ' }
  17. });
  18. });
  19. return _postcss2.default.rule({
  20. selector: `:import(${path})`,
  21. raws: { after: '\n' }
  22. }).append(declarations);
  23. });
  24. };
  25. var createExports = function createExports(exports) {
  26. var declarations = Object.keys(exports).map(function (key) {
  27. return _postcss2.default.decl({
  28. prop: key,
  29. value: exports[key],
  30. raws: { before: '\n ' }
  31. });
  32. });
  33. if (declarations.length === 0) {
  34. return [];
  35. }
  36. var rule = _postcss2.default.rule({
  37. selector: `:export`,
  38. raws: { after: '\n' }
  39. }).append(declarations);
  40. return [rule];
  41. };
  42. var createICSSRules = function createICSSRules(imports, exports) {
  43. return [].concat(_toConsumableArray(createImports(imports)), _toConsumableArray(createExports(exports)));
  44. };
  45. exports.default = createICSSRules;