Compare commits

...

2 Commits

Author SHA1 Message Date
hyper b09560a4e5 refactor: allow chinese layer names 2026-04-07 19:33:08 +08:00
hyper 4d1c40ed3e refactor: add support for non-png icons 2026-04-06 18:31:08 +08:00
4 changed files with 43 additions and 7 deletions

View File

@ -80,6 +80,22 @@
图标会渲染为 `<icon class="icon-attack"></icon>` 形式。
### 支持多种图片格式
默认情况下,`:[icon-name]` 会查找 `.png` 文件。你也可以显式指定其他支持的格式:
```markdown
:[attack] <!-- 查找 attack.png -->
:[attack.svg] <!-- 查找 attack.svg -->
:[shield.gif] <!-- 查找 shield.gif -->
:[photo.jpg] <!-- 查找 photo.jpg -->
:[icon.webp] <!-- 查找 icon.webp -->
```
**支持的扩展名:** `.svg`、`.png`、`.gif`、`.jpg`、`.jpeg`、`.webp`
**注意:** CSS class 名称始终使用不带扩展名的图标名称(如 `icon-attack`),方便统一样式控制。
### 配置图标前缀
可通过 `iconPath` 属性指定图标目录:

View File

@ -1,4 +1,4 @@
import { createStore } from 'solid-js/store';
import { createStore } from 'solid-js/store';
import { calculateDimensions } from './dimensions';
import { loadCSV, CSV } from '../../utils/csv-loader';
import { initLayerConfigs, formatLayers, initLayerConfigsForSide } from './layer-parser';
@ -321,7 +321,7 @@ export function createDeckStore(
if (data.length === 0) {
setState({
error: 'CSV 文件为空或格式不正确',
error: `CSV ${path} 文件为空或格式不正确`,
isLoading: false
});
return;
@ -337,7 +337,7 @@ export function createDeckStore(
updateDimensions();
} catch (err) {
setState({
error: `加载 CSV 失败:${err instanceof Error ? err.message : '未知错误'}`,
error: `加载 CSV ${path} 失败:${err instanceof Error ? err.message : '未知错误'}`,
isLoading: false
});
}

View File

@ -11,7 +11,7 @@ export function parseLayers(layersStr: string): Layer[] {
const layers: Layer[] = [];
// 匹配prop:x1,y1-x2,y2[ffontSize][direction][align]
const regex = /(\w+):(\d+),(\d+)-(\d+),(\d+)(?:f([\d.]+))?([nsew])?([lcr])?/g;
const regex = /([^: ]+):(\d+),(\d+)-(\d+),(\d+)(?:f([\d.]+))?([nsew])?([lcr])?/g;
let match;
while ((match = regex.exec(layersStr)) !== null) {

View File

@ -36,11 +36,31 @@ const marked = new Marked()
{
level: 'inline',
marker: ':',
// :[blah] becomes <i class="icon icon-blah"></i>
// :[icon] 或 :[icon.ext] 语法
// 支持的扩展名: .svg, .png, .gif, .jpg, .jpeg, .webp
// 如果不指定扩展名,默认为 .png
renderer(token) {
if (!token.meta.name) {
const style = globalIconPrefix ? `style="--icon-src: url('${globalIconPrefix}/${token.text}.png')"` : '';
return `<icon ${style} class="icon-${token.text} ${token.attrs?.class || ""}"></icon>`;
const iconText = token.text || '';
// 已知支持的图片扩展名
const supportedExtensions = ['svg', 'png', 'gif', 'jpg', 'jpeg', 'webp'];
// 检查是否包含扩展名(查找最后一个点)
let iconName = iconText;
let extension = 'png'; // 默认扩展名
const lastDotIndex = iconName.lastIndexOf('.');
if (lastDotIndex > 0) {
const potentialExt = iconName.slice(lastDotIndex + 1).toLowerCase();
if (supportedExtensions.includes(potentialExt)) {
extension = potentialExt;
iconName = iconName.slice(0, lastDotIndex);
}
}
const style = globalIconPrefix ? `style="--icon-src: url('${globalIconPrefix}/${iconName}.${extension}')"` : '';
return `<icon ${style} class="icon-${iconName} ${token.attrs?.class || ""}"></icon>`;
}
return false;
}