Files
doodle-mini/miniprogram/pinyinPages/shared/pinyinDailyGenerator.ts
2026-05-20 15:33:06 +08:00

81 lines
2.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { PINYIN_DAILY_GROUPS, type PinyinDailyTask } from './pinyinDailyData';
import { TRACING_COLORS } from '../../core/data/tracingStyles';
export interface PinyinDailyCell {
char: string;
style: 'solid' | 'dashed';
color: string;
alpha: number;
}
export interface PinyinDailyRow {
cells: (PinyinDailyCell | null)[];
}
export interface PinyinDailySection {
task: PinyinDailyTask;
rows: PinyinDailyRow[];
cols: number;
}
export interface PinyinDailyData {
dayIndex: number;
sections: PinyinDailySection[];
}
const COLOR_BLACK = TRACING_COLORS.strong;
const COLOR_LIGHT_RED = TRACING_COLORS.guide;
function buildRows(task: PinyinDailyTask, cols: number): PinyinDailyRow[] {
const rows: PinyinDailyRow[] = [];
const char = task.char;
// 每日打卡固定 7 行
for (let r = 0; r < 7; r++) {
const cells: (PinyinDailyCell | null)[] = [];
let style: 'solid' | 'dashed' = 'solid';
let alpha = 1;
// 样式:
// 0-1行:实线描红 (第0行第0个黑色,其余浅红)
// 2, 4, 6行:留空(null
// 3, 5行:虚线描红
if (r === 2 || r === 4 || r === 6) {
for (let c = 0; c < cols; c++) cells.push(null);
} else {
if (r >= 3) {
style = 'dashed';
alpha = 0.5;
}
for (let c = 0; c < cols; c++) {
const color =
r === 0 && c === 0 ? COLOR_BLACK : COLOR_LIGHT_RED;
cells.push({ char, style, color, alpha });
}
}
rows.push({ cells });
}
return rows;
}
export function generatePinyinDaily(dayIndex: number): PinyinDailyData {
const group = PINYIN_DAILY_GROUPS[dayIndex] || PINYIN_DAILY_GROUPS[0];
const sections: PinyinDailySection[] = group.map((task) => {
const cols = task.char.length <= 2 ? 5 : 4;
return {
task,
rows: buildRows(task, cols),
cols,
};
});
return {
dayIndex: dayIndex + 1,
sections,
};
}