removeAlphaVariables.js 926 B

12345678910111213141516171819202122232425262728293031
  1. /**
  2. * This function removes any uses of CSS variables used as an alpha channel
  3. *
  4. * This is required for selectors like `:visited` which do not allow
  5. * changes in opacity or external control using CSS variables.
  6. *
  7. * @param {import('postcss').Container} container
  8. * @param {string[]} toRemove
  9. */ "use strict";
  10. Object.defineProperty(exports, "__esModule", {
  11. value: true
  12. });
  13. Object.defineProperty(exports, "removeAlphaVariables", {
  14. enumerable: true,
  15. get: function() {
  16. return removeAlphaVariables;
  17. }
  18. });
  19. function removeAlphaVariables(container, toRemove) {
  20. container.walkDecls((decl)=>{
  21. if (toRemove.includes(decl.prop)) {
  22. decl.remove();
  23. return;
  24. }
  25. for (let varName of toRemove){
  26. if (decl.value.includes(`/ var(${varName})`)) {
  27. decl.value = decl.value.replace(`/ var(${varName})`, "");
  28. }
  29. }
  30. });
  31. }