animate/webGl/my-threejs-test/node_modules/htmlnano/lib/modules/deduplicateAttributeValues.cjs

38 lines
1.1 KiB
JavaScript
Raw Normal View History

2024-06-24 09:24:00 +00:00
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.onAttrs = onAttrs;
var _collapseAttributeWhitespace = require("./collapseAttributeWhitespace.cjs");
/** Deduplicate values inside list-like attributes (e.g. class, rel) */
function onAttrs() {
return attrs => {
const newAttrs = attrs;
Object.keys(attrs).forEach(attrName => {
if (!_collapseAttributeWhitespace.attributesWithLists.has(attrName)) {
return;
}
if (typeof attrs[attrName] !== 'string') {
return;
}
const attrValues = attrs[attrName].split(/\s/);
const uniqeAttrValues = new Set();
const deduplicatedAttrValues = [];
attrValues.forEach(attrValue => {
if (!attrValue) {
// Keep whitespaces
deduplicatedAttrValues.push('');
return;
}
if (uniqeAttrValues.has(attrValue)) {
return;
}
deduplicatedAttrValues.push(attrValue);
uniqeAttrValues.add(attrValue);
});
newAttrs[attrName] = deduplicatedAttrValues.join(' ');
});
return newAttrs;
};
}