managarten/packages/wallpaper-generator/src/backgrounds/solid.ts
Till-JS e5109da732 feat(wallpaper-generator): add device wallpaper generation package
Add new @manacore/wallpaper-generator package for creating device
wallpapers from QR codes and images.

Features:
- 30 device presets (phones, tablets, desktops)
- 3 layout types (center, corner, pattern)
- 5 gradient presets + solid color backgrounds
- Browser (Canvas) and Node.js (Sharp) renderers
- Svelte WallpaperModal UI component

Integrations:
- @manacore/qr-export: toWallpaper() function
- @manacore/spiral-db: toWallpaper() function
- QRExportModal: "Als Wallpaper" button

Also includes the full @manacore/qr-export package which was
previously untracked.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-02-17 12:57:43 +01:00

57 lines
1.2 KiB
TypeScript

/**
* Solid Background Renderer
*
* Fills canvas with a solid color.
*/
/**
* Parse hex color to RGB values
*/
export function parseHexColor(hex: string): { r: number; g: number; b: number } {
// Remove # if present
const cleanHex = hex.replace('#', '');
// Handle shorthand hex (e.g., #fff)
const fullHex =
cleanHex.length === 3
? cleanHex
.split('')
.map((c) => c + c)
.join('')
: cleanHex;
const r = parseInt(fullHex.substring(0, 2), 16);
const g = parseInt(fullHex.substring(2, 4), 16);
const b = parseInt(fullHex.substring(4, 6), 16);
return { r, g, b };
}
/**
* Fill canvas with solid color (browser)
*/
export function fillSolid(
ctx: CanvasRenderingContext2D,
width: number,
height: number,
color: string
): void {
ctx.fillStyle = color;
ctx.fillRect(0, 0, width, height);
}
/**
* Create solid color buffer for Node.js/Sharp
*/
export function createSolidBuffer(width: number, height: number, color: string): Uint8Array {
const { r, g, b } = parseHexColor(color);
const buffer = new Uint8Array(width * height * 3);
for (let i = 0; i < width * height; i++) {
buffer[i * 3] = r;
buffer[i * 3 + 1] = g;
buffer[i * 3 + 2] = b;
}
return buffer;
}