|
@@ -1,3 +1,4 @@
|
|
|
+/* eslint-disable */
|
|
|
/* src/components/Icon/iconRegistry.ts */
|
|
|
import React from 'react';
|
|
|
|
|
@@ -26,13 +27,13 @@ interface RawAsset {
|
|
|
size: Density;
|
|
|
fileName: string;
|
|
|
ext: string;
|
|
|
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
+
|
|
|
source: string | React.ComponentType<any>;
|
|
|
reqPath: string; // require.context key (如 './base/module-common/.../icon.svg')
|
|
|
}
|
|
|
|
|
|
export type ResolvedIcon =
|
|
|
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
+
|
|
|
| { kind: 'svg'; Component: React.ComponentType<any>; meta: RawAsset }
|
|
|
| { kind: 'raster'; src: string; srcSet?: string; meta: RawAsset };
|
|
|
|
|
@@ -44,7 +45,7 @@ interface WebpackRequireContext {
|
|
|
resolve(id: string): string;
|
|
|
id: string;
|
|
|
}
|
|
|
- /* eslint-enable */
|
|
|
+/* eslint-enable */
|
|
|
|
|
|
// ---- 构建索引 ----
|
|
|
const defaultExtPriority = ['.svg', '.webp', '.png', '.jpg', '.jpeg'];
|
|
@@ -164,36 +165,38 @@ export function resolveIcon(opts: IconOptions): ResolvedIcon | undefined {
|
|
|
: `base|${moduleName}|${th}|${sz}|${fileName}`;
|
|
|
const asset = assetIndex.get(key);
|
|
|
if (asset) {
|
|
|
- if (
|
|
|
- asset.ext === '.svg' ||
|
|
|
- typeof asset.source === 'function'
|
|
|
- ) {
|
|
|
+ // ADD: 如果是 SVG 且 source 不是字符串(即被 svgr 转换为 React 组件),则当作 svg 组件返回
|
|
|
+ if (asset.ext === '.svg' && typeof asset.source !== 'string') {
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
const Component = asset.source as React.ComponentType<any>;
|
|
|
return { kind: 'svg', Component, meta: asset };
|
|
|
- } else {
|
|
|
- const densities: Density[] = ['1x', '2x', '3x'];
|
|
|
- const srcSetParts: string[] = [];
|
|
|
- for (const d of densities) {
|
|
|
- const k =
|
|
|
- layer === 'custom'
|
|
|
- ? `custom|${asset.userId}|${asset.moduleName}|${asset.theme}|${d}|${asset.fileName}`
|
|
|
- : `base|${asset.moduleName}|${asset.theme}|${d}|${asset.fileName}`;
|
|
|
- const a = assetIndex.get(k);
|
|
|
- if (a && typeof a.source === 'string') {
|
|
|
- srcSetParts.push(`${a.source} ${d}`);
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ // ADD: 否则把它当作 raster 处理(包括那些被 loader 输出为 URL/base64 的 SVG)
|
|
|
+ const densities: Density[] = ['1x', '2x', '3x'];
|
|
|
+ const srcSetParts: string[] = [];
|
|
|
+ for (const d of densities) {
|
|
|
+ const k =
|
|
|
+ layer === 'custom'
|
|
|
+ ? `custom|${asset.userId}|${asset.moduleName}|${asset.theme}|${d}|${asset.fileName}`
|
|
|
+ : `base|${asset.moduleName}|${asset.theme}|${d}|${asset.fileName}`;
|
|
|
+ const a = assetIndex.get(k);
|
|
|
+ if (a && typeof a.source === 'string') {
|
|
|
+ // 注意:srcSet descriptor 我们保留 '1x'/'2x'/'3x' 字符串(可按需改成 '1x' -> '1x' 等)
|
|
|
+ srcSetParts.push(`${a.source} ${d}`);
|
|
|
}
|
|
|
- const srcSet = srcSetParts.length
|
|
|
- ? srcSetParts.join(', ')
|
|
|
- : undefined;
|
|
|
- return {
|
|
|
- kind: 'raster',
|
|
|
- src: asset.source as string,
|
|
|
- srcSet,
|
|
|
- meta: asset,
|
|
|
- };
|
|
|
}
|
|
|
+ const srcSet = srcSetParts.length
|
|
|
+ ? srcSetParts.join(', ')
|
|
|
+ : undefined;
|
|
|
+
|
|
|
+ // asset.source 在此处应为 string(URL 或 base64)
|
|
|
+ return {
|
|
|
+ kind: 'raster',
|
|
|
+ src: asset.source as string,
|
|
|
+ srcSet,
|
|
|
+ meta: asset,
|
|
|
+ };
|
|
|
}
|
|
|
}
|
|
|
}
|