export const pageWidth = 794; export const pageHeight = 1122; export const minFrame = 12; const dimensions = { text: [448, 100], image: [380, 296], gallery: [480, 260], button: [224, 61], qr: [170, 197], video: [440, 280], social: [232, 56], shape: [245, 158], html: [462, 240], }; export const fontFamilies = { sans: 'Arial, sans-serif', serif: 'Georgia, serif', mono: 'monospace' }; export const designLength = (value) => `${value * 100 / pageWidth}cqw`; export function initialFrame(type, index = 0) { const [width, height] = dimensions[type] || dimensions.text; const offset = (index % 11) * 23; return { x: 63 + offset, y: 63 + offset, width, height, angle: 0 }; } const clamp = (value, minimum, maximum) => Math.min(maximum, Math.max(minimum, Math.round(value))); export function moveFrame(frame, x, y) { return { ...frame, x: clamp(x, minFrame - frame.width, pageWidth - minFrame), y: clamp(y, minFrame - frame.height, pageHeight - minFrame) }; } export function resizeFrame(frame, corner, dx, dy) { const west = corner.includes('w'); const north = corner.includes('n'); const width = clamp(frame.width + (west ? -dx : dx), minFrame, pageWidth * 2); const height = clamp(frame.height + (north ? -dy : dy), minFrame, pageHeight * 2); const radians = frame.angle * Math.PI / 180; const dw = (west ? -1 : 1) * (width - frame.width) / 2; const dh = (north ? -1 : 1) * (height - frame.height) / 2; return { ...frame, width, height, x: Math.round(frame.x + (frame.width - width) / 2 + dw * Math.cos(radians) - dh * Math.sin(radians)), y: Math.round(frame.y + (frame.height - height) / 2 + dw * Math.sin(radians) + dh * Math.cos(radians)), }; } export function frameStyle(frame) { return { left: `${frame.x * 100 / pageWidth}%`, top: `${frame.y * 100 / pageHeight}%`, width: `${frame.width * 100 / pageWidth}%`, height: `${frame.height * 100 / pageHeight}%`, transform: frame.angle ? `rotate(${frame.angle}deg)` : undefined, }; } export function appearanceStyle(appearance = {}) { return { '--item-ink': appearance.color, '--item-fill': appearance.fill, '--item-font': fontFamilies[appearance.font], '--item-size': appearance.fontSize === undefined ? undefined : designLength(appearance.fontSize), '--item-weight': appearance.weight, '--item-leading': appearance.leading, '--item-tracking': appearance.tracking === undefined ? undefined : designLength(appearance.tracking), '--item-fit': appearance.fit, '--item-position': appearance.position, '--item-border': appearance.stroke, '--item-stroke': appearance.strokeWidth ? designLength(appearance.strokeWidth) : undefined, '--item-radius': appearance.radius ? designLength(appearance.radius) : undefined, opacity: appearance.opacity === undefined ? undefined : appearance.opacity / 100, }; } export function cssText(rules) { return Object.entries(rules).filter(([, value]) => value !== undefined).map(([property, value]) => `${property}:${value}`).join(';'); }