createICSSRules.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _postcss = _interopRequireDefault(require("postcss"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. const createImports = imports => {
  9. return Object.keys(imports).map(path => {
  10. const aliases = imports[path];
  11. const declarations = Object.keys(aliases).map(key => _postcss.default.decl({
  12. prop: key,
  13. value: aliases[key],
  14. raws: {
  15. before: "\n "
  16. }
  17. }));
  18. const hasDeclarations = declarations.length > 0;
  19. const rule = _postcss.default.rule({
  20. selector: `:import('${path}')`,
  21. raws: {
  22. after: hasDeclarations ? "\n" : ""
  23. }
  24. });
  25. if (hasDeclarations) {
  26. rule.append(declarations);
  27. }
  28. return rule;
  29. });
  30. };
  31. const createExports = exports => {
  32. const declarations = Object.keys(exports).map(key => _postcss.default.decl({
  33. prop: key,
  34. value: exports[key],
  35. raws: {
  36. before: "\n "
  37. }
  38. }));
  39. if (declarations.length === 0) {
  40. return [];
  41. }
  42. const rule = _postcss.default.rule({
  43. selector: `:export`,
  44. raws: {
  45. after: "\n"
  46. }
  47. }).append(declarations);
  48. return [rule];
  49. };
  50. const createICSSRules = (imports, exports) => [...createImports(imports), ...createExports(exports)];
  51. var _default = createICSSRules;
  52. exports.default = _default;