remove-duplicate-font-at-rules.js 619 B

123456789101112131415161718192021222324252627282930
  1. var Token = require('../../tokenizer/token');
  2. var serializeAll = require('../../writer/one-time').all;
  3. var FONT_FACE_SCOPE = '@font-face';
  4. function removeDuplicateFontAtRules(tokens) {
  5. var fontAtRules = [];
  6. var token;
  7. var key;
  8. var i, l;
  9. for (i = 0, l = tokens.length; i < l; i++) {
  10. token = tokens[i];
  11. if (token[0] != Token.AT_RULE_BLOCK && token[1][0][1] != FONT_FACE_SCOPE) {
  12. continue;
  13. }
  14. key = serializeAll([token]);
  15. if (fontAtRules.indexOf(key) > -1) {
  16. token[2] = [];
  17. } else {
  18. fontAtRules.push(key);
  19. }
  20. }
  21. }
  22. module.exports = removeDuplicateFontAtRules;