pwa and mobile client
This commit is contained in:
@@ -47,3 +47,22 @@ export const BWIP_BCID: Record<CodeType, string> = {
|
||||
};
|
||||
|
||||
export const TWO_DIMENSIONAL_CODE_TYPES: ReadonlySet<CodeType> = new Set(['QR', 'DATAMATRIX', 'AZTEC']);
|
||||
|
||||
/** EAN/UPC have their own human-readable text layout (digits between the guard bars). */
|
||||
const EAN_UPC_TYPES: ReadonlySet<CodeType> = new Set(['EAN13', 'EAN8', 'UPCA', 'UPCE']);
|
||||
|
||||
/** bwip-js options to draw a card code black on white; `barHeight` is in mm, for linear codes only. */
|
||||
export function bwipRenderOptions(codeType: CodeType, text: string, barHeight = 14) {
|
||||
const common = {
|
||||
bcid: BWIP_BCID[codeType],
|
||||
text,
|
||||
scale: 3,
|
||||
paddingwidth: 6,
|
||||
paddingheight: 6,
|
||||
backgroundcolor: 'FFFFFF',
|
||||
};
|
||||
if (TWO_DIMENSIONAL_CODE_TYPES.has(codeType)) return common;
|
||||
// Centering the text of EAN/UPC would move the digits onto the guard bars.
|
||||
if (EAN_UPC_TYPES.has(codeType)) return { ...common, height: barHeight, includetext: true };
|
||||
return { ...common, height: barHeight, includetext: true, textxalign: 'center' as const };
|
||||
}
|
||||
|
||||
@@ -20,6 +20,8 @@ export interface Card {
|
||||
color: string;
|
||||
code: string;
|
||||
codeType: CodeType;
|
||||
/** Free text, may be multiline; '' when empty. */
|
||||
comment: string;
|
||||
logo: ImageRef | null;
|
||||
images: ImageRef[];
|
||||
imagesVersion: number;
|
||||
|
||||
@@ -9,6 +9,13 @@ export const cardFieldsSchema = z.object({
|
||||
color: colorSchema,
|
||||
code: z.string().min(1, 'Code is required').max(4000),
|
||||
codeType: z.enum(CODE_TYPES),
|
||||
// Free text, may be multiline. No default: partial updates must not clear it.
|
||||
// Multipart forms send CRLF line breaks: store plain LF.
|
||||
comment: z
|
||||
.string()
|
||||
.transform((s) => s.replace(/\r\n?/g, '\n').trim())
|
||||
.pipe(z.string().max(2000, 'Comment is too long (max 2000 characters)'))
|
||||
.optional(),
|
||||
});
|
||||
export type CardFields = z.infer<typeof cardFieldsSchema>;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user