fix: icons

This commit is contained in:
hypercross 2026-03-13 11:46:18 +08:00
parent 9e8d4e6388
commit 97923c8d35
6 changed files with 20 additions and 14 deletions

View File

@ -4,6 +4,7 @@ import { getLayerStyle } from './hooks/dimensions';
import type { CardData } from './types'; import type { CardData } from './types';
import {DeckStore} from "./hooks/deckStore"; import {DeckStore} from "./hooks/deckStore";
import {processVariables} from "../utils/csv-loader"; import {processVariables} from "../utils/csv-loader";
import {resolvePath} from "../utils/path";
export interface CardLayerProps { export interface CardLayerProps {
cardData: CardData; cardData: CardData;
@ -16,7 +17,8 @@ export function CardLayer(props: CardLayerProps) {
const showBounds = () => props.store.state.isEditing; const showBounds = () => props.store.state.isEditing;
function renderLayerContent(content: string) { function renderLayerContent(content: string) {
return parseMarkdown(processVariables(content, props.cardData, props.store.state.cards), props.cardData.iconPath) as string; const iconPath = resolvePath(props.store.state.cards.sourcePath, props.cardData.iconPath);
return parseMarkdown(processVariables(content, props.cardData, props.store.state.cards), iconPath) as string;
} }
return ( return (
<For each={layers()}> <For each={layers()}>

View File

@ -74,7 +74,7 @@ export interface DeckActions {
setPadding: (padding: number) => void; setPadding: (padding: number) => void;
// 数据设置 // 数据设置
setCards: (cards: CardData[]) => void; setCards: (cards: CSV<CardData>) => void;
setActiveTab: (index: number) => void; setActiveTab: (index: number) => void;
updateCardData: (index: number, key: string, value: string) => void; updateCardData: (index: number, key: string, value: string) => void;
@ -139,7 +139,7 @@ export function createDeckStore(
src: initialSrc, src: initialSrc,
rawSrc: initialSrc, rawSrc: initialSrc,
dimensions: null, dimensions: null,
cards: [], cards: [] as any,
activeTab: 0, activeTab: 0,
layerConfigs: [], layerConfigs: [],
isEditing: false, isEditing: false,
@ -195,7 +195,7 @@ export function createDeckStore(
updateDimensions(); updateDimensions();
}; };
const setCards = (cards: CardData[]) => setState({ cards, activeTab: 0 }); const setCards = (cards: CSV<CardData>) => setState({ cards, activeTab: 0 });
const setActiveTab = (index: number) => setState({ activeTab: index }); const setActiveTab = (index: number) => setState({ activeTab: index });
const updateCardData = (index: number, key: string, value: string) => { const updateCardData = (index: number, key: string, value: string) => {
setState('cards', index, key, value); setState('cards', index, key, value);
@ -271,20 +271,20 @@ export function createDeckStore(
const layersStr = formatLayers(state.layerConfigs); const layersStr = formatLayers(state.layerConfigs);
const parts = [ const parts = [
`:md-deck[${state.rawSrc || state.src}]`, `:md-deck[${state.rawSrc || state.src}]`,
`{size="${state.sizeW}x${state.sizeH}"`, `{size="${state.sizeW}x${state.sizeH} "`,
`grid="${state.gridW}x${state.gridH}"` `grid="${state.gridW}x${state.gridH} "`
]; ];
// 仅在非默认值时添加 bleed 和 padding // 仅在非默认值时添加 bleed 和 padding
if (state.bleed !== DECK_DEFAULTS.BLEED) { if (state.bleed !== DECK_DEFAULTS.BLEED) {
parts.push(`bleed="${state.bleed}"`); parts.push(`bleed="${state.bleed} "`);
} }
if (state.padding !== DECK_DEFAULTS.PADDING) { if (state.padding !== DECK_DEFAULTS.PADDING) {
parts.push(`padding="${state.padding}"`); parts.push(`padding="${state.padding} "`);
} }
parts.push(`layers="${layersStr}"}`); parts.push(`layers="${layersStr}"}`);
return parts.join(' '); return parts.join('');
}; };
const copyCode = async () => { const copyCode = async () => {

View File

@ -57,9 +57,6 @@ export function initLayerConfigs(
): LayerConfig[] { ): LayerConfig[] {
const parsed = parseLayers(existingLayersStr); const parsed = parseLayers(existingLayersStr);
const allProps = Object.keys(data[0] || {}).filter(k => k !== 'label'); const allProps = Object.keys(data[0] || {}).filter(k => k !== 'label');
if(data.frontmatter){
allProps.push(...Object.keys(data.frontmatter));
}
return allProps.map(prop => { return allProps.map(prop => {
const existing = parsed.find(l => l.prop === prop); const existing = parsed.find(l => l.prop === prop);

View File

@ -71,6 +71,7 @@ export async function loadCSV<T = Record<string, string>>(path: string): Promise
Object.assign(each, frontmatter); Object.assign(each, frontmatter);
} }
} }
csvResult.sourcePath = path;
csvCache.set(path, result); csvCache.set(path, result);
return csvResult; return csvResult;
@ -82,6 +83,7 @@ interface JSONObject extends Record<string, JSONData> {}
export type CSV<T> = T[] & { export type CSV<T> = T[] & {
frontmatter?: JSONObject; frontmatter?: JSONObject;
sourcePath: string;
} }
export function processVariables<T extends JSONObject> (body: string, currentRow: T, csv: CSV<T>, filtered?: T[], remix?: boolean): string { export function processVariables<T extends JSONObject> (body: string, currentRow: T, csv: CSV<T>, filtered?: T[], remix?: boolean): string {

View File

@ -35,7 +35,7 @@ const marked = new Marked()
// :[blah] becomes <i class="icon icon-blah"></i> // :[blah] becomes <i class="icon icon-blah"></i>
renderer(token) { renderer(token) {
if (!token.meta.name) { if (!token.meta.name) {
const style = globalIconPrefix ? `style="--icon-src: url('${globalIconPrefix}${token.text}.png')"` : ''; const style = globalIconPrefix ? `style="--icon-src: url('${globalIconPrefix}/${token.text}.png')"` : '';
return `<icon ${style} class="icon-${token.text}"></icon>`; return `<icon ${style} class="icon-${token.text}"></icon>`;
} }
return false; return false;

View File

@ -2,7 +2,7 @@
@plugin "@tailwindcss/typography"; @plugin "@tailwindcss/typography";
/* icon */ /* icon */
icon{ icon, pull{
@apply inline-block; @apply inline-block;
width: 1em; width: 1em;
height: 1em; height: 1em;
@ -11,6 +11,11 @@ icon{
background-size: contain; background-size: contain;
background-position: center; background-position: center;
background-repeat: no-repeat; background-repeat: no-repeat;
margin-bottom: -0.1em;
}
pull{
margin-right: -.5em;
width: 0;
} }
/* prose */ /* prose */