feat: nsew layers

This commit is contained in:
hyper
2026-02-27 23:01:09 +08:00
parent c204dc695c
commit 5bc77a2291
7 changed files with 167 additions and 60 deletions
+7 -5
View File
@@ -28,6 +28,7 @@ export interface DeckState {
fontSize: number;
fixed: boolean;
src: string;
rawSrc: string; // 原始 CSV 路径(用于生成代码时保持相对路径)
// 解析后的尺寸
dimensions: Dimensions | null;
@@ -97,7 +98,7 @@ export interface DeckActions {
cancelSelection: () => void;
// 数据加载
loadCardsFromPath: (path: string, layersStr?: string) => Promise<void>;
loadCardsFromPath: (path: string, rawSrc: string, layersStr?: string) => Promise<void>;
setError: (error: string | null) => void;
clearError: () => void;
@@ -140,6 +141,7 @@ export function createDeckStore(
fontSize: DECK_DEFAULTS.FONT_SIZE,
fixed: false,
src: initialSrc,
rawSrc: initialSrc,
dimensions: null,
cards: [],
activeTab: 0,
@@ -237,13 +239,13 @@ export function createDeckStore(
};
// 加载卡牌数据(核心逻辑)
const loadCardsFromPath = async (path: string, layersStr: string = '') => {
const loadCardsFromPath = async (path: string, rawSrc: string, layersStr: string = '') => {
if (!path) {
setState({ error: '未指定 CSV 文件路径' });
return;
}
setState({ isLoading: true, error: null, src: path });
setState({ isLoading: true, error: null, src: path, rawSrc: rawSrc });
try {
const data = await loadCSV(path);
@@ -277,9 +279,9 @@ export function createDeckStore(
const generateCode = () => {
const layersStr = state.layerConfigs
.filter(l => l.visible)
.map(l => `${l.prop}:${l.x1},${l.y1}-${l.x2},${l.y2}`)
.map(l => `${l.prop}:${l.x1},${l.y1}-${l.x2},${l.y2}${l.orientation && l.orientation !== 'n' ? `${l.orientation}` : ''}`)
.join(' ');
return `:md-deck[${state.src}]{size="${state.sizeW}x${state.sizeH}" grid="${state.gridW}x${state.gridH}" bleed="${state.bleed}" padding="${state.padding}" font-size="${state.fontSize}" layers="${layersStr}"}`;
return `:md-deck[${state.rawSrc || state.src}]{size="${state.sizeW}x${state.sizeH}" grid="${state.gridW}x${state.gridH}" bleed="${state.bleed}" padding="${state.padding}" font-size="${state.fontSize}" layers="${layersStr}"}`;
};
const copyCode = async () => {