removeNonInheritableGroupAttrs.js 925 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. exports.name = 'removeNonInheritableGroupAttrs';
  3. exports.type = 'perItem';
  4. exports.active = true;
  5. exports.description =
  6. 'removes non-inheritable group’s presentational attributes';
  7. const {
  8. inheritableAttrs,
  9. attrsGroups,
  10. presentationNonInheritableGroupAttrs,
  11. } = require('./_collections');
  12. /**
  13. * Remove non-inheritable group's "presentation" attributes.
  14. *
  15. * @param {Object} item current iteration item
  16. * @return {Boolean} if false, item will be filtered out
  17. *
  18. * @author Kir Belevich
  19. */
  20. exports.fn = function (item) {
  21. if (item.type === 'element' && item.name === 'g') {
  22. for (const name of Object.keys(item.attributes)) {
  23. if (
  24. attrsGroups.presentation.includes(name) === true &&
  25. inheritableAttrs.includes(name) === false &&
  26. presentationNonInheritableGroupAttrs.includes(name) === false
  27. ) {
  28. delete item.attributes[name];
  29. }
  30. }
  31. }
  32. };