Something went wrong. Try again.
The IoT platform Cloudflare didn't build. Telemetry, realtime dashboards, and automations on Workers + D1 + R2 + Durable Objects — in your… nodrix.live
Something went wrong. Try again.
12345678910111213141516171819202122232425import type { Layout } from '../types';
export const GRID_COLUMNS = 24;export const ROW_HEIGHT = 40; // grid row height, px (shared by editor + viewer)export const GRID_MARGIN = 12; // gap between cells, pxexport const MIN_UNITS = 2; // smallest widget side, in grid units
// Upscale a sub-resolution (<GRID_COLUMNS) layout to the current grid, idempotently.export function normalizeLayout(layout: Layout): Layout { const cols = layout.grid.columns; if (!cols || cols >= GRID_COLUMNS) return layout; const factor = GRID_COLUMNS / cols; const scale = (n: number) => Math.round(n * factor); return { grid: { columns: GRID_COLUMNS }, items: layout.items.map((it) => { const w = Math.max(1, scale(it.w)); const x = Math.max(0, Math.min(scale(it.x), GRID_COLUMNS - w)); return { ...it, x, y: Math.max(0, scale(it.y)), w, h: Math.max(1, scale(it.h)) }; }), ...(layout.mobile !== undefined ? { mobile: layout.mobile } : {}), ...(layout.refresh !== undefined ? { refresh: layout.refresh } : {}), };}