Urara-Blog/node_modules/.pnpm-store/v3/files/8b/9a5fd59be0df42d3c76a8d9d6c03f92b54a9ede4b6e475c8204254d86fce756a147a21861ffb2dd4244d153612dcaf27ec585579831a9b31a11d2e2399348a
2022-08-14 01:14:53 +08:00

68 lines
2 KiB
Text

'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const icon_index = require('../icon/index.cjs');
function minifyIconSet(data) {
const icons = Object.keys(data.icons);
Object.keys(icon_index.iconDefaults).forEach((prop) => {
if (data[prop] === icon_index.iconDefaults[prop]) {
delete data[prop];
}
const defaultValue = icon_index.iconDefaults[prop];
const propType = typeof defaultValue;
const hasMinifiedDefault = typeof data[prop] === propType && data[prop] !== defaultValue;
let maxCount = 0;
let maxValue = null;
const counters = /* @__PURE__ */ new Map();
for (let i = 0; i < icons.length; i++) {
const item = data.icons[icons[i]];
let value;
if (typeof item[prop] === propType) {
value = item[prop];
} else if (hasMinifiedDefault) {
value = data[prop];
} else {
value = icon_index.iconDefaults[prop];
}
if (i === 0) {
maxCount = 1;
maxValue = value;
counters.set(value, 1);
continue;
}
if (!counters.has(value)) {
counters.set(value, 1);
continue;
}
const count = counters.get(value) + 1;
counters.set(value, count);
if (count > maxCount) {
maxCount = count;
maxValue = value;
}
}
const canMinify = maxValue !== null && maxCount > 1;
const oldDefault = hasMinifiedDefault ? data[prop] : null;
const newDefault = canMinify ? maxValue : oldDefault;
if (newDefault === defaultValue) {
delete data[prop];
} else if (canMinify) {
data[prop] = newDefault;
}
icons.forEach((key) => {
const item = data.icons[key];
const value = item[prop] === void 0 ? hasMinifiedDefault ? oldDefault : defaultValue : item[prop];
if (value === newDefault || newDefault === null && value === defaultValue) {
delete item[prop];
return;
}
if (canMinify && item[prop] === void 0) {
item[prop] = value;
}
});
});
}
exports.minifyIconSet = minifyIconSet;