'lm', 'dark-mode' => 'dm', 'light-accent' => 'la', 'dark-accent' => 'da', ]; // Payment shapes $paymentShapes = ['icon', 'square', 'rectangle', 'text-only']; // Social shapes $socialShapes = ['icon', 'full-logo', 'text-only']; /** * Build a sprite from a directory of SVG files */ function buildSprite(string $sourceDir, string $outputFile, string $modeSuffix): void { if (!is_dir($sourceDir)) { echo " Skipping: $sourceDir (not found)\n"; return; } $files = glob($sourceDir . '/*.svg'); if (empty($files)) { echo " Skipping: $sourceDir (no SVG files)\n"; return; } $symbols = []; foreach ($files as $file) { $filename = basename($file, '.svg'); $content = file_get_contents($file); // Extract viewBox from original SVG preg_match('/viewBox="([^"]+)"/', $content, $viewBoxMatch); $viewBox = $viewBoxMatch[1] ?? '0 0 45 45'; // Extract width/height if present preg_match('/width="([^"]+)"/', $content, $widthMatch); preg_match('/height="([^"]+)"/', $content, $heightMatch); $width = $widthMatch[1] ?? null; $height = $heightMatch[1] ?? null; // Remove XML declaration and outer SVG tags $content = preg_replace('/<\?xml[^>]+\?>/', '', $content); $content = preg_replace('//', '', $content); // Extract inner content (everything between and ) if (preg_match('/]*>(.*)<\/svg>/s', $content, $match)) { $innerContent = trim($match[1]); } else { echo " Warning: Could not parse $filename\n"; continue; } // Clean up the inner content - remove defs with clip-paths that reference unique IDs // and inline styles where possible $innerContent = preg_replace('/.*?<\/defs>/s', '', $innerContent); $innerContent = preg_replace('/clip-path="url\([^)]+\)"/', '', $innerContent); $innerContent = preg_replace('/]*>.*?<\/clipPath>/s', '', $innerContent); $innerContent = preg_replace('/]*>\s*<\/g>/', '', $innerContent); // Use filename as ID (already includes mode suffix like visa_lm) $id = $filename; $symbols[] = " $innerContent"; } if (empty($symbols)) { echo " Skipping: $outputFile (no valid symbols)\n"; return; } $sprite = "\n"; $sprite .= implode("\n", $symbols) . "\n"; $sprite .= "\n"; file_put_contents($outputFile, $sprite); echo " Created: $outputFile (" . count($symbols) . " icons)\n"; } // Build payment sprites echo "Building payment sprites...\n"; foreach ($paymentShapes as $shape) { foreach ($modes as $modeDir => $modeSuffix) { $sourceDir = "$materialsDir/payment-icons/$shape/$modeDir"; $outputFile = "$outputDir/payments/$shape-$modeSuffix.svg"; buildSprite($sourceDir, $outputFile, $modeSuffix); } } // Build social sprites echo "\nBuilding social sprites...\n"; foreach ($socialShapes as $shape) { foreach ($modes as $modeDir => $modeSuffix) { $sourceDir = "$materialsDir/socials-icons/$shape/$modeDir"; $outputFile = "$outputDir/socials/$shape-$modeSuffix.svg"; buildSprite($sourceDir, $outputFile, $modeSuffix); } } echo "\nDone!\n";