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.

27 lines
810 B

4 years ago
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.replaceAll = replaceAll;
  6. var matchConstName = /[$#]?[\w-\.]+/g;
  7. function replaceAll(replacements, text) {
  8. var matches = void 0;
  9. while (matches = matchConstName.exec(text)) {
  10. var replacement = replacements[matches[0]];
  11. if (replacement) {
  12. text = text.slice(0, matches.index) + replacement + text.slice(matchConstName.lastIndex);
  13. matchConstName.lastIndex -= matches[0].length - replacement.length;
  14. }
  15. }
  16. return text;
  17. }
  18. exports.default = function (css, translations) {
  19. css.walkDecls(function (decl) {
  20. return decl.value = replaceAll(translations, decl.value);
  21. });
  22. css.walkAtRules('media', function (atRule) {
  23. return atRule.params = replaceAll(translations, atRule.params);
  24. });
  25. };