feat: add template type definitions

This commit is contained in:
Developer 2026-02-12 07:55:47 +00:00
parent ac7248ec07
commit 72b1d357e8

109
src/types/template.ts Normal file
View File

@ -0,0 +1,109 @@
// 对齐方式
export type Align = 'left' | 'center' | 'right';
// 字体大小
export type FontSize = 'small' | 'normal' | 'large' | 'xlarge';
// 条码格式
export type BarcodeFormat = 'CODE128' | 'QR' | 'EAN13';
// 基础样式
export interface BlockStyle {
align?: Align;
fontSize?: FontSize;
bold?: boolean;
italic?: boolean;
underline?: boolean;
lineHeight?: number;
marginTop?: number;
marginBottom?: number;
}
// 列定义
export interface Column {
content?: string;
align?: Align;
width?: string | number;
bold?: boolean;
header?: string;
}
// Block 类型
export interface TextBlock extends BlockStyle {
type: 'text';
content: string;
}
export interface RowBlock extends BlockStyle {
type: 'row';
columns: Column[];
}
export interface TableBlock extends BlockStyle {
type: 'table';
columns: Column[];
data: string; // mustache expression
}
export interface ListBlock extends BlockStyle {
type: 'list';
data: string; // mustache expression
itemTemplate: Block[];
}
export interface DividerBlock extends BlockStyle {
type: 'divider';
char?: string;
}
export interface ImageBlock extends BlockStyle {
type: 'image';
src: string; // mustache expression or URL
maxWidth?: number;
}
export interface BarcodeBlock extends BlockStyle {
type: 'barcode';
format: BarcodeFormat;
data: string; // mustache expression
height?: number;
}
export interface SpaceBlock extends BlockStyle {
type: 'space';
lines?: number;
}
export type Block =
| TextBlock
| RowBlock
| TableBlock
| ListBlock
| DividerBlock
| ImageBlock
| BarcodeBlock
| SpaceBlock;
// 页面设置
export interface PageConfig {
marginTop?: number;
marginBottom?: number;
}
// 默认样式
export interface DefaultStyle {
fontSize?: FontSize;
lineHeight?: number;
marginBottom?: number;
}
// 完整模板
export interface Template {
id: string;
name: string;
description?: string;
width: string; // e.g., "80mm"
page?: PageConfig;
defaults?: DefaultStyle;
blocks: Block[];
}