Skip to content
File

Blob: src/shared/editor/schema/image-model.ts

typescript19 lines
1// Runtime-safe image metadata used by both editor extensions and static presentation.
2// Keep this file free of Tiptap imports so public Sites islands can use it.
3 
4export type ImageAlign = "left" | "center" | "right";
5 
6export function normalizeImageAlign(value: unknown): ImageAlign {
7 return value === "center" || value === "right" ? value : "left";
8}
9 
10export const MIN_IMAGE_BRIGHTNESS = 25;
11export const MAX_IMAGE_BRIGHTNESS = 100;
12 
13export function normalizeImageBrightness(value: unknown): number {
14 const number = typeof value === "number" ? value : typeof value === "string" && value.trim() ? Number(value) : NaN;
15 return Number.isFinite(number)
16 ? Math.round(Math.max(MIN_IMAGE_BRIGHTNESS, Math.min(MAX_IMAGE_BRIGHTNESS, number)))
17 : MAX_IMAGE_BRIGHTNESS;
18}