refactor: rename pastel app to color and update all references
This commit is contained in:
13
lib/color/utils/color.ts
Normal file
13
lib/color/utils/color.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Parse hex color to RGB
|
||||
*/
|
||||
export function hexToRgb(hex: string): { r: number; g: number; b: number } | null {
|
||||
const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
||||
return result
|
||||
? {
|
||||
r: parseInt(result[1], 16),
|
||||
g: parseInt(result[2], 16),
|
||||
b: parseInt(result[3], 16),
|
||||
}
|
||||
: null;
|
||||
}
|
||||
83
lib/color/utils/export.ts
Normal file
83
lib/color/utils/export.ts
Normal file
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* Export utilities for color palettes
|
||||
*/
|
||||
|
||||
export interface ExportColor {
|
||||
name?: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export colors as CSS variables
|
||||
*/
|
||||
export function exportAsCSS(colors: ExportColor[]): string {
|
||||
const variables = colors
|
||||
.map((color, index) => {
|
||||
const name = color.name || `color-${index + 1}`;
|
||||
return ` --${name}: ${color.value};`;
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
return `:root {\n${variables}\n}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export colors as SCSS variables
|
||||
*/
|
||||
export function exportAsSCSS(colors: ExportColor[]): string {
|
||||
return colors
|
||||
.map((color, index) => {
|
||||
const name = color.name || `color-${index + 1}`;
|
||||
return `$${name}: ${color.value};`;
|
||||
})
|
||||
.join('\n');
|
||||
}
|
||||
|
||||
/**
|
||||
* Export colors as Tailwind config
|
||||
*/
|
||||
export function exportAsTailwind(colors: ExportColor[]): string {
|
||||
const colorEntries = colors
|
||||
.map((color, index) => {
|
||||
const name = color.name || `color-${index + 1}`;
|
||||
return ` '${name}': '${color.value}',`;
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
return `module.exports = {\n theme: {\n extend: {\n colors: {\n${colorEntries}\n },\n },\n },\n};`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export colors as JSON
|
||||
*/
|
||||
export function exportAsJSON(colors: ExportColor[]): string {
|
||||
const colorObjects = colors.map((color, index) => ({
|
||||
name: color.name || `color-${index + 1}`,
|
||||
value: color.value,
|
||||
}));
|
||||
|
||||
return JSON.stringify({ colors: colorObjects }, null, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export colors as JavaScript array
|
||||
*/
|
||||
export function exportAsJavaScript(colors: ExportColor[]): string {
|
||||
const colorArray = colors.map((c) => `'${c.value}'`).join(', ');
|
||||
return `const colors = [${colorArray}];`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Download text as file
|
||||
*/
|
||||
export function downloadAsFile(content: string, filename: string, mimeType: string = 'text/plain') {
|
||||
const blob = new Blob([content], { type: mimeType });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = filename;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
Reference in New Issue
Block a user