mirror of
https://github.com/MultiMote/niimblue
synced 2026-01-19 19:37:11 +03:00
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
import { LabelType, printTaskNames } from "@mmote/niimbluelib";
|
|
import { fabric } from "fabric";
|
|
import { z } from "zod";
|
|
|
|
export type ConnectionState = "connecting" | "connected" | "disconnected";
|
|
export type ConnectionType = "bluetooth" | "serial";
|
|
export type LabelUnit = "mm" | "px";
|
|
export type OjectType = "text" | "rectangle" | "line" | "circle" | "image" | "qrcode" | "barcode";
|
|
export type PostProcessType = "threshold" | "dither";
|
|
export type MoveDirection = "Up" | "Down" | "Left" | "Right";
|
|
|
|
/** Not validated */
|
|
export const FabricObjectSchema = z.custom<fabric.Object>((val: any): boolean => {
|
|
return typeof val === "object";
|
|
});
|
|
|
|
export const LabelPropsSchema = z.object({
|
|
printDirection: z.enum(["left", "top"]),
|
|
size: z.object({
|
|
width: z.number().positive(),
|
|
height: z.number().positive(),
|
|
}),
|
|
});
|
|
|
|
export const LabelPresetSchema = z.object({
|
|
width: z.number().positive(),
|
|
height: z.number().positive(),
|
|
unit: z.enum(["mm", "px"]),
|
|
dpmm: z.number().positive(),
|
|
printDirection: z.enum(["left", "top"]),
|
|
title: z.string().optional(),
|
|
});
|
|
|
|
export const FabricJsonSchema = z.object({
|
|
version: z.string(),
|
|
objects: z.array(FabricObjectSchema),
|
|
});
|
|
|
|
export const ExportedLabelTemplateSchema = z.object({
|
|
canvas: FabricJsonSchema,
|
|
label: LabelPropsSchema,
|
|
});
|
|
|
|
const [firstTask, ...otherTasks] = printTaskNames;
|
|
|
|
export const PreviewPropsSchema = z.object({
|
|
postProcess: z.enum(["threshold", "dither"]).optional(),
|
|
threshold: z.number().gte(1).lte(255).optional(),
|
|
quantity: z.number().gte(1).optional(),
|
|
density: z.number().gte(1).optional(),
|
|
labelType: z.nativeEnum(LabelType).optional(),
|
|
printTaskName: z.enum([firstTask, ...otherTasks]).optional(),
|
|
});
|
|
|
|
export type LabelProps = z.infer<typeof LabelPropsSchema>;
|
|
export type LabelPreset = z.infer<typeof LabelPresetSchema>;
|
|
export type FabricJson = z.infer<typeof FabricJsonSchema>;
|
|
export type ExportedLabelTemplate = z.infer<typeof ExportedLabelTemplateSchema>;
|
|
export type PreviewProps = z.infer<typeof PreviewPropsSchema>;
|