feat(icons): 新增微软 Fluent Emoji 3D 位图图标源(1586 个,MIT),支持位图图标渲染与导出内联

This commit is contained in:
sgp
2026-11-05 11:33:36 +08:00
parent 07d2a79a60
commit fcb70e8c7f
1606 changed files with 266 additions and 55 deletions
+47 -2
View File
@@ -8,7 +8,7 @@
const HGB_IconLib = (function () {
'use strict';
const VERSION = '20261105c'; // 与 index.html 中 builtin-icons.js?v= 版本联动
const VERSION = '20261105d'; // 与 index.html 中 builtin-icons.js?v= 版本联动
const cache = {}; // sid -> {icons:[...]}
const pending = {}; // sid -> Promise
@@ -206,9 +206,54 @@ const HGB_IconLib = (function () {
return String(fullId || '').split(':')[0];
}
/* ---------- 位图图标内联(PNG 导出用) ---------- */
// 3D 位图图标的数据文件以 <image href="js/data/sources/...png"> 引用原图,
// 页面内联渲染可直接显示;但导出 PNG/PDF/SVG 时 SVG 会被转成 blob/data URI,
// 相对路径失效 → 导出前把 href 内联成 data URI(按路径缓存,只取一次)。
var rasterCache = {}; // 相对路径 -> data URI
var RASTER_RE = /href="(js\/data\/sources\/[^"]+\.png)"/g;
/** 是否含位图图标引用 */
function hasRaster(svg) {
return typeof svg === 'string' && svg.indexOf('js/data/sources/') !== -1 && svg.indexOf('.png"') !== -1;
}
function fetchDataURI(p) {
if (rasterCache[p]) return Promise.resolve(rasterCache[p]);
return fetch(p).then(function (r) {
if (!r.ok) throw new Error('位图加载失败: ' + p);
return r.blob();
}).then(function (blob) {
return new Promise(function (resolve, reject) {
var fr = new FileReader();
fr.onload = function () { rasterCache[p] = fr.result; resolve(fr.result); };
fr.onerror = reject;
fr.readAsDataURL(blob);
});
});
}
/** 把 svg 里的位图相对引用内联为 data URI(导出前调用;无位图时原样返回) */
function inlineRasters(svg) {
if (!hasRaster(svg)) return Promise.resolve(svg);
var paths = [], m;
RASTER_RE.lastIndex = 0;
while ((m = RASTER_RE.exec(svg))) {
if (paths.indexOf(m[1]) === -1) paths.push(m[1]);
}
return Promise.all(paths.map(fetchDataURI)).then(function () {
var out = svg;
paths.forEach(function (p) {
out = out.split('href="' + p + '"').join('href="' + rasterCache[p] + '"');
});
return out;
});
}
return {
VERSION, loadSource, loadSources, preload, loadAll,
getSource, loaded, loadedIds, findIcon, searchLoaded, searchIndex, sourceOf,
expandKeyword, matchIcon: iconMatches, scoreIcon
expandKeyword, matchIcon: iconMatches, scoreIcon,
hasRaster, inlineRasters
};
})();