/** * Coloring Page Generator * Creates themed coloring pages with pre-defined SVG shapes */ // Library of coloring illustrations (outlines only) const illustrations = { // Animals cat: ` `, dog: ` `, butterfly: ` `, fish: ` `, flower: ` `, star: ` `, rocket: ` `, sun: ` `, house: ` `, unicorn: ` ` }; const illustrationNames = Object.keys(illustrations); /** * Pick an illustration based on theme keywords with randomization */ function pickIllustration(theme, llmSuggestion, age) { // Try LLM suggestion first if valid if (llmSuggestion && illustrations[llmSuggestion]) { return llmSuggestion; } if (!theme) { return illustrationNames[Math.floor(Math.random() * illustrationNames.length)]; } const themeLower = theme.toLowerCase(); // Direct matches for (const name of illustrationNames) { if (themeLower.includes(name)) { return name; } } // Keyword associations const associations = { cat: ['kitten', 'kitty', 'meow', 'feline', 'pet', 'animal'], dog: ['puppy', 'doggy', 'woof', 'canine', 'pet', 'animal'], butterfly: ['insect', 'bug', 'garden', 'spring', 'animal'], fish: ['ocean', 'sea', 'water', 'aquarium', 'swim', 'animal'], flower: ['garden', 'plant', 'nature', 'spring', 'rose'], star: ['night', 'sky', 'space', 'twinkle', 'magic'], rocket: ['space', 'astronaut', 'moon', 'planet', 'fly'], sun: ['summer', 'sunny', 'bright', 'happy', 'day'], house: ['home', 'building', 'family', 'cozy'], unicorn: ['magic', 'fairy', 'princess', 'rainbow', 'fantasy', 'horse', 'animal'] }; // Collect ALL matching illustrations const matchingIllustrations = []; for (const [illustration, keywords] of Object.entries(associations)) { if (keywords.some(keyword => themeLower.includes(keyword))) { matchingIllustrations.push(illustration); } } // If we found matches, pick one randomly for variety if (matchingIllustrations.length > 0) { return matchingIllustrations[Math.floor(Math.random() * matchingIllustrations.length)]; } // Random fallback return illustrationNames[Math.floor(Math.random() * illustrationNames.length)]; } /** * Generate complete coloring page * @param {Object} params * @param {string} params.theme - Theme for the coloring page * @param {string} params.illustration - LLM-suggested illustration (optional) * @param {number} params.age - Child's age (optional) */ export function generateColoringPage({ theme, illustration, age }) { const selectedIllustration = pickIllustration(theme, illustration, age); const illustrationSvg = illustrations[selectedIllustration] || illustrations.cat; const displayName = selectedIllustration.charAt(0).toUpperCase() + selectedIllustration.slice(1); const svg = ` ${illustrationSvg} `; return { title: `${displayName} Coloring Page`, subtitle: theme ? `${theme} themed coloring fun!` : 'Color and have fun!', sections: [{ id: 'coloring-main', type: 'coloring', content_svg: svg }] }; } export default { generateColoringPage };