File
Blob: src/shared/editor/schema/image-model.ts
| 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 | |
| 4 | export type ImageAlign = "left" | "center" | "right"; |
| 5 | |
| 6 | export function normalizeImageAlign(value: unknown): ImageAlign { |
| 7 | return value === "center" || value === "right" ? value : "left"; |
| 8 | } |
| 9 | |
| 10 | export const MIN_IMAGE_BRIGHTNESS = 25; |
| 11 | export const MAX_IMAGE_BRIGHTNESS = 100; |
| 12 | |
| 13 | export 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 | } |